This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/65752] New: Too strong optimizations int -> pointer casts
- From: "gcc at robbertkrebbers dot nl" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 13 Apr 2015 14:04:08 +0000
- Subject: [Bug c/65752] New: Too strong optimizations int -> pointer casts
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65752
Bug ID: 65752
Summary: Too strong optimizations int -> pointer casts
Product: gcc
Version: 4.9.2
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: gcc at robbertkrebbers dot nl
The following program prints "0" instead of the expected "15":
#include <stdio.h>
#include <stdint.h>
#include <limits.h>
int main() {
int x = 0, *p = 0;
for (uintptr_t i = 0; ; i++) {
if (i == (uintptr_t)&x) { p = (int*)i; break; }
}
*p = 15;
printf("%d\n", x);
}
gcc -O2 makes too strict assumptions about non-aliasing here: it removes the
loop entirely (which is perfectly fine), but then assumes that the pointers p
and &x are unrelated.
NB 1: I do not think that DR #260 applies here
NB 2: When compiled with clang, it also optimizes out the loop, but it does
print the expected "15"