This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
C++ PATCH: PR 11137
- From: Mark Mitchell <mark at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Tue, 1 Jul 2003 11:18:10 -0700
- Subject: C++ PATCH: PR 11137
- Reply-to: mark at codesourcery dot com
I've backported this fix to the 3.3 branch; when I applied it to the
mainline I didn't realize it was a regression.
Tested on i686-pc-linux-gnu, applied on the 3.3 branch.
--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com
2003-07-01 Mark Mitchell <mark@codesourcery.com>
PR c++/11137
* decl2.c (generate_ctor_or_dtor_function): Tolerate a
non-existant ssdf_decls array.
(finish_file): Call generator_ctor_or_dtor_function when there are
static constructors or destructors and no other static
initializations.
2003-07-01 Mark Mitchell <mark@codesourcery.com>
PR c++/11137
* g++.dg/init/attrib1.C: New test.
Index: cp/decl2.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl2.c,v
retrieving revision 1.612
retrieving revision 1.613
diff -c -5 -p -r1.612 -r1.613
*** cp/decl2.c 28 Mar 2003 08:02:14 -0000 1.612
--- cp/decl2.c 28 Mar 2003 19:30:40 -0000 1.613
*************** generate_ctor_or_dtor_function (bool con
*** 2492,2518 ****
/* Begin the function. */
body = start_objects (function_key, priority);
/* 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);
! arguments = tree_cons (NULL_TREE, build_int_2 (constructor_p, 0),
! arguments);
! finish_expr_stmt (build_function_call (VARRAY_TREE (ssdf_decls, i),
! arguments));
! }
/* If we're generating code for the DEFAULT_INIT_PRIORITY, throw in
calls to any functions marked with attributes indicating that
they should be called at initialization- or destruction-time. */
if (priority == DEFAULT_INIT_PRIORITY)
{
tree fns;
!
for (fns = constructor_p ? static_ctors : static_dtors;
fns;
fns = TREE_CHAIN (fns))
finish_expr_stmt (build_function_call (TREE_VALUE (fns), NULL_TREE));
}
--- 2492,2519 ----
/* Begin the function. */
body = start_objects (function_key, priority);
/* Call the static storage duration function with appropriate
arguments. */
! if (ssdf_decls)
! for (i = 0; i < ssdf_decls->elements_used; ++i)
! {
! arguments = tree_cons (NULL_TREE, build_int_2 (priority, 0),
! NULL_TREE);
! arguments = tree_cons (NULL_TREE, build_int_2 (constructor_p, 0),
! arguments);
! finish_expr_stmt (build_function_call (VARRAY_TREE (ssdf_decls, i),
! arguments));
! }
/* If we're generating code for the DEFAULT_INIT_PRIORITY, throw in
calls to any functions marked with attributes indicating that
they should be called at initialization- or destruction-time. */
if (priority == DEFAULT_INIT_PRIORITY)
{
tree fns;
!
for (fns = constructor_p ? static_ctors : static_dtors;
fns;
fns = TREE_CHAIN (fns))
finish_expr_stmt (build_function_call (TREE_VALUE (fns), NULL_TREE));
}
*************** finish_file ()
*** 2836,2845 ****
--- 2837,2855 ----
priorities for which they are required. */
if (priority_info_map)
splay_tree_foreach (priority_info_map,
generate_ctor_and_dtor_functions_for_priority,
/*data=*/0);
+ else
+ {
+ if (static_ctors)
+ generate_ctor_or_dtor_function (/*constructor_p=*/true,
+ DEFAULT_INIT_PRIORITY);
+ if (static_dtors)
+ generate_ctor_or_dtor_function (/*constructor_p=*/false,
+ DEFAULT_INIT_PRIORITY);
+ }
/* We're done with the splay-tree now. */
if (priority_info_map)
splay_tree_delete (priority_info_map);
Index: testsuite/g++.dg/init/attrib1.C
===================================================================
RCS file: testsuite/g++.dg/init/attrib1.C
diff -N testsuite/g++.dg/init/attrib1.C
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/init/attrib1.C 28 Mar 2003 19:30:41 -0000 1.1
***************
*** 0 ****
--- 1,10 ----
+ // { dg-do run }
+
+ void f() __attribute((__constructor__));
+ int i;
+ void f() { i = 1; }
+
+ int main(int, char **)
+ {
+ return 1-i;
+ }