IBM Support

LI75902: INCORRECT OUT WITH -O2 AND -QSTATICINLINE

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • When an unused function is removed from the test case, the test
    case does not encounter a runtime logic error when compiled with
    -O2 and -qstaticinline.
    
    ===== Test case
    // Compile with:
    // xlC -O2 -qstaticinline xlcbug.C -o xlcbug
    
    #include <iostream>
    
    using namespace std;
    
    // This function is not used, but if I remove this, the bug goes
    away.
    static inline void foo(void)
    {
        cout << endl;
    }
    
    typedef unsigned long ulong;
    
    static inline ulong permute_inv(ulong inv, ulong perm)
    {
        if (perm >= 6) {
     ulong i = perm >= 18 ? 2 : (perm+4)/16;
     perm -= 6*(i+1);
     i = 3-i;
     ulong x = ((inv<<i) ^ inv) & 8;
     inv ^= x ^ (x>>i);
        }
        if (perm >= 2) {
     ulong i = 3 - perm/2;
     ulong x = ((inv<<i) ^ inv) & 4;
     inv ^= x ^ (x>>i);
        }
        if (perm & (inv ^ (inv>>1)) & 1)
     inv ^= 3;
        return inv;
    }
    
    struct FnPermT {
        unsigned inv : 5;
    };
    
    int bugfn = 16;
    
    static FnPermT minfn[1<<16];
    
    static void init_minfn(void)
    {
        ulong inv = permute_inv(1,2);
        minfn[bugfn].inv = permute_inv(1,2);
        if (minfn[16].inv != inv)
     printf("BUG: %u != %lu\n", minfn[bugfn].inv, inv);
    }
    
    int main(void)
    {
        init_minfn();
        return 0;
    }
    
    
    ==== Output
    #xlC -O2 -qstaticinline xlcbug.C -o a.opt
    # ./a.opt
    BUG: 0 != 4
    

Local fix

  • Remove the 'static inline void foo()' from the test case.
    
    When the 'foo()' function is removed, the test case executes
    successfully.
    
    
    ==== Output
    # xlC -O2 -qstaticinline xlcbug.C -o b.opt
    # ./b.opt
    #
    

Problem summary

  • Incorrect displacement calculation results in bad code
    generation, leading to incorrect output.
    

Problem conclusion

  • Fix displacement calculation.
    

Temporary fix

Comments

APAR Information

  • APAR number

    LI75902

  • Reported component name

    XL C/C++ RHEL52

  • Reported component ID

    5724U8310

  • Reported release

    A10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2011-01-27

  • Closed date

    2011-01-27

  • Last modified date

    2011-01-27

  • APAR is sysrouted FROM one or more of the following:

    IZ83423

  • APAR is sysrouted TO one or more of the following:

Fix information

  • Fixed component name

    XL C/C++ RHEL52

  • Fixed component ID

    5724U8310

Applicable component levels

[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SSJT9L","label":"XL C\/C++"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"A.1","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

Modified date:
15 October 2021