IBM Support

IJ35502: RVO OVERWRITING PARAMETER TO FUNCTION

Subscribe to this APAR

By subscribing, you receive periodic emails alerting you to the status of the APAR, along with a link to the fix after it becomes available. You can track this item individually or track all items by product.

Notify me when this APAR changes.

Notify me when an APAR for this component changes.

 

APAR status

  • Closed as program error.

Error description

  • Return value optimization (RVO) is overwriting a function input
    parameter object reference, resulting in an incorrect addition
    calculation.
    
    The function calling the function using RVO (i.e. make() calling
    combine() ), should not be using a class return value that
    shares a memory location with one of the parameters.
    
    
    === TEST CASE ===
    
    #include <stdio.h>
    
    struct Numbers
    {
        Numbers() : a(0) , b(0) { }
        Numbers(int av, int bv) : a(av), b(bv) { }
    
        int a;
        int b;
    };
    
    Numbers combine(const Numbers& a, const Numbers& b)
    {
        Numbers x;          //  (1)
        x.a = a.a + b.a;
        x.b = a.b + b.b;
        return x;
    }
    
    Numbers make()
    {
        Numbers a(1, 1);    //  (2)
        Numbers b(2, 2);
    
        a = combine(a, b);
        return a;
    }
    
    int main()
    {
        Numbers a = make();
        printf("%d %d\n", a.a, a.b);
    }
    
    
    
    $ xlC test.cpp
    $ ./a.out
    2 2
    $
    
    Expected output is:
    3 3
    

Local fix

  • Add a user provided copy assignment operator:
    
    
    Numbers &operator=(const Numbers &other) { a = other.a; b =
    other.b; return *this; }
    

Problem summary

  • PROBLEM DESCRIPTION:
    Temporary elision is too aggressive and elides a necessary
    temporary, causing invalid runtime behaviour.
    
    USERS AFFECTED:
    Multiple levels of NRVO.
    

Problem conclusion

  • The temp elision has been corrected.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IJ35502

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    G10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2021-10-15

  • Closed date

    2021-12-13

  • Last modified date

    2021-12-13

  • 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/C++ FOR AI

  • Fixed component ID

    5725C7200

Applicable component levels

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

Document Information

Modified date:
14 December 2021