https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96188
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Keywords| |alias
Component|c++ |tree-optimization
--- Comment #6 from Martin Sebor <msebor at gcc dot gnu.org> ---
The example in comment #4 is due to the same problem/limitation in the
optimizer. The IL that triggers the warning is below:
<bb 2> [local count: 1073741833]:
MEM[(struct _Vector_impl_data *)&v] ={v} {CLOBBER};
_32 = operator new (3);
_27 = _32 + 3; <<< _27
*_32.x = 0;
MEM[(struct S *)_32 + 1B].x = 0;
MEM[(struct S *)_32 + 2B].x = 0;
__cur_3 = &MEM <struct S> [(void *)_32 + 3B]; <<< same as _27
if (__cur_3 != _27) <<< must be false
goto <bb 3>; [82.57%]
else
goto <bb 7>; [17.43%]
<bb 3> [local count: 797929761]:
MEM[(struct S *)_32 + 3B] = 0; <<< -Wstringop-overflow=
goto <bb 5>; [100.00%]
GCC doesn't fold the equality (_32 + 3 == &MEM <struct S> [(void *)_32 + 3B]).
A simplified test case for that limitation is below:
$ cat t.c && gcc -O2 -S -Wall -fdump-tree-optimized=/dev/stdout t.c
struct S { char a[3]; };
void f (struct S *p)
{
void *q0 = p + 1;
void *q1 = p->a + sizeof *p;
if (q0 != q1) // not folded but should be
__builtin_abort ();
}
;; Function f (f, funcdef_no=0, decl_uid=1945, cgraph_uid=1, symbol_order=0)
void f (struct S * p)
{
void * q1;
void * q0;
<bb 2> [local count: 1073741824]:
q0_2 = p_1(D) + 3;
q1_3 = &MEM <char[3]> [(void *)p_1(D) + 3B];
if (q0_2 != q1_3)
goto <bb 3>; [0.00%]
else
goto <bb 4>; [100.00%]
<bb 3> [count: 0]:
__builtin_abort ();
<bb 4> [local count: 1073741824]:
return;
}