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

--- Comment #6 from Alexander Cherepanov <ch3root at openwall dot com> ---
(In reply to Alexander Cherepanov from comment #2)
> But my guess is that the C++ rules will not help. The problem is the
> internal inconsistency so everything will blow up independently of any
> external rules.

Well, the following example should illustrate what I mean. The uninitialized
variable `y` is only used in dead code:

----------------------------------------------------------------------
#include <stdio.h>

__attribute__((noipa)) // imagine it in a separate TU
static int opaque(int i) { return i; }

int main()
{
    short x = opaque(1);
    short y;

    opaque(x - 1);

    while (opaque(1)) {
        printf("x = %d;  x - 1 = %d\n", x, opaque(1) ? x - 1 : 5);

        if (opaque(1))
            break;

        if (x - 1 == y)
            opaque(y);
    }
}
----------------------------------------------------------------------
$ gcc -std=c11 test.c && ./a.out
x = 1;  x - 1 = 0
$ gcc -std=c11 -O3 test.c && ./a.out
x = 1;  x - 1 = 5
----------------------------------------------------------------------
gcc x86-64 version: gcc (GCC) 10.0.1 20200126 (experimental)
----------------------------------------------------------------------

There is some defence in tree-ssa-loop-unswitch.c against loop unswitching on
undefined values but, as you wrote in comment 1, it's probably not that easy.

Reply via email to