]> granicus.if.org Git - clang/commitdiff
Ensure sanitizer check function calls have a !dbg location
authorAdrian Prantl <aprantl@apple.com>
Mon, 22 Oct 2018 16:27:41 +0000 (16:27 +0000)
committerAdrian Prantl <aprantl@apple.com>
Mon, 22 Oct 2018 16:27:41 +0000 (16:27 +0000)
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

Differential Revision: https://reviews.llvm.org/D53459

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@344915 91177308-0d34-0410-b5e6-96231b3b80d8

lib/CodeGen/CGExpr.cpp
test/CodeGenCXX/ubsan-check-debuglocs.cpp [new file with mode: 0644]

index 55fa45511676d589614db873f58a6b3a23fb0bb4..8a8f38678f663fc81fb8be50bccf0b00fca467da 100644 (file)
@@ -2867,6 +2867,9 @@ static void emitCheckHandlerCall(CodeGenFunction &CGF,
                                  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;
diff --git a/test/CodeGenCXX/ubsan-check-debuglocs.cpp b/test/CodeGenCXX/ubsan-check-debuglocs.cpp
new file mode 100644 (file)
index 0000000..96a697a
--- /dev/null
@@ -0,0 +1,17 @@
+// RUN: %clang_cc1 -emit-llvm -debug-info-kind=limited \
+// RUN:   -fsanitize=null %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
+// CHECK-SAME: !dbg
+
+struct SourceLocation {
+  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);
+}