| 1 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -emit-llvm -o - %s | FileCheck --check-prefix=CHECK --check-prefix=UNGENERALIZED %s |
| 2 |
// RUN: %clang_cc1 -triple x86_64-unknown-linux -fsanitize=cfi-icall -fsanitize-trap=cfi-icall -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({{.*}} !type [[TYPE:![0-9]+]] !type [[TYPE_GENERALIZED:![0-9]+]] |
| 8 |
int** f(const char *a, const char **b) { |
| 9 |
return (int**)0; |
| 10 |
} |
| 11 |
|
| 12 |
void g(int** (*fp)(const char *, const char **)) { |
| 13 |
// UNGENERALIZED: call i1 @llvm.type.test(ptr {{.*}}, metadata !"_ZTSFPPiPKcPS2_E") |
| 14 |
// GENERALIZED: call i1 @llvm.type.test(ptr {{.*}}, metadata !"_ZTSFPvPKvS_E.generalized") |
| 15 |
fp(0, 0); |
| 16 |
} |
| 17 |
|
| 18 |
union Union { |
| 19 |
char *c; |
| 20 |
long *n; |
| 21 |
} __attribute__((transparent_union)); |
| 22 |
|
| 23 |
// CHECK: define{{.*}} void @uni({{.*}} !type [[TYPE2:![0-9]+]] !type [[TYPE2_GENERALIZED:![0-9]+]] |
| 24 |
void uni(void (*fn)(union Union), union Union arg1) { |
| 25 |
// UNGENERALIZED: call i1 @llvm.type.test(ptr {{.*}}, metadata !"_ZTSFvPcE") |
| 26 |
// GENERALIZED: call i1 @llvm.type.test(ptr {{.*}}, metadata !"_ZTSFvPvE.generalized") |
| 27 |
fn(arg1); |
| 28 |
} |
| 29 |
|
| 30 |
// CHECK: [[TYPE]] = !{i64 0, !"_ZTSFPPiPKcPS2_E"} |
| 31 |
// CHECK: [[TYPE_GENERALIZED]] = !{i64 0, !"_ZTSFPvPKvS_E.generalized"} |
| 32 |
|
| 33 |
// CHECK: [[TYPE2]] = !{i64 0, !"_ZTSFvPFv5UnionEPcE"} |
| 34 |
// CHECK: [[TYPE2_GENERALIZED]] = !{i64 0, !"_ZTSFvPvS_E.generalized"} |
| 35 |
|