aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2018-06-22 17:21:17 +0000
committerVedant Kumar <vsk@apple.com>2018-06-22 17:21:17 +0000
commit6e647114ea9f022304be52f65da779d4e3bce821 (patch)
tree72bda6b96a199c0d447085a2f871e2f49e1b73e1 /test
parent324947c49535971c87846c5f6b833be2a96d1812 (diff)
[ubsan] Add support for reporting diagnostics to a monitor process
Add support to the ubsan runtime for reporting diagnostics to a monitor process (e.g a debugger). The Xcode IDE uses this by setting a breakpoint on __ubsan_on_report and collecting diagnostic information via __ubsan_get_current_report_data, which it then surfaces to users in the editor UI. Testing for this functionality already exists in upstream lldb, here: lldb/packages/Python/lldbsuite/test/functionalities/ubsan Apart from that, this is `ninja check-{a,ub}san` clean. Differential Revision: https://reviews.llvm.org/D48446 git-svn-id: https://llvm.org/svn/llvm-project/compiler-rt/trunk@335371 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test')
-rw-r--r--test/ubsan/TestCases/Misc/monitor.cpp37
1 files changed, 37 insertions, 0 deletions
diff --git a/test/ubsan/TestCases/Misc/monitor.cpp b/test/ubsan/TestCases/Misc/monitor.cpp
new file mode 100644
index 000000000..78187019c
--- /dev/null
+++ b/test/ubsan/TestCases/Misc/monitor.cpp
@@ -0,0 +1,37 @@
+// RUN: %clangxx -w -fsanitize=bool %s -o %t
+// RUN: %run %t 2>&1 | FileCheck %s
+
+#include <iostream>
+
+extern "C" {
+void __ubsan_get_current_report_data(const char **OutIssueKind,
+ const char **OutMessage,
+ const char **OutFilename,
+ unsigned *OutLine, unsigned *OutCol,
+ char **OutMemoryAddr);
+
+// Override the weak definition of __ubsan_on_report from the runtime, just
+// for testing purposes.
+void __ubsan_on_report(void) {
+ const char *IssueKind, *Message, *Filename;
+ unsigned Line, Col;
+ char *Addr;
+ __ubsan_get_current_report_data(&IssueKind, &Message, &Filename, &Line, &Col,
+ &Addr);
+
+ std::cout << "Issue: " << IssueKind << "\n"
+ << "Location: " << Filename << ":" << Line << ":" << Col << "\n"
+ << "Message: " << Message << std::endl;
+
+ (void)Addr;
+}
+}
+
+int main() {
+ char C = 3;
+ bool B = *(bool *)&C;
+ // CHECK: Issue: invalid-bool-load
+ // CHECK-NEXT: Location: {{.*}}monitor.cpp:[[@LINE-2]]:12
+ // CHECK-NEXT: Message: Load of value 3, which is not a valid value for type 'bool'
+ return 0;
+}