[llvm-commits] [124163] Backport mingw32 support from FSF GCC mainline.

dpatel at apple.com dpatel at apple.com
Mon Feb 26 13:07:35 PST 2007


Revision: 124163
Author:   dpatel
Date:     2007-02-21 12:19:03 -0800 (Wed, 21 Feb 2007)

Log Message:
-----------
Backport mingw32 support from FSF GCC mainline.
This patch is prepared by Anton Korobeynikov.

Modified Paths:
--------------
    apple-local/branches/llvm/gcc/config/i386/cygming.h
    apple-local/branches/llvm/gcc/config/i386/i386-protos.h
    apple-local/branches/llvm/gcc/config/i386/i386.c
    apple-local/branches/llvm/gcc/config/i386/t-cygming
    apple-local/branches/llvm/gcc/config/i386/t-mingw32
    apple-local/branches/llvm/gcc/config/i386/winnt.c
    apple-local/branches/llvm/gcc/config.gcc
    apple-local/branches/llvm/gcc/cp/decl.c
    apple-local/branches/llvm/gcc/doc/extend.texi
    apple-local/branches/llvm/gcc/doc/fragments.texi
    apple-local/branches/llvm/gcc/doc/tm.texi
    apple-local/branches/llvm/gcc/target-def.h
    apple-local/branches/llvm/gcc/target.h
    apple-local/branches/llvm/gcc/tree.c
    apple-local/branches/llvm/gcc/tree.h
    apple-local/branches/llvm/gcc/varasm.c

Modified: apple-local/branches/llvm/gcc/config/i386/cygming.h
===================================================================
--- apple-local/branches/llvm/gcc/config/i386/cygming.h	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/config/i386/cygming.h	2007-02-21 20:19:03 UTC (rev 124163)
@@ -207,8 +207,10 @@
    section and we need to set DECL_SECTION_NAME so we do that here.
    Note that we can be called twice on the same decl.  */
 
-#undef TARGET_ENCODE_SECTION_INFO
-#define TARGET_ENCODE_SECTION_INFO  i386_pe_encode_section_info
+ /* APPLE LOCAL begin mainline 2005-07-31 */
+#undef SUBTARGET_ENCODE_SECTION_INFO
+#define SUBTARGET_ENCODE_SECTION_INFO  i386_pe_encode_section_info
+ /* APPLE LOCAL end mainline 2005-07-31 */
 #undef  TARGET_STRIP_NAME_ENCODING
 #define TARGET_STRIP_NAME_ENCODING  i386_pe_strip_name_encoding_full
 
@@ -216,6 +218,11 @@
 #undef ASM_OUTPUT_LABELREF
 #define ASM_OUTPUT_LABELREF  i386_pe_output_labelref
 
+ /* APPLE LOCAL begin mainline 2005-07-31 */
+#undef  COMMON_ASM_OP
+#define COMMON_ASM_OP	"\t.comm\t"
+ /* APPLE LOCAL end mainline 2005-07-31 */
+
 /* Output a common block.  */
 #undef ASM_OUTPUT_COMMON
 #define ASM_OUTPUT_COMMON(STREAM, NAME, SIZE, ROUNDED)	\
@@ -422,6 +429,23 @@
 #undef TARGET_USE_LOCAL_THUNK_ALIAS_P
 #define TARGET_USE_LOCAL_THUNK_ALIAS_P(DECL) (!DECL_ONE_ONLY (DECL))
 
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+#define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P i386_pe_valid_dllimport_attribute_p
+#define TARGET_CXX_ADJUST_CLASS_AT_DEFINITION i386_pe_adjust_class_at_definition
+ /* APPLE LOCAL end mainline 2005-10-12 */
+
+ /* APPLE LOCAL begin mainline 2005-06-01 */
+/*  mcount() does not need a counter variable.  */
+#undef NO_PROFILE_COUNTERS
+#define NO_PROFILE_COUNTERS 1
+ /* APPLE LOCAL end mainline 2005-06-01 */
+
+ /* APPLE LOCAL begin mainline 2005-04-01 */
+#define SUBTARGET_ATTRIBUTE_TABLE \
+  /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler } */ \
+  { "selectany", 0, 0, true, false, false, ix86_handle_selectany_attribute }
+ /* APPLE LOCAL end mainline 2005-04-01 */
+
 #undef TREE
 
 #ifndef BUFSIZ

Modified: apple-local/branches/llvm/gcc/config/i386/i386-protos.h
===================================================================
--- apple-local/branches/llvm/gcc/config/i386/i386-protos.h	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/config/i386/i386-protos.h	2007-02-21 20:19:03 UTC (rev 124163)
@@ -237,6 +237,9 @@
 extern int ix86_local_alignment (tree, int);
 extern int ix86_constant_alignment (tree, int);
 extern tree ix86_handle_shared_attribute (tree *, tree, tree, int, bool *);
+/* APPLE LOCAL begin mainline 2005-04-01 */
+extern tree ix86_handle_selectany_attribute (tree *, tree, tree, int, bool *); 
+/* APPLE LOCAL end mainline 2005-04-01 */
 
 extern unsigned int i386_pe_section_type_flags (tree, const char *, int);
 extern void i386_pe_asm_named_section (const char *, unsigned int, tree);
@@ -261,6 +264,15 @@
 extern const char *i386_pe_strip_name_encoding (const char *);
 extern const char *i386_pe_strip_name_encoding_full (const char *);
 extern void i386_pe_output_labelref (FILE *, const char *);
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+extern int i386_pe_valid_dllimport_attribute_p (tree);
+
+/* In winnt-cxx.c and winnt-stubs.c  */
+extern void i386_pe_adjust_class_at_definition (tree);
+extern bool i386_pe_type_dllimport_p (tree);
+extern bool i386_pe_type_dllexport_p (tree);
+
+ /* APPLE LOCAL end mainline 2005-10-12 */
 extern rtx maybe_get_pool_constant (rtx);
 
 extern char internal_label_prefix[16];

Modified: apple-local/branches/llvm/gcc/config/i386/i386.c
===================================================================
--- apple-local/branches/llvm/gcc/config/i386/i386.c	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/config/i386/i386.c	2007-02-21 20:19:03 UTC (rev 124163)
@@ -1354,6 +1354,13 @@
 #undef TARGET_ASM_FUNCTION_EPILOGUE
 #define TARGET_ASM_FUNCTION_EPILOGUE ix86_output_function_epilogue
 
