public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/31484]  New: va_list handeling different in 64bit vs 32 bit.
@ 2007-04-05  9:23 Klaas dot Vantournhout at UGent dot be
  2007-04-05  9:31 ` [Bug c++/31484] " schwab at suse dot de
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Klaas dot Vantournhout at UGent dot be @ 2007-04-05  9:23 UTC (permalink / raw)
  To: gcc-bugs

Hi,

It seems that a va_list is messed up when doing multiple functioncalls
containing the va_list.  This only occurs in the 64bit versions of g++ and does
NOT occur in the 32bit versions.

This has been seen in versions 4.1.1 and 4.1.2

Below is all the suff you need (buildparameters, testcode and output)

Regards
Klaas

64 bit version
[klaas]$ g++ -v
Using built-in specs.
Target: x86_64-mandriva-linux-gnu
Configured with: ../configure --prefix=/usr --libexecdir=/usr/lib
--with-slibdir=/lib64 --mandir=/usr/share/man --infodir=/usr/share/info
--enable-checking=release
--enable-languages=c,c++,ada,fortran,objc,obj-c++,java
--host=x86_64-mandriva-linux-gnu --with-cpu=generic --with-system-zlib
--enable-threads=posix --enable-shared --enable-long-long --enable-__cxa_atexit
--disable-libunwind-exceptions --enable-clocale=gnu --enable-java-awt=gtk
--with-java-home=/usr/lib/jvm/java-1.4.2-gcj-1.4.2.0/jre --enable-gtk-cairo
--disable-libjava-multilib --enable-ssp --disable-libssp
Thread model: posix
gcc version 4.1.2 20070302 (prerelease) (4.1.2-1mdv2007.1)

The compiled code
<start code>
#include <iostream>
#include <cstdarg>

void f1(int,...);
void f1b(int, ...);
void f2(va_list);


int main(void) {
  std::cout << "f1" << std::endl;
  f1(3,1.2,3.6,5.9);
  std::cout << "f1b" << std::endl;
  f1b(3,1.2,3.6,5.9);
  return 0;
}
/* this function fails */
void f1(int n, ...) {
  va_list va;
  va_start(va, n);

  for (int i = 0; i < 2; ++i)
    f2(va);

  va_end(va);
}
/* this is a solution */
void f1b(int n, ...) {
  va_list va;

  for (int i = 0; i < 2; ++i) {
    va_start(va,n);
    f2(va);
    va_end(va);
  }
}

void f2(va_list va) {
  double arg1 = va_arg(va,double);
  double arg2 = va_arg(va,double);
  double arg3 = va_arg(va,double);

  std::cout << arg1 << "\t" << arg2 << "\t" << arg3 << std::endl;
}
<end code>

The 64bit output is given by
[klaas@x86_64]$ g++ bug.cpp
[klaas@x86_64]$ ./a.out
f1
1.2     3.6     5.9
3.95253e-323    2.3528e-310     2.3528e-310
f1b
1.2     3.6     5.9
1.2     3.6     5.9

The 32 bit output is given by
[klaas@i586]$ g++ bug.cpp
[klaas@i586]$ ./a.out
f1
1.2     3.6     5.9
1.2     3.6     5.9
f1b
1.2     3.6     5.9
1.2     3.6     5.9


-- 
           Summary: va_list handeling different in 64bit vs 32 bit.
           Product: gcc
           Version: 4.1.2
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: c++
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: Klaas dot Vantournhout at UGent dot be


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31484


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/31484] va_list handeling different in 64bit vs 32 bit.
  2007-04-05  9:23 [Bug c++/31484] New: va_list handeling different in 64bit vs 32 bit Klaas dot Vantournhout at UGent dot be
@ 2007-04-05  9:31 ` schwab at suse dot de
  2007-04-05  9:35 ` Klaas dot Vantournhout at UGent dot be
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: schwab at suse dot de @ 2007-04-05  9:31 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from schwab at suse dot de  2007-04-05 10:31 -------
Not a bug.  You must call va_start/va_end whenever you want to reuse a va_list.


-- 

schwab at suse dot de changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31484


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/31484] va_list handeling different in 64bit vs 32 bit.
  2007-04-05  9:23 [Bug c++/31484] New: va_list handeling different in 64bit vs 32 bit Klaas dot Vantournhout at UGent dot be
  2007-04-05  9:31 ` [Bug c++/31484] " schwab at suse dot de
@ 2007-04-05  9:35 ` Klaas dot Vantournhout at UGent dot be
  2007-04-05  9:47 ` schwab at suse dot de
  2007-04-05 14:35 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: Klaas dot Vantournhout at UGent dot be @ 2007-04-05  9:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from Klaas dot Vantournhout at UGent dot be  2007-04-05 10:35 -------
What is the difference then between 32bit and 64bit?  In the 32bit it works.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31484


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/31484] va_list handeling different in 64bit vs 32 bit.
  2007-04-05  9:23 [Bug c++/31484] New: va_list handeling different in 64bit vs 32 bit Klaas dot Vantournhout at UGent dot be
  2007-04-05  9:31 ` [Bug c++/31484] " schwab at suse dot de
  2007-04-05  9:35 ` Klaas dot Vantournhout at UGent dot be
@ 2007-04-05  9:47 ` schwab at suse dot de
  2007-04-05 14:35 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: schwab at suse dot de @ 2007-04-05  9:47 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from schwab at suse dot de  2007-04-05 10:47 -------
7.15 Variable arguments <stdarg.h>
3 [...] The object ap may be passed as an argument to another function; if that
function invokes the va_arg macro with parameter ap, the value of ap in the
calling function is indeterminate and shall be passed to the va_end
macro prior to any further reference to ap.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31484


^ permalink raw reply	[flat|nested] 5+ messages in thread

* [Bug c++/31484] va_list handeling different in 64bit vs 32 bit.
  2007-04-05  9:23 [Bug c++/31484] New: va_list handeling different in 64bit vs 32 bit Klaas dot Vantournhout at UGent dot be
                   ` (2 preceding siblings ...)
  2007-04-05  9:47 ` schwab at suse dot de
@ 2007-04-05 14:35 ` pinskia at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-04-05 14:35 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from pinskia at gcc dot gnu dot org  2007-04-05 15:34 -------
note you can also use va_copy but that is c99.


-- 


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=31484


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2007-04-05 14:35 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-04-05  9:23 [Bug c++/31484] New: va_list handeling different in 64bit vs 32 bit Klaas dot Vantournhout at UGent dot be
2007-04-05  9:31 ` [Bug c++/31484] " schwab at suse dot de
2007-04-05  9:35 ` Klaas dot Vantournhout at UGent dot be
2007-04-05  9:47 ` schwab at suse dot de
2007-04-05 14:35 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).