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

            Bug ID: 90694
           Summary: incorrect representation of ADDR_EXPR involving a
                    pointer to array
           Product: gcc
           Version: 9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: middle-end
          Assignee: unassigned at gcc dot gnu.org
          Reporter: msebor at gcc dot gnu.org
  Target Milestone: ---

As mentioned in bug 90662 comment #2, the format of an ADDR_EXPR involving
pointers to arrays printed in tree dumps is incorrect: it's missing the
required parentheses.  The test case below shows the problem.  In it the strlen
argument in #1 is equivalent to #2 but not to #3 or #4.  Similarly, the strlen
argument in #3 is equivalent to #4 but not to the other two.

But the IL representation of #1 that's in the dump is identical to the source
in #3: &*p[2], whose representation is actually p + 16.  This is incorrect and
makes tree dumps involving such expressions misleading.

typedef char A8[8];

int f0 (A8 *p)
{
  return __builtin_strlen (&(*p)[2]);     // #1: this is equivalent...
}

int f1 (A8 *p)
{ 
  return __builtin_strlen ((*p) + 2);     // #2: ...to this
}


int g0 (A8 *p)
{
  return __builtin_strlen (&*p[2]);       // #3: and this is equivalent...
}

int g1 (A8 *p)
{
  return __builtin_strlen ((*(p + 2)));   // #4: ...to this 
}

f0 (char[8] * p)
{
  int D.1969;

  _1 = &*p[2];                            ;; #1: but this corresponds to #3
above
  _2 = __builtin_strlen (_1);
  D.1969 = (int) _2;
  return D.1969;
}


f1 (char[8] * p)
{
  int D.1971;

  _1 = p + 2;
  _2 = __builtin_strlen (_1);
  D.1971 = (int) _2;
  return D.1971;
}


g0 (char[8] * p)
{
  int D.1973;

  _1 = p + 16;
  _2 = __builtin_strlen (_1);
  D.1973 = (int) _2;
  return D.1973;
}


g1 (char[8] * p)
{
  int D.1975;

  _1 = p + 16;
  _2 = __builtin_strlen (_1);
  D.1975 = (int) _2;
  return D.1975;
}

Reply via email to