Skip to content

Commit 97332af

Browse files
committed
Temporarily revert "Debug Info: Assign unique names to anonymous variables and arguments."
This reverts commit ef84c81 because fd6e8a9 needed to be reverted.
1 parent 6facd03 commit 97332af

File tree

3 files changed

+44
-60
lines changed

3 files changed

+44
-60
lines changed

lib/IRGen/IRGenSIL.cpp

Lines changed: 25 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -295,8 +295,6 @@ class IRGenSILFunction :
295295
/// Keeps track of the mapping of source variables to -O0 shadow copy allocas.
296296
llvm::SmallDenseMap<std::pair<const SILDebugScope *, StringRef>, Address, 8>
297297
ShadowStackSlots;
298-
llvm::SmallDenseMap<Decl *, SmallString<4>, 8> AnonymousVariables;
299-
unsigned NumAnonVars = 0;
300298

301299
/// Accumulative amount of allocated bytes on the stack. Used to limit the
302300
/// size for stack promoted objects.
@@ -483,26 +481,6 @@ class IRGenSILFunction :
483481
return foundBB->second;
484482
}
485483

486-
StringRef getOrCreateAnonymousVarName(VarDecl *Decl) {
487-
llvm::SmallString<4> &Name = AnonymousVariables[Decl];
488-
if (Name.empty()) {
489-
{
490-
llvm::raw_svector_ostream S(Name);
491-
S << '_' << NumAnonVars++;
492-
}
493-
AnonymousVariables.insert({Decl, Name});
494-
}
495-
return Name;
496-
}
497-
498-
template <class DebugVarCarryingInst>
499-
StringRef getVarName(DebugVarCarryingInst *i) {
500-
StringRef Name = i->getVarInfo().Name;
501-
if (Name.empty() && i->getDecl())
502-
return getOrCreateAnonymousVarName(i->getDecl());
503-
return Name;
504-
}
505-
506484
/// At -O0, emit a shadow copy of an Address in an alloca, so the
507485
/// register allocator doesn't elide the dbg.value intrinsic when
508486
/// register pressure is high. There is a trade-off to this: With
@@ -609,8 +587,6 @@ class IRGenSILFunction :
609587

610588
void emitFunctionArgDebugInfo(SILBasicBlock *BB);
611589

612-
void emitDebugInfoForAllocStack(AllocStackInst *i, const TypeInfo &type,
613-
llvm::Value *addr);
614590
void visitAllocStackInst(AllocStackInst *i);
615591
void visitAllocRefInst(AllocRefInst *i);
616592
void visitAllocRefDynamicInst(AllocRefDynamicInst *i);
@@ -2973,7 +2949,7 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
29732949
if (isa<SILUndef>(SILVal))
29742950
return;
29752951

2976-
StringRef Name = getVarName(i);
2952+
StringRef Name = i->getVarInfo().Name;
29772953
DebugTypeInfo DbgTy;
29782954
SILType SILTy = SILVal.getType();
29792955
if (VarDecl *Decl = i->getDecl())
@@ -3007,7 +2983,7 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
30072983
if (isa<SILUndef>(SILVal))
30082984
return;
30092985

3010-
StringRef Name = getVarName(i);
2986+
StringRef Name = i->getVarInfo().Name;
30112987
auto Addr = getLoweredAddress(SILVal).getAddress();
30122988
DebugTypeInfo DbgTy(Decl, Decl->getType(), getTypeInfo(SILVal.getType()));
30132989
// Put the value into a stack slot at -Onone and emit a debug intrinsic.
@@ -3255,23 +3231,25 @@ static bool tryDeferFixedSizeBufferInitialization(IRGenSILFunction &IGF,
32553231
return false;
32563232
}
32573233

