IBM Support

IV75942: SETJMP USAGE WITH -QHOT OPTIMIZATION SKIPS CODE SECTION

Subscribe

You can track all active APARs for this component.

APAR status

  • Closed as program error.

Error description

  • After -qhot optimization, code found after a nested loop is
    not being run.  The nested loop contains a setjmp call, and
    after exiting, does not branch to the remaining code in the
    parent loop.
    
    
       === TEST CASE ===
    
    #include <stdio.h>
    #include <setjmp.h>
    
    int test(int loop, int flag)
    {
     int i, n, error;
     jmp_buf jbuf;
    
     printf("<BEGIN-FOR loop = %d>\n", loop);
     for (i = 0; i < loop; i++)
     {
      n = 0;
      printf(" <BEGIN-WHILE n = %d>\n", n);
      while(!n)
      {
       if ((error = setjmp(jbuf)) == 0)
       {
        n = printf(" <IN-WHILE error = %d>\n", error);
       }
       else
       {
        if (error == 100)
        {
         if (flag)
          printf(" flag = %d\n", flag);
         break;
        }
        else
         printf(" error = %d\n", error);
       }
      printf(" <IN-WHILE n = %d>\n",n);
      }
      printf(" <END-OF-WHILE>\n");  // qhot opt skips this line
     }
     printf("<END-OF-FOR>\n");
    }
    
    int main()
    {
     test(1, 1);
     return 0;
    }
    
    
    $ xlc -O2 -qhot test.c
    $ ./a.out
    <BEGIN-FOR loop = 1>
     <BEGIN-WHILE n = 0>
     <IN-WHILE error = 0>
     <IN-WHILE n = 22>
    <END-OF-FOR>
    
    $ xlc -O2 -qnohot test.c
    $ ./a.out
    <BEGIN-FOR loop = 1>
     <BEGIN-WHILE n = 0>
     <IN-WHILE error = 0>
     <IN-WHILE n = 22>
     <END-OF-WHILE>
    <END-OF-FOR>
    

Local fix

  • Compile with -qnohot
    

Problem summary

  • USERS AFFECTED:
    Users of setjmp with -qhot may be affected by this issue.
    
    
    PROBLEM DESCRIPTION:
    This issue was caused by an internal optimization trying to
    straighten control flow that shouldn't be straightened.
    The test case makes use of unnatural/irreducible loops but due
    to an optimization issue, the compiler identifies that the
    control flow cannot be straightened
    but then overwrites that value to the default value.
    

Problem conclusion

  • The compiler will now store the results for all nodes correctly.
    

Temporary fix

Comments

APAR Information

  • APAR number

    IV75942

  • Reported component name

    XL C/C++ FOR AI

  • Reported component ID

    5725C7200

  • Reported release

    D10

  • Status

    CLOSED PER

  • PE

    NoPE

  • HIPER

    NoHIPER

  • Special Attention

    NoSpecatt

  • Submitted date

    2015-08-12

  • Closed date

    2015-10-14

  • Last modified date

    2015-10-14

  • 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

  • RD10 PSY

       UP



Document information

More support for: XL C/C++ for AIX
Compiler

Software version: 13.1

Reference #: IV75942

Modified date: 14 October 2015