summaryrefslogtreecommitdiffstats
path: root/test/CodeGenObjC
diff options
context:
space:
mode:
authorVedant Kumar <vsk@apple.com>2016-12-09 23:48:18 +0000
committerVedant Kumar <vsk@apple.com>2016-12-09 23:48:18 +0000
commit68e5066ffd1635a19d3f35daad07d686334bbaec (patch)
treef2efab5a4c31912504c72a156f1a98d4a5390a60 /test/CodeGenObjC
parent6131c670da5b1719255dd010d53086349804f8ec (diff)
[ubsan] Treat ObjC's BOOL as if its range is always {0, 1}
On some Apple platforms, the ObjC BOOL type is defined as a signed char. When performing instrumentation for -fsanitize=bool, we'd like to treat the range of BOOL like it's always {0, 1}. While we can't change clang's IRGen for char-backed BOOL's due to ABI compatibility concerns, we can teach ubsan to catch potential abuses of this type. rdar://problem/29502773 Differential Revision: https://reviews.llvm.org/D27607 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@289290 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenObjC')
-rw-r--r--test/CodeGenObjC/ubsan-bool.m13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/CodeGenObjC/ubsan-bool.m b/test/CodeGenObjC/ubsan-bool.m
new file mode 100644
index 0000000000..6d6c08358d
--- /dev/null
+++ b/test/CodeGenObjC/ubsan-bool.m
@@ -0,0 +1,13 @@
+// RUN: %clang_cc1 -x objective-c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=bool %s -o - | FileCheck %s -check-prefixes=SHARED,OBJC
+// RUN: %clang_cc1 -x objective-c++ -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=bool %s -o - | FileCheck %s -check-prefixes=SHARED,OBJC
+// RUN: %clang_cc1 -x c -emit-llvm -triple x86_64-apple-macosx10.10.0 -fsanitize=bool %s -o - | FileCheck %s -check-prefixes=SHARED,C
+
+typedef signed char BOOL;
+
+// SHARED-LABEL: f1
+BOOL f1() {
+ // OBJC: call void @__ubsan_handle_load_invalid_value
+ // C-NOT: call void @__ubsan_handle_load_invalid_value
+ BOOL a = 2;
+ return a + 1;
+}