summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorReid Kleckner <rnk@google.com>2017-10-16 23:07:15 +0000
committerReid Kleckner <rnk@google.com>2017-10-16 23:07:15 +0000
commit400a64e81b5a297f88a789573c89fe08c60bf914 (patch)
treef07f40d074efcf6a8ae4ce46be534978fae15694
parentcf3ab11caa9bf21fbe9ea7e1c300d8f60c320f4d (diff)
downloadbcm5719-llvm-400a64e81b5a297f88a789573c89fe08c60bf914.tar.gz
bcm5719-llvm-400a64e81b5a297f88a789573c89fe08c60bf914.zip
Don't print end-of-directive tokens in -E output
This comes up when pre-processing standalone .s files containing hash-prefixed comments. The pre-processor should skip the unknown directive and not emit an extra newline as we were doing. Fixes PR34950 llvm-svn: 315953
-rw-r--r--clang/lib/Frontend/PrintPreprocessedOutput.cpp6
-rw-r--r--clang/test/Preprocessor/print-assembler.s16
2 files changed, 22 insertions, 0 deletions
diff --git a/clang/lib/Frontend/PrintPreprocessedOutput.cpp b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
index 8ae9038316c..2e023294f1e 100644
--- a/clang/lib/Frontend/PrintPreprocessedOutput.cpp
+++ b/clang/lib/Frontend/PrintPreprocessedOutput.cpp
@@ -720,6 +720,12 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
// -traditional-cpp the lexer keeps /all/ whitespace, including comments.
SourceLocation StartLoc = Tok.getLocation();
Callbacks->MoveToLine(StartLoc.getLocWithOffset(Tok.getLength()));
+ } else if (Tok.is(tok::eod)) {
+ // Don't print end of directive tokens, since they are typically newlines
+ // that mess up our line tracking. These come from unknown pre-processor
+ // directives or hash-prefixed comments in standalone assembly files.
+ PP.Lex(Tok);
+ continue;
} else if (Tok.is(tok::annot_module_include)) {
// PrintPPOutputPPCallbacks::InclusionDirective handles producing
// appropriate output here. Ignore this token entirely.
diff --git a/clang/test/Preprocessor/print-assembler.s b/clang/test/Preprocessor/print-assembler.s
new file mode 100644
index 00000000000..c4e2e031f2d
--- /dev/null
+++ b/clang/test/Preprocessor/print-assembler.s
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 -E -x assembler-with-cpp %s -o - | FileCheck %s --strict-whitespace
+
+.intel_syntax noprefix
+.text
+ .global _main
+_main:
+# asdf
+# asdf
+ mov bogus_name, 20
+ mov rax, 5
+ ret
+
+// CHECK-LABEL: _main:
+// CHECK-NEXT: {{^}} # asdf
+// CHECK-NEXT: {{^}} # asdf
+// CHECK-NEXT: mov bogus_name, 20
OpenPOWER on IntegriCloud