1 /* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
6 Copyright (C) 1998-2021 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GCC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GCC; see the file COPYING3. If not see
24 <http://www.gnu.org/licenses/>. */
28 #include "coretypes.h"
32 #include "stringpool.h"
36 #include "stor-layout.h"
37 #include "c-family/c-objc.h"
38 #include "tree-inline.h"
40 #include "tree-iterator.h"
41 #include "omp-general.h"
43 #include "stringpool.h"
45 #include "gomp-constants.h"
49 /* There routines provide a modular interface to perform many parsing
50 operations. They may therefore be used during actual parsing, or
51 during template instantiation, which may be regarded as a
52 degenerate form of parsing. */
54 static tree
maybe_convert_cond (tree
);
55 static tree
finalize_nrv_r (tree
*, int *, void *);
56 static tree
capture_decltype (tree
);
58 /* Used for OpenMP non-static data member privatization. */
60 static hash_map
<tree
, tree
> *omp_private_member_map
;
61 static vec
<tree
> omp_private_member_vec
;
62 static bool omp_private_member_ignore_next
;
65 /* Deferred Access Checking Overview
66 ---------------------------------
68 Most C++ expressions and declarations require access checking
69 to be performed during parsing. However, in several cases,
70 this has to be treated differently.
72 For member declarations, access checking has to be deferred
73 until more information about the declaration is known. For
85 When we are parsing the function return type `A::X', we don't
86 really know if this is allowed until we parse the function name.
88 Furthermore, some contexts require that access checking is
89 never performed at all. These include class heads, and template
92 Typical use of access checking functions is described here:
94 1. When we enter a context that requires certain access checking
95 mode, the function `push_deferring_access_checks' is called with
96 DEFERRING argument specifying the desired mode. Access checking
97 may be performed immediately (dk_no_deferred), deferred
98 (dk_deferred), or not performed (dk_no_check).
100 2. When a declaration such as a type, or a variable, is encountered,
101 the function `perform_or_defer_access_check' is called. It
102 maintains a vector of all deferred checks.
104 3. The global `current_class_type' or `current_function_decl' is then
105 setup by the parser. `enforce_access' relies on these information
108 4. Upon exiting the context mentioned in step 1,
109 `perform_deferred_access_checks' is called to check all declaration
110 stored in the vector. `pop_deferring_access_checks' is then
111 called to restore the previous access checking mode.
113 In case of parsing error, we simply call `pop_deferring_access_checks'
114 without `perform_deferred_access_checks'. */
116 struct GTY(()) deferred_access
{
117 /* A vector representing name-lookups for which we have deferred
118 checking access controls. We cannot check the accessibility of
119 names used in a decl-specifier-seq until we know what is being
120 declared because code like:
127 A::B* A::f() { return 0; }
129 is valid, even though `A::B' is not generally accessible. */
130 vec
<deferred_access_check
, va_gc
> *deferred_access_checks
;
132 /* The current mode of access checks. */
133 enum deferring_kind deferring_access_checks_kind
;
136 /* Data for deferred access checking. */
137 static GTY(()) vec
<deferred_access
, va_gc
> *deferred_access_stack
;
138 static GTY(()) unsigned deferred_access_no_check
;
140 /* Save the current deferred access states and start deferred
141 access checking iff DEFER_P is true. */
144 push_deferring_access_checks (deferring_kind deferring
)
146 /* For context like template instantiation, access checking
147 disabling applies to all nested context. */
148 if (deferred_access_no_check
|| deferring
== dk_no_check
)
149 deferred_access_no_check
++;
152 deferred_access e
= {NULL
, deferring
};
153 vec_safe_push (deferred_access_stack
, e
);
157 /* Save the current deferred access states and start deferred access
158 checking, continuing the set of deferred checks in CHECKS. */
161 reopen_deferring_access_checks (vec
<deferred_access_check
, va_gc
> * checks
)
163 push_deferring_access_checks (dk_deferred
);
164 if (!deferred_access_no_check
)
165 deferred_access_stack
->last().deferred_access_checks
= checks
;
168 /* Resume deferring access checks again after we stopped doing
172 resume_deferring_access_checks (void)
174 if (!deferred_access_no_check
)
175 deferred_access_stack
->last().deferring_access_checks_kind
= dk_deferred
;
178 /* Stop deferring access checks. */
181 stop_deferring_access_checks (void)
183 if (!deferred_access_no_check
)
184 deferred_access_stack
->last().deferring_access_checks_kind
= dk_no_deferred
;
187 /* Discard the current deferred access checks and restore the
191 pop_deferring_access_checks (void)
193 if (deferred_access_no_check
)
194 deferred_access_no_check
--;
196 deferred_access_stack
->pop ();
199 /* Returns a TREE_LIST representing the deferred checks.
200 The TREE_PURPOSE of each node is the type through which the
201 access occurred; the TREE_VALUE is the declaration named.
204 vec
<deferred_access_check
, va_gc
> *
205 get_deferred_access_checks (void)
207 if (deferred_access_no_check
)
210 return (deferred_access_stack
->last().deferred_access_checks
);
213 /* Take current deferred checks and combine with the
214 previous states if we also defer checks previously.
215 Otherwise perform checks now. */
218 pop_to_parent_deferring_access_checks (void)
220 if (deferred_access_no_check
)
221 deferred_access_no_check
--;
224 vec
<deferred_access_check
, va_gc
> *checks
;
225 deferred_access
*ptr
;
227 checks
= (deferred_access_stack
->last ().deferred_access_checks
);
229 deferred_access_stack
->pop ();
230 ptr
= &deferred_access_stack
->last ();
231 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
234 perform_access_checks (checks
, tf_warning_or_error
);
238 /* Merge with parent. */
240 deferred_access_check
*chk
, *probe
;
242 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
244 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, j
, probe
)
246 if (probe
->binfo
== chk
->binfo
&&
247 probe
->decl
== chk
->decl
&&
248 probe
->diag_decl
== chk
->diag_decl
)
251 /* Insert into parent's checks. */
252 vec_safe_push (ptr
->deferred_access_checks
, *chk
);
259 /* If the current scope isn't allowed to access DECL along
260 BASETYPE_PATH, give an error, or if we're parsing a function or class
261 template, defer the access check to be performed at instantiation time.
262 The most derived class in BASETYPE_PATH is the one used to qualify DECL.
263 DIAG_DECL is the declaration to use in the error diagnostic. */
266 enforce_access (tree basetype_path
, tree decl
, tree diag_decl
,
267 tsubst_flags_t complain
, access_failure_info
*afi
= NULL
)
269 gcc_assert (TREE_CODE (basetype_path
) == TREE_BINFO
);
271 if (flag_new_inheriting_ctors
272 && DECL_INHERITED_CTOR (decl
))
274 /* 7.3.3/18: The additional constructors are accessible if they would be
275 accessible when used to construct an object of the corresponding base
277 decl
= strip_inheriting_ctors (decl
);
278 basetype_path
= lookup_base (basetype_path
, DECL_CONTEXT (decl
),
279 ba_any
, NULL
, complain
);
282 tree cs
= current_scope ();
283 if (processing_template_decl
284 && (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
))
285 if (tree template_info
= get_template_info (cs
))
287 /* When parsing a function or class template, we in general need to
288 defer access checks until template instantiation time, since a friend
289 declaration may grant access only to a particular specialization of
292 if (accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
293 /* But if the member is deemed accessible at parse time, then we can
294 assume it'll be accessible at instantiation time. */
297 /* Access of a dependent decl should be rechecked after tsubst'ing
298 into the user of the decl, rather than explicitly deferring the
300 gcc_assert (!uses_template_parms (decl
));
301 if (TREE_CODE (decl
) == FIELD_DECL
)
302 gcc_assert (!uses_template_parms (DECL_CONTEXT (decl
)));
304 /* Defer this access check until instantiation time. */
305 deferred_access_check access_check
;
306 access_check
.binfo
= basetype_path
;
307 access_check
.decl
= decl
;
308 access_check
.diag_decl
= diag_decl
;
309 access_check
.loc
= input_location
;
310 vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info
), access_check
);
314 if (!accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
316 if (flag_new_inheriting_ctors
)
317 diag_decl
= strip_inheriting_ctors (diag_decl
);
318 if (complain
& tf_error
)
320 /* We will usually want to point to the same place as
321 diag_decl but not always. */
322 tree diag_location
= diag_decl
;
323 access_kind parent_access
= ak_none
;
325 /* See if any of BASETYPE_PATH's parents had private access
326 to DECL. If they did, that will tell us why we don't. */
327 tree parent_binfo
= get_parent_with_private_access (decl
,
330 /* If a parent had private access, then the diagnostic
331 location DECL should be that of the parent class, since it
332 failed to give suitable access by using a private
333 inheritance. But if DECL was actually defined in the parent,
334 it wasn't privately inherited, and so we don't need to do
335 this, and complain_about_access will figure out what to
337 if (parent_binfo
!= NULL_TREE
338 && (context_for_name_lookup (decl
)
339 != BINFO_TYPE (parent_binfo
)))
341 diag_location
= TYPE_NAME (BINFO_TYPE (parent_binfo
));
342 parent_access
= ak_private
;
345 /* Finally, generate an error message. */
346 complain_about_access (decl
, diag_decl
, diag_location
, true,
350 afi
->record_access_failure (basetype_path
, decl
, diag_decl
);
357 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
358 is the BINFO indicating the qualifying scope used to access the
359 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
360 or we aren't in SFINAE context or all the checks succeed return TRUE,
364 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
365 tsubst_flags_t complain
)
368 deferred_access_check
*chk
;
369 location_t loc
= input_location
;
375 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
377 input_location
= chk
->loc
;
378 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
381 input_location
= loc
;
382 return (complain
& tf_error
) ? true : ok
;
385 /* Perform the deferred access checks.
387 After performing the checks, we still have to keep the list
388 `deferred_access_stack->deferred_access_checks' since we may want
389 to check access for them again later in a different context.
396 A::X A::a, x; // No error for `A::a', error for `x'
398 We have to perform deferred access of `A::X', first with `A::a',
399 next with `x'. Return value like perform_access_checks above. */
402 perform_deferred_access_checks (tsubst_flags_t complain
)
404 return perform_access_checks (get_deferred_access_checks (), complain
);
407 /* Defer checking the accessibility of DECL, when looked up in
408 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
409 Return value like perform_access_checks above.
410 If non-NULL, report failures to AFI. */
413 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
414 tsubst_flags_t complain
,
415 access_failure_info
*afi
)
418 deferred_access
*ptr
;
419 deferred_access_check
*chk
;
421 /* Exit if we are in a context that no access checking is performed. */
422 if (deferred_access_no_check
)
425 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
427 ptr
= &deferred_access_stack
->last ();
429 /* If we are not supposed to defer access checks, just check now. */
430 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
432 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
, afi
);
433 return (complain
& tf_error
) ? true : ok
;
436 /* See if we are already going to perform this check. */
437 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
439 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
440 chk
->diag_decl
== diag_decl
)
445 /* If not, record the check. */
446 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
447 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
452 /* Returns nonzero if the current statement is a full expression,
453 i.e. temporaries created during that statement should be destroyed
454 at the end of the statement. */
457 stmts_are_full_exprs_p (void)
459 return current_stmt_tree ()->stmts_are_full_exprs_p
;
462 /* T is a statement. Add it to the statement-tree. This is the C++
463 version. The C/ObjC frontends have a slightly different version of
469 enum tree_code code
= TREE_CODE (t
);
471 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
473 if (!EXPR_HAS_LOCATION (t
))
474 SET_EXPR_LOCATION (t
, input_location
);
476 /* When we expand a statement-tree, we must know whether or not the
477 statements are full-expressions. We record that fact here. */
478 if (STATEMENT_CODE_P (TREE_CODE (t
)))
479 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
482 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
483 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
485 /* Add T to the statement-tree. Non-side-effect statements need to be
486 recorded during statement expressions. */
487 gcc_checking_assert (!stmt_list_stack
->is_empty ());
488 append_to_statement_list_force (t
, &cur_stmt_list
);
493 /* Returns the stmt_tree to which statements are currently being added. */
496 current_stmt_tree (void)
499 ? &cfun
->language
->base
.x_stmt_tree
500 : &scope_chain
->x_stmt_tree
);
503 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
506 maybe_cleanup_point_expr (tree expr
)
508 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
509 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
513 /* Like maybe_cleanup_point_expr except have the type of the new expression be
514 void so we don't need to create a temporary variable to hold the inner
515 expression. The reason why we do this is because the original type might be
516 an aggregate and we cannot create a temporary variable for that type. */
519 maybe_cleanup_point_expr_void (tree expr
)
521 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
522 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
528 /* Create a declaration statement for the declaration given by the DECL. */
531 add_decl_expr (tree decl
)
533 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
534 if (DECL_INITIAL (decl
)
535 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
536 r
= maybe_cleanup_point_expr_void (r
);
540 /* Finish a scope. */
543 do_poplevel (tree stmt_list
)
547 if (stmts_are_full_exprs_p ())
548 block
= poplevel (kept_level_p (), 1, 0);
550 stmt_list
= pop_stmt_list (stmt_list
);
552 if (!processing_template_decl
)
554 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
555 /* ??? See c_end_compound_stmt re statement expressions. */
561 /* Begin a new scope. */
564 do_pushlevel (scope_kind sk
)
566 tree ret
= push_stmt_list ();
567 if (stmts_are_full_exprs_p ())
568 begin_scope (sk
, NULL
);
572 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
573 when the current scope is exited. EH_ONLY is true when this is not
574 meant to apply to normal control flow transfer. */
577 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
579 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
580 CLEANUP_EH_ONLY (stmt
) = eh_only
;
582 CLEANUP_BODY (stmt
) = push_stmt_list ();
585 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
586 the current loops, represented by 'NULL_TREE' if we've seen a possible
587 exit, and 'error_mark_node' if not. This is currently used only to
588 suppress the warning about a function with no return statements, and
589 therefore we don't bother noting returns as possible exits. We also
590 don't bother with gotos. */
593 begin_maybe_infinite_loop (tree cond
)
595 /* Only track this while parsing a function, not during instantiation. */
596 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
597 && !processing_template_decl
))
599 bool maybe_infinite
= true;
602 cond
= fold_non_dependent_expr (cond
);
603 maybe_infinite
= integer_nonzerop (cond
);
605 vec_safe_push (cp_function_chain
->infinite_loops
,
606 maybe_infinite
? error_mark_node
: NULL_TREE
);
610 /* A break is a possible exit for the current loop. */
613 break_maybe_infinite_loop (void)
617 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
620 /* If we reach the end of the loop without seeing a possible exit, we have
624 end_maybe_infinite_loop (tree cond
)
626 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
627 && !processing_template_decl
))
629 tree current
= cp_function_chain
->infinite_loops
->pop();
630 if (current
!= NULL_TREE
)
632 cond
= fold_non_dependent_expr (cond
);
633 if (integer_nonzerop (cond
))
634 current_function_infinite_loop
= 1;
639 /* Begin a conditional that might contain a declaration. When generating
640 normal code, we want the declaration to appear before the statement
641 containing the conditional. When generating template code, we want the
642 conditional to be rendered as the raw DECL_EXPR. */
645 begin_cond (tree
*cond_p
)
647 if (processing_template_decl
)
648 *cond_p
= push_stmt_list ();
651 /* Finish such a conditional. */
654 finish_cond (tree
*cond_p
, tree expr
)
656 if (processing_template_decl
)
658 tree cond
= pop_stmt_list (*cond_p
);
660 if (expr
== NULL_TREE
)
661 /* Empty condition in 'for'. */
662 gcc_assert (empty_expr_stmt_p (cond
));
663 else if (check_for_bare_parameter_packs (expr
))
664 expr
= error_mark_node
;
665 else if (!empty_expr_stmt_p (cond
))
666 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
671 /* If *COND_P specifies a conditional with a declaration, transform the
674 for (; A x = 42;) { }
676 while (true) { A x = 42; if (!x) break; }
677 for (;;) { A x = 42; if (!x) break; }
678 The statement list for BODY will be empty if the conditional did
679 not declare anything. */
682 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
686 if (!TREE_SIDE_EFFECTS (body
))
690 *cond_p
= boolean_true_node
;
692 if_stmt
= begin_if_stmt ();
693 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, false, tf_warning_or_error
);
694 finish_if_stmt_cond (cond
, if_stmt
);
695 finish_break_stmt ();
696 finish_then_clause (if_stmt
);
697 finish_if_stmt (if_stmt
);
700 /* Finish a goto-statement. */
703 finish_goto_stmt (tree destination
)
705 if (identifier_p (destination
))
706 destination
= lookup_label (destination
);
708 /* We warn about unused labels with -Wunused. That means we have to
709 mark the used labels as used. */
710 if (TREE_CODE (destination
) == LABEL_DECL
)
711 TREE_USED (destination
) = 1;
714 destination
= mark_rvalue_use (destination
);
715 if (!processing_template_decl
)
717 destination
= cp_convert (ptr_type_node
, destination
,
718 tf_warning_or_error
);
719 if (error_operand_p (destination
))
722 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
727 check_goto (destination
);
729 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
730 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
733 /* COND is the condition-expression for an if, while, etc.,
734 statement. Convert it to a boolean value, if appropriate.
735 In addition, verify sequence points if -Wsequence-point is enabled. */
738 maybe_convert_cond (tree cond
)
740 /* Empty conditions remain empty. */
744 /* Wait until we instantiate templates before doing conversion. */
745 if (type_dependent_expression_p (cond
))
748 if (warn_sequence_point
&& !processing_template_decl
)
749 verify_sequence_points (cond
);
751 /* Do the conversion. */
752 cond
= convert_from_reference (cond
);
754 if (TREE_CODE (cond
) == MODIFY_EXPR
755 && !TREE_NO_WARNING (cond
)
757 && warning_at (cp_expr_loc_or_input_loc (cond
),
758 OPT_Wparentheses
, "suggest parentheses around "
759 "assignment used as truth value"))
760 TREE_NO_WARNING (cond
) = 1;
762 return condition_conversion (cond
);
765 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
768 finish_expr_stmt (tree expr
)
771 location_t loc
= EXPR_LOCATION (expr
);
773 if (expr
!= NULL_TREE
)
775 /* If we ran into a problem, make sure we complained. */
776 gcc_assert (expr
!= error_mark_node
|| seen_error ());
778 if (!processing_template_decl
)
780 if (warn_sequence_point
)
781 verify_sequence_points (expr
);
782 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
784 else if (!type_dependent_expression_p (expr
))
785 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
786 tf_warning_or_error
);
788 if (check_for_bare_parameter_packs (expr
))
789 expr
= error_mark_node
;
791 /* Simplification of inner statement expressions, compound exprs,
792 etc can result in us already having an EXPR_STMT. */
793 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
795 if (TREE_CODE (expr
) != EXPR_STMT
)
796 expr
= build_stmt (loc
, EXPR_STMT
, expr
);
797 expr
= maybe_cleanup_point_expr_void (expr
);
807 /* Begin an if-statement. Returns a newly created IF_STMT if
814 scope
= do_pushlevel (sk_cond
);
815 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
816 NULL_TREE
, NULL_TREE
, scope
);
817 current_binding_level
->this_entity
= r
;
818 begin_cond (&IF_COND (r
));
822 /* Returns true if FN, a CALL_EXPR, is a call to
823 std::is_constant_evaluated or __builtin_is_constant_evaluated. */
826 is_std_constant_evaluated_p (tree fn
)
828 /* std::is_constant_evaluated takes no arguments. */
829 if (call_expr_nargs (fn
) != 0)
832 tree fndecl
= cp_get_callee_fndecl_nofold (fn
);
833 if (fndecl
== NULL_TREE
)
836 if (fndecl_built_in_p (fndecl
, CP_BUILT_IN_IS_CONSTANT_EVALUATED
,
840 if (!decl_in_std_namespace_p (fndecl
))
843 tree name
= DECL_NAME (fndecl
);
844 return name
&& id_equal (name
, "is_constant_evaluated");
847 /* Process the COND of an if-statement, which may be given by
851 finish_if_stmt_cond (tree cond
, tree if_stmt
)
853 cond
= maybe_convert_cond (cond
);
854 if (IF_STMT_CONSTEXPR_P (if_stmt
)
855 && !type_dependent_expression_p (cond
)
856 && require_constant_expression (cond
)
857 && !instantiation_dependent_expression_p (cond
)
858 /* Wait until instantiation time, since only then COND has been
859 converted to bool. */
860 && TYPE_MAIN_VARIANT (TREE_TYPE (cond
)) == boolean_type_node
)
862 /* if constexpr (std::is_constant_evaluated()) is always true,
863 so give the user a clue. */
864 if (warn_tautological_compare
)
867 if (TREE_CODE (t
) == CLEANUP_POINT_EXPR
)
868 t
= TREE_OPERAND (t
, 0);
869 if (TREE_CODE (t
) == CALL_EXPR
870 && is_std_constant_evaluated_p (t
))
871 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
872 "%qs always evaluates to true in %<if constexpr%>",
873 "std::is_constant_evaluated");
876 cond
= instantiate_non_dependent_expr (cond
);
877 cond
= cxx_constant_value (cond
, NULL_TREE
);
879 finish_cond (&IF_COND (if_stmt
), cond
);
881 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
885 /* Finish the then-clause of an if-statement, which may be given by
889 finish_then_clause (tree if_stmt
)
891 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
895 /* Begin the else-clause of an if-statement. */
898 begin_else_clause (tree if_stmt
)
900 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
903 /* Finish the else-clause of an if-statement, which may be given by
907 finish_else_clause (tree if_stmt
)
909 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
912 /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
916 maybe_mark_exp_read_r (tree
*tp
, int *, void *)
919 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
924 /* Finish an if-statement. */
927 finish_if_stmt (tree if_stmt
)
929 tree scope
= IF_SCOPE (if_stmt
);
930 IF_SCOPE (if_stmt
) = NULL
;
931 if (IF_STMT_CONSTEXPR_P (if_stmt
))
933 /* Prevent various -Wunused warnings. We might not instantiate
934 either of these branches, so we would not mark the variables
935 used in that branch as read. */
936 cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt
),
937 maybe_mark_exp_read_r
, NULL
);
938 cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt
),
939 maybe_mark_exp_read_r
, NULL
);
941 add_stmt (do_poplevel (scope
));
944 /* Begin a while-statement. Returns a newly created WHILE_STMT if
948 begin_while_stmt (void)
951 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
953 WHILE_BODY (r
) = do_pushlevel (sk_block
);
954 begin_cond (&WHILE_COND (r
));
958 /* Process the COND of a while-statement, which may be given by
962 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
,
963 unsigned short unroll
)
965 cond
= maybe_convert_cond (cond
);
966 finish_cond (&WHILE_COND (while_stmt
), cond
);
967 begin_maybe_infinite_loop (cond
);
968 if (ivdep
&& cond
!= error_mark_node
)
969 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
970 TREE_TYPE (WHILE_COND (while_stmt
)),
971 WHILE_COND (while_stmt
),
972 build_int_cst (integer_type_node
,
973 annot_expr_ivdep_kind
),
975 if (unroll
&& cond
!= error_mark_node
)
976 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
977 TREE_TYPE (WHILE_COND (while_stmt
)),
978 WHILE_COND (while_stmt
),
979 build_int_cst (integer_type_node
,
980 annot_expr_unroll_kind
),
981 build_int_cst (integer_type_node
,
983 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
986 /* Finish a while-statement, which may be given by WHILE_STMT. */
989 finish_while_stmt (tree while_stmt
)
991 end_maybe_infinite_loop (boolean_true_node
);
992 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
995 /* Begin a do-statement. Returns a newly created DO_STMT if
1001 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
1002 begin_maybe_infinite_loop (boolean_true_node
);
1004 DO_BODY (r
) = push_stmt_list ();
1008 /* Finish the body of a do-statement, which may be given by DO_STMT. */
1011 finish_do_body (tree do_stmt
)
1013 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
1015 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
1016 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
1018 if (IS_EMPTY_STMT (body
))
1019 warning (OPT_Wempty_body
,
1020 "suggest explicit braces around empty body in %<do%> statement");
1023 /* Finish a do-statement, which may be given by DO_STMT, and whose
1024 COND is as indicated. */
1027 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
, unsigned short unroll
)
1029 cond
= maybe_convert_cond (cond
);
1030 end_maybe_infinite_loop (cond
);
1031 if (ivdep
&& cond
!= error_mark_node
)
1032 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1033 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
),
1035 if (unroll
&& cond
!= error_mark_node
)
1036 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1037 build_int_cst (integer_type_node
, annot_expr_unroll_kind
),
1038 build_int_cst (integer_type_node
, unroll
));
1039 DO_COND (do_stmt
) = cond
;
1042 /* Finish a return-statement. The EXPRESSION returned, if any, is as
1046 finish_return_stmt (tree expr
)
1051 expr
= check_return_expr (expr
, &no_warning
);
1053 if (error_operand_p (expr
)
1054 || (flag_openmp
&& !check_omp_return ()))
1056 /* Suppress -Wreturn-type for this function. */
1057 if (warn_return_type
)
1058 TREE_NO_WARNING (current_function_decl
) = true;
1059 return error_mark_node
;
1062 if (!processing_template_decl
)
1064 if (warn_sequence_point
)
1065 verify_sequence_points (expr
);
1067 if (DECL_DESTRUCTOR_P (current_function_decl
)
1068 || (DECL_CONSTRUCTOR_P (current_function_decl
)
1069 && targetm
.cxx
.cdtor_returns_this ()))
1071 /* Similarly, all destructors must run destructors for
1072 base-classes before returning. So, all returns in a
1073 destructor get sent to the DTOR_LABEL; finish_function emits
1074 code to return a value there. */
1075 return finish_goto_stmt (cdtor_label
);
1079 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
1080 TREE_NO_WARNING (r
) |= no_warning
;
1081 r
= maybe_cleanup_point_expr_void (r
);
1087 /* Begin the scope of a for-statement or a range-for-statement.
1088 Both the returned trees are to be used in a call to
1089 begin_for_stmt or begin_range_for_stmt. */
1092 begin_for_scope (tree
*init
)
1094 tree scope
= do_pushlevel (sk_for
);
1096 if (processing_template_decl
)
1097 *init
= push_stmt_list ();
1104 /* Begin a for-statement. Returns a new FOR_STMT.
1105 SCOPE and INIT should be the return of begin_for_scope,
1106 or both NULL_TREE */
1109 begin_for_stmt (tree scope
, tree init
)
1113 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
1114 NULL_TREE
, NULL_TREE
, NULL_TREE
);
1116 if (scope
== NULL_TREE
)
1119 scope
= begin_for_scope (&init
);
1122 FOR_INIT_STMT (r
) = init
;
1123 FOR_SCOPE (r
) = scope
;
1128 /* Finish the init-statement of a for-statement, which may be
1129 given by FOR_STMT. */
1132 finish_init_stmt (tree for_stmt
)
1134 if (processing_template_decl
)
1135 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
1136 add_stmt (for_stmt
);
1137 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
1138 begin_cond (&FOR_COND (for_stmt
));
1141 /* Finish the COND of a for-statement, which may be given by
1145 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
, unsigned short unroll
)
1147 cond
= maybe_convert_cond (cond
);
1148 finish_cond (&FOR_COND (for_stmt
), cond
);
1149 begin_maybe_infinite_loop (cond
);
1150 if (ivdep
&& cond
!= error_mark_node
)
1151 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1152 TREE_TYPE (FOR_COND (for_stmt
)),
1153 FOR_COND (for_stmt
),
1154 build_int_cst (integer_type_node
,
1155 annot_expr_ivdep_kind
),
1157 if (unroll
&& cond
!= error_mark_node
)
1158 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1159 TREE_TYPE (FOR_COND (for_stmt
)),
1160 FOR_COND (for_stmt
),
1161 build_int_cst (integer_type_node
,
1162 annot_expr_unroll_kind
),
1163 build_int_cst (integer_type_node
,
1165 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
1168 /* Finish the increment-EXPRESSION in a for-statement, which may be
1169 given by FOR_STMT. */
1172 finish_for_expr (tree expr
, tree for_stmt
)
1176 /* If EXPR is an overloaded function, issue an error; there is no
1177 context available to use to perform overload resolution. */
1178 if (type_unknown_p (expr
))
1180 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1181 expr
= error_mark_node
;
1183 if (!processing_template_decl
)
1185 if (warn_sequence_point
)
1186 verify_sequence_points (expr
);
1187 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1188 tf_warning_or_error
);
1190 else if (!type_dependent_expression_p (expr
))
1191 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1192 tf_warning_or_error
);
1193 expr
= maybe_cleanup_point_expr_void (expr
);
1194 if (check_for_bare_parameter_packs (expr
))
1195 expr
= error_mark_node
;
1196 FOR_EXPR (for_stmt
) = expr
;
1199 /* Finish the body of a for-statement, which may be given by
1200 FOR_STMT. The increment-EXPR for the loop must be
1202 It can also finish RANGE_FOR_STMT. */
1205 finish_for_stmt (tree for_stmt
)
1207 end_maybe_infinite_loop (boolean_true_node
);
1209 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1210 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1212 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1214 /* Pop the scope for the body of the loop. */
1215 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1216 ? &RANGE_FOR_SCOPE (for_stmt
)
1217 : &FOR_SCOPE (for_stmt
));
1218 tree scope
= *scope_ptr
;
1221 /* During parsing of the body, range for uses "__for_{range,begin,end} "
1222 decl names to make those unaccessible by code in the body.
1223 Change it to ones with underscore instead of space, so that it can
1224 be inspected in the debugger. */
1225 tree range_for_decl
[3] = { NULL_TREE
, NULL_TREE
, NULL_TREE
};
1226 gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 1
1227 && CPTI_FOR_END__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 2
1228 && CPTI_FOR_RANGE_IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 3
1229 && CPTI_FOR_BEGIN_IDENTIFIER
== CPTI_FOR_BEGIN__IDENTIFIER
+ 3
1230 && CPTI_FOR_END_IDENTIFIER
== CPTI_FOR_END__IDENTIFIER
+ 3);
1231 for (int i
= 0; i
< 3; i
++)
1233 tree id
= cp_global_trees
[CPTI_FOR_RANGE__IDENTIFIER
+ i
];
1234 if (IDENTIFIER_BINDING (id
)
1235 && IDENTIFIER_BINDING (id
)->scope
== current_binding_level
)
1237 range_for_decl
[i
] = IDENTIFIER_BINDING (id
)->value
;
1238 gcc_assert (VAR_P (range_for_decl
[i
])
1239 && DECL_ARTIFICIAL (range_for_decl
[i
]));
1243 add_stmt (do_poplevel (scope
));
1245 for (int i
= 0; i
< 3; i
++)
1246 if (range_for_decl
[i
])
1247 DECL_NAME (range_for_decl
[i
])
1248 = cp_global_trees
[CPTI_FOR_RANGE_IDENTIFIER
+ i
];
1251 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1252 SCOPE and INIT should be the return of begin_for_scope,
1254 To finish it call finish_for_stmt(). */
1257 begin_range_for_stmt (tree scope
, tree init
)
1259 begin_maybe_infinite_loop (boolean_false_node
);
1261 tree r
= build_stmt (input_location
, RANGE_FOR_STMT
, NULL_TREE
, NULL_TREE
,
1262 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1264 if (scope
== NULL_TREE
)
1267 scope
= begin_for_scope (&init
);
1270 /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1271 RANGE_FOR_INIT_STMT (r
) = init
;
1272 RANGE_FOR_SCOPE (r
) = scope
;
1277 /* Finish the head of a range-based for statement, which may
1278 be given by RANGE_FOR_STMT. DECL must be the declaration
1279 and EXPR must be the loop expression. */
1282 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1284 if (processing_template_decl
)
1285 RANGE_FOR_INIT_STMT (range_for_stmt
)
1286 = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt
));
1287 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1288 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1289 add_stmt (range_for_stmt
);
1290 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1293 /* Finish a break-statement. */
1296 finish_break_stmt (void)
1298 /* In switch statements break is sometimes stylistically used after
1299 a return statement. This can lead to spurious warnings about
1300 control reaching the end of a non-void function when it is
1301 inlined. Note that we are calling block_may_fallthru with
1302 language specific tree nodes; this works because
1303 block_may_fallthru returns true when given something it does not
1305 if (!block_may_fallthru (cur_stmt_list
))
1308 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1311 /* Finish a continue-statement. */
1314 finish_continue_stmt (void)
1316 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1319 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1323 begin_switch_stmt (void)
1327 scope
= do_pushlevel (sk_cond
);
1328 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1330 begin_cond (&SWITCH_STMT_COND (r
));
1335 /* Finish the cond of a switch-statement. */
1338 finish_switch_cond (tree cond
, tree switch_stmt
)
1340 tree orig_type
= NULL
;
1342 if (!processing_template_decl
)
1344 /* Convert the condition to an integer or enumeration type. */
1345 tree orig_cond
= cond
;
1346 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1347 if (cond
== NULL_TREE
)
1349 error_at (cp_expr_loc_or_input_loc (orig_cond
),
1350 "switch quantity not an integer");
1351 cond
= error_mark_node
;
1353 /* We want unlowered type here to handle enum bit-fields. */
1354 orig_type
= unlowered_expr_type (cond
);
1355 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1356 orig_type
= TREE_TYPE (cond
);
1357 if (cond
!= error_mark_node
)
1361 Integral promotions are performed. */
1362 cond
= perform_integral_promotions (cond
);
1363 cond
= maybe_cleanup_point_expr (cond
);
1366 if (check_for_bare_parameter_packs (cond
))
1367 cond
= error_mark_node
;
1368 else if (!processing_template_decl
&& warn_sequence_point
)
1369 verify_sequence_points (cond
);
1371 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1372 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1373 add_stmt (switch_stmt
);
1374 push_switch (switch_stmt
);
1375 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1378 /* Finish the body of a switch-statement, which may be given by
1379 SWITCH_STMT. The COND to switch on is indicated. */
1382 finish_switch_stmt (tree switch_stmt
)
1386 SWITCH_STMT_BODY (switch_stmt
) =
1387 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1390 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1391 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1392 add_stmt (do_poplevel (scope
));
1395 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1399 begin_try_block (void)
1401 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1403 TRY_STMTS (r
) = push_stmt_list ();
1407 /* Likewise, for a function-try-block. The block returned in
1408 *COMPOUND_STMT is an artificial outer scope, containing the
1409 function-try-block. */
1412 begin_function_try_block (tree
*compound_stmt
)
1415 /* This outer scope does not exist in the C++ standard, but we need
1416 a place to put __FUNCTION__ and similar variables. */
1417 *compound_stmt
= begin_compound_stmt (0);
1418 r
= begin_try_block ();
1419 FN_TRY_BLOCK_P (r
) = 1;
1423 /* Finish a try-block, which may be given by TRY_BLOCK. */
1426 finish_try_block (tree try_block
)
1428 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1429 TRY_HANDLERS (try_block
) = push_stmt_list ();
1432 /* Finish the body of a cleanup try-block, which may be given by
1436 finish_cleanup_try_block (tree try_block
)
1438 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1441 /* Finish an implicitly generated try-block, with a cleanup is given
1445 finish_cleanup (tree cleanup
, tree try_block
)
1447 TRY_HANDLERS (try_block
) = cleanup
;
1448 CLEANUP_P (try_block
) = 1;
1451 /* Likewise, for a function-try-block. */
1454 finish_function_try_block (tree try_block
)
1456 finish_try_block (try_block
);
1457 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1458 the try block, but moving it inside. */
1459 in_function_try_handler
= 1;
1462 /* Finish a handler-sequence for a try-block, which may be given by
1466 finish_handler_sequence (tree try_block
)
1468 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1469 check_handlers (TRY_HANDLERS (try_block
));
1472 /* Finish the handler-seq for a function-try-block, given by
1473 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1474 begin_function_try_block. */
1477 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1479 in_function_try_handler
= 0;
1480 finish_handler_sequence (try_block
);
1481 finish_compound_stmt (compound_stmt
);
1484 /* Begin a handler. Returns a HANDLER if appropriate. */
1487 begin_handler (void)
1491 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1494 /* Create a binding level for the eh_info and the exception object
1496 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1501 /* Finish the handler-parameters for a handler, which may be given by
1502 HANDLER. DECL is the declaration for the catch parameter, or NULL
1503 if this is a `catch (...)' clause. */
1506 finish_handler_parms (tree decl
, tree handler
)
1508 tree type
= NULL_TREE
;
1509 if (processing_template_decl
)
1513 decl
= pushdecl (decl
);
1514 decl
= push_template_decl (decl
);
1515 HANDLER_PARMS (handler
) = decl
;
1516 type
= TREE_TYPE (decl
);
1521 type
= expand_start_catch_block (decl
);
1522 if (warn_catch_value
1523 && type
!= NULL_TREE
1524 && type
!= error_mark_node
1525 && !TYPE_REF_P (TREE_TYPE (decl
)))
1527 tree orig_type
= TREE_TYPE (decl
);
1528 if (CLASS_TYPE_P (orig_type
))
1530 if (TYPE_POLYMORPHIC_P (orig_type
))
1531 warning_at (DECL_SOURCE_LOCATION (decl
),
1533 "catching polymorphic type %q#T by value",
1535 else if (warn_catch_value
> 1)
1536 warning_at (DECL_SOURCE_LOCATION (decl
),
1538 "catching type %q#T by value", orig_type
);
1540 else if (warn_catch_value
> 2)
1541 warning_at (DECL_SOURCE_LOCATION (decl
),
1543 "catching non-reference type %q#T", orig_type
);
1546 HANDLER_TYPE (handler
) = type
;
1549 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1550 the return value from the matching call to finish_handler_parms. */
1553 finish_handler (tree handler
)
1555 if (!processing_template_decl
)
1556 expand_end_catch_block ();
1557 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1560 /* Begin a compound statement. FLAGS contains some bits that control the
1561 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1562 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1563 block of a function. If BCS_TRY_BLOCK is set, this is the block
1564 created on behalf of a TRY statement. Returns a token to be passed to
1565 finish_compound_stmt. */
1568 begin_compound_stmt (unsigned int flags
)
1572 if (flags
& BCS_NO_SCOPE
)
1574 r
= push_stmt_list ();
1575 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1577 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1578 But, if it's a statement-expression with a scopeless block, there's
1579 nothing to keep, and we don't want to accidentally keep a block
1580 *inside* the scopeless block. */
1581 keep_next_level (false);
1585 scope_kind sk
= sk_block
;
1586 if (flags
& BCS_TRY_BLOCK
)
1588 else if (flags
& BCS_TRANSACTION
)
1589 sk
= sk_transaction
;
1590 r
= do_pushlevel (sk
);
1593 /* When processing a template, we need to remember where the braces were,
1594 so that we can set up identical scopes when instantiating the template
1595 later. BIND_EXPR is a handy candidate for this.
1596 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1597 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1598 processing templates. */
1599 if (processing_template_decl
)
1601 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1602 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1603 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1604 TREE_SIDE_EFFECTS (r
) = 1;
1610 /* Finish a compound-statement, which is given by STMT. */
1613 finish_compound_stmt (tree stmt
)
1615 if (TREE_CODE (stmt
) == BIND_EXPR
)
1617 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1618 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1619 discard the BIND_EXPR so it can be merged with the containing
1621 if (TREE_CODE (body
) == STATEMENT_LIST
1622 && STATEMENT_LIST_HEAD (body
) == NULL
1623 && !BIND_EXPR_BODY_BLOCK (stmt
)
1624 && !BIND_EXPR_TRY_BLOCK (stmt
))
1627 BIND_EXPR_BODY (stmt
) = body
;
1629 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1630 stmt
= pop_stmt_list (stmt
);
1633 /* Destroy any ObjC "super" receivers that may have been
1635 objc_clear_super_receiver ();
1637 stmt
= do_poplevel (stmt
);
1640 /* ??? See c_end_compound_stmt wrt statement expressions. */
1644 /* Finish an asm-statement, whose components are a STRING, some
1645 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1646 LABELS. Also note whether the asm-statement should be
1647 considered volatile, and whether it is asm inline. */
1650 finish_asm_stmt (location_t loc
, int volatile_p
, tree string
,
1651 tree output_operands
, tree input_operands
, tree clobbers
,
1652 tree labels
, bool inline_p
)
1656 int ninputs
= list_length (input_operands
);
1657 int noutputs
= list_length (output_operands
);
1659 if (!processing_template_decl
)
1661 const char *constraint
;
1662 const char **oconstraints
;
1663 bool allows_mem
, allows_reg
, is_inout
;
1667 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1669 string
= resolve_asm_operand_names (string
, output_operands
,
1670 input_operands
, labels
);
1672 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1674 operand
= TREE_VALUE (t
);
1676 /* ??? Really, this should not be here. Users should be using a
1677 proper lvalue, dammit. But there's a long history of using
1678 casts in the output operands. In cases like longlong.h, this
1679 becomes a primitive form of typechecking -- if the cast can be
1680 removed, then the output operand had a type of the proper width;
1681 otherwise we'll get an error. Gross, but ... */
1682 STRIP_NOPS (operand
);
1684 operand
= mark_lvalue_use (operand
);
1686 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1687 operand
= error_mark_node
;
1689 if (operand
!= error_mark_node
1690 && (TREE_READONLY (operand
)
1691 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1692 /* Functions are not modifiable, even though they are
1694 || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand
))
1695 /* If it's an aggregate and any field is const, then it is
1696 effectively const. */
1697 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1698 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1699 cxx_readonly_error (loc
, operand
, lv_asm
);
1701 tree
*op
= &operand
;
1702 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1703 op
= &TREE_OPERAND (*op
, 1);
1704 switch (TREE_CODE (*op
))
1706 case PREINCREMENT_EXPR
:
1707 case PREDECREMENT_EXPR
:
1709 *op
= genericize_compound_lvalue (*op
);
1710 op
= &TREE_OPERAND (*op
, 1);
1716 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1717 oconstraints
[i
] = constraint
;
1719 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1720 &allows_mem
, &allows_reg
, &is_inout
))
1722 /* If the operand is going to end up in memory,
1723 mark it addressable. */
1724 if (!allows_reg
&& !cxx_mark_addressable (*op
))
1725 operand
= error_mark_node
;
1728 operand
= error_mark_node
;
1730 TREE_VALUE (t
) = operand
;
1733 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1735 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1736 bool constraint_parsed
1737 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1738 oconstraints
, &allows_mem
, &allows_reg
);
1739 /* If the operand is going to end up in memory, don't call
1740 decay_conversion. */
1741 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1742 operand
= mark_lvalue_use (TREE_VALUE (t
));
1744 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1746 /* If the type of the operand hasn't been determined (e.g.,
1747 because it involves an overloaded function), then issue
1748 an error message. There's no context available to
1749 resolve the overloading. */
1750 if (TREE_TYPE (operand
) == unknown_type_node
)
1753 "type of %<asm%> operand %qE could not be determined",
1755 operand
= error_mark_node
;
1758 if (constraint_parsed
)
1760 /* If the operand is going to end up in memory,
1761 mark it addressable. */
1762 if (!allows_reg
&& allows_mem
)
1764 /* Strip the nops as we allow this case. FIXME, this really
1765 should be rejected or made deprecated. */
1766 STRIP_NOPS (operand
);
1768 tree
*op
= &operand
;
1769 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1770 op
= &TREE_OPERAND (*op
, 1);
1771 switch (TREE_CODE (*op
))
1773 case PREINCREMENT_EXPR
:
1774 case PREDECREMENT_EXPR
:
1776 *op
= genericize_compound_lvalue (*op
);
1777 op
= &TREE_OPERAND (*op
, 1);
1783 if (!cxx_mark_addressable (*op
))
1784 operand
= error_mark_node
;
1786 else if (!allows_reg
&& !allows_mem
)
1788 /* If constraint allows neither register nor memory,
1789 try harder to get a constant. */
1790 tree constop
= maybe_constant_value (operand
);
1791 if (TREE_CONSTANT (constop
))
1796 operand
= error_mark_node
;
1798 TREE_VALUE (t
) = operand
;
1802 r
= build_stmt (loc
, ASM_EXPR
, string
,
1803 output_operands
, input_operands
,
1805 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1806 ASM_INLINE_P (r
) = inline_p
;
1807 r
= maybe_cleanup_point_expr_void (r
);
1808 return add_stmt (r
);
1811 /* Finish a label with the indicated NAME. Returns the new label. */
1814 finish_label_stmt (tree name
)
1816 tree decl
= define_label (input_location
, name
);
1818 if (decl
== error_mark_node
)
1819 return error_mark_node
;
1821 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1826 /* Finish a series of declarations for local labels. G++ allows users
1827 to declare "local" labels, i.e., labels with scope. This extension
1828 is useful when writing code involving statement-expressions. */
1831 finish_label_decl (tree name
)
1833 if (!at_function_scope_p ())
1835 error ("%<__label__%> declarations are only allowed in function scopes");
1839 add_decl_expr (declare_local_label (name
));
1842 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1845 finish_decl_cleanup (tree decl
, tree cleanup
)
1847 push_cleanup (decl
, cleanup
, false);
1850 /* If the current scope exits with an exception, run CLEANUP. */
1853 finish_eh_cleanup (tree cleanup
)
1855 push_cleanup (NULL
, cleanup
, true);
1858 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1859 order they were written by the user. Each node is as for
1860 emit_mem_initializers. */
1863 finish_mem_initializers (tree mem_inits
)
1865 /* Reorder the MEM_INITS so that they are in the order they appeared
1866 in the source program. */
1867 mem_inits
= nreverse (mem_inits
);
1869 if (processing_template_decl
)
1873 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1875 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1876 check for bare parameter packs in the TREE_VALUE, because
1877 any parameter packs in the TREE_VALUE have already been
1878 bound as part of the TREE_PURPOSE. See
1879 make_pack_expansion for more information. */
1880 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1881 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1882 TREE_VALUE (mem
) = error_mark_node
;
1885 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1886 CTOR_INITIALIZER
, mem_inits
));
1889 emit_mem_initializers (mem_inits
);
1892 /* Obfuscate EXPR if it looks like an id-expression or member access so
1893 that the call to finish_decltype in do_auto_deduction will give the
1894 right result. If EVEN_UNEVAL, do this even in unevaluated context. */
1897 force_paren_expr (tree expr
, bool even_uneval
)
1899 /* This is only needed for decltype(auto) in C++14. */
1900 if (cxx_dialect
< cxx14
)
1903 /* If we're in unevaluated context, we can't be deducing a
1904 return/initializer type, so we don't need to mess with this. */
1905 if (cp_unevaluated_operand
&& !even_uneval
)
1908 if (!DECL_P (tree_strip_any_location_wrapper (expr
))
1909 && TREE_CODE (expr
) != COMPONENT_REF
1910 && TREE_CODE (expr
) != SCOPE_REF
)
1913 location_t loc
= cp_expr_location (expr
);
1915 if (TREE_CODE (expr
) == COMPONENT_REF
1916 || TREE_CODE (expr
) == SCOPE_REF
)
1917 REF_PARENTHESIZED_P (expr
) = true;
1918 else if (processing_template_decl
)
1919 expr
= build1_loc (loc
, PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1922 expr
= build1_loc (loc
, VIEW_CONVERT_EXPR
, TREE_TYPE (expr
), expr
);
1923 REF_PARENTHESIZED_P (expr
) = true;
1929 /* If T is an id-expression obfuscated by force_paren_expr, undo the
1930 obfuscation and return the underlying id-expression. Otherwise
1934 maybe_undo_parenthesized_ref (tree t
)
1936 if (cxx_dialect
< cxx14
)
1939 if (INDIRECT_REF_P (t
) && REF_PARENTHESIZED_P (t
))
1941 t
= TREE_OPERAND (t
, 0);
1942 while (TREE_CODE (t
) == NON_LVALUE_EXPR
1943 || TREE_CODE (t
) == NOP_EXPR
)
1944 t
= TREE_OPERAND (t
, 0);
1946 gcc_assert (TREE_CODE (t
) == ADDR_EXPR
1947 || TREE_CODE (t
) == STATIC_CAST_EXPR
);
1948 t
= TREE_OPERAND (t
, 0);
1950 else if (TREE_CODE (t
) == PAREN_EXPR
)
1951 t
= TREE_OPERAND (t
, 0);
1952 else if (TREE_CODE (t
) == VIEW_CONVERT_EXPR
1953 && REF_PARENTHESIZED_P (t
))
1954 t
= TREE_OPERAND (t
, 0);
1959 /* Finish a parenthesized expression EXPR. */
1962 finish_parenthesized_expr (cp_expr expr
)
1965 /* This inhibits warnings in c_common_truthvalue_conversion. */
1966 TREE_NO_WARNING (expr
) = 1;
1968 if (TREE_CODE (expr
) == OFFSET_REF
1969 || TREE_CODE (expr
) == SCOPE_REF
)
1970 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1971 enclosed in parentheses. */
1972 PTRMEM_OK_P (expr
) = 0;
1974 tree stripped_expr
= tree_strip_any_location_wrapper (expr
);
1975 if (TREE_CODE (stripped_expr
) == STRING_CST
)
1976 PAREN_STRING_LITERAL_P (stripped_expr
) = 1;
1978 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
1983 /* Finish a reference to a non-static data member (DECL) that is not
1984 preceded by `.' or `->'. */
1987 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1989 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1990 bool try_omp_private
= !object
&& omp_private_member_map
;
1995 tree scope
= qualifying_scope
;
1996 if (scope
== NULL_TREE
)
1998 scope
= context_for_name_lookup (decl
);
1999 if (!TYPE_P (scope
))
2001 /* Can happen during error recovery (c++/85014). */
2002 gcc_assert (seen_error ());
2003 return error_mark_node
;
2006 object
= maybe_dummy_object (scope
, NULL
);
2009 object
= maybe_resolve_dummy (object
, true);
2010 if (object
== error_mark_node
)
2011 return error_mark_node
;
2013 /* DR 613/850: Can use non-static data members without an associated
2014 object in sizeof/decltype/alignof. */
2015 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
2016 && (!processing_template_decl
|| !current_class_ref
))
2018 if (current_function_decl
2019 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2020 error ("invalid use of member %qD in static member function", decl
);
2022 error ("invalid use of non-static data member %qD", decl
);
2023 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
2025 return error_mark_node
;
2028 if (current_class_ptr
)
2029 TREE_USED (current_class_ptr
) = 1;
2030 if (processing_template_decl
)
2032 tree type
= TREE_TYPE (decl
);
2034 if (TYPE_REF_P (type
))
2035 /* Quals on the object don't matter. */;
2036 else if (PACK_EXPANSION_P (type
))
2037 /* Don't bother trying to represent this. */
2041 /* Set the cv qualifiers. */
2042 int quals
= cp_type_quals (TREE_TYPE (object
));
2044 if (DECL_MUTABLE_P (decl
))
2045 quals
&= ~TYPE_QUAL_CONST
;
2047 quals
|= cp_type_quals (TREE_TYPE (decl
));
2048 type
= cp_build_qualified_type (type
, quals
);
2051 if (qualifying_scope
)
2052 /* Wrap this in a SCOPE_REF for now. */
2053 ret
= build_qualified_name (type
, qualifying_scope
, decl
,
2054 /*template_p=*/false);
2056 ret
= (convert_from_reference
2057 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
2059 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2060 QUALIFYING_SCOPE is also non-null. */
2063 tree access_type
= TREE_TYPE (object
);
2065 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
2066 decl
, tf_warning_or_error
);
2068 /* If the data member was named `C::M', convert `*this' to `C'
2070 if (qualifying_scope
)
2072 tree binfo
= NULL_TREE
;
2073 object
= build_scoped_ref (object
, qualifying_scope
,
2077 ret
= build_class_member_access_expr (object
, decl
,
2078 /*access_path=*/NULL_TREE
,
2079 /*preserve_reference=*/false,
2080 tf_warning_or_error
);
2082 if (try_omp_private
)
2084 tree
*v
= omp_private_member_map
->get (decl
);
2086 ret
= convert_from_reference (*v
);
2091 /* DECL was the declaration to which a qualified-id resolved. Issue
2092 an error message if it is not accessible. If OBJECT_TYPE is
2093 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2094 type of `*x', or `x', respectively. If the DECL was named as
2095 `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2096 perform_access_checks above. */
2099 check_accessibility_of_qualified_id (tree decl
,
2101 tree nested_name_specifier
,
2102 tsubst_flags_t complain
)
2104 /* If we're not checking, return immediately. */
2105 if (deferred_access_no_check
)
2108 /* Determine the SCOPE of DECL. */
2109 tree scope
= context_for_name_lookup (decl
);
2110 /* If the SCOPE is not a type, then DECL is not a member. */
2112 /* If SCOPE is dependent then we can't perform this access check now,
2113 and since we'll perform this access check again after substitution
2114 there's no need to explicitly defer it. */
2115 || dependent_type_p (scope
))
2118 tree qualifying_type
= NULL_TREE
;
2119 /* Compute the scope through which DECL is being accessed. */
2121 /* OBJECT_TYPE might not be a class type; consider:
2123 class A { typedef int I; };
2127 In this case, we will have "A::I" as the DECL, but "I" as the
2129 && CLASS_TYPE_P (object_type
)
2130 && DERIVED_FROM_P (scope
, object_type
))
2131 /* If we are processing a `->' or `.' expression, use the type of the
2133 qualifying_type
= object_type
;
2134 else if (nested_name_specifier
)
2136 /* If the reference is to a non-static member of the
2137 current class, treat it as if it were referenced through
2139 if (DECL_NONSTATIC_MEMBER_P (decl
)
2140 && current_class_ptr
)
2141 if (tree current
= current_nonlambda_class_type ())
2143 if (dependent_type_p (current
))
2144 /* In general we can't know whether this access goes through
2145 `this' until instantiation time. Punt now, or else we might
2146 create a deferred access check that's not relative to `this'
2147 when it ought to be. We'll check this access again after
2148 substitution, e.g. from tsubst_qualified_id. */
2151 if (DERIVED_FROM_P (scope
, current
))
2152 qualifying_type
= current
;
2154 /* Otherwise, use the type indicated by the
2155 nested-name-specifier. */
2156 if (!qualifying_type
)
2157 qualifying_type
= nested_name_specifier
;
2160 /* Otherwise, the name must be from the current class or one of
2162 qualifying_type
= currently_open_derived_class (scope
);
2165 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2166 or similar in a default argument value. */
2167 && CLASS_TYPE_P (qualifying_type
))
2168 return perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
2174 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2175 class named to the left of the "::" operator. DONE is true if this
2176 expression is a complete postfix-expression; it is false if this
2177 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2178 iff this expression is the operand of '&'. TEMPLATE_P is true iff
2179 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2180 is true iff this qualified name appears as a template argument. */
2183 finish_qualified_id_expr (tree qualifying_class
,
2188 bool template_arg_p
,
2189 tsubst_flags_t complain
)
2191 gcc_assert (TYPE_P (qualifying_class
));
2193 if (error_operand_p (expr
))
2194 return error_mark_node
;
2196 if ((DECL_P (expr
) || BASELINK_P (expr
))
2197 && !mark_used (expr
, complain
))
2198 return error_mark_node
;
2202 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
2204 /* cp_parser_lookup_name thought we were looking for a type,
2205 but we're actually looking for a declaration. */
2206 qualifying_class
= TYPE_CONTEXT (expr
);
2207 expr
= TYPE_IDENTIFIER (expr
);
2210 check_template_keyword (expr
);
2213 /* If EXPR occurs as the operand of '&', use special handling that
2214 permits a pointer-to-member. */
2215 if (address_p
&& done
)
2217 if (TREE_CODE (expr
) == SCOPE_REF
)
2218 expr
= TREE_OPERAND (expr
, 1);
2219 expr
= build_offset_ref (qualifying_class
, expr
,
2220 /*address_p=*/true, complain
);
2224 /* No need to check access within an enum. */
2225 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
2226 && TREE_CODE (expr
) != IDENTIFIER_NODE
)
2229 /* Within the scope of a class, turn references to non-static
2230 members into expression of the form "this->...". */
2232 /* But, within a template argument, we do not want make the
2233 transformation, as there is no "this" pointer. */
2235 else if (TREE_CODE (expr
) == FIELD_DECL
)
2237 push_deferring_access_checks (dk_no_check
);
2238 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2240 pop_deferring_access_checks ();
2242 else if (BASELINK_P (expr
))
2244 /* See if any of the functions are non-static members. */
2245 /* If so, the expression may be relative to 'this'. */
2246 if (!shared_member_p (expr
)
2247 && current_class_ptr
2248 && DERIVED_FROM_P (qualifying_class
,
2249 current_nonlambda_class_type ()))
2250 expr
= (build_class_member_access_expr
2251 (maybe_dummy_object (qualifying_class
, NULL
),
2253 BASELINK_ACCESS_BINFO (expr
),
2254 /*preserve_reference=*/false,
2257 /* The expression is a qualified name whose address is not
2259 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2262 else if (!template_p
2263 && TREE_CODE (expr
) == TEMPLATE_DECL
2264 && !DECL_FUNCTION_TEMPLATE_P (expr
))
2266 if (complain
& tf_error
)
2267 error ("%qE missing template arguments", expr
);
2268 return error_mark_node
;
2272 /* In a template, return a SCOPE_REF for most qualified-ids
2273 so that we can check access at instantiation time. But if
2274 we're looking at a member of the current instantiation, we
2275 know we have access and building up the SCOPE_REF confuses
2276 non-type template argument handling. */
2277 if (processing_template_decl
2278 && (!currently_open_class (qualifying_class
)
2279 || TREE_CODE (expr
) == IDENTIFIER_NODE
2280 || TREE_CODE (expr
) == TEMPLATE_ID_EXPR
2281 || TREE_CODE (expr
) == BIT_NOT_EXPR
))
2282 expr
= build_qualified_name (TREE_TYPE (expr
),
2283 qualifying_class
, expr
,
2285 else if (tree wrap
= maybe_get_tls_wrapper_call (expr
))
2288 expr
= convert_from_reference (expr
);
2294 /* Begin a statement-expression. The value returned must be passed to
2295 finish_stmt_expr. */
2298 begin_stmt_expr (void)
2300 return push_stmt_list ();
2303 /* Process the final expression of a statement expression. EXPR can be
2304 NULL, if the final expression is empty. Return a STATEMENT_LIST
2305 containing all the statements in the statement-expression, or
2306 ERROR_MARK_NODE if there was an error. */
2309 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2311 if (error_operand_p (expr
))
2313 /* The type of the statement-expression is the type of the last
2315 TREE_TYPE (stmt_expr
) = error_mark_node
;
2316 return error_mark_node
;
2319 /* If the last statement does not have "void" type, then the value
2320 of the last statement is the value of the entire expression. */
2323 tree type
= TREE_TYPE (expr
);
2325 if (type
&& type_unknown_p (type
))
2327 error ("a statement expression is an insufficient context"
2328 " for overload resolution");
2329 TREE_TYPE (stmt_expr
) = error_mark_node
;
2330 return error_mark_node
;
2332 else if (processing_template_decl
)
2334 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2335 expr
= add_stmt (expr
);
2336 /* Mark the last statement so that we can recognize it as such at
2337 template-instantiation time. */
2338 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2340 else if (VOID_TYPE_P (type
))
2342 /* Just treat this like an ordinary statement. */
2343 expr
= finish_expr_stmt (expr
);
2347 /* It actually has a value we need to deal with. First, force it
2348 to be an rvalue so that we won't need to build up a copy
2349 constructor call later when we try to assign it to something. */
2350 expr
= force_rvalue (expr
, tf_warning_or_error
);
2351 if (error_operand_p (expr
))
2352 return error_mark_node
;
2354 /* Update for array-to-pointer decay. */
2355 type
= TREE_TYPE (expr
);
2357 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2358 normal statement, but don't convert to void or actually add
2360 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2361 expr
= maybe_cleanup_point_expr (expr
);
2365 /* The type of the statement-expression is the type of the last
2367 TREE_TYPE (stmt_expr
) = type
;
2373 /* Finish a statement-expression. EXPR should be the value returned
2374 by the previous begin_stmt_expr. Returns an expression
2375 representing the statement-expression. */
2378 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2383 if (error_operand_p (stmt_expr
))
2385 pop_stmt_list (stmt_expr
);
2386 return error_mark_node
;
2389 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2391 type
= TREE_TYPE (stmt_expr
);
2392 result
= pop_stmt_list (stmt_expr
);
2393 TREE_TYPE (result
) = type
;
2395 if (processing_template_decl
)
2397 result
= build_min (STMT_EXPR
, type
, result
);
2398 TREE_SIDE_EFFECTS (result
) = 1;
2399 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2401 else if (CLASS_TYPE_P (type
))
2403 /* Wrap the statement-expression in a TARGET_EXPR so that the
2404 temporary object created by the final expression is destroyed at
2405 the end of the full-expression containing the
2406 statement-expression. */
2407 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2413 /* Returns the expression which provides the value of STMT_EXPR. */
2416 stmt_expr_value_expr (tree stmt_expr
)
2418 tree t
= STMT_EXPR_STMT (stmt_expr
);
2420 if (TREE_CODE (t
) == BIND_EXPR
)
2421 t
= BIND_EXPR_BODY (t
);
2423 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2424 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2426 if (TREE_CODE (t
) == EXPR_STMT
)
2427 t
= EXPR_STMT_EXPR (t
);
2432 /* Return TRUE iff EXPR_STMT is an empty list of
2433 expression statements. */
2436 empty_expr_stmt_p (tree expr_stmt
)
2438 tree body
= NULL_TREE
;
2440 if (expr_stmt
== void_node
)
2445 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2446 body
= EXPR_STMT_EXPR (expr_stmt
);
2447 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2453 if (TREE_CODE (body
) == STATEMENT_LIST
)
2454 return tsi_end_p (tsi_start (body
));
2456 return empty_expr_stmt_p (body
);
2461 /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
2462 the function (or functions) to call; ARGS are the arguments to the
2463 call. Returns the functions to be considered by overload resolution. */
2466 perform_koenig_lookup (cp_expr fn_expr
, vec
<tree
, va_gc
> *args
,
2467 tsubst_flags_t complain
)
2469 tree identifier
= NULL_TREE
;
2470 tree functions
= NULL_TREE
;
2471 tree tmpl_args
= NULL_TREE
;
2472 bool template_id
= false;
2473 location_t loc
= fn_expr
.get_location ();
2474 tree fn
= fn_expr
.get_value ();
2476 STRIP_ANY_LOCATION_WRAPPER (fn
);
2478 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2480 /* Use a separate flag to handle null args. */
2482 tmpl_args
= TREE_OPERAND (fn
, 1);
2483 fn
= TREE_OPERAND (fn
, 0);
2486 /* Find the name of the overloaded function. */
2487 if (identifier_p (fn
))
2492 identifier
= OVL_NAME (functions
);
2495 /* A call to a namespace-scope function using an unqualified name.
2497 Do Koenig lookup -- unless any of the arguments are
2499 if (!any_type_dependent_arguments_p (args
)
2500 && !any_dependent_template_arguments_p (tmpl_args
))
2502 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2505 /* The unqualified name could not be resolved. */
2506 if (complain
& tf_error
)
2507 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2513 if (fn
&& template_id
&& fn
!= error_mark_node
)
2514 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2516 return cp_expr (fn
, loc
);
2519 /* Generate an expression for `FN (ARGS)'. This may change the
2522 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2523 as a virtual call, even if FN is virtual. (This flag is set when
2524 encountering an expression where the function name is explicitly
2525 qualified. For example a call to `X::f' never generates a virtual
2528 Returns code for the call. */
2531 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2532 bool koenig_p
, tsubst_flags_t complain
)
2536 vec
<tree
, va_gc
> *orig_args
= *args
;
2538 if (fn
== error_mark_node
)
2539 return error_mark_node
;
2541 gcc_assert (!TYPE_P (fn
));
2543 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2544 it so that we can tell this is a call to a known function. */
2545 fn
= maybe_undo_parenthesized_ref (fn
);
2547 STRIP_ANY_LOCATION_WRAPPER (fn
);
2551 if (processing_template_decl
)
2553 /* If FN is a local extern declaration or set thereof, look them up
2554 again at instantiation time. */
2555 if (is_overloaded_fn (fn
))
2557 tree ifn
= get_first_fn (fn
);
2558 if (TREE_CODE (ifn
) == FUNCTION_DECL
2559 && DECL_LOCAL_DECL_P (ifn
))
2560 orig_fn
= DECL_NAME (ifn
);
2563 /* If the call expression is dependent, build a CALL_EXPR node
2564 with no type; type_dependent_expression_p recognizes
2565 expressions with no type as being dependent. */
2566 if (type_dependent_expression_p (fn
)
2567 || any_type_dependent_arguments_p (*args
))
2569 result
= build_min_nt_call_vec (orig_fn
, *args
);
2570 SET_EXPR_LOCATION (result
, cp_expr_loc_or_input_loc (fn
));
2571 KOENIG_LOOKUP_P (result
) = koenig_p
;
2572 if (is_overloaded_fn (fn
))
2577 bool abnormal
= true;
2578 for (lkp_iterator
iter (fn
); abnormal
&& iter
; ++iter
)
2580 tree fndecl
= STRIP_TEMPLATE (*iter
);
2581 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2582 || !TREE_THIS_VOLATILE (fndecl
))
2585 /* FIXME: Stop warning about falling off end of non-void
2586 function. But this is wrong. Even if we only see
2587 no-return fns at this point, we could select a
2588 future-defined return fn during instantiation. Or
2591 current_function_returns_abnormally
= 1;
2595 orig_args
= make_tree_vector_copy (*args
);
2596 if (!BASELINK_P (fn
)
2597 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2598 && TREE_TYPE (fn
) != unknown_type_node
)
2599 fn
= build_non_dependent_expr (fn
);
2600 make_args_non_dependent (*args
);
2603 if (TREE_CODE (fn
) == COMPONENT_REF
)
2605 tree member
= TREE_OPERAND (fn
, 1);
2606 if (BASELINK_P (member
))
2608 tree object
= TREE_OPERAND (fn
, 0);
2609 return build_new_method_call (object
, member
,
2612 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2619 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2620 if (TREE_CODE (fn
) == ADDR_EXPR
2621 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2622 fn
= TREE_OPERAND (fn
, 0);
2624 if (is_overloaded_fn (fn
))
2625 fn
= baselink_for_fns (fn
);
2628 if (BASELINK_P (fn
))
2632 /* A call to a member function. From [over.call.func]:
2634 If the keyword this is in scope and refers to the class of
2635 that member function, or a derived class thereof, then the
2636 function call is transformed into a qualified function call
2637 using (*this) as the postfix-expression to the left of the
2638 . operator.... [Otherwise] a contrived object of type T
2639 becomes the implied object argument.
2643 struct A { void f(); };
2644 struct B : public A {};
2645 struct C : public A { void g() { B::f(); }};
2647 "the class of that member function" refers to `A'. But 11.2
2648 [class.access.base] says that we need to convert 'this' to B* as
2649 part of the access, so we pass 'B' to maybe_dummy_object. */
2651 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2653 /* A constructor call always uses a dummy object. (This constructor
2654 call which has the form A::A () is actually invalid and we are
2655 going to reject it later in build_new_method_call.) */
2656 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2659 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2662 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2664 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2669 else if (concept_check_p (fn
))
2671 /* FN is actually a template-id referring to a concept definition. */
2672 tree id
= unpack_concept_check (fn
);
2673 tree tmpl
= TREE_OPERAND (id
, 0);
2674 tree args
= TREE_OPERAND (id
, 1);
2676 if (!function_concept_p (tmpl
))
2678 error_at (EXPR_LOC_OR_LOC (fn
, input_location
),
2679 "cannot call a concept as a function");
2680 return error_mark_node
;
2683 /* Ensure the result is wrapped as a call expression. */
2684 result
= build_concept_check (tmpl
, args
, tf_warning_or_error
);
2686 else if (is_overloaded_fn (fn
))
2688 /* If the function is an overloaded builtin, resolve it. */
2689 if (TREE_CODE (fn
) == FUNCTION_DECL
2690 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2691 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2692 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2696 if (warn_sizeof_pointer_memaccess
2697 && (complain
& tf_warning
)
2698 && !vec_safe_is_empty (*args
)
2699 && !processing_template_decl
)
2701 location_t sizeof_arg_loc
[3];
2704 for (i
= 0; i
< 3; i
++)
2708 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2709 sizeof_arg
[i
] = NULL_TREE
;
2710 if (i
>= (*args
)->length ())
2713 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2715 if (SIZEOF_EXPR_TYPE_P (t
))
2716 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2718 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2719 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2721 sizeof_pointer_memaccess_warning
2722 (sizeof_arg_loc
, fn
, *args
,
2723 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2726 if ((complain
& tf_warning
)
2727 && TREE_CODE (fn
) == FUNCTION_DECL
2728 && fndecl_built_in_p (fn
, BUILT_IN_MEMSET
)
2729 && vec_safe_length (*args
) == 3
2730 && !any_type_dependent_arguments_p (*args
))
2732 tree arg0
= (*orig_args
)[0];
2733 tree arg1
= (*orig_args
)[1];
2734 tree arg2
= (*orig_args
)[2];
2735 int literal_mask
= ((literal_integer_zerop (arg1
) << 1)
2736 | (literal_integer_zerop (arg2
) << 2));
2737 warn_for_memset (input_location
, arg0
, arg2
, literal_mask
);
2740 /* A call to a namespace-scope function. */
2741 result
= build_new_function_call (fn
, args
, complain
);
2744 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2746 if (!vec_safe_is_empty (*args
))
2747 error ("arguments to destructor are not allowed");
2748 /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
2749 which case the postfix-expression is a possibly-parenthesized class
2750 member access), the function call destroys the object of scalar type
2751 denoted by the object expression of the class member access. */
2752 tree ob
= TREE_OPERAND (fn
, 0);
2754 result
= build_trivial_dtor_call (ob
, true);
2756 /* No location to clobber. */
2757 result
= convert_to_void (ob
, ICV_STATEMENT
, complain
);
2759 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2760 /* If the "function" is really an object of class type, it might
2761 have an overloaded `operator ()'. */
2762 result
= build_op_call (fn
, args
, complain
);
2765 /* A call where the function is unknown. */
2766 result
= cp_build_function_call_vec (fn
, args
, complain
);
2768 if (processing_template_decl
&& result
!= error_mark_node
)
2770 if (INDIRECT_REF_P (result
))
2771 result
= TREE_OPERAND (result
, 0);
2772 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2773 SET_EXPR_LOCATION (result
, input_location
);
2774 KOENIG_LOOKUP_P (result
) = koenig_p
;
2775 release_tree_vector (orig_args
);
2776 result
= convert_from_reference (result
);
2782 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2783 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2784 POSTDECREMENT_EXPR.) */
2787 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2789 /* input_location holds the location of the trailing operator token.
2790 Build a location of the form:
2793 with the caret at the operator token, ranging from the start
2794 of EXPR to the end of the operator token. */
2795 location_t combined_loc
= make_location (input_location
,
2797 get_finish (input_location
));
2798 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2799 tf_warning_or_error
);
2800 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2801 result
.set_location (combined_loc
);
2805 /* Finish a use of `this'. Returns an expression for `this'. */
2808 finish_this_expr (void)
2810 tree result
= NULL_TREE
;
2812 if (current_class_ptr
)
2814 tree type
= TREE_TYPE (current_class_ref
);
2816 /* In a lambda expression, 'this' refers to the captured 'this'. */
2817 if (LAMBDA_TYPE_P (type
))
2818 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2820 result
= current_class_ptr
;
2824 /* The keyword 'this' is a prvalue expression. */
2825 return rvalue (result
);
2827 tree fn
= current_nonlambda_function ();
2828 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2829 error ("%<this%> is unavailable for static member functions");
2831 error ("invalid use of %<this%> in non-member function");
2833 error ("invalid use of %<this%> at top level");
2834 return error_mark_node
;
2837 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2838 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2839 the TYPE for the type given. If SCOPE is non-NULL, the expression
2840 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2843 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2846 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2847 return error_mark_node
;
2849 gcc_assert (TYPE_P (destructor
));
2851 if (!processing_template_decl
)
2853 if (scope
== error_mark_node
)
2855 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2856 return error_mark_node
;
2858 if (is_auto (destructor
))
2859 destructor
= TREE_TYPE (object
);
2860 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2863 "qualified type %qT does not match destructor name ~%qT",
2865 return error_mark_node
;
2869 /* [expr.pseudo] says both:
2871 The type designated by the pseudo-destructor-name shall be
2872 the same as the object type.
2876 The cv-unqualified versions of the object type and of the
2877 type designated by the pseudo-destructor-name shall be the
2880 We implement the more generous second sentence, since that is
2881 what most other compilers do. */
2882 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2885 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2886 return error_mark_node
;
2890 tree type
= (type_dependent_expression_p (object
)
2891 ? NULL_TREE
: void_type_node
);
2893 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, type
, object
,
2897 /* Finish an expression of the form CODE EXPR. */
2900 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
2901 tsubst_flags_t complain
)
2903 /* Build a location of the form:
2906 with the caret at the operator token, ranging from the start
2907 of the operator token to the end of EXPR. */
2908 location_t combined_loc
= make_location (op_loc
,
2909 op_loc
, expr
.get_finish ());
2910 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
, complain
);
2911 /* TODO: build_x_unary_op doesn't always honor the location. */
2912 result
.set_location (combined_loc
);
2914 if (result
== error_mark_node
)
2917 if (!(complain
& tf_warning
))
2920 tree result_ovl
= result
;
2921 tree expr_ovl
= expr
;
2923 if (!processing_template_decl
)
2924 expr_ovl
= cp_fully_fold (expr_ovl
);
2926 if (!CONSTANT_CLASS_P (expr_ovl
)
2927 || TREE_OVERFLOW_P (expr_ovl
))
2930 if (!processing_template_decl
)
2931 result_ovl
= cp_fully_fold (result_ovl
);
2933 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
2934 overflow_warning (combined_loc
, result_ovl
);
2939 /* Finish a compound-literal expression or C++11 functional cast with aggregate
2940 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
2944 finish_compound_literal (tree type
, tree compound_literal
,
2945 tsubst_flags_t complain
,
2948 if (type
== error_mark_node
)
2949 return error_mark_node
;
2951 if (TYPE_REF_P (type
))
2954 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2955 complain
, fcl_context
);
2956 /* The prvalue is then used to direct-initialize the reference. */
2957 tree r
= (perform_implicit_conversion_flags
2958 (type
, compound_literal
, complain
, LOOKUP_NORMAL
));
2959 return convert_from_reference (r
);
2962 if (!TYPE_OBJ_P (type
))
2964 if (complain
& tf_error
)
2965 error ("compound literal of non-object type %qT", type
);
2966 return error_mark_node
;
2969 if (tree anode
= type_uses_auto (type
))
2970 if (CLASS_PLACEHOLDER_TEMPLATE (anode
))
2972 type
= do_auto_deduction (type
, compound_literal
, anode
, complain
,
2974 if (type
== error_mark_node
)
2975 return error_mark_node
;
2978 /* Used to hold a copy of the compound literal in a template. */
2979 tree orig_cl
= NULL_TREE
;
2981 if (processing_template_decl
)
2983 const bool dependent_p
2984 = (instantiation_dependent_expression_p (compound_literal
)
2985 || dependent_type_p (type
));
2987 /* We're about to return, no need to copy. */
2988 orig_cl
= compound_literal
;
2990 /* We're going to need a copy. */
2991 orig_cl
= unshare_constructor (compound_literal
);
2992 TREE_TYPE (orig_cl
) = type
;
2993 /* Mark the expression as a compound literal. */
2994 TREE_HAS_CONSTRUCTOR (orig_cl
) = 1;
2995 /* And as instantiation-dependent. */
2996 CONSTRUCTOR_IS_DEPENDENT (orig_cl
) = dependent_p
;
2997 if (fcl_context
== fcl_c99
)
2998 CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl
) = 1;
2999 /* If the compound literal is dependent, we're done for now. */
3002 /* Otherwise, do go on to e.g. check narrowing. */
3005 type
= complete_type (type
);
3007 if (TYPE_NON_AGGREGATE_CLASS (type
))
3009 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3010 everywhere that deals with function arguments would be a pain, so
3011 just wrap it in a TREE_LIST. The parser set a flag so we know
3012 that it came from T{} rather than T({}). */
3013 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
3014 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
3015 return build_functional_cast (input_location
, type
,
3016 compound_literal
, complain
);
3019 if (TREE_CODE (type
) == ARRAY_TYPE
3020 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
3021 return error_mark_node
;
3022 compound_literal
= reshape_init (type
, compound_literal
, complain
);
3023 if (SCALAR_TYPE_P (type
)
3024 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
))
3026 tree t
= instantiate_non_dependent_expr_sfinae (compound_literal
,
3028 if (!check_narrowing (type
, t
, complain
))
3029 return error_mark_node
;
3031 if (TREE_CODE (type
) == ARRAY_TYPE
3032 && TYPE_DOMAIN (type
) == NULL_TREE
)
3034 cp_complete_array_type_or_error (&type
, compound_literal
,
3036 if (type
== error_mark_node
)
3037 return error_mark_node
;
3039 compound_literal
= digest_init_flags (type
, compound_literal
,
3040 LOOKUP_NORMAL
| LOOKUP_NO_NARROWING
,
3042 if (compound_literal
== error_mark_node
)
3043 return error_mark_node
;
3045 /* If we're in a template, return the original compound literal. */
3049 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
3051 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
3052 if (fcl_context
== fcl_c99
)
3053 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
3056 /* Put static/constant array temporaries in static variables. */
3057 /* FIXME all C99 compound literals should be variables rather than C++
3058 temporaries, unless they are used as an aggregate initializer. */
3059 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
3060 && fcl_context
== fcl_c99
3061 && TREE_CODE (type
) == ARRAY_TYPE
3062 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
3063 && initializer_constant_valid_p (compound_literal
, type
))
3065 tree decl
= create_temporary_var (type
);
3066 DECL_CONTEXT (decl
) = NULL_TREE
;
3067 DECL_INITIAL (decl
) = compound_literal
;
3068 TREE_STATIC (decl
) = 1;
3069 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
3071 /* 5.19 says that a constant expression can include an
3072 lvalue-rvalue conversion applied to "a glvalue of literal type
3073 that refers to a non-volatile temporary object initialized
3074 with a constant expression". Rather than try to communicate
3075 that this VAR_DECL is a temporary, just mark it constexpr. */
3076 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
3077 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
3078 TREE_CONSTANT (decl
) = true;
3080 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
3081 decl
= pushdecl_top_level (decl
);
3082 DECL_NAME (decl
) = make_anon_name ();
3083 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
3084 /* Make sure the destructor is callable. */
3085 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
3086 if (clean
== error_mark_node
)
3087 return error_mark_node
;
3091 /* Represent other compound literals with TARGET_EXPR so we produce
3092 an lvalue, but can elide copies. */
3093 if (!VECTOR_TYPE_P (type
))
3094 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
3096 return compound_literal
;
3099 /* Return the declaration for the function-name variable indicated by
3103 finish_fname (tree id
)
3107 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
3108 if (processing_template_decl
&& current_function_decl
3109 && decl
!= error_mark_node
)
3110 decl
= DECL_NAME (decl
);
3114 /* Finish a translation unit. */
3117 finish_translation_unit (void)
3119 /* In case there were missing closebraces,
3120 get us back to the global binding level. */
3122 while (current_namespace
!= global_namespace
)
3125 /* Do file scope __FUNCTION__ et al. */
3126 finish_fname_decls ();
3128 if (scope_chain
->omp_declare_target_attribute
)
3131 error ("%<#pragma omp declare target%> without corresponding "
3132 "%<#pragma omp end declare target%>");
3133 scope_chain
->omp_declare_target_attribute
= 0;
3137 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
3138 Returns the parameter. */
3141 finish_template_type_parm (tree aggr
, tree identifier
)
3143 if (aggr
!= class_type_node
)
3145 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
3146 aggr
= class_type_node
;
3149 return build_tree_list (aggr
, identifier
);
3152 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
3153 Returns the parameter. */
3156 finish_template_template_parm (tree aggr
, tree identifier
)
3158 tree decl
= build_decl (input_location
,
3159 TYPE_DECL
, identifier
, NULL_TREE
);
3161 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
3162 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
3163 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
3164 DECL_ARTIFICIAL (decl
) = 1;
3166 /* Associate the constraints with the underlying declaration,
3167 not the template. */
3168 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
3169 tree constr
= build_constraints (reqs
, NULL_TREE
);
3170 set_constraints (decl
, constr
);
3172 end_template_decl ();
3174 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
3176 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
3177 /*is_primary=*/true, /*is_partial=*/false,
3180 return finish_template_type_parm (aggr
, tmpl
);
3183 /* ARGUMENT is the default-argument value for a template template
3184 parameter. If ARGUMENT is invalid, issue error messages and return
3185 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
3188 check_template_template_default_arg (tree argument
)
3190 if (TREE_CODE (argument
) != TEMPLATE_DECL
3191 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
3192 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
3194 if (TREE_CODE (argument
) == TYPE_DECL
)
3195 error ("invalid use of type %qT as a default value for a template "
3196 "template-parameter", TREE_TYPE (argument
));
3198 error ("invalid default argument for a template template parameter");
3199 return error_mark_node
;
3205 /* Begin a class definition, as indicated by T. */
3208 begin_class_definition (tree t
)
3210 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
3211 return error_mark_node
;
3213 if (processing_template_parmlist
&& !LAMBDA_TYPE_P (t
))
3215 error ("definition of %q#T inside template parameter list", t
);
3216 return error_mark_node
;
3219 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
3220 are passed the same as decimal scalar types. */
3221 if (TREE_CODE (t
) == RECORD_TYPE
3222 && !processing_template_decl
)
3224 tree ns
= TYPE_CONTEXT (t
);
3225 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
3226 && DECL_CONTEXT (ns
) == std_node
3228 && id_equal (DECL_NAME (ns
), "decimal"))
3230 const char *n
= TYPE_NAME_STRING (t
);
3231 if ((strcmp (n
, "decimal32") == 0)
3232 || (strcmp (n
, "decimal64") == 0)
3233 || (strcmp (n
, "decimal128") == 0))
3234 TYPE_TRANSPARENT_AGGR (t
) = 1;
3238 /* A non-implicit typename comes from code like:
3240 template <typename T> struct A {
3241 template <typename U> struct A<T>::B ...
3243 This is erroneous. */
3244 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
3246 error ("invalid definition of qualified type %qT", t
);
3247 t
= error_mark_node
;
3250 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
3252 t
= make_class_type (RECORD_TYPE
);
3253 pushtag (make_anon_name (), t
);
3256 if (TYPE_BEING_DEFINED (t
))
3258 t
= make_class_type (TREE_CODE (t
));
3259 pushtag (TYPE_IDENTIFIER (t
), t
);
3264 if (!module_may_redeclare (TYPE_NAME (t
)))
3266 error ("cannot declare %qD in a different module", TYPE_NAME (t
));
3267 inform (DECL_SOURCE_LOCATION (TYPE_NAME (t
)), "declared here");
3268 return error_mark_node
;
3270 set_instantiating_module (TYPE_NAME (t
));
3271 set_defining_module (TYPE_NAME (t
));
3274 maybe_process_partial_specialization (t
);
3276 TYPE_BEING_DEFINED (t
) = 1;
3277 class_binding_level
->defining_class_p
= 1;
3279 if (flag_pack_struct
)
3282 TYPE_PACKED (t
) = 1;
3283 /* Even though the type is being defined for the first time
3284 here, there might have been a forward declaration, so there
3285 might be cv-qualified variants of T. */
3286 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
3287 TYPE_PACKED (v
) = 1;
3289 /* Reset the interface data, at the earliest possible
3290 moment, as it might have been set via a class foo;
3292 if (! TYPE_UNNAMED_P (t
))
3294 struct c_fileinfo
*finfo
= \
3295 get_fileinfo (LOCATION_FILE (input_location
));
3296 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
3297 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
3298 (t
, finfo
->interface_unknown
);
3300 reset_specialization ();
3302 /* Make a declaration for this class in its own scope. */
3303 build_self_reference ();
3308 /* Finish the member declaration given by DECL. */
3311 finish_member_declaration (tree decl
)
3313 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
3316 if (decl
== void_type_node
)
3317 /* The COMPONENT was a friend, not a member, and so there's
3318 nothing for us to do. */
3321 /* We should see only one DECL at a time. */
3322 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
3324 /* Don't add decls after definition. */
3325 gcc_assert (TYPE_BEING_DEFINED (current_class_type
)
3326 /* We can add lambda types when late parsing default
3328 || LAMBDA_TYPE_P (TREE_TYPE (decl
)));
3330 /* Set up access control for DECL. */
3332 = (current_access_specifier
== access_private_node
);
3333 TREE_PROTECTED (decl
)
3334 = (current_access_specifier
== access_protected_node
);
3335 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3337 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
3338 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
3341 /* Mark the DECL as a member of the current class, unless it's
3342 a member of an enumeration. */
3343 if (TREE_CODE (decl
) != CONST_DECL
)
3344 DECL_CONTEXT (decl
) = current_class_type
;
3346 if (TREE_CODE (decl
) == USING_DECL
)
3347 /* For now, ignore class-scope USING_DECLS, so that debugging
3348 backends do not see them. */
3349 DECL_IGNORED_P (decl
) = 1;
3351 /* Check for bare parameter packs in the non-static data member
3353 if (TREE_CODE (decl
) == FIELD_DECL
)
3355 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
3356 TREE_TYPE (decl
) = error_mark_node
;
3357 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3358 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3363 A C language linkage is ignored for the names of class members
3364 and the member function type of class member functions. */
3365 if (DECL_LANG_SPECIFIC (decl
))
3366 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3370 /* Functions and non-functions are added differently. */
3371 if (DECL_DECLARES_FUNCTION_P (decl
))
3372 add
= add_method (current_class_type
, decl
, false);
3373 /* Enter the DECL into the scope of the class, if the class
3374 isn't a closure (whose fields are supposed to be unnamed). */
3375 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3376 || pushdecl_class_level (decl
))
3381 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3382 go at the beginning. The reason is that
3383 legacy_nonfn_member_lookup searches the list in order, and we
3384 want a field name to override a type name so that the "struct
3385 stat hack" will work. In particular:
3387 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3391 if (TREE_CODE (decl
) == TYPE_DECL
)
3392 TYPE_FIELDS (current_class_type
)
3393 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3396 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3397 TYPE_FIELDS (current_class_type
) = decl
;
3400 maybe_add_class_template_decl_list (current_class_type
, decl
,
3405 /* Finish processing a complete template declaration. The PARMS are
3406 the template parameters. */
3409 finish_template_decl (tree parms
)
3412 end_template_decl ();
3414 end_specialization ();
3417 // Returns the template type of the class scope being entered. If we're
3418 // entering a constrained class scope. TYPE is the class template
3419 // scope being entered and we may need to match the intended type with
3420 // a constrained specialization. For example:
3422 // template<Object T>
3423 // struct S { void f(); }; #1
3425 // template<Object T>
3426 // void S<T>::f() { } #2
3428 // We check, in #2, that S<T> refers precisely to the type declared by
3429 // #1 (i.e., that the constraints match). Note that the following should
3430 // be an error since there is no specialization of S<T> that is
3431 // unconstrained, but this is not diagnosed here.
3433 // template<typename T>
3434 // void S<T>::f() { }
3436 // We cannot diagnose this problem here since this function also matches
3437 // qualified template names that are not part of a definition. For example:
3439 // template<Integral T, Floating_point U>
3440 // typename pair<T, U>::first_type void f(T, U);
3442 // Here, it is unlikely that there is a partial specialization of
3443 // pair constrained for for Integral and Floating_point arguments.
3445 // The general rule is: if a constrained specialization with matching
3446 // constraints is found return that type. Also note that if TYPE is not a
3447 // class-type (e.g. a typename type), then no fixup is needed.
3450 fixup_template_type (tree type
)
3452 // Find the template parameter list at the a depth appropriate to
3453 // the scope we're trying to enter.
3454 tree parms
= current_template_parms
;
3455 int depth
= template_class_depth (type
);
3456 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3457 parms
= TREE_CHAIN (parms
);
3460 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3461 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3463 // Search for a specialization whose type and constraints match.
3464 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3465 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3468 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3470 // If the type and constraints match a specialization, then we
3471 // are entering that type.
3472 if (same_type_p (type
, TREE_TYPE (specs
))
3473 && equivalent_constraints (cur_constr
, spec_constr
))
3474 return TREE_TYPE (specs
);
3475 specs
= TREE_CHAIN (specs
);
3478 // If no specialization matches, then must return the type
3479 // previously found.
3483 /* Finish processing a template-id (which names a type) of the form
3484 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3485 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3486 the scope of template-id indicated. */
3489 finish_template_type (tree name
, tree args
, int entering_scope
)
3493 type
= lookup_template_class (name
, args
,
3494 NULL_TREE
, NULL_TREE
, entering_scope
,
3495 tf_warning_or_error
| tf_user
);
3497 /* If we might be entering the scope of a partial specialization,
3498 find the one with the right constraints. */
3501 && CLASS_TYPE_P (type
)
3502 && CLASSTYPE_TEMPLATE_INFO (type
)
3503 && dependent_type_p (type
)
3504 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3505 type
= fixup_template_type (type
);
3507 if (type
== error_mark_node
)
3509 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3510 return TYPE_STUB_DECL (type
);
3512 return TYPE_NAME (type
);
3515 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3516 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3517 BASE_CLASS, or NULL_TREE if an error occurred. The
3518 ACCESS_SPECIFIER is one of
3519 access_{default,public,protected_private}_node. For a virtual base
3520 we set TREE_TYPE. */
3523 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3527 if (base
== error_mark_node
)
3529 error ("invalid base-class specification");
3532 else if (! MAYBE_CLASS_TYPE_P (base
))
3534 error ("%qT is not a class type", base
);
3539 if (cp_type_quals (base
) != 0)
3541 /* DR 484: Can a base-specifier name a cv-qualified
3543 base
= TYPE_MAIN_VARIANT (base
);
3545 result
= build_tree_list (access
, base
);
3547 TREE_TYPE (result
) = integer_type_node
;
3553 /* If FNS is a member function, a set of member functions, or a
3554 template-id referring to one or more member functions, return a
3555 BASELINK for FNS, incorporating the current access context.
3556 Otherwise, return FNS unchanged. */
3559 baselink_for_fns (tree fns
)
3564 if (BASELINK_P (fns
)
3565 || error_operand_p (fns
))
3568 scope
= ovl_scope (fns
);
3569 if (!CLASS_TYPE_P (scope
))
3572 cl
= currently_open_derived_class (scope
);
3575 cl
= TYPE_BINFO (cl
);
3576 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3579 /* Returns true iff DECL is a variable from a function outside
3583 outer_var_p (tree decl
)
3585 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3586 && DECL_FUNCTION_SCOPE_P (decl
)
3587 /* Don't get confused by temporaries. */
3589 && (DECL_CONTEXT (decl
) != current_function_decl
3590 || parsing_nsdmi ()));
3593 /* As above, but also checks that DECL is automatic. */
3596 outer_automatic_var_p (tree decl
)
3598 return (outer_var_p (decl
)
3599 && !TREE_STATIC (decl
));
3602 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3603 rewrite it for lambda capture.
3605 If ODR_USE is true, we're being called from mark_use, and we complain about
3606 use of constant variables. If ODR_USE is false, we're being called for the
3607 id-expression, and we do lambda capture. */
3610 process_outer_var_ref (tree decl
, tsubst_flags_t complain
, bool odr_use
)
3612 if (cp_unevaluated_operand
)
3614 tree type
= TREE_TYPE (decl
);
3615 if (!dependent_type_p (type
)
3616 && variably_modified_type_p (type
, NULL_TREE
))
3617 /* VLAs are used even in unevaluated context. */;
3619 /* It's not a use (3.2) if we're in an unevaluated context. */
3622 if (decl
== error_mark_node
)
3625 tree context
= DECL_CONTEXT (decl
);
3626 tree containing_function
= current_function_decl
;
3627 tree lambda_stack
= NULL_TREE
;
3628 tree lambda_expr
= NULL_TREE
;
3629 tree initializer
= convert_from_reference (decl
);
3631 /* Mark it as used now even if the use is ill-formed. */
3632 if (!mark_used (decl
, complain
))
3633 return error_mark_node
;
3635 if (parsing_nsdmi ())
3636 containing_function
= NULL_TREE
;
3638 if (containing_function
&& LAMBDA_FUNCTION_P (containing_function
))
3640 /* Check whether we've already built a proxy. */
3642 while (is_normal_capture_proxy (var
))
3643 var
= DECL_CAPTURED_VARIABLE (var
);
3644 tree d
= retrieve_local_specialization (var
);
3646 if (d
&& d
!= decl
&& is_capture_proxy (d
))
3648 if (DECL_CONTEXT (d
) == containing_function
)
3649 /* We already have an inner proxy. */
3652 /* We need to capture an outer proxy. */
3653 return process_outer_var_ref (d
, complain
, odr_use
);
3657 /* If we are in a lambda function, we can move out until we hit
3659 2. a non-lambda function, or
3660 3. a non-default capturing lambda function. */
3661 while (context
!= containing_function
3662 /* containing_function can be null with invalid generic lambdas. */
3663 && containing_function
3664 && LAMBDA_FUNCTION_P (containing_function
))
3666 tree closure
= DECL_CONTEXT (containing_function
);
3667 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3669 if (TYPE_CLASS_SCOPE_P (closure
))
3670 /* A lambda in an NSDMI (c++/64496). */
3673 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3676 lambda_stack
= tree_cons (NULL_TREE
, lambda_expr
, lambda_stack
);
3678 containing_function
= decl_function_context (containing_function
);
3681 /* In a lambda within a template, wait until instantiation time to implicitly
3682 capture a parameter pack. We want to wait because we don't know if we're
3683 capturing the whole pack or a single element, and it's OK to wait because
3684 find_parameter_packs_r walks into the lambda body. */
3685 if (context
== containing_function
3686 && DECL_PACK_P (decl
))
3689 if (lambda_expr
&& VAR_P (decl
) && DECL_ANON_UNION_VAR_P (decl
))
3691 if (complain
& tf_error
)
3692 error ("cannot capture member %qD of anonymous union", decl
);
3693 return error_mark_node
;
3695 /* Do lambda capture when processing the id-expression, not when
3696 odr-using a variable. */
3697 if (!odr_use
&& context
== containing_function
)
3698 decl
= add_default_capture (lambda_stack
,
3699 /*id=*/DECL_NAME (decl
), initializer
);
3700 /* Only an odr-use of an outer automatic variable causes an
3701 error, and a constant variable can decay to a prvalue
3702 constant without odr-use. So don't complain yet. */
3703 else if (!odr_use
&& decl_constant_var_p (decl
))
3705 else if (lambda_expr
)
3707 if (complain
& tf_error
)
3709 error ("%qD is not captured", decl
);
3710 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3711 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3712 inform (location_of (closure
),
3713 "the lambda has no capture-default");
3714 else if (TYPE_CLASS_SCOPE_P (closure
))
3715 inform (UNKNOWN_LOCATION
, "lambda in local class %q+T cannot "
3716 "capture variables from the enclosing context",
3717 TYPE_CONTEXT (closure
));
3718 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3720 return error_mark_node
;
3724 if (complain
& tf_error
)
3727 ? G_("use of local variable with automatic storage from "
3728 "containing function")
3729 : G_("use of parameter from containing function"));
3730 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3732 return error_mark_node
;
3737 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3738 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3739 if non-NULL, is the type or namespace used to explicitly qualify
3740 ID_EXPRESSION. DECL is the entity to which that name has been
3743 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3744 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3745 be set to true if this expression isn't permitted in a
3746 constant-expression, but it is otherwise not set by this function.
3747 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3748 constant-expression, but a non-constant expression is also
3751 DONE is true if this expression is a complete postfix-expression;
3752 it is false if this expression is followed by '->', '[', '(', etc.
3753 ADDRESS_P is true iff this expression is the operand of '&'.
3754 TEMPLATE_P is true iff the qualified-id was of the form
3755 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3756 appears as a template argument.
3758 If an error occurs, and it is the kind of error that might cause
3759 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3760 is the caller's responsibility to issue the message. *ERROR_MSG
3761 will be a string with static storage duration, so the caller need
3764 Return an expression for the entity, after issuing appropriate
3765 diagnostics. This function is also responsible for transforming a
3766 reference to a non-static member into a COMPONENT_REF that makes
3767 the use of "this" explicit.
3769 Upon return, *IDK will be filled in appropriately. */
3771 finish_id_expression_1 (tree id_expression
,
3775 bool integral_constant_expression_p
,
3776 bool allow_non_integral_constant_expression_p
,
3777 bool *non_integral_constant_expression_p
,
3781 bool template_arg_p
,
3782 const char **error_msg
,
3783 location_t location
)
3785 decl
= strip_using_decl (decl
);
3787 /* Initialize the output parameters. */
3788 *idk
= CP_ID_KIND_NONE
;
3791 if (id_expression
== error_mark_node
)
3792 return error_mark_node
;
3793 /* If we have a template-id, then no further lookup is
3794 required. If the template-id was for a template-class, we
3795 will sometimes have a TYPE_DECL at this point. */
3796 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3797 || TREE_CODE (decl
) == TYPE_DECL
)
3799 /* Look up the name. */
3802 if (decl
== error_mark_node
)
3804 /* Name lookup failed. */
3807 || (!dependent_type_p (scope
)
3808 && !(identifier_p (id_expression
)
3809 && IDENTIFIER_CONV_OP_P (id_expression
)
3810 && dependent_type_p (TREE_TYPE (id_expression
))))))
3812 /* If the qualifying type is non-dependent (and the name
3813 does not name a conversion operator to a dependent
3814 type), issue an error. */
3815 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3816 return error_mark_node
;
3820 /* It may be resolved via Koenig lookup. */
3821 *idk
= CP_ID_KIND_UNQUALIFIED
;
3822 return id_expression
;
3825 decl
= id_expression
;
3828 /* Remember that the name was used in the definition of
3829 the current class so that we can check later to see if
3830 the meaning would have been different after the class
3831 was entirely defined. */
3832 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3833 maybe_note_name_used_in_class (id_expression
, decl
);
3835 /* A use in unevaluated operand might not be instantiated appropriately
3836 if tsubst_copy builds a dummy parm, or if we never instantiate a
3837 generic lambda, so mark it now. */
3838 if (processing_template_decl
&& cp_unevaluated_operand
)
3839 mark_type_use (decl
);
3841 /* Disallow uses of local variables from containing functions, except
3842 within lambda-expressions. */
3843 if (outer_automatic_var_p (decl
))
3845 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3846 if (decl
== error_mark_node
)
3847 return error_mark_node
;
3850 /* Also disallow uses of function parameters outside the function
3851 body, except inside an unevaluated context (i.e. decltype). */
3852 if (TREE_CODE (decl
) == PARM_DECL
3853 && DECL_CONTEXT (decl
) == NULL_TREE
3854 && !cp_unevaluated_operand
)
3856 *error_msg
= G_("use of parameter outside function body");
3857 return error_mark_node
;
3861 /* If we didn't find anything, or what we found was a type,
3862 then this wasn't really an id-expression. */
3863 if (TREE_CODE (decl
) == TEMPLATE_DECL
3864 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3866 *error_msg
= G_("missing template arguments");
3867 return error_mark_node
;
3869 else if (TREE_CODE (decl
) == TYPE_DECL
3870 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3872 *error_msg
= G_("expected primary-expression");
3873 return error_mark_node
;
3876 /* If the name resolved to a template parameter, there is no
3877 need to look it up again later. */
3878 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3879 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3883 *idk
= CP_ID_KIND_NONE
;
3884 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3885 decl
= TEMPLATE_PARM_DECL (decl
);
3886 r
= DECL_INITIAL (decl
);
3887 if (CLASS_TYPE_P (TREE_TYPE (r
)) && !CP_TYPE_CONST_P (TREE_TYPE (r
)))
3889 /* If the entity is a template parameter object for a template
3890 parameter of type T, the type of the expression is const T. */
3891 tree ctype
= TREE_TYPE (r
);
3892 ctype
= cp_build_qualified_type (ctype
, (cp_type_quals (ctype
)
3893 | TYPE_QUAL_CONST
));
3894 r
= build1 (VIEW_CONVERT_EXPR
, ctype
, r
);
3896 r
= convert_from_reference (r
);
3897 if (integral_constant_expression_p
3898 && !dependent_type_p (TREE_TYPE (decl
))
3899 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3901 if (!allow_non_integral_constant_expression_p
)
3902 error ("template parameter %qD of type %qT is not allowed in "
3903 "an integral constant expression because it is not of "
3904 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3905 *non_integral_constant_expression_p
= true;
3911 bool dependent_p
= type_dependent_expression_p (decl
);
3913 /* If the declaration was explicitly qualified indicate
3914 that. The semantics of `A::f(3)' are different than
3915 `f(3)' if `f' is virtual. */
3917 ? CP_ID_KIND_QUALIFIED
3918 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3919 ? CP_ID_KIND_TEMPLATE_ID
3921 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3922 : CP_ID_KIND_UNQUALIFIED
)));
3926 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
3927 /* Dependent type attributes on the decl mean that the TREE_TYPE is
3928 wrong, so just return the identifier. */
3929 return id_expression
;
3931 if (DECL_CLASS_TEMPLATE_P (decl
))
3933 error ("use of class template %qT as expression", decl
);
3934 return error_mark_node
;
3937 if (TREE_CODE (decl
) == TREE_LIST
)
3939 /* Ambiguous reference to base members. */
3940 error ("request for member %qD is ambiguous in "
3941 "multiple inheritance lattice", id_expression
);
3942 print_candidates (decl
);
3943 return error_mark_node
;
3946 /* Mark variable-like entities as used. Functions are similarly
3947 marked either below or after overload resolution. */
3949 || TREE_CODE (decl
) == PARM_DECL
3950 || TREE_CODE (decl
) == CONST_DECL
3951 || TREE_CODE (decl
) == RESULT_DECL
)
3952 && !mark_used (decl
))
3953 return error_mark_node
;
3955 /* Only certain kinds of names are allowed in constant
3956 expression. Template parameters have already
3957 been handled above. */
3958 if (! error_operand_p (decl
)
3960 && integral_constant_expression_p
3961 && !decl_constant_var_p (decl
)
3962 && TREE_CODE (decl
) != CONST_DECL
3963 && !builtin_valid_in_constant_expr_p (decl
)
3964 && !concept_check_p (decl
))
3966 if (!allow_non_integral_constant_expression_p
)
3968 error ("%qD cannot appear in a constant-expression", decl
);
3969 return error_mark_node
;
3971 *non_integral_constant_expression_p
= true;
3974 if (tree wrap
= maybe_get_tls_wrapper_call (decl
))
3975 /* Replace an evaluated use of the thread_local variable with
3976 a call to its wrapper. */
3978 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3980 && variable_template_p (TREE_OPERAND (decl
, 0))
3981 && !concept_check_p (decl
))
3983 decl
= finish_template_variable (decl
);
3985 decl
= convert_from_reference (decl
);
3987 else if (concept_check_p (decl
))
3989 /* Nothing more to do. All of the analysis for concept checks
3990 is done by build_conept_id, called from the parser. */
3994 if (TREE_CODE (decl
) == SCOPE_REF
)
3996 gcc_assert (same_type_p (scope
, TREE_OPERAND (decl
, 0)));
3997 decl
= TREE_OPERAND (decl
, 1);
4000 decl
= (adjust_result_of_qualified_name_lookup
4001 (decl
, scope
, current_nonlambda_class_type()));
4003 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4006 cp_warn_deprecated_use_scopes (scope
);
4009 decl
= finish_qualified_id_expr (scope
,
4015 tf_warning_or_error
);
4017 decl
= convert_from_reference (decl
);
4019 else if (TREE_CODE (decl
) == FIELD_DECL
)
4021 /* Since SCOPE is NULL here, this is an unqualified name.
4022 Access checking has been performed during name lookup
4023 already. Turn off checking to avoid duplicate errors. */
4024 push_deferring_access_checks (dk_no_check
);
4025 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
4026 /*qualifying_scope=*/NULL_TREE
);
4027 pop_deferring_access_checks ();
4029 else if (is_overloaded_fn (decl
))
4031 /* We only need to look at the first function,
4032 because all the fns share the attribute we're
4033 concerned with (all member fns or all non-members). */
4034 tree first_fn
= get_first_fn (decl
);
4035 first_fn
= STRIP_TEMPLATE (first_fn
);
4037 /* [basic.def.odr]: "A function whose name appears as a
4038 potentially-evaluated expression is odr-used if it is the unique
4041 But only mark it if it's a complete postfix-expression; in a call,
4042 ADL might select a different function, and we'll call mark_used in
4045 && !really_overloaded_fn (decl
)
4046 && !mark_used (first_fn
))
4047 return error_mark_node
;
4050 && (TREE_CODE (first_fn
) == USING_DECL
4051 || (TREE_CODE (first_fn
) == FUNCTION_DECL
4052 && DECL_FUNCTION_MEMBER_P (first_fn
)
4053 && !shared_member_p (decl
))))
4055 /* A set of member functions. */
4056 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
4057 return finish_class_member_access_expr (decl
, id_expression
,
4058 /*template_p=*/false,
4059 tf_warning_or_error
);
4062 decl
= baselink_for_fns (decl
);
4066 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
4067 && DECL_CLASS_SCOPE_P (decl
))
4069 tree context
= context_for_name_lookup (decl
);
4070 if (context
!= current_class_type
)
4072 tree path
= currently_open_derived_class (context
);
4074 /* PATH can be null for using an enum of an unrelated
4075 class; we checked its access in lookup_using_decl.
4077 ??? Should this case make a clone instead, like
4078 handle_using_decl? */
4079 gcc_assert (TREE_CODE (decl
) == CONST_DECL
);
4081 perform_or_defer_access_check (TYPE_BINFO (path
),
4083 tf_warning_or_error
);
4087 decl
= convert_from_reference (decl
);
4091 return cp_expr (decl
, location
);
4094 /* As per finish_id_expression_1, but adding a wrapper node
4095 around the result if needed to express LOCATION. */
4098 finish_id_expression (tree id_expression
,
4102 bool integral_constant_expression_p
,
4103 bool allow_non_integral_constant_expression_p
,
4104 bool *non_integral_constant_expression_p
,
4108 bool template_arg_p
,
4109 const char **error_msg
,
4110 location_t location
)
4113 = finish_id_expression_1 (id_expression
, decl
, scope
, idk
,
4114 integral_constant_expression_p
,
4115 allow_non_integral_constant_expression_p
,
4116 non_integral_constant_expression_p
,
4117 template_p
, done
, address_p
, template_arg_p
,
4118 error_msg
, location
);
4119 return result
.maybe_add_location_wrapper ();
4122 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
4123 use as a type-specifier. */
4126 finish_typeof (tree expr
)
4130 if (type_dependent_expression_p (expr
))
4132 type
= cxx_make_type (TYPEOF_TYPE
);
4133 TYPEOF_TYPE_EXPR (type
) = expr
;
4134 SET_TYPE_STRUCTURAL_EQUALITY (type
);
4139 expr
= mark_type_use (expr
);
4141 type
= unlowered_expr_type (expr
);
4143 if (!type
|| type
== unknown_type_node
)
4145 error ("type of %qE is unknown", expr
);
4146 return error_mark_node
;
4152 /* Implement the __underlying_type keyword: Return the underlying
4153 type of TYPE, suitable for use as a type-specifier. */
4156 finish_underlying_type (tree type
)
4158 tree underlying_type
;
4160 if (processing_template_decl
)
4162 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
4163 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
4164 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
4166 return underlying_type
;
4169 if (!complete_type_or_else (type
, NULL_TREE
))
4170 return error_mark_node
;
4172 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
4174 error ("%qT is not an enumeration type", type
);
4175 return error_mark_node
;
4178 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
4180 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
4181 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
4182 See finish_enum_value_list for details. */
4183 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
4185 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
4186 TYPE_UNSIGNED (underlying_type
));
4188 return underlying_type
;
4191 /* Implement the __direct_bases keyword: Return the direct base classes
4195 calculate_direct_bases (tree type
, tsubst_flags_t complain
)
4197 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4198 || !NON_UNION_CLASS_TYPE_P (type
))
4199 return make_tree_vec (0);
4201 releasing_vec vector
;
4202 vec
<tree
, va_gc
> *base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
4206 /* Virtual bases are initialized first */
4207 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4208 if (BINFO_VIRTUAL_P (binfo
))
4209 vec_safe_push (vector
, binfo
);
4211 /* Now non-virtuals */
4212 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4213 if (!BINFO_VIRTUAL_P (binfo
))
4214 vec_safe_push (vector
, binfo
);
4216 tree bases_vec
= make_tree_vec (vector
->length ());
4218 for (i
= 0; i
< vector
->length (); ++i
)
4219 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
4224 /* Implement the __bases keyword: Return the base classes
4227 /* Find morally non-virtual base classes by walking binfo hierarchy */
4228 /* Virtual base classes are handled separately in finish_bases */
4231 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
4233 /* Don't walk bases of virtual bases */
4234 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
4238 dfs_calculate_bases_post (tree binfo
, void *data_
)
4240 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
4241 if (!BINFO_VIRTUAL_P (binfo
))
4242 vec_safe_push (*data
, BINFO_TYPE (binfo
));
4246 /* Calculates the morally non-virtual base classes of a class */
4247 static vec
<tree
, va_gc
> *
4248 calculate_bases_helper (tree type
)
4250 vec
<tree
, va_gc
> *vector
= make_tree_vector ();
4252 /* Now add non-virtual base classes in order of construction */
4253 if (TYPE_BINFO (type
))
4254 dfs_walk_all (TYPE_BINFO (type
),
4255 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
4260 calculate_bases (tree type
, tsubst_flags_t complain
)
4262 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4263 || !NON_UNION_CLASS_TYPE_P (type
))
4264 return make_tree_vec (0);
4266 releasing_vec vector
;
4267 tree bases_vec
= NULL_TREE
;
4269 vec
<tree
, va_gc
> *vbases
;
4272 /* First go through virtual base classes */
4273 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
4274 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
4276 releasing_vec vbase_bases
4277 = calculate_bases_helper (BINFO_TYPE (binfo
));
4278 vec_safe_splice (vector
, vbase_bases
);
4281 /* Now for the non-virtual bases */
4282 releasing_vec nonvbases
= calculate_bases_helper (type
);
4283 vec_safe_splice (vector
, nonvbases
);
4285 /* Note that during error recovery vector->length can even be zero. */
4286 if (vector
->length () > 1)
4288 /* Last element is entire class, so don't copy */
4289 bases_vec
= make_tree_vec (vector
->length () - 1);
4291 for (i
= 0; i
< vector
->length () - 1; ++i
)
4292 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
4295 bases_vec
= make_tree_vec (0);
4301 finish_bases (tree type
, bool direct
)
4303 tree bases
= NULL_TREE
;
4305 if (!processing_template_decl
)
4307 /* Parameter packs can only be used in templates */
4308 error ("parameter pack %<__bases%> only valid in template declaration");
4309 return error_mark_node
;
4312 bases
= cxx_make_type (BASES
);
4313 BASES_TYPE (bases
) = type
;
4314 BASES_DIRECT (bases
) = direct
;
4315 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
4320 /* Perform C++-specific checks for __builtin_offsetof before calling
4324 finish_offsetof (tree object_ptr
, tree expr
, location_t loc
)
4326 /* If we're processing a template, we can't finish the semantics yet.
4327 Otherwise we can fold the entire expression now. */
4328 if (processing_template_decl
)
4330 expr
= build2 (OFFSETOF_EXPR
, size_type_node
, expr
, object_ptr
);
4331 SET_EXPR_LOCATION (expr
, loc
);
4335 if (expr
== error_mark_node
)
4336 return error_mark_node
;
4338 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4340 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4341 TREE_OPERAND (expr
, 2));
4342 return error_mark_node
;
4344 if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr
))
4345 || TREE_TYPE (expr
) == unknown_type_node
)
4347 while (TREE_CODE (expr
) == COMPONENT_REF
4348 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4349 expr
= TREE_OPERAND (expr
, 1);
4353 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4354 inform (DECL_SOURCE_LOCATION (expr
), "declared here");
4357 error ("cannot apply %<offsetof%> to member function");
4358 return error_mark_node
;
4360 if (TREE_CODE (expr
) == CONST_DECL
)
4362 error ("cannot apply %<offsetof%> to an enumerator %qD", expr
);
4363 return error_mark_node
;
4365 if (REFERENCE_REF_P (expr
))
4366 expr
= TREE_OPERAND (expr
, 0);
4367 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr
)), object_ptr
))
4368 return error_mark_node
;
4369 if (warn_invalid_offsetof
4370 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr
)))
4371 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr
)))
4372 && cp_unevaluated_operand
== 0)
4373 warning_at (loc
, OPT_Winvalid_offsetof
, "%<offsetof%> within "
4374 "non-standard-layout type %qT is conditionally-supported",
4375 TREE_TYPE (TREE_TYPE (object_ptr
)));
4376 return fold_offsetof (expr
);
4379 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4380 function is broken out from the above for the benefit of the tree-ssa
4384 simplify_aggr_init_expr (tree
*tp
)
4386 tree aggr_init_expr
= *tp
;
4388 /* Form an appropriate CALL_EXPR. */
4389 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4390 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4391 tree type
= TREE_TYPE (slot
);
4394 enum style_t
{ ctor
, arg
, pcc
} style
;
4396 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4398 #ifdef PCC_STATIC_STRUCT_RETURN
4404 gcc_assert (TREE_ADDRESSABLE (type
));
4408 call_expr
= build_call_array_loc (input_location
,
4409 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4411 aggr_init_expr_nargs (aggr_init_expr
),
4412 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4413 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4414 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4415 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4416 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4417 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4418 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4422 /* Replace the first argument to the ctor with the address of the
4424 cxx_mark_addressable (slot
);
4425 CALL_EXPR_ARG (call_expr
, 0) =
4426 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4428 else if (style
== arg
)
4430 /* Just mark it addressable here, and leave the rest to
4431 expand_call{,_inline}. */
4432 cxx_mark_addressable (slot
);
4433 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4434 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4436 else if (style
== pcc
)
4438 /* If we're using the non-reentrant PCC calling convention, then we
4439 need to copy the returned value out of the static buffer into the
4441 push_deferring_access_checks (dk_no_check
);
4442 call_expr
= build_aggr_init (slot
, call_expr
,
4443 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4444 tf_warning_or_error
);
4445 pop_deferring_access_checks ();
4446 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4449 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4451 tree init
= build_zero_init (type
, NULL_TREE
,
4452 /*static_storage_p=*/false);
4453 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4454 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4461 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4464 emit_associated_thunks (tree fn
)
4466 /* When we use vcall offsets, we emit thunks with the virtual
4467 functions to which they thunk. The whole point of vcall offsets
4468 is so that you can know statically the entire set of thunks that
4469 will ever be needed for a given virtual function, thereby
4470 enabling you to output all the thunks with the function itself. */
4471 if (DECL_VIRTUAL_P (fn
)
4472 /* Do not emit thunks for extern template instantiations. */
4473 && ! DECL_REALLY_EXTERN (fn
))
4477 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4479 if (!THUNK_ALIAS (thunk
))
4481 use_thunk (thunk
, /*emit_p=*/1);
4482 if (DECL_RESULT_THUNK_P (thunk
))
4486 for (probe
= DECL_THUNKS (thunk
);
4487 probe
; probe
= DECL_CHAIN (probe
))
4488 use_thunk (probe
, /*emit_p=*/1);
4492 gcc_assert (!DECL_THUNKS (thunk
));
4497 /* Generate RTL for FN. */
4500 expand_or_defer_fn_1 (tree fn
)
4502 /* When the parser calls us after finishing the body of a template
4503 function, we don't really want to expand the body. */
4504 if (processing_template_decl
)
4506 /* Normally, collection only occurs in rest_of_compilation. So,
4507 if we don't collect here, we never collect junk generated
4508 during the processing of templates until we hit a
4509 non-template function. It's not safe to do this inside a
4510 nested class, though, as the parser may have local state that
4511 is not a GC root. */
4512 if (!function_depth
)
4517 gcc_assert (DECL_SAVED_TREE (fn
));
4519 /* We make a decision about linkage for these functions at the end
4520 of the compilation. Until that point, we do not want the back
4521 end to output them -- but we do want it to see the bodies of
4522 these functions so that it can inline them as appropriate. */
4523 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4525 if (DECL_INTERFACE_KNOWN (fn
))
4526 /* We've already made a decision as to how this function will
4529 || DECL_IMMEDIATE_FUNCTION_P (fn
)
4530 || DECL_OMP_DECLARE_REDUCTION_P (fn
))
4531 tentative_decl_linkage (fn
);
4533 import_export_decl (fn
);
4535 /* If the user wants us to keep all inline functions, then mark
4536 this function as needed so that finish_file will make sure to
4537 output it later. Similarly, all dllexport'd functions must
4538 be emitted; there may be callers in other DLLs. */
4539 if (DECL_DECLARED_INLINE_P (fn
)
4540 && !DECL_REALLY_EXTERN (fn
)
4541 && !DECL_IMMEDIATE_FUNCTION_P (fn
)
4542 && !DECL_OMP_DECLARE_REDUCTION_P (fn
)
4543 && (flag_keep_inline_functions
4544 || (flag_keep_inline_dllexport
4545 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4548 DECL_EXTERNAL (fn
) = 0;
4552 /* If this is a constructor or destructor body, we have to clone
4554 if (maybe_clone_body (fn
))
4556 /* We don't want to process FN again, so pretend we've written
4557 it out, even though we haven't. */
4558 TREE_ASM_WRITTEN (fn
) = 1;
4559 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4560 if (!DECL_DECLARED_CONSTEXPR_P (fn
)
4561 && !(modules_p () && DECL_DECLARED_INLINE_P (fn
)))
4562 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4566 /* There's no reason to do any of the work here if we're only doing
4567 semantic analysis; this code just generates RTL. */
4568 if (flag_syntax_only
)
4570 /* Pretend that this function has been written out so that we don't try
4571 to expand it again. */
4572 TREE_ASM_WRITTEN (fn
) = 1;
4576 if (DECL_OMP_DECLARE_REDUCTION_P (fn
))
4583 expand_or_defer_fn (tree fn
)
4585 if (expand_or_defer_fn_1 (fn
))
4589 /* Expand or defer, at the whim of the compilation unit manager. */
4590 cgraph_node::finalize_function (fn
, function_depth
> 1);
4591 emit_associated_thunks (fn
);
4600 nrv_data () : visited (37) {}
4604 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4607 /* Helper function for walk_tree, used by finalize_nrv below. */
4610 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4612 class nrv_data
*dp
= (class nrv_data
*)data
;
4615 /* No need to walk into types. There wouldn't be any need to walk into
4616 non-statements, except that we have to consider STMT_EXPRs. */
4619 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4620 but differs from using NULL_TREE in that it indicates that we care
4621 about the value of the RESULT_DECL. */
4622 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4623 TREE_OPERAND (*tp
, 0) = dp
->result
;
4624 /* Change all cleanups for the NRV to only run when an exception is
4626 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4627 && CLEANUP_DECL (*tp
) == dp
->var
)
4628 CLEANUP_EH_ONLY (*tp
) = 1;
4629 /* Replace the DECL_EXPR for the NRV with an initialization of the
4630 RESULT_DECL, if needed. */
4631 else if (TREE_CODE (*tp
) == DECL_EXPR
4632 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4635 if (DECL_INITIAL (dp
->var
)
4636 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4637 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4638 DECL_INITIAL (dp
->var
));
4640 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4641 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4642 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4645 /* And replace all uses of the NRV with the RESULT_DECL. */
4646 else if (*tp
== dp
->var
)
4649 /* Avoid walking into the same tree more than once. Unfortunately, we
4650 can't just use walk_tree_without duplicates because it would only call
4651 us for the first occurrence of dp->var in the function body. */
4652 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4658 /* Keep iterating. */
4662 /* Called from finish_function to implement the named return value
4663 optimization by overriding all the RETURN_EXPRs and pertinent
4664 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4665 RESULT_DECL for the function. */
4668 finalize_nrv (tree
*tp
, tree var
, tree result
)
4670 class nrv_data data
;
4672 /* Copy name from VAR to RESULT. */
4673 DECL_NAME (result
) = DECL_NAME (var
);
4674 /* Don't forget that we take its address. */
4675 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4676 /* Finally set DECL_VALUE_EXPR to avoid assigning
4677 a stack slot at -O0 for the original var and debug info
4678 uses RESULT location for VAR. */
4679 SET_DECL_VALUE_EXPR (var
, result
);
4680 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4683 data
.result
= result
;
4684 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4687 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4690 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4691 bool need_copy_ctor
, bool need_copy_assignment
,
4694 int save_errorcount
= errorcount
;
4697 /* Always allocate 3 elements for simplicity. These are the
4698 function decls for the ctor, dtor, and assignment op.
4699 This layout is known to the three lang hooks,
4700 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4701 and cxx_omp_clause_assign_op. */
4702 info
= make_tree_vec (3);
4703 CP_OMP_CLAUSE_INFO (c
) = info
;
4705 if (need_default_ctor
|| need_copy_ctor
)
4707 if (need_default_ctor
)
4708 t
= get_default_ctor (type
);
4710 t
= get_copy_ctor (type
, tf_warning_or_error
);
4712 if (t
&& !trivial_fn_p (t
))
4713 TREE_VEC_ELT (info
, 0) = t
;
4716 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4717 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4719 if (need_copy_assignment
)
4721 t
= get_copy_assign (type
);
4723 if (t
&& !trivial_fn_p (t
))
4724 TREE_VEC_ELT (info
, 2) = t
;
4727 return errorcount
!= save_errorcount
;
4730 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4731 FIELD_DECL, otherwise return DECL itself. */
4734 omp_clause_decl_field (tree decl
)
4737 && DECL_HAS_VALUE_EXPR_P (decl
)
4738 && DECL_ARTIFICIAL (decl
)
4739 && DECL_LANG_SPECIFIC (decl
)
4740 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4742 tree f
= DECL_VALUE_EXPR (decl
);
4743 if (INDIRECT_REF_P (f
))
4744 f
= TREE_OPERAND (f
, 0);
4745 if (TREE_CODE (f
) == COMPONENT_REF
)
4747 f
= TREE_OPERAND (f
, 1);
4748 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4755 /* Adjust DECL if needed for printing using %qE. */
4758 omp_clause_printable_decl (tree decl
)
4760 tree t
= omp_clause_decl_field (decl
);
4766 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4767 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4771 omp_note_field_privatization (tree f
, tree t
)
4773 if (!omp_private_member_map
)
4774 omp_private_member_map
= new hash_map
<tree
, tree
>;
4775 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4779 omp_private_member_vec
.safe_push (f
);
4780 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4781 omp_private_member_vec
.safe_push (integer_zero_node
);
4785 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4789 omp_privatize_field (tree t
, bool shared
)
4791 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4792 if (m
== error_mark_node
)
4793 return error_mark_node
;
4794 if (!omp_private_member_map
&& !shared
)
4795 omp_private_member_map
= new hash_map
<tree
, tree
>;
4796 if (TYPE_REF_P (TREE_TYPE (t
)))
4798 gcc_assert (INDIRECT_REF_P (m
));
4799 m
= TREE_OPERAND (m
, 0);
4801 tree vb
= NULL_TREE
;
4802 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4805 v
= create_temporary_var (TREE_TYPE (m
));
4806 retrofit_lang_decl (v
);
4807 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4808 SET_DECL_VALUE_EXPR (v
, m
);
4809 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4811 omp_private_member_vec
.safe_push (t
);
4816 /* Helper function for handle_omp_array_sections. Called recursively
4817 to handle multiple array-section-subscripts. C is the clause,
4818 T current expression (initially OMP_CLAUSE_DECL), which is either
4819 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4820 expression if specified, TREE_VALUE length expression if specified,
4821 TREE_CHAIN is what it has been specified after, or some decl.
4822 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4823 set to true if any of the array-section-subscript could have length
4824 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4825 first array-section-subscript which is known not to have length
4827 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4828 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4829 all are or may have length of 1, array-section-subscript [:2] is the
4830 first one known not to have length 1. For array-section-subscript
4831 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4832 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4833 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4834 case though, as some lengths could be zero. */
4837 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4838 bool &maybe_zero_len
, unsigned int &first_non_one
,
4839 enum c_omp_region_type ort
)
4841 tree ret
, low_bound
, length
, type
;
4842 if (TREE_CODE (t
) != TREE_LIST
)
4844 if (error_operand_p (t
))
4845 return error_mark_node
;
4846 if (REFERENCE_REF_P (t
)
4847 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4848 t
= TREE_OPERAND (t
, 0);
4850 if (TREE_CODE (t
) == COMPONENT_REF
4851 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4852 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
4853 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
4854 && !type_dependent_expression_p (t
))
4856 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
4857 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
4859 error_at (OMP_CLAUSE_LOCATION (c
),
4860 "bit-field %qE in %qs clause",
4861 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4862 return error_mark_node
;
4864 while (TREE_CODE (t
) == COMPONENT_REF
)
4866 if (TREE_TYPE (TREE_OPERAND (t
, 0))
4867 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
4869 error_at (OMP_CLAUSE_LOCATION (c
),
4870 "%qE is a member of a union", t
);
4871 return error_mark_node
;
4873 t
= TREE_OPERAND (t
, 0);
4874 if (ort
== C_ORT_ACC
&& TREE_CODE (t
) == INDIRECT_REF
)
4875 t
= TREE_OPERAND (t
, 0);
4877 if (REFERENCE_REF_P (t
))
4878 t
= TREE_OPERAND (t
, 0);
4880 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
4882 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
4885 error_at (OMP_CLAUSE_LOCATION (c
),
4886 "%qD is not a variable in %qs clause", t
,
4887 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4889 error_at (OMP_CLAUSE_LOCATION (c
),
4890 "%qE is not a variable in %qs clause", t
,
4891 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4892 return error_mark_node
;
4894 else if (ort
== C_ORT_OMP
4895 && TREE_CODE (t
) == PARM_DECL
4896 && DECL_ARTIFICIAL (t
)
4897 && DECL_NAME (t
) == this_identifier
)
4899 error_at (OMP_CLAUSE_LOCATION (c
),
4900 "%<this%> allowed in OpenMP only in %<declare simd%>"
4902 return error_mark_node
;
4904 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4905 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
4907 error_at (OMP_CLAUSE_LOCATION (c
),
4908 "%qD is threadprivate variable in %qs clause", t
,
4909 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4910 return error_mark_node
;
4912 if (type_dependent_expression_p (ret
))
4914 ret
= convert_from_reference (ret
);
4918 if (ort
== C_ORT_OMP
4919 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4920 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4921 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4922 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
4923 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
4924 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4925 maybe_zero_len
, first_non_one
, ort
);
4926 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4929 type
= TREE_TYPE (ret
);
4930 low_bound
= TREE_PURPOSE (t
);
4931 length
= TREE_VALUE (t
);
4932 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4933 || (length
&& type_dependent_expression_p (length
)))
4936 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4937 return error_mark_node
;
4939 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4941 error_at (OMP_CLAUSE_LOCATION (c
),
4942 "low bound %qE of array section does not have integral type",
4944 return error_mark_node
;
4946 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4948 error_at (OMP_CLAUSE_LOCATION (c
),
4949 "length %qE of array section does not have integral type",
4951 return error_mark_node
;
4954 low_bound
= mark_rvalue_use (low_bound
);
4956 length
= mark_rvalue_use (length
);
4957 /* We need to reduce to real constant-values for checks below. */
4959 length
= fold_simple (length
);
4961 low_bound
= fold_simple (low_bound
);
4963 && TREE_CODE (low_bound
) == INTEGER_CST
4964 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4965 > TYPE_PRECISION (sizetype
))
4966 low_bound
= fold_convert (sizetype
, low_bound
);
4968 && TREE_CODE (length
) == INTEGER_CST
4969 && TYPE_PRECISION (TREE_TYPE (length
))
4970 > TYPE_PRECISION (sizetype
))
4971 length
= fold_convert (sizetype
, length
);
4972 if (low_bound
== NULL_TREE
)
4973 low_bound
= integer_zero_node
;
4975 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4976 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
4977 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
4979 if (length
!= integer_one_node
)
4981 error_at (OMP_CLAUSE_LOCATION (c
),
4982 "expected single pointer in %qs clause",
4983 c_omp_map_clause_name (c
, ort
== C_ORT_ACC
));
4984 return error_mark_node
;
4987 if (length
!= NULL_TREE
)
4989 if (!integer_nonzerop (length
))
4991 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4992 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4993 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4994 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4996 if (integer_zerop (length
))
4998 error_at (OMP_CLAUSE_LOCATION (c
),
4999 "zero length array section in %qs clause",
5000 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5001 return error_mark_node
;
5005 maybe_zero_len
= true;
5007 if (first_non_one
== types
.length ()
5008 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
5011 if (TREE_CODE (type
) == ARRAY_TYPE
)
5013 if (length
== NULL_TREE
5014 && (TYPE_DOMAIN (type
) == NULL_TREE
5015 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
5017 error_at (OMP_CLAUSE_LOCATION (c
),
5018 "for unknown bound array type length expression must "
5020 return error_mark_node
;
5022 if (TREE_CODE (low_bound
) == INTEGER_CST
5023 && tree_int_cst_sgn (low_bound
) == -1)
5025 error_at (OMP_CLAUSE_LOCATION (c
),
5026 "negative low bound in array section in %qs clause",
5027 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5028 return error_mark_node
;
5030 if (length
!= NULL_TREE
5031 && TREE_CODE (length
) == INTEGER_CST
5032 && tree_int_cst_sgn (length
) == -1)
5034 error_at (OMP_CLAUSE_LOCATION (c
),
5035 "negative length in array section in %qs clause",
5036 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5037 return error_mark_node
;
5039 if (TYPE_DOMAIN (type
)
5040 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
5041 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
5045 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
5046 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
5047 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5049 if (tree_int_cst_lt (size
, low_bound
))
5051 error_at (OMP_CLAUSE_LOCATION (c
),
5052 "low bound %qE above array section size "
5053 "in %qs clause", low_bound
,
5054 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5055 return error_mark_node
;
5057 if (tree_int_cst_equal (size
, low_bound
))
5059 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5060 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5061 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5062 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5064 error_at (OMP_CLAUSE_LOCATION (c
),
5065 "zero length array section in %qs clause",
5066 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5067 return error_mark_node
;
5069 maybe_zero_len
= true;
5071 else if (length
== NULL_TREE
5072 && first_non_one
== types
.length ()
5073 && tree_int_cst_equal
5074 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
5078 else if (length
== NULL_TREE
)
5080 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5081 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5082 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5083 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5084 maybe_zero_len
= true;
5085 if (first_non_one
== types
.length ())
5088 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
5090 if (tree_int_cst_lt (size
, length
))
5092 error_at (OMP_CLAUSE_LOCATION (c
),
5093 "length %qE above array section size "
5094 "in %qs clause", length
,
5095 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5096 return error_mark_node
;
5098 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5101 = size_binop (PLUS_EXPR
,
5102 fold_convert (sizetype
, low_bound
),
5103 fold_convert (sizetype
, length
));
5104 if (TREE_CODE (lbpluslen
) == INTEGER_CST
5105 && tree_int_cst_lt (size
, lbpluslen
))
5107 error_at (OMP_CLAUSE_LOCATION (c
),
5108 "high bound %qE above array section size "
5109 "in %qs clause", lbpluslen
,
5110 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5111 return error_mark_node
;
5116 else if (length
== NULL_TREE
)
5118 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5119 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5120 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5121 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5122 maybe_zero_len
= true;
5123 if (first_non_one
== types
.length ())
5127 /* For [lb:] we will need to evaluate lb more than once. */
5128 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5130 tree lb
= cp_save_expr (low_bound
);
5131 if (lb
!= low_bound
)
5133 TREE_PURPOSE (t
) = lb
;
5138 else if (TYPE_PTR_P (type
))
5140 if (length
== NULL_TREE
)
5142 if (TREE_CODE (ret
) == PARM_DECL
&& DECL_ARRAY_PARAMETER_P (ret
))
5143 error_at (OMP_CLAUSE_LOCATION (c
),
5144 "for array function parameter length expression "
5145 "must be specified");
5147 error_at (OMP_CLAUSE_LOCATION (c
),
5148 "for pointer type length expression must be specified");
5149 return error_mark_node
;
5151 if (length
!= NULL_TREE
5152 && TREE_CODE (length
) == INTEGER_CST
5153 && tree_int_cst_sgn (length
) == -1)
5155 error_at (OMP_CLAUSE_LOCATION (c
),
5156 "negative length in array section in %qs clause",
5157 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5158 return error_mark_node
;
5160 /* If there is a pointer type anywhere but in the very first
5161 array-section-subscript, the array section can't be contiguous. */
5162 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5163 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
5165 error_at (OMP_CLAUSE_LOCATION (c
),
5166 "array section is not contiguous in %qs clause",
5167 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5168 return error_mark_node
;
5173 error_at (OMP_CLAUSE_LOCATION (c
),
5174 "%qE does not have pointer or array type", ret
);
5175 return error_mark_node
;
5177 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5178 types
.safe_push (TREE_TYPE (ret
));
5179 /* We will need to evaluate lb more than once. */
5180 tree lb
= cp_save_expr (low_bound
);
5181 if (lb
!= low_bound
)
5183 TREE_PURPOSE (t
) = lb
;
5186 /* Temporarily disable -fstrong-eval-order for array reductions.
5187 The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
5188 is something the middle-end can't cope with and more importantly,
5189 it needs to be the actual base variable that is privatized, not some
5190 temporary assigned previous value of it. That, together with OpenMP
5191 saying how many times the side-effects are evaluated is unspecified,
5192 makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
5193 warning_sentinel
s (flag_strong_eval_order
,
5194 OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5195 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5196 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
);
5197 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
5201 /* Handle array sections for clause C. */
5204 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
5206 bool maybe_zero_len
= false;
5207 unsigned int first_non_one
= 0;
5208 auto_vec
<tree
, 10> types
;
5209 tree
*tp
= &OMP_CLAUSE_DECL (c
);
5210 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5211 && TREE_CODE (*tp
) == TREE_LIST
5212 && TREE_PURPOSE (*tp
)
5213 && TREE_CODE (TREE_PURPOSE (*tp
)) == TREE_VEC
)
5214 tp
= &TREE_VALUE (*tp
);
5215 tree first
= handle_omp_array_sections_1 (c
, *tp
, types
,
5216 maybe_zero_len
, first_non_one
,
5218 if (first
== error_mark_node
)
5220 if (first
== NULL_TREE
)
5222 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
5225 tree tem
= NULL_TREE
;
5226 if (processing_template_decl
)
5228 /* Need to evaluate side effects in the length expressions
5230 while (TREE_CODE (t
) == TREE_LIST
)
5232 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
5234 if (tem
== NULL_TREE
)
5235 tem
= TREE_VALUE (t
);
5237 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
5238 TREE_VALUE (t
), tem
);
5243 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
5248 unsigned int num
= types
.length (), i
;
5249 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
5250 tree condition
= NULL_TREE
;
5252 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
5253 maybe_zero_len
= true;
5254 if (processing_template_decl
&& maybe_zero_len
)
5257 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
5260 tree low_bound
= TREE_PURPOSE (t
);
5261 tree length
= TREE_VALUE (t
);
5265 && TREE_CODE (low_bound
) == INTEGER_CST
5266 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5267 > TYPE_PRECISION (sizetype
))
5268 low_bound
= fold_convert (sizetype
, low_bound
);
5270 && TREE_CODE (length
) == INTEGER_CST
5271 && TYPE_PRECISION (TREE_TYPE (length
))
5272 > TYPE_PRECISION (sizetype
))
5273 length
= fold_convert (sizetype
, length
);
5274 if (low_bound
== NULL_TREE
)
5275 low_bound
= integer_zero_node
;
5276 if (!maybe_zero_len
&& i
> first_non_one
)
5278 if (integer_nonzerop (low_bound
))
5279 goto do_warn_noncontiguous
;
5280 if (length
!= NULL_TREE
5281 && TREE_CODE (length
) == INTEGER_CST
5282 && TYPE_DOMAIN (types
[i
])
5283 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
5284 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
5288 size
= size_binop (PLUS_EXPR
,
5289 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5291 if (!tree_int_cst_equal (length
, size
))
5293 do_warn_noncontiguous
:
5294 error_at (OMP_CLAUSE_LOCATION (c
),
5295 "array section is not contiguous in %qs "
5297 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5301 if (!processing_template_decl
5302 && length
!= NULL_TREE
5303 && TREE_SIDE_EFFECTS (length
))
5305 if (side_effects
== NULL_TREE
)
5306 side_effects
= length
;
5308 side_effects
= build2 (COMPOUND_EXPR
,
5309 TREE_TYPE (side_effects
),
5310 length
, side_effects
);
5313 else if (processing_template_decl
)
5319 if (i
> first_non_one
5320 && ((length
&& integer_nonzerop (length
))
5321 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5322 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5323 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
))
5326 l
= fold_convert (sizetype
, length
);
5329 l
= size_binop (PLUS_EXPR
,
5330 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5332 l
= size_binop (MINUS_EXPR
, l
,
5333 fold_convert (sizetype
, low_bound
));
5335 if (i
> first_non_one
)
5337 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
5339 if (condition
== NULL_TREE
)
5342 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
5345 else if (size
== NULL_TREE
)
5347 size
= size_in_bytes (TREE_TYPE (types
[i
]));
5348 tree eltype
= TREE_TYPE (types
[num
- 1]);
5349 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5350 eltype
= TREE_TYPE (eltype
);
5351 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5352 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5353 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5354 size
= size_binop (EXACT_DIV_EXPR
, size
,
5355 size_in_bytes (eltype
));
5356 size
= size_binop (MULT_EXPR
, size
, l
);
5358 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
5359 size
, size_zero_node
);
5362 size
= size_binop (MULT_EXPR
, size
, l
);
5365 if (!processing_template_decl
)
5368 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
5369 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5370 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5371 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5373 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5374 size
= save_expr (size
);
5375 tree index_type
= build_index_type (size
);
5376 tree eltype
= TREE_TYPE (first
);
5377 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5378 eltype
= TREE_TYPE (eltype
);
5379 tree type
= build_array_type (eltype
, index_type
);
5380 tree ptype
= build_pointer_type (eltype
);
5381 if (TYPE_REF_P (TREE_TYPE (t
))
5382 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
5383 t
= convert_from_reference (t
);
5384 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5385 t
= build_fold_addr_expr (t
);
5386 tree t2
= build_fold_addr_expr (first
);
5387 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5388 ptrdiff_type_node
, t2
);
5389 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5390 ptrdiff_type_node
, t2
,
5391 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5392 ptrdiff_type_node
, t
));
5393 if (tree_fits_shwi_p (t2
))
5394 t
= build2 (MEM_REF
, type
, t
,
5395 build_int_cst (ptype
, tree_to_shwi (t2
)));
5398 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5400 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
5401 TREE_TYPE (t
), t
, t2
);
5402 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5404 OMP_CLAUSE_DECL (c
) = t
;
5407 OMP_CLAUSE_DECL (c
) = first
;
5408 OMP_CLAUSE_SIZE (c
) = size
;
5409 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5410 || (TREE_CODE (t
) == COMPONENT_REF
5411 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5413 if (ort
== C_ORT_OMP
|| ort
== C_ORT_ACC
)
5414 switch (OMP_CLAUSE_MAP_KIND (c
))
5416 case GOMP_MAP_ALLOC
:
5417 case GOMP_MAP_IF_PRESENT
:
5420 case GOMP_MAP_TOFROM
:
5421 case GOMP_MAP_ALWAYS_TO
:
5422 case GOMP_MAP_ALWAYS_FROM
:
5423 case GOMP_MAP_ALWAYS_TOFROM
:
5424 case GOMP_MAP_RELEASE
:
5425 case GOMP_MAP_DELETE
:
5426 case GOMP_MAP_FORCE_TO
:
5427 case GOMP_MAP_FORCE_FROM
:
5428 case GOMP_MAP_FORCE_TOFROM
:
5429 case GOMP_MAP_FORCE_PRESENT
:
5430 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5435 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5437 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
&& ort
!= C_ORT_ACC
)
5438 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
5439 else if (TREE_CODE (t
) == COMPONENT_REF
)
5440 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ATTACH_DETACH
);
5441 else if (REFERENCE_REF_P (t
)
5442 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5444 t
= TREE_OPERAND (t
, 0);
5445 gomp_map_kind k
= (ort
== C_ORT_ACC
) ? GOMP_MAP_ATTACH_DETACH
5446 : GOMP_MAP_ALWAYS_POINTER
;
5447 OMP_CLAUSE_SET_MAP_KIND (c2
, k
);
5450 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5451 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5452 && !cxx_mark_addressable (t
))
5454 OMP_CLAUSE_DECL (c2
) = t
;
5455 t
= build_fold_addr_expr (first
);
5456 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5457 ptrdiff_type_node
, t
);
5458 tree ptr
= OMP_CLAUSE_DECL (c2
);
5459 ptr
= convert_from_reference (ptr
);
5460 if (!INDIRECT_TYPE_P (TREE_TYPE (ptr
)))
5461 ptr
= build_fold_addr_expr (ptr
);
5462 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5463 ptrdiff_type_node
, t
,
5464 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5465 ptrdiff_type_node
, ptr
));
5466 OMP_CLAUSE_SIZE (c2
) = t
;
5467 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5468 OMP_CLAUSE_CHAIN (c
) = c2
;
5469 ptr
= OMP_CLAUSE_DECL (c2
);
5470 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5471 && TYPE_REF_P (TREE_TYPE (ptr
))
5472 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5474 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5476 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5477 OMP_CLAUSE_DECL (c3
) = ptr
;
5478 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
5479 || OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ATTACH_DETACH
)
5481 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5482 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5485 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5486 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5487 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5488 OMP_CLAUSE_CHAIN (c2
) = c3
;
5495 /* Return identifier to look up for omp declare reduction. */
5498 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5500 const char *p
= NULL
;
5501 const char *m
= NULL
;
5502 switch (reduction_code
)
5510 case TRUTH_ANDIF_EXPR
:
5511 case TRUTH_ORIF_EXPR
:
5512 reduction_id
= ovl_op_identifier (false, reduction_code
);
5526 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5527 return error_mark_node
;
5528 p
= IDENTIFIER_POINTER (reduction_id
);
5531 if (type
!= NULL_TREE
)
5532 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5534 const char prefix
[] = "omp declare reduction ";
5535 size_t lenp
= sizeof (prefix
);
5536 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5538 size_t len
= strlen (p
);
5539 size_t lenm
= m
? strlen (m
) + 1 : 0;
5540 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5542 memcpy (name
, prefix
, lenp
- 1);
5543 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5546 name
[lenp
+ len
- 1] = '~';
5547 memcpy (name
+ lenp
+ len
, m
, lenm
);
5549 return get_identifier (name
);
5552 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5553 FUNCTION_DECL or NULL_TREE if not found. */
5556 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5557 vec
<tree
> *ambiguousp
)
5560 tree baselink
= NULL_TREE
;
5561 if (identifier_p (id
))
5564 bool nonint_cst_expression_p
;
5565 const char *error_msg
;
5566 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5567 tree decl
= lookup_name (id
);
5568 if (decl
== NULL_TREE
)
5569 decl
= error_mark_node
;
5570 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5571 &nonint_cst_expression_p
, false, true, false,
5572 false, &error_msg
, loc
);
5573 if (idk
== CP_ID_KIND_UNQUALIFIED
5574 && identifier_p (id
))
5576 vec
<tree
, va_gc
> *args
= NULL
;
5577 vec_safe_push (args
, build_reference_type (type
));
5578 id
= perform_koenig_lookup (id
, args
, tf_none
);
5581 else if (TREE_CODE (id
) == SCOPE_REF
)
5582 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5583 omp_reduction_id (ERROR_MARK
,
5584 TREE_OPERAND (id
, 1),
5586 LOOK_want::NORMAL
, false);
5589 if (fns
&& is_overloaded_fn (fns
))
5591 for (lkp_iterator
iter (get_fns (fns
)); iter
; ++iter
)
5593 tree fndecl
= *iter
;
5594 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5596 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5597 if (same_type_p (TREE_TYPE (argtype
), type
))
5605 if (id
&& BASELINK_P (fns
))
5614 if (!id
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5616 vec
<tree
> ambiguous
= vNULL
;
5617 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5619 if (ambiguousp
== NULL
)
5620 ambiguousp
= &ambiguous
;
5621 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5623 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5624 baselinkp
? baselinkp
: &baselink
,
5626 if (id
== NULL_TREE
)
5628 if (!ambiguousp
->is_empty ())
5629 ambiguousp
->safe_push (id
);
5630 else if (ret
!= NULL_TREE
)
5632 ambiguousp
->safe_push (ret
);
5633 ambiguousp
->safe_push (id
);
5639 if (ambiguousp
!= &ambiguous
)
5641 if (!ambiguous
.is_empty ())
5643 const char *str
= _("candidates are:");
5646 error_at (loc
, "user defined reduction lookup is ambiguous");
5647 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5649 inform (DECL_SOURCE_LOCATION (udr
), "%s %#qD", str
, udr
);
5651 str
= get_spaces (str
);
5653 ambiguous
.release ();
5654 ret
= error_mark_node
;
5655 baselink
= NULL_TREE
;
5660 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5661 id
, id
, tf_warning_or_error
);
5665 /* Helper function for cp_parser_omp_declare_reduction_exprs
5667 Remove CLEANUP_STMT for data (omp_priv variable).
5668 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5672 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5676 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5677 *tp
= CLEANUP_BODY (*tp
);
5678 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5680 tree decl
= DECL_EXPR_DECL (*tp
);
5681 if (!processing_template_decl
5682 && decl
== (tree
) data
5683 && DECL_INITIAL (decl
)
5684 && DECL_INITIAL (decl
) != error_mark_node
)
5686 tree list
= NULL_TREE
;
5687 append_to_statement_list_force (*tp
, &list
);
5688 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5689 decl
, DECL_INITIAL (decl
));
5690 DECL_INITIAL (decl
) = NULL_TREE
;
5691 append_to_statement_list_force (init_expr
, &list
);
5698 /* Data passed from cp_check_omp_declare_reduction to
5699 cp_check_omp_declare_reduction_r. */
5701 struct cp_check_omp_declare_reduction_data
5708 /* Helper function for cp_check_omp_declare_reduction, called via
5712 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5714 struct cp_check_omp_declare_reduction_data
*udr_data
5715 = (struct cp_check_omp_declare_reduction_data
*) data
;
5717 && !DECL_ARTIFICIAL (*tp
)
5718 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5719 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5721 location_t loc
= udr_data
->loc
;
5722 if (udr_data
->combiner_p
)
5723 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5724 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5727 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5728 "to variable %qD which is not %<omp_priv%> nor "
5736 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5739 cp_check_omp_declare_reduction (tree udr
)
5741 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5742 gcc_assert (TYPE_REF_P (type
));
5743 type
= TREE_TYPE (type
);
5745 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5747 if (type
== error_mark_node
)
5749 if (ARITHMETIC_TYPE_P (type
))
5751 static enum tree_code predef_codes
[]
5752 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5753 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5754 for (i
= 0; i
< 8; i
++)
5756 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5757 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5758 const char *n2
= IDENTIFIER_POINTER (id
);
5759 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5760 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5761 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5766 && TREE_CODE (type
) != COMPLEX_EXPR
)
5768 const char prefix_minmax
[] = "omp declare reduction m";
5769 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5770 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5771 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5772 prefix_minmax
, prefix_size
) == 0
5773 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5774 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5775 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5780 error_at (loc
, "predeclared arithmetic type %qT in "
5781 "%<#pragma omp declare reduction%>", type
);
5785 else if (FUNC_OR_METHOD_TYPE_P (type
)
5786 || TREE_CODE (type
) == ARRAY_TYPE
)
5788 error_at (loc
, "function or array type %qT in "
5789 "%<#pragma omp declare reduction%>", type
);
5792 else if (TYPE_REF_P (type
))
5794 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5798 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5800 error_at (loc
, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
5801 "type %qT in %<#pragma omp declare reduction%>", type
);
5805 tree body
= DECL_SAVED_TREE (udr
);
5806 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5809 tree_stmt_iterator tsi
;
5810 struct cp_check_omp_declare_reduction_data data
;
5811 memset (data
.stmts
, 0, sizeof data
.stmts
);
5812 for (i
= 0, tsi
= tsi_start (body
);
5813 i
< 7 && !tsi_end_p (tsi
);
5814 i
++, tsi_next (&tsi
))
5815 data
.stmts
[i
] = tsi_stmt (tsi
);
5817 gcc_assert (tsi_end_p (tsi
));
5820 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5821 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5822 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5824 data
.combiner_p
= true;
5825 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5827 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5831 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5832 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5833 data
.combiner_p
= false;
5834 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5836 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5837 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5838 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5840 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5845 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5846 an inline call. But, remap
5847 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5848 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5851 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5852 tree decl
, tree placeholder
)
5855 hash_map
<tree
, tree
> decl_map
;
5857 decl_map
.put (omp_decl1
, placeholder
);
5858 decl_map
.put (omp_decl2
, decl
);
5859 memset (&id
, 0, sizeof (id
));
5860 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5861 id
.dst_fn
= current_function_decl
;
5862 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5863 id
.decl_map
= &decl_map
;
5865 id
.copy_decl
= copy_decl_no_change
;
5866 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5867 id
.transform_new_cfg
= true;
5868 id
.transform_return_to_modify
= false;
5869 id
.transform_lang_insert_block
= NULL
;
5871 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5875 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5876 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5879 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5881 if (*tp
== (tree
) data
)
5886 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5887 Return true if there is some error and the clause should be removed. */
5890 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5892 tree t
= OMP_CLAUSE_DECL (c
);
5893 bool predefined
= false;
5894 if (TREE_CODE (t
) == TREE_LIST
)
5896 gcc_assert (processing_template_decl
);
5899 tree type
= TREE_TYPE (t
);
5900 if (TREE_CODE (t
) == MEM_REF
)
5901 type
= TREE_TYPE (type
);
5902 if (TYPE_REF_P (type
))
5903 type
= TREE_TYPE (type
);
5904 if (TREE_CODE (type
) == ARRAY_TYPE
)
5907 gcc_assert (TREE_CODE (t
) != MEM_REF
);
5908 while (TREE_CODE (type
) == ARRAY_TYPE
)
5909 type
= TREE_TYPE (type
);
5910 if (!processing_template_decl
)
5912 t
= require_complete_type (t
);
5913 if (t
== error_mark_node
)
5915 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
5916 TYPE_SIZE_UNIT (type
));
5917 if (integer_zerop (size
))
5919 error_at (OMP_CLAUSE_LOCATION (c
),
5920 "%qE in %<reduction%> clause is a zero size array",
5921 omp_clause_printable_decl (t
));
5924 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5925 size
= save_expr (size
);
5926 tree index_type
= build_index_type (size
);
5927 tree atype
= build_array_type (type
, index_type
);
5928 tree ptype
= build_pointer_type (type
);
5929 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5930 t
= build_fold_addr_expr (t
);
5931 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
5932 OMP_CLAUSE_DECL (c
) = t
;
5935 if (type
== error_mark_node
)
5937 else if (ARITHMETIC_TYPE_P (type
))
5938 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5947 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5954 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5958 case TRUTH_ANDIF_EXPR
:
5959 case TRUTH_ORIF_EXPR
:
5960 if (FLOAT_TYPE_P (type
))
5967 else if (TYPE_READONLY (type
))
5969 error_at (OMP_CLAUSE_LOCATION (c
),
5970 "%qE has const type for %<reduction%>",
5971 omp_clause_printable_decl (t
));
5974 else if (!processing_template_decl
)
5976 t
= require_complete_type (t
);
5977 if (t
== error_mark_node
)
5979 OMP_CLAUSE_DECL (c
) = t
;
5984 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5987 else if (processing_template_decl
)
5989 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) == error_mark_node
)
5994 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5996 type
= TYPE_MAIN_VARIANT (type
);
5997 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5998 if (id
== NULL_TREE
)
5999 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
6000 NULL_TREE
, NULL_TREE
);
6001 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
6004 if (id
== error_mark_node
)
6007 tree body
= DECL_SAVED_TREE (id
);
6010 if (TREE_CODE (body
) == STATEMENT_LIST
)
6012 tree_stmt_iterator tsi
;
6013 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
6016 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
6017 atype
= TREE_TYPE (atype
);
6018 bool need_static_cast
= !same_type_p (type
, atype
);
6019 memset (stmts
, 0, sizeof stmts
);
6020 for (i
= 0, tsi
= tsi_start (body
);
6021 i
< 7 && !tsi_end_p (tsi
);
6022 i
++, tsi_next (&tsi
))
6023 stmts
[i
] = tsi_stmt (tsi
);
6024 gcc_assert (tsi_end_p (tsi
));
6028 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
6029 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
6030 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
6031 DECL_ARTIFICIAL (placeholder
) = 1;
6032 DECL_IGNORED_P (placeholder
) = 1;
6033 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
6034 if (TREE_CODE (t
) == MEM_REF
)
6036 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
6038 DECL_ARTIFICIAL (decl_placeholder
) = 1;
6039 DECL_IGNORED_P (decl_placeholder
) = 1;
6040 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
6042 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
6043 cxx_mark_addressable (placeholder
);
6044 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
6045 && (decl_placeholder
6046 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6047 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6048 : OMP_CLAUSE_DECL (c
));
6049 tree omp_out
= placeholder
;
6050 tree omp_in
= decl_placeholder
? decl_placeholder
6051 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6052 if (need_static_cast
)
6054 tree rtype
= build_reference_type (atype
);
6055 omp_out
= build_static_cast (input_location
,
6057 tf_warning_or_error
);
6058 omp_in
= build_static_cast (input_location
,
6060 tf_warning_or_error
);
6061 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
6063 omp_out
= convert_from_reference (omp_out
);
6064 omp_in
= convert_from_reference (omp_in
);
6066 OMP_CLAUSE_REDUCTION_MERGE (c
)
6067 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
6068 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
6072 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
6073 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
6074 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3]))
6075 && (decl_placeholder
6076 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6077 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6078 : OMP_CLAUSE_DECL (c
));
6079 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
6080 cxx_mark_addressable (placeholder
);
6081 tree omp_priv
= decl_placeholder
? decl_placeholder
6082 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6083 tree omp_orig
= placeholder
;
6084 if (need_static_cast
)
6088 error_at (OMP_CLAUSE_LOCATION (c
),
6089 "user defined reduction with constructor "
6090 "initializer for base class %qT", atype
);
6093 tree rtype
= build_reference_type (atype
);
6094 omp_priv
= build_static_cast (input_location
,
6096 tf_warning_or_error
);
6097 omp_orig
= build_static_cast (input_location
,
6099 tf_warning_or_error
);
6100 if (omp_priv
== error_mark_node
6101 || omp_orig
== error_mark_node
)
6103 omp_priv
= convert_from_reference (omp_priv
);
6104 omp_orig
= convert_from_reference (omp_orig
);
6107 *need_default_ctor
= true;
6108 OMP_CLAUSE_REDUCTION_INIT (c
)
6109 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
6110 DECL_EXPR_DECL (stmts
[3]),
6111 omp_priv
, omp_orig
);
6112 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
6113 find_omp_placeholder_r
, placeholder
, NULL
))
6114 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
6118 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
6119 *need_default_ctor
= true;
6123 tree v
= decl_placeholder
? decl_placeholder
6124 : convert_from_reference (t
);
6125 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
6126 init
= build_constructor (TREE_TYPE (v
), NULL
);
6128 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
6129 OMP_CLAUSE_REDUCTION_INIT (c
)
6130 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
6135 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
6139 error_at (OMP_CLAUSE_LOCATION (c
),
6140 "user defined reduction not found for %qE",
6141 omp_clause_printable_decl (t
));
6144 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
6145 gcc_assert (TYPE_SIZE_UNIT (type
)
6146 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
6150 /* Called from finish_struct_1. linear(this) or linear(this:step)
6151 clauses might not be finalized yet because the class has been incomplete
6152 when parsing #pragma omp declare simd methods. Fix those up now. */
6155 finish_omp_declare_simd_methods (tree t
)
6157 if (processing_template_decl
)
6160 for (tree x
= TYPE_FIELDS (t
); x
; x
= DECL_CHAIN (x
))
6162 if (TREE_CODE (x
) == USING_DECL
6163 || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x
))
6165 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
6166 if (!ods
|| !TREE_VALUE (ods
))
6168 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
6169 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
6170 && integer_zerop (OMP_CLAUSE_DECL (c
))
6171 && OMP_CLAUSE_LINEAR_STEP (c
)
6172 && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
))))
6174 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
6175 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
6176 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
6177 sizetype
, s
, TYPE_SIZE_UNIT (t
));
6178 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
6183 /* Adjust sink depend clause to take into account pointer offsets.
6185 Return TRUE if there was a problem processing the offset, and the
6186 whole clause should be removed. */
6189 cp_finish_omp_clause_depend_sink (tree sink_clause
)
6191 tree t
= OMP_CLAUSE_DECL (sink_clause
);
6192 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
6194 /* Make sure we don't adjust things twice for templates. */
6195 if (processing_template_decl
)
6198 for (; t
; t
= TREE_CHAIN (t
))
6200 tree decl
= TREE_VALUE (t
);
6201 if (TYPE_PTR_P (TREE_TYPE (decl
)))
6203 tree offset
= TREE_PURPOSE (t
);
6204 bool neg
= wi::neg_p (wi::to_wide (offset
));
6205 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
6206 decl
= mark_rvalue_use (decl
);
6207 decl
= convert_from_reference (decl
);
6208 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
6209 neg
? MINUS_EXPR
: PLUS_EXPR
,
6211 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
6212 MINUS_EXPR
, sizetype
,
6213 fold_convert (sizetype
, t2
),
6214 fold_convert (sizetype
, decl
));
6215 if (t2
== error_mark_node
)
6217 TREE_PURPOSE (t
) = t2
;
6223 /* Finish OpenMP iterators ITER. Return true if they are errorneous
6224 and clauses containing them should be removed. */
6227 cp_omp_finish_iterators (tree iter
)
6230 for (tree it
= iter
; it
; it
= TREE_CHAIN (it
))
6232 tree var
= TREE_VEC_ELT (it
, 0);
6233 tree begin
= TREE_VEC_ELT (it
, 1);
6234 tree end
= TREE_VEC_ELT (it
, 2);
6235 tree step
= TREE_VEC_ELT (it
, 3);
6237 tree type
= TREE_TYPE (var
);
6238 location_t loc
= DECL_SOURCE_LOCATION (var
);
6239 if (type
== error_mark_node
)
6244 if (type_dependent_expression_p (var
))
6246 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
6248 error_at (loc
, "iterator %qD has neither integral nor pointer type",
6253 else if (TYPE_READONLY (type
))
6255 error_at (loc
, "iterator %qD has const qualified type", var
);
6259 if (type_dependent_expression_p (begin
)
6260 || type_dependent_expression_p (end
)
6261 || type_dependent_expression_p (step
))
6263 else if (error_operand_p (step
))
6268 else if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
6270 error_at (EXPR_LOC_OR_LOC (step
, loc
),
6271 "iterator step with non-integral type");
6276 begin
= mark_rvalue_use (begin
);
6277 end
= mark_rvalue_use (end
);
6278 step
= mark_rvalue_use (step
);
6279 begin
= cp_build_c_cast (input_location
, type
, begin
,
6280 tf_warning_or_error
);
6281 end
= cp_build_c_cast (input_location
, type
, end
,
6282 tf_warning_or_error
);
6284 if (!processing_template_decl
)
6285 step
= orig_step
= save_expr (step
);
6286 tree stype
= POINTER_TYPE_P (type
) ? sizetype
: type
;
6287 step
= cp_build_c_cast (input_location
, stype
, step
,
6288 tf_warning_or_error
);
6289 if (POINTER_TYPE_P (type
) && !processing_template_decl
)
6291 begin
= save_expr (begin
);
6292 step
= pointer_int_sum (loc
, PLUS_EXPR
, begin
, step
);
6293 step
= fold_build2_loc (loc
, MINUS_EXPR
, sizetype
,
6294 fold_convert (sizetype
, step
),
6295 fold_convert (sizetype
, begin
));
6296 step
= fold_convert (ssizetype
, step
);
6298 if (!processing_template_decl
)
6300 begin
= maybe_constant_value (begin
);
6301 end
= maybe_constant_value (end
);
6302 step
= maybe_constant_value (step
);
6303 orig_step
= maybe_constant_value (orig_step
);
6305 if (integer_zerop (step
))
6307 error_at (loc
, "iterator %qD has zero step", var
);
6312 if (begin
== error_mark_node
6313 || end
== error_mark_node
6314 || step
== error_mark_node
6315 || orig_step
== error_mark_node
)
6321 if (!processing_template_decl
)
6323 begin
= fold_build_cleanup_point_expr (TREE_TYPE (begin
), begin
);
6324 end
= fold_build_cleanup_point_expr (TREE_TYPE (end
), end
);
6325 step
= fold_build_cleanup_point_expr (TREE_TYPE (step
), step
);
6326 orig_step
= fold_build_cleanup_point_expr (TREE_TYPE (orig_step
),
6329 hash_set
<tree
> pset
;
6331 for (it2
= TREE_CHAIN (it
); it2
; it2
= TREE_CHAIN (it2
))
6333 tree var2
= TREE_VEC_ELT (it2
, 0);
6334 tree begin2
= TREE_VEC_ELT (it2
, 1);
6335 tree end2
= TREE_VEC_ELT (it2
, 2);
6336 tree step2
= TREE_VEC_ELT (it2
, 3);
6337 location_t loc2
= DECL_SOURCE_LOCATION (var2
);
6338 if (cp_walk_tree (&begin2
, find_omp_placeholder_r
, var
, &pset
))
6340 error_at (EXPR_LOC_OR_LOC (begin2
, loc2
),
6341 "begin expression refers to outer iterator %qD", var
);
6344 else if (cp_walk_tree (&end2
, find_omp_placeholder_r
, var
, &pset
))
6346 error_at (EXPR_LOC_OR_LOC (end2
, loc2
),
6347 "end expression refers to outer iterator %qD", var
);
6350 else if (cp_walk_tree (&step2
, find_omp_placeholder_r
, var
, &pset
))
6352 error_at (EXPR_LOC_OR_LOC (step2
, loc2
),
6353 "step expression refers to outer iterator %qD", var
);
6362 TREE_VEC_ELT (it
, 1) = begin
;
6363 TREE_VEC_ELT (it
, 2) = end
;
6364 if (processing_template_decl
)
6365 TREE_VEC_ELT (it
, 3) = orig_step
;
6368 TREE_VEC_ELT (it
, 3) = step
;
6369 TREE_VEC_ELT (it
, 4) = orig_step
;
6375 /* Ensure that pointers are used in OpenACC attach and detach clauses.
6376 Return true if an error has been detected. */
6379 cp_oacc_check_attachments (tree c
)
6381 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6384 /* OpenACC attach / detach clauses must be pointers. */
6385 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
6386 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
)
6388 tree t
= OMP_CLAUSE_DECL (c
);
6391 while (TREE_CODE (t
) == TREE_LIST
)
6394 type
= TREE_TYPE (t
);
6396 if (TREE_CODE (type
) == REFERENCE_TYPE
)
6397 type
= TREE_TYPE (type
);
6399 if (TREE_CODE (type
) != POINTER_TYPE
)
6401 error_at (OMP_CLAUSE_LOCATION (c
), "expected pointer in %qs clause",
6402 c_omp_map_clause_name (c
, true));
6410 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
6411 Remove any elements from the list that are invalid. */
6414 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
6416 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
6417 bitmap_head aligned_head
, map_head
, map_field_head
, oacc_reduction_head
;
6419 tree safelen
= NULL_TREE
;
6420 bool branch_seen
= false;
6421 bool copyprivate_seen
= false;
6422 bool ordered_seen
= false;
6423 bool order_seen
= false;
6424 bool schedule_seen
= false;
6425 bool oacc_async
= false;
6426 tree last_iterators
= NULL_TREE
;
6427 bool last_iterators_remove
= false;
6428 /* 1 if normal/task reduction has been seen, -1 if inscan reduction
6429 has been seen, -2 if mixed inscan/normal reduction diagnosed. */
6430 int reduction_seen
= 0;
6431 bool allocate_seen
= false;
6432 bool detach_seen
= false;
6433 bool mergeable_seen
= false;
6435 bitmap_obstack_initialize (NULL
);
6436 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
6437 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
6438 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
6439 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
6440 /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
6441 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
6442 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
6443 /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
6445 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
6447 if (ort
& C_ORT_ACC
)
6448 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6449 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
6455 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
6457 bool remove
= false;
6458 bool field_ok
= false;
6460 switch (OMP_CLAUSE_CODE (c
))
6462 case OMP_CLAUSE_SHARED
:
6463 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6464 goto check_dup_generic
;
6465 case OMP_CLAUSE_PRIVATE
:
6466 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6467 goto check_dup_generic
;
6468 case OMP_CLAUSE_REDUCTION
:
6469 if (reduction_seen
== 0)
6470 reduction_seen
= OMP_CLAUSE_REDUCTION_INSCAN (c
) ? -1 : 1;
6471 else if (reduction_seen
!= -2
6472 && reduction_seen
!= (OMP_CLAUSE_REDUCTION_INSCAN (c
)
6475 error_at (OMP_CLAUSE_LOCATION (c
),
6476 "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
6477 "on the same construct");
6478 reduction_seen
= -2;
6481 case OMP_CLAUSE_IN_REDUCTION
:
6482 case OMP_CLAUSE_TASK_REDUCTION
:
6483 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6484 t
= OMP_CLAUSE_DECL (c
);
6485 if (TREE_CODE (t
) == TREE_LIST
)
6487 if (handle_omp_array_sections (c
, ort
))
6492 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6493 && OMP_CLAUSE_REDUCTION_INSCAN (c
))
6495 error_at (OMP_CLAUSE_LOCATION (c
),
6496 "%<inscan%> %<reduction%> clause with array "
6501 if (TREE_CODE (t
) == TREE_LIST
)
6503 while (TREE_CODE (t
) == TREE_LIST
)
6508 gcc_assert (TREE_CODE (t
) == MEM_REF
);
6509 t
= TREE_OPERAND (t
, 0);
6510 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
6511 t
= TREE_OPERAND (t
, 0);
6512 if (TREE_CODE (t
) == ADDR_EXPR
6513 || INDIRECT_REF_P (t
))
6514 t
= TREE_OPERAND (t
, 0);
6516 tree n
= omp_clause_decl_field (t
);
6519 goto check_dup_generic_t
;
6522 cxx_mark_addressable (t
);
6523 goto check_dup_generic
;
6524 case OMP_CLAUSE_COPYPRIVATE
:
6525 copyprivate_seen
= true;
6526 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6527 goto check_dup_generic
;
6528 case OMP_CLAUSE_COPYIN
:
6529 goto check_dup_generic
;
6530 case OMP_CLAUSE_LINEAR
:
6531 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6532 t
= OMP_CLAUSE_DECL (c
);
6533 if (ort
!= C_ORT_OMP_DECLARE_SIMD
6534 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
6536 error_at (OMP_CLAUSE_LOCATION (c
),
6537 "modifier should not be specified in %<linear%> "
6538 "clause on %<simd%> or %<for%> constructs");
6539 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
6541 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6542 && !type_dependent_expression_p (t
))
6544 tree type
= TREE_TYPE (t
);
6545 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6546 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
6547 && !TYPE_REF_P (type
))
6549 error_at (OMP_CLAUSE_LOCATION (c
),
6550 "linear clause with %qs modifier applied to "
6551 "non-reference variable with %qT type",
6552 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6553 ? "ref" : "uval", TREE_TYPE (t
));
6557 if (TYPE_REF_P (type
))
6558 type
= TREE_TYPE (type
);
6559 if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
6561 if (!INTEGRAL_TYPE_P (type
)
6562 && !TYPE_PTR_P (type
))
6564 error_at (OMP_CLAUSE_LOCATION (c
),
6565 "linear clause applied to non-integral "
6566 "non-pointer variable with %qT type",
6573 t
= OMP_CLAUSE_LINEAR_STEP (c
);
6575 t
= integer_one_node
;
6576 if (t
== error_mark_node
)
6581 else if (!type_dependent_expression_p (t
)
6582 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
6583 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6584 || TREE_CODE (t
) != PARM_DECL
6585 || !TYPE_REF_P (TREE_TYPE (t
))
6586 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
6588 error_at (OMP_CLAUSE_LOCATION (c
),
6589 "linear step expression must be integral");
6595 t
= mark_rvalue_use (t
);
6596 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
6598 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
6599 goto check_dup_generic
;
6601 if (!processing_template_decl
6602 && (VAR_P (OMP_CLAUSE_DECL (c
))
6603 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
6605 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
6607 t
= maybe_constant_value (t
);
6608 if (TREE_CODE (t
) != INTEGER_CST
)
6610 error_at (OMP_CLAUSE_LOCATION (c
),
6611 "%<linear%> clause step %qE is neither "
6612 "constant nor a parameter", t
);
6617 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6618 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
6619 if (TYPE_REF_P (type
))
6620 type
= TREE_TYPE (type
);
6621 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
6623 type
= build_pointer_type (type
);
6624 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
6625 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6627 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6628 MINUS_EXPR
, sizetype
,
6629 fold_convert (sizetype
, t
),
6630 fold_convert (sizetype
, d
));
6631 if (t
== error_mark_node
)
6637 else if (TYPE_PTR_P (type
)
6638 /* Can't multiply the step yet if *this
6639 is still incomplete type. */
6640 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6641 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
6642 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
6643 || DECL_NAME (OMP_CLAUSE_DECL (c
))
6645 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
6647 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
6648 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6650 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6651 MINUS_EXPR
, sizetype
,
6652 fold_convert (sizetype
, t
),
6653 fold_convert (sizetype
, d
));
6654 if (t
== error_mark_node
)
6661 t
= fold_convert (type
, t
);
6663 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6665 goto check_dup_generic
;
6667 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6670 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6671 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6674 t
= OMP_CLAUSE_DECL (c
);
6675 check_dup_generic_t
:
6676 if (t
== current_class_ptr
6677 && ((ort
!= C_ORT_OMP_DECLARE_SIMD
&& ort
!= C_ORT_ACC
)
6678 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6679 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6681 error_at (OMP_CLAUSE_LOCATION (c
),
6682 "%<this%> allowed in OpenMP only in %<declare simd%>"
6687 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6688 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6690 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6693 error_at (OMP_CLAUSE_LOCATION (c
),
6694 "%qD is not a variable in clause %qs", t
,
6695 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6697 error_at (OMP_CLAUSE_LOCATION (c
),
6698 "%qE is not a variable in clause %qs", t
,
6699 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6702 else if ((ort
== C_ORT_ACC
6703 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
6704 || (ort
== C_ORT_OMP
6705 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
6706 || (OMP_CLAUSE_CODE (c
)
6707 == OMP_CLAUSE_USE_DEVICE_ADDR
))))
6709 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
6711 error_at (OMP_CLAUSE_LOCATION (c
),
6713 ? "%qD appears more than once in reduction clauses"
6714 : "%qD appears more than once in data clauses",
6719 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
6721 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6722 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6723 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6725 error_at (OMP_CLAUSE_LOCATION (c
),
6726 "%qD appears more than once in data clauses", t
);
6729 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6730 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6732 if (ort
== C_ORT_ACC
)
6733 error_at (OMP_CLAUSE_LOCATION (c
),
6734 "%qD appears more than once in data clauses", t
);
6736 error_at (OMP_CLAUSE_LOCATION (c
),
6737 "%qD appears both in data and map clauses", t
);
6741 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6746 && TREE_CODE (t
) == FIELD_DECL
6747 && t
== OMP_CLAUSE_DECL (c
))
6750 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
6751 == OMP_CLAUSE_SHARED
));
6752 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
6757 case OMP_CLAUSE_FIRSTPRIVATE
:
6758 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6760 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6762 t
= OMP_CLAUSE_DECL (c
);
6763 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6765 error_at (OMP_CLAUSE_LOCATION (c
),
6766 "%<this%> allowed in OpenMP only in %<declare simd%>"
6771 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6772 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6773 || TREE_CODE (t
) != FIELD_DECL
))
6775 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6778 error_at (OMP_CLAUSE_LOCATION (c
),
6779 "%qD is not a variable in clause %<firstprivate%>",
6782 error_at (OMP_CLAUSE_LOCATION (c
),
6783 "%qE is not a variable in clause %<firstprivate%>",
6787 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6788 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6790 error_at (OMP_CLAUSE_LOCATION (c
),
6791 "%qD appears more than once in data clauses", t
);
6794 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6796 if (ort
== C_ORT_ACC
)
6797 error_at (OMP_CLAUSE_LOCATION (c
),
6798 "%qD appears more than once in data clauses", t
);
6800 error_at (OMP_CLAUSE_LOCATION (c
),
6801 "%qD appears both in data and map clauses", t
);
6805 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
6806 goto handle_field_decl
;
6808 case OMP_CLAUSE_LASTPRIVATE
:
6809 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6811 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6813 t
= OMP_CLAUSE_DECL (c
);
6814 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6816 error_at (OMP_CLAUSE_LOCATION (c
),
6817 "%<this%> allowed in OpenMP only in %<declare simd%>"
6822 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6823 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6824 || TREE_CODE (t
) != FIELD_DECL
))
6826 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6829 error_at (OMP_CLAUSE_LOCATION (c
),
6830 "%qD is not a variable in clause %<lastprivate%>",
6833 error_at (OMP_CLAUSE_LOCATION (c
),
6834 "%qE is not a variable in clause %<lastprivate%>",
6838 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6839 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6841 error_at (OMP_CLAUSE_LOCATION (c
),
6842 "%qD appears more than once in data clauses", t
);
6846 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
6847 goto handle_field_decl
;
6850 t
= OMP_CLAUSE_IF_EXPR (c
);
6851 t
= maybe_convert_cond (t
);
6852 if (t
== error_mark_node
)
6854 else if (!processing_template_decl
)
6855 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6856 OMP_CLAUSE_IF_EXPR (c
) = t
;
6859 case OMP_CLAUSE_FINAL
:
6860 t
= OMP_CLAUSE_FINAL_EXPR (c
);
6861 t
= maybe_convert_cond (t
);
6862 if (t
== error_mark_node
)
6864 else if (!processing_template_decl
)
6865 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6866 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
6869 case OMP_CLAUSE_GANG
:
6870 /* Operand 1 is the gang static: argument. */
6871 t
= OMP_CLAUSE_OPERAND (c
, 1);
6874 if (t
== error_mark_node
)
6876 else if (!type_dependent_expression_p (t
)
6877 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6879 error_at (OMP_CLAUSE_LOCATION (c
),
6880 "%<gang%> static expression must be integral");
6885 t
= mark_rvalue_use (t
);
6886 if (!processing_template_decl
)
6888 t
= maybe_constant_value (t
);
6889 if (TREE_CODE (t
) == INTEGER_CST
6890 && tree_int_cst_sgn (t
) != 1
6891 && t
!= integer_minus_one_node
)
6893 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6894 "%<gang%> static value must be "
6896 t
= integer_one_node
;
6898 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6901 OMP_CLAUSE_OPERAND (c
, 1) = t
;
6903 /* Check operand 0, the num argument. */
6906 case OMP_CLAUSE_WORKER
:
6907 case OMP_CLAUSE_VECTOR
:
6908 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
6912 case OMP_CLAUSE_NUM_TASKS
:
6913 case OMP_CLAUSE_NUM_TEAMS
:
6914 case OMP_CLAUSE_NUM_THREADS
:
6915 case OMP_CLAUSE_NUM_GANGS
:
6916 case OMP_CLAUSE_NUM_WORKERS
:
6917 case OMP_CLAUSE_VECTOR_LENGTH
:
6918 t
= OMP_CLAUSE_OPERAND (c
, 0);
6919 if (t
== error_mark_node
)
6921 else if (!type_dependent_expression_p (t
)
6922 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6924 switch (OMP_CLAUSE_CODE (c
))
6926 case OMP_CLAUSE_GANG
:
6927 error_at (OMP_CLAUSE_LOCATION (c
),
6928 "%<gang%> num expression must be integral"); break;
6929 case OMP_CLAUSE_VECTOR
:
6930 error_at (OMP_CLAUSE_LOCATION (c
),
6931 "%<vector%> length expression must be integral");
6933 case OMP_CLAUSE_WORKER
:
6934 error_at (OMP_CLAUSE_LOCATION (c
),
6935 "%<worker%> num expression must be integral");
6938 error_at (OMP_CLAUSE_LOCATION (c
),
6939 "%qs expression must be integral",
6940 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6946 t
= mark_rvalue_use (t
);
6947 if (!processing_template_decl
)
6949 t
= maybe_constant_value (t
);
6950 if (TREE_CODE (t
) == INTEGER_CST
6951 && tree_int_cst_sgn (t
) != 1)
6953 switch (OMP_CLAUSE_CODE (c
))
6955 case OMP_CLAUSE_GANG
:
6956 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6957 "%<gang%> num value must be positive");
6959 case OMP_CLAUSE_VECTOR
:
6960 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6961 "%<vector%> length value must be "
6964 case OMP_CLAUSE_WORKER
:
6965 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6966 "%<worker%> num value must be "
6970 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6971 "%qs value must be positive",
6972 omp_clause_code_name
6973 [OMP_CLAUSE_CODE (c
)]);
6975 t
= integer_one_node
;
6977 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6979 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6983 case OMP_CLAUSE_SCHEDULE
:
6984 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
6987 else if (t
== error_mark_node
)
6989 else if (!type_dependent_expression_p (t
)
6990 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6992 error_at (OMP_CLAUSE_LOCATION (c
),
6993 "schedule chunk size expression must be integral");
6998 t
= mark_rvalue_use (t
);
6999 if (!processing_template_decl
)
7001 t
= maybe_constant_value (t
);
7002 if (TREE_CODE (t
) == INTEGER_CST
7003 && tree_int_cst_sgn (t
) != 1)
7005 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7006 "chunk size value must be positive");
7007 t
= integer_one_node
;
7009 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7011 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7014 schedule_seen
= true;
7017 case OMP_CLAUSE_SIMDLEN
:
7018 case OMP_CLAUSE_SAFELEN
:
7019 t
= OMP_CLAUSE_OPERAND (c
, 0);
7020 if (t
== error_mark_node
)
7022 else if (!type_dependent_expression_p (t
)
7023 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7025 error_at (OMP_CLAUSE_LOCATION (c
),
7026 "%qs length expression must be integral",
7027 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7032 t
= mark_rvalue_use (t
);
7033 if (!processing_template_decl
)
7035 t
= maybe_constant_value (t
);
7036 if (TREE_CODE (t
) != INTEGER_CST
7037 || tree_int_cst_sgn (t
) != 1)
7039 error_at (OMP_CLAUSE_LOCATION (c
),
7040 "%qs length expression must be positive "
7041 "constant integer expression",
7042 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7046 OMP_CLAUSE_OPERAND (c
, 0) = t
;
7047 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
7052 case OMP_CLAUSE_ASYNC
:
7053 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
7054 if (t
== error_mark_node
)
7056 else if (!type_dependent_expression_p (t
)
7057 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7059 error_at (OMP_CLAUSE_LOCATION (c
),
7060 "%<async%> expression must be integral");
7065 t
= mark_rvalue_use (t
);
7066 if (!processing_template_decl
)
7067 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7068 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
7072 case OMP_CLAUSE_WAIT
:
7073 t
= OMP_CLAUSE_WAIT_EXPR (c
);
7074 if (t
== error_mark_node
)
7076 else if (!processing_template_decl
)
7077 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7078 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
7081 case OMP_CLAUSE_THREAD_LIMIT
:
7082 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
7083 if (t
== error_mark_node
)
7085 else if (!type_dependent_expression_p (t
)
7086 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7088 error_at (OMP_CLAUSE_LOCATION (c
),
7089 "%<thread_limit%> expression must be integral");
7094 t
= mark_rvalue_use (t
);
7095 if (!processing_template_decl
)
7097 t
= maybe_constant_value (t
);
7098 if (TREE_CODE (t
) == INTEGER_CST
7099 && tree_int_cst_sgn (t
) != 1)
7101 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7102 "%<thread_limit%> value must be positive");
7103 t
= integer_one_node
;
7105 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7107 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
7111 case OMP_CLAUSE_DEVICE
:
7112 t
= OMP_CLAUSE_DEVICE_ID (c
);
7113 if (t
== error_mark_node
)
7115 else if (!type_dependent_expression_p (t
)
7116 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7118 error_at (OMP_CLAUSE_LOCATION (c
),
7119 "%<device%> id must be integral");
7124 t
= mark_rvalue_use (t
);
7125 if (!processing_template_decl
)
7126 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7127 OMP_CLAUSE_DEVICE_ID (c
) = t
;
7131 case OMP_CLAUSE_DIST_SCHEDULE
:
7132 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
7135 else if (t
== error_mark_node
)
7137 else if (!type_dependent_expression_p (t
)
7138 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7140 error_at (OMP_CLAUSE_LOCATION (c
),
7141 "%<dist_schedule%> chunk size expression must be "
7147 t
= mark_rvalue_use (t
);
7148 if (!processing_template_decl
)
7149 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7150 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
7154 case OMP_CLAUSE_ALIGNED
:
7155 t
= OMP_CLAUSE_DECL (c
);
7156 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
7158 error_at (OMP_CLAUSE_LOCATION (c
),
7159 "%<this%> allowed in OpenMP only in %<declare simd%>"
7164 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7166 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7169 error_at (OMP_CLAUSE_LOCATION (c
),
7170 "%qD is not a variable in %<aligned%> clause", t
);
7172 error_at (OMP_CLAUSE_LOCATION (c
),
7173 "%qE is not a variable in %<aligned%> clause", t
);
7176 else if (!type_dependent_expression_p (t
)
7177 && !TYPE_PTR_P (TREE_TYPE (t
))
7178 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
7179 && (!TYPE_REF_P (TREE_TYPE (t
))
7180 || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
7181 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
7184 error_at (OMP_CLAUSE_LOCATION (c
),
7185 "%qE in %<aligned%> clause is neither a pointer nor "
7186 "an array nor a reference to pointer or array", t
);
7189 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7191 error_at (OMP_CLAUSE_LOCATION (c
),
7192 "%qD appears more than once in %<aligned%> clauses",
7197 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
7198 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
7199 if (t
== error_mark_node
)
7201 else if (t
== NULL_TREE
)
7203 else if (!type_dependent_expression_p (t
)
7204 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7206 error_at (OMP_CLAUSE_LOCATION (c
),
7207 "%<aligned%> clause alignment expression must "
7213 t
= mark_rvalue_use (t
);
7214 if (!processing_template_decl
)
7216 t
= maybe_constant_value (t
);
7217 if (TREE_CODE (t
) != INTEGER_CST
7218 || tree_int_cst_sgn (t
) != 1)
7220 error_at (OMP_CLAUSE_LOCATION (c
),
7221 "%<aligned%> clause alignment expression must "
7222 "be positive constant integer expression");
7226 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7228 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
7232 case OMP_CLAUSE_NONTEMPORAL
:
7233 t
= OMP_CLAUSE_DECL (c
);
7234 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7236 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7239 error_at (OMP_CLAUSE_LOCATION (c
),
7240 "%qD is not a variable in %<nontemporal%> clause",
7243 error_at (OMP_CLAUSE_LOCATION (c
),
7244 "%qE is not a variable in %<nontemporal%> clause",
7248 else if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
7250 error_at (OMP_CLAUSE_LOCATION (c
),
7251 "%qD appears more than once in %<nontemporal%> "
7256 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
7259 case OMP_CLAUSE_ALLOCATE
:
7260 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7262 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7264 t
= OMP_CLAUSE_DECL (c
);
7265 if (t
== current_class_ptr
)
7267 error_at (OMP_CLAUSE_LOCATION (c
),
7268 "%<this%> not allowed in %<allocate%> clause");
7273 && TREE_CODE (t
) != PARM_DECL
7274 && TREE_CODE (t
) != FIELD_DECL
)
7276 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7279 error_at (OMP_CLAUSE_LOCATION (c
),
7280 "%qD is not a variable in %<allocate%> clause", t
);
7282 error_at (OMP_CLAUSE_LOCATION (c
),
7283 "%qE is not a variable in %<allocate%> clause", t
);
7286 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7288 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7289 "%qD appears more than once in %<allocate%> clauses",
7295 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
7296 allocate_seen
= true;
7299 allocator
= OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
);
7300 if (error_operand_p (allocator
))
7305 if (allocator
== NULL_TREE
)
7306 goto handle_field_decl
;
7308 allocatort
= TYPE_MAIN_VARIANT (TREE_TYPE (allocator
));
7309 if (!type_dependent_expression_p (allocator
)
7310 && (TREE_CODE (allocatort
) != ENUMERAL_TYPE
7311 || TYPE_NAME (allocatort
) == NULL_TREE
7312 || TREE_CODE (TYPE_NAME (allocatort
)) != TYPE_DECL
7313 || (DECL_NAME (TYPE_NAME (allocatort
))
7314 != get_identifier ("omp_allocator_handle_t"))
7315 || (TYPE_CONTEXT (allocatort
)
7316 != DECL_CONTEXT (global_namespace
))))
7318 error_at (OMP_CLAUSE_LOCATION (c
),
7319 "%<allocate%> clause allocator expression has "
7320 "type %qT rather than %<omp_allocator_handle_t%>",
7321 TREE_TYPE (allocator
));
7326 allocator
= mark_rvalue_use (allocator
);
7327 if (!processing_template_decl
)
7328 allocator
= maybe_constant_value (allocator
);
7329 OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
) = allocator
;
7331 goto handle_field_decl
;
7333 case OMP_CLAUSE_DEPEND
:
7334 t
= OMP_CLAUSE_DECL (c
);
7337 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
7338 == OMP_CLAUSE_DEPEND_SOURCE
);
7341 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
7343 if (cp_finish_omp_clause_depend_sink (c
))
7347 if (TREE_CODE (t
) == TREE_LIST
7349 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
7351 if (TREE_PURPOSE (t
) != last_iterators
)
7352 last_iterators_remove
7353 = cp_omp_finish_iterators (TREE_PURPOSE (t
));
7354 last_iterators
= TREE_PURPOSE (t
);
7356 if (last_iterators_remove
)
7357 t
= error_mark_node
;
7360 last_iterators
= NULL_TREE
;
7362 if (TREE_CODE (t
) == TREE_LIST
)
7364 if (handle_omp_array_sections (c
, ort
))
7366 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7368 error_at (OMP_CLAUSE_LOCATION (c
),
7369 "%<depend%> clause with %<depobj%> dependence "
7370 "type on array section");
7375 if (t
== error_mark_node
)
7377 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7379 error_at (OMP_CLAUSE_LOCATION (c
),
7380 "%<this%> allowed in OpenMP only in %<declare simd%>"
7384 else if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7386 else if (!lvalue_p (t
))
7389 error_at (OMP_CLAUSE_LOCATION (c
),
7390 "%qD is not lvalue expression nor array section "
7391 "in %<depend%> clause", t
);
7393 error_at (OMP_CLAUSE_LOCATION (c
),
7394 "%qE is not lvalue expression nor array section "
7395 "in %<depend%> clause", t
);
7398 else if (TREE_CODE (t
) == COMPONENT_REF
7399 && TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7400 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7402 error_at (OMP_CLAUSE_LOCATION (c
),
7403 "bit-field %qE in %qs clause", t
, "depend");
7406 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7408 if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7409 ? TREE_TYPE (TREE_TYPE (t
))
7412 error_at (OMP_CLAUSE_LOCATION (c
),
7413 "%qE does not have %<omp_depend_t%> type in "
7414 "%<depend%> clause with %<depobj%> dependence "
7419 else if (c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7420 ? TREE_TYPE (TREE_TYPE (t
))
7423 error_at (OMP_CLAUSE_LOCATION (c
),
7424 "%qE should not have %<omp_depend_t%> type in "
7425 "%<depend%> clause with dependence type other than "
7431 tree addr
= cp_build_addr_expr (t
, tf_warning_or_error
);
7432 if (addr
== error_mark_node
)
7436 t
= cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c
),
7437 addr
, RO_UNARY_STAR
,
7438 tf_warning_or_error
);
7439 if (t
== error_mark_node
)
7441 else if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == TREE_LIST
7442 && TREE_PURPOSE (OMP_CLAUSE_DECL (c
))
7443 && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c
)))
7445 TREE_VALUE (OMP_CLAUSE_DECL (c
)) = t
;
7447 OMP_CLAUSE_DECL (c
) = t
;
7451 case OMP_CLAUSE_DETACH
:
7452 t
= OMP_CLAUSE_DECL (c
);
7455 error_at (OMP_CLAUSE_LOCATION (c
),
7456 "too many %qs clauses on a task construct",
7461 else if (error_operand_p (t
))
7468 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
7469 if (!type_dependent_expression_p (t
)
7470 && (!INTEGRAL_TYPE_P (type
)
7471 || TREE_CODE (type
) != ENUMERAL_TYPE
7472 || TYPE_NAME (type
) == NULL_TREE
7473 || (DECL_NAME (TYPE_NAME (type
))
7474 != get_identifier ("omp_event_handle_t"))))
7476 error_at (OMP_CLAUSE_LOCATION (c
),
7477 "%<detach%> clause event handle "
7478 "has type %qT rather than "
7479 "%<omp_event_handle_t%>",
7484 cxx_mark_addressable (t
);
7488 case OMP_CLAUSE_MAP
:
7490 case OMP_CLAUSE_FROM
:
7491 case OMP_CLAUSE__CACHE_
:
7492 t
= OMP_CLAUSE_DECL (c
);
7493 if (TREE_CODE (t
) == TREE_LIST
)
7495 if (handle_omp_array_sections (c
, ort
))
7499 t
= OMP_CLAUSE_DECL (c
);
7500 if (TREE_CODE (t
) != TREE_LIST
7501 && !type_dependent_expression_p (t
)
7502 && !cp_omp_mappable_type (TREE_TYPE (t
)))
7504 error_at (OMP_CLAUSE_LOCATION (c
),
7505 "array section does not have mappable type "
7507 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7508 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7511 while (TREE_CODE (t
) == ARRAY_REF
)
7512 t
= TREE_OPERAND (t
, 0);
7513 if (TREE_CODE (t
) == COMPONENT_REF
7514 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
7516 while (TREE_CODE (t
) == COMPONENT_REF
)
7517 t
= TREE_OPERAND (t
, 0);
7518 if (REFERENCE_REF_P (t
))
7519 t
= TREE_OPERAND (t
, 0);
7520 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7522 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7524 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7525 error_at (OMP_CLAUSE_LOCATION (c
),
7526 "%qD appears more than once in motion"
7528 else if (ort
== C_ORT_ACC
)
7529 error_at (OMP_CLAUSE_LOCATION (c
),
7530 "%qD appears more than once in data"
7533 error_at (OMP_CLAUSE_LOCATION (c
),
7534 "%qD appears more than once in map"
7540 bitmap_set_bit (&map_head
, DECL_UID (t
));
7541 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7545 if (cp_oacc_check_attachments (c
))
7547 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7548 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7549 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7550 /* In this case, we have a single array element which is a
7551 pointer, and we already set OMP_CLAUSE_SIZE in
7552 handle_omp_array_sections above. For attach/detach clauses,
7553 reset the OMP_CLAUSE_SIZE (representing a bias) to zero
7555 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
7558 if (t
== error_mark_node
)
7563 /* OpenACC attach / detach clauses must be pointers. */
7564 if (cp_oacc_check_attachments (c
))
7569 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7570 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7571 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7572 /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
7573 bias) to zero here, so it is not set erroneously to the pointer
7574 size later on in gimplify.c. */
7575 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
7576 if (REFERENCE_REF_P (t
)
7577 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
7579 t
= TREE_OPERAND (t
, 0);
7580 OMP_CLAUSE_DECL (c
) = t
;
7582 if ((ort
== C_ORT_ACC
|| ort
== C_ORT_OMP
)
7583 && TREE_CODE (t
) == COMPONENT_REF
7584 && TREE_CODE (TREE_OPERAND (t
, 0)) == INDIRECT_REF
)
7585 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
7586 if (TREE_CODE (t
) == COMPONENT_REF
7587 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
7588 || ort
== C_ORT_ACC
)
7589 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
7591 if (type_dependent_expression_p (t
))
7593 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7594 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7596 error_at (OMP_CLAUSE_LOCATION (c
),
7597 "bit-field %qE in %qs clause",
7598 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7601 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7603 error_at (OMP_CLAUSE_LOCATION (c
),
7604 "%qE does not have a mappable type in %qs clause",
7605 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7606 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7609 while (TREE_CODE (t
) == COMPONENT_REF
)
7611 if (TREE_TYPE (TREE_OPERAND (t
, 0))
7612 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
7615 error_at (OMP_CLAUSE_LOCATION (c
),
7616 "%qE is a member of a union", t
);
7620 t
= TREE_OPERAND (t
, 0);
7624 if (REFERENCE_REF_P (t
))
7625 t
= TREE_OPERAND (t
, 0);
7626 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7628 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
))
7629 || (ort
== C_ORT_OMP
7630 && bitmap_bit_p (&map_head
, DECL_UID (t
))))
7631 goto handle_map_references
;
7634 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7636 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7638 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7639 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7640 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
7641 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH_DETACH
))
7644 error_at (OMP_CLAUSE_LOCATION (c
),
7645 "%qD is not a variable in %qs clause", t
,
7646 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7648 error_at (OMP_CLAUSE_LOCATION (c
),
7649 "%qE is not a variable in %qs clause", t
,
7650 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7653 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7655 error_at (OMP_CLAUSE_LOCATION (c
),
7656 "%qD is threadprivate variable in %qs clause", t
,
7657 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7660 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7662 error_at (OMP_CLAUSE_LOCATION (c
),
7663 "%<this%> allowed in OpenMP only in %<declare simd%>"
7668 else if (!processing_template_decl
7669 && !TYPE_REF_P (TREE_TYPE (t
))
7670 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
7671 || (OMP_CLAUSE_MAP_KIND (c
)
7672 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
7673 && !cxx_mark_addressable (t
))
7675 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7676 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7677 || (OMP_CLAUSE_MAP_KIND (c
)
7678 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
7679 && t
== OMP_CLAUSE_DECL (c
)
7680 && !type_dependent_expression_p (t
)
7681 && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t
))
7682 ? TREE_TYPE (TREE_TYPE (t
))
7685 error_at (OMP_CLAUSE_LOCATION (c
),
7686 "%qD does not have a mappable type in %qs clause", t
,
7687 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7688 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7691 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7692 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
7693 && !type_dependent_expression_p (t
)
7694 && !INDIRECT_TYPE_P (TREE_TYPE (t
)))
7696 error_at (OMP_CLAUSE_LOCATION (c
),
7697 "%qD is not a pointer variable", t
);
7700 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7701 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
7703 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7704 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7706 error_at (OMP_CLAUSE_LOCATION (c
),
7707 "%qD appears more than once in data clauses", t
);
7710 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7712 if (ort
== C_ORT_ACC
)
7713 error_at (OMP_CLAUSE_LOCATION (c
),
7714 "%qD appears more than once in data clauses", t
);
7716 error_at (OMP_CLAUSE_LOCATION (c
),
7717 "%qD appears both in data and map clauses", t
);
7721 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7723 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
7724 && !bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7726 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7727 error_at (OMP_CLAUSE_LOCATION (c
),
7728 "%qD appears more than once in motion clauses", t
);
7729 else if (ort
== C_ORT_ACC
)
7730 error_at (OMP_CLAUSE_LOCATION (c
),
7731 "%qD appears more than once in data clauses", t
);
7733 error_at (OMP_CLAUSE_LOCATION (c
),
7734 "%qD appears more than once in map clauses", t
);
7737 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7738 && ort
== C_ORT_ACC
)
7740 error_at (OMP_CLAUSE_LOCATION (c
),
7741 "%qD appears more than once in data clauses", t
);
7744 else if (bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7746 if (ort
== C_ORT_ACC
)
7747 error_at (OMP_CLAUSE_LOCATION (c
),
7748 "%qD appears more than once in data clauses", t
);
7750 error_at (OMP_CLAUSE_LOCATION (c
),
7751 "%qD appears both in data and map clauses", t
);
7756 bitmap_set_bit (&map_head
, DECL_UID (t
));
7757 if (t
!= OMP_CLAUSE_DECL (c
)
7758 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
7759 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7761 handle_map_references
:
7763 && !processing_template_decl
7764 && ort
!= C_ORT_DECLARE_SIMD
7765 && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
))))
7767 t
= OMP_CLAUSE_DECL (c
);
7768 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7770 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7771 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7773 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7775 else if (OMP_CLAUSE_MAP_KIND (c
)
7776 != GOMP_MAP_FIRSTPRIVATE_POINTER
7777 && (OMP_CLAUSE_MAP_KIND (c
)
7778 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
7779 && (OMP_CLAUSE_MAP_KIND (c
)
7780 != GOMP_MAP_ALWAYS_POINTER
)
7781 && (OMP_CLAUSE_MAP_KIND (c
)
7782 != GOMP_MAP_ATTACH_DETACH
))
7784 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
7786 if (TREE_CODE (t
) == COMPONENT_REF
)
7787 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ATTACH_DETACH
);
7789 OMP_CLAUSE_SET_MAP_KIND (c2
,
7790 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
7791 OMP_CLAUSE_DECL (c2
) = t
;
7792 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
7793 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
7794 OMP_CLAUSE_CHAIN (c
) = c2
;
7795 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7796 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7798 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7804 case OMP_CLAUSE_TO_DECLARE
:
7805 case OMP_CLAUSE_LINK
:
7806 t
= OMP_CLAUSE_DECL (c
);
7807 if (TREE_CODE (t
) == FUNCTION_DECL
7808 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7810 else if (!VAR_P (t
))
7812 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7814 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
7815 error_at (OMP_CLAUSE_LOCATION (c
),
7816 "template %qE in clause %qs", t
,
7817 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7818 else if (really_overloaded_fn (t
))
7819 error_at (OMP_CLAUSE_LOCATION (c
),
7820 "overloaded function name %qE in clause %qs", t
,
7821 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7823 error_at (OMP_CLAUSE_LOCATION (c
),
7824 "%qE is neither a variable nor a function name "
7826 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7829 error_at (OMP_CLAUSE_LOCATION (c
),
7830 "%qE is not a variable in clause %qs", t
,
7831 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7834 else if (DECL_THREAD_LOCAL_P (t
))
7836 error_at (OMP_CLAUSE_LOCATION (c
),
7837 "%qD is threadprivate variable in %qs clause", t
,
7838 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7841 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7843 error_at (OMP_CLAUSE_LOCATION (c
),
7844 "%qD does not have a mappable type in %qs clause", t
,
7845 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7846 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7851 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
7853 error_at (OMP_CLAUSE_LOCATION (c
),
7854 "%qE appears more than once on the same "
7855 "%<declare target%> directive", t
);
7859 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7862 case OMP_CLAUSE_UNIFORM
:
7863 t
= OMP_CLAUSE_DECL (c
);
7864 if (TREE_CODE (t
) != PARM_DECL
)
7866 if (processing_template_decl
)
7869 error_at (OMP_CLAUSE_LOCATION (c
),
7870 "%qD is not an argument in %<uniform%> clause", t
);
7872 error_at (OMP_CLAUSE_LOCATION (c
),
7873 "%qE is not an argument in %<uniform%> clause", t
);
7877 /* map_head bitmap is used as uniform_head if declare_simd. */
7878 bitmap_set_bit (&map_head
, DECL_UID (t
));
7879 goto check_dup_generic
;
7881 case OMP_CLAUSE_GRAINSIZE
:
7882 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
7883 if (t
== error_mark_node
)
7885 else if (!type_dependent_expression_p (t
)
7886 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7888 error_at (OMP_CLAUSE_LOCATION (c
),
7889 "%<grainsize%> expression must be integral");
7894 t
= mark_rvalue_use (t
);
7895 if (!processing_template_decl
)
7897 t
= maybe_constant_value (t
);
7898 if (TREE_CODE (t
) == INTEGER_CST
7899 && tree_int_cst_sgn (t
) != 1)
7901 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7902 "%<grainsize%> value must be positive");
7903 t
= integer_one_node
;
7905 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7907 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
7911 case OMP_CLAUSE_PRIORITY
:
7912 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
7913 if (t
== error_mark_node
)
7915 else if (!type_dependent_expression_p (t
)
7916 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7918 error_at (OMP_CLAUSE_LOCATION (c
),
7919 "%<priority%> expression must be integral");
7924 t
= mark_rvalue_use (t
);
7925 if (!processing_template_decl
)
7927 t
= maybe_constant_value (t
);
7928 if (TREE_CODE (t
) == INTEGER_CST
7929 && tree_int_cst_sgn (t
) == -1)
7931 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7932 "%<priority%> value must be non-negative");
7933 t
= integer_one_node
;
7935 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7937 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
7941 case OMP_CLAUSE_HINT
:
7942 t
= OMP_CLAUSE_HINT_EXPR (c
);
7943 if (t
== error_mark_node
)
7945 else if (!type_dependent_expression_p (t
)
7946 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7948 error_at (OMP_CLAUSE_LOCATION (c
),
7949 "%<hint%> expression must be integral");
7954 t
= mark_rvalue_use (t
);
7955 if (!processing_template_decl
)
7957 t
= maybe_constant_value (t
);
7958 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7959 if (TREE_CODE (t
) != INTEGER_CST
)
7961 error_at (OMP_CLAUSE_LOCATION (c
),
7962 "%<hint%> expression must be constant integer "
7967 OMP_CLAUSE_HINT_EXPR (c
) = t
;
7971 case OMP_CLAUSE_IS_DEVICE_PTR
:
7972 case OMP_CLAUSE_USE_DEVICE_PTR
:
7973 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
7974 t
= OMP_CLAUSE_DECL (c
);
7975 if (!type_dependent_expression_p (t
))
7977 tree type
= TREE_TYPE (t
);
7978 if (!TYPE_PTR_P (type
)
7979 && (!TYPE_REF_P (type
) || !TYPE_PTR_P (TREE_TYPE (type
))))
7981 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
7982 && ort
== C_ORT_OMP
)
7984 error_at (OMP_CLAUSE_LOCATION (c
),
7985 "%qs variable is neither a pointer "
7986 "nor reference to pointer",
7987 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7990 else if (TREE_CODE (type
) != ARRAY_TYPE
7991 && (!TYPE_REF_P (type
)
7992 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
7994 error_at (OMP_CLAUSE_LOCATION (c
),
7995 "%qs variable is neither a pointer, nor an "
7996 "array nor reference to pointer or array",
7997 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8002 goto check_dup_generic
;
8004 case OMP_CLAUSE_USE_DEVICE_ADDR
:
8006 t
= OMP_CLAUSE_DECL (c
);
8007 if (!processing_template_decl
8008 && (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
8009 && !TYPE_REF_P (TREE_TYPE (t
))
8010 && !cxx_mark_addressable (t
))
8012 goto check_dup_generic
;
8014 case OMP_CLAUSE_NOWAIT
:
8015 case OMP_CLAUSE_DEFAULT
:
8016 case OMP_CLAUSE_UNTIED
:
8017 case OMP_CLAUSE_COLLAPSE
:
8018 case OMP_CLAUSE_PARALLEL
:
8019 case OMP_CLAUSE_FOR
:
8020 case OMP_CLAUSE_SECTIONS
:
8021 case OMP_CLAUSE_TASKGROUP
:
8022 case OMP_CLAUSE_PROC_BIND
:
8023 case OMP_CLAUSE_DEVICE_TYPE
:
8024 case OMP_CLAUSE_NOGROUP
:
8025 case OMP_CLAUSE_THREADS
:
8026 case OMP_CLAUSE_SIMD
:
8027 case OMP_CLAUSE_DEFAULTMAP
:
8028 case OMP_CLAUSE_BIND
:
8029 case OMP_CLAUSE_AUTO
:
8030 case OMP_CLAUSE_INDEPENDENT
:
8031 case OMP_CLAUSE_SEQ
:
8032 case OMP_CLAUSE_IF_PRESENT
:
8033 case OMP_CLAUSE_FINALIZE
:
8036 case OMP_CLAUSE_MERGEABLE
:
8037 mergeable_seen
= true;
8040 case OMP_CLAUSE_TILE
:
8041 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
8042 list
= TREE_CHAIN (list
))
8044 t
= TREE_VALUE (list
);
8046 if (t
== error_mark_node
)
8048 else if (!type_dependent_expression_p (t
)
8049 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8051 error_at (OMP_CLAUSE_LOCATION (c
),
8052 "%<tile%> argument needs integral type");
8057 t
= mark_rvalue_use (t
);
8058 if (!processing_template_decl
)
8060 /* Zero is used to indicate '*', we permit you
8061 to get there via an ICE of value zero. */
8062 t
= maybe_constant_value (t
);
8063 if (!tree_fits_shwi_p (t
)
8064 || tree_to_shwi (t
) < 0)
8066 error_at (OMP_CLAUSE_LOCATION (c
),
8067 "%<tile%> argument needs positive "
8068 "integral constant");
8071 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8075 /* Update list item. */
8076 TREE_VALUE (list
) = t
;
8080 case OMP_CLAUSE_ORDERED
:
8081 ordered_seen
= true;
8084 case OMP_CLAUSE_ORDER
:
8091 case OMP_CLAUSE_INBRANCH
:
8092 case OMP_CLAUSE_NOTINBRANCH
:
8095 error_at (OMP_CLAUSE_LOCATION (c
),
8096 "%<inbranch%> clause is incompatible with "
8103 case OMP_CLAUSE_INCLUSIVE
:
8104 case OMP_CLAUSE_EXCLUSIVE
:
8105 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8107 t
= OMP_CLAUSE_DECL (c
);
8108 if (t
== current_class_ptr
)
8110 error_at (OMP_CLAUSE_LOCATION (c
),
8111 "%<this%> allowed in OpenMP only in %<declare simd%>"
8117 && TREE_CODE (t
) != PARM_DECL
8118 && TREE_CODE (t
) != FIELD_DECL
)
8120 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8123 error_at (OMP_CLAUSE_LOCATION (c
),
8124 "%qD is not a variable in clause %qs", t
,
8125 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8127 error_at (OMP_CLAUSE_LOCATION (c
),
8128 "%qE is not a variable in clause %qs", t
,
8129 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8139 *pc
= OMP_CLAUSE_CHAIN (c
);
8141 pc
= &OMP_CLAUSE_CHAIN (c
);
8144 if (reduction_seen
< 0 && (ordered_seen
|| schedule_seen
))
8145 reduction_seen
= -2;
8147 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
8149 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
8150 bool remove
= false;
8151 bool need_complete_type
= false;
8152 bool need_default_ctor
= false;
8153 bool need_copy_ctor
= false;
8154 bool need_copy_assignment
= false;
8155 bool need_implicitly_determined
= false;
8156 bool need_dtor
= false;
8157 tree type
, inner_type
;
8161 case OMP_CLAUSE_SHARED
:
8162 need_implicitly_determined
= true;
8164 case OMP_CLAUSE_PRIVATE
:
8165 need_complete_type
= true;
8166 need_default_ctor
= true;
8168 need_implicitly_determined
= true;
8170 case OMP_CLAUSE_FIRSTPRIVATE
:
8171 need_complete_type
= true;
8172 need_copy_ctor
= true;
8174 need_implicitly_determined
= true;
8176 case OMP_CLAUSE_LASTPRIVATE
:
8177 need_complete_type
= true;
8178 need_copy_assignment
= true;
8179 need_implicitly_determined
= true;
8181 case OMP_CLAUSE_REDUCTION
:
8182 if (reduction_seen
== -2)
8183 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
8184 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
8185 need_copy_assignment
= true;
8186 need_implicitly_determined
= true;
8188 case OMP_CLAUSE_IN_REDUCTION
:
8189 case OMP_CLAUSE_TASK_REDUCTION
:
8190 case OMP_CLAUSE_INCLUSIVE
:
8191 case OMP_CLAUSE_EXCLUSIVE
:
8192 need_implicitly_determined
= true;
8194 case OMP_CLAUSE_LINEAR
:
8195 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
8196 need_implicitly_determined
= true;
8197 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
8198 && !bitmap_bit_p (&map_head
,
8199 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
8201 error_at (OMP_CLAUSE_LOCATION (c
),
8202 "%<linear%> clause step is a parameter %qD not "
8203 "specified in %<uniform%> clause",
8204 OMP_CLAUSE_LINEAR_STEP (c
));
8205 *pc
= OMP_CLAUSE_CHAIN (c
);
8209 case OMP_CLAUSE_COPYPRIVATE
:
8210 need_copy_assignment
= true;
8212 case OMP_CLAUSE_COPYIN
:
8213 need_copy_assignment
= true;
8215 case OMP_CLAUSE_SIMDLEN
:
8217 && !processing_template_decl
8218 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
8219 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
8221 error_at (OMP_CLAUSE_LOCATION (c
),
8222 "%<simdlen%> clause value is bigger than "
8223 "%<safelen%> clause value");
8224 OMP_CLAUSE_SIMDLEN_EXPR (c
)
8225 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
8227 pc
= &OMP_CLAUSE_CHAIN (c
);
8229 case OMP_CLAUSE_SCHEDULE
:
8231 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
8232 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
8234 error_at (OMP_CLAUSE_LOCATION (c
),
8235 "%<nonmonotonic%> schedule modifier specified "
8236 "together with %<ordered%> clause");
8237 OMP_CLAUSE_SCHEDULE_KIND (c
)
8238 = (enum omp_clause_schedule_kind
)
8239 (OMP_CLAUSE_SCHEDULE_KIND (c
)
8240 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
8242 if (reduction_seen
== -2)
8243 error_at (OMP_CLAUSE_LOCATION (c
),
8244 "%qs clause specified together with %<inscan%> "
8245 "%<reduction%> clause", "schedule");
8246 pc
= &OMP_CLAUSE_CHAIN (c
);
8248 case OMP_CLAUSE_NOGROUP
:
8251 error_at (OMP_CLAUSE_LOCATION (c
),
8252 "%<nogroup%> clause must not be used together with "
8253 "%<reduction%> clause");
8254 *pc
= OMP_CLAUSE_CHAIN (c
);
8257 pc
= &OMP_CLAUSE_CHAIN (c
);
8259 case OMP_CLAUSE_ORDERED
:
8260 if (reduction_seen
== -2)
8261 error_at (OMP_CLAUSE_LOCATION (c
),
8262 "%qs clause specified together with %<inscan%> "
8263 "%<reduction%> clause", "ordered");
8264 pc
= &OMP_CLAUSE_CHAIN (c
);
8266 case OMP_CLAUSE_ORDER
:
8269 error_at (OMP_CLAUSE_LOCATION (c
),
8270 "%<order%> clause must not be used together "
8271 "with %<ordered%>");
8272 *pc
= OMP_CLAUSE_CHAIN (c
);
8275 pc
= &OMP_CLAUSE_CHAIN (c
);
8277 case OMP_CLAUSE_DETACH
:
8280 error_at (OMP_CLAUSE_LOCATION (c
),
8281 "%<detach%> clause must not be used together with "
8282 "%<mergeable%> clause");
8283 *pc
= OMP_CLAUSE_CHAIN (c
);
8286 pc
= &OMP_CLAUSE_CHAIN (c
);
8288 case OMP_CLAUSE_NOWAIT
:
8289 if (copyprivate_seen
)
8291 error_at (OMP_CLAUSE_LOCATION (c
),
8292 "%<nowait%> clause must not be used together "
8293 "with %<copyprivate%>");
8294 *pc
= OMP_CLAUSE_CHAIN (c
);
8299 pc
= &OMP_CLAUSE_CHAIN (c
);
8303 t
= OMP_CLAUSE_DECL (c
);
8306 case OMP_CLAUSE_LASTPRIVATE
:
8308 && !bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
8310 need_default_ctor
= true;
8315 case OMP_CLAUSE_REDUCTION
:
8316 case OMP_CLAUSE_IN_REDUCTION
:
8317 case OMP_CLAUSE_TASK_REDUCTION
:
8320 if (TREE_CODE (t
) == MEM_REF
)
8322 t
= TREE_OPERAND (t
, 0);
8323 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
8324 t
= TREE_OPERAND (t
, 0);
8325 if (TREE_CODE (t
) == ADDR_EXPR
8326 || TREE_CODE (t
) == INDIRECT_REF
)
8327 t
= TREE_OPERAND (t
, 0);
8329 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8331 else if (TREE_CODE (t
) == TREE_LIST
)
8333 while (TREE_CODE (t
) == TREE_LIST
)
8336 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8337 t
= OMP_CLAUSE_DECL (c
);
8339 else if (DECL_P (t
))
8340 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8341 t
= OMP_CLAUSE_DECL (c
);
8343 if (processing_template_decl
8344 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8346 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
8350 t
= OMP_CLAUSE_DECL (c
);
8353 case OMP_CLAUSE_COPYIN
:
8354 if (processing_template_decl
8355 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8357 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
8359 error_at (OMP_CLAUSE_LOCATION (c
),
8360 "%qE must be %<threadprivate%> for %<copyin%>", t
);
8369 if (processing_template_decl
8370 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8372 pc
= &OMP_CLAUSE_CHAIN (c
);
8376 if (need_complete_type
|| need_copy_assignment
)
8378 t
= require_complete_type (t
);
8379 if (t
== error_mark_node
)
8381 else if (!processing_template_decl
8382 && TYPE_REF_P (TREE_TYPE (t
))
8383 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
8386 if (need_implicitly_determined
)
8388 const char *share_name
= NULL
;
8391 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8393 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8395 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
8396 share_name
= "threadprivate";
8397 else switch (cxx_omp_predetermined_sharing_1 (t
))
8399 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
8401 case OMP_CLAUSE_DEFAULT_SHARED
:
8402 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8403 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8404 && c_omp_predefined_variable (t
))
8405 /* The __func__ variable and similar function-local predefined
8406 variables may be listed in a shared or firstprivate
8410 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8412 && cxx_omp_const_qual_no_mutable (t
))
8414 tree ctx
= CP_DECL_CONTEXT (t
);
8415 /* const qualified static data members without mutable
8416 member may be specified in firstprivate clause. */
8417 if (TYPE_P (ctx
) && MAYBE_CLASS_TYPE_P (ctx
))
8420 share_name
= "shared";
8422 case OMP_CLAUSE_DEFAULT_PRIVATE
:
8423 share_name
= "private";
8430 error_at (OMP_CLAUSE_LOCATION (c
),
8431 "%qE is predetermined %qs for %qs",
8432 omp_clause_printable_decl (t
), share_name
,
8433 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8436 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8437 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_FIRSTPRIVATE
8438 && cxx_omp_const_qual_no_mutable (t
))
8440 error_at (OMP_CLAUSE_LOCATION (c
),
8441 "%<const%> qualified %qE without %<mutable%> member "
8442 "may appear only in %<shared%> or %<firstprivate%> "
8443 "clauses", omp_clause_printable_decl (t
));
8449 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8450 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
8451 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8452 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
8453 && OMP_CLAUSE_DECL (c
) == t
)
8455 error_at (OMP_CLAUSE_LOCATION (c
),
8456 "the event handle of a %<detach%> clause "
8457 "should not be in a data-sharing clause");
8461 /* We're interested in the base element, not arrays. */
8462 inner_type
= type
= TREE_TYPE (t
);
8463 if ((need_complete_type
8464 || need_copy_assignment
8465 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
8466 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
8467 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
8468 && TYPE_REF_P (inner_type
))
8469 inner_type
= TREE_TYPE (inner_type
);
8470 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
8471 inner_type
= TREE_TYPE (inner_type
);
8473 /* Check for special function availability by building a call to one.
8474 Save the results, because later we won't be in the right context
8475 for making these queries. */
8476 if (CLASS_TYPE_P (inner_type
)
8477 && COMPLETE_TYPE_P (inner_type
)
8478 && (need_default_ctor
|| need_copy_ctor
8479 || need_copy_assignment
|| need_dtor
)
8480 && !type_dependent_expression_p (t
)
8481 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
8482 need_copy_ctor
, need_copy_assignment
,
8487 && c_kind
== OMP_CLAUSE_SHARED
8488 && processing_template_decl
)
8490 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8492 OMP_CLAUSE_DECL (c
) = t
;
8496 *pc
= OMP_CLAUSE_CHAIN (c
);
8498 pc
= &OMP_CLAUSE_CHAIN (c
);
8502 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
8504 bool remove
= false;
8505 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ALLOCATE
8506 && !OMP_CLAUSE_ALLOCATE_COMBINED (c
)
8507 && DECL_P (OMP_CLAUSE_DECL (c
))
8508 && bitmap_bit_p (&aligned_head
, DECL_UID (OMP_CLAUSE_DECL (c
))))
8510 error_at (OMP_CLAUSE_LOCATION (c
),
8511 "%qD specified in %<allocate%> clause but not in "
8512 "an explicit privatization clause", OMP_CLAUSE_DECL (c
));
8516 *pc
= OMP_CLAUSE_CHAIN (c
);
8518 pc
= &OMP_CLAUSE_CHAIN (c
);
8521 bitmap_obstack_release (NULL
);
8525 /* Start processing OpenMP clauses that can include any
8526 privatization clauses for non-static data members. */
8529 push_omp_privatization_clauses (bool ignore_next
)
8531 if (omp_private_member_ignore_next
)
8533 omp_private_member_ignore_next
= ignore_next
;
8536 omp_private_member_ignore_next
= ignore_next
;
8537 if (omp_private_member_map
)
8538 omp_private_member_vec
.safe_push (error_mark_node
);
8539 return push_stmt_list ();
8542 /* Revert remapping of any non-static data members since
8543 the last push_omp_privatization_clauses () call. */
8546 pop_omp_privatization_clauses (tree stmt
)
8548 if (stmt
== NULL_TREE
)
8550 stmt
= pop_stmt_list (stmt
);
8551 if (omp_private_member_map
)
8553 while (!omp_private_member_vec
.is_empty ())
8555 tree t
= omp_private_member_vec
.pop ();
8556 if (t
== error_mark_node
)
8561 bool no_decl_expr
= t
== integer_zero_node
;
8563 t
= omp_private_member_vec
.pop ();
8564 tree
*v
= omp_private_member_map
->get (t
);
8568 omp_private_member_map
->remove (t
);
8570 delete omp_private_member_map
;
8571 omp_private_member_map
= NULL
;
8576 /* Remember OpenMP privatization clauses mapping and clear it.
8577 Used for lambdas. */
8580 save_omp_privatization_clauses (vec
<tree
> &save
)
8583 if (omp_private_member_ignore_next
)
8584 save
.safe_push (integer_one_node
);
8585 omp_private_member_ignore_next
= false;
8586 if (!omp_private_member_map
)
8589 while (!omp_private_member_vec
.is_empty ())
8591 tree t
= omp_private_member_vec
.pop ();
8592 if (t
== error_mark_node
)
8598 if (t
== integer_zero_node
)
8599 t
= omp_private_member_vec
.pop ();
8600 tree
*v
= omp_private_member_map
->get (t
);
8602 save
.safe_push (*v
);
8607 delete omp_private_member_map
;
8608 omp_private_member_map
= NULL
;
8611 /* Restore OpenMP privatization clauses mapping saved by the
8615 restore_omp_privatization_clauses (vec
<tree
> &save
)
8617 gcc_assert (omp_private_member_vec
.is_empty ());
8618 omp_private_member_ignore_next
= false;
8619 if (save
.is_empty ())
8621 if (save
.length () == 1 && save
[0] == integer_one_node
)
8623 omp_private_member_ignore_next
= true;
8628 omp_private_member_map
= new hash_map
<tree
, tree
>;
8629 while (!save
.is_empty ())
8631 tree t
= save
.pop ();
8633 if (t
!= error_mark_node
)
8635 if (t
== integer_one_node
)
8637 omp_private_member_ignore_next
= true;
8638 gcc_assert (save
.is_empty ());
8641 if (t
== integer_zero_node
)
8643 tree
&v
= omp_private_member_map
->get_or_insert (t
);
8646 omp_private_member_vec
.safe_push (t
);
8648 omp_private_member_vec
.safe_push (n
);
8653 /* For all variables in the tree_list VARS, mark them as thread local. */
8656 finish_omp_threadprivate (tree vars
)
8660 /* Mark every variable in VARS to be assigned thread local storage. */
8661 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8663 tree v
= TREE_PURPOSE (t
);
8665 if (error_operand_p (v
))
8667 else if (!VAR_P (v
))
8668 error ("%<threadprivate%> %qD is not file, namespace "
8669 "or block scope variable", v
);
8670 /* If V had already been marked threadprivate, it doesn't matter
8671 whether it had been used prior to this point. */
8672 else if (TREE_USED (v
)
8673 && (DECL_LANG_SPECIFIC (v
) == NULL
8674 || !CP_DECL_THREADPRIVATE_P (v
)))
8675 error ("%qE declared %<threadprivate%> after first use", v
);
8676 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8677 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8678 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
8679 error ("%<threadprivate%> %qE has incomplete type", v
);
8680 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
8681 && CP_DECL_CONTEXT (v
) != current_class_type
)
8682 error ("%<threadprivate%> %qE directive not "
8683 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
8686 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
8687 if (DECL_LANG_SPECIFIC (v
) == NULL
)
8688 retrofit_lang_decl (v
);
8690 if (! CP_DECL_THREAD_LOCAL_P (v
))
8692 CP_DECL_THREAD_LOCAL_P (v
) = true;
8693 set_decl_tls_model (v
, decl_default_tls_model (v
));
8694 /* If rtl has been already set for this var, call
8695 make_decl_rtl once again, so that encode_section_info
8696 has a chance to look at the new decl flags. */
8697 if (DECL_RTL_SET_P (v
))
8700 CP_DECL_THREADPRIVATE_P (v
) = 1;
8705 /* Build an OpenMP structured block. */
8708 begin_omp_structured_block (void)
8710 return do_pushlevel (sk_omp
);
8714 finish_omp_structured_block (tree block
)
8716 return do_poplevel (block
);
8719 /* Similarly, except force the retention of the BLOCK. */
8722 begin_omp_parallel (void)
8724 keep_next_level (true);
8725 return begin_omp_structured_block ();
8728 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
8732 finish_oacc_data (tree clauses
, tree block
)
8736 block
= finish_omp_structured_block (block
);
8738 stmt
= make_node (OACC_DATA
);
8739 TREE_TYPE (stmt
) = void_type_node
;
8740 OACC_DATA_CLAUSES (stmt
) = clauses
;
8741 OACC_DATA_BODY (stmt
) = block
;
8743 return add_stmt (stmt
);
8746 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
8750 finish_oacc_host_data (tree clauses
, tree block
)
8754 block
= finish_omp_structured_block (block
);
8756 stmt
= make_node (OACC_HOST_DATA
);
8757 TREE_TYPE (stmt
) = void_type_node
;
8758 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
8759 OACC_HOST_DATA_BODY (stmt
) = block
;
8761 return add_stmt (stmt
);
8764 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
8768 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
8770 body
= finish_omp_structured_block (body
);
8772 tree stmt
= make_node (code
);
8773 TREE_TYPE (stmt
) = void_type_node
;
8774 OMP_BODY (stmt
) = body
;
8775 OMP_CLAUSES (stmt
) = clauses
;
8777 return add_stmt (stmt
);
8781 finish_omp_parallel (tree clauses
, tree body
)
8785 body
= finish_omp_structured_block (body
);
8787 stmt
= make_node (OMP_PARALLEL
);
8788 TREE_TYPE (stmt
) = void_type_node
;
8789 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
8790 OMP_PARALLEL_BODY (stmt
) = body
;
8792 return add_stmt (stmt
);
8796 begin_omp_task (void)
8798 keep_next_level (true);
8799 return begin_omp_structured_block ();
8803 finish_omp_task (tree clauses
, tree body
)
8807 body
= finish_omp_structured_block (body
);
8809 stmt
= make_node (OMP_TASK
);
8810 TREE_TYPE (stmt
) = void_type_node
;
8811 OMP_TASK_CLAUSES (stmt
) = clauses
;
8812 OMP_TASK_BODY (stmt
) = body
;
8814 return add_stmt (stmt
);
8817 /* Helper function for finish_omp_for. Convert Ith random access iterator
8818 into integral iterator. Return FALSE if successful. */
8821 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
8822 tree declv
, tree orig_declv
, tree initv
,
8823 tree condv
, tree incrv
, tree
*body
,
8824 tree
*pre_body
, tree
&clauses
,
8825 int collapse
, int ordered
)
8827 tree diff
, iter_init
, iter_incr
= NULL
, last
;
8828 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
8829 tree decl
= TREE_VEC_ELT (declv
, i
);
8830 tree init
= TREE_VEC_ELT (initv
, i
);
8831 tree cond
= TREE_VEC_ELT (condv
, i
);
8832 tree incr
= TREE_VEC_ELT (incrv
, i
);
8834 location_t elocus
= locus
;
8836 if (init
&& EXPR_HAS_LOCATION (init
))
8837 elocus
= EXPR_LOCATION (init
);
8839 switch (TREE_CODE (cond
))
8846 if (TREE_OPERAND (cond
, 1) == iter
)
8847 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
8848 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
8849 if (TREE_OPERAND (cond
, 0) != iter
)
8850 cond
= error_mark_node
;
8853 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
8856 TREE_OPERAND (cond
, 1), ERROR_MARK
,
8857 NULL
, tf_warning_or_error
);
8858 if (error_operand_p (tem
))
8863 cond
= error_mark_node
;
8866 if (cond
== error_mark_node
)
8868 error_at (elocus
, "invalid controlling predicate");
8871 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
8872 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
8873 tf_warning_or_error
);
8874 diff
= cp_fully_fold (diff
);
8875 if (error_operand_p (diff
))
8877 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
8879 error_at (elocus
, "difference between %qE and %qD does not have integer type",
8880 TREE_OPERAND (cond
, 1), iter
);
8883 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
, i
,
8884 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
8885 cond
, cp_walk_subtrees
))
8888 switch (TREE_CODE (incr
))
8890 case PREINCREMENT_EXPR
:
8891 case PREDECREMENT_EXPR
:
8892 case POSTINCREMENT_EXPR
:
8893 case POSTDECREMENT_EXPR
:
8894 if (TREE_OPERAND (incr
, 0) != iter
)
8896 incr
= error_mark_node
;
8899 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
8900 TREE_CODE (incr
), iter
,
8901 tf_warning_or_error
);
8902 if (error_operand_p (iter_incr
))
8904 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
8905 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
8906 incr
= integer_one_node
;
8908 incr
= integer_minus_one_node
;
8911 if (TREE_OPERAND (incr
, 0) != iter
)
8912 incr
= error_mark_node
;
8913 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
8914 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
8916 tree rhs
= TREE_OPERAND (incr
, 1);
8917 if (TREE_OPERAND (rhs
, 0) == iter
)
8919 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
8921 incr
= error_mark_node
;
8924 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8925 iter
, TREE_CODE (rhs
),
8926 TREE_OPERAND (rhs
, 1),
8927 tf_warning_or_error
);
8928 if (error_operand_p (iter_incr
))
8930 incr
= TREE_OPERAND (rhs
, 1);
8931 incr
= cp_convert (TREE_TYPE (diff
), incr
,
8932 tf_warning_or_error
);
8933 if (TREE_CODE (rhs
) == MINUS_EXPR
)
8935 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
8936 incr
= fold_simple (incr
);
8938 if (TREE_CODE (incr
) != INTEGER_CST
8939 && (TREE_CODE (incr
) != NOP_EXPR
8940 || (TREE_CODE (TREE_OPERAND (incr
, 0))
8945 else if (TREE_OPERAND (rhs
, 1) == iter
)
8947 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
8948 || TREE_CODE (rhs
) != PLUS_EXPR
)
8949 incr
= error_mark_node
;
8952 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
8954 TREE_OPERAND (rhs
, 0),
8957 tf_warning_or_error
);
8958 if (error_operand_p (iter_incr
))
8960 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8963 tf_warning_or_error
);
8964 if (error_operand_p (iter_incr
))
8966 incr
= TREE_OPERAND (rhs
, 0);
8971 incr
= error_mark_node
;
8974 incr
= error_mark_node
;
8977 incr
= error_mark_node
;
8981 if (incr
== error_mark_node
)
8983 error_at (elocus
, "invalid increment expression");
8987 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
8988 incr
= cp_fully_fold (incr
);
8989 tree loop_iv_seen
= NULL_TREE
;
8990 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8991 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
8992 && OMP_CLAUSE_DECL (c
) == iter
)
8994 if (code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
8997 OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
) = 1;
9001 else if ((code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
9002 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
9003 && OMP_CLAUSE_DECL (c
) == iter
)
9006 if (code
== OMP_TASKLOOP
)
9007 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
9010 decl
= create_temporary_var (TREE_TYPE (diff
));
9012 add_decl_expr (decl
);
9013 last
= create_temporary_var (TREE_TYPE (diff
));
9015 add_decl_expr (last
);
9016 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
9017 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
9019 incr_var
= create_temporary_var (TREE_TYPE (diff
));
9020 pushdecl (incr_var
);
9021 add_decl_expr (incr_var
);
9023 gcc_assert (stmts_are_full_exprs_p ());
9024 tree diffvar
= NULL_TREE
;
9025 if (code
== OMP_TASKLOOP
)
9029 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9030 OMP_CLAUSE_DECL (ivc
) = iter
;
9031 cxx_omp_finish_clause (ivc
, NULL
, false);
9032 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
9035 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9036 OMP_CLAUSE_DECL (lvc
) = last
;
9037 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
9039 diffvar
= create_temporary_var (TREE_TYPE (diff
));
9041 add_decl_expr (diffvar
);
9043 else if (code
== OMP_LOOP
)
9047 /* While iterators on the loop construct are predetermined
9048 lastprivate, if the decl is not declared inside of the
9049 loop, OMP_CLAUSE_LASTPRIVATE should have been added
9051 loop_iv_seen
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9052 OMP_CLAUSE_DECL (loop_iv_seen
) = iter
;
9053 OMP_CLAUSE_CHAIN (loop_iv_seen
) = clauses
;
9054 clauses
= loop_iv_seen
;
9056 else if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_PRIVATE
)
9058 OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen
) = 0;
9059 OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen
) = 0;
9060 OMP_CLAUSE_CODE (loop_iv_seen
) = OMP_CLAUSE_FIRSTPRIVATE
;
9062 if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_FIRSTPRIVATE
)
9063 cxx_omp_finish_clause (loop_iv_seen
, NULL
, false);
9066 orig_pre_body
= *pre_body
;
9067 *pre_body
= push_stmt_list ();
9069 add_stmt (orig_pre_body
);
9071 finish_expr_stmt (build_x_modify_expr (elocus
,
9072 iter
, NOP_EXPR
, init
,
9073 tf_warning_or_error
));
9074 init
= build_int_cst (TREE_TYPE (diff
), 0);
9075 if (c
&& iter_incr
== NULL
9076 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
9080 finish_expr_stmt (build_x_modify_expr (elocus
,
9082 incr
, tf_warning_or_error
));
9085 iter_incr
= build_x_modify_expr (elocus
,
9086 iter
, PLUS_EXPR
, incr
,
9087 tf_warning_or_error
);
9089 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
9091 finish_expr_stmt (build_x_modify_expr (elocus
,
9092 last
, NOP_EXPR
, init
,
9093 tf_warning_or_error
));
9096 finish_expr_stmt (build_x_modify_expr (elocus
,
9098 diff
, tf_warning_or_error
));
9101 *pre_body
= pop_stmt_list (*pre_body
);
9103 cond
= cp_build_binary_op (elocus
,
9104 TREE_CODE (cond
), decl
, diff
,
9105 tf_warning_or_error
);
9106 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
9107 elocus
, incr
, NULL_TREE
);
9110 *body
= push_stmt_list ();
9111 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
9112 iter_init
= build_x_modify_expr (elocus
,
9113 iter
, PLUS_EXPR
, iter_init
,
9114 tf_warning_or_error
);
9115 if (iter_init
!= error_mark_node
)
9116 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
9117 finish_expr_stmt (iter_init
);
9118 finish_expr_stmt (build_x_modify_expr (elocus
,
9119 last
, NOP_EXPR
, decl
,
9120 tf_warning_or_error
));
9121 add_stmt (orig_body
);
9122 *body
= pop_stmt_list (*body
);
9126 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
9128 finish_expr_stmt (iter_incr
);
9132 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
9133 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
9134 iter_init
, iter_incr
);
9135 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
9136 iter_init
= build_x_modify_expr (elocus
,
9137 iter
, PLUS_EXPR
, iter_init
,
9138 tf_warning_or_error
);
9139 if (iter_init
!= error_mark_node
)
9140 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
9141 finish_expr_stmt (iter_init
);
9143 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
9144 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
9147 if (TREE_CODE (TREE_VEC_ELT (orig_declv
, i
)) == TREE_LIST
)
9149 tree t
= TREE_VEC_ELT (orig_declv
, i
);
9150 gcc_assert (TREE_PURPOSE (t
) == NULL_TREE
9151 && TREE_VALUE (t
) == NULL_TREE
9152 && TREE_CODE (TREE_CHAIN (t
)) == TREE_VEC
);
9153 TREE_PURPOSE (t
) = TREE_VEC_ELT (declv
, i
);
9154 TREE_VALUE (t
) = last
;
9157 TREE_VEC_ELT (orig_declv
, i
)
9158 = tree_cons (TREE_VEC_ELT (declv
, i
), last
, NULL_TREE
);
9159 TREE_VEC_ELT (declv
, i
) = decl
;
9160 TREE_VEC_ELT (initv
, i
) = init
;
9161 TREE_VEC_ELT (condv
, i
) = cond
;
9162 TREE_VEC_ELT (incrv
, i
) = incr
;
9167 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
9168 are directly for their associated operands in the statement. DECL
9169 and INIT are a combo; if DECL is NULL then INIT ought to be a
9170 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
9171 optional statements that need to go before the loop into its
9175 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
9176 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
9177 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
9179 tree omp_for
= NULL
, orig_incr
= NULL
;
9180 tree decl
= NULL
, init
, cond
, incr
;
9186 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
9187 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
9188 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
9189 if (TREE_VEC_LENGTH (declv
) > 1)
9193 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
9195 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
9198 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
9200 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
9201 if (collapse
!= TREE_VEC_LENGTH (declv
))
9202 ordered
= TREE_VEC_LENGTH (declv
);
9205 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
9207 decl
= TREE_VEC_ELT (declv
, i
);
9208 init
= TREE_VEC_ELT (initv
, i
);
9209 cond
= TREE_VEC_ELT (condv
, i
);
9210 incr
= TREE_VEC_ELT (incrv
, i
);
9216 switch (TREE_CODE (init
))
9219 decl
= TREE_OPERAND (init
, 0);
9220 init
= TREE_OPERAND (init
, 1);
9223 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
9225 decl
= TREE_OPERAND (init
, 0);
9226 init
= TREE_OPERAND (init
, 2);
9236 "expected iteration declaration or initialization");
9241 if (init
&& EXPR_HAS_LOCATION (init
))
9242 elocus
= EXPR_LOCATION (init
);
9244 if (cond
== global_namespace
)
9249 error_at (elocus
, "missing controlling predicate");
9255 error_at (elocus
, "missing increment expression");
9259 TREE_VEC_ELT (declv
, i
) = decl
;
9260 TREE_VEC_ELT (initv
, i
) = init
;
9267 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
9269 && !c_omp_check_loop_iv_exprs (locus
,
9270 orig_declv
? orig_declv
: declv
, i
,
9271 TREE_VEC_ELT (declv
, i
), orig_init
,
9272 NULL_TREE
, cp_walk_subtrees
))
9278 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
9282 stmt
= make_node (code
);
9284 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
9286 /* This is really just a place-holder. We'll be decomposing this
9287 again and going through the cp_build_modify_expr path below when
9288 we instantiate the thing. */
9289 TREE_VEC_ELT (initv
, i
)
9290 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
9291 TREE_VEC_ELT (initv
, i
));
9294 TREE_TYPE (stmt
) = void_type_node
;
9295 OMP_FOR_INIT (stmt
) = initv
;
9296 OMP_FOR_COND (stmt
) = condv
;
9297 OMP_FOR_INCR (stmt
) = incrv
;
9298 OMP_FOR_BODY (stmt
) = body
;
9299 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
9300 OMP_FOR_CLAUSES (stmt
) = clauses
;
9302 SET_EXPR_LOCATION (stmt
, locus
);
9303 return add_stmt (stmt
);
9307 orig_declv
= copy_node (declv
);
9309 if (processing_template_decl
)
9310 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
9312 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
9314 decl
= TREE_VEC_ELT (declv
, i
);
9315 init
= TREE_VEC_ELT (initv
, i
);
9316 cond
= TREE_VEC_ELT (condv
, i
);
9317 incr
= TREE_VEC_ELT (incrv
, i
);
9319 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9322 if (init
&& EXPR_HAS_LOCATION (init
))
9323 elocus
= EXPR_LOCATION (init
);
9327 error_at (elocus
, "expected iteration declaration or initialization");
9331 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
9334 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9335 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
9336 TREE_CODE (TREE_OPERAND (incr
, 1)),
9337 TREE_OPERAND (incr
, 2),
9338 tf_warning_or_error
);
9341 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
9343 if (code
== OMP_SIMD
)
9345 error_at (elocus
, "%<#pragma omp simd%> used with class "
9346 "iteration variable %qE", decl
);
9349 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
9350 initv
, condv
, incrv
, &body
,
9357 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
9358 && !TYPE_PTR_P (TREE_TYPE (decl
)))
9360 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
9364 if (!processing_template_decl
&& TREE_CODE (init
) != TREE_VEC
)
9365 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
9366 tf_warning_or_error
);
9368 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
9369 if (decl
== error_mark_node
|| init
== error_mark_node
)
9372 TREE_VEC_ELT (declv
, i
) = decl
;
9373 TREE_VEC_ELT (initv
, i
) = init
;
9374 TREE_VEC_ELT (condv
, i
) = cond
;
9375 TREE_VEC_ELT (incrv
, i
) = incr
;
9379 if (pre_body
&& IS_EMPTY_STMT (pre_body
))
9382 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
9383 incrv
, body
, pre_body
,
9384 !processing_template_decl
);
9386 /* Check for iterators appearing in lb, b or incr expressions. */
9387 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
9388 omp_for
= NULL_TREE
;
9390 if (omp_for
== NULL
)
9395 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
9397 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
);
9398 decl
= TREE_OPERAND (init
, 0);
9399 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), i
);
9400 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
9402 if (!processing_template_decl
)
9404 if (TREE_CODE (TREE_OPERAND (init
, 1)) == TREE_VEC
)
9406 tree t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1);
9407 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1)
9408 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9409 t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2);
9410 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2)
9411 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9415 tree t
= TREE_OPERAND (init
, 1);
9416 TREE_OPERAND (init
, 1)
9417 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9419 if (TREE_CODE (TREE_OPERAND (cond
, 1)) == TREE_VEC
)
9421 tree t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1);
9422 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1)
9423 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9424 t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2);
9425 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2)
9426 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9430 tree t
= TREE_OPERAND (cond
, 1);
9431 TREE_OPERAND (cond
, 1)
9432 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9436 if (TREE_CODE (incr
) != MODIFY_EXPR
)
9439 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
9440 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
9441 && !processing_template_decl
)
9443 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
9444 if (TREE_SIDE_EFFECTS (t
)
9446 && (TREE_CODE (t
) != NOP_EXPR
9447 || TREE_OPERAND (t
, 0) != decl
))
9448 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
9449 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9451 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
9452 if (TREE_SIDE_EFFECTS (t
)
9454 && (TREE_CODE (t
) != NOP_EXPR
9455 || TREE_OPERAND (t
, 0) != decl
))
9456 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
9457 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9461 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
9463 OMP_FOR_CLAUSES (omp_for
) = clauses
;
9465 /* For simd loops with non-static data member iterators, we could have added
9466 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
9467 step at this point, fill it in. */
9468 if (code
== OMP_SIMD
&& !processing_template_decl
9469 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
9470 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
9471 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
9472 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
9474 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
9475 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
9476 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
9478 switch (TREE_CODE (incr
))
9480 case PREINCREMENT_EXPR
:
9481 case POSTINCREMENT_EXPR
:
9482 /* c_omp_for_incr_canonicalize_ptr() should have been
9483 called to massage things appropriately. */
9484 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9485 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
9487 case PREDECREMENT_EXPR
:
9488 case POSTDECREMENT_EXPR
:
9489 /* c_omp_for_incr_canonicalize_ptr() should have been
9490 called to massage things appropriately. */
9491 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9492 OMP_CLAUSE_LINEAR_STEP (c
)
9493 = build_int_cst (TREE_TYPE (decl
), -1);
9496 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9497 incr
= TREE_OPERAND (incr
, 1);
9498 switch (TREE_CODE (incr
))
9501 if (TREE_OPERAND (incr
, 1) == decl
)
9502 step
= TREE_OPERAND (incr
, 0);
9504 step
= TREE_OPERAND (incr
, 1);
9507 case POINTER_PLUS_EXPR
:
9508 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9509 step
= TREE_OPERAND (incr
, 1);
9514 stept
= TREE_TYPE (decl
);
9515 if (INDIRECT_TYPE_P (stept
))
9517 step
= fold_convert (stept
, step
);
9518 if (TREE_CODE (incr
) == MINUS_EXPR
)
9519 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
9520 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
9526 /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
9527 clauses, we need copy ctor for those rather than default ctor,
9528 plus as for other lastprivates assignment op and dtor. */
9529 if (code
== OMP_LOOP
&& !processing_template_decl
)
9530 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9531 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9532 && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
)
9533 && cxx_omp_create_clause_info (c
, TREE_TYPE (OMP_CLAUSE_DECL (c
)),
9534 false, true, true, true))
9535 CP_OMP_CLAUSE_INFO (c
) = NULL_TREE
;
9540 /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS
9541 and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */
9544 finish_omp_for_block (tree bind
, tree omp_for
)
9546 if (omp_for
== NULL_TREE
9547 || !OMP_FOR_ORIG_DECLS (omp_for
)
9548 || bind
== NULL_TREE
9549 || TREE_CODE (bind
) != BIND_EXPR
)
9552 for (int i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for
)); i
++)
9553 if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)) == TREE_LIST
9554 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)))
9556 tree v
= TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
));
9557 gcc_assert (BIND_EXPR_BLOCK (bind
)
9558 && (BIND_EXPR_VARS (bind
)
9559 == BLOCK_VARS (BIND_EXPR_BLOCK (bind
))));
9560 for (int j
= 2; j
< TREE_VEC_LENGTH (v
); j
++)
9561 for (tree
*p
= &BIND_EXPR_VARS (bind
); *p
; p
= &DECL_CHAIN (*p
))
9563 if (*p
== TREE_VEC_ELT (v
, j
))
9566 *p
= DECL_CHAIN (*p
);
9569 b
= make_node (BLOCK
);
9570 b
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
9571 OMP_FOR_BODY (omp_for
), b
);
9572 TREE_SIDE_EFFECTS (b
) = 1;
9573 OMP_FOR_BODY (omp_for
) = b
;
9575 DECL_CHAIN (var
) = BIND_EXPR_VARS (b
);
9576 BIND_EXPR_VARS (b
) = var
;
9577 BLOCK_VARS (BIND_EXPR_BLOCK (b
)) = var
;
9580 BLOCK_VARS (BIND_EXPR_BLOCK (bind
)) = BIND_EXPR_VARS (bind
);
9586 finish_omp_atomic (location_t loc
, enum tree_code code
, enum tree_code opcode
,
9587 tree lhs
, tree rhs
, tree v
, tree lhs1
, tree rhs1
,
9588 tree clauses
, enum omp_memory_order mo
)
9603 dependent_p
= false;
9606 /* Even in a template, we can detect invalid uses of the atomic
9607 pragma if neither LHS nor RHS is type-dependent. */
9608 if (processing_template_decl
)
9610 dependent_p
= (type_dependent_expression_p (lhs
)
9611 || (rhs
&& type_dependent_expression_p (rhs
))
9612 || (v
&& type_dependent_expression_p (v
))
9613 || (lhs1
&& type_dependent_expression_p (lhs1
))
9614 || (rhs1
&& type_dependent_expression_p (rhs1
)));
9617 gcc_assert (TREE_CODE (clauses
) == OMP_CLAUSE
9618 && OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_HINT
9619 && OMP_CLAUSE_CHAIN (clauses
) == NULL_TREE
);
9620 if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses
))
9621 || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses
)) != INTEGER_CST
)
9626 lhs
= build_non_dependent_expr (lhs
);
9628 rhs
= build_non_dependent_expr (rhs
);
9630 v
= build_non_dependent_expr (v
);
9632 lhs1
= build_non_dependent_expr (lhs1
);
9634 rhs1
= build_non_dependent_expr (rhs1
);
9639 bool swapped
= false;
9640 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
9642 std::swap (rhs
, rhs1
);
9643 swapped
= !commutative_tree_code (opcode
);
9645 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
9647 if (code
== OMP_ATOMIC
)
9648 error ("%<#pragma omp atomic update%> uses two different "
9649 "expressions for memory");
9651 error ("%<#pragma omp atomic capture%> uses two different "
9652 "expressions for memory");
9655 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
9657 if (code
== OMP_ATOMIC
)
9658 error ("%<#pragma omp atomic update%> uses two different "
9659 "expressions for memory");
9661 error ("%<#pragma omp atomic capture%> uses two different "
9662 "expressions for memory");
9665 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
,
9666 v
, lhs1
, rhs1
, swapped
, mo
,
9667 processing_template_decl
!= 0);
9668 if (stmt
== error_mark_node
)
9671 if (processing_template_decl
)
9673 if (code
== OMP_ATOMIC_READ
)
9675 stmt
= build_min_nt_loc (loc
, OMP_ATOMIC_READ
, orig_lhs
);
9676 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9677 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9681 if (opcode
== NOP_EXPR
)
9682 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
9684 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
9686 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
9687 COMPOUND_EXPR
, orig_rhs1
, stmt
);
9688 if (code
!= OMP_ATOMIC
)
9690 stmt
= build_min_nt_loc (loc
, code
, orig_lhs1
, stmt
);
9691 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9692 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9695 stmt
= build2 (OMP_ATOMIC
, void_type_node
,
9696 clauses
? clauses
: integer_zero_node
, stmt
);
9697 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9698 SET_EXPR_LOCATION (stmt
, loc
);
9701 /* Avoid -Wunused-value warnings here, the whole construct has side-effects
9702 and even if it might be wrapped from fold-const.c or c-omp.c wrapped
9703 in some tree that appears to be unused, the value is not unused. */
9704 warning_sentinel
w (warn_unused_value
);
9705 finish_expr_stmt (stmt
);
9709 finish_omp_barrier (void)
9711 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
9713 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9714 finish_expr_stmt (stmt
);
9718 finish_omp_depobj (location_t loc
, tree depobj
,
9719 enum omp_clause_depend_kind kind
, tree clause
)
9721 if (!error_operand_p (depobj
) && !type_dependent_expression_p (depobj
))
9723 if (!lvalue_p (depobj
))
9725 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
9726 "%<depobj%> expression is not lvalue expression");
9727 depobj
= error_mark_node
;
9731 if (processing_template_decl
)
9733 if (clause
== NULL_TREE
)
9734 clause
= build_int_cst (integer_type_node
, kind
);
9735 add_stmt (build_min_nt_loc (loc
, OMP_DEPOBJ
, depobj
, clause
));
9739 if (!error_operand_p (depobj
))
9741 tree addr
= cp_build_addr_expr (depobj
, tf_warning_or_error
);
9742 if (addr
== error_mark_node
)
9743 depobj
= error_mark_node
;
9745 depobj
= cp_build_indirect_ref (loc
, addr
, RO_UNARY_STAR
,
9746 tf_warning_or_error
);
9749 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
9753 finish_omp_flush (int mo
)
9755 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
9757 if (mo
!= MEMMODEL_LAST
)
9759 fn
= builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE
);
9760 vec
->quick_push (build_int_cst (integer_type_node
, mo
));
9762 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9763 finish_expr_stmt (stmt
);
9767 finish_omp_taskwait (void)
9769 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
9771 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9772 finish_expr_stmt (stmt
);
9776 finish_omp_taskyield (void)
9778 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
9780 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9781 finish_expr_stmt (stmt
);
9785 finish_omp_cancel (tree clauses
)
9787 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
9789 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9791 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9793 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9795 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9799 error ("%<#pragma omp cancel%> must specify one of "
9800 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9804 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
9805 if (ifc
!= NULL_TREE
)
9807 if (OMP_CLAUSE_IF_MODIFIER (ifc
) != ERROR_MARK
9808 && OMP_CLAUSE_IF_MODIFIER (ifc
) != VOID_CST
)
9809 error_at (OMP_CLAUSE_LOCATION (ifc
),
9810 "expected %<cancel%> %<if%> clause modifier");
9813 tree ifc2
= omp_find_clause (OMP_CLAUSE_CHAIN (ifc
), OMP_CLAUSE_IF
);
9814 if (ifc2
!= NULL_TREE
)
9816 gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc
) == VOID_CST
9817 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != ERROR_MARK
9818 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != VOID_CST
);
9819 error_at (OMP_CLAUSE_LOCATION (ifc2
),
9820 "expected %<cancel%> %<if%> clause modifier");
9824 if (!processing_template_decl
)
9825 ifc
= maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc
));
9827 ifc
= build_x_binary_op (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
9828 OMP_CLAUSE_IF_EXPR (ifc
), ERROR_MARK
,
9829 integer_zero_node
, ERROR_MARK
,
9830 NULL
, tf_warning_or_error
);
9833 ifc
= boolean_true_node
;
9834 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
9835 vec
->quick_push (ifc
);
9836 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9837 finish_expr_stmt (stmt
);
9841 finish_omp_cancellation_point (tree clauses
)
9843 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
9845 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9847 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9849 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9851 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9855 error ("%<#pragma omp cancellation point%> must specify one of "
9856 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9860 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
9861 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9862 finish_expr_stmt (stmt
);
9865 /* Begin a __transaction_atomic or __transaction_relaxed statement.
9866 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
9867 should create an extra compound stmt. */
9870 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
9875 *pcompound
= begin_compound_stmt (0);
9877 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
9879 /* Only add the statement to the function if support enabled. */
9883 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
9884 ? G_("%<__transaction_relaxed%> without "
9885 "transactional memory support enabled")
9886 : G_("%<__transaction_atomic%> without "
9887 "transactional memory support enabled")));
9889 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
9890 TREE_SIDE_EFFECTS (r
) = 1;
9894 /* End a __transaction_atomic or __transaction_relaxed statement.
9895 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
9896 and we should end the compound. If NOEX is non-NULL, we wrap the body in
9897 a MUST_NOT_THROW_EXPR with NOEX as condition. */
9900 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
9902 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
9903 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
9904 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
9905 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
9907 /* noexcept specifications are not allowed for function transactions. */
9908 gcc_assert (!(noex
&& compound_stmt
));
9911 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
9913 protected_set_expr_location
9914 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
9915 TREE_SIDE_EFFECTS (body
) = 1;
9916 TRANSACTION_EXPR_BODY (stmt
) = body
;
9920 finish_compound_stmt (compound_stmt
);
9923 /* Build a __transaction_atomic or __transaction_relaxed expression. If
9924 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
9928 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
9933 expr
= build_must_not_throw_expr (expr
, noex
);
9934 protected_set_expr_location (expr
, loc
);
9935 TREE_SIDE_EFFECTS (expr
) = 1;
9937 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
9938 if (flags
& TM_STMT_ATTR_RELAXED
)
9939 TRANSACTION_EXPR_RELAXED (ret
) = 1;
9940 TREE_SIDE_EFFECTS (ret
) = 1;
9941 SET_EXPR_LOCATION (ret
, loc
);
9946 init_cp_semantics (void)
9951 /* If we have a condition in conjunctive normal form (CNF), find the first
9952 failing clause. In other words, given an expression like
9954 true && true && false && true && false
9956 return the first 'false'. EXPR is the expression. */
9959 find_failing_clause_r (tree expr
)
9961 if (TREE_CODE (expr
) == TRUTH_ANDIF_EXPR
)
9963 /* First check the left side... */
9964 tree e
= find_failing_clause_r (TREE_OPERAND (expr
, 0));
9966 /* ...if we didn't find a false clause, check the right side. */
9967 e
= find_failing_clause_r (TREE_OPERAND (expr
, 1));
9970 tree e
= contextual_conv_bool (expr
, tf_none
);
9971 e
= fold_non_dependent_expr (e
, tf_none
, /*manifestly_const_eval=*/true);
9972 if (integer_zerop (e
))
9973 /* This is the failing clause. */
9978 /* Wrapper for find_failing_clause_r. */
9981 find_failing_clause (tree expr
)
9983 if (TREE_CODE (expr
) != TRUTH_ANDIF_EXPR
)
9985 return find_failing_clause_r (expr
);
9988 /* Build a STATIC_ASSERT for a static assertion with the condition
9989 CONDITION and the message text MESSAGE. LOCATION is the location
9990 of the static assertion in the source code. When MEMBER_P, this
9991 static assertion is a member of a class. If SHOW_EXPR_P is true,
9992 print the condition (because it was instantiation-dependent). */
9995 finish_static_assert (tree condition
, tree message
, location_t location
,
9996 bool member_p
, bool show_expr_p
)
9998 tsubst_flags_t complain
= tf_warning_or_error
;
10000 if (message
== NULL_TREE
10001 || message
== error_mark_node
10002 || condition
== NULL_TREE
10003 || condition
== error_mark_node
)
10006 if (check_for_bare_parameter_packs (condition
))
10007 condition
= error_mark_node
;
10009 if (instantiation_dependent_expression_p (condition
))
10011 /* We're in a template; build a STATIC_ASSERT and put it in
10012 the right place. */
10015 assertion
= make_node (STATIC_ASSERT
);
10016 STATIC_ASSERT_CONDITION (assertion
) = condition
;
10017 STATIC_ASSERT_MESSAGE (assertion
) = message
;
10018 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
10021 maybe_add_class_template_decl_list (current_class_type
,
10025 add_stmt (assertion
);
10030 /* Save the condition in case it was a concept check. */
10031 tree orig_condition
= condition
;
10033 /* Fold the expression and convert it to a boolean value. */
10034 condition
= contextual_conv_bool (condition
, complain
);
10035 condition
= fold_non_dependent_expr (condition
, complain
,
10036 /*manifestly_const_eval=*/true);
10038 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
10039 /* Do nothing; the condition is satisfied. */
10043 iloc_sentinel
ils (location
);
10045 if (integer_zerop (condition
))
10047 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
10048 (TREE_TYPE (TREE_TYPE (message
))));
10049 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
10051 /* See if we can find which clause was failing (for logical AND). */
10052 tree bad
= find_failing_clause (orig_condition
);
10053 /* If not, or its location is unusable, fall back to the previous
10055 location_t cloc
= location
;
10056 if (cp_expr_location (bad
) != UNKNOWN_LOCATION
)
10057 cloc
= cp_expr_location (bad
);
10059 /* Report the error. */
10061 error_at (cloc
, "static assertion failed");
10063 error_at (cloc
, "static assertion failed: %s",
10064 TREE_STRING_POINTER (message
));
10066 inform (cloc
, "%qE evaluates to false",
10067 /* Nobody wants to see the artificial (bool) cast. */
10068 (bad
? tree_strip_nop_conversions (bad
) : orig_condition
));
10070 /* Actually explain the failure if this is a concept check or a
10071 requires-expression. */
10072 if (concept_check_p (orig_condition
)
10073 || TREE_CODE (orig_condition
) == REQUIRES_EXPR
)
10074 diagnose_constraints (location
, orig_condition
, NULL_TREE
);
10076 else if (condition
&& condition
!= error_mark_node
)
10078 error ("non-constant condition for static assertion");
10079 if (require_rvalue_constant_expression (condition
))
10080 cxx_constant_value (condition
);
10085 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
10086 suitable for use as a type-specifier.
10088 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
10089 id-expression or a class member access, FALSE when it was parsed as
10090 a full expression. */
10093 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
10094 tsubst_flags_t complain
)
10096 tree type
= NULL_TREE
;
10098 if (!expr
|| error_operand_p (expr
))
10099 return error_mark_node
;
10102 || TREE_CODE (expr
) == TYPE_DECL
10103 || (TREE_CODE (expr
) == BIT_NOT_EXPR
10104 && TYPE_P (TREE_OPERAND (expr
, 0))))
10106 if (complain
& tf_error
)
10107 error ("argument to %<decltype%> must be an expression");
10108 return error_mark_node
;
10111 /* decltype is an unevaluated context. */
10114 /* Depending on the resolution of DR 1172, we may later need to distinguish
10115 instantiation-dependent but not type-dependent expressions so that, say,
10116 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
10117 if (instantiation_dependent_uneval_expression_p (expr
))
10119 type
= cxx_make_type (DECLTYPE_TYPE
);
10120 DECLTYPE_TYPE_EXPR (type
) = expr
;
10121 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
10122 = id_expression_or_member_access_p
;
10123 SET_TYPE_STRUCTURAL_EQUALITY (type
);
10127 else if (processing_template_decl
)
10129 expr
= instantiate_non_dependent_expr_sfinae (expr
, complain
);
10130 if (expr
== error_mark_node
)
10131 return error_mark_node
;
10134 /* The type denoted by decltype(e) is defined as follows: */
10136 expr
= resolve_nondeduced_context (expr
, complain
);
10138 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
10139 return error_mark_node
;
10141 if (type_unknown_p (expr
))
10143 if (complain
& tf_error
)
10144 error ("%<decltype%> cannot resolve address of overloaded function");
10145 return error_mark_node
;
10148 /* To get the size of a static data member declared as an array of
10149 unknown bound, we need to instantiate it. */
10151 && VAR_HAD_UNKNOWN_BOUND (expr
)
10152 && DECL_TEMPLATE_INSTANTIATION (expr
))
10153 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
10155 if (id_expression_or_member_access_p
)
10157 /* If e is an id-expression or a class member access (5.2.5
10158 [expr.ref]), decltype(e) is defined as the type of the entity
10159 named by e. If there is no such entity, or e names a set of
10160 overloaded functions, the program is ill-formed. */
10161 if (identifier_p (expr
))
10162 expr
= lookup_name (expr
);
10164 if (INDIRECT_REF_P (expr
)
10165 || TREE_CODE (expr
) == VIEW_CONVERT_EXPR
)
10166 /* This can happen when the expression is, e.g., "a.b". Just
10167 look at the underlying operand. */
10168 expr
= TREE_OPERAND (expr
, 0);
10170 if (TREE_CODE (expr
) == OFFSET_REF
10171 || TREE_CODE (expr
) == MEMBER_REF
10172 || TREE_CODE (expr
) == SCOPE_REF
)
10173 /* We're only interested in the field itself. If it is a
10174 BASELINK, we will need to see through it in the next
10176 expr
= TREE_OPERAND (expr
, 1);
10178 if (BASELINK_P (expr
))
10179 /* See through BASELINK nodes to the underlying function. */
10180 expr
= BASELINK_FUNCTIONS (expr
);
10182 /* decltype of a decomposition name drops references in the tuple case
10183 (unlike decltype of a normal variable) and keeps cv-qualifiers from
10184 the containing object in the other cases (unlike decltype of a member
10185 access expression). */
10186 if (DECL_DECOMPOSITION_P (expr
))
10188 if (DECL_HAS_VALUE_EXPR_P (expr
))
10189 /* Expr is an array or struct subobject proxy, handle
10190 bit-fields properly. */
10191 return unlowered_expr_type (expr
);
10193 /* Expr is a reference variable for the tuple case. */
10194 return lookup_decomp_type (expr
);
10197 switch (TREE_CODE (expr
))
10200 if (DECL_BIT_FIELD_TYPE (expr
))
10202 type
= DECL_BIT_FIELD_TYPE (expr
);
10205 /* Fall through for fields that aren't bitfields. */
10206 gcc_fallthrough ();
10208 case FUNCTION_DECL
:
10213 case TEMPLATE_PARM_INDEX
:
10214 expr
= mark_type_use (expr
);
10215 type
= TREE_TYPE (expr
);
10219 type
= error_mark_node
;
10222 case COMPONENT_REF
:
10223 case COMPOUND_EXPR
:
10224 mark_type_use (expr
);
10225 type
= is_bitfield_expr_with_lowered_type (expr
);
10227 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
10230 case BIT_FIELD_REF
:
10231 gcc_unreachable ();
10235 /* We can get here when the id-expression refers to an
10236 enumerator or non-type template parameter. */
10237 type
= TREE_TYPE (expr
);
10241 /* Handle instantiated template non-type arguments. */
10242 type
= TREE_TYPE (expr
);
10248 /* Within a lambda-expression:
10250 Every occurrence of decltype((x)) where x is a possibly
10251 parenthesized id-expression that names an entity of
10252 automatic storage duration is treated as if x were
10253 transformed into an access to a corresponding data member
10254 of the closure type that would have been declared if x
10255 were a use of the denoted entity. */
10256 if (outer_automatic_var_p (expr
)
10257 && current_function_decl
10258 && LAMBDA_FUNCTION_P (current_function_decl
))
10259 type
= capture_decltype (expr
);
10260 else if (error_operand_p (expr
))
10261 type
= error_mark_node
;
10262 else if (expr
== current_class_ptr
)
10263 /* If the expression is just "this", we want the
10264 cv-unqualified pointer for the "this" type. */
10265 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
10268 /* Otherwise, where T is the type of e, if e is an lvalue,
10269 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
10270 cp_lvalue_kind clk
= lvalue_kind (expr
);
10271 type
= unlowered_expr_type (expr
);
10272 gcc_assert (!TYPE_REF_P (type
));
10274 /* For vector types, pick a non-opaque variant. */
10275 if (VECTOR_TYPE_P (type
))
10276 type
= strip_typedefs (type
);
10278 if (clk
!= clk_none
&& !(clk
& clk_class
))
10279 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
10286 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
10287 __has_nothrow_copy, depending on assign_p. Returns true iff all
10288 the copy {ctor,assign} fns are nothrow. */
10291 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
10293 tree fns
= NULL_TREE
;
10295 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
10296 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
10297 : ctor_identifier
);
10299 bool saw_copy
= false;
10300 for (ovl_iterator
iter (fns
); iter
; ++iter
)
10304 if (copy_fn_p (fn
) > 0)
10307 if (!maybe_instantiate_noexcept (fn
)
10308 || !TYPE_NOTHROW_P (TREE_TYPE (fn
)))
10316 /* Actually evaluates the trait. */
10319 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
10321 enum tree_code type_code1
;
10324 type_code1
= TREE_CODE (type1
);
10328 case CPTK_HAS_NOTHROW_ASSIGN
:
10329 type1
= strip_array_types (type1
);
10330 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
10331 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
10332 || (CLASS_TYPE_P (type1
)
10333 && classtype_has_nothrow_assign_or_copy_p (type1
,
10336 case CPTK_HAS_TRIVIAL_ASSIGN
:
10337 /* ??? The standard seems to be missing the "or array of such a class
10338 type" wording for this trait. */
10339 type1
= strip_array_types (type1
);
10340 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
10341 && (trivial_type_p (type1
)
10342 || (CLASS_TYPE_P (type1
)
10343 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
10345 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
10346 type1
= strip_array_types (type1
);
10347 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
10348 || (CLASS_TYPE_P (type1
)
10349 && (t
= locate_ctor (type1
))
10350 && maybe_instantiate_noexcept (t
)
10351 && TYPE_NOTHROW_P (TREE_TYPE (t
))));
10353 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
10354 type1
= strip_array_types (type1
);
10355 return (trivial_type_p (type1
)
10356 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
10358 case CPTK_HAS_NOTHROW_COPY
:
10359 type1
= strip_array_types (type1
);
10360 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
10361 || (CLASS_TYPE_P (type1
)
10362 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
10364 case CPTK_HAS_TRIVIAL_COPY
:
10365 /* ??? The standard seems to be missing the "or array of such a class
10366 type" wording for this trait. */
10367 type1
= strip_array_types (type1
);
10368 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
10369 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
10371 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
10372 type1
= strip_array_types (type1
);
10373 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
10374 || (CLASS_TYPE_P (type1
)
10375 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
10377 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
10378 return type_has_virtual_destructor (type1
);
10380 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
10381 return type_has_unique_obj_representations (type1
);
10383 case CPTK_IS_ABSTRACT
:
10384 return ABSTRACT_CLASS_TYPE_P (type1
);
10386 case CPTK_IS_AGGREGATE
:
10387 return CP_AGGREGATE_TYPE_P (type1
);
10389 case CPTK_IS_BASE_OF
:
10390 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
10391 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
10392 || DERIVED_FROM_P (type1
, type2
)));
10394 case CPTK_IS_CLASS
:
10395 return NON_UNION_CLASS_TYPE_P (type1
);
10397 case CPTK_IS_EMPTY
:
10398 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
10401 return type_code1
== ENUMERAL_TYPE
;
10403 case CPTK_IS_FINAL
:
10404 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
10406 case CPTK_IS_LITERAL_TYPE
:
10407 return literal_type_p (type1
);
10410 return pod_type_p (type1
);
10412 case CPTK_IS_POLYMORPHIC
:
10413 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
10415 case CPTK_IS_SAME_AS
:
10416 return same_type_p (type1
, type2
);
10418 case CPTK_IS_STD_LAYOUT
:
10419 return std_layout_type_p (type1
);
10421 case CPTK_IS_TRIVIAL
:
10422 return trivial_type_p (type1
);
10424 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
10425 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
10427 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
10428 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
10430 case CPTK_IS_TRIVIALLY_COPYABLE
:
10431 return trivially_copyable_p (type1
);
10433 case CPTK_IS_UNION
:
10434 return type_code1
== UNION_TYPE
;
10436 case CPTK_IS_ASSIGNABLE
:
10437 return is_xible (MODIFY_EXPR
, type1
, type2
);
10439 case CPTK_IS_CONSTRUCTIBLE
:
10440 return is_xible (INIT_EXPR
, type1
, type2
);
10442 case CPTK_IS_NOTHROW_ASSIGNABLE
:
10443 return is_nothrow_xible (MODIFY_EXPR
, type1
, type2
);
10445 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
10446 return is_nothrow_xible (INIT_EXPR
, type1
, type2
);
10449 gcc_unreachable ();
10454 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
10455 void, or a complete type, returns true, otherwise false. */
10458 check_trait_type (tree type
)
10460 if (type
== NULL_TREE
)
10463 if (TREE_CODE (type
) == TREE_LIST
)
10464 return (check_trait_type (TREE_VALUE (type
))
10465 && check_trait_type (TREE_CHAIN (type
)));
10467 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
10468 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
10471 if (VOID_TYPE_P (type
))
10474 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
10477 /* Process a trait expression. */
10480 finish_trait_expr (location_t loc
, cp_trait_kind kind
, tree type1
, tree type2
)
10482 if (type1
== error_mark_node
10483 || type2
== error_mark_node
)
10484 return error_mark_node
;
10486 if (processing_template_decl
)
10488 tree trait_expr
= make_node (TRAIT_EXPR
);
10489 TREE_TYPE (trait_expr
) = boolean_type_node
;
10490 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
10491 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
10492 TRAIT_EXPR_KIND (trait_expr
) = kind
;
10493 TRAIT_EXPR_LOCATION (trait_expr
) = loc
;
10499 case CPTK_HAS_NOTHROW_ASSIGN
:
10500 case CPTK_HAS_TRIVIAL_ASSIGN
:
10501 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
10502 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
10503 case CPTK_HAS_NOTHROW_COPY
:
10504 case CPTK_HAS_TRIVIAL_COPY
:
10505 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
10506 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
10507 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
10508 case CPTK_IS_ABSTRACT
:
10509 case CPTK_IS_AGGREGATE
:
10510 case CPTK_IS_EMPTY
:
10511 case CPTK_IS_FINAL
:
10512 case CPTK_IS_LITERAL_TYPE
:
10514 case CPTK_IS_POLYMORPHIC
:
10515 case CPTK_IS_STD_LAYOUT
:
10516 case CPTK_IS_TRIVIAL
:
10517 case CPTK_IS_TRIVIALLY_COPYABLE
:
10518 if (!check_trait_type (type1
))
10519 return error_mark_node
;
10522 case CPTK_IS_ASSIGNABLE
:
10523 case CPTK_IS_CONSTRUCTIBLE
:
10526 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
10527 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
10528 case CPTK_IS_NOTHROW_ASSIGNABLE
:
10529 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
10530 if (!check_trait_type (type1
)
10531 || !check_trait_type (type2
))
10532 return error_mark_node
;
10535 case CPTK_IS_BASE_OF
:
10536 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
10537 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
10538 && !complete_type_or_else (type2
, NULL_TREE
))
10539 /* We already issued an error. */
10540 return error_mark_node
;
10543 case CPTK_IS_CLASS
:
10545 case CPTK_IS_UNION
:
10546 case CPTK_IS_SAME_AS
:
10550 gcc_unreachable ();
10553 tree val
= (trait_expr_value (kind
, type1
, type2
)
10554 ? boolean_true_node
: boolean_false_node
);
10555 return maybe_wrap_with_location (val
, loc
);
10558 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
10559 which is ignored for C++. */
10562 set_float_const_decimal64 (void)
10567 clear_float_const_decimal64 (void)
10572 float_const_decimal64_p (void)
10578 /* Return true if T designates the implied `this' parameter. */
10581 is_this_parameter (tree t
)
10583 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
10585 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
)
10586 || (cp_binding_oracle
&& TREE_CODE (t
) == VAR_DECL
));
10590 /* Insert the deduced return type for an auto function. */
10593 apply_deduced_return_type (tree fco
, tree return_type
)
10597 if (return_type
== error_mark_node
)
10600 if (DECL_CONV_FN_P (fco
))
10601 DECL_NAME (fco
) = make_conv_op_name (return_type
);
10603 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
10605 result
= DECL_RESULT (fco
);
10606 if (result
== NULL_TREE
)
10608 if (TREE_TYPE (result
) == return_type
)
10611 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
10612 && !complete_type_or_else (return_type
, NULL_TREE
))
10615 /* We already have a DECL_RESULT from start_preparsed_function.
10616 Now we need to redo the work it and allocate_struct_function
10617 did to reflect the new type. */
10618 gcc_assert (current_function_decl
== fco
);
10619 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
10620 TYPE_MAIN_VARIANT (return_type
));
10621 DECL_ARTIFICIAL (result
) = 1;
10622 DECL_IGNORED_P (result
) = 1;
10623 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
10626 DECL_RESULT (fco
) = result
;
10628 if (!processing_template_decl
)
10630 bool aggr
= aggregate_value_p (result
, fco
);
10631 #ifdef PCC_STATIC_STRUCT_RETURN
10632 cfun
->returns_pcc_struct
= aggr
;
10634 cfun
->returns_struct
= aggr
;
10638 /* DECL is a local variable or parameter from the surrounding scope of a
10639 lambda-expression. Returns the decltype for a use of the capture field
10640 for DECL even if it hasn't been captured yet. */
10643 capture_decltype (tree decl
)
10645 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
10646 tree cap
= lookup_name (DECL_NAME (decl
), LOOK_where::BLOCK
,
10647 LOOK_want::HIDDEN_LAMBDA
);
10650 if (cap
&& is_capture_proxy (cap
))
10651 type
= TREE_TYPE (cap
);
10653 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
10656 error ("%qD is not captured", decl
);
10657 return error_mark_node
;
10660 type
= TREE_TYPE (decl
);
10661 if (TYPE_REF_P (type
)
10662 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
10663 type
= TREE_TYPE (type
);
10666 case CPLD_REFERENCE
:
10667 type
= TREE_TYPE (decl
);
10668 if (!TYPE_REF_P (type
))
10669 type
= build_reference_type (TREE_TYPE (decl
));
10673 gcc_unreachable ();
10676 if (!TYPE_REF_P (type
))
10678 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
10679 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
10680 |TYPE_QUAL_CONST
));
10681 type
= build_reference_type (type
);
10686 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
10687 this is a right unary fold. Otherwise it is a left unary fold. */
10690 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
10692 /* Build a pack expansion (assuming expr has pack type). */
10693 if (!uses_parameter_packs (expr
))
10695 error_at (location_of (expr
), "operand of fold expression has no "
10696 "unexpanded parameter packs");
10697 return error_mark_node
;
10699 tree pack
= make_pack_expansion (expr
);
10701 /* Build the fold expression. */
10702 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10703 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
);
10704 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10709 finish_left_unary_fold_expr (tree expr
, int op
)
10711 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
10715 finish_right_unary_fold_expr (tree expr
, int op
)
10717 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
10720 /* Build a binary fold expression over EXPR1 and EXPR2. The
10721 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
10722 has an unexpanded parameter pack). */
10725 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
10727 pack
= make_pack_expansion (pack
);
10728 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10729 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
, init
);
10730 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10735 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
10737 // Determine which expr has an unexpanded parameter pack and
10738 // set the pack and initial term.
10739 bool pack1
= uses_parameter_packs (expr1
);
10740 bool pack2
= uses_parameter_packs (expr2
);
10741 if (pack1
&& !pack2
)
10742 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
10743 else if (pack2
&& !pack1
)
10744 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
10748 error ("both arguments in binary fold have unexpanded parameter packs");
10750 error ("no unexpanded parameter packs in binary fold");
10752 return error_mark_node
;
10755 /* Finish __builtin_launder (arg). */
10758 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
10760 tree orig_arg
= arg
;
10761 if (!type_dependent_expression_p (arg
))
10762 arg
= decay_conversion (arg
, complain
);
10763 if (error_operand_p (arg
))
10764 return error_mark_node
;
10765 if (!type_dependent_expression_p (arg
)
10766 && !TYPE_PTR_P (TREE_TYPE (arg
)))
10768 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
10769 return error_mark_node
;
10771 if (processing_template_decl
)
10773 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
10774 TREE_TYPE (arg
), 1, arg
);
10777 /* Finish __builtin_convertvector (arg, type). */
10780 cp_build_vec_convert (tree arg
, location_t loc
, tree type
,
10781 tsubst_flags_t complain
)
10783 if (error_operand_p (type
))
10784 return error_mark_node
;
10785 if (error_operand_p (arg
))
10786 return error_mark_node
;
10788 tree ret
= NULL_TREE
;
10789 if (!type_dependent_expression_p (arg
) && !dependent_type_p (type
))
10790 ret
= c_build_vec_convert (cp_expr_loc_or_input_loc (arg
),
10791 decay_conversion (arg
, complain
),
10792 loc
, type
, (complain
& tf_error
) != 0);
10794 if (!processing_template_decl
)
10797 return build_call_expr_internal_loc (loc
, IFN_VEC_CONVERT
, type
, 1, arg
);
10800 /* Finish __builtin_bit_cast (type, arg). */
10803 cp_build_bit_cast (location_t loc
, tree type
, tree arg
,
10804 tsubst_flags_t complain
)
10806 if (error_operand_p (type
))
10807 return error_mark_node
;
10808 if (!dependent_type_p (type
))
10810 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
))
10811 return error_mark_node
;
10812 if (TREE_CODE (type
) == ARRAY_TYPE
)
10814 /* std::bit_cast for destination ARRAY_TYPE is not possible,
10815 as functions may not return an array, so don't bother trying
10816 to support this (and then deal with VLAs etc.). */
10817 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
10818 "is an array type", type
);
10819 return error_mark_node
;
10821 if (!trivially_copyable_p (type
))
10823 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
10824 "is not trivially copyable", type
);
10825 return error_mark_node
;
10829 if (error_operand_p (arg
))
10830 return error_mark_node
;
10832 if (!type_dependent_expression_p (arg
))
10834 if (TREE_CODE (TREE_TYPE (arg
)) == ARRAY_TYPE
)
10836 /* Don't perform array-to-pointer conversion. */
10837 arg
= mark_rvalue_use (arg
, loc
, true);
10838 if (!complete_type_or_maybe_complain (TREE_TYPE (arg
), arg
, complain
))
10839 return error_mark_node
;
10842 arg
= decay_conversion (arg
, complain
);
10844 if (error_operand_p (arg
))
10845 return error_mark_node
;
10847 if (!trivially_copyable_p (TREE_TYPE (arg
)))
10849 error_at (cp_expr_loc_or_loc (arg
, loc
),
10850 "%<__builtin_bit_cast%> source type %qT "
10851 "is not trivially copyable", TREE_TYPE (arg
));
10852 return error_mark_node
;
10854 if (!dependent_type_p (type
)
10855 && !cp_tree_equal (TYPE_SIZE_UNIT (type
),
10856 TYPE_SIZE_UNIT (TREE_TYPE (arg
))))
10858 error_at (loc
, "%<__builtin_bit_cast%> source size %qE "
10859 "not equal to destination type size %qE",
10860 TYPE_SIZE_UNIT (TREE_TYPE (arg
)),
10861 TYPE_SIZE_UNIT (type
));
10862 return error_mark_node
;
10866 tree ret
= build_min (BIT_CAST_EXPR
, type
, arg
);
10867 SET_EXPR_LOCATION (ret
, loc
);
10869 if (!processing_template_decl
&& CLASS_TYPE_P (type
))
10870 ret
= get_target_expr_sfinae (ret
, complain
);
10875 #include "gt-cp-semantics.h"