This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug tree-optimization/65752] Too strong optimizations int -> pointer casts
- From: "pinskia at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Sun, 15 Nov 2015 21:24:39 +0000
- Subject: [Bug tree-optimization/65752] Too strong optimizations int -> pointer casts
- Auto-submitted: auto-generated
- References: <bug-65752-4 at http dot gcc dot gnu dot org/bugzilla/>
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=65752
--- Comment #39 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
(In reply to Alexander Cherepanov from comment #38)
> IMHO this bug is not specific to integers and boils down to this: when a
> check for equality ignores provenance for some reason, phiopt nevertheless
> will replace one variable by another with the wrong provenance.
>
> Integers are surely compared without regard to prevenance. That's one case.
> Another case is a comparison of two pointers when one of the lost its
> provenance info. E.g. the program (somewhat based on pr61502):
>
> #include <stdint.h>
> #include <stdio.h>
>
> int main()
> {
> int y, x = 0;
> int *volatile v = &x;
> int *xp = v;
> int *i = &y + 1;
>
> if (xp != i) {
> printf("hello\n");
> xp = i;
> }
>
> *xp = 15;
>
> printf("%d\n", x);
> }
>
> prints 0 for me with gcc 5.2.0 -O2.
Except the above testcase is invalid/undefined as &y + 1 is undefined if
deferenced and &x and &y + 1 cannot be compared in a defined sense as both
deals with two different arrays.