@@ -39,8 +39,9 @@ CodeGenTBAA::CodeGenTBAA(ASTContext &Ctx, CodeGenTypes &CGTypes,
39
39
llvm::Module &M, const CodeGenOptions &CGO,
40
40
const LangOptions &Features)
41
41
: 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 ) {}
44
45
45
46
CodeGenTBAA::~CodeGenTBAA () {
46
47
}
@@ -202,14 +203,6 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
202
203
// Other qualifiers could theoretically be distinguished, especially if
203
204
// they involve a significant representation difference. We don't
204
205
// 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.
213
206
if (Ty->isPointerType () || Ty->isReferenceType ()) {
214
207
llvm::MDNode *AnyPtr = createScalarTypeNode (" any pointer" , getChar (), Size);
215
208
if (!CodeGenOpts.PointerTBAA )
@@ -221,7 +214,15 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
221
214
PtrDepth++;
222
215
Ty = Ty->getPointeeType ().getTypePtr ();
223
216
} 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.
225
226
SmallString<256 > TyName;
226
227
if (isa<BuiltinType>(Ty)) {
227
228
llvm::MDNode *ScalarMD = getTypeInfoHelper (Ty);
@@ -230,18 +231,17 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
230
231
ScalarMD->getOperand (CodeGenOpts.NewStructPathTBAA ? 2 : 0 ))
231
232
->getString ();
232
233
TyName = Name;
233
- } else if (!isa<VariableArrayType>(Ty)) {
234
+ } else {
234
235
// For non-builtin types use the mangled name of the canonical type.
235
236
llvm::raw_svector_ostream TyOut (TyName);
236
- Context.createMangleContext ()->mangleCanonicalTypeName (QualType (Ty, 0 ),
237
- TyOut);
237
+ MangleCtx->mangleCanonicalTypeName (QualType (Ty, 0 ), TyOut);
238
238
}
239
239
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);
245
245
}
246
246
247
247
// Accesses to arrays are accesses to objects of their element types.
0 commit comments