+ /* APPLE LOCAL begin mainline 2005-07-31 */
+#ifdef SUBTARGET_ENCODE_SECTION_INFO
+#undef TARGET_ENCODE_SECTION_INFO
+#define TARGET_ENCODE_SECTION_INFO SUBTARGET_ENCODE_SECTION_INFO
+#endif
+
+ /* APPLE LOCAL end mainline 2005-07-31 */
 #undef TARGET_ASM_OPEN_PAREN
 #define TARGET_ASM_OPEN_PAREN ""
 #undef TARGET_ASM_CLOSE_PAREN
@@ -2323,7 +2330,9 @@
 
 #if TARGET_DLLIMPORT_DECL_ATTRIBUTES
   /* Dllimport'd functions are also called indirectly.  */
-  if (decl && lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl))
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  if (decl && DECL_DLLIMPORT_P (decl)
+ /* APPLE LOCAL end mainline 2005-10-12 */
       && ix86_function_regparm (TREE_TYPE (decl), NULL) >= 3)
     return false;
 #endif

Modified: apple-local/branches/llvm/gcc/config/i386/t-cygming
===================================================================
--- apple-local/branches/llvm/gcc/config/i386/t-cygming	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/config/i386/t-cygming	2007-02-21 20:19:03 UTC (rev 124163)
@@ -16,4 +16,19 @@
 	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
 	$(srcdir)/config/i386/winnt.c
 
+ # APPLE LOCAL begin mainline 2005-10-12
+winnt-cxx.o: $(srcdir)/config/i386/winnt-cxx.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
+  $(TM_H) $(RTL_H) $(REGS_H) hard-reg-set.h output.h $(TREE_H) flags.h \
+  $(TM_P_H) toplev.h $(HASHTAB_H) $(GGC_H)
+	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+	$(srcdir)/config/i386/winnt-cxx.c
+
+
+winnt-stubs.o: $(srcdir)/config/i386/winnt-stubs.c $(CONFIG_H) $(SYSTEM_H) coretypes.h \
+  $(TM_H) $(RTL_H) $(REGS_H) hard-reg-set.h output.h $(TREE_H) flags.h \
+  $(TM_P_H) toplev.h $(HASHTAB_H) $(GGC_H)
+	$(CC) -c $(ALL_CFLAGS) $(ALL_CPPFLAGS) $(INCLUDES) \
+	$(srcdir)/config/i386/winnt-stubs.c
+ # APPLE LOCAL end mainline 2005-10-12
+
 STMP_FIXINC=stmp-fixinc

Modified: apple-local/branches/llvm/gcc/config/i386/t-mingw32
===================================================================
--- apple-local/branches/llvm/gcc/config/i386/t-mingw32	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/config/i386/t-mingw32	2007-02-21 20:19:03 UTC (rev 124163)
@@ -1,2 +1,7 @@
 # We hide calls to w32api needed for w32 thread support here:
 LIB2FUNCS_EXTRA = $(srcdir)/config/i386/gthr-win32.c
+
+ # APPLE LOCAL begin mainline 2005-08-02
+# Match SYSTEM_INCLUDE_DIR
+NATIVE_SYSTEM_HEADER_DIR = /mingw/include
+ # APPLE LOCAL end mainline 2005-08-02

Modified: apple-local/branches/llvm/gcc/config/i386/winnt.c
===================================================================
--- apple-local/branches/llvm/gcc/config/i386/winnt.c	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/config/i386/winnt.c	2007-02-21 20:19:03 UTC (rev 124163)
@@ -1,7 +1,7 @@
 /* Subroutines for insn-output.c for Windows NT.
    Contributed by Douglas Rupp (drupp at cs.washington.edu)
    Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004
-   Free Software Foundation, Inc.
+   2005, 2006  Free Software Foundation, Inc.
 
 This file is part of GCC.
 
@@ -76,6 +76,31 @@
 
   return NULL_TREE;
 }
+ /* APPLE LOCAL begin mainline 2005-04-01 */
+
+/* Handle a "selectany" attribute;
+   arguments as in struct attribute_spec.handler.  */
+tree
+ix86_handle_selectany_attribute (tree *node, tree name,
+			         tree args ATTRIBUTE_UNUSED,
+			         int flags ATTRIBUTE_UNUSED,
+				 bool *no_add_attrs)
+{
+  /* The attribute applies only to objects that are initialized and have
+     external linkage.  However, we may not know about initialization
+     until the language frontend has processed the decl. We'll check for
+     initialization later in encode_section_info.  */	
+  if (TREE_CODE (*node) != VAR_DECL || !TREE_PUBLIC (*node))
+    {	
+      error ("%qs attribute applies only to initialized variables"
+       	     " with external linkage",  IDENTIFIER_POINTER (name));
+      *no_add_attrs = true;
+    }
+
+  return NULL_TREE;
+}
+
+ /* APPLE LOCAL end mainline 2005-04-01 */
 
 /* Return the type that we should use to determine if DECL is
    imported or exported.  */
@@ -83,133 +108,85 @@
 static tree
 associated_type (tree decl)
 {
-  tree t = NULL_TREE;
-
-  /* In the C++ frontend, DECL_CONTEXT for a method doesn't actually refer
-     to the containing class.  So we look at the 'this' arg.  */
-  if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE)
-    {
-      /* Artificial methods are not affected by the import/export status
-	 of their class unless they are COMDAT.  Implicit copy ctor's and
-	 dtor's are not affected by class status but virtual and
-	 non-virtual thunks are.  */
-      if (!DECL_ARTIFICIAL (decl) || DECL_COMDAT (decl))
-	t = TYPE_MAIN_VARIANT
-	  (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)))));
-    }
-  else if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
-    t = DECL_CONTEXT (decl);
-
-  return t;
+  /* APPLE LOCAL begin mainline 2005-10-12 */
+  return  (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
+            ?  DECL_CONTEXT (decl) : NULL_TREE;
+  /* APPLE LOCAL end mainline 2005-10-12 */
 }
 
-/* Return nonzero if DECL is a dllexport'd object.  */
+/* Return true if DECL is a dllexport'd object.  */
 
 int
 i386_pe_dllexport_p (tree decl)
 {
-  tree exp;
-
   if (TREE_CODE (decl) != VAR_DECL
       && TREE_CODE (decl) != FUNCTION_DECL)
     return 0;
-  exp = lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl));
-  if (exp)
+
+  /* APPLE LOCAL begin mainline 2005-10-12 */
+  if (lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))
     return 1;
 
