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-2019 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
> * GTY(()) deferred_access_checks
;
132 /* The current mode of access checks. */
133 enum deferring_kind deferring_access_checks_kind
;
137 /* Data for deferred access checking. */
138 static GTY(()) vec
<deferred_access
, va_gc
> *deferred_access_stack
;
139 static GTY(()) unsigned deferred_access_no_check
;
141 /* Save the current deferred access states and start deferred
142 access checking iff DEFER_P is true. */
145 push_deferring_access_checks (deferring_kind deferring
)
147 /* For context like template instantiation, access checking
148 disabling applies to all nested context. */
149 if (deferred_access_no_check
|| deferring
== dk_no_check
)
150 deferred_access_no_check
++;
153 deferred_access e
= {NULL
, deferring
};
154 vec_safe_push (deferred_access_stack
, e
);
158 /* Save the current deferred access states and start deferred access
159 checking, continuing the set of deferred checks in CHECKS. */
162 reopen_deferring_access_checks (vec
<deferred_access_check
, va_gc
> * checks
)
164 push_deferring_access_checks (dk_deferred
);
165 if (!deferred_access_no_check
)
166 deferred_access_stack
->last().deferred_access_checks
= checks
;
169 /* Resume deferring access checks again after we stopped doing
173 resume_deferring_access_checks (void)
175 if (!deferred_access_no_check
)
176 deferred_access_stack
->last().deferring_access_checks_kind
= dk_deferred
;
179 /* Stop deferring access checks. */
182 stop_deferring_access_checks (void)
184 if (!deferred_access_no_check
)
185 deferred_access_stack
->last().deferring_access_checks_kind
= dk_no_deferred
;
188 /* Discard the current deferred access checks and restore the
192 pop_deferring_access_checks (void)
194 if (deferred_access_no_check
)
195 deferred_access_no_check
--;
197 deferred_access_stack
->pop ();
200 /* Returns a TREE_LIST representing the deferred checks.
201 The TREE_PURPOSE of each node is the type through which the
202 access occurred; the TREE_VALUE is the declaration named.
205 vec
<deferred_access_check
, va_gc
> *
206 get_deferred_access_checks (void)
208 if (deferred_access_no_check
)
211 return (deferred_access_stack
->last().deferred_access_checks
);
214 /* Take current deferred checks and combine with the
215 previous states if we also defer checks previously.
216 Otherwise perform checks now. */
219 pop_to_parent_deferring_access_checks (void)
221 if (deferred_access_no_check
)
222 deferred_access_no_check
--;
225 vec
<deferred_access_check
, va_gc
> *checks
;
226 deferred_access
*ptr
;
228 checks
= (deferred_access_stack
->last ().deferred_access_checks
);
230 deferred_access_stack
->pop ();
231 ptr
= &deferred_access_stack
->last ();
232 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
235 perform_access_checks (checks
, tf_warning_or_error
);
239 /* Merge with parent. */
241 deferred_access_check
*chk
, *probe
;
243 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
245 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, j
, probe
)
247 if (probe
->binfo
== chk
->binfo
&&
248 probe
->decl
== chk
->decl
&&
249 probe
->diag_decl
== chk
->diag_decl
)
252 /* Insert into parent's checks. */
253 vec_safe_push (ptr
->deferred_access_checks
, *chk
);
260 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
261 is the BINFO indicating the qualifying scope used to access the
262 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
263 or we aren't in SFINAE context or all the checks succeed return TRUE,
267 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
268 tsubst_flags_t complain
)
271 deferred_access_check
*chk
;
272 location_t loc
= input_location
;
278 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
280 input_location
= chk
->loc
;
281 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
284 input_location
= loc
;
285 return (complain
& tf_error
) ? true : ok
;
288 /* Perform the deferred access checks.
290 After performing the checks, we still have to keep the list
291 `deferred_access_stack->deferred_access_checks' since we may want
292 to check access for them again later in a different context.
299 A::X A::a, x; // No error for `A::a', error for `x'
301 We have to perform deferred access of `A::X', first with `A::a',
302 next with `x'. Return value like perform_access_checks above. */
305 perform_deferred_access_checks (tsubst_flags_t complain
)
307 return perform_access_checks (get_deferred_access_checks (), complain
);
310 /* Defer checking the accessibility of DECL, when looked up in
311 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
312 Return value like perform_access_checks above.
313 If non-NULL, report failures to AFI. */
316 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
317 tsubst_flags_t complain
,
318 access_failure_info
*afi
)
321 deferred_access
*ptr
;
322 deferred_access_check
*chk
;
325 /* Exit if we are in a context that no access checking is performed.
327 if (deferred_access_no_check
)
330 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
332 ptr
= &deferred_access_stack
->last ();
334 /* If we are not supposed to defer access checks, just check now. */
335 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
337 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
, afi
);
338 return (complain
& tf_error
) ? true : ok
;
341 /* See if we are already going to perform this check. */
342 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
344 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
345 chk
->diag_decl
== diag_decl
)
350 /* If not, record the check. */
351 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
352 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
357 /* Returns nonzero if the current statement is a full expression,
358 i.e. temporaries created during that statement should be destroyed
359 at the end of the statement. */
362 stmts_are_full_exprs_p (void)
364 return current_stmt_tree ()->stmts_are_full_exprs_p
;
367 /* T is a statement. Add it to the statement-tree. This is the C++
368 version. The C/ObjC frontends have a slightly different version of
374 enum tree_code code
= TREE_CODE (t
);
376 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
378 if (!EXPR_HAS_LOCATION (t
))
379 SET_EXPR_LOCATION (t
, input_location
);
381 /* When we expand a statement-tree, we must know whether or not the
382 statements are full-expressions. We record that fact here. */
383 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
386 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
387 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
389 /* Add T to the statement-tree. Non-side-effect statements need to be
390 recorded during statement expressions. */
391 gcc_checking_assert (!stmt_list_stack
->is_empty ());
392 append_to_statement_list_force (t
, &cur_stmt_list
);
397 /* Returns the stmt_tree to which statements are currently being added. */
400 current_stmt_tree (void)
403 ? &cfun
->language
->base
.x_stmt_tree
404 : &scope_chain
->x_stmt_tree
);
407 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
410 maybe_cleanup_point_expr (tree expr
)
412 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
413 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
417 /* Like maybe_cleanup_point_expr except have the type of the new expression be
418 void so we don't need to create a temporary variable to hold the inner
419 expression. The reason why we do this is because the original type might be
420 an aggregate and we cannot create a temporary variable for that type. */
423 maybe_cleanup_point_expr_void (tree expr
)
425 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
426 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
432 /* Create a declaration statement for the declaration given by the DECL. */
435 add_decl_expr (tree decl
)
437 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
438 if (DECL_INITIAL (decl
)
439 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
440 r
= maybe_cleanup_point_expr_void (r
);
444 /* Finish a scope. */
447 do_poplevel (tree stmt_list
)
451 if (stmts_are_full_exprs_p ())
452 block
= poplevel (kept_level_p (), 1, 0);
454 stmt_list
= pop_stmt_list (stmt_list
);
456 if (!processing_template_decl
)
458 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
459 /* ??? See c_end_compound_stmt re statement expressions. */
465 /* Begin a new scope. */
468 do_pushlevel (scope_kind sk
)
470 tree ret
= push_stmt_list ();
471 if (stmts_are_full_exprs_p ())
472 begin_scope (sk
, NULL
);
476 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
477 when the current scope is exited. EH_ONLY is true when this is not
478 meant to apply to normal control flow transfer. */
481 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
483 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
484 CLEANUP_EH_ONLY (stmt
) = eh_only
;
486 CLEANUP_BODY (stmt
) = push_stmt_list ();
489 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
490 the current loops, represented by 'NULL_TREE' if we've seen a possible
491 exit, and 'error_mark_node' if not. This is currently used only to
492 suppress the warning about a function with no return statements, and
493 therefore we don't bother noting returns as possible exits. We also
494 don't bother with gotos. */
497 begin_maybe_infinite_loop (tree cond
)
499 /* Only track this while parsing a function, not during instantiation. */
500 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
501 && !processing_template_decl
))
503 bool maybe_infinite
= true;
506 cond
= fold_non_dependent_expr (cond
);
507 maybe_infinite
= integer_nonzerop (cond
);
509 vec_safe_push (cp_function_chain
->infinite_loops
,
510 maybe_infinite
? error_mark_node
: NULL_TREE
);
514 /* A break is a possible exit for the current loop. */
517 break_maybe_infinite_loop (void)
521 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
524 /* If we reach the end of the loop without seeing a possible exit, we have
528 end_maybe_infinite_loop (tree cond
)
530 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
531 && !processing_template_decl
))
533 tree current
= cp_function_chain
->infinite_loops
->pop();
534 if (current
!= NULL_TREE
)
536 cond
= fold_non_dependent_expr (cond
);
537 if (integer_nonzerop (cond
))
538 current_function_infinite_loop
= 1;
543 /* Begin a conditional that might contain a declaration. When generating
544 normal code, we want the declaration to appear before the statement
545 containing the conditional. When generating template code, we want the
546 conditional to be rendered as the raw DECL_EXPR. */
549 begin_cond (tree
*cond_p
)
551 if (processing_template_decl
)
552 *cond_p
= push_stmt_list ();
555 /* Finish such a conditional. */
558 finish_cond (tree
*cond_p
, tree expr
)
560 if (processing_template_decl
)
562 tree cond
= pop_stmt_list (*cond_p
);
564 if (expr
== NULL_TREE
)
565 /* Empty condition in 'for'. */
566 gcc_assert (empty_expr_stmt_p (cond
));
567 else if (check_for_bare_parameter_packs (expr
))
568 expr
= error_mark_node
;
569 else if (!empty_expr_stmt_p (cond
))
570 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
575 /* If *COND_P specifies a conditional with a declaration, transform the
578 for (; A x = 42;) { }
580 while (true) { A x = 42; if (!x) break; }
581 for (;;) { A x = 42; if (!x) break; }
582 The statement list for BODY will be empty if the conditional did
583 not declare anything. */
586 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
590 if (!TREE_SIDE_EFFECTS (body
))
594 *cond_p
= boolean_true_node
;
596 if_stmt
= begin_if_stmt ();
597 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, false, tf_warning_or_error
);
598 finish_if_stmt_cond (cond
, if_stmt
);
599 finish_break_stmt ();
600 finish_then_clause (if_stmt
);
601 finish_if_stmt (if_stmt
);
604 /* Finish a goto-statement. */
607 finish_goto_stmt (tree destination
)
609 if (identifier_p (destination
))
610 destination
= lookup_label (destination
);
612 /* We warn about unused labels with -Wunused. That means we have to
613 mark the used labels as used. */
614 if (TREE_CODE (destination
) == LABEL_DECL
)
615 TREE_USED (destination
) = 1;
618 destination
= mark_rvalue_use (destination
);
619 if (!processing_template_decl
)
621 destination
= cp_convert (ptr_type_node
, destination
,
622 tf_warning_or_error
);
623 if (error_operand_p (destination
))
626 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
631 check_goto (destination
);
633 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
634 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
637 /* COND is the condition-expression for an if, while, etc.,
638 statement. Convert it to a boolean value, if appropriate.
639 In addition, verify sequence points if -Wsequence-point is enabled. */
642 maybe_convert_cond (tree cond
)
644 /* Empty conditions remain empty. */
648 /* Wait until we instantiate templates before doing conversion. */
649 if (type_dependent_expression_p (cond
))
652 if (warn_sequence_point
&& !processing_template_decl
)
653 verify_sequence_points (cond
);
655 /* Do the conversion. */
656 cond
= convert_from_reference (cond
);
658 if (TREE_CODE (cond
) == MODIFY_EXPR
659 && !TREE_NO_WARNING (cond
)
661 && warning_at (cp_expr_loc_or_input_loc (cond
),
662 OPT_Wparentheses
, "suggest parentheses around "
663 "assignment used as truth value"))
664 TREE_NO_WARNING (cond
) = 1;
666 return condition_conversion (cond
);
669 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
672 finish_expr_stmt (tree expr
)
675 location_t loc
= EXPR_LOCATION (expr
);
677 if (expr
!= NULL_TREE
)
679 /* If we ran into a problem, make sure we complained. */
680 gcc_assert (expr
!= error_mark_node
|| seen_error ());
682 if (!processing_template_decl
)
684 if (warn_sequence_point
)
685 verify_sequence_points (expr
);
686 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
688 else if (!type_dependent_expression_p (expr
))
689 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
690 tf_warning_or_error
);
692 if (check_for_bare_parameter_packs (expr
))
693 expr
= error_mark_node
;
695 /* Simplification of inner statement expressions, compound exprs,
696 etc can result in us already having an EXPR_STMT. */
697 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
699 if (TREE_CODE (expr
) != EXPR_STMT
)
700 expr
= build_stmt (loc
, EXPR_STMT
, expr
);
701 expr
= maybe_cleanup_point_expr_void (expr
);
711 /* Begin an if-statement. Returns a newly created IF_STMT if
718 scope
= do_pushlevel (sk_cond
);
719 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
720 NULL_TREE
, NULL_TREE
, scope
);
721 current_binding_level
->this_entity
= r
;
722 begin_cond (&IF_COND (r
));
726 /* Returns true if FN, a CALL_EXPR, is a call to
727 std::is_constant_evaluated or __builtin_is_constant_evaluated. */
730 is_std_constant_evaluated_p (tree fn
)
732 /* std::is_constant_evaluated takes no arguments. */
733 if (call_expr_nargs (fn
) != 0)
736 tree fndecl
= cp_get_callee_fndecl_nofold (fn
);
737 if (fndecl_built_in_p (fndecl
, CP_BUILT_IN_IS_CONSTANT_EVALUATED
,
741 if (!decl_in_std_namespace_p (fndecl
))
744 tree name
= DECL_NAME (fndecl
);
745 return name
&& id_equal (name
, "is_constant_evaluated");
748 /* Process the COND of an if-statement, which may be given by
752 finish_if_stmt_cond (tree cond
, tree if_stmt
)
754 cond
= maybe_convert_cond (cond
);
755 if (IF_STMT_CONSTEXPR_P (if_stmt
)
756 && !type_dependent_expression_p (cond
)
757 && require_constant_expression (cond
)
758 && !instantiation_dependent_expression_p (cond
)
759 /* Wait until instantiation time, since only then COND has been
760 converted to bool. */
761 && TYPE_MAIN_VARIANT (TREE_TYPE (cond
)) == boolean_type_node
)
763 /* if constexpr (std::is_constant_evaluated()) is always true,
764 so give the user a clue. */
765 if (warn_tautological_compare
)
768 if (TREE_CODE (t
) == CLEANUP_POINT_EXPR
)
769 t
= TREE_OPERAND (t
, 0);
770 if (TREE_CODE (t
) == CALL_EXPR
771 && is_std_constant_evaluated_p (t
))
772 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
773 "%qs always evaluates to true in %<if constexpr%>",
774 "std::is_constant_evaluated");
777 cond
= instantiate_non_dependent_expr (cond
);
778 cond
= cxx_constant_value (cond
, NULL_TREE
);
780 finish_cond (&IF_COND (if_stmt
), cond
);
782 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
786 /* Finish the then-clause of an if-statement, which may be given by
790 finish_then_clause (tree if_stmt
)
792 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
796 /* Begin the else-clause of an if-statement. */
799 begin_else_clause (tree if_stmt
)
801 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
804 /* Finish the else-clause of an if-statement, which may be given by
808 finish_else_clause (tree if_stmt
)
810 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
813 /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
817 maybe_mark_exp_read_r (tree
*tp
, int *, void *)
820 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
825 /* Finish an if-statement. */
828 finish_if_stmt (tree if_stmt
)
830 tree scope
= IF_SCOPE (if_stmt
);
831 IF_SCOPE (if_stmt
) = NULL
;
832 if (IF_STMT_CONSTEXPR_P (if_stmt
))
834 /* Prevent various -Wunused warnings. We might not instantiate
835 either of these branches, so we would not mark the variables
836 used in that branch as read. */
837 cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt
),
838 maybe_mark_exp_read_r
, NULL
);
839 cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt
),
840 maybe_mark_exp_read_r
, NULL
);
842 add_stmt (do_poplevel (scope
));
845 /* Begin a while-statement. Returns a newly created WHILE_STMT if
849 begin_while_stmt (void)
852 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
854 WHILE_BODY (r
) = do_pushlevel (sk_block
);
855 begin_cond (&WHILE_COND (r
));
859 /* Process the COND of a while-statement, which may be given by
863 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
,
864 unsigned short unroll
)
866 cond
= maybe_convert_cond (cond
);
867 finish_cond (&WHILE_COND (while_stmt
), cond
);
868 begin_maybe_infinite_loop (cond
);
869 if (ivdep
&& cond
!= error_mark_node
)
870 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
871 TREE_TYPE (WHILE_COND (while_stmt
)),
872 WHILE_COND (while_stmt
),
873 build_int_cst (integer_type_node
,
874 annot_expr_ivdep_kind
),
876 if (unroll
&& cond
!= error_mark_node
)
877 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
878 TREE_TYPE (WHILE_COND (while_stmt
)),
879 WHILE_COND (while_stmt
),
880 build_int_cst (integer_type_node
,
881 annot_expr_unroll_kind
),
882 build_int_cst (integer_type_node
,
884 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
887 /* Finish a while-statement, which may be given by WHILE_STMT. */
890 finish_while_stmt (tree while_stmt
)
892 end_maybe_infinite_loop (boolean_true_node
);
893 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
896 /* Begin a do-statement. Returns a newly created DO_STMT if
902 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
903 begin_maybe_infinite_loop (boolean_true_node
);
905 DO_BODY (r
) = push_stmt_list ();
909 /* Finish the body of a do-statement, which may be given by DO_STMT. */
912 finish_do_body (tree do_stmt
)
914 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
916 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
917 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
919 if (IS_EMPTY_STMT (body
))
920 warning (OPT_Wempty_body
,
921 "suggest explicit braces around empty body in %<do%> statement");
924 /* Finish a do-statement, which may be given by DO_STMT, and whose
925 COND is as indicated. */
928 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
, unsigned short unroll
)
930 cond
= maybe_convert_cond (cond
);
931 end_maybe_infinite_loop (cond
);
932 if (ivdep
&& cond
!= error_mark_node
)
933 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
934 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
),
936 if (unroll
&& cond
!= error_mark_node
)
937 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
938 build_int_cst (integer_type_node
, annot_expr_unroll_kind
),
939 build_int_cst (integer_type_node
, unroll
));
940 DO_COND (do_stmt
) = cond
;
943 /* Finish a return-statement. The EXPRESSION returned, if any, is as
947 finish_return_stmt (tree expr
)
952 expr
= check_return_expr (expr
, &no_warning
);
954 if (error_operand_p (expr
)
955 || (flag_openmp
&& !check_omp_return ()))
957 /* Suppress -Wreturn-type for this function. */
958 if (warn_return_type
)
959 TREE_NO_WARNING (current_function_decl
) = true;
960 return error_mark_node
;
963 if (!processing_template_decl
)
965 if (warn_sequence_point
)
966 verify_sequence_points (expr
);
968 if (DECL_DESTRUCTOR_P (current_function_decl
)
969 || (DECL_CONSTRUCTOR_P (current_function_decl
)
970 && targetm
.cxx
.cdtor_returns_this ()))
972 /* Similarly, all destructors must run destructors for
973 base-classes before returning. So, all returns in a
974 destructor get sent to the DTOR_LABEL; finish_function emits
975 code to return a value there. */
976 return finish_goto_stmt (cdtor_label
);
980 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
981 TREE_NO_WARNING (r
) |= no_warning
;
982 r
= maybe_cleanup_point_expr_void (r
);
988 /* Begin the scope of a for-statement or a range-for-statement.
989 Both the returned trees are to be used in a call to
990 begin_for_stmt or begin_range_for_stmt. */
993 begin_for_scope (tree
*init
)
995 tree scope
= do_pushlevel (sk_for
);
997 if (processing_template_decl
)
998 *init
= push_stmt_list ();
1005 /* Begin a for-statement. Returns a new FOR_STMT.
1006 SCOPE and INIT should be the return of begin_for_scope,
1007 or both NULL_TREE */
1010 begin_for_stmt (tree scope
, tree init
)
1014 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
1015 NULL_TREE
, NULL_TREE
, NULL_TREE
);
1017 if (scope
== NULL_TREE
)
1020 scope
= begin_for_scope (&init
);
1023 FOR_INIT_STMT (r
) = init
;
1024 FOR_SCOPE (r
) = scope
;
1029 /* Finish the init-statement of a for-statement, which may be
1030 given by FOR_STMT. */
1033 finish_init_stmt (tree for_stmt
)
1035 if (processing_template_decl
)
1036 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
1037 add_stmt (for_stmt
);
1038 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
1039 begin_cond (&FOR_COND (for_stmt
));
1042 /* Finish the COND of a for-statement, which may be given by
1046 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
, unsigned short unroll
)
1048 cond
= maybe_convert_cond (cond
);
1049 finish_cond (&FOR_COND (for_stmt
), cond
);
1050 begin_maybe_infinite_loop (cond
);
1051 if (ivdep
&& cond
!= error_mark_node
)
1052 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1053 TREE_TYPE (FOR_COND (for_stmt
)),
1054 FOR_COND (for_stmt
),
1055 build_int_cst (integer_type_node
,
1056 annot_expr_ivdep_kind
),
1058 if (unroll
&& cond
!= error_mark_node
)
1059 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1060 TREE_TYPE (FOR_COND (for_stmt
)),
1061 FOR_COND (for_stmt
),
1062 build_int_cst (integer_type_node
,
1063 annot_expr_unroll_kind
),
1064 build_int_cst (integer_type_node
,
1066 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
1069 /* Finish the increment-EXPRESSION in a for-statement, which may be
1070 given by FOR_STMT. */
1073 finish_for_expr (tree expr
, tree for_stmt
)
1077 /* If EXPR is an overloaded function, issue an error; there is no
1078 context available to use to perform overload resolution. */
1079 if (type_unknown_p (expr
))
1081 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1082 expr
= error_mark_node
;
1084 if (!processing_template_decl
)
1086 if (warn_sequence_point
)
1087 verify_sequence_points (expr
);
1088 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1089 tf_warning_or_error
);
1091 else if (!type_dependent_expression_p (expr
))
1092 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1093 tf_warning_or_error
);
1094 expr
= maybe_cleanup_point_expr_void (expr
);
1095 if (check_for_bare_parameter_packs (expr
))
1096 expr
= error_mark_node
;
1097 FOR_EXPR (for_stmt
) = expr
;
1100 /* Finish the body of a for-statement, which may be given by
1101 FOR_STMT. The increment-EXPR for the loop must be
1103 It can also finish RANGE_FOR_STMT. */
1106 finish_for_stmt (tree for_stmt
)
1108 end_maybe_infinite_loop (boolean_true_node
);
1110 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1111 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1113 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1115 /* Pop the scope for the body of the loop. */
1116 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1117 ? &RANGE_FOR_SCOPE (for_stmt
)
1118 : &FOR_SCOPE (for_stmt
));
1119 tree scope
= *scope_ptr
;
1122 /* During parsing of the body, range for uses "__for_{range,begin,end} "
1123 decl names to make those unaccessible by code in the body.
1124 Change it to ones with underscore instead of space, so that it can
1125 be inspected in the debugger. */
1126 tree range_for_decl
[3] = { NULL_TREE
, NULL_TREE
, NULL_TREE
};
1127 gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 1
1128 && CPTI_FOR_END__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 2
1129 && CPTI_FOR_RANGE_IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 3
1130 && CPTI_FOR_BEGIN_IDENTIFIER
== CPTI_FOR_BEGIN__IDENTIFIER
+ 3
1131 && CPTI_FOR_END_IDENTIFIER
== CPTI_FOR_END__IDENTIFIER
+ 3);
1132 for (int i
= 0; i
< 3; i
++)
1134 tree id
= cp_global_trees
[CPTI_FOR_RANGE__IDENTIFIER
+ i
];
1135 if (IDENTIFIER_BINDING (id
)
1136 && IDENTIFIER_BINDING (id
)->scope
== current_binding_level
)
1138 range_for_decl
[i
] = IDENTIFIER_BINDING (id
)->value
;
1139 gcc_assert (VAR_P (range_for_decl
[i
])
1140 && DECL_ARTIFICIAL (range_for_decl
[i
]));
1144 add_stmt (do_poplevel (scope
));
1146 for (int i
= 0; i
< 3; i
++)
1147 if (range_for_decl
[i
])
1148 DECL_NAME (range_for_decl
[i
])
1149 = cp_global_trees
[CPTI_FOR_RANGE_IDENTIFIER
+ i
];
1152 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1153 SCOPE and INIT should be the return of begin_for_scope,
1155 To finish it call finish_for_stmt(). */
1158 begin_range_for_stmt (tree scope
, tree init
)
1160 begin_maybe_infinite_loop (boolean_false_node
);
1162 tree r
= build_stmt (input_location
, RANGE_FOR_STMT
, NULL_TREE
, NULL_TREE
,
1163 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1165 if (scope
== NULL_TREE
)
1168 scope
= begin_for_scope (&init
);
1171 /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1172 RANGE_FOR_INIT_STMT (r
) = init
;
1173 RANGE_FOR_SCOPE (r
) = scope
;
1178 /* Finish the head of a range-based for statement, which may
1179 be given by RANGE_FOR_STMT. DECL must be the declaration
1180 and EXPR must be the loop expression. */
1183 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1185 if (processing_template_decl
)
1186 RANGE_FOR_INIT_STMT (range_for_stmt
)
1187 = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt
));
1188 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1189 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1190 add_stmt (range_for_stmt
);
1191 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1194 /* Finish a break-statement. */
1197 finish_break_stmt (void)
1199 /* In switch statements break is sometimes stylistically used after
1200 a return statement. This can lead to spurious warnings about
1201 control reaching the end of a non-void function when it is
1202 inlined. Note that we are calling block_may_fallthru with
1203 language specific tree nodes; this works because
1204 block_may_fallthru returns true when given something it does not
1206 if (!block_may_fallthru (cur_stmt_list
))
1209 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1212 /* Finish a continue-statement. */
1215 finish_continue_stmt (void)
1217 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1220 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1224 begin_switch_stmt (void)
1228 scope
= do_pushlevel (sk_cond
);
1229 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1231 begin_cond (&SWITCH_STMT_COND (r
));
1236 /* Finish the cond of a switch-statement. */
1239 finish_switch_cond (tree cond
, tree switch_stmt
)
1241 tree orig_type
= NULL
;
1243 if (!processing_template_decl
)
1245 /* Convert the condition to an integer or enumeration type. */
1246 tree orig_cond
= cond
;
1247 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1248 if (cond
== NULL_TREE
)
1250 error_at (cp_expr_loc_or_input_loc (orig_cond
),
1251 "switch quantity not an integer");
1252 cond
= error_mark_node
;
1254 /* We want unlowered type here to handle enum bit-fields. */
1255 orig_type
= unlowered_expr_type (cond
);
1256 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1257 orig_type
= TREE_TYPE (cond
);
1258 if (cond
!= error_mark_node
)
1262 Integral promotions are performed. */
1263 cond
= perform_integral_promotions (cond
);
1264 cond
= maybe_cleanup_point_expr (cond
);
1267 if (check_for_bare_parameter_packs (cond
))
1268 cond
= error_mark_node
;
1269 else if (!processing_template_decl
&& warn_sequence_point
)
1270 verify_sequence_points (cond
);
1272 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1273 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1274 add_stmt (switch_stmt
);
1275 push_switch (switch_stmt
);
1276 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1279 /* Finish the body of a switch-statement, which may be given by
1280 SWITCH_STMT. The COND to switch on is indicated. */
1283 finish_switch_stmt (tree switch_stmt
)
1287 SWITCH_STMT_BODY (switch_stmt
) =
1288 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1291 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1292 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1293 add_stmt (do_poplevel (scope
));
1296 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1300 begin_try_block (void)
1302 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1304 TRY_STMTS (r
) = push_stmt_list ();
1308 /* Likewise, for a function-try-block. The block returned in
1309 *COMPOUND_STMT is an artificial outer scope, containing the
1310 function-try-block. */
1313 begin_function_try_block (tree
*compound_stmt
)
1316 /* This outer scope does not exist in the C++ standard, but we need
1317 a place to put __FUNCTION__ and similar variables. */
1318 *compound_stmt
= begin_compound_stmt (0);
1319 r
= begin_try_block ();
1320 FN_TRY_BLOCK_P (r
) = 1;
1324 /* Finish a try-block, which may be given by TRY_BLOCK. */
1327 finish_try_block (tree try_block
)
1329 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1330 TRY_HANDLERS (try_block
) = push_stmt_list ();
1333 /* Finish the body of a cleanup try-block, which may be given by
1337 finish_cleanup_try_block (tree try_block
)
1339 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1342 /* Finish an implicitly generated try-block, with a cleanup is given
1346 finish_cleanup (tree cleanup
, tree try_block
)
1348 TRY_HANDLERS (try_block
) = cleanup
;
1349 CLEANUP_P (try_block
) = 1;
1352 /* Likewise, for a function-try-block. */
1355 finish_function_try_block (tree try_block
)
1357 finish_try_block (try_block
);
1358 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1359 the try block, but moving it inside. */
1360 in_function_try_handler
= 1;
1363 /* Finish a handler-sequence for a try-block, which may be given by
1367 finish_handler_sequence (tree try_block
)
1369 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1370 check_handlers (TRY_HANDLERS (try_block
));
1373 /* Finish the handler-seq for a function-try-block, given by
1374 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1375 begin_function_try_block. */
1378 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1380 in_function_try_handler
= 0;
1381 finish_handler_sequence (try_block
);
1382 finish_compound_stmt (compound_stmt
);
1385 /* Begin a handler. Returns a HANDLER if appropriate. */
1388 begin_handler (void)
1392 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1395 /* Create a binding level for the eh_info and the exception object
1397 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1402 /* Finish the handler-parameters for a handler, which may be given by
1403 HANDLER. DECL is the declaration for the catch parameter, or NULL
1404 if this is a `catch (...)' clause. */
1407 finish_handler_parms (tree decl
, tree handler
)
1409 tree type
= NULL_TREE
;
1410 if (processing_template_decl
)
1414 decl
= pushdecl (decl
);
1415 decl
= push_template_decl (decl
);
1416 HANDLER_PARMS (handler
) = decl
;
1417 type
= TREE_TYPE (decl
);
1422 type
= expand_start_catch_block (decl
);
1423 if (warn_catch_value
1424 && type
!= NULL_TREE
1425 && type
!= error_mark_node
1426 && !TYPE_REF_P (TREE_TYPE (decl
)))
1428 tree orig_type
= TREE_TYPE (decl
);
1429 if (CLASS_TYPE_P (orig_type
))
1431 if (TYPE_POLYMORPHIC_P (orig_type
))
1432 warning (OPT_Wcatch_value_
,
1433 "catching polymorphic type %q#T by value", orig_type
);
1434 else if (warn_catch_value
> 1)
1435 warning (OPT_Wcatch_value_
,
1436 "catching type %q#T by value", orig_type
);
1438 else if (warn_catch_value
> 2)
1439 warning (OPT_Wcatch_value_
,
1440 "catching non-reference type %q#T", orig_type
);
1443 HANDLER_TYPE (handler
) = type
;
1446 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1447 the return value from the matching call to finish_handler_parms. */
1450 finish_handler (tree handler
)
1452 if (!processing_template_decl
)
1453 expand_end_catch_block ();
1454 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1457 /* Begin a compound statement. FLAGS contains some bits that control the
1458 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1459 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1460 block of a function. If BCS_TRY_BLOCK is set, this is the block
1461 created on behalf of a TRY statement. Returns a token to be passed to
1462 finish_compound_stmt. */
1465 begin_compound_stmt (unsigned int flags
)
1469 if (flags
& BCS_NO_SCOPE
)
1471 r
= push_stmt_list ();
1472 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1474 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1475 But, if it's a statement-expression with a scopeless block, there's
1476 nothing to keep, and we don't want to accidentally keep a block
1477 *inside* the scopeless block. */
1478 keep_next_level (false);
1482 scope_kind sk
= sk_block
;
1483 if (flags
& BCS_TRY_BLOCK
)
1485 else if (flags
& BCS_TRANSACTION
)
1486 sk
= sk_transaction
;
1487 r
= do_pushlevel (sk
);
1490 /* When processing a template, we need to remember where the braces were,
1491 so that we can set up identical scopes when instantiating the template
1492 later. BIND_EXPR is a handy candidate for this.
1493 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1494 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1495 processing templates. */
1496 if (processing_template_decl
)
1498 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1499 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1500 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1501 TREE_SIDE_EFFECTS (r
) = 1;
1507 /* Finish a compound-statement, which is given by STMT. */
1510 finish_compound_stmt (tree stmt
)
1512 if (TREE_CODE (stmt
) == BIND_EXPR
)
1514 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1515 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1516 discard the BIND_EXPR so it can be merged with the containing
1518 if (TREE_CODE (body
) == STATEMENT_LIST
1519 && STATEMENT_LIST_HEAD (body
) == NULL
1520 && !BIND_EXPR_BODY_BLOCK (stmt
)
1521 && !BIND_EXPR_TRY_BLOCK (stmt
))
1524 BIND_EXPR_BODY (stmt
) = body
;
1526 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1527 stmt
= pop_stmt_list (stmt
);
1530 /* Destroy any ObjC "super" receivers that may have been
1532 objc_clear_super_receiver ();
1534 stmt
= do_poplevel (stmt
);
1537 /* ??? See c_end_compound_stmt wrt statement expressions. */
1541 /* Finish an asm-statement, whose components are a STRING, some
1542 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1543 LABELS. Also note whether the asm-statement should be
1544 considered volatile, and whether it is asm inline. */
1547 finish_asm_stmt (location_t loc
, int volatile_p
, tree string
,
1548 tree output_operands
, tree input_operands
, tree clobbers
,
1549 tree labels
, bool inline_p
)
1553 int ninputs
= list_length (input_operands
);
1554 int noutputs
= list_length (output_operands
);
1556 if (!processing_template_decl
)
1558 const char *constraint
;
1559 const char **oconstraints
;
1560 bool allows_mem
, allows_reg
, is_inout
;
1564 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1566 string
= resolve_asm_operand_names (string
, output_operands
,
1567 input_operands
, labels
);
1569 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1571 operand
= TREE_VALUE (t
);
1573 /* ??? Really, this should not be here. Users should be using a
1574 proper lvalue, dammit. But there's a long history of using
1575 casts in the output operands. In cases like longlong.h, this
1576 becomes a primitive form of typechecking -- if the cast can be
1577 removed, then the output operand had a type of the proper width;
1578 otherwise we'll get an error. Gross, but ... */
1579 STRIP_NOPS (operand
);
1581 operand
= mark_lvalue_use (operand
);
1583 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1584 operand
= error_mark_node
;
1586 if (operand
!= error_mark_node
1587 && (TREE_READONLY (operand
)
1588 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1589 /* Functions are not modifiable, even though they are
1591 || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand
))
1592 /* If it's an aggregate and any field is const, then it is
1593 effectively const. */
1594 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1595 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1596 cxx_readonly_error (loc
, operand
, lv_asm
);
1598 tree
*op
= &operand
;
1599 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1600 op
= &TREE_OPERAND (*op
, 1);
1601 switch (TREE_CODE (*op
))
1603 case PREINCREMENT_EXPR
:
1604 case PREDECREMENT_EXPR
:
1606 *op
= genericize_compound_lvalue (*op
);
1607 op
= &TREE_OPERAND (*op
, 1);
1613 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1614 oconstraints
[i
] = constraint
;
1616 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1617 &allows_mem
, &allows_reg
, &is_inout
))
1619 /* If the operand is going to end up in memory,
1620 mark it addressable. */
1621 if (!allows_reg
&& !cxx_mark_addressable (*op
))
1622 operand
= error_mark_node
;
1625 operand
= error_mark_node
;
1627 TREE_VALUE (t
) = operand
;
1630 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1632 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1633 bool constraint_parsed
1634 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1635 oconstraints
, &allows_mem
, &allows_reg
);
1636 /* If the operand is going to end up in memory, don't call
1637 decay_conversion. */
1638 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1639 operand
= mark_lvalue_use (TREE_VALUE (t
));
1641 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1643 /* If the type of the operand hasn't been determined (e.g.,
1644 because it involves an overloaded function), then issue
1645 an error message. There's no context available to
1646 resolve the overloading. */
1647 if (TREE_TYPE (operand
) == unknown_type_node
)
1650 "type of %<asm%> operand %qE could not be determined",
1652 operand
= error_mark_node
;
1655 if (constraint_parsed
)
1657 /* If the operand is going to end up in memory,
1658 mark it addressable. */
1659 if (!allows_reg
&& allows_mem
)
1661 /* Strip the nops as we allow this case. FIXME, this really
1662 should be rejected or made deprecated. */
1663 STRIP_NOPS (operand
);
1665 tree
*op
= &operand
;
1666 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1667 op
= &TREE_OPERAND (*op
, 1);
1668 switch (TREE_CODE (*op
))
1670 case PREINCREMENT_EXPR
:
1671 case PREDECREMENT_EXPR
:
1673 *op
= genericize_compound_lvalue (*op
);
1674 op
= &TREE_OPERAND (*op
, 1);
1680 if (!cxx_mark_addressable (*op
))
1681 operand
= error_mark_node
;
1683 else if (!allows_reg
&& !allows_mem
)
1685 /* If constraint allows neither register nor memory,
1686 try harder to get a constant. */
1687 tree constop
= maybe_constant_value (operand
);
1688 if (TREE_CONSTANT (constop
))
1693 operand
= error_mark_node
;
1695 TREE_VALUE (t
) = operand
;
1699 r
= build_stmt (loc
, ASM_EXPR
, string
,
1700 output_operands
, input_operands
,
1702 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1703 ASM_INLINE_P (r
) = inline_p
;
1704 r
= maybe_cleanup_point_expr_void (r
);
1705 return add_stmt (r
);
1708 /* Finish a label with the indicated NAME. Returns the new label. */
1711 finish_label_stmt (tree name
)
1713 tree decl
= define_label (input_location
, name
);
1715 if (decl
== error_mark_node
)
1716 return error_mark_node
;
1718 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1723 /* Finish a series of declarations for local labels. G++ allows users
1724 to declare "local" labels, i.e., labels with scope. This extension
1725 is useful when writing code involving statement-expressions. */
1728 finish_label_decl (tree name
)
1730 if (!at_function_scope_p ())
1732 error ("%<__label__%> declarations are only allowed in function scopes");
1736 add_decl_expr (declare_local_label (name
));
1739 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1742 finish_decl_cleanup (tree decl
, tree cleanup
)
1744 push_cleanup (decl
, cleanup
, false);
1747 /* If the current scope exits with an exception, run CLEANUP. */
1750 finish_eh_cleanup (tree cleanup
)
1752 push_cleanup (NULL
, cleanup
, true);
1755 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1756 order they were written by the user. Each node is as for
1757 emit_mem_initializers. */
1760 finish_mem_initializers (tree mem_inits
)
1762 /* Reorder the MEM_INITS so that they are in the order they appeared
1763 in the source program. */
1764 mem_inits
= nreverse (mem_inits
);
1766 if (processing_template_decl
)
1770 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1772 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1773 check for bare parameter packs in the TREE_VALUE, because
1774 any parameter packs in the TREE_VALUE have already been
1775 bound as part of the TREE_PURPOSE. See
1776 make_pack_expansion for more information. */
1777 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1778 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1779 TREE_VALUE (mem
) = error_mark_node
;
1782 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1783 CTOR_INITIALIZER
, mem_inits
));
1786 emit_mem_initializers (mem_inits
);
1789 /* Obfuscate EXPR if it looks like an id-expression or member access so
1790 that the call to finish_decltype in do_auto_deduction will give the
1794 force_paren_expr (tree expr
)
1796 /* This is only needed for decltype(auto) in C++14. */
1797 if (cxx_dialect
< cxx14
)
1800 /* If we're in unevaluated context, we can't be deducing a
1801 return/initializer type, so we don't need to mess with this. */
1802 if (cp_unevaluated_operand
)
1805 if (!DECL_P (tree_strip_any_location_wrapper (expr
))
1806 && TREE_CODE (expr
) != COMPONENT_REF
1807 && TREE_CODE (expr
) != SCOPE_REF
)
1810 location_t loc
= cp_expr_location (expr
);
1812 if (TREE_CODE (expr
) == COMPONENT_REF
1813 || TREE_CODE (expr
) == SCOPE_REF
)
1814 REF_PARENTHESIZED_P (expr
) = true;
1815 else if (processing_template_decl
)
1816 expr
= build1_loc (loc
, PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1819 expr
= build1_loc (loc
, VIEW_CONVERT_EXPR
, TREE_TYPE (expr
), expr
);
1820 REF_PARENTHESIZED_P (expr
) = true;
1826 /* If T is an id-expression obfuscated by force_paren_expr, undo the
1827 obfuscation and return the underlying id-expression. Otherwise
1831 maybe_undo_parenthesized_ref (tree t
)
1833 if (cxx_dialect
< cxx14
)
1836 if (INDIRECT_REF_P (t
) && REF_PARENTHESIZED_P (t
))
1838 t
= TREE_OPERAND (t
, 0);
1839 while (TREE_CODE (t
) == NON_LVALUE_EXPR
1840 || TREE_CODE (t
) == NOP_EXPR
)
1841 t
= TREE_OPERAND (t
, 0);
1843 gcc_assert (TREE_CODE (t
) == ADDR_EXPR
1844 || TREE_CODE (t
) == STATIC_CAST_EXPR
);
1845 t
= TREE_OPERAND (t
, 0);
1847 else if (TREE_CODE (t
) == PAREN_EXPR
)
1848 t
= TREE_OPERAND (t
, 0);
1849 else if (TREE_CODE (t
) == VIEW_CONVERT_EXPR
1850 && REF_PARENTHESIZED_P (t
))
1851 t
= TREE_OPERAND (t
, 0);
1856 /* Finish a parenthesized expression EXPR. */
1859 finish_parenthesized_expr (cp_expr expr
)
1862 /* This inhibits warnings in c_common_truthvalue_conversion. */
1863 TREE_NO_WARNING (expr
) = 1;
1865 if (TREE_CODE (expr
) == OFFSET_REF
1866 || TREE_CODE (expr
) == SCOPE_REF
)
1867 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1868 enclosed in parentheses. */
1869 PTRMEM_OK_P (expr
) = 0;
1871 tree stripped_expr
= tree_strip_any_location_wrapper (expr
);
1872 if (TREE_CODE (stripped_expr
) == STRING_CST
)
1873 PAREN_STRING_LITERAL_P (stripped_expr
) = 1;
1875 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
1880 /* Finish a reference to a non-static data member (DECL) that is not
1881 preceded by `.' or `->'. */
1884 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1886 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1887 bool try_omp_private
= !object
&& omp_private_member_map
;
1892 tree scope
= qualifying_scope
;
1893 if (scope
== NULL_TREE
)
1895 scope
= context_for_name_lookup (decl
);
1896 if (!TYPE_P (scope
))
1898 /* Can happen during error recovery (c++/85014). */
1899 gcc_assert (seen_error ());
1900 return error_mark_node
;
1903 object
= maybe_dummy_object (scope
, NULL
);
1906 object
= maybe_resolve_dummy (object
, true);
1907 if (object
== error_mark_node
)
1908 return error_mark_node
;
1910 /* DR 613/850: Can use non-static data members without an associated
1911 object in sizeof/decltype/alignof. */
1912 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
1913 && (!processing_template_decl
|| !current_class_ref
))
1915 if (current_function_decl
1916 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1917 error ("invalid use of member %qD in static member function", decl
);
1919 error ("invalid use of non-static data member %qD", decl
);
1920 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
1922 return error_mark_node
;
1925 if (current_class_ptr
)
1926 TREE_USED (current_class_ptr
) = 1;
1927 if (processing_template_decl
)
1929 tree type
= TREE_TYPE (decl
);
1931 if (TYPE_REF_P (type
))
1932 /* Quals on the object don't matter. */;
1933 else if (PACK_EXPANSION_P (type
))
1934 /* Don't bother trying to represent this. */
1938 /* Set the cv qualifiers. */
1939 int quals
= cp_type_quals (TREE_TYPE (object
));
1941 if (DECL_MUTABLE_P (decl
))
1942 quals
&= ~TYPE_QUAL_CONST
;
1944 quals
|= cp_type_quals (TREE_TYPE (decl
));
1945 type
= cp_build_qualified_type (type
, quals
);
1948 if (qualifying_scope
)
1949 /* Wrap this in a SCOPE_REF for now. */
1950 ret
= build_qualified_name (type
, qualifying_scope
, decl
,
1951 /*template_p=*/false);
1953 ret
= (convert_from_reference
1954 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
1956 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1957 QUALIFYING_SCOPE is also non-null. */
1960 tree access_type
= TREE_TYPE (object
);
1962 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
1963 decl
, tf_warning_or_error
);
1965 /* If the data member was named `C::M', convert `*this' to `C'
1967 if (qualifying_scope
)
1969 tree binfo
= NULL_TREE
;
1970 object
= build_scoped_ref (object
, qualifying_scope
,
1974 ret
= build_class_member_access_expr (object
, decl
,
1975 /*access_path=*/NULL_TREE
,
1976 /*preserve_reference=*/false,
1977 tf_warning_or_error
);
1979 if (try_omp_private
)
1981 tree
*v
= omp_private_member_map
->get (decl
);
1983 ret
= convert_from_reference (*v
);
1988 /* If we are currently parsing a template and we encountered a typedef
1989 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1990 adds the typedef to a list tied to the current template.
1991 At template instantiation time, that list is walked and access check
1992 performed for each typedef.
1993 LOCATION is the location of the usage point of TYPEDEF_DECL. */
1996 add_typedef_to_current_template_for_access_check (tree typedef_decl
,
1998 location_t location
)
2000 tree template_info
= NULL
;
2001 tree cs
= current_scope ();
2003 if (!is_typedef_decl (typedef_decl
)
2005 || !CLASS_TYPE_P (context
)
2009 if (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
)
2010 template_info
= get_template_info (cs
);
2013 && TI_TEMPLATE (template_info
)
2014 && !currently_open_class (context
))
2015 append_type_to_template_for_access_check (cs
, typedef_decl
,
2019 /* DECL was the declaration to which a qualified-id resolved. Issue
2020 an error message if it is not accessible. If OBJECT_TYPE is
2021 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2022 type of `*x', or `x', respectively. If the DECL was named as
2023 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
2026 check_accessibility_of_qualified_id (tree decl
,
2028 tree nested_name_specifier
)
2031 tree qualifying_type
= NULL_TREE
;
2033 /* If we are parsing a template declaration and if decl is a typedef,
2034 add it to a list tied to the template.
2035 At template instantiation time, that list will be walked and
2036 access check performed. */
2037 add_typedef_to_current_template_for_access_check (decl
,
2038 nested_name_specifier
2039 ? nested_name_specifier
2040 : DECL_CONTEXT (decl
),
2043 /* If we're not checking, return immediately. */
2044 if (deferred_access_no_check
)
2047 /* Determine the SCOPE of DECL. */
2048 scope
= context_for_name_lookup (decl
);
2049 /* If the SCOPE is not a type, then DECL is not a member. */
2050 if (!TYPE_P (scope
))
2052 /* Compute the scope through which DECL is being accessed. */
2054 /* OBJECT_TYPE might not be a class type; consider:
2056 class A { typedef int I; };
2060 In this case, we will have "A::I" as the DECL, but "I" as the
2062 && CLASS_TYPE_P (object_type
)
2063 && DERIVED_FROM_P (scope
, object_type
))
2064 /* If we are processing a `->' or `.' expression, use the type of the
2066 qualifying_type
= object_type
;
2067 else if (nested_name_specifier
)
2069 /* If the reference is to a non-static member of the
2070 current class, treat it as if it were referenced through
2073 if (DECL_NONSTATIC_MEMBER_P (decl
)
2074 && current_class_ptr
2075 && DERIVED_FROM_P (scope
, ct
= current_nonlambda_class_type ()))
2076 qualifying_type
= ct
;
2077 /* Otherwise, use the type indicated by the
2078 nested-name-specifier. */
2080 qualifying_type
= nested_name_specifier
;
2083 /* Otherwise, the name must be from the current class or one of
2085 qualifying_type
= currently_open_derived_class (scope
);
2088 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2089 or similar in a default argument value. */
2090 && CLASS_TYPE_P (qualifying_type
)
2091 && !dependent_type_p (qualifying_type
))
2092 perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
2093 decl
, tf_warning_or_error
);
2096 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2097 class named to the left of the "::" operator. DONE is true if this
2098 expression is a complete postfix-expression; it is false if this
2099 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2100 iff this expression is the operand of '&'. TEMPLATE_P is true iff
2101 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2102 is true iff this qualified name appears as a template argument. */
2105 finish_qualified_id_expr (tree qualifying_class
,
2110 bool template_arg_p
,
2111 tsubst_flags_t complain
)
2113 gcc_assert (TYPE_P (qualifying_class
));
2115 if (error_operand_p (expr
))
2116 return error_mark_node
;
2118 if ((DECL_P (expr
) || BASELINK_P (expr
))
2119 && !mark_used (expr
, complain
))
2120 return error_mark_node
;
2124 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
2126 /* cp_parser_lookup_name thought we were looking for a type,
2127 but we're actually looking for a declaration. */
2128 qualifying_class
= TYPE_CONTEXT (expr
);
2129 expr
= TYPE_IDENTIFIER (expr
);
2132 check_template_keyword (expr
);
2135 /* If EXPR occurs as the operand of '&', use special handling that
2136 permits a pointer-to-member. */
2137 if (address_p
&& done
)
2139 if (TREE_CODE (expr
) == SCOPE_REF
)
2140 expr
= TREE_OPERAND (expr
, 1);
2141 expr
= build_offset_ref (qualifying_class
, expr
,
2142 /*address_p=*/true, complain
);
2146 /* No need to check access within an enum. */
2147 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
2148 && TREE_CODE (expr
) != IDENTIFIER_NODE
)
2151 /* Within the scope of a class, turn references to non-static
2152 members into expression of the form "this->...". */
2154 /* But, within a template argument, we do not want make the
2155 transformation, as there is no "this" pointer. */
2157 else if (TREE_CODE (expr
) == FIELD_DECL
)
2159 push_deferring_access_checks (dk_no_check
);
2160 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2162 pop_deferring_access_checks ();
2164 else if (BASELINK_P (expr
))
2166 /* See if any of the functions are non-static members. */
2167 /* If so, the expression may be relative to 'this'. */
2168 if ((type_dependent_expression_p (expr
)
2169 || !shared_member_p (expr
))
2170 && current_class_ptr
2171 && DERIVED_FROM_P (qualifying_class
,
2172 current_nonlambda_class_type ()))
2173 expr
= (build_class_member_access_expr
2174 (maybe_dummy_object (qualifying_class
, NULL
),
2176 BASELINK_ACCESS_BINFO (expr
),
2177 /*preserve_reference=*/false,
2180 /* The expression is a qualified name whose address is not
2182 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2185 else if (!template_p
2186 && TREE_CODE (expr
) == TEMPLATE_DECL
2187 && !DECL_FUNCTION_TEMPLATE_P (expr
))
2189 if (complain
& tf_error
)
2190 error ("%qE missing template arguments", expr
);
2191 return error_mark_node
;
2195 /* In a template, return a SCOPE_REF for most qualified-ids
2196 so that we can check access at instantiation time. But if
2197 we're looking at a member of the current instantiation, we
2198 know we have access and building up the SCOPE_REF confuses
2199 non-type template argument handling. */
2200 if (processing_template_decl
2201 && (!currently_open_class (qualifying_class
)
2202 || TREE_CODE (expr
) == IDENTIFIER_NODE
2203 || TREE_CODE (expr
) == TEMPLATE_ID_EXPR
2204 || TREE_CODE (expr
) == BIT_NOT_EXPR
))
2205 expr
= build_qualified_name (TREE_TYPE (expr
),
2206 qualifying_class
, expr
,
2208 else if (tree wrap
= maybe_get_tls_wrapper_call (expr
))
2211 expr
= convert_from_reference (expr
);
2217 /* Begin a statement-expression. The value returned must be passed to
2218 finish_stmt_expr. */
2221 begin_stmt_expr (void)
2223 return push_stmt_list ();
2226 /* Process the final expression of a statement expression. EXPR can be
2227 NULL, if the final expression is empty. Return a STATEMENT_LIST
2228 containing all the statements in the statement-expression, or
2229 ERROR_MARK_NODE if there was an error. */
2232 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2234 if (error_operand_p (expr
))
2236 /* The type of the statement-expression is the type of the last
2238 TREE_TYPE (stmt_expr
) = error_mark_node
;
2239 return error_mark_node
;
2242 /* If the last statement does not have "void" type, then the value
2243 of the last statement is the value of the entire expression. */
2246 tree type
= TREE_TYPE (expr
);
2248 if (type
&& type_unknown_p (type
))
2250 error ("a statement expression is an insufficient context"
2251 " for overload resolution");
2252 TREE_TYPE (stmt_expr
) = error_mark_node
;
2253 return error_mark_node
;
2255 else if (processing_template_decl
)
2257 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2258 expr
= add_stmt (expr
);
2259 /* Mark the last statement so that we can recognize it as such at
2260 template-instantiation time. */
2261 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2263 else if (VOID_TYPE_P (type
))
2265 /* Just treat this like an ordinary statement. */
2266 expr
= finish_expr_stmt (expr
);
2270 /* It actually has a value we need to deal with. First, force it
2271 to be an rvalue so that we won't need to build up a copy
2272 constructor call later when we try to assign it to something. */
2273 expr
= force_rvalue (expr
, tf_warning_or_error
);
2274 if (error_operand_p (expr
))
2275 return error_mark_node
;
2277 /* Update for array-to-pointer decay. */
2278 type
= TREE_TYPE (expr
);
2280 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2281 normal statement, but don't convert to void or actually add
2283 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2284 expr
= maybe_cleanup_point_expr (expr
);
2288 /* The type of the statement-expression is the type of the last
2290 TREE_TYPE (stmt_expr
) = type
;
2296 /* Finish a statement-expression. EXPR should be the value returned
2297 by the previous begin_stmt_expr. Returns an expression
2298 representing the statement-expression. */
2301 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2306 if (error_operand_p (stmt_expr
))
2308 pop_stmt_list (stmt_expr
);
2309 return error_mark_node
;
2312 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2314 type
= TREE_TYPE (stmt_expr
);
2315 result
= pop_stmt_list (stmt_expr
);
2316 TREE_TYPE (result
) = type
;
2318 if (processing_template_decl
)
2320 result
= build_min (STMT_EXPR
, type
, result
);
2321 TREE_SIDE_EFFECTS (result
) = 1;
2322 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2324 else if (CLASS_TYPE_P (type
))
2326 /* Wrap the statement-expression in a TARGET_EXPR so that the
2327 temporary object created by the final expression is destroyed at
2328 the end of the full-expression containing the
2329 statement-expression. */
2330 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2336 /* Returns the expression which provides the value of STMT_EXPR. */
2339 stmt_expr_value_expr (tree stmt_expr
)
2341 tree t
= STMT_EXPR_STMT (stmt_expr
);
2343 if (TREE_CODE (t
) == BIND_EXPR
)
2344 t
= BIND_EXPR_BODY (t
);
2346 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2347 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2349 if (TREE_CODE (t
) == EXPR_STMT
)
2350 t
= EXPR_STMT_EXPR (t
);
2355 /* Return TRUE iff EXPR_STMT is an empty list of
2356 expression statements. */
2359 empty_expr_stmt_p (tree expr_stmt
)
2361 tree body
= NULL_TREE
;
2363 if (expr_stmt
== void_node
)
2368 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2369 body
= EXPR_STMT_EXPR (expr_stmt
);
2370 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2376 if (TREE_CODE (body
) == STATEMENT_LIST
)
2377 return tsi_end_p (tsi_start (body
));
2379 return empty_expr_stmt_p (body
);
2384 /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
2385 the function (or functions) to call; ARGS are the arguments to the
2386 call. Returns the functions to be considered by overload resolution. */
2389 perform_koenig_lookup (cp_expr fn_expr
, vec
<tree
, va_gc
> *args
,
2390 tsubst_flags_t complain
)
2392 tree identifier
= NULL_TREE
;
2393 tree functions
= NULL_TREE
;
2394 tree tmpl_args
= NULL_TREE
;
2395 bool template_id
= false;
2396 location_t loc
= fn_expr
.get_location ();
2397 tree fn
= fn_expr
.get_value ();
2399 STRIP_ANY_LOCATION_WRAPPER (fn
);
2401 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2403 /* Use a separate flag to handle null args. */
2405 tmpl_args
= TREE_OPERAND (fn
, 1);
2406 fn
= TREE_OPERAND (fn
, 0);
2409 /* Find the name of the overloaded function. */
2410 if (identifier_p (fn
))
2415 identifier
= OVL_NAME (functions
);
2418 /* A call to a namespace-scope function using an unqualified name.
2420 Do Koenig lookup -- unless any of the arguments are
2422 if (!any_type_dependent_arguments_p (args
)
2423 && !any_dependent_template_arguments_p (tmpl_args
))
2425 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2428 /* The unqualified name could not be resolved. */
2429 if (complain
& tf_error
)
2430 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2436 if (fn
&& template_id
&& fn
!= error_mark_node
)
2437 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2439 return cp_expr (fn
, loc
);
2442 /* Generate an expression for `FN (ARGS)'. This may change the
2445 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2446 as a virtual call, even if FN is virtual. (This flag is set when
2447 encountering an expression where the function name is explicitly
2448 qualified. For example a call to `X::f' never generates a virtual
2451 Returns code for the call. */
2454 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2455 bool koenig_p
, tsubst_flags_t complain
)
2459 vec
<tree
, va_gc
> *orig_args
= *args
;
2461 if (fn
== error_mark_node
)
2462 return error_mark_node
;
2464 gcc_assert (!TYPE_P (fn
));
2466 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2467 it so that we can tell this is a call to a known function. */
2468 fn
= maybe_undo_parenthesized_ref (fn
);
2470 STRIP_ANY_LOCATION_WRAPPER (fn
);
2474 if (processing_template_decl
)
2476 /* If FN is a local extern declaration or set thereof, look them up
2477 again at instantiation time. */
2478 if (is_overloaded_fn (fn
))
2480 tree ifn
= get_first_fn (fn
);
2481 if (TREE_CODE (ifn
) == FUNCTION_DECL
2482 && DECL_LOCAL_FUNCTION_P (ifn
))
2483 orig_fn
= DECL_NAME (ifn
);
2486 /* If the call expression is dependent, build a CALL_EXPR node
2487 with no type; type_dependent_expression_p recognizes
2488 expressions with no type as being dependent. */
2489 if (type_dependent_expression_p (fn
)
2490 || any_type_dependent_arguments_p (*args
))
2492 result
= build_min_nt_call_vec (orig_fn
, *args
);
2493 SET_EXPR_LOCATION (result
, cp_expr_loc_or_input_loc (fn
));
2494 KOENIG_LOOKUP_P (result
) = koenig_p
;
2495 if (is_overloaded_fn (fn
))
2500 bool abnormal
= true;
2501 for (lkp_iterator
iter (fn
); abnormal
&& iter
; ++iter
)
2503 tree fndecl
= *iter
;
2504 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2505 || !TREE_THIS_VOLATILE (fndecl
))
2508 /* FIXME: Stop warning about falling off end of non-void
2509 function. But this is wrong. Even if we only see
2510 no-return fns at this point, we could select a
2511 future-defined return fn during instantiation. Or
2514 current_function_returns_abnormally
= 1;
2518 orig_args
= make_tree_vector_copy (*args
);
2519 if (!BASELINK_P (fn
)
2520 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2521 && TREE_TYPE (fn
) != unknown_type_node
)
2522 fn
= build_non_dependent_expr (fn
);
2523 make_args_non_dependent (*args
);
2526 if (TREE_CODE (fn
) == COMPONENT_REF
)
2528 tree member
= TREE_OPERAND (fn
, 1);
2529 if (BASELINK_P (member
))
2531 tree object
= TREE_OPERAND (fn
, 0);
2532 return build_new_method_call (object
, member
,
2535 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2542 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2543 if (TREE_CODE (fn
) == ADDR_EXPR
2544 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2545 fn
= TREE_OPERAND (fn
, 0);
2547 if (is_overloaded_fn (fn
))
2548 fn
= baselink_for_fns (fn
);
2551 if (BASELINK_P (fn
))
2555 /* A call to a member function. From [over.call.func]:
2557 If the keyword this is in scope and refers to the class of
2558 that member function, or a derived class thereof, then the
2559 function call is transformed into a qualified function call
2560 using (*this) as the postfix-expression to the left of the
2561 . operator.... [Otherwise] a contrived object of type T
2562 becomes the implied object argument.
2566 struct A { void f(); };
2567 struct B : public A {};
2568 struct C : public A { void g() { B::f(); }};
2570 "the class of that member function" refers to `A'. But 11.2
2571 [class.access.base] says that we need to convert 'this' to B* as
2572 part of the access, so we pass 'B' to maybe_dummy_object. */
2574 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2576 /* A constructor call always uses a dummy object. (This constructor
2577 call which has the form A::A () is actually invalid and we are
2578 going to reject it later in build_new_method_call.) */
2579 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2582 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2585 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2587 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2592 else if (is_overloaded_fn (fn
))
2594 /* If the function is an overloaded builtin, resolve it. */
2595 if (TREE_CODE (fn
) == FUNCTION_DECL
2596 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2597 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2598 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2602 if (warn_sizeof_pointer_memaccess
2603 && (complain
& tf_warning
)
2604 && !vec_safe_is_empty (*args
)
2605 && !processing_template_decl
)
2607 location_t sizeof_arg_loc
[3];
2610 for (i
= 0; i
< 3; i
++)
2614 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2615 sizeof_arg
[i
] = NULL_TREE
;
2616 if (i
>= (*args
)->length ())
2619 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2621 if (SIZEOF_EXPR_TYPE_P (t
))
2622 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2624 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2625 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2627 sizeof_pointer_memaccess_warning
2628 (sizeof_arg_loc
, fn
, *args
,
2629 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2632 if ((complain
& tf_warning
)
2633 && TREE_CODE (fn
) == FUNCTION_DECL
2634 && fndecl_built_in_p (fn
, BUILT_IN_MEMSET
)
2635 && vec_safe_length (*args
) == 3
2636 && !any_type_dependent_arguments_p (*args
))
2638 tree arg0
= (*orig_args
)[0];
2639 tree arg1
= (*orig_args
)[1];
2640 tree arg2
= (*orig_args
)[2];
2641 int literal_mask
= ((literal_integer_zerop (arg1
) << 1)
2642 | (literal_integer_zerop (arg2
) << 2));
2643 arg2
= instantiate_non_dependent_expr (arg2
);
2644 warn_for_memset (input_location
, arg0
, arg2
, literal_mask
);
2647 /* A call to a namespace-scope function. */
2648 result
= build_new_function_call (fn
, args
, complain
);
2651 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2653 if (!vec_safe_is_empty (*args
))
2654 error ("arguments to destructor are not allowed");
2655 /* Mark the pseudo-destructor call as having side-effects so
2656 that we do not issue warnings about its use. */
2657 result
= build1 (NOP_EXPR
,
2659 TREE_OPERAND (fn
, 0));
2660 TREE_SIDE_EFFECTS (result
) = 1;
2662 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2663 /* If the "function" is really an object of class type, it might
2664 have an overloaded `operator ()'. */
2665 result
= build_op_call (fn
, args
, complain
);
2668 /* A call where the function is unknown. */
2669 result
= cp_build_function_call_vec (fn
, args
, complain
);
2671 if (processing_template_decl
&& result
!= error_mark_node
)
2673 if (INDIRECT_REF_P (result
))
2674 result
= TREE_OPERAND (result
, 0);
2675 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2676 SET_EXPR_LOCATION (result
, input_location
);
2677 KOENIG_LOOKUP_P (result
) = koenig_p
;
2678 release_tree_vector (orig_args
);
2679 result
= convert_from_reference (result
);
2685 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2686 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2687 POSTDECREMENT_EXPR.) */
2690 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2692 /* input_location holds the location of the trailing operator token.
2693 Build a location of the form:
2696 with the caret at the operator token, ranging from the start
2697 of EXPR to the end of the operator token. */
2698 location_t combined_loc
= make_location (input_location
,
2700 get_finish (input_location
));
2701 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2702 tf_warning_or_error
);
2703 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2704 result
.set_location (combined_loc
);
2708 /* Finish a use of `this'. Returns an expression for `this'. */
2711 finish_this_expr (void)
2713 tree result
= NULL_TREE
;
2715 if (current_class_ptr
)
2717 tree type
= TREE_TYPE (current_class_ref
);
2719 /* In a lambda expression, 'this' refers to the captured 'this'. */
2720 if (LAMBDA_TYPE_P (type
))
2721 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2723 result
= current_class_ptr
;
2727 /* The keyword 'this' is a prvalue expression. */
2728 return rvalue (result
);
2730 tree fn
= current_nonlambda_function ();
2731 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2732 error ("%<this%> is unavailable for static member functions");
2734 error ("invalid use of %<this%> in non-member function");
2736 error ("invalid use of %<this%> at top level");
2737 return error_mark_node
;
2740 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2741 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2742 the TYPE for the type given. If SCOPE is non-NULL, the expression
2743 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2746 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2749 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2750 return error_mark_node
;
2752 gcc_assert (TYPE_P (destructor
));
2754 if (!processing_template_decl
)
2756 if (scope
== error_mark_node
)
2758 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2759 return error_mark_node
;
2761 if (is_auto (destructor
))
2762 destructor
= TREE_TYPE (object
);
2763 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2766 "qualified type %qT does not match destructor name ~%qT",
2768 return error_mark_node
;
2772 /* [expr.pseudo] says both:
2774 The type designated by the pseudo-destructor-name shall be
2775 the same as the object type.
2779 The cv-unqualified versions of the object type and of the
2780 type designated by the pseudo-destructor-name shall be the
2783 We implement the more generous second sentence, since that is
2784 what most other compilers do. */
2785 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2788 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2789 return error_mark_node
;
2793 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, void_type_node
, object
,
2797 /* Finish an expression of the form CODE EXPR. */
2800 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
2801 tsubst_flags_t complain
)
2803 /* Build a location of the form:
2806 with the caret at the operator token, ranging from the start
2807 of the operator token to the end of EXPR. */
2808 location_t combined_loc
= make_location (op_loc
,
2809 op_loc
, expr
.get_finish ());
2810 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
, complain
);
2811 /* TODO: build_x_unary_op doesn't always honor the location. */
2812 result
.set_location (combined_loc
);
2814 if (result
== error_mark_node
)
2817 if (!(complain
& tf_warning
))
2820 tree result_ovl
= result
;
2821 tree expr_ovl
= expr
;
2823 if (!processing_template_decl
)
2824 expr_ovl
= cp_fully_fold (expr_ovl
);
2826 if (!CONSTANT_CLASS_P (expr_ovl
)
2827 || TREE_OVERFLOW_P (expr_ovl
))
2830 if (!processing_template_decl
)
2831 result_ovl
= cp_fully_fold (result_ovl
);
2833 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
2834 overflow_warning (combined_loc
, result_ovl
);
2839 /* Finish a compound-literal expression or C++11 functional cast with aggregate
2840 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
2844 finish_compound_literal (tree type
, tree compound_literal
,
2845 tsubst_flags_t complain
,
2848 if (type
== error_mark_node
)
2849 return error_mark_node
;
2851 if (TYPE_REF_P (type
))
2854 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2855 complain
, fcl_context
);
2856 /* The prvalue is then used to direct-initialize the reference. */
2857 tree r
= (perform_implicit_conversion_flags
2858 (type
, compound_literal
, complain
, LOOKUP_NORMAL
));
2859 return convert_from_reference (r
);
2862 if (!TYPE_OBJ_P (type
))
2864 if (complain
& tf_error
)
2865 error ("compound literal of non-object type %qT", type
);
2866 return error_mark_node
;
2869 if (tree anode
= type_uses_auto (type
))
2870 if (CLASS_PLACEHOLDER_TEMPLATE (anode
))
2872 type
= do_auto_deduction (type
, compound_literal
, anode
, complain
,
2874 if (type
== error_mark_node
)
2875 return error_mark_node
;
2878 /* Used to hold a copy of the compound literal in a template. */
2879 tree orig_cl
= NULL_TREE
;
2881 if (processing_template_decl
)
2883 const bool dependent_p
2884 = (instantiation_dependent_expression_p (compound_literal
)
2885 || dependent_type_p (type
));
2887 /* We're about to return, no need to copy. */
2888 orig_cl
= compound_literal
;
2890 /* We're going to need a copy. */
2891 orig_cl
= unshare_constructor (compound_literal
);
2892 TREE_TYPE (orig_cl
) = type
;
2893 /* Mark the expression as a compound literal. */
2894 TREE_HAS_CONSTRUCTOR (orig_cl
) = 1;
2895 /* And as instantiation-dependent. */
2896 CONSTRUCTOR_IS_DEPENDENT (orig_cl
) = dependent_p
;
2897 if (fcl_context
== fcl_c99
)
2898 CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl
) = 1;
2899 /* If the compound literal is dependent, we're done for now. */
2902 /* Otherwise, do go on to e.g. check narrowing. */
2905 type
= complete_type (type
);
2907 if (TYPE_NON_AGGREGATE_CLASS (type
))
2909 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2910 everywhere that deals with function arguments would be a pain, so
2911 just wrap it in a TREE_LIST. The parser set a flag so we know
2912 that it came from T{} rather than T({}). */
2913 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2914 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2915 return build_functional_cast (type
, compound_literal
, complain
);
2918 if (TREE_CODE (type
) == ARRAY_TYPE
2919 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2920 return error_mark_node
;
2921 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2922 if (SCALAR_TYPE_P (type
)
2923 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
))
2925 tree t
= instantiate_non_dependent_expr_sfinae (compound_literal
,
2927 if (!check_narrowing (type
, t
, complain
))
2928 return error_mark_node
;
2930 if (TREE_CODE (type
) == ARRAY_TYPE
2931 && TYPE_DOMAIN (type
) == NULL_TREE
)
2933 cp_complete_array_type_or_error (&type
, compound_literal
,
2935 if (type
== error_mark_node
)
2936 return error_mark_node
;
2938 compound_literal
= digest_init_flags (type
, compound_literal
,
2939 LOOKUP_NORMAL
| LOOKUP_NO_NARROWING
,
2941 if (compound_literal
== error_mark_node
)
2942 return error_mark_node
;
2944 /* If we're in a template, return the original compound literal. */
2947 if (!VECTOR_TYPE_P (type
))
2948 return get_target_expr_sfinae (orig_cl
, complain
);
2953 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
2955 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
2956 if (fcl_context
== fcl_c99
)
2957 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
2960 /* Put static/constant array temporaries in static variables. */
2961 /* FIXME all C99 compound literals should be variables rather than C++
2962 temporaries, unless they are used as an aggregate initializer. */
2963 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
2964 && fcl_context
== fcl_c99
2965 && TREE_CODE (type
) == ARRAY_TYPE
2966 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
2967 && initializer_constant_valid_p (compound_literal
, type
))
2969 tree decl
= create_temporary_var (type
);
2970 DECL_INITIAL (decl
) = compound_literal
;
2971 TREE_STATIC (decl
) = 1;
2972 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
2974 /* 5.19 says that a constant expression can include an
2975 lvalue-rvalue conversion applied to "a glvalue of literal type
2976 that refers to a non-volatile temporary object initialized
2977 with a constant expression". Rather than try to communicate
2978 that this VAR_DECL is a temporary, just mark it constexpr. */
2979 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
2980 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
2981 TREE_CONSTANT (decl
) = true;
2983 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
2984 decl
= pushdecl_top_level (decl
);
2985 DECL_NAME (decl
) = make_anon_name ();
2986 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
2987 /* Make sure the destructor is callable. */
2988 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
2989 if (clean
== error_mark_node
)
2990 return error_mark_node
;
2994 /* Represent other compound literals with TARGET_EXPR so we produce
2995 an lvalue, but can elide copies. */
2996 if (!VECTOR_TYPE_P (type
))
2997 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
2999 return compound_literal
;
3002 /* Return the declaration for the function-name variable indicated by
3006 finish_fname (tree id
)
3010 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
3011 if (processing_template_decl
&& current_function_decl
3012 && decl
!= error_mark_node
)
3013 decl
= DECL_NAME (decl
);
3017 /* Finish a translation unit. */
3020 finish_translation_unit (void)
3022 /* In case there were missing closebraces,
3023 get us back to the global binding level. */
3025 while (current_namespace
!= global_namespace
)
3028 /* Do file scope __FUNCTION__ et al. */
3029 finish_fname_decls ();
3032 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
3033 Returns the parameter. */
3036 finish_template_type_parm (tree aggr
, tree identifier
)
3038 if (aggr
!= class_type_node
)
3040 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
3041 aggr
= class_type_node
;
3044 return build_tree_list (aggr
, identifier
);
3047 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
3048 Returns the parameter. */
3051 finish_template_template_parm (tree aggr
, tree identifier
)
3053 tree decl
= build_decl (input_location
,
3054 TYPE_DECL
, identifier
, NULL_TREE
);
3056 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
3057 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
3058 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
3059 DECL_ARTIFICIAL (decl
) = 1;
3061 /* Associate the constraints with the underlying declaration,
3062 not the template. */
3063 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
3064 tree constr
= build_constraints (reqs
, NULL_TREE
);
3065 set_constraints (decl
, constr
);
3067 end_template_decl ();
3069 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
3071 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
3072 /*is_primary=*/true, /*is_partial=*/false,
3075 return finish_template_type_parm (aggr
, tmpl
);
3078 /* ARGUMENT is the default-argument value for a template template
3079 parameter. If ARGUMENT is invalid, issue error messages and return
3080 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
3083 check_template_template_default_arg (tree argument
)
3085 if (TREE_CODE (argument
) != TEMPLATE_DECL
3086 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
3087 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
3089 if (TREE_CODE (argument
) == TYPE_DECL
)
3090 error ("invalid use of type %qT as a default value for a template "
3091 "template-parameter", TREE_TYPE (argument
));
3093 error ("invalid default argument for a template template parameter");
3094 return error_mark_node
;
3100 /* Begin a class definition, as indicated by T. */
3103 begin_class_definition (tree t
)
3105 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
3106 return error_mark_node
;
3108 if (processing_template_parmlist
&& !LAMBDA_TYPE_P (t
))
3110 error ("definition of %q#T inside template parameter list", t
);
3111 return error_mark_node
;
3114 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
3115 are passed the same as decimal scalar types. */
3116 if (TREE_CODE (t
) == RECORD_TYPE
3117 && !processing_template_decl
)
3119 tree ns
= TYPE_CONTEXT (t
);
3120 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
3121 && DECL_CONTEXT (ns
) == std_node
3123 && id_equal (DECL_NAME (ns
), "decimal"))
3125 const char *n
= TYPE_NAME_STRING (t
);
3126 if ((strcmp (n
, "decimal32") == 0)
3127 || (strcmp (n
, "decimal64") == 0)
3128 || (strcmp (n
, "decimal128") == 0))
3129 TYPE_TRANSPARENT_AGGR (t
) = 1;
3133 /* A non-implicit typename comes from code like:
3135 template <typename T> struct A {
3136 template <typename U> struct A<T>::B ...
3138 This is erroneous. */
3139 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
3141 error ("invalid definition of qualified type %qT", t
);
3142 t
= error_mark_node
;
3145 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
3147 t
= make_class_type (RECORD_TYPE
);
3148 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
3151 if (TYPE_BEING_DEFINED (t
))
3153 t
= make_class_type (TREE_CODE (t
));
3154 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
3156 maybe_process_partial_specialization (t
);
3158 TYPE_BEING_DEFINED (t
) = 1;
3159 class_binding_level
->defining_class_p
= 1;
3161 if (flag_pack_struct
)
3164 TYPE_PACKED (t
) = 1;
3165 /* Even though the type is being defined for the first time
3166 here, there might have been a forward declaration, so there
3167 might be cv-qualified variants of T. */
3168 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
3169 TYPE_PACKED (v
) = 1;
3171 /* Reset the interface data, at the earliest possible
3172 moment, as it might have been set via a class foo;
3174 if (! TYPE_UNNAMED_P (t
))
3176 struct c_fileinfo
*finfo
= \
3177 get_fileinfo (LOCATION_FILE (input_location
));
3178 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
3179 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
3180 (t
, finfo
->interface_unknown
);
3182 reset_specialization();
3184 /* Make a declaration for this class in its own scope. */
3185 build_self_reference ();
3190 /* Finish the member declaration given by DECL. */
3193 finish_member_declaration (tree decl
)
3195 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
3198 if (decl
== void_type_node
)
3199 /* The COMPONENT was a friend, not a member, and so there's
3200 nothing for us to do. */
3203 /* We should see only one DECL at a time. */
3204 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
3206 /* Don't add decls after definition. */
3207 gcc_assert (TYPE_BEING_DEFINED (current_class_type
)
3208 /* We can add lambda types when late parsing default
3210 || LAMBDA_TYPE_P (TREE_TYPE (decl
)));
3212 /* Set up access control for DECL. */
3214 = (current_access_specifier
== access_private_node
);
3215 TREE_PROTECTED (decl
)
3216 = (current_access_specifier
== access_protected_node
);
3217 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3219 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
3220 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
3223 /* Mark the DECL as a member of the current class, unless it's
3224 a member of an enumeration. */
3225 if (TREE_CODE (decl
) != CONST_DECL
)
3226 DECL_CONTEXT (decl
) = current_class_type
;
3228 if (TREE_CODE (decl
) == USING_DECL
)
3229 /* For now, ignore class-scope USING_DECLS, so that debugging
3230 backends do not see them. */
3231 DECL_IGNORED_P (decl
) = 1;
3233 /* Check for bare parameter packs in the non-static data member
3235 if (TREE_CODE (decl
) == FIELD_DECL
)
3237 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
3238 TREE_TYPE (decl
) = error_mark_node
;
3239 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3240 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3245 A C language linkage is ignored for the names of class members
3246 and the member function type of class member functions. */
3247 if (DECL_LANG_SPECIFIC (decl
))
3248 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3252 /* Functions and non-functions are added differently. */
3253 if (DECL_DECLARES_FUNCTION_P (decl
))
3254 add
= add_method (current_class_type
, decl
, false);
3255 /* Enter the DECL into the scope of the class, if the class
3256 isn't a closure (whose fields are supposed to be unnamed). */
3257 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3258 || pushdecl_class_level (decl
))
3263 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3264 go at the beginning. The reason is that
3265 legacy_nonfn_member_lookup searches the list in order, and we
3266 want a field name to override a type name so that the "struct
3267 stat hack" will work. In particular:
3269 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3273 if (TREE_CODE (decl
) == TYPE_DECL
)
3274 TYPE_FIELDS (current_class_type
)
3275 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3278 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3279 TYPE_FIELDS (current_class_type
) = decl
;
3282 maybe_add_class_template_decl_list (current_class_type
, decl
,
3287 /* Finish processing a complete template declaration. The PARMS are
3288 the template parameters. */
3291 finish_template_decl (tree parms
)
3294 end_template_decl ();
3296 end_specialization ();
3299 // Returns the template type of the class scope being entered. If we're
3300 // entering a constrained class scope. TYPE is the class template
3301 // scope being entered and we may need to match the intended type with
3302 // a constrained specialization. For example:
3304 // template<Object T>
3305 // struct S { void f(); }; #1
3307 // template<Object T>
3308 // void S<T>::f() { } #2
3310 // We check, in #2, that S<T> refers precisely to the type declared by
3311 // #1 (i.e., that the constraints match). Note that the following should
3312 // be an error since there is no specialization of S<T> that is
3313 // unconstrained, but this is not diagnosed here.
3315 // template<typename T>
3316 // void S<T>::f() { }
3318 // We cannot diagnose this problem here since this function also matches
3319 // qualified template names that are not part of a definition. For example:
3321 // template<Integral T, Floating_point U>
3322 // typename pair<T, U>::first_type void f(T, U);
3324 // Here, it is unlikely that there is a partial specialization of
3325 // pair constrained for for Integral and Floating_point arguments.
3327 // The general rule is: if a constrained specialization with matching
3328 // constraints is found return that type. Also note that if TYPE is not a
3329 // class-type (e.g. a typename type), then no fixup is needed.
3332 fixup_template_type (tree type
)
3334 // Find the template parameter list at the a depth appropriate to
3335 // the scope we're trying to enter.
3336 tree parms
= current_template_parms
;
3337 int depth
= template_class_depth (type
);
3338 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3339 parms
= TREE_CHAIN (parms
);
3342 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3343 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3345 // Search for a specialization whose type and constraints match.
3346 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3347 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3350 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3352 // If the type and constraints match a specialization, then we
3353 // are entering that type.
3354 if (same_type_p (type
, TREE_TYPE (specs
))
3355 && equivalent_constraints (cur_constr
, spec_constr
))
3356 return TREE_TYPE (specs
);
3357 specs
= TREE_CHAIN (specs
);
3360 // If no specialization matches, then must return the type
3361 // previously found.
3365 /* Finish processing a template-id (which names a type) of the form
3366 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3367 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3368 the scope of template-id indicated. */
3371 finish_template_type (tree name
, tree args
, int entering_scope
)
3375 type
= lookup_template_class (name
, args
,
3376 NULL_TREE
, NULL_TREE
, entering_scope
,
3377 tf_warning_or_error
| tf_user
);
3379 /* If we might be entering the scope of a partial specialization,
3380 find the one with the right constraints. */
3383 && CLASS_TYPE_P (type
)
3384 && CLASSTYPE_TEMPLATE_INFO (type
)
3385 && dependent_type_p (type
)
3386 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3387 type
= fixup_template_type (type
);
3389 if (type
== error_mark_node
)
3391 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3392 return TYPE_STUB_DECL (type
);
3394 return TYPE_NAME (type
);
3397 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3398 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3399 BASE_CLASS, or NULL_TREE if an error occurred. The
3400 ACCESS_SPECIFIER is one of
3401 access_{default,public,protected_private}_node. For a virtual base
3402 we set TREE_TYPE. */
3405 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3409 if (base
== error_mark_node
)
3411 error ("invalid base-class specification");
3414 else if (! MAYBE_CLASS_TYPE_P (base
))
3416 error ("%qT is not a class type", base
);
3421 if (cp_type_quals (base
) != 0)
3423 /* DR 484: Can a base-specifier name a cv-qualified
3425 base
= TYPE_MAIN_VARIANT (base
);
3427 result
= build_tree_list (access
, base
);
3429 TREE_TYPE (result
) = integer_type_node
;
3435 /* If FNS is a member function, a set of member functions, or a
3436 template-id referring to one or more member functions, return a
3437 BASELINK for FNS, incorporating the current access context.
3438 Otherwise, return FNS unchanged. */
3441 baselink_for_fns (tree fns
)
3446 if (BASELINK_P (fns
)
3447 || error_operand_p (fns
))
3450 scope
= ovl_scope (fns
);
3451 if (!CLASS_TYPE_P (scope
))
3454 cl
= currently_open_derived_class (scope
);
3457 cl
= TYPE_BINFO (cl
);
3458 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3461 /* Returns true iff DECL is a variable from a function outside
3465 outer_var_p (tree decl
)
3467 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3468 && DECL_FUNCTION_SCOPE_P (decl
)
3469 /* Don't get confused by temporaries. */
3471 && (DECL_CONTEXT (decl
) != current_function_decl
3472 || parsing_nsdmi ()));
3475 /* As above, but also checks that DECL is automatic. */
3478 outer_automatic_var_p (tree decl
)
3480 return (outer_var_p (decl
)
3481 && !TREE_STATIC (decl
));
3484 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3485 rewrite it for lambda capture.
3487 If ODR_USE is true, we're being called from mark_use, and we complain about
3488 use of constant variables. If ODR_USE is false, we're being called for the
3489 id-expression, and we do lambda capture. */
3492 process_outer_var_ref (tree decl
, tsubst_flags_t complain
, bool odr_use
)
3494 if (cp_unevaluated_operand
)
3495 /* It's not a use (3.2) if we're in an unevaluated context. */
3497 if (decl
== error_mark_node
)
3500 tree context
= DECL_CONTEXT (decl
);
3501 tree containing_function
= current_function_decl
;
3502 tree lambda_stack
= NULL_TREE
;
3503 tree lambda_expr
= NULL_TREE
;
3504 tree initializer
= convert_from_reference (decl
);
3506 /* Mark it as used now even if the use is ill-formed. */
3507 if (!mark_used (decl
, complain
))
3508 return error_mark_node
;
3510 if (parsing_nsdmi ())
3511 containing_function
= NULL_TREE
;
3513 if (containing_function
&& LAMBDA_FUNCTION_P (containing_function
))
3515 /* Check whether we've already built a proxy. */
3517 while (is_normal_capture_proxy (var
))
3518 var
= DECL_CAPTURED_VARIABLE (var
);
3519 tree d
= retrieve_local_specialization (var
);
3521 if (d
&& d
!= decl
&& is_capture_proxy (d
))
3523 if (DECL_CONTEXT (d
) == containing_function
)
3524 /* We already have an inner proxy. */
3527 /* We need to capture an outer proxy. */
3528 return process_outer_var_ref (d
, complain
, odr_use
);
3532 /* If we are in a lambda function, we can move out until we hit
3534 2. a non-lambda function, or
3535 3. a non-default capturing lambda function. */
3536 while (context
!= containing_function
3537 /* containing_function can be null with invalid generic lambdas. */
3538 && containing_function
3539 && LAMBDA_FUNCTION_P (containing_function
))
3541 tree closure
= DECL_CONTEXT (containing_function
);
3542 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3544 if (TYPE_CLASS_SCOPE_P (closure
))
3545 /* A lambda in an NSDMI (c++/64496). */
3548 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3551 lambda_stack
= tree_cons (NULL_TREE
, lambda_expr
, lambda_stack
);
3553 containing_function
= decl_function_context (containing_function
);
3556 /* In a lambda within a template, wait until instantiation time to implicitly
3557 capture a parameter pack. We want to wait because we don't know if we're
3558 capturing the whole pack or a single element, and it's OK to wait because
3559 find_parameter_packs_r walks into the lambda body. */
3560 if (context
== containing_function
3561 && DECL_PACK_P (decl
))
3564 if (lambda_expr
&& VAR_P (decl
) && DECL_ANON_UNION_VAR_P (decl
))
3566 if (complain
& tf_error
)
3567 error ("cannot capture member %qD of anonymous union", decl
);
3568 return error_mark_node
;
3570 /* Do lambda capture when processing the id-expression, not when
3571 odr-using a variable. */
3572 if (!odr_use
&& context
== containing_function
)
3573 decl
= add_default_capture (lambda_stack
,
3574 /*id=*/DECL_NAME (decl
), initializer
);
3575 /* Only an odr-use of an outer automatic variable causes an
3576 error, and a constant variable can decay to a prvalue
3577 constant without odr-use. So don't complain yet. */
3578 else if (!odr_use
&& decl_constant_var_p (decl
))
3580 else if (lambda_expr
)
3582 if (complain
& tf_error
)
3584 error ("%qD is not captured", decl
);
3585 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3586 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3587 inform (location_of (closure
),
3588 "the lambda has no capture-default");
3589 else if (TYPE_CLASS_SCOPE_P (closure
))
3590 inform (UNKNOWN_LOCATION
, "lambda in local class %q+T cannot "
3591 "capture variables from the enclosing context",
3592 TYPE_CONTEXT (closure
));
3593 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3595 return error_mark_node
;
3599 if (complain
& tf_error
)
3602 ? G_("use of local variable with automatic storage from "
3603 "containing function")
3604 : G_("use of parameter from containing function"));
3605 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3607 return error_mark_node
;
3612 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3613 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3614 if non-NULL, is the type or namespace used to explicitly qualify
3615 ID_EXPRESSION. DECL is the entity to which that name has been
3618 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3619 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3620 be set to true if this expression isn't permitted in a
3621 constant-expression, but it is otherwise not set by this function.
3622 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3623 constant-expression, but a non-constant expression is also
3626 DONE is true if this expression is a complete postfix-expression;
3627 it is false if this expression is followed by '->', '[', '(', etc.
3628 ADDRESS_P is true iff this expression is the operand of '&'.
3629 TEMPLATE_P is true iff the qualified-id was of the form
3630 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3631 appears as a template argument.
3633 If an error occurs, and it is the kind of error that might cause
3634 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3635 is the caller's responsibility to issue the message. *ERROR_MSG
3636 will be a string with static storage duration, so the caller need
3639 Return an expression for the entity, after issuing appropriate
3640 diagnostics. This function is also responsible for transforming a
3641 reference to a non-static member into a COMPONENT_REF that makes
3642 the use of "this" explicit.
3644 Upon return, *IDK will be filled in appropriately. */
3646 finish_id_expression_1 (tree id_expression
,
3650 bool integral_constant_expression_p
,
3651 bool allow_non_integral_constant_expression_p
,
3652 bool *non_integral_constant_expression_p
,
3656 bool template_arg_p
,
3657 const char **error_msg
,
3658 location_t location
)
3660 decl
= strip_using_decl (decl
);
3662 /* Initialize the output parameters. */
3663 *idk
= CP_ID_KIND_NONE
;
3666 if (id_expression
== error_mark_node
)
3667 return error_mark_node
;
3668 /* If we have a template-id, then no further lookup is
3669 required. If the template-id was for a template-class, we
3670 will sometimes have a TYPE_DECL at this point. */
3671 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3672 || TREE_CODE (decl
) == TYPE_DECL
)
3674 /* Look up the name. */
3677 if (decl
== error_mark_node
)
3679 /* Name lookup failed. */
3682 || (!dependent_type_p (scope
)
3683 && !(identifier_p (id_expression
)
3684 && IDENTIFIER_CONV_OP_P (id_expression
)
3685 && dependent_type_p (TREE_TYPE (id_expression
))))))
3687 /* If the qualifying type is non-dependent (and the name
3688 does not name a conversion operator to a dependent
3689 type), issue an error. */
3690 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3691 return error_mark_node
;
3695 /* It may be resolved via Koenig lookup. */
3696 *idk
= CP_ID_KIND_UNQUALIFIED
;
3697 return id_expression
;
3700 decl
= id_expression
;
3703 /* Remember that the name was used in the definition of
3704 the current class so that we can check later to see if
3705 the meaning would have been different after the class
3706 was entirely defined. */
3707 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3708 maybe_note_name_used_in_class (id_expression
, decl
);
3710 /* A use in unevaluated operand might not be instantiated appropriately
3711 if tsubst_copy builds a dummy parm, or if we never instantiate a
3712 generic lambda, so mark it now. */
3713 if (processing_template_decl
&& cp_unevaluated_operand
)
3714 mark_type_use (decl
);
3716 /* Disallow uses of local variables from containing functions, except
3717 within lambda-expressions. */
3718 if (outer_automatic_var_p (decl
))
3720 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3721 if (decl
== error_mark_node
)
3722 return error_mark_node
;
3725 /* Also disallow uses of function parameters outside the function
3726 body, except inside an unevaluated context (i.e. decltype). */
3727 if (TREE_CODE (decl
) == PARM_DECL
3728 && DECL_CONTEXT (decl
) == NULL_TREE
3729 && !cp_unevaluated_operand
)
3731 *error_msg
= G_("use of parameter outside function body");
3732 return error_mark_node
;
3736 /* If we didn't find anything, or what we found was a type,
3737 then this wasn't really an id-expression. */
3738 if (TREE_CODE (decl
) == TEMPLATE_DECL
3739 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3741 *error_msg
= G_("missing template arguments");
3742 return error_mark_node
;
3744 else if (TREE_CODE (decl
) == TYPE_DECL
3745 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3747 *error_msg
= G_("expected primary-expression");
3748 return error_mark_node
;
3751 /* If the name resolved to a template parameter, there is no
3752 need to look it up again later. */
3753 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3754 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3758 *idk
= CP_ID_KIND_NONE
;
3759 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3760 decl
= TEMPLATE_PARM_DECL (decl
);
3761 r
= DECL_INITIAL (decl
);
3762 if (CLASS_TYPE_P (TREE_TYPE (r
)) && !CP_TYPE_CONST_P (TREE_TYPE (r
)))
3764 /* If the entity is a template parameter object for a template
3765 parameter of type T, the type of the expression is const T. */
3766 tree ctype
= TREE_TYPE (r
);
3767 ctype
= cp_build_qualified_type (ctype
, (cp_type_quals (ctype
)
3768 | TYPE_QUAL_CONST
));
3769 r
= build1 (VIEW_CONVERT_EXPR
, ctype
, r
);
3771 r
= convert_from_reference (r
);
3772 if (integral_constant_expression_p
3773 && !dependent_type_p (TREE_TYPE (decl
))
3774 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3776 if (!allow_non_integral_constant_expression_p
)
3777 error ("template parameter %qD of type %qT is not allowed in "
3778 "an integral constant expression because it is not of "
3779 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3780 *non_integral_constant_expression_p
= true;
3786 bool dependent_p
= type_dependent_expression_p (decl
);
3788 /* If the declaration was explicitly qualified indicate
3789 that. The semantics of `A::f(3)' are different than
3790 `f(3)' if `f' is virtual. */
3792 ? CP_ID_KIND_QUALIFIED
3793 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3794 ? CP_ID_KIND_TEMPLATE_ID
3796 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3797 : CP_ID_KIND_UNQUALIFIED
)));
3801 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
3802 /* Dependent type attributes on the decl mean that the TREE_TYPE is
3803 wrong, so just return the identifier. */
3804 return id_expression
;
3806 if (DECL_CLASS_TEMPLATE_P (decl
))
3808 error ("use of class template %qT as expression", decl
);
3809 return error_mark_node
;
3812 if (TREE_CODE (decl
) == TREE_LIST
)
3814 /* Ambiguous reference to base members. */
3815 error ("request for member %qD is ambiguous in "
3816 "multiple inheritance lattice", id_expression
);
3817 print_candidates (decl
);
3818 return error_mark_node
;
3821 /* Mark variable-like entities as used. Functions are similarly
3822 marked either below or after overload resolution. */
3824 || TREE_CODE (decl
) == PARM_DECL
3825 || TREE_CODE (decl
) == CONST_DECL
3826 || TREE_CODE (decl
) == RESULT_DECL
)
3827 && !mark_used (decl
))
3828 return error_mark_node
;
3830 /* Only certain kinds of names are allowed in constant
3831 expression. Template parameters have already
3832 been handled above. */
3833 if (! error_operand_p (decl
)
3835 && integral_constant_expression_p
3836 && ! decl_constant_var_p (decl
)
3837 && TREE_CODE (decl
) != CONST_DECL
3838 && ! builtin_valid_in_constant_expr_p (decl
))
3840 if (!allow_non_integral_constant_expression_p
)
3842 error ("%qD cannot appear in a constant-expression", decl
);
3843 return error_mark_node
;
3845 *non_integral_constant_expression_p
= true;
3848 if (tree wrap
= maybe_get_tls_wrapper_call (decl
))
3849 /* Replace an evaluated use of the thread_local variable with
3850 a call to its wrapper. */
3852 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3854 && variable_template_p (TREE_OPERAND (decl
, 0)))
3856 decl
= finish_template_variable (decl
);
3858 decl
= convert_from_reference (decl
);
3862 if (TREE_CODE (decl
) == SCOPE_REF
)
3864 gcc_assert (same_type_p (scope
, TREE_OPERAND (decl
, 0)));
3865 decl
= TREE_OPERAND (decl
, 1);
3868 decl
= (adjust_result_of_qualified_name_lookup
3869 (decl
, scope
, current_nonlambda_class_type()));
3871 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3874 cp_warn_deprecated_use_scopes (scope
);
3877 decl
= finish_qualified_id_expr (scope
,
3883 tf_warning_or_error
);
3885 decl
= convert_from_reference (decl
);
3887 else if (TREE_CODE (decl
) == FIELD_DECL
)
3889 /* Since SCOPE is NULL here, this is an unqualified name.
3890 Access checking has been performed during name lookup
3891 already. Turn off checking to avoid duplicate errors. */
3892 push_deferring_access_checks (dk_no_check
);
3893 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3894 /*qualifying_scope=*/NULL_TREE
);
3895 pop_deferring_access_checks ();
3897 else if (is_overloaded_fn (decl
))
3899 /* We only need to look at the first function,
3900 because all the fns share the attribute we're
3901 concerned with (all member fns or all non-members). */
3902 tree first_fn
= get_first_fn (decl
);
3903 first_fn
= STRIP_TEMPLATE (first_fn
);
3905 /* [basic.def.odr]: "A function whose name appears as a
3906 potentially-evaluated expression is odr-used if it is the unique
3909 But only mark it if it's a complete postfix-expression; in a call,
3910 ADL might select a different function, and we'll call mark_used in
3913 && !really_overloaded_fn (decl
)
3914 && !mark_used (first_fn
))
3915 return error_mark_node
;
3918 && (TREE_CODE (first_fn
) == USING_DECL
3919 || (TREE_CODE (first_fn
) == FUNCTION_DECL
3920 && DECL_FUNCTION_MEMBER_P (first_fn
)
3921 && !shared_member_p (decl
))))
3923 /* A set of member functions. */
3924 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
3925 return finish_class_member_access_expr (decl
, id_expression
,
3926 /*template_p=*/false,
3927 tf_warning_or_error
);
3930 decl
= baselink_for_fns (decl
);
3934 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
3935 && DECL_CLASS_SCOPE_P (decl
))
3937 tree context
= context_for_name_lookup (decl
);
3938 if (context
!= current_class_type
)
3940 tree path
= currently_open_derived_class (context
);
3941 perform_or_defer_access_check (TYPE_BINFO (path
),
3943 tf_warning_or_error
);
3947 decl
= convert_from_reference (decl
);
3951 return cp_expr (decl
, location
);
3954 /* As per finish_id_expression_1, but adding a wrapper node
3955 around the result if needed to express LOCATION. */
3958 finish_id_expression (tree id_expression
,
3962 bool integral_constant_expression_p
,
3963 bool allow_non_integral_constant_expression_p
,
3964 bool *non_integral_constant_expression_p
,
3968 bool template_arg_p
,
3969 const char **error_msg
,
3970 location_t location
)
3973 = finish_id_expression_1 (id_expression
, decl
, scope
, idk
,
3974 integral_constant_expression_p
,
3975 allow_non_integral_constant_expression_p
,
3976 non_integral_constant_expression_p
,
3977 template_p
, done
, address_p
, template_arg_p
,
3978 error_msg
, location
);
3979 return result
.maybe_add_location_wrapper ();
3982 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3983 use as a type-specifier. */
3986 finish_typeof (tree expr
)
3990 if (type_dependent_expression_p (expr
))
3992 type
= cxx_make_type (TYPEOF_TYPE
);
3993 TYPEOF_TYPE_EXPR (type
) = expr
;
3994 SET_TYPE_STRUCTURAL_EQUALITY (type
);
3999 expr
= mark_type_use (expr
);
4001 type
= unlowered_expr_type (expr
);
4003 if (!type
|| type
== unknown_type_node
)
4005 error ("type of %qE is unknown", expr
);
4006 return error_mark_node
;
4012 /* Implement the __underlying_type keyword: Return the underlying
4013 type of TYPE, suitable for use as a type-specifier. */
4016 finish_underlying_type (tree type
)
4018 tree underlying_type
;
4020 if (processing_template_decl
)
4022 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
4023 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
4024 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
4026 return underlying_type
;
4029 if (!complete_type_or_else (type
, NULL_TREE
))
4030 return error_mark_node
;
4032 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
4034 error ("%qT is not an enumeration type", type
);
4035 return error_mark_node
;
4038 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
4040 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
4041 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
4042 See finish_enum_value_list for details. */
4043 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
4045 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
4046 TYPE_UNSIGNED (underlying_type
));
4048 return underlying_type
;
4051 /* Implement the __direct_bases keyword: Return the direct base classes
4055 calculate_direct_bases (tree type
, tsubst_flags_t complain
)
4057 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4058 || !NON_UNION_CLASS_TYPE_P (type
))
4059 return make_tree_vec (0);
4061 releasing_vec vector
;
4062 vec
<tree
, va_gc
> *base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
4066 /* Virtual bases are initialized first */
4067 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4068 if (BINFO_VIRTUAL_P (binfo
))
4069 vec_safe_push (vector
, binfo
);
4071 /* Now non-virtuals */
4072 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4073 if (!BINFO_VIRTUAL_P (binfo
))
4074 vec_safe_push (vector
, binfo
);
4076 tree bases_vec
= make_tree_vec (vector
->length ());
4078 for (i
= 0; i
< vector
->length (); ++i
)
4079 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
4084 /* Implement the __bases keyword: Return the base classes
4087 /* Find morally non-virtual base classes by walking binfo hierarchy */
4088 /* Virtual base classes are handled separately in finish_bases */
4091 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
4093 /* Don't walk bases of virtual bases */
4094 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
4098 dfs_calculate_bases_post (tree binfo
, void *data_
)
4100 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
4101 if (!BINFO_VIRTUAL_P (binfo
))
4102 vec_safe_push (*data
, BINFO_TYPE (binfo
));
4106 /* Calculates the morally non-virtual base classes of a class */
4107 static vec
<tree
, va_gc
> *
4108 calculate_bases_helper (tree type
)
4110 vec
<tree
, va_gc
> *vector
= make_tree_vector ();
4112 /* Now add non-virtual base classes in order of construction */
4113 if (TYPE_BINFO (type
))
4114 dfs_walk_all (TYPE_BINFO (type
),
4115 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
4120 calculate_bases (tree type
, tsubst_flags_t complain
)
4122 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4123 || !NON_UNION_CLASS_TYPE_P (type
))
4124 return make_tree_vec (0);
4126 releasing_vec vector
;
4127 tree bases_vec
= NULL_TREE
;
4129 vec
<tree
, va_gc
> *vbases
;
4132 /* First go through virtual base classes */
4133 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
4134 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
4136 releasing_vec vbase_bases
4137 = calculate_bases_helper (BINFO_TYPE (binfo
));
4138 vec_safe_splice (vector
, vbase_bases
);
4141 /* Now for the non-virtual bases */
4142 releasing_vec nonvbases
= calculate_bases_helper (type
);
4143 vec_safe_splice (vector
, nonvbases
);
4145 /* Note that during error recovery vector->length can even be zero. */
4146 if (vector
->length () > 1)
4148 /* Last element is entire class, so don't copy */
4149 bases_vec
= make_tree_vec (vector
->length () - 1);
4151 for (i
= 0; i
< vector
->length () - 1; ++i
)
4152 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
4155 bases_vec
= make_tree_vec (0);
4161 finish_bases (tree type
, bool direct
)
4163 tree bases
= NULL_TREE
;
4165 if (!processing_template_decl
)
4167 /* Parameter packs can only be used in templates */
4168 error ("parameter pack %<__bases%> only valid in template declaration");
4169 return error_mark_node
;
4172 bases
= cxx_make_type (BASES
);
4173 BASES_TYPE (bases
) = type
;
4174 BASES_DIRECT (bases
) = direct
;
4175 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
4180 /* Perform C++-specific checks for __builtin_offsetof before calling
4184 finish_offsetof (tree object_ptr
, tree expr
, location_t loc
)
4186 /* If we're processing a template, we can't finish the semantics yet.
4187 Otherwise we can fold the entire expression now. */
4188 if (processing_template_decl
)
4190 expr
= build2 (OFFSETOF_EXPR
, size_type_node
, expr
, object_ptr
);
4191 SET_EXPR_LOCATION (expr
, loc
);
4195 if (expr
== error_mark_node
)
4196 return error_mark_node
;
4198 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4200 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4201 TREE_OPERAND (expr
, 2));
4202 return error_mark_node
;
4204 if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr
))
4205 || TREE_TYPE (expr
) == unknown_type_node
)
4207 while (TREE_CODE (expr
) == COMPONENT_REF
4208 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4209 expr
= TREE_OPERAND (expr
, 1);
4213 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4214 inform (DECL_SOURCE_LOCATION (expr
), "declared here");
4217 error ("cannot apply %<offsetof%> to member function");
4218 return error_mark_node
;
4220 if (TREE_CODE (expr
) == CONST_DECL
)
4222 error ("cannot apply %<offsetof%> to an enumerator %qD", expr
);
4223 return error_mark_node
;
4225 if (REFERENCE_REF_P (expr
))
4226 expr
= TREE_OPERAND (expr
, 0);
4227 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr
)), object_ptr
))
4228 return error_mark_node
;
4229 if (warn_invalid_offsetof
4230 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr
)))
4231 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr
)))
4232 && cp_unevaluated_operand
== 0)
4233 warning_at (loc
, OPT_Winvalid_offsetof
, "%<offsetof%> within "
4234 "non-standard-layout type %qT is conditionally-supported",
4235 TREE_TYPE (TREE_TYPE (object_ptr
)));
4236 return fold_offsetof (expr
);
4239 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4240 function is broken out from the above for the benefit of the tree-ssa
4244 simplify_aggr_init_expr (tree
*tp
)
4246 tree aggr_init_expr
= *tp
;
4248 /* Form an appropriate CALL_EXPR. */
4249 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4250 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4251 tree type
= TREE_TYPE (slot
);
4254 enum style_t
{ ctor
, arg
, pcc
} style
;
4256 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4258 #ifdef PCC_STATIC_STRUCT_RETURN
4264 gcc_assert (TREE_ADDRESSABLE (type
));
4268 call_expr
= build_call_array_loc (input_location
,
4269 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4271 aggr_init_expr_nargs (aggr_init_expr
),
4272 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4273 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4274 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4275 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4276 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4277 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4278 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4282 /* Replace the first argument to the ctor with the address of the
4284 cxx_mark_addressable (slot
);
4285 CALL_EXPR_ARG (call_expr
, 0) =
4286 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4288 else if (style
== arg
)
4290 /* Just mark it addressable here, and leave the rest to
4291 expand_call{,_inline}. */
4292 cxx_mark_addressable (slot
);
4293 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4294 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4296 else if (style
== pcc
)
4298 /* If we're using the non-reentrant PCC calling convention, then we
4299 need to copy the returned value out of the static buffer into the
4301 push_deferring_access_checks (dk_no_check
);
4302 call_expr
= build_aggr_init (slot
, call_expr
,
4303 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4304 tf_warning_or_error
);
4305 pop_deferring_access_checks ();
4306 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4309 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4311 tree init
= build_zero_init (type
, NULL_TREE
,
4312 /*static_storage_p=*/false);
4313 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4314 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4321 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4324 emit_associated_thunks (tree fn
)
4326 /* When we use vcall offsets, we emit thunks with the virtual
4327 functions to which they thunk. The whole point of vcall offsets
4328 is so that you can know statically the entire set of thunks that
4329 will ever be needed for a given virtual function, thereby
4330 enabling you to output all the thunks with the function itself. */
4331 if (DECL_VIRTUAL_P (fn
)
4332 /* Do not emit thunks for extern template instantiations. */
4333 && ! DECL_REALLY_EXTERN (fn
))
4337 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4339 if (!THUNK_ALIAS (thunk
))
4341 use_thunk (thunk
, /*emit_p=*/1);
4342 if (DECL_RESULT_THUNK_P (thunk
))
4346 for (probe
= DECL_THUNKS (thunk
);
4347 probe
; probe
= DECL_CHAIN (probe
))
4348 use_thunk (probe
, /*emit_p=*/1);
4352 gcc_assert (!DECL_THUNKS (thunk
));
4357 /* Generate RTL for FN. */
4360 expand_or_defer_fn_1 (tree fn
)
4362 /* When the parser calls us after finishing the body of a template
4363 function, we don't really want to expand the body. */
4364 if (processing_template_decl
)
4366 /* Normally, collection only occurs in rest_of_compilation. So,
4367 if we don't collect here, we never collect junk generated
4368 during the processing of templates until we hit a
4369 non-template function. It's not safe to do this inside a
4370 nested class, though, as the parser may have local state that
4371 is not a GC root. */
4372 if (!function_depth
)
4377 gcc_assert (DECL_SAVED_TREE (fn
));
4379 /* We make a decision about linkage for these functions at the end
4380 of the compilation. Until that point, we do not want the back
4381 end to output them -- but we do want it to see the bodies of
4382 these functions so that it can inline them as appropriate. */
4383 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4385 if (DECL_INTERFACE_KNOWN (fn
))
4386 /* We've already made a decision as to how this function will
4389 tentative_decl_linkage (fn
);
4391 import_export_decl (fn
);
4393 /* If the user wants us to keep all inline functions, then mark
4394 this function as needed so that finish_file will make sure to
4395 output it later. Similarly, all dllexport'd functions must
4396 be emitted; there may be callers in other DLLs. */
4397 if (DECL_DECLARED_INLINE_P (fn
)
4398 && !DECL_REALLY_EXTERN (fn
)
4399 && (flag_keep_inline_functions
4400 || (flag_keep_inline_dllexport
4401 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4404 DECL_EXTERNAL (fn
) = 0;
4408 /* If this is a constructor or destructor body, we have to clone
4410 if (maybe_clone_body (fn
))
4412 /* We don't want to process FN again, so pretend we've written
4413 it out, even though we haven't. */
4414 TREE_ASM_WRITTEN (fn
) = 1;
4415 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4416 if (!DECL_DECLARED_CONSTEXPR_P (fn
))
4417 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4421 /* There's no reason to do any of the work here if we're only doing
4422 semantic analysis; this code just generates RTL. */
4423 if (flag_syntax_only
)
4425 /* Pretend that this function has been written out so that we don't try
4426 to expand it again. */
4427 TREE_ASM_WRITTEN (fn
) = 1;
4435 expand_or_defer_fn (tree fn
)
4437 if (expand_or_defer_fn_1 (fn
))
4441 /* Expand or defer, at the whim of the compilation unit manager. */
4442 cgraph_node::finalize_function (fn
, function_depth
> 1);
4443 emit_associated_thunks (fn
);
4452 nrv_data () : visited (37) {}
4456 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4459 /* Helper function for walk_tree, used by finalize_nrv below. */
4462 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4464 class nrv_data
*dp
= (class nrv_data
*)data
;
4467 /* No need to walk into types. There wouldn't be any need to walk into
4468 non-statements, except that we have to consider STMT_EXPRs. */
4471 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4472 but differs from using NULL_TREE in that it indicates that we care
4473 about the value of the RESULT_DECL. */
4474 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4475 TREE_OPERAND (*tp
, 0) = dp
->result
;
4476 /* Change all cleanups for the NRV to only run when an exception is
4478 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4479 && CLEANUP_DECL (*tp
) == dp
->var
)
4480 CLEANUP_EH_ONLY (*tp
) = 1;
4481 /* Replace the DECL_EXPR for the NRV with an initialization of the
4482 RESULT_DECL, if needed. */
4483 else if (TREE_CODE (*tp
) == DECL_EXPR
4484 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4487 if (DECL_INITIAL (dp
->var
)
4488 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4489 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4490 DECL_INITIAL (dp
->var
));
4492 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4493 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4494 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4497 /* And replace all uses of the NRV with the RESULT_DECL. */
4498 else if (*tp
== dp
->var
)
4501 /* Avoid walking into the same tree more than once. Unfortunately, we
4502 can't just use walk_tree_without duplicates because it would only call
4503 us for the first occurrence of dp->var in the function body. */
4504 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4510 /* Keep iterating. */
4514 /* Called from finish_function to implement the named return value
4515 optimization by overriding all the RETURN_EXPRs and pertinent
4516 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4517 RESULT_DECL for the function. */
4520 finalize_nrv (tree
*tp
, tree var
, tree result
)
4522 class nrv_data data
;
4524 /* Copy name from VAR to RESULT. */
4525 DECL_NAME (result
) = DECL_NAME (var
);
4526 /* Don't forget that we take its address. */
4527 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4528 /* Finally set DECL_VALUE_EXPR to avoid assigning
4529 a stack slot at -O0 for the original var and debug info
4530 uses RESULT location for VAR. */
4531 SET_DECL_VALUE_EXPR (var
, result
);
4532 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4535 data
.result
= result
;
4536 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4539 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4542 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4543 bool need_copy_ctor
, bool need_copy_assignment
,
4546 int save_errorcount
= errorcount
;
4549 /* Always allocate 3 elements for simplicity. These are the
4550 function decls for the ctor, dtor, and assignment op.
4551 This layout is known to the three lang hooks,
4552 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4553 and cxx_omp_clause_assign_op. */
4554 info
= make_tree_vec (3);
4555 CP_OMP_CLAUSE_INFO (c
) = info
;
4557 if (need_default_ctor
|| need_copy_ctor
)
4559 if (need_default_ctor
)
4560 t
= get_default_ctor (type
);
4562 t
= get_copy_ctor (type
, tf_warning_or_error
);
4564 if (t
&& !trivial_fn_p (t
))
4565 TREE_VEC_ELT (info
, 0) = t
;
4568 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4569 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4571 if (need_copy_assignment
)
4573 t
= get_copy_assign (type
);
4575 if (t
&& !trivial_fn_p (t
))
4576 TREE_VEC_ELT (info
, 2) = t
;
4579 return errorcount
!= save_errorcount
;
4582 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4583 FIELD_DECL, otherwise return DECL itself. */
4586 omp_clause_decl_field (tree decl
)
4589 && DECL_HAS_VALUE_EXPR_P (decl
)
4590 && DECL_ARTIFICIAL (decl
)
4591 && DECL_LANG_SPECIFIC (decl
)
4592 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4594 tree f
= DECL_VALUE_EXPR (decl
);
4595 if (INDIRECT_REF_P (f
))
4596 f
= TREE_OPERAND (f
, 0);
4597 if (TREE_CODE (f
) == COMPONENT_REF
)
4599 f
= TREE_OPERAND (f
, 1);
4600 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4607 /* Adjust DECL if needed for printing using %qE. */
4610 omp_clause_printable_decl (tree decl
)
4612 tree t
= omp_clause_decl_field (decl
);
4618 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4619 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4623 omp_note_field_privatization (tree f
, tree t
)
4625 if (!omp_private_member_map
)
4626 omp_private_member_map
= new hash_map
<tree
, tree
>;
4627 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4631 omp_private_member_vec
.safe_push (f
);
4632 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4633 omp_private_member_vec
.safe_push (integer_zero_node
);
4637 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4641 omp_privatize_field (tree t
, bool shared
)
4643 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4644 if (m
== error_mark_node
)
4645 return error_mark_node
;
4646 if (!omp_private_member_map
&& !shared
)
4647 omp_private_member_map
= new hash_map
<tree
, tree
>;
4648 if (TYPE_REF_P (TREE_TYPE (t
)))
4650 gcc_assert (INDIRECT_REF_P (m
));
4651 m
= TREE_OPERAND (m
, 0);
4653 tree vb
= NULL_TREE
;
4654 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4657 v
= create_temporary_var (TREE_TYPE (m
));
4658 retrofit_lang_decl (v
);
4659 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4660 SET_DECL_VALUE_EXPR (v
, m
);
4661 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4663 omp_private_member_vec
.safe_push (t
);
4668 /* Helper function for handle_omp_array_sections. Called recursively
4669 to handle multiple array-section-subscripts. C is the clause,
4670 T current expression (initially OMP_CLAUSE_DECL), which is either
4671 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4672 expression if specified, TREE_VALUE length expression if specified,
4673 TREE_CHAIN is what it has been specified after, or some decl.
4674 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4675 set to true if any of the array-section-subscript could have length
4676 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4677 first array-section-subscript which is known not to have length
4679 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4680 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4681 all are or may have length of 1, array-section-subscript [:2] is the
4682 first one known not to have length 1. For array-section-subscript
4683 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4684 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4685 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4686 case though, as some lengths could be zero. */
4689 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4690 bool &maybe_zero_len
, unsigned int &first_non_one
,
4691 enum c_omp_region_type ort
)
4693 tree ret
, low_bound
, length
, type
;
4694 if (TREE_CODE (t
) != TREE_LIST
)
4696 if (error_operand_p (t
))
4697 return error_mark_node
;
4698 if (REFERENCE_REF_P (t
)
4699 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4700 t
= TREE_OPERAND (t
, 0);
4702 if (TREE_CODE (t
) == COMPONENT_REF
4704 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4705 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
4706 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
4707 && !type_dependent_expression_p (t
))
4709 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
4710 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
4712 error_at (OMP_CLAUSE_LOCATION (c
),
4713 "bit-field %qE in %qs clause",
4714 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4715 return error_mark_node
;
4717 while (TREE_CODE (t
) == COMPONENT_REF
)
4719 if (TREE_TYPE (TREE_OPERAND (t
, 0))
4720 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
4722 error_at (OMP_CLAUSE_LOCATION (c
),
4723 "%qE is a member of a union", t
);
4724 return error_mark_node
;
4726 t
= TREE_OPERAND (t
, 0);
4728 if (REFERENCE_REF_P (t
))
4729 t
= TREE_OPERAND (t
, 0);
4731 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
4733 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
4736 error_at (OMP_CLAUSE_LOCATION (c
),
4737 "%qD is not a variable in %qs clause", t
,
4738 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4740 error_at (OMP_CLAUSE_LOCATION (c
),
4741 "%qE is not a variable in %qs clause", t
,
4742 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4743 return error_mark_node
;
4745 else if (ort
== C_ORT_OMP
4746 && TREE_CODE (t
) == PARM_DECL
4747 && DECL_ARTIFICIAL (t
)
4748 && DECL_NAME (t
) == this_identifier
)
4750 error_at (OMP_CLAUSE_LOCATION (c
),
4751 "%<this%> allowed in OpenMP only in %<declare simd%>"
4753 return error_mark_node
;
4755 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4756 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
4758 error_at (OMP_CLAUSE_LOCATION (c
),
4759 "%qD is threadprivate variable in %qs clause", t
,
4760 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4761 return error_mark_node
;
4763 if (type_dependent_expression_p (ret
))
4765 ret
= convert_from_reference (ret
);
4769 if (ort
== C_ORT_OMP
4770 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4771 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4772 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4773 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
4774 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
4775 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4776 maybe_zero_len
, first_non_one
, ort
);
4777 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4780 type
= TREE_TYPE (ret
);
4781 low_bound
= TREE_PURPOSE (t
);
4782 length
= TREE_VALUE (t
);
4783 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4784 || (length
&& type_dependent_expression_p (length
)))
4787 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4788 return error_mark_node
;
4790 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4792 error_at (OMP_CLAUSE_LOCATION (c
),
4793 "low bound %qE of array section does not have integral type",
4795 return error_mark_node
;
4797 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4799 error_at (OMP_CLAUSE_LOCATION (c
),
4800 "length %qE of array section does not have integral type",
4802 return error_mark_node
;
4805 low_bound
= mark_rvalue_use (low_bound
);
4807 length
= mark_rvalue_use (length
);
4808 /* We need to reduce to real constant-values for checks below. */
4810 length
= fold_simple (length
);
4812 low_bound
= fold_simple (low_bound
);
4814 && TREE_CODE (low_bound
) == INTEGER_CST
4815 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4816 > TYPE_PRECISION (sizetype
))
4817 low_bound
= fold_convert (sizetype
, low_bound
);
4819 && TREE_CODE (length
) == INTEGER_CST
4820 && TYPE_PRECISION (TREE_TYPE (length
))
4821 > TYPE_PRECISION (sizetype
))
4822 length
= fold_convert (sizetype
, length
);
4823 if (low_bound
== NULL_TREE
)
4824 low_bound
= integer_zero_node
;
4826 if (length
!= NULL_TREE
)
4828 if (!integer_nonzerop (length
))
4830 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4831 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4832 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4833 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4835 if (integer_zerop (length
))
4837 error_at (OMP_CLAUSE_LOCATION (c
),
4838 "zero length array section in %qs clause",
4839 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4840 return error_mark_node
;
4844 maybe_zero_len
= true;
4846 if (first_non_one
== types
.length ()
4847 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4850 if (TREE_CODE (type
) == ARRAY_TYPE
)
4852 if (length
== NULL_TREE
4853 && (TYPE_DOMAIN (type
) == NULL_TREE
4854 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4856 error_at (OMP_CLAUSE_LOCATION (c
),
4857 "for unknown bound array type length expression must "
4859 return error_mark_node
;
4861 if (TREE_CODE (low_bound
) == INTEGER_CST
4862 && tree_int_cst_sgn (low_bound
) == -1)
4864 error_at (OMP_CLAUSE_LOCATION (c
),
4865 "negative low bound in array section in %qs clause",
4866 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4867 return error_mark_node
;
4869 if (length
!= NULL_TREE
4870 && TREE_CODE (length
) == INTEGER_CST
4871 && tree_int_cst_sgn (length
) == -1)
4873 error_at (OMP_CLAUSE_LOCATION (c
),
4874 "negative length in array section in %qs clause",
4875 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4876 return error_mark_node
;
4878 if (TYPE_DOMAIN (type
)
4879 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
4880 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
4884 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
4885 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
4886 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4888 if (tree_int_cst_lt (size
, low_bound
))
4890 error_at (OMP_CLAUSE_LOCATION (c
),
4891 "low bound %qE above array section size "
4892 "in %qs clause", low_bound
,
4893 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4894 return error_mark_node
;
4896 if (tree_int_cst_equal (size
, low_bound
))
4898 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4899 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4900 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4901 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4903 error_at (OMP_CLAUSE_LOCATION (c
),
4904 "zero length array section in %qs clause",
4905 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4906 return error_mark_node
;
4908 maybe_zero_len
= true;
4910 else if (length
== NULL_TREE
4911 && first_non_one
== types
.length ()
4912 && tree_int_cst_equal
4913 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4917 else if (length
== NULL_TREE
)
4919 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4920 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
4921 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
4922 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
4923 maybe_zero_len
= true;
4924 if (first_non_one
== types
.length ())
4927 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
4929 if (tree_int_cst_lt (size
, length
))
4931 error_at (OMP_CLAUSE_LOCATION (c
),
4932 "length %qE above array section size "
4933 "in %qs clause", length
,
4934 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4935 return error_mark_node
;
4937 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4940 = size_binop (PLUS_EXPR
,
4941 fold_convert (sizetype
, low_bound
),
4942 fold_convert (sizetype
, length
));
4943 if (TREE_CODE (lbpluslen
) == INTEGER_CST
4944 && tree_int_cst_lt (size
, lbpluslen
))
4946 error_at (OMP_CLAUSE_LOCATION (c
),
4947 "high bound %qE above array section size "
4948 "in %qs clause", lbpluslen
,
4949 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4950 return error_mark_node
;
4955 else if (length
== NULL_TREE
)
4957 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4958 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
4959 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
4960 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
4961 maybe_zero_len
= true;
4962 if (first_non_one
== types
.length ())
4966 /* For [lb:] we will need to evaluate lb more than once. */
4967 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4969 tree lb
= cp_save_expr (low_bound
);
4970 if (lb
!= low_bound
)
4972 TREE_PURPOSE (t
) = lb
;
4977 else if (TYPE_PTR_P (type
))
4979 if (length
== NULL_TREE
)
4981 error_at (OMP_CLAUSE_LOCATION (c
),
4982 "for pointer type length expression must be specified");
4983 return error_mark_node
;
4985 if (length
!= NULL_TREE
4986 && TREE_CODE (length
) == INTEGER_CST
4987 && tree_int_cst_sgn (length
) == -1)
4989 error_at (OMP_CLAUSE_LOCATION (c
),
4990 "negative length in array section in %qs clause",
4991 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4992 return error_mark_node
;
4994 /* If there is a pointer type anywhere but in the very first
4995 array-section-subscript, the array section can't be contiguous. */
4996 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4997 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
4999 error_at (OMP_CLAUSE_LOCATION (c
),
5000 "array section is not contiguous in %qs clause",
5001 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5002 return error_mark_node
;
5007 error_at (OMP_CLAUSE_LOCATION (c
),
5008 "%qE does not have pointer or array type", ret
);
5009 return error_mark_node
;
5011 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5012 types
.safe_push (TREE_TYPE (ret
));
5013 /* We will need to evaluate lb more than once. */
5014 tree lb
= cp_save_expr (low_bound
);
5015 if (lb
!= low_bound
)
5017 TREE_PURPOSE (t
) = lb
;
5020 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
5024 /* Handle array sections for clause C. */
5027 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
5029 bool maybe_zero_len
= false;
5030 unsigned int first_non_one
= 0;
5031 auto_vec
<tree
, 10> types
;
5032 tree
*tp
= &OMP_CLAUSE_DECL (c
);
5033 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5034 && TREE_CODE (*tp
) == TREE_LIST
5035 && TREE_PURPOSE (*tp
)
5036 && TREE_CODE (TREE_PURPOSE (*tp
)) == TREE_VEC
)
5037 tp
= &TREE_VALUE (*tp
);
5038 tree first
= handle_omp_array_sections_1 (c
, *tp
, types
,
5039 maybe_zero_len
, first_non_one
,
5041 if (first
== error_mark_node
)
5043 if (first
== NULL_TREE
)
5045 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
5048 tree tem
= NULL_TREE
;
5049 if (processing_template_decl
)
5051 /* Need to evaluate side effects in the length expressions
5053 while (TREE_CODE (t
) == TREE_LIST
)
5055 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
5057 if (tem
== NULL_TREE
)
5058 tem
= TREE_VALUE (t
);
5060 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
5061 TREE_VALUE (t
), tem
);
5066 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
5071 unsigned int num
= types
.length (), i
;
5072 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
5073 tree condition
= NULL_TREE
;
5075 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
5076 maybe_zero_len
= true;
5077 if (processing_template_decl
&& maybe_zero_len
)
5080 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
5083 tree low_bound
= TREE_PURPOSE (t
);
5084 tree length
= TREE_VALUE (t
);
5088 && TREE_CODE (low_bound
) == INTEGER_CST
5089 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5090 > TYPE_PRECISION (sizetype
))
5091 low_bound
= fold_convert (sizetype
, low_bound
);
5093 && TREE_CODE (length
) == INTEGER_CST
5094 && TYPE_PRECISION (TREE_TYPE (length
))
5095 > TYPE_PRECISION (sizetype
))
5096 length
= fold_convert (sizetype
, length
);
5097 if (low_bound
== NULL_TREE
)
5098 low_bound
= integer_zero_node
;
5099 if (!maybe_zero_len
&& i
> first_non_one
)
5101 if (integer_nonzerop (low_bound
))
5102 goto do_warn_noncontiguous
;
5103 if (length
!= NULL_TREE
5104 && TREE_CODE (length
) == INTEGER_CST
5105 && TYPE_DOMAIN (types
[i
])
5106 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
5107 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
5111 size
= size_binop (PLUS_EXPR
,
5112 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5114 if (!tree_int_cst_equal (length
, size
))
5116 do_warn_noncontiguous
:
5117 error_at (OMP_CLAUSE_LOCATION (c
),
5118 "array section is not contiguous in %qs "
5120 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5124 if (!processing_template_decl
5125 && length
!= NULL_TREE
5126 && TREE_SIDE_EFFECTS (length
))
5128 if (side_effects
== NULL_TREE
)
5129 side_effects
= length
;
5131 side_effects
= build2 (COMPOUND_EXPR
,
5132 TREE_TYPE (side_effects
),
5133 length
, side_effects
);
5136 else if (processing_template_decl
)
5142 if (i
> first_non_one
5143 && ((length
&& integer_nonzerop (length
))
5144 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5145 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5146 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
))
5149 l
= fold_convert (sizetype
, length
);
5152 l
= size_binop (PLUS_EXPR
,
5153 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5155 l
= size_binop (MINUS_EXPR
, l
,
5156 fold_convert (sizetype
, low_bound
));
5158 if (i
> first_non_one
)
5160 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
5162 if (condition
== NULL_TREE
)
5165 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
5168 else if (size
== NULL_TREE
)
5170 size
= size_in_bytes (TREE_TYPE (types
[i
]));
5171 tree eltype
= TREE_TYPE (types
[num
- 1]);
5172 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5173 eltype
= TREE_TYPE (eltype
);
5174 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5175 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5176 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5177 size
= size_binop (EXACT_DIV_EXPR
, size
,
5178 size_in_bytes (eltype
));
5179 size
= size_binop (MULT_EXPR
, size
, l
);
5181 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
5182 size
, size_zero_node
);
5185 size
= size_binop (MULT_EXPR
, size
, l
);
5188 if (!processing_template_decl
)
5191 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
5192 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5193 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5194 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5196 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5197 size
= save_expr (size
);
5198 tree index_type
= build_index_type (size
);
5199 tree eltype
= TREE_TYPE (first
);
5200 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5201 eltype
= TREE_TYPE (eltype
);
5202 tree type
= build_array_type (eltype
, index_type
);
5203 tree ptype
= build_pointer_type (eltype
);
5204 if (TYPE_REF_P (TREE_TYPE (t
))
5205 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
5206 t
= convert_from_reference (t
);
5207 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5208 t
= build_fold_addr_expr (t
);
5209 tree t2
= build_fold_addr_expr (first
);
5210 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5211 ptrdiff_type_node
, t2
);
5212 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5213 ptrdiff_type_node
, t2
,
5214 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5215 ptrdiff_type_node
, t
));
5216 if (tree_fits_shwi_p (t2
))
5217 t
= build2 (MEM_REF
, type
, t
,
5218 build_int_cst (ptype
, tree_to_shwi (t2
)));
5221 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5223 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
5224 TREE_TYPE (t
), t
, t2
);
5225 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5227 OMP_CLAUSE_DECL (c
) = t
;
5230 OMP_CLAUSE_DECL (c
) = first
;
5231 OMP_CLAUSE_SIZE (c
) = size
;
5232 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5233 || (TREE_CODE (t
) == COMPONENT_REF
5234 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5236 if (ort
== C_ORT_OMP
|| ort
== C_ORT_ACC
)
5237 switch (OMP_CLAUSE_MAP_KIND (c
))
5239 case GOMP_MAP_ALLOC
:
5242 case GOMP_MAP_TOFROM
:
5243 case GOMP_MAP_ALWAYS_TO
:
5244 case GOMP_MAP_ALWAYS_FROM
:
5245 case GOMP_MAP_ALWAYS_TOFROM
:
5246 case GOMP_MAP_RELEASE
:
5247 case GOMP_MAP_DELETE
:
5248 case GOMP_MAP_FORCE_TO
:
5249 case GOMP_MAP_FORCE_FROM
:
5250 case GOMP_MAP_FORCE_TOFROM
:
5251 case GOMP_MAP_FORCE_PRESENT
:
5252 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5257 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5259 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
&& ort
!= C_ORT_ACC
)
5260 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
5261 else if (TREE_CODE (t
) == COMPONENT_REF
)
5262 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5263 else if (REFERENCE_REF_P (t
)
5264 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5266 t
= TREE_OPERAND (t
, 0);
5267 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5270 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5271 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5272 && !cxx_mark_addressable (t
))
5274 OMP_CLAUSE_DECL (c2
) = t
;
5275 t
= build_fold_addr_expr (first
);
5276 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5277 ptrdiff_type_node
, t
);
5278 tree ptr
= OMP_CLAUSE_DECL (c2
);
5279 ptr
= convert_from_reference (ptr
);
5280 if (!INDIRECT_TYPE_P (TREE_TYPE (ptr
)))
5281 ptr
= build_fold_addr_expr (ptr
);
5282 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5283 ptrdiff_type_node
, t
,
5284 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5285 ptrdiff_type_node
, ptr
));
5286 OMP_CLAUSE_SIZE (c2
) = t
;
5287 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5288 OMP_CLAUSE_CHAIN (c
) = c2
;
5289 ptr
= OMP_CLAUSE_DECL (c2
);
5290 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5291 && TYPE_REF_P (TREE_TYPE (ptr
))
5292 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5294 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5296 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5297 OMP_CLAUSE_DECL (c3
) = ptr
;
5298 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
)
5299 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5301 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5302 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5303 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5304 OMP_CLAUSE_CHAIN (c2
) = c3
;
5311 /* Return identifier to look up for omp declare reduction. */
5314 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5316 const char *p
= NULL
;
5317 const char *m
= NULL
;
5318 switch (reduction_code
)
5326 case TRUTH_ANDIF_EXPR
:
5327 case TRUTH_ORIF_EXPR
:
5328 reduction_id
= ovl_op_identifier (false, reduction_code
);
5342 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5343 return error_mark_node
;
5344 p
= IDENTIFIER_POINTER (reduction_id
);
5347 if (type
!= NULL_TREE
)
5348 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5350 const char prefix
[] = "omp declare reduction ";
5351 size_t lenp
= sizeof (prefix
);
5352 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5354 size_t len
= strlen (p
);
5355 size_t lenm
= m
? strlen (m
) + 1 : 0;
5356 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5358 memcpy (name
, prefix
, lenp
- 1);
5359 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5362 name
[lenp
+ len
- 1] = '~';
5363 memcpy (name
+ lenp
+ len
, m
, lenm
);
5365 return get_identifier (name
);
5368 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5369 FUNCTION_DECL or NULL_TREE if not found. */
5372 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5373 vec
<tree
> *ambiguousp
)
5376 tree baselink
= NULL_TREE
;
5377 if (identifier_p (id
))
5380 bool nonint_cst_expression_p
;
5381 const char *error_msg
;
5382 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5383 tree decl
= lookup_name (id
);
5384 if (decl
== NULL_TREE
)
5385 decl
= error_mark_node
;
5386 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5387 &nonint_cst_expression_p
, false, true, false,
5388 false, &error_msg
, loc
);
5389 if (idk
== CP_ID_KIND_UNQUALIFIED
5390 && identifier_p (id
))
5392 vec
<tree
, va_gc
> *args
= NULL
;
5393 vec_safe_push (args
, build_reference_type (type
));
5394 id
= perform_koenig_lookup (id
, args
, tf_none
);
5397 else if (TREE_CODE (id
) == SCOPE_REF
)
5398 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5399 omp_reduction_id (ERROR_MARK
,
5400 TREE_OPERAND (id
, 1),
5405 if (fns
&& is_overloaded_fn (fns
))
5407 for (lkp_iterator
iter (get_fns (fns
)); iter
; ++iter
)
5409 tree fndecl
= *iter
;
5410 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5412 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5413 if (same_type_p (TREE_TYPE (argtype
), type
))
5421 if (id
&& BASELINK_P (fns
))
5430 if (!id
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5432 vec
<tree
> ambiguous
= vNULL
;
5433 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5435 if (ambiguousp
== NULL
)
5436 ambiguousp
= &ambiguous
;
5437 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5439 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5440 baselinkp
? baselinkp
: &baselink
,
5442 if (id
== NULL_TREE
)
5444 if (!ambiguousp
->is_empty ())
5445 ambiguousp
->safe_push (id
);
5446 else if (ret
!= NULL_TREE
)
5448 ambiguousp
->safe_push (ret
);
5449 ambiguousp
->safe_push (id
);
5455 if (ambiguousp
!= &ambiguous
)
5457 if (!ambiguous
.is_empty ())
5459 const char *str
= _("candidates are:");
5462 error_at (loc
, "user defined reduction lookup is ambiguous");
5463 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5465 inform (DECL_SOURCE_LOCATION (udr
), "%s %#qD", str
, udr
);
5467 str
= get_spaces (str
);
5469 ambiguous
.release ();
5470 ret
= error_mark_node
;
5471 baselink
= NULL_TREE
;
5476 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5477 id
, id
, tf_warning_or_error
);
5481 /* Helper function for cp_parser_omp_declare_reduction_exprs
5483 Remove CLEANUP_STMT for data (omp_priv variable).
5484 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5488 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5492 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5493 *tp
= CLEANUP_BODY (*tp
);
5494 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5496 tree decl
= DECL_EXPR_DECL (*tp
);
5497 if (!processing_template_decl
5498 && decl
== (tree
) data
5499 && DECL_INITIAL (decl
)
5500 && DECL_INITIAL (decl
) != error_mark_node
)
5502 tree list
= NULL_TREE
;
5503 append_to_statement_list_force (*tp
, &list
);
5504 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5505 decl
, DECL_INITIAL (decl
));
5506 DECL_INITIAL (decl
) = NULL_TREE
;
5507 append_to_statement_list_force (init_expr
, &list
);
5514 /* Data passed from cp_check_omp_declare_reduction to
5515 cp_check_omp_declare_reduction_r. */
5517 struct cp_check_omp_declare_reduction_data
5524 /* Helper function for cp_check_omp_declare_reduction, called via
5528 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5530 struct cp_check_omp_declare_reduction_data
*udr_data
5531 = (struct cp_check_omp_declare_reduction_data
*) data
;
5533 && !DECL_ARTIFICIAL (*tp
)
5534 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5535 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5537 location_t loc
= udr_data
->loc
;
5538 if (udr_data
->combiner_p
)
5539 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5540 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5543 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5544 "to variable %qD which is not %<omp_priv%> nor "
5552 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5555 cp_check_omp_declare_reduction (tree udr
)
5557 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5558 gcc_assert (TYPE_REF_P (type
));
5559 type
= TREE_TYPE (type
);
5561 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5563 if (type
== error_mark_node
)
5565 if (ARITHMETIC_TYPE_P (type
))
5567 static enum tree_code predef_codes
[]
5568 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5569 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5570 for (i
= 0; i
< 8; i
++)
5572 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5573 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5574 const char *n2
= IDENTIFIER_POINTER (id
);
5575 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5576 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5577 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5582 && TREE_CODE (type
) != COMPLEX_EXPR
)
5584 const char prefix_minmax
[] = "omp declare reduction m";
5585 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5586 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5587 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5588 prefix_minmax
, prefix_size
) == 0
5589 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5590 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5591 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5596 error_at (loc
, "predeclared arithmetic type %qT in "
5597 "%<#pragma omp declare reduction%>", type
);
5601 else if (FUNC_OR_METHOD_TYPE_P (type
)
5602 || TREE_CODE (type
) == ARRAY_TYPE
)
5604 error_at (loc
, "function or array type %qT in "
5605 "%<#pragma omp declare reduction%>", type
);
5608 else if (TYPE_REF_P (type
))
5610 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5614 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5616 error_at (loc
, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
5617 "type %qT in %<#pragma omp declare reduction%>", type
);
5621 tree body
= DECL_SAVED_TREE (udr
);
5622 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5625 tree_stmt_iterator tsi
;
5626 struct cp_check_omp_declare_reduction_data data
;
5627 memset (data
.stmts
, 0, sizeof data
.stmts
);
5628 for (i
= 0, tsi
= tsi_start (body
);
5629 i
< 7 && !tsi_end_p (tsi
);
5630 i
++, tsi_next (&tsi
))
5631 data
.stmts
[i
] = tsi_stmt (tsi
);
5633 gcc_assert (tsi_end_p (tsi
));
5636 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5637 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5638 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5640 data
.combiner_p
= true;
5641 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5643 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5647 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5648 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5649 data
.combiner_p
= false;
5650 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5652 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5653 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5654 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5656 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5660 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5661 an inline call. But, remap
5662 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5663 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5666 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5667 tree decl
, tree placeholder
)
5670 hash_map
<tree
, tree
> decl_map
;
5672 decl_map
.put (omp_decl1
, placeholder
);
5673 decl_map
.put (omp_decl2
, decl
);
5674 memset (&id
, 0, sizeof (id
));
5675 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5676 id
.dst_fn
= current_function_decl
;
5677 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5678 id
.decl_map
= &decl_map
;
5680 id
.copy_decl
= copy_decl_no_change
;
5681 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5682 id
.transform_new_cfg
= true;
5683 id
.transform_return_to_modify
= false;
5684 id
.transform_lang_insert_block
= NULL
;
5686 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5690 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5691 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5694 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5696 if (*tp
== (tree
) data
)
5701 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5702 Return true if there is some error and the clause should be removed. */
5705 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5707 tree t
= OMP_CLAUSE_DECL (c
);
5708 bool predefined
= false;
5709 if (TREE_CODE (t
) == TREE_LIST
)
5711 gcc_assert (processing_template_decl
);
5714 tree type
= TREE_TYPE (t
);
5715 if (TREE_CODE (t
) == MEM_REF
)
5716 type
= TREE_TYPE (type
);
5717 if (TYPE_REF_P (type
))
5718 type
= TREE_TYPE (type
);
5719 if (TREE_CODE (type
) == ARRAY_TYPE
)
5722 gcc_assert (TREE_CODE (t
) != MEM_REF
);
5723 while (TREE_CODE (type
) == ARRAY_TYPE
)
5724 type
= TREE_TYPE (type
);
5725 if (!processing_template_decl
)
5727 t
= require_complete_type (t
);
5728 if (t
== error_mark_node
)
5730 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
5731 TYPE_SIZE_UNIT (type
));
5732 if (integer_zerop (size
))
5734 error_at (OMP_CLAUSE_LOCATION (c
),
5735 "%qE in %<reduction%> clause is a zero size array",
5736 omp_clause_printable_decl (t
));
5739 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5740 size
= save_expr (size
);
5741 tree index_type
= build_index_type (size
);
5742 tree atype
= build_array_type (type
, index_type
);
5743 tree ptype
= build_pointer_type (type
);
5744 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5745 t
= build_fold_addr_expr (t
);
5746 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
5747 OMP_CLAUSE_DECL (c
) = t
;
5750 if (type
== error_mark_node
)
5752 else if (ARITHMETIC_TYPE_P (type
))
5753 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5762 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5769 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5773 case TRUTH_ANDIF_EXPR
:
5774 case TRUTH_ORIF_EXPR
:
5775 if (FLOAT_TYPE_P (type
))
5782 else if (TYPE_READONLY (type
))
5784 error_at (OMP_CLAUSE_LOCATION (c
),
5785 "%qE has const type for %<reduction%>",
5786 omp_clause_printable_decl (t
));
5789 else if (!processing_template_decl
)
5791 t
= require_complete_type (t
);
5792 if (t
== error_mark_node
)
5794 OMP_CLAUSE_DECL (c
) = t
;
5799 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5802 else if (processing_template_decl
)
5804 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) == error_mark_node
)
5809 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5811 type
= TYPE_MAIN_VARIANT (type
);
5812 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5813 if (id
== NULL_TREE
)
5814 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5815 NULL_TREE
, NULL_TREE
);
5816 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5819 if (id
== error_mark_node
)
5822 tree body
= DECL_SAVED_TREE (id
);
5825 if (TREE_CODE (body
) == STATEMENT_LIST
)
5827 tree_stmt_iterator tsi
;
5828 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
5831 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5832 atype
= TREE_TYPE (atype
);
5833 bool need_static_cast
= !same_type_p (type
, atype
);
5834 memset (stmts
, 0, sizeof stmts
);
5835 for (i
= 0, tsi
= tsi_start (body
);
5836 i
< 7 && !tsi_end_p (tsi
);
5837 i
++, tsi_next (&tsi
))
5838 stmts
[i
] = tsi_stmt (tsi
);
5839 gcc_assert (tsi_end_p (tsi
));
5843 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
5844 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
5845 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
5846 DECL_ARTIFICIAL (placeholder
) = 1;
5847 DECL_IGNORED_P (placeholder
) = 1;
5848 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
5849 if (TREE_CODE (t
) == MEM_REF
)
5851 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
5853 DECL_ARTIFICIAL (decl_placeholder
) = 1;
5854 DECL_IGNORED_P (decl_placeholder
) = 1;
5855 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
5857 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
5858 cxx_mark_addressable (placeholder
);
5859 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
5860 && (decl_placeholder
5861 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
5862 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5863 : OMP_CLAUSE_DECL (c
));
5864 tree omp_out
= placeholder
;
5865 tree omp_in
= decl_placeholder
? decl_placeholder
5866 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5867 if (need_static_cast
)
5869 tree rtype
= build_reference_type (atype
);
5870 omp_out
= build_static_cast (rtype
, omp_out
,
5871 tf_warning_or_error
);
5872 omp_in
= build_static_cast (rtype
, omp_in
,
5873 tf_warning_or_error
);
5874 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
5876 omp_out
= convert_from_reference (omp_out
);
5877 omp_in
= convert_from_reference (omp_in
);
5879 OMP_CLAUSE_REDUCTION_MERGE (c
)
5880 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
5881 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
5885 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
5886 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
5887 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3]))
5888 && (decl_placeholder
5889 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
5890 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5891 : OMP_CLAUSE_DECL (c
));
5892 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
5893 cxx_mark_addressable (placeholder
);
5894 tree omp_priv
= decl_placeholder
? decl_placeholder
5895 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5896 tree omp_orig
= placeholder
;
5897 if (need_static_cast
)
5901 error_at (OMP_CLAUSE_LOCATION (c
),
5902 "user defined reduction with constructor "
5903 "initializer for base class %qT", atype
);
5906 tree rtype
= build_reference_type (atype
);
5907 omp_priv
= build_static_cast (rtype
, omp_priv
,
5908 tf_warning_or_error
);
5909 omp_orig
= build_static_cast (rtype
, omp_orig
,
5910 tf_warning_or_error
);
5911 if (omp_priv
== error_mark_node
5912 || omp_orig
== error_mark_node
)
5914 omp_priv
= convert_from_reference (omp_priv
);
5915 omp_orig
= convert_from_reference (omp_orig
);
5918 *need_default_ctor
= true;
5919 OMP_CLAUSE_REDUCTION_INIT (c
)
5920 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
5921 DECL_EXPR_DECL (stmts
[3]),
5922 omp_priv
, omp_orig
);
5923 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
5924 find_omp_placeholder_r
, placeholder
, NULL
))
5925 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
5929 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
5930 *need_default_ctor
= true;
5934 tree v
= decl_placeholder
? decl_placeholder
5935 : convert_from_reference (t
);
5936 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
5937 init
= build_constructor (TREE_TYPE (v
), NULL
);
5939 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
5940 OMP_CLAUSE_REDUCTION_INIT (c
)
5941 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
5946 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5950 error_at (OMP_CLAUSE_LOCATION (c
),
5951 "user defined reduction not found for %qE",
5952 omp_clause_printable_decl (t
));
5955 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
5956 gcc_assert (TYPE_SIZE_UNIT (type
)
5957 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
5961 /* Called from finish_struct_1. linear(this) or linear(this:step)
5962 clauses might not be finalized yet because the class has been incomplete
5963 when parsing #pragma omp declare simd methods. Fix those up now. */
5966 finish_omp_declare_simd_methods (tree t
)
5968 if (processing_template_decl
)
5971 for (tree x
= TYPE_FIELDS (t
); x
; x
= DECL_CHAIN (x
))
5973 if (TREE_CODE (x
) == USING_DECL
5974 || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x
))
5976 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
5977 if (!ods
|| !TREE_VALUE (ods
))
5979 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
5980 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
5981 && integer_zerop (OMP_CLAUSE_DECL (c
))
5982 && OMP_CLAUSE_LINEAR_STEP (c
)
5983 && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
))))
5985 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
5986 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
5987 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
5988 sizetype
, s
, TYPE_SIZE_UNIT (t
));
5989 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
5994 /* Adjust sink depend clause to take into account pointer offsets.
5996 Return TRUE if there was a problem processing the offset, and the
5997 whole clause should be removed. */
6000 cp_finish_omp_clause_depend_sink (tree sink_clause
)
6002 tree t
= OMP_CLAUSE_DECL (sink_clause
);
6003 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
6005 /* Make sure we don't adjust things twice for templates. */
6006 if (processing_template_decl
)
6009 for (; t
; t
= TREE_CHAIN (t
))
6011 tree decl
= TREE_VALUE (t
);
6012 if (TYPE_PTR_P (TREE_TYPE (decl
)))
6014 tree offset
= TREE_PURPOSE (t
);
6015 bool neg
= wi::neg_p (wi::to_wide (offset
));
6016 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
6017 decl
= mark_rvalue_use (decl
);
6018 decl
= convert_from_reference (decl
);
6019 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
6020 neg
? MINUS_EXPR
: PLUS_EXPR
,
6022 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
6023 MINUS_EXPR
, sizetype
,
6024 fold_convert (sizetype
, t2
),
6025 fold_convert (sizetype
, decl
));
6026 if (t2
== error_mark_node
)
6028 TREE_PURPOSE (t
) = t2
;
6034 /* Finish OpenMP iterators ITER. Return true if they are errorneous
6035 and clauses containing them should be removed. */
6038 cp_omp_finish_iterators (tree iter
)
6041 for (tree it
= iter
; it
; it
= TREE_CHAIN (it
))
6043 tree var
= TREE_VEC_ELT (it
, 0);
6044 tree begin
= TREE_VEC_ELT (it
, 1);
6045 tree end
= TREE_VEC_ELT (it
, 2);
6046 tree step
= TREE_VEC_ELT (it
, 3);
6048 tree type
= TREE_TYPE (var
);
6049 location_t loc
= DECL_SOURCE_LOCATION (var
);
6050 if (type
== error_mark_node
)
6055 if (type_dependent_expression_p (var
))
6057 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
6059 error_at (loc
, "iterator %qD has neither integral nor pointer type",
6064 else if (TYPE_READONLY (type
))
6066 error_at (loc
, "iterator %qD has const qualified type", var
);
6070 if (type_dependent_expression_p (begin
)
6071 || type_dependent_expression_p (end
)
6072 || type_dependent_expression_p (step
))
6074 else if (error_operand_p (step
))
6079 else if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
6081 error_at (EXPR_LOC_OR_LOC (step
, loc
),
6082 "iterator step with non-integral type");
6087 begin
= mark_rvalue_use (begin
);
6088 end
= mark_rvalue_use (end
);
6089 step
= mark_rvalue_use (step
);
6090 begin
= cp_build_c_cast (type
, begin
, tf_warning_or_error
);
6091 end
= cp_build_c_cast (type
, end
, tf_warning_or_error
);
6093 if (!processing_template_decl
)
6094 step
= orig_step
= save_expr (step
);
6095 tree stype
= POINTER_TYPE_P (type
) ? sizetype
: type
;
6096 step
= cp_build_c_cast (stype
, step
, tf_warning_or_error
);
6097 if (POINTER_TYPE_P (type
) && !processing_template_decl
)
6099 begin
= save_expr (begin
);
6100 step
= pointer_int_sum (loc
, PLUS_EXPR
, begin
, step
);
6101 step
= fold_build2_loc (loc
, MINUS_EXPR
, sizetype
,
6102 fold_convert (sizetype
, step
),
6103 fold_convert (sizetype
, begin
));
6104 step
= fold_convert (ssizetype
, step
);
6106 if (!processing_template_decl
)
6108 begin
= maybe_constant_value (begin
);
6109 end
= maybe_constant_value (end
);
6110 step
= maybe_constant_value (step
);
6111 orig_step
= maybe_constant_value (orig_step
);
6113 if (integer_zerop (step
))
6115 error_at (loc
, "iterator %qD has zero step", var
);
6120 if (begin
== error_mark_node
6121 || end
== error_mark_node
6122 || step
== error_mark_node
6123 || orig_step
== error_mark_node
)
6129 if (!processing_template_decl
)
6131 begin
= fold_build_cleanup_point_expr (TREE_TYPE (begin
), begin
);
6132 end
= fold_build_cleanup_point_expr (TREE_TYPE (end
), end
);
6133 step
= fold_build_cleanup_point_expr (TREE_TYPE (step
), step
);
6134 orig_step
= fold_build_cleanup_point_expr (TREE_TYPE (orig_step
),
6137 hash_set
<tree
> pset
;
6139 for (it2
= TREE_CHAIN (it
); it2
; it2
= TREE_CHAIN (it2
))
6141 tree var2
= TREE_VEC_ELT (it2
, 0);
6142 tree begin2
= TREE_VEC_ELT (it2
, 1);
6143 tree end2
= TREE_VEC_ELT (it2
, 2);
6144 tree step2
= TREE_VEC_ELT (it2
, 3);
6145 location_t loc2
= DECL_SOURCE_LOCATION (var2
);
6146 if (cp_walk_tree (&begin2
, find_omp_placeholder_r
, var
, &pset
))
6148 error_at (EXPR_LOC_OR_LOC (begin2
, loc2
),
6149 "begin expression refers to outer iterator %qD", var
);
6152 else if (cp_walk_tree (&end2
, find_omp_placeholder_r
, var
, &pset
))
6154 error_at (EXPR_LOC_OR_LOC (end2
, loc2
),
6155 "end expression refers to outer iterator %qD", var
);
6158 else if (cp_walk_tree (&step2
, find_omp_placeholder_r
, var
, &pset
))
6160 error_at (EXPR_LOC_OR_LOC (step2
, loc2
),
6161 "step expression refers to outer iterator %qD", var
);
6170 TREE_VEC_ELT (it
, 1) = begin
;
6171 TREE_VEC_ELT (it
, 2) = end
;
6172 if (processing_template_decl
)
6173 TREE_VEC_ELT (it
, 3) = orig_step
;
6176 TREE_VEC_ELT (it
, 3) = step
;
6177 TREE_VEC_ELT (it
, 4) = orig_step
;
6183 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
6184 Remove any elements from the list that are invalid. */
6187 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
6189 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
6190 bitmap_head aligned_head
, map_head
, map_field_head
, oacc_reduction_head
;
6192 tree safelen
= NULL_TREE
;
6193 bool branch_seen
= false;
6194 bool copyprivate_seen
= false;
6195 bool ordered_seen
= false;
6196 bool order_seen
= false;
6197 bool schedule_seen
= false;
6198 bool oacc_async
= false;
6199 tree last_iterators
= NULL_TREE
;
6200 bool last_iterators_remove
= false;
6201 /* 1 if normal/task reduction has been seen, -1 if inscan reduction
6202 has been seen, -2 if mixed inscan/normal reduction diagnosed. */
6203 int reduction_seen
= 0;
6205 bitmap_obstack_initialize (NULL
);
6206 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
6207 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
6208 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
6209 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
6210 /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
6211 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
6212 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
6213 /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
6215 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
6217 if (ort
& C_ORT_ACC
)
6218 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6219 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
6225 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
6227 bool remove
= false;
6228 bool field_ok
= false;
6230 switch (OMP_CLAUSE_CODE (c
))
6232 case OMP_CLAUSE_SHARED
:
6233 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6234 goto check_dup_generic
;
6235 case OMP_CLAUSE_PRIVATE
:
6236 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6237 goto check_dup_generic
;
6238 case OMP_CLAUSE_REDUCTION
:
6239 if (reduction_seen
== 0)
6240 reduction_seen
= OMP_CLAUSE_REDUCTION_INSCAN (c
) ? -1 : 1;
6241 else if (reduction_seen
!= -2
6242 && reduction_seen
!= (OMP_CLAUSE_REDUCTION_INSCAN (c
)
6245 error_at (OMP_CLAUSE_LOCATION (c
),
6246 "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
6247 "on the same construct");
6248 reduction_seen
= -2;
6251 case OMP_CLAUSE_IN_REDUCTION
:
6252 case OMP_CLAUSE_TASK_REDUCTION
:
6253 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6254 t
= OMP_CLAUSE_DECL (c
);
6255 if (TREE_CODE (t
) == TREE_LIST
)
6257 if (handle_omp_array_sections (c
, ort
))
6262 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6263 && OMP_CLAUSE_REDUCTION_INSCAN (c
))
6265 error_at (OMP_CLAUSE_LOCATION (c
),
6266 "%<inscan%> %<reduction%> clause with array "
6271 if (TREE_CODE (t
) == TREE_LIST
)
6273 while (TREE_CODE (t
) == TREE_LIST
)
6278 gcc_assert (TREE_CODE (t
) == MEM_REF
);
6279 t
= TREE_OPERAND (t
, 0);
6280 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
6281 t
= TREE_OPERAND (t
, 0);
6282 if (TREE_CODE (t
) == ADDR_EXPR
6283 || INDIRECT_REF_P (t
))
6284 t
= TREE_OPERAND (t
, 0);
6286 tree n
= omp_clause_decl_field (t
);
6289 goto check_dup_generic_t
;
6292 cxx_mark_addressable (t
);
6293 goto check_dup_generic
;
6294 case OMP_CLAUSE_COPYPRIVATE
:
6295 copyprivate_seen
= true;
6296 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6297 goto check_dup_generic
;
6298 case OMP_CLAUSE_COPYIN
:
6299 goto check_dup_generic
;
6300 case OMP_CLAUSE_LINEAR
:
6301 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6302 t
= OMP_CLAUSE_DECL (c
);
6303 if (ort
!= C_ORT_OMP_DECLARE_SIMD
6304 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
6306 error_at (OMP_CLAUSE_LOCATION (c
),
6307 "modifier should not be specified in %<linear%> "
6308 "clause on %<simd%> or %<for%> constructs");
6309 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
6311 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6312 && !type_dependent_expression_p (t
))
6314 tree type
= TREE_TYPE (t
);
6315 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6316 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
6317 && !TYPE_REF_P (type
))
6319 error_at (OMP_CLAUSE_LOCATION (c
),
6320 "linear clause with %qs modifier applied to "
6321 "non-reference variable with %qT type",
6322 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6323 ? "ref" : "uval", TREE_TYPE (t
));
6327 if (TYPE_REF_P (type
))
6328 type
= TREE_TYPE (type
);
6329 if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
6331 if (!INTEGRAL_TYPE_P (type
)
6332 && !TYPE_PTR_P (type
))
6334 error_at (OMP_CLAUSE_LOCATION (c
),
6335 "linear clause applied to non-integral "
6336 "non-pointer variable with %qT type",
6343 t
= OMP_CLAUSE_LINEAR_STEP (c
);
6345 t
= integer_one_node
;
6346 if (t
== error_mark_node
)
6351 else if (!type_dependent_expression_p (t
)
6352 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
6353 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6354 || TREE_CODE (t
) != PARM_DECL
6355 || !TYPE_REF_P (TREE_TYPE (t
))
6356 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
6358 error_at (OMP_CLAUSE_LOCATION (c
),
6359 "linear step expression must be integral");
6365 t
= mark_rvalue_use (t
);
6366 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
6368 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
6369 goto check_dup_generic
;
6371 if (!processing_template_decl
6372 && (VAR_P (OMP_CLAUSE_DECL (c
))
6373 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
6375 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
6377 t
= maybe_constant_value (t
);
6378 if (TREE_CODE (t
) != INTEGER_CST
)
6380 error_at (OMP_CLAUSE_LOCATION (c
),
6381 "%<linear%> clause step %qE is neither "
6382 "constant nor a parameter", t
);
6387 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6388 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
6389 if (TYPE_REF_P (type
))
6390 type
= TREE_TYPE (type
);
6391 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
6393 type
= build_pointer_type (type
);
6394 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
6395 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6397 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6398 MINUS_EXPR
, sizetype
,
6399 fold_convert (sizetype
, t
),
6400 fold_convert (sizetype
, d
));
6401 if (t
== error_mark_node
)
6407 else if (TYPE_PTR_P (type
)
6408 /* Can't multiply the step yet if *this
6409 is still incomplete type. */
6410 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6411 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
6412 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
6413 || DECL_NAME (OMP_CLAUSE_DECL (c
))
6415 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
6417 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
6418 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6420 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6421 MINUS_EXPR
, sizetype
,
6422 fold_convert (sizetype
, t
),
6423 fold_convert (sizetype
, d
));
6424 if (t
== error_mark_node
)
6431 t
= fold_convert (type
, t
);
6433 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6435 goto check_dup_generic
;
6437 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6440 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6441 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6444 t
= OMP_CLAUSE_DECL (c
);
6445 check_dup_generic_t
:
6446 if (t
== current_class_ptr
6447 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6448 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6449 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6451 error_at (OMP_CLAUSE_LOCATION (c
),
6452 "%<this%> allowed in OpenMP only in %<declare simd%>"
6457 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6458 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6460 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6463 error_at (OMP_CLAUSE_LOCATION (c
),
6464 "%qD is not a variable in clause %qs", t
,
6465 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6467 error_at (OMP_CLAUSE_LOCATION (c
),
6468 "%qE is not a variable in clause %qs", t
,
6469 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6472 else if ((ort
== C_ORT_ACC
6473 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
6474 || (ort
== C_ORT_OMP
6475 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
6476 || (OMP_CLAUSE_CODE (c
)
6477 == OMP_CLAUSE_USE_DEVICE_ADDR
))))
6479 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
6481 error_at (OMP_CLAUSE_LOCATION (c
),
6483 ? "%qD appears more than once in reduction clauses"
6484 : "%qD appears more than once in data clauses",
6489 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
6491 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6492 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6493 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6495 error_at (OMP_CLAUSE_LOCATION (c
),
6496 "%qD appears more than once in data clauses", t
);
6499 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6500 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6502 if (ort
== C_ORT_ACC
)
6503 error_at (OMP_CLAUSE_LOCATION (c
),
6504 "%qD appears more than once in data clauses", t
);
6506 error_at (OMP_CLAUSE_LOCATION (c
),
6507 "%qD appears both in data and map clauses", t
);
6511 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6516 && TREE_CODE (t
) == FIELD_DECL
6517 && t
== OMP_CLAUSE_DECL (c
)
6518 && ort
!= C_ORT_ACC
)
6521 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
6522 == OMP_CLAUSE_SHARED
));
6523 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
6528 case OMP_CLAUSE_FIRSTPRIVATE
:
6529 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6531 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6533 t
= OMP_CLAUSE_DECL (c
);
6534 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6536 error_at (OMP_CLAUSE_LOCATION (c
),
6537 "%<this%> allowed in OpenMP only in %<declare simd%>"
6542 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6543 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6544 || TREE_CODE (t
) != FIELD_DECL
))
6546 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6549 error_at (OMP_CLAUSE_LOCATION (c
),
6550 "%qD is not a variable in clause %<firstprivate%>",
6553 error_at (OMP_CLAUSE_LOCATION (c
),
6554 "%qE is not a variable in clause %<firstprivate%>",
6558 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6559 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6561 error_at (OMP_CLAUSE_LOCATION (c
),
6562 "%qD appears more than once in data clauses", t
);
6565 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6567 if (ort
== C_ORT_ACC
)
6568 error_at (OMP_CLAUSE_LOCATION (c
),
6569 "%qD appears more than once in data clauses", t
);
6571 error_at (OMP_CLAUSE_LOCATION (c
),
6572 "%qD appears both in data and map clauses", t
);
6576 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
6577 goto handle_field_decl
;
6579 case OMP_CLAUSE_LASTPRIVATE
:
6580 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6582 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6584 t
= OMP_CLAUSE_DECL (c
);
6585 if (t
== current_class_ptr
)
6587 error_at (OMP_CLAUSE_LOCATION (c
),
6588 "%<this%> allowed in OpenMP only in %<declare simd%>"
6593 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6594 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6595 || TREE_CODE (t
) != FIELD_DECL
))
6597 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6600 error_at (OMP_CLAUSE_LOCATION (c
),
6601 "%qD is not a variable in clause %<lastprivate%>",
6604 error_at (OMP_CLAUSE_LOCATION (c
),
6605 "%qE is not a variable in clause %<lastprivate%>",
6609 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6610 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6612 error_at (OMP_CLAUSE_LOCATION (c
),
6613 "%qD appears more than once in data clauses", t
);
6617 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
6618 goto handle_field_decl
;
6621 t
= OMP_CLAUSE_IF_EXPR (c
);
6622 t
= maybe_convert_cond (t
);
6623 if (t
== error_mark_node
)
6625 else if (!processing_template_decl
)
6626 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6627 OMP_CLAUSE_IF_EXPR (c
) = t
;
6630 case OMP_CLAUSE_FINAL
:
6631 t
= OMP_CLAUSE_FINAL_EXPR (c
);
6632 t
= maybe_convert_cond (t
);
6633 if (t
== error_mark_node
)
6635 else if (!processing_template_decl
)
6636 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6637 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
6640 case OMP_CLAUSE_GANG
:
6641 /* Operand 1 is the gang static: argument. */
6642 t
= OMP_CLAUSE_OPERAND (c
, 1);
6645 if (t
== error_mark_node
)
6647 else if (!type_dependent_expression_p (t
)
6648 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6650 error_at (OMP_CLAUSE_LOCATION (c
),
6651 "%<gang%> static expression must be integral");
6656 t
= mark_rvalue_use (t
);
6657 if (!processing_template_decl
)
6659 t
= maybe_constant_value (t
);
6660 if (TREE_CODE (t
) == INTEGER_CST
6661 && tree_int_cst_sgn (t
) != 1
6662 && t
!= integer_minus_one_node
)
6664 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6665 "%<gang%> static value must be "
6667 t
= integer_one_node
;
6669 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6672 OMP_CLAUSE_OPERAND (c
, 1) = t
;
6674 /* Check operand 0, the num argument. */
6677 case OMP_CLAUSE_WORKER
:
6678 case OMP_CLAUSE_VECTOR
:
6679 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
6683 case OMP_CLAUSE_NUM_TASKS
:
6684 case OMP_CLAUSE_NUM_TEAMS
:
6685 case OMP_CLAUSE_NUM_THREADS
:
6686 case OMP_CLAUSE_NUM_GANGS
:
6687 case OMP_CLAUSE_NUM_WORKERS
:
6688 case OMP_CLAUSE_VECTOR_LENGTH
:
6689 t
= OMP_CLAUSE_OPERAND (c
, 0);
6690 if (t
== error_mark_node
)
6692 else if (!type_dependent_expression_p (t
)
6693 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6695 switch (OMP_CLAUSE_CODE (c
))
6697 case OMP_CLAUSE_GANG
:
6698 error_at (OMP_CLAUSE_LOCATION (c
),
6699 "%<gang%> num expression must be integral"); break;
6700 case OMP_CLAUSE_VECTOR
:
6701 error_at (OMP_CLAUSE_LOCATION (c
),
6702 "%<vector%> length expression must be integral");
6704 case OMP_CLAUSE_WORKER
:
6705 error_at (OMP_CLAUSE_LOCATION (c
),
6706 "%<worker%> num expression must be integral");
6709 error_at (OMP_CLAUSE_LOCATION (c
),
6710 "%qs expression must be integral",
6711 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6717 t
= mark_rvalue_use (t
);
6718 if (!processing_template_decl
)
6720 t
= maybe_constant_value (t
);
6721 if (TREE_CODE (t
) == INTEGER_CST
6722 && tree_int_cst_sgn (t
) != 1)
6724 switch (OMP_CLAUSE_CODE (c
))
6726 case OMP_CLAUSE_GANG
:
6727 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6728 "%<gang%> num value must be positive");
6730 case OMP_CLAUSE_VECTOR
:
6731 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6732 "%<vector%> length value must be "
6735 case OMP_CLAUSE_WORKER
:
6736 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6737 "%<worker%> num value must be "
6741 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6742 "%qs value must be positive",
6743 omp_clause_code_name
6744 [OMP_CLAUSE_CODE (c
)]);
6746 t
= integer_one_node
;
6748 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6750 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6754 case OMP_CLAUSE_SCHEDULE
:
6755 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
6758 else if (t
== error_mark_node
)
6760 else if (!type_dependent_expression_p (t
)
6761 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6763 error_at (OMP_CLAUSE_LOCATION (c
),
6764 "schedule chunk size expression must be integral");
6769 t
= mark_rvalue_use (t
);
6770 if (!processing_template_decl
)
6772 t
= maybe_constant_value (t
);
6773 if (TREE_CODE (t
) == INTEGER_CST
6774 && tree_int_cst_sgn (t
) != 1)
6776 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6777 "chunk size value must be positive");
6778 t
= integer_one_node
;
6780 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6782 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
6785 schedule_seen
= true;
6788 case OMP_CLAUSE_SIMDLEN
:
6789 case OMP_CLAUSE_SAFELEN
:
6790 t
= OMP_CLAUSE_OPERAND (c
, 0);
6791 if (t
== error_mark_node
)
6793 else if (!type_dependent_expression_p (t
)
6794 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6796 error_at (OMP_CLAUSE_LOCATION (c
),
6797 "%qs length expression must be integral",
6798 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6803 t
= mark_rvalue_use (t
);
6804 if (!processing_template_decl
)
6806 t
= maybe_constant_value (t
);
6807 if (TREE_CODE (t
) != INTEGER_CST
6808 || tree_int_cst_sgn (t
) != 1)
6810 error_at (OMP_CLAUSE_LOCATION (c
),
6811 "%qs length expression must be positive "
6812 "constant integer expression",
6813 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6817 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6818 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
6823 case OMP_CLAUSE_ASYNC
:
6824 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
6825 if (t
== error_mark_node
)
6827 else if (!type_dependent_expression_p (t
)
6828 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6830 error_at (OMP_CLAUSE_LOCATION (c
),
6831 "%<async%> expression must be integral");
6836 t
= mark_rvalue_use (t
);
6837 if (!processing_template_decl
)
6838 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6839 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
6843 case OMP_CLAUSE_WAIT
:
6844 t
= OMP_CLAUSE_WAIT_EXPR (c
);
6845 if (t
== error_mark_node
)
6847 else if (!processing_template_decl
)
6848 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6849 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
6852 case OMP_CLAUSE_THREAD_LIMIT
:
6853 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
6854 if (t
== error_mark_node
)
6856 else if (!type_dependent_expression_p (t
)
6857 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6859 error_at (OMP_CLAUSE_LOCATION (c
),
6860 "%<thread_limit%> expression must be integral");
6865 t
= mark_rvalue_use (t
);
6866 if (!processing_template_decl
)
6868 t
= maybe_constant_value (t
);
6869 if (TREE_CODE (t
) == INTEGER_CST
6870 && tree_int_cst_sgn (t
) != 1)
6872 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6873 "%<thread_limit%> value must be positive");
6874 t
= integer_one_node
;
6876 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6878 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
6882 case OMP_CLAUSE_DEVICE
:
6883 t
= OMP_CLAUSE_DEVICE_ID (c
);
6884 if (t
== error_mark_node
)
6886 else if (!type_dependent_expression_p (t
)
6887 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6889 error_at (OMP_CLAUSE_LOCATION (c
),
6890 "%<device%> id must be integral");
6895 t
= mark_rvalue_use (t
);
6896 if (!processing_template_decl
)
6897 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6898 OMP_CLAUSE_DEVICE_ID (c
) = t
;
6902 case OMP_CLAUSE_DIST_SCHEDULE
:
6903 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
6906 else if (t
== error_mark_node
)
6908 else if (!type_dependent_expression_p (t
)
6909 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6911 error_at (OMP_CLAUSE_LOCATION (c
),
6912 "%<dist_schedule%> chunk size expression must be "
6918 t
= mark_rvalue_use (t
);
6919 if (!processing_template_decl
)
6920 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6921 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
6925 case OMP_CLAUSE_ALIGNED
:
6926 t
= OMP_CLAUSE_DECL (c
);
6927 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
6929 error_at (OMP_CLAUSE_LOCATION (c
),
6930 "%<this%> allowed in OpenMP only in %<declare simd%>"
6935 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6937 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6940 error_at (OMP_CLAUSE_LOCATION (c
),
6941 "%qD is not a variable in %<aligned%> clause", t
);
6943 error_at (OMP_CLAUSE_LOCATION (c
),
6944 "%qE is not a variable in %<aligned%> clause", t
);
6947 else if (!type_dependent_expression_p (t
)
6948 && !TYPE_PTR_P (TREE_TYPE (t
))
6949 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
6950 && (!TYPE_REF_P (TREE_TYPE (t
))
6951 || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
6952 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
6955 error_at (OMP_CLAUSE_LOCATION (c
),
6956 "%qE in %<aligned%> clause is neither a pointer nor "
6957 "an array nor a reference to pointer or array", t
);
6960 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
6962 error_at (OMP_CLAUSE_LOCATION (c
),
6963 "%qD appears more than once in %<aligned%> clauses",
6968 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
6969 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
6970 if (t
== error_mark_node
)
6972 else if (t
== NULL_TREE
)
6974 else if (!type_dependent_expression_p (t
)
6975 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6977 error_at (OMP_CLAUSE_LOCATION (c
),
6978 "%<aligned%> clause alignment expression must "
6984 t
= mark_rvalue_use (t
);
6985 if (!processing_template_decl
)
6987 t
= maybe_constant_value (t
);
6988 if (TREE_CODE (t
) != INTEGER_CST
6989 || tree_int_cst_sgn (t
) != 1)
6991 error_at (OMP_CLAUSE_LOCATION (c
),
6992 "%<aligned%> clause alignment expression must "
6993 "be positive constant integer expression");
6997 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6999 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
7003 case OMP_CLAUSE_NONTEMPORAL
:
7004 t
= OMP_CLAUSE_DECL (c
);
7005 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7007 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7010 error_at (OMP_CLAUSE_LOCATION (c
),
7011 "%qD is not a variable in %<nontemporal%> clause",
7014 error_at (OMP_CLAUSE_LOCATION (c
),
7015 "%qE is not a variable in %<nontemporal%> clause",
7019 else if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
7021 error_at (OMP_CLAUSE_LOCATION (c
),
7022 "%qD appears more than once in %<nontemporal%> "
7027 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
7030 case OMP_CLAUSE_DEPEND
:
7031 t
= OMP_CLAUSE_DECL (c
);
7034 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
7035 == OMP_CLAUSE_DEPEND_SOURCE
);
7038 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
7040 if (cp_finish_omp_clause_depend_sink (c
))
7044 if (TREE_CODE (t
) == TREE_LIST
7046 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
7048 if (TREE_PURPOSE (t
) != last_iterators
)
7049 last_iterators_remove
7050 = cp_omp_finish_iterators (TREE_PURPOSE (t
));
7051 last_iterators
= TREE_PURPOSE (t
);
7053 if (last_iterators_remove
)
7054 t
= error_mark_node
;
7057 last_iterators
= NULL_TREE
;
7059 if (TREE_CODE (t
) == TREE_LIST
)
7061 if (handle_omp_array_sections (c
, ort
))
7063 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7065 error_at (OMP_CLAUSE_LOCATION (c
),
7066 "%<depend%> clause with %<depobj%> dependence "
7067 "type on array section");
7072 if (t
== error_mark_node
)
7074 else if (t
== current_class_ptr
)
7076 error_at (OMP_CLAUSE_LOCATION (c
),
7077 "%<this%> allowed in OpenMP only in %<declare simd%>"
7081 else if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7083 else if (!lvalue_p (t
))
7086 error_at (OMP_CLAUSE_LOCATION (c
),
7087 "%qD is not lvalue expression nor array section "
7088 "in %<depend%> clause", t
);
7090 error_at (OMP_CLAUSE_LOCATION (c
),
7091 "%qE is not lvalue expression nor array section "
7092 "in %<depend%> clause", t
);
7095 else if (TREE_CODE (t
) == COMPONENT_REF
7096 && TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7097 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7099 error_at (OMP_CLAUSE_LOCATION (c
),
7100 "bit-field %qE in %qs clause", t
, "depend");
7103 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7105 if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7106 ? TREE_TYPE (TREE_TYPE (t
))
7109 error_at (OMP_CLAUSE_LOCATION (c
),
7110 "%qE does not have %<omp_depend_t%> type in "
7111 "%<depend%> clause with %<depobj%> dependence "
7116 else if (c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7117 ? TREE_TYPE (TREE_TYPE (t
))
7120 error_at (OMP_CLAUSE_LOCATION (c
),
7121 "%qE should not have %<omp_depend_t%> type in "
7122 "%<depend%> clause with dependence type other than "
7128 tree addr
= cp_build_addr_expr (t
, tf_warning_or_error
);
7129 if (addr
== error_mark_node
)
7133 t
= cp_build_indirect_ref (addr
, RO_UNARY_STAR
,
7134 tf_warning_or_error
);
7135 if (t
== error_mark_node
)
7137 else if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == TREE_LIST
7138 && TREE_PURPOSE (OMP_CLAUSE_DECL (c
))
7139 && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c
)))
7141 TREE_VALUE (OMP_CLAUSE_DECL (c
)) = t
;
7143 OMP_CLAUSE_DECL (c
) = t
;
7148 case OMP_CLAUSE_MAP
:
7150 case OMP_CLAUSE_FROM
:
7151 case OMP_CLAUSE__CACHE_
:
7152 t
= OMP_CLAUSE_DECL (c
);
7153 if (TREE_CODE (t
) == TREE_LIST
)
7155 if (handle_omp_array_sections (c
, ort
))
7159 t
= OMP_CLAUSE_DECL (c
);
7160 if (TREE_CODE (t
) != TREE_LIST
7161 && !type_dependent_expression_p (t
)
7162 && !cp_omp_mappable_type (TREE_TYPE (t
)))
7164 error_at (OMP_CLAUSE_LOCATION (c
),
7165 "array section does not have mappable type "
7167 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7168 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7171 while (TREE_CODE (t
) == ARRAY_REF
)
7172 t
= TREE_OPERAND (t
, 0);
7173 if (TREE_CODE (t
) == COMPONENT_REF
7174 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
7176 while (TREE_CODE (t
) == COMPONENT_REF
)
7177 t
= TREE_OPERAND (t
, 0);
7178 if (REFERENCE_REF_P (t
))
7179 t
= TREE_OPERAND (t
, 0);
7180 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7182 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7184 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7185 error_at (OMP_CLAUSE_LOCATION (c
),
7186 "%qD appears more than once in motion"
7188 else if (ort
== C_ORT_ACC
)
7189 error_at (OMP_CLAUSE_LOCATION (c
),
7190 "%qD appears more than once in data"
7193 error_at (OMP_CLAUSE_LOCATION (c
),
7194 "%qD appears more than once in map"
7200 bitmap_set_bit (&map_head
, DECL_UID (t
));
7201 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7207 if (t
== error_mark_node
)
7212 if (REFERENCE_REF_P (t
)
7213 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
7215 t
= TREE_OPERAND (t
, 0);
7216 OMP_CLAUSE_DECL (c
) = t
;
7218 if (TREE_CODE (t
) == COMPONENT_REF
7219 && (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
7220 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
7222 if (type_dependent_expression_p (t
))
7224 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7225 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7227 error_at (OMP_CLAUSE_LOCATION (c
),
7228 "bit-field %qE in %qs clause",
7229 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7232 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7234 error_at (OMP_CLAUSE_LOCATION (c
),
7235 "%qE does not have a mappable type in %qs clause",
7236 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7237 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7240 while (TREE_CODE (t
) == COMPONENT_REF
)
7242 if (TREE_TYPE (TREE_OPERAND (t
, 0))
7243 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
7246 error_at (OMP_CLAUSE_LOCATION (c
),
7247 "%qE is a member of a union", t
);
7251 t
= TREE_OPERAND (t
, 0);
7255 if (REFERENCE_REF_P (t
))
7256 t
= TREE_OPERAND (t
, 0);
7257 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7259 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7260 goto handle_map_references
;
7263 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7265 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7267 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7268 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7269 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
))
7272 error_at (OMP_CLAUSE_LOCATION (c
),
7273 "%qD is not a variable in %qs clause", t
,
7274 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7276 error_at (OMP_CLAUSE_LOCATION (c
),
7277 "%qE is not a variable in %qs clause", t
,
7278 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7281 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7283 error_at (OMP_CLAUSE_LOCATION (c
),
7284 "%qD is threadprivate variable in %qs clause", t
,
7285 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7288 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7290 error_at (OMP_CLAUSE_LOCATION (c
),
7291 "%<this%> allowed in OpenMP only in %<declare simd%>"
7296 else if (!processing_template_decl
7297 && !TYPE_REF_P (TREE_TYPE (t
))
7298 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
7299 || (OMP_CLAUSE_MAP_KIND (c
)
7300 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
7301 && !cxx_mark_addressable (t
))
7303 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7304 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7305 || (OMP_CLAUSE_MAP_KIND (c
)
7306 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
7307 && t
== OMP_CLAUSE_DECL (c
)
7308 && !type_dependent_expression_p (t
)
7309 && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t
))
7310 ? TREE_TYPE (TREE_TYPE (t
))
7313 error_at (OMP_CLAUSE_LOCATION (c
),
7314 "%qD does not have a mappable type in %qs clause", t
,
7315 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7316 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7319 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7320 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
7321 && !type_dependent_expression_p (t
)
7322 && !INDIRECT_TYPE_P (TREE_TYPE (t
)))
7324 error_at (OMP_CLAUSE_LOCATION (c
),
7325 "%qD is not a pointer variable", t
);
7328 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7329 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
7331 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7332 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7334 error_at (OMP_CLAUSE_LOCATION (c
),
7335 "%qD appears more than once in data clauses", t
);
7338 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7340 if (ort
== C_ORT_ACC
)
7341 error_at (OMP_CLAUSE_LOCATION (c
),
7342 "%qD appears more than once in data clauses", t
);
7344 error_at (OMP_CLAUSE_LOCATION (c
),
7345 "%qD appears both in data and map clauses", t
);
7349 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7351 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7353 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7354 error_at (OMP_CLAUSE_LOCATION (c
),
7355 "%qD appears more than once in motion clauses", t
);
7356 if (ort
== C_ORT_ACC
)
7357 error_at (OMP_CLAUSE_LOCATION (c
),
7358 "%qD appears more than once in data clauses", t
);
7360 error_at (OMP_CLAUSE_LOCATION (c
),
7361 "%qD appears more than once in map clauses", t
);
7364 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7365 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7367 if (ort
== C_ORT_ACC
)
7368 error_at (OMP_CLAUSE_LOCATION (c
),
7369 "%qD appears more than once in data clauses", t
);
7371 error_at (OMP_CLAUSE_LOCATION (c
),
7372 "%qD appears both in data and map clauses", t
);
7377 bitmap_set_bit (&map_head
, DECL_UID (t
));
7378 if (t
!= OMP_CLAUSE_DECL (c
)
7379 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
7380 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7382 handle_map_references
:
7384 && !processing_template_decl
7385 && ort
!= C_ORT_DECLARE_SIMD
7386 && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
))))
7388 t
= OMP_CLAUSE_DECL (c
);
7389 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7391 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7392 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7394 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7396 else if (OMP_CLAUSE_MAP_KIND (c
)
7397 != GOMP_MAP_FIRSTPRIVATE_POINTER
7398 && (OMP_CLAUSE_MAP_KIND (c
)
7399 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
7400 && (OMP_CLAUSE_MAP_KIND (c
)
7401 != GOMP_MAP_ALWAYS_POINTER
))
7403 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
7405 if (TREE_CODE (t
) == COMPONENT_REF
)
7406 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
7408 OMP_CLAUSE_SET_MAP_KIND (c2
,
7409 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
7410 OMP_CLAUSE_DECL (c2
) = t
;
7411 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
7412 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
7413 OMP_CLAUSE_CHAIN (c
) = c2
;
7414 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7415 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7417 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7423 case OMP_CLAUSE_TO_DECLARE
:
7424 case OMP_CLAUSE_LINK
:
7425 t
= OMP_CLAUSE_DECL (c
);
7426 if (TREE_CODE (t
) == FUNCTION_DECL
7427 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7429 else if (!VAR_P (t
))
7431 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7433 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
7434 error_at (OMP_CLAUSE_LOCATION (c
),
7435 "template %qE in clause %qs", t
,
7436 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7437 else if (really_overloaded_fn (t
))
7438 error_at (OMP_CLAUSE_LOCATION (c
),
7439 "overloaded function name %qE in clause %qs", t
,
7440 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7442 error_at (OMP_CLAUSE_LOCATION (c
),
7443 "%qE is neither a variable nor a function name "
7445 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7448 error_at (OMP_CLAUSE_LOCATION (c
),
7449 "%qE is not a variable in clause %qs", t
,
7450 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7453 else if (DECL_THREAD_LOCAL_P (t
))
7455 error_at (OMP_CLAUSE_LOCATION (c
),
7456 "%qD is threadprivate variable in %qs clause", t
,
7457 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7460 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7462 error_at (OMP_CLAUSE_LOCATION (c
),
7463 "%qD does not have a mappable type in %qs clause", t
,
7464 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7465 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7470 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
7472 error_at (OMP_CLAUSE_LOCATION (c
),
7473 "%qE appears more than once on the same "
7474 "%<declare target%> directive", t
);
7478 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7481 case OMP_CLAUSE_UNIFORM
:
7482 t
= OMP_CLAUSE_DECL (c
);
7483 if (TREE_CODE (t
) != PARM_DECL
)
7485 if (processing_template_decl
)
7488 error_at (OMP_CLAUSE_LOCATION (c
),
7489 "%qD is not an argument in %<uniform%> clause", t
);
7491 error_at (OMP_CLAUSE_LOCATION (c
),
7492 "%qE is not an argument in %<uniform%> clause", t
);
7496 /* map_head bitmap is used as uniform_head if declare_simd. */
7497 bitmap_set_bit (&map_head
, DECL_UID (t
));
7498 goto check_dup_generic
;
7500 case OMP_CLAUSE_GRAINSIZE
:
7501 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
7502 if (t
== error_mark_node
)
7504 else if (!type_dependent_expression_p (t
)
7505 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7507 error_at (OMP_CLAUSE_LOCATION (c
),
7508 "%<grainsize%> expression must be integral");
7513 t
= mark_rvalue_use (t
);
7514 if (!processing_template_decl
)
7516 t
= maybe_constant_value (t
);
7517 if (TREE_CODE (t
) == INTEGER_CST
7518 && tree_int_cst_sgn (t
) != 1)
7520 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7521 "%<grainsize%> value must be positive");
7522 t
= integer_one_node
;
7524 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7526 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
7530 case OMP_CLAUSE_PRIORITY
:
7531 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
7532 if (t
== error_mark_node
)
7534 else if (!type_dependent_expression_p (t
)
7535 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7537 error_at (OMP_CLAUSE_LOCATION (c
),
7538 "%<priority%> expression must be integral");
7543 t
= mark_rvalue_use (t
);
7544 if (!processing_template_decl
)
7546 t
= maybe_constant_value (t
);
7547 if (TREE_CODE (t
) == INTEGER_CST
7548 && tree_int_cst_sgn (t
) == -1)
7550 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7551 "%<priority%> value must be non-negative");
7552 t
= integer_one_node
;
7554 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7556 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
7560 case OMP_CLAUSE_HINT
:
7561 t
= OMP_CLAUSE_HINT_EXPR (c
);
7562 if (t
== error_mark_node
)
7564 else if (!type_dependent_expression_p (t
)
7565 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7567 error_at (OMP_CLAUSE_LOCATION (c
),
7568 "%<hint%> expression must be integral");
7573 t
= mark_rvalue_use (t
);
7574 if (!processing_template_decl
)
7576 t
= maybe_constant_value (t
);
7577 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7578 if (TREE_CODE (t
) != INTEGER_CST
)
7580 error_at (OMP_CLAUSE_LOCATION (c
),
7581 "%<hint%> expression must be constant integer "
7586 OMP_CLAUSE_HINT_EXPR (c
) = t
;
7590 case OMP_CLAUSE_IS_DEVICE_PTR
:
7591 case OMP_CLAUSE_USE_DEVICE_PTR
:
7592 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
7593 t
= OMP_CLAUSE_DECL (c
);
7594 if (!type_dependent_expression_p (t
))
7596 tree type
= TREE_TYPE (t
);
7597 if (!TYPE_PTR_P (type
)
7598 && (!TYPE_REF_P (type
) || !TYPE_PTR_P (TREE_TYPE (type
))))
7600 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
7601 && ort
== C_ORT_OMP
)
7603 error_at (OMP_CLAUSE_LOCATION (c
),
7604 "%qs variable is neither a pointer "
7605 "nor reference to pointer",
7606 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7609 else if (TREE_CODE (type
) != ARRAY_TYPE
7610 && (!TYPE_REF_P (type
)
7611 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
7613 error_at (OMP_CLAUSE_LOCATION (c
),
7614 "%qs variable is neither a pointer, nor an "
7615 "array nor reference to pointer or array",
7616 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7621 goto check_dup_generic
;
7623 case OMP_CLAUSE_USE_DEVICE_ADDR
:
7625 t
= OMP_CLAUSE_DECL (c
);
7626 if (!processing_template_decl
7627 && (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7628 && !TYPE_REF_P (TREE_TYPE (t
))
7629 && !cxx_mark_addressable (t
))
7631 goto check_dup_generic
;
7633 case OMP_CLAUSE_NOWAIT
:
7634 case OMP_CLAUSE_DEFAULT
:
7635 case OMP_CLAUSE_UNTIED
:
7636 case OMP_CLAUSE_COLLAPSE
:
7637 case OMP_CLAUSE_MERGEABLE
:
7638 case OMP_CLAUSE_PARALLEL
:
7639 case OMP_CLAUSE_FOR
:
7640 case OMP_CLAUSE_SECTIONS
:
7641 case OMP_CLAUSE_TASKGROUP
:
7642 case OMP_CLAUSE_PROC_BIND
:
7643 case OMP_CLAUSE_DEVICE_TYPE
:
7644 case OMP_CLAUSE_NOGROUP
:
7645 case OMP_CLAUSE_THREADS
:
7646 case OMP_CLAUSE_SIMD
:
7647 case OMP_CLAUSE_DEFAULTMAP
:
7648 case OMP_CLAUSE_BIND
:
7649 case OMP_CLAUSE_AUTO
:
7650 case OMP_CLAUSE_INDEPENDENT
:
7651 case OMP_CLAUSE_SEQ
:
7652 case OMP_CLAUSE_IF_PRESENT
:
7653 case OMP_CLAUSE_FINALIZE
:
7656 case OMP_CLAUSE_TILE
:
7657 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
7658 list
= TREE_CHAIN (list
))
7660 t
= TREE_VALUE (list
);
7662 if (t
== error_mark_node
)
7664 else if (!type_dependent_expression_p (t
)
7665 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7667 error_at (OMP_CLAUSE_LOCATION (c
),
7668 "%<tile%> argument needs integral type");
7673 t
= mark_rvalue_use (t
);
7674 if (!processing_template_decl
)
7676 /* Zero is used to indicate '*', we permit you
7677 to get there via an ICE of value zero. */
7678 t
= maybe_constant_value (t
);
7679 if (!tree_fits_shwi_p (t
)
7680 || tree_to_shwi (t
) < 0)
7682 error_at (OMP_CLAUSE_LOCATION (c
),
7683 "%<tile%> argument needs positive "
7684 "integral constant");
7687 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7691 /* Update list item. */
7692 TREE_VALUE (list
) = t
;
7696 case OMP_CLAUSE_ORDERED
:
7697 ordered_seen
= true;
7700 case OMP_CLAUSE_ORDER
:
7707 case OMP_CLAUSE_INBRANCH
:
7708 case OMP_CLAUSE_NOTINBRANCH
:
7711 error_at (OMP_CLAUSE_LOCATION (c
),
7712 "%<inbranch%> clause is incompatible with "
7719 case OMP_CLAUSE_INCLUSIVE
:
7720 case OMP_CLAUSE_EXCLUSIVE
:
7721 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7723 t
= OMP_CLAUSE_DECL (c
);
7724 if (t
== current_class_ptr
)
7726 error_at (OMP_CLAUSE_LOCATION (c
),
7727 "%<this%> allowed in OpenMP only in %<declare simd%>"
7733 && TREE_CODE (t
) != PARM_DECL
7734 && TREE_CODE (t
) != FIELD_DECL
)
7736 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7739 error_at (OMP_CLAUSE_LOCATION (c
),
7740 "%qD is not a variable in clause %qs", t
,
7741 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7743 error_at (OMP_CLAUSE_LOCATION (c
),
7744 "%qE is not a variable in clause %qs", t
,
7745 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7755 *pc
= OMP_CLAUSE_CHAIN (c
);
7757 pc
= &OMP_CLAUSE_CHAIN (c
);
7760 if (reduction_seen
< 0 && (ordered_seen
|| schedule_seen
))
7761 reduction_seen
= -2;
7763 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
7765 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
7766 bool remove
= false;
7767 bool need_complete_type
= false;
7768 bool need_default_ctor
= false;
7769 bool need_copy_ctor
= false;
7770 bool need_copy_assignment
= false;
7771 bool need_implicitly_determined
= false;
7772 bool need_dtor
= false;
7773 tree type
, inner_type
;
7777 case OMP_CLAUSE_SHARED
:
7778 need_implicitly_determined
= true;
7780 case OMP_CLAUSE_PRIVATE
:
7781 need_complete_type
= true;
7782 need_default_ctor
= true;
7784 need_implicitly_determined
= true;
7786 case OMP_CLAUSE_FIRSTPRIVATE
:
7787 need_complete_type
= true;
7788 need_copy_ctor
= true;
7790 need_implicitly_determined
= true;
7792 case OMP_CLAUSE_LASTPRIVATE
:
7793 need_complete_type
= true;
7794 need_copy_assignment
= true;
7795 need_implicitly_determined
= true;
7797 case OMP_CLAUSE_REDUCTION
:
7798 if (reduction_seen
== -2)
7799 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
7800 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
7801 need_copy_assignment
= true;
7802 need_implicitly_determined
= true;
7804 case OMP_CLAUSE_IN_REDUCTION
:
7805 case OMP_CLAUSE_TASK_REDUCTION
:
7806 case OMP_CLAUSE_INCLUSIVE
:
7807 case OMP_CLAUSE_EXCLUSIVE
:
7808 need_implicitly_determined
= true;
7810 case OMP_CLAUSE_LINEAR
:
7811 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
7812 need_implicitly_determined
= true;
7813 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
7814 && !bitmap_bit_p (&map_head
,
7815 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
7817 error_at (OMP_CLAUSE_LOCATION (c
),
7818 "%<linear%> clause step is a parameter %qD not "
7819 "specified in %<uniform%> clause",
7820 OMP_CLAUSE_LINEAR_STEP (c
));
7821 *pc
= OMP_CLAUSE_CHAIN (c
);
7825 case OMP_CLAUSE_COPYPRIVATE
:
7826 need_copy_assignment
= true;
7828 case OMP_CLAUSE_COPYIN
:
7829 need_copy_assignment
= true;
7831 case OMP_CLAUSE_SIMDLEN
:
7833 && !processing_template_decl
7834 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
7835 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
7837 error_at (OMP_CLAUSE_LOCATION (c
),
7838 "%<simdlen%> clause value is bigger than "
7839 "%<safelen%> clause value");
7840 OMP_CLAUSE_SIMDLEN_EXPR (c
)
7841 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
7843 pc
= &OMP_CLAUSE_CHAIN (c
);
7845 case OMP_CLAUSE_SCHEDULE
:
7847 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
7848 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
7850 error_at (OMP_CLAUSE_LOCATION (c
),
7851 "%<nonmonotonic%> schedule modifier specified "
7852 "together with %<ordered%> clause");
7853 OMP_CLAUSE_SCHEDULE_KIND (c
)
7854 = (enum omp_clause_schedule_kind
)
7855 (OMP_CLAUSE_SCHEDULE_KIND (c
)
7856 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
7858 if (reduction_seen
== -2)
7859 error_at (OMP_CLAUSE_LOCATION (c
),
7860 "%qs clause specified together with %<inscan%> "
7861 "%<reduction%> clause", "schedule");
7862 pc
= &OMP_CLAUSE_CHAIN (c
);
7864 case OMP_CLAUSE_NOGROUP
:
7867 error_at (OMP_CLAUSE_LOCATION (c
),
7868 "%<nogroup%> clause must not be used together with "
7869 "%<reduction%> clause");
7870 *pc
= OMP_CLAUSE_CHAIN (c
);
7873 pc
= &OMP_CLAUSE_CHAIN (c
);
7875 case OMP_CLAUSE_ORDERED
:
7876 if (reduction_seen
== -2)
7877 error_at (OMP_CLAUSE_LOCATION (c
),
7878 "%qs clause specified together with %<inscan%> "
7879 "%<reduction%> clause", "ordered");
7880 pc
= &OMP_CLAUSE_CHAIN (c
);
7882 case OMP_CLAUSE_ORDER
:
7885 error_at (OMP_CLAUSE_LOCATION (c
),
7886 "%<order%> clause must not be used together "
7887 "with %<ordered%>");
7888 *pc
= OMP_CLAUSE_CHAIN (c
);
7891 pc
= &OMP_CLAUSE_CHAIN (c
);
7893 case OMP_CLAUSE_NOWAIT
:
7894 if (copyprivate_seen
)
7896 error_at (OMP_CLAUSE_LOCATION (c
),
7897 "%<nowait%> clause must not be used together "
7898 "with %<copyprivate%>");
7899 *pc
= OMP_CLAUSE_CHAIN (c
);
7904 pc
= &OMP_CLAUSE_CHAIN (c
);
7908 t
= OMP_CLAUSE_DECL (c
);
7909 if (processing_template_decl
7910 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7912 pc
= &OMP_CLAUSE_CHAIN (c
);
7918 case OMP_CLAUSE_LASTPRIVATE
:
7919 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7921 need_default_ctor
= true;
7926 case OMP_CLAUSE_REDUCTION
:
7927 case OMP_CLAUSE_IN_REDUCTION
:
7928 case OMP_CLAUSE_TASK_REDUCTION
:
7929 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
7933 t
= OMP_CLAUSE_DECL (c
);
7936 case OMP_CLAUSE_COPYIN
:
7937 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
7939 error_at (OMP_CLAUSE_LOCATION (c
),
7940 "%qE must be %<threadprivate%> for %<copyin%>", t
);
7949 if (need_complete_type
|| need_copy_assignment
)
7951 t
= require_complete_type (t
);
7952 if (t
== error_mark_node
)
7954 else if (!processing_template_decl
7955 && TYPE_REF_P (TREE_TYPE (t
))
7956 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
7959 if (need_implicitly_determined
)
7961 const char *share_name
= NULL
;
7963 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7964 share_name
= "threadprivate";
7965 else switch (cxx_omp_predetermined_sharing_1 (t
))
7967 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
7969 case OMP_CLAUSE_DEFAULT_SHARED
:
7971 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
7973 && cxx_omp_const_qual_no_mutable (t
))
7975 tree ctx
= CP_DECL_CONTEXT (t
);
7976 /* const qualified static data members without mutable
7977 member may be specified in firstprivate clause. */
7978 if (TYPE_P (ctx
) && MAYBE_CLASS_TYPE_P (ctx
))
7981 share_name
= "shared";
7983 case OMP_CLAUSE_DEFAULT_PRIVATE
:
7984 share_name
= "private";
7991 error_at (OMP_CLAUSE_LOCATION (c
),
7992 "%qE is predetermined %qs for %qs",
7993 omp_clause_printable_decl (t
), share_name
,
7994 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7997 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
7998 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_FIRSTPRIVATE
7999 && cxx_omp_const_qual_no_mutable (t
))
8001 error_at (OMP_CLAUSE_LOCATION (c
),
8002 "%<const%> qualified %qE without %<mutable%> member "
8003 "may appear only in %<shared%> or %<firstprivate%> "
8004 "clauses", omp_clause_printable_decl (t
));
8009 /* We're interested in the base element, not arrays. */
8010 inner_type
= type
= TREE_TYPE (t
);
8011 if ((need_complete_type
8012 || need_copy_assignment
8013 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
8014 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
8015 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
8016 && TYPE_REF_P (inner_type
))
8017 inner_type
= TREE_TYPE (inner_type
);
8018 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
8019 inner_type
= TREE_TYPE (inner_type
);
8021 /* Check for special function availability by building a call to one.
8022 Save the results, because later we won't be in the right context
8023 for making these queries. */
8024 if (CLASS_TYPE_P (inner_type
)
8025 && COMPLETE_TYPE_P (inner_type
)
8026 && (need_default_ctor
|| need_copy_ctor
8027 || need_copy_assignment
|| need_dtor
)
8028 && !type_dependent_expression_p (t
)
8029 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
8030 need_copy_ctor
, need_copy_assignment
,
8035 && c_kind
== OMP_CLAUSE_SHARED
8036 && processing_template_decl
)
8038 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8040 OMP_CLAUSE_DECL (c
) = t
;
8044 *pc
= OMP_CLAUSE_CHAIN (c
);
8046 pc
= &OMP_CLAUSE_CHAIN (c
);
8049 bitmap_obstack_release (NULL
);
8053 /* Start processing OpenMP clauses that can include any
8054 privatization clauses for non-static data members. */
8057 push_omp_privatization_clauses (bool ignore_next
)
8059 if (omp_private_member_ignore_next
)
8061 omp_private_member_ignore_next
= ignore_next
;
8064 omp_private_member_ignore_next
= ignore_next
;
8065 if (omp_private_member_map
)
8066 omp_private_member_vec
.safe_push (error_mark_node
);
8067 return push_stmt_list ();
8070 /* Revert remapping of any non-static data members since
8071 the last push_omp_privatization_clauses () call. */
8074 pop_omp_privatization_clauses (tree stmt
)
8076 if (stmt
== NULL_TREE
)
8078 stmt
= pop_stmt_list (stmt
);
8079 if (omp_private_member_map
)
8081 while (!omp_private_member_vec
.is_empty ())
8083 tree t
= omp_private_member_vec
.pop ();
8084 if (t
== error_mark_node
)
8089 bool no_decl_expr
= t
== integer_zero_node
;
8091 t
= omp_private_member_vec
.pop ();
8092 tree
*v
= omp_private_member_map
->get (t
);
8096 omp_private_member_map
->remove (t
);
8098 delete omp_private_member_map
;
8099 omp_private_member_map
= NULL
;
8104 /* Remember OpenMP privatization clauses mapping and clear it.
8105 Used for lambdas. */
8108 save_omp_privatization_clauses (vec
<tree
> &save
)
8111 if (omp_private_member_ignore_next
)
8112 save
.safe_push (integer_one_node
);
8113 omp_private_member_ignore_next
= false;
8114 if (!omp_private_member_map
)
8117 while (!omp_private_member_vec
.is_empty ())
8119 tree t
= omp_private_member_vec
.pop ();
8120 if (t
== error_mark_node
)
8126 if (t
== integer_zero_node
)
8127 t
= omp_private_member_vec
.pop ();
8128 tree
*v
= omp_private_member_map
->get (t
);
8130 save
.safe_push (*v
);
8135 delete omp_private_member_map
;
8136 omp_private_member_map
= NULL
;
8139 /* Restore OpenMP privatization clauses mapping saved by the
8143 restore_omp_privatization_clauses (vec
<tree
> &save
)
8145 gcc_assert (omp_private_member_vec
.is_empty ());
8146 omp_private_member_ignore_next
= false;
8147 if (save
.is_empty ())
8149 if (save
.length () == 1 && save
[0] == integer_one_node
)
8151 omp_private_member_ignore_next
= true;
8156 omp_private_member_map
= new hash_map
<tree
, tree
>;
8157 while (!save
.is_empty ())
8159 tree t
= save
.pop ();
8161 if (t
!= error_mark_node
)
8163 if (t
== integer_one_node
)
8165 omp_private_member_ignore_next
= true;
8166 gcc_assert (save
.is_empty ());
8169 if (t
== integer_zero_node
)
8171 tree
&v
= omp_private_member_map
->get_or_insert (t
);
8174 omp_private_member_vec
.safe_push (t
);
8176 omp_private_member_vec
.safe_push (n
);
8181 /* For all variables in the tree_list VARS, mark them as thread local. */
8184 finish_omp_threadprivate (tree vars
)
8188 /* Mark every variable in VARS to be assigned thread local storage. */
8189 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8191 tree v
= TREE_PURPOSE (t
);
8193 if (error_operand_p (v
))
8195 else if (!VAR_P (v
))
8196 error ("%<threadprivate%> %qD is not file, namespace "
8197 "or block scope variable", v
);
8198 /* If V had already been marked threadprivate, it doesn't matter
8199 whether it had been used prior to this point. */
8200 else if (TREE_USED (v
)
8201 && (DECL_LANG_SPECIFIC (v
) == NULL
8202 || !CP_DECL_THREADPRIVATE_P (v
)))
8203 error ("%qE declared %<threadprivate%> after first use", v
);
8204 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8205 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8206 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
8207 error ("%<threadprivate%> %qE has incomplete type", v
);
8208 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
8209 && CP_DECL_CONTEXT (v
) != current_class_type
)
8210 error ("%<threadprivate%> %qE directive not "
8211 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
8214 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
8215 if (DECL_LANG_SPECIFIC (v
) == NULL
)
8216 retrofit_lang_decl (v
);
8218 if (! CP_DECL_THREAD_LOCAL_P (v
))
8220 CP_DECL_THREAD_LOCAL_P (v
) = true;
8221 set_decl_tls_model (v
, decl_default_tls_model (v
));
8222 /* If rtl has been already set for this var, call
8223 make_decl_rtl once again, so that encode_section_info
8224 has a chance to look at the new decl flags. */
8225 if (DECL_RTL_SET_P (v
))
8228 CP_DECL_THREADPRIVATE_P (v
) = 1;
8233 /* Build an OpenMP structured block. */
8236 begin_omp_structured_block (void)
8238 return do_pushlevel (sk_omp
);
8242 finish_omp_structured_block (tree block
)
8244 return do_poplevel (block
);
8247 /* Similarly, except force the retention of the BLOCK. */
8250 begin_omp_parallel (void)
8252 keep_next_level (true);
8253 return begin_omp_structured_block ();
8256 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
8260 finish_oacc_data (tree clauses
, tree block
)
8264 block
= finish_omp_structured_block (block
);
8266 stmt
= make_node (OACC_DATA
);
8267 TREE_TYPE (stmt
) = void_type_node
;
8268 OACC_DATA_CLAUSES (stmt
) = clauses
;
8269 OACC_DATA_BODY (stmt
) = block
;
8271 return add_stmt (stmt
);
8274 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
8278 finish_oacc_host_data (tree clauses
, tree block
)
8282 block
= finish_omp_structured_block (block
);
8284 stmt
= make_node (OACC_HOST_DATA
);
8285 TREE_TYPE (stmt
) = void_type_node
;
8286 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
8287 OACC_HOST_DATA_BODY (stmt
) = block
;
8289 return add_stmt (stmt
);
8292 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
8296 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
8298 body
= finish_omp_structured_block (body
);
8300 tree stmt
= make_node (code
);
8301 TREE_TYPE (stmt
) = void_type_node
;
8302 OMP_BODY (stmt
) = body
;
8303 OMP_CLAUSES (stmt
) = clauses
;
8305 return add_stmt (stmt
);
8309 finish_omp_parallel (tree clauses
, tree body
)
8313 body
= finish_omp_structured_block (body
);
8315 stmt
= make_node (OMP_PARALLEL
);
8316 TREE_TYPE (stmt
) = void_type_node
;
8317 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
8318 OMP_PARALLEL_BODY (stmt
) = body
;
8320 return add_stmt (stmt
);
8324 begin_omp_task (void)
8326 keep_next_level (true);
8327 return begin_omp_structured_block ();
8331 finish_omp_task (tree clauses
, tree body
)
8335 body
= finish_omp_structured_block (body
);
8337 stmt
= make_node (OMP_TASK
);
8338 TREE_TYPE (stmt
) = void_type_node
;
8339 OMP_TASK_CLAUSES (stmt
) = clauses
;
8340 OMP_TASK_BODY (stmt
) = body
;
8342 return add_stmt (stmt
);
8345 /* Helper function for finish_omp_for. Convert Ith random access iterator
8346 into integral iterator. Return FALSE if successful. */
8349 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
8350 tree declv
, tree orig_declv
, tree initv
,
8351 tree condv
, tree incrv
, tree
*body
,
8352 tree
*pre_body
, tree
&clauses
,
8353 int collapse
, int ordered
)
8355 tree diff
, iter_init
, iter_incr
= NULL
, last
;
8356 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
8357 tree decl
= TREE_VEC_ELT (declv
, i
);
8358 tree init
= TREE_VEC_ELT (initv
, i
);
8359 tree cond
= TREE_VEC_ELT (condv
, i
);
8360 tree incr
= TREE_VEC_ELT (incrv
, i
);
8362 location_t elocus
= locus
;
8364 if (init
&& EXPR_HAS_LOCATION (init
))
8365 elocus
= EXPR_LOCATION (init
);
8367 cond
= cp_fully_fold (cond
);
8368 switch (TREE_CODE (cond
))
8375 if (TREE_OPERAND (cond
, 1) == iter
)
8376 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
8377 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
8378 if (TREE_OPERAND (cond
, 0) != iter
)
8379 cond
= error_mark_node
;
8382 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
8385 TREE_OPERAND (cond
, 1), ERROR_MARK
,
8386 NULL
, tf_warning_or_error
);
8387 if (error_operand_p (tem
))
8392 cond
= error_mark_node
;
8395 if (cond
== error_mark_node
)
8397 error_at (elocus
, "invalid controlling predicate");
8400 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
8401 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
8402 tf_warning_or_error
);
8403 diff
= cp_fully_fold (diff
);
8404 if (error_operand_p (diff
))
8406 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
8408 error_at (elocus
, "difference between %qE and %qD does not have integer type",
8409 TREE_OPERAND (cond
, 1), iter
);
8412 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
,
8413 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
8414 cond
, cp_walk_subtrees
))
8417 switch (TREE_CODE (incr
))
8419 case PREINCREMENT_EXPR
:
8420 case PREDECREMENT_EXPR
:
8421 case POSTINCREMENT_EXPR
:
8422 case POSTDECREMENT_EXPR
:
8423 if (TREE_OPERAND (incr
, 0) != iter
)
8425 incr
= error_mark_node
;
8428 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
8429 TREE_CODE (incr
), iter
,
8430 tf_warning_or_error
);
8431 if (error_operand_p (iter_incr
))
8433 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
8434 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
8435 incr
= integer_one_node
;
8437 incr
= integer_minus_one_node
;
8440 if (TREE_OPERAND (incr
, 0) != iter
)
8441 incr
= error_mark_node
;
8442 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
8443 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
8445 tree rhs
= TREE_OPERAND (incr
, 1);
8446 if (TREE_OPERAND (rhs
, 0) == iter
)
8448 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
8450 incr
= error_mark_node
;
8453 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8454 iter
, TREE_CODE (rhs
),
8455 TREE_OPERAND (rhs
, 1),
8456 tf_warning_or_error
);
8457 if (error_operand_p (iter_incr
))
8459 incr
= TREE_OPERAND (rhs
, 1);
8460 incr
= cp_convert (TREE_TYPE (diff
), incr
,
8461 tf_warning_or_error
);
8462 if (TREE_CODE (rhs
) == MINUS_EXPR
)
8464 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
8465 incr
= fold_simple (incr
);
8467 if (TREE_CODE (incr
) != INTEGER_CST
8468 && (TREE_CODE (incr
) != NOP_EXPR
8469 || (TREE_CODE (TREE_OPERAND (incr
, 0))
8474 else if (TREE_OPERAND (rhs
, 1) == iter
)
8476 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
8477 || TREE_CODE (rhs
) != PLUS_EXPR
)
8478 incr
= error_mark_node
;
8481 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
8483 TREE_OPERAND (rhs
, 0),
8486 tf_warning_or_error
);
8487 if (error_operand_p (iter_incr
))
8489 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8492 tf_warning_or_error
);
8493 if (error_operand_p (iter_incr
))
8495 incr
= TREE_OPERAND (rhs
, 0);
8500 incr
= error_mark_node
;
8503 incr
= error_mark_node
;
8506 incr
= error_mark_node
;
8510 if (incr
== error_mark_node
)
8512 error_at (elocus
, "invalid increment expression");
8516 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
8517 incr
= cp_fully_fold (incr
);
8518 tree loop_iv_seen
= NULL_TREE
;
8519 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8520 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
8521 && OMP_CLAUSE_DECL (c
) == iter
)
8523 if (code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
8526 OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
) = 1;
8530 else if ((code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
8531 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
8532 && OMP_CLAUSE_DECL (c
) == iter
)
8535 if (code
== OMP_TASKLOOP
)
8536 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
8539 decl
= create_temporary_var (TREE_TYPE (diff
));
8541 add_decl_expr (decl
);
8542 last
= create_temporary_var (TREE_TYPE (diff
));
8544 add_decl_expr (last
);
8545 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
8546 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
8548 incr_var
= create_temporary_var (TREE_TYPE (diff
));
8549 pushdecl (incr_var
);
8550 add_decl_expr (incr_var
);
8552 gcc_assert (stmts_are_full_exprs_p ());
8553 tree diffvar
= NULL_TREE
;
8554 if (code
== OMP_TASKLOOP
)
8558 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
8559 OMP_CLAUSE_DECL (ivc
) = iter
;
8560 cxx_omp_finish_clause (ivc
, NULL
);
8561 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
8564 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
8565 OMP_CLAUSE_DECL (lvc
) = last
;
8566 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
8568 diffvar
= create_temporary_var (TREE_TYPE (diff
));
8570 add_decl_expr (diffvar
);
8572 else if (code
== OMP_LOOP
)
8576 /* While iterators on the loop construct are predetermined
8577 lastprivate, if the decl is not declared inside of the
8578 loop, OMP_CLAUSE_LASTPRIVATE should have been added
8580 loop_iv_seen
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
8581 OMP_CLAUSE_DECL (loop_iv_seen
) = iter
;
8582 OMP_CLAUSE_CHAIN (loop_iv_seen
) = clauses
;
8583 clauses
= loop_iv_seen
;
8585 else if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_PRIVATE
)
8587 OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen
) = 0;
8588 OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen
) = 0;
8589 OMP_CLAUSE_CODE (loop_iv_seen
) = OMP_CLAUSE_FIRSTPRIVATE
;
8591 if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_FIRSTPRIVATE
)
8592 cxx_omp_finish_clause (loop_iv_seen
, NULL
);
8595 orig_pre_body
= *pre_body
;
8596 *pre_body
= push_stmt_list ();
8598 add_stmt (orig_pre_body
);
8600 finish_expr_stmt (build_x_modify_expr (elocus
,
8601 iter
, NOP_EXPR
, init
,
8602 tf_warning_or_error
));
8603 init
= build_int_cst (TREE_TYPE (diff
), 0);
8604 if (c
&& iter_incr
== NULL
8605 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
8609 finish_expr_stmt (build_x_modify_expr (elocus
,
8611 incr
, tf_warning_or_error
));
8614 iter_incr
= build_x_modify_expr (elocus
,
8615 iter
, PLUS_EXPR
, incr
,
8616 tf_warning_or_error
);
8618 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
8620 finish_expr_stmt (build_x_modify_expr (elocus
,
8621 last
, NOP_EXPR
, init
,
8622 tf_warning_or_error
));
8625 finish_expr_stmt (build_x_modify_expr (elocus
,
8627 diff
, tf_warning_or_error
));
8630 *pre_body
= pop_stmt_list (*pre_body
);
8632 cond
= cp_build_binary_op (elocus
,
8633 TREE_CODE (cond
), decl
, diff
,
8634 tf_warning_or_error
);
8635 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
8636 elocus
, incr
, NULL_TREE
);
8639 *body
= push_stmt_list ();
8640 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
8641 iter_init
= build_x_modify_expr (elocus
,
8642 iter
, PLUS_EXPR
, iter_init
,
8643 tf_warning_or_error
);
8644 if (iter_init
!= error_mark_node
)
8645 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
8646 finish_expr_stmt (iter_init
);
8647 finish_expr_stmt (build_x_modify_expr (elocus
,
8648 last
, NOP_EXPR
, decl
,
8649 tf_warning_or_error
));
8650 add_stmt (orig_body
);
8651 *body
= pop_stmt_list (*body
);
8655 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
8657 finish_expr_stmt (iter_incr
);
8661 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
8662 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
8663 iter_init
, iter_incr
);
8664 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
8665 iter_init
= build_x_modify_expr (elocus
,
8666 iter
, PLUS_EXPR
, iter_init
,
8667 tf_warning_or_error
);
8668 if (iter_init
!= error_mark_node
)
8669 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
8670 finish_expr_stmt (iter_init
);
8672 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
8673 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
8676 if (TREE_CODE (TREE_VEC_ELT (orig_declv
, i
)) == TREE_LIST
)
8678 tree t
= TREE_VEC_ELT (orig_declv
, i
);
8679 gcc_assert (TREE_PURPOSE (t
) == NULL_TREE
8680 && TREE_VALUE (t
) == NULL_TREE
8681 && TREE_CODE (TREE_CHAIN (t
)) == TREE_VEC
);
8682 TREE_PURPOSE (t
) = TREE_VEC_ELT (declv
, i
);
8683 TREE_VALUE (t
) = last
;
8686 TREE_VEC_ELT (orig_declv
, i
)
8687 = tree_cons (TREE_VEC_ELT (declv
, i
), last
, NULL_TREE
);
8688 TREE_VEC_ELT (declv
, i
) = decl
;
8689 TREE_VEC_ELT (initv
, i
) = init
;
8690 TREE_VEC_ELT (condv
, i
) = cond
;
8691 TREE_VEC_ELT (incrv
, i
) = incr
;
8696 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
8697 are directly for their associated operands in the statement. DECL
8698 and INIT are a combo; if DECL is NULL then INIT ought to be a
8699 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
8700 optional statements that need to go before the loop into its
8704 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
8705 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
8706 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
8708 tree omp_for
= NULL
, orig_incr
= NULL
;
8709 tree decl
= NULL
, init
, cond
, incr
;
8715 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
8716 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
8717 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
8718 if (TREE_VEC_LENGTH (declv
) > 1)
8722 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
8724 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
8727 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
8729 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
8730 if (collapse
!= TREE_VEC_LENGTH (declv
))
8731 ordered
= TREE_VEC_LENGTH (declv
);
8734 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8736 decl
= TREE_VEC_ELT (declv
, i
);
8737 init
= TREE_VEC_ELT (initv
, i
);
8738 cond
= TREE_VEC_ELT (condv
, i
);
8739 incr
= TREE_VEC_ELT (incrv
, i
);
8745 switch (TREE_CODE (init
))
8748 decl
= TREE_OPERAND (init
, 0);
8749 init
= TREE_OPERAND (init
, 1);
8752 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
8754 decl
= TREE_OPERAND (init
, 0);
8755 init
= TREE_OPERAND (init
, 2);
8765 "expected iteration declaration or initialization");
8770 if (init
&& EXPR_HAS_LOCATION (init
))
8771 elocus
= EXPR_LOCATION (init
);
8773 if (cond
== global_namespace
)
8778 error_at (elocus
, "missing controlling predicate");
8784 error_at (elocus
, "missing increment expression");
8788 TREE_VEC_ELT (declv
, i
) = decl
;
8789 TREE_VEC_ELT (initv
, i
) = init
;
8796 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
8798 && !c_omp_check_loop_iv_exprs (locus
, orig_declv
8799 ? orig_declv
: declv
,
8800 TREE_VEC_ELT (declv
, i
), orig_init
,
8801 NULL_TREE
, cp_walk_subtrees
))
8807 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
8811 stmt
= make_node (code
);
8813 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8815 /* This is really just a place-holder. We'll be decomposing this
8816 again and going through the cp_build_modify_expr path below when
8817 we instantiate the thing. */
8818 TREE_VEC_ELT (initv
, i
)
8819 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
8820 TREE_VEC_ELT (initv
, i
));
8823 TREE_TYPE (stmt
) = void_type_node
;
8824 OMP_FOR_INIT (stmt
) = initv
;
8825 OMP_FOR_COND (stmt
) = condv
;
8826 OMP_FOR_INCR (stmt
) = incrv
;
8827 OMP_FOR_BODY (stmt
) = body
;
8828 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
8829 OMP_FOR_CLAUSES (stmt
) = clauses
;
8831 SET_EXPR_LOCATION (stmt
, locus
);
8832 return add_stmt (stmt
);
8836 orig_declv
= copy_node (declv
);
8838 if (processing_template_decl
)
8839 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
8841 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
8843 decl
= TREE_VEC_ELT (declv
, i
);
8844 init
= TREE_VEC_ELT (initv
, i
);
8845 cond
= TREE_VEC_ELT (condv
, i
);
8846 incr
= TREE_VEC_ELT (incrv
, i
);
8848 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8851 if (init
&& EXPR_HAS_LOCATION (init
))
8852 elocus
= EXPR_LOCATION (init
);
8856 error_at (elocus
, "expected iteration declaration or initialization");
8860 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
8863 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8864 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
8865 TREE_CODE (TREE_OPERAND (incr
, 1)),
8866 TREE_OPERAND (incr
, 2),
8867 tf_warning_or_error
);
8870 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
8872 if (code
== OMP_SIMD
)
8874 error_at (elocus
, "%<#pragma omp simd%> used with class "
8875 "iteration variable %qE", decl
);
8878 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
8879 initv
, condv
, incrv
, &body
,
8886 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
8887 && !TYPE_PTR_P (TREE_TYPE (decl
)))
8889 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
8893 if (!processing_template_decl
)
8895 init
= fold_build_cleanup_point_expr (TREE_TYPE (init
), init
);
8896 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
8897 tf_warning_or_error
);
8900 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
8902 && TREE_SIDE_EFFECTS (cond
)
8903 && COMPARISON_CLASS_P (cond
)
8904 && !processing_template_decl
)
8906 tree t
= TREE_OPERAND (cond
, 0);
8907 if (TREE_SIDE_EFFECTS (t
)
8909 && (TREE_CODE (t
) != NOP_EXPR
8910 || TREE_OPERAND (t
, 0) != decl
))
8911 TREE_OPERAND (cond
, 0)
8912 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8914 t
= TREE_OPERAND (cond
, 1);
8915 if (TREE_SIDE_EFFECTS (t
)
8917 && (TREE_CODE (t
) != NOP_EXPR
8918 || TREE_OPERAND (t
, 0) != decl
))
8919 TREE_OPERAND (cond
, 1)
8920 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8922 if (decl
== error_mark_node
|| init
== error_mark_node
)
8925 TREE_VEC_ELT (declv
, i
) = decl
;
8926 TREE_VEC_ELT (initv
, i
) = init
;
8927 TREE_VEC_ELT (condv
, i
) = cond
;
8928 TREE_VEC_ELT (incrv
, i
) = incr
;
8932 if (pre_body
&& IS_EMPTY_STMT (pre_body
))
8935 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
8936 incrv
, body
, pre_body
,
8937 !processing_template_decl
);
8939 /* Check for iterators appearing in lb, b or incr expressions. */
8940 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
8941 omp_for
= NULL_TREE
;
8943 if (omp_for
== NULL
)
8948 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
8950 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
), 0);
8951 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
8953 if (TREE_CODE (incr
) != MODIFY_EXPR
)
8956 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
8957 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
8958 && !processing_template_decl
)
8960 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
8961 if (TREE_SIDE_EFFECTS (t
)
8963 && (TREE_CODE (t
) != NOP_EXPR
8964 || TREE_OPERAND (t
, 0) != decl
))
8965 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
8966 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8968 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8969 if (TREE_SIDE_EFFECTS (t
)
8971 && (TREE_CODE (t
) != NOP_EXPR
8972 || TREE_OPERAND (t
, 0) != decl
))
8973 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8974 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8978 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
8980 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8982 /* For simd loops with non-static data member iterators, we could have added
8983 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
8984 step at this point, fill it in. */
8985 if (code
== OMP_SIMD
&& !processing_template_decl
8986 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
8987 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
8988 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
8989 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
8991 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
8992 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
8993 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8995 switch (TREE_CODE (incr
))
8997 case PREINCREMENT_EXPR
:
8998 case POSTINCREMENT_EXPR
:
8999 /* c_omp_for_incr_canonicalize_ptr() should have been
9000 called to massage things appropriately. */
9001 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9002 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
9004 case PREDECREMENT_EXPR
:
9005 case POSTDECREMENT_EXPR
:
9006 /* c_omp_for_incr_canonicalize_ptr() should have been
9007 called to massage things appropriately. */
9008 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9009 OMP_CLAUSE_LINEAR_STEP (c
)
9010 = build_int_cst (TREE_TYPE (decl
), -1);
9013 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9014 incr
= TREE_OPERAND (incr
, 1);
9015 switch (TREE_CODE (incr
))
9018 if (TREE_OPERAND (incr
, 1) == decl
)
9019 step
= TREE_OPERAND (incr
, 0);
9021 step
= TREE_OPERAND (incr
, 1);
9024 case POINTER_PLUS_EXPR
:
9025 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9026 step
= TREE_OPERAND (incr
, 1);
9031 stept
= TREE_TYPE (decl
);
9032 if (INDIRECT_TYPE_P (stept
))
9034 step
= fold_convert (stept
, step
);
9035 if (TREE_CODE (incr
) == MINUS_EXPR
)
9036 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
9037 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
9043 /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
9044 clauses, we need copy ctor for those rather than default ctor,
9045 plus as for other lastprivates assignment op and dtor. */
9046 if (code
== OMP_LOOP
&& !processing_template_decl
)
9047 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9048 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9049 && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
)
9050 && cxx_omp_create_clause_info (c
, TREE_TYPE (OMP_CLAUSE_DECL (c
)),
9051 false, true, true, true))
9052 CP_OMP_CLAUSE_INFO (c
) = NULL_TREE
;
9057 /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS
9058 and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */
9061 finish_omp_for_block (tree bind
, tree omp_for
)
9063 if (omp_for
== NULL_TREE
9064 || !OMP_FOR_ORIG_DECLS (omp_for
)
9065 || bind
== NULL_TREE
9066 || TREE_CODE (bind
) != BIND_EXPR
)
9069 for (int i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for
)); i
++)
9070 if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)) == TREE_LIST
9071 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)))
9073 tree v
= TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
));
9074 gcc_assert (BIND_EXPR_BLOCK (bind
)
9075 && (BIND_EXPR_VARS (bind
)
9076 == BLOCK_VARS (BIND_EXPR_BLOCK (bind
))));
9077 for (int j
= 2; j
< TREE_VEC_LENGTH (v
); j
++)
9078 for (tree
*p
= &BIND_EXPR_VARS (bind
); *p
; p
= &DECL_CHAIN (*p
))
9080 if (*p
== TREE_VEC_ELT (v
, j
))
9083 *p
= DECL_CHAIN (*p
);
9086 b
= make_node (BLOCK
);
9087 b
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
9088 OMP_FOR_BODY (omp_for
), b
);
9089 TREE_SIDE_EFFECTS (b
) = 1;
9090 OMP_FOR_BODY (omp_for
) = b
;
9092 DECL_CHAIN (var
) = BIND_EXPR_VARS (b
);
9093 BIND_EXPR_VARS (b
) = var
;
9094 BLOCK_VARS (BIND_EXPR_BLOCK (b
)) = var
;
9097 BLOCK_VARS (BIND_EXPR_BLOCK (bind
)) = BIND_EXPR_VARS (bind
);
9103 finish_omp_atomic (location_t loc
, enum tree_code code
, enum tree_code opcode
,
9104 tree lhs
, tree rhs
, tree v
, tree lhs1
, tree rhs1
,
9105 tree clauses
, enum omp_memory_order mo
)
9120 dependent_p
= false;
9123 /* Even in a template, we can detect invalid uses of the atomic
9124 pragma if neither LHS nor RHS is type-dependent. */
9125 if (processing_template_decl
)
9127 dependent_p
= (type_dependent_expression_p (lhs
)
9128 || (rhs
&& type_dependent_expression_p (rhs
))
9129 || (v
&& type_dependent_expression_p (v
))
9130 || (lhs1
&& type_dependent_expression_p (lhs1
))
9131 || (rhs1
&& type_dependent_expression_p (rhs1
)));
9134 gcc_assert (TREE_CODE (clauses
) == OMP_CLAUSE
9135 && OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_HINT
9136 && OMP_CLAUSE_CHAIN (clauses
) == NULL_TREE
);
9137 if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses
))
9138 || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses
)) != INTEGER_CST
)
9143 lhs
= build_non_dependent_expr (lhs
);
9145 rhs
= build_non_dependent_expr (rhs
);
9147 v
= build_non_dependent_expr (v
);
9149 lhs1
= build_non_dependent_expr (lhs1
);
9151 rhs1
= build_non_dependent_expr (rhs1
);
9156 bool swapped
= false;
9157 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
9159 std::swap (rhs
, rhs1
);
9160 swapped
= !commutative_tree_code (opcode
);
9162 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
9164 if (code
== OMP_ATOMIC
)
9165 error ("%<#pragma omp atomic update%> uses two different "
9166 "expressions for memory");
9168 error ("%<#pragma omp atomic capture%> uses two different "
9169 "expressions for memory");
9172 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
9174 if (code
== OMP_ATOMIC
)
9175 error ("%<#pragma omp atomic update%> uses two different "
9176 "expressions for memory");
9178 error ("%<#pragma omp atomic capture%> uses two different "
9179 "expressions for memory");
9182 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
,
9183 v
, lhs1
, rhs1
, swapped
, mo
,
9184 processing_template_decl
!= 0);
9185 if (stmt
== error_mark_node
)
9188 if (processing_template_decl
)
9190 if (code
== OMP_ATOMIC_READ
)
9192 stmt
= build_min_nt_loc (loc
, OMP_ATOMIC_READ
, orig_lhs
);
9193 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9194 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9198 if (opcode
== NOP_EXPR
)
9199 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
9201 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
9203 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
9204 COMPOUND_EXPR
, orig_rhs1
, stmt
);
9205 if (code
!= OMP_ATOMIC
)
9207 stmt
= build_min_nt_loc (loc
, code
, orig_lhs1
, stmt
);
9208 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9209 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9212 stmt
= build2 (OMP_ATOMIC
, void_type_node
,
9213 clauses
? clauses
: integer_zero_node
, stmt
);
9214 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9215 SET_EXPR_LOCATION (stmt
, loc
);
9218 /* Avoid -Wunused-value warnings here, the whole construct has side-effects
9219 and even if it might be wrapped from fold-const.c or c-omp.c wrapped
9220 in some tree that appears to be unused, the value is not unused. */
9221 warning_sentinel
w (warn_unused_value
);
9222 finish_expr_stmt (stmt
);
9226 finish_omp_barrier (void)
9228 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
9230 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9231 finish_expr_stmt (stmt
);
9235 finish_omp_depobj (location_t loc
, tree depobj
,
9236 enum omp_clause_depend_kind kind
, tree clause
)
9238 if (!error_operand_p (depobj
) && !type_dependent_expression_p (depobj
))
9240 if (!lvalue_p (depobj
))
9242 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
9243 "%<depobj%> expression is not lvalue expression");
9244 depobj
= error_mark_node
;
9248 if (processing_template_decl
)
9250 if (clause
== NULL_TREE
)
9251 clause
= build_int_cst (integer_type_node
, kind
);
9252 add_stmt (build_min_nt_loc (loc
, OMP_DEPOBJ
, depobj
, clause
));
9256 if (!error_operand_p (depobj
))
9258 tree addr
= cp_build_addr_expr (depobj
, tf_warning_or_error
);
9259 if (addr
== error_mark_node
)
9260 depobj
= error_mark_node
;
9262 depobj
= cp_build_indirect_ref (addr
, RO_UNARY_STAR
,
9263 tf_warning_or_error
);
9266 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
9270 finish_omp_flush (int mo
)
9272 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
9274 if (mo
!= MEMMODEL_LAST
)
9276 fn
= builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE
);
9277 vec
->quick_push (build_int_cst (integer_type_node
, mo
));
9279 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9280 finish_expr_stmt (stmt
);
9284 finish_omp_taskwait (void)
9286 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
9288 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9289 finish_expr_stmt (stmt
);
9293 finish_omp_taskyield (void)
9295 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
9297 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9298 finish_expr_stmt (stmt
);
9302 finish_omp_cancel (tree clauses
)
9304 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
9306 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9308 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9310 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9312 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9316 error ("%<#pragma omp cancel%> must specify one of "
9317 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9321 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
9322 if (ifc
!= NULL_TREE
)
9324 if (OMP_CLAUSE_IF_MODIFIER (ifc
) != ERROR_MARK
9325 && OMP_CLAUSE_IF_MODIFIER (ifc
) != VOID_CST
)
9326 error_at (OMP_CLAUSE_LOCATION (ifc
),
9327 "expected %<cancel%> %<if%> clause modifier");
9330 tree ifc2
= omp_find_clause (OMP_CLAUSE_CHAIN (ifc
), OMP_CLAUSE_IF
);
9331 if (ifc2
!= NULL_TREE
)
9333 gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc
) == VOID_CST
9334 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != ERROR_MARK
9335 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != VOID_CST
);
9336 error_at (OMP_CLAUSE_LOCATION (ifc2
),
9337 "expected %<cancel%> %<if%> clause modifier");
9341 if (!processing_template_decl
)
9342 ifc
= maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc
));
9344 ifc
= build_x_binary_op (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
9345 OMP_CLAUSE_IF_EXPR (ifc
), ERROR_MARK
,
9346 integer_zero_node
, ERROR_MARK
,
9347 NULL
, tf_warning_or_error
);
9350 ifc
= boolean_true_node
;
9351 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
9352 vec
->quick_push (ifc
);
9353 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9354 finish_expr_stmt (stmt
);
9358 finish_omp_cancellation_point (tree clauses
)
9360 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
9362 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9364 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9366 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9368 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9372 error ("%<#pragma omp cancellation point%> must specify one of "
9373 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9377 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
9378 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9379 finish_expr_stmt (stmt
);
9382 /* Begin a __transaction_atomic or __transaction_relaxed statement.
9383 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
9384 should create an extra compound stmt. */
9387 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
9392 *pcompound
= begin_compound_stmt (0);
9394 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
9396 /* Only add the statement to the function if support enabled. */
9400 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
9401 ? G_("%<__transaction_relaxed%> without "
9402 "transactional memory support enabled")
9403 : G_("%<__transaction_atomic%> without "
9404 "transactional memory support enabled")));
9406 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
9407 TREE_SIDE_EFFECTS (r
) = 1;
9411 /* End a __transaction_atomic or __transaction_relaxed statement.
9412 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
9413 and we should end the compound. If NOEX is non-NULL, we wrap the body in
9414 a MUST_NOT_THROW_EXPR with NOEX as condition. */
9417 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
9419 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
9420 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
9421 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
9422 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
9424 /* noexcept specifications are not allowed for function transactions. */
9425 gcc_assert (!(noex
&& compound_stmt
));
9428 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
9430 protected_set_expr_location
9431 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
9432 TREE_SIDE_EFFECTS (body
) = 1;
9433 TRANSACTION_EXPR_BODY (stmt
) = body
;
9437 finish_compound_stmt (compound_stmt
);
9440 /* Build a __transaction_atomic or __transaction_relaxed expression. If
9441 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
9445 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
9450 expr
= build_must_not_throw_expr (expr
, noex
);
9451 protected_set_expr_location (expr
, loc
);
9452 TREE_SIDE_EFFECTS (expr
) = 1;
9454 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
9455 if (flags
& TM_STMT_ATTR_RELAXED
)
9456 TRANSACTION_EXPR_RELAXED (ret
) = 1;
9457 TREE_SIDE_EFFECTS (ret
) = 1;
9458 SET_EXPR_LOCATION (ret
, loc
);
9463 init_cp_semantics (void)
9467 /* Build a STATIC_ASSERT for a static assertion with the condition
9468 CONDITION and the message text MESSAGE. LOCATION is the location
9469 of the static assertion in the source code. When MEMBER_P, this
9470 static assertion is a member of a class. */
9472 finish_static_assert (tree condition
, tree message
, location_t location
,
9475 tsubst_flags_t complain
= tf_warning_or_error
;
9477 if (message
== NULL_TREE
9478 || message
== error_mark_node
9479 || condition
== NULL_TREE
9480 || condition
== error_mark_node
)
9483 if (check_for_bare_parameter_packs (condition
))
9484 condition
= error_mark_node
;
9486 if (instantiation_dependent_expression_p (condition
))
9488 /* We're in a template; build a STATIC_ASSERT and put it in
9492 assertion
= make_node (STATIC_ASSERT
);
9493 STATIC_ASSERT_CONDITION (assertion
) = condition
;
9494 STATIC_ASSERT_MESSAGE (assertion
) = message
;
9495 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
9498 maybe_add_class_template_decl_list (current_class_type
,
9502 add_stmt (assertion
);
9507 /* Fold the expression and convert it to a boolean value. */
9508 condition
= perform_implicit_conversion_flags (boolean_type_node
, condition
,
9509 complain
, LOOKUP_NORMAL
);
9510 condition
= fold_non_dependent_expr (condition
, complain
,
9511 /*manifestly_const_eval=*/true);
9513 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
9514 /* Do nothing; the condition is satisfied. */
9518 location_t saved_loc
= input_location
;
9520 input_location
= location
;
9521 if (TREE_CODE (condition
) == INTEGER_CST
9522 && integer_zerop (condition
))
9524 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
9525 (TREE_TYPE (TREE_TYPE (message
))));
9526 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
9527 /* Report the error. */
9529 error ("static assertion failed");
9531 error ("static assertion failed: %s",
9532 TREE_STRING_POINTER (message
));
9534 else if (condition
&& condition
!= error_mark_node
)
9536 error ("non-constant condition for static assertion");
9537 if (require_rvalue_constant_expression (condition
))
9538 cxx_constant_value (condition
);
9540 input_location
= saved_loc
;
9544 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
9545 suitable for use as a type-specifier.
9547 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
9548 id-expression or a class member access, FALSE when it was parsed as
9549 a full expression. */
9552 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
9553 tsubst_flags_t complain
)
9555 tree type
= NULL_TREE
;
9557 if (!expr
|| error_operand_p (expr
))
9558 return error_mark_node
;
9561 || TREE_CODE (expr
) == TYPE_DECL
9562 || (TREE_CODE (expr
) == BIT_NOT_EXPR
9563 && TYPE_P (TREE_OPERAND (expr
, 0))))
9565 if (complain
& tf_error
)
9566 error ("argument to %<decltype%> must be an expression");
9567 return error_mark_node
;
9570 /* Depending on the resolution of DR 1172, we may later need to distinguish
9571 instantiation-dependent but not type-dependent expressions so that, say,
9572 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
9573 if (instantiation_dependent_uneval_expression_p (expr
))
9575 type
= cxx_make_type (DECLTYPE_TYPE
);
9576 DECLTYPE_TYPE_EXPR (type
) = expr
;
9577 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
9578 = id_expression_or_member_access_p
;
9579 SET_TYPE_STRUCTURAL_EQUALITY (type
);
9584 /* The type denoted by decltype(e) is defined as follows: */
9586 expr
= resolve_nondeduced_context (expr
, complain
);
9588 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
9589 return error_mark_node
;
9591 if (type_unknown_p (expr
))
9593 if (complain
& tf_error
)
9594 error ("%<decltype%> cannot resolve address of overloaded function");
9595 return error_mark_node
;
9598 /* To get the size of a static data member declared as an array of
9599 unknown bound, we need to instantiate it. */
9601 && VAR_HAD_UNKNOWN_BOUND (expr
)
9602 && DECL_TEMPLATE_INSTANTIATION (expr
))
9603 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
9605 if (id_expression_or_member_access_p
)
9607 /* If e is an id-expression or a class member access (5.2.5
9608 [expr.ref]), decltype(e) is defined as the type of the entity
9609 named by e. If there is no such entity, or e names a set of
9610 overloaded functions, the program is ill-formed. */
9611 if (identifier_p (expr
))
9612 expr
= lookup_name (expr
);
9614 if (INDIRECT_REF_P (expr
)
9615 || TREE_CODE (expr
) == VIEW_CONVERT_EXPR
)
9616 /* This can happen when the expression is, e.g., "a.b". Just
9617 look at the underlying operand. */
9618 expr
= TREE_OPERAND (expr
, 0);
9620 if (TREE_CODE (expr
) == OFFSET_REF
9621 || TREE_CODE (expr
) == MEMBER_REF
9622 || TREE_CODE (expr
) == SCOPE_REF
)
9623 /* We're only interested in the field itself. If it is a
9624 BASELINK, we will need to see through it in the next
9626 expr
= TREE_OPERAND (expr
, 1);
9628 if (BASELINK_P (expr
))
9629 /* See through BASELINK nodes to the underlying function. */
9630 expr
= BASELINK_FUNCTIONS (expr
);
9632 /* decltype of a decomposition name drops references in the tuple case
9633 (unlike decltype of a normal variable) and keeps cv-qualifiers from
9634 the containing object in the other cases (unlike decltype of a member
9635 access expression). */
9636 if (DECL_DECOMPOSITION_P (expr
))
9638 if (DECL_HAS_VALUE_EXPR_P (expr
))
9639 /* Expr is an array or struct subobject proxy, handle
9640 bit-fields properly. */
9641 return unlowered_expr_type (expr
);
9643 /* Expr is a reference variable for the tuple case. */
9644 return lookup_decomp_type (expr
);
9647 switch (TREE_CODE (expr
))
9650 if (DECL_BIT_FIELD_TYPE (expr
))
9652 type
= DECL_BIT_FIELD_TYPE (expr
);
9655 /* Fall through for fields that aren't bitfields. */
9663 case TEMPLATE_PARM_INDEX
:
9664 expr
= mark_type_use (expr
);
9665 type
= TREE_TYPE (expr
);
9669 type
= error_mark_node
;
9674 mark_type_use (expr
);
9675 type
= is_bitfield_expr_with_lowered_type (expr
);
9677 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
9685 /* We can get here when the id-expression refers to an
9686 enumerator or non-type template parameter. */
9687 type
= TREE_TYPE (expr
);
9691 /* Handle instantiated template non-type arguments. */
9692 type
= TREE_TYPE (expr
);
9698 /* Within a lambda-expression:
9700 Every occurrence of decltype((x)) where x is a possibly
9701 parenthesized id-expression that names an entity of
9702 automatic storage duration is treated as if x were
9703 transformed into an access to a corresponding data member
9704 of the closure type that would have been declared if x
9705 were a use of the denoted entity. */
9706 if (outer_automatic_var_p (expr
)
9707 && current_function_decl
9708 && LAMBDA_FUNCTION_P (current_function_decl
))
9709 type
= capture_decltype (expr
);
9710 else if (error_operand_p (expr
))
9711 type
= error_mark_node
;
9712 else if (expr
== current_class_ptr
)
9713 /* If the expression is just "this", we want the
9714 cv-unqualified pointer for the "this" type. */
9715 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
9718 /* Otherwise, where T is the type of e, if e is an lvalue,
9719 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
9720 cp_lvalue_kind clk
= lvalue_kind (expr
);
9721 type
= unlowered_expr_type (expr
);
9722 gcc_assert (!TYPE_REF_P (type
));
9724 /* For vector types, pick a non-opaque variant. */
9725 if (VECTOR_TYPE_P (type
))
9726 type
= strip_typedefs (type
);
9728 if (clk
!= clk_none
&& !(clk
& clk_class
))
9729 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
9736 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
9737 __has_nothrow_copy, depending on assign_p. Returns true iff all
9738 the copy {ctor,assign} fns are nothrow. */
9741 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
9743 tree fns
= NULL_TREE
;
9745 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
9746 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
9749 bool saw_copy
= false;
9750 for (ovl_iterator
iter (fns
); iter
; ++iter
)
9754 if (copy_fn_p (fn
) > 0)
9757 if (!maybe_instantiate_noexcept (fn
)
9758 || !TYPE_NOTHROW_P (TREE_TYPE (fn
)))
9766 /* Actually evaluates the trait. */
9769 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
9771 enum tree_code type_code1
;
9774 type_code1
= TREE_CODE (type1
);
9778 case CPTK_HAS_NOTHROW_ASSIGN
:
9779 type1
= strip_array_types (type1
);
9780 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
9781 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
9782 || (CLASS_TYPE_P (type1
)
9783 && classtype_has_nothrow_assign_or_copy_p (type1
,
9786 case CPTK_HAS_TRIVIAL_ASSIGN
:
9787 /* ??? The standard seems to be missing the "or array of such a class
9788 type" wording for this trait. */
9789 type1
= strip_array_types (type1
);
9790 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
9791 && (trivial_type_p (type1
)
9792 || (CLASS_TYPE_P (type1
)
9793 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
9795 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9796 type1
= strip_array_types (type1
);
9797 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
9798 || (CLASS_TYPE_P (type1
)
9799 && (t
= locate_ctor (type1
))
9800 && maybe_instantiate_noexcept (t
)
9801 && TYPE_NOTHROW_P (TREE_TYPE (t
))));
9803 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9804 type1
= strip_array_types (type1
);
9805 return (trivial_type_p (type1
)
9806 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
9808 case CPTK_HAS_NOTHROW_COPY
:
9809 type1
= strip_array_types (type1
);
9810 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
9811 || (CLASS_TYPE_P (type1
)
9812 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
9814 case CPTK_HAS_TRIVIAL_COPY
:
9815 /* ??? The standard seems to be missing the "or array of such a class
9816 type" wording for this trait. */
9817 type1
= strip_array_types (type1
);
9818 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9819 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
9821 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9822 type1
= strip_array_types (type1
);
9823 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9824 || (CLASS_TYPE_P (type1
)
9825 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
9827 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9828 return type_has_virtual_destructor (type1
);
9830 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
9831 return type_has_unique_obj_representations (type1
);
9833 case CPTK_IS_ABSTRACT
:
9834 return ABSTRACT_CLASS_TYPE_P (type1
);
9836 case CPTK_IS_AGGREGATE
:
9837 return CP_AGGREGATE_TYPE_P (type1
);
9839 case CPTK_IS_BASE_OF
:
9840 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9841 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9842 || DERIVED_FROM_P (type1
, type2
)));
9845 return NON_UNION_CLASS_TYPE_P (type1
);
9848 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
9851 return type_code1
== ENUMERAL_TYPE
;
9854 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
9856 case CPTK_IS_LITERAL_TYPE
:
9857 return literal_type_p (type1
);
9860 return pod_type_p (type1
);
9862 case CPTK_IS_POLYMORPHIC
:
9863 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
9865 case CPTK_IS_SAME_AS
:
9866 return same_type_p (type1
, type2
);
9868 case CPTK_IS_STD_LAYOUT
:
9869 return std_layout_type_p (type1
);
9871 case CPTK_IS_TRIVIAL
:
9872 return trivial_type_p (type1
);
9874 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9875 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
9877 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9878 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
9880 case CPTK_IS_TRIVIALLY_COPYABLE
:
9881 return trivially_copyable_p (type1
);
9884 return type_code1
== UNION_TYPE
;
9886 case CPTK_IS_ASSIGNABLE
:
9887 return is_xible (MODIFY_EXPR
, type1
, type2
);
9889 case CPTK_IS_CONSTRUCTIBLE
:
9890 return is_xible (INIT_EXPR
, type1
, type2
);
9898 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
9899 void, or a complete type, returns true, otherwise false. */
9902 check_trait_type (tree type
)
9904 if (type
== NULL_TREE
)
9907 if (TREE_CODE (type
) == TREE_LIST
)
9908 return (check_trait_type (TREE_VALUE (type
))
9909 && check_trait_type (TREE_CHAIN (type
)));
9911 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
9912 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
9915 if (VOID_TYPE_P (type
))
9918 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
9921 /* Process a trait expression. */
9924 finish_trait_expr (location_t loc
, cp_trait_kind kind
, tree type1
, tree type2
)
9926 if (type1
== error_mark_node
9927 || type2
== error_mark_node
)
9928 return error_mark_node
;
9930 if (processing_template_decl
)
9932 tree trait_expr
= make_node (TRAIT_EXPR
);
9933 TREE_TYPE (trait_expr
) = boolean_type_node
;
9934 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
9935 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
9936 TRAIT_EXPR_KIND (trait_expr
) = kind
;
9937 TRAIT_EXPR_LOCATION (trait_expr
) = loc
;
9943 case CPTK_HAS_NOTHROW_ASSIGN
:
9944 case CPTK_HAS_TRIVIAL_ASSIGN
:
9945 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9946 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9947 case CPTK_HAS_NOTHROW_COPY
:
9948 case CPTK_HAS_TRIVIAL_COPY
:
9949 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9950 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
9951 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9952 case CPTK_IS_ABSTRACT
:
9953 case CPTK_IS_AGGREGATE
:
9956 case CPTK_IS_LITERAL_TYPE
:
9958 case CPTK_IS_POLYMORPHIC
:
9959 case CPTK_IS_STD_LAYOUT
:
9960 case CPTK_IS_TRIVIAL
:
9961 case CPTK_IS_TRIVIALLY_COPYABLE
:
9962 if (!check_trait_type (type1
))
9963 return error_mark_node
;
9966 case CPTK_IS_ASSIGNABLE
:
9967 case CPTK_IS_CONSTRUCTIBLE
:
9970 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9971 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9972 if (!check_trait_type (type1
)
9973 || !check_trait_type (type2
))
9974 return error_mark_node
;
9977 case CPTK_IS_BASE_OF
:
9978 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9979 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9980 && !complete_type_or_else (type2
, NULL_TREE
))
9981 /* We already issued an error. */
9982 return error_mark_node
;
9988 case CPTK_IS_SAME_AS
:
9995 tree val
= (trait_expr_value (kind
, type1
, type2
)
9996 ? boolean_true_node
: boolean_false_node
);
9997 return maybe_wrap_with_location (val
, loc
);
10000 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
10001 which is ignored for C++. */
10004 set_float_const_decimal64 (void)
10009 clear_float_const_decimal64 (void)
10014 float_const_decimal64_p (void)
10020 /* Return true if T designates the implied `this' parameter. */
10023 is_this_parameter (tree t
)
10025 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
10027 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
)
10028 || (cp_binding_oracle
&& TREE_CODE (t
) == VAR_DECL
));
10032 /* Insert the deduced return type for an auto function. */
10035 apply_deduced_return_type (tree fco
, tree return_type
)
10039 if (return_type
== error_mark_node
)
10042 if (DECL_CONV_FN_P (fco
))
10043 DECL_NAME (fco
) = make_conv_op_name (return_type
);
10045 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
10047 result
= DECL_RESULT (fco
);
10048 if (result
== NULL_TREE
)
10050 if (TREE_TYPE (result
) == return_type
)
10053 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
10054 && !complete_type_or_else (return_type
, NULL_TREE
))
10057 /* We already have a DECL_RESULT from start_preparsed_function.
10058 Now we need to redo the work it and allocate_struct_function
10059 did to reflect the new type. */
10060 gcc_assert (current_function_decl
== fco
);
10061 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
10062 TYPE_MAIN_VARIANT (return_type
));
10063 DECL_ARTIFICIAL (result
) = 1;
10064 DECL_IGNORED_P (result
) = 1;
10065 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
10068 DECL_RESULT (fco
) = result
;
10070 if (!processing_template_decl
)
10072 bool aggr
= aggregate_value_p (result
, fco
);
10073 #ifdef PCC_STATIC_STRUCT_RETURN
10074 cfun
->returns_pcc_struct
= aggr
;
10076 cfun
->returns_struct
= aggr
;
10080 /* DECL is a local variable or parameter from the surrounding scope of a
10081 lambda-expression. Returns the decltype for a use of the capture field
10082 for DECL even if it hasn't been captured yet. */
10085 capture_decltype (tree decl
)
10087 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
10088 tree cap
= lookup_name_real (DECL_NAME (decl
), /*type*/0, /*nonclass*/1,
10089 /*block_p=*/true, /*ns*/0, LOOKUP_HIDDEN
);
10092 if (cap
&& is_capture_proxy (cap
))
10093 type
= TREE_TYPE (cap
);
10095 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
10098 error ("%qD is not captured", decl
);
10099 return error_mark_node
;
10102 type
= TREE_TYPE (decl
);
10103 if (TYPE_REF_P (type
)
10104 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
10105 type
= TREE_TYPE (type
);
10108 case CPLD_REFERENCE
:
10109 type
= TREE_TYPE (decl
);
10110 if (!TYPE_REF_P (type
))
10111 type
= build_reference_type (TREE_TYPE (decl
));
10115 gcc_unreachable ();
10118 if (!TYPE_REF_P (type
))
10120 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
10121 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
10122 |TYPE_QUAL_CONST
));
10123 type
= build_reference_type (type
);
10128 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
10129 this is a right unary fold. Otherwise it is a left unary fold. */
10132 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
10134 /* Build a pack expansion (assuming expr has pack type). */
10135 if (!uses_parameter_packs (expr
))
10137 error_at (location_of (expr
), "operand of fold expression has no "
10138 "unexpanded parameter packs");
10139 return error_mark_node
;
10141 tree pack
= make_pack_expansion (expr
);
10143 /* Build the fold expression. */
10144 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10145 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
);
10146 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10151 finish_left_unary_fold_expr (tree expr
, int op
)
10153 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
10157 finish_right_unary_fold_expr (tree expr
, int op
)
10159 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
10162 /* Build a binary fold expression over EXPR1 and EXPR2. The
10163 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
10164 has an unexpanded parameter pack). */
10167 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
10169 pack
= make_pack_expansion (pack
);
10170 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10171 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
, init
);
10172 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10177 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
10179 // Determine which expr has an unexpanded parameter pack and
10180 // set the pack and initial term.
10181 bool pack1
= uses_parameter_packs (expr1
);
10182 bool pack2
= uses_parameter_packs (expr2
);
10183 if (pack1
&& !pack2
)
10184 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
10185 else if (pack2
&& !pack1
)
10186 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
10190 error ("both arguments in binary fold have unexpanded parameter packs");
10192 error ("no unexpanded parameter packs in binary fold");
10194 return error_mark_node
;
10197 /* Finish __builtin_launder (arg). */
10200 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
10202 tree orig_arg
= arg
;
10203 if (!type_dependent_expression_p (arg
))
10204 arg
= decay_conversion (arg
, complain
);
10205 if (error_operand_p (arg
))
10206 return error_mark_node
;
10207 if (!type_dependent_expression_p (arg
)
10208 && !TYPE_PTR_P (TREE_TYPE (arg
)))
10210 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
10211 return error_mark_node
;
10213 if (processing_template_decl
)
10215 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
10216 TREE_TYPE (arg
), 1, arg
);
10219 /* Finish __builtin_convertvector (arg, type). */
10222 cp_build_vec_convert (tree arg
, location_t loc
, tree type
,
10223 tsubst_flags_t complain
)
10225 if (error_operand_p (type
))
10226 return error_mark_node
;
10227 if (error_operand_p (arg
))
10228 return error_mark_node
;
10230 tree ret
= NULL_TREE
;
10231 if (!type_dependent_expression_p (arg
) && !dependent_type_p (type
))
10232 ret
= c_build_vec_convert (cp_expr_loc_or_input_loc (arg
), arg
,
10233 loc
, type
, (complain
& tf_error
) != 0);
10235 if (!processing_template_decl
)
10238 return build_call_expr_internal_loc (loc
, IFN_VEC_CONVERT
, type
, 1, arg
);
10241 #include "gt-cp-semantics.h"