This is the mail archive of the
mailing list for the GCC project.
[PATCH] variable size arrays in nested functions
- To: rth at redhat dot com
- Subject: [PATCH] variable size arrays in nested functions
- From: Jakub Jelinek <jakub at redhat dot com>
- Date: Fri, 9 Feb 2001 13:17:28 +0100
- Cc: gcc-patches at gcc dot gnu dot org
- Reply-To: Jakub Jelinek <jakub at redhat dot com>
The testcase below causes in ICE in expand_expr in gcc-2.96-RH. The issue is
that any SAVE_EXPR's generated from grokdeclarator for the function
arguments get context of the containing function, not the function they
belong to (or 0 if the function is not nested).
With current CVS head, the wrong SAVE_EXPR's are generated as well but for
some reason don't make it into expand_expr in this case so the ICE does not
happen (the abort() is because SAVE_EXPR corresponding to variable size
array argument's size doesn't have SAVE_EXPR_RTL attached yet and has non-NULL
context which is different from current function).
Does a patch like this look ok? It causes all SAVE_EXPRs for parameters
to have NULL context meaning they can be used in current function (ie.
nested one in this case).
Bootstrapped on i386-redhat-linux, no regressions.
2001-02-09 Jakub Jelinek <firstname.lastname@example.org>
* c-decl.c (push_parm_decl): Call grokdeclarator always with
current_function_decl == 0, even for nested functions.
* gcc.c-torture/execute/20010209-1.c: New test.
--- gcc/c-decl.c.jj Mon Feb 5 14:50:26 2001
+++ gcc/c-decl.c Fri Feb 9 00:50:29 2001
@@ -3768,15 +3768,22 @@ void
- tree decl;
+ tree decl, fn;
int old_immediate_size_expand = immediate_size_expand;
/* Don't try computing parm sizes now -- wait till fn is called. */
immediate_size_expand = 0;
+ /* Make sure any save_expr are not created in the context of the containing
+ function for nested functions. */
+ fn = current_function_decl;
+ current_function_decl = 0;
decl = grokdeclarator (TREE_VALUE (TREE_PURPOSE (parm)),
TREE_PURPOSE (TREE_PURPOSE (parm)), PARM, 0);
decl_attributes (decl, TREE_VALUE (TREE_VALUE (parm)),
TREE_PURPOSE (TREE_VALUE (parm)));
+ current_function_decl = fn;
if (DECL_NAME (decl))
--- gcc/testsuite/gcc.c-torture/execute/20010209-1.c.jj Fri Feb 9 01:13:27 2001
+++ gcc/testsuite/gcc.c-torture/execute/20010209-1.c Fri Feb 9 01:13:18 2001
@@ -0,0 +1,21 @@
+int foo (void)
+ int x[b];
+ int bar (int t[b])
+ int i;
+ for (i = 0; i < b; i++)
+ t[i] = i + (i > 0 ? t[i-1] : 0);
+ return t[b-1];
+ return bar (x);
+int main ()
+ b = 6;
+ if (foo () != 15)
+ abort ();
+ exit (0);