This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

VLA deallocation (PR 19771)


This patch fixes PR 19771, where a jump to before the declaration of a
VLA did not always deallocate it.

The flag STATEMENT_LIST_HAS_LABEL is used only for the single
condition that ensures a new BIND_EXPR is created to contain a VLA if
it might be possible to jump to before its declaration.  So ensuring
that this flag is set if there is a label in an inner scope is both
safe and sufficient to ensure that VLAs are deallocated in this case.
(Jumps to outside the block containing the VLA - either before or
after it - are handled automatically through each scope getting its
own BIND_EXPR; it's only jumps that do not leave that block that need
this special extra BIND_EXPR creation.)

Bootstrapped with no regressions on x86_64-unknown-linux-gnu.  Applied
to mainline.

2009-04-19  Joseph Myers  <joseph@codesourcery.com>

	PR c/19771
	* c-semantics.c (pop_stmt_list): Propagate
	STATEMENT_LIST_HAS_LABEL to parent statement list.

testsuite:
2009-04-19  Joseph Myers  <joseph@codesourcery.com>

	PR c/19771
	* gcc.c-torture/execute/vla-dealloc-1.c: New test.

Index: gcc/c-semantics.c
===================================================================
--- gcc/c-semantics.c	(revision 146336)
+++ gcc/c-semantics.c	(working copy)
@@ -70,6 +70,8 @@ pop_stmt_list (tree t)
     {
       chain = TREE_CHAIN (u);
       TREE_CHAIN (u) = NULL_TREE;
+      if (chain)
+	STATEMENT_LIST_HAS_LABEL (chain) |= STATEMENT_LIST_HAS_LABEL (u);
       if (t == u)
 	break;
       u = chain;
Index: gcc/testsuite/gcc.c-torture/execute/vla-dealloc-1.c
===================================================================
--- gcc/testsuite/gcc.c-torture/execute/vla-dealloc-1.c	(revision 0)
+++ gcc/testsuite/gcc.c-torture/execute/vla-dealloc-1.c	(revision 0)
@@ -0,0 +1,22 @@
+/* VLAs should be deallocated on a jump to before their definition,
+   including a jump to a label in an inner scope.  PR 19771.  */
+
+void *volatile p;
+
+int
+main (void)
+{
+  int n = 0;
+  if (0)
+    {
+    lab:;
+    }
+  int x[n % 1000 + 1];
+  x[0] = 1;
+  x[n % 1000] = 2;
+  p = x;
+  n++;
+  if (n < 1000000)
+    goto lab;
+  return 0;
+}

-- 
Joseph S. Myers
joseph@codesourcery.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]