-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[NFC][CodeGen][CFI] Pre-commit transparent_union tests #158192
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFC][CodeGen][CFI] Pre-commit transparent_union tests #158192
Conversation
Created using spr 1.3.6 [skip ci]
Created using spr 1.3.6
|
@llvm/pr-subscribers-clang Author: Vitaly Buka (vitalybuka) ChangesFull diff: https://github.com/llvm/llvm-project/pull/158192.diff 4 Files Affected:
diff --git a/clang/test/CodeGen/cfi-icall-generalize.c b/clang/test/CodeGen/cfi-icall-generalize.c
index 0af17e5760cc6..116a99e4e2859 100644
--- a/clang/test/CodeGen/cfi-icall-generalize.c
+++ b/clang/test/CodeGen/cfi-icall-generalize.c
@@ -15,5 +15,20 @@ 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..c88ecc9f0c3f7 100644
--- a/clang/test/CodeGen/cfi-icall-normalize2.c
+++ b/clang/test/CodeGen/cfi-icall-normalize2.c
@@ -24,6 +24,19 @@ 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..89b298f3e2faa 100644
--- a/clang/test/CodeGen/kcfi-generalize.c
+++ b/clang/test/CodeGen/kcfi-generalize.c
@@ -26,8 +26,23 @@ 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 [[TYPE2:![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: [[TYPE2]] = !{i32 981319178}
+// GENERALIZED: [[TYPE2]] = !{i32 -1599950473}
\ No newline at end of file
diff --git a/clang/test/CodeGen/kcfi-normalize.c b/clang/test/CodeGen/kcfi-normalize.c
index b9150e88f6ab5..cde784962d11a 100644
--- a/clang/test/CodeGen/kcfi-normalize.c
+++ b/clang/test/CodeGen/kcfi-normalize.c
@@ -28,7 +28,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: {{.*}}!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}
\ No newline at end of file
|
Created using spr 1.3.6 [skip ci]
Created using spr 1.3.6 [skip ci]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This pull request adds pre-commit tests for transparent_union support in CFI (Control Flow Integrity) and KCFI (Kernel Control Flow Integrity) functionality. The changes prepare test coverage for upcoming transparent_union implementation referenced in issue #158193.
- Adds test cases for transparent_union attribute handling in CFI/KCFI code generation
- Introduces union definitions with transparent_union attribute across multiple test files
- Includes expected CHECK patterns for both generalized and ungeneralized pointer scenarios
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| clang/test/CodeGen/kcfi-normalize.c | Adds transparent_union test case for KCFI normalization with expected metadata |
| clang/test/CodeGen/kcfi-generalize.c | Adds transparent_union test case for KCFI pointer generalization scenarios |
| clang/test/CodeGen/cfi-icall-normalize2.c | Adds transparent_union test case for CFI icall normalization |
| clang/test/CodeGen/cfi-icall-generalize.c | Adds transparent_union test case for CFI icall pointer generalization |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated no new comments.
Created using spr 1.3.6 [skip ci]
For #158193