@@ -39,8 +39,9 @@ CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes,
3939 llvm::Module &M, const CodeGenOptions &CGO,
4040 const LangOptions &Features)
4141 : Context(Ctx), CGTypes(CGTypes), Module(M), CodeGenOpts(CGO),
42- Features(Features), MDHelper(M.getContext()), Root(nullptr ),
43- Char(nullptr ) {}
42+ Features(Features),
43+ MangleCtx(ItaniumMangleContext::create(Ctx, Ctx.getDiagnostics())),
44+ MDHelper(M.getContext()), Root(nullptr ), Char(nullptr ) {}
4445
4546CodeGenTBAA::~CodeGenTBAA () {
4647}
@@ -202,14 +203,6 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
202203 // Other qualifiers could theoretically be distinguished, especially if
203204 // they involve a significant representation difference. We don't
204205 // currently do so, however.
205- //
206- // Computing the pointee type string recursively is implicitly more
207- // forgiving than the standards require. Effectively, we are turning
208- // the question "are these types compatible/similar" into "are
209- // accesses to these types allowed to alias". In both C and C++,
210- // the latter question has special carve-outs for signedness
211- // mismatches that only apply at the top level. As a result, we are
212- // allowing e.g. `int *` l-values to access `unsigned *` objects.
213206 if (Ty->isPointerType () || Ty->isReferenceType ()) {
214207 llvm::MDNode *AnyPtr = createScalarTypeNode (" any pointer" , getChar (), Size);
215208 if (!CodeGenOpts.PointerTBAA )
@@ -221,7 +214,15 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
221214 PtrDepth++;
222215 Ty = Ty->getPointeeType ().getTypePtr ();
223216 } while (Ty->isPointerType ());
224-
217+ Ty = Context.getBaseElementType (QualType (Ty, 0 )).getTypePtr ();
218+ assert (!isa<VariableArrayType>(Ty));
219+ // When the underlying type is a builtin type, we compute the pointee type
220+ // string recursively, which is implicitly more forgiving than the standards
221+ // require. Effectively, we are turning the question "are these types
222+ // compatible/similar" into "are accesses to these types allowed to alias".
223+ // In both C and C++, the latter question has special carve-outs for
224+ // signedness mismatches that only apply at the top level. As a result, we
225+ // are allowing e.g. `int *` l-values to access `unsigned *` objects.
225226 SmallString<256 > TyName;
226227 if (isa<BuiltinType>(Ty)) {
227228 llvm::MDNode *ScalarMD = getTypeInfoHelper (Ty);
@@ -230,18 +231,17 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
230231 ScalarMD->getOperand (CodeGenOpts.NewStructPathTBAA ? 2 : 0 ))
231232 ->getString ();
232233 TyName = Name;
233- } else if (!isa<VariableArrayType>(Ty)) {
234+ } else {
234235 // For non-builtin types use the mangled name of the canonical type.
235236 llvm::raw_svector_ostream TyOut (TyName);
236- Context.createMangleContext ()->mangleCanonicalTypeName (QualType (Ty, 0 ),
237- TyOut);
237+ MangleCtx->mangleCanonicalTypeName (QualType (Ty, 0 ), TyOut);
238238 }
239239
240- SmallString<256 > OutName (" p" );
241- OutName += std::to_string (PtrDepth);
242- OutName += " " ;
243- OutName += TyName;
244- return createScalarTypeNode (OutName, AnyPtr, Size);
240+ SmallString<256 > OutName (" p" );
241+ OutName += std::to_string (PtrDepth);
242+ OutName += " " ;
243+ OutName += TyName;
244+ return createScalarTypeNode (OutName, AnyPtr, Size);
245245 }
246246
247247 // Accesses to arrays are accesses to objects of their element types.
0 commit comments