[arch-general] gcc broken - Arch specific, applying optimization incorrectly - may explain unexplained problems

David C. Rankin drankinatty at suddenlinkmail.com
Tue Mar 13 06:36:40 UTC 2018


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?]
https://stackoverflow.com/questions/49248787/why-does-not-execute-printf-inside-function/49249533#49249533

  The basic issue can be summarized in this short snippet:

#include <stdio.h>

int arr[10];

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.


More information about the arch-general mailing list