]>
Commit | Line | Data |
---|---|---|
5dd72fac | 1 | /* Some code common to C++ and ObjC++ front ends. |
8e8f6434 | 2 | Copyright (C) 2004-2018 Free Software Foundation, Inc. |
5dd72fac | 3 | Contributed by Ziemowit Laski <zlaski@apple.com> |
4 | ||
5 | This file is part of GCC. | |
6 | ||
7 | GCC is free software; you can redistribute it and/or modify it under | |
8 | the terms of the GNU General Public License as published by the Free | |
aa139c3f | 9 | Software Foundation; either version 3, or (at your option) any later |
5dd72fac | 10 | version. |
11 | ||
12 | GCC is distributed in the hope that it will be useful, but WITHOUT ANY | |
13 | WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 | 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/>. */ | |
5dd72fac | 20 | |
21 | #include "config.h" | |
22 | #include "system.h" | |
23 | #include "coretypes.h" | |
5dd72fac | 24 | #include "cp-tree.h" |
5dd72fac | 25 | #include "cp-objcp-common.h" |
35b516bd | 26 | #include "dwarf2.h" |
5dd72fac | 27 | |
28 | /* Special routine to get the alias set for C++. */ | |
29 | ||
32c2fdea | 30 | alias_set_type |
5dd72fac | 31 | cxx_get_alias_set (tree t) |
32 | { | |
33 | if (IS_FAKE_BASE_TYPE (t)) | |
34 | /* The base variant of a type must be in the same alias set as the | |
35 | complete type. */ | |
36 | return get_alias_set (TYPE_CONTEXT (t)); | |
37 | ||
38 | /* Punt on PMFs until we canonicalize functions properly. */ | |
f607c97b | 39 | if (TYPE_PTRMEMFUNC_P (t) |
d03fa520 | 40 | || (INDIRECT_TYPE_P (t) |
f607c97b | 41 | && TYPE_PTRMEMFUNC_P (TREE_TYPE (t)))) |
5dd72fac | 42 | return 0; |
43 | ||
44 | return c_common_get_alias_set (t); | |
45 | } | |
46 | ||
3a1c9df2 | 47 | /* Called from check_global_declaration. */ |
5dd72fac | 48 | |
49 | bool | |
f8fd23c0 | 50 | cxx_warn_unused_global_decl (const_tree decl) |
5dd72fac | 51 | { |
52 | if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl)) | |
53 | return false; | |
54 | if (DECL_IN_SYSTEM_HEADER (decl)) | |
55 | return false; | |
56 | ||
5dd72fac | 57 | return true; |
58 | } | |
59 | ||
5dd72fac | 60 | /* Langhook for tree_size: determine size of our 'x' and 'c' nodes. */ |
61 | size_t | |
62 | cp_tree_size (enum tree_code code) | |
63 | { | |
6273fc17 | 64 | gcc_checking_assert (code >= NUM_TREE_CODES); |
5dd72fac | 65 | switch (code) |
66 | { | |
6273fc17 | 67 | case PTRMEM_CST: return sizeof (ptrmem_cst); |
68 | case BASELINK: return sizeof (tree_baselink); | |
653e5405 | 69 | case TEMPLATE_PARM_INDEX: return sizeof (template_parm_index); |
6273fc17 | 70 | case DEFAULT_ARG: return sizeof (tree_default_arg); |
71 | case DEFERRED_NOEXCEPT: return sizeof (tree_deferred_noexcept); | |
72 | case OVERLOAD: return sizeof (tree_overload); | |
73 | case STATIC_ASSERT: return sizeof (tree_static_assert); | |
d95d815d | 74 | case TYPE_ARGUMENT_PACK: |
6273fc17 | 75 | case TYPE_PACK_EXPANSION: return sizeof (tree_type_non_common); |
d95d815d | 76 | case NONTYPE_ARGUMENT_PACK: |
6273fc17 | 77 | case EXPR_PACK_EXPANSION: return sizeof (tree_exp); |
78 | case ARGUMENT_PACK_SELECT: return sizeof (tree_argument_pack_select); | |
79 | case TRAIT_EXPR: return sizeof (tree_trait_expr); | |
80 | case LAMBDA_EXPR: return sizeof (tree_lambda_expr); | |
81 | case TEMPLATE_INFO: return sizeof (tree_template_info); | |
82 | case CONSTRAINT_INFO: return sizeof (tree_constraint_info); | |
83 | case USERDEF_LITERAL: return sizeof (tree_userdef_literal); | |
84 | case TEMPLATE_DECL: return sizeof (tree_template_decl); | |
5dd72fac | 85 | default: |
6273fc17 | 86 | switch (TREE_CODE_CLASS (code)) |
87 | { | |
88 | case tcc_declaration: return sizeof (tree_decl_non_common); | |
89 | case tcc_type: return sizeof (tree_type_non_common); | |
90 | default: gcc_unreachable (); | |
91 | } | |
5dd72fac | 92 | } |
93 | /* NOTREACHED */ | |
94 | } | |
95 | ||
96 | /* Returns true if T is a variably modified type, in the sense of C99. | |
97 | FN is as passed to variably_modified_p. | |
98 | This routine needs only check cases that cannot be handled by the | |
99 | language-independent logic in tree.c. */ | |
100 | ||
101 | bool | |
102 | cp_var_mod_type_p (tree type, tree fn) | |
103 | { | |
104 | /* If TYPE is a pointer-to-member, it is variably modified if either | |
105 | the class or the member are variably modified. */ | |
05765a91 | 106 | if (TYPE_PTRMEM_P (type)) |
5dd72fac | 107 | return (variably_modified_type_p (TYPE_PTRMEM_CLASS_TYPE (type), fn) |
108 | || variably_modified_type_p (TYPE_PTRMEM_POINTED_TO_TYPE (type), | |
109 | fn)); | |
110 | ||
111 | /* All other types are not variably modified. */ | |
112 | return false; | |
113 | } | |
114 | ||
3dac5c5e | 115 | /* This compares two types for equivalence ("compatible" in C-based languages). |
116 | This routine should only return 1 if it is sure. It should not be used | |
117 | in contexts where erroneously returning 0 causes problems. */ | |
118 | ||
119 | int | |
120 | cxx_types_compatible_p (tree x, tree y) | |
121 | { | |
29f51994 | 122 | return same_type_ignoring_top_level_qualifiers_p (x, y); |
3dac5c5e | 123 | } |
124 | ||
8bcf9382 | 125 | static GTY((cache)) tree_cache_map *debug_type_map; |
e256a0fe | 126 | |
2034deb9 | 127 | /* Return a type to use in the debug info instead of TYPE, or NULL_TREE to |
128 | keep TYPE. */ | |
129 | ||
130 | tree | |
131 | cp_get_debug_type (const_tree type) | |
132 | { | |
8bcf9382 | 133 | tree dtype = NULL_TREE; |
134 | ||
2034deb9 | 135 | if (TYPE_PTRMEMFUNC_P (type) && !typedef_variant_p (type)) |
8bcf9382 | 136 | dtype = build_offset_type (TYPE_PTRMEMFUNC_OBJECT_TYPE (type), |
137 | TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type))); | |
138 | ||
139 | /* We cannot simply return the debug type here because the function uses | |
140 | the type canonicalization hashtable, which is GC-ed, so its behavior | |
141 | depends on the actual collection points. Since we are building these | |
142 | types on the fly for the debug info only, they would not be attached | |
143 | to any GC root and always be swept, so we would make the contents of | |
144 | the debug info depend on the collection points. */ | |
145 | if (dtype) | |
e256a0fe | 146 | { |
8bcf9382 | 147 | tree ktype = CONST_CAST_TREE (type); |
148 | if (debug_type_map == NULL) | |
149 | debug_type_map = tree_cache_map::create_ggc (512); | |
150 | else if (tree *slot = debug_type_map->get (ktype)) | |
151 | return *slot; | |
152 | debug_type_map->put (ktype, dtype); | |
e256a0fe | 153 | } |
2034deb9 | 154 | |
8bcf9382 | 155 | return dtype; |
2034deb9 | 156 | } |
157 | ||
35b516bd | 158 | /* Return -1 if dwarf ATTR shouldn't be added for DECL, or the attribute |
159 | value otherwise. */ | |
160 | int | |
161 | cp_decl_dwarf_attribute (const_tree decl, int attr) | |
cb3582e7 | 162 | { |
35b516bd | 163 | if (decl == NULL_TREE) |
164 | return -1; | |
cb3582e7 | 165 | |
35b516bd | 166 | switch (attr) |
167 | { | |
168 | case DW_AT_explicit: | |
169 | if (TREE_CODE (decl) == FUNCTION_DECL | |
170 | && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl)) | |
171 | && DECL_NONCONVERTING_P (decl)) | |
172 | return 1; | |
173 | break; | |
77cab475 | 174 | |
35b516bd | 175 | case DW_AT_deleted: |
176 | if (TREE_CODE (decl) == FUNCTION_DECL | |
77cab475 | 177 | && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl)) |
35b516bd | 178 | && DECL_DELETED_FN (decl)) |
179 | return 1; | |
180 | break; | |
77cab475 | 181 | |
35b516bd | 182 | case DW_AT_defaulted: |
183 | if (TREE_CODE (decl) == FUNCTION_DECL | |
184 | && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl)) | |
185 | && DECL_DEFAULTED_FN (decl)) | |
186 | { | |
187 | if (DECL_DEFAULTED_IN_CLASS_P (decl)) | |
188 | return DW_DEFAULTED_in_class; | |
832d369d | 189 | |
35b516bd | 190 | if (DECL_DEFAULTED_OUTSIDE_CLASS_P (decl)) |
191 | return DW_DEFAULTED_out_of_class; | |
192 | } | |
193 | break; | |
832d369d | 194 | |
4d8040d8 | 195 | case DW_AT_const_expr: |
196 | if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_DECLARED_CONSTEXPR_P (decl)) | |
197 | return 1; | |
198 | break; | |
199 | ||
1eaf0150 | 200 | case DW_AT_reference: |
201 | if (TREE_CODE (decl) == FUNCTION_DECL | |
202 | && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl) | |
203 | && FUNCTION_REF_QUALIFIED (TREE_TYPE (decl)) | |
204 | && !FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl))) | |
205 | return 1; | |
1eaf0150 | 206 | break; |
207 | ||
208 | case DW_AT_rvalue_reference: | |
209 | if (TREE_CODE (decl) == FUNCTION_DECL | |
210 | && DECL_NONSTATIC_MEMBER_FUNCTION_P (decl) | |
211 | && FUNCTION_REF_QUALIFIED (TREE_TYPE (decl)) | |
212 | && FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl))) | |
213 | return 1; | |
1eaf0150 | 214 | break; |
215 | ||
dcc1dde9 | 216 | case DW_AT_inline: |
217 | if (VAR_P (decl) && DECL_INLINE_VAR_P (decl)) | |
218 | { | |
219 | if (DECL_VAR_DECLARED_INLINE_P (decl)) | |
220 | return DW_INL_declared_inlined; | |
221 | else | |
222 | return DW_INL_inlined; | |
223 | } | |
224 | break; | |
225 | ||
41d01e67 | 226 | case DW_AT_export_symbols: |
227 | if (TREE_CODE (decl) == NAMESPACE_DECL | |
228 | && (DECL_NAMESPACE_INLINE_P (decl) | |
229 | || (DECL_NAME (decl) == NULL_TREE && dwarf_version >= 5))) | |
230 | return 1; | |
231 | break; | |
232 | ||
35b516bd | 233 | default: |
234 | break; | |
832d369d | 235 | } |
236 | ||
35b516bd | 237 | return -1; |
832d369d | 238 | } |
239 | ||
2034deb9 | 240 | /* Return -1 if dwarf ATTR shouldn't be added for TYPE, or the attribute |
241 | value otherwise. */ | |
242 | int | |
243 | cp_type_dwarf_attribute (const_tree type, int attr) | |
244 | { | |
245 | if (type == NULL_TREE) | |
246 | return -1; | |
247 | ||
248 | switch (attr) | |
249 | { | |
250 | case DW_AT_reference: | |
251 | if ((TREE_CODE (type) == FUNCTION_TYPE | |
252 | || TREE_CODE (type) == METHOD_TYPE) | |
253 | && FUNCTION_REF_QUALIFIED (type) | |
254 | && !FUNCTION_RVALUE_QUALIFIED (type)) | |
255 | return 1; | |
256 | break; | |
257 | ||
258 | case DW_AT_rvalue_reference: | |
259 | if ((TREE_CODE (type) == FUNCTION_TYPE | |
260 | || TREE_CODE (type) == METHOD_TYPE) | |
261 | && FUNCTION_REF_QUALIFIED (type) | |
262 | && FUNCTION_RVALUE_QUALIFIED (type)) | |
263 | return 1; | |
264 | break; | |
265 | ||
266 | default: | |
267 | break; | |
268 | } | |
269 | ||
270 | return -1; | |
271 | } | |
272 | ||
3dae587b | 273 | /* Return the unit size of TYPE without reusable tail padding. */ |
274 | ||
275 | tree | |
276 | cp_unit_size_without_reusable_padding (tree type) | |
277 | { | |
278 | if (CLASS_TYPE_P (type)) | |
279 | return CLASSTYPE_SIZE_UNIT (type); | |
280 | return TYPE_SIZE_UNIT (type); | |
281 | } | |
282 | ||
5dd72fac | 283 | /* Stubs to keep c-opts.c happy. */ |
284 | void | |
285 | push_file_scope (void) | |
286 | { | |
287 | } | |
288 | ||
289 | void | |
290 | pop_file_scope (void) | |
291 | { | |
292 | } | |
293 | ||
294 | /* c-pragma.c needs to query whether a decl has extern "C" linkage. */ | |
295 | bool | |
9f627b1a | 296 | has_c_linkage (const_tree decl) |
5dd72fac | 297 | { |
298 | return DECL_EXTERN_C_P (decl); | |
299 | } | |
4dd41a12 | 300 | |
88aa6d3e | 301 | /* Return true if stmt can fall through. Used by block_may_fallthru |
6cb25bec | 302 | default case. */ |
303 | ||
304 | bool | |
305 | cxx_block_may_fallthru (const_tree stmt) | |
306 | { | |
307 | switch (TREE_CODE (stmt)) | |
308 | { | |
309 | case EXPR_STMT: | |
310 | return block_may_fallthru (EXPR_STMT_EXPR (stmt)); | |
311 | ||
312 | case THROW_EXPR: | |
313 | return false; | |
314 | ||
68f67eac | 315 | case IF_STMT: |
316 | if (block_may_fallthru (THEN_CLAUSE (stmt))) | |
317 | return true; | |
318 | return block_may_fallthru (ELSE_CLAUSE (stmt)); | |
319 | ||
3501ad33 | 320 | case SWITCH_STMT: |
321 | return (!SWITCH_STMT_ALL_CASES_P (stmt) | |
322 | || !SWITCH_STMT_NO_BREAK_P (stmt) | |
323 | || block_may_fallthru (SWITCH_STMT_BODY (stmt))); | |
324 | ||
6cb25bec | 325 | default: |
326 | return true; | |
327 | } | |
328 | } | |
329 | ||
3fd4f7d8 | 330 | /* Return the list of decls in the global namespace. */ |
331 | ||
332 | tree | |
333 | cp_get_global_decls () | |
334 | { | |
335 | return NAMESPACE_LEVEL (global_namespace)->names; | |
336 | } | |
337 | ||
338 | /* Push DECL into the current scope. */ | |
339 | ||
340 | tree | |
341 | cp_pushdecl (tree decl) | |
342 | { | |
343 | return pushdecl (decl); | |
344 | } | |
345 | ||
64924d1d | 346 | /* Get the global value binding of NAME. Called directly from |
347 | c-common.c, not via a hook. */ | |
348 | ||
349 | tree | |
350 | identifier_global_value (tree name) | |
351 | { | |
352 | return get_global_binding (name); | |
353 | } | |
354 | ||
0fa326f5 | 355 | /* Register c++-specific dumps. */ |
356 | ||
357 | void | |
358 | cp_register_dumps (gcc::dump_manager *dumps) | |
359 | { | |
360 | class_dump_id = dumps->dump_register | |
361 | (".class", "lang-class", "lang-class", DK_lang, OPTGROUP_NONE, false); | |
88df6264 | 362 | |
363 | raw_dump_id = dumps->dump_register | |
364 | (".raw", "lang-raw", "lang-raw", DK_lang, OPTGROUP_NONE, false); | |
0fa326f5 | 365 | } |
366 | ||
9b88d08d | 367 | void |
368 | cp_common_init_ts (void) | |
369 | { | |
9b88d08d | 370 | MARK_TS_DECL_NON_COMMON (USING_DECL); |
83c7dcd8 | 371 | MARK_TS_DECL_COMMON (TEMPLATE_DECL); |
56c12fd4 | 372 | MARK_TS_DECL_COMMON (WILDCARD_DECL); |
9b88d08d | 373 | |
374 | MARK_TS_COMMON (TEMPLATE_TEMPLATE_PARM); | |
375 | MARK_TS_COMMON (TEMPLATE_TYPE_PARM); | |
376 | MARK_TS_COMMON (TEMPLATE_PARM_INDEX); | |
377 | MARK_TS_COMMON (OVERLOAD); | |
378 | MARK_TS_COMMON (TEMPLATE_INFO); | |
9b88d08d | 379 | MARK_TS_COMMON (TYPENAME_TYPE); |
380 | MARK_TS_COMMON (TYPEOF_TYPE); | |
8de5c43e | 381 | MARK_TS_COMMON (UNDERLYING_TYPE); |
9b88d08d | 382 | MARK_TS_COMMON (BASELINK); |
9b88d08d | 383 | MARK_TS_COMMON (TYPE_PACK_EXPANSION); |
b0801676 | 384 | MARK_TS_COMMON (TYPE_ARGUMENT_PACK); |
9b88d08d | 385 | MARK_TS_COMMON (DECLTYPE_TYPE); |
386 | MARK_TS_COMMON (BOUND_TEMPLATE_TEMPLATE_PARM); | |
387 | MARK_TS_COMMON (UNBOUND_CLASS_TEMPLATE); | |
9b88d08d | 388 | |
d558fa9c | 389 | MARK_TS_TYPED (EXPR_PACK_EXPANSION); |
1f919c50 | 390 | MARK_TS_TYPED (SWITCH_STMT); |
852787ab | 391 | MARK_TS_TYPED (IF_STMT); |
e45c9c55 | 392 | MARK_TS_TYPED (FOR_STMT); |
393 | MARK_TS_TYPED (RANGE_FOR_STMT); | |
9b88d08d | 394 | MARK_TS_TYPED (AGGR_INIT_EXPR); |
395 | MARK_TS_TYPED (EXPR_STMT); | |
396 | MARK_TS_TYPED (EH_SPEC_BLOCK); | |
397 | MARK_TS_TYPED (CLEANUP_STMT); | |
398 | MARK_TS_TYPED (SCOPE_REF); | |
399 | MARK_TS_TYPED (CAST_EXPR); | |
400 | MARK_TS_TYPED (NON_DEPENDENT_EXPR); | |
401 | MARK_TS_TYPED (MODOP_EXPR); | |
402 | MARK_TS_TYPED (TRY_BLOCK); | |
403 | MARK_TS_TYPED (THROW_EXPR); | |
404 | MARK_TS_TYPED (HANDLER); | |
405 | MARK_TS_TYPED (REINTERPRET_CAST_EXPR); | |
406 | MARK_TS_TYPED (CONST_CAST_EXPR); | |
407 | MARK_TS_TYPED (STATIC_CAST_EXPR); | |
408 | MARK_TS_TYPED (DYNAMIC_CAST_EXPR); | |
91c3ace5 | 409 | MARK_TS_TYPED (IMPLICIT_CONV_EXPR); |
9b88d08d | 410 | MARK_TS_TYPED (TEMPLATE_ID_EXPR); |
411 | MARK_TS_TYPED (ARROW_EXPR); | |
412 | MARK_TS_TYPED (SIZEOF_EXPR); | |
413 | MARK_TS_TYPED (ALIGNOF_EXPR); | |
414 | MARK_TS_TYPED (AT_ENCODE_EXPR); | |
415 | MARK_TS_TYPED (UNARY_PLUS_EXPR); | |
416 | MARK_TS_TYPED (TRAIT_EXPR); | |
417 | MARK_TS_TYPED (TYPE_ARGUMENT_PACK); | |
418 | MARK_TS_TYPED (NOEXCEPT_EXPR); | |
419 | MARK_TS_TYPED (NONTYPE_ARGUMENT_PACK); | |
420 | MARK_TS_TYPED (WHILE_STMT); | |
421 | MARK_TS_TYPED (NEW_EXPR); | |
422 | MARK_TS_TYPED (VEC_NEW_EXPR); | |
423 | MARK_TS_TYPED (BREAK_STMT); | |
424 | MARK_TS_TYPED (MEMBER_REF); | |
425 | MARK_TS_TYPED (DOTSTAR_EXPR); | |
426 | MARK_TS_TYPED (DO_STMT); | |
427 | MARK_TS_TYPED (DELETE_EXPR); | |
428 | MARK_TS_TYPED (VEC_DELETE_EXPR); | |
429 | MARK_TS_TYPED (CONTINUE_STMT); | |
430 | MARK_TS_TYPED (TAG_DEFN); | |
431 | MARK_TS_TYPED (PSEUDO_DTOR_EXPR); | |
432 | MARK_TS_TYPED (TYPEID_EXPR); | |
433 | MARK_TS_TYPED (MUST_NOT_THROW_EXPR); | |
434 | MARK_TS_TYPED (STMT_EXPR); | |
435 | MARK_TS_TYPED (OFFSET_REF); | |
436 | MARK_TS_TYPED (OFFSETOF_EXPR); | |
cd45162d | 437 | MARK_TS_TYPED (ADDRESSOF_EXPR); |
9b88d08d | 438 | MARK_TS_TYPED (PTRMEM_CST); |
439 | MARK_TS_TYPED (EMPTY_CLASS_EXPR); | |
440 | MARK_TS_TYPED (VEC_INIT_EXPR); | |
441 | MARK_TS_TYPED (USING_STMT); | |
442 | MARK_TS_TYPED (LAMBDA_EXPR); | |
e2d6b6ce | 443 | MARK_TS_TYPED (CTOR_INITIALIZER); |
56c12fd4 | 444 | MARK_TS_TYPED (REQUIRES_EXPR); |
a4c3da45 | 445 | MARK_TS_TYPED (UNARY_LEFT_FOLD_EXPR); |
446 | MARK_TS_TYPED (UNARY_RIGHT_FOLD_EXPR); | |
447 | MARK_TS_TYPED (BINARY_LEFT_FOLD_EXPR); | |
448 | MARK_TS_TYPED (BINARY_RIGHT_FOLD_EXPR); | |
7e5a76c8 | 449 | MARK_TS_TYPED (OMP_DEPOBJ); |
9b88d08d | 450 | } |
4dd41a12 | 451 | |
452 | #include "gt-cp-cp-objcp-common.h" |