[Bug middle-end/21985] [4.0/4.1 Regression] miscompiled or wrong code snippet?

pinskia at gcc dot gnu dot org gcc-bugzilla@gcc.gnu.org
Thu Jun 9 21:55:00 GMT 2005


------- Additional Comments From pinskia at gcc dot gnu dot org  2005-06-09 21:55 -------
(In reply to comment #4)
> Pointer subtraction is only defined for pointers to the same array object.
> So this code has undefined behaviour.

Yes that might be true but we can get a testcase where it fails even though it is valid code:
void abort (void);
int
main (void)
{
  unsigned char *b;
  unsigned size;

  b = ((unsigned char *)&b)+1;

  /* location of pointer on stack - pointer - constvar */
  size = ((unsigned char *) &b) - b;
  if (size!=-1)
    abort ();
  return 0;
}

-- 
           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|RESOLVED                    |REOPENED
         Resolution|INVALID                     |


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



More information about the Gcc-bugs mailing list