Uploaded image for project: 'C++ Standard Library'
  1. C++ Standard Library
  2. STDCXX-861

[Sun C++ 5.9/x86_64] bad codegen on va_arg and long double

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: External
    • Labels:
      None
    • Severity:
      Runtime Error

      Description

      Sun C++ 5.9 appears to generate incorrect code for x86_64 (but not for x86 or SPARC) the attached program involving va_arg() and long double.

      $ cat t.cpp && CC -m64 -V t.cpp && ./a.out
      #include <cassert>
      #include <cstdarg>
      #include <cstdio>
      #include <cstring>
      
      char buffer [80];
      const char* a1;
      int a2;
      const char* a3;
      int a4;
      const char* a5;
      long double a6;
      
      void setargs (std::va_list va) {
          a1 = va_arg (va, const char*);
          a2 = va_arg (va, int);
          a3 = va_arg (va, const char*);
          a4 = va_arg (va, int);
          a5 = va_arg (va, const char*);
          a6 = va_arg (va, long double);
      }
      
      void foo (const char *fmt, ...) {
          std::va_list va;
          va_start (va, fmt);
          setargs (va);
          std::sprintf (buffer, "%s %x %Lg", a3, a4, a6);
          va_end (va);
      }
      
      void bar (char *buf, const char *fmt, ...) {
          std::va_list va;
          va_start (va, fmt);
          setargs (va);
          std::sprintf (buf, "%s %x %Lg", a3, a4, a6);
          va_end (va);
      }
      
      int main () {
          char buf [80];
      
          foo (     "", "", 1, "", 0x12345678, "%Lg", 1.0L);
          bar (buf, "", "", 1, "", 0x12345678, "%Lg", 1.0L);
      
          std::puts (buffer);
          std::puts (buf);
      
          assert (0 == std::strcmp (buf, buffer));
          assert (0 == std::strcmp (buf, " 12345678 1"));
      }
      CC: Sun C++ 5.9 SunOS_i386 Patch 124864-01 2007/07/25
      /amd/packages/mdx/solaris/amd64/compilers/sun/C++5.9j1/prod/bin/c++filt: Sun C++ 5.9 SunOS_i386 2007/05/03
      ccfe: Sun C++ 5.9 SunOS_i386 Patch 124864-01 2007/07/25
      ld: Software Generation Utilities - Solaris Link Editors: 5.10-1.482
       12345678 1
       12345678 2.60544e-4932
      Assertion failed: 0 == std::strcmp (buf, buffer), file t.cpp, line 48
      Abort (core dumped)
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                Unassigned
                Reporter:
                sebor Martin Sebor
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated: