diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-13 07:11:50 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2012-12-13 07:11:50 +0000 |
commit | 463b48ba7eab6d7c96d23b59caea7f25de548293 (patch) | |
tree | 6b55f8068dd1c79805b0ecfcaadec1b26c8c0946 /test/CodeGenCXX/catch-undef-behavior.cpp | |
parent | cdc2e82c317163693c99a8cbef76685e86420395 (diff) |
ubsan: Add -fsanitize=bool and -fsanitize=enum, which check for loads of
bit-patterns which are not valid values for enumerated or boolean types.
These checks are the ubsan analogue of !range metadata.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@170108 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'test/CodeGenCXX/catch-undef-behavior.cpp')
-rw-r--r-- | test/CodeGenCXX/catch-undef-behavior.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/test/CodeGenCXX/catch-undef-behavior.cpp b/test/CodeGenCXX/catch-undef-behavior.cpp index 86a306daf5..a4e13bfa26 100644 --- a/test/CodeGenCXX/catch-undef-behavior.cpp +++ b/test/CodeGenCXX/catch-undef-behavior.cpp @@ -1,4 +1,4 @@ -// RUN: %clang_cc1 -fsanitize=signed-integer-overflow,integer-divide-by-zero,float-divide-by-zero,shift,unreachable,return,vla-bound,alignment,null,vptr,object-size,float-cast-overflow -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s +// RUN: %clang_cc1 -fsanitize=signed-integer-overflow,integer-divide-by-zero,float-divide-by-zero,shift,unreachable,return,vla-bound,alignment,null,vptr,object-size,float-cast-overflow,bool,enum -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s // CHECK: @_Z17reference_binding void reference_binding(int *p) { @@ -136,3 +136,36 @@ int no_return() { // CHECK: call void @__ubsan_handle_missing_return(i8* bitcast ({{.*}}* @{{.*}} to i8*)) noreturn nounwind // CHECK-NEXT: unreachable } + +// CHECK: @_Z9sour_bool +bool sour_bool(bool *p) { + // CHECK: %[[OK:.*]] = icmp ule i8 {{.*}}, 1 + // CHECK: br i1 %[[OK]] + // CHECK: call void @__ubsan_handle_load_invalid_value_abort(i8* bitcast ({{.*}}), i64 {{.*}}) + return *p; +} + +enum E1 { e1a = 0, e1b = 127 } e1; +enum E2 { e2a = -1, e2b = 64 } e2; +enum E3 { e3a = (1u << 31) - 1 } e3; + +// CHECK: @_Z14bad_enum_value +int bad_enum_value() { + // CHECK: %[[E1:.*]] = icmp ule i32 {{.*}}, 127 + // CHECK: br i1 %[[E1]] + // CHECK: call void @__ubsan_handle_load_invalid_value_abort( + int a = e1; + + // CHECK: %[[E2HI:.*]] = icmp sle i32 {{.*}}, 127 + // CHECK: %[[E2LO:.*]] = icmp sge i32 {{.*}}, -128 + // CHECK: %[[E2:.*]] = and i1 %[[E2HI]], %[[E2LO]] + // CHECK: br i1 %[[E2]] + // CHECK: call void @__ubsan_handle_load_invalid_value_abort( + int b = e2; + + // CHECK: %[[E3:.*]] = icmp ule i32 {{.*}}, 2147483647 + // CHECK: br i1 %[[E3]] + // CHECK: call void @__ubsan_handle_load_invalid_value_abort( + int c = e3; + return a + b + c; +} |