From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 484C13858C62; Wed, 12 Jul 2023 17:52:18 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 484C13858C62 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1689184338; bh=nHj0pZyggV2bx5dbXTlJ5OWu956k/L3+u/cbFLra6Vk=; h=From:To:Subject:Date:From; b=NgTxW0a3ya6EsJMQ3vU5Or4S81U6272IVQBzoUhquYl4wCCDGHutaOtbtHWE5uQOz X2QYTzPNg6ZG0PEeCc2jmvU9DDoOC6R5k8r/Un7uIVRH0RxSKkU/OU3hjJW/pAFHtT 8jCs0kBpl+ZVlrc5MsgQZWATDfuR/wNYAWp3YRhs= From: "andres at anarazel dot de" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/110645] New: False positive -Warray-bounds warning Date: Wed, 12 Jul 2023 17:52:17 +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: unknown X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: andres at anarazel dot de 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=3D110645 Bug ID: 110645 Summary: False positive -Warray-bounds warning Product: gcc Version: unknown Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: andres at anarazel dot de Target Milestone: --- Created attachment 55531 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=3D55531&action=3Dedit reproducer Hi, The attached minimized reproducer (from postgres code) triggers a clearly b= ogus -Warray-bounds warning, even with -Warray-bounds=3D1. $ gcc -O1 -Wall -Warray-bounds=3D1 -c -o /dev/null -c repro.i=20 In function =E2=80=98formTextDatum=E2=80=99, inlined from =E2=80=98spgist_name_compress=E2=80=99 at /tmp/cvise2/repr= o.i:44:9: /tmp/cvise2/repro.i:35:17: warning: =E2=80=98memcpy=E2=80=99 forming offset= [2, 254] is out of the bounds [0, 2] [-Warray-bounds] 35 | memcpy(att->data, src, srclen); | ^~~~~~~~~~~~ This is despite srclen being strlen(src), which gcc does know is <=3D 1. It seems that the known range of srclen is "widened" due to the if (srclen < 0xff), causing the warning. It is somewhat interesting that removing -Wall removes the spurious warning, despite -Warray-bounds=3D1. This triggers for gcc-11 - HEAD at 3b007164b3e, but not in gcc-10. I looked through quite a few bugs about spurious -Warray-bounds warnings to= see if this is a duplicate - quite possible, but I didn't find a real match for this. Regards, Andres=