IBM Support

LI78230: -O OPTIMIZES AWAY AN IF CLAUSE

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • When compiling the following test case with -O2, the resulting
    binary leads to an incorrect output:
    
    ===== COMPILE COMMAND:
    xlC_r -qmakedep=gcc -D_AIX51 -D_LARGE_FILES
    -D__NO_XLC_BUILTIN_VA -DOS_LEVEL=710 -D_Packed= -qnotempinc
    -U__unix -q64 -qtbtable=full -qhalt=e -qalias=noansi -qutf -+ -O
    -qfdpr -qstrict -qlibansi -qinlglue -qmaxmem=-1 -DNDEBUG
    -qarch=pwr4 -qtune=balanced -qspill=2560 -qlonglong
    -qalign=natural -qldbl128  -qdebug=RNSSMALL -c -o test.o test.c
    
    xlC_r -o a.out -bcdtors:mbr::s -bweaklocal -q64 -brtl  -bbigtoc
    -lc -lc128 test.o  -lperfstat  -lrt -lwlm -lpthread -lm
    
    ===== TESTCASE:
    $ cat test.c
    #include <stdio.h>
    #include <stdlib.h>
    #include <unistd.h>
    
    typedef unsigned short P_CHAR;
    
    static bool isStandardChar(P_CHAR &c)
    {
            printf ("-->isStandardChar (%d: %c) a: %d z: %d
    \n",(P_CHAR) c, (P_CHAR) c, (P_CHAR)u'a', (P_CHAR)u'z');
        if ( (c >= (P_CHAR) u'a') && (c <= (P_CHAR) u'z') )
        {
            return true;
        }
        else if ( (c >= (P_CHAR) u'A') && (c <= (P_CHAR) u'Z') )
        {
            return true;
        }
        else if ( (c >= (P_CHAR) u'0') && (c <= (P_CHAR) u'9') )
        {
            return true;
        }
        else if ( ( c == u'_') || ( c == u':') ||
                  ( c == u'/') || ( c == u'-') ||
                  ( c == u';') )
        {
            return true;
        }
    
        return false;
    }
    
    int main(int argc, char** argv)
    {
        P_CHAR c = 117;
        if ( isStandardChar(c) )
            printf ("%c is a StandardChar\n", (P_CHAR) c);
            else
            printf ("%c is NOT a StandardChar\n", (P_CHAR) c);
    
        return 0;
    }
    $
    
    
    ===== ACTUAL OUTPUT:
    $ ./restKrn
    -->isStandardChar (117: u) a: 97 z: 122
    u is NOT a StandardChar
    $
    
    ===== EXPECTED OUTPUT:
    $ ./restKm
    -->isStandardChar (117: u) a: 97 z: 122
    u is a StandardChar
    

Local fix

  • Change
    
    typedef unsigned short P_CHAR;
    
    to
    
    typedef unsigned int P_CHAR;
    
    as a workaround.
    

Problem summary

  • USERS AFFECTED:
    Users who perform a range check of alphabetical ASCII
    characters (a-z,A-Z) in their code may be affected by this
    issue.
    
    PROBLEM DESCRIPTION:
    The compiler optimizes out an IF clause under specific
    circumstances whenever a char is checked for the range of
    alphabetical ASCII characters (a-z,A-Z).
    This occured because a parameter passed was mangled without
    restoring to next parameter.
    

Problem conclusion

  • The compiler has been fixed to properly check the range of
    alphabetical ASCII characters (a-z,A-Z).
    

Temporary fix

Comments

APAR Information

  • APAR number

    LI78230

  • Reported component name

    XL C/C++ FOR LI

  • Reported component ID

    5725C7300

  • Reported release

    D10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2014-10-30

  • Closed date

    2014-10-30

  • Last modified date

    2014-10-30

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

    IV62591

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

Fix information

  • Fixed component name

    XL C/C++ FOR LI

  • Fixed component ID

    5725C7300

Applicable component levels

[{"Business Unit":{"code":"BU058","label":"IBM Infrastructure w\/TPS"},"Product":{"code":"SSXVZZ","label":"XL C\/C++ for Linux"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"13.1","Line of Business":{"code":"LOB57","label":"Power"}}]

Document Information

Modified date:
17 October 2021