@@ -205,16 +205,27 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
205
205
llvm::MDNode *AnyPtr = createScalarTypeNode (" any pointer" , getChar (), Size);
206
206
if (!CodeGenOpts.PointerTBAA )
207
207
return AnyPtr;
208
- // Compute the depth of the pointer and generate a tag of the form "p<depth>
209
- // <base type tag>". Look through pointer and array types to determine the
210
- // base type.
208
+ // C++ [basic.lval]p11 permits objects to accessed through an l-value of
209
+ // similar type. Two types are similar under C++ [conv.qual]p2 if the
210
+ // decomposition of the types into pointers, member pointers, and arrays has
211
+ // the same structure when ignoring cv-qualifiers at each level of the
212
+ // decomposition. Meanwhile, C makes T(*)[] and T(*)[N] compatible, which
213
+ // would really complicate any attempt to distinguish pointers to arrays by
214
+ // their bounds. It's simpler, and much easier to explain to users, to
215
+ // simply treat all pointers to arrays as pointers to their element type for
216
+ // aliasing purposes. So when creating a TBAA tag for a pointer type, we
217
+ // recursively ignore both qualifiers and array types when decomposing the
218
+ // pointee type. The only meaningful remaining structure is the number of
219
+ // pointer types we encountered along the way, so we just produce the tag
220
+ // "p<depth> <base type tag>". If we do find a member pointer type, for now
221
+ // we just conservatively bail out with AnyPtr (below) rather than trying to
222
+ // create a tag that honors the similar-type rules while still
223
+ // distinguishing different kinds of member pointer.
211
224
unsigned PtrDepth = 0 ;
212
225
do {
213
226
PtrDepth++;
214
- Ty = Ty->isPointerType () ? Ty->getPointeeType ().getTypePtr ()
215
- : Ty->getArrayElementTypeNoTypeQual ();
227
+ Ty = Ty->getPointeeType ()->getBaseElementTypeUnsafe ();
216
228
} while (Ty->isPointerType () || Ty->isArrayType ());
217
- Ty = Context.getBaseElementType (QualType (Ty, 0 )).getTypePtr ();
218
229
assert (!isa<VariableArrayType>(Ty));
219
230
// When the underlying type is a builtin type, we compute the pointee type
220
231
// string recursively, which is implicitly more forgiving than the standards
@@ -232,9 +243,10 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
232
243
->getString ();
233
244
TyName = Name;
234
245
} else {
235
- // Be conservative if the type a MemberPointerType. Those would require
236
- // stripping const-qualifiers inside the type.
237
- if (Ty->isMemberPointerType ())
246
+ // Be conservative if the type isn't a RecordType. We are specifically
247
+ // required to do this for member pointers until we implement the
248
+ // similar-types rule.
249
+ if (!Ty->isRecordType ())
238
250
return AnyPtr;
239
251
240
252
// For non-builtin types use the mangled name of the canonical type.
0 commit comments