@@ -347,6 +347,12 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo {
347347 // / Convert a SILLocation into the corresponding LLVM Loc.
348348 FileAndLocation computeLLVMLoc (const SILDebugScope *DS, SILLocation Loc);
349349
350+ // / Compute the LLVM DebugLoc when targeting CodeView. In CodeView, zero is
351+ // / not an artificial line location; attempt to avoid those line locations near
352+ // / user code to reduce the number of breaks in the linetables.
353+ FileAndLocation computeLLVMLocCodeView (const SILDebugScope *DS,
354+ SILLocation Loc);
355+
350356 static StringRef getFilenameFromDC (const DeclContext *DC) {
351357 if (auto *LF = dyn_cast<LoadedFile>(DC))
352358 return LF->getFilename ();
@@ -2617,11 +2623,21 @@ bool IRGenDebugInfoImpl::lineEntryIsSane(FileAndLocation DL,
26172623}
26182624#endif
26192625
2626+ IRGenDebugInfoImpl::FileAndLocation
2627+ IRGenDebugInfoImpl::computeLLVMLocCodeView (const SILDebugScope *DS,
2628+ SILLocation Loc) {
2629+ // If the scope has not changed and the line number is either zero or
2630+ // artificial, we want to keep the most recent debug location.
2631+ if (DS == LastScope &&
2632+ (Loc.is <ArtificialUnreachableLocation>() || Loc.isLineZero (SM)))
2633+ return LastFileAndLocation;
2634+
2635+ // Decode the location.
2636+ return decodeFileAndLocation (Loc);
2637+ }
2638+
26202639IRGenDebugInfoImpl::FileAndLocation
26212640IRGenDebugInfoImpl::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.
26252641 SILFunction *Fn = DS->getInlinedFunction ();
26262642 if (Fn && (Fn->isThunk () || Fn->isTransparent ()))
26272643 return {0 , 0 , CompilerGeneratedFile};
@@ -2631,24 +2647,14 @@ IRGenDebugInfoImpl::computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc) {
26312647 if (DS == LastScope && Loc.isHiddenFromDebugInfo ())
26322648 return LastFileAndLocation;
26332649
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;
2650+ if (Opts.DebugInfoFormat == IRGenDebugInfoFormat::CodeView)
2651+ return computeLLVMLocCodeView (DS, Loc);
26402652
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) {
2653+ FileAndLocation L =
2654+ Loc.isInPrologue () ? FileAndLocation () : decodeFileAndLocation (Loc);
2655+
2656+ // Otherwise use a line 0 artificial location, but the file from the location.
2657+ if (Loc.isHiddenFromDebugInfo ()) {
26522658 L.Line = 0 ;
26532659 L.Column = 0 ;
26542660 }
0 commit comments