From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id D6E833858D1E; Mon, 29 Jan 2024 21:50:06 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D6E833858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1706565006; bh=u9Ho/3KE+HrujqxVBMsNR/qhnEaRw/fNy1wQFZfgS20=; h=From:To:Subject:Date:From; b=hvkMfRfsx1Bj//qZ6Af9KO82lOjLzev8rHjAwCPq+DZLtigA8rwcRu1GVkS2An7Hc oUfgsV6bHMGLSKONdcbPK5n2wTxA99GLg3BVaF1KXxXljcsPTILWFJoHc7ZVRpq0VU +kWHWhM/0jKjT2yXS8c+NfjAqpCC43CNPn3fGz5Y= From: "stefan at bytereef dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/113664] New: False positive warnings with -fno-strict-overflow (-Warray-bounds, -Wstringop-overflow) Date: Mon, 29 Jan 2024 21:50:06 +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: 14.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: stefan at bytereef dot 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: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter target_milestone 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=3D113664 Bug ID: 113664 Summary: False positive warnings with -fno-strict-overflow (-Warray-bounds, -Wstringop-overflow) Product: gcc Version: 14.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c Assignee: unassigned at gcc dot gnu.org Reporter: stefan at bytereef dot org Target Milestone: --- These false positives only occur in combination with fno-strict-overflow: =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -Warray-bounds =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D foo.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D #include static char * f(char *s, int n, char *dot) { switch(n) { case 1: if (s =3D=3D dot) { *s++ =3D '.'; } *s++ =3D '0'; /* fall-through (yes, really!) */ default: if (s =3D=3D dot) { *s++ =3D '.'; } } *s =3D '\0'; return s; } char * g(char *s) { return f(s, 1, NULL); } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D $ /home/skrah/gcc/bin/gcc -Wall -O3 -c foo.c $ /home/skrah/gcc/bin/gcc -Wall -O3 -fno-strict-overflow -c foo.c In function =E2=80=98f=E2=80=99, inlined from =E2=80=98g=E2=80=99 at foo.c:25:10: foo.c:11:10: warning: array subscript 0 is outside array bounds of =E2=80= =98char[0]=E2=80=99 [-Warray-bounds=3D] 11 | *s++ =3D '0'; /* fall-through (yes, really!) */ | ~~~~~^~~~~ In function =E2=80=98g=E2=80=99: cc1: note: source object is likely at address zero =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D -Wstringop-overflow=20 =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D bar.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D #include static char * f(char *s, int n, char *dot) { switch(n) { case 1: if (s =3D=3D dot) { *s++ =3D '.'; } *s++ =3D '0'; /* fall-through (yes, really!) */ default: if (s =3D=3D dot) { *s++ =3D '.'; } } *s =3D '\0'; return s; } char * g(char *s) { char sign =3D '+'; *s++ =3D sign; return f(s, 1, NULL); } =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D $ /home/skrah/gcc/bin/gcc -Wall -O3 -c bar.c $ /home/skrah/gcc/bin/gcc -Wall -O3 -fno-strict-overflow -c bar.c In function =E2=80=98f=E2=80=99, inlined from =E2=80=98g=E2=80=99 at bar.c:28:12: bar.c:11:10: warning: writing 1 byte into a region of size 0 [-Wstringop-overflow=3D] 11 | *s++ =3D '0'; /* fall-through (yes, really!) */ | ~~~~~^~~~~ In function =E2=80=98g=E2=80=99: cc1: note: destination object is likely at address zero Note that a very small change gives a very different warning.=