[llvm] [DWARF] Emit line 0 source locations for BB padding nops (PR #99496)

Nabeel Omer via llvm-commits llvm-commits at lists.llvm.org
Sat Jul 20 11:11:21 PDT 2024


================
@@ -3668,3 +3668,19 @@ bool DwarfDebug::alwaysUseRanges(const DwarfCompileUnit &CU) const {
     return true;
   return false;
 }
+
+void DwarfDebug::beginCodeAlignment(const MachineBasicBlock &MBB) {
+  auto *SP = MBB.getParent()->getFunction().getSubprogram();
+
+  bool NoDebug =
+      !SP || SP->getUnit()->getEmissionKind() == DICompileUnit::NoDebug;
+
+  if (NoDebug)
+    return;
+
+  auto PrevLoc = Asm->OutStreamer->getContext().getCurrentDwarfLoc();
+  Asm->OutStreamer->emitDwarfLocDirective(
----------------
omern1 wrote:

I think you're right. We control whether or not we call `beginCodeAlignment` in [this](https://github.com/llvm/llvm-project/pull/99496/files#diff-17b326b45ef392288420bed274616afa7df81b27576c96723b3c25f5198dc398R3969) `if` block but if other users call `beginCodeAlignment` unconditionally they would end up with a line 0 `.loc` immediately followed by the correct `.loc`.

The function is named `beginCodeAlignment` so one may argue you should only call it when emitting alignment nops but on the other hand we can easily move the [`if` block](https://github.com/llvm/llvm-project/pull/99496/files#diff-17b326b45ef392288420bed274616afa7df81b27576c96723b3c25f5198dc398R3969) into `beginCodeAlignment` so I'll do that.

https://github.com/llvm/llvm-project/pull/99496


More information about the llvm-commits mailing list