Skip to content

[META] Fix as many instructions with missing DebugLoc as possible. #24211

Open
@llvmbot

Description

@llvmbot
Bugzilla Link 23837
Version trunk
OS Linux
Reporter LLVM Bugzilla Contributor
CC @dwblaikie,@echristo,@eugenis,@pogo59

Extended Description

Generally, LLVM does very bad job in ensuring that, when debug info is enabled (-gline-tables-only or above), all necessary([1]) instructions indeed have DebugLoc attached to them, or that DebugLoc are preserved as we transform the code. For example:

  • DebugLoc can be easily missed as we split/rearrange basic blocks.
  • Synthesized instructions in GVN, SCEV etc. often have no debug info.

Once we have an instruction I with no DebugLoc, this "missing" DebugLoc would propagate through the program - e.g. every time we construct IRBuilder<> with I as insertion point, it will fail to set correct DebugLoc for instructions it creates.

This is painful - with optimizations enabled, we may often fail to provide reasonable line info for instructions, or (worse case, which often happens) incorrectly return line info for some preceding instruction which happened
to have DebugLoc, but may be completely irrelevant (e.g. come from a
different inlined subroutine).

I've did several improvements recently:
http://llvm.org/viewvc/llvm-project?rev=239438&view=rev
http://llvm.org/viewvc/llvm-project?rev=239479&view=rev
http://llvm.org/viewvc/llvm-project?rev=239550&view=rev
http://llvm.org/viewvc/llvm-project?rev=239551&view=rev
http://llvm.org/viewvc/llvm-project?rev=239584&view=rev
http://llvm.org/viewvc/llvm-project?rev=239585&view=rev
http://llvm.org/viewvc/llvm-project?rev=239643&view=rev

But there are many more cases to fix, and even if we fix them all,
we should be able to somehow prevent further breakages.

  • We can improve API for creating new instructions that would force callers
    to set DebugLoc (or explicitly pass empty one, promising to set it up later).
  • Add module verifier check that would enforce that if function has some
    attached DebugLocs, then all ([1]) instruction should have them.
  • Add asserts to places where we believe DebugLoc should always be present if
    line tables are enabled (e.g. we need it in SanitizerCoverage pass where
    we know that PCs of certain instructions would be collected, and possibly
    symbolized later).
  • Some combination of above.

Notes:
[1] - Function prologue instructions (alloca's etc.) intentionally have no DebugLoc. PHI nodes sometimes do have them, but it's not clear whether there's a contract of some sort. Many users actually call BB->getFirstNonPHI()->getDebugLoc() to get the "entry" debug location, probably because they believe it will be the first insertion point / non-transient instruction.

Metadata

Metadata

Assignees

Labels

bugzillaIssues migrated from bugzilladebuginfometaissueIssue to collect references to a group of similar or related issues.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions