IBM Support

IJ00526: INCORRECT STATIC STRING WITH OPTIMIZATION

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

  • A problem occurs when inlining a function from an include file
    that uses static data, while using compiler optimization.  In
    some cases, multiple copies of the static variable occur instead
    of the single instance expected.
    
    
       === TEST CASE ===
    
    ----------------------------------------------------------------
    apar1.cpp:
    #include <apar3.h>
    #include <iostream>
    
    int main() {
        std::cout << Derived::GetStr() << "\n";
    }
    
    ----------------------------------------------------------------
    apar2.cpp:
    #include <apar3.h>
    
    void Derived::InitStr() {
        GetStr() = "Derived class did this.";
    }
    
    ----------------------------------------------------------------
    apar3.h:
    #ifndef INCLUDED_APAR3
    #define INCLUDED_APAR3
    
    #include <string>
    
    template <typename Derived>
    struct Base {
        static std::string& GetStr();
        virtual ~Base() { }
    };
    
    template <typename Derived>
    std::string& Base<Derived>::GetStr() {
        static std::string str = "Base class did this.";
        static bool init = false;
        if (!init) {
            init = true;
            Derived::InitStr();
        }
        return str;
    }
    
    struct Derived : public Base<Derived> {
        static void InitStr();
    };
    
    #endif
    
    ----------------------------------------------------------------
    
    Output:
    $ xlC -I. apar1.cpp apar2.cpp -O3
    apar1.cpp:
    apar2.cpp:
    $ ./a.out
    Base class did this.
    $
    
    Expected Output:
    $ xlC -I. apar1.cpp apar2.cpp -O3
    apar1.cpp:
    apar2.cpp:
    $ ./a.out
    Derived class did this.
    $
    

Local fix

  • Lower optimization level.
    

Problem summary

  • PROBLEM DESCRIPTION:
    Inlined function is duplicating static variable.
    
    USERS AFFECTED:
    Users of inlining with optimization and static variables in
    header files.
    

Problem conclusion

  • The problem has been resolved.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IJ00526

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    C10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2017-10-10

  • Closed date

    2018-04-23

  • Last modified date

    2018-04-23

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

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

    IJ04431 IJ08166

Fix information

  • Fixed component name

    XL C FOR AIX

  • Fixed component ID

    5725C7100

Applicable component levels

[{"Business Unit":{"code":"BU048","label":"IBM Software"},"Product":{"code":"SSCFQM8","label":"Compiler"},"Component":"","ARM Category":[],"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"12.1","Edition":"","Line of Business":{"code":"","label":""}}]

Document Information

Modified date:
23 April 2018