http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51554

             Bug #: 51554
           Summary: ICE in cp/semantics.c:cxx_eval_indirect_ref with -Wall
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassig...@gcc.gnu.org
        ReportedBy: dnovi...@gcc.gnu.org
                CC: ja...@redhat.com, sing...@gcc.gnu.org


In:

static tree
cxx_eval_indirect_ref (const constexpr_call *call, tree t,
                       bool allow_non_constant, bool addr,
                       bool *non_constant_p)
{
[ ... ]
  if (r)
    r = cxx_eval_constant_expression (call, r, allow_non_constant,
                                      addr, non_constant_p);
  else
    {
      tree sub = op0;
      STRIP_NOPS (sub);
      if (TREE_CODE (sub) == ADDR_EXPR
          || TREE_CODE (sub) == POINTER_PLUS_EXPR)
        {
==>          gcc_assert (!same_type_ignoring_top_level_qualifiers_p
==>                      (TREE_TYPE (TREE_TYPE (sub)), TREE_TYPE (t)));
          /* DR 1188 says we don't have to deal with this.  */
          if (!allow_non_constant)

at the point of the failure, we have:

t: *((const uint8 *) &XX[0] + 1);
sub: (const uint8 *) &XX[0] + 1;

and (naturally) TREE_TYPE(t) is the same as TREE_TYPE(TREE_TYPE(sub)), so the
assertion fails trivially. 

The values for T and SUB seem to come unmodified all the way up from
process_init_constructor_array.  The original source code where this is coming
from is:

const uint8 F::V[] = {
  ...
  *(reinterpret_cast<const uint8*>(&XX[0]) + 1),
  ...
};

This code seems to be enabled only with -Wall, the following reproducer only
fails if compiled with -Wall:

$ cat a.cc
typedef unsigned char uint8;
typedef unsigned int uint32;

const uint32 XX[] = { 1, 3, 7 };

const uint8 V[] = {
  *(reinterpret_cast<const uint8*>(&XX[0]) + 0),
  *(reinterpret_cast<const uint8*>(&XX[0]) + 1),
  *(reinterpret_cast<const uint8*>(&XX[0]) + 2),
  *(reinterpret_cast<const uint8*>(&XX[0]) + 3),
  *(reinterpret_cast<const uint8*>(&XX[1]) + 0),
  *(reinterpret_cast<const uint8*>(&XX[1]) + 1),
  *(reinterpret_cast<const uint8*>(&XX[1]) + 2),
  *(reinterpret_cast<const uint8*>(&XX[1]) + 3),
};

$ g++ -Wall -c a.cc
a.cc:15:1: internal compiler error: in cxx_eval_indirect_ref, at
cp/semantics.c:7321
Please submit a full bug report,
with preprocessed source if appropriate.

Reply via email to