Skip to content

Commit 2f5660a

Browse files
authored
Merge pull request #38233 from mshockwave/dev-irgen-dbg-val-improve
[IRGen][DebugInfo] Use attached SILLocation for generating debug location for variable declaration
2 parents 3504310 + 2d35d31 commit 2f5660a

File tree

4 files changed

+44
-15
lines changed

4 files changed

+44
-15
lines changed

lib/IRGen/IRGenDebugInfo.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
192192
void emitVariableDeclaration(IRBuilder &Builder,
193193
ArrayRef<llvm::Value *> Storage,
194194
DebugTypeInfo Ty, const SILDebugScope *DS,
195-
ValueDecl *VarDecl, SILDebugVariable VarInfo,
195+
Optional<SILLocation> VarLoc,
196+
SILDebugVariable VarInfo,
196197
IndirectionKind = DirectValue,
197198
ArtificialKind = RealValue);
198199
void emitDbgIntrinsic(IRBuilder &Builder, llvm::Value *Storage,
@@ -2331,7 +2332,7 @@ void IRGenDebugInfoImpl::emitArtificialFunction(IRBuilder &Builder,
23312332

23322333
void IRGenDebugInfoImpl::emitVariableDeclaration(
23332334
IRBuilder &Builder, ArrayRef<llvm::Value *> Storage, DebugTypeInfo DbgTy,
2334-
const SILDebugScope *DS, ValueDecl *VarDecl, SILDebugVariable VarInfo,
2335+
const SILDebugScope *DS, Optional<SILLocation> VarLoc, SILDebugVariable VarInfo,
23352336
IndirectionKind Indirection, ArtificialKind Artificial) {
23362337
assert(DS && "variable has no scope");
23372338

@@ -2347,7 +2348,7 @@ void IRGenDebugInfoImpl::emitVariableDeclaration(
23472348

23482349
auto *Scope = dyn_cast_or_null<llvm::DILocalScope>(getOrCreateScope(DS));
23492350
assert(Scope && "variable has no local scope");
2350-
auto Loc = getFilenameAndLocation(*this, VarDecl);
2351+
auto Loc = getStartLocation(VarLoc);
23512352

23522353
// FIXME: this should be the scope of the type's declaration.
23532354
// If this is an argument, attach it to the current function scope.
@@ -2541,7 +2542,7 @@ void IRGenDebugInfoImpl::emitTypeMetadata(IRGenFunction &IGF,
25412542
Metadata->getType(), Size(CI.getTargetInfo().getPointerWidth(0)),
25422543
Alignment(CI.getTargetInfo().getPointerAlign(0)));
25432544
emitVariableDeclaration(IGF.Builder, Metadata, DbgTy, IGF.getDebugScope(),
2544-
nullptr, {OS.str().str(), 0, false},
2545+
{}, {OS.str().str(), 0, false},
25452546
// swift.type is already a pointer type,
25462547
// having a shadow copy doesn't add another
25472548
// layer of indirection.
@@ -2639,10 +2640,10 @@ void IRGenDebugInfo::emitArtificialFunction(IRBuilder &Builder,
26392640

26402641
void IRGenDebugInfo::emitVariableDeclaration(
26412642
IRBuilder &Builder, ArrayRef<llvm::Value *> Storage, DebugTypeInfo Ty,
2642-
const SILDebugScope *DS, ValueDecl *VarDecl, SILDebugVariable VarInfo,
2643+
const SILDebugScope *DS, Optional<SILLocation> VarLoc, SILDebugVariable VarInfo,
26432644
IndirectionKind Indirection, ArtificialKind Artificial) {
26442645
static_cast<IRGenDebugInfoImpl *>(this)->emitVariableDeclaration(
2645-
Builder, Storage, Ty, DS, VarDecl, VarInfo, Indirection, Artificial);
2646+
Builder, Storage, Ty, DS, VarLoc, VarInfo, Indirection, Artificial);
26462647
}
26472648

26482649
void IRGenDebugInfo::emitDbgIntrinsic(IRBuilder &Builder, llvm::Value *Storage,

lib/IRGen/IRGenDebugInfo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,8 @@ class IRGenDebugInfo {
141141
void emitVariableDeclaration(IRBuilder &Builder,
142142
ArrayRef<llvm::Value *> Storage,
143143
DebugTypeInfo Ty, const SILDebugScope *DS,
144-
ValueDecl *VarDecl, SILDebugVariable VarInfo,
144+
Optional<SILLocation> VarLoc,
145+
SILDebugVariable VarInfo,
145146
IndirectionKind Indirection = DirectValue,
146147
ArtificialKind Artificial = RealValue);
147148

lib/IRGen/IRGenSIL.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,7 +1056,8 @@ class IRGenSILFunction :
10561056
template <typename StorageType>
10571057
void emitDebugVariableDeclaration(StorageType Storage, DebugTypeInfo Ty,
10581058
SILType SILTy, const SILDebugScope *DS,
1059-
VarDecl *VarDecl, SILDebugVariable VarInfo,
1059+
SILLocation VarLoc,
1060+
SILDebugVariable VarInfo,
10601061
IndirectionKind Indirection) {
10611062
// TODO: fix demangling for C++ types (SR-13223).
10621063
if (swift::TypeBase *ty = SILTy.getASTType().getPointer()) {
@@ -1072,10 +1073,10 @@ class IRGenSILFunction :
10721073
assert(IGM.DebugInfo && "debug info not enabled");
10731074
if (VarInfo.ArgNo) {
10741075
PrologueLocation AutoRestore(IGM.DebugInfo.get(), Builder);
1075-
IGM.DebugInfo->emitVariableDeclaration(Builder, Storage, Ty, DS, VarDecl,
1076+
IGM.DebugInfo->emitVariableDeclaration(Builder, Storage, Ty, DS, VarLoc,
10761077
VarInfo, Indirection);
10771078
} else
1078-
IGM.DebugInfo->emitVariableDeclaration(Builder, Storage, Ty, DS, VarDecl,
1079+
IGM.DebugInfo->emitVariableDeclaration(Builder, Storage, Ty, DS, VarLoc,
10791080
VarInfo, Indirection);
10801081
}
10811082

@@ -4596,7 +4597,7 @@ void IRGenSILFunction::emitErrorResultVar(CanSILFunctionType FnTy,
45964597
ErrorResultSlot->getType(), IGM.getPointerSize(),
45974598
IGM.getPointerAlignment());
45984599
IGM.DebugInfo->emitVariableDeclaration(Builder, Storage, DbgTy,
4599-
getDebugScope(), nullptr, *Var,
4600+
getDebugScope(), {}, *Var,
46004601
IndirectValue, ArtificialValue);
46014602
}
46024603

@@ -4757,7 +4758,7 @@ void IRGenSILFunction::visitDebugValueInst(DebugValueInst *i) {
47574758
InCoroContext(*CurSILFn, *i) ? CoroDirectValue : DirectValue;
47584759

47594760
emitDebugVariableDeclaration(Copy, DbgTy, SILTy, i->getDebugScope(),
4760-
i->getDecl(), *VarInfo, Indirection);
4761+
i->getLoc(), *VarInfo, Indirection);
47614762
}
47624763

47634764
void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
@@ -4805,7 +4806,7 @@ void IRGenSILFunction::visitDebugValueAddrInst(DebugValueAddrInst *i) {
48054806
// intrinsic.
48064807
emitDebugVariableDeclaration(
48074808
emitShadowCopyIfNeeded(Addr, i->getDebugScope(), *VarInfo, IsAnonymous),
4808-
DbgTy, SILType(), i->getDebugScope(), Decl, *VarInfo, Indirection);
4809+
DbgTy, SILType(), i->getDebugScope(), i->getLoc(), *VarInfo, Indirection);
48094810
}
48104811

48114812
void IRGenSILFunction::visitFixLifetimeInst(swift::FixLifetimeInst *i) {
@@ -5152,7 +5153,8 @@ void IRGenSILFunction::emitDebugInfoForAllocStack(AllocStackInst *i,
51525153

51535154
bindArchetypes(DbgTy.getType());
51545155
if (IGM.DebugInfo)
5155-
emitDebugVariableDeclaration(addr, DbgTy, SILTy, DS, Decl, *VarInfo,
5156+
emitDebugVariableDeclaration(addr, DbgTy, SILTy, DS,
5157+
i->getLoc(), *VarInfo,
51565158
Indirection);
51575159
}
51585160

@@ -5366,7 +5368,7 @@ void IRGenSILFunction::visitAllocBoxInst(swift::AllocBoxInst *i) {
53665368
return;
53675369

53685370
IGM.DebugInfo->emitVariableDeclaration(
5369-
Builder, Storage, DbgTy, i->getDebugScope(), Decl, *VarInfo,
5371+
Builder, Storage, DbgTy, i->getDebugScope(), i->getLoc(), *VarInfo,
53705372
InCoroContext(*CurSILFn, *i) ? CoroIndirectValue : IndirectValue);
53715373
}
53725374

test/DebugInfo/debug_variable.sil

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// RUN: %target-swiftc_driver -g -emit-ir %s | %FileCheck %s
2+
sil_stage canonical
3+
4+
import Builtin
5+
import Swift
6+
7+
sil_scope 2 { loc "simple.swift":1:2 parent @test_debug_value : $@convention(thin) (Int) -> () }
8+
9+
// SR-14868: Incorrect source location on `llvm.dbg.declare` when the input
10+
// is SIL file.
11+
12+
// CHECK: @test_debug_value
13+
// CHECK-SAME: !dbg ![[FUNC_DI:[0-9]+]]
14+
sil hidden @test_debug_value : $@convention(thin) (Int) -> () {
15+
bb0(%0 : $Int):
16+
// CHECK: @llvm.dbg.declare(metadata i{{[0-9]+}}*
17+
// CHECK-SAME: metadata ![[VAR_DI:[0-9]+]]
18+
// CHECK-SAME: ), !dbg ![[LOC_DI:[0-9]+]]
19+
debug_value %0 : $Int, let, name "x", argno 1, loc "simple.swift":3:4, scope 2
20+
%1 = tuple ()
21+
return %1 : $()
22+
}
23+
24+
// CHECK: ![[VAR_DI]] = !DILocalVariable(name: "x", arg: 1
25+
// CHECK: ![[LOC_DI]] = !DILocation(line: 3, column: 4, scope: ![[FUNC_DI]]

0 commit comments

Comments
 (0)