Skip to content

Commit d0b2f41

Browse files
authored
Merge pull request #59463 from adrian-prantl/3259672-main
Unique the debug info function declarations for Swift runtime failure…
2 parents bda8aac + 92d7e63 commit d0b2f41

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
132132
llvm::DenseMap<TypeBase *, llvm::TrackingMDNodeRef> DITypeCache;
133133
llvm::DenseMap<const void *, llvm::TrackingMDNodeRef> DIModuleCache;
134134
llvm::StringMap<llvm::TrackingMDNodeRef> DIFileCache;
135+
llvm::StringMap<llvm::TrackingMDNodeRef> RuntimeErrorFnCache;
135136
TrackingDIRefMap DIRefMap;
136137
TrackingDIRefMap InnerTypeCache;
137138
/// \}
@@ -2109,13 +2110,20 @@ void IRGenDebugInfoImpl::addFailureMessageToCurrentLoc(IRBuilder &Builder,
21092110

21102111
llvm::DISubroutineType *DIFnTy = DBuilder.createSubroutineType(nullptr);
21112112

2112-
std::string FuncName = "Swift runtime failure: ";
2113-
FuncName += failureMsg;
2114-
2115-
llvm::DISubprogram *TrapSP = DBuilder.createFunction(
2116-
MainModule, FuncName, StringRef(), TrapLoc->getFile(), 0, DIFnTy, 0,
2117-
llvm::DINode::FlagArtificial, llvm::DISubprogram::SPFlagDefinition,
2118-
nullptr, nullptr, nullptr);
2113+
llvm::DISubprogram *TrapSP;
2114+
auto It = RuntimeErrorFnCache.find(failureMsg);
2115+
if (It != RuntimeErrorFnCache.end())
2116+
TrapSP = llvm::cast<llvm::DISubprogram>(It->second);
2117+
else {
2118+
std::string FuncName = "Swift runtime failure: ";
2119+
FuncName += failureMsg;
2120+
llvm::DIFile *File = getOrCreateFile({});
2121+
TrapSP = DBuilder.createFunction(
2122+
File, FuncName, StringRef(), File, 0,
2123+
DIFnTy, 0, llvm::DINode::FlagArtificial,
2124+
llvm::DISubprogram::SPFlagDefinition, nullptr, nullptr, nullptr);
2125+
RuntimeErrorFnCache.insert({failureMsg, llvm::TrackingMDNodeRef(TrapSP)});
2126+
}
21192127

21202128
ScopeCache[TrapSc] = llvm::TrackingMDNodeRef(TrapSP);
21212129
LastScope = TrapSc;

test/DebugInfo/runtime-failure.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// RUN: %target-swift-frontend %s -emit-ir -g -o - | %FileCheck %s
2+
3+
public func f(_ input: Int) -> Int {
4+
return input * 2 + 1
5+
}
6+
7+
// CHECK: distinct !DISubprogram(name: "Swift runtime failure: arithmetic overflow"
8+
// CHECK-SAME: scope: ![[FILE:[0-9]+]]
9+
// CHECK-SAME: file: ![[FILE]]
10+
// CHECK-NOT: "Swift runtime failure: arithmetic overflow"

0 commit comments

Comments
 (0)