public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/18128] New: REGRESSION: Wrong precedence
@ 2004-10-24 18:57 adamm at zombino dot com
2004-10-24 19:01 ` [Bug c/18128] " pinskia at gcc dot gnu dot org
0 siblings, 1 reply; 2+ messages in thread
From: adamm at zombino dot com @ 2004-10-24 18:57 UTC (permalink / raw)
To: gcc-bugs
Produces wrong code on both 3.3.4 and 3.4.2 (in Debian Sid). It works perfectly
with gcc 2.95.
The problem is that,
-A+B == B-A
-A()+B == B-A()
-A+B() == B()-A
but,
-A()+B() ?= B()-A()
if A or B depend on each other, the last condition is !=. Otherwise, it is ==.
This breaks any code that relies on things like stack to execute operations, for
example,
stack<int> A;
A.push(5);
A.push(2);
// do a subtraction of 5-2 and push resuls onto stack
A.push( -A.pop() + A.pop());
What it does, it actually A.pop() - A.pop() which is very wrong.
>>>>>>>>>>>>> TEST CASE >>>>>>>>>>>>>>>>>>>>>>>>>
#include <stdio.h>
double A(){
static int div;
double r = 10.0/++div+div;
printf( "A() returns: %f iteration %d\n", r, div );
return r;
}
int main()
{
/* EXECUTES A()-A() INSTEAD OF -A()+A() */
printf( "-4.0 is %f\n", -A() + A());
}
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<
reported in Debian BTS: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=278081
--
Summary: REGRESSION: Wrong precedence
Product: gcc
Version: 3.3.4
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: adamm at zombino dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i386-linux
GCC host triplet: i386-linux
GCC target triplet: i386-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18128
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c/18128] REGRESSION: Wrong precedence
2004-10-24 18:57 [Bug c/18128] New: REGRESSION: Wrong precedence adamm at zombino dot com
@ 2004-10-24 19:01 ` pinskia at gcc dot gnu dot org
0 siblings, 0 replies; 2+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-24 19:01 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-24 19:01 -------
Invalid:
printf( "-4.0 is %f\n", -A() + A());
either A() can be evaluated first which is the misunderstanding in your part.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=18128
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2004-10-24 19:01 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-10-24 18:57 [Bug c/18128] New: REGRESSION: Wrong precedence adamm at zombino dot com
2004-10-24 19:01 ` [Bug c/18128] " pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).