From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by sourceware.org (Postfix) with ESMTPS id D993C3858413 for ; Wed, 5 Apr 2023 01:31:40 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org D993C3858413 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pj1-x102b.google.com with SMTP id qe8-20020a17090b4f8800b0023f07253a2cso35734389pjb.3 for ; Tue, 04 Apr 2023 18:31:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1680658300; x=1683250300; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=IOgYdi4L25Rr3skzME2TegF2LH3RHQNH6WwYwVunEiA=; b=QHDzMlLA/yngsz/3mS6c+0oLR1MCJrRMMtxSBSQPAm/PVzrg6AVtMGHqKCTNLKtKzL 3SnvnSCHQ3zolayLWBdxo5+MCkxASpKzPdAVXGv188A1kLvxi9EF/pkhcW0i31eG1u8i YGyr7YygdtEwUrsrnqb6DYepUPeP0aQUhFFwOhxymknMvTHMNA/tz1OhKkPHJeeLkpXh YC+dya+S0cjiLAUz9ytMII77A+1ASr5T2hSM5UpJfILaK77mvo6K7iC0hxqzRnvhI58/ rvF3E+YD7VnZ2tjCmQO7y5SH//Rm8OEYw4gGBbb38OUDjJncYMQrj1s21fgrUFy08kOT hI7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680658300; x=1683250300; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=IOgYdi4L25Rr3skzME2TegF2LH3RHQNH6WwYwVunEiA=; b=r93IiQNJ5lA9B7JiJKfCYGLDPlzDggqWkkskfHe3UhfnHP/jRLkjruGC9ITq5+Znvq ISqhyAPPOIafkE5tpOBTr58byvPH/eDcoJrA2Xge1SRQ+1/oWOKcixU6O6ygouOP+ncl ruznJCPy2sp6Prms+n4ELqqxKOi5nqXhvTUUlYNBESBtbVMAUxJRDXfqLp0KCEfTlfw8 CgzaUzFEjyfSBCxu6ehtu9UGA90/aRLOl4vn1uges7/34Z73I4AB7q7isiBiowW9gadA Ly+/SvBqK60CXefENou2ltPYvvjEXqiCz8sadfQKlooK5UCZO/2hS7mNHU4pwkbCLvhK 0lKw== X-Gm-Message-State: AAQBX9fYUN2Uo4u3PuiauAxRGVsFrEiZnExWAPHfE6OBmInmoCemmWj1 8tcFdNsi/BINz+Z4W0VKGUkYPAb3tx4= X-Google-Smtp-Source: AKy350Y6Wp10Bdyy5bqXAkuYmXjdH++qjxr2S2cQFFo8MRFSVN96s7ws1nPss14o71VsQj2BEBmb8w== X-Received: by 2002:a17:903:2112:b0:19c:e405:4446 with SMTP id o18-20020a170903211200b0019ce4054446mr3914608ple.30.1680658299642; Tue, 04 Apr 2023 18:31:39 -0700 (PDT) Received: from ?IPV6:2601:681:8600:13d0::f0a? ([2601:681:8600:13d0::f0a]) by smtp.gmail.com with ESMTPSA id d6-20020a170902c18600b0019ca68ef7c3sm8915794pld.74.2023.04.04.18.31.38 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 04 Apr 2023 18:31:39 -0700 (PDT) Message-ID: <7e3070d8-c214-808e-3e52-a22aba64d786@gmail.com> Date: Tue, 4 Apr 2023 19:31:38 -0600 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.9.0 Subject: Re: [PATCH] Less warnings for parameters declared as arrays [PR98541, PR98536] Content-Language: en-US To: Martin Uecker , gcc-patches@gcc.gnu.org References: From: Jeff Law In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.3 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 List-Id: On 4/3/23 13:34, Martin Uecker via Gcc-patches wrote: > > > With the relatively new warnings (11..) affecting VLA bounds, > I now get a lot of false positives with -Wall. In general, I find > the new warnings very useful, but they seem a bit too > aggressive and some minor tweaks are needed, otherwise they are > too noisy. This patch suggests two changes: > > 1. For VLA bounds non-null is implied only when 'static' is > used (similar to clang) and not already when a bound > 0 is > specified: > > int foo(int n, char buf[static n]); > > int foo(10, 0); // warning with 'static' but not without. > > > (It also seems problematic to require a size of 0 to indicate > that the pointer may be null, because 0 is not allowed in > ISO C as a size. It is also inconsistent to how arrays with > static bound behave.) > > There seems to be agreement about this change in PR98541. > > > 2. GCC always warns when the number of unspecified > bounds is different between two declarations: > > int foo(int n, char buf[*]); > int foo(int n, char buf[n]); > > or > > int foo(int n, char buf[n]); > int foo(int n, char buf[*]); > > But the first version is useful if the size expression > can not be specified in a header (e.g. because it uses > a macro or variable not available there) and there is > currently no easy way to avoid this. The warning for > both cases was by design,  but I suggest to limit the > warning to the second case. > > Note that the logic currently applied by GCC is too > simplistic anyway, as GCC does not warn for > > int foo(int x, int y, double m[*][y]); > int foo(int x, int y, double m[x][*]); > > because the number of specified / unspecified bounds > is the same. So I suggest to go with the attached > patch now and add more precise warnings later > if there is more experience with these warning > in gernal and if this then still seems desirable. > > > Martin > > > Less warnings for parameters declared as arrays [PR98541, PR98536] > > To avoid false positivies, tune the warnings for parameters declared > as arrays with size expressions. Only warn about null arguments with > 'static'. Also do not warn when more bounds are specified in the new > declaration than before. > > PR c/98541 > PR c/98536 > > c-family/ > * c-warn.cc (warn_parm_array_mismatch): Do not warn if more > bounds are specified. > > gcc/ > * gimple-ssa-warn-access.cc > (pass_waccess::maybe_check_access_sizes): For VLA bounds > in parameters, only warn about null pointers with 'static'. > > gcc/testsuite: > * gcc.dg/Wnonnull-4: Adapt test. > * gcc.dg/Wstringop-overflow-40.c: Adapt test. > * gcc.dg/Wvla-parameter-4.c: Adapt test. > * gcc.dg/attr-access-2.c: Adapt test. Neither appears to be a regression. Seems like it should defer to gcc-14. jeff