From patchwork Sun Mar 5 19:21:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luc Van Oostenryck X-Patchwork-Id: 9604751 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 46571604E2 for ; Sun, 5 Mar 2017 19:22:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2781C27F8C for ; Sun, 5 Mar 2017 19:22:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C6AC27F94; Sun, 5 Mar 2017 19:22:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 15AA127F93 for ; Sun, 5 Mar 2017 19:22:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752371AbdCETWo (ORCPT ); Sun, 5 Mar 2017 14:22:44 -0500 Received: from mail-wm0-f68.google.com ([74.125.82.68]:36528 "EHLO mail-wm0-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752398AbdCETWl (ORCPT ); Sun, 5 Mar 2017 14:22:41 -0500 Received: by mail-wm0-f68.google.com with SMTP id v190so10657071wme.3 for ; Sun, 05 Mar 2017 11:22:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=pb3cN1bxYMR7FfnwCrntaq8GhstNZHVEVj7+YLfaO2Y=; b=GRG/I9d4jLhVzJitTMkylyZENYK91x9WuQTMYIHZoHHuUrMNHjxKhN8mFPi0debMO6 StIc8K/oMUIRcd9eQ5yencPsR2/KWzAihS0mv7jj/LcyHcGFqC6JVJmqwcDz8Tqv/Kio Ctq9qfqQsGJip1uhHuhgwmcAwyQ+woBNskhKTk1oug//A+q3AaldHxlGI4lXGYeyhR+A wV5YmcG88KbW14j9270augRp6akTc3jDQkpdSYEY4Z2EQM3eYPyS0//kF1Ofn9fQpC+t nwtKfbOwHF3aZpV2EA/cYoNUCve6pzrafSbYd3lVlKGvxUjr+YbtIrRcAIBE+65g69mV k+uQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=pb3cN1bxYMR7FfnwCrntaq8GhstNZHVEVj7+YLfaO2Y=; b=jzQaQ7LGG2/H9+x3+9b44WF9Qfkw0K7gkQwgMXJ32F31u/QGE2GiUrQwEvO36oUb/h poolWko+7tkNwfNEtEonWz3G8WyzQ6a8Y4qytclRRRuxVGiNYfyThA5Bh+mP577jCrfr BwZp20/ErnogB3jS9CIkCKnVdQ95WX7+SWILUCp9bHhQnmRkv7Fqz1RM5TFRy6M85b7G +dYE53htbz8vb7+Zk+VKLuCmkv/xoVKRg7TiY85XLYZEq/f5OMGbzUTZgfoDdXUrcTCk geFZUcRSofSyIYZ9dJgfoiuq0cjL4nFB7qen1FC4gUC/A5DkKRS++6wGmkd+jMncv4As GHbw== X-Gm-Message-State: AMke39kTcTeJie/53mf3qaIHTS1vRGxPu0jQlxFOsseLbfSFH+3H3/Nj58U3WBr424UVUw== X-Received: by 10.28.165.147 with SMTP id o141mr10411869wme.67.1488741724617; Sun, 05 Mar 2017 11:22:04 -0800 (PST) Received: from localhost.localdomain ([2a02:a03f:831:5800:f8cf:2af6:4bc0:a4d4]) by smtp.gmail.com with ESMTPSA id 32sm22198519wrr.64.2017.03.05.11.22.03 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 05 Mar 2017 11:22:04 -0800 (PST) From: Luc Van Oostenryck To: linux-sparse@vger.kernel.org Cc: Christopher Li , Luc Van Oostenryck Subject: [PATCH v4 6/6] move 'extern with initializer' validation after the validate method Date: Sun, 5 Mar 2017 20:21:52 +0100 Message-Id: <20170305192152.67931-7-luc.vanoostenryck@gmail.com> X-Mailer: git-send-email 2.11.1 In-Reply-To: <20170305192152.67931-1-luc.vanoostenryck@gmail.com> References: <20170305192152.67931-1-luc.vanoostenryck@gmail.com> Sender: linux-sparse-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sparse@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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'