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