-  /* Class members get the dllexport status of their class.  */
-  if (associated_type (decl))
-    {
-      exp = lookup_attribute ("dllexport",
-			      TYPE_ATTRIBUTES (associated_type (decl)));
-      if (exp)
-	return 1;
-    }
-
+  /* Also mark class members of exported classes with dllexport.  */
+  if (associated_type (decl)
+      && lookup_attribute ("dllexport",
+                           TYPE_ATTRIBUTES (associated_type (decl))))
+    return i386_pe_type_dllexport_p (decl);
+  /* APPLE LOCAL end mainline 2005-10-12 */
+  
   return 0;
 }
 
-/* Return nonzero if DECL is a dllimport'd object.  */
+/* Return true if DECL is a dllimport'd object.  */
 
 int
 i386_pe_dllimport_p (tree decl)
 {
-  tree imp;
-  int context_imp = 0;
-
-  if (TREE_CODE (decl) == FUNCTION_DECL
-      && TARGET_NOP_FUN_DLLIMPORT)
-    return 0;
-
   if (TREE_CODE (decl) != VAR_DECL
       && TREE_CODE (decl) != FUNCTION_DECL)
     return 0;
 
-  imp = lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl));
-
-  /* Class members get the dllimport status of their class.  */
-  if (!imp && associated_type (decl))
+  /* APPLE LOCAL begin mainline 2005-10-12 */
+  /* Lookup the attribute in addition to checking the DECL_DLLIMPORT_P flag.
+     We may need to override an earlier decision.  */
+  if (DECL_DLLIMPORT_P (decl)
+      && lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl)))
     {
-      imp = lookup_attribute ("dllimport",
-			      TYPE_ATTRIBUTES (associated_type (decl)));
-      if (imp)
-	context_imp = 1;
-    }
-
-  if (imp)
-    {
-      /* Don't mark defined functions as dllimport.  If the definition
-	 itself was marked with dllimport, than ix86_handle_dll_attribute
-	 reports an error. This handles the case when the definition
-	 overrides an earlier declaration.  */
-      if (TREE_CODE (decl) ==  FUNCTION_DECL && DECL_INITIAL (decl)
-	  && !DECL_INLINE (decl))
-	{
-	   /* Don't warn about artificial methods.  */
-	  if (!DECL_ARTIFICIAL (decl))
-	    warning ("%Jfunction '%D' is defined after prior declaration "
-		     "as dllimport: attribute ignored", decl, decl);
-	  return 0;
-	}
-
-      /* We ignore the dllimport attribute for inline member functions.
-	 This differs from MSVC behavior which treats it like GNUC
-	 'extern inline' extension.  */
-      else if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INLINE (decl))
+      /* Make a final check to see if this is a definition before we generate
+         RTL for an indirect reference.  */   
+      if (!DECL_EXTERNAL (decl))
         {
-	  if (extra_warnings)
-	    warning ("%Jinline function '%D' is declared as dllimport: "
-		     "attribute ignored.", decl, decl);
-	  return 0;
-	}
-
-      /*  Don't allow definitions of static data members in dllimport class,
-	  Just ignore attribute for vtable data.  */
-      else if (TREE_CODE (decl) == VAR_DECL
-	       && TREE_STATIC (decl) && TREE_PUBLIC (decl)
-	       && !DECL_EXTERNAL (decl) && context_imp)
-	{
-	  if (!DECL_VIRTUAL_P (decl))
-            error ("%Jdefinition of static data member '%D' of "
-		   "dllimport'd class.", decl, decl);
-	  return 0;
-	}
-
-      /* 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.  Don't mark
-	 artificial methods either (in associated_type, only COMDAT
-	 artificial method get import status from class context).  */
-      else if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
-	       && (DECL_VIRTUAL_P (decl) || DECL_ARTIFICIAL (decl)))
-	return 0;
-
+          error ("%qD: definition is marked as dllimport", decl);
+          DECL_DLLIMPORT_P (decl) = 0;
+          return 0;
+        }
       return 1;
     }
 
+  /* The DECL_DLLIMPORT_P flag was set for decls in the class definition
+     by  targetm.cxx.adjust_class_at_definition.  Check again to emit
+     warnings if the class attribute has been overriden by an
+     out-of-class definition.  */
+  else if (associated_type (decl)
+           && lookup_attribute ("dllimport",
+                                TYPE_ATTRIBUTES (associated_type (decl))))
+    return i386_pe_type_dllimport_p (decl);
+  /* APPLE LOCAL end mainline 2005-10-12 */
+  
   return 0;
 }
 
+/* APPLE LOCAL begin mainline 2005-10-12 */
+/* Handle the -mno-fun-dllimport target switch.  */
+int
+i386_pe_valid_dllimport_attribute_p (tree decl)
+{
+   if (TARGET_NOP_FUN_DLLIMPORT && TREE_CODE (decl) == FUNCTION_DECL)
+     return 0;
+   return 1;
+}
+/* APPLE LOCAL end mainline 2005-10-12 */
+
 /* Return nonzero if SYMBOL is marked as being dllexport'd.  */
 
 int
@@ -251,10 +228,9 @@
   if (i386_pe_dllimport_name_p (oldname))
     {
       warning ("%Jinconsistent dll linkage for '%D', dllexport assumed.",
-	       decl, decl);
+        decl, decl);
      /* Remove DLL_IMPORT_PREFIX.  */
       oldname += strlen (DLL_IMPORT_PREFIX);
-      DECL_NON_ADDR_CONST_P (decl) = 0;
     }
   else if (i386_pe_dllexport_name_p (oldname))
     return;  /*  already done  */
@@ -301,12 +277,15 @@
   else if (i386_pe_dllimport_name_p (oldname))
     {
       /* Already done, but do a sanity check to prevent assembler errors.  */
-      if (!DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl))
-	{
-	  error ("%Jfailure in redeclaration of '%D': dllimport'd "
-		 "symbol lacks external linkage.", decl, decl);
-	  abort();
-	}
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+      if (!DECL_EXTERNAL (decl) || !TREE_PUBLIC (decl)
+          || !DECL_DLLIMPORT_P (decl))
+        {
+          error ("%Jfailure in redeclaration of '%D': dllimport'd "
+                 "symbol lacks external linkage.", decl, decl);
+          abort();
+        }
+ /* APPLE LOCAL end mainline 2005-10-12 */
       return;
     }
 
@@ -324,8 +303,9 @@
   newrtl = gen_rtx_MEM (Pmode,symref);
   XEXP (DECL_RTL (decl), 0) = newrtl;
 
-  /* Can't treat a pointer to this as a constant address */
-  DECL_NON_ADDR_CONST_P (decl) = 1;
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  DECL_DLLIMPORT_P (decl) = 1;
+ /* APPLE LOCAL end mainline 2005-10-12 */
 }
 
 /* Return string which is the former assembler name modified with a
@@ -338,7 +318,7 @@
   int total = 0;
   /* ??? This probably should use XSTR (XEXP (DECL_RTL (decl), 0), 0) instead
      of DECL_ASSEMBLER_NAME.  */
