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

Reply via email to