IBM Support

IJ08166: 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

    IJ08166

  • Reported component name

    XL C FOR AIX

  • Reported component ID

    5725C7100

  • Reported release

    D13

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt / Xsystem

  • Submitted date

    2018-08-02

  • Closed date

    2018-08-02

  • Last modified date

    2018-08-02

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

    IJ00526

  • 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



Document information

More support for: XL C for AIX
Compiler

Software version: D13

Reference #: IJ08166

Modified date: 02 August 2018