Skip to content

Commit 97ffdf9

Browse files
authored
Merge pull request #762 from vedantk/ubsan-20190619
[ubsan] Null-check and adjust TypeLoc before using it
2 parents 10caba1 + c2a8d6e commit 97ffdf9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

clang/lib/CodeGen/CGCall.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -2996,7 +2996,7 @@ void CodeGenFunction::EmitReturnValueCheck(llvm::Value *RV) {
29962996
} else {
29972997
if (auto *DD = dyn_cast<DeclaratorDecl>(CurCodeDecl))
29982998
if (auto *TSI = DD->getTypeSourceInfo())
2999-
if (auto FTL = TSI->getTypeLoc().castAs<FunctionTypeLoc>())
2999+
if (auto FTL = TSI->getTypeLoc().getAsAdjusted<FunctionTypeLoc>())
30003000
AttrLoc = FTL.getReturnLoc().findNullabilityLoc();
30013001
CheckKind = SanitizerKind::NullabilityReturn;
30023002
Handler = SanitizerHandler::NullabilityReturn;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// RUN: %clang_cc1 -fsanitize=nullability-return -emit-llvm %s -o - -triple x86_64-apple-macosx10.10.0 | FileCheck %s
2+
3+
// CHECK: [[ATTR_LOC:@[0-9]+]] = {{.*}} global { {{.*}} i32 15, i32 38
4+
5+
// CHECK-LABEL: define i8* @_Z3foov()
6+
// CHECK: [[CALL:%.*]] = call i8* @_Z6helperv()
7+
// CHECK: icmp ne i8* [[CALL]]
8+
// CHECK: call void @__ubsan_handle_nullability_return_v1_abort({{.*}}[[ATTR_LOC]]
9+
10+
structS {
11+
using PtrTy = id;
12+
};
13+
14+
#pragma clang assume_nonnull begin
15+
__attribute__((ns_returns_retained)) S::PtrTy foo(void) {
16+
extern S::PtrTy helper(void);
17+
returnhelper();
18+
}
19+
#pragma clang assume_nonnull end

0 commit comments

Comments
 (0)
close