diff --git a/clang/lib/CodeGen/CGCall.cpp b/clang/lib/CodeGen/CGCall.cpp --- a/clang/lib/CodeGen/CGCall.cpp +++ b/clang/lib/CodeGen/CGCall.cpp @@ -3060,7 +3060,7 @@ } else { if (auto *DD = dyn_cast(CurCodeDecl)) if (auto *TSI = DD->getTypeSourceInfo()) - if (auto FTL = TSI->getTypeLoc().castAs()) + if (auto FTL = TSI->getTypeLoc().getAsAdjusted()) AttrLoc = FTL.getReturnLoc().findNullabilityLoc(); CheckKind = SanitizerKind::NullabilityReturn; Handler = SanitizerHandler::NullabilityReturn; diff --git a/clang/test/CodeGenObjCXX/ubsan-nullability-return-notypeloc.mm b/clang/test/CodeGenObjCXX/ubsan-nullability-return-notypeloc.mm new file mode 100644 --- /dev/null +++ b/clang/test/CodeGenObjCXX/ubsan-nullability-return-notypeloc.mm @@ -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