1 // RUN: %clangxx -w -fsanitize=bool %s -o %t 2 // RUN: %run %t 2>&1 | FileCheck %s 3 4 #include <iostream> 5 6 extern "C" { 7 void __ubsan_get_current_report_data(const char **OutIssueKind, 8 const char **OutMessage, 9 const char **OutFilename, 10 unsigned *OutLine, unsigned *OutCol, 11 char **OutMemoryAddr); 12 13 // Override the weak definition of __ubsan_on_report from the runtime, just 14 // for testing purposes. 15 void __ubsan_on_report(void) { 16 const char *IssueKind, *Message, *Filename; 17 unsigned Line, Col; 18 char *Addr; 19 __ubsan_get_current_report_data(&IssueKind, &Message, &Filename, &Line, &Col, 20 &Addr); 21 22 std::cout << "Issue: " << IssueKind << "\n" 23 << "Location: " << Filename << ":" << Line << ":" << Col << "\n" 24 << "Message: " << Message << std::endl; 25 26 (void)Addr; 27 } 28 } 29 30 int main() { 31 char C = 3; 32 bool B = *(bool *)&C; 33 // CHECK: Issue: invalid-bool-load 34 // CHECK-NEXT: Location: {{.*}}monitor.cpp:[[@LINE-2]]:12 35 // CHECK-NEXT: Message: Load of value 3, which is not a valid value for type 'bool' 36 return 0; 37 } 38