-   const char *asmname =  IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
+  const char *asmname =  IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
   char *newsym;
   char *p;
   tree formal_type;
@@ -351,7 +331,7 @@
   if (formal_type != NULL_TREE)
     {
       /* These attributes are ignored for variadic functions in
-	 i386.c:ix86_return_pops_args. For compatibility with MS
+         i386.c:ix86_return_pops_args. For compatibility with MS
          compiler do not add @0 suffix here.  */ 
       if (TREE_VALUE (tree_last (formal_type)) != void_type_node)
         return DECL_ASSEMBLER_NAME (decl);
@@ -360,17 +340,19 @@
          by convert_arguments in c-typeck.c or cp/typeck.c.  */
       while (TREE_VALUE (formal_type) != void_type_node
 	     && COMPLETE_TYPE_P (TREE_VALUE (formal_type)))	
-	{
-	  int parm_size
-	    = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
-	    /* Must round up to include padding.  This is done the same
-	       way as in store_one_arg.  */
-	  parm_size = ((parm_size + PARM_BOUNDARY - 1)
-		       / PARM_BOUNDARY * PARM_BOUNDARY);
-	  total += parm_size;
-	  formal_type = TREE_CHAIN (formal_type);\
-	}
-     }
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+        {
+          int parm_size
+            = TREE_INT_CST_LOW (TYPE_SIZE (TREE_VALUE (formal_type)));
+          /* Must round up to include padding.  This is done the same
+             way as in store_one_arg.  */
+          parm_size = ((parm_size + PARM_BOUNDARY - 1)
+                       / PARM_BOUNDARY * PARM_BOUNDARY);
+          total += parm_size;
+          formal_type = TREE_CHAIN (formal_type); \
+        }
+ /* APPLE LOCAL end mainline 2005-10-12 */
+    }
 
   /* Assume max of 8 base 10 digits in the suffix.  */
   newsym = alloca (1 + strlen (asmname) + 1 + 8 + 1);
@@ -392,62 +374,65 @@
       tree newid = NULL_TREE;
 
       if (lookup_attribute ("stdcall", type_attributes))
-	newid = gen_stdcall_or_fastcall_suffix (decl, false);
+        newid = gen_stdcall_or_fastcall_suffix (decl, false);
       else if (lookup_attribute ("fastcall", type_attributes))
-	newid = gen_stdcall_or_fastcall_suffix (decl, true);
+        newid = gen_stdcall_or_fastcall_suffix (decl, true);
       if (newid != NULL_TREE) 	
-	{
-	  rtx rtlname = XEXP (rtl, 0);
-	  if (GET_CODE (rtlname) == MEM)
-	    rtlname = XEXP (rtlname, 0);
-	  XSTR (rtlname, 0) = IDENTIFIER_POINTER (newid);
-	  /* These attributes must be present on first declaration,
-	     change_decl_assembler_name will warn if they are added
-	     later and the decl has been referenced, but duplicate_decls
-	     should catch the mismatch before this is called.  */ 
-	  change_decl_assembler_name (decl, newid);
-	}
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+        {
+          rtx rtlname = XEXP (rtl, 0);
+          if (GET_CODE (rtlname) == MEM)
+            rtlname = XEXP (rtlname, 0);
+          XSTR (rtlname, 0) = IDENTIFIER_POINTER (newid);
+          /* These attributes must be present on first declaration,
+             change_decl_assembler_name will warn if they are added
+             later and the decl has been referenced, but duplicate_decls
+             should catch the mismatch before this is called.  */ 
+          change_decl_assembler_name (decl, newid);
+        }
+ /* APPLE LOCAL end mainline 2005-10-12 */
     }
 
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  else if (TREE_CODE (decl) == VAR_DECL
+           && lookup_attribute ("selectany", DECL_ATTRIBUTES (decl)))
+    {
+      if (DECL_INITIAL (decl)
+        /* If an object is initialized with a ctor, the static
+           initialization and destruction code for it is present in
+           each unit defining the object.  The code that calls the
+           ctor is protected by a link-once guard variable, so that
+           the object still has link-once semantics,  */
+          || TYPE_NEEDS_CONSTRUCTING (TREE_TYPE (decl)))
+        make_decl_one_only (decl);
+      else
+        error ("%qD:'selectany' attribute applies only to initialized objects",
+               decl);
+    }
+ /* APPLE LOCAL end mainline 2005-10-12 */
+
   /* 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.  */
+     dllexport'd or dllimport'd.  tree.c: merge_dllimport_decl_attributes
+     handles dllexport/dllimport override semantics.  */
 
   if (i386_pe_dllexport_p (decl))
     i386_pe_mark_dllexport (decl);
   else if (i386_pe_dllimport_p (decl))
     i386_pe_mark_dllimport (decl);
