Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 1 | // RUN: %clangxx -fsanitize=function %s -O3 -g -o %t |
| 2 | // RUN: %run %t 2>&1 | FileCheck %s |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 3 | // Verify that we can disable symbolization if needed: |
Pirama Arumuga Nainar | 799172d | 2016-03-03 15:50:30 -0800 | [diff] [blame^] | 4 | // RUN: %env_ubsan_opts=symbolize=0 %run %t 2>&1 | FileCheck %s --check-prefix=NOSYM |
Stephen Hines | 6d18623 | 2014-11-26 17:56:19 -0800 | [diff] [blame] | 5 | |
| 6 | // -fsanitize=function is unsupported on Darwin yet. |
| 7 | // XFAIL: darwin |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 8 | |
| 9 | #include <stdint.h> |
| 10 | |
| 11 | void f() {} |
| 12 | |
| 13 | void g(int x) {} |
| 14 | |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 15 | void make_valid_call() { |
Stephen Hines | 2d1fdb2 | 2014-05-28 23:58:16 -0700 | [diff] [blame] | 16 | // CHECK-NOT: runtime error: call to function g |
| 17 | reinterpret_cast<void (*)(int)>(reinterpret_cast<uintptr_t>(g))(42); |
| 18 | } |
Stephen Hines | 86277eb | 2015-03-23 12:06:32 -0700 | [diff] [blame] | 19 | |
| 20 | void 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 | |
| 28 | int 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 | } |