3258-
void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
3259-
const TypeInfo &type,
3260-
llvm::Value *addr) {
3234+
static void emitDebugDeclarationForAllocStack(IRGenSILFunction &IGF,
3235+
AllocStackInst *i,
3236+
const TypeInfo &type,
3237+
llvm::Value *addr) {
32613238
VarDecl *Decl = i->getDecl();
3262-
if (IGM.DebugInfo && Decl) {
3239+
if (IGF.IGM.DebugInfo && Decl) {
32633240
auto *Pattern = Decl->getParentPattern();
32643241
if (!Pattern || !Pattern->isImplicit()) {
32653242
auto DbgTy = DebugTypeInfo(Decl, type);
32663243
// Discard any inout or lvalue qualifiers. Since the object itself
32673244
// is stored in the alloca, emitting it as a reference type would
32683245
// be wrong.
32693246
DbgTy.unwrapLValueOrInOutType();
3270-
StringRef Name = getVarName(i);
3271-
if (auto DS = i->getDebugScope()) {
3272-
assert(DS->SILFn == CurSILFn || DS->InlinedCallSite);
3273-
emitDebugVariableDeclaration(addr, DbgTy, DS, Name,
3274-
i->getVarInfo().ArgNo);
3247+
auto Name = i->getVarInfo().Name.empty() ? "_" : i->getVarInfo().Name;
3248+
auto DS = i->getDebugScope();
3249+
if (DS) {
3250+
assert(DS->SILFn == IGF.CurSILFn || DS->InlinedCallSite);
3251+
IGF.emitDebugVariableDeclaration(addr, DbgTy, DS, Name,
3252+
i->getVarInfo().ArgNo);
32753253
}
32763254
}
32773255
}
@@ -3285,7 +3263,7 @@ void IRGenSILFunction::visitAllocStackInst(swift::AllocStackInst *i) {
32853263
StringRef dbgname;
32863264
# ifndef NDEBUG
32873265
// If this is a DEBUG build, use pretty names for the LLVM IR.
3288-
dbgname = getVarName(i);
3266+
dbgname = i->getVarInfo().Name;
32893267
# endif
32903268

32913269
(void) Decl;
@@ -3302,8 +3280,10 @@ void IRGenSILFunction::visitAllocStackInst(swift::AllocStackInst *i) {
33023280
auto addr = type.allocateStack(*this,
33033281
i->getElementType(),
33043282
dbgname);
3305-
3306-
emitDebugInfoForAllocStack(i, type, addr.getAddress().getAddress());
3283+
3284+
emitDebugDeclarationForAllocStack(*this, i, type,
3285+
addr.getAddress().getAddress());
3286+
33073287
setLoweredAddress(i->getContainerResult(), addr.getContainer());
33083288
setLoweredAddress(i->getAddressResult(), addr.getAddress());
33093289
}
@@ -3397,7 +3377,7 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
33973377

33983378
// Derive name from SIL location.
33993379
VarDecl *Decl = i->getDecl();
3400-
StringRef Name = getVarName(i);
3380+
StringRef Name = i->getVarInfo().Name;
34013381
StringRef DbgName =
34023382
# ifndef NDEBUG
34033383
// If this is a DEBUG build, use pretty names for the LLVM IR.
@@ -4352,15 +4332,15 @@ void IRGenSILFunction::visitWitnessMethodInst(swift::WitnessMethodInst *i) {
43524332

43534333
void IRGenSILFunction::setAllocatedAddressForBuffer(SILValue v,
43544334
const Address &allocedAddress) {
4355-
assert(getLoweredValue(v).kind ==
4356-
LoweredValue::Kind::UnallocatedAddressInBuffer &&
4357-
"not an unallocated address");
4358-
4335+
assert(getLoweredValue(v).kind == LoweredValue::Kind::UnallocatedAddressInBuffer
4336+
&& "not an unallocated address");
4337+
43594338
overwriteLoweredAddress(v, allocedAddress);
43604339
// Emit the debug info for the variable if any.
43614340
if (auto allocStack = dyn_cast<AllocStackInst>(v)) {
4362-
emitDebugInfoForAllocStack(allocStack, getTypeInfo(v.getType()),
4363-
allocedAddress.getAddress());
4341+
emitDebugDeclarationForAllocStack(*this, allocStack,
4342+
getTypeInfo(v.getType()),
4343+
allocedAddress.getAddress());
43644344
}
43654345
}
43664346

lib/SILGen/SILGenProlog.cpp

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -324,17 +324,9 @@ struct ArgumentInitVisitor :
324324
++ArgNo;
325325
auto PD = P->getDecl();
326326
if (!PD->hasName()) {
327-
ManagedValue argrv = makeArgument(P->getType(), &*f.begin(), PD);
328-
// Emit debug information for the argument.
329-
SILLocation loc(PD);
330-
loc.markAsPrologue();
331-
if (argrv.getType().isAddress())
332-
gen.B.createDebugValueAddr(loc, argrv.getValue(), {PD->isLet(), ArgNo});
333-
else
334-
gen.B.createDebugValue(loc, argrv.getValue(), {PD->isLet(), ArgNo});
335-
336327
// A value bound to _ is unused and can be immediately released.
337328
Scope discardScope(gen.Cleanups, CleanupLocation(P));
329+
makeArgument(P->getType(), &*f.begin(), PD);
338330
// Popping the scope destroys the value.
339331
} else {
340332
makeArgumentIntoBinding(P->getType(), &*f.begin(), PD);

test/DebugInfo/anonymous.swift

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,22 @@
11
// RUN: %target-swift-frontend -primary-file %s -emit-ir -g -o - | FileCheck %s
22

3-
// CHECK: !DILocalVariable(name: "_0", arg: 1
4-
// CHECK: !DILocalVariable(name: "_1", arg: 2
5-
// CHECK: !DILocalVariable(name: "_2", arg: 3
6-
// CHECK: !DILocalVariable(name: "x4", arg: 4
3+
// Don't crash when emitting debug info for anonymous variables.
4+
// CHECK: !DILocalVariable(name: "_"
75

8-
public func fourth<T>(_: T, _: T, _: T, x4 : T) -> T {
9-
return x4
6+
func markUsed<T>(t: T) {}
7+
8+
protocol F_ {
9+
func successor() -> Self
10+
}
11+
12+
protocol F : F_ {
13+
func ~> (_: Self, _: (_Distance, (Self))) -> Int64
14+
}
15+
16+
struct _Distance {}
17+
18+
func ~> <I: F_>(self_:I, _: (_Distance, (I))) -> Int64 {
19+
self_.successor()
20+
markUsed("F")
21+
return 0
1022
}

0 commit comments

Comments
 (0)