-  /* It might be that DECL has already been marked as dllimport, but a
-     subsequent definition nullified that.  The attribute is gone but
-     DECL_RTL still has (DLL_IMPORT_PREFIX) prefixed. We need to remove
-     that. Ditto for the DECL_NON_ADDR_CONST_P flag.  */
-  else if ((TREE_CODE (decl) == FUNCTION_DECL
-	    || TREE_CODE (decl) == VAR_DECL)
-	   && DECL_RTL (decl) != NULL_RTX
-	   && GET_CODE (DECL_RTL (decl)) == MEM
-	   && GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
-	   && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 0)) == SYMBOL_REF
-	   && i386_pe_dllimport_name_p (XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0)))
-    {
-      const char *oldname = XSTR (XEXP (XEXP (DECL_RTL (decl), 0), 0), 0);
-
-      /* Remove DLL_IMPORT_PREFIX.  */
-      tree idp = get_identifier (oldname + strlen (DLL_IMPORT_PREFIX));
-      rtx symref = gen_rtx_SYMBOL_REF (Pmode, IDENTIFIER_POINTER (idp));
-      SYMBOL_REF_DECL (symref) = decl;
-      XEXP (DECL_RTL (decl), 0) = symref;
-      DECL_NON_ADDR_CONST_P (decl) = 0;
-
-      /* We previously set TREE_PUBLIC and DECL_EXTERNAL.
-	 We leave these alone for now.  */
-
-      if (DECL_INITIAL (decl) || !DECL_EXTERNAL (decl))
-	warning ("%J'%D' defined locally after being "
-		 "referenced with dllimport linkage", decl, decl);
-      else
-	warning ("%J'%D' redeclared without dllimport attribute "
-		 "after being referenced with dllimport linkage", decl, decl);
-    }
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  /* It might be that DECL has been declared as dllimport, but a
+     subsequent definition nullified that.  Assert that
+     tree.c: merge_dllimport_decl_attributes has removed the attribute
+     before the RTL name was marked with the DLL_IMPORT_PREFIX.  */
+  else
+    gcc_assert(!((TREE_CODE (decl) == FUNCTION_DECL
+                  || TREE_CODE (decl) == VAR_DECL)
+               && rtl != NULL_RTX
+               && GET_CODE (rtl) == MEM
+               && GET_CODE (XEXP (rtl, 0)) == MEM
+               && GET_CODE (XEXP (XEXP (rtl, 0), 0)) == SYMBOL_REF
+               && i386_pe_dllimport_name_p (XSTR (XEXP (XEXP (rtl, 0), 0), 0))));
+ /* APPLE LOCAL end mainline 2005-10-12 */
 }
 
 /* Strip only the leading encoding, leaving the stdcall suffix and fastcall
@@ -595,8 +580,10 @@
       flags = SECTION_WRITE;
 
       if (decl && TREE_CODE (decl) == VAR_DECL
-	  && lookup_attribute ("shared", DECL_ATTRIBUTES (decl)))
-	flags |= SECTION_PE_SHARED;
+ /* APPLE LOCAL begin mainline 2005-04-01 */
+          && lookup_attribute ("shared", DECL_ATTRIBUTES (decl)))
+        flags |= SECTION_PE_SHARED;
+ /* APPLE LOCAL end mainline 2005-04-01 */
     }
 
   if (decl && DECL_ONE_ONLY (decl))
@@ -612,7 +599,7 @@
   else
     {
       if (decl && **slot != flags)
-	error ("%J'%D' causes a section type conflict", decl, decl);
+        error ("%J'%D' causes a section type conflict", decl, decl);
     }
 
   return flags;
@@ -620,7 +607,7 @@
 
 void
 i386_pe_asm_named_section (const char *name, unsigned int flags, 
-			   tree decl ATTRIBUTE_UNUSED)
+			   tree decl)
 {
   char flagchars[8], *f = flagchars;
 
@@ -647,10 +634,18 @@
   if (flags & SECTION_LINKONCE)
     {
       /* Functions may have been compiled at various levels of
-         optimization so we can't use `same_size' here.
-         Instead, have the linker pick one.  */
+	 optimization so we can't use `same_size' here.
+	 Instead, have the linker pick one, without warning.
+	 If 'selectany' attibute has been specified,  MS compiler
+	 sets 'discard' characteristic, rather than telling linker
+	 to warn of size or content mismatch, so do the same.  */ 
+ /* APPLE LOCAL begin mainline 2005-04-01 */
+      bool discard = (flags & SECTION_CODE)
+		      || lookup_attribute ("selectany",
+					   DECL_ATTRIBUTES (decl));	 
       fprintf (asm_out_file, "\t.linkonce %s\n",
-	       (flags & SECTION_CODE ? "discard" : "same_size"));
+	       (discard  ? "discard" : "same_size"));
+ /* APPLE LOCAL end mainline 2005-10-12 */
     }
 }
 
@@ -751,11 +746,11 @@
 
       /* Positively ensure only one declaration for any given symbol.  */
       if (! TREE_ASM_WRITTEN (decl) && TREE_SYMBOL_REFERENCED (decl))
-	{
-	  TREE_ASM_WRITTEN (decl) = 1;
-	  i386_pe_declare_function_type (asm_out_file, p->name,
-					 TREE_PUBLIC (decl));
-	}
+        {
+          TREE_ASM_WRITTEN (decl) = 1;
+          i386_pe_declare_function_type (asm_out_file, p->name,
+                                         TREE_PUBLIC (decl));
+        }
     }
 
   if (export_head)
@@ -763,11 +758,11 @@
       struct export_list *q;
       drectve_section ();
       for (q = export_head; q != NULL; q = q->next)
-	{
-	  fprintf (asm_out_file, "\t.ascii \" -export:%s%s\"\n",
-		   i386_pe_strip_name_encoding (q->name),
-		   (q->is_data) ? ",data" : "");
-	}
+        {
+          fprintf (asm_out_file, "\t.ascii \" -export:%s%s\"\n",
+                   i386_pe_strip_name_encoding (q->name),
+                   (q->is_data) ? ",data" : "");
+        }
     }
 }
 

Modified: apple-local/branches/llvm/gcc/config.gcc
===================================================================
--- apple-local/branches/llvm/gcc/config.gcc	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/config.gcc	2007-02-21 20:19:03 UTC (rev 124163)
@@ -1209,9 +1209,11 @@
 	xm_file=i386/xm-cygwin.h
 	tmake_file="i386/t-cygwin i386/t-cygming"
 	target_gtfiles="\$(srcdir)/config/i386/winnt.c"
-	extra_objs=winnt.o
+ # APPLE LOCAL begin mainline 2005-10-12
+	extra_objs="winnt.o winnt-stubs.o"
+ # APPLE LOCAL end mainline 2005-10-12
 	c_target_objs=cygwin2.o
-	cxx_target_objs=cygwin2.o
+	cxx_target_objs="cygwin2.o winnt-cxx.o"
 	extra_gcc_objs=cygwin1.o
 	if test x$enable_threads = xyes; then
 		thread_file='posix'
@@ -1222,7 +1224,10 @@
 	xm_file=i386/xm-mingw32.h
 	tmake_file="i386/t-cygming i386/t-mingw32"
 	target_gtfiles="\$(srcdir)/config/i386/winnt.c"
-	extra_objs=winnt.o
+ # APPLE LOCAL begin mainline 2005-10-12
+	extra_objs="winnt.o winnt-stubs.o"
+	cxx_target_objs="winnt-cxx.o"
+ # APPLE LOCAL end mainline 2005-10-12
 	case ${enable_threads} in
 	  "" | yes | win32) thread_file='win32' ;;
 	esac

Modified: apple-local/branches/llvm/gcc/cp/decl.c
===================================================================
--- apple-local/branches/llvm/gcc/cp/decl.c	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/cp/decl.c	2007-02-21 20:19:03 UTC (rev 124163)
@@ -3846,6 +3846,18 @@
     objc_checkon_weak_attribute (decl);
   /* APPLE LOCAL end radar 4592503 */
 
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  /* Dllimported symbols cannot be defined.  Static data members (which
+     can be initialized in-class and dllimported) go through grokfield,
+     not here, so we don't need to exclude those decls when checking for
+     a definition.  */
+  if (initialized && DECL_DLLIMPORT_P (decl))
+    {
+      error ("definition of %q#D is marked %<dllimport%>", decl);
+      DECL_DLLIMPORT_P (decl) = 0;
+    }
+ /* APPLE LOCAL end mainline 2005-10-12 */
+
   /* If #pragma weak was used, mark the decl weak now.  */
   maybe_apply_pragma_weak (decl);
 

