https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53265
--- Comment #31 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For the testcase in comment #0 we do warn:
<source>: In function 'void foo()':
<source>:7:47: warning: iteration 3 invokes undefined behavior
[-Waggressive-loop-optimizations]
7 | for (i=0, accum=a[0]; i < N; i++, accum+=a[i])
| ~~~^
<source>:7:27: note: within this loop
7 | for (i=0, accum=a[0]; i < N; i++, accum+=a[i])
| ~~^~~
For comment #2:
<source>: In function 'void fn1()':
<source>:11:14: warning: iteration 64 invokes undefined behavior
[-Waggressive-loop-optimizations]
11 | a[i] = i * 0x02000001;
| ~~^~~~~~~~~~~~
<source>:10:17: note: within this loop
10 | for (i = 0; i < 128; ++i)
| ~~^~~~~
<source>: In function 'void fn2()':
<source>:22:22: warning: iteration 112 invokes undefined behavior
[-Waggressive-loop-optimizations]
22 | a[i] = (i + 1LL) * 0x0123456789ABCDEFLL;
| ~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
<source>:21:17: note: within this loop
21 | for (i = 0; i < 128; i++)
| ~~^~~~~
<source>: In function 'void fn3()':
<source>:35:16: warning: iteration 8 invokes undefined behavior
[-Waggressive-loop-optimizations]
35 | c[i + 8] = b[i];
| ~~~~~~~~~^~~~~~
<source>:33:17: note: within this loop
33 | for (i = 0; i < (int) (sizeof (a) / sizeof (a[0])); i++)
| ~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
<source>: In function 'void fn5()':
<source>:64:24: warning: iteration 950 invokes undefined behavior
[-Waggressive-loop-optimizations]
64 | a[23940 + j - 950] = b[j];
| ~~~~~~~~~~~~~~~~~~~^~~~~~
<source>:63:17: note: within this loop
63 | for (j = 0; j < 1140; j++)
| ~~^~~~~~
<source>: In function 'void fn3()':
<source>: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=]
35 | c[i + 8] = b[i];
| ~~~~~~~~~^~~~~~
<source>:29:31: note: at offset 8 into destination object 'c' of size 16
29 | unsigned char a[16], b[16], c[16];
| ^
<source>: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=]
36 | a[i + 8] = b[i + 8];
| ~~~~~~~~~^~~~~~~~~~
<source>: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.