Skip to content

Commit 0505eae

Browse files
authored
Merge pull request #738 from vedantk/cherry
[ubsan] Omit return value check when return block is unreachable
2 parents 968ade3 + 537cd37 commit 0505eae

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

clang/lib/CodeGen/CGCall.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3045,6 +3045,11 @@ void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) {
30453045
if (!CurCodeDecl)
30463046
return;
30473047

3048+
// If the return block isn't reachable, neither is this check, so don't emit
3049+
// it.
3050+
if (ReturnBlock.isValid() && ReturnBlock.getBlock()->use_empty())
3051+
return;
3052+
30483053
ReturnsNonNullAttr *RetNNAttr = nullptr;
30493054
if (SanOpts.has(SanitizerKind::ReturnsNonnullAttribute))
30503055
RetNNAttr = CurCodeDecl->getAttr<ReturnsNonNullAttr>();
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// RUN: %clang_cc1 -fsanitize=nullability-return -emit-llvm %s -o - -triple x86_64-apple-macosx10.10.0 -Wno-objc-root-class | FileCheck %s
2+
3+
// CHECK-LABEL: define internal i8* @"\01-[I init]"
4+
// CHECK: unreachable
5+
// CHECK-NEXT: }
6+
7+
#pragma clang assume_nonnull begin
8+
@interface I
9+
- (instancetype)init __attribute__((unavailable));
10+
@end
11+
@implementation I
12+
- (instancetype)init __attribute__((unavailable)) { __builtin_unreachable(); }
13+
@end
14+
#pragma clang assume_nonnull end

0 commit comments

Comments
 (0)