Bug 20952

Summary: -finstrument-functions breaks on functions returning doubles
Product: [Retired] Red Hat Linux Reporter: Alexander Larsson <alexl>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED CURRENTRELEASE QA Contact: David Lawrence <dkl>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.0CC: alla
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-03-08 13:33:38 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 Alexander Larsson 2000-11-16 14:30:09 UTC
Compiling code that returns doubles with -finstrument-functions is broken.
This does not depend on -O or -g flags.

This program:
double function (void)
{
  return 10.0;
}
int main(void)
{
  double d = function ();
  printf ("res: %f\n", d);
}

outputs:

res: nan

Here is the generated code:
function:
	pushl	%ebp
	movl	%esp, %ebp
	pushl	%esi
	pushl	%ebx
	subl	$16, %esp
	subl	$8, %esp
	pushl	4(%ebp)
	pushl	$function
	call	__cyg_profile_func_enter
	addl	$16, %esp
	movl	$0, %ebx
	movl	$1076101120, %esi
	subl	$8, %esp
	pushl	4(%ebp)
	pushl	$function
	call	__cyg_profile_func_exit
	addl	$16, %esp
	movl	%ebx, -16(%ebp)
	movl	%esi, -12(%ebp)
	fldl	-16(%ebp)
	leal	-8(%ebp), %esp
	popl	%ebx
	popl	%esi
	popl	%ebp
	fstp	%st(0)
	ret

Everything seems peachy, except the last "fstp %st(0)" which just throws
away the calculated result.

This is pretty bad. I regulary use -finstrument-functions to profile
Mozilla and other things.

Comment 1 Jakub Jelinek 2001-03-14 16:20:44 UTC
I have fixed this in my tree, am just bootstrapping CVS gcc with it before
submitting it to gcc-patches. It will appear later on in gcc-2.96-79.

Comment 2 Jakub Jelinek 2001-09-06 17:08:54 UTC
Oops, forgot to close this. It was really fixed in 2.96-79 and above.

Comment 3 Miloslav Trmac 2004-03-08 13:33:38 UTC
Fix confirmed in gcc-3.3.2-1.