blob: 183e62738bb26b6f961bcd2d8a402a08e49857f9 [file] [log] [blame]
Alexey Samsonov41172a32016-02-24 00:16:57 +00001// RUN: %clang -o %t1 %s
Peter Collingbourne1db3a4482015-09-10 02:18:02 +00002// RUN: %t1 2>&1 | FileCheck --check-prefix=NCFI %s
3
Alexey Samsonov41172a32016-02-24 00:16:57 +00004// RUN: %clang_cfi -o %t2 %s
Peter Collingbourne1db3a4482015-09-10 02:18:02 +00005// RUN: %expect_crash %t2 2>&1 | FileCheck --check-prefix=CFI %s
6
Alexey Samsonov41172a32016-02-24 00:16:57 +00007// RUN: %clang_cfi_diag -g -o %t3 %s
Peter Collingbourne1db3a4482015-09-10 02:18:02 +00008// 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
Alexey Samsonov41172a32016-02-24 00:16:57 +000021 // CFI-DIAG: f defined here
Peter Collingbourne1db3a4482015-09-10 02:18:02 +000022 ((void (*)(int))f)(42); // UB here
23
24 // CFI-NOT: 2
25 // NCFI: 2
26 fprintf(stderr, "2\n");
27}