[Bug middle-end/85974] [8/9 Regression] Failure to optimize difference of two pointers into a compile time constant

2018-07-12 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85974

Martin Sebor  changed:

   What|Removed |Added

 CC||msebor at gcc dot gnu.org

--- Comment #4 from Martin Sebor  ---
The optimization aside, the code in the test violates the C constraint that:

When two pointers are subtracted, both shall point to elements of the same
array object, or one past the last element of the array object; ...

Since s.f and s.b and distinct arrays (with s.b being treated as an array of
one element), the behavior of the test case is undefined.  GCC should diagnose
it before some optimization relies on code not doing these kinds of bad things
(as we have seen recently in bug 86259).

A valid (and more straightforward) way of writing the same code is:

  struct S
  {
char a, b, f[3];
  } s;

  long i = offsetof (struct S, f) - offsetof (struct S, b);

or (for the purposes of testing):

  long i = ((char*)&s + offsetof (struct S, f)) - (char*)&s + offsetof (struct
S, b));

[Bug middle-end/85974] [8/9 Regression] Failure to optimize difference of two pointers into a compile time constant

2018-07-12 Thread rguenth at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85974

Richard Biener  changed:

   What|Removed |Added

   Priority|P3  |P2
 Status|NEW |ASSIGNED
   Assignee|unassigned at gcc dot gnu.org  |rguenth at gcc dot 
gnu.org
   Target Milestone|--- |8.2

--- Comment #3 from Richard Biener  ---
Mine.