public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/65752] New: Too strong optimizations int -> pointer casts
@ 2015-04-13 14:04 gcc at robbertkrebbers dot nl
  2015-04-13 17:38 ` [Bug c/65752] " joseph at codesourcery dot com
                   ` (36 more replies)
  0 siblings, 37 replies; 39+ messages in thread
From: gcc at robbertkrebbers dot nl @ 2015-04-13 14:04 UTC (permalink / raw)
  To: gcc-bugs

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"


^ permalink raw reply	[flat|nested] 39+ messages in thread

end of thread, other threads:[~2020-08-05  7:07 UTC | newest]

Thread overview: 39+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-04-13 14:04 [Bug c/65752] New: Too strong optimizations int -> pointer casts gcc at robbertkrebbers dot nl
2015-04-13 17:38 ` [Bug c/65752] " joseph at codesourcery dot com
2015-04-13 23:25 ` gcc at robbertkrebbers dot nl
2015-04-13 23:25 ` gcc at robbertkrebbers dot nl
2015-04-14  8:39 ` rguenth at gcc dot gnu.org
2015-04-14  8:46 ` gcc at robbertkrebbers dot nl
2015-04-14  9:01 ` rguenth at gcc dot gnu.org
2015-04-14  9:06 ` rguenth at gcc dot gnu.org
2015-04-14  9:23 ` gcc at robbertkrebbers dot nl
2015-04-14  9:26 ` gcc at robbertkrebbers dot nl
2015-04-14 10:50 ` rguenth at gcc dot gnu.org
2015-04-20 13:45 ` [Bug tree-optimization/65752] " mpolacek at gcc dot gnu.org
2015-04-20 13:53 ` gcc at robbertkrebbers dot nl
2015-05-18 17:13 ` gil.hur at sf dot snu.ac.kr
2015-05-19  9:21 ` rguenth at gcc dot gnu.org
2015-05-19 12:08 ` gil.hur at sf dot snu.ac.kr
2015-05-19 12:33 ` rguenth at gcc dot gnu.org
2015-05-19 13:14 ` gil.hur at sf dot snu.ac.kr
2015-05-19 14:21 ` rguenther at suse dot de
2015-05-19 14:29 ` gil.hur at sf dot snu.ac.kr
2015-05-19 14:32 ` mpolacek at gcc dot gnu.org
2015-05-19 15:12 ` gil.hur at sf dot snu.ac.kr
2015-05-19 15:23   ` Andreas Schwab
2015-05-19 15:23 ` schwab at suse dot de
2015-05-19 15:29 ` gil.hur at sf dot snu.ac.kr
2015-05-20  8:01 ` rguenth at gcc dot gnu.org
2015-05-20 10:55 ` gil.hur at sf dot snu.ac.kr
2015-05-20 11:20 ` gil.hur at sf dot snu.ac.kr
2015-05-20 11:33 ` rguenther at suse dot de
2015-05-22  4:55 ` mail at robbertkrebbers dot nl
2015-05-22  4:57 ` gcc at robbertkrebbers dot nl
2015-05-22  8:52 ` rguenth at gcc dot gnu.org
2015-05-23  8:14 ` gil.hur at sf dot snu.ac.kr
2015-05-26 11:26 ` rguenther at suse dot de
2015-05-26 13:55 ` gil.hur at sf dot snu.ac.kr
2015-05-26 14:00 ` rguenther at suse dot de
2015-05-26 14:06 ` gil.hur at sf dot snu.ac.kr
2020-08-04 21:31 ` tavianator at gmail dot com
2020-08-05  7:07 ` rguenther at suse dot de

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).