summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2003-04-18 06:45:15 +0000
committerebotcazou <ebotcazou@138bc75d-0d04-0410-961f-82ee72b054a4>2003-04-18 06:45:15 +0000
commitf3d3a8e25ed135d4c539aed7203030dc140d4820 (patch)
treee0dee3b9bf6420657cea4b3e36c2550d4e9614f9
parent2113f013b978972368794f4e76b47553d19186e1 (diff)
downloadgcc-f3d3a8e25ed135d4c539aed7203030dc140d4820.tar.gz
PR optimization/7675
* c-typeck.c (build_external_ref): Set the DECL_NONLOCAL flag on VAR_DECL, PARM_DECL and FUNCTION_DECL from within nested functions if they refer to declarations from parent functions. * stmt.c (expand_decl): Don't put automatic variables in registers if the DECL_NONLOCAL flag is set. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@65774 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog9
-rw-r--r--gcc/c-typeck.c11
-rw-r--r--gcc/stmt.c1
-rw-r--r--gcc/testsuite/ChangeLog4
-rw-r--r--gcc/testsuite/gcc.c-torture/compile/20030418-1.c16
5 files changed, 41 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index abbec33da06..68c3d86de6c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,12 @@
+2003-04-18 Eric Botcazou <ebotcazou@libertysurf.fr>
+
+ PR optimization/7675
+ * c-typeck.c (build_external_ref): Set the DECL_NONLOCAL flag
+ on VAR_DECL, PARM_DECL and FUNCTION_DECL from within
+ nested functions if they refer to declarations from parent functions.
+ * stmt.c (expand_decl): Don't put automatic variables in registers
+ if the DECL_NONLOCAL flag is set.
+
2003-04-18 Hans-Peter Nilsson <hp@bitrange.com>
* gcse.c (compute_ld_motion_mems): For MEM destinations, only
diff --git a/gcc/c-typeck.c b/gcc/c-typeck.c
index 4c14b5f9685..871e10807f9 100644
--- a/gcc/c-typeck.c
+++ b/gcc/c-typeck.c
@@ -1463,6 +1463,17 @@ build_external_ref (id, fun)
ref = DECL_INITIAL (ref);
TREE_CONSTANT (ref) = 1;
}
+ else if (current_function_decl != 0
+ && DECL_CONTEXT (current_function_decl) != 0
+ && (TREE_CODE (ref) == VAR_DECL
+ || TREE_CODE (ref) == PARM_DECL
+ || TREE_CODE (ref) == FUNCTION_DECL))
+ {
+ tree context = decl_function_context (ref);
+
+ if (context != 0 && context != current_function_decl)
+ DECL_NONLOCAL (ref) = 1;
+ }
return ref;
}
diff --git a/gcc/stmt.c b/gcc/stmt.c
index 642a5b1ccfc..9caa5c2b54c 100644
--- a/gcc/stmt.c
+++ b/gcc/stmt.c
@@ -3924,6 +3924,7 @@ expand_decl (decl)
&& !(flag_float_store
&& TREE_CODE (type) == REAL_TYPE)
&& ! TREE_THIS_VOLATILE (decl)
+ && ! DECL_NONLOCAL (decl)
&& (DECL_REGISTER (decl) || optimize))
{
/* Automatic variable that can go in a register. */
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index fb5d59ebc1d..99c3b2b12df 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,7 @@
+2003-04-18 Eric Botcazou <ebotcazou@libertysurf.fr>
+
+ * gcc.c-torture/compile/20030418-1.c: New test.
+
2003-04-17 Janis Johnson <janis187@us.ibm.com>
* README.compat: Remove; content moved to doc/sourcebuild.texi.
diff --git a/gcc/testsuite/gcc.c-torture/compile/20030418-1.c b/gcc/testsuite/gcc.c-torture/compile/20030418-1.c
new file mode 100644
index 00000000000..f6d5a4af51c
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/20030418-1.c
@@ -0,0 +1,16 @@
+/* PR optimization/7675 */
+/* Contributed by Volker Reichelt */
+
+/* Verify that we don't put automatic variables
+ in registers too early. */
+
+extern int dummy (int *);
+
+void foo(int i)
+{
+ int j=i;
+
+ void bar() { int x=j, y=i; }
+
+ dummy(&i);
+}