Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ubsan] Null-check and adjust TypeLoc before using it
Null-check and adjut a TypeLoc before casting it to a FunctionTypeLoc. This fixes a crash in -fsanitize=nullability-return, and also makes the location of the nonnull type available when the return type is adjusted. rdar://59263039 Differential Revision: https://reviews.llvm.org/D74355
- Loading branch information
Showing
2 changed files
with
20 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
clang/test/CodeGenObjCXX/ubsan-nullability-return-notypeloc.mm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// RUN: %clang_cc1 -fsanitize=nullability-return -emit-llvm %s -o - -triple x86_64-apple-macosx10.10.0 | FileCheck %s | ||
|
||
// CHECK: [[ATTR_LOC:@[0-9]+]] = {{.*}} global { {{.*}} i32 15, i32 38 | ||
|
||
// CHECK-LABEL: define i8* @_Z3foov() | ||
// CHECK: [[CALL:%.*]] = call i8* @_Z6helperv() | ||
// CHECK: icmp ne i8* [[CALL]] | ||
// CHECK: call void @__ubsan_handle_nullability_return_v1_abort({{.*}}[[ATTR_LOC]] | ||
|
||
struct S { | ||
using PtrTy = id; | ||
}; | ||
|
||
#pragma clang assume_nonnull begin | ||
__attribute__((ns_returns_retained)) S::PtrTy foo(void) { | ||
extern S::PtrTy helper(void); | ||
return helper(); | ||
} | ||
#pragma clang assume_nonnull end |