2 Replies Latest reply on Jan 9, 2019 8:13 AM by Maxim Kartashev-Oracle

    Bug in Studio 12.6 C++ compiler

    3853493

      Consider the following piece of code:

       

      =================

       

      typedef unsigned long long uint64;

      typedef unsigned long size_t;

       

      void convert_double(double* pool, size_t size)

      {

          union {

              double* d;

              uint64* i;

          } p;

          p.d = pool;

       

          for( size_t i=0; i < size; ++i )

          {

              p.i[i] &= 0x000fffffffffffffULL;

              p.i[i] |= 0x3ff0000000000000ULL;

              p.d[i] -= 0.99999999999999988898;

          }

      }

       

      =================

       

      When compiled I get the following error:

       

      % CC -fast -g -c bug.cc

       

      "bug.cc", [_Z14convert_doublePdm]: assertion failed in function tmpl_emit() @ tmpl.c:1543

      assert(tmpl != S_ILLEGAL)

       

      expr 101: st:24  fi:3  ln:16 lf:0   ty(Vr):60  r:1 a:0 nd:1  uc:1  bf:0  sc:0 inv:  CONVERT     EXP:100

       

       

      CC: ube failed for bug.cc

       

      % CC -V

      CC: Studio 12.6 Sun C++ 5.15 Linux_i386 2017/05/30

       

      Any suggestions for a workaround would be appreciated (other than changing the compiler flags, I would rather avoid that).

        • 1. Re: Bug in Studio 12.6 C++ compiler
          3853493

          Found a workaround. The following code

           

          =================

           

          typedef unsigned long long uint64;

          typedef unsigned long size_t;

           

          union pun

          {

              double d;

              uint64 i;

          };

           

          void convert_double(double* pool, size_t size)

          {

              for( size_t i=0; i < size; ++i )

              {

                  pun* p = reinterpret_cast<pun*>(pool+i);

                  p->i &= 0x000fffffffffffffULL;

                  p->i |= 0x3ff0000000000000ULL;

                  p->d -= 0.99999999999999988898;

              }

          }

           

          =================

           

          should be just as efficient and compiles OK. It may even be safer than the original code regarding strict aliasing rules.

          • 2. Re: Bug in Studio 12.6 C++ compiler
            Maxim Kartashev-Oracle

            This is certainly a bug in the Studio compiler. We have filed 29146330 for this issue; if you have a support contract, you an escalate for a patch.

            Thanks for reporting the problem!