Modified: apple-local/branches/llvm/gcc/doc/extend.texi
===================================================================
--- apple-local/branches/llvm/gcc/doc/extend.texi	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/doc/extend.texi	2007-02-21 20:19:03 UTC (rev 124163)
@@ -3198,6 +3198,28 @@
 is invalid even if the size of the structure is the same as the size of
 the @code{int}.
 
+ at c APPLE LOCAL begin mainline 2005-04-01
+ at item selectany
+The @code{selectany} attribute causes an initialized global variable to
+have link-once semantics.  When multiple definitions of the variable are
+encountered by the linker, the first is selected and the remainder are
+discarded.  Following usage by the Microsoft compiler, the linker is told
+ at emph{not} to warn about size or content differences of the multiple
+definitions.
+
+Although the primary usage of this attribute is for POD types, the
+attribute can also be applied to global C++ objects that are initialized
+by a constructor.  In this case, the static initialization and destruction
+code for the object is emitted in each translation defining the object,
+but the calls to the constructor and destructor are protected by a
+link-once guard variable. 
+
+The @code{selectany} attribute is only available on Microsoft Windows
+targets.  You can use @code{__declspec (selectany)} as a synonym for
+ at code{__attribute__ ((selectany))} for compatibility with other
+compilers.
+ at c APPLE LOCAL end mainline 2005-04-01
+
 @item weak
 The @code{weak} attribute is described in @xref{Function Attributes}.
 

Modified: apple-local/branches/llvm/gcc/doc/fragments.texi
===================================================================
--- apple-local/branches/llvm/gcc/doc/fragments.texi	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/doc/fragments.texi	2007-02-21 20:19:03 UTC (rev 124163)
@@ -151,6 +151,14 @@
 of options to be used for all builds.  If you set this, you should
 probably set @code{CRTSTUFF_T_CFLAGS} to a dash followed by it.
 
+ at c APPLE LOCAL begin mainline 2005-08-02
+ at findex NATIVE_SYSTEM_HEADER_DIR
+ at item NATIVE_SYSTEM_HEADER_DIR
+If the default location for system headers is not @file{/usr/include},
+you must set this to the directory containing the headers.  This value
+should match the value of the @code{SYSTEM_INCLUDE_DIR} macro.
+ at c APPLE LOCAL end mainline 2005-08-02
+
 @findex SPECS
 @item SPECS
 Unfortunately, setting @code{MULTILIB_EXTRA_OPTS} is not enough, since

Modified: apple-local/branches/llvm/gcc/doc/tm.texi
===================================================================
--- apple-local/branches/llvm/gcc/doc/tm.texi	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/doc/tm.texi	2007-02-21 20:19:03 UTC (rev 124163)
@@ -8560,6 +8560,14 @@
 @file{i386/i386.c}, for example.
 @end deftypefn
 
+ at c APPLE LOCAL begin mainline 2005-10-12
+ at deftypefn {Target Hook} bool TARGET_VALID_DLLIMPORT_ATTRIBUTE_P (tree @var{decl})
+ at var{decl} is a variable or function with @code{__attribute__((dllimport))}
+specified. Use this hook if the target needs to add extra validation
+checks to @code{handle_dll_attribute}.
+ at end deftypefn
+ at c APPLE LOCAL begin mainline 2005-10-12
+
 @defmac TARGET_DECLSPEC
 Define this macro to a nonzero value if you want to treat
 @code{__declspec(X)} as equivalent to @code{__attribute((X))}.  By
@@ -8727,6 +8735,15 @@
 @end deftypefn
 
 @c APPLE LOCAL end mainline 4.2 2006-03-01 4311680
+
+ at c APPLE LOCAL begin mainline 2005-10-12
+ at deftypefn {Target Hook} void TARGET_CXX_ADJUST_CLASS_AT_DEFINITION (tree @var{type})
+ at var{type} is a C++ class (i.e., RECORD_TYPE or UNION_TYPE) that has just been
+defined.  Use this hook to make adjustments to the class (eg, tweak
+visibility or perform any other required target modifications).
+ at end deftypefn
+ at c APPLE LOCAL end mainline 2005-10-12
+
 @node Misc
 @section Miscellaneous Parameters
 @cindex parameters, miscellaneous

Modified: apple-local/branches/llvm/gcc/target-def.h
===================================================================
--- apple-local/branches/llvm/gcc/target-def.h	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/target-def.h	2007-02-21 20:19:03 UTC (rev 124163)
@@ -416,6 +416,12 @@
 
 #define TARGET_DWARF_HANDLE_FRAME_UNSPEC 0
 
+/* APPLE LOCAL begin mainline 2005-10-12 */
+#ifndef TARGET_VALID_DLLIMPORT_ATTRIBUTE_P
+#define TARGET_VALID_DLLIMPORT_ATTRIBUTE_P hook_bool_tree_true
+#endif
+/* APPLE LOCAL end mainline 2005-10-12 */
+
 #define TARGET_PROMOTE_FUNCTION_ARGS hook_bool_tree_false
 #define TARGET_PROMOTE_FUNCTION_RETURN hook_bool_tree_false
 #define TARGET_PROMOTE_PROTOTYPES hook_bool_tree_false
@@ -530,6 +536,13 @@
 #endif
 
 /* APPLE LOCAL end mainline 4.2 2006-03-01 4311680 */
+
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+#ifndef TARGET_CXX_ADJUST_CLASS_AT_DEFINITION
+#define TARGET_CXX_ADJUST_CLASS_AT_DEFINITION hook_void_tree
+#endif
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+
 #define TARGET_CXX				\
   {						\
     TARGET_CXX_GUARD_TYPE,			\
@@ -543,6 +556,9 @@
     TARGET_CXX_DETERMINE_CLASS_DATA_VISIBILITY,	\
     TARGET_CXX_CLASS_DATA_ALWAYS_COMDAT,        \
 /* APPLE LOCAL end mainline 4.2 2006-03-01 4311680 */ \
+ /* APPLE LOCAL begin mainline 2005-10-12 */ \
+    TARGET_CXX_ADJUST_CLASS_AT_DEFINITION          \
+ /* APPLE LOCAL end mainline 2005-10-12 */ \
   }
 
 /* The whole shebang.  */
