Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / compiler-rt / test / ubsan / TestCases / Misc / monitor.cpp
blobd3de725773d9c55149695c5a19cba3567dd10de9
1 // RUN: %clangxx -w -fsanitize=bool -fno-sanitize-memory-param-retval %s -o %t
2 // RUN: %run %t 2>&1 | FileCheck %s
4 // __ubsan_on_report is not defined as weak. Redefining it here isn't supported
5 // on Windows.
6 //
7 // UNSUPPORTED: target={{.*windows.*}}
8 // Linkage issue
9 // XFAIL: target={{.*openbsd.*}}
11 #include <cstdio>
13 // Override __ubsan_on_report() from the runtime, just for testing purposes.
14 // Required for dyld macOS 12.0+
15 #if (__APPLE__)
16 __attribute__((weak))
17 #endif
18 extern "C" void
19 __ubsan_on_report(void) {
20 void __ubsan_get_current_report_data(
21 const char **OutIssueKind, const char **OutMessage,
22 const char **OutFilename, unsigned *OutLine, unsigned *OutCol,
23 char **OutMemoryAddr);
24 const char *IssueKind, *Message, *Filename;
25 unsigned Line, Col;
26 char *Addr;
28 __ubsan_get_current_report_data(&IssueKind, &Message, &Filename, &Line, &Col,
29 &Addr);
31 printf("Issue: %s\n", IssueKind);
32 printf("Location: %s:%u:%u\n", Filename, Line, Col);
33 printf("Message: %s\n", Message);
34 fflush(stdout);
36 (void)Addr;
39 int main() {
40 char C = 3;
41 bool B = *(bool *)&C;
42 // CHECK: Issue: invalid-bool-load
43 // CHECK-NEXT: Location: {{.*}}monitor.cpp:[[@LINE-2]]:12
44 // CHECK-NEXT: Message: Load of value 3, which is not a valid value for type 'bool'
45 return 0;