From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1666) id 377723858406; Mon, 8 Nov 2021 14:07:35 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 377723858406 MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Richard Biener To: gcc-cvs@gcc.gnu.org Subject: [gcc r9-9817] middle-end/101824 - properly handle volatiles in nested fn lowering X-Act-Checkin: gcc X-Git-Author: Richard Biener X-Git-Refname: refs/heads/releases/gcc-9 X-Git-Oldrev: e06957a82671396be2a327ac1d161a104a6ea731 X-Git-Newrev: 8dec0ae6200ae8c56dbeef5ff9acd2214282de67 Message-Id: <20211108140735.377723858406@sourceware.org> Date: Mon, 8 Nov 2021 14:07:35 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 08 Nov 2021 14:07:35 -0000 https://gcc.gnu.org/g:8dec0ae6200ae8c56dbeef5ff9acd2214282de67 commit r9-9817-g8dec0ae6200ae8c56dbeef5ff9acd2214282de67 Author: Richard Biener Date: Mon Aug 9 10:19:10 2021 +0200 middle-end/101824 - properly handle volatiles in nested fn lowering When we build the COMPONENT_REF of a formerly volatile local off the FRAME decl we have to make sure to mark the COMPONENT_REF as TREE_THIS_VOLATILE. While the GIMPLE operand scanner looks at the FIELD_DECL this is not how volatile GENERIC refs work. 2021-08-09 Richard Biener PR middle-end/101824 * tree-nested.c (get_frame_field): Mark the COMPONENT_REF as volatile in case the variable was. * gcc.dg/tree-ssa/pr101824.c: New testcase. (cherry picked from commit bb169406cdc9e044eaec500dd742c2fed40f5488) Diff: --- gcc/testsuite/gcc.dg/tree-ssa/pr101824.c | 19 +++++++++++++++++++ gcc/tree-nested.c | 1 + 2 files changed, 20 insertions(+) diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr101824.c b/gcc/testsuite/gcc.dg/tree-ssa/pr101824.c new file mode 100644 index 00000000000..d5987e14360 --- /dev/null +++ b/gcc/testsuite/gcc.dg/tree-ssa/pr101824.c @@ -0,0 +1,19 @@ +/* { dg-do compile } */ +/* { dg-options "-O3 -fdump-tree-pcom-details -fdump-tree-optimized" } */ + +int main() +{ + volatile int y; + void bar() + { + __builtin_printf ("%d", y); + } + while (y) + ; + return 0; +} + +/* Make sure the load from y is correctly interpreted as volatile, even + when going through FRAME. */ +/* { dg-final { scan-tree-dump-not "Executing predictive commoning" "pcom" } } */ +/* { dg-final { scan-tree-dump " ={v} FRAME" "optimized" } } */ diff --git a/gcc/tree-nested.c b/gcc/tree-nested.c index dc0cfe27142..a2ae3aefe4a 100644 --- a/gcc/tree-nested.c +++ b/gcc/tree-nested.c @@ -923,6 +923,7 @@ get_frame_field (struct nesting_info *info, tree target_context, } x = build3 (COMPONENT_REF, TREE_TYPE (field), x, field, NULL_TREE); + TREE_THIS_VOLATILE (x) = TREE_THIS_VOLATILE (field); return x; }