mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-03-16 04:40:25 +08:00
middle-end/69482 - not preserving volatile accesses
The following addresses a long standing issue with not preserving accesses to non-volatile objects through volatile qualified pointers in the case that object gets expanded to a register. The fix is to treat accesses to an object with a volatile qualified access as forcing that object to memory. This issue got more exposed recently so it regressed more since GCC 11. PR middle-end/69482 * cfgexpand.cc (discover_nonconstant_array_refs_r): Volatile qualified accesses also force objects to memory. * gcc.target/i386/pr69482-1.c: New testcase. * gcc.target/i386/pr69482-2.c: Likewise.
This commit is contained in:
parent
fb082e3293
commit
a5a8242153
@ -6291,6 +6291,15 @@ discover_nonconstant_array_refs_r (tree * tp, int *walk_subtrees,
|
||||
|
||||
if (IS_TYPE_OR_DECL_P (t))
|
||||
*walk_subtrees = 0;
|
||||
else if (REFERENCE_CLASS_P (t) && TREE_THIS_VOLATILE (t))
|
||||
{
|
||||
t = get_base_address (t);
|
||||
if (t && DECL_P (t)
|
||||
&& DECL_MODE (t) != BLKmode
|
||||
&& !TREE_ADDRESSABLE (t))
|
||||
bitmap_set_bit (forced_stack_vars, DECL_UID (t));
|
||||
*walk_subtrees = 0;
|
||||
}
|
||||
else if (TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
|
||||
{
|
||||
while (((TREE_CODE (t) == ARRAY_REF || TREE_CODE (t) == ARRAY_RANGE_REF)
|
||||
|
16
gcc/testsuite/gcc.target/i386/pr69482-1.c
Normal file
16
gcc/testsuite/gcc.target/i386/pr69482-1.c
Normal file
@ -0,0 +1,16 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O3" } */
|
||||
|
||||
static inline void memset_s(void* s, int n) {
|
||||
volatile unsigned char * p = s;
|
||||
for(int i = 0; i < n; ++i) {
|
||||
p[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void test() {
|
||||
unsigned char x[4];
|
||||
memset_s(x, sizeof x);
|
||||
}
|
||||
|
||||
/* { dg-final { scan-assembler-times "mov" 4 } } */
|
10
gcc/testsuite/gcc.target/i386/pr69482-2.c
Normal file
10
gcc/testsuite/gcc.target/i386/pr69482-2.c
Normal file
@ -0,0 +1,10 @@
|
||||
/* { dg-do compile } */
|
||||
/* { dg-options "-O2" } */
|
||||
|
||||
void bar ()
|
||||
{
|
||||
int j;
|
||||
*(volatile int *)&j = 0;
|
||||
}
|
||||
|
||||
/* { dg-final { scan-assembler-times "mov" 1 } } */
|
Loading…
x
Reference in New Issue
Block a user