]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
middle-end/101824 - properly handle volatiles in nested fn lowering
authorRichard Biener <rguenther@suse.de>
Mon, 9 Aug 2021 08:19:10 +0000 (10:19 +0200)
committerRichard Biener <rguenther@suse.de>
Tue, 10 Aug 2021 07:27:49 +0000 (09:27 +0200)
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  <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 [new file with mode: 0644]
gcc/tree-nested.c

diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr101824.c b/gcc/testsuite/gcc.dg/tree-ssa/pr101824.c
new file mode 100644 (file)
index 0000000..d5987e1
--- /dev/null
@@ -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" } } */
index 0c3fb029054704059b494f5c4335bde2fc9fb874..cc59526dab80d86f134895abc2c8569d2b965d90 100644 (file)
@@ -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;
 }