This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

egcs-1.1: i386 stdcall function codegen bug



egcs version : release and mainline
binutils     : 2.9.1 and 980830 snapshots

There seems to be a i386 codegen bug that affects "stdcall" functions
returning anything larger than an integer.

For the following function,

  double __attribute__((stdcall))
  foo_local1 (double f) {
    return f;
  }

The assembly created (using -O2 -fomit-frame-pointer to cut noise), we
get the following. This causes the return value to be garbage unless
I comment out the "fstp" instruction. 

  .globl _foo_local1@8
  _foo_local1@8:
	  fldl 4(%esp)
	  fstp %st(0)		## <<<< offending instruction
	  ret $8

Interestingly, for a "cdecl" function, the fstp instruction is missing
and everything works as expected.

  double 
  foo_local2 (double f) {
    return f;
  }

  .globl _foo_local2
  _foo_local2:
	  fldl 4(%esp)		## <<<< no fstp instruction
	  ret

I'm attaching a trivial, but complete, test program that shows the 
problem.

Regards,
Mumit

#include <stdio.h>

#define WINAPI __attribute__((stdcall))

double WINAPI
foo_local1 (double f) {
  return f;
}

double 
foo_local2 (double f) {
  return f;
}

int 
main () 
{ 
  double f1, f2;
  f1 = 5.0;
  f2 = foo_local1 (f1);
  printf ("foo_local1 (%f) = %f\n", f1, f2);
  f2 = foo_local2 (f1);
  printf ("foo_local2 (%f) = %f\n", f1, f2);
  return 0;
}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]