AFAIK this is the exact case of gcc bugzilla #84607:
As this is an upstream bug this should affect all distributions, maybe
the commenter on Debian is using 7.3.1 so he can't reproduce the
On Tue, Mar 13, 2018 at 2:36 PM, David C. Rankin
> Houston -- we have a problem.
> The problem is gcc is mis-applying optimizations, and it seems Arch
> specific. See discussion:
> [Why does not execute printf inside function?]
> The basic issue can be summarized in this short snippet:
> #include <stdio.h>
> int arr;
> int func()
> printf ("In func\n");
> return 0;
> int main (void)
> if (&arr[func()])
> printf("In main\n");
> return 0;
> Compile (with or without optimization) and the output on Archlinux (all
> packages current as of 1hr ago) and you get:
> $ ./bin/if2
> In main
> That is wrong. `func()` has been completely optimized out of the procedure
> in main(). The assembly generated omits any call to func. (full assembly
> posted as part of the answer on SO)
> Debian gcc 7.3 does not exhibit this same behavior. I do not know where to
> start looking to find why this is happening, but it does not take much of a
> stretch to see how this could be the root cause of some of the "unexplained"
> errors I and others have seen in the past few days on Arch.
> Let me know if I need to file a bug here. Since it "works on Debian" and not
> here, I suspect the bug should start here and so the default optimization we
> package with can be eliminated.
> What say the devs?
> David C. Rankin, J.D.,P.E.