]> granicus.if.org Git - clang/commitdiff
Don't print end-of-directive tokens in -E output
authorReid Kleckner <rnk@google.com>
Mon, 16 Oct 2017 23:07:15 +0000 (23:07 +0000)
committerReid Kleckner <rnk@google.com>
Mon, 16 Oct 2017 23:07:15 +0000 (23:07 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315953 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Frontend/PrintPreprocessedOutput.cpp
test/Preprocessor/print-assembler.s [new file with mode: 0644]

index 8ae9038316c2c8da1a7daefcb02ca4516bf574f1..2e023294f1e8e8a43fe6cf57cf81d34984d64c22 100644 (file)
@@ -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/test/Preprocessor/print-assembler.s b/test/Preprocessor/print-assembler.s
new file mode 100644 (file)
index 0000000..c4e2e03
--- /dev/null
@@ -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