Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

No, but that just makes me assume that this is an optimization bug. Especially since -O4 actually coughs up different pointers:

  gcc-7 -std=c11 -O4 -o test test.c
  $ ./test
  0x7fff5b5f5a08 0x7fff5b5f5a10 0
The following code works as expected even with your flags and the pointers are clearly not related to one another:

  #include <stdio.h>
  #include <stdint.h>
  
  int main(void) {
      uint32_t *p = ((uint32_t *)0x7fffffffffff3eac)+1;
      uint32_t *q = (uint32_t *)0x7fffffffffff3eb0;
      printf("%p %p %d\n", (void *)p, (void *)q, p == q);
      return 0;
  }
So, I would either chalk this up to either 1) "compiler optimization bug" unless a gcc maintainer explicitly gave me a reason to believe to the contrary or 2) getting your underwear eaten by weasels because you optimized after invoking undefined behavior (attempting to probe stack layouts qualifies as undefined behavior in a big way).

My assumption would be that the compiler had to do something screwball that it got wrong because you actually asked for a pointer to a stack object that it had optimized to always be in registers.



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: