IBM Support

IJ02084: MISSING POST-INCREMENT FOR GLOBAL VARIABLE IN CONDITIONAL WITH UNUSED OBJECT

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • A post-increment of a global variable in an IF conditional is
    not incremented when an unused object with a defined
    destructor is present in the same function:
    
            int glob_var = 0;     // GLOBAL VALUE
            ...
            {
                UnusedObj a;
                if (glob_var++) { return; }
    
    If the unused object does not have a defined destructor,
    the post-increment succeeds.
    
    
    
       === TEST CASE ===
    
    #include <cstdio>
    #include <cassert>
    
    int glob_var = 0;
    
    class UnusedObj {
      public:
        ~UnusedObj() { } // If commented out, problem does not occur
    };
    
    void initialize()
    {
        UnusedObj a;
        if (glob_var++) { return; }  // Post-increment
    }
    
    void shutdown()
    {
        UnusedObj a;
        assert(glob_var > 0);
    
        printf("%d\n",glob_var);
        if (--glob_var != 0) { return; }
    }
    
    int main(int argc, char *argv[])
    {
        initialize(); initialize();
        shutdown(); shutdown();
    }
    
    
    $ xlC apar.cpp
    
    OUTPUT:
    $ ./a.out
    1
    Assertion failed: glob_var > 0, file  apar.cpp, line 20
    IOT/Abort trap (core dumped)
    $
    
    EXPECTED OUTPUT:
    $ ./a.out
    2
    1
    $
    

Local fix

  • Remove destructor for unused object.
    

Problem summary

  • PROBLEM DESCRIPTION:
    Insertion of post-increment code into block may be inserted
    incorrectly.
    
    USERS AFFECTED:
    Post increment in the condition of an if-statement, if last
    statement in the conditional block is a return statement and
    implicit object destruction is pending.
    

Problem conclusion

  • Compiler may generate incorrect code in some cases with
    post-increment in the condition of an if-statement, if last
    statement in the conditional block is a return statement and
    implicit object destruction is pending.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IJ02084

  • 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-11-28

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

Fix information

  • Fixed component name

    XL C/C++ FOR AI

  • Fixed component ID

    5725C7200

Applicable component levels

  • RC10 PSY

       UP

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

Document Information

Modified date:
22 September 2021