From: Mark Mitchell Date: Fri, 28 Mar 2003 19:30:41 +0000 (+0000) Subject: decl2.c (generate_ctor_or_dtor_function): Tolerate a non-existant ssdf_decls array. X-Git-Tag: releases/gcc-3.4.0~7619 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=400fbc086860b08dfc220532a0f3b7aad382ce4c;p=thirdparty%2Fgcc.git decl2.c (generate_ctor_or_dtor_function): Tolerate a non-existant ssdf_decls array. * 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. * g++.dg/init/attrib1.C: New test. From-SVN: r64979 --- diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 888d4dcc5128..7a86f1d01b2d 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,11 @@ +2003-03-28 Mark Mitchell + + * 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-03-28 Nathan Sidwell PR c++/10047 diff --git a/gcc/cp/decl2.c b/gcc/cp/decl2.c index 77b9636a570b..88545d46281d 100644 --- a/gcc/cp/decl2.c +++ b/gcc/cp/decl2.c @@ -2494,15 +2494,16 @@ generate_ctor_or_dtor_function (bool constructor_p, int 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 (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 @@ -2510,7 +2511,7 @@ generate_ctor_or_dtor_function (bool constructor_p, int priority) if (priority == DEFAULT_INIT_PRIORITY) { tree fns; - + for (fns = constructor_p ? static_ctors : static_dtors; fns; fns = TREE_CHAIN (fns)) @@ -2838,6 +2839,15 @@ finish_file () 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) diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index 5818881ca764..66a35ad36905 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2003-03-28 Mark Mitchell + + * g++.dg/init/attrib1.C: New test. + 2003-03-28 Eric Botcazou * gcc.dg/ultrasp8.c: New test. diff --git a/gcc/testsuite/g++.dg/init/attrib1.C b/gcc/testsuite/g++.dg/init/attrib1.C new file mode 100644 index 000000000000..839e4ce215d6 --- /dev/null +++ b/gcc/testsuite/g++.dg/init/attrib1.C @@ -0,0 +1,10 @@ +// { dg-do run } + +void f() __attribute((__constructor__)); +int i; +void f() { i = 1; } + +int main(int, char **) +{ + return 1-i; +}