public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/38679]  New: semantics of assignment in a return statement suspect
@ 2008-12-31  0:56 dan at math dot uiuc dot edu
  2008-12-31  9:19 ` [Bug c/38679] " rguenth at gcc dot gnu dot org
  0 siblings, 1 reply; 3+ messages in thread
From: dan at math dot uiuc dot edu @ 2008-12-31  0:56 UTC (permalink / raw)
  To: gcc-bugs

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


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

* [Bug c/38679] semantics of assignment in a return statement suspect
  2008-12-31  0:56 [Bug c/38679] New: semantics of assignment in a return statement suspect dan at math dot uiuc dot edu
@ 2008-12-31  9:19 ` rguenth at gcc dot gnu dot org
  0 siblings, 0 replies; 3+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2008-12-31  9:19 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2008-12-31 09:18 -------
The frontend already presents us with

;; Function f (null)
;; enabled by -tree-original


{
  fff (x = 1);
  return x = 1;, 1{no-warn};
}

note that other compilers IMHO correctly do the same for the function argument.


-- 


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


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

* [Bug c/38679] semantics of assignment in a return statement suspect
       [not found] <bug-38679-4@http.gcc.gnu.org/bugzilla/>
@ 2021-09-17  7:11 ` pinskia at gcc dot gnu.org
  0 siblings, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-17  7:11 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=38679

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |4.6.0
         Resolution|---                         |FIXED
             Status|UNCONFIRMED                 |RESOLVED
           Keywords|                            |wrong-code

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
This changed in GCC 4.6.0 with r0-102336 which also clarify the documentation
on volatile so fixed for GCC 4.6.0.

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

end of thread, other threads:[~2021-09-17  7:11 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-12-31  0:56 [Bug c/38679] New: semantics of assignment in a return statement suspect dan at math dot uiuc dot edu
2008-12-31  9:19 ` [Bug c/38679] " rguenth at gcc dot gnu dot org
     [not found] <bug-38679-4@http.gcc.gnu.org/bugzilla/>
2021-09-17  7:11 ` pinskia at gcc dot gnu.org

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