From f301014645f6ec88d2c543fba1e26a2f2418c40a Mon Sep 17 00:00:00 2001 From: Mark Mitchell Date: Sat, 9 Oct 1999 21:06:03 +0000 Subject: [PATCH] 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 --- gcc/cp/ChangeLog | 8 ++++ gcc/cp/cp-tree.h | 1 + gcc/cp/decl.c | 59 ++++++++++++++++++------- gcc/cp/semantics.c | 16 +------ gcc/testsuite/g++.old-deja/g++.other/static10.C | 16 +++++++ 5 files changed, 68 insertions(+), 32 deletions(-) create mode 100644 gcc/testsuite/g++.old-deja/g++.other/static10.C 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 + + * 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 * 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 + +struct st +{ + int a; +}; + +int +foo (int a) +{ + static const st i = { 0 }; + + if (i.a == a) + return 0; +} -- 2.7.4