@@ -371,11 +371,27 @@ static bool isStructPathTBAA(const MDNode *MD) {
371371 return isa<MDNode>(MD->getOperand (0 )) && MD->getNumOperands () >= 3 ;
372372}
373373
374+ // When using the TypeSanitizer, don't use TBAA information for alias analysis.
375+ // This might cause us to remove memory accesses that we need to verify at
376+ // runtime.
377+ static bool usingSanitizeType (const Value *V) {
378+ const Function *F;
379+
380+ if (auto *I = dyn_cast<Instruction>(V))
381+ F = I->getParent ()->getParent ();
382+ else if (auto *A = dyn_cast<Argument>(V))
383+ F = A->getParent ();
384+ else
385+ return false ;
386+
387+ return F->hasFnAttribute (Attribute::SanitizeType);
388+ }
389+
374390AliasResult TypeBasedAAResult::alias (const MemoryLocation &LocA,
375391 const MemoryLocation &LocB,
376392 AAQueryInfo &AAQI, const Instruction *) {
377- if (!EnableTBAA)
378- return AliasResult::MayAlias ;
393+ if (!EnableTBAA || usingSanitizeType (LocA. Ptr ) || usingSanitizeType (LocB. Ptr ) )
394+ return AAResultBase::alias (LocA, LocB, AAQI, nullptr ) ;
379395
380396 if (Aliases (LocA.AATags .TBAA , LocB.AATags .TBAA ))
381397 return AliasResult::MayAlias;
@@ -425,8 +441,8 @@ MemoryEffects TypeBasedAAResult::getMemoryEffects(const Function *F) {
425441ModRefInfo TypeBasedAAResult::getModRefInfo (const CallBase *Call,
426442 const MemoryLocation &Loc,
427443 AAQueryInfo &AAQI) {
428- if (!EnableTBAA)
429- return ModRefInfo::ModRef ;
444+ if (!EnableTBAA || usingSanitizeType (Call) )
445+ return AAResultBase::getModRefInfo (Call, Loc, AAQI) ;
430446
431447 if (const MDNode *L = Loc.AATags .TBAA )
432448 if (const MDNode *M = Call->getMetadata (LLVMContext::MD_tbaa))
@@ -439,8 +455,8 @@ ModRefInfo TypeBasedAAResult::getModRefInfo(const CallBase *Call,
439455ModRefInfo TypeBasedAAResult::getModRefInfo (const CallBase *Call1,
440456 const CallBase *Call2,
441457 AAQueryInfo &AAQI) {
442- if (!EnableTBAA)
443- return ModRefInfo::ModRef ;
458+ if (!EnableTBAA || usingSanitizeType (Call1) )
459+ return AAResultBase::getModRefInfo (Call1, Call2, AAQI) ;
444460
445461 if (const MDNode *M1 = Call1->getMetadata (LLVMContext::MD_tbaa))
446462 if (const MDNode *M2 = Call2->getMetadata (LLVMContext::MD_tbaa))
0 commit comments