diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-01-23 03:37:29 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2019-01-23 03:37:29 +0000 |
commit | cfa79b27b5c50c0f698176355b9f3249036c267e (patch) | |
tree | 70777ab9e9edf970619c545490fef61ef0778c0d /clang/test/CodeGenCXX/catch-undef-behavior.cpp | |
parent | 59d99731467654bd488d54eaa44855c5b5a0d8c0 (diff) | |
download | bcm5719-llvm-cfa79b27b5c50c0f698176355b9f3249036c267e.tar.gz bcm5719-llvm-cfa79b27b5c50c0f698176355b9f3249036c267e.zip |
[ubsan] Check the correct size when sanitizing array new.
We previously forgot to multiply the element size by the array bound.
llvm-svn: 351924
Diffstat (limited to 'clang/test/CodeGenCXX/catch-undef-behavior.cpp')
-rw-r--r-- | clang/test/CodeGenCXX/catch-undef-behavior.cpp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/clang/test/CodeGenCXX/catch-undef-behavior.cpp b/clang/test/CodeGenCXX/catch-undef-behavior.cpp index 0e8d4fa51a0..ba72af038ab 100644 --- a/clang/test/CodeGenCXX/catch-undef-behavior.cpp +++ b/clang/test/CodeGenCXX/catch-undef-behavior.cpp @@ -533,6 +533,7 @@ namespace NothrowNew { // CHECK: [[nonnull]]: // CHECK: llvm.objectsize + // CHECK: icmp uge i64 {{.*}}, 123456, // CHECK: br i1 // // CHECK: call {{.*}}__ubsan_handle_type_mismatch @@ -550,6 +551,7 @@ namespace NothrowNew { // CHECK: [[nonnull]]: // CHECK: llvm.objectsize + // CHECK: icmp uge i64 {{.*}}, 123456, // CHECK: br i1 // // CHECK: call {{.*}}__ubsan_handle_type_mismatch @@ -561,6 +563,47 @@ namespace NothrowNew { // CHECK: ret return new (nothrow{}) X[123456]; } + + // CHECK-LABEL: define{{.*}}throwing_new + void *throwing_new(int size) { + // CHECK: icmp ne i8*{{.*}}, null + // CHECK: %[[size:.*]] = mul + // CHECK: llvm.objectsize + // CHECK: icmp uge i64 {{.*}}, %[[size]], + // CHECK: %[[ok:.*]] = and + // CHECK: br i1 %[[ok]], label %[[good:.*]], label %[[bad:[^,]*]] + // + // CHECK: [[bad]]: + // CHECK: call {{.*}}__ubsan_handle_type_mismatch + // + // CHECK: [[good]]: + // CHECK-NOT: {{ }}br{{ }} + // CHECK: ret + return new char[size]; + } + + // CHECK-LABEL: define{{.*}}nothrow_new_zero_size + void *nothrow_new_zero_size() { + // CHECK: %[[nonnull:.*]] = icmp ne i8*{{.*}}, null + // CHECK-NOT: llvm.objectsize + // CHECK: br i1 %[[nonnull]], label %[[good:.*]], label %[[bad:[^,]*]] + // + // CHECK: [[bad]]: + // CHECK: call {{.*}}__ubsan_handle_type_mismatch + // + // CHECK: [[good]]: + // CHECK-NOT: {{ }}br{{ }} + // CHECK: ret + return new char[0]; + } + + // CHECK-LABEL: define{{.*}}throwing_new_zero_size + void *throwing_new_zero_size() { + // Nothing to check here. + // CHECK-NOT: __ubsan_handle_type_mismatch + return new (nothrow{}) char[0]; + // CHECK: ret + } } struct ThisAlign { |