https://gcc.gnu.org/bugzilla/show_bug.cgi?id=92893
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Keywords| |diagnostic Status|UNCONFIRMED |NEW Last reconfirmed| |2019-12-10 Blocks| |88443 Ever confirmed|0 |1 --- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> --- The warning sees the IL below. It calls compute_objsize() to determine the size of the destination (what _34 points to) which, after failing to determine the size of the object the pointer points to, falls back on its type, which it determines from the assignment to _30 to be 1. A solution that I think would avoid the warning in this case is to work a harder and before falling back on using the type consider where the pointer comes from. Here, it's ADDR_EXPR (MEM_REF (SSA_NAME (get()), 1)), so by drilling into the operands we arrive at offset 1 from Buf*. Determining that offset 1 from Buf* corresponds to a trailing array would let us avoid the warning. I think all the bits to implement this are in place (particularly field_at_offset in gimple-ssa-sprintf.c), so they just need to be made use of here. #pragma GCC warning is unfortunately known to work poorly for middle-end warnings. It's also on my list of things to do for GCC 10 but I haven't gotten around to it yet. f (const char * p) { char * D.2771; struct Cat c; struct View D.2558; struct Cat D.2568; struct Buf * _6; long unsigned int _8; char * _30; char * _34; <bb 2> [local count: 1073741824]: _8 = __builtin_strlen (p_2(D)); _6 = get (); MEM[(char * {ref-all})_6] = 0; _30 = &MEM <char[1]> [(void *)_6 + 1B]; <<< char[1] __builtin_memcpy (_30, p_2(D), _8); _34 = _30 + _8; MEM <unsigned int> [(char * {ref-all})_34] = 7895160; <<< -Wstringop-overflow c ={v} {CLOBBER}; D.2568 ={v} {CLOBBER}; D.2558 ={v} {CLOBBER}; return; } Referenced Bugs: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88443 [Bug 88443] [meta-bug] bogus/missing -Wstringop-overflow warnings