[llvm] 56262a7 - Fix debug line info when line markers are present inside macros.
Thomas Preud'homme via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 16 08:13:18 PDT 2020
Author: Leandro Vaz
Date: 2020-06-16T16:13:11+01:00
New Revision: 56262a74c315f7a654915ac6053d7d5a3b4f71d7
URL: https://github.com/llvm/llvm-project/commit/56262a74c315f7a654915ac6053d7d5a3b4f71d7
DIFF: https://github.com/llvm/llvm-project/commit/56262a74c315f7a654915ac6053d7d5a3b4f71d7.diff
LOG: Fix debug line info when line markers are present inside macros.
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.
Reviewed By: probinson
Differential Revision: https://reviews.llvm.org/D80381
Added:
llvm/test/MC/AsmParser/line-marker-inside-macro.s
Modified:
llvm/lib/MC/MCParser/AsmParser.cpp
Removed:
################################################################################
diff --git a/llvm/lib/MC/MCParser/AsmParser.cpp b/llvm/lib/MC/MCParser/AsmParser.cpp
index 1cb30ae3073e..9e92ce09986f 100644
--- a/llvm/lib/MC/MCParser/AsmParser.cpp
+++ b/llvm/lib/MC/MCParser/AsmParser.cpp
@@ -267,7 +267,7 @@ class AsmParser : public MCAsmParser {
bool parseStatement(ParseStatementInfo &Info,
MCAsmParserSemaCallback *SI);
bool parseCurlyBlockScope(SmallVectorImpl<AsmRewrite>& AsmStrRewrites);
- bool parseCppHashLineFilenameComment(SMLoc L);
+ bool parseCppHashLineFilenameComment(SMLoc L, bool SaveLocInfo = true);
void checkForBadMacro(SMLoc DirectiveLoc, StringRef Name, StringRef Body,
ArrayRef<MCAsmMacroParameter> Parameters);
@@ -1699,7 +1699,9 @@ bool AsmParser::parseStatement(ParseStatementInfo &Info,
StringRef IDVal;
int64_t LocalLabelVal = -1;
if (Lexer.is(AsmToken::HashDirective))
- return parseCppHashLineFilenameComment(IDLoc);
+ return parseCppHashLineFilenameComment(IDLoc,
+ !isInsideMacroInstantiation());
+
// Allow an integer followed by a ':' as a directional local label.
if (Lexer.is(AsmToken::Integer)) {
LocalLabelVal = getTok().getIntVal();
@@ -2294,7 +2296,7 @@ AsmParser::parseCurlyBlockScope(SmallVectorImpl<AsmRewrite> &AsmStrRewrites) {
/// parseCppHashLineFilenameComment as this:
/// ::= # number "filename"
-bool AsmParser::parseCppHashLineFilenameComment(SMLoc L) {
+bool AsmParser::parseCppHashLineFilenameComment(SMLoc L, bool SaveLocInfo) {
Lex(); // Eat the hash token.
// Lexer only ever emits HashDirective if it fully formed if it's
// done the checking already so this is an internal error.
@@ -2307,6 +2309,9 @@ bool AsmParser::parseCppHashLineFilenameComment(SMLoc L) {
StringRef Filename = getTok().getString();
Lex();
+ if (!SaveLocInfo)
+ return false;
+
// Get rid of the enclosing quotes.
Filename = Filename.substr(1, Filename.size() - 2);
@@ -4454,7 +4459,8 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
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 +4480,8 @@ bool AsmParser::parseDirectiveMacro(SMLoc DirectiveLoc) {
// 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.
diff --git a/llvm/test/MC/AsmParser/line-marker-inside-macro.s b/llvm/test/MC/AsmParser/line-marker-inside-macro.s
new file mode 100644
index 000000000000..ee6ddb8f5835
--- /dev/null
+++ b/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
More information about the llvm-commits
mailing list