summaryrefslogtreecommitdiffstats
path: root/clang
diff options
context:
space:
mode:
Diffstat (limited to 'clang')
-rw-r--r--clang/lib/CodeGen/CGExprCXX.cpp5
-rw-r--r--clang/test/CodeGenCXX/catch-undef-behavior.cpp43
2 files changed, 46 insertions, 2 deletions
diff --git a/clang/lib/CodeGen/CGExprCXX.cpp b/clang/lib/CodeGen/CGExprCXX.cpp
index fabbb4ca54c..884ce96859c 100644
--- a/clang/lib/CodeGen/CGExprCXX.cpp
+++ b/clang/lib/CodeGen/CGExprCXX.cpp
@@ -1656,9 +1656,10 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
// Emit a null check on the allocation result if the allocation
// function is allowed to return null (because it has a non-throwing
// exception spec or is the reserved placement new) and we have an
- // interesting initializer.
+ // interesting initializer will be running sanitizers on the initialization.
bool nullCheck = E->shouldNullCheckAllocation() &&
- (!allocType.isPODType(getContext()) || E->hasInitializer());
+ (!allocType.isPODType(getContext()) || E->hasInitializer() ||
+ sanitizePerformTypeCheck());
llvm::BasicBlock *nullCheckBB = nullptr;
llvm::BasicBlock *contBB = nullptr;
diff --git a/clang/test/CodeGenCXX/catch-undef-behavior.cpp b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
index 50a05a06bf6..0e8d4fa51a0 100644
--- a/clang/test/CodeGenCXX/catch-undef-behavior.cpp
+++ b/clang/test/CodeGenCXX/catch-undef-behavior.cpp
@@ -520,6 +520,49 @@ void upcast_to_vbase() {
}
}
+struct nothrow {};
+void *operator new[](__SIZE_TYPE__, nothrow) noexcept;
+
+namespace NothrowNew {
+ struct X { X(); };
+
+ // CHECK-LABEL: define{{.*}}nothrow_new_trivial
+ void *nothrow_new_trivial() {
+ // CHECK: %[[is_null:.*]] = icmp eq i8*{{.*}}, null
+ // CHECK: br i1 %[[is_null]], label %[[null:.*]], label %[[nonnull:.*]]
+
+ // CHECK: [[nonnull]]:
+ // CHECK: llvm.objectsize
+ // CHECK: br i1
+ //
+ // CHECK: call {{.*}}__ubsan_handle_type_mismatch
+ //
+ // CHECK: [[null]]:
+ // CHECK-NOT: {{ }}br{{ }}
+ // CHECK: ret
+ return new (nothrow{}) char[123456];
+ }
+
+ // CHECK-LABEL: define{{.*}}nothrow_new_nontrivial
+ void *nothrow_new_nontrivial() {
+ // CHECK: %[[is_null:.*]] = icmp eq i8*{{.*}}, null
+ // CHECK: br i1 %[[is_null]], label %[[null:.*]], label %[[nonnull:.*]]
+
+ // CHECK: [[nonnull]]:
+ // CHECK: llvm.objectsize
+ // CHECK: br i1
+ //
+ // CHECK: call {{.*}}__ubsan_handle_type_mismatch
+ //
+ // CHECK: call {{.*}}_ZN10NothrowNew1XC1Ev
+ //
+ // CHECK: [[null]]:
+ // CHECK-NOT: {{ }}br{{ }}
+ // CHECK: ret
+ return new (nothrow{}) X[123456];
+ }
+}
+
struct ThisAlign {
void this_align_lambda();
void this_align_lambda_2();
OpenPOWER on IntegriCloud