Bug 16717 - [3.4 Regression] [unit-at-a-time] __attribute__((constructor)) broken in C++
Summary: [3.4 Regression] [unit-at-a-time] __attribute__((constructor)) broken in C++
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 3.4.1
: P2 normal
Target Milestone: 3.4.2
Assignee: Mark Mitchell
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2004-07-26 16:32 UTC by Andris Pavenis
Modified: 2024-07-19 11:33 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work: 3.3.3, 4.0.0
Known to fail: 3.4.0
Last reconfirmed: 2004-07-27 02:37:13


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Andris Pavenis 2004-07-26 16:32:48 UTC
__attribute__((constructor)) doesn't work in C++ for both gcc-3.4.1 and
gcc-3.5.0 20040725 when optimization level -O2 is being used. 

All seems to work Ok with gcc-3.3.4.

-------------------- bug.cc ----------------------
#include <stdio.h>

void hello (void) __attribute__ ((constructor));

void hello (void) { printf ("Hello world\n"); }

int main (void) { return 0; }
---------------------------------------------------

g++ -O2 bug.cc -o bug
./bug

works with gcc-3.3.4, but not with gcc-3.4.1 and 3.5.0 20040725

(Initially bug were reported for target i586-pc-msdosdjgpp)
Comment 1 Mark Mitchell 2004-08-12 00:58:29 UTC
This works in GCC 3.5 now.
Comment 2 GCC Commits 2004-08-12 02:49:43 UTC
Subject: Bug 16717

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	mmitchel@gcc.gnu.org	2004-08-12 02:49:39

Modified files:
	gcc/cp         : ChangeLog semantics.c 
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/ext: construct1.C 

Log message:
	PR c++/16717
	* semantics.c (expand_body): Do not update static_ctors and
	static_dtors here.
	(expand_or_defer_fn): Do it here, instead.
	
	PR c++/16717
	* g++.dg/ext/construct1.C: New test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3892.2.142&r2=1.3892.2.143
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/semantics.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.381.4.12&r2=1.381.4.13
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.3389.2.245&r2=1.3389.2.246
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/construct1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1

Comment 3 GCC Commits 2004-08-12 02:51:33 UTC
Subject: Bug 16717

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	mmitchel@gcc.gnu.org	2004-08-12 02:51:31

Modified files:
	gcc/testsuite  : ChangeLog 
Added files:
	gcc/testsuite/g++.dg/ext: construct1.C 

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

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.diff?cvsroot=gcc&r1=1.4120&r2=1.4121
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/ext/construct1.C.diff?cvsroot=gcc&r1=1.1&r2=1.2

Comment 4 Mark Mitchell 2004-08-12 02:53:40 UTC
Fixed in GCC 3.4.2.