• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
__ubsan_on_report(void)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 
33   (void)Addr;
34 }
35 }
36 
main()37 int main() {
38   char C = 3;
39   bool B = *(bool *)&C;
40   // CHECK: Issue: invalid-bool-load
41   // CHECK-NEXT: Location: {{.*}}monitor.cpp:[[@LINE-2]]:12
42   // CHECK-NEXT: Message: Load of value 3, which is not a valid value for type 'bool'
43   return 0;
44 }
45