aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorMark Mitchell <mark@codesourcery.com>1999-10-09 21:06:03 +0000
committerMark Mitchell <mmitchel@gcc.gnu.org>1999-10-09 21:06:03 +0000
commitf301014645f6ec88d2c543fba1e26a2f2418c40a (patch)
tree8aa5a888de758612c31c5b837bb35ab0f091e001 /gcc
parentab61414260712684d8f75c8550933f24e0d1df22 (diff)
downloadgcc-f301014645f6ec88d2c543fba1e26a2f2418c40a.zip
gcc-f301014645f6ec88d2c543fba1e26a2f2418c40a.tar.gz
gcc-f301014645f6ec88d2c543fba1e26a2f2418c40a.tar.bz2
cp-tree.h (make_rtl_for_local_static): New function.
* 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
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/ChangeLog8
-rw-r--r--gcc/cp/cp-tree.h1
-rw-r--r--gcc/cp/decl.c59
-rw-r--r--gcc/cp/semantics.c16
-rw-r--r--gcc/testsuite/g++.old-deja/g++.other/static10.C16
5 files changed, 68 insertions, 32 deletions
diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog
index 3fab215..a4ab8c5 100644
--- a/gcc/cp/ChangeLog
+++ b/gcc/cp/ChangeLog
@@ -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.
diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
index 4c00f00..ea8e495 100644
--- a/gcc/cp/cp-tree.h
+++ b/gcc/cp/cp-tree.h
@@ -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));
diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index c425fcb..1554abc 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -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.
diff --git a/gcc/cp/semantics.c b/gcc/cp/semantics.c
index 5cdeb07..4c91e16 100644
--- a/gcc/cp/semantics.c
+++ b/gcc/cp/semantics.c
@@ -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
index 0000000..212191c
--- /dev/null
+++ b/gcc/testsuite/g++.old-deja/g++.other/static10.C
@@ -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;
+}