[PATCH] avoid assuming every type has a size (PR 89662)

Richard Biener richard.guenther@gmail.com
Tue Mar 12 08:25:00 GMT 2019


On Mon, Mar 11, 2019 at 9:16 PM Martin Sebor <msebor@gmail.com> wrote:
>
> A -Warray-bounds enhancement committed last year into GCC 9
> introduced an assumption that the MEM_REF type argument has
> a size.  The test case submitted in PR89662 does pointer
> addition on void*, in which the MEM_REF type is void*, which
> breaks the assumption.
>
> The attached change removes this assumption and considers such
> types to have the size of 1.  (The result is used to scale
> the offset in diagnostics after it has been determined to be
> out of bounds.)

Why's this not catched here:

  if (POINTER_TYPE_P (reftype)
      || !COMPLETE_TYPE_P (reftype)
^^^

      || TREE_CODE (TYPE_SIZE_UNIT (reftype)) != INTEGER_CST
      || RECORD_OR_UNION_TYPE_P (reftype))
    return;

and what avoids the bad situation for

  char (*a)[n];
  sink (a - 1);

?  That is, the code assumes TYPE_SIZE_UNIT is an INTEGER_CST
but the above should get you a non-constant type?  It's probably
easier to generate a gimple testcase with this.

Richard.

> Martin



More information about the Gcc-patches mailing list