[Bug tree-optimization/65752] Too strong optimizations int -> pointer casts
mail at robbertkrebbers dot nl
gcc-bugzilla@gcc.gnu.org
Fri May 22 04:55:00 GMT 2015
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65752
--- Comment #30 from mail at robbertkrebbers dot nl ---
Hi Gil,
Nice example! I am a bit occupied lately, and thus have not read all
comments at the bug report in detail. I will be away for the weekend,
but will read those quickly after.
Robbert
On 05/22/2015 04:12 AM, gil.hur at sf dot snu.ac.kr wrote:
> 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.
>
More information about the Gcc-bugs
mailing list