From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 155E63858408; Fri, 3 Mar 2023 15:12:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 155E63858408 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677856333; bh=7v3PAPE4gfneNM02KQjZBgMS8qa67n92pEU0esNRkhw=; h=From:To:Subject:Date:In-Reply-To:References:From; b=psznN2v5rbxAQiZsqTEpD5YPpgZz/fyxt37ibiuSsvpvtrGhszDrYQ6p84tx0jtTi nwkzcQVoAk3xsZuJ35z7Gt4I+PINL5RysqglHzPCuGqX1/w+KsbgvMRdUJ4z1HpmXC t3/Dz4pYDzGjwv/V+bk3AYHSaNQWWXls0rh+UfYc= From: "cvs-commit at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/108986] [11/12/13 Regression] Incorrect warning for [static] array parameter Date: Fri, 03 Mar 2023 15:12:11 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 12.2.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: cvs-commit at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: jakub at gcc dot gnu.org X-Bugzilla-Target-Milestone: 12.3 X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D108986 --- Comment #5 from CVS Commits --- The master branch has been updated by Jakub Jelinek : https://gcc.gnu.org/g:1b0e3f8ca369f63d3e1a8e1c268d93530035503a commit r13-6450-g1b0e3f8ca369f63d3e1a8e1c268d93530035503a Author: Jakub Jelinek Date: Fri Mar 3 16:11:11 2023 +0100 waccess: Fix two -Wnonnull warning issues [PR108986] The following patch fixes 2 issues with the -Wnonnull warning. One, fixed by the second hunk, is that the warning wording is bogus since r11-3305, instead of printing warning: argument 1 to =C3=A2int[static 7]=C3=A2 is null where non-null= expected [-Wnonnull] it prints warning: argument 1 to =C3=A2int[static 28]=C3=A2 is null where non-nul= l expected [-Wnonnull] access_size is measured in bytes, so obviously will be correct as array number of elements only if it is 1 byte element array. In the function, access_nelts is either constant (if sizidx =3D=3D -1) = or when the array size is determined by some other parameter, I believe a value passed to that argument. Later on we query the range of it: if (get_size_range (m_ptr_qry.rvals, access_nelts, stmt, sizrng, = 1)) which I bet must just return accesS_nelts in sizrng[0] and [1] if it is constant. access_size is later computed as: tree access_size =3D NULL_TREE; if (tree_int_cst_sgn (sizrng[0]) >=3D 0) { if (COMPLETE_TYPE_P (argtype)) { ... wide_int minsize =3D wi::to_wide (sizrng[0], prec); minsize *=3D wi::to_wide (argsize, prec); access_size =3D wide_int_to_tree (sizetype, minsize= ); } } else access_size =3D access_nelts; } and immediately after this the code does: if (integer_zerop (ptr)) { if (sizidx >=3D 0 && tree_int_cst_sgn (sizrng[0]) > 0) { some other warning wording } else if (access_size && access.second.static_p) { this spot } } So, because argtype is complete, access_size has been multiplied by argsize, but in case of this exact warning ("this spot" above) I believe access_nelts must be really constant, otherwise "some other warning wording" would handle it. So, I think access_nelts is exactly what we want to print there. The other problem is that since the introduction of -Wdangling-pointer in r12-6606, the pass has early and late instances and while lots of stuff in the pass is guarded on being done in the late pass only, this particular function is not, furthermore it is emitting two differe= nt warnings in a loop and already messes up with stuff like clearing warning suppression for one of the warning (ugh!). The end effect is that we warn twice about the same problem, once in the early and once in the late pass. Now, e.g. with -O2 -Wall we warn just once, during the early pass, as it is then optimized away, so I think just making this late warning only wouldn't be best. This patch instead returns early if either of the warnings is suppressed on the call stmt already. I think if one of the passes warned on it already (even if say on some other argument), then warning again (even on some other argument) is unnecess= ary, if both problems are visible in the same pass we'll still warn about bo= th. 2023-03-03 Jakub Jelinek PR c/108986 * gimple-ssa-warn-access.cc (pass_waccess::maybe_check_access_sizes): Return immediately if OPT_Wnonnull or OPT_Wstringop_overflow_ is suppressed on stmt. For [static %E] warning, print access_nelts rather than access_size. Fix up comment wording. * gcc.dg/Wnonnull-8.c: New test.=