winnt-cxx.c (i386_pe_type_dllimport_p): Don't ignore dllimport attribute of virtual...
authorDanny Smith <dannysmith@users.sourceforge.net>
Wed, 4 Apr 2007 08:00:56 +0000 (08:00 +0000)
committerDanny Smith <dannysmith@gcc.gnu.org>
Wed, 4 Apr 2007 08:00:56 +0000 (08:00 +0000)
gcc
* config/i386/winnt-cxx.c (i386_pe_type_dllimport_p): Don't ignore
dllimport attribute of virtual methods.

gcc/cp
* class.c (check_for_override): Don't remove dllmport attribute of
virtual methods.

gcc/testsuite

* g++.dg/ext/dllimport12.C: Update comments

From-SVN: r123492

gcc/ChangeLog
gcc/config/i386/winnt-cxx.c
gcc/cp/ChangeLog
gcc/cp/class.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/ext/dllimport12.C

index 00d1e9e96a90beb213f5e3a018233cd5bf4d4d4c..e8786498354779eb521830e0f701409182a8285f 100644 (file)
@@ -1,3 +1,8 @@
+2007-04-04  Danny Smith  <dannysmith.users.sourceforge.net>
+
+       * config/i386/winnt-cxx.c (i386_pe_type_dllimport_p): Don't ignore
+       dllimport attribute of virtual methods.
+
 2007-04-04  Chen Liqin  <liqin@sunnorth.com.cn>
 
         * config/score/crti.asm: Change _bss_start to __bss_start.
index 6123ebbcdc39ced513f2d624b9329b826c4624d9..a6a8510720bb5a7f517ce0f756d36e5a2e95b079 100644 (file)
@@ -38,66 +38,43 @@ Boston, MA 02110-1301, USA.  */
 bool
 i386_pe_type_dllimport_p (tree decl)
 {
-   gcc_assert (TREE_CODE (decl) == VAR_DECL 
-               || TREE_CODE (decl) == FUNCTION_DECL);
-
-   if (TARGET_NOP_FUN_DLLIMPORT && TREE_CODE (decl) == FUNCTION_DECL)
-     return false;
-
-   /* We ignore the dllimport attribute for inline member functions.
-      This differs from MSVC behavior which treats it like GNUC
-      'extern inline' extension.  Also ignore for template
-      instantiations with linkonce semantics and artificial methods.  */
-    if (TREE_CODE (decl) ==  FUNCTION_DECL
-        && (DECL_DECLARED_INLINE_P (decl)
-           || DECL_TEMPLATE_INSTANTIATION (decl)
-           || DECL_ARTIFICIAL (decl)))
-      return false;
-
-   /* Since we can't treat a pointer to a dllimport'd symbol as a
-       constant address, we turn off the attribute on C++ virtual
-       methods to allow creation of vtables using thunks.  */
-    else if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
-            && DECL_VIRTUAL_P (decl))
-      {
-       /* Even though we ignore the attribute from the start, warn if we later see
-          an out-of class definition, as we do for other member functions in
-          tree.c:merge_dllimport_decl_attributes.  If this is the key method, the
-          definition may affect the import-export status of vtables, depending
-           on how we handle MULTIPLE_SYMBOL_SPACES in cp/decl2.c.   */
-       if (DECL_INITIAL (decl))
-         {
-           warning (OPT_Wattributes, "%q+D redeclared without dllimport attribute: "
-                   "previous dllimport ignored", decl);
-#ifdef PE_DLL_DEBUG
-           if (decl == CLASSTYPE_KEY_METHOD (DECL_CONTEXT (decl)))            
-             warning (OPT_Wattributes, "key method %q+D of dllimport'd class defined"
-                      decl);
-#endif
-         }
-       return false;
-      }
-
-      /* Don't mark defined functions as dllimport.  This code will only be
-         reached if we see a non-inline function defined out-of-class.  */
-    else if (TREE_CODE (decl) ==  FUNCTION_DECL
-            && (DECL_INITIAL (decl)))
+  gcc_assert (TREE_CODE (decl) == VAR_DECL 
+             || TREE_CODE (decl) == FUNCTION_DECL);
+
+  if (TARGET_NOP_FUN_DLLIMPORT && TREE_CODE (decl) == FUNCTION_DECL)
+    return false;
+
+  /* We ignore the dllimport attribute for inline member functions.
+     This differs from MSVC behavior which treats it like GNUC
+     'extern inline' extension.  Also ignore for template
+     instantiations with linkonce semantics and artificial methods.  */
+  if (TREE_CODE (decl) ==  FUNCTION_DECL
+      && (DECL_DECLARED_INLINE_P (decl)
+         || DECL_TEMPLATE_INSTANTIATION (decl)
+         || DECL_ARTIFICIAL (decl)))
+    return false;
+
+
+  /* Don't mark defined functions as dllimport.  This code will only be
+     reached if we see a non-inline function defined out-of-class.  */
+  else if (TREE_CODE (decl) ==  FUNCTION_DECL
+          && (DECL_INITIAL (decl)))
+    return false;
+
+  /*  Don't allow definitions of static data members in dllimport class,
+      If vtable data is marked as DECL_EXTERNAL, import it; otherwise just
+      ignore the class attribute.  */
+  else if (TREE_CODE (decl) == VAR_DECL
+          && TREE_STATIC (decl) && TREE_PUBLIC (decl)
+          && !DECL_EXTERNAL (decl))
+    {
+      if (!DECL_VIRTUAL_P (decl))
+         error ("definition of static data member %q+D of "
+                "dllimport'd class", decl);
       return false;
+    }
 
