blob: 6e7e314bf7e274891e118622ec62d66b33d7dc8f [file] [log] [blame]
Stephen Hines2d1fdb22014-05-28 23:58:16 -07001// RUN: %clangxx -fsanitize=function %s -O3 -g -o %t
2// RUN: %run %t 2>&1 | FileCheck %s
Stephen Hines6d186232014-11-26 17:56:19 -08003// Verify that we can disable symbolization if needed:
Pirama Arumuga Nainar799172d2016-03-03 15:50:30 -08004// RUN: %env_ubsan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM
Stephen Hines6d186232014-11-26 17:56:19 -08005
6// -fsanitize=function is unsupported on Darwin yet.
7// XFAIL: darwin
Stephen Hines2d1fdb22014-05-28 23:58:16 -07008
9#include <stdint.h>
10
11void f() {}
12
13void g(int x) {}
14
Stephen Hines86277eb2015-03-23 12:06:32 -070015void make_valid_call() {
Stephen Hines2d1fdb22014-05-28 23:58:16 -070016 // CHECK-NOT: runtime error: call to function g
17 reinterpret_cast<void (*)(int)>(reinterpret_cast<uintptr_t>(g))(42);
18}
Stephen Hines86277eb2015-03-23 12:06:32 -070019
20void make_invalid_call() {
21 // CHECK: function.cpp:25:3: runtime error: call to function f() through pointer to incorrect function type 'void (*)(int)'
22 // CHECK-NEXT: function.cpp:11: note: f() defined here
23 // NOSYM: function.cpp:25:3: runtime error: call to function (unknown) through pointer to incorrect function type 'void (*)(int)'
24 // NOSYM-NEXT: ({{.*}}+0x{{.*}}): note: (unknown) defined here
25 reinterpret_cast<void (*)(int)>(reinterpret_cast<uintptr_t>(f))(42);
26}
27
28int main(void) {
29 make_valid_call();
30 make_invalid_call();
31 // Check that no more errors will be printed.
32 // CHECK-NOT: runtime error: call to function
33 // NOSYM-NOT: runtime error: call to function
34 make_invalid_call();
35}