comparison gcc/config/i386/winnt-cxx.c @ 111:04ced10e8804

gcc 7
author kono
date Fri, 27 Oct 2017 22:46:09 +0900
parents f6334be47118
children 84e7813d76e9
comparison
equal deleted inserted replaced
68:561a7518be6b 111:04ced10e8804
1 /* Target support for C++ classes on Windows. 1 /* Target support for C++ classes on Windows.
2 Contributed by Danny Smith (dannysmith@users.sourceforge.net) 2 Contributed by Danny Smith (dannysmith@users.sourceforge.net)
3 Copyright (C) 2005, 2007, 2009, 2010 Free Software Foundation, Inc. 3 Copyright (C) 2005-2017 Free Software Foundation, Inc.
4 4
5 This file is part of GCC. 5 This file is part of GCC.
6 6
7 GCC is free software; you can redistribute it and/or modify it under 7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free 8 the terms of the GNU General Public License as published by the Free
19 <http://www.gnu.org/licenses/>. */ 19 <http://www.gnu.org/licenses/>. */
20 20
21 #include "config.h" 21 #include "config.h"
22 #include "system.h" 22 #include "system.h"
23 #include "coretypes.h" 23 #include "coretypes.h"
24 #include "tm.h"
25 #include "tree.h"
26 #include "cp/cp-tree.h" /* This is why we're a separate module. */ 24 #include "cp/cp-tree.h" /* This is why we're a separate module. */
27 #include "flags.h" 25 #include "stringpool.h"
28 #include "tm_p.h" 26 #include "attribs.h"
29 #include "diagnostic-core.h"
30 #include "hashtab.h"
31 27
32 bool 28 bool
33 i386_pe_type_dllimport_p (tree decl) 29 i386_pe_type_dllimport_p (tree decl)
34 { 30 {
35 gcc_assert (TREE_CODE (decl) == VAR_DECL 31 gcc_assert (TREE_CODE (decl) == VAR_DECL
63 The only artificial methods that need to be exported are virtual 59 The only artificial methods that need to be exported are virtual
64 and non-virtual thunks. */ 60 and non-virtual thunks. */
65 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE 61 if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE
66 && DECL_ARTIFICIAL (decl) && !DECL_THUNK_P (decl)) 62 && DECL_ARTIFICIAL (decl) && !DECL_THUNK_P (decl))
67 return false; 63 return false;
64 if (TREE_CODE (decl) == FUNCTION_DECL
65 && DECL_DECLARED_INLINE_P (decl))
66 {
67 if (DECL_REALLY_EXTERN (decl)
68 || !flag_keep_inline_dllexport)
69 return false;
70 }
68 return true; 71 return true;
69 } 72 }
70 73
71 static inline void maybe_add_dllimport (tree decl) 74 static inline void maybe_add_dllimport (tree decl)
72 { 75 {
95 gcc_assert (CLASS_TYPE_P (t)); 98 gcc_assert (CLASS_TYPE_P (t));
96 99
97 100
98 if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (t)) != NULL_TREE) 101 if (lookup_attribute ("dllexport", TYPE_ATTRIBUTES (t)) != NULL_TREE)
99 { 102 {
100 /* Check static VAR_DECL's. */ 103 tree tmv = TYPE_MAIN_VARIANT (t);
104
105 /* Make sure that we set dllexport attribute to typeinfo's
106 base declaration, as otherwise it would fail to be exported as
107 it isn't a class-member. */
108 if (tmv != NULL_TREE
109 && CLASSTYPE_TYPEINFO_VAR (tmv) != NULL_TREE)
110 {
111 tree na, ti_decl = CLASSTYPE_TYPEINFO_VAR (tmv);
112 na = tree_cons (get_identifier ("dllexport"), NULL_TREE,
113 NULL_TREE);
114 decl_attributes (&ti_decl, na, 0);
115 }
116
117 /* Check FUNCTION_DECL's and static VAR_DECL's. */
101 for (member = TYPE_FIELDS (t); member; member = DECL_CHAIN (member)) 118 for (member = TYPE_FIELDS (t); member; member = DECL_CHAIN (member))
102 if (TREE_CODE (member) == VAR_DECL) 119 if (TREE_CODE (member) == VAR_DECL)
103 maybe_add_dllexport (member); 120 maybe_add_dllexport (member);
104 121 else if (TREE_CODE (member) == FUNCTION_DECL)
105 /* Check FUNCTION_DECL's. */
106 for (member = TYPE_METHODS (t); member; member = DECL_CHAIN (member))
107 if (TREE_CODE (member) == FUNCTION_DECL)
108 { 122 {
109 tree thunk; 123 tree thunk;
110 maybe_add_dllexport (member); 124 maybe_add_dllexport (member);
111 125
112 /* Also add the attribute to its thunks. */ 126 /* Also add the attribute to its thunks. */
113 for (thunk = DECL_THUNKS (member); thunk; 127 for (thunk = DECL_THUNKS (member); thunk;
114 thunk = TREE_CHAIN (thunk)) 128 thunk = TREE_CHAIN (thunk))
115 maybe_add_dllexport (thunk); 129 maybe_add_dllexport (thunk);
116 } 130 }
131
117 /* Check vtables */ 132 /* Check vtables */
118 for (member = CLASSTYPE_VTABLES (t); member; member = DECL_CHAIN (member)) 133 for (member = CLASSTYPE_VTABLES (t);
134 member; member = DECL_CHAIN (member))
119 if (TREE_CODE (member) == VAR_DECL) 135 if (TREE_CODE (member) == VAR_DECL)
120 maybe_add_dllexport (member); 136 maybe_add_dllexport (member);
121 } 137 }
122 138
123 else if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (t)) != NULL_TREE) 139 else if (lookup_attribute ("dllimport", TYPE_ATTRIBUTES (t)) != NULL_TREE)
128 cause the DECL_DLLIMPORT_P flag to be unset. 144 cause the DECL_DLLIMPORT_P flag to be unset.
129 (See tree.c: merge_dllimport_decl_attributes). 145 (See tree.c: merge_dllimport_decl_attributes).
130 That is just right since out-of class declarations can only be a 146 That is just right since out-of class declarations can only be a
131 definition. */ 147 definition. */
132 148
133 /* Check static VAR_DECL's. */ 149 /* Check FUNCTION_DECL's and static VAR_DECL's. */
134 for (member = TYPE_FIELDS (t); member; member = DECL_CHAIN (member)) 150 for (member = TYPE_FIELDS (t); member; member = DECL_CHAIN (member))
135 if (TREE_CODE (member) == VAR_DECL) 151 if (TREE_CODE (member) == VAR_DECL)
136 maybe_add_dllimport (member); 152 maybe_add_dllimport (member);
137 153 else if (TREE_CODE (member) == FUNCTION_DECL)
138 /* Check FUNCTION_DECL's. */
139 for (member = TYPE_METHODS (t); member; member = DECL_CHAIN (member))
140 if (TREE_CODE (member) == FUNCTION_DECL)
141 { 154 {
142 tree thunk; 155 tree thunk;
143 maybe_add_dllimport (member); 156 maybe_add_dllimport (member);
144 157
145 /* Also add the attribute to its thunks. */ 158 /* Also add the attribute to its thunks. */
146 for (thunk = DECL_THUNKS (member); thunk; 159 for (thunk = DECL_THUNKS (member); thunk;
147 thunk = DECL_CHAIN (thunk)) 160 thunk = DECL_CHAIN (thunk))
148 maybe_add_dllimport (thunk); 161 maybe_add_dllimport (thunk);
149 } 162 }
150 163
151 /* Check vtables */ 164 /* Check vtables */
152 for (member = CLASSTYPE_VTABLES (t); member; member = DECL_CHAIN (member)) 165 for (member = CLASSTYPE_VTABLES (t);
166 member; member = DECL_CHAIN (member))
153 if (TREE_CODE (member) == VAR_DECL) 167 if (TREE_CODE (member) == VAR_DECL)
154 maybe_add_dllimport (member); 168 maybe_add_dllimport (member);
155 169
156 /* We leave typeinfo tables alone. We can't mark TI objects as 170 /* We leave typeinfo tables alone. We can't mark TI objects as
157 dllimport, since the address of a secondary VTT may be needed 171 dllimport, since the address of a secondary VTT may be needed