cp-tree.h (make_rtl_for_local_static): New function.
authorMark Mitchell <mark@codesourcery.com>
Sat, 9 Oct 1999 21:06:03 +0000 (21:06 +0000)
committerMark Mitchell <mmitchel@gcc.gnu.org>
Sat, 9 Oct 1999 21:06:03 +0000 (21:06 +0000)
* cp-tree.h (make_rtl_for_local_static): New function.
* decl.c (make_rtl_for_nonlocal_decl): Move code to create RTL for
local statics ...
(make_rtl_for_local_static): Here.
* semantics.c (expand_stmt): Use make_rtl_for_local_static.

From-SVN: r29879

gcc/cp/ChangeLog
gcc/cp/cp-tree.h
gcc/cp/decl.c
gcc/cp/semantics.c
gcc/testsuite/g++.old-deja/g++.other/static10.C [new file with mode: 0644]

index 3fab215..a4ab8c5 100644 (file)
@@ -1,3 +1,11 @@
+1999-10-09  Mark Mitchell  <mark@codesourcery.com>
+
+       * cp-tree.h (make_rtl_for_local_static): New function.  
+       * decl.c (make_rtl_for_nonlocal_decl): Move code to create RTL for
+       local statics ...
+       (make_rtl_for_local_static): Here.
+       * semantics.c (expand_stmt): Use make_rtl_for_local_static.
+       
 1999-10-08  Kaveh R. Ghazi  <ghazi@caip.rutgers.edu>
 
        * method.c: Include tm_p.h.
index 4c00f00..ea8e495 100644 (file)
@@ -3470,6 +3470,7 @@ extern tree create_implicit_typedef             PROTO((tree, tree));
 extern tree maybe_push_decl                     PROTO((tree));
 extern void emit_local_var                      PROTO((tree));
 extern tree build_target_expr                   PROTO((tree, tree));
+extern void make_rtl_for_local_static           PROTO((tree));
 
 /* in decl2.c */
 extern void init_decl2                         PROTO((void));
index c425fcb..1554abc 100644 (file)
@@ -7378,23 +7378,7 @@ make_rtl_for_nonlocal_decl (decl, init, asmspec)
     {
       DECL_INITIAL (decl) = save_expr (DECL_INITIAL (decl));
 
-      if (! toplev
-         && TREE_STATIC (decl)
-         && ! TREE_SIDE_EFFECTS (decl)
-         && ! TREE_PUBLIC (decl)
-         && ! DECL_EXTERNAL (decl)
-         && ! TYPE_NEEDS_DESTRUCTOR (type)
-         && DECL_MODE (decl) != BLKmode)
-       {
-         /* If this variable is really a constant, then fill its DECL_RTL
-            slot with something which won't take up storage.
-            If something later should take its address, we can always give
-            it legitimate RTL at that time.  */
-         DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
-         store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
-         TREE_ASM_WRITTEN (decl) = 1;
-       }
-      else if (toplev && ! TREE_PUBLIC (decl))
+      if (toplev && ! TREE_PUBLIC (decl))
        {
          /* If this is a static const, change its apparent linkage
             if it belongs to a #pragma interface.  */
@@ -7432,6 +7416,47 @@ make_rtl_for_nonlocal_decl (decl, init, asmspec)
     rest_of_decl_compilation (decl, asmspec, toplev, at_eof);
 }
 
+/* Create RTL for the local static variable DECL.  */
+
+void
+make_rtl_for_local_static (decl)
+     tree decl;
+{
+  tree type = TREE_TYPE (decl);
+  const char *asmspec = NULL;
+
+  if (TREE_READONLY (decl)
+      && DECL_INITIAL (decl) != NULL_TREE
+      && DECL_INITIAL (decl) != error_mark_node
+      && ! EMPTY_CONSTRUCTOR_P (DECL_INITIAL (decl))
+      && ! TREE_SIDE_EFFECTS (decl)
+      && ! TREE_PUBLIC (decl)
+      && ! DECL_EXTERNAL (decl)
+      && ! TYPE_NEEDS_DESTRUCTOR (type)
+      && DECL_MODE (decl) != BLKmode)
+    {
+      /* As an optimization, we try to put register-sized static
+        constants in a register, rather than writing them out.  If we
+        take the address of the constant later, we'll make RTL for it
+        at that point.  */
+      DECL_RTL (decl) = gen_reg_rtx (DECL_MODE (decl));
+      store_expr (DECL_INITIAL (decl), DECL_RTL (decl), 0);
+      TREE_ASM_WRITTEN (decl) = 1;
+      return;
+    }
+
+  if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
+    {
+      /* The only way this situaton can occur is if the
+        user specified a name for this DECL using the
+        `attribute' syntax.  */
+      asmspec = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+      DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl);
+    }
+
+  rest_of_decl_compilation (decl, asmspec, /*top_level=*/0, /*at_end=*/0);
+}
+
 /* The old ARM scoping rules injected variables declared in the
    initialization statement of a for-statement into the surrounding
    scope.  We support this usage, in order to be backward-compatible.
index 5cdeb07..4c91e16 100644 (file)
@@ -2301,21 +2301,7 @@ expand_stmt (t)
                                          DECL_ANON_UNION_ELEMS (decl));
              }
            else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
-             {
-               const char *asmspec = NULL;
-
-               if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl))
-                 {
-                   /* The only way this situaton can occur is if the
-                      user specified a name for this DECL using the
-                      `attribute' syntax.  */
-                   asmspec = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
-                   DECL_ASSEMBLER_NAME (decl) = DECL_NAME (decl);
-                 }
-
-               rest_of_decl_compilation (decl, asmspec, 
-                                         /*top_level=*/0, /*at_end=*/0);
-             }
+             make_rtl_for_local_static (decl);
 
            resume_momentary (i);
          }
diff --git a/gcc/testsuite/g++.old-deja/g++.other/static10.C b/gcc/testsuite/g++.old-deja/g++.other/static10.C
new file mode 100644 (file)
index 0000000..212191c
--- /dev/null
@@ -0,0 +1,16 @@
+// Build don't link:
+// Origin: Ulrich Drepper <drepper@cygnus.com>
+
+struct st
+{
+  int a;
+};
+
+int
+foo (int a)
+{
+  static const st i = { 0 };
+
+  if (i.a == a)
+    return 0;
+}