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

--- Comment #29 from Chung-Kil Hur <gil.hur at sf dot snu.ac.kr> ---
Dear Richard,

This time, I think I constructed a real bug.
Please have a look and correct me if I am wrong.

=====================
#include <stdio.h>

int main() {
  int x = 0;
  uintptr_t xp = (uintptr_t) &x;
  uintptr_t i;

  for (i = 0; i < xp; i++) { }

  *(int*)xp = 15;

  printf("%d\n", x);
}
=====================

This program prints "15" and I do not think this raises UB.

Now I add an if-statement to the program.

=====================
#include <stdio.h>

int main() {
  int x = 0;
  uintptr_t xp = (uintptr_t) &x;
  uintptr_t i;

  for (i = 0; i < xp; i++) { }

  /*** begin ***/
  if (xp != i) {
    printf("hello\n");
    xp = i;
  }
  /*** end ***/

  *(int*)xp = 15;

  printf("%d\n", x);
}
=====================

This program just prints "0".

Since "hello" is not printed, the if-statement is not executed.
However, it prints a different result than before, which I think is a bug.

Reply via email to