-    /*  Don't allow definitions of static data members in dllimport class,
-        If vtable data is marked as DECL_EXTERNAL, import it; otherwise just
-        ignore the class attribute.  */
-    else if (TREE_CODE (decl) == VAR_DECL
-            && TREE_STATIC (decl) && TREE_PUBLIC (decl)
-            && !DECL_EXTERNAL (decl))
-      {
-       if (!DECL_VIRTUAL_P (decl))
-            error ("definition of static data member %q+D of "
-                   "dllimport'd class", decl);
-       return false;
-      }
-
-    return true;
+  return true;
 }
 
 
@@ -143,7 +120,7 @@ i386_pe_adjust_class_at_definition (tree t)
      definition.  We recheck the class members  at RTL generation to
      emit warnings if this has happened.  Definition of static data member
      of dllimport'd class always causes an error (as per MS compiler).
-     */
+  */
 
   /* Check static VAR_DECL's.  */
   for (member = TYPE_FIELDS (t); member; member = TREE_CHAIN (member))
index 192d7e8adfbb9b2f2405a8ab476b3eba4095619b..f5b7aceca61e2e2b37c1bf3a945184f16cb5a08e 100644 (file)
@@ -1,3 +1,10 @@
+2007-04-04  Danny Smith  <dannysmith.users.sourceforge.net>
+
+       * class.c (check_for_override): Don't remove dllmport attribute
+       of virtual methods.
+
+
+
 2007-04-03  Jakub Jelinek  <jakub@redhat.com>
 
        PR c++/30847
index 5e5bcbf895c40eb9aaf4215a7f78b13c50a9d2d2..0bb441e32698066119eb5781901bcadee68cf6d7 100644 (file)
@@ -2343,16 +2343,6 @@ check_for_override (tree decl, tree ctype)
       if (!DECL_VINDEX (decl))
        DECL_VINDEX (decl) = error_mark_node;
       IDENTIFIER_VIRTUAL_P (DECL_NAME (decl)) = 1;
-      if (DECL_DLLIMPORT_P (decl))
-       {
-         /* When we handled the dllimport attribute we may not have known
-            that this function is virtual   We can't use dllimport
-            semantics for a virtual method because we need to initialize
-            the vtable entry with a constant address.  */
-         DECL_DLLIMPORT_P (decl) = 0;
-         DECL_ATTRIBUTES (decl)
-           = remove_attribute ("dllimport", DECL_ATTRIBUTES (decl));
-       }
     }
 }
 
index 5e61ac13331944ea7c796ec0146bd48d60f649b2..4a5ce3b4ce84f0557c8d98e7181b52bf1132c817 100644 (file)
@@ -1,3 +1,7 @@
+2007-04-04  Danny Smith  <dannysmith.users.sourceforge.net>
+
+       * g++.dg/ext/dllimport12.C: Update comments.
+
 2007-04-03  Eric Christopher  <echristo@apple.com>
 
        * g++.dg/tree-ssa/pr29902.C: Require ilp32.
index fe480f21c3a1d521a16f17ae25a0724bd2bb9858..9868596a899bc833c0e9ad9fbd870013cc38cc0f 100755 (executable)
@@ -1,8 +1,9 @@
 // PR target/27650
-// Don't use dllimport semantics on virtual methods
+// Don't use dllimport semantics on virtual methods when initializing
+// vtables
 // { dg-do compile { target i?86-*-cygwin* i?86-*-mingw*} }
 
-// Don't import explicitly virtual method.
+// Use import lib thunk for vtable entry of explicitly virtual method,
 struct base
 {
   virtual void key_method();
@@ -12,7 +13,7 @@ struct base
 void base::key_method() {}
 
 
-// Nor an implicitly virtual method.
+// Likewise for an implicitly virtual method.
 struct derived : public base
 {
   void key_method();