Skip to content

Commit eb2b7ba

Browse files
committed
Fix local variable uniquing to take into account tail-allocated variable names
1 parent fd19e4b commit eb2b7ba

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
#include "clang/Basic/TargetInfo.h"
4848
#include "clang/Frontend/CompilerInstance.h"
4949
#include "clang/Serialization/ASTReader.h"
50+
#include "llvm/ADT/StringSet.h"
5051
#include "llvm/Config/config.h"
5152
#include "llvm/IR/DIBuilder.h"
5253
#include "llvm/IR/DebugInfo.h"
@@ -107,9 +108,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
107108
const PathRemapper &DebugPrefixMap;
108109

109110
/// Various caches.
110-
/// @{
111-
using SILVarScope = llvm::PointerUnion<const SILDebugScope *, SILFunction *>;
112-
using VarID = std::tuple<SILVarScope, const char *, uint16_t>;
111+
/// \{
112+
llvm::StringSet<> VarNames;
113+
using VarID = std::tuple<llvm::MDNode *, llvm::StringRef, unsigned, uint16_t>;
113114
llvm::DenseMap<VarID, llvm::TrackingMDNodeRef> LocalVarCache;
114115
llvm::DenseMap<const SILDebugScope *, llvm::TrackingMDNodeRef> ScopeCache;
115116
llvm::DenseMap<const SILDebugScope *, llvm::TrackingMDNodeRef> InlinedAtCache;
@@ -120,7 +121,7 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
120121
llvm::StringMap<llvm::TrackingMDNodeRef> DIFileCache;
121122
TrackingDIRefMap DIRefMap;
122123
TrackingDIRefMap InnerTypeCache;
123-
/// @}
124+
/// \}
124125

125126
/// A list of replaceable fwddecls that need to be RAUWed at the end.
126127
std::vector<std::pair<TypeBase *, llvm::TrackingMDRef>> ReplaceMap;
@@ -2444,7 +2445,6 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
24442445
if (!DbgTy.getTypeSize())
24452446
DbgTy.setSize(getStorageSize(IGM.DataLayout, Storage));
24462447

2447-
SILVarScope KeyScope = DS;
24482448
auto *Scope = dyn_cast_or_null<llvm::DILocalScope>(getOrCreateScope(DS));
24492449
assert(Scope && "variable has no local scope");
24502450
auto DInstLoc = getStartLocation(DbgInstLoc);
@@ -2455,7 +2455,6 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
24552455
if (ArgNo > 0) {
24562456
while (isa<llvm::DILexicalBlock>(Scope))
24572457
Scope = cast<llvm::DILexicalBlock>(Scope)->getScope();
2458-
KeyScope = DS->getInlinedFunction();
24592458
}
24602459
assert(isa_and_nonnull<llvm::DIScope>(Scope) && "variable has no scope");
24612460
llvm::DIFile *Unit = getFile(Scope);
@@ -2476,22 +2475,25 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
24762475

24772476
// Create the descriptor for the variable.
24782477
unsigned DVarLine = DInstLine;
2478+
uint16_t DVarCol = 0;
24792479
if (VarInfo.Loc) {
24802480
auto DVarLoc = getStartLocation(VarInfo.Loc);
24812481
DVarLine = DVarLoc.line;
2482+
DVarCol = DVarLoc.column;
24822483
}
24832484
llvm::DIScope *VarScope = Scope;
24842485
if (ArgNo == 0 && VarInfo.Scope) {
24852486
if (auto *VS = dyn_cast_or_null<llvm::DILocalScope>(
24862487
getOrCreateScope(VarInfo.Scope))) {
24872488
VarScope = VS;
2488-
KeyScope = VarInfo.Scope;
24892489
}
24902490
}
24912491

24922492
// Get or create the DILocalVariable.
24932493
llvm::DILocalVariable *Var;
2494-
VarID Key(KeyScope, VarInfo.Name.data(), ArgNo);
2494+
// VarInfo.Name points into tail-allocated storage in debug_value insns.
2495+
llvm::StringRef UniqueName = VarNames.insert(VarInfo.Name).first->getKey();
2496+
VarID Key(VarScope, UniqueName, DVarLine, DVarCol);
24952497
auto CachedVar = LocalVarCache.find(Key);
24962498
if (CachedVar != LocalVarCache.end()) {
24972499
Var = cast<llvm::DILocalVariable>(CachedVar->second);

0 commit comments

Comments
 (0)