This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH for dllimport PR's 9738 and 10148 [Was Re: encode_section_info vs tentative definitions]
- From: Danny Smith <danny_r_smith_2001 at yahoo dot co dot nz>
- To: GCC Patches <gcc-patches at gcc dot gnu dot org>
- Cc: rth at redhat dot com, Christopher Faylor <cgf at redhat dot com>
- Date: Mon, 19 May 2003 07:42:29 +1000 (EST)
- Subject: PATCH for dllimport PR's 9738 and 10148 [Was Re: encode_section_info vs tentative definitions]
Richard Henderson <rth at redhat dot com> wrote:
> On Fri, May 16, 2003 at 01:03:55PM +1000, Danny Smith wrote:
> > But if there is an obvious reason for
> > not putting in cp/decl.c, please advise.
>
> Since C++ doesn't have tentative defintions, I didn't think
> it was needed. If you have a test case for which this does
> matter (and a patch!) feel free to post it.
>
>
> r~
PR 9738 and PR 10148 are two such cases. The tentative dllimport
attribute needs to be overriden by later definition, else we get an ICE.
This has not caused problems in C, but does in C++
I have included these testcases as new testsuite files in patch.
This patch also facilitates fixes in winnt.c for two other dllimport
attribute ICE's, PR 8378 and PR 7910. I will submit that in separate post.
The following has been tested on i386-pc-mingw with no new regressions.
ChangeLog
2003-05-19 Danny Smith <daanysmith@users.sourcecode.net>
* config/i386/winnt.c (i386_pe_encode_section_info): Enable
even if not first.
testsuite/ChangeLog
2003-05-19 Danny Smith <daanysmith@users.sourcecode.net>
* g++.dg/ext/dllimport2.C: New file.
* g++.dg/ext/dllimport3.C: New file.
cp/ChangeLog
2003-05-19 Danny Smith <daanysmith@users.sourcecode.net>
* decl.c (duplicate_decls): For targets with dllimport,
re-invoke make_decl_rtl if the old decl had instantiated
DECL_RTL (Base on Richard Henderson patch to c-decl.c).
Index: gcc/cp/decl.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cp/decl.c,v
retrieving revision 1.1054
diff -c -3 -p -r1.1054 decl.c
*** gcc/cp/decl.c 10 May 2003 11:29:51 -0000 1.1054
--- gcc/cp/decl.c 18 May 2003 21:27:03 -0000
*************** duplicate_decls (tree newdecl, tree oldd
*** 3587,3592 ****
--- 3587,3603 ----
Update OLDDECL to be the same. */
DECL_ATTRIBUTES (olddecl) = DECL_ATTRIBUTES (newdecl);
+ #ifdef TARGET_DLLIMPORT_DECL_ATTRIBUTES
+ /* If OLDDECL had its DECL_RTL instantiated, re-invoke make_decl_rtl
+ so that encode_section_info has a chance to look at the new decl
+ flags and attributes. */
+ if (DECL_RTL_SET_P (olddecl)
+ && (TREE_CODE (olddecl) == FUNCTION_DECL
+ || (TREE_CODE (olddecl) == VAR_DECL
+ && TREE_STATIC (olddecl))))
+ make_decl_rtl (olddecl, NULL);
+ #endif
+
return 1;
}
Index: gcc/config/i386/winnt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/winnt.c,v
retrieving revision 1.46
diff -c -3 -p -r1.46 winnt.c
*** gcc/config/i386/winnt.c 21 Apr 2003 23:23:39 -0000 1.46
--- gcc/config/i386/winnt.c 18 May 2003 21:27:03 -0000
*************** i386_pe_encode_section_info (decl, rtl,
*** 427,435 ****
rtx rtl;
int first;
{
- if (!first)
- return;
-
default_encode_section_info (decl, rtl, first);
if (TREE_CODE (decl) == FUNCTION_DECL)
--- 427,432 ----
*************** i386_pe_encode_section_info (decl, rtl,
*** 445,451 ****
}
/* Mark the decl so we can tell from the rtl whether the object is
! dllexport'd or dllimport'd. */
if (i386_pe_dllexport_p (decl))
i386_pe_mark_dllexport (decl);
--- 442,449 ----
}
/* Mark the decl so we can tell from the rtl whether the object is
! dllexport'd or dllimport'd. This also handles dllexport/dllimport
! override semantics. */
if (i386_pe_dllexport_p (decl))
i386_pe_mark_dllexport (decl);
*** /dev/null Sun May 18 21:59:17 2003
--- gcc/testsuite/g++.dg/ext/dllimport2.C Sun May 18 05:06:24 2003
***************
*** 0 ****
--- 1,15 ----
+ // { dg-do compile { target i?86-*-cygwin* i?86-*-mingw*} }
+
+ // PR 9738 Dllimport attribute is overriden by later definition
+
+ void __attribute__((dllimport)) Bar(void);
+
+ void Foo(void)
+ {
+ Bar();
+ }
+
+ void Bar(void)
+ {
+ }
+
*** /dev/null Sun May 18 21:59:18 2003
--- gcc/testsuite/g++.dg/ext/dllimport3.C Sun May 18 05:02:55 2003
***************
*** 0 ****
--- 1,25 ----
+ // { dg-do compile { target i?86-*-cygwin* i?86-*-mingw*} }
+
+ // PR 10148 Dllimport attribute of object is overriden by later
+ // redefinition without attribute.
+
+ struct Foo
+ {
+ int a;
+ };
+
+ __attribute__((dllimport)) struct Foo f;
+
+ void Bar(void)
+ {
+ void* dummy = &f;
+ }
+
+ struct Foo f;
+
+ // Dllimport sets DECL_NON_ADDR_CONST_P to 1, so following
+ // assignment would require static_initialization_and_destruction
+ // if attribute is retained.
+
+ void* dummy = &f;
+
http://mobile.yahoo.com.au - Yahoo! Mobile
- Check & compose your email via SMS on your Telstra or Vodafone mobile.