This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Patch to fix support of C++ dllimports



This patch allows the use of the static C++ class variables imported from
a DLL. Without it, you need to add explicit hacks/workarounds. Now you can
write:
  
  struct __attribute__((dllimport)) foo {
    static int static_var;
  }

  int blah = foo::static_var;

Also has the good and expected side effect that all methods etc are marked
dllimport right away without having to use dlltool thunks.

The fact that foo::static_var is imported from a DLL needs to be caught 
before finish_class_definition is called, and that means that the type 
attributes aren't accessible via TYPE_ATTRIBUTES yet, but rather still 
left in TREE_TYPE (enclosing_type);

Jason, any side effect of peeking into TREE_TYPE(enclosing_type)?

Currently, you have to do the following for it to work:

  struct __attribute__((dllimport)) foo {
    __attribute__((dllimport) static int static_var;	// EXPLICIT
  }

Regards,
Mumit

Wed Aug 12 18:18:16 1998  Mumit Khan  <khan@xraylith.wisc.edu>

	* i386/winnt.c (i386_pe_dllexport_p): Check TREE_TYPE for
	attributes as well for C++ class members.
	(i386_pe_dllimport_p): Likewise.

Index: config/i386/winnt.c
===================================================================
RCS file: /egcs/carton/cvsfiles/egcs/gcc/config/i386/winnt.c,v
retrieving revision 1.5.2.1
diff -u -3 -p -r1.5.2.1 winnt.c
--- config/i386/winnt.c	1998/07/28 22:31:10	1.5.2.1
+++ config/i386/winnt.c	1998/08/12 23:18:16
@@ -169,6 +169,7 @@ i386_pe_dllexport_p (decl)
      tree decl;
 {
   tree exp;
+  tree context;
 
   if (TREE_CODE (decl) != VAR_DECL
       && TREE_CODE (decl) != FUNCTION_DECL)
@@ -178,12 +179,18 @@ i386_pe_dllexport_p (decl)
     return 1;
 
   /* Class members get the dllexport status of their class.  */
-  if (associated_type (decl))
+  context = associated_type (decl);
+  if (context)
     {
       exp = lookup_attribute ("dllexport",
-			      TYPE_ATTRIBUTES (associated_type (decl)));
+			      TYPE_ATTRIBUTES (context));
       if (exp)
 	return 1;
+
+      exp = lookup_attribute ("dllexport",
+			      TREE_TYPE (context));
+      if (exp)
+	return 1;
     }
 
   return 0;
@@ -196,6 +203,7 @@ i386_pe_dllimport_p (decl)
      tree decl;
 {
   tree imp;
+  tree context;
 
   if (TREE_CODE (decl) == FUNCTION_DECL
       && TARGET_NOP_FUN_DLLIMPORT)
@@ -209,10 +217,16 @@ i386_pe_dllimport_p (decl)
     return 1;
 
   /* Class members get the dllimport status of their class.  */
-  if (associated_type (decl))
+  context = associated_type (decl);
+  if (context)
     {
+      imp = lookup_attribute ("dllimport",
+			      TYPE_ATTRIBUTES (context));
+      if (imp)
+	return 1;
+
       imp = lookup_attribute ("dllimport",
-			      TYPE_ATTRIBUTES (associated_type (decl)));
+			      TREE_TYPE (context));
       if (imp)
 	return 1;
     }


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]