IBM Support

IV70765: INCORRECT CONVERSION FROM DOUBLE TO INTEGER WITH -O2

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • When compiling with -O2, the resulting binary produces incorrect
    results at runtime:
    
    ===== COMPILE COMMAND:
    xlc -q64 -qarch=pwr7 -O2 f.c main.c
    
    ===== TESTCASE:
    $ cat f.c
    double f(long *l, double *d) {
      l[0] = (int)*d;
      return *d - (int)*d;
    }
    $ cat main.c
    #include <stdio.h>
    int main()
    {
      long l;
      double d = 42.42;
      extern double f(long *l, double *d);
      f(&l, &d);
      printf("%lx\n", l);
      return 0;
    }
    $
    
    ===== ACTUAL OUTPUT:
    $ ./a.out
    2a0000002a
    $
    
    
    ===== EXPECTED OUTPUT:
    $ ./a.out
    2a
    $
    

Local fix

  • N/A
    

Problem summary

  • USERS AFFECTED:
    Users who have code that casts from double to int may see this
    problem.
    Optimization level must be at least O2 for this problem to
    appear.
    
    PROBLEM DESCRIPTION:
    Cast form double to int will sometimes produce incorrect
    results.
    

Problem conclusion

  • The problem was caused by an optimization that went too far and
    sometimes folded instructions when it was not correct to do so.
    The fix prevents that folding in those incorrect situations.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV70765

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    D10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2015-03-10

  • Closed date

    2015-07-28

  • Last modified date

    2015-07-28

  • 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

  • RD10 PSY

       UP

[{"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":"13.1"}]

Document Information

Modified date:
03 October 2021