C++ PATCH: Fix PR c++/16717

Mark Mitchell mark@codesourcery.com
Thu Aug 12 03:57:00 GMT 2004


When flag_unit_at_a_time got added for 3.4, various things went
squirrely.  This one got fixed on the mainline with my patch that
turned on flag_unit_at_a_time unconditionally in C++, but all that's
needed for 3.4.x is a backport of this little piece.

Tested on i686-pc-linux-gnu, applied on the branch.  I added the test
case to the mainline too.

--
Mark Mitchell
CodeSourcery, LLC
mark@codesourcery.com

2004-08-11  Mark Mitchell  <mark@codesourcery.com>

	PR c++/16717
	* semantics.c (expand_body): Do not update static_ctors and
	static_dtors here.
	(expand_or_defer_fn): Do it here, instead.

2004-08-11  Mark Mitchell  <mark@codesourcery.com>

	PR c++/16717
	* g++.dg/ext/construct1.C: New test.

Index: cp/semantics.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/semantics.c,v
retrieving revision 1.381.4.12
diff -c -5 -p -r1.381.4.12 semantics.c
*** cp/semantics.c	2 Aug 2004 01:56:29 -0000	1.381.4.12
--- cp/semantics.c	12 Aug 2004 02:01:27 -0000
*************** expand_body (tree fn)
*** 2923,2944 ****
  
    current_function_decl = saved_function;
  
    extract_interface_info ();
  
-   /* If this function is marked with the constructor attribute, add it
-      to the list of functions to be called along with constructors
-      from static duration objects.  */
-   if (DECL_STATIC_CONSTRUCTOR (fn))
-     static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
- 
-   /* If this function is marked with the destructor attribute, add it
-      to the list of functions to be called along with destructors from
-      static duration objects.  */
-   if (DECL_STATIC_DESTRUCTOR (fn))
-     static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
- 
    if (DECL_CLONED_FUNCTION_P (fn))
      {
        /* If this is a clone, go through the other clones now and mark
           their parameters used.  We have to do that here, as we don't
           know whether any particular clone will be expanded, and
--- 2923,2932 ----
*************** expand_or_defer_fn (tree fn)
*** 2997,3006 ****
--- 2985,3006 ----
  
    /* Compute the appropriate object-file linkage for inline functions.  */
    if (DECL_DECLARED_INLINE_P (fn))
      import_export_decl (fn);
  
+   /* If this function is marked with the constructor attribute, add it
+      to the list of functions to be called along with constructors
+      from static duration objects.  */
+   if (DECL_STATIC_CONSTRUCTOR (fn))
+     static_ctors = tree_cons (NULL_TREE, fn, static_ctors);
+ 
+   /* If this function is marked with the destructor attribute, add it
+      to the list of functions to be called along with destructors from
+      static duration objects.  */
+   if (DECL_STATIC_DESTRUCTOR (fn))
+     static_dtors = tree_cons (NULL_TREE, fn, static_dtors);
+ 
    function_depth++;
  
    /* Expand or defer, at the whim of the compilation unit manager.  */
    cgraph_finalize_function (fn, function_depth > 1);
  
Index: testsuite/g++.dg/ext/construct1.C
===================================================================
RCS file: testsuite/g++.dg/ext/construct1.C
diff -N testsuite/g++.dg/ext/construct1.C
*** /dev/null	1 Jan 1970 00:00:00 -0000
--- testsuite/g++.dg/ext/construct1.C	12 Aug 2004 02:01:28 -0000
***************
*** 0 ****
--- 1,12 ----
+ // PR c++/16717
+ // { dg-options "-O2" }
+ 
+ int i;
+ 
+ void hello (void) __attribute__ ((constructor));
+ void hello (void) { i = 1; }
+ 
+ int main (void) {
+   if (i != 1)
+     return 1;
+ }



More information about the Gcc-patches mailing list