42 lines · c
1// Test that the checking is done with the actual type of f() even when the2// calling module has an incorrect declaration. Test a mix of lto types.3//4// -flto below overrides -flto=thin in %clang_cfi5// RUN: %clang_cfi %s -DMODULE_A -c -o %t1_a.o6// RUN: %clang_cfi %s -DMODULE_B -c -o %t1_b.o -flto7// RUN: %clang_cfi %t1_a.o %t1_b.o -o %t18// RUN: %expect_crash %t1 2>&1 | FileCheck --check-prefix=CFI %s9//10// RUN: %clang_cfi %s -DMODULE_A -c -o %t2_a.o -flto11// RUN: %clang_cfi %s -DMODULE_B -c -o %t2_b.o12// RUN: %clang_cfi %t2_a.o %t2_b.o -o %t213// RUN: %expect_crash %t2 2>&1 | FileCheck --check-prefix=CFI %s14//15// RUN: %clang_cfi %s -DMODULE_A -c -o %t3_a.o16// RUN: %clang_cfi %s -DMODULE_B -c -o %t3_b.o17// RUN: %clang_cfi %t3_a.o %t3_b.o -o %t318// RUN: %expect_crash %t3 2>&1 | FileCheck --check-prefix=CFI %s19//20// REQUIRES: thinlto21 22#include <stdio.h>23 24#if defined(MODULE_B)25int f() {26 return 42;27}28#elif defined(MODULE_A)29void f();30 31int main() {32 // CFI: 133 fprintf(stderr, "1\n");34 35 void (*volatile p)() = &f;36 p();37 38 // CFI-NOT: 239 fprintf(stderr, "2\n");40}41#endif42