Bug 84743

Summary: c++ segfault with va_arg(marker, float)
Product: [Retired] Red Hat Linux Reporter: Jim Lindstrom <jlindstr>
Component: gcc3Assignee: Jakub Jelinek <jakub>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: medium Docs Contact:
Priority: medium    
Version: 8.0   
Target Milestone: ---   
Target Release: ---   
Hardware: i386   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-10-03 12:16:07 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Jim Lindstrom 2003-02-20 23:28:17 UTC
Description of problem:

I'm trying to use a variable number of float args in a class member function. 
I've deleted all the file components that aren't central to the bug, leaving
only a minimal set of code.  gcc (invoked by 'c++') complains that the float
should be promoted to a double, and then segfaults at the end of the procedure.

Version-Release number of selected component (if applicable):

[jlindstr@herbert temp]$ gcc -v
Reading specs from /usr/lib/gcc-lib/i386-redhat-linux/3.2/specs
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --enable-shared --enable-threads=posix
--disable-checking --host=i386-redhat-linux --with-system-zlib --enable-__cxa_atexit
Thread model: posix
gcc version 3.2 20020903 (Red Hat Linux 8.0 3.2-7)

How reproducible:
Every single time

Steps to Reproduce:
1. Setup these two files in the same directory
//----------------------------------------------------------------------------//
// MultiPan.h
//----------------------------------------------------------------------------//

#ifndef MOSS_MULTIPAN_H
#define MOSS_MULTIPAN_H

#include <vector>

class MultiPan
{
private:
	int n_channels;
public:
	MultiPan(int nChans);
    
	void addEntry(float t, ...);
};

#endif //MOSS_MULTIPAN_H

//----------------------------------------------------------------------------//
// MultiPan.cpp
//----------------------------------------------------------------------------//

#include <cstdarg>
#include "MultiPan.h"

MultiPan::MultiPan(int nChans)
{
	n_channels = nChans;
}
   
void MultiPan::addEntry(float t, ...)
{
	va_list marker;
	int i;
	float y_i, total;

	// total the params
	va_start(marker, t);
	for(i=0;i<n_channels;i++)
		//total += va_arg(marker, double);
		total += va_arg(marker, float);
	va_end(marker);

	// now actually set the entries
	va_start(marker, t);
	for(i=0;i<n_channels;i++)
	{
		//y_i = va_arg(marker, double);
		y_i = va_arg(marker, float);
		//(InterpList[i])->addEntry(t, y_i/total);
	}
	va_end(marker);
}

//----------------------------------------------------------------------------//

2. invoke the compiler:
c++ -O2 -ftemplate-depth-25 -c MultiPan.cpp -o MultiPan.o
    
Actual results:
MultiPan.cpp: In member function `void MultiPan::addEntry(float, ...)':
MultiPan.cpp:21: warning: `float' is promoted to `double' when passed through `...'
MultiPan.cpp:21: warning: (so you should pass `double' not `float' to `va_arg')
MultiPan.cpp:29: warning: `float' is promoted to `double' when passed through `...'
MultiPan.cpp:33: internal error: Segmentation fault
Please submit a full bug report, 
[...]

Expected results:

Normal compilation

Additional info:

When I call va_arg with 'double' instead of 'float' (leaving the function
prototype as is), everything then works fine.

Comment 1 Richard Henderson 2004-10-03 12:16:07 UTC
ICE fixed with gcc 3.3.2-1.