Index: lib/Analysis/TypeBasedAliasAnalysis.cpp =================================================================== --- lib/Analysis/TypeBasedAliasAnalysis.cpp +++ lib/Analysis/TypeBasedAliasAnalysis.cpp @@ -448,6 +448,18 @@ if (!EnableTBAA) return AliasAnalysis::alias(LocA, LocB); + // Be conservative when comparing elements of StructType as members of union + // MayAlias each other. + const Value* VA = LocA.Ptr; + const Value* VB = LocB.Ptr; + if (VA->getType()->getTypeID() == Type::PointerTyID && + VB->getType()->getTypeID() == Type::PointerTyID) { + Type* TyA = cast(VA->getType())->getElementType(); + Type* TyB = cast(VB->getType())->getElementType(); + if(TyA->getTypeID() == Type::StructTyID && + TyB->getTypeID() == Type::StructTyID) + return AliasAnalysis::alias(LocA, LocB); + } // Get the attached MDNodes. If either value lacks a tbaa MDNode, we must // be conservative. const MDNode *AM = LocA.TBAATag; Index: test/Analysis/TypeBasedAliasAnalysis/placement-tbaa.ll =================================================================== --- test/Analysis/TypeBasedAliasAnalysis/placement-tbaa.ll +++ test/Analysis/TypeBasedAliasAnalysis/placement-tbaa.ll @@ -16,9 +16,9 @@ ; return f->i; ; } -; Basic AA says MayAlias, TBAA says NoAlias +; Basic AA says MayAlias, TBAA also conservatively says MayAlias ; CHECK: MayAlias: i64* %i5, i8** %p -; CHECK: NoAlias: store i64 %conv, i64* %i5, align 8, !tbaa !6 <-> store i8* null, i8** %p, align 8, !tbaa !9 +; CHECK: MayAlias: store i64 %conv, i64* %i5, align 8, !tbaa !6 <-> store i8* null, i8** %p, align 8, !tbaa !9 %struct.Foo = type { i64 } %struct.Bar = type { i8* }