r315953 - Don't print end-of-directive tokens in -E output

Reid Kleckner via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 16 16:07:15 PDT 2017


Author: rnk
Date: Mon Oct 16 16:07:15 2017
New Revision: 315953

URL: http://llvm.org/viewvc/llvm-project?rev=315953&view=rev
Log:
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

Added:
    cfe/trunk/test/Preprocessor/print-assembler.s
Modified:
    cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp

Modified: cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp?rev=315953&r1=315952&r2=315953&view=diff
==============================================================================
--- cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp (original)
+++ cfe/trunk/lib/Frontend/PrintPreprocessedOutput.cpp Mon Oct 16 16:07:15 2017
@@ -720,6 +720,12 @@ static void PrintPreprocessedTokens(Prep
       // -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.

Added: cfe/trunk/test/Preprocessor/print-assembler.s
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/print-assembler.s?rev=315953&view=auto
==============================================================================
--- cfe/trunk/test/Preprocessor/print-assembler.s (added)
+++ cfe/trunk/test/Preprocessor/print-assembler.s Mon Oct 16 16:07:15 2017
@@ -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




More information about the cfe-commits mailing list