| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=kcfi -fsanitize-trap=kcfi -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=UNGENERALIZED %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=kcfi -fsanitize-trap=kcfi -fsanitize-cfi-icall-generalize-pointers -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=GENERALIZED %s |
| 3 |
|
| 4 |
// Test that const char* is generalized to const ptr and that char** is |
| 5 |
// generalized to ptr |
| 6 |
|
| 7 |
// CHECK: define{{.*}} ptr @f({{.*}} !kcfi_type [[TYPE:![0-9]+]] |
| 8 |
int** f(const char *a, const char **b) { |
| 9 |
return (int**)0; |
| 10 |
} |
| 11 |
|
| 12 |
// GENERALIZED: define{{.*}} ptr @f2({{.*}} !kcfi_type [[TYPE]] |
| 13 |
// UNGENERALIZED: define{{.*}} ptr @f2({{.*}} !kcfi_type [[TYPE2:![0-9]+]] |
| 14 |
int** f2(const int *a, const int **b) { |
| 15 |
return (int**)0; |
| 16 |
} |
| 17 |
|
| 18 |
// CHECK: define{{.*}} ptr @f3({{.*}} !kcfi_type [[TYPE3:![0-9]+]] |
| 19 |
int** f3(char *a, char **b) { |
| 20 |
return (int**)0; |
| 21 |
} |
| 22 |
|
| 23 |
void g(int** (*fp)(const char *, const char **)) { |
| 24 |
// UNGENERALIZED: call {{.*}} [ "kcfi"(i32 1296635908) ] |
| 25 |
// GENERALIZED: call {{.*}} [ "kcfi"(i32 -49168686) ] |
| 26 |
fp(0, 0); |
| 27 |
} |
| 28 |
|
| 29 |
union Union { |
| 30 |
char *c; |
| 31 |
long *n; |
| 32 |
} __attribute__((transparent_union)); |
| 33 |
|
| 34 |
// CHECK: define{{.*}} void @uni({{.*}} !kcfi_type [[TYPE4:![0-9]+]] |
| 35 |
void uni(void (*fn)(union Union), union Union arg1) { |
| 36 |
// UNGENERALIZED: call {{.*}} [ "kcfi"(i32 -587217045) ] |
| 37 |
// GENERALIZED: call {{.*}} [ "kcfi"(i32 2139530422) ] |
| 38 |
fn(arg1); |
| 39 |
} |
| 40 |
|
| 41 |
// UNGENERALIZED: [[TYPE]] = !{i32 1296635908} |
| 42 |
// GENERALIZED: [[TYPE]] = !{i32 -49168686} |
| 43 |
|
| 44 |
// UNGENERALIZED: [[TYPE3]] = !{i32 874141567} |
| 45 |
// GENERALIZED: [[TYPE3]] = !{i32 954385378} |
| 46 |
|
| 47 |
// UNGENERALIZED: [[TYPE4]] = !{i32 -1619636625} |
| 48 |
// GENERALIZED: [[TYPE4]] = !{i32 -125078496} |