diff options
author | Jakub Jelinek <jakub@redhat.com> | 2024-02-10 11:28:00 +0100 |
---|---|---|
committer | Jakub Jelinek <jakub@redhat.com> | 2024-02-10 11:28:00 +0100 |
commit | 39920447f876128ff7942a9cd931021800865894 (patch) | |
tree | c38e25b273bdc97dcbf628e090e81dc33a9a437b /gcc/testsuite/g++.dg/cpp23 | |
parent | 8427290f33d95bc173d37637fbec044b2c067f14 (diff) | |
download | gcc-39920447f876128ff7942a9cd931021800865894.zip gcc-39920447f876128ff7942a9cd931021800865894.tar.gz gcc-39920447f876128ff7942a9cd931021800865894.tar.bz2 |
gimple-low: Fix up handling of volatile automatic vars in assume attribute [PR110754]
As the following testcases show, the gimple-low outlining of assume
magic functions handled volatile automatic vars (including
parameters/results) like non-volatile ones except it copied volatile
to the new PARM_DECL, which has the undesirable effect that a load
from the volatile var is passed to IFN_ASSUME and so there is a
side-effect there even when side-effects of the assume attribute
shouldn't be evaluated.
The following patch fixes that by passing address of the volatile
variables/parameters/results instead and doing loads or stores from it
or to it where it was originally accessed in the assume attribute
expression.
2024-02-10 Jakub Jelinek <jakub@redhat.com>
PR middle-end/110754
* gimple-low.cc (assumption_copy_decl): For TREE_THIS_VOLATILE
decls create PARM_DECL with pointer to original type, set
TREE_READONLY and keep TREE_THIS_VOLATILE, TREE_ADDRESSABLE,
DECL_NOT_GIMPLE_REG_P and DECL_BY_REFERENCE cleared.
(adjust_assumption_stmt_op): For remapped TREE_THIS_VOLATILE decls
wrap PARM_DECL into a simple TREE_THIS_NO_TRAP MEM_REF.
(lower_assumption): For TREE_THIS_VOLATILE vars pass ADDR_EXPR
of the var as argument.
* gcc.dg/attr-assume-6.c: New test.
* g++.dg/cpp23/attr-assume12.C: New test.
Diffstat (limited to 'gcc/testsuite/g++.dg/cpp23')
-rw-r--r-- | gcc/testsuite/g++.dg/cpp23/attr-assume12.C | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/gcc/testsuite/g++.dg/cpp23/attr-assume12.C b/gcc/testsuite/g++.dg/cpp23/attr-assume12.C new file mode 100644 index 0000000..c955cd1 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp23/attr-assume12.C @@ -0,0 +1,14 @@ +// PR middle-end/110754 +// { dg-do compile { target c++11 } } +// { dg-options "-O2 -fdump-tree-optimized" } +// { dg-final { scan-tree-dump-times "a ={v} x" 1 "optimized" } } +// { dg-final { scan-tree-dump-not "={v} a" "optimized" } } +// { dg-final { scan-tree-dump-times "return 0;" 1 "optimized" } } + +int +foo (int x) +{ + volatile int a = x; + [[gnu::assume (x == (a & 0))]]; + return x; +} |