c/8221: return value of a function is forgotten

c.kaliszyk@zodiac.mimuw.edu.pl c.kaliszyk@zodiac.mimuw.edu.pl
Mon Oct 14 01:46:00 GMT 2002


>Number:         8221
>Category:       c
>Synopsis:       return value of a function is forgotten
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Mon Oct 14 01:46:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator:     c.kaliszyk@zodiac.mimuw.edu.pl
>Release:        3.2
>Organization:
>Environment:
Linux orka 2.5.40 #1 Thu Oct 3 07:30:38 CEST 2002 i686 unknown
configured with: /home/c/tmp/gcc-3.2/configure --prefix=3D/usr --enable-thr=
eads
>Description:
I tried to measure time twice, and substract these results.

When the function is inlined both results are stored in %ecx and after that
%ecx is substracted from itself, and I get zero.
Without inlining it works correct.
>How-To-Repeat:
I call "gcc -O2" on this:
--cut--
inline int getcputime(void) {
  int i;
  __asm__(
    "rdtsc
    movl %%eax, %0"
    : :"g" (i) :"ax", "dx");
  return i;
}

int main(void) {
  int x =3D getcputime();
  int y =3D getcputime();
  printf ("Time measure resolution: %i\n", y - x);
  return 0;
}
--cut--
>Fix:
Remove "inline" before the function definition or call gcc without -O
If the function is not inlined the return values of both calls are stored on
the stack in diffrent places and correctly substracted.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list