From 6e5fbe9870a8a593230a16cafc2de69aa2b91f78 Mon Sep 17 00:00:00 2001 From: Luc Van Oostenryck Date: Thu, 12 Mar 2020 02:01:34 +0100 Subject: cpp: remove extra newlines during macro expansion During macro expansion, Sparse doesn't strip newlines from the arguments as required by 6.10.3p10 and done by gcc & clang. So, remove these newlines. Note: the current behaviour may make the preprocessed output more readable (and so may be considered as a feature). Signed-off-by: Luc Van Oostenryck --- pre-process.c | 1 + validation/preprocessor/directive-within-macro.c | 8 ++------ validation/preprocessor/expand-and-nl.c | 13 +++++++++++++ validation/preprocessor/preprocessor22.c | 4 +--- 4 files changed, 17 insertions(+), 9 deletions(-) create mode 100644 validation/preprocessor/expand-and-nl.c diff --git a/pre-process.c b/pre-process.c index a5a3c5fb..f2053676 100644 --- a/pre-process.c +++ b/pre-process.c @@ -309,6 +309,7 @@ static struct token *collect_arg(struct token *prev, int vararg, struct position next->pos.stream = pos->stream; next->pos.line = pos->line; next->pos.pos = pos->pos; + next->pos.newline = 0; p = &next->next; } *p = &eof_token_entry; diff --git a/validation/preprocessor/directive-within-macro.c b/validation/preprocessor/directive-within-macro.c index 5269d4a7..4562078a 100644 --- a/validation/preprocessor/directive-within-macro.c +++ b/validation/preprocessor/directive-within-macro.c @@ -26,12 +26,8 @@ f(1 * * check-output-start -1 -a -d -3 -1 -3 +1 a d 3 +1 3 * check-output-end * * check-error-start diff --git a/validation/preprocessor/expand-and-nl.c b/validation/preprocessor/expand-and-nl.c new file mode 100644 index 00000000..1a5f2265 --- /dev/null +++ b/validation/preprocessor/expand-and-nl.c @@ -0,0 +1,13 @@ +#define M(X) X-X + +M(a +b) +/* + * check-name: expand-and-nl + * check-command: sparse -E $file + * + * check-output-start + +a b-a b + * check-output-end + */ diff --git a/validation/preprocessor/preprocessor22.c b/validation/preprocessor/preprocessor22.c index 11f625c0..0d13c5f8 100644 --- a/validation/preprocessor/preprocessor22.c +++ b/validation/preprocessor/preprocessor22.c @@ -28,8 +28,6 @@ preprocessor/preprocessor22.c:12:1: warning: directive in macro's argument list * * check-output-start -struct { -int b; -} a;; +struct { int b; } a;; * check-output-end */ -- cgit 1.2.3-korg