Message ID | 20231028191402.217288-1-pobrn@protonmail.com |
---|---|
State | Accepted |
Headers |
Return-Path: <gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:d641:0:b0:403:3b70:6f57 with SMTP id cy1csp1362761vqb; Sat, 28 Oct 2023 12:14:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGRZqCSBpwha6jYJAQrj/9pR+HQMdhS2EXt3Btm344M3CaKO33cwQjy18uLKJ0pmyJBgLaD X-Received: by 2002:ac8:5785:0:b0:41e:279d:ddc0 with SMTP id v5-20020ac85785000000b0041e279dddc0mr7060057qta.40.1698520478111; Sat, 28 Oct 2023 12:14:38 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1698520478; cv=pass; d=google.com; s=arc-20160816; b=RJCQBSkza35wlCWQ1JgyGF8O+5O5S+KiHtTMiPAfGcO0g/I3khKaupAJ8g12E5m2Hz eNiqoT+PXH6DAziEigGNFLxrj3x4aWzUlQakvcwrbP6ABRpw0/C1waavRIdB06w72evE 0X2asWXz7VUgfG5d48bHuVzoBFgIfbJi8NtNWC48RetBAi1MHrETA2OBWMRVU4XeScbA A4qO3JMWzvNBAMxl+l37vSVa4nQ79+aP1Tb/aBCkLoD1uA4SC4fFx+fkAMmT7HUVvdhe tRfJOpuVrudmAO6N9tyIDUny1QmgG2YsxJ/Rol5GPj8FhQ+KRz6yMw+dYiZOMJqyVJWk p64A== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:feedback-id:message-id:subject:from:to:date :dkim-signature:arc-filter:dmarc-filter:delivered-to; bh=N6XvgTLjrmWjdVahGoRLHTdUhh058C//BzwqvutkNKY=; fh=hPrbWPhweUx4V0GV9uXJqbyAzg2ABmTz7kczrAQqMmM=; b=ZJZ0Cx1j+1yXDZR2bPhN1KkWjp5UTQZq3pEtd/D3ur4Ks0JT9fHHLf/rC0CdQkS8fg 8fuci5ZEqjWhngN1VWhkyhIkFOQyOwyz+PJD13BPDIW+ygat5jsT+GVJAgX89xvUH0lE Yp/QIicOJrGgIw+Fv7A6rnLmJDubOpREtWvGfC6oxTvaz2QYlqgm0Q44ITdvQlGTQv3y ffGwrpYNk6HuDmB7yNj14fUnkfmT+mxAMLgDqeyxh5GvFj7rM1YhmkkPGa7bL6HnEMk+ vhfHBNZqLdEVHv0lBFtvOTf8NAD+aHDi3E7bchacYEAiS/0K6hBS3f2VZ3o7zHlYdEJl YBWA== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=mCzX9eOk; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: from server2.sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id o8-20020a05622a008800b0041cc02700dbsi2822902qtw.257.2023.10.28.12.14.38 for <ouuuleilei@gmail.com> (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 28 Oct 2023 12:14:38 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@protonmail.com header.s=protonmail3 header.b=mCzX9eOk; arc=pass (i=1); spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=protonmail.com Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D08D838618C1 for <ouuuleilei@gmail.com>; Sat, 28 Oct 2023 19:14:37 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-4316.protonmail.ch (mail-4316.protonmail.ch [185.70.43.16]) by sourceware.org (Postfix) with ESMTPS id 94B70385C6FC for <gcc-patches@gcc.gnu.org>; Sat, 28 Oct 2023 19:14:13 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 94B70385C6FC Authentication-Results: sourceware.org; dmarc=pass (p=quarantine dis=none) header.from=protonmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=protonmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 94B70385C6FC Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=185.70.43.16 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698520454; cv=none; b=QUUkYNXynSPOJx8jZh5kBP9YShfrLgnu7yxTStAs1WjjI6r015Xa8qu/QTyAPD5VkpSJ1Vbc+JL6kLy+7mWWwb5clN5VimyO3EtcvEMjhQk1T3c0yikAJviQepFlMKnD2cgxyMM5Lyt29gw0PEa7vNvMZh4dwbu0GnvEQEBGm70= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1698520454; c=relaxed/simple; bh=Cv7VU2YXOi5A2oqAexiuwZw7oqWslnSoWdW1h4aVuqg=; h=DKIM-Signature:Date:To:From:Subject:Message-ID:MIME-Version; b=KzN17ESjUXnEXqiflT9QfxZK4/T1xJd2oDrXWHYNK3obX9iTQeR4iX46392Er4s29nW9vyWFkwnsQHkfRfmdn0F15GS136X60r6RCVrorqfqh2RrcmHWlllVh2aovFsGbx7DWzrYmGZJOyiUnxUarizjQT/9Z2mwncZN7LpBUVw= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=protonmail.com; s=protonmail3; t=1698520451; x=1698779651; bh=N6XvgTLjrmWjdVahGoRLHTdUhh058C//BzwqvutkNKY=; h=Date:To:From:Subject:Message-ID:Feedback-ID:From:To:Cc:Date: Subject:Reply-To:Feedback-ID:Message-ID:BIMI-Selector; b=mCzX9eOk6iMOQWBVpoewOQG3CTObirHJusAAmzItlmg3ERSusrlSKTvfyCmsGrqeB xlE3RaVydG4TGgnjawnXpY7ncrwsLF6xRFzBdqiJJXuDXe7+IhmgevcUhjLBMq1Bg5 MtDTP1r2By0Fv2F3R1MHtlev5Rb/H/LpMbIPeV0g+YTSysHw13Lh+cN9Jt47Anx36y z67CWuxisyY/nS3c6Xjdaklr9b2uPbqI4SENyZCd7zZjMg8a/CZcmkqNRuIHanleXN j3FK1Zn7FxNzKi263NWpvz3b80I+lyy1qmDShNgfZ0a/itIGpASusV/F6gVO4lZdQY neDq5nj4wKzNw== Date: Sat, 28 Oct 2023 19:14:05 +0000 To: gcc-patches@gcc.gnu.org From: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= <pobrn@protonmail.com> Subject: [RFC PATCH v1] c: Do not warn about external declaration following inline definition Message-ID: <20231028191402.217288-1-pobrn@protonmail.com> Feedback-ID: 20568564:user:proton MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_PASS, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 Precedence: list List-Id: Gcc-patches mailing list <gcc-patches.gcc.gnu.org> List-Unsubscribe: <https://gcc.gnu.org/mailman/options/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=unsubscribe> List-Archive: <https://gcc.gnu.org/pipermail/gcc-patches/> List-Post: <mailto:gcc-patches@gcc.gnu.org> List-Help: <mailto:gcc-patches-request@gcc.gnu.org?subject=help> List-Subscribe: <https://gcc.gnu.org/mailman/listinfo/gcc-patches>, <mailto:gcc-patches-request@gcc.gnu.org?subject=subscribe> Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781027808517739712 X-GMAIL-MSGID: 1781027808517739712 |
Series |
[RFC,v1] c: Do not warn about external declaration following inline definition
|
|
Checks
Context | Check | Description |
---|---|---|
snail/gcc-patch-check | success | Github commit url |
Commit Message
Barnabás Pőcze
Oct. 28, 2023, 7:14 p.m. UTC
An external declaration following an inline definition is not redundant because it forces the compiler to emit an external definition for the function. That is, inline void f(void) { } [extern] void f(void); should not trigger the redundant redeclaration of ... warning. gcc/c/ChangeLog: * c-decl.cc (diagnose_mismatched_decls): Add new case for Wredundant-decls suppression. --- gcc/c/c-decl.cc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
Comments
On Sat, 28 Oct 2023, Barnabás Pőcze wrote: > An external declaration following an inline definition is not redundant > because it forces the compiler to emit an external definition for the function. > That is, > > inline void f(void) { } > [extern] void f(void); > > should not trigger the > > redundant redeclaration of ... > > warning. This should add a testcase to the testsuite (that fails before and passes after the front-end change is made).
Hi 2023. október 30., hétfő 19:01 keltezéssel, Joseph Myers írta: > On Sat, 28 Oct 2023, Barnabás Pőcze wrote: > > > An external declaration following an inline definition is not redundant > > because it forces the compiler to emit an external definition for the function. > > That is, > > > > inline void f(void) { } > > [extern] void f(void); > > > > should not trigger the > > > > redundant redeclaration of ... > > > > warning. > > > This should add a testcase to the testsuite (that fails before and passes > after the front-end change is made). I did not want to commit more effort until I have some feedback. I will most certainly add a test case if it turns out that the change seems reasonable and has a chance of being accepted. Regards, Barnabás Pőcze
On Mon, 30 Oct 2023, Barnabás Pőcze wrote: > Hi > > > 2023. október 30., hétfő 19:01 keltezéssel, Joseph Myers írta: > > > On Sat, 28 Oct 2023, Barnabás Pőcze wrote: > > > > > An external declaration following an inline definition is not redundant > > > because it forces the compiler to emit an external definition for the function. > > > That is, > > > > > > inline void f(void) { } > > > [extern] void f(void); > > > > > > should not trigger the > > > > > > redundant redeclaration of ... > > > > > > warning. > > > > > > This should add a testcase to the testsuite (that fails before and passes > > after the front-end change is made). > > I did not want to commit more effort until I have some feedback. > I will most certainly add a test case if it turns out that the change > seems reasonable and has a chance of being accepted. I agree that such a declaration is not redundant, and indeed serves a useful purpose, and so it's appropriate to avoid the warning in that case. Maybe also edit the documentation in invoke.texi to mention this case as not being diagnosed because not redundant. Hopefully cases such as inline void f(void) { } void f(void); void f(void); do warn for the final declaration, because that one *is* redundant. Similarly, the changes should not affect warnings in the -fgnu89-inline case, because then a subsequent extern declaration has no effect on a prior inline definition. Tests should include all these variations.
diff --git a/gcc/c/c-decl.cc b/gcc/c/c-decl.cc index 7a145bed281..e86f7950858 100644 --- a/gcc/c/c-decl.cc +++ b/gcc/c/c-decl.cc @@ -2592,7 +2592,12 @@ diagnose_mismatched_decls (tree newdecl, tree olddecl, && TREE_ASM_WRITTEN (olddecl) && !TREE_ASM_WRITTEN (newdecl)) /* Don't warn about a variable definition following a declaration. */ && !(VAR_P (newdecl) - && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl))) + && DECL_INITIAL (newdecl) && !DECL_INITIAL (olddecl)) + /* Don't warn about external declaration following inline definition. */ + && !(TREE_CODE (newdecl) == FUNCTION_DECL + && !DECL_INITIAL (newdecl) && !DECL_DECLARED_INLINE_P (newdecl) + && DECL_EXTERNAL (newdecl) && DECL_INITIAL (olddecl) + && DECL_DECLARED_INLINE_P (olddecl) && DECL_EXTERNAL (olddecl))) { warned = warning (OPT_Wredundant_decls, "redundant redeclaration of %q+D", newdecl);