From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 12184 invoked by alias); 31 Dec 2008 00:56:21 -0000 Received: (qmail 11714 invoked by uid 48); 31 Dec 2008 00:54:59 -0000 Date: Wed, 31 Dec 2008 00:56:00 -0000 Subject: [Bug c/38679] New: semantics of assignment in a return statement suspect X-Bugzilla-Reason: CC Message-ID: Reply-To: gcc-bugzilla@gcc.gnu.org To: gcc-bugs@gcc.gnu.org From: "dan at math dot uiuc dot edu" Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2008-12/txt/msg02995.txt.bz2 extern volatile int x; extern fff(int); int f() { fff(x=1); return x=1; } #if 0 The code generated by gcc below from the source code above shows that the value of the expression x=1, when x is volatile, depends on the context, most likely violating the standard. In a return statement, the value is 1. In an argument being passed to a function, the value is the value obtained by fetching the contents of x after the assignment is made. The command used was gcc -S -O2 -c bar.c .file "bar.c" .text .p2align 4,,15 .globl f .type f, @function f: pushl %ebp movl %esp, %ebp subl $8, %esp movl $1, x movl x, %eax movl %eax, (%esp) call fff movl $1, %eax movl $1, x leave ret .size f, .-f .ident "GCC: (Ubuntu 4.3.2-1ubuntu11) 4.3.2" .section .note.GNU-stack,"",@progbits $ uname -a Linux gallium 2.6.27-9-generic #1 SMP Thu Nov 20 21:57:00 UTC 2008 i686 GNU/Linux $ cat /etc/issue Ubuntu 8.10 \n \l #endif -- Summary: semantics of assignment in a return statement suspect Product: gcc Version: 4.3.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: dan at math dot uiuc dot edu GCC build triplet: i686-pc-linux-gnu GCC host triplet: i686-pc-linux-gnu GCC target triplet: i686-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=38679