This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/53656] New: sequence point bug


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

             Bug #: 53656
           Summary: sequence point bug
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: alexcheremkhin@gmail.com


Created attachment 27614
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27614
source code

$gcc -v

COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/local/libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
ÐÐÐÐÐÐÑ ÐÑÑÐÑÐÐÑÑÑÐ: i686-pc-linux-gnu
ÐÐÑÐÐÐÑÑÑ ÐÐÐÑÐÐÑÑÐÑÐÐ: ./configure
ÐÐÐÐÐÑ ÐÐÐÐÐÐÐÑÐÑÐÐÑÑÐ: posix
gcc ÐÐÑÑÐÑ 4.6.0 (GCC) 

Optimization options do not matter (result is the same).

Source code:
----------------------------------------------------
/* bug.c */

#include <stdio.h>

int x = 0;

int f()
{
    return x++;
}

int main()
{
    int y = x++ + f();
    printf("x=%d\n", x);
    return 0;
}
------------------------------------------------------
The program should have printed 'x=2', but prints 'x=1'.
It looks like the variable x had been read to a register before call of f(),
and incremented after the call.
The function call makes a sequence point, so the behaviuor is not correct.

Alexey Cheremkhin; Compiler Department, KM211.
avc@km211.ru


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]