IBM Support

IV55902: INVALID OUTPUT WITH -O2

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • Consider the following example:
    
    cat $test.c
    #include <stdio.h>
    #include <stdlib.h>
    
    #define TOKENSTRING " ,;\t\15\n"
    #define FALSE 0
    #define TRUE  1
    
    static char *MyToken ( char *String, char *Delimiter );
    
    int main ( void )
    {
       char      TestString[80];
       char     *s;
    
       sprintf ( TestString, "type var '[s] testfall'" );
       s = MyToken ( TestString, TOKENSTRING );
       printf ( "1 <%s>\n", s );
    
       while ( s != NULL ) {
          s = MyToken ( NULL, TOKENSTRING );
          printf ( "2 <%s>\n", s );
       }
       return ( 0 );
    }
    
    static char *MyToken ( char *String,  char *Delimiter )
    {
    
    /*--------------------------------------------------------------
    /  Do not account for delimiters found in [] or ''.            /
    /------------------------------------------------------------* /
       static char   *p = NULL;
              char   *s, *Begin;
              int     BracketOpen, Apostroph;
    
            if ( String != NULL ) p = String;
       else if ( p      == NULL ) return ( NULL );
    
       BracketOpen = Apostroph = FALSE;
       Begin       = p;
    
    
    /*--------------------------------------------------------------
    / '\0' and '\n' are taken as delimiters too.                   /
    /-------------------------------------------------------------*/
       while ( (*p != '\0') && (*p != '\n') ) {
    
    /*------------------------------------------------------------ -
    / Account for [ and '.
    / Within brackets and apostrophs,                              /
    / no delimiters  shall be evaluated.                          /
    ----------------------------------------------------- - -----*/
          if ( *p == '[' ) BracketOpen = TRUE;
          if ( *p == '\'') Apostroph   = !Apostroph;
          if ( !(BracketOpen || Apostroph) ) {
    
    /*-------------------------------------------------------------
    / We are outside brackets or apostrophs;                       /
    /   thus we can evaluate the delimiter.                        /
    /------------------------------------------------------------*/
             s = Delimiter;
             while ( *s != '\0' ) {
                if ( *p == *s ) {
                   *p++ = '\0';
                   return ( Begin );
                }
                s++;
             }
          }
    
          if ( *p == ']' ) BracketOpen = FALSE;
          p++;
       }
       if ( p != Begin ) { *p = '\0'; return ( Begin ); }
       else                           return ( NULL);
    }
    
    Compile it with -O2 and execute the binary:
    
    xlc -O2 test.c
    ./a.out
    
    Expected output:
    
     ./a.out
    1 <type>
    2 <var>
    2 <'[s] testfall'>
    2 <>
    <end of output>
    
    but the binary generates the following output:
    
    ./a.out
    1 <type>
    2 <var>
    2 <'[s]>
    2 <testfall'>
    2 <>
    <end of output>
    

Local fix

  • Compile with noopt or -O3 and above.
    

Problem summary

  • Incorrect optimization
    

Problem conclusion

  • The problem had been fixed
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV55902

  • Reported component name

    XL C/C++ AIX

  • Reported component ID

    5724X1300

  • Reported release

    C10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2014-02-25

  • Closed date

    2014-07-18

  • Last modified date

    2014-07-18

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

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

    LI77977

Fix information

  • Fixed component name

    XL C FOR AIX

  • Fixed component ID

    5725C7100

Applicable component levels

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

Document Information

Modified date:
01 October 2021