-
Notifications
You must be signed in to change notification settings - Fork 10.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[DebugInfo] Change lowering of SIL instructions to use line 0 when appropriate #77655
base: main
Are you sure you want to change the base?
[DebugInfo] Change lowering of SIL instructions to use line 0 when appropriate #77655
Conversation
With [0], more accurate line numbers are generated; as such, some LLDB tests need to be updated. [0]: swiftlang/swift#77655
@@ -341,6 +341,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { | |||
IRGenDebugInfoFormat getDebugInfoFormat() { return Opts.DebugInfoFormat; } | |||
|
|||
private: | |||
FileAndLocation computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
short Doxygen comment?
@@ -342,6 +342,8 @@ class IRGenDebugInfoImpl : public IRGenDebugInfo { | |||
|
|||
private: | |||
FileAndLocation computeLLVMLoc(const SILDebugScope *DS, SILLocation Loc); | |||
FileAndLocation computeLLVMLocCodeView(const SILDebugScope *DS, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and here
lib/IRGen/IRGenDebugInfo.cpp
Outdated
@@ -2613,11 +2615,24 @@ bool IRGenDebugInfoImpl::lineEntryIsSane(FileAndLocation DL, | |||
} | |||
#endif | |||
|
|||
/// In CodeView, zero is not an artificial line location. We try to avoid those | |||
/// line locations near user code to reduce the number of breaks in the | |||
/// linetables. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be in the declaration I think
The actual change looks good! |
This patch moves, into its own function, the code computing a `FileAndLocation` for the instruction being lowered (SIL>LLVM IR). Control flows is simplified as a result.
CodeView has its own needs / limitations for representing line 0. However, this is adding control flow complexities that make changing the underlying logic complicated for both cases. Furthermore, the limitations above may be temporary if we change LLVM's backend; by having a separate function, we can, in the future, easily unify the code paths in the future by deleting the function.
Prior to this commit, when lowering SIL instructions that should are "hidden" for the purposes of debugging, the compiler just attaches the location of the previous instruction in the name of keeping a simpler line table. However, this is wrong for many reasons. One such reason is this: at the start of a basic block, inheriting the previous debug location will almost certainly cause the instruction to have a random location in the code, as it will depend on whatever BB was visited previously. Other examples can be seen in the tests affect by this commit, which changes lowering to use Line 0 instead of the line number of the previous instruction. CodeView doesn't handle line 0 the same way DWARF does, so this commit preserves the old behavior for the CodeView path. rdar://139826231&110187845
6f8db75
to
fc35afc
Compare
addressed review comments |
swiftlang/llvm-project#9614 |
This patch performs two NFC refactors to make the code control flow legible, and then fixes an issue where incorrect line numbers causes poor debugging experience.