From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 685C63856DD5; Fri, 22 Apr 2022 17:33:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 685C63856DD5 From: "thiago at kde dot org" To: gcc-bugs@gcc.gnu.org Subject: [Bug middle-end/105348] New: Overly aggressive -Warray-bounds after conditional Date: Fri, 22 Apr 2022 17:33:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: middle-end X-Bugzilla-Version: 12.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: thiago at kde 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 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 22 Apr 2022 17:33:09 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105348 Bug ID: 105348 Summary: Overly aggressive -Warray-bounds after conditional Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: middle-end Assignee: unassigned at gcc dot gnu.org Reporter: thiago at kde dot org Target Milestone: --- Testcase: #include char empty; void sink(int); bool cond(size_t); void f(const char *s, size_t l) { int n; if (cond(l)) { memcpy(&n, s, sizeof(n)); sink(n); } } void g() { f(&empty, 1); } #ifdef EXPAND bool cond(size_t l) { return l >=3D sizeof(int); } #endif $ gcc -DEXPAND -O3 -c -Wall -Wextra -Werror test.cpp && echo $? 0 $ gcc -O3 -c -Wall -Wextra -Werror test.cpp && echo $?=20=20=20=20=20=20=20= =20=20 In function =E2=80=98void f(const char*, size_t)=E2=80=99, inlined from =E2=80=98void f(const char*, size_t)=E2=80=99 at test.cpp:= 6:6, inlined from =E2=80=98void g()=E2=80=99 at test.cpp:17:6: test.cpp:10:15: error: array subscript =E2=80=98unsigned int[0]=E2=80=99 is= partly outside array bounds of =E2=80=98char [1]=E2=80=99 [-Werror=3Darray-bounds] 10 | memcpy(&n, s, sizeof(n)); | ~~~~~~^~~~~~~~~~~~~~~~~~ test.cpp: In function =E2=80=98void g()=E2=80=99: test.cpp:2:6: note: object =E2=80=98empty=E2=80=99 of size 1 2 | char empty; | ^~~~~ cc1plus: all warnings being treated as errors I've noticed this even when the other function was present and available for inlining. Unfortunately, for reasons outside of my direct control, GCC deci= ded not to inline that function, which meant it considers the condition bad.=