[PATCH] D106924: [Preprocessor] -E -P: Ensure newline after 8 skipped lines.

Michael Kruse via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Jul 27 17:02:18 PDT 2021


Meinersbur created this revision.
Meinersbur added reviewers: aaron.ballman, mstorsjo, dblaikie.
Meinersbur added a project: clang.
Meinersbur requested review of this revision.

The implementation of -fminimize-whitespace (D104601 <https://reviews.llvm.org/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 `-fminimize-whitespace` case is handled explicitly and the emit at least one newline is the new fallback case. Without `DisableLineMarkers`, there is the choice between emitting a line marker or up to 8 empty lines. 
The up to 8 newlines likely are fewer characters that 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. With `DisableLineMarkers`, we now don't consider printing empty lines (just start a new line) which matches gcc's behaviour.

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


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106924

Files:
  clang/lib/Frontend/PrintPreprocessedOutput.cpp
  clang/test/Preprocessor/line-directive-output-mincol.c
  clang/test/Preprocessor/minimize-whitespace.c
  clang/test/Preprocessor/skip-empty-lines.c

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106924.362219.patch
Type: text/x-patch
Size: 5599 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210728/372cd24a/attachment.bin>


More information about the cfe-commits mailing list