[Bug c/71598] New: Wrong optimization with aliasing enums

ch3root at openwall dot com gcc-bugzilla@gcc.gnu.org
Mon Jun 20 18:11:00 GMT 2016


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

            Bug ID: 71598
           Summary: Wrong optimization with aliasing enums
           Product: gcc
           Version: 7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ch3root at openwall dot com
  Target Milestone: ---

Source code:

----------------------------------------------------------------------
extern void abort (void);

enum e1 { c1 };
enum e2 { c2 };

__attribute__((noinline,noclone))
int f(enum e1 *p, enum e2 *q)
{
  *p = 1;
  *q = 2;
  return *p;
}

int main()
{
  unsigned x;

  if (f(&x, &x) != 2)
    abort();
}
----------------------------------------------------------------------

Results:

----------------------------------------------------------------------
$ gcc -std=c11 -pedantic -Wall -Wextra -O3 test.c && ./a.out
Aborted
----------------------------------------------------------------------

gcc version: gcc (GCC) 7.0.0 20160616 (experimental)

In gcc such enums are compatible with unsigned int. Hence they could alias. But
gcc seem to (wrongly) assume that *p and *q cannot refer to the same object.


More information about the Gcc-bugs mailing list