[llvm] [DWARF] Emit a worst-case prologue_end flag for pathological inputs (PR #107849)

Jeremy Morse via llvm-commits llvm-commits at lists.llvm.org
Mon Nov 11 08:27:48 PST 2024


================
@@ -2192,12 +2279,20 @@ DwarfDebug::emitInitialLocDirective(const MachineFunction &MF, unsigned CUID) {
   bool IsEmptyPrologue = PrologEnd.second;
 
   // If the prolog is empty, no need to generate scope line for the proc.
-  if (IsEmptyPrologue)
+  if (IsEmptyPrologue) {
     // In degenerate cases, we can have functions with no source locations
-    // at all. These want a scope line, to avoid a totally empty function.
-    // Thus, only skip scope line if there's location to place prologue_end.
-    if (PrologEndLoc)
-      return PrologEndLoc;
+    // at all, or only empty ones. These want a scope line, to avoid a totally
+    // empty function. Thus, only skip the scope line if there's location to
+    // place prologue_end.
+    if (PrologEndLoc) {
+      const DebugLoc &DL = PrologEndLoc->getDebugLoc();
+      if (!DL || DL->getLine() != 0)
----------------
jmorse wrote:

I guess it's not clear that the real purpose is simply filtering out line-zero-locations -- those with an _empty_ DebugLoc get given the scope line due to an earlier patch. (It's unfortunate that we've got "empty" nullptr DebugLocs, but also "empty" source locations in the form of line-zero, but here we are).

Without this awkward logic we would end up with zero-length linetable entries for the scope line, before then having a prologue_end linetable entry.

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


More information about the llvm-commits mailing list