blob: 43de1178fe6c5fac1aff19ce545bdd7585f8d43b [file] [log] [blame]
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08001// RUN: %clangxx -o %t1 %s
2// RUN: %t1 2>&1 | FileCheck --check-prefix=NCFI %s
3
4// RUN: %clangxx_cfi -o %t2 %s
5// RUN: %expect_crash %t2 2>&1 | FileCheck --check-prefix=CFI %s
6
7// RUN: %clangxx_cfi_diag -g -o %t3 %s
8// RUN: %t3 2>&1 | FileCheck --check-prefix=CFI-DIAG %s
9
10#include <stdio.h>
11
12void f() {
13}
14
15int main() {
16 // CFI: 1
17 // NCFI: 1
18 fprintf(stderr, "1\n");
19
20 // CFI-DIAG: runtime error: control flow integrity check for type 'void (int)' failed during indirect function call
21 // CFI-DIAG: f() defined here
22 ((void (*)(int))f)(42); // UB here
23
24 // CFI-NOT: 2
25 // NCFI: 2
26 fprintf(stderr, "2\n");
27}