llvm/clang/test/Preprocessor/minimize-whitespace.c
Michael Kruse c6b0b16c0f [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
2021-07-28 22:50:54 -05:00

62 lines
2.4 KiB
C

// RUN: %clang_cc1 -fminimize-whitespace -E %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCOL
// RUN: %clang_cc1 -fminimize-whitespace -E -C %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCCOL
// RUN: %clang_cc1 -fminimize-whitespace -E -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINWS
// RUN: %clang_cc1 -fminimize-whitespace -E -C -P %s 2>&1 | FileCheck %s --strict-whitespace --check-prefix=MINCWS
// The follow empty lines ensure that a #line directive is emitted instead of newline padding after the RUN comments.
#define NOT_OMP omp something
#define HASH #
int a; /* span-comment */
int b ; // line-comment
_Pragma ( "omp barrier" ) x // more line-comments
#pragma omp nothing // another comment
HASH pragma NOT_OMP
int e; // again a line
int \
f ;
// MINCOL: {{^}}# 15 "{{.*}}minimize-whitespace.c"{{$}}
// MINCOL: {{^}}int a;{{$}}
// MINCOL-NEXT: {{^}}int b;{{$}}
// MINCOL-NEXT: {{^}}#pragma omp barrier{{$}}
// MINCOL-NEXT: # 17 "{{.*}}minimize-whitespace.c"
// MINCOL-NEXT: {{^}}x{{$}}
// MINCOL-NEXT: {{^}}#pragma omp nothing{{$}}
// MINCOL-NEXT: {{^ }}#pragma omp something{{$}}
// MINCOL-NEXT: {{^}}int e;{{$}}
// MINCOL-NEXT: {{^}}int f;{{$}}
// FIXME: Comments after pragmas disappear, even without -fminimize-whitespace
// MINCCOL: {{^}}# 15 "{{.*}}minimize-whitespace.c"{{$}}
// MINCCOL: {{^}}int a;/* span-comment */{{$}}
// MINCCOL-NEXT: {{^}}int b;// line-comment{{$}}
// MINCCOL-NEXT: {{^}}#pragma omp barrier{{$}}
// MINCCOL-NEXT: # 17 "{{.*}}minimize-whitespace.c"
// MINCCOL-NEXT: {{^}}x// more line-comments{{$}}
// MINCCOL-NEXT: {{^}}#pragma omp nothing{{$}}
// MINCCOL-NEXT: {{^ }}#pragma omp something{{$}}
// MINCCOL-NEXT: {{^}}int e;// again a line{{$}}
// MINCCOL-NEXT: {{^}}int f;{{$}}
// MINWS: {{^}}int a;int b;{{$}}
// MINWS-NEXT: {{^}}#pragma omp barrier{{$}}
// MINWS-NEXT: {{^}}x{{$}}
// MINWS-NEXT: {{^}}#pragma omp nothing{{$}}
// MINWS-NEXT: {{^ }}#pragma omp something int e;int f;{{$}}
// FIXME: Comments after pragmas disappear, even without -fminimize-whitespace
// MINCWS: {{^}}int a;/* span-comment */int b;// line-comment{{$}}
// MINCWS-NEXT: {{^}}#pragma omp barrier{{$}}
// MINCWS-NEXT: {{^}}x// more line-comments{{$}}
// MINCWS-NEXT: {{^}}#pragma omp nothing{{$}}
// MINCWS-NEXT: {{^ }}#pragma omp something int e;// again a line{{$}}
// MINCWS-NEXT: {{^}}int f;