[clang] [TBAA] Only emit pointer tbaa metedata for record types. (PR #116991)

John McCall via cfe-commits cfe-commits at lists.llvm.org
Wed Nov 20 15:38:21 PST 2024


================
@@ -206,12 +206,14 @@ llvm::MDNode *CodeGenTBAA::getTypeInfoHelper(const Type *Ty) {
     if (!CodeGenOpts.PointerTBAA)
       return AnyPtr;
     // Compute the depth of the pointer and generate a tag of the form "p<depth>
-    // <base type tag>".
+    // <base type tag>". Look through pointer and array types to determine the
+    // base type.
----------------
rjmccall wrote:

Suggestion as a replacement for the comment:

```
    // C++ [basic.lval]p11 permits objects to accessed through an l-value
    // of similar type. Two types are similar under C++ [conv.qual]p2
    // if the decomposition of the types into pointers, member pointers,
    // and arrays has the same structure when ignoring cv-qualifiers at
    // each level of the decomposition. Meanwhile, C makes T(*)[] and
    // T(*)[N] compatible, which would really complicate any attempt to
    // distinguish pointers to arrays by their bounds. It's simpler, and
    // much easier to explain to users, to simply treat all pointers to
    // arrays as pointers to their element type for aliasing purposes.
    // So when creating a TBAA tag for a pointer type, we recursively
    // ignore both qualifiers and array types when decomposing
    // the pointee type. The only meaningful remaining structure is the
    // number of pointer types we encountered along the way, so we
    // just produce the tag "p<depth> <base type tag>". If we do find a
    // member pointer type, for now we just conservatively bail out
    // with AnyPtr (below) rather than trying to create a tag that
    // honors the similar-type rules while still distinguishing different
    // kinds of member pointer.
```

https://github.com/llvm/llvm-project/pull/116991


More information about the cfe-commits mailing list