@@ -205,7 +205,7 @@ void ThreadSanitizer::initialize(Module &M, const TargetLibraryInfo &TLI) {
205205 Attr = Attr.addFnAttribute (Ctx, Attribute::NoUnwind);
206206 // Initialize the callbacks.
207207 TsanFuncEntry = M.getOrInsertFunction (" __tsan_func_entry" , Attr,
208- IRB.getVoidTy (), IRB.getPtrTy ());
208+ IRB.getVoidTy (), IRB.getInt8PtrTy ());
209209 TsanFuncExit =
210210 M.getOrInsertFunction (" __tsan_func_exit" , Attr, IRB.getVoidTy ());
211211 TsanIgnoreBegin = M.getOrInsertFunction (" __tsan_ignore_thread_begin" , Attr,
@@ -220,49 +220,49 @@ void ThreadSanitizer::initialize(Module &M, const TargetLibraryInfo &TLI) {
220220 std::string BitSizeStr = utostr (BitSize);
221221 SmallString<32 > ReadName (" __tsan_read" + ByteSizeStr);
222222 TsanRead[i] = M.getOrInsertFunction (ReadName, Attr, IRB.getVoidTy (),
223- IRB.getPtrTy ());
223+ IRB.getInt8PtrTy ());
224224
225225 SmallString<32 > WriteName (" __tsan_write" + ByteSizeStr);
226226 TsanWrite[i] = M.getOrInsertFunction (WriteName, Attr, IRB.getVoidTy (),
227- IRB.getPtrTy ());
227+ IRB.getInt8PtrTy ());
228228
229229 SmallString<64 > UnalignedReadName (" __tsan_unaligned_read" + ByteSizeStr);
230230 TsanUnalignedRead[i] = M.getOrInsertFunction (
231- UnalignedReadName, Attr, IRB.getVoidTy (), IRB.getPtrTy ());
231+ UnalignedReadName, Attr, IRB.getVoidTy (), IRB.getInt8PtrTy ());
232232
233233 SmallString<64 > UnalignedWriteName (" __tsan_unaligned_write" + ByteSizeStr);
234234 TsanUnalignedWrite[i] = M.getOrInsertFunction (
235- UnalignedWriteName, Attr, IRB.getVoidTy (), IRB.getPtrTy ());
235+ UnalignedWriteName, Attr, IRB.getVoidTy (), IRB.getInt8PtrTy ());
236236
237237 SmallString<64 > VolatileReadName (" __tsan_volatile_read" + ByteSizeStr);
238238 TsanVolatileRead[i] = M.getOrInsertFunction (
239- VolatileReadName, Attr, IRB.getVoidTy (), IRB.getPtrTy ());
239+ VolatileReadName, Attr, IRB.getVoidTy (), IRB.getInt8PtrTy ());
240240
241241 SmallString<64 > VolatileWriteName (" __tsan_volatile_write" + ByteSizeStr);
242242 TsanVolatileWrite[i] = M.getOrInsertFunction (
243- VolatileWriteName, Attr, IRB.getVoidTy (), IRB.getPtrTy ());
243+ VolatileWriteName, Attr, IRB.getVoidTy (), IRB.getInt8PtrTy ());
244244
245245 SmallString<64 > UnalignedVolatileReadName (" __tsan_unaligned_volatile_read" +
246246 ByteSizeStr);
247247 TsanUnalignedVolatileRead[i] = M.getOrInsertFunction (
248- UnalignedVolatileReadName, Attr, IRB.getVoidTy (), IRB.getPtrTy ());
248+ UnalignedVolatileReadName, Attr, IRB.getVoidTy (), IRB.getInt8PtrTy ());
249249
250250 SmallString<64 > UnalignedVolatileWriteName (
251251 " __tsan_unaligned_volatile_write" + ByteSizeStr);
252252 TsanUnalignedVolatileWrite[i] = M.getOrInsertFunction (
253- UnalignedVolatileWriteName, Attr, IRB.getVoidTy (), IRB.getPtrTy ());
253+ UnalignedVolatileWriteName, Attr, IRB.getVoidTy (), IRB.getInt8PtrTy ());
254254
255255 SmallString<64 > CompoundRWName (" __tsan_read_write" + ByteSizeStr);
256256 TsanCompoundRW[i] = M.getOrInsertFunction (
257- CompoundRWName, Attr, IRB.getVoidTy (), IRB.getPtrTy ());
257+ CompoundRWName, Attr, IRB.getVoidTy (), IRB.getInt8PtrTy ());
258258
259259 SmallString<64 > UnalignedCompoundRWName (" __tsan_unaligned_read_write" +
260260 ByteSizeStr);
261261 TsanUnalignedCompoundRW[i] = M.getOrInsertFunction (
262- UnalignedCompoundRWName, Attr, IRB.getVoidTy (), IRB.getPtrTy ());
262+ UnalignedCompoundRWName, Attr, IRB.getVoidTy (), IRB.getInt8PtrTy ());
263263
264264 Type *Ty = Type::getIntNTy (Ctx, BitSize);
265- Type *PtrTy = PointerType::get (Ctx, 0 );
265+ Type *PtrTy = Ty-> getPointerTo ( );
266266 SmallString<32 > AtomicLoadName (" __tsan_atomic" + BitSizeStr + " _load" );
267267 TsanAtomicLoad[i] =
268268 M.getOrInsertFunction (AtomicLoadName,
@@ -318,9 +318,9 @@ void ThreadSanitizer::initialize(Module &M, const TargetLibraryInfo &TLI) {
318318 }
319319 TsanVptrUpdate =
320320 M.getOrInsertFunction (" __tsan_vptr_update" , Attr, IRB.getVoidTy (),
321- IRB.getPtrTy (), IRB.getPtrTy ());
321+ IRB.getInt8PtrTy (), IRB.getInt8PtrTy ());
322322 TsanVptrLoad = M.getOrInsertFunction (" __tsan_vptr_read" , Attr,
323- IRB.getVoidTy (), IRB.getPtrTy ());
323+ IRB.getVoidTy (), IRB.getInt8PtrTy ());
324324 TsanAtomicThreadFence = M.getOrInsertFunction (
325325 " __tsan_atomic_thread_fence" ,
326326 TLI.getAttrList (&Ctx, {0 }, /* Signed=*/ true , /* Ret=*/ false , Attr),
@@ -332,15 +332,15 @@ void ThreadSanitizer::initialize(Module &M, const TargetLibraryInfo &TLI) {
332332 IRB.getVoidTy (), OrdTy);
333333
334334 MemmoveFn =
335- M.getOrInsertFunction (" __tsan_memmove" , Attr, IRB.getPtrTy (),
336- IRB.getPtrTy (), IRB.getPtrTy (), IntptrTy);
335+ M.getOrInsertFunction (" __tsan_memmove" , Attr, IRB.getInt8PtrTy (),
336+ IRB.getInt8PtrTy (), IRB.getInt8PtrTy (), IntptrTy);
337337 MemcpyFn =
338- M.getOrInsertFunction (" __tsan_memcpy" , Attr, IRB.getPtrTy (),
339- IRB.getPtrTy (), IRB.getPtrTy (), IntptrTy);
338+ M.getOrInsertFunction (" __tsan_memcpy" , Attr, IRB.getInt8PtrTy (),
339+ IRB.getInt8PtrTy (), IRB.getInt8PtrTy (), IntptrTy);
340340 MemsetFn = M.getOrInsertFunction (
341341 " __tsan_memset" ,
342342 TLI.getAttrList (&Ctx, {1 }, /* Signed=*/ true , /* Ret=*/ false , Attr),
343- IRB.getPtrTy (), IRB.getPtrTy (), IRB.getInt32Ty (), IntptrTy);
343+ IRB.getInt8PtrTy (), IRB.getInt8PtrTy (), IRB.getInt32Ty (), IntptrTy);
344344}
345345
346346static bool isVtableAccess (Instruction *I) {
@@ -613,14 +613,17 @@ bool ThreadSanitizer::instrumentLoadOrStore(const InstructionInfo &II,
613613 StoredValue = IRB.CreateExtractElement (
614614 StoredValue, ConstantInt::get (IRB.getInt32Ty (), 0 ));
615615 if (StoredValue->getType ()->isIntegerTy ())
616- StoredValue = IRB.CreateIntToPtr (StoredValue, IRB.getPtrTy ());
616+ StoredValue = IRB.CreateIntToPtr (StoredValue, IRB.getInt8PtrTy ());
617617 // Call TsanVptrUpdate.
618- IRB.CreateCall (TsanVptrUpdate, {Addr, StoredValue});
618+ IRB.CreateCall (TsanVptrUpdate,
619+ {IRB.CreatePointerCast (Addr, IRB.getInt8PtrTy ()),
620+ IRB.CreatePointerCast (StoredValue, IRB.getInt8PtrTy ())});
619621 NumInstrumentedVtableWrites++;
620622 return true ;
621623 }
622624 if (!IsWrite && isVtableAccess (II.Inst )) {
623- IRB.CreateCall (TsanVptrLoad, Addr);
625+ IRB.CreateCall (TsanVptrLoad,
626+ IRB.CreatePointerCast (Addr, IRB.getInt8PtrTy ()));
624627 NumInstrumentedVtableReads++;
625628 return true ;
626629 }
@@ -652,7 +655,7 @@ bool ThreadSanitizer::instrumentLoadOrStore(const InstructionInfo &II,
652655 else
653656 OnAccessFunc = IsWrite ? TsanUnalignedWrite[Idx] : TsanUnalignedRead[Idx];
654657 }
655- IRB.CreateCall (OnAccessFunc, Addr);
658+ IRB.CreateCall (OnAccessFunc, IRB. CreatePointerCast ( Addr, IRB. getInt8PtrTy ()) );
656659 if (IsCompoundRW || IsWrite)
657660 NumInstrumentedWrites++;
658661 if (IsCompoundRW || !IsWrite)
@@ -688,19 +691,17 @@ static ConstantInt *createOrdering(IRBuilder<> *IRB, AtomicOrdering ord) {
688691bool ThreadSanitizer::instrumentMemIntrinsic (Instruction *I) {
689692 InstrumentationIRBuilder IRB (I);
690693 if (MemSetInst *M = dyn_cast<MemSetInst>(I)) {
691- Value *Cast1 = IRB.CreateIntCast (M->getArgOperand (1 ), IRB.getInt32Ty (), false );
692- Value *Cast2 = IRB.CreateIntCast (M->getArgOperand (2 ), IntptrTy, false );
693694 IRB.CreateCall (
694695 MemsetFn,
695- {M->getArgOperand (0 ),
696- Cast1 ,
697- Cast2 });
696+ {IRB. CreatePointerCast ( M->getArgOperand (0 ), IRB. getInt8PtrTy () ),
697+ IRB. CreateIntCast (M-> getArgOperand ( 1 ), IRB. getInt32Ty (), false ) ,
698+ IRB. CreateIntCast (M-> getArgOperand ( 2 ), IntptrTy, false ) });
698699 I->eraseFromParent ();
699700 } else if (MemTransferInst *M = dyn_cast<MemTransferInst>(I)) {
700701 IRB.CreateCall (
701702 isa<MemCpyInst>(M) ? MemcpyFn : MemmoveFn,
702- {M->getArgOperand (0 ),
703- M->getArgOperand (1 ),
703+ {IRB. CreatePointerCast ( M->getArgOperand (0 ), IRB. getInt8PtrTy () ),
704+ IRB. CreatePointerCast ( M->getArgOperand (1 ), IRB. getInt8PtrTy () ),
704705 IRB.CreateIntCast (M->getArgOperand (2 ), IntptrTy, false )});
705706 I->eraseFromParent ();
706707 }
@@ -723,7 +724,11 @@ bool ThreadSanitizer::instrumentAtomic(Instruction *I, const DataLayout &DL) {
723724 int Idx = getMemoryAccessFuncIndex (OrigTy, Addr, DL);
724725 if (Idx < 0 )
725726 return false ;
726- Value *Args[] = {Addr,
727+ const unsigned ByteSize = 1U << Idx;
728+ const unsigned BitSize = ByteSize * 8 ;
729+ Type *Ty = Type::getIntNTy (IRB.getContext (), BitSize);
730+ Type *PtrTy = Ty->getPointerTo ();
731+ Value *Args[] = {IRB.CreatePointerCast (Addr, PtrTy),
727732 createOrdering (&IRB, LI->getOrdering ())};
728733 Value *C = IRB.CreateCall (TsanAtomicLoad[Idx], Args);
729734 Value *Cast = IRB.CreateBitOrPointerCast (C, OrigTy);
@@ -737,7 +742,8 @@ bool ThreadSanitizer::instrumentAtomic(Instruction *I, const DataLayout &DL) {
737742 const unsigned ByteSize = 1U << Idx;
738743 const unsigned BitSize = ByteSize * 8 ;
739744 Type *Ty = Type::getIntNTy (IRB.getContext (), BitSize);
740- Value *Args[] = {Addr,
745+ Type *PtrTy = Ty->getPointerTo ();
746+ Value *Args[] = {IRB.CreatePointerCast (Addr, PtrTy),
741747 IRB.CreateBitOrPointerCast (SI->getValueOperand (), Ty),
742748 createOrdering (&IRB, SI->getOrdering ())};
743749 CallInst *C = CallInst::Create (TsanAtomicStore[Idx], Args);
@@ -754,7 +760,8 @@ bool ThreadSanitizer::instrumentAtomic(Instruction *I, const DataLayout &DL) {
754760 const unsigned ByteSize = 1U << Idx;
755761 const unsigned BitSize = ByteSize * 8 ;
756762 Type *Ty = Type::getIntNTy (IRB.getContext (), BitSize);
757- Value *Args[] = {Addr,
763+ Type *PtrTy = Ty->getPointerTo ();
764+ Value *Args[] = {IRB.CreatePointerCast (Addr, PtrTy),
758765 IRB.CreateIntCast (RMWI->getValOperand (), Ty, false ),
759766 createOrdering (&IRB, RMWI->getOrdering ())};
760767 CallInst *C = CallInst::Create (F, Args);
@@ -768,11 +775,12 @@ bool ThreadSanitizer::instrumentAtomic(Instruction *I, const DataLayout &DL) {
768775 const unsigned ByteSize = 1U << Idx;
769776 const unsigned BitSize = ByteSize * 8 ;
770777 Type *Ty = Type::getIntNTy (IRB.getContext (), BitSize);
778+ Type *PtrTy = Ty->getPointerTo ();
771779 Value *CmpOperand =
772780 IRB.CreateBitOrPointerCast (CASI->getCompareOperand (), Ty);
773781 Value *NewOperand =
774782 IRB.CreateBitOrPointerCast (CASI->getNewValOperand (), Ty);
775- Value *Args[] = {Addr,
783+ Value *Args[] = {IRB. CreatePointerCast ( Addr, PtrTy) ,
776784 CmpOperand,
777785 NewOperand,
778786 createOrdering (&IRB, CASI->getSuccessOrdering ()),
0 commit comments