diff options
author | Danny Smith <dannysmith@gcc.gnu.org> | 2006-06-23 08:25:33 +0000 |
---|---|---|
committer | Danny Smith <dannysmith@gcc.gnu.org> | 2006-06-23 08:25:33 +0000 |
commit | 4e2bb0a4b816a3dc9dbcd871c6ad8e9c678146a5 (patch) | |
tree | 708dd600878c8dfe4cd831930197553a97ae4c13 /gcc/config | |
parent | ecf7b86fb84c46a26473a1f9ad148e69189e6db4 (diff) | |
download | gcc-4e2bb0a4b816a3dc9dbcd871c6ad8e9c678146a5.zip gcc-4e2bb0a4b816a3dc9dbcd871c6ad8e9c678146a5.tar.gz gcc-4e2bb0a4b816a3dc9dbcd871c6ad8e9c678146a5.tar.bz2 |
re PR target/27789 (attribute handling fallout from DECL_INITIAL changes)
PR target/27789
* config/i386/winnt.c (ix86_handle_selectany_attribute): Move check
for initialization and setting of one_only flag to ...
(i386_pe_encode_section_info): ...here.
(i386_pe_dllimport_p): Check for DECL_DLLIMPORT_P also.
Recheck that the symbol has not been defined.
cp
* decl.c (start_decl): Check that dllimports are not initialized.
testsuite
* g++.dg/ext/dllimport4.C. Add more tests for invalid
initialization.
From-SVN: r114927
Diffstat (limited to 'gcc/config')
-rw-r--r-- | gcc/config/i386/winnt.c | 59 |
1 files changed, 39 insertions, 20 deletions
diff --git a/gcc/config/i386/winnt.c b/gcc/config/i386/winnt.c index c7eae6c..a46fc5b 100644 --- a/gcc/config/i386/winnt.c +++ b/gcc/config/i386/winnt.c @@ -1,7 +1,7 @@ /* Subroutines for insn-output.c for Windows NT. Contributed by Douglas Rupp (drupp@cs.washington.edu) - Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005 - Free Software Foundation, Inc. + Copyright (C) 1995, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, + 2005, 2006 Free Software Foundation, Inc. This file is part of GCC. @@ -88,17 +88,10 @@ ix86_handle_selectany_attribute (tree *node, tree name, bool *no_add_attrs) { /* The attribute applies only to objects that are initialized and have - external linkage, */ - if (TREE_CODE (*node) == VAR_DECL && TREE_PUBLIC (*node) - && (DECL_INITIAL (*node) - /* 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 (*node)))) - make_decl_one_only (*node); - else + 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)); @@ -148,18 +141,28 @@ i386_pe_dllimport_p (tree decl) && TREE_CODE (decl) != FUNCTION_DECL) return false; - /* Lookup the attribute rather than rely on the DECL_DLLIMPORT_P flag. + /* Lookup the attribute in addition to checking the DECL_DLLIMPORT_P flag. We may need to override an earlier decision. */ - if (lookup_attribute ("dllimport", DECL_ATTRIBUTES (decl))) - return true; - + 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. */ - if (associated_type (decl) - && lookup_attribute ("dllimport", - TYPE_ATTRIBUTES (associated_type (decl)))) + else if (associated_type (decl) + && lookup_attribute ("dllimport", + TYPE_ATTRIBUTES (associated_type (decl)))) return i386_pe_type_dllimport_p (decl); return false; @@ -362,6 +365,22 @@ i386_pe_encode_section_info (tree decl, rtx rtl, int first) } } + 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 ("%q+D:'selectany' attribute applies only to initialized objects", + decl); + } + /* Mark the decl so we can tell from the rtl whether the object is dllexport'd or dllimport'd. tree.c: merge_dllimport_decl_attributes handles dllexport/dllimport override semantics. */ |