[Bug c/53656] New: sequence point bug
alexcheremkhin at gmail dot com
gcc-bugzilla@gcc.gnu.org
Wed Jun 13 12:09:00 GMT 2012
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
More information about the Gcc-bugs
mailing list