This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Lower VLA representation to pointers
On Wed, Aug 11, 2004 at 01:29:06PM -0700, Richard Henderson wrote:
> On Wed, Aug 11, 2004 at 07:25:13PM +0000, Joseph S. Myers wrote:
> > In standard terms there is no new block, neither after the label (which
> > indeed could be in a nested block) nor before the VLA, and the scope is
> > the same (same scope being defined as scope ending at same point) as that
> > of other declarations in the block.
>
> Huh. Perhaps I was confusing with C++, or just confused.
> Anyway, testing a patch that adds an artifical BIND_EXPR,
> but not a lexical scope.
Like so.
r~
* c-common.h (STATEMENT_LIST_HAS_LABEL): New.
* c-semantics.c (add_stmt): Set it.
* c-decl.c (finish_decl): Use it to create a new BIND_EXPR
before instantiating a variable sized type.
Index: c-common.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-common.h,v
retrieving revision 1.255
diff -c -p -d -r1.255 c-common.h
*** c-common.h 6 Aug 2004 02:03:18 -0000 1.255
--- c-common.h 12 Aug 2004 04:06:53 -0000
*************** Software Foundation, 59 Temple Place - S
*** 35,41 ****
STMT_IS_FULL_EXPR_P (in _STMT)
STATEMENT_LIST_STMT_EXPR (in STATEMENT_LIST)
2: unused
! 3: unused
4: unused
*/
--- 35,41 ----
STMT_IS_FULL_EXPR_P (in _STMT)
STATEMENT_LIST_STMT_EXPR (in STATEMENT_LIST)
2: unused
! 3: STATEMENT_LIST_HAS_LABEL (in STATEMENT_LIST)
4: unused
*/
*************** extern void finish_file (void);
*** 708,713 ****
--- 708,717 ----
#define STATEMENT_LIST_STMT_EXPR(NODE) \
TREE_LANG_FLAG_1 (STATEMENT_LIST_CHECK (NODE))
+ /* Nonzero if a label has been added to the statement list. */
+ #define STATEMENT_LIST_HAS_LABEL(NODE) \
+ TREE_LANG_FLAG_3 (STATEMENT_LIST_CHECK (NODE))
+
/* WHILE_STMT accessors. These give access to the condition of the
while statement and the body of the while statement, respectively. */
#define WHILE_COND(NODE) TREE_OPERAND (WHILE_STMT_CHECK (NODE), 0)
Index: c-decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-decl.c,v
retrieving revision 1.553
diff -c -p -d -r1.553 c-decl.c
*** c-decl.c 6 Aug 2004 02:03:18 -0000 1.553
--- c-decl.c 12 Aug 2004 04:06:54 -0000
*************** finish_decl (tree decl, tree init, tree
*** 3061,3067 ****
}
if (TREE_CODE (decl) != FUNCTION_DECL)
! add_stmt (build_stmt (DECL_EXPR, decl));
}
--- 3061,3084 ----
}
if (TREE_CODE (decl) != FUNCTION_DECL)
! {
! /* If we're building a variable sized type, and we might be
! reachable other than via the top of the current binding
! level, then create a new BIND_EXPR so that we deallocate
! the object at the right time. */
! /* Note that DECL_SIZE can be null due to errors. */
! if (DECL_SIZE (decl)
! && !TREE_CONSTANT (DECL_SIZE (decl))
! && STATEMENT_LIST_HAS_LABEL (cur_stmt_list))
! {
! tree bind;
! bind = build (BIND_EXPR, void_type_node, NULL, NULL, NULL);
! TREE_SIDE_EFFECTS (bind) = 1;
! add_stmt (bind);
! BIND_EXPR_BODY (bind) = push_stmt_list ();
! }
! add_stmt (build_stmt (DECL_EXPR, decl));
! }
}
Index: c-semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/c-semantics.c,v
retrieving revision 1.91
diff -c -p -d -r1.91 c-semantics.c
*** c-semantics.c 5 Aug 2004 05:51:50 -0000 1.91
--- c-semantics.c 12 Aug 2004 04:06:54 -0000
*************** add_stmt (tree t)
*** 140,145 ****
--- 140,148 ----
STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
}
+ if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
+ STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
+
/* Add T to the statement-tree. Non-side-effect statements need to be
recorded during statement expressions. */
append_to_statement_list_force (t, &cur_stmt_list);
Index: testsuite/gcc.c-torture/execute/20040811-1.c
===================================================================
RCS file: testsuite/gcc.c-torture/execute/20040811-1.c
diff -N testsuite/gcc.c-torture/execute/20040811-1.c
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/gcc.c-torture/execute/20040811-1.c 12 Aug 2004 04:08:18 -0000
***************
*** 0 ****
--- 1,19 ----
+ /* Ensure that we deallocate X when branching back before its
+ declaration. */
+
+ void *volatile p;
+
+ int
+ main (void)
+ {
+ int n = 0;
+ lab:;
+ int x[n % 1000 + 1];
+ x[0] = 1;
+ x[n % 1000] = 2;
+ p = x;
+ n++;
+ if (n < 1000000)
+ goto lab;
+ return 0;
+ }