ubsan unit tests for -fsanitize=bool and -fsanitize=enum.

llvm-svn: 170109
This commit is contained in:
Richard Smith 2012-12-13 07:12:20 +00:00
parent 1629da95fe
commit 177f80376d
2 changed files with 27 additions and 0 deletions

View File

@ -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;
}

View File

@ -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;
}