[Bug c++/83060] ICE on valid C++ code: in ignore_overflows, at cp/cvt.c:583

jakub at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Mon Nov 20 14:16:00 GMT 2017


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=83060

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org,
                   |                            |jsm28 at gcc dot gnu.org,
                   |                            |nathan at gcc dot gnu.org

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Surely related to that.
The question is what to do.  E.g.
struct A { int i; int s[8]; } a;

int *p = &a.s[-1];
int *q = &a.s[__PTRDIFF_MAX__];
is accepted even with -pedantic-errors without any warnings, only if p/q are
constexpr there are errors.
So, shall we handle offsetof like the above without constexpr and not complain
at all (and thus drop the overflow bits somewhere silently)?

Another thing is that fold_offsetof_1 is I bet called with unfolded trees, so
just doing offsetof (A, s[0 - 1]) or offsetof (A, s[__PTRDIFF_MAX__]) could
bypass the -Warray-bounds stuff in that function.  Shall it c_fully_fold the
array index, or shall we just build OFFSETOF_EXPR always and handle it during
folding (guess that might be GCC9 material)?

For negative values, I wonder if we just shouldn't move the
  t = convert (sizetype, t);
before the
      /* Check if the offset goes beyond the upper bound of the array.  */
      if (TREE_CODE (t) == INTEGER_CST && tree_int_cst_sgn (t) >= 0)
(and then we wouldn't need to even do the && tree_int_cst_sgn (t) >= 0 part),
so that negative references are considered like very large positive ones; or if
there should be a special warning.
In any case, at least for __PTRDIFF_MAX__ the overflow is introduced during the
MULT_EXPR folding.


More information about the Gcc-bugs mailing list