All of lore.kernel.org
 help / color / mirror / Atom feed
From: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
To: linux-sparse@vger.kernel.org
Cc: Christopher Li <sparse@chrisli.org>,
	Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
Subject: [PATCH v4 6/6] move 'extern with initializer' validation after the validate method
Date: Sun,  5 Mar 2017 20:21:52 +0100	[thread overview]
Message-ID: <20170305192152.67931-7-luc.vanoostenryck@gmail.com> (raw)
In-Reply-To: <20170305192152.67931-1-luc.vanoostenryck@gmail.com>

Before the call to the method external_decl::validate_decl()
there is another validation done which check if the declaration
linkage is not external, otherwise an error is issued and the
'extern' is removed from the declaration.

While also valid for C99 for-loop initializer, this is less
desirable because in this context, 'extern' is invalid anyway
and removing it from the declaration make it imposible to issue
a diagnostic about it.

Fix this by moving the 'extern with initializer' check after the
call to validate_decl() method, where it is always pertinent and
so allowing process_for_loop_decl() to make its own diagnostic.

Signed-off-by: Luc Van Oostenryck <luc.vanoostenryck@gmail.com>
---
 parse.c                        | 9 +++++----
 validation/c99-for-loop-decl.c | 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/parse.c b/parse.c
index 6ec1bab97..80f0337cc 100644
--- a/parse.c
+++ b/parse.c
@@ -2890,16 +2890,17 @@ struct token *external_declaration(struct token *token, struct symbol_list **lis
 
 	for (;;) {
 		if (!is_typedef && match_op(token, '=')) {
-			if (decl->ctype.modifiers & MOD_EXTERN) {
-				warning(decl->pos, "symbol with external linkage has initializer");
-				decl->ctype.modifiers &= ~MOD_EXTERN;
-			}
 			token = initializer(&decl->initializer, token->next);
 		}
 		if (!is_typedef) {
 			if (validate_decl)
 				validate_decl(decl);
 
+			if (decl->initializer && decl->ctype.modifiers & MOD_EXTERN) {
+				warning(decl->pos, "symbol with external linkage has initializer");
+				decl->ctype.modifiers &= ~MOD_EXTERN;
+			}
+
 			if (!(decl->ctype.modifiers & (MOD_EXTERN | MOD_INLINE))) {
 				add_symbol(list, decl);
 				fn_local_symbol(decl);
diff --git a/validation/c99-for-loop-decl.c b/validation/c99-for-loop-decl.c
index e813b0ae3..d382d3c9b 100644
--- a/validation/c99-for-loop-decl.c
+++ b/validation/c99-for-loop-decl.c
@@ -32,7 +32,7 @@ static int c99(void)
  * check-name: C99 for-loop declarations
  *
  * check-error-start
-c99-for-loop-decl.c:22:27: warning: symbol with external linkage has initializer
+c99-for-loop-decl.c:22:27: error: non-local var 'l' in for-loop initializer
 c99-for-loop-decl.c:24:27: error: non-local var 'm' in for-loop initializer
 c99-for-loop-decl.c:26:27: error: non-local var 'n' in for-loop initializer
 c99-for-loop-decl.c:9:16: error: undefined identifier 'i'
-- 
2.11.1


  parent reply	other threads:[~2017-03-05 19:22 UTC|newest]

Thread overview: 45+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-02-18 20:30 [PATCH 0/5] more validation of C99 for-loop initializers Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 1/5] replace test for c99 " Luc Van Oostenryck
2017-02-18 22:37   ` Ramsay Jones
2017-02-19  1:10     ` Luc Van Oostenryck
2017-02-19 20:58       ` Ramsay Jones
2017-02-20  7:20         ` [PATCH v2 0/5] more validation of C99 " Luc Van Oostenryck
2017-02-20  7:20           ` [PATCH v2 1/5] replace test for c99 " Luc Van Oostenryck
2017-02-20 14:05             ` Ramsay Jones
2017-02-20  7:20           ` [PATCH v2 2/5] add test case for scope of C99 for-loop declarations Luc Van Oostenryck
2017-02-20  7:20           ` [PATCH v2 3/5] add test cases for storage of c99 " Luc Van Oostenryck
2017-02-20  7:20           ` [PATCH v2 4/5] add a method to external_declaration() Luc Van Oostenryck
2017-02-20  7:20           ` [PATCH v2 5/5] check the storage of C99 for-loop initializers Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 2/5] add test case for scope of C99 for-loop declarations Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 3/5] add test cases for storage of c99 " Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 4/5] add a method to external_declaration() Luc Van Oostenryck
2017-02-27 15:37   ` Christopher Li
2017-02-27 21:34     ` Luc Van Oostenryck
2017-02-28  9:46     ` Luc Van Oostenryck
2017-02-28 10:03       ` [PATCH v3 0/7] more validation of C99 for-loop initializers Luc Van Oostenryck
2017-02-28 10:03         ` [PATCH v3 1/7] replace test for c99 " Luc Van Oostenryck
2017-02-28 10:03         ` [PATCH v3 2/7] add test case for scope of C99 for-loop declarations Luc Van Oostenryck
2017-02-28 10:03         ` [PATCH v3 3/7] add test cases for storage of c99 " Luc Van Oostenryck
2017-02-28 10:04         ` [PATCH v3 4/7] add a method to external_declaration() Luc Van Oostenryck
2017-03-05 14:04           ` Christopher Li
2017-03-05 15:12             ` Luc Van Oostenryck
2017-03-06  1:13               ` Christopher Li
2017-03-05 19:21             ` [PATCH v4 0/6] more validation of C99 for-loop initializers Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 1/6] replace test for c99 " Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 2/6] add test case for scope of C99 for-loop declarations Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 3/6] add test cases for storage of c99 " Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 4/6] add an optional validation method to external_declaration() Luc Van Oostenryck
2017-03-05 19:21               ` [PATCH v4 5/6] check the storage of C99 for-loop initializers Luc Van Oostenryck
2017-03-05 19:21               ` Luc Van Oostenryck [this message]
2017-03-06  0:59               ` [PATCH v4 0/6] more validation " Christopher Li
2017-03-06  1:08                 ` Luc Van Oostenryck
2017-02-28 10:04         ` [PATCH v3 5/7] check the storage " Luc Van Oostenryck
2017-03-05 14:26           ` Christopher Li
2017-03-05 15:24             ` Luc Van Oostenryck
2017-02-28 10:04         ` [PATCH v3 6/7] make process_decl() aware of the presence of an initializer Luc Van Oostenryck
2017-03-05 14:49           ` Christopher Li
2017-03-05 15:29             ` Luc Van Oostenryck
2017-02-28 10:04         ` [PATCH v3 7/7] move check extern with initializer to default_process_decl() Luc Van Oostenryck
2017-02-28 16:34         ` [PATCH v3 0/7] more validation of C99 for-loop initializers Christopher Li
2017-02-28 16:40           ` Luc Van Oostenryck
2017-02-18 20:30 ` [PATCH 5/5] check the storage " Luc Van Oostenryck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170305192152.67931-7-luc.vanoostenryck@gmail.com \
    --to=luc.vanoostenryck@gmail.com \
    --cc=linux-sparse@vger.kernel.org \
    --cc=sparse@chrisli.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.