* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 1:46 gcc 2.96 optimization bug on RedHat7.0/alpha Uncle George
@ 2001-04-18 0:04 ` Christopher C. Chimelis
2001-04-18 3:41 ` Matt Wilson
2001-04-18 4:32 ` Brad Lucier
2 siblings, 0 replies; 25+ messages in thread
From: Christopher C. Chimelis @ 2001-04-18 0:04 UTC (permalink / raw)
To: Uncle George; +Cc: gcc-bugs, axp-list
On Tue, 17 Apr 2001, Uncle George wrote:
> with -O2 i get the wrong answer
>
> [gat@LX gat]$ gcc -g -O2 a.c -o a
> [gat@LX gat]$ ./a
> FlooR: x = 22.16, i0=1, i1=536871996
>
>
> with -O i get a passable answer
>
> [gat@LX gat]$ gcc -g -O a.c -o a
> [gat@LX gat]$ ./a
> FlooR: x = 22.16, i0=1077291253, i1=-1030792151
>
>
> BTW what exactly is the page one uses to submit/fill in the bug report
> for gcc et al ?
This has not been fixed in upstream gcc CVS, FYI. Using your source
and the gcc 3.0 snapshot from :
chris@spawn:
~/test > gcc-3.0 -g -O2 -o uncleg uncleg.c
chris@spawn:
~/test > ./uncleg
FlooR: x = 22.16, i0=1, i1=536872108
chris@spawn:
~/test > gcc-3.0 -g -O -o uncleg uncleg.c
chris@spawn:
~/test > ./uncleg
FlooR: x = 22.16, i0=1077291253, i1=-1030792151
My local copy of a patched 2.95.4pre returns the correct results, though,
so something broke between 2.95.x and 3.0pre.
Figured that you'd want to know :-)
C
^ permalink raw reply [flat|nested] 25+ messages in thread
* gcc 2.96 optimization bug on RedHat7.0/alpha
@ 2001-04-18 1:46 Uncle George
2001-04-18 0:04 ` Christopher C. Chimelis
` (2 more replies)
0 siblings, 3 replies; 25+ messages in thread
From: Uncle George @ 2001-04-18 1:46 UTC (permalink / raw)
To: gcc-bugs, axp-list
with -O2 i get the wrong answer
[gat@LX gat]$ gcc -g -O2 a.c -o a
[gat@LX gat]$ ./a
FlooR: x = 22.16, i0=1, i1=536871996
with -O i get a passable answer
[gat@LX gat]$ gcc -g -O a.c -o a
[gat@LX gat]$ ./a
FlooR: x = 22.16, i0=1077291253, i1=-1030792151
BTW what exactly is the page one uses to submit/fill in the bug report
for gcc et al ?
pgm is :
[gat@LX gat]$ cat a.c
double floor ( double );
main()
{
double d = 22.16;
floor( d );
}
double
floor( double x )
{
int i0,i1;
i0 = *((int*)&x+1);
i1 = *(int*)&x;
printf("FlooR: x = %g, i0=%d, i1=%d\n",x, i0, i1);
return x;
}
-----------------------------------------------------------
[gat@LX gat]$ gcc -v -save-temps -g -O2 a.c -o a
Reading specs from /usr/lib/gcc-lib/alpha-redhat-linux/2.96/specs
gcc version 2.96 20000731 (Red Hat Linux 7.0)
/usr/lib/gcc-lib/alpha-redhat-linux/2.96/cpp0 -lang-c -v -D__GNUC__=2
-D__GNUC_MINOR__=96 -D__GNUC_PATCHLEVEL__=0 -Dlinux -Dunix -D_LONGLONG
-D__alpha__ -D__ELF__ -D__linux__ -D__unix__ -D_LONGLONG -D__alpha__
-D__ELF__ -D__linux -D__unix -Asystem(linux) -D__OPTIMIZE__ -g
-D__LANGUAGE_C__ -D__LANGUAGE_C -DLANGUAGE_C -Acpu(alpha)
-Amachine(alpha) -D__alpha -D__alpha__ -D__alpha_ev4__ -Acpu(ev4) a.c
a.i
GNU CPP version 2.96 20000731 (Red Hat Linux 7.0) (cpplib)
(Alpha GNU/Linux for ELF)
ignoring nonexistent directory "/usr/alpha-redhat-linux/include"
#include "..." search starts here:
#include <...> search starts here:
/usr/local/include
/usr/lib/gcc-lib/alpha-redhat-linux/2.96/include
/usr/include
End of search list.
/usr/lib/gcc-lib/alpha-redhat-linux/2.96/cc1 a.i -quiet -dumpbase a.c
-g -O2 -version -o a.s
GNU C version 2.96 20000731 (Red Hat Linux 7.0) (alpha-redhat-linux)
compiled by GNU C version 2.96 20000731 (Red Hat Linux 7.0).
as -o a.o a.s
/usr/lib/gcc-lib/alpha-redhat-linux/2.96/collect2 -m elf64alpha -O3
-dynamic-linker /lib/ld-linux.so.2 -o a
/usr/lib/gcc-lib/alpha-redhat-linux/2.96/../../../crt1.o
/usr/lib/gcc-lib/alpha-redhat-linux/2.96/../../../crti.o
/usr/lib/gcc-lib/alpha-redhat-linux/2.96/crtbegin.o
-L/usr/lib/gcc-lib/alpha-redhat-linux/2.96
-L/usr/lib/gcc-lib/alpha-redhat-linux/2.96/../../.. a.o -lgcc -lc -lgcc
/usr/lib/gcc-lib/alpha-redhat-linux/2.96/crtend.o
/usr/lib/gcc-lib/alpha-redhat-linux/2.96/../../../crtn.o
[gat@LX gat]$
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 1:46 gcc 2.96 optimization bug on RedHat7.0/alpha Uncle George
2001-04-18 0:04 ` Christopher C. Chimelis
@ 2001-04-18 3:41 ` Matt Wilson
2001-04-18 4:32 ` Brad Lucier
2 siblings, 0 replies; 25+ messages in thread
From: Matt Wilson @ 2001-04-18 3:41 UTC (permalink / raw)
To: axp-list; +Cc: gcc-bugs
On Tue, Apr 17, 2001 at 09:46:08PM -0400, Uncle George wrote:
>
> BTW what exactly is the page one uses to submit/fill in the bug report
> for gcc et al ?
For 2.96 as shipped, use http://bugzilla.redhat.com/bugzilla
Cheers,
Matt
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 1:46 gcc 2.96 optimization bug on RedHat7.0/alpha Uncle George
2001-04-18 0:04 ` Christopher C. Chimelis
2001-04-18 3:41 ` Matt Wilson
@ 2001-04-18 4:32 ` Brad Lucier
2001-04-18 15:13 ` Uncle George
2 siblings, 1 reply; 25+ messages in thread
From: Brad Lucier @ 2001-04-18 4:32 UTC (permalink / raw)
To: axp-list; +Cc: gcc-bugs
>
> with -O2 i get the wrong answer
>
> [gat@LX gat]$ gcc -g -O2 a.c -o a
> [gat@LX gat]$ ./a
> FlooR: x = 22.16, i0=1, i1=536871996
>
>
> with -O i get a passable answer
>
> [gat@LX gat]$ gcc -g -O a.c -o a
> [gat@LX gat]$ ./a
> FlooR: x = 22.16, i0=1077291253, i1=-1030792151
In ISO C, the compiler can assume that the address of a real is not
the same as the address of an int, and gcc does so unless you give
the -fno-strict-aliasing flag:
popov-9% gcc -v
Reading specs from /export/u10/egcs-test/lib/gcc-lib/alphaev6-unknown-linux-gnu/3.1/specs
Configured with: ../configure --prefix=/export/u10/egcs-test --enable-checking=no --enable-shared=no
gcc version 3.1 20010415 (experimental)
popov-10% gcc -O2 -o a a.c
popov-11% ./a
FlooR: x = 22.16, i0=1, i1=536871788
popov-12% gcc -O2 -fno-strict-aliasing -o a a.c
popov-13% ./a
FlooR: x = 22.16, i0=1077291253, i1=-1030792151
So it may not be a bug.
Brad
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 15:13 ` Uncle George
@ 2001-04-18 13:40 ` Pawel Salek
2001-04-18 15:53 ` Uncle George
2001-04-18 14:03 ` David Woodhouse
2001-04-18 14:55 ` Michal Jaegermann
2 siblings, 1 reply; 25+ messages in thread
From: Pawel Salek @ 2001-04-18 13:40 UTC (permalink / raw)
To: axp-list
On 2001-04-18 17:13 Uncle George wrote:
> Any compiler that does not produce the correct code has a bug - baring
> any error messages.
>
> I suppose one has to deceide if an error message should be produced
> OR proper code should be produced.
So, proper code has been generated because ISO C allows that. Full stop.
I cannot imagine what error message should be produced (hm, ... "I am
producing the code following ISO C standard. You use ambigous type casts
and the result may be different from your expectations"). This gives
rise to a question what is "ambigous type cast" and what algorithm
should the compiler use to recognize that it is about to violate your
assumptions.
/Pawel
> >
> > In ISO C, the compiler can assume that the address of a real is not
> > the same as the address of an int, and gcc does so unless you give
> > the -fno-strict-aliasing flag:
--
Pawel Salek (pawsa@theochem.kth.se) http://www.theochem.kth.se/~pawsa/
Theoretical Chemistry Division, KTH voice: +46 8 790-8202
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 15:13 ` Uncle George
2001-04-18 13:40 ` Pawel Salek
@ 2001-04-18 14:03 ` David Woodhouse
2001-04-18 17:10 ` Uncle George
2001-04-18 14:55 ` Michal Jaegermann
2 siblings, 1 reply; 25+ messages in thread
From: David Woodhouse @ 2001-04-18 14:03 UTC (permalink / raw)
To: axp-list
gatgul@voicenet.com said:
> Any compiler that does not produce the correct code has a bug - baring
> any error messages.
How do you define 'correct'?
The compiler produced 'correct' code according to the ISO C standard. It
has no way of knowing what's 'correct' if you define that as meaning the
_intention_ of the programmer, even when they write incorrect source code.
The code posted was broken - or at least the assumption about the results
was incorrect. The compiler's behaviour was perfectly OK.
If you have code to enable a 'Do what I meant, not what I wrote' feature in
gcc, I'm sure we'd all be glad to see it - I know I've needed it before now :)
Gcc does have some warnings of the 'You wrote this; are you sure you didn't
mean something else' variety. Perhaps adding a warning for this situation
would be possible - perhaps not. But that wouldn't be a bug report, that
would be a feature request. And I believe gcc-3.0 is in feature-freeze
already.
--
dwmw2
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 15:13 ` Uncle George
2001-04-18 13:40 ` Pawel Salek
2001-04-18 14:03 ` David Woodhouse
@ 2001-04-18 14:55 ` Michal Jaegermann
2001-04-18 22:18 ` Uncle George
2 siblings, 1 reply; 25+ messages in thread
From: Michal Jaegermann @ 2001-04-18 14:55 UTC (permalink / raw)
To: axp-list
On Wed, Apr 18, 2001 at 11:13:59AM -0400, Uncle George wrote:
> Any compiler that does not produce the correct code has a bug - baring
> any error messages.
Indeed, but you should also add "from a correct source" for clarity.
> I suppose one has to deceide if an error message should be produced
> OR proper code should be produced.
Can you explain what you intended to see from your example and why?
I was looking at that code yesterday and scratching my head. I am
still not absolutely sure what the _real_ meaning was supposed to be.
If you want overlay different types you have 'union' construct for
that. Playing loose with pointers was not guaranteed to work ever.
Michal
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 4:32 ` Brad Lucier
@ 2001-04-18 15:13 ` Uncle George
2001-04-18 13:40 ` Pawel Salek
` (2 more replies)
0 siblings, 3 replies; 25+ messages in thread
From: Uncle George @ 2001-04-18 15:13 UTC (permalink / raw)
To: axp-list; +Cc: gcc-bugs
Any compiler that does not produce the correct code has a bug - baring any error messages.
I suppose one has to deceide if an error message should be produced OR proper code should be produced.
Its not terribly reasonable to have the defectively generated code around for some poor user to fall
over upon. AND I dont want to spend another day trying to figure out which one of the newly
installed Redhat 6.2/7.0, gcc, glib's were at fault in producing the wrong results ( for what ever
reason )
/gat
BTW did I say thanks for the insight ? It looks like a strange subject to get into, and a fairly
dangerous one if not taken into consideration. Its something I would not have considered at all.
Hummmm.
Brad Lucier wrote:
> >
> > with -O2 i get the wrong answer
> >
> > [gat@LX gat]$ gcc -g -O2 a.c -o a
> > [gat@LX gat]$ ./a
> > FlooR: x = 22.16, i0=1, i1=536871996
> >
> >
> > with -O i get a passable answer
> >
> > [gat@LX gat]$ gcc -g -O a.c -o a
> > [gat@LX gat]$ ./a
> > FlooR: x = 22.16, i0=1077291253, i1=-1030792151
>
> In ISO C, the compiler can assume that the address of a real is not
> the same as the address of an int, and gcc does so unless you give
> the -fno-strict-aliasing flag:
>
> popov-9% gcc -v
> Reading specs from /export/u10/egcs-test/lib/gcc-lib/alphaev6-unknown-linux-gnu/3.1/specs
> Configured with: ../configure --prefix=/export/u10/egcs-test --enable-checking=no --enable-shared=no
> gcc version 3.1 20010415 (experimental)
> popov-10% gcc -O2 -o a a.c
> popov-11% ./a
> FlooR: x = 22.16, i0=1, i1=536871788
> popov-12% gcc -O2 -fno-strict-aliasing -o a a.c
> popov-13% ./a
> FlooR: x = 22.16, i0=1077291253, i1=-1030792151
>
> So it may not be a bug.
>
> Brad
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 17:10 ` Uncle George
@ 2001-04-18 15:40 ` Pawel Salek
2001-04-18 16:17 ` David Woodhouse
` (2 subsequent siblings)
3 siblings, 0 replies; 25+ messages in thread
From: Pawel Salek @ 2001-04-18 15:40 UTC (permalink / raw)
To: axp-list
On 2001-04-18 19:10 Uncle George wrote:
> I'm sorry that u believe this but i believe that the results from
>
> -O0 == -O1 == -O2 == -O3 == -O4
>
> should all be the same.
Well, I am not sure if I do right rebutting this claim but the simplest
proof of your misunderstanding of the problem is the following program:
#include <stdio.h>
int main()
{
float f = 1.0/3.0;
printf("%20.10f\n", f+f+f);
return 0;
}
compiled with
gcc t.c
and
gcc -O t.c
(actually, the compiler should not matter). Straightforward compilation
without compilation will produce result different from 1 due to rounding
errors; gcc -O will detect that it can get rid of the addition and the
result will be equal to 1 - as expected(?).
The code is correct when it follows the standard, not matter how it is
interpreted. if the code depends on the interpretation, the code _is_
broken. I have seen quite many broken Fortran programs written by
chemists that believed they knew the language so I think I know what I
am talking about. if you don't care about standards, don't be suprized
that you waste your time finding errors in compilers.
just my 0.02zlp
/Pawel
--
Pawel Salek (pawsa@theochem.kth.se) http://www.theochem.kth.se/~pawsa/
Theoretical Chemistry Division, KTH voice: +46 8 790-8202
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 13:40 ` Pawel Salek
@ 2001-04-18 15:53 ` Uncle George
0 siblings, 0 replies; 25+ messages in thread
From: Uncle George @ 2001-04-18 15:53 UTC (permalink / raw)
To: axp-list
[-- Attachment #1: Type: text/plain, Size: 868 bytes --]
ur not suggesting that "proper code has been generated" are you ? If one
does not know anything about the proper results, then one might think that
the bogus answer is just as good as the right answer.
Gee, I can just imagine the frustration computational 'mad' scientists have
with answers that go mysteriously awry.
Any way -- is it or is it not a violation of the "strict aliasing" . And
how does a user know. Docs seem to be vague. Concept seems to be vague and
the compiler does its majic in silence.
Pawel Salek wrote:
> On 2001-04-18 17:13 Uncle George wrote:
> > Any compiler that does not produce the correct code has a bug - baring
> > any error messages.
> >
> > I suppose one has to deceide if an error message should be produced
> > OR proper code should be produced.
>
> So, proper code has been generated because ISO C allows that. Full stop.
>
>
[-- Attachment #2: Type: text/html, Size: 1088 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 17:10 ` Uncle George
2001-04-18 15:40 ` Pawel Salek
@ 2001-04-18 16:17 ` David Woodhouse
2001-04-18 16:46 ` Andrew A. Gill
2001-04-18 18:38 ` jeff.sturm
3 siblings, 0 replies; 25+ messages in thread
From: David Woodhouse @ 2001-04-18 16:17 UTC (permalink / raw)
To: axp-list
gatgul@voicenet.com said:
> BTW your opinion about the code posted is broken, is also ur opinion.
> It is perfectly correct IMHO . I guess it just does not live up to
> some one else's arbitrary standard.
The 'arbitrary standard' to which you refer is known as ISO C99.
If you desire a compiler which lives up to other standards, that's fine -
just don't report bugs against gcc. Do you see people reporting gcc to be
buggy because it doesn't compile FORTRAN code to produce the results you
expect?
> I'm sorry that u believe this but i believe that the results from
> -O0 == -O1 == -O2 == -O3 == -O4
> should all be the same. If any one of them failes to be equal, then
> the compiler failed to produce the correct code to derive the correct
> results.
That is an interesting opinion. The rest of the world, however, accepts the
fact that according to the specifications of the C language, certain code
has _undefined_ behaviour. If the compiler encounters such code, it's
perfectly entitled to send insulting mail to your boss and sleep with your
wife. It's certainly not required to do the same thing each time.
--
dwmw2
^ permalink raw reply [flat|nested] 25+ messages in thread
* RE: gcc 2.96 optimization bug on RedHat7.0/alpha
@ 2001-04-18 16:22 Hoover, Tony
2001-04-18 16:55 ` David Woodhouse
2001-04-18 17:07 ` alvin
0 siblings, 2 replies; 25+ messages in thread
From: Hoover, Tony @ 2001-04-18 16:22 UTC (permalink / raw)
To: 'axp-list@redhat.com'
Granted, however a compile time warning that your source will generate
"_undefined_ behavior" should not be out of the question.
---------------------------------------------------------------------------
Tony Hoover, Network Administrator
KSU - Salina, College of Technology
mailto:hoover@sal.ksu.edu
"Don't Blend in..."
----------------------------------------------------------------------------
> ----------
> From: David Woodhouse[SMTP:dwmw2@infradead.org]
> Reply To: axp-list@redhat.com
> Sent: Wednesday, April 18, 2001 11:17 AM
> To: axp-list@redhat.com
> Subject: Re: gcc 2.96 optimization bug on RedHat7.0/alpha
>
>
> gatgul@voicenet.com said:
> > BTW your opinion about the code posted is broken, is also ur opinion.
> > It is perfectly correct IMHO . I guess it just does not live up to
> > some one else's arbitrary standard.
>
> The 'arbitrary standard' to which you refer is known as ISO C99.
>
> If you desire a compiler which lives up to other standards, that's fine -
> just don't report bugs against gcc. Do you see people reporting gcc to be
> buggy because it doesn't compile FORTRAN code to produce the results you
> expect?
>
>
> > I'm sorry that u believe this but i believe that the results from
> > -O0 == -O1 == -O2 == -O3 == -O4
> > should all be the same. If any one of them failes to be equal, then
> > the compiler failed to produce the correct code to derive the correct
> > results.
>
> That is an interesting opinion. The rest of the world, however, accepts
> the
> fact that according to the specifications of the C language, certain code
> has _undefined_ behaviour. If the compiler encounters such code, it's
> perfectly entitled to send insulting mail to your boss and sleep with your
> wife. It's certainly not required to do the same thing each time.
>
> --
> dwmw2
>
>
>
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
>
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 17:10 ` Uncle George
2001-04-18 15:40 ` Pawel Salek
2001-04-18 16:17 ` David Woodhouse
@ 2001-04-18 16:46 ` Andrew A. Gill
2001-04-18 17:04 ` T. Daniel Crawford
2001-04-18 18:38 ` jeff.sturm
3 siblings, 1 reply; 25+ messages in thread
From: Andrew A. Gill @ 2001-04-18 16:46 UTC (permalink / raw)
To: axp-list; +Cc: gcc-bugs
[does gcc-bugs still want to be cc'd?]
On Wed, 18 Apr 2001, Uncle George antagonized the horn and now...
> I'm sorry that u believe this but i believe that the results from
>
> -O0 == -O1 == -O2 == -O3 == -O4
>
> should all be the same. If any one of them failes to be equal, then
> the compiler failed to produce the correct code to derive the correct
> results. It is particularly onerous if the failure is not reported in
> any fashion.
Does anyone remember the old PBS instructional television sketch where
the guy decides that he hates rules and wishes that they were never
invented and then he falls asleep and he dreams that he's in a world
without rules and he's run over by a car or something? [*]
Anyways, we're talking about a programming language. It has a formal
syntax and grammar. Like English. I would say that English has many
problems--so does C. English has no separate you (pl.), for example.
Does this mean that English is buggy?
We're dealing with documented results, here. This means that the burden
is on you. If you don't like C's implementation, try another language.
Lord knows that there are others out there that many people find much
better than C.
> It is never perfectly OK to produce bad code. AND i dont care what
> standard one uses to justify this 'OK'ness.
So stop writing bad code! <g>
[*] Where was I? Oh, yeah--I like TV.
--
|Andrew A. Gill |I posted to Silent-Tristero and|
|<superluser@mail.rit.edu> |all I got was this stupid sig! |
|alt.tv.simpsons CBG-FAQ author | |
| (Report all obscene mail to Le Maitre Pots)|
|<http://trystero.rh.rit.edu> Temporary sig: --
FORTRAN? The syntactically incorrect statement "DO 10 I = 1.10" will
parse and generate code creating a variable, DO10I, as follows:
"DO10I = 1.10" If that doesn't terrify you, it should.
- fortune database
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 16:22 Hoover, Tony
@ 2001-04-18 16:55 ` David Woodhouse
2001-04-18 17:07 ` alvin
1 sibling, 0 replies; 25+ messages in thread
From: David Woodhouse @ 2001-04-18 16:55 UTC (permalink / raw)
To: axp-list
hoover@sal.ksu.edu said:
> Granted, however a compile time warning that your source will generate
> "_undefined_ behavior" should not be out of the question.
Indeed. But as I said - that wouldn't be a bug report, that would be a
feature request. And I believe gcc-3.0 is in feature-freeze already.
--
dwmw2
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 16:46 ` Andrew A. Gill
@ 2001-04-18 17:04 ` T. Daniel Crawford
2001-04-18 18:15 ` Nelson Brito
0 siblings, 1 reply; 25+ messages in thread
From: T. Daniel Crawford @ 2001-04-18 17:04 UTC (permalink / raw)
To: axp-list
On Wed, 18 Apr 2001, Andrew A. Gill wrote:
>
> Anyways, we're talking about a programming language. It has a formal
> syntax and grammar. Like English. I would say that English has many
> problems--so does C. English has no separate you (pl.), for example.
> Does this mean that English is buggy?
I must disagree with Andrew's English-grammar example, y'all. ;)
-Daniel
--
T. Daniel Crawford Department of Chemistry
crawdad@vt.edu Virginia Tech
www.chem.vt.edu/chem-dept/crawford Voice: 540-231-7760 FAX: 540-231-3255
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 16:22 Hoover, Tony
2001-04-18 16:55 ` David Woodhouse
@ 2001-04-18 17:07 ` alvin
1 sibling, 0 replies; 25+ messages in thread
From: alvin @ 2001-04-18 17:07 UTC (permalink / raw)
To: axp-list
"Hoover, Tony" wrote:
>
> Granted, however a compile time warning that your source will generate
> "_undefined_ behavior" should not be out of the question.
> ---------------------------------------------------------------------------
> Tony Hoover, Network Administrator
> KSU - Salina, College of Technology
> mailto:hoover@sal.ksu.edu
>
> "Don't Blend in..."
> ----------------------------------------------------------------------------
>
> > ----------
> > From: David Woodhouse[SMTP:dwmw2@infradead.org]
> > Reply To: axp-list@redhat.com
> > Sent: Wednesday, April 18, 2001 11:17 AM
> > To: axp-list@redhat.com
> > Subject: Re: gcc 2.96 optimization bug on RedHat7.0/alpha
> >
> >
> > gatgul@voicenet.com said:
> > > BTW your opinion about the code posted is broken, is also ur opinion.
> > > It is perfectly correct IMHO . I guess it just does not live up to
> > > some one else's arbitrary standard.
> >
> > The 'arbitrary standard' to which you refer is known as ISO C99.
> >
> > If you desire a compiler which lives up to other standards, that's fine -
> > just don't report bugs against gcc. Do you see people reporting gcc to be
> > buggy because it doesn't compile FORTRAN code to produce the results you
> > expect?
> >
> >
> > > I'm sorry that u believe this but i believe that the results from
> > > -O0 == -O1 == -O2 == -O3 == -O4
> > > should all be the same. If any one of them failes to be equal, then
> > > the compiler failed to produce the correct code to derive the correct
> > > results.
> >
> > That is an interesting opinion. The rest of the world, however, accepts
> > the
> > fact that according to the specifications of the C language, certain code
> > has _undefined_ behaviour. If the compiler encounters such code, it's
> > perfectly entitled to send insulting mail to your boss and sleep with your
> > wife. It's certainly not required to do the same thing each time.
Then the compiler should allways print out a line that is somthing like
"you code may not work as you expect(you have been warned)"
Just a little try at humor. But on a more serious note. C as a language
has a number of issues about order of evaluation of expressions and what
will happen if you have side effects because of expression evaluation. I
missed part of the early part of the thread but at this point it seems
to be a discussion about what a compiler will do compared to what you
might expect.
Concider
int x = 1;
int y = 2;
int fval = 4;
int f(int val)
{
return fval/=val;
}
t = f(x) + f(y);
is t = 4 + 2
or is t = 2 + 2
since "+" is commutitive it is legitimate to evaluate either f(x) or
f(y) first but because of side effects you will get different results. A
compiler can pick any order of evaluation so long as the operator
precedance is kept.
Now this is an extreem example but it is possible to find more subtile
examples of this in everyday code.
--
Alvin Starr || voice: (416)585-9971
Interlink Connectivity || fax: (416)585-9974
alvin@iplink.net ||
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 14:03 ` David Woodhouse
@ 2001-04-18 17:10 ` Uncle George
2001-04-18 15:40 ` Pawel Salek
` (3 more replies)
0 siblings, 4 replies; 25+ messages in thread
From: Uncle George @ 2001-04-18 17:10 UTC (permalink / raw)
To: axp-list, gcc-bugs
I'm sorry that u believe this but i believe that the results from
-O0 == -O1 == -O2 == -O3 == -O4
should all be the same. If any one of them failes to be equal, then the compiler
failed to produce the correct code to derive the correct results. It is
particularly onerous if the failure is not reported in any fashion.
It is never perfectly OK to produce bad code. AND i dont care what standard one
uses to justify this 'OK'ness.
/gat
BTW your opinion about the code posted is broken, is also ur opinion. It is
perfectly correct IMHO . I guess it just does not live up to some one else's
arbitrary standard.
BTW#2 all that stuff about meaning & intention just doesnt work for me. It just
appears to be another form of vague subtrafuge.
David Woodhouse wrote:
> gatgul@voicenet.com said:
> > Any compiler that does not produce the correct code has a bug - baring
> > any error messages.
>
> How do you define 'correct'?
>
> The compiler produced 'correct' code according to the ISO C standard. It
> has no way of knowing what's 'correct' if you define that as meaning the
> _intention_ of the programmer, even when they write incorrect source code.
>
> The code posted was broken - or at least the assumption about the results
> was incorrect. The compiler's behaviour was perfectly OK.
>
> If you have code to enable a 'Do what I meant, not what I wrote' feature in
> gcc, I'm sure we'd all be glad to see it - I know I've needed it before now :)
>
> Gcc does have some warnings of the 'You wrote this; are you sure you didn't
> mean something else' variety. Perhaps adding a warning for this situation
> would be possible - perhaps not. But that wouldn't be a bug report, that
> would be a feature request. And I believe gcc-3.0 is in feature-freeze
> already.
>
> --
> dwmw2
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 17:04 ` T. Daniel Crawford
@ 2001-04-18 18:15 ` Nelson Brito
0 siblings, 0 replies; 25+ messages in thread
From: Nelson Brito @ 2001-04-18 18:15 UTC (permalink / raw)
To: axp-list
On Wed, 18 Apr 2001, T. Daniel Crawford wrote:
-> On Wed, 18 Apr 2001, Andrew A. Gill wrote:
-> >
-> > Anyways, we're talking about a programming language. It has a formal
-> > syntax and grammar. Like English. I would say that English has many
-> > problems--so does C. English has no separate you (pl.), for example.
-> > Does this mean that English is buggy?
->
-> I must disagree with Andrew's English-grammar example, y'all. ;)
Well i have to disagree too because Portuguese grammar has all this diferent
forms for pl. and males and females that most of the us don't know how to use!!
So languages are not buggy! sometimes we don't know how to use them...
nelson
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 17:10 ` Uncle George
` (2 preceding siblings ...)
2001-04-18 16:46 ` Andrew A. Gill
@ 2001-04-18 18:38 ` jeff.sturm
3 siblings, 0 replies; 25+ messages in thread
From: jeff.sturm @ 2001-04-18 18:38 UTC (permalink / raw)
To: axp-list
On Wed, 18 Apr 2001, Uncle George wrote:
> It is never perfectly OK to produce bad code. AND i dont care what
> standard one uses to justify this 'OK'ness.
So what do you want to hear? That the behavior of your code is defined
according to the standard? I don't have the relevant text handy but I'm
pretty sure it isn't. If you want to know how to make your code work
as before, Brad already said -fno-strict-aliasing gives you the old
behavior (along with lesser optimization). FWIW I didn't realize
-fstrict-aliasing was the default on Red Hat's compiler. With 2.95 you
still had to specify -fstrict-alising if you wanted it. (Anybody
try Uncle George's example on ccc, just for kicks?)
Anyhow... all standards and correctness issues aside, one problem with
that sort of pointer manipulation is that the compiler cannot generate
optimal code (i.e. eliminate evil loads/stores). Your double argument
starts in a register, then must be written to a temporary location from
which the integers are read. That's a RAW conflict, and likely causes a
replay trap.
I don't know if EV6 has a better way, but you aren't going to see one as
long as you are confusing the compiler by casting pointers. A union is
the correct way to handle it. In principle, the compiler can optimize
accesses to a union type by generating register->register ops when
appropriate. (I proved this with an experiment on x86, since my alpha is
1000's of miles away and crippled by a power storm... <sigh>.)
--
Jeff Sturm
jeff.sturm@commerceone.com
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 22:18 ` Uncle George
@ 2001-04-18 20:50 ` Chris Eleveld (Sector 7 Group)
2001-04-18 21:33 ` Michal Jaegermann
2001-04-18 22:03 ` jeff.sturm
2 siblings, 0 replies; 25+ messages in thread
From: Chris Eleveld (Sector 7 Group) @ 2001-04-18 20:50 UTC (permalink / raw)
To: axp-list
This brings up the thing that disturbs me most about the original
code fragment. It assumes a double is in IEEE format and little endian.
both dangerous assumptions. I do not believe the C standard specifies
IEEE floating point semantics or types for math. The alpha in particular
has and may be optimized for other floating point representations. I'm
sure the alpha isn't the only system to do things differently.
Just my 2 cents from the porting business,
Chris
On Wed, Apr 18, 2001 at 06:18:13PM -0400, Uncle George wrote:
> Its not my code segment, and from my experience a union might be better.
> although from this discourse not safe either.
>
> the code as stated should:
> 1) take address of x
> 2) make into int ptr
> 3) add 1 to ptr ( value of 4 bec its an int ptr )
> 4) fetch integer from the address as calculated.
>
> It should not matter if at x there is 8 bytes of a double, as that
> distinction is superflous to the equation.
>
> anyway the segment was taken from a floor() function (akin to glibc:
> ./sysdeps/ieee754/dbl-64/s_floor.c).
>
> static double huge = 1.0e300;
> #endif
>
> #ifdef __STDC__
> double __floor(double x)
> #else
> double __floor(x)
> double x;
> #endif
> {
> int32_t i0,i1,j0;
> u_int32_t i,j;
> EXTRACT_WORDS(i0,i1,x); <== Majic happens behind this macro
> which I suppose is tailored for each system
> j0 = ((i0>>20)&0x7ff)-0x3ff;
>:
>
>
> Michal Jaegermann wrote:
>
> > On Wed, Apr 18, 2001 at 11:13:59AM -0400, Uncle George wrote:
> > > Any compiler that does not produce the correct code has a bug - baring
> > > any error messages.
> >
> > Indeed, but you should also add "from a correct source" for clarity.
> >
> > > I suppose one has to deceide if an error message should be produced
> > > OR proper code should be produced.
> >
> > Can you explain what you intended to see from your example and why?
> > I was looking at that code yesterday and scratching my head. I am
> > still not absolutely sure what the _real_ meaning was supposed to be.
> >
> > If you want overlay different types you have 'union' construct for
> > that. Playing loose with pointers was not guaranteed to work ever.
>
>
>
> _______________________________________________
> Axp-list mailing list
> Axp-list@redhat.com
> https://listman.redhat.com/mailman/listinfo/axp-list
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 22:18 ` Uncle George
2001-04-18 20:50 ` Chris Eleveld (Sector 7 Group)
@ 2001-04-18 21:33 ` Michal Jaegermann
2001-04-18 23:09 ` P.TURLAIS
2001-04-19 0:28 ` Uncle George
2001-04-18 22:03 ` jeff.sturm
2 siblings, 2 replies; 25+ messages in thread
From: Michal Jaegermann @ 2001-04-18 21:33 UTC (permalink / raw)
To: axp-list
On Wed, Apr 18, 2001 at 06:18:13PM -0400, Uncle George wrote:
> Its not my code segment, and from my experience a union might be better.
> although from this discourse not safe either.
>
> the code as stated should:
> 1) take address of x
> 2) make into int ptr
> 3) add 1 to ptr ( value of 4 bec its an int ptr )
> 4) fetch integer from the address as calculated.
Well, yes, you translated the code from C to English. But the
question really was what you expect that it will happen after these
operations and what kind of a _meaning_ you ascribe to that.
> It should not matter if at x there is 8 bytes of a double, as that
> distinction is superflous to the equation.
But if you think that some consistent results should come from this
program then you assume that such "pointer puns" have a well defined
semantics. I do not recall that they ever had.
> anyway the segment was taken from a floor() function (akin to glibc:
> ./sysdeps/ieee754/dbl-64/s_floor.c).
This may even work for some particular platform and some particular
compiler, so it may be ok in internals of libraries, but it does
not mean that it can be copied elsewhere.
Michal
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 22:18 ` Uncle George
2001-04-18 20:50 ` Chris Eleveld (Sector 7 Group)
2001-04-18 21:33 ` Michal Jaegermann
@ 2001-04-18 22:03 ` jeff.sturm
2 siblings, 0 replies; 25+ messages in thread
From: jeff.sturm @ 2001-04-18 22:03 UTC (permalink / raw)
To: axp-list
On Wed, 18 Apr 2001, Uncle George wrote:
> anyway the segment was taken from a floor() function (akin to glibc:
> ./sysdeps/ieee754/dbl-64/s_floor.c).
If there is a bug in glibc, it should be reported as such.
--
Jeff Sturm
jeff.sturm@commerceone.com
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 14:55 ` Michal Jaegermann
@ 2001-04-18 22:18 ` Uncle George
2001-04-18 20:50 ` Chris Eleveld (Sector 7 Group)
` (2 more replies)
0 siblings, 3 replies; 25+ messages in thread
From: Uncle George @ 2001-04-18 22:18 UTC (permalink / raw)
To: axp-list
Its not my code segment, and from my experience a union might be better.
although from this discourse not safe either.
the code as stated should:
1) take address of x
2) make into int ptr
3) add 1 to ptr ( value of 4 bec its an int ptr )
4) fetch integer from the address as calculated.
It should not matter if at x there is 8 bytes of a double, as that
distinction is superflous to the equation.
anyway the segment was taken from a floor() function (akin to glibc:
./sysdeps/ieee754/dbl-64/s_floor.c).
static double huge = 1.0e300;
#endif
#ifdef __STDC__
double __floor(double x)
#else
double __floor(x)
double x;
#endif
{
int32_t i0,i1,j0;
u_int32_t i,j;
EXTRACT_WORDS(i0,i1,x); <== Majic happens behind this macro
which I suppose is tailored for each system
j0 = ((i0>>20)&0x7ff)-0x3ff;
:
Michal Jaegermann wrote:
> On Wed, Apr 18, 2001 at 11:13:59AM -0400, Uncle George wrote:
> > Any compiler that does not produce the correct code has a bug - baring
> > any error messages.
>
> Indeed, but you should also add "from a correct source" for clarity.
>
> > I suppose one has to deceide if an error message should be produced
> > OR proper code should be produced.
>
> Can you explain what you intended to see from your example and why?
> I was looking at that code yesterday and scratching my head. I am
> still not absolutely sure what the _real_ meaning was supposed to be.
>
> If you want overlay different types you have 'union' construct for
> that. Playing loose with pointers was not guaranteed to work ever.
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 21:33 ` Michal Jaegermann
@ 2001-04-18 23:09 ` P.TURLAIS
2001-04-19 0:28 ` Uncle George
1 sibling, 0 replies; 25+ messages in thread
From: P.TURLAIS @ 2001-04-18 23:09 UTC (permalink / raw)
To: axp-list
Michal Jaegermann wrote:
>
> On Wed, Apr 18, 2001 at 06:18:13PM -0400, Uncle George wrote:
> > Its not my code segment, and from my experience a union might be better.
> > although from this discourse not safe either.
> >
> > the code as stated should:
> > 1) take address of x
> > 2) make into int ptr
> > 3) add 1 to ptr ( value of 4 bec its an int ptr )
> > 4) fetch integer from the address as calculated.
>
> Well, yes, you translated the code from C to English. But the
> question really was what you expect that it will happen after these
> operations and what kind of a _meaning_ you ascribe to that.
i0 should contain the bit sign, the exponent and a part of the mantissa.
i1 should contain the rest of the mantissa.
You can use these values for a conversion to another FP format (
VAX ( G or F ? ), IBM, CRAY ), to implement a function using tables
rather than math calls, to use the mantissa as an hash code ( because
the magnitude changes a lot, and a conversion to int doesn't give you
a good hash function ) ....
For me the semantic of the code is perfectly defined ( for a low-endian
machine supporting ieee754, for a big-endian, you have to switch i0 & i1 ).
> > It should not matter if at x there is 8 bytes of a double, as that
> > distinction is superflous to the equation.
>
> But if you think that some consistent results should come from this
> program then you assume that such "pointer puns" have a well defined
> semantics. I do not recall that they ever had.
Hum, I would say that a pointer is a pointer to an area. The fact that
you interpret the content of this area the wrong way is one thing,
the fact that this content changes because of a compilation flag is
another thing. May be the pointer to an argument is undefined ( I don't
think so, but I have no C ISO standards near me ... ) ?
Regards.
--
Pierre TURLAIS
^ permalink raw reply [flat|nested] 25+ messages in thread
* Re: gcc 2.96 optimization bug on RedHat7.0/alpha
2001-04-18 21:33 ` Michal Jaegermann
2001-04-18 23:09 ` P.TURLAIS
@ 2001-04-19 0:28 ` Uncle George
1 sibling, 0 replies; 25+ messages in thread
From: Uncle George @ 2001-04-19 0:28 UTC (permalink / raw)
To: axp-list
[-- Attachment #1: Type: text/plain, Size: 1919 bytes --]
Michal Jaegermann wrote:
> On Wed, Apr 18, 2001 at 06:18:13PM -0400, Uncle George wrote:
> > Its not my code segment, and from my experience a union might be better.
> > although from this discourse not safe either.
> >
> > the code as stated should:
> > 1) take address of x
> > 2) make into int ptr
> > 3) add 1 to ptr ( value of 4 bec its an int ptr )
> > 4) fetch integer from the address as calculated.
>
> Well, yes, you translated the code from C to English. But the
> question really was what you expect that it will happen after these
> operations and what kind of a _meaning_ you ascribe to that.
What happens after is also irrelevant, as there is no point on continuing
with the routine if steps 1-4 of the equation dont happen. i ascribe no
particular meaning to either I0, or I1. Just need to realize that the results
are different between optimizations.
>
>
> > It should not matter if at x there is 8 bytes of a double, as that
> > distinction is superflous to the equation.
>
> But if you think that some consistent results should come from this
> program then you assume that such "pointer puns" have a well defined
> semantics. I do not recall that they ever had.
>
I hope that pointer arith is well defined. and should yield the same results
with -O0 -O1 -O2 and so on.
>
> > anyway the segment was taken from a floor() function (akin to glibc:
> > ./sysdeps/ieee754/dbl-64/s_floor.c).
>
> This may even work for some particular platform and some particular
> compiler, so it may be ok in internals of libraries, but it does
> not mean that it can be copied elsewhere.
>
yup, ergo the majic statement to disassemble the double to 2 ints is a macro.
But again, irrelevant to talk about the various other architectures. I have
only posted a CPP'd snippet of the problem code to demonstrate the erroneous
results, as per gnu c bug reporting info.
Whats a pointer pun?
/gat
[-- Attachment #2: Type: text/html, Size: 2337 bytes --]
^ permalink raw reply [flat|nested] 25+ messages in thread
end of thread, other threads:[~2001-04-19 0:28 UTC | newest]
Thread overview: 25+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2001-04-18 1:46 gcc 2.96 optimization bug on RedHat7.0/alpha Uncle George
2001-04-18 0:04 ` Christopher C. Chimelis
2001-04-18 3:41 ` Matt Wilson
2001-04-18 4:32 ` Brad Lucier
2001-04-18 15:13 ` Uncle George
2001-04-18 13:40 ` Pawel Salek
2001-04-18 15:53 ` Uncle George
2001-04-18 14:03 ` David Woodhouse
2001-04-18 17:10 ` Uncle George
2001-04-18 15:40 ` Pawel Salek
2001-04-18 16:17 ` David Woodhouse
2001-04-18 16:46 ` Andrew A. Gill
2001-04-18 17:04 ` T. Daniel Crawford
2001-04-18 18:15 ` Nelson Brito
2001-04-18 18:38 ` jeff.sturm
2001-04-18 14:55 ` Michal Jaegermann
2001-04-18 22:18 ` Uncle George
2001-04-18 20:50 ` Chris Eleveld (Sector 7 Group)
2001-04-18 21:33 ` Michal Jaegermann
2001-04-18 23:09 ` P.TURLAIS
2001-04-19 0:28 ` Uncle George
2001-04-18 22:03 ` jeff.sturm
-- strict thread matches above, loose matches on Subject: below --
2001-04-18 16:22 Hoover, Tony
2001-04-18 16:55 ` David Woodhouse
2001-04-18 17:07 ` alvin
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox