re PR rtl-optimization/7675 (ICE in fixup_var_refs_1)
authorEric Botcazou <ebotcazou@libertysurf.fr>
Fri, 18 Apr 2003 06:45:15 +0000 (08:45 +0200)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 18 Apr 2003 06:45:15 +0000 (06:45 +0000)
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.

From-SVN: r65774

gcc/ChangeLog
gcc/c-typeck.c
gcc/stmt.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.c-torture/compile/20030418-1.c [new file with mode: 0644]

index abbec33da066af879d601485eecbde693ecbc37a..68c3d86de6c389158159c721d63736653604d929 100644 (file)
@@ -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
index 4c14b5f9685a9e0d5ce8a2c87cd6ca4ed262eb41..871e10807f957e8f1c697260b9f8eae81184cfa9 100644 (file)
@@ -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;
 }
index 642a5b1ccfc43016efa65d75a912cfe8de8dfd52..9caa5c2b54c83e83c85cb81bccccc19ac4eb2d56 100644 (file)
@@ -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.  */
index fb5d59ebc1d38faf10f4dfb6afd79c840a97d567..99c3b2b12dfb4bd42d54066b661b49b0cd6a2877 100644 (file)
@@ -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 (file)
index 0000000..f6d5a4a
--- /dev/null
@@ -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);
+}