https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85651
Martin Sebor <msebor at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|UNCONFIRMED |NEW Last reconfirmed| |2018-05-07 CC| |msebor at gcc dot gnu.org Component|c++ |tree-optimization Ever confirmed|0 |1 --- Comment #2 from Martin Sebor <msebor at gcc dot gnu.org> --- Confirmed. The warning is issued from gimple-ssa-warn-restrict.c for the following expression: _68 = &logBuilder + _69; The offset _69 is in the anti-range ~[-9223372036854775800, -9223372036854775800] which the warning pass interprets as/transforms into [-9223372036854775799, -9223372036854775801] (this is the range referenced by the diagnostic). The builtin_memref::offset_out_of_bounds() function detects this kind of range and has special code to deal with it but only for references of ARRAY_TYPE. In the test case, logBuilder is RECORD_TYPE so the special handling isn't performed. The following lightly tested change adds this handling for structs as well to avoid the spurious warning. Index: gcc/gimple-ssa-warn-restrict.c =================================================================== --- gcc/gimple-ssa-warn-restrict.c (revision 260013) +++ gcc/gimple-ssa-warn-restrict.c (working copy) @@ -475,7 +475,10 @@ builtin_memref::offset_out_of_bounds (int strict, /* A temporary, possibly adjusted, copy of the offset range. */ offset_int offrng[2] = { offrange[0], offrange[1] }; - if (DECL_P (base) && TREE_CODE (TREE_TYPE (base)) == ARRAY_TYPE) + tree_code basecode = TREE_CODE (TREE_TYPE (base)); + if (DECL_P (base) + && (basecode == ARRAY_TYPE + || basecode == RECORD_TYPE)) { /* Check for offset in an anti-range with a negative lower bound. For such a range, consider only the non-negative subrange. */