From patchwork Sat Aug 5 16:22:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Uecker X-Patchwork-Id: 131500 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:c44e:0:b0:3f2:4152:657d with SMTP id w14csp535583vqr; Sat, 5 Aug 2023 09:23:34 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHjXnsOex/n99vLffnyENKF4ML9qKAw6MBZpSKRYVuLuXhm//B/kZzonCLOy7KJriusMbLg X-Received: by 2002:a17:906:7483:b0:99c:ad52:b06 with SMTP id e3-20020a170906748300b0099cad520b06mr3211325ejl.10.1691252614414; Sat, 05 Aug 2023 09:23:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691252614; cv=none; d=google.com; s=arc-20160816; b=KVOqoDE2RAE1gj45zHOQzFaVFOG1a7+TzpayaHlHR1tu3Zsg7vl7AwvxPEVb4cqmfh IJE6wohxxVh3BjHxRjziM8eKfi7c+Xu/Bj3rQ0M1ISM8QoUUTHueVtCGBzx7jXqR0huJ yIlrzNb6AUbW70D42ebJQMfB442czXS3/esU2liZwR9ews3OB/ThHMnIzPMQYUYDsrlp 4C2biPYjzN+QReeYOrip49VRRRzQcCwrAYTObKVjvNXP5YugxPPhgKJhxM4c6FKWAHpT Q+/izYUglyl5YQkAnsjmKmo8pmI0qUtRd0IIVFRQddadnQeezH4naF4DXObVsU+Wfxsv oclQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:user-agent:date:to:subject :message-id:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=k32W4rsR/j/pODrevWkGd/XHn659txQGt5H7gqyXd1M=; fh=DWsf36hTBTZWqY8olHOcX36iN3VVHiMnPltdR0Tl3Bk=; b=0C4W09jhBhvTMQpZvy1QuHml/ewQET8y9Q9RIOdvvU9MfG2hNSMuePTKa5Y0KFC61Y /6SaRwqz/kjNsrZGJBX5TB++MQ7JqJlpNJes1QKyA9O/IWH2NHw3YIdDcrYXGcpnqyhn 6Rl31Hjdx0th7UNzMeHpmQzRDzyvdTOjzY3yb5oIa9DXWLnTrx5ai59nGl+R45hv5qa0 dObyjxlhja1ozUkCFb8fu1TLU9bie7JbPCfx0krpvY4OhByJ32DGttCaf0AP0on3hAhw oWFhGsYWjRWo5C0D9xzLmAbaVu0gUzUHL3zm/eYVP5diP5grgnuWiTmpL+39iuFjqr4h iaFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kGNJrG2H; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id qc27-20020a170906d8bb00b0099b5445ceb7si3233907ejb.614.2023.08.05.09.23.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Aug 2023 09:23:34 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=kGNJrG2H; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 1D2863858C3A for ; Sat, 5 Aug 2023 16:23:33 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1D2863858C3A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1691252613; bh=k32W4rsR/j/pODrevWkGd/XHn659txQGt5H7gqyXd1M=; h=Subject:To:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=kGNJrG2HKg+TMMqZ6DmIQYuk7a5kw16ia5GXEP/PI5a0SaK1Nr/qjVUnuP7lu/ti6 NmRs6GbwfdLo2WX9JvsIA0q2m12GhIuIUHNMBkmxuU50ENnYKpzIyZO/a3uYomBMZF k9wkmuL+g5uFlSmgHYzFe+OVTdtOJLRSRlSe4MBc= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mailrelay.tugraz.at (mailrelay.tugraz.at [129.27.2.202]) by sourceware.org (Postfix) with ESMTPS id E12253858D35 for ; Sat, 5 Aug 2023 16:22:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E12253858D35 Received: from vra-169-214.tugraz.at (vra-169-214.tugraz.at [129.27.169.214]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4RJ7Cm3L26z3wVL for ; Sat, 5 Aug 2023 18:22:44 +0200 (CEST) Message-ID: <8283eb31e9bd32b704bd337a846ea980c1d4e182.camel@tugraz.at> Subject: [committed] c: Less warnings for parameters declared as arrays [PR98536] To: gcc-patches@gcc.gnu.org Date: Sat, 05 Aug 2023 18:22:43 +0200 User-Agent: Evolution 3.38.3-1+deb11u2 MIME-Version: 1.0 X-TUG-Backscatter-control: G/VXY7/6zeyuAY/PU2/0qw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.116 X-Spam-Status: No, score=-11.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_MSPIKE_H3, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, 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.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Martin Uecker via Gcc-patches From: Martin Uecker Reply-To: Martin Uecker Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773406901298027821 X-GMAIL-MSGID: 1773406901298027821 I splitted up the patch into two parts and committed only the FE parts which were already approved and the tests. This solves one of the two issues. Bootstrapped and regression tested on x86_64-pc-linux-gnu. Less warnings for parameters declared as arrays [PR98536] To avoid false positivies, tune the warnings for parameters declared as arrays with size expressions. Do not warn when more bounds are specified in the declaration than before. PR c/98536 c-family/ * c-warn.cc (warn_parm_array_mismatch): Do not warn if more bounds are specified. gcc/testsuite: * gcc.dg/Wvla-parameter-4.c: Adapt test. * gcc.dg/attr-access-2.c: Adapt test. diff --git a/gcc/c-family/c-warn.cc b/gcc/c-family/c-warn.cc index d4d62c48b20..b7c5d7c01a2 100644 --- a/gcc/c-family/c-warn.cc +++ b/gcc/c-family/c-warn.cc @@ -3599,23 +3599,13 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms) continue; } - if (newunspec != curunspec) + if (newunspec > curunspec) { location_t warnloc = newloc, noteloc = origloc; const char *warnparmstr = newparmstr.c_str (); const char *noteparmstr = curparmstr.c_str (); unsigned warnunspec = newunspec, noteunspec = curunspec; - if (newunspec < curunspec) - { - /* If the new declaration has fewer unspecified bounds - point the warning to the previous declaration to make - it clear that that's the one to change. Otherwise, - point it to the new decl. */ - std::swap (warnloc, noteloc); - std::swap (warnparmstr, noteparmstr); - std::swap (warnunspec, noteunspec); - } if (warning_n (warnloc, OPT_Wvla_parameter, warnunspec, "argument %u of type %s declared with " "%u unspecified variable bound", @@ -3643,14 +3633,10 @@ warn_parm_array_mismatch (location_t origloc, tree fndecl, tree newparms) } /* Iterate over the lists of VLA variable bounds, comparing each - pair for equality, and diagnosing mismatches. The case of - the lists having different lengths is handled above so at - this point they do . */ - for (tree newvbl = newa->size, curvbl = cura->size; newvbl; + pair for equality, and diagnosing mismatches. */ + for (tree newvbl = newa->size, curvbl = cura->size; newvbl && curvbl; newvbl = TREE_CHAIN (newvbl), curvbl = TREE_CHAIN (curvbl)) { - gcc_assert (curvbl); - tree newpos = TREE_PURPOSE (newvbl); tree curpos = TREE_PURPOSE (curvbl); diff --git a/gcc/testsuite/gcc.dg/Wvla-parameter-4.c b/gcc/testsuite/gcc.dg/Wvla-parameter-4.c index 599ad19a3e4..f35faea361a 100644 --- a/gcc/testsuite/gcc.dg/Wvla-parameter-4.c +++ b/gcc/testsuite/gcc.dg/Wvla-parameter-4.c @@ -12,11 +12,6 @@ typedef int IA3[3]; /* Verify the warning points to the declaration with more unspecified bounds, guiding the user to specify them rather than making them all unspecified. */ -void* f_pIA3ax (IA3 *x[*]); // { dg-warning "argument 1 of type 'int \\\(\\\*\\\[\\\*]\\\)\\\[3]' .aka '\[^\n\r\}\]+'. declared with 1 unspecified variable bound" } -void* f_pIA3ax (IA3 *x[*]); -void* f_pIA3ax (IA3 *x[n]); // { dg-message "subsequently declared as 'int \\\(\\\*\\\[n]\\\)\\\[3]' with 0 unspecified variable bounds" "note" } -void* f_pIA3ax (IA3 *x[n]) { return x; } - void* f_pIA3an (IA3 *x[n]); // { dg-message "previously declared as 'int \\\(\\\*\\\[n]\\\)\\\[3]' with 0 unspecified variable bounds" "note" } void* f_pIA3an (IA3 *x[n]); diff --git a/gcc/testsuite/gcc.dg/attr-access-2.c b/gcc/testsuite/gcc.dg/attr-access-2.c index 76baddffc9f..616b7a9527c 100644 --- a/gcc/testsuite/gcc.dg/attr-access-2.c +++ b/gcc/testsuite/gcc.dg/attr-access-2.c @@ -60,16 +60,6 @@ RW (2, 1) void f10 (int n, char a[n]) // { dg-warning "attribute 'access *\\\( // { dg-warning "argument 2 of type 'char\\\[n]' declared as a variable length array" "" { target *-*-* } .-1 } { (void)&n; (void)&a; } - -/* The following is diagnosed to point out declarations with the T[*] - form in headers where specifying the bound is just as important as - in the definition (to detect bugs). */ - void f11 (int, char[*]); // { dg-warning "argument 2 of type 'char\\\[\\\*\\\]' declared with 1 unspecified variable bound" } - void f11 (int m, char a[m]); // { dg-message "subsequently declared as 'char\\\[m]' with 0 unspecified variable bounds" "note" } -RW (2, 1) void f11 (int n, char arr[n]) // { dg-message "subsequently declared as 'char\\\[n]' with 0 unspecified variable bounds" "note" } -{ (void)&n; (void)&arr; } - - /* Verify that redeclaring a function with attribute access applying to an array parameter of any form is not diagnosed. */ void f12__ (int, int[]) RW (2, 1);