Example #1
0
bool
i386_pe_dllimport_p (tree decl)
{
    if (TREE_CODE (decl) != VAR_DECL
            && TREE_CODE (decl) != FUNCTION_DECL)
        return false;

    /* 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)))
    {
        /* Make a final check to see if this is a definition before we generate
           RTL for an indirect reference.  */
        if (!DECL_EXTERNAL (decl))
        {
            error ("%q+D: definition is marked as dllimport", decl);
            DECL_DLLIMPORT_P (decl) = 0;
            return false;
        }
        return true;
    }
    /* 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 overridden 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);

    return false;
}
Example #2
0
static bool
i386_pe_determine_dllimport_p (tree decl)
{
  tree assoc;

  if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != FUNCTION_DECL)
    return false;

  if (DECL_DLLIMPORT_P (decl))
    return true;

  /* The DECL_DLLIMPORT_P flag was set for decls in the class definition
     by  targetm.cxx.adjust_class_at_definition.  Check again to emit
     error message if the class attribute has been overridden by an
     out-of-class definition of static data.  */
  assoc = associated_type (decl);
  if (assoc && lookup_attribute ("dllimport", TYPE_ATTRIBUTES (assoc))
      && TREE_CODE (decl) == VAR_DECL
      && TREE_STATIC (decl) && TREE_PUBLIC (decl)
      && !DECL_EXTERNAL (decl)
      /* vtable's are linkonce constants, so defining a vtable is not
	 an error as long as we don't try to import it too.  */
      && !DECL_VIRTUAL_P (decl))
	error ("definition of static data member %q+D of "
	       "dllimport%'d class", decl);

  return false;
}
Example #3
0
bool
i386_pe_dllexport_p (tree decl)
{
    if (TREE_CODE (decl) != VAR_DECL
            && TREE_CODE (decl) != FUNCTION_DECL)
        return false;

    if (lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))
        return true;

    /* 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);

    return false;
}
Example #4
0
int
i386_pe_dllexport_p (tree decl)
{
  if (TREE_CODE (decl) != VAR_DECL
      && TREE_CODE (decl) != FUNCTION_DECL)
    return 0;

  /* APPLE LOCAL begin mainline 2005-10-12 */
  if (lookup_attribute ("dllexport", DECL_ATTRIBUTES (decl)))
    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;
}
Example #5
0
static 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)
    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;
    }

  return 0;
}
Example #6
0
static 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))
    {
      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))
        {
	  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;

      return 1;
    }

  return 0;
}