Patch: Fix dllimport and template member functions, add test case

Danny Smith dannysmith@clear.net.nz
Tue Oct 18 21:24:00 GMT 2005


Hi,

The following code (reduced from PR 23589) used to ICE on mingw and
cygwin targets with:
"internal compiler error: in rest_of_handle_final, at toplev.c"

=========================================
struct __attribute__((dllimport)) Foo
{
  template <class T> Foo (T);
};

void a (int i)
{
  Foo f(i);
}

template <class T>  Foo::Foo (T) {}
=======================================


My recent dllimport patch should have fixed that. Instead it moved the
ICE to a

   gcc_assert (TREE_CODE (decl) == VAR_DECL 
               || TREE_CODE (decl) == FUNCTION_DECL);

statement in config/i386/winnt-cxx.c.

I forget to check that TYPE_METHODS of a class are also FUNCTION_DECLs.

The following patch to config/i386/winnt-cxx.c adds that check.  (I
think
that this falls within my authority to check in as target maintainer,
but
I'll ask to be sure  because of the current regression-fix-only policy
and
because I also want to ask...)

Is it also OK to add a testsuite case to test this use of dllimport?

Tested on i386-pc-mingw32.

Danny

ChangeLog  

        2005-10-18  Danny Smith  <dannysmith@users.sourceforge.net>
	* config/i386/winnt-cxx.c (i386_pe_adjust_class_at_definition):
	Check that elements of TYPE_METHODS are FUNCTION_DECLs.

ChangeLog/testsuite
	PR target/23589
	* g++.dg/ext/dllimport11.C: New file.


Index: config/i386/winnt-cxx.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/config/i386/winnt-cxx.c,v
retrieving revision 1.1
diff -c -3 -p -r1.1 winnt-cxx.c
*** config/i386/winnt-cxx.c	12 Oct 2005 20:54:49 -0000	1.1
--- config/i386/winnt-cxx.c	18 Oct 2005 19:42:42 -0000
*************** i386_pe_adjust_class_at_definition (tree
*** 152,158 ****
      
    /* Check FUNCTION_DECL's.  */
    for (member = TYPE_METHODS (t); member;  member = TREE_CHAIN
(member))
!     maybe_add_dllimport (member);
   
    /* Check vtables  */
    for (member = CLASSTYPE_VTABLES (t); member;  member = TREE_CHAIN
(member))
--- 152,159 ----
      
    /* Check FUNCTION_DECL's.  */
    for (member = TYPE_METHODS (t); member;  member = TREE_CHAIN
(member))
!     if (TREE_CODE (member) == FUNCTION_DECL)
!       maybe_add_dllimport (member);
   
    /* Check vtables  */
    for (member = CLASSTYPE_VTABLES (t); member;  member = TREE_CHAIN
(member))
*** /dev/null	Wed Oct 19 09:42:27 2005
--- testsuite/g++.dg/ext/dllimport11.C	Wed Oct 19 09:42:03 2005
***************
*** 0 ****
--- 1,15 ----
+ // PR target/23589
+ // Template member functions do not get dllimport status of class 
+ // { dg-do compile { target i?86-*-cygwin* i?86-*-mingw*} }
+ 
+ struct __attribute__((dllimport)) Foo
+ {
+   template <class T> Foo (T);
+ };
+ 
+ void a (int i)
+ {
+   Foo f(i);
+ }
+ 
+ template <class T>  Foo::Foo (T) {}   // no dllimport warnings on
definition.



More information about the Gcc-patches mailing list