[PATCH] D74355: [ubsan] Null-check TypeLoc before using it
Vedant Kumar via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Feb 10 13:39:37 PST 2020
vsk created this revision.
vsk added reviewers: erik.pilkington, delcypher.
Herald added a subscriber: dexonsmith.
Null-check a TypeLoc before casting it to a FunctionTypeLoc. This fixes
a crash in -fsanitize=nullability-return.
rdar://59263039
https://reviews.llvm.org/D74355
Files:
clang/lib/CodeGen/CGCall.cpp
clang/test/CodeGenObjC/ubsan-nullability-return-notypeloc.m
Index: clang/test/CodeGenObjC/ubsan-nullability-return-notypeloc.m
===================================================================
--- /dev/null
+++ clang/test/CodeGenObjC/ubsan-nullability-return-notypeloc.m
@@ -0,0 +1,12 @@
+// RUN: %clang_cc1 -fsanitize=nullability-return -emit-llvm %s -o - -triple x86_64-apple-macosx10.10.0 | FileCheck %s
+
+// CHECK-LABEL: define i8* @foo()
+// CHECK: call i8* @helper()
+// CHECK-NEXT: ret i8*
+
+#pragma clang assume_nonnull begin
+__attribute__((ns_returns_retained)) id foo(void) {
+ extern id helper(void);
+ return helper();
+}
+#pragma clang assume_nonnull end
Index: clang/lib/CodeGen/CGCall.cpp
===================================================================
--- clang/lib/CodeGen/CGCall.cpp
+++ clang/lib/CodeGen/CGCall.cpp
@@ -3060,7 +3060,7 @@
} else {
if (auto *DD = dyn_cast<DeclaratorDecl>(CurCodeDecl))
if (auto *TSI = DD->getTypeSourceInfo())
- if (auto FTL = TSI->getTypeLoc().castAs<FunctionTypeLoc>())
+ if (auto FTL = TSI->getTypeLoc().getAs<FunctionTypeLoc>())
AttrLoc = FTL.getReturnLoc().findNullabilityLoc();
CheckKind = SanitizerKind::NullabilityReturn;
Handler = SanitizerHandler::NullabilityReturn;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74355.243665.patch
Type: text/x-patch
Size: 1228 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200210/3212eac9/attachment.bin>
More information about the cfe-commits
mailing list