File tree Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Expand file tree Collapse file tree 2 files changed +46
-2
lines changed Original file line number Diff line number Diff line change @@ -1656,9 +1656,10 @@ llvm::Value *CodeGenFunction::EmitCXXNewExpr(const CXXNewExpr *E) {
1656
1656
// Emit a null check on the allocation result if the allocation
1657
1657
// function is allowed to return null (because it has a non-throwing
1658
1658
// exception spec or is the reserved placement new) and we have an
1659
- // interesting initializer.
1659
+ // interesting initializer will be running sanitizers on the initialization .
1660
1660
bool nullCheck = E->shouldNullCheckAllocation () &&
1661
- (!allocType.isPODType (getContext ()) || E->hasInitializer ());
1661
+ (!allocType.isPODType (getContext ()) || E->hasInitializer () ||
1662
+ sanitizePerformTypeCheck ());
1662
1663
1663
1664
llvm::BasicBlock *nullCheckBB = nullptr ;
1664
1665
llvm::BasicBlock *contBB = nullptr ;
Original file line number Diff line number Diff line change @@ -520,6 +520,49 @@ void upcast_to_vbase() {
520
520
}
521
521
}
522
522
523
+ struct nothrow {};
524
+ void *operator new [](__SIZE_TYPE__, nothrow) noexcept ;
525
+
526
+ namespace NothrowNew {
527
+ struct X { X(); };
528
+
529
+ // CHECK-LABEL: define{{.*}}nothrow_new_trivial
530
+ void *nothrow_new_trivial () {
531
+ // CHECK: %[[is_null:.*]] = icmp eq i8*{{.*}}, null
532
+ // CHECK: br i1 %[[is_null]], label %[[null:.*]], label %[[nonnull:.*]]
533
+
534
+ // CHECK: [[nonnull]]:
535
+ // CHECK: llvm.objectsize
536
+ // CHECK: br i1
537
+ //
538
+ // CHECK: call {{.*}}__ubsan_handle_type_mismatch
539
+ //
540
+ // CHECK: [[null]]:
541
+ // CHECK-NOT: {{ }}br{{ }}
542
+ // CHECK: ret
543
+ return new (nothrow{}) char [123456 ];
544
+ }
545
+
546
+ // CHECK-LABEL: define{{.*}}nothrow_new_nontrivial
547
+ void *nothrow_new_nontrivial () {
548
+ // CHECK: %[[is_null:.*]] = icmp eq i8*{{.*}}, null
549
+ // CHECK: br i1 %[[is_null]], label %[[null:.*]], label %[[nonnull:.*]]
550
+
551
+ // CHECK: [[nonnull]]:
552
+ // CHECK: llvm.objectsize
553
+ // CHECK: br i1
554
+ //
555
+ // CHECK: call {{.*}}__ubsan_handle_type_mismatch
556
+ //
557
+ // CHECK: call {{.*}}_ZN10NothrowNew1XC1Ev
558
+ //
559
+ // CHECK: [[null]]:
560
+ // CHECK-NOT: {{ }}br{{ }}
561
+ // CHECK: ret
562
+ return new (nothrow{}) X[123456 ];
563
+ }
564
+ }
565
+
523
566
struct ThisAlign {
524
567
void this_align_lambda ();
525
568
void this_align_lambda_2 ();
You can’t perform that action at this time.
0 commit comments