From 4f032cd2216d69fad556211ac89b0c1e8004068f Mon Sep 17 00:00:00 2001 From: Adrian Prantl Date: Mon, 12 Jun 2023 16:32:20 -0700 Subject: [PATCH] Make source locations for standard library calls explicit --- lib/SILGen/SILGenApply.cpp | 4 ++++ test/DebugInfo/iuo_assertloc.swift | 10 ++++++++++ 2 files changed, 14 insertions(+) create mode 100644 test/DebugInfo/iuo_assertloc.swift diff --git a/lib/SILGen/SILGenApply.cpp b/lib/SILGen/SILGenApply.cpp index 8212dbd7b7c..89fcdb11bea 100644 --- a/lib/SILGen/SILGenApply.cpp +++ b/lib/SILGen/SILGenApply.cpp @@ -5935,6 +5935,10 @@ RValue SILGenFunction::emitApplyOfLibraryIntrinsic(SILLocation loc, SubstitutionMap subMap, ArrayRef args, SGFContext ctx) { + // Calls into library intrinsics are implicitly generated by the compiler. + // Marking them as explicit creates a backtrace pointing back to the user code + // that the intrinsic call was generated from. + loc.markExplicit(); auto callee = Callee::forDirect(*this, declRef, subMap, loc); auto origFormalType = callee.getOrigFormalType(); diff --git a/test/DebugInfo/iuo_assertloc.swift b/test/DebugInfo/iuo_assertloc.swift new file mode 100644 index 00000000000..508943bbafe --- /dev/null +++ b/test/DebugInfo/iuo_assertloc.swift @@ -0,0 +1,10 @@ +// RUN: %target-swift-frontend %s -emit-sil -parse-as-library -g -o - | %FileCheck %s --check-prefix=CHECK-SIL +// RUN: %target-swift-frontend %s -emit-ir -parse-as-library -g -o - | %FileCheck %s --check-prefix=CHECK-IR + +public func f(_ a: Int!) -> Int { + // CHECK-IR: call {{.*}}assertionFailure{{.*}}, !dbg ![[LOC:[0-9]+]] + // CHECK-IR: ![[LOC]] = !DILocation(line: [[@LINE+1]], column: 11 + return (a // CHECK-SIL: apply {{.*}}:[[@LINE]]:11 + + + 1) +}