47 lines · cpp
1// RUN: %clangxx -w -fsanitize=bool -fno-sanitize-memory-param-retval %s -o %t2// RUN: %run %t 2>&1 | FileCheck %s3 4// __ubsan_on_report is not defined as weak. Redefining it here isn't supported5// on Windows.6//7// UNSUPPORTED: target={{.*windows.*}}8// Linkage issue9// 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#endif18extern "C" void19__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(&IssueKind, &Message, &Filename, &Line, &Col,29 &Addr);30 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);35 36 (void)Addr;37}38 39int main() {40 char C = 3;41 bool B = *(bool *)&C;42 // CHECK: Issue: invalid-bool-load43 // CHECK-NEXT: Location: {{.*}}monitor.cpp:[[@LINE-2]]:1244 // CHECK-NEXT: Message: Load of value 3, which is not a valid value for type 'bool'45 return 0;46}47