From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 75EC63858D39; Mon, 9 Oct 2023 02:38:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 75EC63858D39 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696819120; bh=CcZPbtHfXCuQAgMCjznGmlsdeONKi3Kq2iYUg7Fbwe0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=xZMtV4TN2cG9odSCx30p4HJQvMKngHNFxRmWwK6eTQp1BvI4VZpYmwqUYHWt/AOvK e8hte90AAWFwSscm+KGgPl4c7oRNM60npQRemjnBIwBtlVViAx1D5h1juzpsdWryvY QDcol7SrZLS/HBsxAt3hDjylZb2bSSJdvy6LKq8Y= From: "xavier.cooney03 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/111730] erroneous alloc-size-larger-than warning with -O1 Date: Mon, 09 Oct 2023 02:38:40 +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.2.1 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: normal X-Bugzilla-Who: xavier.cooney03 at gmail dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- 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=3D111730 --- Comment #4 from Xavier Cooney --- I see, thanks for looking into this. The unreduced test case (which was from a student confused about the error message) was still passing a value to `malloc` which from the context which= gcc could see wasn't /necessarily/ non-negative. But the code ``` void foo2(int x) { char *a =3D malloc(x); (void) a; } ``` doesn't trigger the warning, even though `x` could also be negative. I'm not sure why the extra loops are necessary for the warning to be emitte= d if the compiler is trying to warn about any time a potentially negative value might be passed to `malloc`. Also the error message reads to me as saying that argument 1 must be in the range [18446744071562067968, 18446744073709551615] (in which case it would = be incorrect), rather than saying the argument could be in the range (in which case it would be correct). Thanks again for look into this :)=