This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[C++] constructor/destructor attribute fix
- To: gcc-patches at gcc dot gnu dot org
- Subject: [C++] constructor/destructor attribute fix
- From: "Mark E." <snowball3 at bigfoot dot com>
- Date: Fri, 28 Jul 2000 15:47:21 -0400
Hi guys,
I decided to try and figure out how to fix the bug described in gcc/131.
Calls to functions marked with the constructor or destructor attribute aren't
output in C++ unless there is a static duration class too. I also fixed
another bug where the marked function is called twice.
cp/ChangeLog:
2000-07-28 Mark Elbrecht <snowball3@bigfoot.com>
* decl.c (finish_function): Don't add fndecl to static_ctors or
static_dtors if fndecl has already been written out.
* decl2.c (finish_file): Generate calls to functions marked with
the constructor or destructor attributes when there are no
static storage duration functions.
(generate_ctor_or_dtor_function): Adjust.
Index: gcc/gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl.c,v
retrieving revision 1.664
diff -c -p -r1.664 decl.c
*** decl.c 2000/07/28 06:05:09 1.664
--- decl.c 2000/07/28 19:01:19
*************** finish_function (flags)
*** 14512,14520 ****
DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX;
}
! if (DECL_STATIC_CONSTRUCTOR (fndecl))
static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
! if (DECL_STATIC_DESTRUCTOR (fndecl))
static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
/* Clean up. */
--- 14512,14520 ----
DECL_RTL (t) = DECL_INCOMING_RTL (t) = NULL_RTX;
}
! if (DECL_STATIC_CONSTRUCTOR (fndecl) && !TREE_ASM_WRITTEN (fndecl))
static_ctors = tree_cons (NULL_TREE, fndecl, static_ctors);
! if (DECL_STATIC_DESTRUCTOR (fndecl) && !TREE_ASM_WRITTEN (fndecl))
static_dtors = tree_cons (NULL_TREE, fndecl, static_dtors);
/* Clean up. */
Index: gcc/gcc/cp/decl2.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cp/decl2.c,v
retrieving revision 1.379
diff -c -p -r1.379 decl2.c
*** decl2.c 2000/07/27 04:49:17 1.379
--- decl2.c 2000/07/28 19:01:45
*************** generate_ctor_or_dtor_function (construc
*** 3533,3538 ****
--- 3533,3539 ----
tree arguments;
tree body;
size_t i;
+ size_t elems_used;
/* We use `I' to indicate initialization and `D' to indicate
destruction. */
*************** generate_ctor_or_dtor_function (construc
*** 3546,3552 ****
/* Call the static storage duration function with appropriate
arguments. */
! for (i = 0; i < ssdf_decls->elements_used; ++i)
{
arguments = tree_cons (NULL_TREE, build_int_2 (priority, 0),
NULL_TREE);
--- 3547,3554 ----
/* Call the static storage duration function with appropriate
arguments. */
! elems_used = ssdf_decls ? ssdf_decls->elements_used : 0;
! for (i = 0; i < elems_used; ++i)
{
arguments = tree_cons (NULL_TREE, build_int_2 (priority, 0),
NULL_TREE);
*************** finish_file ()
*** 3828,3834 ****
splay_tree_foreach (priority_info_map,
generate_ctor_and_dtor_functions_for_priority,
/*data=*/0);
!
/* We're done with the splay-tree now. */
if (priority_info_map)
splay_tree_delete (priority_info_map);
--- 3830,3848 ----
splay_tree_foreach (priority_info_map,
generate_ctor_and_dtor_functions_for_priority,
/*data=*/0);
! else
! {
! /* When there are no static duration objects, then just
! generate calls to functions marked with the constructor
! and destructor attributes. */
! if (static_ctors)
! generate_ctor_or_dtor_function (/*constructor_p=*/1,
! DEFAULT_INIT_PRIORITY);
! if (static_dtors)
! generate_ctor_or_dtor_function (/*constructor_p=*/0,
! DEFAULT_INIT_PRIORITY);
! }
!
/* We're done with the splay-tree now. */
if (priority_info_map)
splay_tree_delete (priority_info_map);