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

John McCall via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 21 09:52:01 PST 2024


================
@@ -18,10 +20,23 @@ struct A {};
 
 // CHECK-LABEL: define {{.*}} @_Z1g
 const int *(A::*const *g(const int *(A::* const **p)[3], int *(A::***q)[3]))[3] {
+  // CHECK: load ptr, ptr %p.addr
   // CHECK: load ptr, {{.*}}, !tbaa ![[MEMPTR_TBAA:[^,]*]]
   const int *(A::*const *x)[3] = *p;
   // CHECK: store ptr null, {{.*}}, !tbaa ![[MEMPTR_TBAA]]
   *q = 0;
   return x;
 }
 
+// CHECK-LABEL: define {{.*}} @_Z1h
+const int * h(const int * (*p)[10],  int *(*q)[9]) {
+  // CHECK:  load ptr, ptr %p.addr, align 8, !tbaa [[PTRARRAY_TBAA:!.+]]
+  const int * x = *p[0];
+
+  // CHECK: load ptr, ptr %q.addr, align 8, !tbaa [[PTRARRAY_TBAA]]
+  *q[0] = 0;
+  return x;
+}
+
+// POINTER-TBAA: [[PTRARRAY_TBAA]] = !{[[PTRARRAY_TY:!.+]], [[PTRARRAY_TY]], i64 0}
+// POINTER-TBAA: [[PTRARRAY_TY]] = !{!"p3 int", !4, i64 0}
----------------
rjmccall wrote:

Hmm. Why is this `p3`?  I'd expect it to be `p2 int`: the l-value is of type `int *(*)[]`, and we're ignoring all the array structure, so this should have the same tag as `int **`, i.e. `p2 int`, right?

Also, I assume the `!4` is brittle.  That's `AnyPtr`?

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


More information about the cfe-commits mailing list