[Preprocessor] -E -P: Ensure newline after 8 skipped lines.
authorMichael Kruse <llvm-project@meinersbur.de>
Thu, 29 Jul 2021 03:01:14 +0000 (22:01 -0500)
committerMichael Kruse <llvm-project@meinersbur.de>
Thu, 29 Jul 2021 03:50:54 +0000 (22:50 -0500)
commitc6b0b16c0f55c34f4eaa05184815bbbe97f4b750
treee32ad2f1b2058d643966ab09280483715d7366b5
parent768f56264150ad20f0d1416314a0affafb55bd0f
[Preprocessor] -E -P: Ensure newline after 8 skipped lines.

The implementation of -fminimize-whitespace (D104601) revised the logic
when to emit newlines. There was no case to handle when more than
8 lines were skippped in -P (DisableLineMarkers) mode and instead fell
through the case intended for -fminimize-whitespace, i.e. emit nothing.
This patch will emit one newline in this case.

The newline logic is slightly reorganized. The `-P -fminimize-whitespace`
case is handled explicitly and emitting at least one newline is the new
fallback case. The choice between emitting a line marker or up to
7 empty lines is now a choice only with enabled line markers. The up to
8 newlines likely are fewer characters than a line directive, but
in -P mode this had the paradoxic effect that it would print up to
7 empty lines, but none at all if more than 8 lines had to be skipped.
Now with DisableLineMarkers, we don't consider printing empty lines
(just start a new line) which matches gcc's behavior.

The line-directive-output-mincol.c test is replaced with a more
comprehensive test skip-empty-lines.c also testing the more than
8 skipped lines behaviour with all flag combinations.

Reviewed By: aaron.ballman

Differential Revision: https://reviews.llvm.org/D106924
clang/lib/Frontend/PrintPreprocessedOutput.cpp
clang/test/Preprocessor/line-directive-output-mincol.c [deleted file]
clang/test/Preprocessor/minimize-whitespace.c
clang/test/Preprocessor/skip-empty-lines.c [new file with mode: 0644]