From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 175F63858C41; Mon, 9 Oct 2023 01:12:48 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 175F63858C41 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1696813968; bh=SF6/6qqvP8LqnbP8eQTD5I/mitfn/Mgclj0xWXsrF7s=; h=From:To:Subject:Date:From; b=uebjJD0m5lONriGlf93qRjJuypZaccAFKGbtfl477EdtGkiAg3gCT0UUW57pc822U uDF4tmalhS9PmwDUtl/gwfTHS81VVCdhiilQODmVVN9rkJB70+hv/aGpdn3uVqgWek 1xL9WuzMfmwLUhizVz8GYh4yFFB19QVJHn15dZ8M= From: "xavier.cooney03 at gmail dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/111730] New: erroneous alloc-size-larger-than warning with -O1 Date: Mon, 09 Oct 2023 01:12:47 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Version: 13.2.1 X-Bugzilla-Keywords: 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone attachments.created Message-ID: 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 Bug ID: 111730 Summary: erroneous alloc-size-larger-than warning with -O1 Product: gcc Version: 13.2.1 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: xavier.cooney03 at gmail dot com Target Milestone: --- Created attachment 56076 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D56076&action=3Dedit bug.c Hi, in some circumstances gcc incorrectly emits the alloc-size-larger-than warning: $ gcc -O1 -Wall -c bug.c bug.c: In function =E2=80=98foo=E2=80=99: bug.c:9:15: warning: argument 1 range [18446744071562067968, 18446744073709551615] exceeds maximum object size 9223372036854775807 [-Walloc-size-larger-than=3D] 9 | char *a =3D malloc(x); | ^~~~~~~~~ bug.c:4:14: note: in a call to allocation function =E2=80=98malloc=E2=80=99= declared here 4 | extern void *malloc (size_t size) __attribute__ ((__malloc__)); | ^~~~~~ This only seems to occur when using -O1, other optimisation levels (-O0, -O= 2, -O3, -Os) don't result in the warning. The 'useless' loops are necessary to reproduce, removing the first or last = loop causes the warning to disappear. 18446744071562067968 =3D 0xffffffff80000000 18446744073709551615 =3D 0xffffffffffffffff It seems as if gcc is incorrectly deducing that `x` must be negative. $ gcc -v Using built-in specs. COLLECT_GCC=3Dgcc COLLECT_LTO_WRAPPER=3D/usr/lib/gcc/x86_64-pc-linux-gnu/13.2.1/lto-wrapper Target: x86_64-pc-linux-gnu Configured with: /build/gcc/src/gcc/configure --enable-languages=3Dada,c,c++,d,fortran,go,lto,objc,obj-c++ --enable-boots= trap --prefix=3D/usr --libdir=3D/usr/lib --libexecdir=3D/usr/lib --mandir=3D/usr= /share/man --infodir=3D/usr/share/info --with-bugurl=3Dhttps://bugs.archlinux.org/ --with-build-config=3Dbootstrap-lto --with-linker-hash-style=3Dgnu --with-system-zlib --enable-__cxa_atexit --enable-cet=3Dauto --enable-checking=3Drelease --enable-clocale=3Dgnu --enable-default-pie --enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-obj= ect --enable-libstdcxx-backtrace --enable-link-serialization=3D1 --enable-linker-build-id --enable-lto --enable-multilib --enable-plugin --enable-shared --enable-threads=3Dposix --disable-libssp --disable-libstdc= xx-pch --disable-werror Thread model: posix Supported LTO compression algorithms: zlib zstd gcc version 13.2.1 20230801 (GCC)=