Bug 55544 - -fexcess-precision=standard is not implemented for C++
Summary: -fexcess-precision=standard is not implemented for C++
Status: RESOLVED DUPLICATE of bug 323
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.7.2
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2012-11-30 12:30 UTC by Jörg Richter
Modified: 2014-01-02 08:38 UTC (History)
2 users (show)

See Also:
Host: x86_64-unknown-linux-gnu
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jörg Richter 2012-11-30 12:30:32 UTC
$ cat t.c
#include <stdio.h>
int main( int argc, char** argv )
{
  long long v1;
  sscanf( argv[1], "%lld", &v1 );
  double d = (double)v1;
  long long v2 = (long long)d;
  printf( "v1=%lld d=%19.0f v2=%lld\n", v1, d, v2 );
  return 0;
}

$ gcc -m32 -O -o t t.c
$ t 9223372036854774781
v1=9223372036854774781 d=9223372036854774784 v2=9223372036854774781

please note that v1 == v2.  This is wrong

$ gcc -m32 -o t t.c
$ t 9223372036854774781
v1=9223372036854774781 d=9223372036854774784 v2=9223372036854774784

v2 == d.  This is correct
-m64 (with or without optimisation) works too
Comment 1 Mikael Pettersson 2012-11-30 12:37:49 UTC
(In reply to comment #0)
>   double d = (double)v1;

Doesn't this overflow and provoke undefined behaviour when v1 is 9223372036854774781LL (0x7ffffffffffffbfd)?
Comment 2 Jakub Jelinek 2012-11-30 12:42:38 UTC
You need to use -fexcess-precision=standard or -std=c99 on i?86, the default is -fexcess-precision=fast unless -std=c99 (even for -std=gnu99).
Otherwise it might be evaluated with excess precision, and the number in question fits into the 80-bit long double just fine.
Comment 3 Jörg Richter 2012-11-30 13:07:07 UTC
Okay thanks.
This testcase is derived from C++ source.
Using g++ -fexcess-precision=standard results in:

cc1plus: sorry, unimplemented: -fexcess-precision=standard for C++

Can we change this bug to an enhancment request?

I think I will use volatile then ...
Comment 4 Jakub Jelinek 2012-11-30 13:14:24 UTC
For C++ you can use -ffloat-store (of course, the penalty for that is quite big).
Or better -msse2 -mfpmath=sse if you don't need to support prehistoric HW.
Comment 5 Jörg Richter 2012-11-30 13:47:24 UTC
-ffloat-store works. But I dont want to use it in our project.

-msse2 -mfpmath=sse does not work.
I still see fildll,fnstcw,... instructions in the assembler listing.
Comment 6 Andrew Pinski 2012-11-30 18:06:40 UTC
This is a dup of bug 323.

*** This bug has been marked as a duplicate of bug 323 ***
Comment 7 Jörg Richter 2012-12-01 09:53:13 UTC
I see no reference to -fexcess-precision=standard in (garbage sink) bug 323, do you? So IMHO this is not a dup.
Comment 8 joseph@codesourcery.com 2012-12-01 20:53:02 UTC
On Sat, 1 Dec 2012, joerg.richter@pdv-fs.de wrote:

> I see no reference to -fexcess-precision=standard in (garbage sink) bug 323, do
> you? So IMHO this is not a dup.

See comment 127 in that bug.