diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/CodeGenCXX/catch-undef-behavior.cpp | 91 | ||||
-rw-r--r-- | test/Driver/darwin-sanitizer-ld.c | 6 | ||||
-rw-r--r-- | test/Driver/ubsan-ld.c | 8 |
3 files changed, 94 insertions, 11 deletions
diff --git a/test/CodeGenCXX/catch-undef-behavior.cpp b/test/CodeGenCXX/catch-undef-behavior.cpp index b2d6fce367..044b92be9f 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,bool,enum -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,bounds -emit-llvm %s -o - -triple x86_64-linux-gnu | FileCheck %s struct S { double d; @@ -220,4 +220,93 @@ void bad_downcast_reference(S &p) { (void) static_cast<T&>(p); } +// CHECK: @_Z11array_index +int array_index(const int (&a)[4], int n) { + // CHECK: %[[K1_OK:.*]] = icmp ult i64 %{{.*}}, 4 + // CHECK: br i1 %[[K1_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + int k1 = a[n]; + + // CHECK: %[[R1_OK:.*]] = icmp ule i64 %{{.*}}, 4 + // CHECK: br i1 %[[R1_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + const int *r1 = &a[n]; + + // CHECK: %[[K2_OK:.*]] = icmp ult i64 %{{.*}}, 8 + // CHECK: br i1 %[[K2_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + int k2 = ((const int(&)[8])a)[n]; + + // CHECK: %[[K3_OK:.*]] = icmp ult i64 %{{.*}}, 4 + // CHECK: br i1 %[[K3_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + int k3 = n[a]; + + return k1 + *r1 + k2; +} + +// CHECK: @_Z17multi_array_index +int multi_array_index(int n, int m) { + int arr[4][6]; + + // CHECK: %[[IDX2_OK:.*]] = icmp ult i64 %{{.*}}, 6 + // CHECK: br i1 %[[IDX2_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + + // CHECK: %[[IDX1_OK:.*]] = icmp ult i64 %{{.*}}, 4 + // CHECK: br i1 %[[IDX1_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + return arr[n][m]; +} + +// CHECK: @_Z11array_arith +int array_arith(const int (&a)[4], int n) { + // CHECK: %[[K1_OK:.*]] = icmp ule i64 %{{.*}}, 4 + // CHECK: br i1 %[[K1_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + const int *k1 = a + n; + + // CHECK: %[[K2_OK:.*]] = icmp ule i64 %{{.*}}, 8 + // CHECK: br i1 %[[K2_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + const int *k2 = (const int(&)[8])a + n; + + return *k1 + *k2; +} + +struct ArrayMembers { + int a1[5]; + int a2[1]; +}; +// CHECK: @_Z18struct_array_index +int struct_array_index(ArrayMembers *p, int n) { + // CHECK: %[[IDX_OK:.*]] = icmp ult i64 %{{.*}}, 5 + // CHECK: br i1 %[[IDX_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + return p->a1[n]; +} + +// CHECK: @_Z16flex_array_index +int flex_array_index(ArrayMembers *p, int n) { + // CHECK-NOT: call void @__ubsan_handle_out_of_bounds( + return p->a2[n]; +} + +typedef __attribute__((ext_vector_type(4))) int V4I; +// CHECK: @_Z12vector_index +int vector_index(V4I v, int n) { + // CHECK: %[[IDX_OK:.*]] = icmp ult i64 %{{.*}}, 4 + // CHECK: br i1 %[[IDX_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + return v[n]; +} + +// CHECK: @_Z12string_index +char string_index(int n) { + // CHECK: %[[IDX_OK:.*]] = icmp ult i64 %{{.*}}, 6 + // CHECK: br i1 %[[IDX_OK]] + // CHECK: call void @__ubsan_handle_out_of_bounds( + return "Hello"[n]; +} + // CHECK: attributes [[NR_NUW]] = { noreturn nounwind } diff --git a/test/Driver/darwin-sanitizer-ld.c b/test/Driver/darwin-sanitizer-ld.c index e4134c91e8..98b37e96fe 100644 --- a/test/Driver/darwin-sanitizer-ld.c +++ b/test/Driver/darwin-sanitizer-ld.c @@ -28,7 +28,8 @@ // CHECK-UBSAN: stdc++ // RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \ -// RUN: -fsanitize=bounds %s -o %t.o 2>&1 \ +// RUN: -fsanitize=bounds -fsanitize-undefined-trap-on-error \ +// RUN: %s -o %t.o 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-BOUNDS %s // CHECK-BOUNDS: "{{.*}}ld{{(.exe)?}}" @@ -43,7 +44,8 @@ // CHECK-DYN-UBSAN: libclang_rt.ubsan_osx.a // RUN: %clang -no-canonical-prefixes -### -target x86_64-darwin \ -// RUN: -fPIC -shared -fsanitize=bounds %s -o %t.so 2>&1 \ +// RUN: -fsanitize=bounds -fsanitize-undefined-trap-on-error \ +// RUN: %s -o %t.so -fPIC -shared 2>&1 \ // RUN: | FileCheck --check-prefix=CHECK-DYN-BOUNDS %s // CHECK-DYN-BOUNDS: "{{.*}}ld{{(.exe)?}}" diff --git a/test/Driver/ubsan-ld.c b/test/Driver/ubsan-ld.c index 133d7a3a6d..7f601ab316 100644 --- a/test/Driver/ubsan-ld.c +++ b/test/Driver/ubsan-ld.c @@ -18,11 +18,3 @@ // CHECK-LINUX-SHARED-NOT: "-lc" // CHECK-LINUX-SHARED: libclang_rt.ubsan-i386.a" // CHECK-LINUX-SHARED: "-lpthread" - -// RUN: %clang -fsanitize=bounds %s -### -o %t.o 2>&1 \ -// RUN: -target i386-unknown-linux \ -// RUN: --sysroot=%S/Inputs/basic_linux_tree \ -// RUN: | FileCheck --check-prefix=CHECK-LINUX1 %s -// CHECK-LINUX1: "{{.*}}ld{{(.exe)?}}" -// CHECK-LINUX1-NOT: libclang_rt.ubsan-i386.a" -// CHECK-LINUX1-NOT: "-lpthread" |