@@ -604,6 +620,9 @@
   TARGET_MD_ASM_CLOBBERS,			\
   TARGET_DWARF_CALLING_CONVENTION,              \
   TARGET_DWARF_HANDLE_FRAME_UNSPEC,		\
+ /* APPLE LOCAL begin mainline 2005-10-12 */   \
+  TARGET_VALID_DLLIMPORT_ATTRIBUTE_P,         \
+ /* APPLE LOCAL end mainline 2005-10-12 */    \
   TARGET_CALLS,					\
   TARGET_CXX,					\
   TARGET_HAVE_NAMED_SECTIONS,			\

Modified: apple-local/branches/llvm/gcc/target.h
===================================================================
--- apple-local/branches/llvm/gcc/target.h	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/target.h	2007-02-21 20:19:03 UTC (rev 124163)
@@ -525,6 +525,13 @@
      to let the backend emit the call frame instructions.  */
   void (* dwarf_handle_frame_unspec) (const char *, rtx, int);
 
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  /* DECL is a variable or function with __attribute__((dllimport))
+     specified.  Use this hook if the target needs to add extra validation
+     checks to  handle_dll_attribute ().  */
+  bool (* valid_dllimport_attribute_p) (tree decl);
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+
   /* Functions relating to calls - argument passing, returns, etc.  */
   struct calls {
     bool (*promote_function_args) (tree fntype);
@@ -628,6 +635,13 @@
        only one translation unit will not be COMDAT.  */
     bool (*class_data_always_comdat) (void);
 /* APPLE LOCAL end mainline 4.2 2006-03-01 4311680 */
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+    /* TYPE is a C++ class (i.e., RECORD_TYPE or UNION_TYPE) that
+       has just been defined.  Use this hook to make adjustments to the
+       class  (eg, tweak visibility or perform any other required
+       target modifications).  */  
+    void (*adjust_class_at_definition) (tree type);
+ /* APPLE LOCAL end mainline 2005-10-12 */
   } cxx;
 
   /* Leave the boolean fields at the end.  */

Modified: apple-local/branches/llvm/gcc/tree.c
===================================================================
--- apple-local/branches/llvm/gcc/tree.c	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/tree.c	2007-02-21 20:19:03 UTC (rev 124163)
@@ -1632,7 +1632,9 @@
     case VAR_DECL:
       return ((TREE_STATIC (arg) || DECL_EXTERNAL (arg))
 	      && ! DECL_THREAD_LOCAL (arg)
-	      && ! DECL_NON_ADDR_CONST_P (arg)
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+	      && ! DECL_DLLIMPORT_P (arg)
+ /* APPLE LOCAL end mainline 2005-10-12 */
 	      ? arg : NULL);
 
     case CONST_DECL:
