From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id CF6393858D32; Mon, 27 Feb 2023 16:16:24 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org CF6393858D32 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677514584; bh=S3JG0Yn2wpoO470rQH5GuQetuBF8xix5r+N1CeWuZiU=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ru4odgYaoC9R9NmjfQtthq6mdiXyKc3cX/FoRbvAcoH0Iptyfod56mb9Yw9pzwPFT U5/na4SSurqVKoHDe4K6ZoRHKiwGVAzF7rsqBNwEMlVVO6/2lS1OVQpMOFUpW33ItG MMLIldnA1RrYfdkP0wzLs7Yj4PaYk8lKbaF1Mf0A= From: "aldyh at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/107561] [13 Regression] g++.dg/pr71488.C and [g++.dg/warn/Warray-bounds-16.C -m32] regression due to -Wstringop-overflow problem Date: Mon, 27 Feb 2023 16:16:24 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: tree-optimization X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: diagnostic, missed-optimization X-Bugzilla-Severity: normal X-Bugzilla-Who: aldyh at gcc dot gnu.org X-Bugzilla-Status: ASSIGNED X-Bugzilla-Resolution: X-Bugzilla-Priority: P1 X-Bugzilla-Assigned-To: rguenth at gcc dot gnu.org X-Bugzilla-Target-Milestone: 13.0 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=3D107561 --- Comment #14 from Aldy Hernandez --- (In reply to Richard Biener from comment #11) > So I've missed the VR_ANTI_RANGE handling in get_size_range where we run = into >=20 > wide_int maxsize =3D wi::to_wide (max_object_size ()); > min =3D wide_int::from (min, maxsize.get_precision (), UNSIGNED= ); > max =3D wide_int::from (max, maxsize.get_precision (), UNSIGNED= ); > if (wi::eq_p (0, min - 1)) > { > /* EXP is unsigned and not in the range [1, MAX]. That mea= ns > it's either zero or greater than MAX. Even though 0 wou= ld > normally be detected by -Walloc-zero, unless ALLOW_ZERO > is set, set the range to [MAX, TYPE_MAX] so that when MAX > is greater than the limit the whole range is diagnosed. = */ > wide_int maxsize =3D wi::to_wide (max_object_size ()); > if (flags & SR_ALLOW_ZERO) > { > if (wi::leu_p (maxsize, max + 1) > || !(flags & SR_USE_LARGEST)) > min =3D max =3D wi::zero (expprec); > else > { > min =3D max + 1; > max =3D wi::to_wide (TYPE_MAX_VALUE (exptype)); > } > } > else > { > min =3D max + 1; > max =3D wi::to_wide (TYPE_MAX_VALUE (exptype)); > } >=20 > and from [0,0] [8, +INF] pick [8, +INF] based on the comments reasoning. Ughh, you're reaching all the problematic cases I ran into while trying to remove legacy. >=20 > This all wouldn't happen if we'd be able to CSE the zero size ... >=20 > We can now try to put additional heuristic ontop of the above heuristic, > namely when the object we write to is of size zero set SR_ALLOW_ZERO. > Or try to "undo" the multiplication trick which would probably make us > end up with VARYING. >=20 > I'll note that with the earlier proposed change we regress the following, > that's an observation I make a lot of times - all "weirdness" in the code > is backed by (artificial) testcases verifying it works exactly as coded .= .. +1 >=20 > FAIL: gcc.dg/Wstringop-overflow-15.c pr82608 (test for warnings, line= 37) > FAIL: gcc.dg/Wstringop-overflow-15.c pr82608 (test for warnings, line= 38) > FAIL: gcc.dg/Wstringop-overflow-15.c pr82608 (test for warnings, line= 69) > FAIL: gcc.dg/Wstringop-overflow-15.c pr82608 (test for warnings, line= 70) > FAIL: gcc.dg/Wstringop-overflow-56.c (test for warnings, line 64) > FAIL: gcc.dg/Wstringop-overflow-56.c (test for warnings, line 75) > FAIL: gcc.dg/Wstringop-overflow-56.c (test for warnings, line 86) > FAIL: gcc.dg/Wstringop-overflow-56.c (test for warnings, line 97) > FAIL: gcc.dg/Wstringop-overflow-56.c (test for warnings, line 108) > FAIL: gcc.dg/Wstringop-overflow-56.c (test for warnings, line 148) > FAIL: gcc.dg/Wstringop-overflow-56.c (test for warnings, line 159) > FAIL: gcc.dg/attr-alloc_size-11.c (test for warnings, line 52) > FAIL: gcc.dg/attr-alloc_size-11.c (test for warnings, line 53) > FAIL: gcc.dg/attr-alloc_size-11.c (test for warnings, line 54) > FAIL: gcc.dg/attr-alloc_size-11.c (test for warnings, line 55) > FAIL: gcc.dg/attr-alloc_size-11.c (test for warnings, line 56) > FAIL: gcc.dg/attr-alloc_size-11.c (test for warnings, line 57) > FAIL: gcc.dg/attr-alloc_size-11.c (test for warnings, line 58) > FAIL: gcc.dg/attr-alloc_size-11.c (test for warnings, line 64) > FAIL: gcc.dg/attr-alloc_size-11.c (test for warnings, line 65) > FAIL: gcc.dg/attr-alloc_size-3.c (test for warnings, line 438) > FAIL: gcc.dg/attr-alloc_size-4.c (test for warnings, line 138) > FAIL: gcc.dg/attr-alloc_size-4.c (test for warnings, line 143) > FAIL: gcc.dg/attr-alloc_size-4.c (test for warnings, line 187) > FAIL: gcc.dg/pr98721-1.c (test for warnings, line 11) > FAIL: gcc.dg/pr98721-1.c (test for warnings, line 12) >=20 > For example gcc.dg/pr98721-1.c has >=20 > int > foo (int n) > { > if (n <=3D 0) > { > char vla[n]; /* { dg-message "source object 'v= la' > of size 0" } */ > return __builtin_strlen (vla); /* { dg-warning "'__builtin_strle= n' > reading 1 or more bytes from a region of size 0" } */ >=20 > but of course we do not diagnose >=20 > int > foo (int n) > { > if (n < 0) > { > char vla[n]; >=20 > or when no condition is present or a n > 32 condition is present. Yup, ran into that too. >=20 > I fear it's not possible to "fix" this testcase without changing the > expectation on a bunch of other testcases. But the messaging to the > user is quite unhelpful because it doesn't actually inform him about > above reasoning. Agreed.=