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-2020 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 if (STATEMENT_CODE_P (TREE_CODE (t
)))
384 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
387 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
388 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
390 /* Add T to the statement-tree. Non-side-effect statements need to be
391 recorded during statement expressions. */
392 gcc_checking_assert (!stmt_list_stack
->is_empty ());
393 append_to_statement_list_force (t
, &cur_stmt_list
);
398 /* Returns the stmt_tree to which statements are currently being added. */
401 current_stmt_tree (void)
404 ? &cfun
->language
->base
.x_stmt_tree
405 : &scope_chain
->x_stmt_tree
);
408 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
411 maybe_cleanup_point_expr (tree expr
)
413 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
414 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
418 /* Like maybe_cleanup_point_expr except have the type of the new expression be
419 void so we don't need to create a temporary variable to hold the inner
420 expression. The reason why we do this is because the original type might be
421 an aggregate and we cannot create a temporary variable for that type. */
424 maybe_cleanup_point_expr_void (tree expr
)
426 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
427 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
433 /* Create a declaration statement for the declaration given by the DECL. */
436 add_decl_expr (tree decl
)
438 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
439 if (DECL_INITIAL (decl
)
440 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
441 r
= maybe_cleanup_point_expr_void (r
);
445 /* Finish a scope. */
448 do_poplevel (tree stmt_list
)
452 if (stmts_are_full_exprs_p ())
453 block
= poplevel (kept_level_p (), 1, 0);
455 stmt_list
= pop_stmt_list (stmt_list
);
457 if (!processing_template_decl
)
459 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
460 /* ??? See c_end_compound_stmt re statement expressions. */
466 /* Begin a new scope. */
469 do_pushlevel (scope_kind sk
)
471 tree ret
= push_stmt_list ();
472 if (stmts_are_full_exprs_p ())
473 begin_scope (sk
, NULL
);
477 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
478 when the current scope is exited. EH_ONLY is true when this is not
479 meant to apply to normal control flow transfer. */
482 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
484 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
485 CLEANUP_EH_ONLY (stmt
) = eh_only
;
487 CLEANUP_BODY (stmt
) = push_stmt_list ();
490 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
491 the current loops, represented by 'NULL_TREE' if we've seen a possible
492 exit, and 'error_mark_node' if not. This is currently used only to
493 suppress the warning about a function with no return statements, and
494 therefore we don't bother noting returns as possible exits. We also
495 don't bother with gotos. */
498 begin_maybe_infinite_loop (tree cond
)
500 /* Only track this while parsing a function, not during instantiation. */
501 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
502 && !processing_template_decl
))
504 bool maybe_infinite
= true;
507 cond
= fold_non_dependent_expr (cond
);
508 maybe_infinite
= integer_nonzerop (cond
);
510 vec_safe_push (cp_function_chain
->infinite_loops
,
511 maybe_infinite
? error_mark_node
: NULL_TREE
);
515 /* A break is a possible exit for the current loop. */
518 break_maybe_infinite_loop (void)
522 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
525 /* If we reach the end of the loop without seeing a possible exit, we have
529 end_maybe_infinite_loop (tree cond
)
531 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
532 && !processing_template_decl
))
534 tree current
= cp_function_chain
->infinite_loops
->pop();
535 if (current
!= NULL_TREE
)
537 cond
= fold_non_dependent_expr (cond
);
538 if (integer_nonzerop (cond
))
539 current_function_infinite_loop
= 1;
544 /* Begin a conditional that might contain a declaration. When generating
545 normal code, we want the declaration to appear before the statement
546 containing the conditional. When generating template code, we want the
547 conditional to be rendered as the raw DECL_EXPR. */
550 begin_cond (tree
*cond_p
)
552 if (processing_template_decl
)
553 *cond_p
= push_stmt_list ();
556 /* Finish such a conditional. */
559 finish_cond (tree
*cond_p
, tree expr
)
561 if (processing_template_decl
)
563 tree cond
= pop_stmt_list (*cond_p
);
565 if (expr
== NULL_TREE
)
566 /* Empty condition in 'for'. */
567 gcc_assert (empty_expr_stmt_p (cond
));
568 else if (check_for_bare_parameter_packs (expr
))
569 expr
= error_mark_node
;
570 else if (!empty_expr_stmt_p (cond
))
571 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
576 /* If *COND_P specifies a conditional with a declaration, transform the
579 for (; A x = 42;) { }
581 while (true) { A x = 42; if (!x) break; }
582 for (;;) { A x = 42; if (!x) break; }
583 The statement list for BODY will be empty if the conditional did
584 not declare anything. */
587 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
591 if (!TREE_SIDE_EFFECTS (body
))
595 *cond_p
= boolean_true_node
;
597 if_stmt
= begin_if_stmt ();
598 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, false, tf_warning_or_error
);
599 finish_if_stmt_cond (cond
, if_stmt
);
600 finish_break_stmt ();
601 finish_then_clause (if_stmt
);
602 finish_if_stmt (if_stmt
);
605 /* Finish a goto-statement. */
608 finish_goto_stmt (tree destination
)
610 if (identifier_p (destination
))
611 destination
= lookup_label (destination
);
613 /* We warn about unused labels with -Wunused. That means we have to
614 mark the used labels as used. */
615 if (TREE_CODE (destination
) == LABEL_DECL
)
616 TREE_USED (destination
) = 1;
619 destination
= mark_rvalue_use (destination
);
620 if (!processing_template_decl
)
622 destination
= cp_convert (ptr_type_node
, destination
,
623 tf_warning_or_error
);
624 if (error_operand_p (destination
))
627 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
632 check_goto (destination
);
634 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
635 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
638 /* COND is the condition-expression for an if, while, etc.,
639 statement. Convert it to a boolean value, if appropriate.
640 In addition, verify sequence points if -Wsequence-point is enabled. */
643 maybe_convert_cond (tree cond
)
645 /* Empty conditions remain empty. */
649 /* Wait until we instantiate templates before doing conversion. */
650 if (type_dependent_expression_p (cond
))
653 if (warn_sequence_point
&& !processing_template_decl
)
654 verify_sequence_points (cond
);
656 /* Do the conversion. */
657 cond
= convert_from_reference (cond
);
659 if (TREE_CODE (cond
) == MODIFY_EXPR
660 && !TREE_NO_WARNING (cond
)
662 && warning_at (cp_expr_loc_or_input_loc (cond
),
663 OPT_Wparentheses
, "suggest parentheses around "
664 "assignment used as truth value"))
665 TREE_NO_WARNING (cond
) = 1;
667 return condition_conversion (cond
);
670 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
673 finish_expr_stmt (tree expr
)
676 location_t loc
= EXPR_LOCATION (expr
);
678 if (expr
!= NULL_TREE
)
680 /* If we ran into a problem, make sure we complained. */
681 gcc_assert (expr
!= error_mark_node
|| seen_error ());
683 if (!processing_template_decl
)
685 if (warn_sequence_point
)
686 verify_sequence_points (expr
);
687 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
689 else if (!type_dependent_expression_p (expr
))
690 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
691 tf_warning_or_error
);
693 if (check_for_bare_parameter_packs (expr
))
694 expr
= error_mark_node
;
696 /* Simplification of inner statement expressions, compound exprs,
697 etc can result in us already having an EXPR_STMT. */
698 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
700 if (TREE_CODE (expr
) != EXPR_STMT
)
701 expr
= build_stmt (loc
, EXPR_STMT
, expr
);
702 expr
= maybe_cleanup_point_expr_void (expr
);
712 /* Begin an if-statement. Returns a newly created IF_STMT if
719 scope
= do_pushlevel (sk_cond
);
720 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
721 NULL_TREE
, NULL_TREE
, scope
);
722 current_binding_level
->this_entity
= r
;
723 begin_cond (&IF_COND (r
));
727 /* Returns true if FN, a CALL_EXPR, is a call to
728 std::is_constant_evaluated or __builtin_is_constant_evaluated. */
731 is_std_constant_evaluated_p (tree fn
)
733 /* std::is_constant_evaluated takes no arguments. */
734 if (call_expr_nargs (fn
) != 0)
737 tree fndecl
= cp_get_callee_fndecl_nofold (fn
);
738 if (fndecl
== NULL_TREE
)
741 if (fndecl_built_in_p (fndecl
, CP_BUILT_IN_IS_CONSTANT_EVALUATED
,
745 if (!decl_in_std_namespace_p (fndecl
))
748 tree name
= DECL_NAME (fndecl
);
749 return name
&& id_equal (name
, "is_constant_evaluated");
752 /* Process the COND of an if-statement, which may be given by
756 finish_if_stmt_cond (tree cond
, tree if_stmt
)
758 cond
= maybe_convert_cond (cond
);
759 if (IF_STMT_CONSTEXPR_P (if_stmt
)
760 && !type_dependent_expression_p (cond
)
761 && require_constant_expression (cond
)
762 && !instantiation_dependent_expression_p (cond
)
763 /* Wait until instantiation time, since only then COND has been
764 converted to bool. */
765 && TYPE_MAIN_VARIANT (TREE_TYPE (cond
)) == boolean_type_node
)
767 /* if constexpr (std::is_constant_evaluated()) is always true,
768 so give the user a clue. */
769 if (warn_tautological_compare
)
772 if (TREE_CODE (t
) == CLEANUP_POINT_EXPR
)
773 t
= TREE_OPERAND (t
, 0);
774 if (TREE_CODE (t
) == CALL_EXPR
775 && is_std_constant_evaluated_p (t
))
776 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
777 "%qs always evaluates to true in %<if constexpr%>",
778 "std::is_constant_evaluated");
781 cond
= instantiate_non_dependent_expr (cond
);
782 cond
= cxx_constant_value (cond
, NULL_TREE
);
784 finish_cond (&IF_COND (if_stmt
), cond
);
786 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
790 /* Finish the then-clause of an if-statement, which may be given by
794 finish_then_clause (tree if_stmt
)
796 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
800 /* Begin the else-clause of an if-statement. */
803 begin_else_clause (tree if_stmt
)
805 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
808 /* Finish the else-clause of an if-statement, which may be given by
812 finish_else_clause (tree if_stmt
)
814 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
817 /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
821 maybe_mark_exp_read_r (tree
*tp
, int *, void *)
824 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
829 /* Finish an if-statement. */
832 finish_if_stmt (tree if_stmt
)
834 tree scope
= IF_SCOPE (if_stmt
);
835 IF_SCOPE (if_stmt
) = NULL
;
836 if (IF_STMT_CONSTEXPR_P (if_stmt
))
838 /* Prevent various -Wunused warnings. We might not instantiate
839 either of these branches, so we would not mark the variables
840 used in that branch as read. */
841 cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt
),
842 maybe_mark_exp_read_r
, NULL
);
843 cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt
),
844 maybe_mark_exp_read_r
, NULL
);
846 add_stmt (do_poplevel (scope
));
849 /* Begin a while-statement. Returns a newly created WHILE_STMT if
853 begin_while_stmt (void)
856 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
858 WHILE_BODY (r
) = do_pushlevel (sk_block
);
859 begin_cond (&WHILE_COND (r
));
863 /* Process the COND of a while-statement, which may be given by
867 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
,
868 unsigned short unroll
)
870 cond
= maybe_convert_cond (cond
);
871 finish_cond (&WHILE_COND (while_stmt
), cond
);
872 begin_maybe_infinite_loop (cond
);
873 if (ivdep
&& cond
!= error_mark_node
)
874 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
875 TREE_TYPE (WHILE_COND (while_stmt
)),
876 WHILE_COND (while_stmt
),
877 build_int_cst (integer_type_node
,
878 annot_expr_ivdep_kind
),
880 if (unroll
&& cond
!= error_mark_node
)
881 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
882 TREE_TYPE (WHILE_COND (while_stmt
)),
883 WHILE_COND (while_stmt
),
884 build_int_cst (integer_type_node
,
885 annot_expr_unroll_kind
),
886 build_int_cst (integer_type_node
,
888 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
891 /* Finish a while-statement, which may be given by WHILE_STMT. */
894 finish_while_stmt (tree while_stmt
)
896 end_maybe_infinite_loop (boolean_true_node
);
897 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
900 /* Begin a do-statement. Returns a newly created DO_STMT if
906 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
907 begin_maybe_infinite_loop (boolean_true_node
);
909 DO_BODY (r
) = push_stmt_list ();
913 /* Finish the body of a do-statement, which may be given by DO_STMT. */
916 finish_do_body (tree do_stmt
)
918 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
920 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
921 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
923 if (IS_EMPTY_STMT (body
))
924 warning (OPT_Wempty_body
,
925 "suggest explicit braces around empty body in %<do%> statement");
928 /* Finish a do-statement, which may be given by DO_STMT, and whose
929 COND is as indicated. */
932 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
, unsigned short unroll
)
934 cond
= maybe_convert_cond (cond
);
935 end_maybe_infinite_loop (cond
);
936 if (ivdep
&& cond
!= error_mark_node
)
937 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
938 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
),
940 if (unroll
&& cond
!= error_mark_node
)
941 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
942 build_int_cst (integer_type_node
, annot_expr_unroll_kind
),
943 build_int_cst (integer_type_node
, unroll
));
944 DO_COND (do_stmt
) = cond
;
947 /* Finish a return-statement. The EXPRESSION returned, if any, is as
951 finish_return_stmt (tree expr
)
956 expr
= check_return_expr (expr
, &no_warning
);
958 if (error_operand_p (expr
)
959 || (flag_openmp
&& !check_omp_return ()))
961 /* Suppress -Wreturn-type for this function. */
962 if (warn_return_type
)
963 TREE_NO_WARNING (current_function_decl
) = true;
964 return error_mark_node
;
967 if (!processing_template_decl
)
969 if (warn_sequence_point
)
970 verify_sequence_points (expr
);
972 if (DECL_DESTRUCTOR_P (current_function_decl
)
973 || (DECL_CONSTRUCTOR_P (current_function_decl
)
974 && targetm
.cxx
.cdtor_returns_this ()))
976 /* Similarly, all destructors must run destructors for
977 base-classes before returning. So, all returns in a
978 destructor get sent to the DTOR_LABEL; finish_function emits
979 code to return a value there. */
980 return finish_goto_stmt (cdtor_label
);
984 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
985 TREE_NO_WARNING (r
) |= no_warning
;
986 r
= maybe_cleanup_point_expr_void (r
);
992 /* Begin the scope of a for-statement or a range-for-statement.
993 Both the returned trees are to be used in a call to
994 begin_for_stmt or begin_range_for_stmt. */
997 begin_for_scope (tree
*init
)
999 tree scope
= do_pushlevel (sk_for
);
1001 if (processing_template_decl
)
1002 *init
= push_stmt_list ();
1009 /* Begin a for-statement. Returns a new FOR_STMT.
1010 SCOPE and INIT should be the return of begin_for_scope,
1011 or both NULL_TREE */
1014 begin_for_stmt (tree scope
, tree init
)
1018 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
1019 NULL_TREE
, NULL_TREE
, NULL_TREE
);
1021 if (scope
== NULL_TREE
)
1024 scope
= begin_for_scope (&init
);
1027 FOR_INIT_STMT (r
) = init
;
1028 FOR_SCOPE (r
) = scope
;
1033 /* Finish the init-statement of a for-statement, which may be
1034 given by FOR_STMT. */
1037 finish_init_stmt (tree for_stmt
)
1039 if (processing_template_decl
)
1040 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
1041 add_stmt (for_stmt
);
1042 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
1043 begin_cond (&FOR_COND (for_stmt
));
1046 /* Finish the COND of a for-statement, which may be given by
1050 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
, unsigned short unroll
)
1052 cond
= maybe_convert_cond (cond
);
1053 finish_cond (&FOR_COND (for_stmt
), cond
);
1054 begin_maybe_infinite_loop (cond
);
1055 if (ivdep
&& cond
!= error_mark_node
)
1056 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1057 TREE_TYPE (FOR_COND (for_stmt
)),
1058 FOR_COND (for_stmt
),
1059 build_int_cst (integer_type_node
,
1060 annot_expr_ivdep_kind
),
1062 if (unroll
&& cond
!= error_mark_node
)
1063 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1064 TREE_TYPE (FOR_COND (for_stmt
)),
1065 FOR_COND (for_stmt
),
1066 build_int_cst (integer_type_node
,
1067 annot_expr_unroll_kind
),
1068 build_int_cst (integer_type_node
,
1070 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
1073 /* Finish the increment-EXPRESSION in a for-statement, which may be
1074 given by FOR_STMT. */
1077 finish_for_expr (tree expr
, tree for_stmt
)
1081 /* If EXPR is an overloaded function, issue an error; there is no
1082 context available to use to perform overload resolution. */
1083 if (type_unknown_p (expr
))
1085 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1086 expr
= error_mark_node
;
1088 if (!processing_template_decl
)
1090 if (warn_sequence_point
)
1091 verify_sequence_points (expr
);
1092 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1093 tf_warning_or_error
);
1095 else if (!type_dependent_expression_p (expr
))
1096 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1097 tf_warning_or_error
);
1098 expr
= maybe_cleanup_point_expr_void (expr
);
1099 if (check_for_bare_parameter_packs (expr
))
1100 expr
= error_mark_node
;
1101 FOR_EXPR (for_stmt
) = expr
;
1104 /* Finish the body of a for-statement, which may be given by
1105 FOR_STMT. The increment-EXPR for the loop must be
1107 It can also finish RANGE_FOR_STMT. */
1110 finish_for_stmt (tree for_stmt
)
1112 end_maybe_infinite_loop (boolean_true_node
);
1114 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1115 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1117 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1119 /* Pop the scope for the body of the loop. */
1120 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1121 ? &RANGE_FOR_SCOPE (for_stmt
)
1122 : &FOR_SCOPE (for_stmt
));
1123 tree scope
= *scope_ptr
;
1126 /* During parsing of the body, range for uses "__for_{range,begin,end} "
1127 decl names to make those unaccessible by code in the body.
1128 Change it to ones with underscore instead of space, so that it can
1129 be inspected in the debugger. */
1130 tree range_for_decl
[3] = { NULL_TREE
, NULL_TREE
, NULL_TREE
};
1131 gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 1
1132 && CPTI_FOR_END__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 2
1133 && CPTI_FOR_RANGE_IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 3
1134 && CPTI_FOR_BEGIN_IDENTIFIER
== CPTI_FOR_BEGIN__IDENTIFIER
+ 3
1135 && CPTI_FOR_END_IDENTIFIER
== CPTI_FOR_END__IDENTIFIER
+ 3);
1136 for (int i
= 0; i
< 3; i
++)
1138 tree id
= cp_global_trees
[CPTI_FOR_RANGE__IDENTIFIER
+ i
];
1139 if (IDENTIFIER_BINDING (id
)
1140 && IDENTIFIER_BINDING (id
)->scope
== current_binding_level
)
1142 range_for_decl
[i
] = IDENTIFIER_BINDING (id
)->value
;
1143 gcc_assert (VAR_P (range_for_decl
[i
])
1144 && DECL_ARTIFICIAL (range_for_decl
[i
]));
1148 add_stmt (do_poplevel (scope
));
1150 for (int i
= 0; i
< 3; i
++)
1151 if (range_for_decl
[i
])
1152 DECL_NAME (range_for_decl
[i
])
1153 = cp_global_trees
[CPTI_FOR_RANGE_IDENTIFIER
+ i
];
1156 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1157 SCOPE and INIT should be the return of begin_for_scope,
1159 To finish it call finish_for_stmt(). */
1162 begin_range_for_stmt (tree scope
, tree init
)
1164 begin_maybe_infinite_loop (boolean_false_node
);
1166 tree r
= build_stmt (input_location
, RANGE_FOR_STMT
, NULL_TREE
, NULL_TREE
,
1167 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1169 if (scope
== NULL_TREE
)
1172 scope
= begin_for_scope (&init
);
1175 /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1176 RANGE_FOR_INIT_STMT (r
) = init
;
1177 RANGE_FOR_SCOPE (r
) = scope
;
1182 /* Finish the head of a range-based for statement, which may
1183 be given by RANGE_FOR_STMT. DECL must be the declaration
1184 and EXPR must be the loop expression. */
1187 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1189 if (processing_template_decl
)
1190 RANGE_FOR_INIT_STMT (range_for_stmt
)
1191 = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt
));
1192 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1193 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1194 add_stmt (range_for_stmt
);
1195 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1198 /* Finish a break-statement. */
1201 finish_break_stmt (void)
1203 /* In switch statements break is sometimes stylistically used after
1204 a return statement. This can lead to spurious warnings about
1205 control reaching the end of a non-void function when it is
1206 inlined. Note that we are calling block_may_fallthru with
1207 language specific tree nodes; this works because
1208 block_may_fallthru returns true when given something it does not
1210 if (!block_may_fallthru (cur_stmt_list
))
1213 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1216 /* Finish a continue-statement. */
1219 finish_continue_stmt (void)
1221 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1224 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1228 begin_switch_stmt (void)
1232 scope
= do_pushlevel (sk_cond
);
1233 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1235 begin_cond (&SWITCH_STMT_COND (r
));
1240 /* Finish the cond of a switch-statement. */
1243 finish_switch_cond (tree cond
, tree switch_stmt
)
1245 tree orig_type
= NULL
;
1247 if (!processing_template_decl
)
1249 /* Convert the condition to an integer or enumeration type. */
1250 tree orig_cond
= cond
;
1251 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1252 if (cond
== NULL_TREE
)
1254 error_at (cp_expr_loc_or_input_loc (orig_cond
),
1255 "switch quantity not an integer");
1256 cond
= error_mark_node
;
1258 /* We want unlowered type here to handle enum bit-fields. */
1259 orig_type
= unlowered_expr_type (cond
);
1260 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1261 orig_type
= TREE_TYPE (cond
);
1262 if (cond
!= error_mark_node
)
1266 Integral promotions are performed. */
1267 cond
= perform_integral_promotions (cond
);
1268 cond
= maybe_cleanup_point_expr (cond
);
1271 if (check_for_bare_parameter_packs (cond
))
1272 cond
= error_mark_node
;
1273 else if (!processing_template_decl
&& warn_sequence_point
)
1274 verify_sequence_points (cond
);
1276 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1277 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1278 add_stmt (switch_stmt
);
1279 push_switch (switch_stmt
);
1280 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1283 /* Finish the body of a switch-statement, which may be given by
1284 SWITCH_STMT. The COND to switch on is indicated. */
1287 finish_switch_stmt (tree switch_stmt
)
1291 SWITCH_STMT_BODY (switch_stmt
) =
1292 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1295 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1296 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1297 add_stmt (do_poplevel (scope
));
1300 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1304 begin_try_block (void)
1306 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1308 TRY_STMTS (r
) = push_stmt_list ();
1312 /* Likewise, for a function-try-block. The block returned in
1313 *COMPOUND_STMT is an artificial outer scope, containing the
1314 function-try-block. */
1317 begin_function_try_block (tree
*compound_stmt
)
1320 /* This outer scope does not exist in the C++ standard, but we need
1321 a place to put __FUNCTION__ and similar variables. */
1322 *compound_stmt
= begin_compound_stmt (0);
1323 r
= begin_try_block ();
1324 FN_TRY_BLOCK_P (r
) = 1;
1328 /* Finish a try-block, which may be given by TRY_BLOCK. */
1331 finish_try_block (tree try_block
)
1333 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1334 TRY_HANDLERS (try_block
) = push_stmt_list ();
1337 /* Finish the body of a cleanup try-block, which may be given by
1341 finish_cleanup_try_block (tree try_block
)
1343 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1346 /* Finish an implicitly generated try-block, with a cleanup is given
1350 finish_cleanup (tree cleanup
, tree try_block
)
1352 TRY_HANDLERS (try_block
) = cleanup
;
1353 CLEANUP_P (try_block
) = 1;
1356 /* Likewise, for a function-try-block. */
1359 finish_function_try_block (tree try_block
)
1361 finish_try_block (try_block
);
1362 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1363 the try block, but moving it inside. */
1364 in_function_try_handler
= 1;
1367 /* Finish a handler-sequence for a try-block, which may be given by
1371 finish_handler_sequence (tree try_block
)
1373 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1374 check_handlers (TRY_HANDLERS (try_block
));
1377 /* Finish the handler-seq for a function-try-block, given by
1378 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1379 begin_function_try_block. */
1382 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1384 in_function_try_handler
= 0;
1385 finish_handler_sequence (try_block
);
1386 finish_compound_stmt (compound_stmt
);
1389 /* Begin a handler. Returns a HANDLER if appropriate. */
1392 begin_handler (void)
1396 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1399 /* Create a binding level for the eh_info and the exception object
1401 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1406 /* Finish the handler-parameters for a handler, which may be given by
1407 HANDLER. DECL is the declaration for the catch parameter, or NULL
1408 if this is a `catch (...)' clause. */
1411 finish_handler_parms (tree decl
, tree handler
)
1413 tree type
= NULL_TREE
;
1414 if (processing_template_decl
)
1418 decl
= pushdecl (decl
);
1419 decl
= push_template_decl (decl
);
1420 HANDLER_PARMS (handler
) = decl
;
1421 type
= TREE_TYPE (decl
);
1426 type
= expand_start_catch_block (decl
);
1427 if (warn_catch_value
1428 && type
!= NULL_TREE
1429 && type
!= error_mark_node
1430 && !TYPE_REF_P (TREE_TYPE (decl
)))
1432 tree orig_type
= TREE_TYPE (decl
);
1433 if (CLASS_TYPE_P (orig_type
))
1435 if (TYPE_POLYMORPHIC_P (orig_type
))
1436 warning_at (DECL_SOURCE_LOCATION (decl
),
1438 "catching polymorphic type %q#T by value",
1440 else if (warn_catch_value
> 1)
1441 warning_at (DECL_SOURCE_LOCATION (decl
),
1443 "catching type %q#T by value", orig_type
);
1445 else if (warn_catch_value
> 2)
1446 warning_at (DECL_SOURCE_LOCATION (decl
),
1448 "catching non-reference type %q#T", orig_type
);
1451 HANDLER_TYPE (handler
) = type
;
1454 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1455 the return value from the matching call to finish_handler_parms. */
1458 finish_handler (tree handler
)
1460 if (!processing_template_decl
)
1461 expand_end_catch_block ();
1462 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1465 /* Begin a compound statement. FLAGS contains some bits that control the
1466 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1467 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1468 block of a function. If BCS_TRY_BLOCK is set, this is the block
1469 created on behalf of a TRY statement. Returns a token to be passed to
1470 finish_compound_stmt. */
1473 begin_compound_stmt (unsigned int flags
)
1477 if (flags
& BCS_NO_SCOPE
)
1479 r
= push_stmt_list ();
1480 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1482 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1483 But, if it's a statement-expression with a scopeless block, there's
1484 nothing to keep, and we don't want to accidentally keep a block
1485 *inside* the scopeless block. */
1486 keep_next_level (false);
1490 scope_kind sk
= sk_block
;
1491 if (flags
& BCS_TRY_BLOCK
)
1493 else if (flags
& BCS_TRANSACTION
)
1494 sk
= sk_transaction
;
1495 r
= do_pushlevel (sk
);
1498 /* When processing a template, we need to remember where the braces were,
1499 so that we can set up identical scopes when instantiating the template
1500 later. BIND_EXPR is a handy candidate for this.
1501 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1502 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1503 processing templates. */
1504 if (processing_template_decl
)
1506 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1507 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1508 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1509 TREE_SIDE_EFFECTS (r
) = 1;
1515 /* Finish a compound-statement, which is given by STMT. */
1518 finish_compound_stmt (tree stmt
)
1520 if (TREE_CODE (stmt
) == BIND_EXPR
)
1522 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1523 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1524 discard the BIND_EXPR so it can be merged with the containing
1526 if (TREE_CODE (body
) == STATEMENT_LIST
1527 && STATEMENT_LIST_HEAD (body
) == NULL
1528 && !BIND_EXPR_BODY_BLOCK (stmt
)
1529 && !BIND_EXPR_TRY_BLOCK (stmt
))
1532 BIND_EXPR_BODY (stmt
) = body
;
1534 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1535 stmt
= pop_stmt_list (stmt
);
1538 /* Destroy any ObjC "super" receivers that may have been
1540 objc_clear_super_receiver ();
1542 stmt
= do_poplevel (stmt
);
1545 /* ??? See c_end_compound_stmt wrt statement expressions. */
1549 /* Finish an asm-statement, whose components are a STRING, some
1550 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1551 LABELS. Also note whether the asm-statement should be
1552 considered volatile, and whether it is asm inline. */
1555 finish_asm_stmt (location_t loc
, int volatile_p
, tree string
,
1556 tree output_operands
, tree input_operands
, tree clobbers
,
1557 tree labels
, bool inline_p
)
1561 int ninputs
= list_length (input_operands
);
1562 int noutputs
= list_length (output_operands
);
1564 if (!processing_template_decl
)
1566 const char *constraint
;
1567 const char **oconstraints
;
1568 bool allows_mem
, allows_reg
, is_inout
;
1572 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1574 string
= resolve_asm_operand_names (string
, output_operands
,
1575 input_operands
, labels
);
1577 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1579 operand
= TREE_VALUE (t
);
1581 /* ??? Really, this should not be here. Users should be using a
1582 proper lvalue, dammit. But there's a long history of using
1583 casts in the output operands. In cases like longlong.h, this
1584 becomes a primitive form of typechecking -- if the cast can be
1585 removed, then the output operand had a type of the proper width;
1586 otherwise we'll get an error. Gross, but ... */
1587 STRIP_NOPS (operand
);
1589 operand
= mark_lvalue_use (operand
);
1591 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1592 operand
= error_mark_node
;
1594 if (operand
!= error_mark_node
1595 && (TREE_READONLY (operand
)
1596 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1597 /* Functions are not modifiable, even though they are
1599 || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand
))
1600 /* If it's an aggregate and any field is const, then it is
1601 effectively const. */
1602 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1603 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1604 cxx_readonly_error (loc
, operand
, lv_asm
);
1606 tree
*op
= &operand
;
1607 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1608 op
= &TREE_OPERAND (*op
, 1);
1609 switch (TREE_CODE (*op
))
1611 case PREINCREMENT_EXPR
:
1612 case PREDECREMENT_EXPR
:
1614 *op
= genericize_compound_lvalue (*op
);
1615 op
= &TREE_OPERAND (*op
, 1);
1621 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1622 oconstraints
[i
] = constraint
;
1624 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1625 &allows_mem
, &allows_reg
, &is_inout
))
1627 /* If the operand is going to end up in memory,
1628 mark it addressable. */
1629 if (!allows_reg
&& !cxx_mark_addressable (*op
))
1630 operand
= error_mark_node
;
1633 operand
= error_mark_node
;
1635 TREE_VALUE (t
) = operand
;
1638 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1640 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1641 bool constraint_parsed
1642 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1643 oconstraints
, &allows_mem
, &allows_reg
);
1644 /* If the operand is going to end up in memory, don't call
1645 decay_conversion. */
1646 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1647 operand
= mark_lvalue_use (TREE_VALUE (t
));
1649 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1651 /* If the type of the operand hasn't been determined (e.g.,
1652 because it involves an overloaded function), then issue
1653 an error message. There's no context available to
1654 resolve the overloading. */
1655 if (TREE_TYPE (operand
) == unknown_type_node
)
1658 "type of %<asm%> operand %qE could not be determined",
1660 operand
= error_mark_node
;
1663 if (constraint_parsed
)
1665 /* If the operand is going to end up in memory,
1666 mark it addressable. */
1667 if (!allows_reg
&& allows_mem
)
1669 /* Strip the nops as we allow this case. FIXME, this really
1670 should be rejected or made deprecated. */
1671 STRIP_NOPS (operand
);
1673 tree
*op
= &operand
;
1674 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1675 op
= &TREE_OPERAND (*op
, 1);
1676 switch (TREE_CODE (*op
))
1678 case PREINCREMENT_EXPR
:
1679 case PREDECREMENT_EXPR
:
1681 *op
= genericize_compound_lvalue (*op
);
1682 op
= &TREE_OPERAND (*op
, 1);
1688 if (!cxx_mark_addressable (*op
))
1689 operand
= error_mark_node
;
1691 else if (!allows_reg
&& !allows_mem
)
1693 /* If constraint allows neither register nor memory,
1694 try harder to get a constant. */
1695 tree constop
= maybe_constant_value (operand
);
1696 if (TREE_CONSTANT (constop
))
1701 operand
= error_mark_node
;
1703 TREE_VALUE (t
) = operand
;
1707 r
= build_stmt (loc
, ASM_EXPR
, string
,
1708 output_operands
, input_operands
,
1710 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1711 ASM_INLINE_P (r
) = inline_p
;
1712 r
= maybe_cleanup_point_expr_void (r
);
1713 return add_stmt (r
);
1716 /* Finish a label with the indicated NAME. Returns the new label. */
1719 finish_label_stmt (tree name
)
1721 tree decl
= define_label (input_location
, name
);
1723 if (decl
== error_mark_node
)
1724 return error_mark_node
;
1726 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1731 /* Finish a series of declarations for local labels. G++ allows users
1732 to declare "local" labels, i.e., labels with scope. This extension
1733 is useful when writing code involving statement-expressions. */
1736 finish_label_decl (tree name
)
1738 if (!at_function_scope_p ())
1740 error ("%<__label__%> declarations are only allowed in function scopes");
1744 add_decl_expr (declare_local_label (name
));
1747 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1750 finish_decl_cleanup (tree decl
, tree cleanup
)
1752 push_cleanup (decl
, cleanup
, false);
1755 /* If the current scope exits with an exception, run CLEANUP. */
1758 finish_eh_cleanup (tree cleanup
)
1760 push_cleanup (NULL
, cleanup
, true);
1763 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1764 order they were written by the user. Each node is as for
1765 emit_mem_initializers. */
1768 finish_mem_initializers (tree mem_inits
)
1770 /* Reorder the MEM_INITS so that they are in the order they appeared
1771 in the source program. */
1772 mem_inits
= nreverse (mem_inits
);
1774 if (processing_template_decl
)
1778 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1780 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1781 check for bare parameter packs in the TREE_VALUE, because
1782 any parameter packs in the TREE_VALUE have already been
1783 bound as part of the TREE_PURPOSE. See
1784 make_pack_expansion for more information. */
1785 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1786 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1787 TREE_VALUE (mem
) = error_mark_node
;
1790 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1791 CTOR_INITIALIZER
, mem_inits
));
1794 emit_mem_initializers (mem_inits
);
1797 /* Obfuscate EXPR if it looks like an id-expression or member access so
1798 that the call to finish_decltype in do_auto_deduction will give the
1799 right result. If EVEN_UNEVAL, do this even in unevaluated context. */
1802 force_paren_expr (tree expr
, bool even_uneval
)
1804 /* This is only needed for decltype(auto) in C++14. */
1805 if (cxx_dialect
< cxx14
)
1808 /* If we're in unevaluated context, we can't be deducing a
1809 return/initializer type, so we don't need to mess with this. */
1810 if (cp_unevaluated_operand
&& !even_uneval
)
1813 if (!DECL_P (tree_strip_any_location_wrapper (expr
))
1814 && TREE_CODE (expr
) != COMPONENT_REF
1815 && TREE_CODE (expr
) != SCOPE_REF
)
1818 location_t loc
= cp_expr_location (expr
);
1820 if (TREE_CODE (expr
) == COMPONENT_REF
1821 || TREE_CODE (expr
) == SCOPE_REF
)
1822 REF_PARENTHESIZED_P (expr
) = true;
1823 else if (processing_template_decl
)
1824 expr
= build1_loc (loc
, PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1827 expr
= build1_loc (loc
, VIEW_CONVERT_EXPR
, TREE_TYPE (expr
), expr
);
1828 REF_PARENTHESIZED_P (expr
) = true;
1834 /* If T is an id-expression obfuscated by force_paren_expr, undo the
1835 obfuscation and return the underlying id-expression. Otherwise
1839 maybe_undo_parenthesized_ref (tree t
)
1841 if (cxx_dialect
< cxx14
)
1844 if (INDIRECT_REF_P (t
) && REF_PARENTHESIZED_P (t
))
1846 t
= TREE_OPERAND (t
, 0);
1847 while (TREE_CODE (t
) == NON_LVALUE_EXPR
1848 || TREE_CODE (t
) == NOP_EXPR
)
1849 t
= TREE_OPERAND (t
, 0);
1851 gcc_assert (TREE_CODE (t
) == ADDR_EXPR
1852 || TREE_CODE (t
) == STATIC_CAST_EXPR
);
1853 t
= TREE_OPERAND (t
, 0);
1855 else if (TREE_CODE (t
) == PAREN_EXPR
)
1856 t
= TREE_OPERAND (t
, 0);
1857 else if (TREE_CODE (t
) == VIEW_CONVERT_EXPR
1858 && REF_PARENTHESIZED_P (t
))
1859 t
= TREE_OPERAND (t
, 0);
1864 /* Finish a parenthesized expression EXPR. */
1867 finish_parenthesized_expr (cp_expr expr
)
1870 /* This inhibits warnings in c_common_truthvalue_conversion. */
1871 TREE_NO_WARNING (expr
) = 1;
1873 if (TREE_CODE (expr
) == OFFSET_REF
1874 || TREE_CODE (expr
) == SCOPE_REF
)
1875 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1876 enclosed in parentheses. */
1877 PTRMEM_OK_P (expr
) = 0;
1879 tree stripped_expr
= tree_strip_any_location_wrapper (expr
);
1880 if (TREE_CODE (stripped_expr
) == STRING_CST
)
1881 PAREN_STRING_LITERAL_P (stripped_expr
) = 1;
1883 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
1888 /* Finish a reference to a non-static data member (DECL) that is not
1889 preceded by `.' or `->'. */
1892 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1894 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1895 bool try_omp_private
= !object
&& omp_private_member_map
;
1900 tree scope
= qualifying_scope
;
1901 if (scope
== NULL_TREE
)
1903 scope
= context_for_name_lookup (decl
);
1904 if (!TYPE_P (scope
))
1906 /* Can happen during error recovery (c++/85014). */
1907 gcc_assert (seen_error ());
1908 return error_mark_node
;
1911 object
= maybe_dummy_object (scope
, NULL
);
1914 object
= maybe_resolve_dummy (object
, true);
1915 if (object
== error_mark_node
)
1916 return error_mark_node
;
1918 /* DR 613/850: Can use non-static data members without an associated
1919 object in sizeof/decltype/alignof. */
1920 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
1921 && (!processing_template_decl
|| !current_class_ref
))
1923 if (current_function_decl
1924 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1925 error ("invalid use of member %qD in static member function", decl
);
1927 error ("invalid use of non-static data member %qD", decl
);
1928 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
1930 return error_mark_node
;
1933 if (current_class_ptr
)
1934 TREE_USED (current_class_ptr
) = 1;
1935 if (processing_template_decl
)
1937 tree type
= TREE_TYPE (decl
);
1939 if (TYPE_REF_P (type
))
1940 /* Quals on the object don't matter. */;
1941 else if (PACK_EXPANSION_P (type
))
1942 /* Don't bother trying to represent this. */
1946 /* Set the cv qualifiers. */
1947 int quals
= cp_type_quals (TREE_TYPE (object
));
1949 if (DECL_MUTABLE_P (decl
))
1950 quals
&= ~TYPE_QUAL_CONST
;
1952 quals
|= cp_type_quals (TREE_TYPE (decl
));
1953 type
= cp_build_qualified_type (type
, quals
);
1956 if (qualifying_scope
)
1957 /* Wrap this in a SCOPE_REF for now. */
1958 ret
= build_qualified_name (type
, qualifying_scope
, decl
,
1959 /*template_p=*/false);
1961 ret
= (convert_from_reference
1962 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
1964 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1965 QUALIFYING_SCOPE is also non-null. */
1968 tree access_type
= TREE_TYPE (object
);
1970 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
1971 decl
, tf_warning_or_error
);
1973 /* If the data member was named `C::M', convert `*this' to `C'
1975 if (qualifying_scope
)
1977 tree binfo
= NULL_TREE
;
1978 object
= build_scoped_ref (object
, qualifying_scope
,
1982 ret
= build_class_member_access_expr (object
, decl
,
1983 /*access_path=*/NULL_TREE
,
1984 /*preserve_reference=*/false,
1985 tf_warning_or_error
);
1987 if (try_omp_private
)
1989 tree
*v
= omp_private_member_map
->get (decl
);
1991 ret
= convert_from_reference (*v
);
1996 /* If we are currently parsing a template and we encountered a typedef
1997 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1998 adds the typedef to a list tied to the current template.
1999 At template instantiation time, that list is walked and access check
2000 performed for each typedef.
2001 LOCATION is the location of the usage point of TYPEDEF_DECL. */
2004 add_typedef_to_current_template_for_access_check (tree typedef_decl
,
2006 location_t location
)
2008 tree template_info
= NULL
;
2009 tree cs
= current_scope ();
2011 if (!is_typedef_decl (typedef_decl
)
2013 || !CLASS_TYPE_P (context
)
2017 if (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
)
2018 template_info
= get_template_info (cs
);
2021 && TI_TEMPLATE (template_info
)
2022 && !currently_open_class (context
))
2023 append_type_to_template_for_access_check (cs
, typedef_decl
,
2027 /* DECL was the declaration to which a qualified-id resolved. Issue
2028 an error message if it is not accessible. If OBJECT_TYPE is
2029 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2030 type of `*x', or `x', respectively. If the DECL was named as
2031 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
2034 check_accessibility_of_qualified_id (tree decl
,
2036 tree nested_name_specifier
)
2039 tree qualifying_type
= NULL_TREE
;
2041 /* If we are parsing a template declaration and if decl is a typedef,
2042 add it to a list tied to the template.
2043 At template instantiation time, that list will be walked and
2044 access check performed. */
2045 add_typedef_to_current_template_for_access_check (decl
,
2046 nested_name_specifier
2047 ? nested_name_specifier
2048 : DECL_CONTEXT (decl
),
2051 /* If we're not checking, return immediately. */
2052 if (deferred_access_no_check
)
2055 /* Determine the SCOPE of DECL. */
2056 scope
= context_for_name_lookup (decl
);
2057 /* If the SCOPE is not a type, then DECL is not a member. */
2058 if (!TYPE_P (scope
))
2060 /* Compute the scope through which DECL is being accessed. */
2062 /* OBJECT_TYPE might not be a class type; consider:
2064 class A { typedef int I; };
2068 In this case, we will have "A::I" as the DECL, but "I" as the
2070 && CLASS_TYPE_P (object_type
)
2071 && DERIVED_FROM_P (scope
, object_type
))
2072 /* If we are processing a `->' or `.' expression, use the type of the
2074 qualifying_type
= object_type
;
2075 else if (nested_name_specifier
)
2077 /* If the reference is to a non-static member of the
2078 current class, treat it as if it were referenced through
2081 if (DECL_NONSTATIC_MEMBER_P (decl
)
2082 && current_class_ptr
2083 && DERIVED_FROM_P (scope
, ct
= current_nonlambda_class_type ()))
2084 qualifying_type
= ct
;
2085 /* Otherwise, use the type indicated by the
2086 nested-name-specifier. */
2088 qualifying_type
= nested_name_specifier
;
2091 /* Otherwise, the name must be from the current class or one of
2093 qualifying_type
= currently_open_derived_class (scope
);
2096 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2097 or similar in a default argument value. */
2098 && CLASS_TYPE_P (qualifying_type
)
2099 && !dependent_type_p (qualifying_type
))
2100 perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
2101 decl
, tf_warning_or_error
);
2104 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2105 class named to the left of the "::" operator. DONE is true if this
2106 expression is a complete postfix-expression; it is false if this
2107 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2108 iff this expression is the operand of '&'. TEMPLATE_P is true iff
2109 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2110 is true iff this qualified name appears as a template argument. */
2113 finish_qualified_id_expr (tree qualifying_class
,
2118 bool template_arg_p
,
2119 tsubst_flags_t complain
)
2121 gcc_assert (TYPE_P (qualifying_class
));
2123 if (error_operand_p (expr
))
2124 return error_mark_node
;
2126 if ((DECL_P (expr
) || BASELINK_P (expr
))
2127 && !mark_used (expr
, complain
))
2128 return error_mark_node
;
2132 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
2134 /* cp_parser_lookup_name thought we were looking for a type,
2135 but we're actually looking for a declaration. */
2136 qualifying_class
= TYPE_CONTEXT (expr
);
2137 expr
= TYPE_IDENTIFIER (expr
);
2140 check_template_keyword (expr
);
2143 /* If EXPR occurs as the operand of '&', use special handling that
2144 permits a pointer-to-member. */
2145 if (address_p
&& done
)
2147 if (TREE_CODE (expr
) == SCOPE_REF
)
2148 expr
= TREE_OPERAND (expr
, 1);
2149 expr
= build_offset_ref (qualifying_class
, expr
,
2150 /*address_p=*/true, complain
);
2154 /* No need to check access within an enum. */
2155 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
2156 && TREE_CODE (expr
) != IDENTIFIER_NODE
)
2159 /* Within the scope of a class, turn references to non-static
2160 members into expression of the form "this->...". */
2162 /* But, within a template argument, we do not want make the
2163 transformation, as there is no "this" pointer. */
2165 else if (TREE_CODE (expr
) == FIELD_DECL
)
2167 push_deferring_access_checks (dk_no_check
);
2168 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2170 pop_deferring_access_checks ();
2172 else if (BASELINK_P (expr
))
2174 /* See if any of the functions are non-static members. */
2175 /* If so, the expression may be relative to 'this'. */
2176 if ((type_dependent_expression_p (expr
)
2177 || !shared_member_p (expr
))
2178 && current_class_ptr
2179 && DERIVED_FROM_P (qualifying_class
,
2180 current_nonlambda_class_type ()))
2181 expr
= (build_class_member_access_expr
2182 (maybe_dummy_object (qualifying_class
, NULL
),
2184 BASELINK_ACCESS_BINFO (expr
),
2185 /*preserve_reference=*/false,
2188 /* The expression is a qualified name whose address is not
2190 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2193 else if (!template_p
2194 && TREE_CODE (expr
) == TEMPLATE_DECL
2195 && !DECL_FUNCTION_TEMPLATE_P (expr
))
2197 if (complain
& tf_error
)
2198 error ("%qE missing template arguments", expr
);
2199 return error_mark_node
;
2203 /* In a template, return a SCOPE_REF for most qualified-ids
2204 so that we can check access at instantiation time. But if
2205 we're looking at a member of the current instantiation, we
2206 know we have access and building up the SCOPE_REF confuses
2207 non-type template argument handling. */
2208 if (processing_template_decl
2209 && (!currently_open_class (qualifying_class
)
2210 || TREE_CODE (expr
) == IDENTIFIER_NODE
2211 || TREE_CODE (expr
) == TEMPLATE_ID_EXPR
2212 || TREE_CODE (expr
) == BIT_NOT_EXPR
))
2213 expr
= build_qualified_name (TREE_TYPE (expr
),
2214 qualifying_class
, expr
,
2216 else if (tree wrap
= maybe_get_tls_wrapper_call (expr
))
2219 expr
= convert_from_reference (expr
);
2225 /* Begin a statement-expression. The value returned must be passed to
2226 finish_stmt_expr. */
2229 begin_stmt_expr (void)
2231 return push_stmt_list ();
2234 /* Process the final expression of a statement expression. EXPR can be
2235 NULL, if the final expression is empty. Return a STATEMENT_LIST
2236 containing all the statements in the statement-expression, or
2237 ERROR_MARK_NODE if there was an error. */
2240 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2242 if (error_operand_p (expr
))
2244 /* The type of the statement-expression is the type of the last
2246 TREE_TYPE (stmt_expr
) = error_mark_node
;
2247 return error_mark_node
;
2250 /* If the last statement does not have "void" type, then the value
2251 of the last statement is the value of the entire expression. */
2254 tree type
= TREE_TYPE (expr
);
2256 if (type
&& type_unknown_p (type
))
2258 error ("a statement expression is an insufficient context"
2259 " for overload resolution");
2260 TREE_TYPE (stmt_expr
) = error_mark_node
;
2261 return error_mark_node
;
2263 else if (processing_template_decl
)
2265 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2266 expr
= add_stmt (expr
);
2267 /* Mark the last statement so that we can recognize it as such at
2268 template-instantiation time. */
2269 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2271 else if (VOID_TYPE_P (type
))
2273 /* Just treat this like an ordinary statement. */
2274 expr
= finish_expr_stmt (expr
);
2278 /* It actually has a value we need to deal with. First, force it
2279 to be an rvalue so that we won't need to build up a copy
2280 constructor call later when we try to assign it to something. */
2281 expr
= force_rvalue (expr
, tf_warning_or_error
);
2282 if (error_operand_p (expr
))
2283 return error_mark_node
;
2285 /* Update for array-to-pointer decay. */
2286 type
= TREE_TYPE (expr
);
2288 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2289 normal statement, but don't convert to void or actually add
2291 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2292 expr
= maybe_cleanup_point_expr (expr
);
2296 /* The type of the statement-expression is the type of the last
2298 TREE_TYPE (stmt_expr
) = type
;
2304 /* Finish a statement-expression. EXPR should be the value returned
2305 by the previous begin_stmt_expr. Returns an expression
2306 representing the statement-expression. */
2309 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2314 if (error_operand_p (stmt_expr
))
2316 pop_stmt_list (stmt_expr
);
2317 return error_mark_node
;
2320 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2322 type
= TREE_TYPE (stmt_expr
);
2323 result
= pop_stmt_list (stmt_expr
);
2324 TREE_TYPE (result
) = type
;
2326 if (processing_template_decl
)
2328 result
= build_min (STMT_EXPR
, type
, result
);
2329 TREE_SIDE_EFFECTS (result
) = 1;
2330 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2332 else if (CLASS_TYPE_P (type
))
2334 /* Wrap the statement-expression in a TARGET_EXPR so that the
2335 temporary object created by the final expression is destroyed at
2336 the end of the full-expression containing the
2337 statement-expression. */
2338 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2344 /* Returns the expression which provides the value of STMT_EXPR. */
2347 stmt_expr_value_expr (tree stmt_expr
)
2349 tree t
= STMT_EXPR_STMT (stmt_expr
);
2351 if (TREE_CODE (t
) == BIND_EXPR
)
2352 t
= BIND_EXPR_BODY (t
);
2354 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2355 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2357 if (TREE_CODE (t
) == EXPR_STMT
)
2358 t
= EXPR_STMT_EXPR (t
);
2363 /* Return TRUE iff EXPR_STMT is an empty list of
2364 expression statements. */
2367 empty_expr_stmt_p (tree expr_stmt
)
2369 tree body
= NULL_TREE
;
2371 if (expr_stmt
== void_node
)
2376 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2377 body
= EXPR_STMT_EXPR (expr_stmt
);
2378 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2384 if (TREE_CODE (body
) == STATEMENT_LIST
)
2385 return tsi_end_p (tsi_start (body
));
2387 return empty_expr_stmt_p (body
);
2392 /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
2393 the function (or functions) to call; ARGS are the arguments to the
2394 call. Returns the functions to be considered by overload resolution. */
2397 perform_koenig_lookup (cp_expr fn_expr
, vec
<tree
, va_gc
> *args
,
2398 tsubst_flags_t complain
)
2400 tree identifier
= NULL_TREE
;
2401 tree functions
= NULL_TREE
;
2402 tree tmpl_args
= NULL_TREE
;
2403 bool template_id
= false;
2404 location_t loc
= fn_expr
.get_location ();
2405 tree fn
= fn_expr
.get_value ();
2407 STRIP_ANY_LOCATION_WRAPPER (fn
);
2409 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2411 /* Use a separate flag to handle null args. */
2413 tmpl_args
= TREE_OPERAND (fn
, 1);
2414 fn
= TREE_OPERAND (fn
, 0);
2417 /* Find the name of the overloaded function. */
2418 if (identifier_p (fn
))
2423 identifier
= OVL_NAME (functions
);
2426 /* A call to a namespace-scope function using an unqualified name.
2428 Do Koenig lookup -- unless any of the arguments are
2430 if (!any_type_dependent_arguments_p (args
)
2431 && !any_dependent_template_arguments_p (tmpl_args
))
2433 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2436 /* The unqualified name could not be resolved. */
2437 if (complain
& tf_error
)
2438 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2444 if (fn
&& template_id
&& fn
!= error_mark_node
)
2445 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2447 return cp_expr (fn
, loc
);
2450 /* Generate an expression for `FN (ARGS)'. This may change the
2453 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2454 as a virtual call, even if FN is virtual. (This flag is set when
2455 encountering an expression where the function name is explicitly
2456 qualified. For example a call to `X::f' never generates a virtual
2459 Returns code for the call. */
2462 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2463 bool koenig_p
, tsubst_flags_t complain
)
2467 vec
<tree
, va_gc
> *orig_args
= *args
;
2469 if (fn
== error_mark_node
)
2470 return error_mark_node
;
2472 gcc_assert (!TYPE_P (fn
));
2474 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2475 it so that we can tell this is a call to a known function. */
2476 fn
= maybe_undo_parenthesized_ref (fn
);
2478 STRIP_ANY_LOCATION_WRAPPER (fn
);
2482 if (processing_template_decl
)
2484 /* If FN is a local extern declaration or set thereof, look them up
2485 again at instantiation time. */
2486 if (is_overloaded_fn (fn
))
2488 tree ifn
= get_first_fn (fn
);
2489 if (TREE_CODE (ifn
) == FUNCTION_DECL
2490 && DECL_LOCAL_FUNCTION_P (ifn
))
2491 orig_fn
= DECL_NAME (ifn
);
2494 /* If the call expression is dependent, build a CALL_EXPR node
2495 with no type; type_dependent_expression_p recognizes
2496 expressions with no type as being dependent. */
2497 if (type_dependent_expression_p (fn
)
2498 || any_type_dependent_arguments_p (*args
))
2500 result
= build_min_nt_call_vec (orig_fn
, *args
);
2501 SET_EXPR_LOCATION (result
, cp_expr_loc_or_input_loc (fn
));
2502 KOENIG_LOOKUP_P (result
) = koenig_p
;
2503 if (is_overloaded_fn (fn
))
2508 bool abnormal
= true;
2509 for (lkp_iterator
iter (fn
); abnormal
&& iter
; ++iter
)
2511 tree fndecl
= *iter
;
2512 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2513 || !TREE_THIS_VOLATILE (fndecl
))
2516 /* FIXME: Stop warning about falling off end of non-void
2517 function. But this is wrong. Even if we only see
2518 no-return fns at this point, we could select a
2519 future-defined return fn during instantiation. Or
2522 current_function_returns_abnormally
= 1;
2526 orig_args
= make_tree_vector_copy (*args
);
2527 if (!BASELINK_P (fn
)
2528 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2529 && TREE_TYPE (fn
) != unknown_type_node
)
2530 fn
= build_non_dependent_expr (fn
);
2531 make_args_non_dependent (*args
);
2534 if (TREE_CODE (fn
) == COMPONENT_REF
)
2536 tree member
= TREE_OPERAND (fn
, 1);
2537 if (BASELINK_P (member
))
2539 tree object
= TREE_OPERAND (fn
, 0);
2540 return build_new_method_call (object
, member
,
2543 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2550 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2551 if (TREE_CODE (fn
) == ADDR_EXPR
2552 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2553 fn
= TREE_OPERAND (fn
, 0);
2555 if (is_overloaded_fn (fn
))
2556 fn
= baselink_for_fns (fn
);
2559 if (BASELINK_P (fn
))
2563 /* A call to a member function. From [over.call.func]:
2565 If the keyword this is in scope and refers to the class of
2566 that member function, or a derived class thereof, then the
2567 function call is transformed into a qualified function call
2568 using (*this) as the postfix-expression to the left of the
2569 . operator.... [Otherwise] a contrived object of type T
2570 becomes the implied object argument.
2574 struct A { void f(); };
2575 struct B : public A {};
2576 struct C : public A { void g() { B::f(); }};
2578 "the class of that member function" refers to `A'. But 11.2
2579 [class.access.base] says that we need to convert 'this' to B* as
2580 part of the access, so we pass 'B' to maybe_dummy_object. */
2582 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2584 /* A constructor call always uses a dummy object. (This constructor
2585 call which has the form A::A () is actually invalid and we are
2586 going to reject it later in build_new_method_call.) */
2587 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2590 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2593 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2595 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2600 else if (concept_check_p (fn
))
2602 /* FN is actually a template-id referring to a concept definition. */
2603 tree id
= unpack_concept_check (fn
);
2604 tree tmpl
= TREE_OPERAND (id
, 0);
2605 tree args
= TREE_OPERAND (id
, 1);
2607 if (!function_concept_p (tmpl
))
2609 error_at (EXPR_LOC_OR_LOC (fn
, input_location
),
2610 "cannot call a concept as a function");
2611 return error_mark_node
;
2614 /* Ensure the result is wrapped as a call expression. */
2615 result
= build_concept_check (tmpl
, args
, tf_warning_or_error
);
2617 else if (is_overloaded_fn (fn
))
2619 /* If the function is an overloaded builtin, resolve it. */
2620 if (TREE_CODE (fn
) == FUNCTION_DECL
2621 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2622 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2623 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2627 if (warn_sizeof_pointer_memaccess
2628 && (complain
& tf_warning
)
2629 && !vec_safe_is_empty (*args
)
2630 && !processing_template_decl
)
2632 location_t sizeof_arg_loc
[3];
2635 for (i
= 0; i
< 3; i
++)
2639 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2640 sizeof_arg
[i
] = NULL_TREE
;
2641 if (i
>= (*args
)->length ())
2644 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2646 if (SIZEOF_EXPR_TYPE_P (t
))
2647 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2649 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2650 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2652 sizeof_pointer_memaccess_warning
2653 (sizeof_arg_loc
, fn
, *args
,
2654 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2657 if ((complain
& tf_warning
)
2658 && TREE_CODE (fn
) == FUNCTION_DECL
2659 && fndecl_built_in_p (fn
, BUILT_IN_MEMSET
)
2660 && vec_safe_length (*args
) == 3
2661 && !any_type_dependent_arguments_p (*args
))
2663 tree arg0
= (*orig_args
)[0];
2664 tree arg1
= (*orig_args
)[1];
2665 tree arg2
= (*orig_args
)[2];
2666 int literal_mask
= ((literal_integer_zerop (arg1
) << 1)
2667 | (literal_integer_zerop (arg2
) << 2));
2668 warn_for_memset (input_location
, arg0
, arg2
, literal_mask
);
2671 /* A call to a namespace-scope function. */
2672 result
= build_new_function_call (fn
, args
, complain
);
2675 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2677 if (!vec_safe_is_empty (*args
))
2678 error ("arguments to destructor are not allowed");
2679 /* Mark the pseudo-destructor call as having side-effects so
2680 that we do not issue warnings about its use. */
2681 result
= build1 (NOP_EXPR
,
2683 TREE_OPERAND (fn
, 0));
2684 TREE_SIDE_EFFECTS (result
) = 1;
2686 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2687 /* If the "function" is really an object of class type, it might
2688 have an overloaded `operator ()'. */
2689 result
= build_op_call (fn
, args
, complain
);
2692 /* A call where the function is unknown. */
2693 result
= cp_build_function_call_vec (fn
, args
, complain
);
2695 if (processing_template_decl
&& result
!= error_mark_node
)
2697 if (INDIRECT_REF_P (result
))
2698 result
= TREE_OPERAND (result
, 0);
2699 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2700 SET_EXPR_LOCATION (result
, input_location
);
2701 KOENIG_LOOKUP_P (result
) = koenig_p
;
2702 release_tree_vector (orig_args
);
2703 result
= convert_from_reference (result
);
2709 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2710 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2711 POSTDECREMENT_EXPR.) */
2714 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2716 /* input_location holds the location of the trailing operator token.
2717 Build a location of the form:
2720 with the caret at the operator token, ranging from the start
2721 of EXPR to the end of the operator token. */
2722 location_t combined_loc
= make_location (input_location
,
2724 get_finish (input_location
));
2725 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2726 tf_warning_or_error
);
2727 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2728 result
.set_location (combined_loc
);
2732 /* Finish a use of `this'. Returns an expression for `this'. */
2735 finish_this_expr (void)
2737 tree result
= NULL_TREE
;
2739 if (current_class_ptr
)
2741 tree type
= TREE_TYPE (current_class_ref
);
2743 /* In a lambda expression, 'this' refers to the captured 'this'. */
2744 if (LAMBDA_TYPE_P (type
))
2745 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2747 result
= current_class_ptr
;
2751 /* The keyword 'this' is a prvalue expression. */
2752 return rvalue (result
);
2754 tree fn
= current_nonlambda_function ();
2755 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2756 error ("%<this%> is unavailable for static member functions");
2758 error ("invalid use of %<this%> in non-member function");
2760 error ("invalid use of %<this%> at top level");
2761 return error_mark_node
;
2764 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2765 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2766 the TYPE for the type given. If SCOPE is non-NULL, the expression
2767 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2770 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2773 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2774 return error_mark_node
;
2776 gcc_assert (TYPE_P (destructor
));
2778 if (!processing_template_decl
)
2780 if (scope
== error_mark_node
)
2782 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2783 return error_mark_node
;
2785 if (is_auto (destructor
))
2786 destructor
= TREE_TYPE (object
);
2787 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2790 "qualified type %qT does not match destructor name ~%qT",
2792 return error_mark_node
;
2796 /* [expr.pseudo] says both:
2798 The type designated by the pseudo-destructor-name shall be
2799 the same as the object type.
2803 The cv-unqualified versions of the object type and of the
2804 type designated by the pseudo-destructor-name shall be the
2807 We implement the more generous second sentence, since that is
2808 what most other compilers do. */
2809 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2812 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2813 return error_mark_node
;
2817 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, void_type_node
, object
,
2821 /* Finish an expression of the form CODE EXPR. */
2824 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
2825 tsubst_flags_t complain
)
2827 /* Build a location of the form:
2830 with the caret at the operator token, ranging from the start
2831 of the operator token to the end of EXPR. */
2832 location_t combined_loc
= make_location (op_loc
,
2833 op_loc
, expr
.get_finish ());
2834 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
, complain
);
2835 /* TODO: build_x_unary_op doesn't always honor the location. */
2836 result
.set_location (combined_loc
);
2838 if (result
== error_mark_node
)
2841 if (!(complain
& tf_warning
))
2844 tree result_ovl
= result
;
2845 tree expr_ovl
= expr
;
2847 if (!processing_template_decl
)
2848 expr_ovl
= cp_fully_fold (expr_ovl
);
2850 if (!CONSTANT_CLASS_P (expr_ovl
)
2851 || TREE_OVERFLOW_P (expr_ovl
))
2854 if (!processing_template_decl
)
2855 result_ovl
= cp_fully_fold (result_ovl
);
2857 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
2858 overflow_warning (combined_loc
, result_ovl
);
2863 /* Finish a compound-literal expression or C++11 functional cast with aggregate
2864 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
2868 finish_compound_literal (tree type
, tree compound_literal
,
2869 tsubst_flags_t complain
,
2872 if (type
== error_mark_node
)
2873 return error_mark_node
;
2875 if (TYPE_REF_P (type
))
2878 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2879 complain
, fcl_context
);
2880 /* The prvalue is then used to direct-initialize the reference. */
2881 tree r
= (perform_implicit_conversion_flags
2882 (type
, compound_literal
, complain
, LOOKUP_NORMAL
));
2883 return convert_from_reference (r
);
2886 if (!TYPE_OBJ_P (type
))
2888 if (complain
& tf_error
)
2889 error ("compound literal of non-object type %qT", type
);
2890 return error_mark_node
;
2893 if (tree anode
= type_uses_auto (type
))
2894 if (CLASS_PLACEHOLDER_TEMPLATE (anode
))
2896 type
= do_auto_deduction (type
, compound_literal
, anode
, complain
,
2898 if (type
== error_mark_node
)
2899 return error_mark_node
;
2902 /* Used to hold a copy of the compound literal in a template. */
2903 tree orig_cl
= NULL_TREE
;
2905 if (processing_template_decl
)
2907 const bool dependent_p
2908 = (instantiation_dependent_expression_p (compound_literal
)
2909 || dependent_type_p (type
));
2911 /* We're about to return, no need to copy. */
2912 orig_cl
= compound_literal
;
2914 /* We're going to need a copy. */
2915 orig_cl
= unshare_constructor (compound_literal
);
2916 TREE_TYPE (orig_cl
) = type
;
2917 /* Mark the expression as a compound literal. */
2918 TREE_HAS_CONSTRUCTOR (orig_cl
) = 1;
2919 /* And as instantiation-dependent. */
2920 CONSTRUCTOR_IS_DEPENDENT (orig_cl
) = dependent_p
;
2921 if (fcl_context
== fcl_c99
)
2922 CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl
) = 1;
2923 /* If the compound literal is dependent, we're done for now. */
2926 /* Otherwise, do go on to e.g. check narrowing. */
2929 type
= complete_type (type
);
2931 if (TYPE_NON_AGGREGATE_CLASS (type
))
2933 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2934 everywhere that deals with function arguments would be a pain, so
2935 just wrap it in a TREE_LIST. The parser set a flag so we know
2936 that it came from T{} rather than T({}). */
2937 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2938 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2939 return build_functional_cast (input_location
, type
,
2940 compound_literal
, complain
);
2943 if (TREE_CODE (type
) == ARRAY_TYPE
2944 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2945 return error_mark_node
;
2946 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2947 if (SCALAR_TYPE_P (type
)
2948 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
))
2950 tree t
= instantiate_non_dependent_expr_sfinae (compound_literal
,
2952 if (!check_narrowing (type
, t
, complain
))
2953 return error_mark_node
;
2955 if (TREE_CODE (type
) == ARRAY_TYPE
2956 && TYPE_DOMAIN (type
) == NULL_TREE
)
2958 cp_complete_array_type_or_error (&type
, compound_literal
,
2960 if (type
== error_mark_node
)
2961 return error_mark_node
;
2963 compound_literal
= digest_init_flags (type
, compound_literal
,
2964 LOOKUP_NORMAL
| LOOKUP_NO_NARROWING
,
2966 if (compound_literal
== error_mark_node
)
2967 return error_mark_node
;
2969 /* If we're in a template, return the original compound literal. */
2972 if (!VECTOR_TYPE_P (type
))
2973 return get_target_expr_sfinae (orig_cl
, complain
);
2978 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
2980 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
2981 if (fcl_context
== fcl_c99
)
2982 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
2985 /* Put static/constant array temporaries in static variables. */
2986 /* FIXME all C99 compound literals should be variables rather than C++
2987 temporaries, unless they are used as an aggregate initializer. */
2988 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
2989 && fcl_context
== fcl_c99
2990 && TREE_CODE (type
) == ARRAY_TYPE
2991 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
2992 && initializer_constant_valid_p (compound_literal
, type
))
2994 tree decl
= create_temporary_var (type
);
2995 DECL_INITIAL (decl
) = compound_literal
;
2996 TREE_STATIC (decl
) = 1;
2997 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
2999 /* 5.19 says that a constant expression can include an
3000 lvalue-rvalue conversion applied to "a glvalue of literal type
3001 that refers to a non-volatile temporary object initialized
3002 with a constant expression". Rather than try to communicate
3003 that this VAR_DECL is a temporary, just mark it constexpr. */
3004 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
3005 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
3006 TREE_CONSTANT (decl
) = true;
3008 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
3009 decl
= pushdecl_top_level (decl
);
3010 DECL_NAME (decl
) = make_anon_name ();
3011 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
3012 /* Make sure the destructor is callable. */
3013 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
3014 if (clean
== error_mark_node
)
3015 return error_mark_node
;
3019 /* Represent other compound literals with TARGET_EXPR so we produce
3020 an lvalue, but can elide copies. */
3021 if (!VECTOR_TYPE_P (type
))
3022 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
3024 return compound_literal
;
3027 /* Return the declaration for the function-name variable indicated by
3031 finish_fname (tree id
)
3035 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
3036 if (processing_template_decl
&& current_function_decl
3037 && decl
!= error_mark_node
)
3038 decl
= DECL_NAME (decl
);
3042 /* Finish a translation unit. */
3045 finish_translation_unit (void)
3047 /* In case there were missing closebraces,
3048 get us back to the global binding level. */
3050 while (current_namespace
!= global_namespace
)
3053 /* Do file scope __FUNCTION__ et al. */
3054 finish_fname_decls ();
3056 if (scope_chain
->omp_declare_target_attribute
)
3059 error ("%<#pragma omp declare target%> without corresponding "
3060 "%<#pragma omp end declare target%>");
3061 scope_chain
->omp_declare_target_attribute
= 0;
3065 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
3066 Returns the parameter. */
3069 finish_template_type_parm (tree aggr
, tree identifier
)
3071 if (aggr
!= class_type_node
)
3073 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
3074 aggr
= class_type_node
;
3077 return build_tree_list (aggr
, identifier
);
3080 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
3081 Returns the parameter. */
3084 finish_template_template_parm (tree aggr
, tree identifier
)
3086 tree decl
= build_decl (input_location
,
3087 TYPE_DECL
, identifier
, NULL_TREE
);
3089 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
3090 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
3091 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
3092 DECL_ARTIFICIAL (decl
) = 1;
3094 /* Associate the constraints with the underlying declaration,
3095 not the template. */
3096 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
3097 tree constr
= build_constraints (reqs
, NULL_TREE
);
3098 set_constraints (decl
, constr
);
3100 end_template_decl ();
3102 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
3104 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
3105 /*is_primary=*/true, /*is_partial=*/false,
3108 return finish_template_type_parm (aggr
, tmpl
);
3111 /* ARGUMENT is the default-argument value for a template template
3112 parameter. If ARGUMENT is invalid, issue error messages and return
3113 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
3116 check_template_template_default_arg (tree argument
)
3118 if (TREE_CODE (argument
) != TEMPLATE_DECL
3119 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
3120 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
3122 if (TREE_CODE (argument
) == TYPE_DECL
)
3123 error ("invalid use of type %qT as a default value for a template "
3124 "template-parameter", TREE_TYPE (argument
));
3126 error ("invalid default argument for a template template parameter");
3127 return error_mark_node
;
3133 /* Begin a class definition, as indicated by T. */
3136 begin_class_definition (tree t
)
3138 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
3139 return error_mark_node
;
3141 if (processing_template_parmlist
&& !LAMBDA_TYPE_P (t
))
3143 error ("definition of %q#T inside template parameter list", t
);
3144 return error_mark_node
;
3147 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
3148 are passed the same as decimal scalar types. */
3149 if (TREE_CODE (t
) == RECORD_TYPE
3150 && !processing_template_decl
)
3152 tree ns
= TYPE_CONTEXT (t
);
3153 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
3154 && DECL_CONTEXT (ns
) == std_node
3156 && id_equal (DECL_NAME (ns
), "decimal"))
3158 const char *n
= TYPE_NAME_STRING (t
);
3159 if ((strcmp (n
, "decimal32") == 0)
3160 || (strcmp (n
, "decimal64") == 0)
3161 || (strcmp (n
, "decimal128") == 0))
3162 TYPE_TRANSPARENT_AGGR (t
) = 1;
3166 /* A non-implicit typename comes from code like:
3168 template <typename T> struct A {
3169 template <typename U> struct A<T>::B ...
3171 This is erroneous. */
3172 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
3174 error ("invalid definition of qualified type %qT", t
);
3175 t
= error_mark_node
;
3178 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
3180 t
= make_class_type (RECORD_TYPE
);
3181 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
3184 if (TYPE_BEING_DEFINED (t
))
3186 t
= make_class_type (TREE_CODE (t
));
3187 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
3189 maybe_process_partial_specialization (t
);
3191 TYPE_BEING_DEFINED (t
) = 1;
3192 class_binding_level
->defining_class_p
= 1;
3194 if (flag_pack_struct
)
3197 TYPE_PACKED (t
) = 1;
3198 /* Even though the type is being defined for the first time
3199 here, there might have been a forward declaration, so there
3200 might be cv-qualified variants of T. */
3201 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
3202 TYPE_PACKED (v
) = 1;
3204 /* Reset the interface data, at the earliest possible
3205 moment, as it might have been set via a class foo;
3207 if (! TYPE_UNNAMED_P (t
))
3209 struct c_fileinfo
*finfo
= \
3210 get_fileinfo (LOCATION_FILE (input_location
));
3211 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
3212 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
3213 (t
, finfo
->interface_unknown
);
3215 reset_specialization();
3217 /* Make a declaration for this class in its own scope. */
3218 build_self_reference ();
3223 /* Finish the member declaration given by DECL. */
3226 finish_member_declaration (tree decl
)
3228 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
3231 if (decl
== void_type_node
)
3232 /* The COMPONENT was a friend, not a member, and so there's
3233 nothing for us to do. */
3236 /* We should see only one DECL at a time. */
3237 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
3239 /* Don't add decls after definition. */
3240 gcc_assert (TYPE_BEING_DEFINED (current_class_type
)
3241 /* We can add lambda types when late parsing default
3243 || LAMBDA_TYPE_P (TREE_TYPE (decl
)));
3245 /* Set up access control for DECL. */
3247 = (current_access_specifier
== access_private_node
);
3248 TREE_PROTECTED (decl
)
3249 = (current_access_specifier
== access_protected_node
);
3250 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3252 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
3253 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
3256 /* Mark the DECL as a member of the current class, unless it's
3257 a member of an enumeration. */
3258 if (TREE_CODE (decl
) != CONST_DECL
)
3259 DECL_CONTEXT (decl
) = current_class_type
;
3261 if (TREE_CODE (decl
) == USING_DECL
)
3262 /* For now, ignore class-scope USING_DECLS, so that debugging
3263 backends do not see them. */
3264 DECL_IGNORED_P (decl
) = 1;
3266 /* Check for bare parameter packs in the non-static data member
3268 if (TREE_CODE (decl
) == FIELD_DECL
)
3270 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
3271 TREE_TYPE (decl
) = error_mark_node
;
3272 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3273 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3278 A C language linkage is ignored for the names of class members
3279 and the member function type of class member functions. */
3280 if (DECL_LANG_SPECIFIC (decl
))
3281 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3285 /* Functions and non-functions are added differently. */
3286 if (DECL_DECLARES_FUNCTION_P (decl
))
3287 add
= add_method (current_class_type
, decl
, false);
3288 /* Enter the DECL into the scope of the class, if the class
3289 isn't a closure (whose fields are supposed to be unnamed). */
3290 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3291 || pushdecl_class_level (decl
))
3296 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3297 go at the beginning. The reason is that
3298 legacy_nonfn_member_lookup searches the list in order, and we
3299 want a field name to override a type name so that the "struct
3300 stat hack" will work. In particular:
3302 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3306 if (TREE_CODE (decl
) == TYPE_DECL
)
3307 TYPE_FIELDS (current_class_type
)
3308 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3311 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3312 TYPE_FIELDS (current_class_type
) = decl
;
3315 maybe_add_class_template_decl_list (current_class_type
, decl
,
3320 /* Finish processing a complete template declaration. The PARMS are
3321 the template parameters. */
3324 finish_template_decl (tree parms
)
3327 end_template_decl ();
3329 end_specialization ();
3332 // Returns the template type of the class scope being entered. If we're
3333 // entering a constrained class scope. TYPE is the class template
3334 // scope being entered and we may need to match the intended type with
3335 // a constrained specialization. For example:
3337 // template<Object T>
3338 // struct S { void f(); }; #1
3340 // template<Object T>
3341 // void S<T>::f() { } #2
3343 // We check, in #2, that S<T> refers precisely to the type declared by
3344 // #1 (i.e., that the constraints match). Note that the following should
3345 // be an error since there is no specialization of S<T> that is
3346 // unconstrained, but this is not diagnosed here.
3348 // template<typename T>
3349 // void S<T>::f() { }
3351 // We cannot diagnose this problem here since this function also matches
3352 // qualified template names that are not part of a definition. For example:
3354 // template<Integral T, Floating_point U>
3355 // typename pair<T, U>::first_type void f(T, U);
3357 // Here, it is unlikely that there is a partial specialization of
3358 // pair constrained for for Integral and Floating_point arguments.
3360 // The general rule is: if a constrained specialization with matching
3361 // constraints is found return that type. Also note that if TYPE is not a
3362 // class-type (e.g. a typename type), then no fixup is needed.
3365 fixup_template_type (tree type
)
3367 // Find the template parameter list at the a depth appropriate to
3368 // the scope we're trying to enter.
3369 tree parms
= current_template_parms
;
3370 int depth
= template_class_depth (type
);
3371 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3372 parms
= TREE_CHAIN (parms
);
3375 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3376 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3378 // Search for a specialization whose type and constraints match.
3379 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3380 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3383 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3385 // If the type and constraints match a specialization, then we
3386 // are entering that type.
3387 if (same_type_p (type
, TREE_TYPE (specs
))
3388 && equivalent_constraints (cur_constr
, spec_constr
))
3389 return TREE_TYPE (specs
);
3390 specs
= TREE_CHAIN (specs
);
3393 // If no specialization matches, then must return the type
3394 // previously found.
3398 /* Finish processing a template-id (which names a type) of the form
3399 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3400 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3401 the scope of template-id indicated. */
3404 finish_template_type (tree name
, tree args
, int entering_scope
)
3408 type
= lookup_template_class (name
, args
,
3409 NULL_TREE
, NULL_TREE
, entering_scope
,
3410 tf_warning_or_error
| tf_user
);
3412 /* If we might be entering the scope of a partial specialization,
3413 find the one with the right constraints. */
3416 && CLASS_TYPE_P (type
)
3417 && CLASSTYPE_TEMPLATE_INFO (type
)
3418 && dependent_type_p (type
)
3419 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3420 type
= fixup_template_type (type
);
3422 if (type
== error_mark_node
)
3424 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3425 return TYPE_STUB_DECL (type
);
3427 return TYPE_NAME (type
);
3430 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3431 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3432 BASE_CLASS, or NULL_TREE if an error occurred. The
3433 ACCESS_SPECIFIER is one of
3434 access_{default,public,protected_private}_node. For a virtual base
3435 we set TREE_TYPE. */
3438 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3442 if (base
== error_mark_node
)
3444 error ("invalid base-class specification");
3447 else if (! MAYBE_CLASS_TYPE_P (base
))
3449 error ("%qT is not a class type", base
);
3454 if (cp_type_quals (base
) != 0)
3456 /* DR 484: Can a base-specifier name a cv-qualified
3458 base
= TYPE_MAIN_VARIANT (base
);
3460 result
= build_tree_list (access
, base
);
3462 TREE_TYPE (result
) = integer_type_node
;
3468 /* If FNS is a member function, a set of member functions, or a
3469 template-id referring to one or more member functions, return a
3470 BASELINK for FNS, incorporating the current access context.
3471 Otherwise, return FNS unchanged. */
3474 baselink_for_fns (tree fns
)
3479 if (BASELINK_P (fns
)
3480 || error_operand_p (fns
))
3483 scope
= ovl_scope (fns
);
3484 if (!CLASS_TYPE_P (scope
))
3487 cl
= currently_open_derived_class (scope
);
3490 cl
= TYPE_BINFO (cl
);
3491 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3494 /* Returns true iff DECL is a variable from a function outside
3498 outer_var_p (tree decl
)
3500 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3501 && DECL_FUNCTION_SCOPE_P (decl
)
3502 /* Don't get confused by temporaries. */
3504 && (DECL_CONTEXT (decl
) != current_function_decl
3505 || parsing_nsdmi ()));
3508 /* As above, but also checks that DECL is automatic. */
3511 outer_automatic_var_p (tree decl
)
3513 return (outer_var_p (decl
)
3514 && !TREE_STATIC (decl
));
3517 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3518 rewrite it for lambda capture.
3520 If ODR_USE is true, we're being called from mark_use, and we complain about
3521 use of constant variables. If ODR_USE is false, we're being called for the
3522 id-expression, and we do lambda capture. */
3525 process_outer_var_ref (tree decl
, tsubst_flags_t complain
, bool odr_use
)
3527 if (cp_unevaluated_operand
)
3529 tree type
= TREE_TYPE (decl
);
3530 if (!dependent_type_p (type
)
3531 && variably_modified_type_p (type
, NULL_TREE
))
3532 /* VLAs are used even in unevaluated context. */;
3534 /* It's not a use (3.2) if we're in an unevaluated context. */
3537 if (decl
== error_mark_node
)
3540 tree context
= DECL_CONTEXT (decl
);
3541 tree containing_function
= current_function_decl
;
3542 tree lambda_stack
= NULL_TREE
;
3543 tree lambda_expr
= NULL_TREE
;
3544 tree initializer
= convert_from_reference (decl
);
3546 /* Mark it as used now even if the use is ill-formed. */
3547 if (!mark_used (decl
, complain
))
3548 return error_mark_node
;
3550 if (parsing_nsdmi ())
3551 containing_function
= NULL_TREE
;
3553 if (containing_function
&& LAMBDA_FUNCTION_P (containing_function
))
3555 /* Check whether we've already built a proxy. */
3557 while (is_normal_capture_proxy (var
))
3558 var
= DECL_CAPTURED_VARIABLE (var
);
3559 tree d
= retrieve_local_specialization (var
);
3561 if (d
&& d
!= decl
&& is_capture_proxy (d
))
3563 if (DECL_CONTEXT (d
) == containing_function
)
3564 /* We already have an inner proxy. */
3567 /* We need to capture an outer proxy. */
3568 return process_outer_var_ref (d
, complain
, odr_use
);
3572 /* If we are in a lambda function, we can move out until we hit
3574 2. a non-lambda function, or
3575 3. a non-default capturing lambda function. */
3576 while (context
!= containing_function
3577 /* containing_function can be null with invalid generic lambdas. */
3578 && containing_function
3579 && LAMBDA_FUNCTION_P (containing_function
))
3581 tree closure
= DECL_CONTEXT (containing_function
);
3582 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3584 if (TYPE_CLASS_SCOPE_P (closure
))
3585 /* A lambda in an NSDMI (c++/64496). */
3588 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3591 lambda_stack
= tree_cons (NULL_TREE
, lambda_expr
, lambda_stack
);
3593 containing_function
= decl_function_context (containing_function
);
3596 /* In a lambda within a template, wait until instantiation time to implicitly
3597 capture a parameter pack. We want to wait because we don't know if we're
3598 capturing the whole pack or a single element, and it's OK to wait because
3599 find_parameter_packs_r walks into the lambda body. */
3600 if (context
== containing_function
3601 && DECL_PACK_P (decl
))
3604 if (lambda_expr
&& VAR_P (decl
) && DECL_ANON_UNION_VAR_P (decl
))
3606 if (complain
& tf_error
)
3607 error ("cannot capture member %qD of anonymous union", decl
);
3608 return error_mark_node
;
3610 /* Do lambda capture when processing the id-expression, not when
3611 odr-using a variable. */
3612 if (!odr_use
&& context
== containing_function
)
3613 decl
= add_default_capture (lambda_stack
,
3614 /*id=*/DECL_NAME (decl
), initializer
);
3615 /* Only an odr-use of an outer automatic variable causes an
3616 error, and a constant variable can decay to a prvalue
3617 constant without odr-use. So don't complain yet. */
3618 else if (!odr_use
&& decl_constant_var_p (decl
))
3620 else if (lambda_expr
)
3622 if (complain
& tf_error
)
3624 error ("%qD is not captured", decl
);
3625 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3626 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3627 inform (location_of (closure
),
3628 "the lambda has no capture-default");
3629 else if (TYPE_CLASS_SCOPE_P (closure
))
3630 inform (UNKNOWN_LOCATION
, "lambda in local class %q+T cannot "
3631 "capture variables from the enclosing context",
3632 TYPE_CONTEXT (closure
));
3633 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3635 return error_mark_node
;
3639 if (complain
& tf_error
)
3642 ? G_("use of local variable with automatic storage from "
3643 "containing function")
3644 : G_("use of parameter from containing function"));
3645 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3647 return error_mark_node
;
3652 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3653 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3654 if non-NULL, is the type or namespace used to explicitly qualify
3655 ID_EXPRESSION. DECL is the entity to which that name has been
3658 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3659 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3660 be set to true if this expression isn't permitted in a
3661 constant-expression, but it is otherwise not set by this function.
3662 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3663 constant-expression, but a non-constant expression is also
3666 DONE is true if this expression is a complete postfix-expression;
3667 it is false if this expression is followed by '->', '[', '(', etc.
3668 ADDRESS_P is true iff this expression is the operand of '&'.
3669 TEMPLATE_P is true iff the qualified-id was of the form
3670 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3671 appears as a template argument.
3673 If an error occurs, and it is the kind of error that might cause
3674 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3675 is the caller's responsibility to issue the message. *ERROR_MSG
3676 will be a string with static storage duration, so the caller need
3679 Return an expression for the entity, after issuing appropriate
3680 diagnostics. This function is also responsible for transforming a
3681 reference to a non-static member into a COMPONENT_REF that makes
3682 the use of "this" explicit.
3684 Upon return, *IDK will be filled in appropriately. */
3686 finish_id_expression_1 (tree id_expression
,
3690 bool integral_constant_expression_p
,
3691 bool allow_non_integral_constant_expression_p
,
3692 bool *non_integral_constant_expression_p
,
3696 bool template_arg_p
,
3697 const char **error_msg
,
3698 location_t location
)
3700 decl
= strip_using_decl (decl
);
3702 /* Initialize the output parameters. */
3703 *idk
= CP_ID_KIND_NONE
;
3706 if (id_expression
== error_mark_node
)
3707 return error_mark_node
;
3708 /* If we have a template-id, then no further lookup is
3709 required. If the template-id was for a template-class, we
3710 will sometimes have a TYPE_DECL at this point. */
3711 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3712 || TREE_CODE (decl
) == TYPE_DECL
)
3714 /* Look up the name. */
3717 if (decl
== error_mark_node
)
3719 /* Name lookup failed. */
3722 || (!dependent_type_p (scope
)
3723 && !(identifier_p (id_expression
)
3724 && IDENTIFIER_CONV_OP_P (id_expression
)
3725 && dependent_type_p (TREE_TYPE (id_expression
))))))
3727 /* If the qualifying type is non-dependent (and the name
3728 does not name a conversion operator to a dependent
3729 type), issue an error. */
3730 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3731 return error_mark_node
;
3735 /* It may be resolved via Koenig lookup. */
3736 *idk
= CP_ID_KIND_UNQUALIFIED
;
3737 return id_expression
;
3740 decl
= id_expression
;
3743 /* Remember that the name was used in the definition of
3744 the current class so that we can check later to see if
3745 the meaning would have been different after the class
3746 was entirely defined. */
3747 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3748 maybe_note_name_used_in_class (id_expression
, decl
);
3750 /* A use in unevaluated operand might not be instantiated appropriately
3751 if tsubst_copy builds a dummy parm, or if we never instantiate a
3752 generic lambda, so mark it now. */
3753 if (processing_template_decl
&& cp_unevaluated_operand
)
3754 mark_type_use (decl
);
3756 /* Disallow uses of local variables from containing functions, except
3757 within lambda-expressions. */
3758 if (outer_automatic_var_p (decl
))
3760 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3761 if (decl
== error_mark_node
)
3762 return error_mark_node
;
3765 /* Also disallow uses of function parameters outside the function
3766 body, except inside an unevaluated context (i.e. decltype). */
3767 if (TREE_CODE (decl
) == PARM_DECL
3768 && DECL_CONTEXT (decl
) == NULL_TREE
3769 && !cp_unevaluated_operand
)
3771 *error_msg
= G_("use of parameter outside function body");
3772 return error_mark_node
;
3776 /* If we didn't find anything, or what we found was a type,
3777 then this wasn't really an id-expression. */
3778 if (TREE_CODE (decl
) == TEMPLATE_DECL
3779 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3781 *error_msg
= G_("missing template arguments");
3782 return error_mark_node
;
3784 else if (TREE_CODE (decl
) == TYPE_DECL
3785 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3787 *error_msg
= G_("expected primary-expression");
3788 return error_mark_node
;
3791 /* If the name resolved to a template parameter, there is no
3792 need to look it up again later. */
3793 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3794 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3798 *idk
= CP_ID_KIND_NONE
;
3799 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3800 decl
= TEMPLATE_PARM_DECL (decl
);
3801 r
= DECL_INITIAL (decl
);
3802 if (CLASS_TYPE_P (TREE_TYPE (r
)) && !CP_TYPE_CONST_P (TREE_TYPE (r
)))
3804 /* If the entity is a template parameter object for a template
3805 parameter of type T, the type of the expression is const T. */
3806 tree ctype
= TREE_TYPE (r
);
3807 ctype
= cp_build_qualified_type (ctype
, (cp_type_quals (ctype
)
3808 | TYPE_QUAL_CONST
));
3809 r
= build1 (VIEW_CONVERT_EXPR
, ctype
, r
);
3811 r
= convert_from_reference (r
);
3812 if (integral_constant_expression_p
3813 && !dependent_type_p (TREE_TYPE (decl
))
3814 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3816 if (!allow_non_integral_constant_expression_p
)
3817 error ("template parameter %qD of type %qT is not allowed in "
3818 "an integral constant expression because it is not of "
3819 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3820 *non_integral_constant_expression_p
= true;
3826 bool dependent_p
= type_dependent_expression_p (decl
);
3828 /* If the declaration was explicitly qualified indicate
3829 that. The semantics of `A::f(3)' are different than
3830 `f(3)' if `f' is virtual. */
3832 ? CP_ID_KIND_QUALIFIED
3833 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3834 ? CP_ID_KIND_TEMPLATE_ID
3836 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3837 : CP_ID_KIND_UNQUALIFIED
)));
3841 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
3842 /* Dependent type attributes on the decl mean that the TREE_TYPE is
3843 wrong, so just return the identifier. */
3844 return id_expression
;
3846 if (DECL_CLASS_TEMPLATE_P (decl
))
3848 error ("use of class template %qT as expression", decl
);
3849 return error_mark_node
;
3852 if (TREE_CODE (decl
) == TREE_LIST
)
3854 /* Ambiguous reference to base members. */
3855 error ("request for member %qD is ambiguous in "
3856 "multiple inheritance lattice", id_expression
);
3857 print_candidates (decl
);
3858 return error_mark_node
;
3861 /* Mark variable-like entities as used. Functions are similarly
3862 marked either below or after overload resolution. */
3864 || TREE_CODE (decl
) == PARM_DECL
3865 || TREE_CODE (decl
) == CONST_DECL
3866 || TREE_CODE (decl
) == RESULT_DECL
)
3867 && !mark_used (decl
))
3868 return error_mark_node
;
3870 /* Only certain kinds of names are allowed in constant
3871 expression. Template parameters have already
3872 been handled above. */
3873 if (! error_operand_p (decl
)
3875 && integral_constant_expression_p
3876 && !decl_constant_var_p (decl
)
3877 && TREE_CODE (decl
) != CONST_DECL
3878 && !builtin_valid_in_constant_expr_p (decl
)
3879 && !concept_check_p (decl
))
3881 if (!allow_non_integral_constant_expression_p
)
3883 error ("%qD cannot appear in a constant-expression", decl
);
3884 return error_mark_node
;
3886 *non_integral_constant_expression_p
= true;
3889 if (tree wrap
= maybe_get_tls_wrapper_call (decl
))
3890 /* Replace an evaluated use of the thread_local variable with
3891 a call to its wrapper. */
3893 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3895 && variable_template_p (TREE_OPERAND (decl
, 0))
3896 && !concept_check_p (decl
))
3898 decl
= finish_template_variable (decl
);
3900 decl
= convert_from_reference (decl
);
3902 else if (concept_check_p (decl
))
3904 /* Nothing more to do. All of the analysis for concept checks
3905 is done by build_conept_id, called from the parser. */
3909 if (TREE_CODE (decl
) == SCOPE_REF
)
3911 gcc_assert (same_type_p (scope
, TREE_OPERAND (decl
, 0)));
3912 decl
= TREE_OPERAND (decl
, 1);
3915 decl
= (adjust_result_of_qualified_name_lookup
3916 (decl
, scope
, current_nonlambda_class_type()));
3918 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3921 cp_warn_deprecated_use_scopes (scope
);
3924 decl
= finish_qualified_id_expr (scope
,
3930 tf_warning_or_error
);
3932 decl
= convert_from_reference (decl
);
3934 else if (TREE_CODE (decl
) == FIELD_DECL
)
3936 /* Since SCOPE is NULL here, this is an unqualified name.
3937 Access checking has been performed during name lookup
3938 already. Turn off checking to avoid duplicate errors. */
3939 push_deferring_access_checks (dk_no_check
);
3940 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3941 /*qualifying_scope=*/NULL_TREE
);
3942 pop_deferring_access_checks ();
3944 else if (is_overloaded_fn (decl
))
3946 /* We only need to look at the first function,
3947 because all the fns share the attribute we're
3948 concerned with (all member fns or all non-members). */
3949 tree first_fn
= get_first_fn (decl
);
3950 first_fn
= STRIP_TEMPLATE (first_fn
);
3952 /* [basic.def.odr]: "A function whose name appears as a
3953 potentially-evaluated expression is odr-used if it is the unique
3956 But only mark it if it's a complete postfix-expression; in a call,
3957 ADL might select a different function, and we'll call mark_used in
3960 && !really_overloaded_fn (decl
)
3961 && !mark_used (first_fn
))
3962 return error_mark_node
;
3965 && (TREE_CODE (first_fn
) == USING_DECL
3966 || (TREE_CODE (first_fn
) == FUNCTION_DECL
3967 && DECL_FUNCTION_MEMBER_P (first_fn
)
3968 && !shared_member_p (decl
))))
3970 /* A set of member functions. */
3971 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
3972 return finish_class_member_access_expr (decl
, id_expression
,
3973 /*template_p=*/false,
3974 tf_warning_or_error
);
3977 decl
= baselink_for_fns (decl
);
3981 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
3982 && DECL_CLASS_SCOPE_P (decl
))
3984 tree context
= context_for_name_lookup (decl
);
3985 if (context
!= current_class_type
)
3987 tree path
= currently_open_derived_class (context
);
3988 perform_or_defer_access_check (TYPE_BINFO (path
),
3990 tf_warning_or_error
);
3994 decl
= convert_from_reference (decl
);
3998 return cp_expr (decl
, location
);
4001 /* As per finish_id_expression_1, but adding a wrapper node
4002 around the result if needed to express LOCATION. */
4005 finish_id_expression (tree id_expression
,
4009 bool integral_constant_expression_p
,
4010 bool allow_non_integral_constant_expression_p
,
4011 bool *non_integral_constant_expression_p
,
4015 bool template_arg_p
,
4016 const char **error_msg
,
4017 location_t location
)
4020 = finish_id_expression_1 (id_expression
, decl
, scope
, idk
,
4021 integral_constant_expression_p
,
4022 allow_non_integral_constant_expression_p
,
4023 non_integral_constant_expression_p
,
4024 template_p
, done
, address_p
, template_arg_p
,
4025 error_msg
, location
);
4026 return result
.maybe_add_location_wrapper ();
4029 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
4030 use as a type-specifier. */
4033 finish_typeof (tree expr
)
4037 if (type_dependent_expression_p (expr
))
4039 type
= cxx_make_type (TYPEOF_TYPE
);
4040 TYPEOF_TYPE_EXPR (type
) = expr
;
4041 SET_TYPE_STRUCTURAL_EQUALITY (type
);
4046 expr
= mark_type_use (expr
);
4048 type
= unlowered_expr_type (expr
);
4050 if (!type
|| type
== unknown_type_node
)
4052 error ("type of %qE is unknown", expr
);
4053 return error_mark_node
;
4059 /* Implement the __underlying_type keyword: Return the underlying
4060 type of TYPE, suitable for use as a type-specifier. */
4063 finish_underlying_type (tree type
)
4065 tree underlying_type
;
4067 if (processing_template_decl
)
4069 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
4070 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
4071 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
4073 return underlying_type
;
4076 if (!complete_type_or_else (type
, NULL_TREE
))
4077 return error_mark_node
;
4079 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
4081 error ("%qT is not an enumeration type", type
);
4082 return error_mark_node
;
4085 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
4087 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
4088 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
4089 See finish_enum_value_list for details. */
4090 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
4092 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
4093 TYPE_UNSIGNED (underlying_type
));
4095 return underlying_type
;
4098 /* Implement the __direct_bases keyword: Return the direct base classes
4102 calculate_direct_bases (tree type
, tsubst_flags_t complain
)
4104 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4105 || !NON_UNION_CLASS_TYPE_P (type
))
4106 return make_tree_vec (0);
4108 releasing_vec vector
;
4109 vec
<tree
, va_gc
> *base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
4113 /* Virtual bases are initialized first */
4114 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4115 if (BINFO_VIRTUAL_P (binfo
))
4116 vec_safe_push (vector
, binfo
);
4118 /* Now non-virtuals */
4119 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4120 if (!BINFO_VIRTUAL_P (binfo
))
4121 vec_safe_push (vector
, binfo
);
4123 tree bases_vec
= make_tree_vec (vector
->length ());
4125 for (i
= 0; i
< vector
->length (); ++i
)
4126 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
4131 /* Implement the __bases keyword: Return the base classes
4134 /* Find morally non-virtual base classes by walking binfo hierarchy */
4135 /* Virtual base classes are handled separately in finish_bases */
4138 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
4140 /* Don't walk bases of virtual bases */
4141 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
4145 dfs_calculate_bases_post (tree binfo
, void *data_
)
4147 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
4148 if (!BINFO_VIRTUAL_P (binfo
))
4149 vec_safe_push (*data
, BINFO_TYPE (binfo
));
4153 /* Calculates the morally non-virtual base classes of a class */
4154 static vec
<tree
, va_gc
> *
4155 calculate_bases_helper (tree type
)
4157 vec
<tree
, va_gc
> *vector
= make_tree_vector ();
4159 /* Now add non-virtual base classes in order of construction */
4160 if (TYPE_BINFO (type
))
4161 dfs_walk_all (TYPE_BINFO (type
),
4162 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
4167 calculate_bases (tree type
, tsubst_flags_t complain
)
4169 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4170 || !NON_UNION_CLASS_TYPE_P (type
))
4171 return make_tree_vec (0);
4173 releasing_vec vector
;
4174 tree bases_vec
= NULL_TREE
;
4176 vec
<tree
, va_gc
> *vbases
;
4179 /* First go through virtual base classes */
4180 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
4181 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
4183 releasing_vec vbase_bases
4184 = calculate_bases_helper (BINFO_TYPE (binfo
));
4185 vec_safe_splice (vector
, vbase_bases
);
4188 /* Now for the non-virtual bases */
4189 releasing_vec nonvbases
= calculate_bases_helper (type
);
4190 vec_safe_splice (vector
, nonvbases
);
4192 /* Note that during error recovery vector->length can even be zero. */
4193 if (vector
->length () > 1)
4195 /* Last element is entire class, so don't copy */
4196 bases_vec
= make_tree_vec (vector
->length () - 1);
4198 for (i
= 0; i
< vector
->length () - 1; ++i
)
4199 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
4202 bases_vec
= make_tree_vec (0);
4208 finish_bases (tree type
, bool direct
)
4210 tree bases
= NULL_TREE
;
4212 if (!processing_template_decl
)
4214 /* Parameter packs can only be used in templates */
4215 error ("parameter pack %<__bases%> only valid in template declaration");
4216 return error_mark_node
;
4219 bases
= cxx_make_type (BASES
);
4220 BASES_TYPE (bases
) = type
;
4221 BASES_DIRECT (bases
) = direct
;
4222 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
4227 /* Perform C++-specific checks for __builtin_offsetof before calling
4231 finish_offsetof (tree object_ptr
, tree expr
, location_t loc
)
4233 /* If we're processing a template, we can't finish the semantics yet.
4234 Otherwise we can fold the entire expression now. */
4235 if (processing_template_decl
)
4237 expr
= build2 (OFFSETOF_EXPR
, size_type_node
, expr
, object_ptr
);
4238 SET_EXPR_LOCATION (expr
, loc
);
4242 if (expr
== error_mark_node
)
4243 return error_mark_node
;
4245 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4247 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4248 TREE_OPERAND (expr
, 2));
4249 return error_mark_node
;
4251 if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr
))
4252 || TREE_TYPE (expr
) == unknown_type_node
)
4254 while (TREE_CODE (expr
) == COMPONENT_REF
4255 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4256 expr
= TREE_OPERAND (expr
, 1);
4260 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4261 inform (DECL_SOURCE_LOCATION (expr
), "declared here");
4264 error ("cannot apply %<offsetof%> to member function");
4265 return error_mark_node
;
4267 if (TREE_CODE (expr
) == CONST_DECL
)
4269 error ("cannot apply %<offsetof%> to an enumerator %qD", expr
);
4270 return error_mark_node
;
4272 if (REFERENCE_REF_P (expr
))
4273 expr
= TREE_OPERAND (expr
, 0);
4274 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr
)), object_ptr
))
4275 return error_mark_node
;
4276 if (warn_invalid_offsetof
4277 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr
)))
4278 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr
)))
4279 && cp_unevaluated_operand
== 0)
4280 warning_at (loc
, OPT_Winvalid_offsetof
, "%<offsetof%> within "
4281 "non-standard-layout type %qT is conditionally-supported",
4282 TREE_TYPE (TREE_TYPE (object_ptr
)));
4283 return fold_offsetof (expr
);
4286 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4287 function is broken out from the above for the benefit of the tree-ssa
4291 simplify_aggr_init_expr (tree
*tp
)
4293 tree aggr_init_expr
= *tp
;
4295 /* Form an appropriate CALL_EXPR. */
4296 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4297 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4298 tree type
= TREE_TYPE (slot
);
4301 enum style_t
{ ctor
, arg
, pcc
} style
;
4303 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4305 #ifdef PCC_STATIC_STRUCT_RETURN
4311 gcc_assert (TREE_ADDRESSABLE (type
));
4315 call_expr
= build_call_array_loc (input_location
,
4316 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4318 aggr_init_expr_nargs (aggr_init_expr
),
4319 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4320 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4321 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4322 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4323 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4324 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4325 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4329 /* Replace the first argument to the ctor with the address of the
4331 cxx_mark_addressable (slot
);
4332 CALL_EXPR_ARG (call_expr
, 0) =
4333 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4335 else if (style
== arg
)
4337 /* Just mark it addressable here, and leave the rest to
4338 expand_call{,_inline}. */
4339 cxx_mark_addressable (slot
);
4340 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4341 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4343 else if (style
== pcc
)
4345 /* If we're using the non-reentrant PCC calling convention, then we
4346 need to copy the returned value out of the static buffer into the
4348 push_deferring_access_checks (dk_no_check
);
4349 call_expr
= build_aggr_init (slot
, call_expr
,
4350 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4351 tf_warning_or_error
);
4352 pop_deferring_access_checks ();
4353 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4356 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4358 tree init
= build_zero_init (type
, NULL_TREE
,
4359 /*static_storage_p=*/false);
4360 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4361 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4368 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4371 emit_associated_thunks (tree fn
)
4373 /* When we use vcall offsets, we emit thunks with the virtual
4374 functions to which they thunk. The whole point of vcall offsets
4375 is so that you can know statically the entire set of thunks that
4376 will ever be needed for a given virtual function, thereby
4377 enabling you to output all the thunks with the function itself. */
4378 if (DECL_VIRTUAL_P (fn
)
4379 /* Do not emit thunks for extern template instantiations. */
4380 && ! DECL_REALLY_EXTERN (fn
))
4384 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4386 if (!THUNK_ALIAS (thunk
))
4388 use_thunk (thunk
, /*emit_p=*/1);
4389 if (DECL_RESULT_THUNK_P (thunk
))
4393 for (probe
= DECL_THUNKS (thunk
);
4394 probe
; probe
= DECL_CHAIN (probe
))
4395 use_thunk (probe
, /*emit_p=*/1);
4399 gcc_assert (!DECL_THUNKS (thunk
));
4404 /* Generate RTL for FN. */
4407 expand_or_defer_fn_1 (tree fn
)
4409 /* When the parser calls us after finishing the body of a template
4410 function, we don't really want to expand the body. */
4411 if (processing_template_decl
)
4413 /* Normally, collection only occurs in rest_of_compilation. So,
4414 if we don't collect here, we never collect junk generated
4415 during the processing of templates until we hit a
4416 non-template function. It's not safe to do this inside a
4417 nested class, though, as the parser may have local state that
4418 is not a GC root. */
4419 if (!function_depth
)
4424 gcc_assert (DECL_SAVED_TREE (fn
));
4426 /* We make a decision about linkage for these functions at the end
4427 of the compilation. Until that point, we do not want the back
4428 end to output them -- but we do want it to see the bodies of
4429 these functions so that it can inline them as appropriate. */
4430 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4432 if (DECL_INTERFACE_KNOWN (fn
))
4433 /* We've already made a decision as to how this function will
4436 || DECL_IMMEDIATE_FUNCTION_P (fn
)
4437 || DECL_OMP_DECLARE_REDUCTION_P (fn
))
4438 tentative_decl_linkage (fn
);
4440 import_export_decl (fn
);
4442 /* If the user wants us to keep all inline functions, then mark
4443 this function as needed so that finish_file will make sure to
4444 output it later. Similarly, all dllexport'd functions must
4445 be emitted; there may be callers in other DLLs. */
4446 if (DECL_DECLARED_INLINE_P (fn
)
4447 && !DECL_REALLY_EXTERN (fn
)
4448 && !DECL_IMMEDIATE_FUNCTION_P (fn
)
4449 && !DECL_OMP_DECLARE_REDUCTION_P (fn
)
4450 && (flag_keep_inline_functions
4451 || (flag_keep_inline_dllexport
4452 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4455 DECL_EXTERNAL (fn
) = 0;
4459 /* If this is a constructor or destructor body, we have to clone
4461 if (maybe_clone_body (fn
))
4463 /* We don't want to process FN again, so pretend we've written
4464 it out, even though we haven't. */
4465 TREE_ASM_WRITTEN (fn
) = 1;
4466 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4467 if (!DECL_DECLARED_CONSTEXPR_P (fn
))
4468 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4472 /* There's no reason to do any of the work here if we're only doing
4473 semantic analysis; this code just generates RTL. */
4474 if (flag_syntax_only
)
4476 /* Pretend that this function has been written out so that we don't try
4477 to expand it again. */
4478 TREE_ASM_WRITTEN (fn
) = 1;
4482 if (DECL_OMP_DECLARE_REDUCTION_P (fn
))
4489 expand_or_defer_fn (tree fn
)
4491 if (expand_or_defer_fn_1 (fn
))
4495 /* Expand or defer, at the whim of the compilation unit manager. */
4496 cgraph_node::finalize_function (fn
, function_depth
> 1);
4497 emit_associated_thunks (fn
);
4506 nrv_data () : visited (37) {}
4510 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4513 /* Helper function for walk_tree, used by finalize_nrv below. */
4516 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4518 class nrv_data
*dp
= (class nrv_data
*)data
;
4521 /* No need to walk into types. There wouldn't be any need to walk into
4522 non-statements, except that we have to consider STMT_EXPRs. */
4525 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4526 but differs from using NULL_TREE in that it indicates that we care
4527 about the value of the RESULT_DECL. */
4528 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4529 TREE_OPERAND (*tp
, 0) = dp
->result
;
4530 /* Change all cleanups for the NRV to only run when an exception is
4532 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4533 && CLEANUP_DECL (*tp
) == dp
->var
)
4534 CLEANUP_EH_ONLY (*tp
) = 1;
4535 /* Replace the DECL_EXPR for the NRV with an initialization of the
4536 RESULT_DECL, if needed. */
4537 else if (TREE_CODE (*tp
) == DECL_EXPR
4538 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4541 if (DECL_INITIAL (dp
->var
)
4542 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4543 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4544 DECL_INITIAL (dp
->var
));
4546 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4547 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4548 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4551 /* And replace all uses of the NRV with the RESULT_DECL. */
4552 else if (*tp
== dp
->var
)
4555 /* Avoid walking into the same tree more than once. Unfortunately, we
4556 can't just use walk_tree_without duplicates because it would only call
4557 us for the first occurrence of dp->var in the function body. */
4558 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4564 /* Keep iterating. */
4568 /* Called from finish_function to implement the named return value
4569 optimization by overriding all the RETURN_EXPRs and pertinent
4570 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4571 RESULT_DECL for the function. */
4574 finalize_nrv (tree
*tp
, tree var
, tree result
)
4576 class nrv_data data
;
4578 /* Copy name from VAR to RESULT. */
4579 DECL_NAME (result
) = DECL_NAME (var
);
4580 /* Don't forget that we take its address. */
4581 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4582 /* Finally set DECL_VALUE_EXPR to avoid assigning
4583 a stack slot at -O0 for the original var and debug info
4584 uses RESULT location for VAR. */
4585 SET_DECL_VALUE_EXPR (var
, result
);
4586 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4589 data
.result
= result
;
4590 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4593 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4596 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4597 bool need_copy_ctor
, bool need_copy_assignment
,
4600 int save_errorcount
= errorcount
;
4603 /* Always allocate 3 elements for simplicity. These are the
4604 function decls for the ctor, dtor, and assignment op.
4605 This layout is known to the three lang hooks,
4606 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4607 and cxx_omp_clause_assign_op. */
4608 info
= make_tree_vec (3);
4609 CP_OMP_CLAUSE_INFO (c
) = info
;
4611 if (need_default_ctor
|| need_copy_ctor
)
4613 if (need_default_ctor
)
4614 t
= get_default_ctor (type
);
4616 t
= get_copy_ctor (type
, tf_warning_or_error
);
4618 if (t
&& !trivial_fn_p (t
))
4619 TREE_VEC_ELT (info
, 0) = t
;
4622 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4623 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4625 if (need_copy_assignment
)
4627 t
= get_copy_assign (type
);
4629 if (t
&& !trivial_fn_p (t
))
4630 TREE_VEC_ELT (info
, 2) = t
;
4633 return errorcount
!= save_errorcount
;
4636 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4637 FIELD_DECL, otherwise return DECL itself. */
4640 omp_clause_decl_field (tree decl
)
4643 && DECL_HAS_VALUE_EXPR_P (decl
)
4644 && DECL_ARTIFICIAL (decl
)
4645 && DECL_LANG_SPECIFIC (decl
)
4646 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4648 tree f
= DECL_VALUE_EXPR (decl
);
4649 if (INDIRECT_REF_P (f
))
4650 f
= TREE_OPERAND (f
, 0);
4651 if (TREE_CODE (f
) == COMPONENT_REF
)
4653 f
= TREE_OPERAND (f
, 1);
4654 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4661 /* Adjust DECL if needed for printing using %qE. */
4664 omp_clause_printable_decl (tree decl
)
4666 tree t
= omp_clause_decl_field (decl
);
4672 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4673 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4677 omp_note_field_privatization (tree f
, tree t
)
4679 if (!omp_private_member_map
)
4680 omp_private_member_map
= new hash_map
<tree
, tree
>;
4681 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4685 omp_private_member_vec
.safe_push (f
);
4686 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4687 omp_private_member_vec
.safe_push (integer_zero_node
);
4691 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4695 omp_privatize_field (tree t
, bool shared
)
4697 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4698 if (m
== error_mark_node
)
4699 return error_mark_node
;
4700 if (!omp_private_member_map
&& !shared
)
4701 omp_private_member_map
= new hash_map
<tree
, tree
>;
4702 if (TYPE_REF_P (TREE_TYPE (t
)))
4704 gcc_assert (INDIRECT_REF_P (m
));
4705 m
= TREE_OPERAND (m
, 0);
4707 tree vb
= NULL_TREE
;
4708 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4711 v
= create_temporary_var (TREE_TYPE (m
));
4712 retrofit_lang_decl (v
);
4713 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4714 SET_DECL_VALUE_EXPR (v
, m
);
4715 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4717 omp_private_member_vec
.safe_push (t
);
4722 /* Helper function for handle_omp_array_sections. Called recursively
4723 to handle multiple array-section-subscripts. C is the clause,
4724 T current expression (initially OMP_CLAUSE_DECL), which is either
4725 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4726 expression if specified, TREE_VALUE length expression if specified,
4727 TREE_CHAIN is what it has been specified after, or some decl.
4728 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4729 set to true if any of the array-section-subscript could have length
4730 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4731 first array-section-subscript which is known not to have length
4733 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4734 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4735 all are or may have length of 1, array-section-subscript [:2] is the
4736 first one known not to have length 1. For array-section-subscript
4737 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4738 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4739 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4740 case though, as some lengths could be zero. */
4743 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4744 bool &maybe_zero_len
, unsigned int &first_non_one
,
4745 enum c_omp_region_type ort
)
4747 tree ret
, low_bound
, length
, type
;
4748 if (TREE_CODE (t
) != TREE_LIST
)
4750 if (error_operand_p (t
))
4751 return error_mark_node
;
4752 if (REFERENCE_REF_P (t
)
4753 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4754 t
= TREE_OPERAND (t
, 0);
4756 if (TREE_CODE (t
) == COMPONENT_REF
4757 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4758 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
4759 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
4760 && !type_dependent_expression_p (t
))
4762 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
4763 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
4765 error_at (OMP_CLAUSE_LOCATION (c
),
4766 "bit-field %qE in %qs clause",
4767 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4768 return error_mark_node
;
4770 while (TREE_CODE (t
) == COMPONENT_REF
)
4772 if (TREE_TYPE (TREE_OPERAND (t
, 0))
4773 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
4775 error_at (OMP_CLAUSE_LOCATION (c
),
4776 "%qE is a member of a union", t
);
4777 return error_mark_node
;
4779 t
= TREE_OPERAND (t
, 0);
4780 if (ort
== C_ORT_ACC
&& TREE_CODE (t
) == INDIRECT_REF
)
4781 t
= TREE_OPERAND (t
, 0);
4783 if (REFERENCE_REF_P (t
))
4784 t
= TREE_OPERAND (t
, 0);
4786 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
4788 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
4791 error_at (OMP_CLAUSE_LOCATION (c
),
4792 "%qD is not a variable in %qs clause", t
,
4793 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4795 error_at (OMP_CLAUSE_LOCATION (c
),
4796 "%qE is not a variable in %qs clause", t
,
4797 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4798 return error_mark_node
;
4800 else if (ort
== C_ORT_OMP
4801 && TREE_CODE (t
) == PARM_DECL
4802 && DECL_ARTIFICIAL (t
)
4803 && DECL_NAME (t
) == this_identifier
)
4805 error_at (OMP_CLAUSE_LOCATION (c
),
4806 "%<this%> allowed in OpenMP only in %<declare simd%>"
4808 return error_mark_node
;
4810 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4811 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
4813 error_at (OMP_CLAUSE_LOCATION (c
),
4814 "%qD is threadprivate variable in %qs clause", t
,
4815 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4816 return error_mark_node
;
4818 if (type_dependent_expression_p (ret
))
4820 ret
= convert_from_reference (ret
);
4824 if (ort
== C_ORT_OMP
4825 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4826 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4827 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4828 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
4829 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
4830 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4831 maybe_zero_len
, first_non_one
, ort
);
4832 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4835 type
= TREE_TYPE (ret
);
4836 low_bound
= TREE_PURPOSE (t
);
4837 length
= TREE_VALUE (t
);
4838 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4839 || (length
&& type_dependent_expression_p (length
)))
4842 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4843 return error_mark_node
;
4845 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4847 error_at (OMP_CLAUSE_LOCATION (c
),
4848 "low bound %qE of array section does not have integral type",
4850 return error_mark_node
;
4852 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4854 error_at (OMP_CLAUSE_LOCATION (c
),
4855 "length %qE of array section does not have integral type",
4857 return error_mark_node
;
4860 low_bound
= mark_rvalue_use (low_bound
);
4862 length
= mark_rvalue_use (length
);
4863 /* We need to reduce to real constant-values for checks below. */
4865 length
= fold_simple (length
);
4867 low_bound
= fold_simple (low_bound
);
4869 && TREE_CODE (low_bound
) == INTEGER_CST
4870 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4871 > TYPE_PRECISION (sizetype
))
4872 low_bound
= fold_convert (sizetype
, low_bound
);
4874 && TREE_CODE (length
) == INTEGER_CST
4875 && TYPE_PRECISION (TREE_TYPE (length
))
4876 > TYPE_PRECISION (sizetype
))
4877 length
= fold_convert (sizetype
, length
);
4878 if (low_bound
== NULL_TREE
)
4879 low_bound
= integer_zero_node
;
4881 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4882 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
4883 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
4885 if (length
!= integer_one_node
)
4887 error_at (OMP_CLAUSE_LOCATION (c
),
4888 "expected single pointer in %qs clause",
4889 c_omp_map_clause_name (c
, ort
== C_ORT_ACC
));
4890 return error_mark_node
;
4893 if (length
!= NULL_TREE
)
4895 if (!integer_nonzerop (length
))
4897 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4898 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4899 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4900 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4902 if (integer_zerop (length
))
4904 error_at (OMP_CLAUSE_LOCATION (c
),
4905 "zero length array section in %qs clause",
4906 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4907 return error_mark_node
;
4911 maybe_zero_len
= true;
4913 if (first_non_one
== types
.length ()
4914 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4917 if (TREE_CODE (type
) == ARRAY_TYPE
)
4919 if (length
== NULL_TREE
4920 && (TYPE_DOMAIN (type
) == NULL_TREE
4921 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4923 error_at (OMP_CLAUSE_LOCATION (c
),
4924 "for unknown bound array type length expression must "
4926 return error_mark_node
;
4928 if (TREE_CODE (low_bound
) == INTEGER_CST
4929 && tree_int_cst_sgn (low_bound
) == -1)
4931 error_at (OMP_CLAUSE_LOCATION (c
),
4932 "negative low bound in array section in %qs clause",
4933 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4934 return error_mark_node
;
4936 if (length
!= NULL_TREE
4937 && TREE_CODE (length
) == INTEGER_CST
4938 && tree_int_cst_sgn (length
) == -1)
4940 error_at (OMP_CLAUSE_LOCATION (c
),
4941 "negative length in array section in %qs clause",
4942 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4943 return error_mark_node
;
4945 if (TYPE_DOMAIN (type
)
4946 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
4947 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
4951 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
4952 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
4953 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4955 if (tree_int_cst_lt (size
, low_bound
))
4957 error_at (OMP_CLAUSE_LOCATION (c
),
4958 "low bound %qE above array section size "
4959 "in %qs clause", low_bound
,
4960 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4961 return error_mark_node
;
4963 if (tree_int_cst_equal (size
, low_bound
))
4965 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4966 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4967 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4968 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4970 error_at (OMP_CLAUSE_LOCATION (c
),
4971 "zero length array section in %qs clause",
4972 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4973 return error_mark_node
;
4975 maybe_zero_len
= true;
4977 else if (length
== NULL_TREE
4978 && first_non_one
== types
.length ()
4979 && tree_int_cst_equal
4980 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4984 else if (length
== NULL_TREE
)
4986 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4987 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
4988 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
4989 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
4990 maybe_zero_len
= true;
4991 if (first_non_one
== types
.length ())
4994 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
4996 if (tree_int_cst_lt (size
, length
))
4998 error_at (OMP_CLAUSE_LOCATION (c
),
4999 "length %qE above array section size "
5000 "in %qs clause", length
,
5001 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5002 return error_mark_node
;
5004 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5007 = size_binop (PLUS_EXPR
,
5008 fold_convert (sizetype
, low_bound
),
5009 fold_convert (sizetype
, length
));
5010 if (TREE_CODE (lbpluslen
) == INTEGER_CST
5011 && tree_int_cst_lt (size
, lbpluslen
))
5013 error_at (OMP_CLAUSE_LOCATION (c
),
5014 "high bound %qE above array section size "
5015 "in %qs clause", lbpluslen
,
5016 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5017 return error_mark_node
;
5022 else if (length
== NULL_TREE
)
5024 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5025 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5026 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5027 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5028 maybe_zero_len
= true;
5029 if (first_non_one
== types
.length ())
5033 /* For [lb:] we will need to evaluate lb more than once. */
5034 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5036 tree lb
= cp_save_expr (low_bound
);
5037 if (lb
!= low_bound
)
5039 TREE_PURPOSE (t
) = lb
;
5044 else if (TYPE_PTR_P (type
))
5046 if (length
== NULL_TREE
)
5048 error_at (OMP_CLAUSE_LOCATION (c
),
5049 "for pointer type length expression must be specified");
5050 return error_mark_node
;
5052 if (length
!= NULL_TREE
5053 && TREE_CODE (length
) == INTEGER_CST
5054 && tree_int_cst_sgn (length
) == -1)
5056 error_at (OMP_CLAUSE_LOCATION (c
),
5057 "negative length in array section in %qs clause",
5058 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5059 return error_mark_node
;
5061 /* If there is a pointer type anywhere but in the very first
5062 array-section-subscript, the array section can't be contiguous. */
5063 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5064 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
5066 error_at (OMP_CLAUSE_LOCATION (c
),
5067 "array section is not contiguous in %qs clause",
5068 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5069 return error_mark_node
;
5074 error_at (OMP_CLAUSE_LOCATION (c
),
5075 "%qE does not have pointer or array type", ret
);
5076 return error_mark_node
;
5078 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5079 types
.safe_push (TREE_TYPE (ret
));
5080 /* We will need to evaluate lb more than once. */
5081 tree lb
= cp_save_expr (low_bound
);
5082 if (lb
!= low_bound
)
5084 TREE_PURPOSE (t
) = lb
;
5087 /* Temporarily disable -fstrong-eval-order for array reductions.
5088 The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
5089 is something the middle-end can't cope with and more importantly,
5090 it needs to be the actual base variable that is privatized, not some
5091 temporary assigned previous value of it. That, together with OpenMP
5092 saying how many times the side-effects are evaluated is unspecified,
5093 makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
5094 warning_sentinel
s (flag_strong_eval_order
,
5095 OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5096 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5097 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
);
5098 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
5102 /* Handle array sections for clause C. */
5105 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
5107 bool maybe_zero_len
= false;
5108 unsigned int first_non_one
= 0;
5109 auto_vec
<tree
, 10> types
;
5110 tree
*tp
= &OMP_CLAUSE_DECL (c
);
5111 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5112 && TREE_CODE (*tp
) == TREE_LIST
5113 && TREE_PURPOSE (*tp
)
5114 && TREE_CODE (TREE_PURPOSE (*tp
)) == TREE_VEC
)
5115 tp
= &TREE_VALUE (*tp
);
5116 tree first
= handle_omp_array_sections_1 (c
, *tp
, types
,
5117 maybe_zero_len
, first_non_one
,
5119 if (first
== error_mark_node
)
5121 if (first
== NULL_TREE
)
5123 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
5126 tree tem
= NULL_TREE
;
5127 if (processing_template_decl
)
5129 /* Need to evaluate side effects in the length expressions
5131 while (TREE_CODE (t
) == TREE_LIST
)
5133 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
5135 if (tem
== NULL_TREE
)
5136 tem
= TREE_VALUE (t
);
5138 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
5139 TREE_VALUE (t
), tem
);
5144 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
5149 unsigned int num
= types
.length (), i
;
5150 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
5151 tree condition
= NULL_TREE
;
5153 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
5154 maybe_zero_len
= true;
5155 if (processing_template_decl
&& maybe_zero_len
)
5158 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
5161 tree low_bound
= TREE_PURPOSE (t
);
5162 tree length
= TREE_VALUE (t
);
5166 && TREE_CODE (low_bound
) == INTEGER_CST
5167 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5168 > TYPE_PRECISION (sizetype
))
5169 low_bound
= fold_convert (sizetype
, low_bound
);
5171 && TREE_CODE (length
) == INTEGER_CST
5172 && TYPE_PRECISION (TREE_TYPE (length
))
5173 > TYPE_PRECISION (sizetype
))
5174 length
= fold_convert (sizetype
, length
);
5175 if (low_bound
== NULL_TREE
)
5176 low_bound
= integer_zero_node
;
5177 if (!maybe_zero_len
&& i
> first_non_one
)
5179 if (integer_nonzerop (low_bound
))
5180 goto do_warn_noncontiguous
;
5181 if (length
!= NULL_TREE
5182 && TREE_CODE (length
) == INTEGER_CST
5183 && TYPE_DOMAIN (types
[i
])
5184 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
5185 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
5189 size
= size_binop (PLUS_EXPR
,
5190 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5192 if (!tree_int_cst_equal (length
, size
))
5194 do_warn_noncontiguous
:
5195 error_at (OMP_CLAUSE_LOCATION (c
),
5196 "array section is not contiguous in %qs "
5198 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5202 if (!processing_template_decl
5203 && length
!= NULL_TREE
5204 && TREE_SIDE_EFFECTS (length
))
5206 if (side_effects
== NULL_TREE
)
5207 side_effects
= length
;
5209 side_effects
= build2 (COMPOUND_EXPR
,
5210 TREE_TYPE (side_effects
),
5211 length
, side_effects
);
5214 else if (processing_template_decl
)
5220 if (i
> first_non_one
5221 && ((length
&& integer_nonzerop (length
))
5222 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5223 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5224 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
))
5227 l
= fold_convert (sizetype
, length
);
5230 l
= size_binop (PLUS_EXPR
,
5231 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5233 l
= size_binop (MINUS_EXPR
, l
,
5234 fold_convert (sizetype
, low_bound
));
5236 if (i
> first_non_one
)
5238 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
5240 if (condition
== NULL_TREE
)
5243 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
5246 else if (size
== NULL_TREE
)
5248 size
= size_in_bytes (TREE_TYPE (types
[i
]));
5249 tree eltype
= TREE_TYPE (types
[num
- 1]);
5250 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5251 eltype
= TREE_TYPE (eltype
);
5252 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5253 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5254 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5255 size
= size_binop (EXACT_DIV_EXPR
, size
,
5256 size_in_bytes (eltype
));
5257 size
= size_binop (MULT_EXPR
, size
, l
);
5259 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
5260 size
, size_zero_node
);
5263 size
= size_binop (MULT_EXPR
, size
, l
);
5266 if (!processing_template_decl
)
5269 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
5270 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5271 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5272 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5274 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5275 size
= save_expr (size
);
5276 tree index_type
= build_index_type (size
);
5277 tree eltype
= TREE_TYPE (first
);
5278 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5279 eltype
= TREE_TYPE (eltype
);
5280 tree type
= build_array_type (eltype
, index_type
);
5281 tree ptype
= build_pointer_type (eltype
);
5282 if (TYPE_REF_P (TREE_TYPE (t
))
5283 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
5284 t
= convert_from_reference (t
);
5285 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5286 t
= build_fold_addr_expr (t
);
5287 tree t2
= build_fold_addr_expr (first
);
5288 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5289 ptrdiff_type_node
, t2
);
5290 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5291 ptrdiff_type_node
, t2
,
5292 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5293 ptrdiff_type_node
, t
));
5294 if (tree_fits_shwi_p (t2
))
5295 t
= build2 (MEM_REF
, type
, t
,
5296 build_int_cst (ptype
, tree_to_shwi (t2
)));
5299 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5301 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
5302 TREE_TYPE (t
), t
, t2
);
5303 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5305 OMP_CLAUSE_DECL (c
) = t
;
5308 OMP_CLAUSE_DECL (c
) = first
;
5309 OMP_CLAUSE_SIZE (c
) = size
;
5310 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5311 || (TREE_CODE (t
) == COMPONENT_REF
5312 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5314 if (ort
== C_ORT_OMP
|| ort
== C_ORT_ACC
)
5315 switch (OMP_CLAUSE_MAP_KIND (c
))
5317 case GOMP_MAP_ALLOC
:
5318 case GOMP_MAP_IF_PRESENT
:
5321 case GOMP_MAP_TOFROM
:
5322 case GOMP_MAP_ALWAYS_TO
:
5323 case GOMP_MAP_ALWAYS_FROM
:
5324 case GOMP_MAP_ALWAYS_TOFROM
:
5325 case GOMP_MAP_RELEASE
:
5326 case GOMP_MAP_DELETE
:
5327 case GOMP_MAP_FORCE_TO
:
5328 case GOMP_MAP_FORCE_FROM
:
5329 case GOMP_MAP_FORCE_TOFROM
:
5330 case GOMP_MAP_FORCE_PRESENT
:
5331 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5336 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5338 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
&& ort
!= C_ORT_ACC
)
5339 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
5340 else if (TREE_CODE (t
) == COMPONENT_REF
)
5342 gomp_map_kind k
= (ort
== C_ORT_ACC
) ? GOMP_MAP_ATTACH_DETACH
5343 : GOMP_MAP_ALWAYS_POINTER
;
5344 OMP_CLAUSE_SET_MAP_KIND (c2
, k
);
5346 else if (REFERENCE_REF_P (t
)
5347 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5349 t
= TREE_OPERAND (t
, 0);
5350 gomp_map_kind k
= (ort
== C_ORT_ACC
) ? GOMP_MAP_ATTACH_DETACH
5351 : GOMP_MAP_ALWAYS_POINTER
;
5352 OMP_CLAUSE_SET_MAP_KIND (c2
, k
);
5355 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5356 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5357 && !cxx_mark_addressable (t
))
5359 OMP_CLAUSE_DECL (c2
) = t
;
5360 t
= build_fold_addr_expr (first
);
5361 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5362 ptrdiff_type_node
, t
);
5363 tree ptr
= OMP_CLAUSE_DECL (c2
);
5364 ptr
= convert_from_reference (ptr
);
5365 if (!INDIRECT_TYPE_P (TREE_TYPE (ptr
)))
5366 ptr
= build_fold_addr_expr (ptr
);
5367 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5368 ptrdiff_type_node
, t
,
5369 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5370 ptrdiff_type_node
, ptr
));
5371 OMP_CLAUSE_SIZE (c2
) = t
;
5372 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5373 OMP_CLAUSE_CHAIN (c
) = c2
;
5374 ptr
= OMP_CLAUSE_DECL (c2
);
5375 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5376 && TYPE_REF_P (TREE_TYPE (ptr
))
5377 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5379 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5381 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5382 OMP_CLAUSE_DECL (c3
) = ptr
;
5383 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
)
5384 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5386 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5387 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5388 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5389 OMP_CLAUSE_CHAIN (c2
) = c3
;
5396 /* Return identifier to look up for omp declare reduction. */
5399 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5401 const char *p
= NULL
;
5402 const char *m
= NULL
;
5403 switch (reduction_code
)
5411 case TRUTH_ANDIF_EXPR
:
5412 case TRUTH_ORIF_EXPR
:
5413 reduction_id
= ovl_op_identifier (false, reduction_code
);
5427 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5428 return error_mark_node
;
5429 p
= IDENTIFIER_POINTER (reduction_id
);
5432 if (type
!= NULL_TREE
)
5433 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5435 const char prefix
[] = "omp declare reduction ";
5436 size_t lenp
= sizeof (prefix
);
5437 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5439 size_t len
= strlen (p
);
5440 size_t lenm
= m
? strlen (m
) + 1 : 0;
5441 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5443 memcpy (name
, prefix
, lenp
- 1);
5444 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5447 name
[lenp
+ len
- 1] = '~';
5448 memcpy (name
+ lenp
+ len
, m
, lenm
);
5450 return get_identifier (name
);
5453 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5454 FUNCTION_DECL or NULL_TREE if not found. */
5457 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5458 vec
<tree
> *ambiguousp
)
5461 tree baselink
= NULL_TREE
;
5462 if (identifier_p (id
))
5465 bool nonint_cst_expression_p
;
5466 const char *error_msg
;
5467 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5468 tree decl
= lookup_name (id
);
5469 if (decl
== NULL_TREE
)
5470 decl
= error_mark_node
;
5471 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5472 &nonint_cst_expression_p
, false, true, false,
5473 false, &error_msg
, loc
);
5474 if (idk
== CP_ID_KIND_UNQUALIFIED
5475 && identifier_p (id
))
5477 vec
<tree
, va_gc
> *args
= NULL
;
5478 vec_safe_push (args
, build_reference_type (type
));
5479 id
= perform_koenig_lookup (id
, args
, tf_none
);
5482 else if (TREE_CODE (id
) == SCOPE_REF
)
5483 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5484 omp_reduction_id (ERROR_MARK
,
5485 TREE_OPERAND (id
, 1),
5490 if (fns
&& is_overloaded_fn (fns
))
5492 for (lkp_iterator
iter (get_fns (fns
)); iter
; ++iter
)
5494 tree fndecl
= *iter
;
5495 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5497 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5498 if (same_type_p (TREE_TYPE (argtype
), type
))
5506 if (id
&& BASELINK_P (fns
))
5515 if (!id
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5517 vec
<tree
> ambiguous
= vNULL
;
5518 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5520 if (ambiguousp
== NULL
)
5521 ambiguousp
= &ambiguous
;
5522 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5524 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5525 baselinkp
? baselinkp
: &baselink
,
5527 if (id
== NULL_TREE
)
5529 if (!ambiguousp
->is_empty ())
5530 ambiguousp
->safe_push (id
);
5531 else if (ret
!= NULL_TREE
)
5533 ambiguousp
->safe_push (ret
);
5534 ambiguousp
->safe_push (id
);
5540 if (ambiguousp
!= &ambiguous
)
5542 if (!ambiguous
.is_empty ())
5544 const char *str
= _("candidates are:");
5547 error_at (loc
, "user defined reduction lookup is ambiguous");
5548 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5550 inform (DECL_SOURCE_LOCATION (udr
), "%s %#qD", str
, udr
);
5552 str
= get_spaces (str
);
5554 ambiguous
.release ();
5555 ret
= error_mark_node
;
5556 baselink
= NULL_TREE
;
5561 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5562 id
, id
, tf_warning_or_error
);
5566 /* Helper function for cp_parser_omp_declare_reduction_exprs
5568 Remove CLEANUP_STMT for data (omp_priv variable).
5569 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5573 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5577 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5578 *tp
= CLEANUP_BODY (*tp
);
5579 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5581 tree decl
= DECL_EXPR_DECL (*tp
);
5582 if (!processing_template_decl
5583 && decl
== (tree
) data
5584 && DECL_INITIAL (decl
)
5585 && DECL_INITIAL (decl
) != error_mark_node
)
5587 tree list
= NULL_TREE
;
5588 append_to_statement_list_force (*tp
, &list
);
5589 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5590 decl
, DECL_INITIAL (decl
));
5591 DECL_INITIAL (decl
) = NULL_TREE
;
5592 append_to_statement_list_force (init_expr
, &list
);
5599 /* Data passed from cp_check_omp_declare_reduction to
5600 cp_check_omp_declare_reduction_r. */
5602 struct cp_check_omp_declare_reduction_data
5609 /* Helper function for cp_check_omp_declare_reduction, called via
5613 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5615 struct cp_check_omp_declare_reduction_data
*udr_data
5616 = (struct cp_check_omp_declare_reduction_data
*) data
;
5618 && !DECL_ARTIFICIAL (*tp
)
5619 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5620 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5622 location_t loc
= udr_data
->loc
;
5623 if (udr_data
->combiner_p
)
5624 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5625 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5628 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5629 "to variable %qD which is not %<omp_priv%> nor "
5637 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5640 cp_check_omp_declare_reduction (tree udr
)
5642 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5643 gcc_assert (TYPE_REF_P (type
));
5644 type
= TREE_TYPE (type
);
5646 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5648 if (type
== error_mark_node
)
5650 if (ARITHMETIC_TYPE_P (type
))
5652 static enum tree_code predef_codes
[]
5653 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5654 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5655 for (i
= 0; i
< 8; i
++)
5657 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5658 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5659 const char *n2
= IDENTIFIER_POINTER (id
);
5660 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5661 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5662 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5667 && TREE_CODE (type
) != COMPLEX_EXPR
)
5669 const char prefix_minmax
[] = "omp declare reduction m";
5670 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5671 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5672 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5673 prefix_minmax
, prefix_size
) == 0
5674 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5675 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5676 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5681 error_at (loc
, "predeclared arithmetic type %qT in "
5682 "%<#pragma omp declare reduction%>", type
);
5686 else if (FUNC_OR_METHOD_TYPE_P (type
)
5687 || TREE_CODE (type
) == ARRAY_TYPE
)
5689 error_at (loc
, "function or array type %qT in "
5690 "%<#pragma omp declare reduction%>", type
);
5693 else if (TYPE_REF_P (type
))
5695 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5699 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5701 error_at (loc
, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
5702 "type %qT in %<#pragma omp declare reduction%>", type
);
5706 tree body
= DECL_SAVED_TREE (udr
);
5707 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5710 tree_stmt_iterator tsi
;
5711 struct cp_check_omp_declare_reduction_data data
;
5712 memset (data
.stmts
, 0, sizeof data
.stmts
);
5713 for (i
= 0, tsi
= tsi_start (body
);
5714 i
< 7 && !tsi_end_p (tsi
);
5715 i
++, tsi_next (&tsi
))
5716 data
.stmts
[i
] = tsi_stmt (tsi
);
5718 gcc_assert (tsi_end_p (tsi
));
5721 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5722 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5723 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5725 data
.combiner_p
= true;
5726 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5728 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5732 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5733 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5734 data
.combiner_p
= false;
5735 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5737 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5738 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5739 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5741 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5745 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5746 an inline call. But, remap
5747 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5748 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5751 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5752 tree decl
, tree placeholder
)
5755 hash_map
<tree
, tree
> decl_map
;
5757 decl_map
.put (omp_decl1
, placeholder
);
5758 decl_map
.put (omp_decl2
, decl
);
5759 memset (&id
, 0, sizeof (id
));
5760 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5761 id
.dst_fn
= current_function_decl
;
5762 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5763 id
.decl_map
= &decl_map
;
5765 id
.copy_decl
= copy_decl_no_change
;
5766 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5767 id
.transform_new_cfg
= true;
5768 id
.transform_return_to_modify
= false;
5769 id
.transform_lang_insert_block
= NULL
;
5771 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5775 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5776 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5779 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5781 if (*tp
== (tree
) data
)
5786 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5787 Return true if there is some error and the clause should be removed. */
5790 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5792 tree t
= OMP_CLAUSE_DECL (c
);
5793 bool predefined
= false;
5794 if (TREE_CODE (t
) == TREE_LIST
)
5796 gcc_assert (processing_template_decl
);
5799 tree type
= TREE_TYPE (t
);
5800 if (TREE_CODE (t
) == MEM_REF
)
5801 type
= TREE_TYPE (type
);
5802 if (TYPE_REF_P (type
))
5803 type
= TREE_TYPE (type
);
5804 if (TREE_CODE (type
) == ARRAY_TYPE
)
5807 gcc_assert (TREE_CODE (t
) != MEM_REF
);
5808 while (TREE_CODE (type
) == ARRAY_TYPE
)
5809 type
= TREE_TYPE (type
);
5810 if (!processing_template_decl
)
5812 t
= require_complete_type (t
);
5813 if (t
== error_mark_node
)
5815 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
5816 TYPE_SIZE_UNIT (type
));
5817 if (integer_zerop (size
))
5819 error_at (OMP_CLAUSE_LOCATION (c
),
5820 "%qE in %<reduction%> clause is a zero size array",
5821 omp_clause_printable_decl (t
));
5824 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5825 size
= save_expr (size
);
5826 tree index_type
= build_index_type (size
);
5827 tree atype
= build_array_type (type
, index_type
);
5828 tree ptype
= build_pointer_type (type
);
5829 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5830 t
= build_fold_addr_expr (t
);
5831 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
5832 OMP_CLAUSE_DECL (c
) = t
;
5835 if (type
== error_mark_node
)
5837 else if (ARITHMETIC_TYPE_P (type
))
5838 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5847 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5854 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5858 case TRUTH_ANDIF_EXPR
:
5859 case TRUTH_ORIF_EXPR
:
5860 if (FLOAT_TYPE_P (type
))
5867 else if (TYPE_READONLY (type
))
5869 error_at (OMP_CLAUSE_LOCATION (c
),
5870 "%qE has const type for %<reduction%>",
5871 omp_clause_printable_decl (t
));
5874 else if (!processing_template_decl
)
5876 t
= require_complete_type (t
);
5877 if (t
== error_mark_node
)
5879 OMP_CLAUSE_DECL (c
) = t
;
5884 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5887 else if (processing_template_decl
)
5889 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) == error_mark_node
)
5894 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5896 type
= TYPE_MAIN_VARIANT (type
);
5897 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5898 if (id
== NULL_TREE
)
5899 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5900 NULL_TREE
, NULL_TREE
);
5901 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5904 if (id
== error_mark_node
)
5907 tree body
= DECL_SAVED_TREE (id
);
5910 if (TREE_CODE (body
) == STATEMENT_LIST
)
5912 tree_stmt_iterator tsi
;
5913 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
5916 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5917 atype
= TREE_TYPE (atype
);
5918 bool need_static_cast
= !same_type_p (type
, atype
);
5919 memset (stmts
, 0, sizeof stmts
);
5920 for (i
= 0, tsi
= tsi_start (body
);
5921 i
< 7 && !tsi_end_p (tsi
);
5922 i
++, tsi_next (&tsi
))
5923 stmts
[i
] = tsi_stmt (tsi
);
5924 gcc_assert (tsi_end_p (tsi
));
5928 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
5929 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
5930 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
5931 DECL_ARTIFICIAL (placeholder
) = 1;
5932 DECL_IGNORED_P (placeholder
) = 1;
5933 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
5934 if (TREE_CODE (t
) == MEM_REF
)
5936 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
5938 DECL_ARTIFICIAL (decl_placeholder
) = 1;
5939 DECL_IGNORED_P (decl_placeholder
) = 1;
5940 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
5942 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
5943 cxx_mark_addressable (placeholder
);
5944 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
5945 && (decl_placeholder
5946 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
5947 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5948 : OMP_CLAUSE_DECL (c
));
5949 tree omp_out
= placeholder
;
5950 tree omp_in
= decl_placeholder
? decl_placeholder
5951 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5952 if (need_static_cast
)
5954 tree rtype
= build_reference_type (atype
);
5955 omp_out
= build_static_cast (input_location
,
5957 tf_warning_or_error
);
5958 omp_in
= build_static_cast (input_location
,
5960 tf_warning_or_error
);
5961 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
5963 omp_out
= convert_from_reference (omp_out
);
5964 omp_in
= convert_from_reference (omp_in
);
5966 OMP_CLAUSE_REDUCTION_MERGE (c
)
5967 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
5968 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
5972 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
5973 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
5974 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3]))
5975 && (decl_placeholder
5976 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
5977 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5978 : OMP_CLAUSE_DECL (c
));
5979 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
5980 cxx_mark_addressable (placeholder
);
5981 tree omp_priv
= decl_placeholder
? decl_placeholder
5982 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5983 tree omp_orig
= placeholder
;
5984 if (need_static_cast
)
5988 error_at (OMP_CLAUSE_LOCATION (c
),
5989 "user defined reduction with constructor "
5990 "initializer for base class %qT", atype
);
5993 tree rtype
= build_reference_type (atype
);
5994 omp_priv
= build_static_cast (input_location
,
5996 tf_warning_or_error
);
5997 omp_orig
= build_static_cast (input_location
,
5999 tf_warning_or_error
);
6000 if (omp_priv
== error_mark_node
6001 || omp_orig
== error_mark_node
)
6003 omp_priv
= convert_from_reference (omp_priv
);
6004 omp_orig
= convert_from_reference (omp_orig
);
6007 *need_default_ctor
= true;
6008 OMP_CLAUSE_REDUCTION_INIT (c
)
6009 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
6010 DECL_EXPR_DECL (stmts
[3]),
6011 omp_priv
, omp_orig
);
6012 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
6013 find_omp_placeholder_r
, placeholder
, NULL
))
6014 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
6018 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
6019 *need_default_ctor
= true;
6023 tree v
= decl_placeholder
? decl_placeholder
6024 : convert_from_reference (t
);
6025 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
6026 init
= build_constructor (TREE_TYPE (v
), NULL
);
6028 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
6029 OMP_CLAUSE_REDUCTION_INIT (c
)
6030 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
6035 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
6039 error_at (OMP_CLAUSE_LOCATION (c
),
6040 "user defined reduction not found for %qE",
6041 omp_clause_printable_decl (t
));
6044 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
6045 gcc_assert (TYPE_SIZE_UNIT (type
)
6046 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
6050 /* Called from finish_struct_1. linear(this) or linear(this:step)
6051 clauses might not be finalized yet because the class has been incomplete
6052 when parsing #pragma omp declare simd methods. Fix those up now. */
6055 finish_omp_declare_simd_methods (tree t
)
6057 if (processing_template_decl
)
6060 for (tree x
= TYPE_FIELDS (t
); x
; x
= DECL_CHAIN (x
))
6062 if (TREE_CODE (x
) == USING_DECL
6063 || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x
))
6065 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
6066 if (!ods
|| !TREE_VALUE (ods
))
6068 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
6069 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
6070 && integer_zerop (OMP_CLAUSE_DECL (c
))
6071 && OMP_CLAUSE_LINEAR_STEP (c
)
6072 && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
))))
6074 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
6075 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
6076 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
6077 sizetype
, s
, TYPE_SIZE_UNIT (t
));
6078 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
6083 /* Adjust sink depend clause to take into account pointer offsets.
6085 Return TRUE if there was a problem processing the offset, and the
6086 whole clause should be removed. */
6089 cp_finish_omp_clause_depend_sink (tree sink_clause
)
6091 tree t
= OMP_CLAUSE_DECL (sink_clause
);
6092 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
6094 /* Make sure we don't adjust things twice for templates. */
6095 if (processing_template_decl
)
6098 for (; t
; t
= TREE_CHAIN (t
))
6100 tree decl
= TREE_VALUE (t
);
6101 if (TYPE_PTR_P (TREE_TYPE (decl
)))
6103 tree offset
= TREE_PURPOSE (t
);
6104 bool neg
= wi::neg_p (wi::to_wide (offset
));
6105 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
6106 decl
= mark_rvalue_use (decl
);
6107 decl
= convert_from_reference (decl
);
6108 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
6109 neg
? MINUS_EXPR
: PLUS_EXPR
,
6111 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
6112 MINUS_EXPR
, sizetype
,
6113 fold_convert (sizetype
, t2
),
6114 fold_convert (sizetype
, decl
));
6115 if (t2
== error_mark_node
)
6117 TREE_PURPOSE (t
) = t2
;
6123 /* Finish OpenMP iterators ITER. Return true if they are errorneous
6124 and clauses containing them should be removed. */
6127 cp_omp_finish_iterators (tree iter
)
6130 for (tree it
= iter
; it
; it
= TREE_CHAIN (it
))
6132 tree var
= TREE_VEC_ELT (it
, 0);
6133 tree begin
= TREE_VEC_ELT (it
, 1);
6134 tree end
= TREE_VEC_ELT (it
, 2);
6135 tree step
= TREE_VEC_ELT (it
, 3);
6137 tree type
= TREE_TYPE (var
);
6138 location_t loc
= DECL_SOURCE_LOCATION (var
);
6139 if (type
== error_mark_node
)
6144 if (type_dependent_expression_p (var
))
6146 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
6148 error_at (loc
, "iterator %qD has neither integral nor pointer type",
6153 else if (TYPE_READONLY (type
))
6155 error_at (loc
, "iterator %qD has const qualified type", var
);
6159 if (type_dependent_expression_p (begin
)
6160 || type_dependent_expression_p (end
)
6161 || type_dependent_expression_p (step
))
6163 else if (error_operand_p (step
))
6168 else if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
6170 error_at (EXPR_LOC_OR_LOC (step
, loc
),
6171 "iterator step with non-integral type");
6176 begin
= mark_rvalue_use (begin
);
6177 end
= mark_rvalue_use (end
);
6178 step
= mark_rvalue_use (step
);
6179 begin
= cp_build_c_cast (input_location
, type
, begin
,
6180 tf_warning_or_error
);
6181 end
= cp_build_c_cast (input_location
, type
, end
,
6182 tf_warning_or_error
);
6184 if (!processing_template_decl
)
6185 step
= orig_step
= save_expr (step
);
6186 tree stype
= POINTER_TYPE_P (type
) ? sizetype
: type
;
6187 step
= cp_build_c_cast (input_location
, stype
, step
,
6188 tf_warning_or_error
);
6189 if (POINTER_TYPE_P (type
) && !processing_template_decl
)
6191 begin
= save_expr (begin
);
6192 step
= pointer_int_sum (loc
, PLUS_EXPR
, begin
, step
);
6193 step
= fold_build2_loc (loc
, MINUS_EXPR
, sizetype
,
6194 fold_convert (sizetype
, step
),
6195 fold_convert (sizetype
, begin
));
6196 step
= fold_convert (ssizetype
, step
);
6198 if (!processing_template_decl
)
6200 begin
= maybe_constant_value (begin
);
6201 end
= maybe_constant_value (end
);
6202 step
= maybe_constant_value (step
);
6203 orig_step
= maybe_constant_value (orig_step
);
6205 if (integer_zerop (step
))
6207 error_at (loc
, "iterator %qD has zero step", var
);
6212 if (begin
== error_mark_node
6213 || end
== error_mark_node
6214 || step
== error_mark_node
6215 || orig_step
== error_mark_node
)
6221 if (!processing_template_decl
)
6223 begin
= fold_build_cleanup_point_expr (TREE_TYPE (begin
), begin
);
6224 end
= fold_build_cleanup_point_expr (TREE_TYPE (end
), end
);
6225 step
= fold_build_cleanup_point_expr (TREE_TYPE (step
), step
);
6226 orig_step
= fold_build_cleanup_point_expr (TREE_TYPE (orig_step
),
6229 hash_set
<tree
> pset
;
6231 for (it2
= TREE_CHAIN (it
); it2
; it2
= TREE_CHAIN (it2
))
6233 tree var2
= TREE_VEC_ELT (it2
, 0);
6234 tree begin2
= TREE_VEC_ELT (it2
, 1);
6235 tree end2
= TREE_VEC_ELT (it2
, 2);
6236 tree step2
= TREE_VEC_ELT (it2
, 3);
6237 location_t loc2
= DECL_SOURCE_LOCATION (var2
);
6238 if (cp_walk_tree (&begin2
, find_omp_placeholder_r
, var
, &pset
))
6240 error_at (EXPR_LOC_OR_LOC (begin2
, loc2
),
6241 "begin expression refers to outer iterator %qD", var
);
6244 else if (cp_walk_tree (&end2
, find_omp_placeholder_r
, var
, &pset
))
6246 error_at (EXPR_LOC_OR_LOC (end2
, loc2
),
6247 "end expression refers to outer iterator %qD", var
);
6250 else if (cp_walk_tree (&step2
, find_omp_placeholder_r
, var
, &pset
))
6252 error_at (EXPR_LOC_OR_LOC (step2
, loc2
),
6253 "step expression refers to outer iterator %qD", var
);
6262 TREE_VEC_ELT (it
, 1) = begin
;
6263 TREE_VEC_ELT (it
, 2) = end
;
6264 if (processing_template_decl
)
6265 TREE_VEC_ELT (it
, 3) = orig_step
;
6268 TREE_VEC_ELT (it
, 3) = step
;
6269 TREE_VEC_ELT (it
, 4) = orig_step
;
6275 /* Ensure that pointers are used in OpenACC attach and detach clauses.
6276 Return true if an error has been detected. */
6279 cp_oacc_check_attachments (tree c
)
6281 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6284 /* OpenACC attach / detach clauses must be pointers. */
6285 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
6286 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
)
6288 tree t
= OMP_CLAUSE_DECL (c
);
6291 while (TREE_CODE (t
) == TREE_LIST
)
6294 type
= TREE_TYPE (t
);
6296 if (TREE_CODE (type
) == REFERENCE_TYPE
)
6297 type
= TREE_TYPE (type
);
6299 if (TREE_CODE (type
) != POINTER_TYPE
)
6301 error_at (OMP_CLAUSE_LOCATION (c
), "expected pointer in %qs clause",
6302 c_omp_map_clause_name (c
, true));
6310 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
6311 Remove any elements from the list that are invalid. */
6314 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
6316 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
6317 bitmap_head aligned_head
, map_head
, map_field_head
, oacc_reduction_head
;
6319 tree safelen
= NULL_TREE
;
6320 bool branch_seen
= false;
6321 bool copyprivate_seen
= false;
6322 bool ordered_seen
= false;
6323 bool order_seen
= false;
6324 bool schedule_seen
= false;
6325 bool oacc_async
= false;
6326 tree last_iterators
= NULL_TREE
;
6327 bool last_iterators_remove
= false;
6328 /* 1 if normal/task reduction has been seen, -1 if inscan reduction
6329 has been seen, -2 if mixed inscan/normal reduction diagnosed. */
6330 int reduction_seen
= 0;
6332 bitmap_obstack_initialize (NULL
);
6333 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
6334 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
6335 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
6336 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
6337 /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
6338 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
6339 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
6340 /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
6342 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
6344 if (ort
& C_ORT_ACC
)
6345 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6346 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
6352 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
6354 bool remove
= false;
6355 bool field_ok
= false;
6357 switch (OMP_CLAUSE_CODE (c
))
6359 case OMP_CLAUSE_SHARED
:
6360 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6361 goto check_dup_generic
;
6362 case OMP_CLAUSE_PRIVATE
:
6363 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6364 goto check_dup_generic
;
6365 case OMP_CLAUSE_REDUCTION
:
6366 if (reduction_seen
== 0)
6367 reduction_seen
= OMP_CLAUSE_REDUCTION_INSCAN (c
) ? -1 : 1;
6368 else if (reduction_seen
!= -2
6369 && reduction_seen
!= (OMP_CLAUSE_REDUCTION_INSCAN (c
)
6372 error_at (OMP_CLAUSE_LOCATION (c
),
6373 "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
6374 "on the same construct");
6375 reduction_seen
= -2;
6378 case OMP_CLAUSE_IN_REDUCTION
:
6379 case OMP_CLAUSE_TASK_REDUCTION
:
6380 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6381 t
= OMP_CLAUSE_DECL (c
);
6382 if (TREE_CODE (t
) == TREE_LIST
)
6384 if (handle_omp_array_sections (c
, ort
))
6389 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6390 && OMP_CLAUSE_REDUCTION_INSCAN (c
))
6392 error_at (OMP_CLAUSE_LOCATION (c
),
6393 "%<inscan%> %<reduction%> clause with array "
6398 if (TREE_CODE (t
) == TREE_LIST
)
6400 while (TREE_CODE (t
) == TREE_LIST
)
6405 gcc_assert (TREE_CODE (t
) == MEM_REF
);
6406 t
= TREE_OPERAND (t
, 0);
6407 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
6408 t
= TREE_OPERAND (t
, 0);
6409 if (TREE_CODE (t
) == ADDR_EXPR
6410 || INDIRECT_REF_P (t
))
6411 t
= TREE_OPERAND (t
, 0);
6413 tree n
= omp_clause_decl_field (t
);
6416 goto check_dup_generic_t
;
6419 cxx_mark_addressable (t
);
6420 goto check_dup_generic
;
6421 case OMP_CLAUSE_COPYPRIVATE
:
6422 copyprivate_seen
= true;
6423 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6424 goto check_dup_generic
;
6425 case OMP_CLAUSE_COPYIN
:
6426 goto check_dup_generic
;
6427 case OMP_CLAUSE_LINEAR
:
6428 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6429 t
= OMP_CLAUSE_DECL (c
);
6430 if (ort
!= C_ORT_OMP_DECLARE_SIMD
6431 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
6433 error_at (OMP_CLAUSE_LOCATION (c
),
6434 "modifier should not be specified in %<linear%> "
6435 "clause on %<simd%> or %<for%> constructs");
6436 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
6438 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6439 && !type_dependent_expression_p (t
))
6441 tree type
= TREE_TYPE (t
);
6442 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6443 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
6444 && !TYPE_REF_P (type
))
6446 error_at (OMP_CLAUSE_LOCATION (c
),
6447 "linear clause with %qs modifier applied to "
6448 "non-reference variable with %qT type",
6449 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6450 ? "ref" : "uval", TREE_TYPE (t
));
6454 if (TYPE_REF_P (type
))
6455 type
= TREE_TYPE (type
);
6456 if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
6458 if (!INTEGRAL_TYPE_P (type
)
6459 && !TYPE_PTR_P (type
))
6461 error_at (OMP_CLAUSE_LOCATION (c
),
6462 "linear clause applied to non-integral "
6463 "non-pointer variable with %qT type",
6470 t
= OMP_CLAUSE_LINEAR_STEP (c
);
6472 t
= integer_one_node
;
6473 if (t
== error_mark_node
)
6478 else if (!type_dependent_expression_p (t
)
6479 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
6480 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6481 || TREE_CODE (t
) != PARM_DECL
6482 || !TYPE_REF_P (TREE_TYPE (t
))
6483 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
6485 error_at (OMP_CLAUSE_LOCATION (c
),
6486 "linear step expression must be integral");
6492 t
= mark_rvalue_use (t
);
6493 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
6495 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
6496 goto check_dup_generic
;
6498 if (!processing_template_decl
6499 && (VAR_P (OMP_CLAUSE_DECL (c
))
6500 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
6502 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
6504 t
= maybe_constant_value (t
);
6505 if (TREE_CODE (t
) != INTEGER_CST
)
6507 error_at (OMP_CLAUSE_LOCATION (c
),
6508 "%<linear%> clause step %qE is neither "
6509 "constant nor a parameter", t
);
6514 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6515 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
6516 if (TYPE_REF_P (type
))
6517 type
= TREE_TYPE (type
);
6518 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
6520 type
= build_pointer_type (type
);
6521 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
6522 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6524 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6525 MINUS_EXPR
, sizetype
,
6526 fold_convert (sizetype
, t
),
6527 fold_convert (sizetype
, d
));
6528 if (t
== error_mark_node
)
6534 else if (TYPE_PTR_P (type
)
6535 /* Can't multiply the step yet if *this
6536 is still incomplete type. */
6537 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6538 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
6539 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
6540 || DECL_NAME (OMP_CLAUSE_DECL (c
))
6542 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
6544 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
6545 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6547 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6548 MINUS_EXPR
, sizetype
,
6549 fold_convert (sizetype
, t
),
6550 fold_convert (sizetype
, d
));
6551 if (t
== error_mark_node
)
6558 t
= fold_convert (type
, t
);
6560 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6562 goto check_dup_generic
;
6564 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6567 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6568 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6571 t
= OMP_CLAUSE_DECL (c
);
6572 check_dup_generic_t
:
6573 if (t
== current_class_ptr
6574 && ((ort
!= C_ORT_OMP_DECLARE_SIMD
&& ort
!= C_ORT_ACC
)
6575 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6576 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6578 error_at (OMP_CLAUSE_LOCATION (c
),
6579 "%<this%> allowed in OpenMP only in %<declare simd%>"
6584 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6585 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6587 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6590 error_at (OMP_CLAUSE_LOCATION (c
),
6591 "%qD is not a variable in clause %qs", t
,
6592 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6594 error_at (OMP_CLAUSE_LOCATION (c
),
6595 "%qE is not a variable in clause %qs", t
,
6596 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6599 else if ((ort
== C_ORT_ACC
6600 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
6601 || (ort
== C_ORT_OMP
6602 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
6603 || (OMP_CLAUSE_CODE (c
)
6604 == OMP_CLAUSE_USE_DEVICE_ADDR
))))
6606 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
6608 error_at (OMP_CLAUSE_LOCATION (c
),
6610 ? "%qD appears more than once in reduction clauses"
6611 : "%qD appears more than once in data clauses",
6616 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
6618 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6619 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6620 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6622 error_at (OMP_CLAUSE_LOCATION (c
),
6623 "%qD appears more than once in data clauses", t
);
6626 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6627 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6629 if (ort
== C_ORT_ACC
)
6630 error_at (OMP_CLAUSE_LOCATION (c
),
6631 "%qD appears more than once in data clauses", t
);
6633 error_at (OMP_CLAUSE_LOCATION (c
),
6634 "%qD appears both in data and map clauses", t
);
6638 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6643 && TREE_CODE (t
) == FIELD_DECL
6644 && t
== OMP_CLAUSE_DECL (c
))
6647 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
6648 == OMP_CLAUSE_SHARED
));
6649 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
6654 case OMP_CLAUSE_FIRSTPRIVATE
:
6655 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6657 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6659 t
= OMP_CLAUSE_DECL (c
);
6660 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6662 error_at (OMP_CLAUSE_LOCATION (c
),
6663 "%<this%> allowed in OpenMP only in %<declare simd%>"
6668 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6669 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6670 || TREE_CODE (t
) != FIELD_DECL
))
6672 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6675 error_at (OMP_CLAUSE_LOCATION (c
),
6676 "%qD is not a variable in clause %<firstprivate%>",
6679 error_at (OMP_CLAUSE_LOCATION (c
),
6680 "%qE is not a variable in clause %<firstprivate%>",
6684 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6685 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6687 error_at (OMP_CLAUSE_LOCATION (c
),
6688 "%qD appears more than once in data clauses", t
);
6691 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6693 if (ort
== C_ORT_ACC
)
6694 error_at (OMP_CLAUSE_LOCATION (c
),
6695 "%qD appears more than once in data clauses", t
);
6697 error_at (OMP_CLAUSE_LOCATION (c
),
6698 "%qD appears both in data and map clauses", t
);
6702 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
6703 goto handle_field_decl
;
6705 case OMP_CLAUSE_LASTPRIVATE
:
6706 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6708 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6710 t
= OMP_CLAUSE_DECL (c
);
6711 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6713 error_at (OMP_CLAUSE_LOCATION (c
),
6714 "%<this%> allowed in OpenMP only in %<declare simd%>"
6719 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6720 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6721 || TREE_CODE (t
) != FIELD_DECL
))
6723 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6726 error_at (OMP_CLAUSE_LOCATION (c
),
6727 "%qD is not a variable in clause %<lastprivate%>",
6730 error_at (OMP_CLAUSE_LOCATION (c
),
6731 "%qE is not a variable in clause %<lastprivate%>",
6735 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6736 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6738 error_at (OMP_CLAUSE_LOCATION (c
),
6739 "%qD appears more than once in data clauses", t
);
6743 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
6744 goto handle_field_decl
;
6747 t
= OMP_CLAUSE_IF_EXPR (c
);
6748 t
= maybe_convert_cond (t
);
6749 if (t
== error_mark_node
)
6751 else if (!processing_template_decl
)
6752 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6753 OMP_CLAUSE_IF_EXPR (c
) = t
;
6756 case OMP_CLAUSE_FINAL
:
6757 t
= OMP_CLAUSE_FINAL_EXPR (c
);
6758 t
= maybe_convert_cond (t
);
6759 if (t
== error_mark_node
)
6761 else if (!processing_template_decl
)
6762 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6763 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
6766 case OMP_CLAUSE_GANG
:
6767 /* Operand 1 is the gang static: argument. */
6768 t
= OMP_CLAUSE_OPERAND (c
, 1);
6771 if (t
== error_mark_node
)
6773 else if (!type_dependent_expression_p (t
)
6774 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6776 error_at (OMP_CLAUSE_LOCATION (c
),
6777 "%<gang%> static expression must be integral");
6782 t
= mark_rvalue_use (t
);
6783 if (!processing_template_decl
)
6785 t
= maybe_constant_value (t
);
6786 if (TREE_CODE (t
) == INTEGER_CST
6787 && tree_int_cst_sgn (t
) != 1
6788 && t
!= integer_minus_one_node
)
6790 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6791 "%<gang%> static value must be "
6793 t
= integer_one_node
;
6795 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6798 OMP_CLAUSE_OPERAND (c
, 1) = t
;
6800 /* Check operand 0, the num argument. */
6803 case OMP_CLAUSE_WORKER
:
6804 case OMP_CLAUSE_VECTOR
:
6805 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
6809 case OMP_CLAUSE_NUM_TASKS
:
6810 case OMP_CLAUSE_NUM_TEAMS
:
6811 case OMP_CLAUSE_NUM_THREADS
:
6812 case OMP_CLAUSE_NUM_GANGS
:
6813 case OMP_CLAUSE_NUM_WORKERS
:
6814 case OMP_CLAUSE_VECTOR_LENGTH
:
6815 t
= OMP_CLAUSE_OPERAND (c
, 0);
6816 if (t
== error_mark_node
)
6818 else if (!type_dependent_expression_p (t
)
6819 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6821 switch (OMP_CLAUSE_CODE (c
))
6823 case OMP_CLAUSE_GANG
:
6824 error_at (OMP_CLAUSE_LOCATION (c
),
6825 "%<gang%> num expression must be integral"); break;
6826 case OMP_CLAUSE_VECTOR
:
6827 error_at (OMP_CLAUSE_LOCATION (c
),
6828 "%<vector%> length expression must be integral");
6830 case OMP_CLAUSE_WORKER
:
6831 error_at (OMP_CLAUSE_LOCATION (c
),
6832 "%<worker%> num expression must be integral");
6835 error_at (OMP_CLAUSE_LOCATION (c
),
6836 "%qs expression must be integral",
6837 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6843 t
= mark_rvalue_use (t
);
6844 if (!processing_template_decl
)
6846 t
= maybe_constant_value (t
);
6847 if (TREE_CODE (t
) == INTEGER_CST
6848 && tree_int_cst_sgn (t
) != 1)
6850 switch (OMP_CLAUSE_CODE (c
))
6852 case OMP_CLAUSE_GANG
:
6853 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6854 "%<gang%> num value must be positive");
6856 case OMP_CLAUSE_VECTOR
:
6857 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6858 "%<vector%> length value must be "
6861 case OMP_CLAUSE_WORKER
:
6862 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6863 "%<worker%> num value must be "
6867 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6868 "%qs value must be positive",
6869 omp_clause_code_name
6870 [OMP_CLAUSE_CODE (c
)]);
6872 t
= integer_one_node
;
6874 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6876 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6880 case OMP_CLAUSE_SCHEDULE
:
6881 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
6884 else 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 "schedule chunk size expression must be integral");
6895 t
= mark_rvalue_use (t
);
6896 if (!processing_template_decl
)
6898 t
= maybe_constant_value (t
);
6899 if (TREE_CODE (t
) == INTEGER_CST
6900 && tree_int_cst_sgn (t
) != 1)
6902 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6903 "chunk size value must be positive");
6904 t
= integer_one_node
;
6906 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6908 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
6911 schedule_seen
= true;
6914 case OMP_CLAUSE_SIMDLEN
:
6915 case OMP_CLAUSE_SAFELEN
:
6916 t
= OMP_CLAUSE_OPERAND (c
, 0);
6917 if (t
== error_mark_node
)
6919 else if (!type_dependent_expression_p (t
)
6920 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6922 error_at (OMP_CLAUSE_LOCATION (c
),
6923 "%qs length expression must be integral",
6924 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6929 t
= mark_rvalue_use (t
);
6930 if (!processing_template_decl
)
6932 t
= maybe_constant_value (t
);
6933 if (TREE_CODE (t
) != INTEGER_CST
6934 || tree_int_cst_sgn (t
) != 1)
6936 error_at (OMP_CLAUSE_LOCATION (c
),
6937 "%qs length expression must be positive "
6938 "constant integer expression",
6939 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6943 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6944 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
6949 case OMP_CLAUSE_ASYNC
:
6950 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
6951 if (t
== error_mark_node
)
6953 else if (!type_dependent_expression_p (t
)
6954 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6956 error_at (OMP_CLAUSE_LOCATION (c
),
6957 "%<async%> expression must be integral");
6962 t
= mark_rvalue_use (t
);
6963 if (!processing_template_decl
)
6964 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6965 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
6969 case OMP_CLAUSE_WAIT
:
6970 t
= OMP_CLAUSE_WAIT_EXPR (c
);
6971 if (t
== error_mark_node
)
6973 else if (!processing_template_decl
)
6974 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6975 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
6978 case OMP_CLAUSE_THREAD_LIMIT
:
6979 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
6980 if (t
== error_mark_node
)
6982 else if (!type_dependent_expression_p (t
)
6983 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6985 error_at (OMP_CLAUSE_LOCATION (c
),
6986 "%<thread_limit%> expression must be integral");
6991 t
= mark_rvalue_use (t
);
6992 if (!processing_template_decl
)
6994 t
= maybe_constant_value (t
);
6995 if (TREE_CODE (t
) == INTEGER_CST
6996 && tree_int_cst_sgn (t
) != 1)
6998 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6999 "%<thread_limit%> value must be positive");
7000 t
= integer_one_node
;
7002 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7004 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
7008 case OMP_CLAUSE_DEVICE
:
7009 t
= OMP_CLAUSE_DEVICE_ID (c
);
7010 if (t
== error_mark_node
)
7012 else if (!type_dependent_expression_p (t
)
7013 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7015 error_at (OMP_CLAUSE_LOCATION (c
),
7016 "%<device%> id must be integral");
7021 t
= mark_rvalue_use (t
);
7022 if (!processing_template_decl
)
7023 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7024 OMP_CLAUSE_DEVICE_ID (c
) = t
;
7028 case OMP_CLAUSE_DIST_SCHEDULE
:
7029 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
7032 else if (t
== error_mark_node
)
7034 else if (!type_dependent_expression_p (t
)
7035 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7037 error_at (OMP_CLAUSE_LOCATION (c
),
7038 "%<dist_schedule%> chunk size expression must be "
7044 t
= mark_rvalue_use (t
);
7045 if (!processing_template_decl
)
7046 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7047 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
7051 case OMP_CLAUSE_ALIGNED
:
7052 t
= OMP_CLAUSE_DECL (c
);
7053 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
7055 error_at (OMP_CLAUSE_LOCATION (c
),
7056 "%<this%> allowed in OpenMP only in %<declare simd%>"
7061 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7063 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7066 error_at (OMP_CLAUSE_LOCATION (c
),
7067 "%qD is not a variable in %<aligned%> clause", t
);
7069 error_at (OMP_CLAUSE_LOCATION (c
),
7070 "%qE is not a variable in %<aligned%> clause", t
);
7073 else if (!type_dependent_expression_p (t
)
7074 && !TYPE_PTR_P (TREE_TYPE (t
))
7075 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
7076 && (!TYPE_REF_P (TREE_TYPE (t
))
7077 || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
7078 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
7081 error_at (OMP_CLAUSE_LOCATION (c
),
7082 "%qE in %<aligned%> clause is neither a pointer nor "
7083 "an array nor a reference to pointer or array", t
);
7086 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7088 error_at (OMP_CLAUSE_LOCATION (c
),
7089 "%qD appears more than once in %<aligned%> clauses",
7094 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
7095 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
7096 if (t
== error_mark_node
)
7098 else if (t
== NULL_TREE
)
7100 else if (!type_dependent_expression_p (t
)
7101 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7103 error_at (OMP_CLAUSE_LOCATION (c
),
7104 "%<aligned%> clause alignment expression must "
7110 t
= mark_rvalue_use (t
);
7111 if (!processing_template_decl
)
7113 t
= maybe_constant_value (t
);
7114 if (TREE_CODE (t
) != INTEGER_CST
7115 || tree_int_cst_sgn (t
) != 1)
7117 error_at (OMP_CLAUSE_LOCATION (c
),
7118 "%<aligned%> clause alignment expression must "
7119 "be positive constant integer expression");
7123 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7125 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
7129 case OMP_CLAUSE_NONTEMPORAL
:
7130 t
= OMP_CLAUSE_DECL (c
);
7131 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7133 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7136 error_at (OMP_CLAUSE_LOCATION (c
),
7137 "%qD is not a variable in %<nontemporal%> clause",
7140 error_at (OMP_CLAUSE_LOCATION (c
),
7141 "%qE is not a variable in %<nontemporal%> clause",
7145 else if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
7147 error_at (OMP_CLAUSE_LOCATION (c
),
7148 "%qD appears more than once in %<nontemporal%> "
7153 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
7156 case OMP_CLAUSE_DEPEND
:
7157 t
= OMP_CLAUSE_DECL (c
);
7160 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
7161 == OMP_CLAUSE_DEPEND_SOURCE
);
7164 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
7166 if (cp_finish_omp_clause_depend_sink (c
))
7170 if (TREE_CODE (t
) == TREE_LIST
7172 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
7174 if (TREE_PURPOSE (t
) != last_iterators
)
7175 last_iterators_remove
7176 = cp_omp_finish_iterators (TREE_PURPOSE (t
));
7177 last_iterators
= TREE_PURPOSE (t
);
7179 if (last_iterators_remove
)
7180 t
= error_mark_node
;
7183 last_iterators
= NULL_TREE
;
7185 if (TREE_CODE (t
) == TREE_LIST
)
7187 if (handle_omp_array_sections (c
, ort
))
7189 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7191 error_at (OMP_CLAUSE_LOCATION (c
),
7192 "%<depend%> clause with %<depobj%> dependence "
7193 "type on array section");
7198 if (t
== error_mark_node
)
7200 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7202 error_at (OMP_CLAUSE_LOCATION (c
),
7203 "%<this%> allowed in OpenMP only in %<declare simd%>"
7207 else if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7209 else if (!lvalue_p (t
))
7212 error_at (OMP_CLAUSE_LOCATION (c
),
7213 "%qD is not lvalue expression nor array section "
7214 "in %<depend%> clause", t
);
7216 error_at (OMP_CLAUSE_LOCATION (c
),
7217 "%qE is not lvalue expression nor array section "
7218 "in %<depend%> clause", t
);
7221 else if (TREE_CODE (t
) == COMPONENT_REF
7222 && TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7223 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7225 error_at (OMP_CLAUSE_LOCATION (c
),
7226 "bit-field %qE in %qs clause", t
, "depend");
7229 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7231 if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7232 ? TREE_TYPE (TREE_TYPE (t
))
7235 error_at (OMP_CLAUSE_LOCATION (c
),
7236 "%qE does not have %<omp_depend_t%> type in "
7237 "%<depend%> clause with %<depobj%> dependence "
7242 else if (c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7243 ? TREE_TYPE (TREE_TYPE (t
))
7246 error_at (OMP_CLAUSE_LOCATION (c
),
7247 "%qE should not have %<omp_depend_t%> type in "
7248 "%<depend%> clause with dependence type other than "
7254 tree addr
= cp_build_addr_expr (t
, tf_warning_or_error
);
7255 if (addr
== error_mark_node
)
7259 t
= cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c
),
7260 addr
, RO_UNARY_STAR
,
7261 tf_warning_or_error
);
7262 if (t
== error_mark_node
)
7264 else if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == TREE_LIST
7265 && TREE_PURPOSE (OMP_CLAUSE_DECL (c
))
7266 && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c
)))
7268 TREE_VALUE (OMP_CLAUSE_DECL (c
)) = t
;
7270 OMP_CLAUSE_DECL (c
) = t
;
7275 case OMP_CLAUSE_MAP
:
7277 case OMP_CLAUSE_FROM
:
7278 case OMP_CLAUSE__CACHE_
:
7279 t
= OMP_CLAUSE_DECL (c
);
7280 if (TREE_CODE (t
) == TREE_LIST
)
7282 if (handle_omp_array_sections (c
, ort
))
7286 t
= OMP_CLAUSE_DECL (c
);
7287 if (TREE_CODE (t
) != TREE_LIST
7288 && !type_dependent_expression_p (t
)
7289 && !cp_omp_mappable_type (TREE_TYPE (t
)))
7291 error_at (OMP_CLAUSE_LOCATION (c
),
7292 "array section does not have mappable type "
7294 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7295 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7298 while (TREE_CODE (t
) == ARRAY_REF
)
7299 t
= TREE_OPERAND (t
, 0);
7300 if (TREE_CODE (t
) == COMPONENT_REF
7301 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
7303 while (TREE_CODE (t
) == COMPONENT_REF
)
7304 t
= TREE_OPERAND (t
, 0);
7305 if (REFERENCE_REF_P (t
))
7306 t
= TREE_OPERAND (t
, 0);
7307 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7309 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7311 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7312 error_at (OMP_CLAUSE_LOCATION (c
),
7313 "%qD appears more than once in motion"
7315 else if (ort
== C_ORT_ACC
)
7316 error_at (OMP_CLAUSE_LOCATION (c
),
7317 "%qD appears more than once in data"
7320 error_at (OMP_CLAUSE_LOCATION (c
),
7321 "%qD appears more than once in map"
7327 bitmap_set_bit (&map_head
, DECL_UID (t
));
7328 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7332 if (cp_oacc_check_attachments (c
))
7336 if (t
== error_mark_node
)
7341 /* OpenACC attach / detach clauses must be pointers. */
7342 if (cp_oacc_check_attachments (c
))
7347 if (REFERENCE_REF_P (t
)
7348 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
7350 t
= TREE_OPERAND (t
, 0);
7351 OMP_CLAUSE_DECL (c
) = t
;
7353 if (ort
== C_ORT_ACC
7354 && TREE_CODE (t
) == COMPONENT_REF
7355 && TREE_CODE (TREE_OPERAND (t
, 0)) == INDIRECT_REF
)
7356 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
7357 if (TREE_CODE (t
) == COMPONENT_REF
7358 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
7359 || ort
== C_ORT_ACC
)
7360 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
7362 if (type_dependent_expression_p (t
))
7364 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7365 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7367 error_at (OMP_CLAUSE_LOCATION (c
),
7368 "bit-field %qE in %qs clause",
7369 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7372 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7374 error_at (OMP_CLAUSE_LOCATION (c
),
7375 "%qE does not have a mappable type in %qs clause",
7376 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7377 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7380 while (TREE_CODE (t
) == COMPONENT_REF
)
7382 if (TREE_TYPE (TREE_OPERAND (t
, 0))
7383 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
7386 error_at (OMP_CLAUSE_LOCATION (c
),
7387 "%qE is a member of a union", t
);
7391 t
= TREE_OPERAND (t
, 0);
7395 if (REFERENCE_REF_P (t
))
7396 t
= TREE_OPERAND (t
, 0);
7397 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7399 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7400 goto handle_map_references
;
7403 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7405 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7407 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7408 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7409 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
7410 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH_DETACH
))
7413 error_at (OMP_CLAUSE_LOCATION (c
),
7414 "%qD is not a variable in %qs clause", t
,
7415 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7417 error_at (OMP_CLAUSE_LOCATION (c
),
7418 "%qE is not a variable in %qs clause", t
,
7419 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7422 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7424 error_at (OMP_CLAUSE_LOCATION (c
),
7425 "%qD is threadprivate variable in %qs clause", t
,
7426 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7429 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7431 error_at (OMP_CLAUSE_LOCATION (c
),
7432 "%<this%> allowed in OpenMP only in %<declare simd%>"
7437 else if (!processing_template_decl
7438 && !TYPE_REF_P (TREE_TYPE (t
))
7439 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
7440 || (OMP_CLAUSE_MAP_KIND (c
)
7441 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
7442 && !cxx_mark_addressable (t
))
7444 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7445 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7446 || (OMP_CLAUSE_MAP_KIND (c
)
7447 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
7448 && t
== OMP_CLAUSE_DECL (c
)
7449 && !type_dependent_expression_p (t
)
7450 && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t
))
7451 ? TREE_TYPE (TREE_TYPE (t
))
7454 error_at (OMP_CLAUSE_LOCATION (c
),
7455 "%qD does not have a mappable type in %qs clause", t
,
7456 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7457 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7460 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7461 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
7462 && !type_dependent_expression_p (t
)
7463 && !INDIRECT_TYPE_P (TREE_TYPE (t
)))
7465 error_at (OMP_CLAUSE_LOCATION (c
),
7466 "%qD is not a pointer variable", t
);
7469 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7470 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
7472 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7473 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7475 error_at (OMP_CLAUSE_LOCATION (c
),
7476 "%qD appears more than once in data clauses", t
);
7479 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7481 if (ort
== C_ORT_ACC
)
7482 error_at (OMP_CLAUSE_LOCATION (c
),
7483 "%qD appears more than once in data clauses", t
);
7485 error_at (OMP_CLAUSE_LOCATION (c
),
7486 "%qD appears both in data and map clauses", t
);
7490 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7492 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
7493 && (ort
!= C_ORT_ACC
7494 || !bitmap_bit_p (&map_field_head
, DECL_UID (t
))))
7496 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7497 error_at (OMP_CLAUSE_LOCATION (c
),
7498 "%qD appears more than once in motion clauses", t
);
7499 if (ort
== C_ORT_ACC
)
7500 error_at (OMP_CLAUSE_LOCATION (c
),
7501 "%qD appears more than once in data clauses", t
);
7503 error_at (OMP_CLAUSE_LOCATION (c
),
7504 "%qD appears more than once in map clauses", t
);
7507 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7508 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7510 if (ort
== C_ORT_ACC
)
7511 error_at (OMP_CLAUSE_LOCATION (c
),
7512 "%qD appears more than once in data clauses", t
);
7514 error_at (OMP_CLAUSE_LOCATION (c
),
7515 "%qD appears both in data and map clauses", t
);
7520 bitmap_set_bit (&map_head
, DECL_UID (t
));
7521 if (t
!= OMP_CLAUSE_DECL (c
)
7522 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
7523 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7525 handle_map_references
:
7527 && !processing_template_decl
7528 && ort
!= C_ORT_DECLARE_SIMD
7529 && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
))))
7531 t
= OMP_CLAUSE_DECL (c
);
7532 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7534 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7535 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7537 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7539 else if (OMP_CLAUSE_MAP_KIND (c
)
7540 != GOMP_MAP_FIRSTPRIVATE_POINTER
7541 && (OMP_CLAUSE_MAP_KIND (c
)
7542 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
7543 && (OMP_CLAUSE_MAP_KIND (c
)
7544 != GOMP_MAP_ALWAYS_POINTER
))
7546 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
7548 if (TREE_CODE (t
) == COMPONENT_REF
)
7551 = (ort
== C_ORT_ACC
) ? GOMP_MAP_ATTACH_DETACH
7552 : GOMP_MAP_ALWAYS_POINTER
;
7553 OMP_CLAUSE_SET_MAP_KIND (c2
, k
);
7556 OMP_CLAUSE_SET_MAP_KIND (c2
,
7557 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
7558 OMP_CLAUSE_DECL (c2
) = t
;
7559 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
7560 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
7561 OMP_CLAUSE_CHAIN (c
) = c2
;
7562 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7563 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7565 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7571 case OMP_CLAUSE_TO_DECLARE
:
7572 case OMP_CLAUSE_LINK
:
7573 t
= OMP_CLAUSE_DECL (c
);
7574 if (TREE_CODE (t
) == FUNCTION_DECL
7575 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7577 else if (!VAR_P (t
))
7579 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7581 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
7582 error_at (OMP_CLAUSE_LOCATION (c
),
7583 "template %qE in clause %qs", t
,
7584 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7585 else if (really_overloaded_fn (t
))
7586 error_at (OMP_CLAUSE_LOCATION (c
),
7587 "overloaded function name %qE in clause %qs", t
,
7588 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7590 error_at (OMP_CLAUSE_LOCATION (c
),
7591 "%qE is neither a variable nor a function name "
7593 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7596 error_at (OMP_CLAUSE_LOCATION (c
),
7597 "%qE is not a variable in clause %qs", t
,
7598 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7601 else if (DECL_THREAD_LOCAL_P (t
))
7603 error_at (OMP_CLAUSE_LOCATION (c
),
7604 "%qD is threadprivate variable in %qs clause", t
,
7605 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7608 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7610 error_at (OMP_CLAUSE_LOCATION (c
),
7611 "%qD does not have a mappable type in %qs clause", t
,
7612 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7613 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7618 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
7620 error_at (OMP_CLAUSE_LOCATION (c
),
7621 "%qE appears more than once on the same "
7622 "%<declare target%> directive", t
);
7626 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7629 case OMP_CLAUSE_UNIFORM
:
7630 t
= OMP_CLAUSE_DECL (c
);
7631 if (TREE_CODE (t
) != PARM_DECL
)
7633 if (processing_template_decl
)
7636 error_at (OMP_CLAUSE_LOCATION (c
),
7637 "%qD is not an argument in %<uniform%> clause", t
);
7639 error_at (OMP_CLAUSE_LOCATION (c
),
7640 "%qE is not an argument in %<uniform%> clause", t
);
7644 /* map_head bitmap is used as uniform_head if declare_simd. */
7645 bitmap_set_bit (&map_head
, DECL_UID (t
));
7646 goto check_dup_generic
;
7648 case OMP_CLAUSE_GRAINSIZE
:
7649 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
7650 if (t
== error_mark_node
)
7652 else if (!type_dependent_expression_p (t
)
7653 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7655 error_at (OMP_CLAUSE_LOCATION (c
),
7656 "%<grainsize%> expression must be integral");
7661 t
= mark_rvalue_use (t
);
7662 if (!processing_template_decl
)
7664 t
= maybe_constant_value (t
);
7665 if (TREE_CODE (t
) == INTEGER_CST
7666 && tree_int_cst_sgn (t
) != 1)
7668 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7669 "%<grainsize%> value must be positive");
7670 t
= integer_one_node
;
7672 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7674 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
7678 case OMP_CLAUSE_PRIORITY
:
7679 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
7680 if (t
== error_mark_node
)
7682 else if (!type_dependent_expression_p (t
)
7683 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7685 error_at (OMP_CLAUSE_LOCATION (c
),
7686 "%<priority%> expression must be integral");
7691 t
= mark_rvalue_use (t
);
7692 if (!processing_template_decl
)
7694 t
= maybe_constant_value (t
);
7695 if (TREE_CODE (t
) == INTEGER_CST
7696 && tree_int_cst_sgn (t
) == -1)
7698 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7699 "%<priority%> value must be non-negative");
7700 t
= integer_one_node
;
7702 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7704 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
7708 case OMP_CLAUSE_HINT
:
7709 t
= OMP_CLAUSE_HINT_EXPR (c
);
7710 if (t
== error_mark_node
)
7712 else if (!type_dependent_expression_p (t
)
7713 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7715 error_at (OMP_CLAUSE_LOCATION (c
),
7716 "%<hint%> expression must be integral");
7721 t
= mark_rvalue_use (t
);
7722 if (!processing_template_decl
)
7724 t
= maybe_constant_value (t
);
7725 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7726 if (TREE_CODE (t
) != INTEGER_CST
)
7728 error_at (OMP_CLAUSE_LOCATION (c
),
7729 "%<hint%> expression must be constant integer "
7734 OMP_CLAUSE_HINT_EXPR (c
) = t
;
7738 case OMP_CLAUSE_IS_DEVICE_PTR
:
7739 case OMP_CLAUSE_USE_DEVICE_PTR
:
7740 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
7741 t
= OMP_CLAUSE_DECL (c
);
7742 if (!type_dependent_expression_p (t
))
7744 tree type
= TREE_TYPE (t
);
7745 if (!TYPE_PTR_P (type
)
7746 && (!TYPE_REF_P (type
) || !TYPE_PTR_P (TREE_TYPE (type
))))
7748 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
7749 && ort
== C_ORT_OMP
)
7751 error_at (OMP_CLAUSE_LOCATION (c
),
7752 "%qs variable is neither a pointer "
7753 "nor reference to pointer",
7754 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7757 else if (TREE_CODE (type
) != ARRAY_TYPE
7758 && (!TYPE_REF_P (type
)
7759 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
7761 error_at (OMP_CLAUSE_LOCATION (c
),
7762 "%qs variable is neither a pointer, nor an "
7763 "array nor reference to pointer or array",
7764 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7769 goto check_dup_generic
;
7771 case OMP_CLAUSE_USE_DEVICE_ADDR
:
7773 t
= OMP_CLAUSE_DECL (c
);
7774 if (!processing_template_decl
7775 && (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7776 && !TYPE_REF_P (TREE_TYPE (t
))
7777 && !cxx_mark_addressable (t
))
7779 goto check_dup_generic
;
7781 case OMP_CLAUSE_NOWAIT
:
7782 case OMP_CLAUSE_DEFAULT
:
7783 case OMP_CLAUSE_UNTIED
:
7784 case OMP_CLAUSE_COLLAPSE
:
7785 case OMP_CLAUSE_MERGEABLE
:
7786 case OMP_CLAUSE_PARALLEL
:
7787 case OMP_CLAUSE_FOR
:
7788 case OMP_CLAUSE_SECTIONS
:
7789 case OMP_CLAUSE_TASKGROUP
:
7790 case OMP_CLAUSE_PROC_BIND
:
7791 case OMP_CLAUSE_DEVICE_TYPE
:
7792 case OMP_CLAUSE_NOGROUP
:
7793 case OMP_CLAUSE_THREADS
:
7794 case OMP_CLAUSE_SIMD
:
7795 case OMP_CLAUSE_DEFAULTMAP
:
7796 case OMP_CLAUSE_BIND
:
7797 case OMP_CLAUSE_AUTO
:
7798 case OMP_CLAUSE_INDEPENDENT
:
7799 case OMP_CLAUSE_SEQ
:
7800 case OMP_CLAUSE_IF_PRESENT
:
7801 case OMP_CLAUSE_FINALIZE
:
7804 case OMP_CLAUSE_TILE
:
7805 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
7806 list
= TREE_CHAIN (list
))
7808 t
= TREE_VALUE (list
);
7810 if (t
== error_mark_node
)
7812 else if (!type_dependent_expression_p (t
)
7813 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7815 error_at (OMP_CLAUSE_LOCATION (c
),
7816 "%<tile%> argument needs integral type");
7821 t
= mark_rvalue_use (t
);
7822 if (!processing_template_decl
)
7824 /* Zero is used to indicate '*', we permit you
7825 to get there via an ICE of value zero. */
7826 t
= maybe_constant_value (t
);
7827 if (!tree_fits_shwi_p (t
)
7828 || tree_to_shwi (t
) < 0)
7830 error_at (OMP_CLAUSE_LOCATION (c
),
7831 "%<tile%> argument needs positive "
7832 "integral constant");
7835 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7839 /* Update list item. */
7840 TREE_VALUE (list
) = t
;
7844 case OMP_CLAUSE_ORDERED
:
7845 ordered_seen
= true;
7848 case OMP_CLAUSE_ORDER
:
7855 case OMP_CLAUSE_INBRANCH
:
7856 case OMP_CLAUSE_NOTINBRANCH
:
7859 error_at (OMP_CLAUSE_LOCATION (c
),
7860 "%<inbranch%> clause is incompatible with "
7867 case OMP_CLAUSE_INCLUSIVE
:
7868 case OMP_CLAUSE_EXCLUSIVE
:
7869 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7871 t
= OMP_CLAUSE_DECL (c
);
7872 if (t
== current_class_ptr
)
7874 error_at (OMP_CLAUSE_LOCATION (c
),
7875 "%<this%> allowed in OpenMP only in %<declare simd%>"
7881 && TREE_CODE (t
) != PARM_DECL
7882 && TREE_CODE (t
) != FIELD_DECL
)
7884 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7887 error_at (OMP_CLAUSE_LOCATION (c
),
7888 "%qD is not a variable in clause %qs", t
,
7889 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7891 error_at (OMP_CLAUSE_LOCATION (c
),
7892 "%qE is not a variable in clause %qs", t
,
7893 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7903 *pc
= OMP_CLAUSE_CHAIN (c
);
7905 pc
= &OMP_CLAUSE_CHAIN (c
);
7908 if (reduction_seen
< 0 && (ordered_seen
|| schedule_seen
))
7909 reduction_seen
= -2;
7911 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
7913 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
7914 bool remove
= false;
7915 bool need_complete_type
= false;
7916 bool need_default_ctor
= false;
7917 bool need_copy_ctor
= false;
7918 bool need_copy_assignment
= false;
7919 bool need_implicitly_determined
= false;
7920 bool need_dtor
= false;
7921 tree type
, inner_type
;
7925 case OMP_CLAUSE_SHARED
:
7926 need_implicitly_determined
= true;
7928 case OMP_CLAUSE_PRIVATE
:
7929 need_complete_type
= true;
7930 need_default_ctor
= true;
7932 need_implicitly_determined
= true;
7934 case OMP_CLAUSE_FIRSTPRIVATE
:
7935 need_complete_type
= true;
7936 need_copy_ctor
= true;
7938 need_implicitly_determined
= true;
7940 case OMP_CLAUSE_LASTPRIVATE
:
7941 need_complete_type
= true;
7942 need_copy_assignment
= true;
7943 need_implicitly_determined
= true;
7945 case OMP_CLAUSE_REDUCTION
:
7946 if (reduction_seen
== -2)
7947 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
7948 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
7949 need_copy_assignment
= true;
7950 need_implicitly_determined
= true;
7952 case OMP_CLAUSE_IN_REDUCTION
:
7953 case OMP_CLAUSE_TASK_REDUCTION
:
7954 case OMP_CLAUSE_INCLUSIVE
:
7955 case OMP_CLAUSE_EXCLUSIVE
:
7956 need_implicitly_determined
= true;
7958 case OMP_CLAUSE_LINEAR
:
7959 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
7960 need_implicitly_determined
= true;
7961 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
7962 && !bitmap_bit_p (&map_head
,
7963 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
7965 error_at (OMP_CLAUSE_LOCATION (c
),
7966 "%<linear%> clause step is a parameter %qD not "
7967 "specified in %<uniform%> clause",
7968 OMP_CLAUSE_LINEAR_STEP (c
));
7969 *pc
= OMP_CLAUSE_CHAIN (c
);
7973 case OMP_CLAUSE_COPYPRIVATE
:
7974 need_copy_assignment
= true;
7976 case OMP_CLAUSE_COPYIN
:
7977 need_copy_assignment
= true;
7979 case OMP_CLAUSE_SIMDLEN
:
7981 && !processing_template_decl
7982 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
7983 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
7985 error_at (OMP_CLAUSE_LOCATION (c
),
7986 "%<simdlen%> clause value is bigger than "
7987 "%<safelen%> clause value");
7988 OMP_CLAUSE_SIMDLEN_EXPR (c
)
7989 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
7991 pc
= &OMP_CLAUSE_CHAIN (c
);
7993 case OMP_CLAUSE_SCHEDULE
:
7995 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
7996 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
7998 error_at (OMP_CLAUSE_LOCATION (c
),
7999 "%<nonmonotonic%> schedule modifier specified "
8000 "together with %<ordered%> clause");
8001 OMP_CLAUSE_SCHEDULE_KIND (c
)
8002 = (enum omp_clause_schedule_kind
)
8003 (OMP_CLAUSE_SCHEDULE_KIND (c
)
8004 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
8006 if (reduction_seen
== -2)
8007 error_at (OMP_CLAUSE_LOCATION (c
),
8008 "%qs clause specified together with %<inscan%> "
8009 "%<reduction%> clause", "schedule");
8010 pc
= &OMP_CLAUSE_CHAIN (c
);
8012 case OMP_CLAUSE_NOGROUP
:
8015 error_at (OMP_CLAUSE_LOCATION (c
),
8016 "%<nogroup%> clause must not be used together with "
8017 "%<reduction%> clause");
8018 *pc
= OMP_CLAUSE_CHAIN (c
);
8021 pc
= &OMP_CLAUSE_CHAIN (c
);
8023 case OMP_CLAUSE_ORDERED
:
8024 if (reduction_seen
== -2)
8025 error_at (OMP_CLAUSE_LOCATION (c
),
8026 "%qs clause specified together with %<inscan%> "
8027 "%<reduction%> clause", "ordered");
8028 pc
= &OMP_CLAUSE_CHAIN (c
);
8030 case OMP_CLAUSE_ORDER
:
8033 error_at (OMP_CLAUSE_LOCATION (c
),
8034 "%<order%> clause must not be used together "
8035 "with %<ordered%>");
8036 *pc
= OMP_CLAUSE_CHAIN (c
);
8039 pc
= &OMP_CLAUSE_CHAIN (c
);
8041 case OMP_CLAUSE_NOWAIT
:
8042 if (copyprivate_seen
)
8044 error_at (OMP_CLAUSE_LOCATION (c
),
8045 "%<nowait%> clause must not be used together "
8046 "with %<copyprivate%>");
8047 *pc
= OMP_CLAUSE_CHAIN (c
);
8052 pc
= &OMP_CLAUSE_CHAIN (c
);
8056 t
= OMP_CLAUSE_DECL (c
);
8057 if (processing_template_decl
8058 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8060 pc
= &OMP_CLAUSE_CHAIN (c
);
8066 case OMP_CLAUSE_LASTPRIVATE
:
8067 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
8069 need_default_ctor
= true;
8074 case OMP_CLAUSE_REDUCTION
:
8075 case OMP_CLAUSE_IN_REDUCTION
:
8076 case OMP_CLAUSE_TASK_REDUCTION
:
8077 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
8081 t
= OMP_CLAUSE_DECL (c
);
8084 case OMP_CLAUSE_COPYIN
:
8085 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
8087 error_at (OMP_CLAUSE_LOCATION (c
),
8088 "%qE must be %<threadprivate%> for %<copyin%>", t
);
8097 if (need_complete_type
|| need_copy_assignment
)
8099 t
= require_complete_type (t
);
8100 if (t
== error_mark_node
)
8102 else if (!processing_template_decl
8103 && TYPE_REF_P (TREE_TYPE (t
))
8104 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
8107 if (need_implicitly_determined
)
8109 const char *share_name
= NULL
;
8111 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
8112 share_name
= "threadprivate";
8113 else switch (cxx_omp_predetermined_sharing_1 (t
))
8115 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
8117 case OMP_CLAUSE_DEFAULT_SHARED
:
8118 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8119 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8120 && c_omp_predefined_variable (t
))
8121 /* The __func__ variable and similar function-local predefined
8122 variables may be listed in a shared or firstprivate
8126 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8128 && cxx_omp_const_qual_no_mutable (t
))
8130 tree ctx
= CP_DECL_CONTEXT (t
);
8131 /* const qualified static data members without mutable
8132 member may be specified in firstprivate clause. */
8133 if (TYPE_P (ctx
) && MAYBE_CLASS_TYPE_P (ctx
))
8136 share_name
= "shared";
8138 case OMP_CLAUSE_DEFAULT_PRIVATE
:
8139 share_name
= "private";
8146 error_at (OMP_CLAUSE_LOCATION (c
),
8147 "%qE is predetermined %qs for %qs",
8148 omp_clause_printable_decl (t
), share_name
,
8149 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8152 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8153 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_FIRSTPRIVATE
8154 && cxx_omp_const_qual_no_mutable (t
))
8156 error_at (OMP_CLAUSE_LOCATION (c
),
8157 "%<const%> qualified %qE without %<mutable%> member "
8158 "may appear only in %<shared%> or %<firstprivate%> "
8159 "clauses", omp_clause_printable_decl (t
));
8164 /* We're interested in the base element, not arrays. */
8165 inner_type
= type
= TREE_TYPE (t
);
8166 if ((need_complete_type
8167 || need_copy_assignment
8168 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
8169 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
8170 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
8171 && TYPE_REF_P (inner_type
))
8172 inner_type
= TREE_TYPE (inner_type
);
8173 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
8174 inner_type
= TREE_TYPE (inner_type
);
8176 /* Check for special function availability by building a call to one.
8177 Save the results, because later we won't be in the right context
8178 for making these queries. */
8179 if (CLASS_TYPE_P (inner_type
)
8180 && COMPLETE_TYPE_P (inner_type
)
8181 && (need_default_ctor
|| need_copy_ctor
8182 || need_copy_assignment
|| need_dtor
)
8183 && !type_dependent_expression_p (t
)
8184 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
8185 need_copy_ctor
, need_copy_assignment
,
8190 && c_kind
== OMP_CLAUSE_SHARED
8191 && processing_template_decl
)
8193 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8195 OMP_CLAUSE_DECL (c
) = t
;
8199 *pc
= OMP_CLAUSE_CHAIN (c
);
8201 pc
= &OMP_CLAUSE_CHAIN (c
);
8204 bitmap_obstack_release (NULL
);
8208 /* Start processing OpenMP clauses that can include any
8209 privatization clauses for non-static data members. */
8212 push_omp_privatization_clauses (bool ignore_next
)
8214 if (omp_private_member_ignore_next
)
8216 omp_private_member_ignore_next
= ignore_next
;
8219 omp_private_member_ignore_next
= ignore_next
;
8220 if (omp_private_member_map
)
8221 omp_private_member_vec
.safe_push (error_mark_node
);
8222 return push_stmt_list ();
8225 /* Revert remapping of any non-static data members since
8226 the last push_omp_privatization_clauses () call. */
8229 pop_omp_privatization_clauses (tree stmt
)
8231 if (stmt
== NULL_TREE
)
8233 stmt
= pop_stmt_list (stmt
);
8234 if (omp_private_member_map
)
8236 while (!omp_private_member_vec
.is_empty ())
8238 tree t
= omp_private_member_vec
.pop ();
8239 if (t
== error_mark_node
)
8244 bool no_decl_expr
= t
== integer_zero_node
;
8246 t
= omp_private_member_vec
.pop ();
8247 tree
*v
= omp_private_member_map
->get (t
);
8251 omp_private_member_map
->remove (t
);
8253 delete omp_private_member_map
;
8254 omp_private_member_map
= NULL
;
8259 /* Remember OpenMP privatization clauses mapping and clear it.
8260 Used for lambdas. */
8263 save_omp_privatization_clauses (vec
<tree
> &save
)
8266 if (omp_private_member_ignore_next
)
8267 save
.safe_push (integer_one_node
);
8268 omp_private_member_ignore_next
= false;
8269 if (!omp_private_member_map
)
8272 while (!omp_private_member_vec
.is_empty ())
8274 tree t
= omp_private_member_vec
.pop ();
8275 if (t
== error_mark_node
)
8281 if (t
== integer_zero_node
)
8282 t
= omp_private_member_vec
.pop ();
8283 tree
*v
= omp_private_member_map
->get (t
);
8285 save
.safe_push (*v
);
8290 delete omp_private_member_map
;
8291 omp_private_member_map
= NULL
;
8294 /* Restore OpenMP privatization clauses mapping saved by the
8298 restore_omp_privatization_clauses (vec
<tree
> &save
)
8300 gcc_assert (omp_private_member_vec
.is_empty ());
8301 omp_private_member_ignore_next
= false;
8302 if (save
.is_empty ())
8304 if (save
.length () == 1 && save
[0] == integer_one_node
)
8306 omp_private_member_ignore_next
= true;
8311 omp_private_member_map
= new hash_map
<tree
, tree
>;
8312 while (!save
.is_empty ())
8314 tree t
= save
.pop ();
8316 if (t
!= error_mark_node
)
8318 if (t
== integer_one_node
)
8320 omp_private_member_ignore_next
= true;
8321 gcc_assert (save
.is_empty ());
8324 if (t
== integer_zero_node
)
8326 tree
&v
= omp_private_member_map
->get_or_insert (t
);
8329 omp_private_member_vec
.safe_push (t
);
8331 omp_private_member_vec
.safe_push (n
);
8336 /* For all variables in the tree_list VARS, mark them as thread local. */
8339 finish_omp_threadprivate (tree vars
)
8343 /* Mark every variable in VARS to be assigned thread local storage. */
8344 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8346 tree v
= TREE_PURPOSE (t
);
8348 if (error_operand_p (v
))
8350 else if (!VAR_P (v
))
8351 error ("%<threadprivate%> %qD is not file, namespace "
8352 "or block scope variable", v
);
8353 /* If V had already been marked threadprivate, it doesn't matter
8354 whether it had been used prior to this point. */
8355 else if (TREE_USED (v
)
8356 && (DECL_LANG_SPECIFIC (v
) == NULL
8357 || !CP_DECL_THREADPRIVATE_P (v
)))
8358 error ("%qE declared %<threadprivate%> after first use", v
);
8359 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8360 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8361 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
8362 error ("%<threadprivate%> %qE has incomplete type", v
);
8363 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
8364 && CP_DECL_CONTEXT (v
) != current_class_type
)
8365 error ("%<threadprivate%> %qE directive not "
8366 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
8369 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
8370 if (DECL_LANG_SPECIFIC (v
) == NULL
)
8371 retrofit_lang_decl (v
);
8373 if (! CP_DECL_THREAD_LOCAL_P (v
))
8375 CP_DECL_THREAD_LOCAL_P (v
) = true;
8376 set_decl_tls_model (v
, decl_default_tls_model (v
));
8377 /* If rtl has been already set for this var, call
8378 make_decl_rtl once again, so that encode_section_info
8379 has a chance to look at the new decl flags. */
8380 if (DECL_RTL_SET_P (v
))
8383 CP_DECL_THREADPRIVATE_P (v
) = 1;
8388 /* Build an OpenMP structured block. */
8391 begin_omp_structured_block (void)
8393 return do_pushlevel (sk_omp
);
8397 finish_omp_structured_block (tree block
)
8399 return do_poplevel (block
);
8402 /* Similarly, except force the retention of the BLOCK. */
8405 begin_omp_parallel (void)
8407 keep_next_level (true);
8408 return begin_omp_structured_block ();
8411 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
8415 finish_oacc_data (tree clauses
, tree block
)
8419 block
= finish_omp_structured_block (block
);
8421 stmt
= make_node (OACC_DATA
);
8422 TREE_TYPE (stmt
) = void_type_node
;
8423 OACC_DATA_CLAUSES (stmt
) = clauses
;
8424 OACC_DATA_BODY (stmt
) = block
;
8426 return add_stmt (stmt
);
8429 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
8433 finish_oacc_host_data (tree clauses
, tree block
)
8437 block
= finish_omp_structured_block (block
);
8439 stmt
= make_node (OACC_HOST_DATA
);
8440 TREE_TYPE (stmt
) = void_type_node
;
8441 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
8442 OACC_HOST_DATA_BODY (stmt
) = block
;
8444 return add_stmt (stmt
);
8447 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
8451 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
8453 body
= finish_omp_structured_block (body
);
8455 tree stmt
= make_node (code
);
8456 TREE_TYPE (stmt
) = void_type_node
;
8457 OMP_BODY (stmt
) = body
;
8458 OMP_CLAUSES (stmt
) = clauses
;
8460 return add_stmt (stmt
);
8464 finish_omp_parallel (tree clauses
, tree body
)
8468 body
= finish_omp_structured_block (body
);
8470 stmt
= make_node (OMP_PARALLEL
);
8471 TREE_TYPE (stmt
) = void_type_node
;
8472 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
8473 OMP_PARALLEL_BODY (stmt
) = body
;
8475 return add_stmt (stmt
);
8479 begin_omp_task (void)
8481 keep_next_level (true);
8482 return begin_omp_structured_block ();
8486 finish_omp_task (tree clauses
, tree body
)
8490 body
= finish_omp_structured_block (body
);
8492 stmt
= make_node (OMP_TASK
);
8493 TREE_TYPE (stmt
) = void_type_node
;
8494 OMP_TASK_CLAUSES (stmt
) = clauses
;
8495 OMP_TASK_BODY (stmt
) = body
;
8497 return add_stmt (stmt
);
8500 /* Helper function for finish_omp_for. Convert Ith random access iterator
8501 into integral iterator. Return FALSE if successful. */
8504 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
8505 tree declv
, tree orig_declv
, tree initv
,
8506 tree condv
, tree incrv
, tree
*body
,
8507 tree
*pre_body
, tree
&clauses
,
8508 int collapse
, int ordered
)
8510 tree diff
, iter_init
, iter_incr
= NULL
, last
;
8511 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
8512 tree decl
= TREE_VEC_ELT (declv
, i
);
8513 tree init
= TREE_VEC_ELT (initv
, i
);
8514 tree cond
= TREE_VEC_ELT (condv
, i
);
8515 tree incr
= TREE_VEC_ELT (incrv
, i
);
8517 location_t elocus
= locus
;
8519 if (init
&& EXPR_HAS_LOCATION (init
))
8520 elocus
= EXPR_LOCATION (init
);
8522 switch (TREE_CODE (cond
))
8529 if (TREE_OPERAND (cond
, 1) == iter
)
8530 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
8531 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
8532 if (TREE_OPERAND (cond
, 0) != iter
)
8533 cond
= error_mark_node
;
8536 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
8539 TREE_OPERAND (cond
, 1), ERROR_MARK
,
8540 NULL
, tf_warning_or_error
);
8541 if (error_operand_p (tem
))
8546 cond
= error_mark_node
;
8549 if (cond
== error_mark_node
)
8551 error_at (elocus
, "invalid controlling predicate");
8554 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
8555 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
8556 tf_warning_or_error
);
8557 diff
= cp_fully_fold (diff
);
8558 if (error_operand_p (diff
))
8560 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
8562 error_at (elocus
, "difference between %qE and %qD does not have integer type",
8563 TREE_OPERAND (cond
, 1), iter
);
8566 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
,
8567 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
8568 cond
, cp_walk_subtrees
))
8571 switch (TREE_CODE (incr
))
8573 case PREINCREMENT_EXPR
:
8574 case PREDECREMENT_EXPR
:
8575 case POSTINCREMENT_EXPR
:
8576 case POSTDECREMENT_EXPR
:
8577 if (TREE_OPERAND (incr
, 0) != iter
)
8579 incr
= error_mark_node
;
8582 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
8583 TREE_CODE (incr
), iter
,
8584 tf_warning_or_error
);
8585 if (error_operand_p (iter_incr
))
8587 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
8588 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
8589 incr
= integer_one_node
;
8591 incr
= integer_minus_one_node
;
8594 if (TREE_OPERAND (incr
, 0) != iter
)
8595 incr
= error_mark_node
;
8596 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
8597 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
8599 tree rhs
= TREE_OPERAND (incr
, 1);
8600 if (TREE_OPERAND (rhs
, 0) == iter
)
8602 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
8604 incr
= error_mark_node
;
8607 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8608 iter
, TREE_CODE (rhs
),
8609 TREE_OPERAND (rhs
, 1),
8610 tf_warning_or_error
);
8611 if (error_operand_p (iter_incr
))
8613 incr
= TREE_OPERAND (rhs
, 1);
8614 incr
= cp_convert (TREE_TYPE (diff
), incr
,
8615 tf_warning_or_error
);
8616 if (TREE_CODE (rhs
) == MINUS_EXPR
)
8618 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
8619 incr
= fold_simple (incr
);
8621 if (TREE_CODE (incr
) != INTEGER_CST
8622 && (TREE_CODE (incr
) != NOP_EXPR
8623 || (TREE_CODE (TREE_OPERAND (incr
, 0))
8628 else if (TREE_OPERAND (rhs
, 1) == iter
)
8630 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
8631 || TREE_CODE (rhs
) != PLUS_EXPR
)
8632 incr
= error_mark_node
;
8635 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
8637 TREE_OPERAND (rhs
, 0),
8640 tf_warning_or_error
);
8641 if (error_operand_p (iter_incr
))
8643 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8646 tf_warning_or_error
);
8647 if (error_operand_p (iter_incr
))
8649 incr
= TREE_OPERAND (rhs
, 0);
8654 incr
= error_mark_node
;
8657 incr
= error_mark_node
;
8660 incr
= error_mark_node
;
8664 if (incr
== error_mark_node
)
8666 error_at (elocus
, "invalid increment expression");
8670 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
8671 incr
= cp_fully_fold (incr
);
8672 tree loop_iv_seen
= NULL_TREE
;
8673 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8674 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
8675 && OMP_CLAUSE_DECL (c
) == iter
)
8677 if (code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
8680 OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
) = 1;
8684 else if ((code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
8685 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
8686 && OMP_CLAUSE_DECL (c
) == iter
)
8689 if (code
== OMP_TASKLOOP
)
8690 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
8693 decl
= create_temporary_var (TREE_TYPE (diff
));
8695 add_decl_expr (decl
);
8696 last
= create_temporary_var (TREE_TYPE (diff
));
8698 add_decl_expr (last
);
8699 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
8700 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
8702 incr_var
= create_temporary_var (TREE_TYPE (diff
));
8703 pushdecl (incr_var
);
8704 add_decl_expr (incr_var
);
8706 gcc_assert (stmts_are_full_exprs_p ());
8707 tree diffvar
= NULL_TREE
;
8708 if (code
== OMP_TASKLOOP
)
8712 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
8713 OMP_CLAUSE_DECL (ivc
) = iter
;
8714 cxx_omp_finish_clause (ivc
, NULL
);
8715 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
8718 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
8719 OMP_CLAUSE_DECL (lvc
) = last
;
8720 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
8722 diffvar
= create_temporary_var (TREE_TYPE (diff
));
8724 add_decl_expr (diffvar
);
8726 else if (code
== OMP_LOOP
)
8730 /* While iterators on the loop construct are predetermined
8731 lastprivate, if the decl is not declared inside of the
8732 loop, OMP_CLAUSE_LASTPRIVATE should have been added
8734 loop_iv_seen
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
8735 OMP_CLAUSE_DECL (loop_iv_seen
) = iter
;
8736 OMP_CLAUSE_CHAIN (loop_iv_seen
) = clauses
;
8737 clauses
= loop_iv_seen
;
8739 else if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_PRIVATE
)
8741 OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen
) = 0;
8742 OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen
) = 0;
8743 OMP_CLAUSE_CODE (loop_iv_seen
) = OMP_CLAUSE_FIRSTPRIVATE
;
8745 if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_FIRSTPRIVATE
)
8746 cxx_omp_finish_clause (loop_iv_seen
, NULL
);
8749 orig_pre_body
= *pre_body
;
8750 *pre_body
= push_stmt_list ();
8752 add_stmt (orig_pre_body
);
8754 finish_expr_stmt (build_x_modify_expr (elocus
,
8755 iter
, NOP_EXPR
, init
,
8756 tf_warning_or_error
));
8757 init
= build_int_cst (TREE_TYPE (diff
), 0);
8758 if (c
&& iter_incr
== NULL
8759 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
8763 finish_expr_stmt (build_x_modify_expr (elocus
,
8765 incr
, tf_warning_or_error
));
8768 iter_incr
= build_x_modify_expr (elocus
,
8769 iter
, PLUS_EXPR
, incr
,
8770 tf_warning_or_error
);
8772 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
8774 finish_expr_stmt (build_x_modify_expr (elocus
,
8775 last
, NOP_EXPR
, init
,
8776 tf_warning_or_error
));
8779 finish_expr_stmt (build_x_modify_expr (elocus
,
8781 diff
, tf_warning_or_error
));
8784 *pre_body
= pop_stmt_list (*pre_body
);
8786 cond
= cp_build_binary_op (elocus
,
8787 TREE_CODE (cond
), decl
, diff
,
8788 tf_warning_or_error
);
8789 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
8790 elocus
, incr
, NULL_TREE
);
8793 *body
= push_stmt_list ();
8794 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
8795 iter_init
= build_x_modify_expr (elocus
,
8796 iter
, PLUS_EXPR
, iter_init
,
8797 tf_warning_or_error
);
8798 if (iter_init
!= error_mark_node
)
8799 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
8800 finish_expr_stmt (iter_init
);
8801 finish_expr_stmt (build_x_modify_expr (elocus
,
8802 last
, NOP_EXPR
, decl
,
8803 tf_warning_or_error
));
8804 add_stmt (orig_body
);
8805 *body
= pop_stmt_list (*body
);
8809 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
8811 finish_expr_stmt (iter_incr
);
8815 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
8816 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
8817 iter_init
, iter_incr
);
8818 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
8819 iter_init
= build_x_modify_expr (elocus
,
8820 iter
, PLUS_EXPR
, iter_init
,
8821 tf_warning_or_error
);
8822 if (iter_init
!= error_mark_node
)
8823 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
8824 finish_expr_stmt (iter_init
);
8826 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
8827 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
8830 if (TREE_CODE (TREE_VEC_ELT (orig_declv
, i
)) == TREE_LIST
)
8832 tree t
= TREE_VEC_ELT (orig_declv
, i
);
8833 gcc_assert (TREE_PURPOSE (t
) == NULL_TREE
8834 && TREE_VALUE (t
) == NULL_TREE
8835 && TREE_CODE (TREE_CHAIN (t
)) == TREE_VEC
);
8836 TREE_PURPOSE (t
) = TREE_VEC_ELT (declv
, i
);
8837 TREE_VALUE (t
) = last
;
8840 TREE_VEC_ELT (orig_declv
, i
)
8841 = tree_cons (TREE_VEC_ELT (declv
, i
), last
, NULL_TREE
);
8842 TREE_VEC_ELT (declv
, i
) = decl
;
8843 TREE_VEC_ELT (initv
, i
) = init
;
8844 TREE_VEC_ELT (condv
, i
) = cond
;
8845 TREE_VEC_ELT (incrv
, i
) = incr
;
8850 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
8851 are directly for their associated operands in the statement. DECL
8852 and INIT are a combo; if DECL is NULL then INIT ought to be a
8853 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
8854 optional statements that need to go before the loop into its
8858 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
8859 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
8860 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
8862 tree omp_for
= NULL
, orig_incr
= NULL
;
8863 tree decl
= NULL
, init
, cond
, incr
;
8869 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
8870 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
8871 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
8872 if (TREE_VEC_LENGTH (declv
) > 1)
8876 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
8878 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
8881 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
8883 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
8884 if (collapse
!= TREE_VEC_LENGTH (declv
))
8885 ordered
= TREE_VEC_LENGTH (declv
);
8888 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8890 decl
= TREE_VEC_ELT (declv
, i
);
8891 init
= TREE_VEC_ELT (initv
, i
);
8892 cond
= TREE_VEC_ELT (condv
, i
);
8893 incr
= TREE_VEC_ELT (incrv
, i
);
8899 switch (TREE_CODE (init
))
8902 decl
= TREE_OPERAND (init
, 0);
8903 init
= TREE_OPERAND (init
, 1);
8906 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
8908 decl
= TREE_OPERAND (init
, 0);
8909 init
= TREE_OPERAND (init
, 2);
8919 "expected iteration declaration or initialization");
8924 if (init
&& EXPR_HAS_LOCATION (init
))
8925 elocus
= EXPR_LOCATION (init
);
8927 if (cond
== global_namespace
)
8932 error_at (elocus
, "missing controlling predicate");
8938 error_at (elocus
, "missing increment expression");
8942 TREE_VEC_ELT (declv
, i
) = decl
;
8943 TREE_VEC_ELT (initv
, i
) = init
;
8950 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
8952 && !c_omp_check_loop_iv_exprs (locus
, orig_declv
8953 ? orig_declv
: declv
,
8954 TREE_VEC_ELT (declv
, i
), orig_init
,
8955 NULL_TREE
, cp_walk_subtrees
))
8961 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
8965 stmt
= make_node (code
);
8967 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8969 /* This is really just a place-holder. We'll be decomposing this
8970 again and going through the cp_build_modify_expr path below when
8971 we instantiate the thing. */
8972 TREE_VEC_ELT (initv
, i
)
8973 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
8974 TREE_VEC_ELT (initv
, i
));
8977 TREE_TYPE (stmt
) = void_type_node
;
8978 OMP_FOR_INIT (stmt
) = initv
;
8979 OMP_FOR_COND (stmt
) = condv
;
8980 OMP_FOR_INCR (stmt
) = incrv
;
8981 OMP_FOR_BODY (stmt
) = body
;
8982 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
8983 OMP_FOR_CLAUSES (stmt
) = clauses
;
8985 SET_EXPR_LOCATION (stmt
, locus
);
8986 return add_stmt (stmt
);
8990 orig_declv
= copy_node (declv
);
8992 if (processing_template_decl
)
8993 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
8995 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
8997 decl
= TREE_VEC_ELT (declv
, i
);
8998 init
= TREE_VEC_ELT (initv
, i
);
8999 cond
= TREE_VEC_ELT (condv
, i
);
9000 incr
= TREE_VEC_ELT (incrv
, i
);
9002 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9005 if (init
&& EXPR_HAS_LOCATION (init
))
9006 elocus
= EXPR_LOCATION (init
);
9010 error_at (elocus
, "expected iteration declaration or initialization");
9014 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
9017 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9018 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
9019 TREE_CODE (TREE_OPERAND (incr
, 1)),
9020 TREE_OPERAND (incr
, 2),
9021 tf_warning_or_error
);
9024 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
9026 if (code
== OMP_SIMD
)
9028 error_at (elocus
, "%<#pragma omp simd%> used with class "
9029 "iteration variable %qE", decl
);
9032 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
9033 initv
, condv
, incrv
, &body
,
9040 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
9041 && !TYPE_PTR_P (TREE_TYPE (decl
)))
9043 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
9047 if (!processing_template_decl
)
9049 init
= fold_build_cleanup_point_expr (TREE_TYPE (init
), init
);
9050 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
9051 tf_warning_or_error
);
9054 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
9056 && TREE_SIDE_EFFECTS (cond
)
9057 && COMPARISON_CLASS_P (cond
)
9058 && !processing_template_decl
)
9060 tree t
= TREE_OPERAND (cond
, 0);
9061 if (TREE_SIDE_EFFECTS (t
)
9063 && (TREE_CODE (t
) != NOP_EXPR
9064 || TREE_OPERAND (t
, 0) != decl
))
9065 TREE_OPERAND (cond
, 0)
9066 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9068 t
= TREE_OPERAND (cond
, 1);
9069 if (TREE_SIDE_EFFECTS (t
)
9071 && (TREE_CODE (t
) != NOP_EXPR
9072 || TREE_OPERAND (t
, 0) != decl
))
9073 TREE_OPERAND (cond
, 1)
9074 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9076 if (decl
== error_mark_node
|| init
== error_mark_node
)
9079 TREE_VEC_ELT (declv
, i
) = decl
;
9080 TREE_VEC_ELT (initv
, i
) = init
;
9081 TREE_VEC_ELT (condv
, i
) = cond
;
9082 TREE_VEC_ELT (incrv
, i
) = incr
;
9086 if (pre_body
&& IS_EMPTY_STMT (pre_body
))
9089 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
9090 incrv
, body
, pre_body
,
9091 !processing_template_decl
);
9093 /* Check for iterators appearing in lb, b or incr expressions. */
9094 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
9095 omp_for
= NULL_TREE
;
9097 if (omp_for
== NULL
)
9102 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
9104 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
), 0);
9105 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
9107 if (TREE_CODE (incr
) != MODIFY_EXPR
)
9110 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
9111 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
9112 && !processing_template_decl
)
9114 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
9115 if (TREE_SIDE_EFFECTS (t
)
9117 && (TREE_CODE (t
) != NOP_EXPR
9118 || TREE_OPERAND (t
, 0) != decl
))
9119 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
9120 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9122 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
9123 if (TREE_SIDE_EFFECTS (t
)
9125 && (TREE_CODE (t
) != NOP_EXPR
9126 || TREE_OPERAND (t
, 0) != decl
))
9127 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
9128 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9132 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
9134 OMP_FOR_CLAUSES (omp_for
) = clauses
;
9136 /* For simd loops with non-static data member iterators, we could have added
9137 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
9138 step at this point, fill it in. */
9139 if (code
== OMP_SIMD
&& !processing_template_decl
9140 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
9141 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
9142 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
9143 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
9145 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
9146 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
9147 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
9149 switch (TREE_CODE (incr
))
9151 case PREINCREMENT_EXPR
:
9152 case POSTINCREMENT_EXPR
:
9153 /* c_omp_for_incr_canonicalize_ptr() should have been
9154 called to massage things appropriately. */
9155 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9156 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
9158 case PREDECREMENT_EXPR
:
9159 case POSTDECREMENT_EXPR
:
9160 /* c_omp_for_incr_canonicalize_ptr() should have been
9161 called to massage things appropriately. */
9162 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9163 OMP_CLAUSE_LINEAR_STEP (c
)
9164 = build_int_cst (TREE_TYPE (decl
), -1);
9167 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9168 incr
= TREE_OPERAND (incr
, 1);
9169 switch (TREE_CODE (incr
))
9172 if (TREE_OPERAND (incr
, 1) == decl
)
9173 step
= TREE_OPERAND (incr
, 0);
9175 step
= TREE_OPERAND (incr
, 1);
9178 case POINTER_PLUS_EXPR
:
9179 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9180 step
= TREE_OPERAND (incr
, 1);
9185 stept
= TREE_TYPE (decl
);
9186 if (INDIRECT_TYPE_P (stept
))
9188 step
= fold_convert (stept
, step
);
9189 if (TREE_CODE (incr
) == MINUS_EXPR
)
9190 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
9191 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
9197 /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
9198 clauses, we need copy ctor for those rather than default ctor,
9199 plus as for other lastprivates assignment op and dtor. */
9200 if (code
== OMP_LOOP
&& !processing_template_decl
)
9201 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9202 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9203 && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
)
9204 && cxx_omp_create_clause_info (c
, TREE_TYPE (OMP_CLAUSE_DECL (c
)),
9205 false, true, true, true))
9206 CP_OMP_CLAUSE_INFO (c
) = NULL_TREE
;
9211 /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS
9212 and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */
9215 finish_omp_for_block (tree bind
, tree omp_for
)
9217 if (omp_for
== NULL_TREE
9218 || !OMP_FOR_ORIG_DECLS (omp_for
)
9219 || bind
== NULL_TREE
9220 || TREE_CODE (bind
) != BIND_EXPR
)
9223 for (int i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for
)); i
++)
9224 if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)) == TREE_LIST
9225 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)))
9227 tree v
= TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
));
9228 gcc_assert (BIND_EXPR_BLOCK (bind
)
9229 && (BIND_EXPR_VARS (bind
)
9230 == BLOCK_VARS (BIND_EXPR_BLOCK (bind
))));
9231 for (int j
= 2; j
< TREE_VEC_LENGTH (v
); j
++)
9232 for (tree
*p
= &BIND_EXPR_VARS (bind
); *p
; p
= &DECL_CHAIN (*p
))
9234 if (*p
== TREE_VEC_ELT (v
, j
))
9237 *p
= DECL_CHAIN (*p
);
9240 b
= make_node (BLOCK
);
9241 b
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
9242 OMP_FOR_BODY (omp_for
), b
);
9243 TREE_SIDE_EFFECTS (b
) = 1;
9244 OMP_FOR_BODY (omp_for
) = b
;
9246 DECL_CHAIN (var
) = BIND_EXPR_VARS (b
);
9247 BIND_EXPR_VARS (b
) = var
;
9248 BLOCK_VARS (BIND_EXPR_BLOCK (b
)) = var
;
9251 BLOCK_VARS (BIND_EXPR_BLOCK (bind
)) = BIND_EXPR_VARS (bind
);
9257 finish_omp_atomic (location_t loc
, enum tree_code code
, enum tree_code opcode
,
9258 tree lhs
, tree rhs
, tree v
, tree lhs1
, tree rhs1
,
9259 tree clauses
, enum omp_memory_order mo
)
9274 dependent_p
= false;
9277 /* Even in a template, we can detect invalid uses of the atomic
9278 pragma if neither LHS nor RHS is type-dependent. */
9279 if (processing_template_decl
)
9281 dependent_p
= (type_dependent_expression_p (lhs
)
9282 || (rhs
&& type_dependent_expression_p (rhs
))
9283 || (v
&& type_dependent_expression_p (v
))
9284 || (lhs1
&& type_dependent_expression_p (lhs1
))
9285 || (rhs1
&& type_dependent_expression_p (rhs1
)));
9288 gcc_assert (TREE_CODE (clauses
) == OMP_CLAUSE
9289 && OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_HINT
9290 && OMP_CLAUSE_CHAIN (clauses
) == NULL_TREE
);
9291 if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses
))
9292 || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses
)) != INTEGER_CST
)
9297 lhs
= build_non_dependent_expr (lhs
);
9299 rhs
= build_non_dependent_expr (rhs
);
9301 v
= build_non_dependent_expr (v
);
9303 lhs1
= build_non_dependent_expr (lhs1
);
9305 rhs1
= build_non_dependent_expr (rhs1
);
9310 bool swapped
= false;
9311 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
9313 std::swap (rhs
, rhs1
);
9314 swapped
= !commutative_tree_code (opcode
);
9316 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
9318 if (code
== OMP_ATOMIC
)
9319 error ("%<#pragma omp atomic update%> uses two different "
9320 "expressions for memory");
9322 error ("%<#pragma omp atomic capture%> uses two different "
9323 "expressions for memory");
9326 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
9328 if (code
== OMP_ATOMIC
)
9329 error ("%<#pragma omp atomic update%> uses two different "
9330 "expressions for memory");
9332 error ("%<#pragma omp atomic capture%> uses two different "
9333 "expressions for memory");
9336 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
,
9337 v
, lhs1
, rhs1
, swapped
, mo
,
9338 processing_template_decl
!= 0);
9339 if (stmt
== error_mark_node
)
9342 if (processing_template_decl
)
9344 if (code
== OMP_ATOMIC_READ
)
9346 stmt
= build_min_nt_loc (loc
, OMP_ATOMIC_READ
, orig_lhs
);
9347 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9348 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9352 if (opcode
== NOP_EXPR
)
9353 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
9355 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
9357 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
9358 COMPOUND_EXPR
, orig_rhs1
, stmt
);
9359 if (code
!= OMP_ATOMIC
)
9361 stmt
= build_min_nt_loc (loc
, code
, orig_lhs1
, stmt
);
9362 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9363 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9366 stmt
= build2 (OMP_ATOMIC
, void_type_node
,
9367 clauses
? clauses
: integer_zero_node
, stmt
);
9368 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9369 SET_EXPR_LOCATION (stmt
, loc
);
9372 /* Avoid -Wunused-value warnings here, the whole construct has side-effects
9373 and even if it might be wrapped from fold-const.c or c-omp.c wrapped
9374 in some tree that appears to be unused, the value is not unused. */
9375 warning_sentinel
w (warn_unused_value
);
9376 finish_expr_stmt (stmt
);
9380 finish_omp_barrier (void)
9382 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
9384 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9385 finish_expr_stmt (stmt
);
9389 finish_omp_depobj (location_t loc
, tree depobj
,
9390 enum omp_clause_depend_kind kind
, tree clause
)
9392 if (!error_operand_p (depobj
) && !type_dependent_expression_p (depobj
))
9394 if (!lvalue_p (depobj
))
9396 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
9397 "%<depobj%> expression is not lvalue expression");
9398 depobj
= error_mark_node
;
9402 if (processing_template_decl
)
9404 if (clause
== NULL_TREE
)
9405 clause
= build_int_cst (integer_type_node
, kind
);
9406 add_stmt (build_min_nt_loc (loc
, OMP_DEPOBJ
, depobj
, clause
));
9410 if (!error_operand_p (depobj
))
9412 tree addr
= cp_build_addr_expr (depobj
, tf_warning_or_error
);
9413 if (addr
== error_mark_node
)
9414 depobj
= error_mark_node
;
9416 depobj
= cp_build_indirect_ref (loc
, addr
, RO_UNARY_STAR
,
9417 tf_warning_or_error
);
9420 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
9424 finish_omp_flush (int mo
)
9426 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
9428 if (mo
!= MEMMODEL_LAST
)
9430 fn
= builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE
);
9431 vec
->quick_push (build_int_cst (integer_type_node
, mo
));
9433 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9434 finish_expr_stmt (stmt
);
9438 finish_omp_taskwait (void)
9440 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
9442 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9443 finish_expr_stmt (stmt
);
9447 finish_omp_taskyield (void)
9449 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
9451 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9452 finish_expr_stmt (stmt
);
9456 finish_omp_cancel (tree clauses
)
9458 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
9460 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9462 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9464 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9466 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9470 error ("%<#pragma omp cancel%> must specify one of "
9471 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9475 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
9476 if (ifc
!= NULL_TREE
)
9478 if (OMP_CLAUSE_IF_MODIFIER (ifc
) != ERROR_MARK
9479 && OMP_CLAUSE_IF_MODIFIER (ifc
) != VOID_CST
)
9480 error_at (OMP_CLAUSE_LOCATION (ifc
),
9481 "expected %<cancel%> %<if%> clause modifier");
9484 tree ifc2
= omp_find_clause (OMP_CLAUSE_CHAIN (ifc
), OMP_CLAUSE_IF
);
9485 if (ifc2
!= NULL_TREE
)
9487 gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc
) == VOID_CST
9488 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != ERROR_MARK
9489 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != VOID_CST
);
9490 error_at (OMP_CLAUSE_LOCATION (ifc2
),
9491 "expected %<cancel%> %<if%> clause modifier");
9495 if (!processing_template_decl
)
9496 ifc
= maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc
));
9498 ifc
= build_x_binary_op (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
9499 OMP_CLAUSE_IF_EXPR (ifc
), ERROR_MARK
,
9500 integer_zero_node
, ERROR_MARK
,
9501 NULL
, tf_warning_or_error
);
9504 ifc
= boolean_true_node
;
9505 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
9506 vec
->quick_push (ifc
);
9507 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9508 finish_expr_stmt (stmt
);
9512 finish_omp_cancellation_point (tree clauses
)
9514 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
9516 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9518 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9520 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9522 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9526 error ("%<#pragma omp cancellation point%> must specify one of "
9527 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9531 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
9532 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9533 finish_expr_stmt (stmt
);
9536 /* Begin a __transaction_atomic or __transaction_relaxed statement.
9537 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
9538 should create an extra compound stmt. */
9541 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
9546 *pcompound
= begin_compound_stmt (0);
9548 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
9550 /* Only add the statement to the function if support enabled. */
9554 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
9555 ? G_("%<__transaction_relaxed%> without "
9556 "transactional memory support enabled")
9557 : G_("%<__transaction_atomic%> without "
9558 "transactional memory support enabled")));
9560 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
9561 TREE_SIDE_EFFECTS (r
) = 1;
9565 /* End a __transaction_atomic or __transaction_relaxed statement.
9566 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
9567 and we should end the compound. If NOEX is non-NULL, we wrap the body in
9568 a MUST_NOT_THROW_EXPR with NOEX as condition. */
9571 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
9573 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
9574 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
9575 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
9576 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
9578 /* noexcept specifications are not allowed for function transactions. */
9579 gcc_assert (!(noex
&& compound_stmt
));
9582 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
9584 protected_set_expr_location
9585 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
9586 TREE_SIDE_EFFECTS (body
) = 1;
9587 TRANSACTION_EXPR_BODY (stmt
) = body
;
9591 finish_compound_stmt (compound_stmt
);
9594 /* Build a __transaction_atomic or __transaction_relaxed expression. If
9595 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
9599 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
9604 expr
= build_must_not_throw_expr (expr
, noex
);
9605 protected_set_expr_location (expr
, loc
);
9606 TREE_SIDE_EFFECTS (expr
) = 1;
9608 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
9609 if (flags
& TM_STMT_ATTR_RELAXED
)
9610 TRANSACTION_EXPR_RELAXED (ret
) = 1;
9611 TREE_SIDE_EFFECTS (ret
) = 1;
9612 SET_EXPR_LOCATION (ret
, loc
);
9617 init_cp_semantics (void)
9621 /* Build a STATIC_ASSERT for a static assertion with the condition
9622 CONDITION and the message text MESSAGE. LOCATION is the location
9623 of the static assertion in the source code. When MEMBER_P, this
9624 static assertion is a member of a class. */
9626 finish_static_assert (tree condition
, tree message
, location_t location
,
9629 tsubst_flags_t complain
= tf_warning_or_error
;
9631 if (message
== NULL_TREE
9632 || message
== error_mark_node
9633 || condition
== NULL_TREE
9634 || condition
== error_mark_node
)
9637 if (check_for_bare_parameter_packs (condition
))
9638 condition
= error_mark_node
;
9640 if (instantiation_dependent_expression_p (condition
))
9642 /* We're in a template; build a STATIC_ASSERT and put it in
9646 assertion
= make_node (STATIC_ASSERT
);
9647 STATIC_ASSERT_CONDITION (assertion
) = condition
;
9648 STATIC_ASSERT_MESSAGE (assertion
) = message
;
9649 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
9652 maybe_add_class_template_decl_list (current_class_type
,
9656 add_stmt (assertion
);
9661 /* Save the condition in case it was a concept check. */
9662 tree orig_condition
= condition
;
9664 /* Fold the expression and convert it to a boolean value. */
9665 condition
= perform_implicit_conversion_flags (boolean_type_node
, condition
,
9666 complain
, LOOKUP_NORMAL
);
9667 condition
= fold_non_dependent_expr (condition
, complain
,
9668 /*manifestly_const_eval=*/true);
9670 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
9671 /* Do nothing; the condition is satisfied. */
9675 location_t saved_loc
= input_location
;
9677 input_location
= location
;
9678 if (TREE_CODE (condition
) == INTEGER_CST
9679 && integer_zerop (condition
))
9681 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
9682 (TREE_TYPE (TREE_TYPE (message
))));
9683 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
9684 /* Report the error. */
9686 error ("static assertion failed");
9688 error ("static assertion failed: %s",
9689 TREE_STRING_POINTER (message
));
9691 /* Actually explain the failure if this is a concept check or a
9692 requires-expression. */
9693 if (concept_check_p (orig_condition
)
9694 || TREE_CODE (orig_condition
) == REQUIRES_EXPR
)
9695 diagnose_constraints (location
, orig_condition
, NULL_TREE
);
9697 else if (condition
&& condition
!= error_mark_node
)
9699 error ("non-constant condition for static assertion");
9700 if (require_rvalue_constant_expression (condition
))
9701 cxx_constant_value (condition
);
9703 input_location
= saved_loc
;
9707 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
9708 suitable for use as a type-specifier.
9710 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
9711 id-expression or a class member access, FALSE when it was parsed as
9712 a full expression. */
9715 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
9716 tsubst_flags_t complain
)
9718 tree type
= NULL_TREE
;
9720 if (!expr
|| error_operand_p (expr
))
9721 return error_mark_node
;
9724 || TREE_CODE (expr
) == TYPE_DECL
9725 || (TREE_CODE (expr
) == BIT_NOT_EXPR
9726 && TYPE_P (TREE_OPERAND (expr
, 0))))
9728 if (complain
& tf_error
)
9729 error ("argument to %<decltype%> must be an expression");
9730 return error_mark_node
;
9733 /* Depending on the resolution of DR 1172, we may later need to distinguish
9734 instantiation-dependent but not type-dependent expressions so that, say,
9735 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
9736 if (instantiation_dependent_uneval_expression_p (expr
))
9738 type
= cxx_make_type (DECLTYPE_TYPE
);
9739 DECLTYPE_TYPE_EXPR (type
) = expr
;
9740 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
9741 = id_expression_or_member_access_p
;
9742 SET_TYPE_STRUCTURAL_EQUALITY (type
);
9747 /* The type denoted by decltype(e) is defined as follows: */
9749 expr
= resolve_nondeduced_context (expr
, complain
);
9751 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
9752 return error_mark_node
;
9754 if (type_unknown_p (expr
))
9756 if (complain
& tf_error
)
9757 error ("%<decltype%> cannot resolve address of overloaded function");
9758 return error_mark_node
;
9761 /* To get the size of a static data member declared as an array of
9762 unknown bound, we need to instantiate it. */
9764 && VAR_HAD_UNKNOWN_BOUND (expr
)
9765 && DECL_TEMPLATE_INSTANTIATION (expr
))
9766 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
9768 if (id_expression_or_member_access_p
)
9770 /* If e is an id-expression or a class member access (5.2.5
9771 [expr.ref]), decltype(e) is defined as the type of the entity
9772 named by e. If there is no such entity, or e names a set of
9773 overloaded functions, the program is ill-formed. */
9774 if (identifier_p (expr
))
9775 expr
= lookup_name (expr
);
9777 if (INDIRECT_REF_P (expr
)
9778 || TREE_CODE (expr
) == VIEW_CONVERT_EXPR
)
9779 /* This can happen when the expression is, e.g., "a.b". Just
9780 look at the underlying operand. */
9781 expr
= TREE_OPERAND (expr
, 0);
9783 if (TREE_CODE (expr
) == OFFSET_REF
9784 || TREE_CODE (expr
) == MEMBER_REF
9785 || TREE_CODE (expr
) == SCOPE_REF
)
9786 /* We're only interested in the field itself. If it is a
9787 BASELINK, we will need to see through it in the next
9789 expr
= TREE_OPERAND (expr
, 1);
9791 if (BASELINK_P (expr
))
9792 /* See through BASELINK nodes to the underlying function. */
9793 expr
= BASELINK_FUNCTIONS (expr
);
9795 /* decltype of a decomposition name drops references in the tuple case
9796 (unlike decltype of a normal variable) and keeps cv-qualifiers from
9797 the containing object in the other cases (unlike decltype of a member
9798 access expression). */
9799 if (DECL_DECOMPOSITION_P (expr
))
9801 if (DECL_HAS_VALUE_EXPR_P (expr
))
9802 /* Expr is an array or struct subobject proxy, handle
9803 bit-fields properly. */
9804 return unlowered_expr_type (expr
);
9806 /* Expr is a reference variable for the tuple case. */
9807 return lookup_decomp_type (expr
);
9810 switch (TREE_CODE (expr
))
9813 if (DECL_BIT_FIELD_TYPE (expr
))
9815 type
= DECL_BIT_FIELD_TYPE (expr
);
9818 /* Fall through for fields that aren't bitfields. */
9826 case TEMPLATE_PARM_INDEX
:
9827 expr
= mark_type_use (expr
);
9828 type
= TREE_TYPE (expr
);
9832 type
= error_mark_node
;
9837 mark_type_use (expr
);
9838 type
= is_bitfield_expr_with_lowered_type (expr
);
9840 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
9848 /* We can get here when the id-expression refers to an
9849 enumerator or non-type template parameter. */
9850 type
= TREE_TYPE (expr
);
9854 /* Handle instantiated template non-type arguments. */
9855 type
= TREE_TYPE (expr
);
9861 /* Within a lambda-expression:
9863 Every occurrence of decltype((x)) where x is a possibly
9864 parenthesized id-expression that names an entity of
9865 automatic storage duration is treated as if x were
9866 transformed into an access to a corresponding data member
9867 of the closure type that would have been declared if x
9868 were a use of the denoted entity. */
9869 if (outer_automatic_var_p (expr
)
9870 && current_function_decl
9871 && LAMBDA_FUNCTION_P (current_function_decl
))
9872 type
= capture_decltype (expr
);
9873 else if (error_operand_p (expr
))
9874 type
= error_mark_node
;
9875 else if (expr
== current_class_ptr
)
9876 /* If the expression is just "this", we want the
9877 cv-unqualified pointer for the "this" type. */
9878 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
9881 /* Otherwise, where T is the type of e, if e is an lvalue,
9882 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
9883 cp_lvalue_kind clk
= lvalue_kind (expr
);
9884 type
= unlowered_expr_type (expr
);
9885 gcc_assert (!TYPE_REF_P (type
));
9887 /* For vector types, pick a non-opaque variant. */
9888 if (VECTOR_TYPE_P (type
))
9889 type
= strip_typedefs (type
);
9891 if (clk
!= clk_none
&& !(clk
& clk_class
))
9892 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
9899 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
9900 __has_nothrow_copy, depending on assign_p. Returns true iff all
9901 the copy {ctor,assign} fns are nothrow. */
9904 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
9906 tree fns
= NULL_TREE
;
9908 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
9909 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
9912 bool saw_copy
= false;
9913 for (ovl_iterator
iter (fns
); iter
; ++iter
)
9917 if (copy_fn_p (fn
) > 0)
9920 if (!maybe_instantiate_noexcept (fn
)
9921 || !TYPE_NOTHROW_P (TREE_TYPE (fn
)))
9929 /* Actually evaluates the trait. */
9932 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
9934 enum tree_code type_code1
;
9937 type_code1
= TREE_CODE (type1
);
9941 case CPTK_HAS_NOTHROW_ASSIGN
:
9942 type1
= strip_array_types (type1
);
9943 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
9944 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
9945 || (CLASS_TYPE_P (type1
)
9946 && classtype_has_nothrow_assign_or_copy_p (type1
,
9949 case CPTK_HAS_TRIVIAL_ASSIGN
:
9950 /* ??? The standard seems to be missing the "or array of such a class
9951 type" wording for this trait. */
9952 type1
= strip_array_types (type1
);
9953 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
9954 && (trivial_type_p (type1
)
9955 || (CLASS_TYPE_P (type1
)
9956 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
9958 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9959 type1
= strip_array_types (type1
);
9960 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
9961 || (CLASS_TYPE_P (type1
)
9962 && (t
= locate_ctor (type1
))
9963 && maybe_instantiate_noexcept (t
)
9964 && TYPE_NOTHROW_P (TREE_TYPE (t
))));
9966 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9967 type1
= strip_array_types (type1
);
9968 return (trivial_type_p (type1
)
9969 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
9971 case CPTK_HAS_NOTHROW_COPY
:
9972 type1
= strip_array_types (type1
);
9973 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
9974 || (CLASS_TYPE_P (type1
)
9975 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
9977 case CPTK_HAS_TRIVIAL_COPY
:
9978 /* ??? The standard seems to be missing the "or array of such a class
9979 type" wording for this trait. */
9980 type1
= strip_array_types (type1
);
9981 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9982 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
9984 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9985 type1
= strip_array_types (type1
);
9986 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9987 || (CLASS_TYPE_P (type1
)
9988 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
9990 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9991 return type_has_virtual_destructor (type1
);
9993 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
9994 return type_has_unique_obj_representations (type1
);
9996 case CPTK_IS_ABSTRACT
:
9997 return ABSTRACT_CLASS_TYPE_P (type1
);
9999 case CPTK_IS_AGGREGATE
:
10000 return CP_AGGREGATE_TYPE_P (type1
);
10002 case CPTK_IS_BASE_OF
:
10003 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
10004 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
10005 || DERIVED_FROM_P (type1
, type2
)));
10007 case CPTK_IS_CLASS
:
10008 return NON_UNION_CLASS_TYPE_P (type1
);
10010 case CPTK_IS_EMPTY
:
10011 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
10014 return type_code1
== ENUMERAL_TYPE
;
10016 case CPTK_IS_FINAL
:
10017 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
10019 case CPTK_IS_LITERAL_TYPE
:
10020 return literal_type_p (type1
);
10023 return pod_type_p (type1
);
10025 case CPTK_IS_POLYMORPHIC
:
10026 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
10028 case CPTK_IS_SAME_AS
:
10029 return same_type_p (type1
, type2
);
10031 case CPTK_IS_STD_LAYOUT
:
10032 return std_layout_type_p (type1
);
10034 case CPTK_IS_TRIVIAL
:
10035 return trivial_type_p (type1
);
10037 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
10038 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
10040 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
10041 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
10043 case CPTK_IS_TRIVIALLY_COPYABLE
:
10044 return trivially_copyable_p (type1
);
10046 case CPTK_IS_UNION
:
10047 return type_code1
== UNION_TYPE
;
10049 case CPTK_IS_ASSIGNABLE
:
10050 return is_xible (MODIFY_EXPR
, type1
, type2
);
10052 case CPTK_IS_CONSTRUCTIBLE
:
10053 return is_xible (INIT_EXPR
, type1
, type2
);
10056 gcc_unreachable ();
10061 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
10062 void, or a complete type, returns true, otherwise false. */
10065 check_trait_type (tree type
)
10067 if (type
== NULL_TREE
)
10070 if (TREE_CODE (type
) == TREE_LIST
)
10071 return (check_trait_type (TREE_VALUE (type
))
10072 && check_trait_type (TREE_CHAIN (type
)));
10074 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
10075 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
10078 if (VOID_TYPE_P (type
))
10081 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
10084 /* Process a trait expression. */
10087 finish_trait_expr (location_t loc
, cp_trait_kind kind
, tree type1
, tree type2
)
10089 if (type1
== error_mark_node
10090 || type2
== error_mark_node
)
10091 return error_mark_node
;
10093 if (processing_template_decl
)
10095 tree trait_expr
= make_node (TRAIT_EXPR
);
10096 TREE_TYPE (trait_expr
) = boolean_type_node
;
10097 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
10098 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
10099 TRAIT_EXPR_KIND (trait_expr
) = kind
;
10100 TRAIT_EXPR_LOCATION (trait_expr
) = loc
;
10106 case CPTK_HAS_NOTHROW_ASSIGN
:
10107 case CPTK_HAS_TRIVIAL_ASSIGN
:
10108 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
10109 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
10110 case CPTK_HAS_NOTHROW_COPY
:
10111 case CPTK_HAS_TRIVIAL_COPY
:
10112 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
10113 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
10114 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
10115 case CPTK_IS_ABSTRACT
:
10116 case CPTK_IS_AGGREGATE
:
10117 case CPTK_IS_EMPTY
:
10118 case CPTK_IS_FINAL
:
10119 case CPTK_IS_LITERAL_TYPE
:
10121 case CPTK_IS_POLYMORPHIC
:
10122 case CPTK_IS_STD_LAYOUT
:
10123 case CPTK_IS_TRIVIAL
:
10124 case CPTK_IS_TRIVIALLY_COPYABLE
:
10125 if (!check_trait_type (type1
))
10126 return error_mark_node
;
10129 case CPTK_IS_ASSIGNABLE
:
10130 case CPTK_IS_CONSTRUCTIBLE
:
10133 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
10134 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
10135 if (!check_trait_type (type1
)
10136 || !check_trait_type (type2
))
10137 return error_mark_node
;
10140 case CPTK_IS_BASE_OF
:
10141 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
10142 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
10143 && !complete_type_or_else (type2
, NULL_TREE
))
10144 /* We already issued an error. */
10145 return error_mark_node
;
10148 case CPTK_IS_CLASS
:
10150 case CPTK_IS_UNION
:
10151 case CPTK_IS_SAME_AS
:
10155 gcc_unreachable ();
10158 tree val
= (trait_expr_value (kind
, type1
, type2
)
10159 ? boolean_true_node
: boolean_false_node
);
10160 return maybe_wrap_with_location (val
, loc
);
10163 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
10164 which is ignored for C++. */
10167 set_float_const_decimal64 (void)
10172 clear_float_const_decimal64 (void)
10177 float_const_decimal64_p (void)
10183 /* Return true if T designates the implied `this' parameter. */
10186 is_this_parameter (tree t
)
10188 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
10190 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
)
10191 || (cp_binding_oracle
&& TREE_CODE (t
) == VAR_DECL
));
10195 /* Insert the deduced return type for an auto function. */
10198 apply_deduced_return_type (tree fco
, tree return_type
)
10202 if (return_type
== error_mark_node
)
10205 if (DECL_CONV_FN_P (fco
))
10206 DECL_NAME (fco
) = make_conv_op_name (return_type
);
10208 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
10210 result
= DECL_RESULT (fco
);
10211 if (result
== NULL_TREE
)
10213 if (TREE_TYPE (result
) == return_type
)
10216 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
10217 && !complete_type_or_else (return_type
, NULL_TREE
))
10220 /* We already have a DECL_RESULT from start_preparsed_function.
10221 Now we need to redo the work it and allocate_struct_function
10222 did to reflect the new type. */
10223 gcc_assert (current_function_decl
== fco
);
10224 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
10225 TYPE_MAIN_VARIANT (return_type
));
10226 DECL_ARTIFICIAL (result
) = 1;
10227 DECL_IGNORED_P (result
) = 1;
10228 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
10231 DECL_RESULT (fco
) = result
;
10233 if (!processing_template_decl
)
10235 bool aggr
= aggregate_value_p (result
, fco
);
10236 #ifdef PCC_STATIC_STRUCT_RETURN
10237 cfun
->returns_pcc_struct
= aggr
;
10239 cfun
->returns_struct
= aggr
;
10243 /* DECL is a local variable or parameter from the surrounding scope of a
10244 lambda-expression. Returns the decltype for a use of the capture field
10245 for DECL even if it hasn't been captured yet. */
10248 capture_decltype (tree decl
)
10250 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
10251 tree cap
= lookup_name_real (DECL_NAME (decl
), /*type*/0, /*nonclass*/1,
10252 /*block_p=*/true, /*ns*/0, LOOKUP_HIDDEN
);
10255 if (cap
&& is_capture_proxy (cap
))
10256 type
= TREE_TYPE (cap
);
10258 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
10261 error ("%qD is not captured", decl
);
10262 return error_mark_node
;
10265 type
= TREE_TYPE (decl
);
10266 if (TYPE_REF_P (type
)
10267 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
10268 type
= TREE_TYPE (type
);
10271 case CPLD_REFERENCE
:
10272 type
= TREE_TYPE (decl
);
10273 if (!TYPE_REF_P (type
))
10274 type
= build_reference_type (TREE_TYPE (decl
));
10278 gcc_unreachable ();
10281 if (!TYPE_REF_P (type
))
10283 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
10284 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
10285 |TYPE_QUAL_CONST
));
10286 type
= build_reference_type (type
);
10291 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
10292 this is a right unary fold. Otherwise it is a left unary fold. */
10295 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
10297 /* Build a pack expansion (assuming expr has pack type). */
10298 if (!uses_parameter_packs (expr
))
10300 error_at (location_of (expr
), "operand of fold expression has no "
10301 "unexpanded parameter packs");
10302 return error_mark_node
;
10304 tree pack
= make_pack_expansion (expr
);
10306 /* Build the fold expression. */
10307 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10308 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
);
10309 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10314 finish_left_unary_fold_expr (tree expr
, int op
)
10316 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
10320 finish_right_unary_fold_expr (tree expr
, int op
)
10322 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
10325 /* Build a binary fold expression over EXPR1 and EXPR2. The
10326 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
10327 has an unexpanded parameter pack). */
10330 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
10332 pack
= make_pack_expansion (pack
);
10333 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10334 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
, init
);
10335 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10340 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
10342 // Determine which expr has an unexpanded parameter pack and
10343 // set the pack and initial term.
10344 bool pack1
= uses_parameter_packs (expr1
);
10345 bool pack2
= uses_parameter_packs (expr2
);
10346 if (pack1
&& !pack2
)
10347 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
10348 else if (pack2
&& !pack1
)
10349 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
10353 error ("both arguments in binary fold have unexpanded parameter packs");
10355 error ("no unexpanded parameter packs in binary fold");
10357 return error_mark_node
;
10360 /* Finish __builtin_launder (arg). */
10363 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
10365 tree orig_arg
= arg
;
10366 if (!type_dependent_expression_p (arg
))
10367 arg
= decay_conversion (arg
, complain
);
10368 if (error_operand_p (arg
))
10369 return error_mark_node
;
10370 if (!type_dependent_expression_p (arg
)
10371 && !TYPE_PTR_P (TREE_TYPE (arg
)))
10373 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
10374 return error_mark_node
;
10376 if (processing_template_decl
)
10378 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
10379 TREE_TYPE (arg
), 1, arg
);
10382 /* Finish __builtin_convertvector (arg, type). */
10385 cp_build_vec_convert (tree arg
, location_t loc
, tree type
,
10386 tsubst_flags_t complain
)
10388 if (error_operand_p (type
))
10389 return error_mark_node
;
10390 if (error_operand_p (arg
))
10391 return error_mark_node
;
10393 tree ret
= NULL_TREE
;
10394 if (!type_dependent_expression_p (arg
) && !dependent_type_p (type
))
10395 ret
= c_build_vec_convert (cp_expr_loc_or_input_loc (arg
),
10396 decay_conversion (arg
, complain
),
10397 loc
, type
, (complain
& tf_error
) != 0);
10399 if (!processing_template_decl
)
10402 return build_call_expr_internal_loc (loc
, IFN_VEC_CONVERT
, type
, 1, arg
);
10405 #include "gt-cp-semantics.h"