[PATCH] D53459: Ensure sanitizer check function calls have a !dbg location

Adrian Prantl via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Oct 19 16:33:43 PDT 2018


aprantl created this revision.
aprantl added a reviewer: vsk.

Function calls without a !dbg location inside a function that has a DISubprogram make it impossible to construct inline information and are rejected by the verifier. This patch ensures that sanitizer check function calls have a !dbg location, by carrying forward the location of the preceding instruction or by inserting an artificial location if necessary.

This fixes a crash when compiling the attached testcase with -Os.

rdar://problem/45311226


https://reviews.llvm.org/D53459

Files:
  lib/CodeGen/CGExpr.cpp
  test/CodeGenCXX/ubsan-check-debuglocs.cpp


Index: test/CodeGenCXX/ubsan-check-debuglocs.cpp
===================================================================
--- /dev/null
+++ test/CodeGenCXX/ubsan-check-debuglocs.cpp
@@ -0,0 +1,18 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \
+// RUN:   -fsanitize=null,object-size,return -fsanitize-recover=null \
+// RUN:   %s -o - | FileCheck %s
+
+// Check that santizer check calls have a !dbg location.
+// CHECK: define {{.*}}acquire{{.*}} !dbg
+// CHECK-NOT: define
+// CHECK: call void {{.*}}@__ubsan_handle_type_mismatch_v1 {{.*}}, !dbg
+
+class SourceLocation {
+public:
+  SourceLocation acquire() {};
+};
+extern "C" void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc);
+static void handleTypeMismatchImpl(SourceLocation *Loc) { Loc->acquire(); }
+void __ubsan_handle_type_mismatch_v1(SourceLocation *Loc) {
+  handleTypeMismatchImpl(Loc);
+}
Index: lib/CodeGen/CGExpr.cpp
===================================================================
--- lib/CodeGen/CGExpr.cpp
+++ lib/CodeGen/CGExpr.cpp
@@ -2867,6 +2867,9 @@
                                  CheckRecoverableKind RecoverKind, bool IsFatal,
                                  llvm::BasicBlock *ContBB) {
   assert(IsFatal || RecoverKind != CheckRecoverableKind::Unrecoverable);
+  auto *DI = CGF.getDebugInfo();
+  SourceLocation Loc = DI ? DI->getLocation() : SourceLocation();
+  auto DL = ApplyDebugLocation::CreateDefaultArtificial(CGF, Loc);
   bool NeedsAbortSuffix =
       IsFatal && RecoverKind != CheckRecoverableKind::Unrecoverable;
   bool MinimalRuntime = CGF.CGM.getCodeGenOpts().SanitizeMinimalRuntime;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D53459.170275.patch
Type: text/x-patch
Size: 1603 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20181019/26cdf2cf/attachment.bin>


More information about the cfe-commits mailing list