[clang] ba3b3e3 - [NFC][CodeGen][CFI] Pre-commit transparent_union tests (#158192)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 12 17:37:54 PDT 2025
Author: Vitaly Buka
Date: 2025-09-13T00:37:50Z
New Revision: ba3b3e3ac812ae30f12f92ee8c4a1c668cd9817e
URL: https://github.com/llvm/llvm-project/commit/ba3b3e3ac812ae30f12f92ee8c4a1c668cd9817e
DIFF: https://github.com/llvm/llvm-project/commit/ba3b3e3ac812ae30f12f92ee8c4a1c668cd9817e.diff
LOG: [NFC][CodeGen][CFI] Pre-commit transparent_union tests (#158192)
For #158193
Added:
Modified:
clang/test/CodeGen/cfi-icall-generalize.c
clang/test/CodeGen/cfi-icall-normalize2.c
clang/test/CodeGen/kcfi-generalize.c
clang/test/CodeGen/kcfi-normalize.c
Removed:
################################################################################
diff --git a/clang/test/CodeGen/cfi-icall-generalize.c b/clang/test/CodeGen/cfi-icall-generalize.c
index 0af17e5760cc6..46d38511ba6b6 100644
--- a/clang/test/CodeGen/cfi-icall-generalize.c
+++ b/clang/test/CodeGen/cfi-icall-generalize.c
@@ -15,5 +15,21 @@ void g(int** (*fp)(const char *, const char **)) {
fp(0, 0);
}
+union Union {
+ char *c;
+ long *n;
+} __attribute__((transparent_union));
+
+// CHECK: define{{.*}} void @uni({{.*}} !type [[TYPE2:![0-9]+]] !type [[TYPE2_GENERALIZED:![0-9]+]]
+void uni(void (*fn)(union Union), union Union arg1) {
+ // UNGENERALIZED: call i1 @llvm.type.test(ptr {{.*}}, metadata !"_ZTSFv5UnionE")
+ // GENERALIZED: call i1 @llvm.type.test(ptr {{.*}}, metadata !"_ZTSFv5UnionE.generalized")
+ fn(arg1);
+}
+
// CHECK: [[TYPE]] = !{i64 0, !"_ZTSFPPiPKcPS2_E"}
// CHECK: [[TYPE_GENERALIZED]] = !{i64 0, !"_ZTSFPvPKvS_E.generalized"}
+
+// CHECK: [[TYPE2]] = !{i64 0, !"_ZTSFvPFv5UnionES_E"}
+// CHECK: [[TYPE2_GENERALIZED]] = !{i64 0, !"_ZTSFvPv5UnionE.generalized"}
+
diff --git a/clang/test/CodeGen/cfi-icall-normalize2.c b/clang/test/CodeGen/cfi-icall-normalize2.c
index 93893065cf903..5e457dc97f0a2 100644
--- a/clang/test/CodeGen/cfi-icall-normalize2.c
+++ b/clang/test/CodeGen/cfi-icall-normalize2.c
@@ -24,6 +24,20 @@ void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
fn(arg1, arg2, arg3);
}
+union Union {
+ char *c;
+ long *n;
+} __attribute__((transparent_union));
+
+void uni(void (*fn)(union Union), union Union arg1) {
+ // CHECK-LABEL: define{{.*}}uni
+ // CHECK-SAME: {{.*}}!type ![[TYPE4:[0-9]+]] !type !{{[0-9]+}}
+ // CHECK: call i1 @llvm.type.test({{i8\*|ptr}} {{%f|%0}}, metadata !"_ZTSFv5UnionE.normalized")
+ fn(arg1);
+}
+
// CHECK: ![[TYPE1]] = !{i64 0, !"_ZTSFvPFvu3i32ES_E.normalized"}
// CHECK: ![[TYPE2]] = !{i64 0, !"_ZTSFvPFvu3i32S_ES_S_E.normalized"}
// CHECK: ![[TYPE3]] = !{i64 0, !"_ZTSFvPFvu3i32S_S_ES_S_S_E.normalized"}
+// CHECK: ![[TYPE4]] = !{i64 0, !"_ZTSFvPFv5UnionES_E.normalized"}
+
diff --git a/clang/test/CodeGen/kcfi-generalize.c b/clang/test/CodeGen/kcfi-generalize.c
index 4e32f4f35057c..864cdb8c2e092 100644
--- a/clang/test/CodeGen/kcfi-generalize.c
+++ b/clang/test/CodeGen/kcfi-generalize.c
@@ -26,8 +26,24 @@ void g(int** (*fp)(const char *, const char **)) {
fp(0, 0);
}
+union Union {
+ char *c;
+ long *n;
+} __attribute__((transparent_union));
+
+// CHECK: define{{.*}} void @uni({{.*}} !kcfi_type [[TYPE4:![0-9]+]]
+void uni(void (*fn)(union Union), union Union arg1) {
+ // UNGENERALIZED: call {{.*}} [ "kcfi"(i32 -1037059548) ]
+ // GENERALIZED: call {{.*}} [ "kcfi"(i32 422130955) ]
+ fn(arg1);
+}
+
// UNGENERALIZED: [[TYPE]] = !{i32 1296635908}
// GENERALIZED: [[TYPE]] = !{i32 -49168686}
// UNGENERALIZED: [[TYPE3]] = !{i32 874141567}
// GENERALIZED: [[TYPE3]] = !{i32 954385378}
+
+// UNGENERALIZED: [[TYPE4]] = !{i32 981319178}
+// GENERALIZED: [[TYPE4]] = !{i32 -1599950473}
+
diff --git a/clang/test/CodeGen/kcfi-normalize.c b/clang/test/CodeGen/kcfi-normalize.c
index b9150e88f6ab5..9291ff8529b31 100644
--- a/clang/test/CodeGen/kcfi-normalize.c
+++ b/clang/test/CodeGen/kcfi-normalize.c
@@ -28,7 +28,21 @@ void baz(void (*fn)(int, int, int), int arg1, int arg2, int arg3) {
fn(arg1, arg2, arg3);
}
+union Union {
+ char *c;
+ long *n;
+} __attribute__((transparent_union));
+
+void uni(void (*fn)(union Union), union Union arg1) {
+ // CHECK-LABEL: define{{.*}}uni
+ // CHECK-SAME: {{.*}}!kcfi_type ![[TYPE4:[0-9]+]]
+ // CHECK: call void %0(ptr %1) [ "kcfi"(i32 -1430221633) ]
+ fn(arg1);
+}
+
// CHECK: ![[#]] = !{i32 4, !"cfi-normalize-integers", i32 1}
// CHECK: ![[TYPE1]] = !{i32 -1143117868}
// CHECK: ![[TYPE2]] = !{i32 -460921415}
// CHECK: ![[TYPE3]] = !{i32 -333839615}
+// CHECK: ![[TYPE4]] = !{i32 1766237188}
+
More information about the cfe-commits
mailing list