| 1 | // Test that the checking is done with the actual type of f() even when the |
| 2 | // calling module has an incorrect declaration. Test a mix of lto types. |
| 3 | // |
| 4 | // -flto below overrides -flto=thin in %clang_cfi |
| 5 | // RUN: %clang_cfi %s -DMODULE_A -c -o %t1_a.o |
| 6 | // RUN: %clang_cfi %s -DMODULE_B -c -o %t1_b.o -flto |
| 7 | // RUN: %clang_cfi %t1_a.o %t1_b.o -o %t1 |
| 8 | // RUN: %expect_crash %t1 2>&1 | FileCheck --check-prefix=CFI %s |
| 9 | // |
| 10 | // RUN: %clang_cfi %s -DMODULE_A -c -o %t2_a.o -flto |
| 11 | // RUN: %clang_cfi %s -DMODULE_B -c -o %t2_b.o |
| 12 | // RUN: %clang_cfi %t2_a.o %t2_b.o -o %t2 |
| 13 | // RUN: %expect_crash %t2 2>&1 | FileCheck --check-prefix=CFI %s |
| 14 | // |
| 15 | // RUN: %clang_cfi %s -DMODULE_A -c -o %t3_a.o |
| 16 | // RUN: %clang_cfi %s -DMODULE_B -c -o %t3_b.o |
| 17 | // RUN: %clang_cfi %t3_a.o %t3_b.o -o %t3 |
| 18 | // RUN: %expect_crash %t3 2>&1 | FileCheck --check-prefix=CFI %s |
| 19 | // |
| 20 | // REQUIRES: thinlto |
| 21 | |
| 22 | #include <stdio.h> |
| 23 | |
| 24 | #if defined(MODULE_B) |
| 25 | int f() { |
| 26 | return 42; |
| 27 | } |
| 28 | #elif defined(MODULE_A) |
| 29 | void f(); |
| 30 | |
| 31 | int main() { |
| 32 | // CFI: 1 |
| 33 | fprintf(stderr, "1\n" ); |
| 34 | |
| 35 | void (*volatile p)() = &f; |
| 36 | p(); |
| 37 | |
| 38 | // CFI-NOT: 2 |
| 39 | fprintf(stderr, "2\n" ); |
| 40 | } |
| 41 | #endif |
| 42 | |