public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3
@ 2012-04-23 12:54 unixoid2003 at mail dot ru
2012-04-23 12:58 ` [Bug c/53085] " unixoid2003 at mail dot ru
` (9 more replies)
0 siblings, 10 replies; 11+ messages in thread
From: unixoid2003 at mail dot ru @ 2012-04-23 12:54 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
Bug #: 53085
Summary: write to volatile struct member is missing on
Cortex-M3
Classification: Unclassified
Product: gcc
Version: 4.7.0
Status: UNCONFIRMED
Severity: critical
Priority: P3
Component: c
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: unixoid2003@mail.ru
Created attachment 27221
--> http://gcc.gnu.org/bugzilla/attachment.cgi?id=27221
test code
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53085] write to volatile struct member is missing on Cortex-M3
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
@ 2012-04-23 12:58 ` unixoid2003 at mail dot ru
2012-04-23 13:19 ` unixoid2003 at mail dot ru
` (8 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: unixoid2003 at mail dot ru @ 2012-04-23 12:58 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
--- Comment #1 from brag <unixoid2003 at mail dot ru> 2012-04-23 12:58:17 UTC ---
struct aa{
volatile unsigned short a;
unsigned short b;
volatile unsigned short c;
unsigned short d;
};
#define AAmem ((struct aa *) 256)
static inline unsigned int tx(unsigned int v){
while(AAmem->a&1);
AAmem->c=v;
while(AAmem->a&2);
v=AAmem->c;
return v;
}
void f(){
tx(0xff);
tx(0xff);
}
Compiled by:
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O2 -fomit-frame-pointer
-ffreestanding -fno-common -Wall -Wextra -x c -c test.cpp
OR
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -O2 -fomit-frame-pointer
-ffreestanding -fno-common -Wall -Wextra -x c++ -c test.cpp
The code generated is wrong. There should be two writes to AAmem->c bute there
is one write (strh r3, [r2, #4])
arm-none-eabi-objdump -d test.o :
test.o: file format elf32-littlearm
Disassembly of section .text:
00000000 <f>:
0: f44f 7180 mov.w r1, #256 ; 0x100
4: 880b ldrh r3, [r1, #0]
6: f44f 7280 mov.w r2, #256 ; 0x100
a: 07d8 lsls r0, r3, #31
c: d4fa bmi.n 4 <f+0x4>
e: 23ff movs r3, #255 ; 0xff
10: 8093 strh r3, [r2, #4]
12: 4611 mov r1, r2
14: 880b ldrh r3, [r1, #0]
16: f44f 7280 mov.w r2, #256 ; 0x100
1a: f003 0302 and.w r3, r3, #2
1e: b29b uxth r3, r3
20: 2b00 cmp r3, #0
22: d1f7 bne.n 14 <f+0x14>
24: 8893 ldrh r3, [r2, #4]
26: 8813 ldrh r3, [r2, #0]
28: 07db lsls r3, r3, #31
2a: d4fc bmi.n 26 <f+0x26>
2c: f44f 7280 mov.w r2, #256 ; 0x100
30: 8813 ldrh r3, [r2, #0]
32: f003 0302 and.w r3, r3, #2
36: b29b uxth r3, r3
38: 2b00 cmp r3, #0
3a: d1f9 bne.n 30 <f+0x30>
3c: f44f 7380 mov.w r3, #256 ; 0x100
40: 889b ldrh r3, [r3, #4]
42: 4770 bx lr
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53085] write to volatile struct member is missing on Cortex-M3
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
2012-04-23 12:58 ` [Bug c/53085] " unixoid2003 at mail dot ru
@ 2012-04-23 13:19 ` unixoid2003 at mail dot ru
2012-04-23 13:27 ` [Bug c/53085] writes to volatile struct members is missing unixoid2003 at mail dot ru
` (7 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: unixoid2003 at mail dot ru @ 2012-04-23 13:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
--- Comment #2 from brag <unixoid2003 at mail dot ru> 2012-04-23 13:19:03 UTC ---
The simpler example:
struct aa{
volatile unsigned short a;
};
struct aa AAmem;
void f(){
AAmem.a=0xff;
AAmem.a=0xff;
}
00000000 <_Z1fv>:
0: f240 0300 movw r3, #0
4: f2c0 0300 movt r3, #0
8: 22ff movs r2, #255 ; 0xff
a: 801a strh r2, [r3, #0] ; <<--- one write here
c: 4770 bx lr
e: bf00 nop
There is one write but should be two.
Reads seems to work good:
struct aa{
volatile unsigned short a;
};
#define AAmem ((struct aa *) 256)
void f(){
int t;
t=AAmem->a;
t=AAmem->a;
}
00000000 <_Z1fv>:
0: f44f 7380 mov.w r3, #256 ; 0x100
4: 881a ldrh r2, [r3, #0] ;<<---| two reads here
6: 881b ldrh r3, [r3, #0] ;<<---|
8: 4770 bx lr
a: bf00 nop
Simple volatile variable seems to work OK:
#define s (*((volatile unsigned short*)128))
void f(){
s=0xff;
s=0xff;
}
00000000 <_Z1fv>:
0: 2380 movs r3, #128 ; 0x80
2: 22ff movs r2, #255 ; 0xff
4: 801a strh r2, [r3, #0] ;<<---| two writes here
6: 801a strh r2, [r3, #0] ;<<---|
8: 4770 bx lr
a: bf00 nop
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53085] writes to volatile struct members is missing
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
2012-04-23 12:58 ` [Bug c/53085] " unixoid2003 at mail dot ru
2012-04-23 13:19 ` unixoid2003 at mail dot ru
@ 2012-04-23 13:27 ` unixoid2003 at mail dot ru
2012-04-23 15:19 ` amonakov at gcc dot gnu.org
` (6 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: unixoid2003 at mail dot ru @ 2012-04-23 13:27 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
brag <unixoid2003 at mail dot ru> changed:
What |Removed |Added
----------------------------------------------------------------------------
Severity|critical |normal
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53085] writes to volatile struct members is missing
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
` (2 preceding siblings ...)
2012-04-23 13:27 ` [Bug c/53085] writes to volatile struct members is missing unixoid2003 at mail dot ru
@ 2012-04-23 15:19 ` amonakov at gcc dot gnu.org
2012-04-24 12:28 ` unixoid2003 at mail dot ru
` (5 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: amonakov at gcc dot gnu.org @ 2012-04-23 15:19 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
Alexander Monakov <amonakov at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |amonakov at gcc dot gnu.org
--- Comment #3 from Alexander Monakov <amonakov at gcc dot gnu.org> 2012-04-23 15:18:52 UTC ---
See discussion of volatile members in non-volatile structs in bug 45472
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug c/53085] writes to volatile struct members is missing
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
` (3 preceding siblings ...)
2012-04-23 15:19 ` amonakov at gcc dot gnu.org
@ 2012-04-24 12:28 ` unixoid2003 at mail dot ru
2012-04-24 13:07 ` [Bug tree-optimization/53085] " rguenth at gcc dot gnu.org
` (4 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: unixoid2003 at mail dot ru @ 2012-04-24 12:28 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
--- Comment #4 from brag <unixoid2003 at mail dot ru> 2012-04-24 12:27:29 UTC ---
Alexander Monakov, As for me it's ok to treat whole struct as non-volatile even
if it has a volatile members when doing smth like this:
struct ss0 a,b;
a=b;
a=b;
Simple example with class:
class aa{
void f();
private:
volatile int a;
};
void aa::f(){
a=0xff;
a=0xff;
}
arm-none-eabi-gcc -O2 -mcpu=cortex-m3 -mthumb -c test.cpp
gcc-4.6.1 compiled:
00000000 <_ZN2aa1fEv>:
0: 23ff movs r3, #255 ; 0xff
2: 6003 str r3, [r0, #0]
4: 6003 str r3, [r0, #0]
6: 4770 bx lr
The code is right.
gcc-4.7.0 compiled:
00000000 <_ZN2aa1fEv>:
0: 23ff movs r3, #255 ; 0xff
2: 6003 str r3, [r0, #0]
4: 4770 bx lr
6: bf00 nop
The code is wrong. It's not ok to write once 'volatile int a' member.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/53085] writes to volatile struct members is missing
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
` (4 preceding siblings ...)
2012-04-24 12:28 ` unixoid2003 at mail dot ru
@ 2012-04-24 13:07 ` rguenth at gcc dot gnu.org
2012-04-24 13:14 ` rguenth at gcc dot gnu.org
` (3 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-04-24 13:07 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |ASSIGNED
Last reconfirmed| |2012-04-24
Component|c |tree-optimization
AssignedTo|unassigned at gcc dot |rguenth at gcc dot gnu.org
|gnu.org |
Ever Confirmed|0 |1
--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-24 13:06:40 UTC ---
Confirmed and mine.
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/53085] writes to volatile struct members is missing
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
` (5 preceding siblings ...)
2012-04-24 13:07 ` [Bug tree-optimization/53085] " rguenth at gcc dot gnu.org
@ 2012-04-24 13:14 ` rguenth at gcc dot gnu.org
2012-04-24 14:42 ` rguenth at gcc dot gnu.org
` (2 subsequent siblings)
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-04-24 13:14 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
--- Comment #6 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-24 13:13:26 UTC ---
Patch that applies to all maintained branches (the bug is also in 4.5!)
Index: gcc/tree-ssa-pre.c
===================================================================
--- gcc/tree-ssa-pre.c (revision 186760)
+++ gcc/tree-ssa-pre.c (working copy)
@@ -4409,6 +4409,7 @@ eliminate (void)
has the same value number as its rhs. If so, the store is
dead. */
else if (gimple_assign_single_p (stmt)
+ && !gimple_has_volatile_ops (stmt)
&& !is_gimple_reg (gimple_assign_lhs (stmt))
&& (TREE_CODE (rhs) == SSA_NAME
|| is_gimple_min_invariant (rhs)))
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/53085] writes to volatile struct members is missing
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
` (6 preceding siblings ...)
2012-04-24 13:14 ` rguenth at gcc dot gnu.org
@ 2012-04-24 14:42 ` rguenth at gcc dot gnu.org
2012-04-24 14:43 ` rguenth at gcc dot gnu.org
2012-04-24 14:45 ` [Bug tree-optimization/53085] [4.7/4.8 Regression] " rguenth at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-04-24 14:42 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
--- Comment #7 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-24 14:41:59 UTC ---
Author: rguenth
Date: Tue Apr 24 14:41:49 2012
New Revision: 186764
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186764
Log:
2012-04-24 Richard Guenther <rguenther@suse.de>
PR tree-optimization/53085
* tree-ssa-pre.c (eliminate): Do not eliminate volatile redundant
stores.
* g++.dg/torture/pr53085.C: New testcase.
Added:
trunk/gcc/testsuite/g++.dg/torture/pr53085.C
Modified:
trunk/gcc/ChangeLog
trunk/gcc/testsuite/ChangeLog
trunk/gcc/tree-ssa-pre.c
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/53085] writes to volatile struct members is missing
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
` (7 preceding siblings ...)
2012-04-24 14:42 ` rguenth at gcc dot gnu.org
@ 2012-04-24 14:43 ` rguenth at gcc dot gnu.org
2012-04-24 14:45 ` [Bug tree-optimization/53085] [4.7/4.8 Regression] " rguenth at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-04-24 14:43 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
--- Comment #8 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-24 14:43:01 UTC ---
Author: rguenth
Date: Tue Apr 24 14:42:53 2012
New Revision: 186765
URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=186765
Log:
2012-04-24 Richard Guenther <rguenther@suse.de>
PR tree-optimization/53085
* tree-ssa-pre.c (eliminate): Do not eliminate volatile redundant
stores.
* g++.dg/torture/pr53085.C: New testcase.
Added:
branches/gcc-4_7-branch/gcc/testsuite/g++.dg/torture/pr53085.C
Modified:
branches/gcc-4_7-branch/gcc/ChangeLog
branches/gcc-4_7-branch/gcc/testsuite/ChangeLog
branches/gcc-4_7-branch/gcc/tree-ssa-pre.c
^ permalink raw reply [flat|nested] 11+ messages in thread
* [Bug tree-optimization/53085] [4.7/4.8 Regression] writes to volatile struct members is missing
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
` (8 preceding siblings ...)
2012-04-24 14:43 ` rguenth at gcc dot gnu.org
@ 2012-04-24 14:45 ` rguenth at gcc dot gnu.org
9 siblings, 0 replies; 11+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-04-24 14:45 UTC (permalink / raw)
To: gcc-bugs
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=53085
Richard Guenther <rguenth at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|ASSIGNED |RESOLVED
Known to work| |4.7.1
Resolution| |FIXED
Target Milestone|--- |4.7.1
Summary|writes to volatile struct |[4.7/4.8 Regression] writes
|members is missing |to volatile struct members
| |is missing
Known to fail| |4.7.0
--- Comment #9 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-04-24 14:45:02 UTC ---
Fixed for 4.7.1.
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2012-04-24 14:45 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-23 12:54 [Bug c/53085] New: write to volatile struct member is missing on Cortex-M3 unixoid2003 at mail dot ru
2012-04-23 12:58 ` [Bug c/53085] " unixoid2003 at mail dot ru
2012-04-23 13:19 ` unixoid2003 at mail dot ru
2012-04-23 13:27 ` [Bug c/53085] writes to volatile struct members is missing unixoid2003 at mail dot ru
2012-04-23 15:19 ` amonakov at gcc dot gnu.org
2012-04-24 12:28 ` unixoid2003 at mail dot ru
2012-04-24 13:07 ` [Bug tree-optimization/53085] " rguenth at gcc dot gnu.org
2012-04-24 13:14 ` rguenth at gcc dot gnu.org
2012-04-24 14:42 ` rguenth at gcc dot gnu.org
2012-04-24 14:43 ` rguenth at gcc dot gnu.org
2012-04-24 14:45 ` [Bug tree-optimization/53085] [4.7/4.8 Regression] " rguenth 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).