public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53382] New: incorrect associativity in expressions
@ 2012-05-16 23:06 miguel.barao at gmail dot com
  2012-05-16 23:08 ` [Bug c/53382] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: miguel.barao at gmail dot com @ 2012-05-16 23:06 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53382

             Bug #: 53382
           Summary: incorrect associativity in expressions
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: critical
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: miguel.barao@gmail.com


I found the following behavior while writing a small RPN calculator.
The ideia is to perform a subtraction on the two top elements of a stack using

push(&mystack, -pop(&mystack) + pop(&mystack));

Since the + associativity is left-to-right, this should pop the stack, negate
this value, pop the second argument then add. But the order is reversed in gcc
leading to a wrong result.

The behavior was observed in gcc 4.4.5 (debian stable), 4.6.3 (ubuntu 12.04),
and the llvm-gcc versions shipping with MacOSX.
The clang frontend versions 1.1 (on debian stable), 3.0 (OSX and ubuntu 12.04)
work correctly.

Example:
Suppose a stack contains [ 1 2 ], the top of the stack being 2.
On gcc the above expression returns 1, the first pop executed is the second
one.
On clang the same expression returns -1, the first pop executed is the first
one as should be.


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2012-05-17  9:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-05-16 23:06 [Bug c/53382] New: incorrect associativity in expressions miguel.barao at gmail dot com
2012-05-16 23:08 ` [Bug c/53382] " pinskia at gcc dot gnu.org
2012-05-16 23:12 ` pinskia at gcc dot gnu.org
2012-05-16 23:15 ` pinskia at gcc dot gnu.org
2012-05-17 10:19 ` miguel.barao at gmail dot com

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).