@@ -344,6 +344,9 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
344
344
IRGenDebugInfoFormat getDebugInfoFormat () { return Opts.DebugInfoFormat ; }
345
345
346
346
private:
347
+ // / Convert a SILLocation into the corresponding LLVM Loc.
348
+ FileAndLocation computeLLVMLoc (const SILDebugScope *DS, SILLocation Loc);
349
+
347
350
static StringRef getFilenameFromDC (const DeclContext *DC) {
348
351
if (auto *LF = dyn_cast<LoadedFile>(DC))
349
352
return LF->getFilename ();
@@ -2614,6 +2617,45 @@ bool IRGenDebugInfoImpl::lineEntryIsSane(FileAndLocation DL,
2614
2617
}
2615
2618
#endif
2616
2619
2620
+ IRGenDebugInfoImpl::FileAndLocation
2621
+ IRGenDebugInfoImpl::computeLLVMLoc (const SILDebugScope *DS, SILLocation Loc) {
2622
+ // NOTE: In CodeView, zero is not an artificial line location. We try to
2623
+ // avoid those line locations near user code to reduce the number
2624
+ // of breaks in the linetables.
2625
+ SILFunction *Fn = DS->getInlinedFunction ();
2626
+ if (Fn && (Fn->isThunk () || Fn->isTransparent ()))
2627
+ return {0 , 0 , CompilerGeneratedFile};
2628
+
2629
+ // Reuse the last source location if we are still in the same scope to get a
2630
+ // more contiguous line table.
2631
+ if (DS == LastScope && Loc.isHiddenFromDebugInfo ())
2632
+ return LastFileAndLocation;
2633
+
2634
+ // If the scope has not changed and the line number is either zero or
2635
+ // artificial, we want to keep the most recent debug location.
2636
+ if (DS == LastScope &&
2637
+ (Loc.is <ArtificialUnreachableLocation>() || Loc.isLineZero (SM)) &&
2638
+ Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2639
+ return LastFileAndLocation;
2640
+
2641
+ FileAndLocation L;
2642
+ // Decode the location.
2643
+ if (!Loc.isInPrologue () ||
2644
+ Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2645
+ L = decodeFileAndLocation (Loc);
2646
+
2647
+ // Otherwise use a line 0 artificial location, but the file from the
2648
+ // location. If we are emitting CodeView, we do not want to use line zero
2649
+ // since it does not represent an artificial line location.
2650
+ if (Loc.isHiddenFromDebugInfo () &&
2651
+ Opts.DebugInfoFormat != IRGenDebugInfoFormat::CodeView) {
2652
+ L.Line = 0 ;
2653
+ L.Column = 0 ;
2654
+ }
2655
+
2656
+ return L;
2657
+ }
2658
+
2617
2659
void IRGenDebugInfoImpl::setCurrentLoc (IRBuilder &Builder,
2618
2660
const SILDebugScope *DS,
2619
2661
SILLocation Loc) {
@@ -2622,38 +2664,7 @@ void IRGenDebugInfoImpl::setCurrentLoc(IRBuilder &Builder,
2622
2664
if (!Scope)
2623
2665
return ;
2624
2666
2625
- // NOTE: In CodeView, zero is not an artificial line location. We try to
2626
- // avoid those line locations near user code to reduce the number
2627
- // of breaks in the linetables.
2628
- FileAndLocation L;
2629
- SILFunction *Fn = DS->getInlinedFunction ();
2630
- if (Fn && (Fn->isThunk () || Fn->isTransparent ())) {
2631
- L = {0 , 0 , CompilerGeneratedFile};
2632
- } else if (DS == LastScope && Loc.isHiddenFromDebugInfo ()) {
2633
- // Reuse the last source location if we are still in the same
2634
- // scope to get a more contiguous line table.
2635
- L = LastFileAndLocation;
2636
- } else if (DS == LastScope &&
2637
- (Loc.is <ArtificialUnreachableLocation>() || Loc.isLineZero (SM)) &&
2638
- Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView) {
2639
- // If the scope has not changed and the line number is either zero or
2640
- // artificial, we want to keep the most recent debug location.
2641
- L = LastFileAndLocation;
2642
- } else {
2643
- // Decode the location.
2644
- if (!Loc.isInPrologue () ||
2645
- Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2646
- L = decodeFileAndLocation (Loc);
2647
-
2648
- // Otherwise use a line 0 artificial location, but the file from the
2649
- // location. If we are emitting CodeView, we do not want to use line zero
2650
- // since it does not represent an artificial line location.
2651
- if (Loc.isHiddenFromDebugInfo () &&
2652
- Opts.DebugInfoFormat != IRGenDebugInfoFormat::CodeView) {
2653
- L.Line = 0 ;
2654
- L.Column = 0 ;
2655
- }
2656
- }
2667
+ FileAndLocation L = computeLLVMLoc (DS, Loc);
2657
2668
2658
2669
if (L.getFilename () != Scope->getFilename ()) {
2659
2670
// We changed files in the middle of a scope. This happens, for
0 commit comments