This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug regression/50472] New: Volatile qualification in data is not enough to avoid optimization over pointer to data
- From: "Paulo.Matos at csr dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Wed, 21 Sep 2011 08:09:42 +0000
- Subject: [Bug regression/50472] New: Volatile qualification in data is not enough to avoid optimization over pointer to data
- Auto-submitted: auto-generated
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=50472
Bug #: 50472
Summary: Volatile qualification in data is not enough to avoid
optimization over pointer to data
Classification: Unclassified
Product: gcc
Version: 4.6.1
Status: UNCONFIRMED
Severity: major
Priority: P3
Component: regression
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: Paulo.Matos@csr.com
Given the following code:
static const unsigned int foo = 1;
unsigned int test( void )
{
const volatile unsigned int *bar = &foo;
return ( *bar );
}
GCC46 is generating:
$ local/gcc-4.6.1/bin/gcc -Os -S vol.c
$ cat vol.s
...
test:
.LFB0:
.cfi_startproc
movl $1, %eax
ret
.cfi_endproc
...
This is optimizing away bar even though the data bar points to is being
qualified as volatile. The way to ensure this doesn't happen requires
qualifying the pointer as a volatile too:
static const unsigned int foo = 1;
unsigned int test( void )
{
const volatile unsigned int * volatile bar = &foo;
return ( *bar );
}
$ local/gcc-4.6.1/bin/gcc -Os -S vol.c
$ cat vol.s
...
test:
.LFB0:
.cfi_startproc
movq $foo, -8(%rsp)
movq -8(%rsp), %rax
movl (%rax), %eax
ret
.cfi_endproc
...
This is a regression to what GCC45 used to do. Qualification of the data as
volatile used to be enough to block the optimization.
Posting this to the mailing list revealed Ian agrees this is a regression:
http://gcc.gnu.org/ml/gcc/2011-09/msg00197.html