IBM Support

LI71673: COMMA OPERATOR BEHAVES INCORRECTLY

Subscribe

You can track all active APARs for this component.

 

APAR status

  • Closed as program error.

Error description

  • The comma operator is not behaving correctly due to incorrect
    code generation. For the test case below the same output is
    expected from both functions: use_comma() and use_semi().
    
    Functions use_semi and use_comma should be functionally
    identical. However, in the use_comma case the code generator has
    remembered an offset (in the example you have 4 bytes). It has
    used this offset to modify the address it is zeroing. This is
    why the p[1] value has been incorrectly overwritten. If you
    play with the "struct punion" and put more things in where I
    have put "link" then the incorrect offset changes size. This
    will incorrectly overwrite a different offset from "p".
    
    
    TESTCASE:
    
    #include <stdio.h>
    
    typedef struct Pocket *PP;
    
    struct Pocket {
       union {                 // this seems to be critical
          struct {
             unsigned link;    // just to get some offset
             union {           // in front of this
                PP p;
                unsigned u;
                } lnsword[1];  // has to be an array
             } stack;
          } punion;
       };
    
    struct
    {
       PP   sistack;
       PP   clobbered;
    } root_pocket;
    
    #define TRpock root_pocket.sistack->punion.stack.lnsword[0].p
    
    void use_comma(PP *pp)
    {
       TRpock = *pp, *pp = 0;  // this gets the *pp = 0 part wrong!
    }
    
    void use_semi(PP *pp)
    {
       TRpock = *pp; *pp = 0;  // this gets the *pp = 0 part right!
    }
    
    int main(void)
    {
       struct Pocket frame;
       PP p[2];
    
       root_pocket.sistack = &frame;
       p[0] = &frame;
       use_semi(&p[0]);
    
       printf("using a semi gives a correct value for p[0] of \
              %p\n", p[0]);
    
       p[0] = &frame;
       p[1] = &frame;
       use_comma(&p[0]);
    
       printf("using a comma leaves an incorrect value for p[0] of \
              %p\n", p[0]);
       printf("and has zeroed p[1] = %p\n", p[1]);
    }
    
    
    $ xlc -qlist -qchars=unsigned -qcpluscmt t.c && a.out
    using a semi gives a correct value for p[0] of 0
    using a comma leaves an incorrect value for p[0] of 2ff22880
    and has zeroed p[1] = 0
    

Local fix

  • n/a
    

Problem summary

  • USERS AFFECTED:
    Users of comma operator.
    
    PROBLEM DESCRIPTION:
    Compiler was incorrectly
    generating code for the right operand of
    the comma operator when the left and the
    right operands are
    assignment expression that store a value
    into a member of the aggregate
    via a pointer derefence.
    
    WORKAROUND:
    Change the comma expression into
    two separate statements.
    
    EXPECTED ERRORS:
    None.
    

Problem conclusion

  • Compiler no longer generates incorrect code for the right
    operand.
    

Temporary fix

Comments

APAR Information

  • APAR number

    LI71673

  • Reported component name

    XL C/C++ RHEL4

  • Reported component ID

    5724K7720

  • Reported release

    701

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2006-10-25

  • Closed date

    2006-10-25

  • Last modified date

    2006-10-25

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

    IY76251

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

Fix information

  • Fixed component name

    XL C/C++ RHEL4

  • Fixed component ID

    5724K7720

Applicable component levels

[{"Business Unit":{"code":"BU054","label":"Systems w\/TPS"},"Product":{"code":"SSJT9L","label":"XL C\/C++"},"Platform":[{"code":"PF025","label":"Platform Independent"}],"Version":"7.0.1","Line of Business":{"code":"LOB08","label":"Cognitive Systems"}}]

Document Information

Modified date:
16 October 2021