User account creation filtered due to spam.

Bug 45852 - volatile structs are broken!
Summary: volatile structs are broken!
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 4.6.0
: P3 normal
Target Milestone: ---
Assignee: Jakub Jelinek
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2010-10-01 03:10 UTC by John Regehr
Modified: 2011-01-17 08:01 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2010-10-01 10:27:24


Attachments
gcc46-pr45852.patch (635 bytes, patch)
2010-12-14 13:43 UTC, Jakub Jelinek
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Regehr 2010-10-01 03:10:26 UTC
gcc should not be optimizing away the read from or write to this struct.

regehr@john-home:~$ current-gcc -v
Using built-in specs.
COLLECT_GCC=current-gcc
COLLECT_LTO_WRAPPER=/home/regehr/z/compiler-install/gcc-r164818-install/libexec/gcc/i686-pc-linux-gnu/4.6.0/lto-wrapper
Target: i686-pc-linux-gnu
Configured with: ../configure --with-libelf=/usr/local --enable-lto --prefix=/home/regehr/z/compiler-install/gcc-r164818-install --program-prefix=r164818- --enable-languages=c,c++
Thread model: posix
gcc version 4.6.0 20100930 (experimental) (GCC) 

regehr@john-home:~$ current-gcc -S -o - -O1 small.c 

        .file   "small.c"
        .text
        .globl  func_1
        .type   func_1, @function
func_1:
.LFB0:
        .cfi_startproc
        rep
        ret
        .cfi_endproc
.LFE0:
        .size   func_1, .-func_1
        .globl  g_18
        .data
        .align 4
        .type   g_18, @object
        .size   g_18, 4
g_18:
        .long   -6
        .ident  "GCC: (GNU) 4.6.0 20100930 (experimental)"
        .section        .note.GNU-stack,"",@progbits

regehr@john-home:~$ cat small.c

struct S1
{
  int f0;
};

volatile struct S1 g_18 = { -6 };

void
func_1 (void)
{
  g_18 = g_18;
}
Comment 1 John Regehr 2010-10-01 03:40:43 UTC
This problem has been there for some time: none of 3.0.0, 3.1.0, 3.2.0, 3.3.0, 3.4.0, 4.0.0, 4.1.0, 4.2.0, 4.3.0, 4.4.0, or 4.5.0 for x86 generates the right code.
Comment 2 Richard Biener 2010-10-01 10:27:24 UTC
The expander throws away the assignment.
Comment 3 Jakub Jelinek 2010-12-14 13:43:42 UTC
Created attachment 22753 [details]
gcc46-pr45852.patch

Untested fix.  Alternatively if alt_rtl (or target?) has side-effects, we could
ignore it in store_expr.
Comment 4 Alexander Monakov 2010-12-14 14:54:38 UTC
There's a couple of related bugs:

Optimizes away access to volatile field (unconfirmed):
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=46762

Does not use volatile MEMs for assignments of structs with volatile fields:
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=45472
Comment 5 Jakub Jelinek 2010-12-21 08:35:19 UTC
Author: jakub
Date: Tue Dec 21 08:35:16 2010
New Revision: 168105

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168105
Log:
	PR middle-end/45852
	* expr.c (store_expr): Ignore alt_rtl if equal to target,
	but has side-effects.

	* gcc.target/i386/pr45852.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr45852.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/expr.c
    trunk/gcc/testsuite/ChangeLog
Comment 6 Jakub Jelinek 2011-01-16 20:23:04 UTC
Author: jakub
Date: Sun Jan 16 20:23:01 2011
New Revision: 168867

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168867
Log:
	Backport from mainline
	2010-12-21  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/45852
	* expr.c (store_expr): Ignore alt_rtl if equal to target,
	but has side-effects.

	* gcc.target/i386/pr45852.c: New test.

Added:
    branches/gcc-4_5-branch/gcc/testsuite/gcc.target/i386/pr45852.c
Modified:
    branches/gcc-4_5-branch/gcc/ChangeLog
    branches/gcc-4_5-branch/gcc/expr.c
    branches/gcc-4_5-branch/gcc/testsuite/ChangeLog
Comment 7 Jakub Jelinek 2011-01-16 22:56:13 UTC
Author: jakub
Date: Sun Jan 16 22:56:10 2011
New Revision: 168879

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=168879
Log:
	Backport from mainline
	2010-12-21  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/45852
	* expr.c (store_expr): Ignore alt_rtl if equal to target,
	but has side-effects.

	* gcc.target/i386/pr45852.c: New test.

Added:
    branches/gcc-4_4-branch/gcc/testsuite/gcc.target/i386/pr45852.c
Modified:
    branches/gcc-4_4-branch/gcc/ChangeLog
    branches/gcc-4_4-branch/gcc/expr.c
    branches/gcc-4_4-branch/gcc/testsuite/ChangeLog
Comment 8 Jakub Jelinek 2011-01-17 08:01:41 UTC
Fixed for 4.4+.