[PATCH] D80381: Fix debug line info when line markers are present inside macros.

Leandro Vaz via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu May 21 09:09:07 PDT 2020


leandrov created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
leandrov updated this revision to Diff 265513.
leandrov added a comment.

Moved the test case to AsmParser tests.



================
Comment at: llvm/lib/MC/MCParser/AsmParser.cpp:1705
+      return parseCppHashLineFilenameComment(IDLoc);
+    // Eat the line marker.
+    Lex();
----------------
Is there code inside parseCppHashLineFilenameComment that could be hoisted out in a separate function that could be used here? If not, maybe you could create a function anyway which would make the code here smaller and more obvious.

Might be nice having in the heading comment for that function the format of a line marker: # linenum filename flags. I don't know if it's customary to refer to documentation for a format when it's an online page, but if it is you could mention https://gcc.gnu.org/onlinedocs/cpp/Preprocessor-Output.html in that heading comment.


Compiling assembly files when newlines are reduced to line markers within a `.macro` context will generate wrong information in `.debug_line` section.
This patch fixes this issue by evaluating line markers within the macro scope but not when they are used and evaluated.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D80381

Files:
  llvm/lib/MC/MCParser/AsmParser.cpp
  llvm/test/MC/AsmParser/line-marker-inside-macro.s


Index: llvm/test/MC/AsmParser/line-marker-inside-macro.s
===================================================================
--- /dev/null
+++ llvm/test/MC/AsmParser/line-marker-inside-macro.s
@@ -0,0 +1,14 @@
+// RUN: llvm-mc -triple i386-unknown-unknown --filetype=obj -g %s -o %t
+// RUN: llvm-dwarfdump -a %t | FileCheck %s
+
+.macro FOO
+# 100 "./line-marker-inside-macro.s"
+.endm
+
+
+
+FOO
+  mov %eax, 0
+
+// CHECK:      0x0000000000000000 105 0 1 0 0 is_stmt
+// CHECK-NEXT: 0x0000000000000005 105 0 1 0 0 is_stmt end_sequence
Index: llvm/lib/MC/MCParser/AsmParser.cpp
===================================================================
--- llvm/lib/MC/MCParser/AsmParser.cpp
+++ llvm/lib/MC/MCParser/AsmParser.cpp
@@ -1698,8 +1698,20 @@
   SMLoc IDLoc = ID.getLoc();
   StringRef IDVal;
   int64_t LocalLabelVal = -1;
-  if (Lexer.is(AsmToken::HashDirective))
-    return parseCppHashLineFilenameComment(IDLoc);
+  if (Lexer.is(AsmToken::HashDirective)) {
+    // Do not evaluate line markers during instantiation.
+    if (!isInsideMacroInstantiation())
+      return parseCppHashLineFilenameComment(IDLoc);
+    // Eat the line marker.
+    Lex();
+    assert(getTok().is(AsmToken::Integer) &&
+           "Lexing Cpp line comment: Expected Integer");
+    Lex();
+    assert(getTok().is(AsmToken::String) &&
+           "Lexing Cpp line comment: Expected String");
+    Lex();
+    return false;
+  }
   // Allow an integer followed by a ':' as a directional local label.
   if (Lexer.is(AsmToken::Integer)) {
     LocalLabelVal = getTok().getIntVal();
@@ -4454,7 +4466,8 @@
     if (getLexer().is(AsmToken::Eof))
       return Error(DirectiveLoc, "no matching '.endmacro' in definition");
 
-    // Otherwise, check whether we have reach the .endmacro.
+    // Otherwise, check whether we have reach the .endmacro or the start of a
+    // preprocessor line marker.
     if (getLexer().is(AsmToken::Identifier)) {
       if (getTok().getIdentifier() == ".endm" ||
           getTok().getIdentifier() == ".endmacro") {
@@ -4474,6 +4487,8 @@
         // macro is expanded so just ignore them for now.
         ++MacroDepth;
       }
+    } else if (Lexer.is(AsmToken::HashDirective)) {
+      (void)parseCppHashLineFilenameComment(getLexer().getLoc());
     }
 
     // Otherwise, scan til the end of the statement.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D80381.265513.patch
Type: text/x-patch
Size: 2330 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200521/380c133b/attachment.bin>


More information about the llvm-commits mailing list