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