IBM Support

IV80991: INCORRECT OUTPUT WITH -O2

Subscribe

You can track all active APARs for this component.

APAR status

  • Closed as program error.

Error description

  • When compiling with -O2 or higher using V13.1.x, the resulting
    program produces incorrect results at runtime:
    
    
    ===== COMPILE COMMAND:
    xlc -O2 xlc_optimiser_fault.c
    
    ===== TESTCASE:
    $ cat xlc_optimiser_fault.c
    #define SECS_IN_DAY     86400
    #define DATE_OFFSET     25567
    
    double stack[20];
    int sp;
    
    static void date_time ();
    
    main ()
    {
            unsigned long d;
    
            sp = -1;
            stack[++sp] = DATE_OFFSET + 16425;
            stack[++sp] = 0.0;
            stack[++sp] = 0.0;
    
            date_time ();
    
            printf ("d = %lu\n", (long)stack[0]);
            if (stack[0] == 0.0)
                    printf ("Incorrect return value\n");
            else
                    printf ("Correct return value\n");
    }
    
    static void date_time ()
    {
            unsigned long d, t;
            int gmt;
    
    #if 1
            gmt = (int) stack[sp--];
            t = (unsigned long) stack[sp--];
            d = (unsigned long) stack[sp];
    #else
            /* NOTE: If these are set manually it works */
            gmt = 0;
            t = 0;
            d = DATE_OFFSET + 16425;
    #endif
    
            if (t >= SECS_IN_DAY || d <= DATE_OFFSET)
            {
                    d = 0;
    #if 0
                    /* NOTE: If any line is added here it works */
                    printf ("This will cause it to work\n");
    #endif
            }
            else
            {
                    d -= DATE_OFFSET;
                    if (d > ((unsigned long)0xFFFFFFFFL /
    SECS_IN_DAY))
    #if 1
                            d = 0;
    #else
                            d = 1;  /* NOTE: if d = 1 is specified
    it works. */
    #endif
                    else
                    {
                            d *= SECS_IN_DAY;
                            d += t;
                    }
            }
            stack[sp] = d;
    }
    
    $
    
    
    ===== ACTUAL OUTPUT:
    $ ./a.out
    d = 0
    Incorrect return value
    $
    
    
    ===== EXPECTED OUTPUT:
    $ ./a.out
    d = 1419120000
    Correct return value
    $
    

Local fix

  • N/A
    

Problem summary

  • USERS AFFECTED:
    Users whose source code has some if-else condition range check
    merge opportunity but
    some value assignments occur between these target conditions;
    may be affected by this issue.
    
    PROBLEM DESCRIPTION:
    Unexpected behavior or incorrect results can occur due to this
    issue.
    

Problem conclusion

  • Do more checks on what is between the conditions and do not
    optimize if its dangerous.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV80991

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    D13

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2016-01-29

  • Closed date

    2016-06-10

  • Last modified date

    2016-06-10

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

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

Fix information

  • Fixed component name

    XL C FOR AIX

  • Fixed component ID

    5725C7100

Applicable component levels

  • RD13 PSY

       UP



Document information

More support for: XL C for AIX
Compiler

Software version: D13

Reference #: IV80991

Modified date: 10 June 2016