From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 436CB3858C41; Mon, 9 Oct 2023 02:15:43 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 436CB3858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696817743; bh=ZrXpheumEqHKai3k5J8IOTTZRB/aKx8GwahxSjCE5j0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jGHvmIQViTC0eCuuBHU/bauxjq1Cc4M+6oIX1DKJ7ObQL8Q37EKPhKb6uHcendxHz SOYBkJZeWJxzYAGMoe7fZQD0YhMpfsI6T2rfFatnuw2Y8rMrF3a6OHbzlNbGBO0KPE mMKTChh8IdmToWohBNrXHcyOjmV80drJnZpBjcGc= From: "pinskia at gcc dot gnu.org" 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:15:42 +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: pinskia at gcc dot gnu.org 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 #3 from Andrew Pinski --- Note you can reproduce the same warning with ( -O2 -fno-code-hoisting -fno-tree-loop-im -fno-tree-pre): ``` // #include typedef long unsigned int size_t; extern void *malloc (size_t size) __attribute__ ((__malloc__)); int *t; void foo(int x) { // if (x < 1) return; for (int i =3D 0; i < x; i++) {*t =3D i;} char *a =3D malloc(x); for (int i =3D 0; i < x; i++) a[i] =3D 0; while (a[x - 1]) {*t++;} } ``` I still think you should add a check for x being negative to fix the code/warning. Unless you have a unreduced testcase which has the test before and still able to produce the warning, this will most likely be closed as invalid.=