summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRichard Smith <richard-llvm@metafoo.co.uk>2012-12-13 07:12:20 +0000
committerRichard Smith <richard-llvm@metafoo.co.uk>2012-12-13 07:12:20 +0000
commit177f80376dc12a263372d5e5e526af2a8249ea2a (patch)
treed987f10563d9cbc880ce874e008813e8c73c6293
parent1629da95fe78ae4cf8b66496aaddbe06bbbe2a90 (diff)
downloadbcm5719-llvm-177f80376dc12a263372d5e5e526af2a8249ea2a.tar.gz
bcm5719-llvm-177f80376dc12a263372d5e5e526af2a8249ea2a.zip
ubsan unit tests for -fsanitize=bool and -fsanitize=enum.
llvm-svn: 170109
-rw-r--r--compiler-rt/lib/ubsan/lit_tests/Misc/bool.cpp10
-rw-r--r--compiler-rt/lib/ubsan/lit_tests/Misc/enum.cpp17
2 files changed, 27 insertions, 0 deletions
diff --git a/compiler-rt/lib/ubsan/lit_tests/Misc/bool.cpp b/compiler-rt/lib/ubsan/lit_tests/Misc/bool.cpp
new file mode 100644
index 00000000000..4df1fb82a5d
--- /dev/null
+++ b/compiler-rt/lib/ubsan/lit_tests/Misc/bool.cpp
@@ -0,0 +1,10 @@
+// RUN: %clang -fsanitize=bool %s -O3 -o %t && %t 2>&1 | FileCheck %s
+
+unsigned char NotABool = 123;
+
+int main(int argc, char **argv) {
+ bool *p = (bool*)&NotABool;
+
+ // CHECK: error: load of value 123, which is not a valid value for type 'bool'
+ return *p;
+}
diff --git a/compiler-rt/lib/ubsan/lit_tests/Misc/enum.cpp b/compiler-rt/lib/ubsan/lit_tests/Misc/enum.cpp
new file mode 100644
index 00000000000..b363fea3487
--- /dev/null
+++ b/compiler-rt/lib/ubsan/lit_tests/Misc/enum.cpp
@@ -0,0 +1,17 @@
+// RUN: %clang -fsanitize=enum %s -O3 -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-PLAIN
+// RUN: %clang -fsanitize=enum -std=c++11 -DE="class E" %s -O3 -o %t && %t
+// RUN: %clang -fsanitize=enum -std=c++11 -DE="class E : bool" %s -O3 -o %t && %t 2>&1 | FileCheck %s --check-prefix=CHECK-BOOL
+
+enum E { a = 1 } e;
+#undef E
+
+int main(int argc, char **argv) {
+ // memset(&e, 0xff, sizeof(e));
+ for (unsigned char *p = (unsigned char*)&e; p != (unsigned char*)(&e + 1); ++p)
+ *p = 0xff;
+
+ // CHECK-PLAIN: error: load of value 4294967295, which is not a valid value for type 'enum E'
+ // FIXME: Support marshalling and display of enum class values.
+ // CHECK-BOOL: error: load of value <unknown>, which is not a valid value for type 'enum E'
+ return (int)e != -1;
+}
OpenPOWER on IntegriCloud