[clang] c4eeef3 - [TBAA] Add test for generating pointer-tbaa for unnamed structs.

Florian Hahn via cfe-commits cfe-commits at lists.llvm.org
Sun Nov 17 12:04:55 PST 2024


Author: Florian Hahn
Date: 2024-11-17T20:04:36Z
New Revision: c4eeef32d5dc8ec7560edabf18ac29416a7551e5

URL: https://github.com/llvm/llvm-project/commit/c4eeef32d5dc8ec7560edabf18ac29416a7551e5
DIFF: https://github.com/llvm/llvm-project/commit/c4eeef32d5dc8ec7560edabf18ac29416a7551e5.diff

LOG: [TBAA] Add test for generating pointer-tbaa for unnamed structs.

Currently we generate incorrect metadata not considering compatible
types in C.

Added: 
    

Modified: 
    clang/test/CodeGen/tbaa-pointers.c

Removed: 
    


################################################################################
diff  --git a/clang/test/CodeGen/tbaa-pointers.c b/clang/test/CodeGen/tbaa-pointers.c
index f33281ada9903f..cf6061486b6ee4 100644
--- a/clang/test/CodeGen/tbaa-pointers.c
+++ b/clang/test/CodeGen/tbaa-pointers.c
@@ -186,6 +186,28 @@ void vla1(int n, int ptr[][n], int idx) {
     ptr[idx][0] = 0;
 }
 
+typedef struct {
+  int i1;
+} TypedefS;
+
+// FIXME: The !tbaa tag for unnamed structs doesn't account for compatible
+// types in C.
+void unamed_struct_typedef(TypedefS *ptr) {
+// COMMON-LABEL: define void @unamed_struct_typedef(
+// COMMON-SAME: ptr noundef %ptr)
+// COMMON-NEXT: entry:
+// COMMON-NEXT:   [[PTR_ADDR:%.+]]  = alloca ptr, align 8
+// DEFAULT-NEXT:  store ptr %ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[ANYPTR]]
+// DEFAULT-NEXT:  [[L0:%.+]] = load ptr, ptr  [[PTR_ADDR]], align 8, !tbaa  [[ANYPTR]]
+// ENABLED-NEXT:  store ptr %ptr, ptr [[PTR_ADDR]], align 8, !tbaa [[P1TYPEDEF:!.+]]
+// ENABLED-NEXT:  [[L0:%.+]] = load ptr, ptr [[PTR_ADDR]], align 8, !tbaa  [[P1TYPEDEF]]
+// COMMON-NEXT:   [[GEP:%.+]]  = getelementptr inbounds nuw %struct.TypedefS, ptr [[L0]], i32 0, i32 0
+// COMMON-NEXT:   store i32 0, ptr [[GEP]], align 4
+// COMMON-NEXT:   ret void
+
+  ptr->i1 = 0;
+}
+
 // ENABLED: [[P2INT_0]] = !{[[P2INT:!.+]], [[P2INT]], i64 0}
 // ENABLED: [[P2INT]] = !{!"p2 int", [[ANY_POINTER:!.+]], i64 0}
 // DEFAULT: [[ANYPTR]] = !{[[ANY_POINTER:!.+]], [[ANY_POINTER]], i64 0}
@@ -217,3 +239,5 @@ void vla1(int n, int ptr[][n], int idx) {
 // DEFAULT: [[S2_TY]]  = !{!"S2", [[ANY_POINTER]], i64 0}
 // COMMON:  [[INT_TAG]] = !{[[INT_TY:!.+]], [[INT_TY]], i64 0}
 // COMMON:  [[INT_TY]] = !{!"int", [[CHAR]], i64 0}
+// ENABLED: [[P1TYPEDEF]] = !{[[P1TYPEDEF_TY:!.+]],  [[P1TYPEDEF_TY]], i64 0}
+// ENABLED: [[P1TYPEDEF_TY]] = !{!"p1 _ZTS8TypedefS", [[ANY_POINTER]], i64 0}


        


More information about the cfe-commits mailing list