From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C21313858D3C; Fri, 9 Jun 2023 16:52:17 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C21313858D3C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1686329537; bh=mX9o6CGEbKjc5ay4yWUTjEasHfgF7OSiDDQavv9TGv8=; h=From:To:Subject:Date:In-Reply-To:References:From; b=jXrVWr/QmtUeCro6etoAxZtm2wTSN3/h6SJ76Art5HjyySXqIn+HXMWOYMfvqg/BU T0oQ0JXvyJJKwgYyPVkNwgfk1F36ftEHh7BmoYFto3ijsAIxFOgDW8gPqmggbJjCAM b463Tqfqz1c22gG9KYM/tUgIR1+lmg8CEOpInJKU= From: "pinskia at gcc dot gnu.org" To: gcc-bugs@gcc.gnu.org Subject: [Bug tree-optimization/53265] Warn when undefined behavior implies smaller iteration count Date: Fri, 09 Jun 2023 16:52:17 +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: 4.8.0 X-Bugzilla-Keywords: diagnostic X-Bugzilla-Severity: enhancement X-Bugzilla-Who: pinskia at gcc dot gnu.org X-Bugzilla-Status: NEW 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=3D53265 --- Comment #31 from Andrew Pinski --- For the testcase in comment #0 we do warn: : In function 'void foo()': :7:47: warning: iteration 3 invokes undefined behavior [-Waggressive-loop-optimizations] 7 | for (i=3D0, accum=3Da[0]; i < N; i++, accum+=3Da[i]) | ~~~^ :7:27: note: within this loop 7 | for (i=3D0, accum=3Da[0]; i < N; i++, accum+=3Da[i]) | ~~^~~ For comment #2: : In function 'void fn1()': :11:14: warning: iteration 64 invokes undefined behavior [-Waggressive-loop-optimizations] 11 | a[i] =3D i * 0x02000001; | ~~^~~~~~~~~~~~ :10:17: note: within this loop 10 | for (i =3D 0; i < 128; ++i) | ~~^~~~~ : In function 'void fn2()': :22:22: warning: iteration 112 invokes undefined behavior [-Waggressive-loop-optimizations] 22 | a[i] =3D (i + 1LL) * 0x0123456789ABCDEFLL; | ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~ :21:17: note: within this loop 21 | for (i =3D 0; i < 128; i++) | ~~^~~~~ : In function 'void fn3()': :35:16: warning: iteration 8 invokes undefined behavior [-Waggressive-loop-optimizations] 35 | c[i + 8] =3D b[i]; | ~~~~~~~~~^~~~~~ :33:17: note: within this loop 33 | for (i =3D 0; i < (int) (sizeof (a) / sizeof (a[0])); i++) | ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ : In function 'void fn5()': :64:24: warning: iteration 950 invokes undefined behavior [-Waggressive-loop-optimizations] 64 | a[23940 + j - 950] =3D b[j]; | ~~~~~~~~~~~~~~~~~~~^~~~~~ :63:17: note: within this loop 63 | for (j =3D 0; j < 1140; j++) | ~~^~~~~~ : In function 'void fn3()': :35:16: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' writing 16 bytes into a region of size 8 overflows the destination [-Wstringop-overflow=3D] 35 | c[i + 8] =3D b[i]; | ~~~~~~~~~^~~~~~ :29:31: note: at offset 8 into destination object 'c' of size 16 29 | unsigned char a[16], b[16], c[16]; | ^ :36:16: warning: 'void* __builtin_memcpy(void*, const void*, long unsigned int)' writing 16 bytes into a region of size 8 overflows the destination [-Wstringop-overflow=3D] 36 | a[i + 8] =3D b[i + 8]; | ~~~~~~~~~^~~~~~~~~~ :29:17: note: at offset 8 into destination object 'a' of size 16 29 | unsigned char a[16], b[16], c[16]; | ^ So this looks partialy fixed. Someone will need to do a summary of what is fixed and not though.=