]>
Commit | Line | Data |
---|---|---|
8d08fdba | 1 | /* Language-dependent node constructors for parse phase of GNU compiler. |
d1e082c2 | 2 | Copyright (C) 1987-2013 Free Software Foundation, Inc. |
8d08fdba MS |
3 | Hacked by Michael Tiemann (tiemann@cygnus.com) |
4 | ||
f5adbb8d | 5 | This file is part of GCC. |
8d08fdba | 6 | |
f5adbb8d | 7 | GCC is free software; you can redistribute it and/or modify |
8d08fdba | 8 | it under the terms of the GNU General Public License as published by |
e77f031d | 9 | the Free Software Foundation; either version 3, or (at your option) |
8d08fdba MS |
10 | any later version. |
11 | ||
f5adbb8d | 12 | GCC is distributed in the hope that it will be useful, |
8d08fdba MS |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 | GNU General Public License for more details. | |
16 | ||
17 | You should have received a copy of the GNU General Public License | |
e77f031d NC |
18 | along with GCC; see the file COPYING3. If not see |
19 | <http://www.gnu.org/licenses/>. */ | |
8d08fdba MS |
20 | |
21 | #include "config.h" | |
8d052bc7 | 22 | #include "system.h" |
4977bab6 ZW |
23 | #include "coretypes.h" |
24 | #include "tm.h" | |
8d08fdba MS |
25 | #include "tree.h" |
26 | #include "cp-tree.h" | |
27 | #include "flags.h" | |
25af8512 | 28 | #include "tree-inline.h" |
e58a9aa1 | 29 | #include "debug.h" |
41990f96 | 30 | #include "convert.h" |
87501227 | 31 | #include "cgraph.h" |
245763e3 | 32 | #include "splay-tree.h" |
6662d794 | 33 | #include "gimple.h" /* gimple_has_body_p */ |
703c8606 | 34 | #include "hash-table.h" |
12027a89 | 35 | |
b57b79f7 NN |
36 | static tree bot_manip (tree *, int *, void *); |
37 | static tree bot_replace (tree *, int *, void *); | |
b57b79f7 NN |
38 | static int list_hash_eq (const void *, const void *); |
39 | static hashval_t list_hash_pieces (tree, tree, tree); | |
40 | static hashval_t list_hash (const void *); | |
574cfaa4 | 41 | static tree build_target_expr (tree, tree, tsubst_flags_t); |
b57b79f7 NN |
42 | static tree count_trees_r (tree *, int *, void *); |
43 | static tree verify_stmt_tree_r (tree *, int *, void *); | |
a6f86b51 | 44 | static tree build_local_temp (tree); |
b57b79f7 NN |
45 | |
46 | static tree handle_java_interface_attribute (tree *, tree, tree, int, bool *); | |
47 | static tree handle_com_interface_attribute (tree *, tree, tree, int, bool *); | |
48 | static tree handle_init_priority_attribute (tree *, tree, tree, int, bool *); | |
7dbb85a7 | 49 | static tree handle_abi_tag_attribute (tree *, tree, tree, int, bool *); |
91d231cb | 50 | |
27b8d0cd | 51 | /* If REF is an lvalue, returns the kind of lvalue that REF is. |
df5c89cb | 52 | Otherwise, returns clk_none. */ |
8d08fdba | 53 | |
4e9ca9b0 JM |
54 | cp_lvalue_kind |
55 | lvalue_kind (const_tree ref) | |
8ccc31eb | 56 | { |
27b8d0cd MM |
57 | cp_lvalue_kind op1_lvalue_kind = clk_none; |
58 | cp_lvalue_kind op2_lvalue_kind = clk_none; | |
59 | ||
8af2fec4 RY |
60 | /* Expressions of reference type are sometimes wrapped in |
61 | INDIRECT_REFs. INDIRECT_REFs are just internal compiler | |
62 | representation, not part of the language, so we have to look | |
63 | through them. */ | |
31e292c7 | 64 | if (REFERENCE_REF_P (ref)) |
4e9ca9b0 | 65 | return lvalue_kind (TREE_OPERAND (ref, 0)); |
8af2fec4 | 66 | |
8810610e JJ |
67 | if (TREE_TYPE (ref) |
68 | && TREE_CODE (TREE_TYPE (ref)) == REFERENCE_TYPE) | |
8af2fec4 RY |
69 | { |
70 | /* unnamed rvalue references are rvalues */ | |
71 | if (TYPE_REF_IS_RVALUE (TREE_TYPE (ref)) | |
72 | && TREE_CODE (ref) != PARM_DECL | |
73 | && TREE_CODE (ref) != VAR_DECL | |
b24290fb JM |
74 | && TREE_CODE (ref) != COMPONENT_REF |
75 | /* Functions are always lvalues. */ | |
76 | && TREE_CODE (TREE_TYPE (TREE_TYPE (ref))) != FUNCTION_TYPE) | |
df5c89cb | 77 | return clk_rvalueref; |
8af2fec4 | 78 | |
d732e98f | 79 | /* lvalue references and named rvalue references are lvalues. */ |
8af2fec4 RY |
80 | return clk_ordinary; |
81 | } | |
8ccc31eb | 82 | |
394fd776 | 83 | if (ref == current_class_ptr) |
27b8d0cd | 84 | return clk_none; |
8ccc31eb MS |
85 | |
86 | switch (TREE_CODE (ref)) | |
87 | { | |
8f4361eb AP |
88 | case SAVE_EXPR: |
89 | return clk_none; | |
8ccc31eb | 90 | /* preincrements and predecrements are valid lvals, provided |
e92cc029 | 91 | what they refer to are valid lvals. */ |
8ccc31eb MS |
92 | case PREINCREMENT_EXPR: |
93 | case PREDECREMENT_EXPR: | |
c7ae64f2 JM |
94 | case TRY_CATCH_EXPR: |
95 | case WITH_CLEANUP_EXPR: | |
69851283 MM |
96 | case REALPART_EXPR: |
97 | case IMAGPART_EXPR: | |
4e9ca9b0 | 98 | return lvalue_kind (TREE_OPERAND (ref, 0)); |
8ccc31eb | 99 | |
27b8d0cd | 100 | case COMPONENT_REF: |
4e9ca9b0 | 101 | op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); |
c8b2e872 | 102 | /* Look at the member designator. */ |
4af9e878 | 103 | if (!op1_lvalue_kind) |
0cbd7506 | 104 | ; |
4af9e878 JM |
105 | else if (is_overloaded_fn (TREE_OPERAND (ref, 1))) |
106 | /* The "field" can be a FUNCTION_DECL or an OVERLOAD in some | |
b7da27c2 JM |
107 | situations. If we're seeing a COMPONENT_REF, it's a non-static |
108 | member, so it isn't an lvalue. */ | |
109 | op1_lvalue_kind = clk_none; | |
110 | else if (TREE_CODE (TREE_OPERAND (ref, 1)) != FIELD_DECL) | |
111 | /* This can be IDENTIFIER_NODE in a template. */; | |
e0d1297c | 112 | else if (DECL_C_BIT_FIELD (TREE_OPERAND (ref, 1))) |
27b8d0cd MM |
113 | { |
114 | /* Clear the ordinary bit. If this object was a class | |
115 | rvalue we want to preserve that information. */ | |
116 | op1_lvalue_kind &= ~clk_ordinary; | |
cd0be382 | 117 | /* The lvalue is for a bitfield. */ |
27b8d0cd MM |
118 | op1_lvalue_kind |= clk_bitfield; |
119 | } | |
e0d1297c NS |
120 | else if (DECL_PACKED (TREE_OPERAND (ref, 1))) |
121 | op1_lvalue_kind |= clk_packed; | |
9f63daea | 122 | |
27b8d0cd MM |
123 | return op1_lvalue_kind; |
124 | ||
8ccc31eb | 125 | case STRING_CST: |
266b4890 | 126 | case COMPOUND_LITERAL_EXPR: |
27b8d0cd | 127 | return clk_ordinary; |
8ccc31eb | 128 | |
e58a9aa1 | 129 | case CONST_DECL: |
4b8c1a92 JJ |
130 | /* CONST_DECL without TREE_STATIC are enumeration values and |
131 | thus not lvalues. With TREE_STATIC they are used by ObjC++ | |
132 | in objc_build_string_object and need to be considered as | |
133 | lvalues. */ | |
134 | if (! TREE_STATIC (ref)) | |
135 | return clk_none; | |
8ccc31eb MS |
136 | case VAR_DECL: |
137 | if (TREE_READONLY (ref) && ! TREE_STATIC (ref) | |
138 | && DECL_LANG_SPECIFIC (ref) | |
139 | && DECL_IN_AGGR_P (ref)) | |
27b8d0cd | 140 | return clk_none; |
8ccc31eb | 141 | case INDIRECT_REF: |
e87b4dde | 142 | case ARROW_EXPR: |
8ccc31eb MS |
143 | case ARRAY_REF: |
144 | case PARM_DECL: | |
145 | case RESULT_DECL: | |
ea48c8a0 | 146 | return clk_ordinary; |
8ccc31eb | 147 | |
3ee353e9 JM |
148 | /* A scope ref in a template, left as SCOPE_REF to support later |
149 | access checking. */ | |
8ccc31eb | 150 | case SCOPE_REF: |
c5c8755a JM |
151 | gcc_assert (!type_dependent_expression_p (CONST_CAST_TREE (ref))); |
152 | { | |
153 | tree op = TREE_OPERAND (ref, 1); | |
154 | if (TREE_CODE (op) == FIELD_DECL) | |
155 | return (DECL_C_BIT_FIELD (op) ? clk_bitfield : clk_ordinary); | |
156 | else | |
157 | return lvalue_kind (op); | |
158 | } | |
3ee353e9 | 159 | |
27b8d0cd MM |
160 | case MAX_EXPR: |
161 | case MIN_EXPR: | |
d211a298 RS |
162 | /* Disallow <? and >? as lvalues if either argument side-effects. */ |
163 | if (TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 0)) | |
164 | || TREE_SIDE_EFFECTS (TREE_OPERAND (ref, 1))) | |
165 | return clk_none; | |
4e9ca9b0 JM |
166 | op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 0)); |
167 | op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1)); | |
8ccc31eb MS |
168 | break; |
169 | ||
170 | case COND_EXPR: | |
4e9ca9b0 | 171 | op1_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 1) |
42924ed7 | 172 | ? TREE_OPERAND (ref, 1) |
df5c89cb | 173 | : TREE_OPERAND (ref, 0)); |
4e9ca9b0 | 174 | op2_lvalue_kind = lvalue_kind (TREE_OPERAND (ref, 2)); |
27b8d0cd | 175 | break; |
8ccc31eb MS |
176 | |
177 | case MODIFY_EXPR: | |
e87b4dde | 178 | case TYPEID_EXPR: |
27b8d0cd | 179 | return clk_ordinary; |
8ccc31eb MS |
180 | |
181 | case COMPOUND_EXPR: | |
4e9ca9b0 | 182 | return lvalue_kind (TREE_OPERAND (ref, 1)); |
69851283 MM |
183 | |
184 | case TARGET_EXPR: | |
df5c89cb | 185 | return clk_class; |
69851283 | 186 | |
356955cf | 187 | case VA_ARG_EXPR: |
df5c89cb | 188 | return (CLASS_TYPE_P (TREE_TYPE (ref)) ? clk_class : clk_none); |
c0ad5a31 MM |
189 | |
190 | case CALL_EXPR: | |
e87b4dde JM |
191 | /* We can see calls outside of TARGET_EXPR in templates. */ |
192 | if (CLASS_TYPE_P (TREE_TYPE (ref))) | |
193 | return clk_class; | |
4e8dca1c | 194 | return clk_none; |
69851283 MM |
195 | |
196 | case FUNCTION_DECL: | |
197 | /* All functions (except non-static-member functions) are | |
198 | lvalues. */ | |
9f63daea | 199 | return (DECL_NONSTATIC_MEMBER_FUNCTION_P (ref) |
27b8d0cd | 200 | ? clk_none : clk_ordinary); |
7f85441b | 201 | |
4af9e878 JM |
202 | case BASELINK: |
203 | /* We now represent a reference to a single static member function | |
204 | with a BASELINK. */ | |
1e4ae551 MLI |
205 | /* This CONST_CAST is okay because BASELINK_FUNCTIONS returns |
206 | its argument unmodified and we assign it to a const_tree. */ | |
4e9ca9b0 | 207 | return lvalue_kind (BASELINK_FUNCTIONS (CONST_CAST_TREE (ref))); |
4af9e878 | 208 | |
d17811fd | 209 | case NON_DEPENDENT_EXPR: |
ca8dc274 JM |
210 | /* We just return clk_ordinary for NON_DEPENDENT_EXPR in C++98, but |
211 | in C++11 lvalues don't bind to rvalue references, so we need to | |
212 | work harder to avoid bogus errors (c++/44870). */ | |
213 | if (cxx_dialect < cxx0x) | |
214 | return clk_ordinary; | |
215 | else | |
216 | return lvalue_kind (TREE_OPERAND (ref, 0)); | |
d17811fd | 217 | |
7f85441b | 218 | default: |
e87b4dde JM |
219 | if (!TREE_TYPE (ref)) |
220 | return clk_none; | |
221 | if (CLASS_TYPE_P (TREE_TYPE (ref))) | |
222 | return clk_class; | |
7f85441b | 223 | break; |
8ccc31eb MS |
224 | } |
225 | ||
27b8d0cd MM |
226 | /* If one operand is not an lvalue at all, then this expression is |
227 | not an lvalue. */ | |
228 | if (!op1_lvalue_kind || !op2_lvalue_kind) | |
229 | return clk_none; | |
230 | ||
231 | /* Otherwise, it's an lvalue, and it has all the odd properties | |
232 | contributed by either operand. */ | |
233 | op1_lvalue_kind = op1_lvalue_kind | op2_lvalue_kind; | |
9771799c | 234 | /* It's not an ordinary lvalue if it involves any other kind. */ |
27b8d0cd MM |
235 | if ((op1_lvalue_kind & ~clk_ordinary) != clk_none) |
236 | op1_lvalue_kind &= ~clk_ordinary; | |
9771799c JM |
237 | /* It can't be both a pseudo-lvalue and a non-addressable lvalue. |
238 | A COND_EXPR of those should be wrapped in a TARGET_EXPR. */ | |
239 | if ((op1_lvalue_kind & (clk_rvalueref|clk_class)) | |
240 | && (op1_lvalue_kind & (clk_bitfield|clk_packed))) | |
241 | op1_lvalue_kind = clk_none; | |
27b8d0cd | 242 | return op1_lvalue_kind; |
8ccc31eb MS |
243 | } |
244 | ||
aa6e8ed3 MM |
245 | /* Returns the kind of lvalue that REF is, in the sense of |
246 | [basic.lval]. This function should really be named lvalue_p; it | |
247 | computes the C++ definition of lvalue. */ | |
248 | ||
249 | cp_lvalue_kind | |
4e9ca9b0 | 250 | real_lvalue_p (const_tree ref) |
aa6e8ed3 | 251 | { |
4e9ca9b0 | 252 | cp_lvalue_kind kind = lvalue_kind (ref); |
df5c89cb JM |
253 | if (kind & (clk_rvalueref|clk_class)) |
254 | return clk_none; | |
255 | else | |
256 | return kind; | |
aa6e8ed3 MM |
257 | } |
258 | ||
df5c89cb JM |
259 | /* This differs from real_lvalue_p in that class rvalues are considered |
260 | lvalues. */ | |
69851283 | 261 | |
1e4ae551 MLI |
262 | bool |
263 | lvalue_p (const_tree ref) | |
8d08fdba | 264 | { |
4e9ca9b0 | 265 | return (lvalue_kind (ref) != clk_none); |
df5c89cb JM |
266 | } |
267 | ||
268 | /* This differs from real_lvalue_p in that rvalues formed by dereferencing | |
269 | rvalue references are considered rvalues. */ | |
270 | ||
271 | bool | |
272 | lvalue_or_rvalue_with_address_p (const_tree ref) | |
273 | { | |
4e9ca9b0 | 274 | cp_lvalue_kind kind = lvalue_kind (ref); |
df5c89cb JM |
275 | if (kind & clk_class) |
276 | return false; | |
277 | else | |
278 | return (kind != clk_none); | |
6c6e776d MA |
279 | } |
280 | ||
04398fa8 PC |
281 | /* Returns true if REF is an xvalue, false otherwise. */ |
282 | ||
283 | bool | |
284 | xvalue_p (const_tree ref) | |
285 | { | |
286 | return (lvalue_kind (ref) == clk_rvalueref); | |
287 | } | |
288 | ||
100d337a MA |
289 | /* Test whether DECL is a builtin that may appear in a |
290 | constant-expression. */ | |
291 | ||
292 | bool | |
58f9752a | 293 | builtin_valid_in_constant_expr_p (const_tree decl) |
100d337a MA |
294 | { |
295 | /* At present BUILT_IN_CONSTANT_P is the only builtin we're allowing | |
296 | in constant-expressions. We may want to add other builtins later. */ | |
88a7beb7 | 297 | return DECL_IS_BUILTIN_CONSTANT_P (decl); |
100d337a MA |
298 | } |
299 | ||
c506ca22 MM |
300 | /* Build a TARGET_EXPR, initializing the DECL with the VALUE. */ |
301 | ||
302 | static tree | |
574cfaa4 | 303 | build_target_expr (tree decl, tree value, tsubst_flags_t complain) |
c506ca22 MM |
304 | { |
305 | tree t; | |
30fdd4f2 | 306 | tree type = TREE_TYPE (decl); |
04941f76 AO |
307 | |
308 | #ifdef ENABLE_CHECKING | |
309 | gcc_assert (VOID_TYPE_P (TREE_TYPE (value)) | |
310 | || TREE_TYPE (decl) == TREE_TYPE (value) | |
22d60ad2 JM |
311 | /* On ARM ctors return 'this'. */ |
312 | || (TREE_CODE (TREE_TYPE (value)) == POINTER_TYPE | |
313 | && TREE_CODE (value) == CALL_EXPR) | |
04941f76 AO |
314 | || useless_type_conversion_p (TREE_TYPE (decl), |
315 | TREE_TYPE (value))); | |
316 | #endif | |
c506ca22 | 317 | |
574cfaa4 JM |
318 | t = cxx_maybe_build_cleanup (decl, complain); |
319 | if (t == error_mark_node) | |
320 | return error_mark_node; | |
30fdd4f2 | 321 | t = build4 (TARGET_EXPR, type, decl, value, t, NULL_TREE); |
c506ca22 MM |
322 | /* We always set TREE_SIDE_EFFECTS so that expand_expr does not |
323 | ignore the TARGET_EXPR. If there really turn out to be no | |
324 | side-effects, then the optimizer should be able to get rid of | |
325 | whatever code is generated anyhow. */ | |
326 | TREE_SIDE_EFFECTS (t) = 1; | |
327 | ||
328 | return t; | |
329 | } | |
330 | ||
a6f86b51 JM |
331 | /* Return an undeclared local temporary of type TYPE for use in building a |
332 | TARGET_EXPR. */ | |
333 | ||
334 | static tree | |
335 | build_local_temp (tree type) | |
336 | { | |
c2255bc4 AH |
337 | tree slot = build_decl (input_location, |
338 | VAR_DECL, NULL_TREE, type); | |
a6f86b51 | 339 | DECL_ARTIFICIAL (slot) = 1; |
78e0d62b | 340 | DECL_IGNORED_P (slot) = 1; |
a6f86b51 JM |
341 | DECL_CONTEXT (slot) = current_function_decl; |
342 | layout_decl (slot, 0); | |
343 | return slot; | |
344 | } | |
345 | ||
5039610b SL |
346 | /* Set various status flags when building an AGGR_INIT_EXPR object T. */ |
347 | ||
348 | static void | |
349 | process_aggr_init_operands (tree t) | |
350 | { | |
351 | bool side_effects; | |
352 | ||
353 | side_effects = TREE_SIDE_EFFECTS (t); | |
354 | if (!side_effects) | |
355 | { | |
356 | int i, n; | |
357 | n = TREE_OPERAND_LENGTH (t); | |
358 | for (i = 1; i < n; i++) | |
359 | { | |
360 | tree op = TREE_OPERAND (t, i); | |
361 | if (op && TREE_SIDE_EFFECTS (op)) | |
362 | { | |
363 | side_effects = 1; | |
364 | break; | |
365 | } | |
366 | } | |
367 | } | |
368 | TREE_SIDE_EFFECTS (t) = side_effects; | |
369 | } | |
370 | ||
371 | /* Build an AGGR_INIT_EXPR of class tcc_vl_exp with the indicated RETURN_TYPE, | |
372 | FN, and SLOT. NARGS is the number of call arguments which are specified | |
373 | as a tree array ARGS. */ | |
374 | ||
375 | static tree | |
376 | build_aggr_init_array (tree return_type, tree fn, tree slot, int nargs, | |
377 | tree *args) | |
378 | { | |
379 | tree t; | |
380 | int i; | |
381 | ||
382 | t = build_vl_exp (AGGR_INIT_EXPR, nargs + 3); | |
383 | TREE_TYPE (t) = return_type; | |
384 | AGGR_INIT_EXPR_FN (t) = fn; | |
385 | AGGR_INIT_EXPR_SLOT (t) = slot; | |
386 | for (i = 0; i < nargs; i++) | |
387 | AGGR_INIT_EXPR_ARG (t, i) = args[i]; | |
388 | process_aggr_init_operands (t); | |
389 | return t; | |
390 | } | |
391 | ||
392 | /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its | |
844ae01d | 393 | target. TYPE is the type to be initialized. |
8d08fdba | 394 | |
844ae01d JM |
395 | Build an AGGR_INIT_EXPR to represent the initialization. This function |
396 | differs from build_cplus_new in that an AGGR_INIT_EXPR can only be used | |
397 | to initialize another object, whereas a TARGET_EXPR can either | |
398 | initialize another object or create its own temporary object, and as a | |
399 | result building up a TARGET_EXPR requires that the type's destructor be | |
400 | callable. */ | |
e92cc029 | 401 | |
8d08fdba | 402 | tree |
094484e7 | 403 | build_aggr_init_expr (tree type, tree init) |
8d08fdba | 404 | { |
e1376b00 | 405 | tree fn; |
e8abc66f MS |
406 | tree slot; |
407 | tree rval; | |
4977bab6 | 408 | int is_ctor; |
e8abc66f | 409 | |
e4d7d8cb JM |
410 | /* Don't build AGGR_INIT_EXPR in a template. */ |
411 | if (processing_template_decl) | |
412 | return init; | |
413 | ||
5039610b SL |
414 | if (TREE_CODE (init) == CALL_EXPR) |
415 | fn = CALL_EXPR_FN (init); | |
416 | else if (TREE_CODE (init) == AGGR_INIT_EXPR) | |
417 | fn = AGGR_INIT_EXPR_FN (init); | |
418 | else | |
06126ca2 | 419 | return convert (type, init); |
c11b6f21 | 420 | |
4977bab6 ZW |
421 | is_ctor = (TREE_CODE (fn) == ADDR_EXPR |
422 | && TREE_CODE (TREE_OPERAND (fn, 0)) == FUNCTION_DECL | |
423 | && DECL_CONSTRUCTOR_P (TREE_OPERAND (fn, 0))); | |
424 | ||
e1376b00 MM |
425 | /* We split the CALL_EXPR into its function and its arguments here. |
426 | Then, in expand_expr, we put them back together. The reason for | |
427 | this is that this expression might be a default argument | |
428 | expression. In that case, we need a new temporary every time the | |
429 | expression is used. That's what break_out_target_exprs does; it | |
430 | replaces every AGGR_INIT_EXPR with a copy that uses a fresh | |
431 | temporary slot. Then, expand_expr builds up a call-expression | |
432 | using the new slot. */ | |
4977bab6 ZW |
433 | |
434 | /* If we don't need to use a constructor to create an object of this | |
435 | type, don't mess with AGGR_INIT_EXPR. */ | |
436 | if (is_ctor || TREE_ADDRESSABLE (type)) | |
437 | { | |
844ae01d JM |
438 | slot = build_local_temp (type); |
439 | ||
5039610b SL |
440 | if (TREE_CODE(init) == CALL_EXPR) |
441 | rval = build_aggr_init_array (void_type_node, fn, slot, | |
442 | call_expr_nargs (init), | |
443 | CALL_EXPR_ARGP (init)); | |
444 | else | |
445 | rval = build_aggr_init_array (void_type_node, fn, slot, | |
446 | aggr_init_expr_nargs (init), | |
447 | AGGR_INIT_EXPR_ARGP (init)); | |
4977bab6 ZW |
448 | TREE_SIDE_EFFECTS (rval) = 1; |
449 | AGGR_INIT_VIA_CTOR_P (rval) = is_ctor; | |
d8a0d13e | 450 | TREE_NOTHROW (rval) = TREE_NOTHROW (init); |
4977bab6 ZW |
451 | } |
452 | else | |
453 | rval = init; | |
454 | ||
844ae01d JM |
455 | return rval; |
456 | } | |
457 | ||
458 | /* INIT is a CALL_EXPR or AGGR_INIT_EXPR which needs info about its | |
459 | target. TYPE is the type that this initialization should appear to | |
460 | have. | |
461 | ||
462 | Build an encapsulation of the initialization to perform | |
463 | and return it so that it can be processed by language-independent | |
464 | and language-specific expression expanders. */ | |
465 | ||
466 | tree | |
362115a9 | 467 | build_cplus_new (tree type, tree init, tsubst_flags_t complain) |
844ae01d | 468 | { |
094484e7 | 469 | tree rval = build_aggr_init_expr (type, init); |
844ae01d JM |
470 | tree slot; |
471 | ||
0ed4ab44 JM |
472 | /* Make sure that we're not trying to create an instance of an |
473 | abstract class. */ | |
474 | if (abstract_virtuals_error_sfinae (NULL_TREE, type, complain)) | |
475 | return error_mark_node; | |
476 | ||
844ae01d JM |
477 | if (TREE_CODE (rval) == AGGR_INIT_EXPR) |
478 | slot = AGGR_INIT_EXPR_SLOT (rval); | |
236fd18c JM |
479 | else if (TREE_CODE (rval) == CALL_EXPR |
480 | || TREE_CODE (rval) == CONSTRUCTOR) | |
844ae01d JM |
481 | slot = build_local_temp (type); |
482 | else | |
483 | return rval; | |
484 | ||
574cfaa4 | 485 | rval = build_target_expr (slot, rval, complain); |
a6343f61 PC |
486 | |
487 | if (rval != error_mark_node) | |
488 | TARGET_EXPR_IMPLICIT_P (rval) = 1; | |
8d08fdba | 489 | |
8d08fdba MS |
490 | return rval; |
491 | } | |
492 | ||
262a7d6b JM |
493 | /* Subroutine of build_vec_init_expr: Build up a single element |
494 | intialization as a proxy for the full array initialization to get things | |
495 | marked as used and any appropriate diagnostics. | |
496 | ||
497 | Since we're deferring building the actual constructor calls until | |
498 | gimplification time, we need to build one now and throw it away so | |
499 | that the relevant constructor gets mark_used before cgraph decides | |
500 | what functions are needed. Here we assume that init is either | |
501 | NULL_TREE, void_type_node (indicating value-initialization), or | |
502 | another array to copy. */ | |
503 | ||
504 | static tree | |
9c69dcea | 505 | build_vec_init_elt (tree type, tree init, tsubst_flags_t complain) |
262a7d6b | 506 | { |
b73a4704 | 507 | tree inner_type = strip_array_types (type); |
9771b263 | 508 | vec<tree, va_gc> *argvec; |
262a7d6b | 509 | |
b73a4704 JM |
510 | if (integer_zerop (array_type_nelts_total (type)) |
511 | || !CLASS_TYPE_P (inner_type)) | |
262a7d6b JM |
512 | /* No interesting initialization to do. */ |
513 | return integer_zero_node; | |
514 | else if (init == void_type_node) | |
9c69dcea | 515 | return build_value_init (inner_type, complain); |
262a7d6b | 516 | |
b73a4704 JM |
517 | gcc_assert (init == NULL_TREE |
518 | || (same_type_ignoring_top_level_qualifiers_p | |
519 | (type, TREE_TYPE (init)))); | |
520 | ||
521 | argvec = make_tree_vector (); | |
522 | if (init) | |
262a7d6b | 523 | { |
01290963 JM |
524 | tree init_type = strip_array_types (TREE_TYPE (init)); |
525 | tree dummy = build_dummy_object (init_type); | |
262a7d6b JM |
526 | if (!real_lvalue_p (init)) |
527 | dummy = move (dummy); | |
9771b263 | 528 | argvec->quick_push (dummy); |
262a7d6b | 529 | } |
9c69dcea | 530 | init = build_special_member_call (NULL_TREE, complete_ctor_identifier, |
262a7d6b | 531 | &argvec, inner_type, LOOKUP_NORMAL, |
9c69dcea JM |
532 | complain); |
533 | release_tree_vector (argvec); | |
534 | ||
20888def JM |
535 | /* For a trivial constructor, build_over_call creates a TARGET_EXPR. But |
536 | we don't want one here because we aren't creating a temporary. */ | |
537 | if (TREE_CODE (init) == TARGET_EXPR) | |
538 | init = TARGET_EXPR_INITIAL (init); | |
539 | ||
9c69dcea | 540 | return init; |
262a7d6b JM |
541 | } |
542 | ||
b73a4704 JM |
543 | /* Return a TARGET_EXPR which expresses the initialization of an array to |
544 | be named later, either default-initialization or copy-initialization | |
545 | from another array of the same type. */ | |
d5f4eddd JM |
546 | |
547 | tree | |
9c69dcea | 548 | build_vec_init_expr (tree type, tree init, tsubst_flags_t complain) |
d5f4eddd | 549 | { |
b73a4704 | 550 | tree slot; |
4de2f020 | 551 | bool value_init = false; |
9c69dcea | 552 | tree elt_init = build_vec_init_elt (type, init, complain); |
534ecb17 | 553 | |
262a7d6b | 554 | if (init == void_type_node) |
534ecb17 | 555 | { |
4de2f020 JM |
556 | value_init = true; |
557 | init = NULL_TREE; | |
558 | } | |
534ecb17 | 559 | |
b73a4704 JM |
560 | slot = build_local_temp (type); |
561 | init = build2 (VEC_INIT_EXPR, type, slot, init); | |
0a2cdfe6 | 562 | TREE_SIDE_EFFECTS (init) = true; |
d5f4eddd | 563 | SET_EXPR_LOCATION (init, input_location); |
4de2f020 | 564 | |
262a7d6b JM |
565 | if (cxx_dialect >= cxx0x |
566 | && potential_constant_expression (elt_init)) | |
567 | VEC_INIT_EXPR_IS_CONSTEXPR (init) = true; | |
4de2f020 JM |
568 | VEC_INIT_EXPR_VALUE_INIT (init) = value_init; |
569 | ||
d5f4eddd JM |
570 | return init; |
571 | } | |
572 | ||
262a7d6b JM |
573 | /* Give a helpful diagnostic for a non-constexpr VEC_INIT_EXPR in a context |
574 | that requires a constant expression. */ | |
575 | ||
576 | void | |
577 | diagnose_non_constexpr_vec_init (tree expr) | |
578 | { | |
579 | tree type = TREE_TYPE (VEC_INIT_EXPR_SLOT (expr)); | |
580 | tree init, elt_init; | |
581 | if (VEC_INIT_EXPR_VALUE_INIT (expr)) | |
7ac37b96 | 582 | init = void_type_node; |
262a7d6b JM |
583 | else |
584 | init = VEC_INIT_EXPR_INIT (expr); | |
585 | ||
9c69dcea | 586 | elt_init = build_vec_init_elt (type, init, tf_warning_or_error); |
262a7d6b JM |
587 | require_potential_constant_expression (elt_init); |
588 | } | |
589 | ||
534ecb17 JM |
590 | tree |
591 | build_array_copy (tree init) | |
592 | { | |
9c69dcea | 593 | return build_vec_init_expr (TREE_TYPE (init), init, tf_warning_or_error); |
534ecb17 JM |
594 | } |
595 | ||
ab93b543 | 596 | /* Build a TARGET_EXPR using INIT to initialize a new temporary of the |
c506ca22 | 597 | indicated TYPE. */ |
aa36c081 JM |
598 | |
599 | tree | |
574cfaa4 | 600 | build_target_expr_with_type (tree init, tree type, tsubst_flags_t complain) |
aa36c081 | 601 | { |
50bc768d | 602 | gcc_assert (!VOID_TYPE_P (type)); |
59445d74 | 603 | |
309714d4 JM |
604 | if (TREE_CODE (init) == TARGET_EXPR |
605 | || init == error_mark_node) | |
5062dbd5 | 606 | return init; |
d758e847 | 607 | else if (CLASS_TYPE_P (type) && type_has_nontrivial_copy_init (type) |
7efc22ea | 608 | && !VOID_TYPE_P (TREE_TYPE (init)) |
4b5aa881 | 609 | && TREE_CODE (init) != COND_EXPR |
662eceda MM |
610 | && TREE_CODE (init) != CONSTRUCTOR |
611 | && TREE_CODE (init) != VA_ARG_EXPR) | |
7efc22ea JM |
612 | /* We need to build up a copy constructor call. A void initializer |
613 | means we're being called from bot_manip. COND_EXPR is a special | |
182609b5 | 614 | case because we already have copies on the arms and we don't want |
4b5aa881 | 615 | another one here. A CONSTRUCTOR is aggregate initialization, which |
662eceda MM |
616 | is handled separately. A VA_ARG_EXPR is magic creation of an |
617 | aggregate; there's no additional work to be done. */ | |
574cfaa4 | 618 | return force_rvalue (init, complain); |
5062dbd5 | 619 | |
574cfaa4 | 620 | return force_target_expr (type, init, complain); |
a6f86b51 | 621 | } |
aa36c081 | 622 | |
a6f86b51 JM |
623 | /* Like the above function, but without the checking. This function should |
624 | only be used by code which is deliberately trying to subvert the type | |
d758e847 JM |
625 | system, such as call_builtin_trap. Or build_over_call, to avoid |
626 | infinite recursion. */ | |
a6f86b51 JM |
627 | |
628 | tree | |
574cfaa4 | 629 | force_target_expr (tree type, tree init, tsubst_flags_t complain) |
a6f86b51 | 630 | { |
59445d74 RH |
631 | tree slot; |
632 | ||
50bc768d | 633 | gcc_assert (!VOID_TYPE_P (type)); |
59445d74 RH |
634 | |
635 | slot = build_local_temp (type); | |
574cfaa4 | 636 | return build_target_expr (slot, init, complain); |
aa36c081 JM |
637 | } |
638 | ||
c506ca22 MM |
639 | /* Like build_target_expr_with_type, but use the type of INIT. */ |
640 | ||
641 | tree | |
574cfaa4 | 642 | get_target_expr_sfinae (tree init, tsubst_flags_t complain) |
c506ca22 | 643 | { |
450a927a | 644 | if (TREE_CODE (init) == AGGR_INIT_EXPR) |
574cfaa4 | 645 | return build_target_expr (AGGR_INIT_EXPR_SLOT (init), init, complain); |
991e0156 | 646 | else if (TREE_CODE (init) == VEC_INIT_EXPR) |
574cfaa4 | 647 | return build_target_expr (VEC_INIT_EXPR_SLOT (init), init, complain); |
450a927a | 648 | else |
574cfaa4 JM |
649 | return build_target_expr_with_type (init, TREE_TYPE (init), complain); |
650 | } | |
651 | ||
652 | tree | |
653 | get_target_expr (tree init) | |
654 | { | |
655 | return get_target_expr_sfinae (init, tf_warning_or_error); | |
c506ca22 MM |
656 | } |
657 | ||
e1039697 MM |
658 | /* If EXPR is a bitfield reference, convert it to the declared type of |
659 | the bitfield, and return the resulting expression. Otherwise, | |
660 | return EXPR itself. */ | |
661 | ||
662 | tree | |
663 | convert_bitfield_to_declared_type (tree expr) | |
664 | { | |
665 | tree bitfield_type; | |
666 | ||
667 | bitfield_type = is_bitfield_expr_with_lowered_type (expr); | |
668 | if (bitfield_type) | |
41990f96 MM |
669 | expr = convert_to_integer (TYPE_MAIN_VARIANT (bitfield_type), |
670 | expr); | |
e1039697 MM |
671 | return expr; |
672 | } | |
673 | ||
5cc53d4e MM |
674 | /* EXPR is being used in an rvalue context. Return a version of EXPR |
675 | that is marked as an rvalue. */ | |
676 | ||
677 | tree | |
678 | rvalue (tree expr) | |
679 | { | |
41990f96 MM |
680 | tree type; |
681 | ||
682 | if (error_operand_p (expr)) | |
683 | return expr; | |
684 | ||
03a904b5 JJ |
685 | expr = mark_rvalue_use (expr); |
686 | ||
41990f96 MM |
687 | /* [basic.lval] |
688 | ||
689 | Non-class rvalues always have cv-unqualified types. */ | |
690 | type = TREE_TYPE (expr); | |
36c37128 JM |
691 | if (!CLASS_TYPE_P (type) && cv_qualified_p (type)) |
692 | type = cv_unqualified (type); | |
41990f96 | 693 | |
b9c6b842 JM |
694 | /* We need to do this for rvalue refs as well to get the right answer |
695 | from decltype; see c++/36628. */ | |
696 | if (!processing_template_decl && lvalue_or_rvalue_with_address_p (expr)) | |
41990f96 MM |
697 | expr = build1 (NON_LVALUE_EXPR, type, expr); |
698 | else if (type != TREE_TYPE (expr)) | |
699 | expr = build_nop (type, expr); | |
700 | ||
5cc53d4e MM |
701 | return expr; |
702 | } | |
703 | ||
8d08fdba | 704 | \f |
06d40de8 DG |
705 | /* Hash an ARRAY_TYPE. K is really of type `tree'. */ |
706 | ||
707 | static hashval_t | |
708 | cplus_array_hash (const void* k) | |
709 | { | |
710 | hashval_t hash; | |
741ac903 | 711 | const_tree const t = (const_tree) k; |
06d40de8 | 712 | |
eb9c434c JJ |
713 | hash = TYPE_UID (TREE_TYPE (t)); |
714 | if (TYPE_DOMAIN (t)) | |
715 | hash ^= TYPE_UID (TYPE_DOMAIN (t)); | |
06d40de8 DG |
716 | return hash; |
717 | } | |
718 | ||
719 | typedef struct cplus_array_info { | |
720 | tree type; | |
721 | tree domain; | |
722 | } cplus_array_info; | |
723 | ||
724 | /* Compare two ARRAY_TYPEs. K1 is really of type `tree', K2 is really | |
725 | of type `cplus_array_info*'. */ | |
726 | ||
727 | static int | |
728 | cplus_array_compare (const void * k1, const void * k2) | |
729 | { | |
741ac903 KG |
730 | const_tree const t1 = (const_tree) k1; |
731 | const cplus_array_info *const t2 = (const cplus_array_info*) k2; | |
06d40de8 | 732 | |
714f2304 | 733 | return (TREE_TYPE (t1) == t2->type && TYPE_DOMAIN (t1) == t2->domain); |
06d40de8 DG |
734 | } |
735 | ||
38e40fcd JM |
736 | /* Hash table containing dependent array types, which are unsuitable for |
737 | the language-independent type hash table. */ | |
06d40de8 DG |
738 | static GTY ((param_is (union tree_node))) htab_t cplus_array_htab; |
739 | ||
38e40fcd | 740 | /* Like build_array_type, but handle special C++ semantics. */ |
06d40de8 | 741 | |
38e40fcd JM |
742 | tree |
743 | build_cplus_array_type (tree elt_type, tree index_type) | |
8d08fdba | 744 | { |
8d08fdba MS |
745 | tree t; |
746 | ||
adecb3f4 MM |
747 | if (elt_type == error_mark_node || index_type == error_mark_node) |
748 | return error_mark_node; | |
749 | ||
6da06848 JJ |
750 | if (processing_template_decl |
751 | && (dependent_type_p (elt_type) | |
752 | || (index_type && !TREE_CONSTANT (TYPE_MAX_VALUE (index_type))))) | |
5566b478 | 753 | { |
06d40de8 DG |
754 | void **e; |
755 | cplus_array_info cai; | |
756 | hashval_t hash; | |
714f2304 | 757 | |
06d40de8 DG |
758 | if (cplus_array_htab == NULL) |
759 | cplus_array_htab = htab_create_ggc (61, &cplus_array_hash, | |
760 | &cplus_array_compare, NULL); | |
761 | ||
eb9c434c JJ |
762 | hash = TYPE_UID (elt_type); |
763 | if (index_type) | |
764 | hash ^= TYPE_UID (index_type); | |
06d40de8 DG |
765 | cai.type = elt_type; |
766 | cai.domain = index_type; | |
767 | ||
768 | e = htab_find_slot_with_hash (cplus_array_htab, &cai, hash, INSERT); | |
769 | if (*e) | |
714f2304 | 770 | /* We have found the type: we're done. */ |
06d40de8 DG |
771 | return (tree) *e; |
772 | else | |
773 | { | |
714f2304 | 774 | /* Build a new array type. */ |
7ecbca9d | 775 | t = cxx_make_type (ARRAY_TYPE); |
06d40de8 DG |
776 | TREE_TYPE (t) = elt_type; |
777 | TYPE_DOMAIN (t) = index_type; | |
778 | ||
714f2304 DG |
779 | /* Store it in the hash table. */ |
780 | *e = t; | |
781 | ||
782 | /* Set the canonical type for this new node. */ | |
06d40de8 DG |
783 | if (TYPE_STRUCTURAL_EQUALITY_P (elt_type) |
784 | || (index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type))) | |
785 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
786 | else if (TYPE_CANONICAL (elt_type) != elt_type | |
787 | || (index_type | |
788 | && TYPE_CANONICAL (index_type) != index_type)) | |
714f2304 DG |
789 | TYPE_CANONICAL (t) |
790 | = build_cplus_array_type | |
791 | (TYPE_CANONICAL (elt_type), | |
6da06848 | 792 | index_type ? TYPE_CANONICAL (index_type) : index_type); |
714f2304 DG |
793 | else |
794 | TYPE_CANONICAL (t) = t; | |
06d40de8 | 795 | } |
5566b478 MS |
796 | } |
797 | else | |
3ebc22c1 JM |
798 | { |
799 | if (!TYPE_STRUCTURAL_EQUALITY_P (elt_type) | |
800 | && !(index_type && TYPE_STRUCTURAL_EQUALITY_P (index_type)) | |
801 | && (TYPE_CANONICAL (elt_type) != elt_type | |
802 | || (index_type && TYPE_CANONICAL (index_type) != index_type))) | |
803 | /* Make sure that the canonical type is on the appropriate | |
804 | variants list. */ | |
805 | build_cplus_array_type | |
806 | (TYPE_CANONICAL (elt_type), | |
807 | index_type ? TYPE_CANONICAL (index_type) : index_type); | |
808 | t = build_array_type (elt_type, index_type); | |
809 | } | |
8d08fdba | 810 | |
e78167f2 JM |
811 | /* Push these needs up so that initialization takes place |
812 | more easily. */ | |
813 | bool needs_ctor | |
814 | = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (elt_type)); | |
815 | TYPE_NEEDS_CONSTRUCTING (t) = needs_ctor; | |
816 | bool needs_dtor | |
817 | = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (elt_type)); | |
818 | TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) = needs_dtor; | |
819 | ||
38e40fcd JM |
820 | /* We want TYPE_MAIN_VARIANT of an array to strip cv-quals from the |
821 | element type as well, so fix it up if needed. */ | |
822 | if (elt_type != TYPE_MAIN_VARIANT (elt_type)) | |
823 | { | |
824 | tree m = build_cplus_array_type (TYPE_MAIN_VARIANT (elt_type), | |
825 | index_type); | |
697c474c | 826 | |
38e40fcd JM |
827 | if (TYPE_MAIN_VARIANT (t) != m) |
828 | { | |
e78167f2 JM |
829 | if (COMPLETE_TYPE_P (t) && !COMPLETE_TYPE_P (m)) |
830 | { | |
831 | /* m was built before the element type was complete, so we | |
832 | also need to copy the layout info from t. */ | |
833 | tree size = TYPE_SIZE (t); | |
834 | tree size_unit = TYPE_SIZE_UNIT (t); | |
835 | unsigned int align = TYPE_ALIGN (t); | |
836 | unsigned int user_align = TYPE_USER_ALIGN (t); | |
837 | enum machine_mode mode = TYPE_MODE (t); | |
838 | for (tree var = m; var; var = TYPE_NEXT_VARIANT (var)) | |
839 | { | |
840 | TYPE_SIZE (var) = size; | |
841 | TYPE_SIZE_UNIT (var) = size_unit; | |
842 | TYPE_ALIGN (var) = align; | |
843 | TYPE_USER_ALIGN (var) = user_align; | |
844 | SET_TYPE_MODE (var, mode); | |
845 | TYPE_NEEDS_CONSTRUCTING (var) = needs_ctor; | |
846 | TYPE_HAS_NONTRIVIAL_DESTRUCTOR (var) = needs_dtor; | |
847 | } | |
848 | } | |
849 | ||
38e40fcd JM |
850 | TYPE_MAIN_VARIANT (t) = m; |
851 | TYPE_NEXT_VARIANT (t) = TYPE_NEXT_VARIANT (m); | |
852 | TYPE_NEXT_VARIANT (m) = t; | |
853 | } | |
854 | } | |
855 | ||
03d31730 PC |
856 | /* Avoid spurious warnings with VLAs (c++/54583). */ |
857 | if (TYPE_SIZE (t) && EXPR_P (TYPE_SIZE (t))) | |
858 | TREE_NO_WARNING (TYPE_SIZE (t)) = 1; | |
859 | ||
8d08fdba MS |
860 | return t; |
861 | } | |
e349ee73 | 862 | |
09357846 JM |
863 | /* Return an ARRAY_TYPE with element type ELT and length N. */ |
864 | ||
865 | tree | |
866 | build_array_of_n_type (tree elt, int n) | |
867 | { | |
868 | return build_cplus_array_type (elt, build_index_type (size_int (n - 1))); | |
869 | } | |
870 | ||
8af2fec4 RY |
871 | /* Return a reference type node referring to TO_TYPE. If RVAL is |
872 | true, return an rvalue reference type, otherwise return an lvalue | |
873 | reference type. If a type node exists, reuse it, otherwise create | |
874 | a new one. */ | |
875 | tree | |
876 | cp_build_reference_type (tree to_type, bool rval) | |
877 | { | |
878 | tree lvalue_ref, t; | |
879 | lvalue_ref = build_reference_type (to_type); | |
880 | if (!rval) | |
881 | return lvalue_ref; | |
882 | ||
883 | /* This code to create rvalue reference types is based on and tied | |
884 | to the code creating lvalue reference types in the middle-end | |
885 | functions build_reference_type_for_mode and build_reference_type. | |
886 | ||
887 | It works by putting the rvalue reference type nodes after the | |
888 | lvalue reference nodes in the TYPE_NEXT_REF_TO linked list, so | |
889 | they will effectively be ignored by the middle end. */ | |
890 | ||
891 | for (t = lvalue_ref; (t = TYPE_NEXT_REF_TO (t)); ) | |
892 | if (TYPE_REF_IS_RVALUE (t)) | |
893 | return t; | |
894 | ||
22521c89 | 895 | t = build_distinct_type_copy (lvalue_ref); |
8af2fec4 RY |
896 | |
897 | TYPE_REF_IS_RVALUE (t) = true; | |
898 | TYPE_NEXT_REF_TO (t) = TYPE_NEXT_REF_TO (lvalue_ref); | |
899 | TYPE_NEXT_REF_TO (lvalue_ref) = t; | |
8af2fec4 RY |
900 | |
901 | if (TYPE_STRUCTURAL_EQUALITY_P (to_type)) | |
902 | SET_TYPE_STRUCTURAL_EQUALITY (t); | |
903 | else if (TYPE_CANONICAL (to_type) != to_type) | |
904 | TYPE_CANONICAL (t) | |
905 | = cp_build_reference_type (TYPE_CANONICAL (to_type), rval); | |
906 | else | |
907 | TYPE_CANONICAL (t) = t; | |
908 | ||
909 | layout_type (t); | |
910 | ||
911 | return t; | |
912 | ||
913 | } | |
914 | ||
d5f4eddd JM |
915 | /* Returns EXPR cast to rvalue reference type, like std::move. */ |
916 | ||
917 | tree | |
918 | move (tree expr) | |
919 | { | |
920 | tree type = TREE_TYPE (expr); | |
921 | gcc_assert (TREE_CODE (type) != REFERENCE_TYPE); | |
922 | type = cp_build_reference_type (type, /*rval*/true); | |
923 | return build_static_cast (type, expr, tf_warning_or_error); | |
924 | } | |
925 | ||
9ae165a0 DG |
926 | /* Used by the C++ front end to build qualified array types. However, |
927 | the C version of this function does not properly maintain canonical | |
928 | types (which are not used in C). */ | |
929 | tree | |
930 | c_build_qualified_type (tree type, int type_quals) | |
931 | { | |
932 | return cp_build_qualified_type (type, type_quals); | |
933 | } | |
8af2fec4 | 934 | |
8d08fdba | 935 | \f |
adecb3f4 MM |
936 | /* Make a variant of TYPE, qualified with the TYPE_QUALS. Handles |
937 | arrays correctly. In particular, if TYPE is an array of T's, and | |
c2ea3a40 | 938 | TYPE_QUALS is non-empty, returns an array of qualified T's. |
9f63daea | 939 | |
39a13be5 | 940 | FLAGS determines how to deal with ill-formed qualifications. If |
4f2b0fb2 NS |
941 | tf_ignore_bad_quals is set, then bad qualifications are dropped |
942 | (this is permitted if TYPE was introduced via a typedef or template | |
943 | type parameter). If bad qualifications are dropped and tf_warning | |
944 | is set, then a warning is issued for non-const qualifications. If | |
945 | tf_ignore_bad_quals is not set and tf_error is not set, we | |
946 | return error_mark_node. Otherwise, we issue an error, and ignore | |
947 | the qualifications. | |
948 | ||
949 | Qualification of a reference type is valid when the reference came | |
950 | via a typedef or template type argument. [dcl.ref] No such | |
951 | dispensation is provided for qualifying a function type. [dcl.fct] | |
952 | DR 295 queries this and the proposed resolution brings it into line | |
34cd5ae7 | 953 | with qualifying a reference. We implement the DR. We also behave |
4f2b0fb2 | 954 | in a similar manner for restricting non-pointer types. */ |
9f63daea | 955 | |
f376e137 | 956 | tree |
9f63daea | 957 | cp_build_qualified_type_real (tree type, |
0cbd7506 MS |
958 | int type_quals, |
959 | tsubst_flags_t complain) | |
f376e137 | 960 | { |
2adeacc9 | 961 | tree result; |
4f2b0fb2 | 962 | int bad_quals = TYPE_UNQUALIFIED; |
2adeacc9 | 963 | |
e76a2646 MS |
964 | if (type == error_mark_node) |
965 | return type; | |
e271912d | 966 | |
89d684bb | 967 | if (type_quals == cp_type_quals (type)) |
e271912d JM |
968 | return type; |
969 | ||
4f2b0fb2 | 970 | if (TREE_CODE (type) == ARRAY_TYPE) |
f376e137 | 971 | { |
db3626d1 MM |
972 | /* In C++, the qualification really applies to the array element |
973 | type. Obtain the appropriately qualified element type. */ | |
974 | tree t; | |
9f63daea EC |
975 | tree element_type |
976 | = cp_build_qualified_type_real (TREE_TYPE (type), | |
db3626d1 MM |
977 | type_quals, |
978 | complain); | |
979 | ||
980 | if (element_type == error_mark_node) | |
adecb3f4 | 981 | return error_mark_node; |
f376e137 | 982 | |
38e40fcd JM |
983 | /* See if we already have an identically qualified type. Tests |
984 | should be equivalent to those in check_qualified_type. */ | |
29fae15c | 985 | for (t = TYPE_MAIN_VARIANT (type); t; t = TYPE_NEXT_VARIANT (t)) |
ef765996 | 986 | if (TREE_TYPE (t) == element_type |
29fae15c | 987 | && TYPE_NAME (t) == TYPE_NAME (type) |
38e40fcd JM |
988 | && TYPE_CONTEXT (t) == TYPE_CONTEXT (type) |
989 | && attribute_list_equal (TYPE_ATTRIBUTES (t), | |
990 | TYPE_ATTRIBUTES (type))) | |
29fae15c | 991 | break; |
9f63daea | 992 | |
29fae15c | 993 | if (!t) |
38e40fcd JM |
994 | { |
995 | t = build_cplus_array_type (element_type, TYPE_DOMAIN (type)); | |
996 | ||
997 | /* Keep the typedef name. */ | |
998 | if (TYPE_NAME (t) != TYPE_NAME (type)) | |
999 | { | |
1000 | t = build_variant_type_copy (t); | |
1001 | TYPE_NAME (t) = TYPE_NAME (type); | |
1002 | } | |
1003 | } | |
f376e137 | 1004 | |
db3626d1 | 1005 | /* Even if we already had this variant, we update |
834c6dff | 1006 | TYPE_NEEDS_CONSTRUCTING and TYPE_HAS_NONTRIVIAL_DESTRUCTOR in case |
9f63daea EC |
1007 | they changed since the variant was originally created. |
1008 | ||
db3626d1 MM |
1009 | This seems hokey; if there is some way to use a previous |
1010 | variant *without* coming through here, | |
1011 | TYPE_NEEDS_CONSTRUCTING will never be updated. */ | |
9f63daea | 1012 | TYPE_NEEDS_CONSTRUCTING (t) |
db3626d1 | 1013 | = TYPE_NEEDS_CONSTRUCTING (TYPE_MAIN_VARIANT (element_type)); |
9f63daea | 1014 | TYPE_HAS_NONTRIVIAL_DESTRUCTOR (t) |
834c6dff | 1015 | = TYPE_HAS_NONTRIVIAL_DESTRUCTOR (TYPE_MAIN_VARIANT (element_type)); |
db3626d1 | 1016 | return t; |
f376e137 | 1017 | } |
2adeacc9 MM |
1018 | else if (TYPE_PTRMEMFUNC_P (type)) |
1019 | { | |
1020 | /* For a pointer-to-member type, we can't just return a | |
1021 | cv-qualified version of the RECORD_TYPE. If we do, we | |
4f2b0fb2 | 1022 | haven't changed the field that contains the actual pointer to |
2adeacc9 MM |
1023 | a method, and so TYPE_PTRMEMFUNC_FN_TYPE will be wrong. */ |
1024 | tree t; | |
1025 | ||
1026 | t = TYPE_PTRMEMFUNC_FN_TYPE (type); | |
1027 | t = cp_build_qualified_type_real (t, type_quals, complain); | |
46cbda4a | 1028 | return build_ptrmemfunc_type (t); |
2adeacc9 | 1029 | } |
9a3c2683 JJ |
1030 | else if (TREE_CODE (type) == TYPE_PACK_EXPANSION) |
1031 | { | |
1032 | tree t = PACK_EXPANSION_PATTERN (type); | |
1033 | ||
1034 | t = cp_build_qualified_type_real (t, type_quals, complain); | |
1035 | return make_pack_expansion (t); | |
1036 | } | |
9f63daea | 1037 | |
39a13be5 | 1038 | /* A reference or method type shall not be cv-qualified. |
93e1ddcf JM |
1039 | [dcl.ref], [dcl.fct]. This used to be an error, but as of DR 295 |
1040 | (in CD1) we always ignore extra cv-quals on functions. */ | |
4b011bbf JM |
1041 | if (type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE) |
1042 | && (TREE_CODE (type) == REFERENCE_TYPE | |
2872152c | 1043 | || TREE_CODE (type) == FUNCTION_TYPE |
4b011bbf JM |
1044 | || TREE_CODE (type) == METHOD_TYPE)) |
1045 | { | |
93e1ddcf JM |
1046 | if (TREE_CODE (type) == REFERENCE_TYPE) |
1047 | bad_quals |= type_quals & (TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); | |
4b011bbf JM |
1048 | type_quals &= ~(TYPE_QUAL_CONST | TYPE_QUAL_VOLATILE); |
1049 | } | |
9f63daea | 1050 | |
2872152c JM |
1051 | /* But preserve any function-cv-quals on a FUNCTION_TYPE. */ |
1052 | if (TREE_CODE (type) == FUNCTION_TYPE) | |
1053 | type_quals |= type_memfn_quals (type); | |
1054 | ||
4b011bbf | 1055 | /* A restrict-qualified type must be a pointer (or reference) |
0d9c0892 | 1056 | to object or incomplete type. */ |
4b011bbf JM |
1057 | if ((type_quals & TYPE_QUAL_RESTRICT) |
1058 | && TREE_CODE (type) != TEMPLATE_TYPE_PARM | |
1059 | && TREE_CODE (type) != TYPENAME_TYPE | |
1060 | && !POINTER_TYPE_P (type)) | |
1061 | { | |
1062 | bad_quals |= TYPE_QUAL_RESTRICT; | |
1063 | type_quals &= ~TYPE_QUAL_RESTRICT; | |
1064 | } | |
1065 | ||
93e1ddcf JM |
1066 | if (bad_quals == TYPE_UNQUALIFIED |
1067 | || (complain & tf_ignore_bad_quals)) | |
4b011bbf | 1068 | /*OK*/; |
93e1ddcf | 1069 | else if (!(complain & tf_error)) |
4b011bbf | 1070 | return error_mark_node; |
4b011bbf JM |
1071 | else |
1072 | { | |
93e1ddcf JM |
1073 | tree bad_type = build_qualified_type (ptr_type_node, bad_quals); |
1074 | error ("%qV qualifiers cannot be applied to %qT", | |
1075 | bad_type, type); | |
4b011bbf | 1076 | } |
9f63daea | 1077 | |
2adeacc9 MM |
1078 | /* Retrieve (or create) the appropriately qualified variant. */ |
1079 | result = build_qualified_type (type, type_quals); | |
1080 | ||
1081 | /* If this was a pointer-to-method type, and we just made a copy, | |
3cfab7ec GK |
1082 | then we need to unshare the record that holds the cached |
1083 | pointer-to-member-function type, because these will be distinct | |
1084 | between the unqualified and qualified types. */ | |
9f63daea | 1085 | if (result != type |
2adeacc9 | 1086 | && TREE_CODE (type) == POINTER_TYPE |
0f67bdf1 JM |
1087 | && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE |
1088 | && TYPE_LANG_SPECIFIC (result) == TYPE_LANG_SPECIFIC (type)) | |
3cfab7ec | 1089 | TYPE_LANG_SPECIFIC (result) = NULL; |
2adeacc9 | 1090 | |
7aa4a1df DG |
1091 | /* We may also have ended up building a new copy of the canonical |
1092 | type of a pointer-to-method type, which could have the same | |
1093 | sharing problem described above. */ | |
1094 | if (TYPE_CANONICAL (result) != TYPE_CANONICAL (type) | |
1095 | && TREE_CODE (type) == POINTER_TYPE | |
1096 | && TREE_CODE (TREE_TYPE (type)) == METHOD_TYPE | |
1097 | && (TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result)) | |
1098 | == TYPE_LANG_SPECIFIC (TYPE_CANONICAL (type)))) | |
1099 | TYPE_LANG_SPECIFIC (TYPE_CANONICAL (result)) = NULL; | |
7aa4a1df | 1100 | |
2adeacc9 | 1101 | return result; |
f376e137 | 1102 | } |
53929c47 | 1103 | |
164247b0 JM |
1104 | /* Return TYPE with const and volatile removed. */ |
1105 | ||
1106 | tree | |
1107 | cv_unqualified (tree type) | |
1108 | { | |
ea8b8aa0 JM |
1109 | int quals; |
1110 | ||
1111 | if (type == error_mark_node) | |
1112 | return type; | |
1113 | ||
a3360e77 | 1114 | quals = cp_type_quals (type); |
164247b0 JM |
1115 | quals &= ~(TYPE_QUAL_CONST|TYPE_QUAL_VOLATILE); |
1116 | return cp_build_qualified_type (type, quals); | |
1117 | } | |
1118 | ||
cd41d410 DS |
1119 | /* Builds a qualified variant of T that is not a typedef variant. |
1120 | E.g. consider the following declarations: | |
1121 | typedef const int ConstInt; | |
1122 | typedef ConstInt* PtrConstInt; | |
1123 | If T is PtrConstInt, this function returns a type representing | |
1124 | const int*. | |
1125 | In other words, if T is a typedef, the function returns the underlying type. | |
1126 | The cv-qualification and attributes of the type returned match the | |
1127 | input type. | |
1128 | They will always be compatible types. | |
1129 | The returned type is built so that all of its subtypes | |
1130 | recursively have their typedefs stripped as well. | |
1131 | ||
1132 | This is different from just returning TYPE_CANONICAL (T) | |
1133 | Because of several reasons: | |
1134 | * If T is a type that needs structural equality | |
1135 | its TYPE_CANONICAL (T) will be NULL. | |
1136 | * TYPE_CANONICAL (T) desn't carry type attributes | |
49bb4bbe | 1137 | and loses template parameter names. */ |
53929c47 JM |
1138 | |
1139 | tree | |
cd41d410 | 1140 | strip_typedefs (tree t) |
53929c47 | 1141 | { |
cd41d410 DS |
1142 | tree result = NULL, type = NULL, t0 = NULL; |
1143 | ||
1144 | if (!t || t == error_mark_node || t == TYPE_CANONICAL (t)) | |
1145 | return t; | |
1146 | ||
1147 | gcc_assert (TYPE_P (t)); | |
1148 | ||
1149 | switch (TREE_CODE (t)) | |
1150 | { | |
1151 | case POINTER_TYPE: | |
1152 | type = strip_typedefs (TREE_TYPE (t)); | |
1153 | result = build_pointer_type (type); | |
1154 | break; | |
1155 | case REFERENCE_TYPE: | |
1156 | type = strip_typedefs (TREE_TYPE (t)); | |
1157 | result = cp_build_reference_type (type, TYPE_REF_IS_RVALUE (t)); | |
1158 | break; | |
1159 | case OFFSET_TYPE: | |
1160 | t0 = strip_typedefs (TYPE_OFFSET_BASETYPE (t)); | |
1161 | type = strip_typedefs (TREE_TYPE (t)); | |
1162 | result = build_offset_type (t0, type); | |
1163 | break; | |
1164 | case RECORD_TYPE: | |
1165 | if (TYPE_PTRMEMFUNC_P (t)) | |
1166 | { | |
1167 | t0 = strip_typedefs (TYPE_PTRMEMFUNC_FN_TYPE (t)); | |
1168 | result = build_ptrmemfunc_type (t0); | |
1169 | } | |
1170 | break; | |
1171 | case ARRAY_TYPE: | |
1172 | type = strip_typedefs (TREE_TYPE (t)); | |
1173 | t0 = strip_typedefs (TYPE_DOMAIN (t));; | |
1174 | result = build_cplus_array_type (type, t0); | |
1175 | break; | |
1176 | case FUNCTION_TYPE: | |
1177 | case METHOD_TYPE: | |
1178 | { | |
1179 | tree arg_types = NULL, arg_node, arg_type; | |
1180 | for (arg_node = TYPE_ARG_TYPES (t); | |
1181 | arg_node; | |
1182 | arg_node = TREE_CHAIN (arg_node)) | |
1183 | { | |
1184 | if (arg_node == void_list_node) | |
1185 | break; | |
1186 | arg_type = strip_typedefs (TREE_VALUE (arg_node)); | |
1187 | gcc_assert (arg_type); | |
1188 | ||
1189 | arg_types = | |
1190 | tree_cons (TREE_PURPOSE (arg_node), arg_type, arg_types); | |
1191 | } | |
1192 | ||
1193 | if (arg_types) | |
1194 | arg_types = nreverse (arg_types); | |
1195 | ||
1196 | /* A list of parameters not ending with an ellipsis | |
1197 | must end with void_list_node. */ | |
1198 | if (arg_node) | |
1199 | arg_types = chainon (arg_types, void_list_node); | |
1200 | ||
1201 | type = strip_typedefs (TREE_TYPE (t)); | |
1202 | if (TREE_CODE (t) == METHOD_TYPE) | |
1203 | { | |
1204 | tree class_type = TREE_TYPE (TREE_VALUE (arg_types)); | |
1205 | gcc_assert (class_type); | |
1206 | result = | |
1207 | build_method_type_directly (class_type, type, | |
1208 | TREE_CHAIN (arg_types)); | |
1209 | } | |
1210 | else | |
2872152c | 1211 | { |
cd41d410 DS |
1212 | result = build_function_type (type, |
1213 | arg_types); | |
2872152c JM |
1214 | result = apply_memfn_quals (result, type_memfn_quals (t)); |
1215 | } | |
3c3905fc JM |
1216 | |
1217 | if (TYPE_RAISES_EXCEPTIONS (t)) | |
1218 | result = build_exception_variant (result, | |
1219 | TYPE_RAISES_EXCEPTIONS (t)); | |
cd41d410 DS |
1220 | } |
1221 | break; | |
e6c2fc5d DS |
1222 | case TYPENAME_TYPE: |
1223 | result = make_typename_type (strip_typedefs (TYPE_CONTEXT (t)), | |
1224 | TYPENAME_TYPE_FULLNAME (t), | |
1225 | typename_type, tf_none); | |
1226 | break; | |
49bb4bbe JM |
1227 | case DECLTYPE_TYPE: |
1228 | result = strip_typedefs_expr (DECLTYPE_TYPE_EXPR (t)); | |
1229 | if (result == DECLTYPE_TYPE_EXPR (t)) | |
1230 | return t; | |
1231 | else | |
1232 | result = (finish_decltype_type | |
1233 | (result, | |
1234 | DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (t), | |
1235 | tf_none)); | |
1236 | break; | |
cd41d410 DS |
1237 | default: |
1238 | break; | |
1239 | } | |
1ad8aeeb | 1240 | |
cd41d410 DS |
1241 | if (!result) |
1242 | result = TYPE_MAIN_VARIANT (t); | |
05322543 JM |
1243 | if (TYPE_USER_ALIGN (t) != TYPE_USER_ALIGN (result) |
1244 | || TYPE_ALIGN (t) != TYPE_ALIGN (result)) | |
1245 | { | |
1246 | gcc_assert (TYPE_USER_ALIGN (t)); | |
1247 | if (TYPE_ALIGN (t) == TYPE_ALIGN (result)) | |
1248 | result = build_variant_type_copy (result); | |
1249 | else | |
1250 | result = build_aligned_type (result, TYPE_ALIGN (t)); | |
1251 | TYPE_USER_ALIGN (result) = true; | |
1252 | } | |
3c3905fc JM |
1253 | if (TYPE_ATTRIBUTES (t)) |
1254 | result = cp_build_type_attribute_variant (result, TYPE_ATTRIBUTES (t)); | |
cd41d410 | 1255 | return cp_build_qualified_type (result, cp_type_quals (t)); |
53929c47 | 1256 | } |
cd41d410 | 1257 | |
49bb4bbe JM |
1258 | /* Like strip_typedefs above, but works on expressions, so that in |
1259 | ||
1260 | template<class T> struct A | |
1261 | { | |
1262 | typedef T TT; | |
1263 | B<sizeof(TT)> b; | |
1264 | }; | |
1265 | ||
1266 | sizeof(TT) is replaced by sizeof(T). */ | |
1267 | ||
1268 | tree | |
1269 | strip_typedefs_expr (tree t) | |
1270 | { | |
1271 | unsigned i,n; | |
1272 | tree r, type, *ops; | |
1273 | enum tree_code code; | |
1274 | ||
1275 | if (t == NULL_TREE || t == error_mark_node) | |
1276 | return t; | |
1277 | ||
1278 | if (DECL_P (t) || CONSTANT_CLASS_P (t)) | |
1279 | return t; | |
1280 | ||
1281 | /* Some expressions have type operands, so let's handle types here rather | |
1282 | than check TYPE_P in multiple places below. */ | |
1283 | if (TYPE_P (t)) | |
1284 | return strip_typedefs (t); | |
1285 | ||
1286 | code = TREE_CODE (t); | |
1287 | switch (code) | |
1288 | { | |
1289 | case IDENTIFIER_NODE: | |
1290 | case TEMPLATE_PARM_INDEX: | |
1291 | case OVERLOAD: | |
1292 | case BASELINK: | |
1293 | case ARGUMENT_PACK_SELECT: | |
1294 | return t; | |
1295 | ||
1296 | case TRAIT_EXPR: | |
1297 | { | |
1298 | tree type1 = strip_typedefs (TRAIT_EXPR_TYPE1 (t)); | |
1299 | tree type2 = strip_typedefs (TRAIT_EXPR_TYPE2 (t)); | |
1300 | if (type1 == TRAIT_EXPR_TYPE1 (t) | |
1301 | && type2 == TRAIT_EXPR_TYPE2 (t)) | |
1302 | return t; | |
1303 | r = copy_node (t); | |
1304 | TRAIT_EXPR_TYPE1 (t) = type1; | |
1305 | TRAIT_EXPR_TYPE2 (t) = type2; | |
1306 | return r; | |
1307 | } | |
1308 | ||
1309 | case TREE_LIST: | |
1310 | { | |
9771b263 | 1311 | vec<tree, va_gc> *vec = make_tree_vector (); |
49bb4bbe JM |
1312 | bool changed = false; |
1313 | tree it; | |
1314 | for (it = t; it; it = TREE_CHAIN (it)) | |
1315 | { | |
1316 | tree val = strip_typedefs_expr (TREE_VALUE (t)); | |
9771b263 | 1317 | vec_safe_push (vec, val); |
49bb4bbe JM |
1318 | if (val != TREE_VALUE (t)) |
1319 | changed = true; | |
1320 | gcc_assert (TREE_PURPOSE (it) == NULL_TREE); | |
1321 | } | |
1322 | if (changed) | |
1323 | { | |
1324 | r = NULL_TREE; | |
9771b263 | 1325 | FOR_EACH_VEC_ELT_REVERSE (*vec, i, it) |
49bb4bbe JM |
1326 | r = tree_cons (NULL_TREE, it, r); |
1327 | } | |
1328 | else | |
1329 | r = t; | |
1330 | release_tree_vector (vec); | |
1331 | return r; | |
1332 | } | |
1333 | ||
1334 | case TREE_VEC: | |
1335 | { | |
1336 | bool changed = false; | |
9771b263 | 1337 | vec<tree, va_gc> *vec = make_tree_vector (); |
49bb4bbe | 1338 | n = TREE_VEC_LENGTH (t); |
9771b263 | 1339 | vec_safe_reserve (vec, n); |
49bb4bbe JM |
1340 | for (i = 0; i < n; ++i) |
1341 | { | |
1342 | tree op = strip_typedefs_expr (TREE_VEC_ELT (t, i)); | |
9771b263 | 1343 | vec->quick_push (op); |
49bb4bbe JM |
1344 | if (op != TREE_VEC_ELT (t, i)) |
1345 | changed = true; | |
1346 | } | |
1347 | if (changed) | |
1348 | { | |
1349 | r = copy_node (t); | |
1350 | for (i = 0; i < n; ++i) | |
9771b263 | 1351 | TREE_VEC_ELT (r, i) = (*vec)[i]; |
dcdb8613 JM |
1352 | SET_NON_DEFAULT_TEMPLATE_ARGS_COUNT |
1353 | (r, GET_NON_DEFAULT_TEMPLATE_ARGS_COUNT (t)); | |
49bb4bbe JM |
1354 | } |
1355 | else | |
1356 | r = t; | |
1357 | release_tree_vector (vec); | |
1358 | return r; | |
1359 | } | |
1360 | ||
1361 | case CONSTRUCTOR: | |
1362 | { | |
1363 | bool changed = false; | |
9771b263 DN |
1364 | vec<constructor_elt, va_gc> *vec |
1365 | = vec_safe_copy (CONSTRUCTOR_ELTS (t)); | |
49bb4bbe JM |
1366 | n = CONSTRUCTOR_NELTS (t); |
1367 | type = strip_typedefs (TREE_TYPE (t)); | |
1368 | for (i = 0; i < n; ++i) | |
1369 | { | |
9771b263 | 1370 | constructor_elt *e = &(*vec)[i]; |
49bb4bbe JM |
1371 | tree op = strip_typedefs_expr (e->value); |
1372 | if (op != e->value) | |
1373 | { | |
1374 | changed = true; | |
1375 | e->value = op; | |
1376 | } | |
1377 | gcc_checking_assert (e->index == strip_typedefs_expr (e->index)); | |
1378 | } | |
1379 | ||
1380 | if (!changed && type == TREE_TYPE (t)) | |
1381 | { | |
9771b263 | 1382 | vec_free (vec); |
49bb4bbe JM |
1383 | return t; |
1384 | } | |
1385 | else | |
1386 | { | |
1387 | r = copy_node (t); | |
1388 | TREE_TYPE (r) = type; | |
1389 | CONSTRUCTOR_ELTS (r) = vec; | |
1390 | return r; | |
1391 | } | |
1392 | } | |
1393 | ||
1394 | case LAMBDA_EXPR: | |
1395 | gcc_unreachable (); | |
1396 | ||
1397 | default: | |
1398 | break; | |
1399 | } | |
1400 | ||
1401 | gcc_assert (EXPR_P (t)); | |
1402 | ||
1403 | n = TREE_OPERAND_LENGTH (t); | |
1404 | ops = XALLOCAVEC (tree, n); | |
1405 | type = TREE_TYPE (t); | |
1406 | ||
1407 | switch (code) | |
1408 | { | |
1409 | CASE_CONVERT: | |
1410 | case IMPLICIT_CONV_EXPR: | |
1411 | case DYNAMIC_CAST_EXPR: | |
1412 | case STATIC_CAST_EXPR: | |
1413 | case CONST_CAST_EXPR: | |
1414 | case REINTERPRET_CAST_EXPR: | |
1415 | case CAST_EXPR: | |
1416 | case NEW_EXPR: | |
1417 | type = strip_typedefs (type); | |
1418 | /* fallthrough */ | |
1419 | ||
1420 | default: | |
1421 | for (i = 0; i < n; ++i) | |
1422 | ops[i] = strip_typedefs_expr (TREE_OPERAND (t, i)); | |
1423 | break; | |
1424 | } | |
1425 | ||
1426 | /* If nothing changed, return t. */ | |
1427 | for (i = 0; i < n; ++i) | |
1428 | if (ops[i] != TREE_OPERAND (t, i)) | |
1429 | break; | |
1430 | if (i == n && type == TREE_TYPE (t)) | |
1431 | return t; | |
1432 | ||
1433 | r = copy_node (t); | |
1434 | TREE_TYPE (r) = type; | |
1435 | for (i = 0; i < n; ++i) | |
1436 | TREE_OPERAND (r, i) = ops[i]; | |
1437 | return r; | |
1438 | } | |
1439 | ||
48b45647 NS |
1440 | /* Makes a copy of BINFO and TYPE, which is to be inherited into a |
1441 | graph dominated by T. If BINFO is NULL, TYPE is a dependent base, | |
1442 | and we do a shallow copy. If BINFO is non-NULL, we do a deep copy. | |
1443 | VIRT indicates whether TYPE is inherited virtually or not. | |
1444 | IGO_PREV points at the previous binfo of the inheritance graph | |
1445 | order chain. The newly copied binfo's TREE_CHAIN forms this | |
1446 | ordering. | |
1447 | ||
1448 | The CLASSTYPE_VBASECLASSES vector of T is constructed in the | |
1449 | correct order. That is in the order the bases themselves should be | |
1450 | constructed in. | |
dbbf88d1 NS |
1451 | |
1452 | The BINFO_INHERITANCE of a virtual base class points to the binfo | |
48b45647 NS |
1453 | of the most derived type. ??? We could probably change this so that |
1454 | BINFO_INHERITANCE becomes synonymous with BINFO_PRIMARY, and hence | |
1455 | remove a field. They currently can only differ for primary virtual | |
1456 | virtual bases. */ | |
dbbf88d1 NS |
1457 | |
1458 | tree | |
48b45647 | 1459 | copy_binfo (tree binfo, tree type, tree t, tree *igo_prev, int virt) |
9a71c18b | 1460 | { |
48b45647 | 1461 | tree new_binfo; |
9a71c18b | 1462 | |
48b45647 NS |
1463 | if (virt) |
1464 | { | |
1465 | /* See if we've already made this virtual base. */ | |
1466 | new_binfo = binfo_for_vbase (type, t); | |
1467 | if (new_binfo) | |
1468 | return new_binfo; | |
1469 | } | |
9f63daea | 1470 | |
fa743e8c | 1471 | new_binfo = make_tree_binfo (binfo ? BINFO_N_BASE_BINFOS (binfo) : 0); |
48b45647 | 1472 | BINFO_TYPE (new_binfo) = type; |
9a71c18b | 1473 | |
48b45647 NS |
1474 | /* Chain it into the inheritance graph. */ |
1475 | TREE_CHAIN (*igo_prev) = new_binfo; | |
1476 | *igo_prev = new_binfo; | |
9f63daea | 1477 | |
05262294 | 1478 | if (binfo && !BINFO_DEPENDENT_BASE_P (binfo)) |
dfbcd65a | 1479 | { |
fa743e8c NS |
1480 | int ix; |
1481 | tree base_binfo; | |
9f63daea | 1482 | |
539ed333 | 1483 | gcc_assert (SAME_BINFO_TYPE_P (BINFO_TYPE (binfo), type)); |
9f63daea | 1484 | |
48b45647 NS |
1485 | BINFO_OFFSET (new_binfo) = BINFO_OFFSET (binfo); |
1486 | BINFO_VIRTUALS (new_binfo) = BINFO_VIRTUALS (binfo); | |
9f63daea | 1487 | |
fa743e8c NS |
1488 | /* We do not need to copy the accesses, as they are read only. */ |
1489 | BINFO_BASE_ACCESSES (new_binfo) = BINFO_BASE_ACCESSES (binfo); | |
9f63daea | 1490 | |
48b45647 | 1491 | /* Recursively copy base binfos of BINFO. */ |
fa743e8c | 1492 | for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++) |
dbbf88d1 | 1493 | { |
48b45647 | 1494 | tree new_base_binfo; |
48b45647 NS |
1495 | new_base_binfo = copy_binfo (base_binfo, BINFO_TYPE (base_binfo), |
1496 | t, igo_prev, | |
1497 | BINFO_VIRTUAL_P (base_binfo)); | |
9f63daea | 1498 | |
48b45647 NS |
1499 | if (!BINFO_INHERITANCE_CHAIN (new_base_binfo)) |
1500 | BINFO_INHERITANCE_CHAIN (new_base_binfo) = new_binfo; | |
fa743e8c | 1501 | BINFO_BASE_APPEND (new_binfo, new_base_binfo); |
dbbf88d1 | 1502 | } |
9a71c18b | 1503 | } |
48b45647 NS |
1504 | else |
1505 | BINFO_DEPENDENT_BASE_P (new_binfo) = 1; | |
9f63daea | 1506 | |
48b45647 NS |
1507 | if (virt) |
1508 | { | |
1509 | /* Push it onto the list after any virtual bases it contains | |
1510 | will have been pushed. */ | |
9771b263 | 1511 | CLASSTYPE_VBASECLASSES (t)->quick_push (new_binfo); |
48b45647 NS |
1512 | BINFO_VIRTUAL_P (new_binfo) = 1; |
1513 | BINFO_INHERITANCE_CHAIN (new_binfo) = TYPE_BINFO (t); | |
1514 | } | |
9f63daea | 1515 | |
48b45647 | 1516 | return new_binfo; |
9a71c18b | 1517 | } |
8d08fdba MS |
1518 | \f |
1519 | /* Hashing of lists so that we don't make duplicates. | |
1520 | The entry point is `list_hash_canon'. */ | |
1521 | ||
8d08fdba MS |
1522 | /* Now here is the hash table. When recording a list, it is added |
1523 | to the slot whose index is the hash code mod the table size. | |
1524 | Note that the hash table is used for several kinds of lists. | |
1525 | While all these live in the same table, they are completely independent, | |
1526 | and the hash code is computed differently for each of these. */ | |
1527 | ||
e2500fed | 1528 | static GTY ((param_is (union tree_node))) htab_t list_hash_table; |
9ccb25d5 | 1529 | |
9f63daea | 1530 | struct list_proxy |
9ccb25d5 MM |
1531 | { |
1532 | tree purpose; | |
1533 | tree value; | |
1534 | tree chain; | |
1535 | }; | |
1536 | ||
1537 | /* Compare ENTRY (an entry in the hash table) with DATA (a list_proxy | |
1538 | for a node we are thinking about adding). */ | |
1539 | ||
1540 | static int | |
b57b79f7 | 1541 | list_hash_eq (const void* entry, const void* data) |
9ccb25d5 | 1542 | { |
741ac903 KG |
1543 | const_tree const t = (const_tree) entry; |
1544 | const struct list_proxy *const proxy = (const struct list_proxy *) data; | |
9ccb25d5 MM |
1545 | |
1546 | return (TREE_VALUE (t) == proxy->value | |
1547 | && TREE_PURPOSE (t) == proxy->purpose | |
1548 | && TREE_CHAIN (t) == proxy->chain); | |
1549 | } | |
8d08fdba MS |
1550 | |
1551 | /* Compute a hash code for a list (chain of TREE_LIST nodes | |
1552 | with goodies in the TREE_PURPOSE, TREE_VALUE, and bits of the | |
1553 | TREE_COMMON slots), by adding the hash codes of the individual entries. */ | |
1554 | ||
9ccb25d5 | 1555 | static hashval_t |
b57b79f7 | 1556 | list_hash_pieces (tree purpose, tree value, tree chain) |
8d08fdba | 1557 | { |
9ccb25d5 | 1558 | hashval_t hashcode = 0; |
9f63daea | 1559 | |
37c46b43 | 1560 | if (chain) |
fd917e0d | 1561 | hashcode += TREE_HASH (chain); |
9f63daea | 1562 | |
37c46b43 | 1563 | if (value) |
fd917e0d | 1564 | hashcode += TREE_HASH (value); |
8d08fdba MS |
1565 | else |
1566 | hashcode += 1007; | |
37c46b43 | 1567 | if (purpose) |
fd917e0d | 1568 | hashcode += TREE_HASH (purpose); |
8d08fdba MS |
1569 | else |
1570 | hashcode += 1009; | |
1571 | return hashcode; | |
1572 | } | |
1573 | ||
9ccb25d5 | 1574 | /* Hash an already existing TREE_LIST. */ |
8d08fdba | 1575 | |
9ccb25d5 | 1576 | static hashval_t |
b57b79f7 | 1577 | list_hash (const void* p) |
8d08fdba | 1578 | { |
741ac903 | 1579 | const_tree const t = (const_tree) p; |
9f63daea EC |
1580 | return list_hash_pieces (TREE_PURPOSE (t), |
1581 | TREE_VALUE (t), | |
9ccb25d5 | 1582 | TREE_CHAIN (t)); |
8d08fdba MS |
1583 | } |
1584 | ||
51632249 JM |
1585 | /* Given list components PURPOSE, VALUE, AND CHAIN, return the canonical |
1586 | object for an identical list if one already exists. Otherwise, build a | |
1587 | new one, and record it as the canonical object. */ | |
8d08fdba | 1588 | |
8d08fdba | 1589 | tree |
b57b79f7 | 1590 | hash_tree_cons (tree purpose, tree value, tree chain) |
8d08fdba | 1591 | { |
a703fb38 | 1592 | int hashcode = 0; |
fad205ff | 1593 | void **slot; |
9ccb25d5 MM |
1594 | struct list_proxy proxy; |
1595 | ||
1596 | /* Hash the list node. */ | |
1597 | hashcode = list_hash_pieces (purpose, value, chain); | |
1598 | /* Create a proxy for the TREE_LIST we would like to create. We | |
1599 | don't actually create it so as to avoid creating garbage. */ | |
1600 | proxy.purpose = purpose; | |
1601 | proxy.value = value; | |
1602 | proxy.chain = chain; | |
1603 | /* See if it is already in the table. */ | |
1604 | slot = htab_find_slot_with_hash (list_hash_table, &proxy, hashcode, | |
1605 | INSERT); | |
1606 | /* If not, create a new node. */ | |
1607 | if (!*slot) | |
fad205ff | 1608 | *slot = tree_cons (purpose, value, chain); |
67f5655f | 1609 | return (tree) *slot; |
8d08fdba MS |
1610 | } |
1611 | ||
1612 | /* Constructor for hashed lists. */ | |
e92cc029 | 1613 | |
8d08fdba | 1614 | tree |
b57b79f7 | 1615 | hash_tree_chain (tree value, tree chain) |
8d08fdba | 1616 | { |
51632249 | 1617 | return hash_tree_cons (NULL_TREE, value, chain); |
8d08fdba | 1618 | } |
8d08fdba | 1619 | \f |
8d08fdba | 1620 | void |
b57b79f7 | 1621 | debug_binfo (tree elem) |
8d08fdba | 1622 | { |
fed3cef0 | 1623 | HOST_WIDE_INT n; |
8d08fdba MS |
1624 | tree virtuals; |
1625 | ||
90ff44cf KG |
1626 | fprintf (stderr, "type \"%s\", offset = " HOST_WIDE_INT_PRINT_DEC |
1627 | "\nvtable type:\n", | |
1628 | TYPE_NAME_STRING (BINFO_TYPE (elem)), | |
fed3cef0 | 1629 | TREE_INT_CST_LOW (BINFO_OFFSET (elem))); |
8d08fdba MS |
1630 | debug_tree (BINFO_TYPE (elem)); |
1631 | if (BINFO_VTABLE (elem)) | |
fed3cef0 | 1632 | fprintf (stderr, "vtable decl \"%s\"\n", |
c35cce41 | 1633 | IDENTIFIER_POINTER (DECL_NAME (get_vtbl_decl_for_binfo (elem)))); |
8d08fdba MS |
1634 | else |
1635 | fprintf (stderr, "no vtable decl yet\n"); | |
1636 | fprintf (stderr, "virtuals:\n"); | |
da3d4dfa | 1637 | virtuals = BINFO_VIRTUALS (elem); |
1f84ec23 | 1638 | n = 0; |
f30432d7 | 1639 | |
8d08fdba MS |
1640 | while (virtuals) |
1641 | { | |
83f2ccf4 | 1642 | tree fndecl = TREE_VALUE (virtuals); |
71e89f27 | 1643 | fprintf (stderr, "%s [%ld =? %ld]\n", |
8d08fdba | 1644 | IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl)), |
71e89f27 | 1645 | (long) n, (long) TREE_INT_CST_LOW (DECL_VINDEX (fndecl))); |
f30432d7 | 1646 | ++n; |
8d08fdba | 1647 | virtuals = TREE_CHAIN (virtuals); |
8d08fdba MS |
1648 | } |
1649 | } | |
1650 | ||
02ed62dd MM |
1651 | /* Build a representation for the qualified name SCOPE::NAME. TYPE is |
1652 | the type of the result expression, if known, or NULL_TREE if the | |
1653 | resulting expression is type-dependent. If TEMPLATE_P is true, | |
1654 | NAME is known to be a template because the user explicitly used the | |
3db45ab5 | 1655 | "template" keyword after the "::". |
02ed62dd MM |
1656 | |
1657 | All SCOPE_REFs should be built by use of this function. */ | |
1658 | ||
1659 | tree | |
1660 | build_qualified_name (tree type, tree scope, tree name, bool template_p) | |
1661 | { | |
1662 | tree t; | |
36569397 MM |
1663 | if (type == error_mark_node |
1664 | || scope == error_mark_node | |
1665 | || name == error_mark_node) | |
1666 | return error_mark_node; | |
02ed62dd MM |
1667 | t = build2 (SCOPE_REF, type, scope, name); |
1668 | QUALIFIED_NAME_IS_TEMPLATE (t) = template_p; | |
d816a3ba | 1669 | PTRMEM_OK_P (t) = true; |
7097b3ac JM |
1670 | if (type) |
1671 | t = convert_from_reference (t); | |
02ed62dd MM |
1672 | return t; |
1673 | } | |
1674 | ||
3b426391 | 1675 | /* Returns nonzero if X is an expression for a (possibly overloaded) |
eff3a276 MM |
1676 | function. If "f" is a function or function template, "f", "c->f", |
1677 | "c.f", "C::f", and "f<int>" will all be considered possibly | |
1678 | overloaded functions. Returns 2 if the function is actually | |
b9704fc5 | 1679 | overloaded, i.e., if it is impossible to know the type of the |
eff3a276 MM |
1680 | function without performing overload resolution. */ |
1681 | ||
8d08fdba | 1682 | int |
b57b79f7 | 1683 | is_overloaded_fn (tree x) |
8d08fdba | 1684 | { |
4bb0968f | 1685 | /* A baselink is also considered an overloaded function. */ |
ccbe00a4 JM |
1686 | if (TREE_CODE (x) == OFFSET_REF |
1687 | || TREE_CODE (x) == COMPONENT_REF) | |
05e0b2f4 | 1688 | x = TREE_OPERAND (x, 1); |
4bb0968f | 1689 | if (BASELINK_P (x)) |
da15dae6 | 1690 | x = BASELINK_FUNCTIONS (x); |
d095e03c JM |
1691 | if (TREE_CODE (x) == TEMPLATE_ID_EXPR) |
1692 | x = TREE_OPERAND (x, 0); | |
1693 | if (DECL_FUNCTION_TEMPLATE_P (OVL_CURRENT (x)) | |
eff3a276 MM |
1694 | || (TREE_CODE (x) == OVERLOAD && OVL_CHAIN (x))) |
1695 | return 2; | |
1696 | return (TREE_CODE (x) == FUNCTION_DECL | |
1697 | || TREE_CODE (x) == OVERLOAD); | |
8d08fdba MS |
1698 | } |
1699 | ||
f7d605ac JM |
1700 | /* X is the CALL_EXPR_FN of a CALL_EXPR. If X represents a dependent name |
1701 | (14.6.2), return the IDENTIFIER_NODE for that name. Otherwise, return | |
1702 | NULL_TREE. */ | |
1703 | ||
4b6aaa99 | 1704 | tree |
f7d605ac JM |
1705 | dependent_name (tree x) |
1706 | { | |
1707 | if (TREE_CODE (x) == IDENTIFIER_NODE) | |
1708 | return x; | |
1709 | if (TREE_CODE (x) != COMPONENT_REF | |
d54ce1df JM |
1710 | && TREE_CODE (x) != OFFSET_REF |
1711 | && TREE_CODE (x) != BASELINK | |
f7d605ac JM |
1712 | && is_overloaded_fn (x)) |
1713 | return DECL_NAME (get_first_fn (x)); | |
1714 | return NULL_TREE; | |
1715 | } | |
1716 | ||
eff3a276 MM |
1717 | /* Returns true iff X is an expression for an overloaded function |
1718 | whose type cannot be known without performing overload | |
1719 | resolution. */ | |
1720 | ||
1721 | bool | |
b57b79f7 | 1722 | really_overloaded_fn (tree x) |
9f63daea | 1723 | { |
eff3a276 | 1724 | return is_overloaded_fn (x) == 2; |
8926095f MS |
1725 | } |
1726 | ||
8d08fdba | 1727 | tree |
294e855f | 1728 | get_fns (tree from) |
8d08fdba | 1729 | { |
50bc768d | 1730 | gcc_assert (is_overloaded_fn (from)); |
c6002625 | 1731 | /* A baselink is also considered an overloaded function. */ |
7e361ae6 JM |
1732 | if (TREE_CODE (from) == OFFSET_REF |
1733 | || TREE_CODE (from) == COMPONENT_REF) | |
ccbe00a4 | 1734 | from = TREE_OPERAND (from, 1); |
4bb0968f | 1735 | if (BASELINK_P (from)) |
da15dae6 | 1736 | from = BASELINK_FUNCTIONS (from); |
d095e03c JM |
1737 | if (TREE_CODE (from) == TEMPLATE_ID_EXPR) |
1738 | from = TREE_OPERAND (from, 0); | |
294e855f JM |
1739 | return from; |
1740 | } | |
1741 | ||
1742 | tree | |
1743 | get_first_fn (tree from) | |
1744 | { | |
1745 | return OVL_CURRENT (get_fns (from)); | |
2c73f9f5 | 1746 | } |
8d08fdba | 1747 | |
c6002625 | 1748 | /* Return a new OVL node, concatenating it with the old one. */ |
2c73f9f5 ML |
1749 | |
1750 | tree | |
b57b79f7 | 1751 | ovl_cons (tree decl, tree chain) |
2c73f9f5 ML |
1752 | { |
1753 | tree result = make_node (OVERLOAD); | |
1754 | TREE_TYPE (result) = unknown_type_node; | |
1755 | OVL_FUNCTION (result) = decl; | |
1756 | TREE_CHAIN (result) = chain; | |
9f63daea | 1757 | |
2c73f9f5 ML |
1758 | return result; |
1759 | } | |
1760 | ||
2c73f9f5 ML |
1761 | /* Build a new overloaded function. If this is the first one, |
1762 | just return it; otherwise, ovl_cons the _DECLs */ | |
1763 | ||
1764 | tree | |
b57b79f7 | 1765 | build_overload (tree decl, tree chain) |
2c73f9f5 | 1766 | { |
161c12b0 | 1767 | if (! chain && TREE_CODE (decl) != TEMPLATE_DECL) |
2c73f9f5 | 1768 | return decl; |
2c73f9f5 | 1769 | return ovl_cons (decl, chain); |
73452ce7 DS |
1770 | } |
1771 | ||
aef3a6b2 JM |
1772 | /* Return the scope where the overloaded functions OVL were found. */ |
1773 | ||
1774 | tree | |
1775 | ovl_scope (tree ovl) | |
1776 | { | |
1777 | if (TREE_CODE (ovl) == OFFSET_REF | |
1778 | || TREE_CODE (ovl) == COMPONENT_REF) | |
1779 | ovl = TREE_OPERAND (ovl, 1); | |
1780 | if (TREE_CODE (ovl) == BASELINK) | |
1781 | return BINFO_TYPE (BASELINK_BINFO (ovl)); | |
1782 | if (TREE_CODE (ovl) == TEMPLATE_ID_EXPR) | |
1783 | ovl = TREE_OPERAND (ovl, 0); | |
1784 | /* Skip using-declarations. */ | |
1785 | while (TREE_CODE (ovl) == OVERLOAD && OVL_USED (ovl) && OVL_CHAIN (ovl)) | |
1786 | ovl = OVL_CHAIN (ovl); | |
1787 | return CP_DECL_CONTEXT (OVL_CURRENT (ovl)); | |
1788 | } | |
1789 | ||
73452ce7 DS |
1790 | /* Return TRUE if FN is a non-static member function, FALSE otherwise. |
1791 | This function looks into BASELINK and OVERLOAD nodes. */ | |
1792 | ||
1793 | bool | |
1794 | non_static_member_function_p (tree fn) | |
1795 | { | |
1796 | if (fn == NULL_TREE) | |
1797 | return false; | |
1798 | ||
1799 | if (is_overloaded_fn (fn)) | |
1800 | fn = get_first_fn (fn); | |
1801 | ||
1802 | return (DECL_P (fn) | |
1803 | && DECL_NONSTATIC_MEMBER_FUNCTION_P (fn)); | |
2c73f9f5 ML |
1804 | } |
1805 | ||
8d08fdba MS |
1806 | \f |
1807 | #define PRINT_RING_SIZE 4 | |
1808 | ||
f41c4af3 JM |
1809 | static const char * |
1810 | cxx_printable_name_internal (tree decl, int v, bool translate) | |
8d08fdba | 1811 | { |
1bde0042 | 1812 | static unsigned int uid_ring[PRINT_RING_SIZE]; |
8d08fdba | 1813 | static char *print_ring[PRINT_RING_SIZE]; |
f41c4af3 | 1814 | static bool trans_ring[PRINT_RING_SIZE]; |
8d08fdba MS |
1815 | static int ring_counter; |
1816 | int i; | |
1817 | ||
1818 | /* Only cache functions. */ | |
2ba25f50 MS |
1819 | if (v < 2 |
1820 | || TREE_CODE (decl) != FUNCTION_DECL | |
8d08fdba | 1821 | || DECL_LANG_SPECIFIC (decl) == 0) |
f41c4af3 | 1822 | return lang_decl_name (decl, v, translate); |
8d08fdba MS |
1823 | |
1824 | /* See if this print name is lying around. */ | |
1825 | for (i = 0; i < PRINT_RING_SIZE; i++) | |
f41c4af3 | 1826 | if (uid_ring[i] == DECL_UID (decl) && translate == trans_ring[i]) |
8d08fdba MS |
1827 | /* yes, so return it. */ |
1828 | return print_ring[i]; | |
1829 | ||
1830 | if (++ring_counter == PRINT_RING_SIZE) | |
1831 | ring_counter = 0; | |
1832 | ||
1833 | if (current_function_decl != NULL_TREE) | |
1834 | { | |
8fa6fa79 JM |
1835 | /* There may be both translated and untranslated versions of the |
1836 | name cached. */ | |
1837 | for (i = 0; i < 2; i++) | |
1838 | { | |
1839 | if (uid_ring[ring_counter] == DECL_UID (current_function_decl)) | |
1840 | ring_counter += 1; | |
1841 | if (ring_counter == PRINT_RING_SIZE) | |
1842 | ring_counter = 0; | |
1843 | } | |
1bde0042 | 1844 | gcc_assert (uid_ring[ring_counter] != DECL_UID (current_function_decl)); |
8d08fdba MS |
1845 | } |
1846 | ||
04695783 | 1847 | free (print_ring[ring_counter]); |
8d08fdba | 1848 | |
f41c4af3 | 1849 | print_ring[ring_counter] = xstrdup (lang_decl_name (decl, v, translate)); |
1bde0042 | 1850 | uid_ring[ring_counter] = DECL_UID (decl); |
f41c4af3 | 1851 | trans_ring[ring_counter] = translate; |
8d08fdba MS |
1852 | return print_ring[ring_counter]; |
1853 | } | |
f41c4af3 JM |
1854 | |
1855 | const char * | |
1856 | cxx_printable_name (tree decl, int v) | |
1857 | { | |
1858 | return cxx_printable_name_internal (decl, v, false); | |
1859 | } | |
1860 | ||
1861 | const char * | |
1862 | cxx_printable_name_translate (tree decl, int v) | |
1863 | { | |
1864 | return cxx_printable_name_internal (decl, v, true); | |
1865 | } | |
8d08fdba | 1866 | \f |
f30432d7 | 1867 | /* Build the FUNCTION_TYPE or METHOD_TYPE which may throw exceptions |
8d08fdba | 1868 | listed in RAISES. */ |
e92cc029 | 1869 | |
8d08fdba | 1870 | tree |
b57b79f7 | 1871 | build_exception_variant (tree type, tree raises) |
8d08fdba | 1872 | { |
3a55fb4c JM |
1873 | tree v; |
1874 | int type_quals; | |
8d08fdba | 1875 | |
3a55fb4c JM |
1876 | if (comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (type), ce_exact)) |
1877 | return type; | |
1878 | ||
1879 | type_quals = TYPE_QUALS (type); | |
1880 | for (v = TYPE_MAIN_VARIANT (type); v; v = TYPE_NEXT_VARIANT (v)) | |
896c3aa3 | 1881 | if (check_qualified_type (v, type, type_quals) |
3a55fb4c | 1882 | && comp_except_specs (raises, TYPE_RAISES_EXCEPTIONS (v), ce_exact)) |
4cc1d462 | 1883 | return v; |
8d08fdba MS |
1884 | |
1885 | /* Need to build a new variant. */ | |
8dd16ecc | 1886 | v = build_variant_type_copy (type); |
8d08fdba MS |
1887 | TYPE_RAISES_EXCEPTIONS (v) = raises; |
1888 | return v; | |
1889 | } | |
1890 | ||
dac65501 KL |
1891 | /* Given a TEMPLATE_TEMPLATE_PARM node T, create a new |
1892 | BOUND_TEMPLATE_TEMPLATE_PARM bound with NEWARGS as its template | |
1899c3a4 | 1893 | arguments. */ |
73b0fce8 KL |
1894 | |
1895 | tree | |
b57b79f7 | 1896 | bind_template_template_parm (tree t, tree newargs) |
73b0fce8 | 1897 | { |
1899c3a4 | 1898 | tree decl = TYPE_NAME (t); |
6b9b6b15 JM |
1899 | tree t2; |
1900 | ||
9e1e64ec | 1901 | t2 = cxx_make_type (BOUND_TEMPLATE_TEMPLATE_PARM); |
c2255bc4 AH |
1902 | decl = build_decl (input_location, |
1903 | TYPE_DECL, DECL_NAME (decl), NULL_TREE); | |
1899c3a4 | 1904 | |
dac65501 KL |
1905 | /* These nodes have to be created to reflect new TYPE_DECL and template |
1906 | arguments. */ | |
1907 | TEMPLATE_TYPE_PARM_INDEX (t2) = copy_node (TEMPLATE_TYPE_PARM_INDEX (t)); | |
1908 | TEMPLATE_PARM_DECL (TEMPLATE_TYPE_PARM_INDEX (t2)) = decl; | |
1909 | TEMPLATE_TEMPLATE_PARM_TEMPLATE_INFO (t2) | |
aa373032 | 1910 | = build_template_info (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t), newargs); |
6b9b6b15 | 1911 | |
1899c3a4 KL |
1912 | TREE_TYPE (decl) = t2; |
1913 | TYPE_NAME (t2) = decl; | |
1914 | TYPE_STUB_DECL (t2) = decl; | |
dac65501 | 1915 | TYPE_SIZE (t2) = 0; |
06d40de8 | 1916 | SET_TYPE_STRUCTURAL_EQUALITY (t2); |
73b0fce8 | 1917 | |
73b0fce8 KL |
1918 | return t2; |
1919 | } | |
1920 | ||
bf3428d0 | 1921 | /* Called from count_trees via walk_tree. */ |
297a5329 JM |
1922 | |
1923 | static tree | |
44de5aeb | 1924 | count_trees_r (tree *tp, int *walk_subtrees, void *data) |
297a5329 | 1925 | { |
44de5aeb RK |
1926 | ++*((int *) data); |
1927 | ||
1928 | if (TYPE_P (*tp)) | |
1929 | *walk_subtrees = 0; | |
1930 | ||
297a5329 JM |
1931 | return NULL_TREE; |
1932 | } | |
1933 | ||
1934 | /* Debugging function for measuring the rough complexity of a tree | |
1935 | representation. */ | |
1936 | ||
1937 | int | |
b57b79f7 | 1938 | count_trees (tree t) |
297a5329 | 1939 | { |
bf3428d0 | 1940 | int n_trees = 0; |
14588106 | 1941 | cp_walk_tree_without_duplicates (&t, count_trees_r, &n_trees); |
297a5329 | 1942 | return n_trees; |
9f63daea | 1943 | } |
297a5329 | 1944 | |
b2244c65 MM |
1945 | /* Called from verify_stmt_tree via walk_tree. */ |
1946 | ||
1947 | static tree | |
12308bc6 | 1948 | verify_stmt_tree_r (tree* tp, int * /*walk_subtrees*/, void* data) |
b2244c65 MM |
1949 | { |
1950 | tree t = *tp; | |
703c8606 LC |
1951 | hash_table <pointer_hash <tree_node> > *statements |
1952 | = static_cast <hash_table <pointer_hash <tree_node> > *> (data); | |
1953 | tree_node **slot; | |
b2244c65 | 1954 | |
009ed910 | 1955 | if (!STATEMENT_CODE_P (TREE_CODE (t))) |
b2244c65 MM |
1956 | return NULL_TREE; |
1957 | ||
1958 | /* If this statement is already present in the hash table, then | |
1959 | there is a circularity in the statement tree. */ | |
703c8606 | 1960 | gcc_assert (!statements->find (t)); |
9f63daea | 1961 | |
703c8606 | 1962 | slot = statements->find_slot (t, INSERT); |
b2244c65 MM |
1963 | *slot = t; |
1964 | ||
1965 | return NULL_TREE; | |
1966 | } | |
1967 | ||
1968 | /* Debugging function to check that the statement T has not been | |
1969 | corrupted. For now, this function simply checks that T contains no | |
1970 | circularities. */ | |
1971 | ||
1972 | void | |
b57b79f7 | 1973 | verify_stmt_tree (tree t) |
b2244c65 | 1974 | { |
703c8606 LC |
1975 | hash_table <pointer_hash <tree_node> > statements; |
1976 | statements.create (37); | |
14588106 | 1977 | cp_walk_tree (&t, verify_stmt_tree_r, &statements, NULL); |
703c8606 | 1978 | statements.dispose (); |
b2244c65 MM |
1979 | } |
1980 | ||
50a6dbd7 | 1981 | /* Check if the type T depends on a type with no linkage and if so, return |
4684cd27 | 1982 | it. If RELAXED_P then do not consider a class type declared within |
ecc607fc | 1983 | a vague-linkage function to have no linkage. */ |
50a6dbd7 JM |
1984 | |
1985 | tree | |
4684cd27 | 1986 | no_linkage_check (tree t, bool relaxed_p) |
50a6dbd7 | 1987 | { |
caf43ca4 MM |
1988 | tree r; |
1989 | ||
2adeacc9 MM |
1990 | /* There's no point in checking linkage on template functions; we |
1991 | can't know their complete types. */ | |
1992 | if (processing_template_decl) | |
1993 | return NULL_TREE; | |
1994 | ||
caf43ca4 MM |
1995 | switch (TREE_CODE (t)) |
1996 | { | |
1997 | case RECORD_TYPE: | |
1998 | if (TYPE_PTRMEMFUNC_P (t)) | |
1999 | goto ptrmem; | |
e6d92cec JM |
2000 | /* Lambda types that don't have mangling scope have no linkage. We |
2001 | check CLASSTYPE_LAMBDA_EXPR here rather than LAMBDA_TYPE_P because | |
2002 | when we get here from pushtag none of the lambda information is | |
2003 | set up yet, so we want to assume that the lambda has linkage and | |
2004 | fix it up later if not. */ | |
2005 | if (CLASSTYPE_LAMBDA_EXPR (t) | |
2006 | && LAMBDA_TYPE_EXTRA_SCOPE (t) == NULL_TREE) | |
2007 | return t; | |
caf43ca4 MM |
2008 | /* Fall through. */ |
2009 | case UNION_TYPE: | |
2010 | if (!CLASS_TYPE_P (t)) | |
2011 | return NULL_TREE; | |
2012 | /* Fall through. */ | |
2013 | case ENUMERAL_TYPE: | |
ecc607fc | 2014 | /* Only treat anonymous types as having no linkage if they're at |
2f59d9e0 | 2015 | namespace scope. This is core issue 966. */ |
ecc607fc | 2016 | if (TYPE_ANONYMOUS_P (t) && TYPE_NAMESPACE_SCOPE_P (t)) |
caf43ca4 | 2017 | return t; |
ecc607fc | 2018 | |
e6d92cec | 2019 | for (r = CP_TYPE_CONTEXT (t); ; ) |
ecc607fc | 2020 | { |
e6d92cec JM |
2021 | /* If we're a nested type of a !TREE_PUBLIC class, we might not |
2022 | have linkage, or we might just be in an anonymous namespace. | |
2023 | If we're in a TREE_PUBLIC class, we have linkage. */ | |
2024 | if (TYPE_P (r) && !TREE_PUBLIC (TYPE_NAME (r))) | |
2025 | return no_linkage_check (TYPE_CONTEXT (t), relaxed_p); | |
2026 | else if (TREE_CODE (r) == FUNCTION_DECL) | |
2027 | { | |
d6dcdbd5 | 2028 | if (!relaxed_p || !vague_linkage_p (r)) |
e6d92cec JM |
2029 | return t; |
2030 | else | |
2031 | r = CP_DECL_CONTEXT (r); | |
2032 | } | |
ecc607fc | 2033 | else |
e6d92cec | 2034 | break; |
ecc607fc JM |
2035 | } |
2036 | ||
caf43ca4 MM |
2037 | return NULL_TREE; |
2038 | ||
2039 | case ARRAY_TYPE: | |
2040 | case POINTER_TYPE: | |
2041 | case REFERENCE_TYPE: | |
4684cd27 | 2042 | return no_linkage_check (TREE_TYPE (t), relaxed_p); |
caf43ca4 MM |
2043 | |
2044 | case OFFSET_TYPE: | |
2045 | ptrmem: | |
4684cd27 MM |
2046 | r = no_linkage_check (TYPE_PTRMEM_POINTED_TO_TYPE (t), |
2047 | relaxed_p); | |
caf43ca4 MM |
2048 | if (r) |
2049 | return r; | |
4684cd27 | 2050 | return no_linkage_check (TYPE_PTRMEM_CLASS_TYPE (t), relaxed_p); |
caf43ca4 MM |
2051 | |
2052 | case METHOD_TYPE: | |
4684cd27 | 2053 | r = no_linkage_check (TYPE_METHOD_BASETYPE (t), relaxed_p); |
caf43ca4 MM |
2054 | if (r) |
2055 | return r; | |
2056 | /* Fall through. */ | |
2057 | case FUNCTION_TYPE: | |
2058 | { | |
2059 | tree parm; | |
9f63daea EC |
2060 | for (parm = TYPE_ARG_TYPES (t); |
2061 | parm && parm != void_list_node; | |
caf43ca4 MM |
2062 | parm = TREE_CHAIN (parm)) |
2063 | { | |
4684cd27 | 2064 | r = no_linkage_check (TREE_VALUE (parm), relaxed_p); |
caf43ca4 MM |
2065 | if (r) |
2066 | return r; | |
2067 | } | |
4684cd27 | 2068 | return no_linkage_check (TREE_TYPE (t), relaxed_p); |
caf43ca4 MM |
2069 | } |
2070 | ||
2071 | default: | |
2072 | return NULL_TREE; | |
2073 | } | |
50a6dbd7 JM |
2074 | } |
2075 | ||
5566b478 | 2076 | extern int depth_reached; |
5566b478 | 2077 | |
8d08fdba | 2078 | void |
b57b79f7 | 2079 | cxx_print_statistics (void) |
8d08fdba | 2080 | { |
8d08fdba MS |
2081 | print_search_statistics (); |
2082 | print_class_statistics (); | |
7dcfe861 | 2083 | print_template_statistics (); |
7aa6d18a SB |
2084 | if (GATHER_STATISTICS) |
2085 | fprintf (stderr, "maximum template instantiation depth reached: %d\n", | |
2086 | depth_reached); | |
8d08fdba MS |
2087 | } |
2088 | ||
e92cc029 MS |
2089 | /* Return, as an INTEGER_CST node, the number of elements for TYPE |
2090 | (which is an ARRAY_TYPE). This counts only elements of the top | |
2091 | array. */ | |
8d08fdba MS |
2092 | |
2093 | tree | |
b57b79f7 | 2094 | array_type_nelts_top (tree type) |
8d08fdba | 2095 | { |
db3927fb AH |
2096 | return fold_build2_loc (input_location, |
2097 | PLUS_EXPR, sizetype, | |
7866705a | 2098 | array_type_nelts (type), |
701e903a | 2099 | size_one_node); |
8d08fdba MS |
2100 | } |
2101 | ||
e92cc029 MS |
2102 | /* Return, as an INTEGER_CST node, the number of elements for TYPE |
2103 | (which is an ARRAY_TYPE). This one is a recursive count of all | |
2104 | ARRAY_TYPEs that are clumped together. */ | |
8d08fdba MS |
2105 | |
2106 | tree | |
b57b79f7 | 2107 | array_type_nelts_total (tree type) |
8d08fdba MS |
2108 | { |
2109 | tree sz = array_type_nelts_top (type); | |
2110 | type = TREE_TYPE (type); | |
2111 | while (TREE_CODE (type) == ARRAY_TYPE) | |
2112 | { | |
2113 | tree n = array_type_nelts_top (type); | |
db3927fb AH |
2114 | sz = fold_build2_loc (input_location, |
2115 | MULT_EXPR, sizetype, sz, n); | |
8d08fdba MS |
2116 | type = TREE_TYPE (type); |
2117 | } | |
2118 | return sz; | |
2119 | } | |
878cd289 | 2120 | |
b3ab27f3 MM |
2121 | /* Called from break_out_target_exprs via mapcar. */ |
2122 | ||
2123 | static tree | |
b57b79f7 | 2124 | bot_manip (tree* tp, int* walk_subtrees, void* data) |
878cd289 | 2125 | { |
8dfaeb63 MM |
2126 | splay_tree target_remap = ((splay_tree) data); |
2127 | tree t = *tp; | |
2128 | ||
edb7c512 | 2129 | if (!TYPE_P (t) && TREE_CONSTANT (t) && !TREE_SIDE_EFFECTS (t)) |
8dfaeb63 | 2130 | { |
a4d25b44 JM |
2131 | /* There can't be any TARGET_EXPRs or their slot variables below this |
2132 | point. But we must make a copy, in case subsequent processing | |
2133 | alters any part of it. For example, during gimplification a cast | |
2134 | of the form (T) &X::f (where "f" is a member function) will lead | |
2135 | to replacing the PTRMEM_CST for &X::f with a VAR_DECL. */ | |
8dfaeb63 | 2136 | *walk_subtrees = 0; |
a4d25b44 | 2137 | *tp = unshare_expr (t); |
8dfaeb63 MM |
2138 | return NULL_TREE; |
2139 | } | |
495d26d6 | 2140 | if (TREE_CODE (t) == TARGET_EXPR) |
73aad9b9 | 2141 | { |
b3ab27f3 MM |
2142 | tree u; |
2143 | ||
02531345 | 2144 | if (TREE_CODE (TREE_OPERAND (t, 1)) == AGGR_INIT_EXPR) |
875bcfdb JM |
2145 | { |
2146 | u = build_cplus_new (TREE_TYPE (t), TREE_OPERAND (t, 1), | |
2147 | tf_warning_or_error); | |
2148 | if (AGGR_INIT_ZERO_FIRST (TREE_OPERAND (t, 1))) | |
2149 | AGGR_INIT_ZERO_FIRST (TREE_OPERAND (u, 1)) = true; | |
2150 | } | |
9f63daea | 2151 | else |
574cfaa4 JM |
2152 | u = build_target_expr_with_type (TREE_OPERAND (t, 1), TREE_TYPE (t), |
2153 | tf_warning_or_error); | |
b3ab27f3 | 2154 | |
e08cc018 JM |
2155 | TARGET_EXPR_IMPLICIT_P (u) = TARGET_EXPR_IMPLICIT_P (t); |
2156 | TARGET_EXPR_LIST_INIT_P (u) = TARGET_EXPR_LIST_INIT_P (t); | |
2157 | TARGET_EXPR_DIRECT_INIT_P (u) = TARGET_EXPR_DIRECT_INIT_P (t); | |
2158 | ||
b3ab27f3 | 2159 | /* Map the old variable to the new one. */ |
9f63daea EC |
2160 | splay_tree_insert (target_remap, |
2161 | (splay_tree_key) TREE_OPERAND (t, 0), | |
b3ab27f3 | 2162 | (splay_tree_value) TREE_OPERAND (u, 0)); |
8dfaeb63 | 2163 | |
7efc22ea JM |
2164 | TREE_OPERAND (u, 1) = break_out_target_exprs (TREE_OPERAND (u, 1)); |
2165 | ||
8dfaeb63 MM |
2166 | /* Replace the old expression with the new version. */ |
2167 | *tp = u; | |
2168 | /* We don't have to go below this point; the recursive call to | |
2169 | break_out_target_exprs will have handled anything below this | |
2170 | point. */ | |
2171 | *walk_subtrees = 0; | |
2172 | return NULL_TREE; | |
73aad9b9 | 2173 | } |
73aad9b9 | 2174 | |
8dfaeb63 | 2175 | /* Make a copy of this node. */ |
5507a6c3 JM |
2176 | t = copy_tree_r (tp, walk_subtrees, NULL); |
2177 | if (TREE_CODE (*tp) == CALL_EXPR) | |
2178 | set_flags_from_callee (*tp); | |
2179 | return t; | |
878cd289 | 2180 | } |
9f63daea | 2181 | |
8dfaeb63 MM |
2182 | /* Replace all remapped VAR_DECLs in T with their new equivalents. |
2183 | DATA is really a splay-tree mapping old variables to new | |
2184 | variables. */ | |
b3ab27f3 MM |
2185 | |
2186 | static tree | |
12308bc6 | 2187 | bot_replace (tree* t, int* /*walk_subtrees*/, void* data) |
b3ab27f3 | 2188 | { |
8dfaeb63 MM |
2189 | splay_tree target_remap = ((splay_tree) data); |
2190 | ||
b3ab27f3 MM |
2191 | if (TREE_CODE (*t) == VAR_DECL) |
2192 | { | |
2193 | splay_tree_node n = splay_tree_lookup (target_remap, | |
2194 | (splay_tree_key) *t); | |
2195 | if (n) | |
2196 | *t = (tree) n->value; | |
2197 | } | |
382346e5 JM |
2198 | else if (TREE_CODE (*t) == PARM_DECL |
2199 | && DECL_NAME (*t) == this_identifier) | |
2200 | { | |
2201 | /* In an NSDMI we need to replace the 'this' parameter we used for | |
2202 | parsing with the real one for this function. */ | |
2203 | *t = current_class_ptr; | |
2204 | } | |
c65b0607 JM |
2205 | else if (TREE_CODE (*t) == CONVERT_EXPR |
2206 | && CONVERT_EXPR_VBASE_PATH (*t)) | |
2207 | { | |
2208 | /* In an NSDMI build_base_path defers building conversions to virtual | |
2209 | bases, and we handle it here. */ | |
2210 | tree basetype = TYPE_MAIN_VARIANT (TREE_TYPE (TREE_TYPE (*t))); | |
9771b263 | 2211 | vec<tree, va_gc> *vbases = CLASSTYPE_VBASECLASSES (current_class_type); |
c65b0607 | 2212 | int i; tree binfo; |
9771b263 | 2213 | FOR_EACH_VEC_SAFE_ELT (vbases, i, binfo) |
c65b0607 JM |
2214 | if (BINFO_TYPE (binfo) == basetype) |
2215 | break; | |
2216 | *t = build_base_path (PLUS_EXPR, TREE_OPERAND (*t, 0), binfo, true, | |
2217 | tf_warning_or_error); | |
2218 | } | |
b3ab27f3 MM |
2219 | |
2220 | return NULL_TREE; | |
2221 | } | |
9f63daea | 2222 | |
8dfaeb63 MM |
2223 | /* When we parse a default argument expression, we may create |
2224 | temporary variables via TARGET_EXPRs. When we actually use the | |
a4d25b44 JM |
2225 | default-argument expression, we make a copy of the expression |
2226 | and replace the temporaries with appropriate local versions. */ | |
e92cc029 | 2227 | |
878cd289 | 2228 | tree |
b57b79f7 | 2229 | break_out_target_exprs (tree t) |
878cd289 | 2230 | { |
8dfaeb63 MM |
2231 | static int target_remap_count; |
2232 | static splay_tree target_remap; | |
2233 | ||
b3ab27f3 | 2234 | if (!target_remap_count++) |
9f63daea EC |
2235 | target_remap = splay_tree_new (splay_tree_compare_pointers, |
2236 | /*splay_tree_delete_key_fn=*/NULL, | |
b3ab27f3 | 2237 | /*splay_tree_delete_value_fn=*/NULL); |
14588106 RG |
2238 | cp_walk_tree (&t, bot_manip, target_remap, NULL); |
2239 | cp_walk_tree (&t, bot_replace, target_remap, NULL); | |
b3ab27f3 MM |
2240 | |
2241 | if (!--target_remap_count) | |
2242 | { | |
2243 | splay_tree_delete (target_remap); | |
2244 | target_remap = NULL; | |
2245 | } | |
2246 | ||
2247 | return t; | |
878cd289 | 2248 | } |
f30432d7 | 2249 | |
8e1daa34 NS |
2250 | /* Similar to `build_nt', but for template definitions of dependent |
2251 | expressions */ | |
5566b478 MS |
2252 | |
2253 | tree | |
f330f599 | 2254 | build_min_nt_loc (location_t loc, enum tree_code code, ...) |
5566b478 | 2255 | { |
926ce8bd KH |
2256 | tree t; |
2257 | int length; | |
2258 | int i; | |
e34d07f2 | 2259 | va_list p; |
5566b478 | 2260 | |
5039610b SL |
2261 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
2262 | ||
e34d07f2 | 2263 | va_start (p, code); |
5566b478 | 2264 | |
5566b478 | 2265 | t = make_node (code); |
f330f599 | 2266 | SET_EXPR_LOCATION (t, loc); |
8d5e6e25 | 2267 | length = TREE_CODE_LENGTH (code); |
5566b478 MS |
2268 | |
2269 | for (i = 0; i < length; i++) | |
2270 | { | |
2271 | tree x = va_arg (p, tree); | |
2a1e9fdd | 2272 | TREE_OPERAND (t, i) = x; |
5566b478 MS |
2273 | } |
2274 | ||
e34d07f2 | 2275 | va_end (p); |
5566b478 MS |
2276 | return t; |
2277 | } | |
2278 | ||
5039610b | 2279 | |
8e1daa34 | 2280 | /* Similar to `build', but for template definitions. */ |
5566b478 MS |
2281 | |
2282 | tree | |
e34d07f2 | 2283 | build_min (enum tree_code code, tree tt, ...) |
5566b478 | 2284 | { |
926ce8bd KH |
2285 | tree t; |
2286 | int length; | |
2287 | int i; | |
e34d07f2 | 2288 | va_list p; |
5566b478 | 2289 | |
5039610b SL |
2290 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
2291 | ||
e34d07f2 | 2292 | va_start (p, tt); |
5566b478 | 2293 | |
5566b478 | 2294 | t = make_node (code); |
8d5e6e25 | 2295 | length = TREE_CODE_LENGTH (code); |
2a1e9fdd | 2296 | TREE_TYPE (t) = tt; |
5566b478 MS |
2297 | |
2298 | for (i = 0; i < length; i++) | |
2299 | { | |
2300 | tree x = va_arg (p, tree); | |
2a1e9fdd | 2301 | TREE_OPERAND (t, i) = x; |
4f976745 | 2302 | if (x && !TYPE_P (x) && TREE_SIDE_EFFECTS (x)) |
8e1daa34 | 2303 | TREE_SIDE_EFFECTS (t) = 1; |
5566b478 MS |
2304 | } |
2305 | ||
e34d07f2 | 2306 | va_end (p); |
5566b478 MS |
2307 | return t; |
2308 | } | |
2309 | ||
8e1daa34 NS |
2310 | /* Similar to `build', but for template definitions of non-dependent |
2311 | expressions. NON_DEP is the non-dependent expression that has been | |
2312 | built. */ | |
2313 | ||
2314 | tree | |
2315 | build_min_non_dep (enum tree_code code, tree non_dep, ...) | |
2316 | { | |
926ce8bd KH |
2317 | tree t; |
2318 | int length; | |
2319 | int i; | |
8e1daa34 NS |
2320 | va_list p; |
2321 | ||
5039610b SL |
2322 | gcc_assert (TREE_CODE_CLASS (code) != tcc_vl_exp); |
2323 | ||
8e1daa34 NS |
2324 | va_start (p, non_dep); |
2325 | ||
e87b4dde JM |
2326 | if (REFERENCE_REF_P (non_dep)) |
2327 | non_dep = TREE_OPERAND (non_dep, 0); | |
2328 | ||
8e1daa34 NS |
2329 | t = make_node (code); |
2330 | length = TREE_CODE_LENGTH (code); | |
2331 | TREE_TYPE (t) = TREE_TYPE (non_dep); | |
8e1daa34 NS |
2332 | TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep); |
2333 | ||
2334 | for (i = 0; i < length; i++) | |
2335 | { | |
2336 | tree x = va_arg (p, tree); | |
2337 | TREE_OPERAND (t, i) = x; | |
2338 | } | |
2339 | ||
2340 | if (code == COMPOUND_EXPR && TREE_CODE (non_dep) != COMPOUND_EXPR) | |
2341 | /* This should not be considered a COMPOUND_EXPR, because it | |
04c06002 | 2342 | resolves to an overload. */ |
8e1daa34 | 2343 | COMPOUND_EXPR_OVERLOADED (t) = 1; |
9f63daea | 2344 | |
8e1daa34 | 2345 | va_end (p); |
e87b4dde | 2346 | return convert_from_reference (t); |
8e1daa34 NS |
2347 | } |
2348 | ||
3fcb9d1b NF |
2349 | /* Similar to `build_nt_call_vec', but for template definitions of |
2350 | non-dependent expressions. NON_DEP is the non-dependent expression | |
2351 | that has been built. */ | |
5039610b SL |
2352 | |
2353 | tree | |
9771b263 | 2354 | build_min_non_dep_call_vec (tree non_dep, tree fn, vec<tree, va_gc> *argvec) |
5039610b | 2355 | { |
c166b898 | 2356 | tree t = build_nt_call_vec (fn, argvec); |
e87b4dde JM |
2357 | if (REFERENCE_REF_P (non_dep)) |
2358 | non_dep = TREE_OPERAND (non_dep, 0); | |
5039610b SL |
2359 | TREE_TYPE (t) = TREE_TYPE (non_dep); |
2360 | TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (non_dep); | |
e87b4dde | 2361 | return convert_from_reference (t); |
5039610b SL |
2362 | } |
2363 | ||
5566b478 | 2364 | tree |
b57b79f7 | 2365 | get_type_decl (tree t) |
5566b478 | 2366 | { |
5566b478 MS |
2367 | if (TREE_CODE (t) == TYPE_DECL) |
2368 | return t; | |
2f939d94 | 2369 | if (TYPE_P (t)) |
5566b478 | 2370 | return TYPE_STUB_DECL (t); |
315fb5db NS |
2371 | gcc_assert (t == error_mark_node); |
2372 | return t; | |
5566b478 MS |
2373 | } |
2374 | ||
700466c2 JM |
2375 | /* Returns the namespace that contains DECL, whether directly or |
2376 | indirectly. */ | |
2377 | ||
2378 | tree | |
b57b79f7 | 2379 | decl_namespace_context (tree decl) |
700466c2 JM |
2380 | { |
2381 | while (1) | |
2382 | { | |
2383 | if (TREE_CODE (decl) == NAMESPACE_DECL) | |
2384 | return decl; | |
2385 | else if (TYPE_P (decl)) | |
2386 | decl = CP_DECL_CONTEXT (TYPE_MAIN_DECL (decl)); | |
2387 | else | |
2388 | decl = CP_DECL_CONTEXT (decl); | |
2389 | } | |
2390 | } | |
2391 | ||
b9e75696 JM |
2392 | /* Returns true if decl is within an anonymous namespace, however deeply |
2393 | nested, or false otherwise. */ | |
2394 | ||
2395 | bool | |
58f9752a | 2396 | decl_anon_ns_mem_p (const_tree decl) |
b9e75696 JM |
2397 | { |
2398 | while (1) | |
2399 | { | |
653109bd | 2400 | if (decl == NULL_TREE || decl == error_mark_node) |
b9e75696 JM |
2401 | return false; |
2402 | if (TREE_CODE (decl) == NAMESPACE_DECL | |
2403 | && DECL_NAME (decl) == NULL_TREE) | |
2404 | return true; | |
2405 | /* Classes and namespaces inside anonymous namespaces have | |
2406 | TREE_PUBLIC == 0, so we can shortcut the search. */ | |
2407 | else if (TYPE_P (decl)) | |
82f2836c | 2408 | return (TREE_PUBLIC (TYPE_MAIN_DECL (decl)) == 0); |
b9e75696 JM |
2409 | else if (TREE_CODE (decl) == NAMESPACE_DECL) |
2410 | return (TREE_PUBLIC (decl) == 0); | |
2411 | else | |
2412 | decl = DECL_CONTEXT (decl); | |
2413 | } | |
2414 | } | |
2415 | ||
c873934c JM |
2416 | /* Subroutine of cp_tree_equal: t1 and t2 are the CALL_EXPR_FNs of two |
2417 | CALL_EXPRS. Return whether they are equivalent. */ | |
2418 | ||
2419 | static bool | |
2420 | called_fns_equal (tree t1, tree t2) | |
2421 | { | |
2422 | /* Core 1321: dependent names are equivalent even if the overload sets | |
2423 | are different. But do compare explicit template arguments. */ | |
2424 | tree name1 = dependent_name (t1); | |
2425 | tree name2 = dependent_name (t2); | |
2426 | if (name1 || name2) | |
2427 | { | |
2428 | tree targs1 = NULL_TREE, targs2 = NULL_TREE; | |
2429 | ||
2430 | if (name1 != name2) | |
2431 | return false; | |
2432 | ||
2433 | if (TREE_CODE (t1) == TEMPLATE_ID_EXPR) | |
2434 | targs1 = TREE_OPERAND (t1, 1); | |
2435 | if (TREE_CODE (t2) == TEMPLATE_ID_EXPR) | |
2436 | targs2 = TREE_OPERAND (t2, 1); | |
2437 | return cp_tree_equal (targs1, targs2); | |
2438 | } | |
2439 | else | |
2440 | return cp_tree_equal (t1, t2); | |
2441 | } | |
2442 | ||
67d743fe | 2443 | /* Return truthvalue of whether T1 is the same tree structure as T2. |
c8a209ca | 2444 | Return 1 if they are the same. Return 0 if they are different. */ |
67d743fe | 2445 | |
c8a209ca | 2446 | bool |
b57b79f7 | 2447 | cp_tree_equal (tree t1, tree t2) |
67d743fe | 2448 | { |
926ce8bd | 2449 | enum tree_code code1, code2; |
67d743fe MS |
2450 | |
2451 | if (t1 == t2) | |
c8a209ca NS |
2452 | return true; |
2453 | if (!t1 || !t2) | |
2454 | return false; | |
2455 | ||
2456 | for (code1 = TREE_CODE (t1); | |
1a87cf0c | 2457 | CONVERT_EXPR_CODE_P (code1) |
c8a209ca NS |
2458 | || code1 == NON_LVALUE_EXPR; |
2459 | code1 = TREE_CODE (t1)) | |
2460 | t1 = TREE_OPERAND (t1, 0); | |
2461 | for (code2 = TREE_CODE (t2); | |
1a87cf0c | 2462 | CONVERT_EXPR_CODE_P (code2) |
c8a209ca NS |
2463 | || code1 == NON_LVALUE_EXPR; |
2464 | code2 = TREE_CODE (t2)) | |
2465 | t2 = TREE_OPERAND (t2, 0); | |
2466 | ||
2467 | /* They might have become equal now. */ | |
2468 | if (t1 == t2) | |
2469 | return true; | |
9f63daea | 2470 | |
67d743fe | 2471 | if (code1 != code2) |
c8a209ca | 2472 | return false; |
67d743fe MS |
2473 | |
2474 | switch (code1) | |
2475 | { | |
2476 | case INTEGER_CST: | |
2477 | return TREE_INT_CST_LOW (t1) == TREE_INT_CST_LOW (t2) | |
2478 | && TREE_INT_CST_HIGH (t1) == TREE_INT_CST_HIGH (t2); | |
2479 | ||
2480 | case REAL_CST: | |
2481 | return REAL_VALUES_EQUAL (TREE_REAL_CST (t1), TREE_REAL_CST (t2)); | |
2482 | ||
2483 | case STRING_CST: | |
2484 | return TREE_STRING_LENGTH (t1) == TREE_STRING_LENGTH (t2) | |
da61dec9 | 2485 | && !memcmp (TREE_STRING_POINTER (t1), TREE_STRING_POINTER (t2), |
c8a209ca | 2486 | TREE_STRING_LENGTH (t1)); |
67d743fe | 2487 | |
d05739f8 JM |
2488 | case FIXED_CST: |
2489 | return FIXED_VALUES_IDENTICAL (TREE_FIXED_CST (t1), | |
2490 | TREE_FIXED_CST (t2)); | |
2491 | ||
2a2193e0 SM |
2492 | case COMPLEX_CST: |
2493 | return cp_tree_equal (TREE_REALPART (t1), TREE_REALPART (t2)) | |
2494 | && cp_tree_equal (TREE_IMAGPART (t1), TREE_IMAGPART (t2)); | |
2495 | ||
4eab75dd MG |
2496 | case VECTOR_CST: |
2497 | return operand_equal_p (t1, t2, OEP_ONLY_CONST); | |
2498 | ||
67d743fe | 2499 | case CONSTRUCTOR: |
7dd4bdf5 MM |
2500 | /* We need to do this when determining whether or not two |
2501 | non-type pointer to member function template arguments | |
2502 | are the same. */ | |
31d06664 JM |
2503 | if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2)) |
2504 | || CONSTRUCTOR_NELTS (t1) != CONSTRUCTOR_NELTS (t2)) | |
c8a209ca | 2505 | return false; |
31d06664 JM |
2506 | { |
2507 | tree field, value; | |
2508 | unsigned int i; | |
2509 | FOR_EACH_CONSTRUCTOR_ELT (CONSTRUCTOR_ELTS (t1), i, field, value) | |
2510 | { | |
2511 | constructor_elt *elt2 = CONSTRUCTOR_ELT (t2, i); | |
2512 | if (!cp_tree_equal (field, elt2->index) | |
2513 | || !cp_tree_equal (value, elt2->value)) | |
2514 | return false; | |
2515 | } | |
2516 | } | |
2517 | return true; | |
7dd4bdf5 MM |
2518 | |
2519 | case TREE_LIST: | |
c8a209ca NS |
2520 | if (!cp_tree_equal (TREE_PURPOSE (t1), TREE_PURPOSE (t2))) |
2521 | return false; | |
2522 | if (!cp_tree_equal (TREE_VALUE (t1), TREE_VALUE (t2))) | |
2523 | return false; | |
7dd4bdf5 | 2524 | return cp_tree_equal (TREE_CHAIN (t1), TREE_CHAIN (t2)); |
67d743fe MS |
2525 | |
2526 | case SAVE_EXPR: | |
2527 | return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
2528 | ||
2529 | case CALL_EXPR: | |
5039610b SL |
2530 | { |
2531 | tree arg1, arg2; | |
2532 | call_expr_arg_iterator iter1, iter2; | |
c873934c | 2533 | if (!called_fns_equal (CALL_EXPR_FN (t1), CALL_EXPR_FN (t2))) |
5039610b SL |
2534 | return false; |
2535 | for (arg1 = first_call_expr_arg (t1, &iter1), | |
2536 | arg2 = first_call_expr_arg (t2, &iter2); | |
2537 | arg1 && arg2; | |
2538 | arg1 = next_call_expr_arg (&iter1), | |
2539 | arg2 = next_call_expr_arg (&iter2)) | |
2540 | if (!cp_tree_equal (arg1, arg2)) | |
2541 | return false; | |
96b4a0b5 JM |
2542 | if (arg1 || arg2) |
2543 | return false; | |
2544 | return true; | |
5039610b | 2545 | } |
67d743fe | 2546 | |
c8a209ca NS |
2547 | case TARGET_EXPR: |
2548 | { | |
2549 | tree o1 = TREE_OPERAND (t1, 0); | |
2550 | tree o2 = TREE_OPERAND (t2, 0); | |
9f63daea | 2551 | |
c8a209ca NS |
2552 | /* Special case: if either target is an unallocated VAR_DECL, |
2553 | it means that it's going to be unified with whatever the | |
2554 | TARGET_EXPR is really supposed to initialize, so treat it | |
2555 | as being equivalent to anything. */ | |
2556 | if (TREE_CODE (o1) == VAR_DECL && DECL_NAME (o1) == NULL_TREE | |
2557 | && !DECL_RTL_SET_P (o1)) | |
2558 | /*Nop*/; | |
2559 | else if (TREE_CODE (o2) == VAR_DECL && DECL_NAME (o2) == NULL_TREE | |
2560 | && !DECL_RTL_SET_P (o2)) | |
2561 | /*Nop*/; | |
2562 | else if (!cp_tree_equal (o1, o2)) | |
2563 | return false; | |
9f63daea | 2564 | |
c8a209ca NS |
2565 | return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1)); |
2566 | } | |
9f63daea | 2567 | |
67d743fe | 2568 | case WITH_CLEANUP_EXPR: |
c8a209ca NS |
2569 | if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))) |
2570 | return false; | |
6ad7895a | 2571 | return cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t1, 1)); |
67d743fe MS |
2572 | |
2573 | case COMPONENT_REF: | |
c8a209ca NS |
2574 | if (TREE_OPERAND (t1, 1) != TREE_OPERAND (t2, 1)) |
2575 | return false; | |
2576 | return cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)); | |
67d743fe | 2577 | |
67d743fe | 2578 | case PARM_DECL: |
a77f94e2 | 2579 | /* For comparing uses of parameters in late-specified return types |
e7dc5734 JM |
2580 | with an out-of-class definition of the function, but can also come |
2581 | up for expressions that involve 'this' in a member function | |
2582 | template. */ | |
25976b7f JM |
2583 | |
2584 | if (comparing_specializations) | |
2585 | /* When comparing hash table entries, only an exact match is | |
2586 | good enough; we don't want to replace 'this' with the | |
2587 | version from another function. */ | |
2588 | return false; | |
2589 | ||
e7dc5734 JM |
2590 | if (same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))) |
2591 | { | |
2592 | if (DECL_ARTIFICIAL (t1) ^ DECL_ARTIFICIAL (t2)) | |
2593 | return false; | |
2594 | if (DECL_ARTIFICIAL (t1) | |
2595 | || (DECL_PARM_LEVEL (t1) == DECL_PARM_LEVEL (t2) | |
2596 | && DECL_PARM_INDEX (t1) == DECL_PARM_INDEX (t2))) | |
2597 | return true; | |
2598 | } | |
2599 | return false; | |
a77f94e2 JM |
2600 | |
2601 | case VAR_DECL: | |
67d743fe | 2602 | case CONST_DECL: |
9b2770f2 | 2603 | case FIELD_DECL: |
67d743fe | 2604 | case FUNCTION_DECL: |
c8a209ca NS |
2605 | case TEMPLATE_DECL: |
2606 | case IDENTIFIER_NODE: | |
47c0c7d7 | 2607 | case SSA_NAME: |
c8a209ca | 2608 | return false; |
67d743fe | 2609 | |
17a27b4f MM |
2610 | case BASELINK: |
2611 | return (BASELINK_BINFO (t1) == BASELINK_BINFO (t2) | |
2612 | && BASELINK_ACCESS_BINFO (t1) == BASELINK_ACCESS_BINFO (t2) | |
4643a68e | 2613 | && BASELINK_QUALIFIED_P (t1) == BASELINK_QUALIFIED_P (t2) |
17a27b4f MM |
2614 | && cp_tree_equal (BASELINK_FUNCTIONS (t1), |
2615 | BASELINK_FUNCTIONS (t2))); | |
2616 | ||
f84b4be9 | 2617 | case TEMPLATE_PARM_INDEX: |
31758337 NS |
2618 | return (TEMPLATE_PARM_IDX (t1) == TEMPLATE_PARM_IDX (t2) |
2619 | && TEMPLATE_PARM_LEVEL (t1) == TEMPLATE_PARM_LEVEL (t2) | |
9524f710 LE |
2620 | && (TEMPLATE_PARM_PARAMETER_PACK (t1) |
2621 | == TEMPLATE_PARM_PARAMETER_PACK (t2)) | |
31758337 NS |
2622 | && same_type_p (TREE_TYPE (TEMPLATE_PARM_DECL (t1)), |
2623 | TREE_TYPE (TEMPLATE_PARM_DECL (t2)))); | |
67d743fe | 2624 | |
bf12d54d | 2625 | case TEMPLATE_ID_EXPR: |
c873934c JM |
2626 | return (cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0)) |
2627 | && cp_tree_equal (TREE_OPERAND (t1, 1), TREE_OPERAND (t2, 1))); | |
2628 | ||
2629 | case TREE_VEC: | |
bf12d54d NS |
2630 | { |
2631 | unsigned ix; | |
c873934c | 2632 | if (TREE_VEC_LENGTH (t1) != TREE_VEC_LENGTH (t2)) |
bf12d54d | 2633 | return false; |
c873934c JM |
2634 | for (ix = TREE_VEC_LENGTH (t1); ix--;) |
2635 | if (!cp_tree_equal (TREE_VEC_ELT (t1, ix), | |
2636 | TREE_VEC_ELT (t2, ix))) | |
bf12d54d | 2637 | return false; |
bf12d54d NS |
2638 | return true; |
2639 | } | |
9f63daea | 2640 | |
67d743fe | 2641 | case SIZEOF_EXPR: |
abff8e06 | 2642 | case ALIGNOF_EXPR: |
c8a209ca NS |
2643 | { |
2644 | tree o1 = TREE_OPERAND (t1, 0); | |
2645 | tree o2 = TREE_OPERAND (t2, 0); | |
9f63daea | 2646 | |
ba29e5c2 JJ |
2647 | if (code1 == SIZEOF_EXPR) |
2648 | { | |
2649 | if (SIZEOF_EXPR_TYPE_P (t1)) | |
2650 | o1 = TREE_TYPE (o1); | |
2651 | if (SIZEOF_EXPR_TYPE_P (t2)) | |
2652 | o2 = TREE_TYPE (o2); | |
2653 | } | |
c8a209ca NS |
2654 | if (TREE_CODE (o1) != TREE_CODE (o2)) |
2655 | return false; | |
2656 | if (TYPE_P (o1)) | |
2657 | return same_type_p (o1, o2); | |
2658 | else | |
2659 | return cp_tree_equal (o1, o2); | |
2660 | } | |
9f63daea | 2661 | |
6f9f76e3 SM |
2662 | case MODOP_EXPR: |
2663 | { | |
2664 | tree t1_op1, t2_op1; | |
2665 | ||
2666 | if (!cp_tree_equal (TREE_OPERAND (t1, 0), TREE_OPERAND (t2, 0))) | |
2667 | return false; | |
2668 | ||
2669 | t1_op1 = TREE_OPERAND (t1, 1); | |
2670 | t2_op1 = TREE_OPERAND (t2, 1); | |
2671 | if (TREE_CODE (t1_op1) != TREE_CODE (t2_op1)) | |
2672 | return false; | |
2673 | ||
2674 | return cp_tree_equal (TREE_OPERAND (t1, 2), TREE_OPERAND (t2, 2)); | |
2675 | } | |
2676 | ||
61a127b3 MM |
2677 | case PTRMEM_CST: |
2678 | /* Two pointer-to-members are the same if they point to the same | |
2679 | field or function in the same class. */ | |
c8a209ca NS |
2680 | if (PTRMEM_CST_MEMBER (t1) != PTRMEM_CST_MEMBER (t2)) |
2681 | return false; | |
2682 | ||
2683 | return same_type_p (PTRMEM_CST_CLASS (t1), PTRMEM_CST_CLASS (t2)); | |
61a127b3 | 2684 | |
943e3ede MM |
2685 | case OVERLOAD: |
2686 | if (OVL_FUNCTION (t1) != OVL_FUNCTION (t2)) | |
2687 | return false; | |
2688 | return cp_tree_equal (OVL_CHAIN (t1), OVL_CHAIN (t2)); | |
2689 | ||
ea798d0f PC |
2690 | case TRAIT_EXPR: |
2691 | if (TRAIT_EXPR_KIND (t1) != TRAIT_EXPR_KIND (t2)) | |
2692 | return false; | |
2693 | return same_type_p (TRAIT_EXPR_TYPE1 (t1), TRAIT_EXPR_TYPE1 (t2)) | |
2694 | && same_type_p (TRAIT_EXPR_TYPE2 (t1), TRAIT_EXPR_TYPE2 (t2)); | |
2695 | ||
ab73eba8 JM |
2696 | case CAST_EXPR: |
2697 | case STATIC_CAST_EXPR: | |
2698 | case REINTERPRET_CAST_EXPR: | |
2699 | case CONST_CAST_EXPR: | |
2700 | case DYNAMIC_CAST_EXPR: | |
a4474a38 | 2701 | case IMPLICIT_CONV_EXPR: |
ab73eba8 JM |
2702 | case NEW_EXPR: |
2703 | if (!same_type_p (TREE_TYPE (t1), TREE_TYPE (t2))) | |
2704 | return false; | |
2705 | /* Now compare operands as usual. */ | |
2706 | break; | |
2707 | ||
10261728 JM |
2708 | case DEFERRED_NOEXCEPT: |
2709 | return (cp_tree_equal (DEFERRED_NOEXCEPT_PATTERN (t1), | |
2710 | DEFERRED_NOEXCEPT_PATTERN (t2)) | |
2711 | && comp_template_args (DEFERRED_NOEXCEPT_ARGS (t1), | |
2712 | DEFERRED_NOEXCEPT_ARGS (t2))); | |
2713 | break; | |
2714 | ||
7f85441b KG |
2715 | default: |
2716 | break; | |
67d743fe MS |
2717 | } |
2718 | ||
2719 | switch (TREE_CODE_CLASS (code1)) | |
2720 | { | |
6615c446 JO |
2721 | case tcc_unary: |
2722 | case tcc_binary: | |
2723 | case tcc_comparison: | |
2724 | case tcc_expression: | |
5039610b | 2725 | case tcc_vl_exp: |
6615c446 JO |
2726 | case tcc_reference: |
2727 | case tcc_statement: | |
aa1826e2 | 2728 | { |
5039610b SL |
2729 | int i, n; |
2730 | ||
d26e5986 | 2731 | n = cp_tree_operand_length (t1); |
5039610b SL |
2732 | if (TREE_CODE_CLASS (code1) == tcc_vl_exp |
2733 | && n != TREE_OPERAND_LENGTH (t2)) | |
2734 | return false; | |
9f63daea | 2735 | |
5039610b | 2736 | for (i = 0; i < n; ++i) |
c8a209ca NS |
2737 | if (!cp_tree_equal (TREE_OPERAND (t1, i), TREE_OPERAND (t2, i))) |
2738 | return false; | |
9f63daea | 2739 | |
c8a209ca | 2740 | return true; |
aa1826e2 | 2741 | } |
9f63daea | 2742 | |
6615c446 | 2743 | case tcc_type: |
c8a209ca | 2744 | return same_type_p (t1, t2); |
6615c446 JO |
2745 | default: |
2746 | gcc_unreachable (); | |
67d743fe | 2747 | } |
6615c446 | 2748 | /* We can get here with --disable-checking. */ |
c8a209ca | 2749 | return false; |
67d743fe | 2750 | } |
73aad9b9 | 2751 | |
d11ad92e MS |
2752 | /* The type of ARG when used as an lvalue. */ |
2753 | ||
2754 | tree | |
b57b79f7 | 2755 | lvalue_type (tree arg) |
d11ad92e | 2756 | { |
2c73f9f5 | 2757 | tree type = TREE_TYPE (arg); |
8cd4c175 | 2758 | return type; |
d11ad92e MS |
2759 | } |
2760 | ||
2761 | /* The type of ARG for printing error messages; denote lvalues with | |
2762 | reference types. */ | |
2763 | ||
2764 | tree | |
b57b79f7 | 2765 | error_type (tree arg) |
d11ad92e MS |
2766 | { |
2767 | tree type = TREE_TYPE (arg); | |
9f63daea | 2768 | |
d11ad92e MS |
2769 | if (TREE_CODE (type) == ARRAY_TYPE) |
2770 | ; | |
08476342 NS |
2771 | else if (TREE_CODE (type) == ERROR_MARK) |
2772 | ; | |
d11ad92e MS |
2773 | else if (real_lvalue_p (arg)) |
2774 | type = build_reference_type (lvalue_type (arg)); | |
9e1e64ec | 2775 | else if (MAYBE_CLASS_TYPE_P (type)) |
d11ad92e MS |
2776 | type = lvalue_type (arg); |
2777 | ||
2778 | return type; | |
2779 | } | |
eb66be0e MS |
2780 | |
2781 | /* Does FUNCTION use a variable-length argument list? */ | |
2782 | ||
2783 | int | |
58f9752a | 2784 | varargs_function_p (const_tree function) |
eb66be0e | 2785 | { |
f38958e8 | 2786 | return stdarg_p (TREE_TYPE (function)); |
eb66be0e | 2787 | } |
f94ae2f5 JM |
2788 | |
2789 | /* Returns 1 if decl is a member of a class. */ | |
2790 | ||
2791 | int | |
58f9752a | 2792 | member_p (const_tree decl) |
f94ae2f5 | 2793 | { |
58f9752a | 2794 | const_tree const ctx = DECL_CONTEXT (decl); |
2f939d94 | 2795 | return (ctx && TYPE_P (ctx)); |
f94ae2f5 | 2796 | } |
51924768 JM |
2797 | |
2798 | /* Create a placeholder for member access where we don't actually have an | |
2799 | object that the access is against. */ | |
2800 | ||
2801 | tree | |
b57b79f7 | 2802 | build_dummy_object (tree type) |
51924768 | 2803 | { |
44689c12 | 2804 | tree decl = build1 (NOP_EXPR, build_pointer_type (type), void_zero_node); |
dd865ef6 | 2805 | return cp_build_indirect_ref (decl, RO_NULL, tf_warning_or_error); |
51924768 JM |
2806 | } |
2807 | ||
2808 | /* We've gotten a reference to a member of TYPE. Return *this if appropriate, | |
2809 | or a dummy object otherwise. If BINFOP is non-0, it is filled with the | |
2810 | binfo path from current_class_type to TYPE, or 0. */ | |
2811 | ||
2812 | tree | |
b57b79f7 | 2813 | maybe_dummy_object (tree type, tree* binfop) |
51924768 JM |
2814 | { |
2815 | tree decl, context; | |
2db1ab2d | 2816 | tree binfo; |
a6846853 | 2817 | tree current = current_nonlambda_class_type (); |
9f63daea | 2818 | |
a6846853 | 2819 | if (current |
22854930 PC |
2820 | && (binfo = lookup_base (current, type, ba_any, NULL, |
2821 | tf_warning_or_error))) | |
a6846853 | 2822 | context = current; |
51924768 JM |
2823 | else |
2824 | { | |
2825 | /* Reference from a nested class member function. */ | |
2826 | context = type; | |
2db1ab2d | 2827 | binfo = TYPE_BINFO (type); |
51924768 JM |
2828 | } |
2829 | ||
2db1ab2d NS |
2830 | if (binfop) |
2831 | *binfop = binfo; | |
9f63daea | 2832 | |
41d04a8d JM |
2833 | if (current_class_ref |
2834 | /* current_class_ref might not correspond to current_class_type if | |
2835 | we're in tsubst_default_argument or a lambda-declarator; in either | |
2836 | case, we want to use current_class_ref if it matches CONTEXT. */ | |
2837 | && (same_type_ignoring_top_level_qualifiers_p | |
2838 | (TREE_TYPE (current_class_ref), context))) | |
51924768 | 2839 | decl = current_class_ref; |
a6846853 JM |
2840 | else if (current != current_class_type |
2841 | && context == nonlambda_method_basetype ()) | |
2842 | /* In a lambda, need to go through 'this' capture. */ | |
ac4b1cc0 | 2843 | decl = (build_x_indirect_ref |
4fe977f2 PC |
2844 | (input_location, (lambda_expr_this_capture |
2845 | (CLASSTYPE_LAMBDA_EXPR (current_class_type))), | |
a6846853 | 2846 | RO_NULL, tf_warning_or_error)); |
51924768 JM |
2847 | else |
2848 | decl = build_dummy_object (context); | |
2849 | ||
2850 | return decl; | |
2851 | } | |
2852 | ||
2853 | /* Returns 1 if OB is a placeholder object, or a pointer to one. */ | |
2854 | ||
2855 | int | |
58f9752a | 2856 | is_dummy_object (const_tree ob) |
51924768 JM |
2857 | { |
2858 | if (TREE_CODE (ob) == INDIRECT_REF) | |
2859 | ob = TREE_OPERAND (ob, 0); | |
2860 | return (TREE_CODE (ob) == NOP_EXPR | |
44689c12 | 2861 | && TREE_OPERAND (ob, 0) == void_zero_node); |
51924768 | 2862 | } |
5524676d | 2863 | |
c32097d8 JM |
2864 | /* Returns 1 iff type T is something we want to treat as a scalar type for |
2865 | the purpose of deciding whether it is trivial/POD/standard-layout. */ | |
2866 | ||
11f35925 | 2867 | bool |
c32097d8 JM |
2868 | scalarish_type_p (const_tree t) |
2869 | { | |
2870 | if (t == error_mark_node) | |
2871 | return 1; | |
2872 | ||
2873 | return (SCALAR_TYPE_P (t) | |
2874 | || TREE_CODE (t) == VECTOR_TYPE); | |
2875 | } | |
2876 | ||
2877 | /* Returns true iff T requires non-trivial default initialization. */ | |
2878 | ||
2879 | bool | |
2880 | type_has_nontrivial_default_init (const_tree t) | |
2881 | { | |
2882 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2883 | ||
2884 | if (CLASS_TYPE_P (t)) | |
2885 | return TYPE_HAS_COMPLEX_DFLT (t); | |
2886 | else | |
2887 | return 0; | |
2888 | } | |
2889 | ||
d758e847 JM |
2890 | /* Returns true iff copying an object of type T (including via move |
2891 | constructor) is non-trivial. That is, T has no non-trivial copy | |
2892 | constructors and no non-trivial move constructors. */ | |
c32097d8 JM |
2893 | |
2894 | bool | |
2895 | type_has_nontrivial_copy_init (const_tree t) | |
2896 | { | |
2897 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2898 | ||
2899 | if (CLASS_TYPE_P (t)) | |
d758e847 JM |
2900 | { |
2901 | gcc_assert (COMPLETE_TYPE_P (t)); | |
2902 | return ((TYPE_HAS_COPY_CTOR (t) | |
2903 | && TYPE_HAS_COMPLEX_COPY_CTOR (t)) | |
2904 | || TYPE_HAS_COMPLEX_MOVE_CTOR (t)); | |
2905 | } | |
c32097d8 JM |
2906 | else |
2907 | return 0; | |
2908 | } | |
2909 | ||
46408846 JM |
2910 | /* Returns 1 iff type T is a trivially copyable type, as defined in |
2911 | [basic.types] and [class]. */ | |
c32097d8 JM |
2912 | |
2913 | bool | |
46408846 | 2914 | trivially_copyable_p (const_tree t) |
c32097d8 JM |
2915 | { |
2916 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2917 | ||
2918 | if (CLASS_TYPE_P (t)) | |
d758e847 JM |
2919 | return ((!TYPE_HAS_COPY_CTOR (t) |
2920 | || !TYPE_HAS_COMPLEX_COPY_CTOR (t)) | |
2921 | && !TYPE_HAS_COMPLEX_MOVE_CTOR (t) | |
2922 | && (!TYPE_HAS_COPY_ASSIGN (t) | |
2923 | || !TYPE_HAS_COMPLEX_COPY_ASSIGN (t)) | |
2924 | && !TYPE_HAS_COMPLEX_MOVE_ASSIGN (t) | |
334738b4 | 2925 | && TYPE_HAS_TRIVIAL_DESTRUCTOR (t)); |
c32097d8 JM |
2926 | else |
2927 | return scalarish_type_p (t); | |
2928 | } | |
2929 | ||
46408846 JM |
2930 | /* Returns 1 iff type T is a trivial type, as defined in [basic.types] and |
2931 | [class]. */ | |
2932 | ||
2933 | bool | |
2934 | trivial_type_p (const_tree t) | |
2935 | { | |
2936 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2937 | ||
2938 | if (CLASS_TYPE_P (t)) | |
2939 | return (TYPE_HAS_TRIVIAL_DFLT (t) | |
2940 | && trivially_copyable_p (t)); | |
2941 | else | |
2942 | return scalarish_type_p (t); | |
2943 | } | |
2944 | ||
5524676d JM |
2945 | /* Returns 1 iff type T is a POD type, as defined in [basic.types]. */ |
2946 | ||
c32097d8 | 2947 | bool |
58f9752a | 2948 | pod_type_p (const_tree t) |
5524676d | 2949 | { |
4e9b57fa | 2950 | /* This CONST_CAST is okay because strip_array_types returns its |
75547801 | 2951 | argument unmodified and we assign it to a const_tree. */ |
b1d5455a | 2952 | t = strip_array_types (CONST_CAST_TREE(t)); |
5524676d | 2953 | |
cc72bbaa JM |
2954 | if (!CLASS_TYPE_P (t)) |
2955 | return scalarish_type_p (t); | |
2956 | else if (cxx_dialect > cxx98) | |
c32097d8 JM |
2957 | /* [class]/10: A POD struct is a class that is both a trivial class and a |
2958 | standard-layout class, and has no non-static data members of type | |
2959 | non-POD struct, non-POD union (or array of such types). | |
2960 | ||
2961 | We don't need to check individual members because if a member is | |
2962 | non-std-layout or non-trivial, the class will be too. */ | |
2963 | return (std_layout_type_p (t) && trivial_type_p (t)); | |
2964 | else | |
cc72bbaa JM |
2965 | /* The C++98 definition of POD is different. */ |
2966 | return !CLASSTYPE_NON_LAYOUT_POD_P (t); | |
c32097d8 JM |
2967 | } |
2968 | ||
2969 | /* Returns true iff T is POD for the purpose of layout, as defined in the | |
2970 | C++ ABI. */ | |
2971 | ||
2972 | bool | |
2973 | layout_pod_type_p (const_tree t) | |
2974 | { | |
2975 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2976 | ||
2977 | if (CLASS_TYPE_P (t)) | |
2978 | return !CLASSTYPE_NON_LAYOUT_POD_P (t); | |
2979 | else | |
2980 | return scalarish_type_p (t); | |
2981 | } | |
2982 | ||
2983 | /* Returns true iff T is a standard-layout type, as defined in | |
2984 | [basic.types]. */ | |
2985 | ||
2986 | bool | |
2987 | std_layout_type_p (const_tree t) | |
2988 | { | |
2989 | t = strip_array_types (CONST_CAST_TREE (t)); | |
2990 | ||
2991 | if (CLASS_TYPE_P (t)) | |
2992 | return !CLASSTYPE_NON_STD_LAYOUT (t); | |
2993 | else | |
2994 | return scalarish_type_p (t); | |
5524676d | 2995 | } |
e5dc5fb2 | 2996 | |
39ef6592 LC |
2997 | /* Nonzero iff type T is a class template implicit specialization. */ |
2998 | ||
2999 | bool | |
ac7d7749 | 3000 | class_tmpl_impl_spec_p (const_tree t) |
39ef6592 LC |
3001 | { |
3002 | return CLASS_TYPE_P (t) && CLASSTYPE_TEMPLATE_INSTANTIATION (t); | |
3003 | } | |
3004 | ||
94e6e4c4 AO |
3005 | /* Returns 1 iff zero initialization of type T means actually storing |
3006 | zeros in it. */ | |
3007 | ||
3008 | int | |
58f9752a | 3009 | zero_init_p (const_tree t) |
94e6e4c4 | 3010 | { |
4e9b57fa | 3011 | /* This CONST_CAST is okay because strip_array_types returns its |
75547801 | 3012 | argument unmodified and we assign it to a const_tree. */ |
b1d5455a | 3013 | t = strip_array_types (CONST_CAST_TREE(t)); |
94e6e4c4 | 3014 | |
17bbb839 MM |
3015 | if (t == error_mark_node) |
3016 | return 1; | |
3017 | ||
94e6e4c4 | 3018 | /* NULL pointers to data members are initialized with -1. */ |
66b1156a | 3019 | if (TYPE_PTRDATAMEM_P (t)) |
94e6e4c4 AO |
3020 | return 0; |
3021 | ||
3022 | /* Classes that contain types that can't be zero-initialized, cannot | |
3023 | be zero-initialized themselves. */ | |
3024 | if (CLASS_TYPE_P (t) && CLASSTYPE_NON_ZERO_INIT_P (t)) | |
3025 | return 0; | |
3026 | ||
3027 | return 1; | |
3028 | } | |
3029 | ||
91d231cb | 3030 | /* Table of valid C++ attributes. */ |
349ae713 | 3031 | const struct attribute_spec cxx_attribute_table[] = |
e5dc5fb2 | 3032 | { |
62d784f7 KT |
3033 | /* { name, min_len, max_len, decl_req, type_req, fn_type_req, handler, |
3034 | affects_type_identity } */ | |
3035 | { "java_interface", 0, 0, false, false, false, | |
3036 | handle_java_interface_attribute, false }, | |
3037 | { "com_interface", 0, 0, false, false, false, | |
3038 | handle_com_interface_attribute, false }, | |
3039 | { "init_priority", 1, 1, true, false, false, | |
3040 | handle_init_priority_attribute, false }, | |
7dbb85a7 JM |
3041 | { "abi_tag", 1, -1, false, false, false, |
3042 | handle_abi_tag_attribute, true }, | |
62d784f7 | 3043 | { NULL, 0, 0, false, false, false, NULL, false } |
91d231cb JM |
3044 | }; |
3045 | ||
3046 | /* Handle a "java_interface" attribute; arguments as in | |
3047 | struct attribute_spec.handler. */ | |
3048 | static tree | |
9f63daea | 3049 | handle_java_interface_attribute (tree* node, |
0cbd7506 | 3050 | tree name, |
12308bc6 | 3051 | tree /*args*/, |
0cbd7506 MS |
3052 | int flags, |
3053 | bool* no_add_attrs) | |
91d231cb JM |
3054 | { |
3055 | if (DECL_P (*node) | |
3056 | || !CLASS_TYPE_P (*node) | |
3057 | || !TYPE_FOR_JAVA (*node)) | |
60c87482 | 3058 | { |
a82e1a7d | 3059 | error ("%qE attribute can only be applied to Java class definitions", |
4460cef2 | 3060 | name); |
91d231cb JM |
3061 | *no_add_attrs = true; |
3062 | return NULL_TREE; | |
60c87482 | 3063 | } |
91d231cb | 3064 | if (!(flags & (int) ATTR_FLAG_TYPE_IN_PLACE)) |
8dd16ecc | 3065 | *node = build_variant_type_copy (*node); |
91d231cb | 3066 | TYPE_JAVA_INTERFACE (*node) = 1; |
e5dc5fb2 | 3067 | |
91d231cb JM |
3068 | return NULL_TREE; |
3069 | } | |
3070 | ||
3071 | /* Handle a "com_interface" attribute; arguments as in | |
3072 | struct attribute_spec.handler. */ | |
3073 | static tree | |
9f63daea | 3074 | handle_com_interface_attribute (tree* node, |
0cbd7506 | 3075 | tree name, |
12308bc6 PC |
3076 | tree /*args*/, |
3077 | int /*flags*/, | |
0cbd7506 | 3078 | bool* no_add_attrs) |
91d231cb JM |
3079 | { |
3080 | static int warned; | |
3081 | ||
3082 | *no_add_attrs = true; | |
3083 | ||
3084 | if (DECL_P (*node) | |
3085 | || !CLASS_TYPE_P (*node) | |
3086 | || *node != TYPE_MAIN_VARIANT (*node)) | |
e5dc5fb2 | 3087 | { |
5c498b10 DD |
3088 | warning (OPT_Wattributes, "%qE attribute can only be applied " |
3089 | "to class definitions", name); | |
91d231cb JM |
3090 | return NULL_TREE; |
3091 | } | |
e5dc5fb2 | 3092 | |
91d231cb | 3093 | if (!warned++) |
d4ee4d25 | 3094 | warning (0, "%qE is obsolete; g++ vtables are now COM-compatible by default", |
4460cef2 | 3095 | name); |
91d231cb JM |
3096 | |
3097 | return NULL_TREE; | |
3098 | } | |
3099 | ||
3100 | /* Handle an "init_priority" attribute; arguments as in | |
3101 | struct attribute_spec.handler. */ | |
3102 | static tree | |
9f63daea | 3103 | handle_init_priority_attribute (tree* node, |
0cbd7506 MS |
3104 | tree name, |
3105 | tree args, | |
12308bc6 | 3106 | int /*flags*/, |
0cbd7506 | 3107 | bool* no_add_attrs) |
91d231cb JM |
3108 | { |
3109 | tree initp_expr = TREE_VALUE (args); | |
3110 | tree decl = *node; | |
3111 | tree type = TREE_TYPE (decl); | |
3112 | int pri; | |
3113 | ||
3114 | STRIP_NOPS (initp_expr); | |
9f63daea | 3115 | |
91d231cb JM |
3116 | if (!initp_expr || TREE_CODE (initp_expr) != INTEGER_CST) |
3117 | { | |
3118 | error ("requested init_priority is not an integer constant"); | |
3119 | *no_add_attrs = true; | |
3120 | return NULL_TREE; | |
3121 | } | |
e5dc5fb2 | 3122 | |
91d231cb | 3123 | pri = TREE_INT_CST_LOW (initp_expr); |
9f63daea | 3124 | |
91d231cb JM |
3125 | type = strip_array_types (type); |
3126 | ||
3127 | if (decl == NULL_TREE | |
3128 | || TREE_CODE (decl) != VAR_DECL | |
3129 | || !TREE_STATIC (decl) | |
3130 | || DECL_EXTERNAL (decl) | |
3131 | || (TREE_CODE (type) != RECORD_TYPE | |
3132 | && TREE_CODE (type) != UNION_TYPE) | |
3133 | /* Static objects in functions are initialized the | |
3134 | first time control passes through that | |
3135 | function. This is not precise enough to pin down an | |
c6002625 | 3136 | init_priority value, so don't allow it. */ |
9f63daea | 3137 | || current_function_decl) |
91d231cb | 3138 | { |
a82e1a7d | 3139 | error ("can only use %qE attribute on file-scope definitions " |
0cbd7506 | 3140 | "of objects of class type", name); |
91d231cb JM |
3141 | *no_add_attrs = true; |
3142 | return NULL_TREE; | |
3143 | } | |
e5dc5fb2 | 3144 | |
91d231cb JM |
3145 | if (pri > MAX_INIT_PRIORITY || pri <= 0) |
3146 | { | |
3147 | error ("requested init_priority is out of range"); | |
3148 | *no_add_attrs = true; | |
3149 | return NULL_TREE; | |
3150 | } | |
e5dc5fb2 | 3151 | |
91d231cb JM |
3152 | /* Check for init_priorities that are reserved for |
3153 | language and runtime support implementations.*/ | |
3154 | if (pri <= MAX_RESERVED_INIT_PRIORITY) | |
3155 | { | |
9f63daea | 3156 | warning |
d4ee4d25 | 3157 | (0, "requested init_priority is reserved for internal use"); |
e5dc5fb2 JM |
3158 | } |
3159 | ||
91d231cb JM |
3160 | if (SUPPORTS_INIT_PRIORITY) |
3161 | { | |
820cc88f DB |
3162 | SET_DECL_INIT_PRIORITY (decl, pri); |
3163 | DECL_HAS_INIT_PRIORITY_P (decl) = 1; | |
91d231cb JM |
3164 | return NULL_TREE; |
3165 | } | |
3166 | else | |
3167 | { | |
a82e1a7d | 3168 | error ("%qE attribute is not supported on this platform", name); |
91d231cb JM |
3169 | *no_add_attrs = true; |
3170 | return NULL_TREE; | |
3171 | } | |
e5dc5fb2 | 3172 | } |
87533b37 | 3173 | |
7dbb85a7 JM |
3174 | /* DECL is being redeclared; the old declaration had the abi tags in OLD, |
3175 | and the new one has the tags in NEW_. Give an error if there are tags | |
3176 | in NEW_ that weren't in OLD. */ | |
3177 | ||
3178 | bool | |
3179 | check_abi_tag_redeclaration (const_tree decl, const_tree old, const_tree new_) | |
3180 | { | |
3181 | if (old && TREE_CODE (TREE_VALUE (old)) == TREE_LIST) | |
3182 | old = TREE_VALUE (old); | |
3183 | if (new_ && TREE_CODE (TREE_VALUE (new_)) == TREE_LIST) | |
3184 | new_ = TREE_VALUE (new_); | |
3185 | bool err = false; | |
3186 | for (const_tree t = new_; t; t = TREE_CHAIN (t)) | |
3187 | { | |
3188 | tree str = TREE_VALUE (t); | |
3189 | for (const_tree in = old; in; in = TREE_CHAIN (in)) | |
3190 | { | |
3191 | tree ostr = TREE_VALUE (in); | |
3192 | if (cp_tree_equal (str, ostr)) | |
3193 | goto found; | |
3194 | } | |
3195 | error ("redeclaration of %qD adds abi tag %E", decl, str); | |
3196 | err = true; | |
3197 | found:; | |
3198 | } | |
3199 | if (err) | |
3200 | { | |
3201 | inform (DECL_SOURCE_LOCATION (decl), "previous declaration here"); | |
3202 | return false; | |
3203 | } | |
3204 | return true; | |
3205 | } | |
3206 | ||
3207 | /* Handle an "abi_tag" attribute; arguments as in | |
3208 | struct attribute_spec.handler. */ | |
3209 | ||
3210 | static tree | |
3211 | handle_abi_tag_attribute (tree* node, tree name, tree args, | |
3212 | int flags, bool* no_add_attrs) | |
3213 | { | |
3214 | if (TYPE_P (*node)) | |
3215 | { | |
3216 | if (!TAGGED_TYPE_P (*node)) | |
3217 | { | |
3218 | error ("%qE attribute applied to non-class, non-enum type %qT", | |
3219 | name, *node); | |
3220 | goto fail; | |
3221 | } | |
3222 | else if (!(flags & (int)ATTR_FLAG_TYPE_IN_PLACE)) | |
3223 | { | |
3224 | error ("%qE attribute applied to %qT after its definition", | |
3225 | name, *node); | |
3226 | goto fail; | |
3227 | } | |
3228 | ||
3229 | tree attributes = TYPE_ATTRIBUTES (*node); | |
3230 | tree decl = TYPE_NAME (*node); | |
3231 | ||
3232 | /* Make sure all declarations have the same abi tags. */ | |
3233 | if (DECL_SOURCE_LOCATION (decl) != input_location) | |
3234 | { | |
3235 | if (!check_abi_tag_redeclaration (decl, | |
3236 | lookup_attribute ("abi_tag", | |
3237 | attributes), | |
3238 | args)) | |
3239 | goto fail; | |
3240 | } | |
3241 | } | |
3242 | else | |
3243 | { | |
3244 | if (TREE_CODE (*node) != FUNCTION_DECL) | |
3245 | { | |
3246 | error ("%qE attribute applied to non-function %qD", name, *node); | |
3247 | goto fail; | |
3248 | } | |
3249 | else if (DECL_LANGUAGE (*node) == lang_c) | |
3250 | { | |
3251 | error ("%qE attribute applied to extern \"C\" function %qD", | |
3252 | name, *node); | |
3253 | goto fail; | |
3254 | } | |
3255 | } | |
3256 | ||
3257 | return NULL_TREE; | |
3258 | ||
3259 | fail: | |
3260 | *no_add_attrs = true; | |
3261 | return NULL_TREE; | |
3262 | } | |
3263 | ||
87533b37 MM |
3264 | /* Return a new PTRMEM_CST of the indicated TYPE. The MEMBER is the |
3265 | thing pointed to by the constant. */ | |
3266 | ||
3267 | tree | |
b57b79f7 | 3268 | make_ptrmem_cst (tree type, tree member) |
87533b37 MM |
3269 | { |
3270 | tree ptrmem_cst = make_node (PTRMEM_CST); | |
87533b37 MM |
3271 | TREE_TYPE (ptrmem_cst) = type; |
3272 | PTRMEM_CST_MEMBER (ptrmem_cst) = member; | |
3273 | return ptrmem_cst; | |
3274 | } | |
3275 | ||
e9525111 | 3276 | /* Build a variant of TYPE that has the indicated ATTRIBUTES. May |
51035976 | 3277 | return an existing type if an appropriate type already exists. */ |
e9525111 MM |
3278 | |
3279 | tree | |
3280 | cp_build_type_attribute_variant (tree type, tree attributes) | |
3281 | { | |
3282 | tree new_type; | |
3283 | ||
3284 | new_type = build_type_attribute_variant (type, attributes); | |
3a55fb4c JM |
3285 | if (TREE_CODE (new_type) == FUNCTION_TYPE |
3286 | || TREE_CODE (new_type) == METHOD_TYPE) | |
e9525111 MM |
3287 | new_type = build_exception_variant (new_type, |
3288 | TYPE_RAISES_EXCEPTIONS (type)); | |
8e30dcf3 JM |
3289 | |
3290 | /* Making a new main variant of a class type is broken. */ | |
3291 | gcc_assert (!CLASS_TYPE_P (type) || new_type == type); | |
3292 | ||
e9525111 MM |
3293 | return new_type; |
3294 | } | |
3295 | ||
2dff8956 JJ |
3296 | /* Return TRUE if TYPE1 and TYPE2 are identical for type hashing purposes. |
3297 | Called only after doing all language independent checks. Only | |
3298 | to check TYPE_RAISES_EXCEPTIONS for FUNCTION_TYPE, the rest is already | |
3299 | compared in type_hash_eq. */ | |
3300 | ||
3301 | bool | |
3302 | cxx_type_hash_eq (const_tree typea, const_tree typeb) | |
3303 | { | |
220e83ca KT |
3304 | gcc_assert (TREE_CODE (typea) == FUNCTION_TYPE |
3305 | || TREE_CODE (typea) == METHOD_TYPE); | |
2dff8956 JJ |
3306 | |
3307 | return comp_except_specs (TYPE_RAISES_EXCEPTIONS (typea), | |
3a55fb4c | 3308 | TYPE_RAISES_EXCEPTIONS (typeb), ce_exact); |
2dff8956 JJ |
3309 | } |
3310 | ||
25af8512 | 3311 | /* Apply FUNC to all language-specific sub-trees of TP in a pre-order |
350fae66 | 3312 | traversal. Called from walk_tree. */ |
25af8512 | 3313 | |
9f63daea | 3314 | tree |
350fae66 | 3315 | cp_walk_subtrees (tree *tp, int *walk_subtrees_p, walk_tree_fn func, |
0c58f841 | 3316 | void *data, struct pointer_set_t *pset) |
25af8512 AO |
3317 | { |
3318 | enum tree_code code = TREE_CODE (*tp); | |
3319 | tree result; | |
9f63daea | 3320 | |
25af8512 AO |
3321 | #define WALK_SUBTREE(NODE) \ |
3322 | do \ | |
3323 | { \ | |
14588106 | 3324 | result = cp_walk_tree (&(NODE), func, data, pset); \ |
6de9cd9a | 3325 | if (result) goto out; \ |
25af8512 AO |
3326 | } \ |
3327 | while (0) | |
3328 | ||
3329 | /* Not one of the easy cases. We must explicitly go through the | |
3330 | children. */ | |
6de9cd9a | 3331 | result = NULL_TREE; |
25af8512 AO |
3332 | switch (code) |
3333 | { | |
3334 | case DEFAULT_ARG: | |
3335 | case TEMPLATE_TEMPLATE_PARM: | |
3336 | case BOUND_TEMPLATE_TEMPLATE_PARM: | |
b8c6534b | 3337 | case UNBOUND_CLASS_TEMPLATE: |
25af8512 AO |
3338 | case TEMPLATE_PARM_INDEX: |
3339 | case TEMPLATE_TYPE_PARM: | |
3340 | case TYPENAME_TYPE: | |
3341 | case TYPEOF_TYPE: | |
a0d260fc | 3342 | case UNDERLYING_TYPE: |
da1d7781 | 3343 | /* None of these have subtrees other than those already walked |
0cbd7506 | 3344 | above. */ |
25af8512 AO |
3345 | *walk_subtrees_p = 0; |
3346 | break; | |
3347 | ||
5d80a306 DG |
3348 | case BASELINK: |
3349 | WALK_SUBTREE (BASELINK_FUNCTIONS (*tp)); | |
3350 | *walk_subtrees_p = 0; | |
3351 | break; | |
3352 | ||
25af8512 AO |
3353 | case PTRMEM_CST: |
3354 | WALK_SUBTREE (TREE_TYPE (*tp)); | |
3355 | *walk_subtrees_p = 0; | |
3356 | break; | |
3357 | ||
3358 | case TREE_LIST: | |
5dae1114 | 3359 | WALK_SUBTREE (TREE_PURPOSE (*tp)); |
25af8512 AO |
3360 | break; |
3361 | ||
3362 | case OVERLOAD: | |
3363 | WALK_SUBTREE (OVL_FUNCTION (*tp)); | |
3364 | WALK_SUBTREE (OVL_CHAIN (*tp)); | |
3365 | *walk_subtrees_p = 0; | |
4439d02f DG |
3366 | break; |
3367 | ||
3368 | case USING_DECL: | |
3369 | WALK_SUBTREE (DECL_NAME (*tp)); | |
3370 | WALK_SUBTREE (USING_DECL_SCOPE (*tp)); | |
3371 | WALK_SUBTREE (USING_DECL_DECLS (*tp)); | |
3372 | *walk_subtrees_p = 0; | |
25af8512 AO |
3373 | break; |
3374 | ||
3375 | case RECORD_TYPE: | |
3376 | if (TYPE_PTRMEMFUNC_P (*tp)) | |
3377 | WALK_SUBTREE (TYPE_PTRMEMFUNC_FN_TYPE (*tp)); | |
3378 | break; | |
3379 | ||
5d80a306 DG |
3380 | case TYPE_ARGUMENT_PACK: |
3381 | case NONTYPE_ARGUMENT_PACK: | |
3382 | { | |
3383 | tree args = ARGUMENT_PACK_ARGS (*tp); | |
3384 | int i, len = TREE_VEC_LENGTH (args); | |
3385 | for (i = 0; i < len; i++) | |
3386 | WALK_SUBTREE (TREE_VEC_ELT (args, i)); | |
3387 | } | |
3388 | break; | |
3389 | ||
3390 | case TYPE_PACK_EXPANSION: | |
3391 | WALK_SUBTREE (TREE_TYPE (*tp)); | |
c67dd256 | 3392 | WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp)); |
5d80a306 DG |
3393 | *walk_subtrees_p = 0; |
3394 | break; | |
3395 | ||
3396 | case EXPR_PACK_EXPANSION: | |
3397 | WALK_SUBTREE (TREE_OPERAND (*tp, 0)); | |
c67dd256 | 3398 | WALK_SUBTREE (PACK_EXPANSION_EXTRA_ARGS (*tp)); |
5d80a306 DG |
3399 | *walk_subtrees_p = 0; |
3400 | break; | |
3401 | ||
3402 | case CAST_EXPR: | |
a7cbc517 JJ |
3403 | case REINTERPRET_CAST_EXPR: |
3404 | case STATIC_CAST_EXPR: | |
3405 | case CONST_CAST_EXPR: | |
3406 | case DYNAMIC_CAST_EXPR: | |
a4474a38 | 3407 | case IMPLICIT_CONV_EXPR: |
5d80a306 DG |
3408 | if (TREE_TYPE (*tp)) |
3409 | WALK_SUBTREE (TREE_TYPE (*tp)); | |
3410 | ||
3411 | { | |
3412 | int i; | |
3413 | for (i = 0; i < TREE_CODE_LENGTH (TREE_CODE (*tp)); ++i) | |
3414 | WALK_SUBTREE (TREE_OPERAND (*tp, i)); | |
3415 | } | |
3416 | *walk_subtrees_p = 0; | |
3417 | break; | |
3418 | ||
cb68ec50 PC |
3419 | case TRAIT_EXPR: |
3420 | WALK_SUBTREE (TRAIT_EXPR_TYPE1 (*tp)); | |
3421 | WALK_SUBTREE (TRAIT_EXPR_TYPE2 (*tp)); | |
3422 | *walk_subtrees_p = 0; | |
3423 | break; | |
3424 | ||
3ad6a8e1 DG |
3425 | case DECLTYPE_TYPE: |
3426 | WALK_SUBTREE (DECLTYPE_TYPE_EXPR (*tp)); | |
3427 | *walk_subtrees_p = 0; | |
3428 | break; | |
3429 | ||
3430 | ||
25af8512 | 3431 | default: |
350fae66 | 3432 | return NULL_TREE; |
25af8512 AO |
3433 | } |
3434 | ||
3435 | /* We didn't find what we were looking for. */ | |
6de9cd9a | 3436 | out: |
6de9cd9a | 3437 | return result; |
25af8512 AO |
3438 | |
3439 | #undef WALK_SUBTREE | |
3440 | } | |
3441 | ||
b655f214 MM |
3442 | /* Like save_expr, but for C++. */ |
3443 | ||
3444 | tree | |
3445 | cp_save_expr (tree expr) | |
3446 | { | |
3447 | /* There is no reason to create a SAVE_EXPR within a template; if | |
3448 | needed, we can create the SAVE_EXPR when instantiating the | |
3449 | template. Furthermore, the middle-end cannot handle C++-specific | |
3450 | tree codes. */ | |
3451 | if (processing_template_decl) | |
3452 | return expr; | |
3453 | return save_expr (expr); | |
3454 | } | |
3455 | ||
87e3dbc9 MM |
3456 | /* Initialize tree.c. */ |
3457 | ||
0a818f84 | 3458 | void |
b57b79f7 | 3459 | init_tree (void) |
0a818f84 | 3460 | { |
e2500fed | 3461 | list_hash_table = htab_create_ggc (31, list_hash, list_hash_eq, NULL); |
0a818f84 GRK |
3462 | } |
3463 | ||
872f37f9 | 3464 | /* Returns the kind of special function that DECL (a FUNCTION_DECL) |
50ad9642 MM |
3465 | is. Note that sfk_none is zero, so this function can be used as a |
3466 | predicate to test whether or not DECL is a special function. */ | |
872f37f9 MM |
3467 | |
3468 | special_function_kind | |
58f9752a | 3469 | special_function_p (const_tree decl) |
872f37f9 MM |
3470 | { |
3471 | /* Rather than doing all this stuff with magic names, we should | |
3472 | probably have a field of type `special_function_kind' in | |
3473 | DECL_LANG_SPECIFIC. */ | |
85b5d65a JM |
3474 | if (DECL_INHERITED_CTOR_BASE (decl)) |
3475 | return sfk_inheriting_constructor; | |
872f37f9 MM |
3476 | if (DECL_COPY_CONSTRUCTOR_P (decl)) |
3477 | return sfk_copy_constructor; | |
d5f4eddd JM |
3478 | if (DECL_MOVE_CONSTRUCTOR_P (decl)) |
3479 | return sfk_move_constructor; | |
872f37f9 MM |
3480 | if (DECL_CONSTRUCTOR_P (decl)) |
3481 | return sfk_constructor; | |
596ea4e5 | 3482 | if (DECL_OVERLOADED_OPERATOR_P (decl) == NOP_EXPR) |
ac177431 JM |
3483 | { |
3484 | if (copy_fn_p (decl)) | |
3485 | return sfk_copy_assignment; | |
3486 | if (move_fn_p (decl)) | |
3487 | return sfk_move_assignment; | |
3488 | } | |
872f37f9 MM |
3489 | if (DECL_MAYBE_IN_CHARGE_DESTRUCTOR_P (decl)) |
3490 | return sfk_destructor; | |
3491 | if (DECL_COMPLETE_DESTRUCTOR_P (decl)) | |
3492 | return sfk_complete_destructor; | |
3493 | if (DECL_BASE_DESTRUCTOR_P (decl)) | |
3494 | return sfk_base_destructor; | |
3495 | if (DECL_DELETING_DESTRUCTOR_P (decl)) | |
3496 | return sfk_deleting_destructor; | |
3497 | if (DECL_CONV_FN_P (decl)) | |
3498 | return sfk_conversion; | |
3499 | ||
3500 | return sfk_none; | |
3501 | } | |
7b019c19 | 3502 | |
838dfd8a | 3503 | /* Returns nonzero if TYPE is a character type, including wchar_t. */ |
7b019c19 MM |
3504 | |
3505 | int | |
b57b79f7 | 3506 | char_type_p (tree type) |
7b019c19 MM |
3507 | { |
3508 | return (same_type_p (type, char_type_node) | |
3509 | || same_type_p (type, unsigned_char_type_node) | |
3510 | || same_type_p (type, signed_char_type_node) | |
b6baa67d KVH |
3511 | || same_type_p (type, char16_type_node) |
3512 | || same_type_p (type, char32_type_node) | |
7b019c19 MM |
3513 | || same_type_p (type, wchar_type_node)); |
3514 | } | |
ad50e811 MM |
3515 | |
3516 | /* Returns the kind of linkage associated with the indicated DECL. Th | |
3517 | value returned is as specified by the language standard; it is | |
3518 | independent of implementation details regarding template | |
3519 | instantiation, etc. For example, it is possible that a declaration | |
3520 | to which this function assigns external linkage would not show up | |
3521 | as a global symbol when you run `nm' on the resulting object file. */ | |
3522 | ||
3523 | linkage_kind | |
b57b79f7 | 3524 | decl_linkage (tree decl) |
ad50e811 MM |
3525 | { |
3526 | /* This function doesn't attempt to calculate the linkage from first | |
3527 | principles as given in [basic.link]. Instead, it makes use of | |
3528 | the fact that we have already set TREE_PUBLIC appropriately, and | |
3529 | then handles a few special cases. Ideally, we would calculate | |
3530 | linkage first, and then transform that into a concrete | |
3531 | implementation. */ | |
3532 | ||
3533 | /* Things that don't have names have no linkage. */ | |
3534 | if (!DECL_NAME (decl)) | |
3535 | return lk_none; | |
3536 | ||
c02cdc25 TT |
3537 | /* Fields have no linkage. */ |
3538 | if (TREE_CODE (decl) == FIELD_DECL) | |
3539 | return lk_none; | |
3540 | ||
ad50e811 MM |
3541 | /* Things that are TREE_PUBLIC have external linkage. */ |
3542 | if (TREE_PUBLIC (decl)) | |
3543 | return lk_external; | |
3db45ab5 | 3544 | |
b70f0f48 JM |
3545 | if (TREE_CODE (decl) == NAMESPACE_DECL) |
3546 | return lk_external; | |
3547 | ||
3db45ab5 | 3548 | /* Linkage of a CONST_DECL depends on the linkage of the enumeration |
3f774254 DB |
3549 | type. */ |
3550 | if (TREE_CODE (decl) == CONST_DECL) | |
8d0d1915 | 3551 | return decl_linkage (TYPE_NAME (DECL_CONTEXT (decl))); |
ad50e811 MM |
3552 | |
3553 | /* Some things that are not TREE_PUBLIC have external linkage, too. | |
3554 | For example, on targets that don't have weak symbols, we make all | |
3555 | template instantiations have internal linkage (in the object | |
3556 | file), but the symbols should still be treated as having external | |
3557 | linkage from the point of view of the language. */ | |
ad909c97 JM |
3558 | if ((TREE_CODE (decl) == FUNCTION_DECL |
3559 | || TREE_CODE (decl) == VAR_DECL) | |
b9e75696 | 3560 | && DECL_COMDAT (decl)) |
ad50e811 MM |
3561 | return lk_external; |
3562 | ||
3563 | /* Things in local scope do not have linkage, if they don't have | |
3564 | TREE_PUBLIC set. */ | |
3565 | if (decl_function_context (decl)) | |
3566 | return lk_none; | |
3567 | ||
b70f0f48 JM |
3568 | /* Members of the anonymous namespace also have TREE_PUBLIC unset, but |
3569 | are considered to have external linkage for language purposes. DECLs | |
3570 | really meant to have internal linkage have DECL_THIS_STATIC set. */ | |
ce41114b | 3571 | if (TREE_CODE (decl) == TYPE_DECL) |
b70f0f48 | 3572 | return lk_external; |
ce41114b JJ |
3573 | if (TREE_CODE (decl) == VAR_DECL || TREE_CODE (decl) == FUNCTION_DECL) |
3574 | { | |
3575 | if (!DECL_THIS_STATIC (decl)) | |
3576 | return lk_external; | |
3577 | ||
3578 | /* Static data members and static member functions from classes | |
3579 | in anonymous namespace also don't have TREE_PUBLIC set. */ | |
3580 | if (DECL_CLASS_CONTEXT (decl)) | |
3581 | return lk_external; | |
3582 | } | |
b70f0f48 | 3583 | |
ad50e811 MM |
3584 | /* Everything else has internal linkage. */ |
3585 | return lk_internal; | |
3586 | } | |
b95ca513 JM |
3587 | |
3588 | /* Returns the storage duration of the object or reference associated with | |
3589 | the indicated DECL, which should be a VAR_DECL or PARM_DECL. */ | |
3590 | ||
3591 | duration_kind | |
3592 | decl_storage_duration (tree decl) | |
3593 | { | |
3594 | if (TREE_CODE (decl) == PARM_DECL) | |
3595 | return dk_auto; | |
3596 | if (TREE_CODE (decl) == FUNCTION_DECL) | |
3597 | return dk_static; | |
3598 | gcc_assert (TREE_CODE (decl) == VAR_DECL); | |
3599 | if (!TREE_STATIC (decl) | |
3600 | && !DECL_EXTERNAL (decl)) | |
3601 | return dk_auto; | |
3602 | if (DECL_THREAD_LOCAL_P (decl)) | |
3603 | return dk_thread; | |
3604 | return dk_static; | |
3605 | } | |
6f30f1f1 | 3606 | \f |
9beafc83 MM |
3607 | /* EXP is an expression that we want to pre-evaluate. Returns (in |
3608 | *INITP) an expression that will perform the pre-evaluation. The | |
3609 | value returned by this function is a side-effect free expression | |
3610 | equivalent to the pre-evaluated expression. Callers must ensure | |
3611 | that *INITP is evaluated before EXP. */ | |
6f30f1f1 JM |
3612 | |
3613 | tree | |
b57b79f7 | 3614 | stabilize_expr (tree exp, tree* initp) |
6f30f1f1 JM |
3615 | { |
3616 | tree init_expr; | |
3617 | ||
3618 | if (!TREE_SIDE_EFFECTS (exp)) | |
9beafc83 | 3619 | init_expr = NULL_TREE; |
982058cb PC |
3620 | else if (VOID_TYPE_P (TREE_TYPE (exp))) |
3621 | { | |
989e6706 JM |
3622 | init_expr = exp; |
3623 | exp = void_zero_node; | |
982058cb | 3624 | } |
e3edeff4 JM |
3625 | /* There are no expressions with REFERENCE_TYPE, but there can be call |
3626 | arguments with such a type; just treat it as a pointer. */ | |
3627 | else if (TREE_CODE (TREE_TYPE (exp)) == REFERENCE_TYPE | |
fa07d25b | 3628 | || SCALAR_TYPE_P (TREE_TYPE (exp)) |
883fff6c | 3629 | || !lvalue_or_rvalue_with_address_p (exp)) |
6f30f1f1 JM |
3630 | { |
3631 | init_expr = get_target_expr (exp); | |
3632 | exp = TARGET_EXPR_SLOT (init_expr); | |
3633 | } | |
3634 | else | |
3635 | { | |
883fff6c | 3636 | bool xval = !real_lvalue_p (exp); |
93c0e0bb | 3637 | exp = cp_build_addr_expr (exp, tf_warning_or_error); |
6f30f1f1 JM |
3638 | init_expr = get_target_expr (exp); |
3639 | exp = TARGET_EXPR_SLOT (init_expr); | |
dd865ef6 | 3640 | exp = cp_build_indirect_ref (exp, RO_NULL, tf_warning_or_error); |
883fff6c JM |
3641 | if (xval) |
3642 | exp = move (exp); | |
6f30f1f1 | 3643 | } |
6f30f1f1 | 3644 | *initp = init_expr; |
9beafc83 MM |
3645 | |
3646 | gcc_assert (!TREE_SIDE_EFFECTS (exp)); | |
6f30f1f1 JM |
3647 | return exp; |
3648 | } | |
6de9cd9a | 3649 | |
be93747e | 3650 | /* Add NEW_EXPR, an expression whose value we don't care about, after the |
40aac948 JM |
3651 | similar expression ORIG. */ |
3652 | ||
3653 | tree | |
be93747e | 3654 | add_stmt_to_compound (tree orig, tree new_expr) |
40aac948 | 3655 | { |
be93747e | 3656 | if (!new_expr || !TREE_SIDE_EFFECTS (new_expr)) |
40aac948 JM |
3657 | return orig; |
3658 | if (!orig || !TREE_SIDE_EFFECTS (orig)) | |
be93747e KG |
3659 | return new_expr; |
3660 | return build2 (COMPOUND_EXPR, void_type_node, orig, new_expr); | |
40aac948 JM |
3661 | } |
3662 | ||
9beafc83 MM |
3663 | /* Like stabilize_expr, but for a call whose arguments we want to |
3664 | pre-evaluate. CALL is modified in place to use the pre-evaluated | |
3665 | arguments, while, upon return, *INITP contains an expression to | |
3666 | compute the arguments. */ | |
6de9cd9a DN |
3667 | |
3668 | void | |
3669 | stabilize_call (tree call, tree *initp) | |
3670 | { | |
3671 | tree inits = NULL_TREE; | |
5039610b SL |
3672 | int i; |
3673 | int nargs = call_expr_nargs (call); | |
6de9cd9a | 3674 | |
28267cfc JJ |
3675 | if (call == error_mark_node || processing_template_decl) |
3676 | { | |
3677 | *initp = NULL_TREE; | |
3678 | return; | |
3679 | } | |
6de9cd9a | 3680 | |
5039610b | 3681 | gcc_assert (TREE_CODE (call) == CALL_EXPR); |
6de9cd9a | 3682 | |
5039610b SL |
3683 | for (i = 0; i < nargs; i++) |
3684 | { | |
3685 | tree init; | |
3686 | CALL_EXPR_ARG (call, i) = | |
3687 | stabilize_expr (CALL_EXPR_ARG (call, i), &init); | |
3688 | inits = add_stmt_to_compound (inits, init); | |
3689 | } | |
3690 | ||
3691 | *initp = inits; | |
3692 | } | |
3693 | ||
3694 | /* Like stabilize_expr, but for an AGGR_INIT_EXPR whose arguments we want | |
3695 | to pre-evaluate. CALL is modified in place to use the pre-evaluated | |
3696 | arguments, while, upon return, *INITP contains an expression to | |
3697 | compute the arguments. */ | |
3698 | ||
81bd268c | 3699 | static void |
5039610b SL |
3700 | stabilize_aggr_init (tree call, tree *initp) |
3701 | { | |
3702 | tree inits = NULL_TREE; | |
3703 | int i; | |
3704 | int nargs = aggr_init_expr_nargs (call); | |
3705 | ||
3706 | if (call == error_mark_node) | |
3707 | return; | |
3708 | ||
3709 | gcc_assert (TREE_CODE (call) == AGGR_INIT_EXPR); | |
3710 | ||
3711 | for (i = 0; i < nargs; i++) | |
3712 | { | |
3713 | tree init; | |
3714 | AGGR_INIT_EXPR_ARG (call, i) = | |
3715 | stabilize_expr (AGGR_INIT_EXPR_ARG (call, i), &init); | |
3716 | inits = add_stmt_to_compound (inits, init); | |
3717 | } | |
6de9cd9a DN |
3718 | |
3719 | *initp = inits; | |
3720 | } | |
3721 | ||
9beafc83 MM |
3722 | /* Like stabilize_expr, but for an initialization. |
3723 | ||
3724 | If the initialization is for an object of class type, this function | |
3725 | takes care not to introduce additional temporaries. | |
3726 | ||
3727 | Returns TRUE iff the expression was successfully pre-evaluated, | |
66edf32a | 3728 | i.e., if INIT is now side-effect free, except for, possibly, a |
9beafc83 | 3729 | single call to a constructor. */ |
6de9cd9a DN |
3730 | |
3731 | bool | |
3732 | stabilize_init (tree init, tree *initp) | |
3733 | { | |
3734 | tree t = init; | |
3735 | ||
9beafc83 MM |
3736 | *initp = NULL_TREE; |
3737 | ||
28267cfc | 3738 | if (t == error_mark_node || processing_template_decl) |
6de9cd9a DN |
3739 | return true; |
3740 | ||
9beafc83 MM |
3741 | if (TREE_CODE (t) == INIT_EXPR) |
3742 | t = TREE_OPERAND (t, 1); | |
3743 | if (TREE_CODE (t) == TARGET_EXPR) | |
3744 | t = TARGET_EXPR_INITIAL (t); | |
66edf32a JM |
3745 | |
3746 | /* If the RHS can be stabilized without breaking copy elision, stabilize | |
3747 | it. We specifically don't stabilize class prvalues here because that | |
3748 | would mean an extra copy, but they might be stabilized below. */ | |
3749 | if (TREE_CODE (init) == INIT_EXPR | |
3750 | && TREE_CODE (t) != CONSTRUCTOR | |
3751 | && TREE_CODE (t) != AGGR_INIT_EXPR | |
3752 | && (SCALAR_TYPE_P (TREE_TYPE (t)) | |
3753 | || lvalue_or_rvalue_with_address_p (t))) | |
3754 | { | |
3755 | TREE_OPERAND (init, 1) = stabilize_expr (t, initp); | |
3756 | return true; | |
3757 | } | |
3758 | ||
3759 | if (TREE_CODE (t) == COMPOUND_EXPR | |
3760 | && TREE_CODE (init) == INIT_EXPR) | |
3761 | { | |
3762 | tree last = expr_last (t); | |
3763 | /* Handle stabilizing the EMPTY_CLASS_EXPR pattern. */ | |
3764 | if (!TREE_SIDE_EFFECTS (last)) | |
3765 | { | |
3766 | *initp = t; | |
3767 | TREE_OPERAND (init, 1) = last; | |
3768 | return true; | |
3769 | } | |
3770 | } | |
3771 | ||
b9d6b015 JM |
3772 | if (TREE_CODE (t) == CONSTRUCTOR) |
3773 | { | |
3774 | /* Aggregate initialization: stabilize each of the field | |
3775 | initializers. */ | |
3776 | unsigned i; | |
0c59fd2f | 3777 | constructor_elt *ce; |
b9d6b015 | 3778 | bool good = true; |
9771b263 DN |
3779 | vec<constructor_elt, va_gc> *v = CONSTRUCTOR_ELTS (t); |
3780 | for (i = 0; vec_safe_iterate (v, i, &ce); ++i) | |
0c59fd2f JM |
3781 | { |
3782 | tree type = TREE_TYPE (ce->value); | |
3783 | tree subinit; | |
3784 | if (TREE_CODE (type) == REFERENCE_TYPE | |
3785 | || SCALAR_TYPE_P (type)) | |
3786 | ce->value = stabilize_expr (ce->value, &subinit); | |
3787 | else if (!stabilize_init (ce->value, &subinit)) | |
3788 | good = false; | |
3789 | *initp = add_stmt_to_compound (*initp, subinit); | |
3790 | } | |
b9d6b015 JM |
3791 | return good; |
3792 | } | |
9beafc83 | 3793 | |
5039610b | 3794 | if (TREE_CODE (t) == CALL_EXPR) |
9beafc83 MM |
3795 | { |
3796 | stabilize_call (t, initp); | |
3797 | return true; | |
6de9cd9a DN |
3798 | } |
3799 | ||
5039610b SL |
3800 | if (TREE_CODE (t) == AGGR_INIT_EXPR) |
3801 | { | |
3802 | stabilize_aggr_init (t, initp); | |
3803 | return true; | |
3804 | } | |
3805 | ||
9beafc83 MM |
3806 | /* The initialization is being performed via a bitwise copy -- and |
3807 | the item copied may have side effects. */ | |
4bbbcbf6 | 3808 | return !TREE_SIDE_EFFECTS (init); |
6de9cd9a DN |
3809 | } |
3810 | ||
455f19cb MM |
3811 | /* Like "fold", but should be used whenever we might be processing the |
3812 | body of a template. */ | |
3813 | ||
3814 | tree | |
3815 | fold_if_not_in_template (tree expr) | |
3816 | { | |
3817 | /* In the body of a template, there is never any need to call | |
3818 | "fold". We will call fold later when actually instantiating the | |
3819 | template. Integral constant expressions in templates will be | |
f9f1c24e | 3820 | evaluated via fold_non_dependent_expr, as necessary. */ |
392e3d51 RS |
3821 | if (processing_template_decl) |
3822 | return expr; | |
3823 | ||
3824 | /* Fold C++ front-end specific tree codes. */ | |
3825 | if (TREE_CODE (expr) == UNARY_PLUS_EXPR) | |
3826 | return fold_convert (TREE_TYPE (expr), TREE_OPERAND (expr, 0)); | |
3827 | ||
3828 | return fold (expr); | |
455f19cb MM |
3829 | } |
3830 | ||
015c2c66 MM |
3831 | /* Returns true if a cast to TYPE may appear in an integral constant |
3832 | expression. */ | |
3833 | ||
3834 | bool | |
3835 | cast_valid_in_integral_constant_expression_p (tree type) | |
3836 | { | |
3837 | return (INTEGRAL_OR_ENUMERATION_TYPE_P (type) | |
fa2200cb | 3838 | || cxx_dialect >= cxx0x |
015c2c66 MM |
3839 | || dependent_type_p (type) |
3840 | || type == error_mark_node); | |
3841 | } | |
3842 | ||
4537ec0c DN |
3843 | /* Return true if we need to fix linkage information of DECL. */ |
3844 | ||
3845 | static bool | |
3846 | cp_fix_function_decl_p (tree decl) | |
3847 | { | |
3848 | /* Skip if DECL is not externally visible. */ | |
3849 | if (!TREE_PUBLIC (decl)) | |
3850 | return false; | |
3851 | ||
3852 | /* We need to fix DECL if it a appears to be exported but with no | |
3853 | function body. Thunks do not have CFGs and we may need to | |
3854 | handle them specially later. */ | |
3855 | if (!gimple_has_body_p (decl) | |
3856 | && !DECL_THUNK_P (decl) | |
3857 | && !DECL_EXTERNAL (decl)) | |
87501227 JJ |
3858 | { |
3859 | struct cgraph_node *node = cgraph_get_node (decl); | |
3860 | ||
3861 | /* Don't fix same_body aliases. Although they don't have their own | |
3862 | CFG, they share it with what they alias to. */ | |
39e2db00 | 3863 | if (!node || !node->alias |
9771b263 | 3864 | || !vec_safe_length (node->symbol.ref_list.references)) |
87501227 JJ |
3865 | return true; |
3866 | } | |
4537ec0c DN |
3867 | |
3868 | return false; | |
3869 | } | |
3870 | ||
3871 | /* Clean the C++ specific parts of the tree T. */ | |
3872 | ||
3873 | void | |
3874 | cp_free_lang_data (tree t) | |
3875 | { | |
3876 | if (TREE_CODE (t) == METHOD_TYPE | |
3877 | || TREE_CODE (t) == FUNCTION_TYPE) | |
3878 | { | |
3879 | /* Default args are not interesting anymore. */ | |
3880 | tree argtypes = TYPE_ARG_TYPES (t); | |
3881 | while (argtypes) | |
3882 | { | |
3883 | TREE_PURPOSE (argtypes) = 0; | |
3884 | argtypes = TREE_CHAIN (argtypes); | |
3885 | } | |
3886 | } | |
3887 | else if (TREE_CODE (t) == FUNCTION_DECL | |
3888 | && cp_fix_function_decl_p (t)) | |
3889 | { | |
3890 | /* If T is used in this translation unit at all, the definition | |
3891 | must exist somewhere else since we have decided to not emit it | |
3892 | in this TU. So make it an external reference. */ | |
3893 | DECL_EXTERNAL (t) = 1; | |
3894 | TREE_STATIC (t) = 0; | |
3895 | } | |
b4ca4f9e RG |
3896 | if (TREE_CODE (t) == NAMESPACE_DECL) |
3897 | { | |
3898 | /* The list of users of a namespace isn't useful for the middle-end | |
3899 | or debug generators. */ | |
3900 | DECL_NAMESPACE_USERS (t) = NULL_TREE; | |
3901 | /* Neither do we need the leftover chaining of namespaces | |
3902 | from the binding level. */ | |
3903 | DECL_CHAIN (t) = NULL_TREE; | |
3904 | } | |
4537ec0c DN |
3905 | } |
3906 | ||
bffad7f1 SB |
3907 | /* Stub for c-common. Please keep in sync with c-decl.c. |
3908 | FIXME: If address space support is target specific, then this | |
3909 | should be a C target hook. But currently this is not possible, | |
3910 | because this function is called via REGISTER_TARGET_PRAGMAS. */ | |
3911 | void | |
12308bc6 | 3912 | c_register_addr_space (const char * /*word*/, addr_space_t /*as*/) |
bffad7f1 SB |
3913 | { |
3914 | } | |
3915 | ||
d26e5986 NF |
3916 | /* Return the number of operands in T that we care about for things like |
3917 | mangling. */ | |
3918 | ||
3919 | int | |
3920 | cp_tree_operand_length (const_tree t) | |
3921 | { | |
3922 | enum tree_code code = TREE_CODE (t); | |
3923 | ||
3924 | switch (code) | |
3925 | { | |
3926 | case PREINCREMENT_EXPR: | |
3927 | case PREDECREMENT_EXPR: | |
3928 | case POSTINCREMENT_EXPR: | |
3929 | case POSTDECREMENT_EXPR: | |
3930 | return 1; | |
3931 | ||
3932 | case ARRAY_REF: | |
3933 | return 2; | |
3934 | ||
3935 | case EXPR_PACK_EXPANSION: | |
3936 | return 1; | |
3937 | ||
3938 | default: | |
3939 | return TREE_OPERAND_LENGTH (t); | |
3940 | } | |
3941 | } | |
e2500fed GK |
3942 | \f |
3943 | #if defined ENABLE_TREE_CHECKING && (GCC_VERSION >= 2007) | |
3944 | /* Complain that some language-specific thing hanging off a tree | |
3945 | node has been accessed improperly. */ | |
3946 | ||
3947 | void | |
b57b79f7 | 3948 | lang_check_failed (const char* file, int line, const char* function) |
e2500fed GK |
3949 | { |
3950 | internal_error ("lang_* check: failed in %s, at %s:%d", | |
3951 | function, trim_filename (file), line); | |
3952 | } | |
3953 | #endif /* ENABLE_TREE_CHECKING */ | |
3954 | ||
3955 | #include "gt-cp-tree.h" |