Branch data Line data Source code
1 : : /* Some code common to C++ and ObjC++ front ends.
2 : : Copyright (C) 2004-2025 Free Software Foundation, Inc.
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
9 : : Software Foundation; either version 3, or (at your option) any later
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
18 : : along with GCC; see the file COPYING3. If not see
19 : : <http://www.gnu.org/licenses/>. */
20 : :
21 : : #include "config.h"
22 : : #include "system.h"
23 : : #include "coretypes.h"
24 : : #include "cp-tree.h"
25 : : #include "cp-objcp-common.h"
26 : : #include "c-family/c-common.h"
27 : : #include "dwarf2.h"
28 : : #include "stringpool.h"
29 : : #include "contracts.h"
30 : :
31 : : /* Class to determine whether a given C++ language feature is available.
32 : : Used to implement __has_{feature,extension}. */
33 : :
34 : : struct cp_feature_selector
35 : : {
36 : : enum
37 : : {
38 : : DIALECT,
39 : : FLAG
40 : : } kind;
41 : :
42 : : enum class result
43 : : {
44 : : NONE,
45 : : EXT,
46 : : FEAT
47 : : };
48 : :
49 : : union
50 : : {
51 : : const int *enable_flag;
52 : : struct {
53 : : enum cxx_dialect feat;
54 : : enum cxx_dialect ext;
55 : : } dialect;
56 : : };
57 : :
58 : : constexpr cp_feature_selector (const int *flag)
59 : : : kind (FLAG), enable_flag (flag) {}
60 : : constexpr cp_feature_selector (enum cxx_dialect feat,
61 : : enum cxx_dialect ext)
62 : : : kind (DIALECT), dialect{feat, ext} {}
63 : : constexpr cp_feature_selector (enum cxx_dialect feat)
64 : : : cp_feature_selector (feat, feat) {}
65 : :
66 : : inline result has_feature () const;
67 : : };
68 : :
69 : : /* Check whether this language feature is available as a feature,
70 : : extension, or not at all. */
71 : :
72 : : cp_feature_selector::result
73 : 1019328 : cp_feature_selector::has_feature () const
74 : : {
75 : 1019328 : switch (kind)
76 : : {
77 : 955620 : case DIALECT:
78 : 955620 : if (cxx_dialect >= dialect.feat)
79 : : return result::FEAT;
80 : 57402 : else if (cxx_dialect >= dialect.ext)
81 : : return result::EXT;
82 : : else
83 : 49678 : return result::NONE;
84 : 63708 : case FLAG:
85 : 63708 : return *enable_flag ? result::FEAT : result::NONE;
86 : : }
87 : :
88 : 0 : gcc_unreachable ();
89 : : }
90 : :
91 : : /* Information about a C++ language feature which can be queried
92 : : through __has_{feature,extension}. IDENT is the name of the feature,
93 : : and SELECTOR encodes how to compute whether the feature is available. */
94 : :
95 : : struct cp_feature_info
96 : : {
97 : : const char *ident;
98 : : cp_feature_selector selector;
99 : : };
100 : :
101 : : /* Table of features for __has_{feature,extension}. */
102 : :
103 : : static constexpr cp_feature_info cp_feature_table[] =
104 : : {
105 : : { "cxx_exceptions", &flag_exceptions },
106 : : { "cxx_rtti", &flag_rtti },
107 : : { "cxx_access_control_sfinae", { cxx11, cxx98 } },
108 : : { "cxx_alias_templates", cxx11 },
109 : : { "cxx_alignas", cxx11 },
110 : : { "cxx_alignof", cxx11 },
111 : : { "cxx_attributes", cxx11 },
112 : : { "cxx_constexpr", cxx11 },
113 : : { "cxx_decltype", cxx11 },
114 : : { "cxx_decltype_incomplete_return_types", cxx11 },
115 : : { "cxx_default_function_template_args", cxx11 },
116 : : { "cxx_defaulted_functions", cxx11 },
117 : : { "cxx_delegating_constructors", cxx11 },
118 : : { "cxx_deleted_functions", cxx11 },
119 : : { "cxx_explicit_conversions", cxx11 },
120 : : { "cxx_generalized_initializers", cxx11 },
121 : : { "cxx_implicit_moves", cxx11 },
122 : : { "cxx_inheriting_constructors", cxx11 },
123 : : { "cxx_inline_namespaces", { cxx11, cxx98 } },
124 : : { "cxx_lambdas", cxx11 },
125 : : { "cxx_local_type_template_args", cxx11 },
126 : : { "cxx_noexcept", cxx11 },
127 : : { "cxx_nonstatic_member_init", cxx11 },
128 : : { "cxx_nullptr", cxx11 },
129 : : { "cxx_override_control", cxx11 },
130 : : { "cxx_reference_qualified_functions", cxx11 },
131 : : { "cxx_range_for", cxx11 },
132 : : { "cxx_raw_string_literals", cxx11 },
133 : : { "cxx_rvalue_references", cxx11 },
134 : : { "cxx_static_assert", cxx11 },
135 : : { "cxx_thread_local", cxx11 },
136 : : { "cxx_auto_type", cxx11 },
137 : : { "cxx_strong_enums", cxx11 },
138 : : { "cxx_trailing_return", cxx11 },
139 : : { "cxx_unicode_literals", cxx11 },
140 : : { "cxx_unrestricted_unions", cxx11 },
141 : : { "cxx_user_literals", cxx11 },
142 : : { "cxx_variadic_templates", { cxx11, cxx98 } },
143 : : { "cxx_binary_literals", { cxx14, cxx98 } },
144 : : { "cxx_contextual_conversions", { cxx14, cxx98 } },
145 : : { "cxx_decltype_auto", cxx14 },
146 : : { "cxx_aggregate_nsdmi", cxx14 },
147 : : { "cxx_init_captures", { cxx14, cxx11 } },
148 : : { "cxx_generic_lambdas", cxx14 },
149 : : { "cxx_relaxed_constexpr", cxx14 },
150 : : { "cxx_return_type_deduction", cxx14 },
151 : : { "cxx_variable_templates", cxx14 },
152 : : { "modules", &flag_modules },
153 : : };
154 : :
155 : : /* Register C++ language features for __has_{feature,extension}. */
156 : :
157 : : void
158 : 21236 : cp_register_features ()
159 : : {
160 : 21236 : using result = cp_feature_selector::result;
161 : :
162 : 1040564 : for (unsigned i = 0; i < ARRAY_SIZE (cp_feature_table); i++)
163 : : {
164 : 1019328 : const cp_feature_info *info = cp_feature_table + i;
165 : 1019328 : const auto res = info->selector.has_feature ();
166 : 1019328 : if (res == result::NONE)
167 : 72321 : continue;
168 : :
169 : 947007 : c_common_register_feature (info->ident, res == result::FEAT);
170 : : }
171 : 21236 : }
172 : :
173 : : /* Special routine to get the alias set for C++. */
174 : :
175 : : alias_set_type
176 : 426795524 : cxx_get_alias_set (tree t)
177 : : {
178 : 426795524 : if (IS_FAKE_BASE_TYPE (t))
179 : : /* The base variant of a type must be in the same alias set as the
180 : : complete type. */
181 : 883237 : return get_alias_set (TYPE_CONTEXT (t));
182 : :
183 : : /* Punt on PMFs until we canonicalize functions properly. */
184 : 621145 : if (TYPE_PTRMEMFUNC_P (t)
185 : 426353267 : || (INDIRECT_TYPE_P (t)
186 : 405546 : && TYPE_PTRMEMFUNC_P (TREE_TYPE (t))))
187 : : return 0;
188 : :
189 : 425715637 : return c_common_get_alias_set (t);
190 : : }
191 : :
192 : : /* Called from check_global_declaration. */
193 : :
194 : : bool
195 : 2962 : cxx_warn_unused_global_decl (const_tree decl)
196 : : {
197 : 2962 : if (TREE_CODE (decl) == FUNCTION_DECL && DECL_DECLARED_INLINE_P (decl))
198 : : return false;
199 : 93 : if (DECL_IN_SYSTEM_HEADER (decl))
200 : : return false;
201 : :
202 : : return true;
203 : : }
204 : :
205 : : /* Langhook for tree_size: determine size of our 'x' and 'c' nodes. */
206 : : size_t
207 : 2148054663 : cp_tree_size (enum tree_code code)
208 : : {
209 : 2148054663 : gcc_checking_assert (code >= NUM_TREE_CODES);
210 : 2148054663 : switch (code)
211 : : {
212 : : case PTRMEM_CST: return sizeof (ptrmem_cst);
213 : : case BASELINK: return sizeof (tree_baselink);
214 : : case TEMPLATE_PARM_INDEX: return sizeof (template_parm_index);
215 : : case DEFERRED_PARSE: return sizeof (tree_deferred_parse);
216 : : case DEFERRED_NOEXCEPT: return sizeof (tree_deferred_noexcept);
217 : : case OVERLOAD: return sizeof (tree_overload);
218 : : case STATIC_ASSERT: return sizeof (tree_static_assert);
219 : : #if 0
220 : : /* This would match cp_common_init_ts, but breaks GC because
221 : : tree_node_structure_for_code returns TS_TYPE_NON_COMMON for all
222 : : types. */
223 : : case UNBOUND_CLASS_TEMPLATE:
224 : : case TYPE_ARGUMENT_PACK: return sizeof (tree_type_common);
225 : : #endif
226 : : case ARGUMENT_PACK_SELECT: return sizeof (tree_argument_pack_select);
227 : : case TRAIT_EXPR: return sizeof (tree_trait_expr);
228 : 903699 : case LAMBDA_EXPR: return sizeof (tree_lambda_expr);
229 : : case TEMPLATE_INFO: return sizeof (tree_template_info);
230 : : case CONSTRAINT_INFO: return sizeof (tree_constraint_info);
231 : : case USERDEF_LITERAL: return sizeof (tree_userdef_literal);
232 : 198114927 : case TEMPLATE_DECL: return sizeof (tree_template_decl);
233 : : case ASSERTION_STMT: return sizeof (tree_exp);
234 : : case PRECONDITION_STMT: return sizeof (tree_exp);
235 : : case POSTCONDITION_STMT: return sizeof (tree_exp);
236 : : case TU_LOCAL_ENTITY: return sizeof (tree_tu_local_entity);
237 : 646747378 : default:
238 : 646747378 : switch (TREE_CODE_CLASS (code))
239 : : {
240 : : case tcc_declaration: return sizeof (tree_decl_non_common);
241 : 618396280 : case tcc_type: return sizeof (tree_type_non_common);
242 : 0 : default: gcc_unreachable ();
243 : : }
244 : : }
245 : : /* NOTREACHED */
246 : : }
247 : :
248 : : /* Returns true if T is a variably modified type, in the sense of C99.
249 : : FN is as passed to variably_modified_p.
250 : : This routine needs only check cases that cannot be handled by the
251 : : language-independent logic in tree.cc. */
252 : :
253 : : bool
254 : 1516135683 : cp_var_mod_type_p (tree type, tree fn)
255 : : {
256 : : /* If TYPE is a pointer-to-member, it is variably modified if either
257 : : the class or the member are variably modified. */
258 : 1516135683 : if (TYPE_PTRMEM_P (type))
259 : 1828456 : return (variably_modified_type_p (TYPE_PTRMEM_CLASS_TYPE (type), fn)
260 : 1828456 : || variably_modified_type_p (TYPE_PTRMEM_POINTED_TO_TYPE (type),
261 : : fn));
262 : :
263 : : /* All other types are not variably modified. */
264 : : return false;
265 : : }
266 : :
267 : : /* This compares two types for equivalence ("compatible" in C-based languages).
268 : : This routine should only return 1 if it is sure. It should not be used
269 : : in contexts where erroneously returning 0 causes problems. */
270 : :
271 : : int
272 : 1190269 : cxx_types_compatible_p (tree x, tree y)
273 : : {
274 : 1190269 : return same_type_ignoring_top_level_qualifiers_p (x, y);
275 : : }
276 : :
277 : : static GTY((cache)) type_tree_cache_map *debug_type_map;
278 : :
279 : : /* Return a type to use in the debug info instead of TYPE, or NULL_TREE to
280 : : keep TYPE. */
281 : :
282 : : tree
283 : 1006936648 : cp_get_debug_type (const_tree type)
284 : : {
285 : 1006936648 : tree dtype = NULL_TREE;
286 : :
287 : 1006936648 : if (TYPE_PTRMEMFUNC_P (type) && !typedef_variant_p (type))
288 : 255583 : dtype = build_offset_type (TYPE_PTRMEMFUNC_OBJECT_TYPE (type),
289 : 255583 : TREE_TYPE (TYPE_PTRMEMFUNC_FN_TYPE (type)));
290 : :
291 : : /* We cannot simply return the debug type here because the function uses
292 : : the type canonicalization hashtable, which is GC-ed, so its behavior
293 : : depends on the actual collection points. Since we are building these
294 : : types on the fly for the debug info only, they would not be attached
295 : : to any GC root and always be swept, so we would make the contents of
296 : : the debug info depend on the collection points. */
297 : 1006936648 : if (dtype)
298 : : {
299 : 255583 : tree ktype = CONST_CAST_TREE (type);
300 : 501394 : if (tree *slot = hash_map_safe_get (debug_type_map, ktype))
301 : 223868 : return *slot;
302 : 31715 : hash_map_safe_put<hm_ggc> (debug_type_map, ktype, dtype);
303 : : }
304 : :
305 : : return dtype;
306 : : }
307 : :
308 : : /* Return -1 if dwarf ATTR shouldn't be added for DECL, or the attribute
309 : : value otherwise. */
310 : : int
311 : 466599218 : cp_decl_dwarf_attribute (const_tree decl, int attr)
312 : : {
313 : 466599218 : if (decl == NULL_TREE)
314 : : return -1;
315 : :
316 : 466599218 : switch (attr)
317 : : {
318 : 77392565 : case DW_AT_explicit:
319 : 77392565 : if (TREE_CODE (decl) == FUNCTION_DECL
320 : 77392565 : && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl))
321 : 154785041 : && DECL_NONCONVERTING_P (decl))
322 : 2056688 : return 1;
323 : : break;
324 : :
325 : 77392547 : case DW_AT_deleted:
326 : 77392547 : if (TREE_CODE (decl) == FUNCTION_DECL
327 : 77392547 : && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl))
328 : 154785005 : && DECL_DELETED_FN (decl))
329 : 2402874 : return 1;
330 : : break;
331 : :
332 : 78727775 : case DW_AT_defaulted:
333 : 78727775 : if (TREE_CODE (decl) == FUNCTION_DECL
334 : 78727775 : && DECL_LANG_SPECIFIC (STRIP_TEMPLATE (decl))
335 : 157455461 : && DECL_DEFAULTED_FN (decl))
336 : : {
337 : 5734582 : if (DECL_DEFAULTED_IN_CLASS_P (decl))
338 : : return DW_DEFAULTED_in_class;
339 : :
340 : 938891 : if (DECL_DEFAULTED_OUTSIDE_CLASS_P (decl))
341 : 601 : return DW_DEFAULTED_out_of_class;
342 : : }
343 : : break;
344 : :
345 : 31394275 : case DW_AT_const_expr:
346 : 31394275 : if (VAR_OR_FUNCTION_DECL_P (decl) && DECL_DECLARED_CONSTEXPR_P (decl))
347 : 26391885 : return 1;
348 : : break;
349 : :
350 : 77392547 : case DW_AT_reference:
351 : 77392547 : if (TREE_CODE (decl) == FUNCTION_DECL
352 : 77392547 : && DECL_IOBJ_MEMBER_FUNCTION_P (decl)
353 : 66319489 : && FUNCTION_REF_QUALIFIED (TREE_TYPE (decl))
354 : 77453066 : && !FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl)))
355 : 27199 : return 1;
356 : : break;
357 : :
358 : 77392547 : case DW_AT_rvalue_reference:
359 : 77392547 : if (TREE_CODE (decl) == FUNCTION_DECL
360 : 77392547 : && DECL_IOBJ_MEMBER_FUNCTION_P (decl)
361 : 66319489 : && FUNCTION_REF_QUALIFIED (TREE_TYPE (decl))
362 : 77453066 : && FUNCTION_RVALUE_QUALIFIED (TREE_TYPE (decl)))
363 : 33320 : return 1;
364 : : break;
365 : :
366 : 46421981 : case DW_AT_inline:
367 : 46421981 : if (VAR_P (decl) && DECL_INLINE_VAR_P (decl))
368 : : {
369 : 39755800 : if (DECL_VAR_DECLARED_INLINE_P (decl))
370 : : return DW_INL_declared_inlined;
371 : : else
372 : 28983811 : return DW_INL_inlined;
373 : : }
374 : : break;
375 : :
376 : 484981 : case DW_AT_export_symbols:
377 : 484981 : if (TREE_CODE (decl) == NAMESPACE_DECL
378 : 484981 : && (DECL_NAMESPACE_INLINE_P (decl)
379 : 277671 : || (DECL_NAME (decl) == NULL_TREE && dwarf_version >= 5)))
380 : 208375 : return 1;
381 : : break;
382 : :
383 : : default:
384 : : break;
385 : : }
386 : :
387 : : return -1;
388 : : }
389 : :
390 : : /* Return -1 if dwarf ATTR shouldn't be added for TYPE, or the attribute
391 : : value otherwise. */
392 : : int
393 : 727597 : cp_type_dwarf_attribute (const_tree type, int attr)
394 : : {
395 : 727597 : if (type == NULL_TREE)
396 : : return -1;
397 : :
398 : 727597 : switch (attr)
399 : : {
400 : 301722 : case DW_AT_reference:
401 : 301722 : if (FUNC_OR_METHOD_TYPE_P (type)
402 : 301722 : && FUNCTION_REF_QUALIFIED (type)
403 : 301853 : && !FUNCTION_RVALUE_QUALIFIED (type))
404 : 91 : return 1;
405 : : break;
406 : :
407 : 301722 : case DW_AT_rvalue_reference:
408 : 301722 : if (FUNC_OR_METHOD_TYPE_P (type)
409 : 301722 : && FUNCTION_REF_QUALIFIED (type)
410 : 301853 : && FUNCTION_RVALUE_QUALIFIED (type))
411 : 40 : return 1;
412 : : break;
413 : :
414 : 124153 : case DW_AT_export_symbols:
415 : 124153 : if (ANON_AGGR_TYPE_P (type))
416 : 124153 : return 1;
417 : : break;
418 : :
419 : : default:
420 : : break;
421 : : }
422 : :
423 : : return -1;
424 : : }
425 : :
426 : : /* Return the unit size of TYPE without reusable tail padding. */
427 : :
428 : : tree
429 : 30973 : cp_unit_size_without_reusable_padding (tree type)
430 : : {
431 : 30973 : if (CLASS_TYPE_P (type))
432 : 30973 : return CLASSTYPE_SIZE_UNIT (type);
433 : 0 : return TYPE_SIZE_UNIT (type);
434 : : }
435 : :
436 : : /* Returns type corresponding to FIELD's type when FIELD is a C++ base class
437 : : i.e., type without virtual base classes or tail padding. Returns
438 : : NULL_TREE otherwise. */
439 : :
440 : : tree
441 : 2362 : cp_classtype_as_base (const_tree field)
442 : : {
443 : 2362 : if (DECL_FIELD_IS_BASE (field))
444 : : {
445 : 195 : tree type = TREE_TYPE (field);
446 : 195 : if (TYPE_LANG_SPECIFIC (type))
447 : 188 : return CLASSTYPE_AS_BASE (type);
448 : : }
449 : : return NULL_TREE;
450 : : }
451 : :
452 : : /* Stubs to keep c-opts.cc happy. */
453 : : void
454 : 93777 : push_file_scope (void)
455 : : {
456 : 93777 : }
457 : :
458 : : void
459 : 93652 : pop_file_scope (void)
460 : : {
461 : 93652 : }
462 : :
463 : : /* c-pragma.cc needs to query whether a decl has extern "C" linkage. */
464 : : bool
465 : 47566907 : has_c_linkage (const_tree decl)
466 : : {
467 : 47566907 : return DECL_EXTERN_C_P (decl);
468 : : }
469 : :
470 : : /* Return true if stmt can fall through. Used by block_may_fallthru
471 : : default case. */
472 : :
473 : : bool
474 : 3803692 : cxx_block_may_fallthru (const_tree stmt)
475 : : {
476 : 3803692 : switch (TREE_CODE (stmt))
477 : : {
478 : 1737429 : case EXPR_STMT:
479 : 1737429 : return block_may_fallthru (EXPR_STMT_EXPR (stmt));
480 : :
481 : : case THROW_EXPR:
482 : : return false;
483 : :
484 : 485615 : case IF_STMT:
485 : 485615 : if (IF_STMT_CONSTEXPR_P (stmt))
486 : : {
487 : 14017 : if (integer_nonzerop (IF_COND (stmt)))
488 : 260 : return block_may_fallthru (THEN_CLAUSE (stmt));
489 : 13757 : if (integer_zerop (IF_COND (stmt)))
490 : 577 : return block_may_fallthru (ELSE_CLAUSE (stmt));
491 : : }
492 : 484778 : if (block_may_fallthru (THEN_CLAUSE (stmt)))
493 : : return true;
494 : 1106 : return block_may_fallthru (ELSE_CLAUSE (stmt));
495 : :
496 : 11 : case CLEANUP_STMT:
497 : : /* Just handle the try/finally cases. */
498 : 11 : if (!CLEANUP_EH_ONLY (stmt))
499 : : {
500 : 11 : return (block_may_fallthru (CLEANUP_BODY (stmt))
501 : 19 : && block_may_fallthru (CLEANUP_EXPR (stmt)));
502 : : }
503 : : return true;
504 : :
505 : 1580615 : default:
506 : 1580615 : return c_block_may_fallthru (stmt);
507 : : }
508 : : }
509 : :
510 : : /* Return the list of decls in the global namespace. */
511 : :
512 : : tree
513 : 0 : cp_get_global_decls ()
514 : : {
515 : 0 : return NAMESPACE_LEVEL (global_namespace)->names;
516 : : }
517 : :
518 : : /* Push DECL into the current (namespace) scope. */
519 : :
520 : : tree
521 : 1897572 : cp_pushdecl (tree decl)
522 : : {
523 : 1897572 : DECL_CONTEXT (decl) = FROB_CONTEXT (current_namespace);
524 : 1897572 : return pushdecl (decl);
525 : : }
526 : :
527 : : /* Get the global value binding of NAME. Called directly from
528 : : c-common.cc, not via a hook. */
529 : :
530 : : tree
531 : 3326337 : identifier_global_value (tree name)
532 : : {
533 : 3326337 : return get_global_binding (name);
534 : : }
535 : :
536 : : /* Similarly, but return struct/class/union NAME instead. */
537 : :
538 : : tree
539 : 36 : identifier_global_tag (tree name)
540 : : {
541 : 36 : tree ret = lookup_qualified_name (global_namespace, name, LOOK_want::TYPE,
542 : : /*complain*/false);
543 : 36 : if (ret == error_mark_node)
544 : 3 : return NULL_TREE;
545 : : return ret;
546 : : }
547 : :
548 : : /* Returns non-zero (result of __has_builtin) if NAME refers to a built-in
549 : : function or function-like operator. */
550 : :
551 : : int
552 : 6014893 : names_builtin_p (const char *name)
553 : : {
554 : 6014893 : tree id = get_identifier (name);
555 : 6014893 : if (tree binding = get_global_binding (id))
556 : : {
557 : 1762887 : if (TREE_CODE (binding) == FUNCTION_DECL
558 : 1762887 : && DECL_IS_UNDECLARED_BUILTIN (binding))
559 : : return 1;
560 : :
561 : : /* Handle the case when an overload for a built-in name exists. */
562 : 9 : if (TREE_CODE (binding) != OVERLOAD)
563 : : return 0;
564 : :
565 : 9 : for (ovl_iterator it (binding); it; ++it)
566 : : {
567 : 9 : tree decl = *it;
568 : 9 : if (DECL_IS_UNDECLARED_BUILTIN (decl))
569 : 9 : return 1;
570 : : }
571 : : }
572 : :
573 : : /* Check for built-in traits. */
574 : 4252006 : if (IDENTIFIER_TRAIT_P (id))
575 : : return 1;
576 : :
577 : : /* Also detect common reserved C++ words that aren't strictly built-in
578 : : functions. */
579 : 598029 : switch (C_RID_CODE (id))
580 : : {
581 : : case RID_ADDRESSOF:
582 : : case RID_BUILTIN_CONVERTVECTOR:
583 : : case RID_BUILTIN_HAS_ATTRIBUTE:
584 : : case RID_BUILTIN_SHUFFLE:
585 : : case RID_BUILTIN_SHUFFLEVECTOR:
586 : : case RID_BUILTIN_LAUNDER:
587 : : case RID_BUILTIN_ASSOC_BARRIER:
588 : : case RID_BUILTIN_BIT_CAST:
589 : : case RID_OFFSETOF:
590 : : case RID_VA_ARG:
591 : : return 1;
592 : : case RID_BUILTIN_OPERATOR_NEW:
593 : : case RID_BUILTIN_OPERATOR_DELETE:
594 : : return 201802L;
595 : : default:
596 : : break;
597 : : }
598 : :
599 : : return 0;
600 : : }
601 : :
602 : : /* Register c++-specific dumps. */
603 : :
604 : : void
605 : 95119 : cp_register_dumps (gcc::dump_manager *dumps)
606 : : {
607 : 190238 : class_dump_id = dumps->dump_register
608 : 95119 : (".class", "lang-class", "lang-class", DK_lang, OPTGROUP_NONE, false);
609 : :
610 : 190238 : module_dump_id = dumps->dump_register
611 : 95119 : (".module", "lang-module", "lang-module", DK_lang, OPTGROUP_NONE, false);
612 : :
613 : 190238 : raw_dump_id = dumps->dump_register
614 : 95119 : (".raw", "lang-raw", "lang-raw", DK_lang, OPTGROUP_NONE, false);
615 : 190238 : coro_dump_id = dumps->dump_register
616 : 95119 : (".coro", "lang-coro", "lang-coro", DK_lang, OPTGROUP_NONE, false);
617 : 190238 : tinst_dump_id = dumps->dump_register
618 : 95119 : (".tinst", "lang-tinst", "lang-tinst", DK_lang, OPTGROUP_NONE, false);
619 : 95119 : }
620 : :
621 : : void
622 : 95119 : cp_common_init_ts (void)
623 : : {
624 : : /* With type. */
625 : 95119 : MARK_TS_TYPED (PTRMEM_CST);
626 : 95119 : MARK_TS_TYPED (LAMBDA_EXPR);
627 : 95119 : MARK_TS_TYPED (TYPE_ARGUMENT_PACK);
628 : 95119 : MARK_TS_TYPED (TRAIT_EXPR);
629 : :
630 : : /* Random new trees. */
631 : 95119 : MARK_TS_COMMON (BASELINK);
632 : 95119 : MARK_TS_COMMON (OVERLOAD);
633 : 95119 : MARK_TS_COMMON (TEMPLATE_PARM_INDEX);
634 : :
635 : : /* New decls. */
636 : 95119 : MARK_TS_DECL_COMMON (TEMPLATE_DECL);
637 : :
638 : 95119 : MARK_TS_DECL_NON_COMMON (USING_DECL);
639 : :
640 : : /* New Types. */
641 : 95119 : MARK_TS_TYPE_COMMON (UNBOUND_CLASS_TEMPLATE);
642 : 95119 : MARK_TS_TYPE_COMMON (TYPE_ARGUMENT_PACK);
643 : 95119 : MARK_TS_TYPE_COMMON (DEPENDENT_OPERATOR_TYPE);
644 : :
645 : 95119 : MARK_TS_TYPE_NON_COMMON (DECLTYPE_TYPE);
646 : 95119 : MARK_TS_TYPE_NON_COMMON (TYPENAME_TYPE);
647 : 95119 : MARK_TS_TYPE_NON_COMMON (TYPEOF_TYPE);
648 : 95119 : MARK_TS_TYPE_NON_COMMON (TRAIT_TYPE);
649 : 95119 : MARK_TS_TYPE_NON_COMMON (BOUND_TEMPLATE_TEMPLATE_PARM);
650 : 95119 : MARK_TS_TYPE_NON_COMMON (TEMPLATE_TEMPLATE_PARM);
651 : 95119 : MARK_TS_TYPE_NON_COMMON (TEMPLATE_TYPE_PARM);
652 : 95119 : MARK_TS_TYPE_NON_COMMON (TYPE_PACK_EXPANSION);
653 : 95119 : MARK_TS_TYPE_NON_COMMON (PACK_INDEX_TYPE);
654 : :
655 : : /* Statements. */
656 : 95119 : MARK_TS_EXP (CLEANUP_STMT);
657 : 95119 : MARK_TS_EXP (EH_SPEC_BLOCK);
658 : 95119 : MARK_TS_EXP (HANDLER);
659 : 95119 : MARK_TS_EXP (IF_STMT);
660 : 95119 : MARK_TS_EXP (OMP_DEPOBJ);
661 : 95119 : MARK_TS_EXP (RANGE_FOR_STMT);
662 : 95119 : MARK_TS_EXP (TRY_BLOCK);
663 : 95119 : MARK_TS_EXP (USING_STMT);
664 : :
665 : : /* Random expressions. */
666 : 95119 : MARK_TS_EXP (ADDRESSOF_EXPR);
667 : 95119 : MARK_TS_EXP (AGGR_INIT_EXPR);
668 : 95119 : MARK_TS_EXP (ALIGNOF_EXPR);
669 : 95119 : MARK_TS_EXP (ARROW_EXPR);
670 : 95119 : MARK_TS_EXP (AT_ENCODE_EXPR);
671 : 95119 : MARK_TS_EXP (BIT_CAST_EXPR);
672 : 95119 : MARK_TS_EXP (CAST_EXPR);
673 : 95119 : MARK_TS_EXP (CONST_CAST_EXPR);
674 : 95119 : MARK_TS_EXP (CTOR_INITIALIZER);
675 : 95119 : MARK_TS_EXP (DELETE_EXPR);
676 : 95119 : MARK_TS_EXP (DOTSTAR_EXPR);
677 : 95119 : MARK_TS_EXP (DYNAMIC_CAST_EXPR);
678 : 95119 : MARK_TS_EXP (EMPTY_CLASS_EXPR);
679 : 95119 : MARK_TS_EXP (EXPR_STMT);
680 : 95119 : MARK_TS_EXP (IMPLICIT_CONV_EXPR);
681 : 95119 : MARK_TS_EXP (MEMBER_REF);
682 : 95119 : MARK_TS_EXP (MODOP_EXPR);
683 : 95119 : MARK_TS_EXP (MUST_NOT_THROW_EXPR);
684 : 95119 : MARK_TS_EXP (NEW_EXPR);
685 : 95119 : MARK_TS_EXP (NOEXCEPT_EXPR);
686 : 95119 : MARK_TS_EXP (OFFSETOF_EXPR);
687 : 95119 : MARK_TS_EXP (OFFSET_REF);
688 : 95119 : MARK_TS_EXP (PSEUDO_DTOR_EXPR);
689 : 95119 : MARK_TS_EXP (REINTERPRET_CAST_EXPR);
690 : 95119 : MARK_TS_EXP (SCOPE_REF);
691 : 95119 : MARK_TS_EXP (STATIC_CAST_EXPR);
692 : 95119 : MARK_TS_EXP (STMT_EXPR);
693 : 95119 : MARK_TS_EXP (TAG_DEFN);
694 : 95119 : MARK_TS_EXP (TEMPLATE_ID_EXPR);
695 : 95119 : MARK_TS_EXP (THROW_EXPR);
696 : 95119 : MARK_TS_EXP (TYPEID_EXPR);
697 : 95119 : MARK_TS_EXP (TYPE_EXPR);
698 : 95119 : MARK_TS_EXP (UNARY_PLUS_EXPR);
699 : 95119 : MARK_TS_EXP (VEC_DELETE_EXPR);
700 : 95119 : MARK_TS_EXP (VEC_INIT_EXPR);
701 : 95119 : MARK_TS_EXP (VEC_NEW_EXPR);
702 : 95119 : MARK_TS_EXP (SPACESHIP_EXPR);
703 : :
704 : : /* Fold expressions. */
705 : 95119 : MARK_TS_EXP (BINARY_LEFT_FOLD_EXPR);
706 : 95119 : MARK_TS_EXP (BINARY_RIGHT_FOLD_EXPR);
707 : 95119 : MARK_TS_EXP (EXPR_PACK_EXPANSION);
708 : 95119 : MARK_TS_EXP (NONTYPE_ARGUMENT_PACK);
709 : 95119 : MARK_TS_EXP (UNARY_LEFT_FOLD_EXPR);
710 : 95119 : MARK_TS_EXP (UNARY_RIGHT_FOLD_EXPR);
711 : 95119 : MARK_TS_EXP (PACK_INDEX_EXPR);
712 : :
713 : : /* Constraints. */
714 : 95119 : MARK_TS_EXP (COMPOUND_REQ);
715 : 95119 : MARK_TS_EXP (CONJ_CONSTR);
716 : 95119 : MARK_TS_EXP (DISJ_CONSTR);
717 : 95119 : MARK_TS_EXP (ATOMIC_CONSTR);
718 : 95119 : MARK_TS_EXP (NESTED_REQ);
719 : 95119 : MARK_TS_EXP (REQUIRES_EXPR);
720 : 95119 : MARK_TS_EXP (SIMPLE_REQ);
721 : 95119 : MARK_TS_EXP (TYPE_REQ);
722 : :
723 : 95119 : MARK_TS_EXP (CO_AWAIT_EXPR);
724 : 95119 : MARK_TS_EXP (CO_YIELD_EXPR);
725 : 95119 : MARK_TS_EXP (CO_RETURN_EXPR);
726 : :
727 : 95119 : MARK_TS_EXP (ASSERTION_STMT);
728 : 95119 : MARK_TS_EXP (PRECONDITION_STMT);
729 : 95119 : MARK_TS_EXP (POSTCONDITION_STMT);
730 : :
731 : 95119 : c_common_init_ts ();
732 : 95119 : }
733 : :
734 : : /* Handle C++-specficic options here. Punt to c_common otherwise. */
735 : :
736 : : bool
737 : 1853632 : cp_handle_option (size_t scode, const char *arg, HOST_WIDE_INT value,
738 : : int kind, location_t loc,
739 : : const struct cl_option_handlers *handlers)
740 : : {
741 : 1853632 : if (handle_module_option (unsigned (scode), arg, value))
742 : : return true;
743 : :
744 : 1852705 : enum opt_code code = (enum opt_code) scode;
745 : 1852705 : bool handled_p = true;
746 : :
747 : 1852705 : switch (code)
748 : : {
749 : 4 : case OPT_fcontract_build_level_:
750 : 4 : handle_OPT_fcontract_build_level_ (arg);
751 : 4 : break;
752 : :
753 : 0 : case OPT_fcontract_assumption_mode_:
754 : 0 : handle_OPT_fcontract_assumption_mode_ (arg);
755 : 0 : break;
756 : :
757 : 57 : case OPT_fcontract_continuation_mode_:
758 : 57 : handle_OPT_fcontract_continuation_mode_ (arg);
759 : 57 : break;
760 : :
761 : 25 : case OPT_fcontract_role_:
762 : 25 : handle_OPT_fcontract_role_ (arg);
763 : 25 : break;
764 : :
765 : 3 : case OPT_fcontract_semantic_:
766 : 3 : handle_OPT_fcontract_semantic_ (arg);
767 : 3 : break;
768 : :
769 : : default:
770 : : handled_p = false;
771 : : break;
772 : : }
773 : 89 : if (handled_p)
774 : 89 : return handled_p;
775 : :
776 : 1852616 : return c_common_handle_option (scode, arg, value, kind, loc, handlers);
777 : : }
778 : :
779 : : #include "gt-cp-cp-objcp-common.h"
|