[PATCH] D74355: [ubsan] Null-check and adjust TypeLoc before using it

Vedant Kumar via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Feb 10 14:06:49 PST 2020


vsk updated this revision to Diff 243672.
vsk retitled this revision from "[ubsan] Null-check TypeLoc before using it" to "[ubsan] Null-check and adjust TypeLoc before using it".
vsk edited the summary of this revision.
vsk added a comment.

- Check adjusted return type per Erik's offline feedback.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74355/new/

https://reviews.llvm.org/D74355

Files:
  clang/lib/CodeGen/CGCall.cpp
  clang/test/CodeGenObjCXX/ubsan-nullability-return-notypeloc.mm


Index: clang/test/CodeGenObjCXX/ubsan-nullability-return-notypeloc.mm
===================================================================
--- /dev/null
+++ 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
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().getAsAdjusted<FunctionTypeLoc>())
           AttrLoc = FTL.getReturnLoc().findNullabilityLoc();
     CheckKind = SanitizerKind::NullabilityReturn;
     Handler = SanitizerHandler::NullabilityReturn;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74355.243672.patch
Type: text/x-patch
Size: 1482 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200210/03147362/attachment.bin>


More information about the cfe-commits mailing list