1 // RUN: %clangxx -w -fsanitize=bool %s -o %t 2 // RUN: %run %t 2>&1 | FileCheck %s 3 4 // __ubsan_on_report is not defined as weak. Redefining it here isn't supported 5 // on Windows. 6 // 7 // UNSUPPORTED: windows-msvc 8 // Linkage issue 9 // XFAIL: openbsd 10 11 #include <cstdio> 12 13 extern "C" { 14 void __ubsan_get_current_report_data(const char **OutIssueKind, 15 const char **OutMessage, 16 const char **OutFilename, 17 unsigned *OutLine, unsigned *OutCol, 18 char **OutMemoryAddr); 19 20 // Override the definition of __ubsan_on_report from the runtime, just for 21 // testing purposes. 22 void __ubsan_on_report(void) { 23 const char *IssueKind, *Message, *Filename; 24 unsigned Line, Col; 25 char *Addr; 26 __ubsan_get_current_report_data(&IssueKind, &Message, &Filename, &Line, &Col, 27 &Addr); 28 29 printf("Issue: %s\n", IssueKind); 30 printf("Location: %s:%u:%u\n", Filename, Line, Col); 31 printf("Message: %s\n", Message); 32 fflush(stdout); 33 34 (void)Addr; 35 } 36 } 37 38 int main() { 39 char C = 3; 40 bool B = *(bool *)&C; 41 // CHECK: Issue: invalid-bool-load 42 // CHECK-NEXT: Location: {{.*}}monitor.cpp:[[@LINE-2]]:12 43 // CHECK-NEXT: Message: Load of value 3, which is not a valid value for type 'bool' 44 return 0; 45 } 46