Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit f98dea1

Browse files
committed
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 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@315953 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 73c1500 commit f98dea1

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

lib/Frontend/PrintPreprocessedOutput.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -720,6 +720,12 @@ static void PrintPreprocessedTokens(Preprocessor &PP, Token &Tok,
720720
// -traditional-cpp the lexer keeps /all/ whitespace, including comments.
721721
SourceLocation StartLoc = Tok.getLocation();
722722
Callbacks->MoveToLine(StartLoc.getLocWithOffset(Tok.getLength()));
723+
} else if (Tok.is(tok::eod)) {
724+
// Don't print end of directive tokens, since they are typically newlines
725+
// that mess up our line tracking. These come from unknown pre-processor
726+
// directives or hash-prefixed comments in standalone assembly files.
727+
PP.Lex(Tok);
728+
continue;
723729
} else if (Tok.is(tok::annot_module_include)) {
724730
// PrintPPOutputPPCallbacks::InclusionDirective handles producing
725731
// appropriate output here. Ignore this token entirely.

test/Preprocessor/print-assembler.s

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// RUN: %clang_cc1 -E -x assembler-with-cpp %s -o - | FileCheck %s --strict-whitespace
2+
3+
.intel_syntax noprefix
4+
.text
5+
.global _main
6+
_main:
7+
# asdf
8+
# asdf
9+
mov bogus_name, 20
10+
mov rax, 5
11+
ret
12+
13+
// CHECK-LABEL: _main:
14+
// CHECK-NEXT: {{^}} # asdf
15+
// CHECK-NEXT: {{^}} # asdf
16+
// CHECK-NEXT: mov bogus_name, 20

0 commit comments

Comments
 (0)