@@ -1561,20 +1561,23 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
1561
1561
if (!Scope)
1562
1562
return ;
1563
1563
1564
- SILFunction *Fn = DS->getInlinedFunction ();
1565
1564
SILLocation::DebugLoc L;
1566
-
1567
- if ((Loc && Loc->isAutoGenerated ()) || (Fn && Fn->isThunk ())) {
1565
+ SILFunction *Fn = DS->getInlinedFunction ();
1566
+ if (Fn && Fn->isThunk ()) {
1567
+ L = SILLocation::getCompilerGeneratedDebugLoc ();
1568
+ } else if (DS == LastScope && Loc && Loc->isAutoGenerated ()) {
1568
1569
// Reuse the last source location if we are still in the same
1569
1570
// scope to get a more contiguous line table.
1570
- // Otherwise use a line 0 artificial location.
1571
- if (DS == LastScope)
1572
- L = LastDebugLoc;
1573
- else
1574
- L.Filename = LastDebugLoc.Filename ;
1571
+ L = LastDebugLoc;
1575
1572
} else {
1576
1573
// Decode the location.
1577
1574
L = getDebugLocation (Loc);
1575
+ // Otherwise use a line 0 artificial location, but the file from the
1576
+ // location.
1577
+ if (Loc && Loc->isAutoGenerated ()) {
1578
+ L.Line = 0 ;
1579
+ L.Column = 0 ;
1580
+ }
1578
1581
}
1579
1582
1580
1583
auto *File = getOrCreateFile (L.Filename );
@@ -1748,17 +1751,20 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
1748
1751
Name = getName (DS->Loc );
1749
1752
}
1750
1753
1754
+ // / The source line used for the function prologue.
1755
+ unsigned ScopeLine = 0 ;
1751
1756
SILLocation::DebugLoc L;
1752
- unsigned ScopeLine = 0 ; // / The source line used for the function prologue.
1753
- // Bare functions and thunks should not have any line numbers. This
1754
- // is especially important for shared functions like reabstraction
1755
- // thunk helpers, where DS->Loc is an arbitrary location of whichever use
1756
- // was emitted first.
1757
1757
if (DS && (!SILFn || (!SILFn->isBare () && !SILFn->isThunk ()))) {
1758
+ // Bare functions and thunks should not have any line numbers. This
1759
+ // is especially important for shared functions like reabstraction
1760
+ // thunk helpers, where DS->Loc is an arbitrary location of whichever use
1761
+ // was emitted first.
1758
1762
L = decodeDebugLoc (DS->Loc );
1759
1763
ScopeLine = L.Line ;
1760
1764
if (!DS->Loc .isDebugInfoLoc ())
1761
1765
L = decodeSourceLoc (DS->Loc .getSourceLoc ());
1766
+ } else {
1767
+ L = SILLocation::getCompilerGeneratedDebugLoc ();
1762
1768
}
1763
1769
1764
1770
auto Line = L.Line ;
@@ -1769,8 +1775,7 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
1769
1775
1770
1776
// We know that main always comes from MainFile.
1771
1777
if (LinkageName == SWIFT_ENTRY_POINT_FUNCTION) {
1772
- if (L.Filename .empty ())
1773
- File = MainFile;
1778
+ File = MainFile;
1774
1779
Line = 1 ;
1775
1780
Name = LinkageName;
1776
1781
}
@@ -1787,16 +1792,15 @@ IRGenDebugInfoImpl::emitFunction(const SILDebugScope *DS, llvm::Function *Fn,
1787
1792
bool IsLocalToUnit = Fn ? Fn->hasInternalLinkage () : true ;
1788
1793
bool IsDefinition = true ;
1789
1794
llvm::DINode::DIFlags Flags = llvm::DINode::FlagZero;
1790
-
1791
1795
// Mark everything that is not visible from the source code (i.e.,
1792
1796
// does not have a Swift name) as artificial, so the debugger can
1793
1797
// ignore it. Explicit closures are exempt from this rule. We also
1794
1798
// make an exception for toplevel code, which, although it does not
1795
1799
// have a Swift name, does appear prominently in the source code.
1800
+ // ObjC thunks should also not show up in the linetable, because we
1801
+ // never want to set a breakpoint there.
1796
1802
if ((Name.empty () && LinkageName != SWIFT_ENTRY_POINT_FUNCTION &&
1797
1803
!isExplicitClosure (SILFn)) ||
1798
- // ObjC thunks should also not show up in the linetable, because we
1799
- // never want to set a breakpoint there.
1800
1804
(Rep == SILFunctionTypeRepresentation::ObjCMethod) ||
1801
1805
isAllocatingConstructor (Rep, DeclCtx)) {
1802
1806
Flags |= llvm::DINode::FlagArtificial;
@@ -1849,7 +1853,9 @@ void IRGenDebugInfoImpl::emitArtificialFunction(IRBuilder &Builder,
1849
1853
RegularLocation ALoc = RegularLocation::getAutoGeneratedLocation ();
1850
1854
const SILDebugScope *Scope = new (IGM.getSILModule ()) SILDebugScope (ALoc);
1851
1855
emitFunction (Scope, Fn, SILFunctionTypeRepresentation::Thin, SILTy);
1852
- setCurrentLoc (Builder, Scope);
1856
+ // / Reusing the current file would be wrong: An objc thunk, for example, could
1857
+ // / be triggered from any random location. Use a placeholder name instead.
1858
+ setCurrentLoc (Builder, Scope, ALoc);
1853
1859
}
1854
1860
1855
1861
void IRGenDebugInfoImpl::emitVariableDeclaration (
0 commit comments