@@ -3245,39 +3247,84 @@
 merge_dllimport_decl_attributes (tree old, tree new)
 {
   tree a;
-  int delete_dllimport_p;
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  int delete_dllimport_p = 1;
+ /* APPLE LOCAL end mainline 2005-10-12 */
 
-  old = DECL_ATTRIBUTES (old);
-  new = DECL_ATTRIBUTES (new);
-
   /* What we need to do here is remove from `old' dllimport if it doesn't
      appear in `new'.  dllimport behaves like extern: if a declaration is
      marked dllimport and a definition appears later, then the object
-     is not dllimport'd.  */
-  if (lookup_attribute ("dllimport", old) != NULL_TREE
-      && lookup_attribute ("dllimport", new) == NULL_TREE)
-    delete_dllimport_p = 1;
+     is not dllimport'd.  We also remove a `new' dllimport if the old list
+     contains dllexport:  dllexport always overrides dllimport, regardless
+     of the order of declaration.  */
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  if (!VAR_OR_FUNCTION_DECL_P (new))
+    delete_dllimport_p = 0;
+  else if (DECL_DLLIMPORT_P (new)
+           && lookup_attribute ("dllexport", DECL_ATTRIBUTES (old)))
+    { 
+      DECL_DLLIMPORT_P (new) = 0;
+      warning ("%qD already declared with dllexport attribute: "
+	      "dllimport ignored", new);
+    }
+  else if (DECL_DLLIMPORT_P (old) && !DECL_DLLIMPORT_P (new))
+    {
+      /* Warn about overriding a symbol that has already been used. eg:
+           extern int __attribute__ ((dllimport)) foo;
+           int* bar () {return &foo;}
+           int foo;
+      */
+      if (TREE_USED (old))
+        {
+          warning ("%qD redeclared without dllimport attribute "
+                   "after being referenced with dll linkage", new);
+          /* If we have used a variable's address with dllimport linkage,
+             keep the old DECL_DLLIMPORT_P flag: the ADDR_EXPR using the
+             decl may already have had TREE_INVARIANT and TREE_CONSTANT
+             computed.
+             We still remove the attribute so that assembler code refers
+             to '&foo rather than '_imp__foo'.  */
+          if (TREE_CODE (old) == VAR_DECL && TREE_ADDRESSABLE (old))
+            DECL_DLLIMPORT_P (new) = 1;
+        }
+
+      /* Let an inline definition silently override the external reference,
+         but otherwise warn about attribute inconsistency.  */ 
+      else if (TREE_CODE (new) == VAR_DECL
+               || !DECL_DECLARED_INLINE_P (new))
+        warning ("%qD redeclared without dllimport attribute: "
+                 "previous dllimport ignored", new);
+    }
+ /* APPLE LOCAL end mainline 2005-10-12 */
   else
     delete_dllimport_p = 0;
 
-  a = merge_attributes (old, new);
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  a = merge_attributes (DECL_ATTRIBUTES (old), DECL_ATTRIBUTES (new));
+ /* APPLE LOCAL end mainline 2005-10-12 */
 
   if (delete_dllimport_p)
     {
       tree prev, t;
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+      const size_t attr_len = strlen ("dllimport");
+ /* APPLE LOCAL end mainline 2005-10-12 */
 
       /* Scan the list for dllimport and delete it.  */
       for (prev = NULL_TREE, t = a; t; prev = t, t = TREE_CHAIN (t))
-	{
-	  if (is_attribute_p ("dllimport", TREE_PURPOSE (t)))
-	    {
-	      if (prev == NULL_TREE)
-		a = TREE_CHAIN (a);
-	      else
-		TREE_CHAIN (prev) = TREE_CHAIN (t);
-	      break;
-	    }
-	}
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+       {
+         if (is_attribute_with_length_p ("dllimport", attr_len,
+                                         TREE_PURPOSE (t)))           
+           {
+             if (prev == NULL_TREE)
+               a = TREE_CHAIN (a);
+             else
+               TREE_CHAIN (prev) = TREE_CHAIN (t);
+             break;
+           }
+       }
+ /* APPLE LOCAL end mainline 2005-10-12 */
     }
 
   return a;
@@ -3298,15 +3345,19 @@
     {
       if (flags & ((int) ATTR_FLAG_DECL_NEXT | (int) ATTR_FLAG_FUNCTION_NEXT
 		   | (int) ATTR_FLAG_ARRAY_NEXT))
-	{
-	  *no_add_attrs = true;
-	  return tree_cons (name, args, NULL_TREE);
-	}
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+        {
+          *no_add_attrs = true;
+          return tree_cons (name, args, NULL_TREE);
+        }
+ /* APPLE LOCAL end mainline 2005-10-12 */
       if (TREE_CODE (node) != RECORD_TYPE && TREE_CODE (node) != UNION_TYPE)
-	{
-	  warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
-	  *no_add_attrs = true;
-	}
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+        {
+          warning ("%qs attribute ignored", IDENTIFIER_POINTER (name));
+          *no_add_attrs = true;
+        }
+ /* APPLE LOCAL end mainline 2005-10-12 */
 
       return NULL_TREE;
     }
@@ -3315,34 +3366,51 @@
      any damage.  */
   if (is_attribute_p ("dllimport", name))
     {
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+      /* Honor any target-specific overides. */ 
+      if (!targetm.valid_dllimport_attribute_p (node))
+        *no_add_attrs = true;
+
+      else if (TREE_CODE (node) == FUNCTION_DECL
+               && DECL_DECLARED_INLINE_P (node))
+        {
+          warning ("inline function %qD declared as "
+                   " dllimport: attribute ignored", node); 
+          *no_add_attrs = true;
+        }
+ /* APPLE LOCAL end mainline 2005-10-12 */
       /* Like MS, treat definition of dllimported variables and
-	 non-inlined functions on declaration as syntax errors.  We
-	 allow the attribute for function definitions if declared
-	 inline.  */
-      if (TREE_CODE (node) == FUNCTION_DECL  && DECL_INITIAL (node)
-          && !DECL_DECLARED_INLINE_P (node))
-	{
-	  error ("%Jfunction %qD definition is marked dllimport.", node, node);
-	  *no_add_attrs = true;
-	}
+         non-inlined functions on declaration as syntax errors. */
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+      else if (TREE_CODE (node) == FUNCTION_DECL && DECL_INITIAL (node))
+        {
+          error ("%Jfunction %qD definition is marked dllimport.", node, node);
+          *no_add_attrs = true;
+        }
+ /* APPLE LOCAL end mainline 2005-10-12 */
 
       else if (TREE_CODE (node) == VAR_DECL)
-	{
-	  if (DECL_INITIAL (node))
-	    {
-	      error ("%Jvariable %qD definition is marked dllimport.",
-		     node, node);
-	      *no_add_attrs = true;
-	    }
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+        {
+          if (DECL_INITIAL (node))
+            {
+              error ("%Jvariable %qD definition is marked dllimport.",
+                     node, node);
+              *no_add_attrs = true;
+            }
 
-	  /* `extern' needn't be specified with dllimport.
-	     Specify `extern' now and hope for the best.  Sigh.  */
-	  DECL_EXTERNAL (node) = 1;
-	  /* Also, implicitly give dllimport'd variables declared within
-	     a function global scope, unless declared static.  */
-	  if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
-	    TREE_PUBLIC (node) = 1;
-	}
+          /* `extern' needn't be specified with dllimport.
+             Specify `extern' now and hope for the best.  Sigh.  */
+          DECL_EXTERNAL (node) = 1;
+          /* Also, implicitly give dllimport'd variables declared within
+             a function global scope, unless declared static.  */
+          if (current_function_decl != NULL_TREE && !TREE_STATIC (node))
+            TREE_PUBLIC (node) = 1;
+        }
+
+      if (*no_add_attrs == false)
+        DECL_DLLIMPORT_P (node) = 1;
+ /* APPLE LOCAL end mainline 2005-10-12 */
     }
 
   /*  Report error if symbol is not accessible at global scope.  */

Modified: apple-local/branches/llvm/gcc/tree.h
===================================================================
--- apple-local/branches/llvm/gcc/tree.h	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/tree.h	2007-02-21 20:19:03 UTC (rev 124163)
@@ -2368,9 +2368,10 @@
 #define DECL_LANG_FLAG_6(NODE) (DECL_CHECK (NODE)->decl.lang_flag_6)
 #define DECL_LANG_FLAG_7(NODE) (DECL_CHECK (NODE)->decl.lang_flag_7)
 
-/* Used to indicate that the pointer to this DECL cannot be treated as
-   an address constant.  */
-#define DECL_NON_ADDR_CONST_P(NODE) (DECL_CHECK (NODE)->decl.non_addr_const_p)
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+/* Used to indicate that the DECL is a dllimport.  */
+#define DECL_DLLIMPORT_P(NODE) (DECL_CHECK (NODE)->decl.dllimport_flag)
+ /* APPLE LOCAL end mainline 2005-10-12 */
 
 /* Used in a FIELD_DECL to indicate that we cannot form the address of
    this component.  */
@@ -2463,7 +2464,9 @@
   unsigned artificial_flag : 1;
   unsigned weak_flag : 1;
 
-  unsigned non_addr_const_p : 1;
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+  unsigned dllimport_flag : 1; 
+ /* APPLE LOCAL end mainline 2005-10-12 */
   unsigned no_instrument_function_entry_exit : 1;
   unsigned comdat_flag : 1;
   unsigned malloc_flag : 1;

Modified: apple-local/branches/llvm/gcc/varasm.c
===================================================================
--- apple-local/branches/llvm/gcc/varasm.c	2007-02-21 17:50:03 UTC (rev 124162)
+++ apple-local/branches/llvm/gcc/varasm.c	2007-02-21 20:19:03 UTC (rev 124163)
@@ -3705,7 +3705,9 @@
       if (value
 	  && TREE_CODE (value) == FUNCTION_DECL
 	  && ((decl_function_context (value) && !DECL_NO_STATIC_CHAIN (value))
-	      || DECL_NON_ADDR_CONST_P (value)))
+ /* APPLE LOCAL begin mainline 2005-10-12 */
+	      || DECL_DLLIMPORT_P (value)))
+ /* APPLE LOCAL end mainline 2005-10-12 */
 	return NULL_TREE;
       return value;
 





More information about the llvm-commits mailing list