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

Alexander Cherepanov <ch3root at openwall dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ch3root at openwall dot com

--- Comment #38 from Alexander Cherepanov <ch3root at openwall dot com> ---
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.

The evident solution is to not apply this optimization when provenance info of
the two variables differs. I guess for most integers it will be the same.

Additionally, this optimization could be applied when provenance info for the
first variable is known but it's unknown for the second one. This leads to the
loss of provenance info and can prevent other optimizations.

Maybe a more complex solution is possible, like tracking provenance info
separately from the core value, I don't know.

Reply via email to