[llvm-commits] [compiler-rt] r170109 - in /compiler-rt/trunk/lib/ubsan/lit_tests/Misc: bool.cpp enum.cpp
Richard Smith
richard-llvm at metafoo.co.uk
Wed Dec 12 23:12:20 PST 2012
Author: rsmith
Date: Thu Dec 13 01:12:20 2012
New Revision: 170109
URL: http://llvm.org/viewvc/llvm-project?rev=170109&view=rev
Log:
ubsan unit tests for -fsanitize=bool and -fsanitize=enum.
Added:
compiler-rt/trunk/lib/ubsan/lit_tests/Misc/bool.cpp
compiler-rt/trunk/lib/ubsan/lit_tests/Misc/enum.cpp
Added: compiler-rt/trunk/lib/ubsan/lit_tests/Misc/bool.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/lit_tests/Misc/bool.cpp?rev=170109&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/lit_tests/Misc/bool.cpp (added)
+++ compiler-rt/trunk/lib/ubsan/lit_tests/Misc/bool.cpp Thu Dec 13 01:12:20 2012
@@ -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;
+}
Added: compiler-rt/trunk/lib/ubsan/lit_tests/Misc/enum.cpp
URL: http://llvm.org/viewvc/llvm-project/compiler-rt/trunk/lib/ubsan/lit_tests/Misc/enum.cpp?rev=170109&view=auto
==============================================================================
--- compiler-rt/trunk/lib/ubsan/lit_tests/Misc/enum.cpp (added)
+++ compiler-rt/trunk/lib/ubsan/lit_tests/Misc/enum.cpp Thu Dec 13 01:12:20 2012
@@ -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;
+}
More information about the llvm-commits
mailing list