1// RUN: %clangxx -w -fsanitize=bool -fno-sanitize-memory-param-retval %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: target={{.*windows.*}}
8// Linkage issue
9// XFAIL: target={{.*openbsd.*}}
10
11#include <cstdio>
12
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
18extern "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;
27
28 __ubsan_get_current_report_data(OutIssueKind: &IssueKind, OutMessage: &Message, OutFilename: &Filename, OutLine: &Line, OutCol: &Col,
29 OutMemoryAddr: &Addr);
30
31 printf(format: "Issue: %s\n", IssueKind);
32 printf(format: "Location: %s:%u:%u\n", Filename, Line, Col);
33 printf(format: "Message: %s\n", Message);
34 fflush(stdout);
35
36 (void)Addr;
37}
38
39int 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;
46}
47

source code of compiler-rt/test/ubsan/TestCases/Misc/monitor.cpp