diff mbox series

middle-end/101824 - properly handle volatiles in nested fn lowering

Message ID 5n952073-937o-q256-no9o-9p624980s182@fhfr.qr
State New
Headers show
Series middle-end/101824 - properly handle volatiles in nested fn lowering | expand

Commit Message

Richard Biener Aug. 9, 2021, 8:34 a.m. UTC
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.

Bootstrap & regtest in progress on x86_64-unknown-linux-gnu.

I'm going to try scrapping the processing of the FIELD_DECL from
the operand scanner as followup.  Frontends generally seem to
process the FIELD_DECLs volatile setting and set the COMPONENT_REF
volatile seetting accordingly - so I wonder whether we should
change build3 to do that as well for convenience?

2021-08-09  Richard Biener  <rguenther@suse.de>

	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.
---
 gcc/testsuite/gcc.dg/tree-ssa/pr101824.c | 19 +++++++++++++++++++
 gcc/tree-nested.c                        |  1 +
 2 files changed, 20 insertions(+)
 create mode 100644 gcc/testsuite/gcc.dg/tree-ssa/pr101824.c
diff mbox series

Patch

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 0c3fb029054..cc59526dab8 100644
--- a/gcc/tree-nested.c
+++ b/gcc/tree-nested.c
@@ -1033,6 +1033,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;
 }