Bug 85321

Summary: const double arguments and -ffloat-store do not work together
Product: [Retired] Red Hat Linux Reporter: Need Real Name <richard>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED CURRENTRELEASE QA Contact:
Severity: high Docs Contact:
Priority: medium    
Version: 7.2   
Target Milestone: ---   
Target Release: ---   
Hardware: i686   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2004-10-03 12:39:14 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:

Description Need Real Name 2003-02-27 23:41:03 UTC
Description of problem:
//////////main.c
extern double rightfunc(double);
extern double wrongfunc(double);
int
main(void)
{
  if (rightfunc(0.75) != 0.75)
    return 1;
  const double x = 0.25;
  if (wrongfunc(x) != 0.25)
    return 2;
  return 0;
}

//////////funcs.c
extern double rightfunc(double);
extern double wrongfunc(double);
double rightfunc(double t) { return t; }
double wrongfunc(const double t) { return t; }

//////////GNUmakefile:
all: right wrong
right: main.c funcs.c; gcc -O3 -o $@ main.c funcs.c
wrong: main.c funcs.c; gcc -O3 -ffloat-store -o $@ main.c funcs.c

With the three supplied files, use gmake to build.

The generated 'right' file works properly, but the
generated 'wrong' file generates incorrect code
for the 'wrongfunc' function:

wrongfunc:
        pushl   %ebp
        movl    %esp, %ebp
        subl    $8, %esp
        fldl    -8(%ebp)
        leave
        ret

Basically, the code uses memory that has not be set
to the value passed as the 'const double' argument.

Note that rightfunc() has a double argument, while
wrongfunc() has a const double argument.  Otherwise
they are the same.

The 'wrong' file is built with -ffloat-store while
the 'right' file is built without.


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

gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2)

How reproducible:
Always

Steps to Reproduce:
1. Create specified main.c, funcs.c, and GNUmakefile
2. gmake
3. ./wrong


Actual Results:  ./wrong exits with 2.


Expected Results:  ./wrong should exit with 0 (like ./right).


Additional info:

This bug occurs when using -ffloat-store with
gcc version 2.96 20000731 (Red Hat Linux 7.2 2.96-112.7.2),
with or without optimization.

It does not occur with gcc 2.91 or gcc 3.2.2.

Comment 1 Richard Henderson 2004-10-03 12:39:14 UTC
Indeed fixed in gcc 3.2.

Comment 2 Need Real Name 2004-10-03 23:15:17 UTC
So, 584 days after the bug report was submitted,
the only response is to repeat a point made in
the initial report and close the bug report?

Comment 3 Jakub Jelinek 2004-10-03 23:28:06 UTC
RHL 7.2 is not supported any longer, this will not be fixed in
GCC 2.96-RH.

Comment 4 Need Real Name 2004-10-03 23:49:52 UTC
But it was supported at the time that the
bug report was submitted.