1 /* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
6 Copyright (C) 1998-2021 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GCC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GCC; see the file COPYING3. If not see
24 <http://www.gnu.org/licenses/>. */
28 #include "coretypes.h"
32 #include "stringpool.h"
36 #include "stor-layout.h"
37 #include "c-family/c-objc.h"
38 #include "tree-inline.h"
40 #include "tree-iterator.h"
41 #include "omp-general.h"
43 #include "stringpool.h"
45 #include "gomp-constants.h"
49 /* There routines provide a modular interface to perform many parsing
50 operations. They may therefore be used during actual parsing, or
51 during template instantiation, which may be regarded as a
52 degenerate form of parsing. */
54 static tree
maybe_convert_cond (tree
);
55 static tree
finalize_nrv_r (tree
*, int *, void *);
56 static tree
capture_decltype (tree
);
58 /* Used for OpenMP non-static data member privatization. */
60 static hash_map
<tree
, tree
> *omp_private_member_map
;
61 static vec
<tree
> omp_private_member_vec
;
62 static bool omp_private_member_ignore_next
;
65 /* Deferred Access Checking Overview
66 ---------------------------------
68 Most C++ expressions and declarations require access checking
69 to be performed during parsing. However, in several cases,
70 this has to be treated differently.
72 For member declarations, access checking has to be deferred
73 until more information about the declaration is known. For
85 When we are parsing the function return type `A::X', we don't
86 really know if this is allowed until we parse the function name.
88 Furthermore, some contexts require that access checking is
89 never performed at all. These include class heads, and template
92 Typical use of access checking functions is described here:
94 1. When we enter a context that requires certain access checking
95 mode, the function `push_deferring_access_checks' is called with
96 DEFERRING argument specifying the desired mode. Access checking
97 may be performed immediately (dk_no_deferred), deferred
98 (dk_deferred), or not performed (dk_no_check).
100 2. When a declaration such as a type, or a variable, is encountered,
101 the function `perform_or_defer_access_check' is called. It
102 maintains a vector of all deferred checks.
104 3. The global `current_class_type' or `current_function_decl' is then
105 setup by the parser. `enforce_access' relies on these information
108 4. Upon exiting the context mentioned in step 1,
109 `perform_deferred_access_checks' is called to check all declaration
110 stored in the vector. `pop_deferring_access_checks' is then
111 called to restore the previous access checking mode.
113 In case of parsing error, we simply call `pop_deferring_access_checks'
114 without `perform_deferred_access_checks'. */
116 struct GTY(()) deferred_access
{
117 /* A vector representing name-lookups for which we have deferred
118 checking access controls. We cannot check the accessibility of
119 names used in a decl-specifier-seq until we know what is being
120 declared because code like:
127 A::B* A::f() { return 0; }
129 is valid, even though `A::B' is not generally accessible. */
130 vec
<deferred_access_check
, va_gc
> *deferred_access_checks
;
132 /* The current mode of access checks. */
133 enum deferring_kind deferring_access_checks_kind
;
136 /* Data for deferred access checking. */
137 static GTY(()) vec
<deferred_access
, va_gc
> *deferred_access_stack
;
138 static GTY(()) unsigned deferred_access_no_check
;
140 /* Save the current deferred access states and start deferred
141 access checking iff DEFER_P is true. */
144 push_deferring_access_checks (deferring_kind deferring
)
146 /* For context like template instantiation, access checking
147 disabling applies to all nested context. */
148 if (deferred_access_no_check
|| deferring
== dk_no_check
)
149 deferred_access_no_check
++;
152 deferred_access e
= {NULL
, deferring
};
153 vec_safe_push (deferred_access_stack
, e
);
157 /* Save the current deferred access states and start deferred access
158 checking, continuing the set of deferred checks in CHECKS. */
161 reopen_deferring_access_checks (vec
<deferred_access_check
, va_gc
> * checks
)
163 push_deferring_access_checks (dk_deferred
);
164 if (!deferred_access_no_check
)
165 deferred_access_stack
->last().deferred_access_checks
= checks
;
168 /* Resume deferring access checks again after we stopped doing
172 resume_deferring_access_checks (void)
174 if (!deferred_access_no_check
)
175 deferred_access_stack
->last().deferring_access_checks_kind
= dk_deferred
;
178 /* Stop deferring access checks. */
181 stop_deferring_access_checks (void)
183 if (!deferred_access_no_check
)
184 deferred_access_stack
->last().deferring_access_checks_kind
= dk_no_deferred
;
187 /* Discard the current deferred access checks and restore the
191 pop_deferring_access_checks (void)
193 if (deferred_access_no_check
)
194 deferred_access_no_check
--;
196 deferred_access_stack
->pop ();
199 /* Returns a TREE_LIST representing the deferred checks.
200 The TREE_PURPOSE of each node is the type through which the
201 access occurred; the TREE_VALUE is the declaration named.
204 vec
<deferred_access_check
, va_gc
> *
205 get_deferred_access_checks (void)
207 if (deferred_access_no_check
)
210 return (deferred_access_stack
->last().deferred_access_checks
);
213 /* Take current deferred checks and combine with the
214 previous states if we also defer checks previously.
215 Otherwise perform checks now. */
218 pop_to_parent_deferring_access_checks (void)
220 if (deferred_access_no_check
)
221 deferred_access_no_check
--;
224 vec
<deferred_access_check
, va_gc
> *checks
;
225 deferred_access
*ptr
;
227 checks
= (deferred_access_stack
->last ().deferred_access_checks
);
229 deferred_access_stack
->pop ();
230 ptr
= &deferred_access_stack
->last ();
231 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
234 perform_access_checks (checks
, tf_warning_or_error
);
238 /* Merge with parent. */
240 deferred_access_check
*chk
, *probe
;
242 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
244 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, j
, probe
)
246 if (probe
->binfo
== chk
->binfo
&&
247 probe
->decl
== chk
->decl
&&
248 probe
->diag_decl
== chk
->diag_decl
)
251 /* Insert into parent's checks. */
252 vec_safe_push (ptr
->deferred_access_checks
, *chk
);
259 /* If the current scope isn't allowed to access DECL along
260 BASETYPE_PATH, give an error, or if we're parsing a function or class
261 template, defer the access check to be performed at instantiation time.
262 The most derived class in BASETYPE_PATH is the one used to qualify DECL.
263 DIAG_DECL is the declaration to use in the error diagnostic. */
266 enforce_access (tree basetype_path
, tree decl
, tree diag_decl
,
267 tsubst_flags_t complain
, access_failure_info
*afi
= NULL
)
269 gcc_assert (TREE_CODE (basetype_path
) == TREE_BINFO
);
271 if (flag_new_inheriting_ctors
272 && DECL_INHERITED_CTOR (decl
))
274 /* 7.3.3/18: The additional constructors are accessible if they would be
275 accessible when used to construct an object of the corresponding base
277 decl
= strip_inheriting_ctors (decl
);
278 basetype_path
= lookup_base (basetype_path
, DECL_CONTEXT (decl
),
279 ba_any
, NULL
, complain
);
282 tree cs
= current_scope ();
283 if (processing_template_decl
284 && (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
))
285 if (tree template_info
= get_template_info (cs
))
287 /* When parsing a function or class template, we in general need to
288 defer access checks until template instantiation time, since a friend
289 declaration may grant access only to a particular specialization of
292 if (accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
293 /* But if the member is deemed accessible at parse time, then we can
294 assume it'll be accessible at instantiation time. */
297 /* Access of a dependent decl should be rechecked after tsubst'ing
298 into the user of the decl, rather than explicitly deferring the
300 gcc_assert (!uses_template_parms (decl
));
301 if (TREE_CODE (decl
) == FIELD_DECL
)
302 gcc_assert (!uses_template_parms (DECL_CONTEXT (decl
)));
304 /* Defer this access check until instantiation time. */
305 deferred_access_check access_check
;
306 access_check
.binfo
= basetype_path
;
307 access_check
.decl
= decl
;
308 access_check
.diag_decl
= diag_decl
;
309 access_check
.loc
= input_location
;
310 vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info
), access_check
);
314 if (!accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
316 if (flag_new_inheriting_ctors
)
317 diag_decl
= strip_inheriting_ctors (diag_decl
);
318 if (complain
& tf_error
)
319 complain_about_access (decl
, diag_decl
, true);
321 afi
->record_access_failure (basetype_path
, decl
, diag_decl
);
328 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
329 is the BINFO indicating the qualifying scope used to access the
330 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
331 or we aren't in SFINAE context or all the checks succeed return TRUE,
335 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
336 tsubst_flags_t complain
)
339 deferred_access_check
*chk
;
340 location_t loc
= input_location
;
346 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
348 input_location
= chk
->loc
;
349 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
352 input_location
= loc
;
353 return (complain
& tf_error
) ? true : ok
;
356 /* Perform the deferred access checks.
358 After performing the checks, we still have to keep the list
359 `deferred_access_stack->deferred_access_checks' since we may want
360 to check access for them again later in a different context.
367 A::X A::a, x; // No error for `A::a', error for `x'
369 We have to perform deferred access of `A::X', first with `A::a',
370 next with `x'. Return value like perform_access_checks above. */
373 perform_deferred_access_checks (tsubst_flags_t complain
)
375 return perform_access_checks (get_deferred_access_checks (), complain
);
378 /* Defer checking the accessibility of DECL, when looked up in
379 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
380 Return value like perform_access_checks above.
381 If non-NULL, report failures to AFI. */
384 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
385 tsubst_flags_t complain
,
386 access_failure_info
*afi
)
389 deferred_access
*ptr
;
390 deferred_access_check
*chk
;
392 /* Exit if we are in a context that no access checking is performed. */
393 if (deferred_access_no_check
)
396 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
398 ptr
= &deferred_access_stack
->last ();
400 /* If we are not supposed to defer access checks, just check now. */
401 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
403 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
, afi
);
404 return (complain
& tf_error
) ? true : ok
;
407 /* See if we are already going to perform this check. */
408 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
410 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
411 chk
->diag_decl
== diag_decl
)
416 /* If not, record the check. */
417 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
418 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
423 /* Returns nonzero if the current statement is a full expression,
424 i.e. temporaries created during that statement should be destroyed
425 at the end of the statement. */
428 stmts_are_full_exprs_p (void)
430 return current_stmt_tree ()->stmts_are_full_exprs_p
;
433 /* T is a statement. Add it to the statement-tree. This is the C++
434 version. The C/ObjC frontends have a slightly different version of
440 enum tree_code code
= TREE_CODE (t
);
442 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
444 if (!EXPR_HAS_LOCATION (t
))
445 SET_EXPR_LOCATION (t
, input_location
);
447 /* When we expand a statement-tree, we must know whether or not the
448 statements are full-expressions. We record that fact here. */
449 if (STATEMENT_CODE_P (TREE_CODE (t
)))
450 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
453 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
454 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
456 /* Add T to the statement-tree. Non-side-effect statements need to be
457 recorded during statement expressions. */
458 gcc_checking_assert (!stmt_list_stack
->is_empty ());
459 append_to_statement_list_force (t
, &cur_stmt_list
);
464 /* Returns the stmt_tree to which statements are currently being added. */
467 current_stmt_tree (void)
470 ? &cfun
->language
->base
.x_stmt_tree
471 : &scope_chain
->x_stmt_tree
);
474 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
477 maybe_cleanup_point_expr (tree expr
)
479 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
480 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
484 /* Like maybe_cleanup_point_expr except have the type of the new expression be
485 void so we don't need to create a temporary variable to hold the inner
486 expression. The reason why we do this is because the original type might be
487 an aggregate and we cannot create a temporary variable for that type. */
490 maybe_cleanup_point_expr_void (tree expr
)
492 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
493 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
499 /* Create a declaration statement for the declaration given by the DECL. */
502 add_decl_expr (tree decl
)
504 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
505 if (DECL_INITIAL (decl
)
506 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
507 r
= maybe_cleanup_point_expr_void (r
);
511 /* Finish a scope. */
514 do_poplevel (tree stmt_list
)
518 if (stmts_are_full_exprs_p ())
519 block
= poplevel (kept_level_p (), 1, 0);
521 stmt_list
= pop_stmt_list (stmt_list
);
523 if (!processing_template_decl
)
525 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
526 /* ??? See c_end_compound_stmt re statement expressions. */
532 /* Begin a new scope. */
535 do_pushlevel (scope_kind sk
)
537 tree ret
= push_stmt_list ();
538 if (stmts_are_full_exprs_p ())
539 begin_scope (sk
, NULL
);
543 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
544 when the current scope is exited. EH_ONLY is true when this is not
545 meant to apply to normal control flow transfer. */
548 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
550 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
551 CLEANUP_EH_ONLY (stmt
) = eh_only
;
553 CLEANUP_BODY (stmt
) = push_stmt_list ();
556 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
557 the current loops, represented by 'NULL_TREE' if we've seen a possible
558 exit, and 'error_mark_node' if not. This is currently used only to
559 suppress the warning about a function with no return statements, and
560 therefore we don't bother noting returns as possible exits. We also
561 don't bother with gotos. */
564 begin_maybe_infinite_loop (tree cond
)
566 /* Only track this while parsing a function, not during instantiation. */
567 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
568 && !processing_template_decl
))
570 bool maybe_infinite
= true;
573 cond
= fold_non_dependent_expr (cond
);
574 maybe_infinite
= integer_nonzerop (cond
);
576 vec_safe_push (cp_function_chain
->infinite_loops
,
577 maybe_infinite
? error_mark_node
: NULL_TREE
);
581 /* A break is a possible exit for the current loop. */
584 break_maybe_infinite_loop (void)
588 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
591 /* If we reach the end of the loop without seeing a possible exit, we have
595 end_maybe_infinite_loop (tree cond
)
597 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
598 && !processing_template_decl
))
600 tree current
= cp_function_chain
->infinite_loops
->pop();
601 if (current
!= NULL_TREE
)
603 cond
= fold_non_dependent_expr (cond
);
604 if (integer_nonzerop (cond
))
605 current_function_infinite_loop
= 1;
610 /* Begin a conditional that might contain a declaration. When generating
611 normal code, we want the declaration to appear before the statement
612 containing the conditional. When generating template code, we want the
613 conditional to be rendered as the raw DECL_EXPR. */
616 begin_cond (tree
*cond_p
)
618 if (processing_template_decl
)
619 *cond_p
= push_stmt_list ();
622 /* Finish such a conditional. */
625 finish_cond (tree
*cond_p
, tree expr
)
627 if (processing_template_decl
)
629 tree cond
= pop_stmt_list (*cond_p
);
631 if (expr
== NULL_TREE
)
632 /* Empty condition in 'for'. */
633 gcc_assert (empty_expr_stmt_p (cond
));
634 else if (check_for_bare_parameter_packs (expr
))
635 expr
= error_mark_node
;
636 else if (!empty_expr_stmt_p (cond
))
637 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
642 /* If *COND_P specifies a conditional with a declaration, transform the
645 for (; A x = 42;) { }
647 while (true) { A x = 42; if (!x) break; }
648 for (;;) { A x = 42; if (!x) break; }
649 The statement list for BODY will be empty if the conditional did
650 not declare anything. */
653 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
657 if (!TREE_SIDE_EFFECTS (body
))
661 *cond_p
= boolean_true_node
;
663 if_stmt
= begin_if_stmt ();
664 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, false, tf_warning_or_error
);
665 finish_if_stmt_cond (cond
, if_stmt
);
666 finish_break_stmt ();
667 finish_then_clause (if_stmt
);
668 finish_if_stmt (if_stmt
);
671 /* Finish a goto-statement. */
674 finish_goto_stmt (tree destination
)
676 if (identifier_p (destination
))
677 destination
= lookup_label (destination
);
679 /* We warn about unused labels with -Wunused. That means we have to
680 mark the used labels as used. */
681 if (TREE_CODE (destination
) == LABEL_DECL
)
682 TREE_USED (destination
) = 1;
685 destination
= mark_rvalue_use (destination
);
686 if (!processing_template_decl
)
688 destination
= cp_convert (ptr_type_node
, destination
,
689 tf_warning_or_error
);
690 if (error_operand_p (destination
))
693 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
698 check_goto (destination
);
700 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
701 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
704 /* COND is the condition-expression for an if, while, etc.,
705 statement. Convert it to a boolean value, if appropriate.
706 In addition, verify sequence points if -Wsequence-point is enabled. */
709 maybe_convert_cond (tree cond
)
711 /* Empty conditions remain empty. */
715 /* Wait until we instantiate templates before doing conversion. */
716 if (type_dependent_expression_p (cond
))
719 if (warn_sequence_point
&& !processing_template_decl
)
720 verify_sequence_points (cond
);
722 /* Do the conversion. */
723 cond
= convert_from_reference (cond
);
725 if (TREE_CODE (cond
) == MODIFY_EXPR
726 && !TREE_NO_WARNING (cond
)
728 && warning_at (cp_expr_loc_or_input_loc (cond
),
729 OPT_Wparentheses
, "suggest parentheses around "
730 "assignment used as truth value"))
731 TREE_NO_WARNING (cond
) = 1;
733 return condition_conversion (cond
);
736 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
739 finish_expr_stmt (tree expr
)
742 location_t loc
= EXPR_LOCATION (expr
);
744 if (expr
!= NULL_TREE
)
746 /* If we ran into a problem, make sure we complained. */
747 gcc_assert (expr
!= error_mark_node
|| seen_error ());
749 if (!processing_template_decl
)
751 if (warn_sequence_point
)
752 verify_sequence_points (expr
);
753 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
755 else if (!type_dependent_expression_p (expr
))
756 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
757 tf_warning_or_error
);
759 if (check_for_bare_parameter_packs (expr
))
760 expr
= error_mark_node
;
762 /* Simplification of inner statement expressions, compound exprs,
763 etc can result in us already having an EXPR_STMT. */
764 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
766 if (TREE_CODE (expr
) != EXPR_STMT
)
767 expr
= build_stmt (loc
, EXPR_STMT
, expr
);
768 expr
= maybe_cleanup_point_expr_void (expr
);
778 /* Begin an if-statement. Returns a newly created IF_STMT if
785 scope
= do_pushlevel (sk_cond
);
786 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
787 NULL_TREE
, NULL_TREE
, scope
);
788 current_binding_level
->this_entity
= r
;
789 begin_cond (&IF_COND (r
));
793 /* Returns true if FN, a CALL_EXPR, is a call to
794 std::is_constant_evaluated or __builtin_is_constant_evaluated. */
797 is_std_constant_evaluated_p (tree fn
)
799 /* std::is_constant_evaluated takes no arguments. */
800 if (call_expr_nargs (fn
) != 0)
803 tree fndecl
= cp_get_callee_fndecl_nofold (fn
);
804 if (fndecl
== NULL_TREE
)
807 if (fndecl_built_in_p (fndecl
, CP_BUILT_IN_IS_CONSTANT_EVALUATED
,
811 if (!decl_in_std_namespace_p (fndecl
))
814 tree name
= DECL_NAME (fndecl
);
815 return name
&& id_equal (name
, "is_constant_evaluated");
818 /* Process the COND of an if-statement, which may be given by
822 finish_if_stmt_cond (tree cond
, tree if_stmt
)
824 cond
= maybe_convert_cond (cond
);
825 if (IF_STMT_CONSTEXPR_P (if_stmt
)
826 && !type_dependent_expression_p (cond
)
827 && require_constant_expression (cond
)
828 && !instantiation_dependent_expression_p (cond
)
829 /* Wait until instantiation time, since only then COND has been
830 converted to bool. */
831 && TYPE_MAIN_VARIANT (TREE_TYPE (cond
)) == boolean_type_node
)
833 /* if constexpr (std::is_constant_evaluated()) is always true,
834 so give the user a clue. */
835 if (warn_tautological_compare
)
838 if (TREE_CODE (t
) == CLEANUP_POINT_EXPR
)
839 t
= TREE_OPERAND (t
, 0);
840 if (TREE_CODE (t
) == CALL_EXPR
841 && is_std_constant_evaluated_p (t
))
842 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
843 "%qs always evaluates to true in %<if constexpr%>",
844 "std::is_constant_evaluated");
847 cond
= instantiate_non_dependent_expr (cond
);
848 cond
= cxx_constant_value (cond
, NULL_TREE
);
850 finish_cond (&IF_COND (if_stmt
), cond
);
852 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
856 /* Finish the then-clause of an if-statement, which may be given by
860 finish_then_clause (tree if_stmt
)
862 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
866 /* Begin the else-clause of an if-statement. */
869 begin_else_clause (tree if_stmt
)
871 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
874 /* Finish the else-clause of an if-statement, which may be given by
878 finish_else_clause (tree if_stmt
)
880 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
883 /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
887 maybe_mark_exp_read_r (tree
*tp
, int *, void *)
890 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
895 /* Finish an if-statement. */
898 finish_if_stmt (tree if_stmt
)
900 tree scope
= IF_SCOPE (if_stmt
);
901 IF_SCOPE (if_stmt
) = NULL
;
902 if (IF_STMT_CONSTEXPR_P (if_stmt
))
904 /* Prevent various -Wunused warnings. We might not instantiate
905 either of these branches, so we would not mark the variables
906 used in that branch as read. */
907 cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt
),
908 maybe_mark_exp_read_r
, NULL
);
909 cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt
),
910 maybe_mark_exp_read_r
, NULL
);
912 add_stmt (do_poplevel (scope
));
915 /* Begin a while-statement. Returns a newly created WHILE_STMT if
919 begin_while_stmt (void)
922 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
924 WHILE_BODY (r
) = do_pushlevel (sk_block
);
925 begin_cond (&WHILE_COND (r
));
929 /* Process the COND of a while-statement, which may be given by
933 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
,
934 unsigned short unroll
)
936 cond
= maybe_convert_cond (cond
);
937 finish_cond (&WHILE_COND (while_stmt
), cond
);
938 begin_maybe_infinite_loop (cond
);
939 if (ivdep
&& cond
!= error_mark_node
)
940 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
941 TREE_TYPE (WHILE_COND (while_stmt
)),
942 WHILE_COND (while_stmt
),
943 build_int_cst (integer_type_node
,
944 annot_expr_ivdep_kind
),
946 if (unroll
&& cond
!= error_mark_node
)
947 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
948 TREE_TYPE (WHILE_COND (while_stmt
)),
949 WHILE_COND (while_stmt
),
950 build_int_cst (integer_type_node
,
951 annot_expr_unroll_kind
),
952 build_int_cst (integer_type_node
,
954 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
957 /* Finish a while-statement, which may be given by WHILE_STMT. */
960 finish_while_stmt (tree while_stmt
)
962 end_maybe_infinite_loop (boolean_true_node
);
963 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
966 /* Begin a do-statement. Returns a newly created DO_STMT if
972 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
973 begin_maybe_infinite_loop (boolean_true_node
);
975 DO_BODY (r
) = push_stmt_list ();
979 /* Finish the body of a do-statement, which may be given by DO_STMT. */
982 finish_do_body (tree do_stmt
)
984 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
986 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
987 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
989 if (IS_EMPTY_STMT (body
))
990 warning (OPT_Wempty_body
,
991 "suggest explicit braces around empty body in %<do%> statement");
994 /* Finish a do-statement, which may be given by DO_STMT, and whose
995 COND is as indicated. */
998 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
, unsigned short unroll
)
1000 cond
= maybe_convert_cond (cond
);
1001 end_maybe_infinite_loop (cond
);
1002 if (ivdep
&& cond
!= error_mark_node
)
1003 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1004 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
),
1006 if (unroll
&& cond
!= error_mark_node
)
1007 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1008 build_int_cst (integer_type_node
, annot_expr_unroll_kind
),
1009 build_int_cst (integer_type_node
, unroll
));
1010 DO_COND (do_stmt
) = cond
;
1013 /* Finish a return-statement. The EXPRESSION returned, if any, is as
1017 finish_return_stmt (tree expr
)
1022 expr
= check_return_expr (expr
, &no_warning
);
1024 if (error_operand_p (expr
)
1025 || (flag_openmp
&& !check_omp_return ()))
1027 /* Suppress -Wreturn-type for this function. */
1028 if (warn_return_type
)
1029 TREE_NO_WARNING (current_function_decl
) = true;
1030 return error_mark_node
;
1033 if (!processing_template_decl
)
1035 if (warn_sequence_point
)
1036 verify_sequence_points (expr
);
1038 if (DECL_DESTRUCTOR_P (current_function_decl
)
1039 || (DECL_CONSTRUCTOR_P (current_function_decl
)
1040 && targetm
.cxx
.cdtor_returns_this ()))
1042 /* Similarly, all destructors must run destructors for
1043 base-classes before returning. So, all returns in a
1044 destructor get sent to the DTOR_LABEL; finish_function emits
1045 code to return a value there. */
1046 return finish_goto_stmt (cdtor_label
);
1050 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
1051 TREE_NO_WARNING (r
) |= no_warning
;
1052 r
= maybe_cleanup_point_expr_void (r
);
1058 /* Begin the scope of a for-statement or a range-for-statement.
1059 Both the returned trees are to be used in a call to
1060 begin_for_stmt or begin_range_for_stmt. */
1063 begin_for_scope (tree
*init
)
1065 tree scope
= do_pushlevel (sk_for
);
1067 if (processing_template_decl
)
1068 *init
= push_stmt_list ();
1075 /* Begin a for-statement. Returns a new FOR_STMT.
1076 SCOPE and INIT should be the return of begin_for_scope,
1077 or both NULL_TREE */
1080 begin_for_stmt (tree scope
, tree init
)
1084 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
1085 NULL_TREE
, NULL_TREE
, NULL_TREE
);
1087 if (scope
== NULL_TREE
)
1090 scope
= begin_for_scope (&init
);
1093 FOR_INIT_STMT (r
) = init
;
1094 FOR_SCOPE (r
) = scope
;
1099 /* Finish the init-statement of a for-statement, which may be
1100 given by FOR_STMT. */
1103 finish_init_stmt (tree for_stmt
)
1105 if (processing_template_decl
)
1106 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
1107 add_stmt (for_stmt
);
1108 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
1109 begin_cond (&FOR_COND (for_stmt
));
1112 /* Finish the COND of a for-statement, which may be given by
1116 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
, unsigned short unroll
)
1118 cond
= maybe_convert_cond (cond
);
1119 finish_cond (&FOR_COND (for_stmt
), cond
);
1120 begin_maybe_infinite_loop (cond
);
1121 if (ivdep
&& cond
!= error_mark_node
)
1122 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1123 TREE_TYPE (FOR_COND (for_stmt
)),
1124 FOR_COND (for_stmt
),
1125 build_int_cst (integer_type_node
,
1126 annot_expr_ivdep_kind
),
1128 if (unroll
&& cond
!= error_mark_node
)
1129 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1130 TREE_TYPE (FOR_COND (for_stmt
)),
1131 FOR_COND (for_stmt
),
1132 build_int_cst (integer_type_node
,
1133 annot_expr_unroll_kind
),
1134 build_int_cst (integer_type_node
,
1136 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
1139 /* Finish the increment-EXPRESSION in a for-statement, which may be
1140 given by FOR_STMT. */
1143 finish_for_expr (tree expr
, tree for_stmt
)
1147 /* If EXPR is an overloaded function, issue an error; there is no
1148 context available to use to perform overload resolution. */
1149 if (type_unknown_p (expr
))
1151 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1152 expr
= error_mark_node
;
1154 if (!processing_template_decl
)
1156 if (warn_sequence_point
)
1157 verify_sequence_points (expr
);
1158 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1159 tf_warning_or_error
);
1161 else if (!type_dependent_expression_p (expr
))
1162 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1163 tf_warning_or_error
);
1164 expr
= maybe_cleanup_point_expr_void (expr
);
1165 if (check_for_bare_parameter_packs (expr
))
1166 expr
= error_mark_node
;
1167 FOR_EXPR (for_stmt
) = expr
;
1170 /* Finish the body of a for-statement, which may be given by
1171 FOR_STMT. The increment-EXPR for the loop must be
1173 It can also finish RANGE_FOR_STMT. */
1176 finish_for_stmt (tree for_stmt
)
1178 end_maybe_infinite_loop (boolean_true_node
);
1180 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1181 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1183 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1185 /* Pop the scope for the body of the loop. */
1186 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1187 ? &RANGE_FOR_SCOPE (for_stmt
)
1188 : &FOR_SCOPE (for_stmt
));
1189 tree scope
= *scope_ptr
;
1192 /* During parsing of the body, range for uses "__for_{range,begin,end} "
1193 decl names to make those unaccessible by code in the body.
1194 Change it to ones with underscore instead of space, so that it can
1195 be inspected in the debugger. */
1196 tree range_for_decl
[3] = { NULL_TREE
, NULL_TREE
, NULL_TREE
};
1197 gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 1
1198 && CPTI_FOR_END__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 2
1199 && CPTI_FOR_RANGE_IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 3
1200 && CPTI_FOR_BEGIN_IDENTIFIER
== CPTI_FOR_BEGIN__IDENTIFIER
+ 3
1201 && CPTI_FOR_END_IDENTIFIER
== CPTI_FOR_END__IDENTIFIER
+ 3);
1202 for (int i
= 0; i
< 3; i
++)
1204 tree id
= cp_global_trees
[CPTI_FOR_RANGE__IDENTIFIER
+ i
];
1205 if (IDENTIFIER_BINDING (id
)
1206 && IDENTIFIER_BINDING (id
)->scope
== current_binding_level
)
1208 range_for_decl
[i
] = IDENTIFIER_BINDING (id
)->value
;
1209 gcc_assert (VAR_P (range_for_decl
[i
])
1210 && DECL_ARTIFICIAL (range_for_decl
[i
]));
1214 add_stmt (do_poplevel (scope
));
1216 for (int i
= 0; i
< 3; i
++)
1217 if (range_for_decl
[i
])
1218 DECL_NAME (range_for_decl
[i
])
1219 = cp_global_trees
[CPTI_FOR_RANGE_IDENTIFIER
+ i
];
1222 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1223 SCOPE and INIT should be the return of begin_for_scope,
1225 To finish it call finish_for_stmt(). */
1228 begin_range_for_stmt (tree scope
, tree init
)
1230 begin_maybe_infinite_loop (boolean_false_node
);
1232 tree r
= build_stmt (input_location
, RANGE_FOR_STMT
, NULL_TREE
, NULL_TREE
,
1233 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1235 if (scope
== NULL_TREE
)
1238 scope
= begin_for_scope (&init
);
1241 /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1242 RANGE_FOR_INIT_STMT (r
) = init
;
1243 RANGE_FOR_SCOPE (r
) = scope
;
1248 /* Finish the head of a range-based for statement, which may
1249 be given by RANGE_FOR_STMT. DECL must be the declaration
1250 and EXPR must be the loop expression. */
1253 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1255 if (processing_template_decl
)
1256 RANGE_FOR_INIT_STMT (range_for_stmt
)
1257 = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt
));
1258 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1259 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1260 add_stmt (range_for_stmt
);
1261 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1264 /* Finish a break-statement. */
1267 finish_break_stmt (void)
1269 /* In switch statements break is sometimes stylistically used after
1270 a return statement. This can lead to spurious warnings about
1271 control reaching the end of a non-void function when it is
1272 inlined. Note that we are calling block_may_fallthru with
1273 language specific tree nodes; this works because
1274 block_may_fallthru returns true when given something it does not
1276 if (!block_may_fallthru (cur_stmt_list
))
1279 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1282 /* Finish a continue-statement. */
1285 finish_continue_stmt (void)
1287 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1290 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1294 begin_switch_stmt (void)
1298 scope
= do_pushlevel (sk_cond
);
1299 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1301 begin_cond (&SWITCH_STMT_COND (r
));
1306 /* Finish the cond of a switch-statement. */
1309 finish_switch_cond (tree cond
, tree switch_stmt
)
1311 tree orig_type
= NULL
;
1313 if (!processing_template_decl
)
1315 /* Convert the condition to an integer or enumeration type. */
1316 tree orig_cond
= cond
;
1317 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1318 if (cond
== NULL_TREE
)
1320 error_at (cp_expr_loc_or_input_loc (orig_cond
),
1321 "switch quantity not an integer");
1322 cond
= error_mark_node
;
1324 /* We want unlowered type here to handle enum bit-fields. */
1325 orig_type
= unlowered_expr_type (cond
);
1326 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1327 orig_type
= TREE_TYPE (cond
);
1328 if (cond
!= error_mark_node
)
1332 Integral promotions are performed. */
1333 cond
= perform_integral_promotions (cond
);
1334 cond
= maybe_cleanup_point_expr (cond
);
1337 if (check_for_bare_parameter_packs (cond
))
1338 cond
= error_mark_node
;
1339 else if (!processing_template_decl
&& warn_sequence_point
)
1340 verify_sequence_points (cond
);
1342 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1343 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1344 add_stmt (switch_stmt
);
1345 push_switch (switch_stmt
);
1346 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1349 /* Finish the body of a switch-statement, which may be given by
1350 SWITCH_STMT. The COND to switch on is indicated. */
1353 finish_switch_stmt (tree switch_stmt
)
1357 SWITCH_STMT_BODY (switch_stmt
) =
1358 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1361 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1362 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1363 add_stmt (do_poplevel (scope
));
1366 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1370 begin_try_block (void)
1372 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1374 TRY_STMTS (r
) = push_stmt_list ();
1378 /* Likewise, for a function-try-block. The block returned in
1379 *COMPOUND_STMT is an artificial outer scope, containing the
1380 function-try-block. */
1383 begin_function_try_block (tree
*compound_stmt
)
1386 /* This outer scope does not exist in the C++ standard, but we need
1387 a place to put __FUNCTION__ and similar variables. */
1388 *compound_stmt
= begin_compound_stmt (0);
1389 r
= begin_try_block ();
1390 FN_TRY_BLOCK_P (r
) = 1;
1394 /* Finish a try-block, which may be given by TRY_BLOCK. */
1397 finish_try_block (tree try_block
)
1399 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1400 TRY_HANDLERS (try_block
) = push_stmt_list ();
1403 /* Finish the body of a cleanup try-block, which may be given by
1407 finish_cleanup_try_block (tree try_block
)
1409 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1412 /* Finish an implicitly generated try-block, with a cleanup is given
1416 finish_cleanup (tree cleanup
, tree try_block
)
1418 TRY_HANDLERS (try_block
) = cleanup
;
1419 CLEANUP_P (try_block
) = 1;
1422 /* Likewise, for a function-try-block. */
1425 finish_function_try_block (tree try_block
)
1427 finish_try_block (try_block
);
1428 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1429 the try block, but moving it inside. */
1430 in_function_try_handler
= 1;
1433 /* Finish a handler-sequence for a try-block, which may be given by
1437 finish_handler_sequence (tree try_block
)
1439 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1440 check_handlers (TRY_HANDLERS (try_block
));
1443 /* Finish the handler-seq for a function-try-block, given by
1444 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1445 begin_function_try_block. */
1448 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1450 in_function_try_handler
= 0;
1451 finish_handler_sequence (try_block
);
1452 finish_compound_stmt (compound_stmt
);
1455 /* Begin a handler. Returns a HANDLER if appropriate. */
1458 begin_handler (void)
1462 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1465 /* Create a binding level for the eh_info and the exception object
1467 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1472 /* Finish the handler-parameters for a handler, which may be given by
1473 HANDLER. DECL is the declaration for the catch parameter, or NULL
1474 if this is a `catch (...)' clause. */
1477 finish_handler_parms (tree decl
, tree handler
)
1479 tree type
= NULL_TREE
;
1480 if (processing_template_decl
)
1484 decl
= pushdecl (decl
);
1485 decl
= push_template_decl (decl
);
1486 HANDLER_PARMS (handler
) = decl
;
1487 type
= TREE_TYPE (decl
);
1492 type
= expand_start_catch_block (decl
);
1493 if (warn_catch_value
1494 && type
!= NULL_TREE
1495 && type
!= error_mark_node
1496 && !TYPE_REF_P (TREE_TYPE (decl
)))
1498 tree orig_type
= TREE_TYPE (decl
);
1499 if (CLASS_TYPE_P (orig_type
))
1501 if (TYPE_POLYMORPHIC_P (orig_type
))
1502 warning_at (DECL_SOURCE_LOCATION (decl
),
1504 "catching polymorphic type %q#T by value",
1506 else if (warn_catch_value
> 1)
1507 warning_at (DECL_SOURCE_LOCATION (decl
),
1509 "catching type %q#T by value", orig_type
);
1511 else if (warn_catch_value
> 2)
1512 warning_at (DECL_SOURCE_LOCATION (decl
),
1514 "catching non-reference type %q#T", orig_type
);
1517 HANDLER_TYPE (handler
) = type
;
1520 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1521 the return value from the matching call to finish_handler_parms. */
1524 finish_handler (tree handler
)
1526 if (!processing_template_decl
)
1527 expand_end_catch_block ();
1528 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1531 /* Begin a compound statement. FLAGS contains some bits that control the
1532 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1533 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1534 block of a function. If BCS_TRY_BLOCK is set, this is the block
1535 created on behalf of a TRY statement. Returns a token to be passed to
1536 finish_compound_stmt. */
1539 begin_compound_stmt (unsigned int flags
)
1543 if (flags
& BCS_NO_SCOPE
)
1545 r
= push_stmt_list ();
1546 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1548 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1549 But, if it's a statement-expression with a scopeless block, there's
1550 nothing to keep, and we don't want to accidentally keep a block
1551 *inside* the scopeless block. */
1552 keep_next_level (false);
1556 scope_kind sk
= sk_block
;
1557 if (flags
& BCS_TRY_BLOCK
)
1559 else if (flags
& BCS_TRANSACTION
)
1560 sk
= sk_transaction
;
1561 r
= do_pushlevel (sk
);
1564 /* When processing a template, we need to remember where the braces were,
1565 so that we can set up identical scopes when instantiating the template
1566 later. BIND_EXPR is a handy candidate for this.
1567 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1568 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1569 processing templates. */
1570 if (processing_template_decl
)
1572 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1573 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1574 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1575 TREE_SIDE_EFFECTS (r
) = 1;
1581 /* Finish a compound-statement, which is given by STMT. */
1584 finish_compound_stmt (tree stmt
)
1586 if (TREE_CODE (stmt
) == BIND_EXPR
)
1588 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1589 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1590 discard the BIND_EXPR so it can be merged with the containing
1592 if (TREE_CODE (body
) == STATEMENT_LIST
1593 && STATEMENT_LIST_HEAD (body
) == NULL
1594 && !BIND_EXPR_BODY_BLOCK (stmt
)
1595 && !BIND_EXPR_TRY_BLOCK (stmt
))
1598 BIND_EXPR_BODY (stmt
) = body
;
1600 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1601 stmt
= pop_stmt_list (stmt
);
1604 /* Destroy any ObjC "super" receivers that may have been
1606 objc_clear_super_receiver ();
1608 stmt
= do_poplevel (stmt
);
1611 /* ??? See c_end_compound_stmt wrt statement expressions. */
1615 /* Finish an asm-statement, whose components are a STRING, some
1616 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1617 LABELS. Also note whether the asm-statement should be
1618 considered volatile, and whether it is asm inline. */
1621 finish_asm_stmt (location_t loc
, int volatile_p
, tree string
,
1622 tree output_operands
, tree input_operands
, tree clobbers
,
1623 tree labels
, bool inline_p
)
1627 int ninputs
= list_length (input_operands
);
1628 int noutputs
= list_length (output_operands
);
1630 if (!processing_template_decl
)
1632 const char *constraint
;
1633 const char **oconstraints
;
1634 bool allows_mem
, allows_reg
, is_inout
;
1638 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1640 string
= resolve_asm_operand_names (string
, output_operands
,
1641 input_operands
, labels
);
1643 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1645 operand
= TREE_VALUE (t
);
1647 /* ??? Really, this should not be here. Users should be using a
1648 proper lvalue, dammit. But there's a long history of using
1649 casts in the output operands. In cases like longlong.h, this
1650 becomes a primitive form of typechecking -- if the cast can be
1651 removed, then the output operand had a type of the proper width;
1652 otherwise we'll get an error. Gross, but ... */
1653 STRIP_NOPS (operand
);
1655 operand
= mark_lvalue_use (operand
);
1657 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1658 operand
= error_mark_node
;
1660 if (operand
!= error_mark_node
1661 && (TREE_READONLY (operand
)
1662 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1663 /* Functions are not modifiable, even though they are
1665 || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand
))
1666 /* If it's an aggregate and any field is const, then it is
1667 effectively const. */
1668 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1669 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1670 cxx_readonly_error (loc
, operand
, lv_asm
);
1672 tree
*op
= &operand
;
1673 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1674 op
= &TREE_OPERAND (*op
, 1);
1675 switch (TREE_CODE (*op
))
1677 case PREINCREMENT_EXPR
:
1678 case PREDECREMENT_EXPR
:
1680 *op
= genericize_compound_lvalue (*op
);
1681 op
= &TREE_OPERAND (*op
, 1);
1687 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1688 oconstraints
[i
] = constraint
;
1690 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1691 &allows_mem
, &allows_reg
, &is_inout
))
1693 /* If the operand is going to end up in memory,
1694 mark it addressable. */
1695 if (!allows_reg
&& !cxx_mark_addressable (*op
))
1696 operand
= error_mark_node
;
1699 operand
= error_mark_node
;
1701 TREE_VALUE (t
) = operand
;
1704 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1706 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1707 bool constraint_parsed
1708 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1709 oconstraints
, &allows_mem
, &allows_reg
);
1710 /* If the operand is going to end up in memory, don't call
1711 decay_conversion. */
1712 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1713 operand
= mark_lvalue_use (TREE_VALUE (t
));
1715 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1717 /* If the type of the operand hasn't been determined (e.g.,
1718 because it involves an overloaded function), then issue
1719 an error message. There's no context available to
1720 resolve the overloading. */
1721 if (TREE_TYPE (operand
) == unknown_type_node
)
1724 "type of %<asm%> operand %qE could not be determined",
1726 operand
= error_mark_node
;
1729 if (constraint_parsed
)
1731 /* If the operand is going to end up in memory,
1732 mark it addressable. */
1733 if (!allows_reg
&& allows_mem
)
1735 /* Strip the nops as we allow this case. FIXME, this really
1736 should be rejected or made deprecated. */
1737 STRIP_NOPS (operand
);
1739 tree
*op
= &operand
;
1740 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1741 op
= &TREE_OPERAND (*op
, 1);
1742 switch (TREE_CODE (*op
))
1744 case PREINCREMENT_EXPR
:
1745 case PREDECREMENT_EXPR
:
1747 *op
= genericize_compound_lvalue (*op
);
1748 op
= &TREE_OPERAND (*op
, 1);
1754 if (!cxx_mark_addressable (*op
))
1755 operand
= error_mark_node
;
1757 else if (!allows_reg
&& !allows_mem
)
1759 /* If constraint allows neither register nor memory,
1760 try harder to get a constant. */
1761 tree constop
= maybe_constant_value (operand
);
1762 if (TREE_CONSTANT (constop
))
1767 operand
= error_mark_node
;
1769 TREE_VALUE (t
) = operand
;
1773 r
= build_stmt (loc
, ASM_EXPR
, string
,
1774 output_operands
, input_operands
,
1776 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1777 ASM_INLINE_P (r
) = inline_p
;
1778 r
= maybe_cleanup_point_expr_void (r
);
1779 return add_stmt (r
);
1782 /* Finish a label with the indicated NAME. Returns the new label. */
1785 finish_label_stmt (tree name
)
1787 tree decl
= define_label (input_location
, name
);
1789 if (decl
== error_mark_node
)
1790 return error_mark_node
;
1792 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1797 /* Finish a series of declarations for local labels. G++ allows users
1798 to declare "local" labels, i.e., labels with scope. This extension
1799 is useful when writing code involving statement-expressions. */
1802 finish_label_decl (tree name
)
1804 if (!at_function_scope_p ())
1806 error ("%<__label__%> declarations are only allowed in function scopes");
1810 add_decl_expr (declare_local_label (name
));
1813 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1816 finish_decl_cleanup (tree decl
, tree cleanup
)
1818 push_cleanup (decl
, cleanup
, false);
1821 /* If the current scope exits with an exception, run CLEANUP. */
1824 finish_eh_cleanup (tree cleanup
)
1826 push_cleanup (NULL
, cleanup
, true);
1829 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1830 order they were written by the user. Each node is as for
1831 emit_mem_initializers. */
1834 finish_mem_initializers (tree mem_inits
)
1836 /* Reorder the MEM_INITS so that they are in the order they appeared
1837 in the source program. */
1838 mem_inits
= nreverse (mem_inits
);
1840 if (processing_template_decl
)
1844 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1846 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1847 check for bare parameter packs in the TREE_VALUE, because
1848 any parameter packs in the TREE_VALUE have already been
1849 bound as part of the TREE_PURPOSE. See
1850 make_pack_expansion for more information. */
1851 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1852 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1853 TREE_VALUE (mem
) = error_mark_node
;
1856 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1857 CTOR_INITIALIZER
, mem_inits
));
1860 emit_mem_initializers (mem_inits
);
1863 /* Obfuscate EXPR if it looks like an id-expression or member access so
1864 that the call to finish_decltype in do_auto_deduction will give the
1865 right result. If EVEN_UNEVAL, do this even in unevaluated context. */
1868 force_paren_expr (tree expr
, bool even_uneval
)
1870 /* This is only needed for decltype(auto) in C++14. */
1871 if (cxx_dialect
< cxx14
)
1874 /* If we're in unevaluated context, we can't be deducing a
1875 return/initializer type, so we don't need to mess with this. */
1876 if (cp_unevaluated_operand
&& !even_uneval
)
1879 if (!DECL_P (tree_strip_any_location_wrapper (expr
))
1880 && TREE_CODE (expr
) != COMPONENT_REF
1881 && TREE_CODE (expr
) != SCOPE_REF
)
1884 location_t loc
= cp_expr_location (expr
);
1886 if (TREE_CODE (expr
) == COMPONENT_REF
1887 || TREE_CODE (expr
) == SCOPE_REF
)
1888 REF_PARENTHESIZED_P (expr
) = true;
1889 else if (processing_template_decl
)
1890 expr
= build1_loc (loc
, PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1893 expr
= build1_loc (loc
, VIEW_CONVERT_EXPR
, TREE_TYPE (expr
), expr
);
1894 REF_PARENTHESIZED_P (expr
) = true;
1900 /* If T is an id-expression obfuscated by force_paren_expr, undo the
1901 obfuscation and return the underlying id-expression. Otherwise
1905 maybe_undo_parenthesized_ref (tree t
)
1907 if (cxx_dialect
< cxx14
)
1910 if (INDIRECT_REF_P (t
) && REF_PARENTHESIZED_P (t
))
1912 t
= TREE_OPERAND (t
, 0);
1913 while (TREE_CODE (t
) == NON_LVALUE_EXPR
1914 || TREE_CODE (t
) == NOP_EXPR
)
1915 t
= TREE_OPERAND (t
, 0);
1917 gcc_assert (TREE_CODE (t
) == ADDR_EXPR
1918 || TREE_CODE (t
) == STATIC_CAST_EXPR
);
1919 t
= TREE_OPERAND (t
, 0);
1921 else if (TREE_CODE (t
) == PAREN_EXPR
)
1922 t
= TREE_OPERAND (t
, 0);
1923 else if (TREE_CODE (t
) == VIEW_CONVERT_EXPR
1924 && REF_PARENTHESIZED_P (t
))
1925 t
= TREE_OPERAND (t
, 0);
1930 /* Finish a parenthesized expression EXPR. */
1933 finish_parenthesized_expr (cp_expr expr
)
1936 /* This inhibits warnings in c_common_truthvalue_conversion. */
1937 TREE_NO_WARNING (expr
) = 1;
1939 if (TREE_CODE (expr
) == OFFSET_REF
1940 || TREE_CODE (expr
) == SCOPE_REF
)
1941 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1942 enclosed in parentheses. */
1943 PTRMEM_OK_P (expr
) = 0;
1945 tree stripped_expr
= tree_strip_any_location_wrapper (expr
);
1946 if (TREE_CODE (stripped_expr
) == STRING_CST
)
1947 PAREN_STRING_LITERAL_P (stripped_expr
) = 1;
1949 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
1954 /* Finish a reference to a non-static data member (DECL) that is not
1955 preceded by `.' or `->'. */
1958 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1960 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1961 bool try_omp_private
= !object
&& omp_private_member_map
;
1966 tree scope
= qualifying_scope
;
1967 if (scope
== NULL_TREE
)
1969 scope
= context_for_name_lookup (decl
);
1970 if (!TYPE_P (scope
))
1972 /* Can happen during error recovery (c++/85014). */
1973 gcc_assert (seen_error ());
1974 return error_mark_node
;
1977 object
= maybe_dummy_object (scope
, NULL
);
1980 object
= maybe_resolve_dummy (object
, true);
1981 if (object
== error_mark_node
)
1982 return error_mark_node
;
1984 /* DR 613/850: Can use non-static data members without an associated
1985 object in sizeof/decltype/alignof. */
1986 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
1987 && (!processing_template_decl
|| !current_class_ref
))
1989 if (current_function_decl
1990 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1991 error ("invalid use of member %qD in static member function", decl
);
1993 error ("invalid use of non-static data member %qD", decl
);
1994 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
1996 return error_mark_node
;
1999 if (current_class_ptr
)
2000 TREE_USED (current_class_ptr
) = 1;
2001 if (processing_template_decl
)
2003 tree type
= TREE_TYPE (decl
);
2005 if (TYPE_REF_P (type
))
2006 /* Quals on the object don't matter. */;
2007 else if (PACK_EXPANSION_P (type
))
2008 /* Don't bother trying to represent this. */
2012 /* Set the cv qualifiers. */
2013 int quals
= cp_type_quals (TREE_TYPE (object
));
2015 if (DECL_MUTABLE_P (decl
))
2016 quals
&= ~TYPE_QUAL_CONST
;
2018 quals
|= cp_type_quals (TREE_TYPE (decl
));
2019 type
= cp_build_qualified_type (type
, quals
);
2022 if (qualifying_scope
)
2023 /* Wrap this in a SCOPE_REF for now. */
2024 ret
= build_qualified_name (type
, qualifying_scope
, decl
,
2025 /*template_p=*/false);
2027 ret
= (convert_from_reference
2028 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
2030 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2031 QUALIFYING_SCOPE is also non-null. */
2034 tree access_type
= TREE_TYPE (object
);
2036 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
2037 decl
, tf_warning_or_error
);
2039 /* If the data member was named `C::M', convert `*this' to `C'
2041 if (qualifying_scope
)
2043 tree binfo
= NULL_TREE
;
2044 object
= build_scoped_ref (object
, qualifying_scope
,
2048 ret
= build_class_member_access_expr (object
, decl
,
2049 /*access_path=*/NULL_TREE
,
2050 /*preserve_reference=*/false,
2051 tf_warning_or_error
);
2053 if (try_omp_private
)
2055 tree
*v
= omp_private_member_map
->get (decl
);
2057 ret
= convert_from_reference (*v
);
2062 /* DECL was the declaration to which a qualified-id resolved. Issue
2063 an error message if it is not accessible. If OBJECT_TYPE is
2064 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2065 type of `*x', or `x', respectively. If the DECL was named as
2066 `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2067 perform_access_checks above. */
2070 check_accessibility_of_qualified_id (tree decl
,
2072 tree nested_name_specifier
,
2073 tsubst_flags_t complain
)
2075 /* If we're not checking, return immediately. */
2076 if (deferred_access_no_check
)
2079 /* Determine the SCOPE of DECL. */
2080 tree scope
= context_for_name_lookup (decl
);
2081 /* If the SCOPE is not a type, then DECL is not a member. */
2083 /* If SCOPE is dependent then we can't perform this access check now,
2084 and since we'll perform this access check again after substitution
2085 there's no need to explicitly defer it. */
2086 || dependent_type_p (scope
))
2089 tree qualifying_type
= NULL_TREE
;
2090 /* Compute the scope through which DECL is being accessed. */
2092 /* OBJECT_TYPE might not be a class type; consider:
2094 class A { typedef int I; };
2098 In this case, we will have "A::I" as the DECL, but "I" as the
2100 && CLASS_TYPE_P (object_type
)
2101 && DERIVED_FROM_P (scope
, object_type
))
2102 /* If we are processing a `->' or `.' expression, use the type of the
2104 qualifying_type
= object_type
;
2105 else if (nested_name_specifier
)
2107 /* If the reference is to a non-static member of the
2108 current class, treat it as if it were referenced through
2110 if (DECL_NONSTATIC_MEMBER_P (decl
)
2111 && current_class_ptr
)
2112 if (tree current
= current_nonlambda_class_type ())
2114 if (dependent_type_p (current
))
2115 /* In general we can't know whether this access goes through
2116 `this' until instantiation time. Punt now, or else we might
2117 create a deferred access check that's not relative to `this'
2118 when it ought to be. We'll check this access again after
2119 substitution, e.g. from tsubst_qualified_id. */
2122 if (DERIVED_FROM_P (scope
, current
))
2123 qualifying_type
= current
;
2125 /* Otherwise, use the type indicated by the
2126 nested-name-specifier. */
2127 if (!qualifying_type
)
2128 qualifying_type
= nested_name_specifier
;
2131 /* Otherwise, the name must be from the current class or one of
2133 qualifying_type
= currently_open_derived_class (scope
);
2136 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2137 or similar in a default argument value. */
2138 && CLASS_TYPE_P (qualifying_type
))
2139 return perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
2145 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2146 class named to the left of the "::" operator. DONE is true if this
2147 expression is a complete postfix-expression; it is false if this
2148 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2149 iff this expression is the operand of '&'. TEMPLATE_P is true iff
2150 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2151 is true iff this qualified name appears as a template argument. */
2154 finish_qualified_id_expr (tree qualifying_class
,
2159 bool template_arg_p
,
2160 tsubst_flags_t complain
)
2162 gcc_assert (TYPE_P (qualifying_class
));
2164 if (error_operand_p (expr
))
2165 return error_mark_node
;
2167 if ((DECL_P (expr
) || BASELINK_P (expr
))
2168 && !mark_used (expr
, complain
))
2169 return error_mark_node
;
2173 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
2175 /* cp_parser_lookup_name thought we were looking for a type,
2176 but we're actually looking for a declaration. */
2177 qualifying_class
= TYPE_CONTEXT (expr
);
2178 expr
= TYPE_IDENTIFIER (expr
);
2181 check_template_keyword (expr
);
2184 /* If EXPR occurs as the operand of '&', use special handling that
2185 permits a pointer-to-member. */
2186 if (address_p
&& done
)
2188 if (TREE_CODE (expr
) == SCOPE_REF
)
2189 expr
= TREE_OPERAND (expr
, 1);
2190 expr
= build_offset_ref (qualifying_class
, expr
,
2191 /*address_p=*/true, complain
);
2195 /* No need to check access within an enum. */
2196 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
2197 && TREE_CODE (expr
) != IDENTIFIER_NODE
)
2200 /* Within the scope of a class, turn references to non-static
2201 members into expression of the form "this->...". */
2203 /* But, within a template argument, we do not want make the
2204 transformation, as there is no "this" pointer. */
2206 else if (TREE_CODE (expr
) == FIELD_DECL
)
2208 push_deferring_access_checks (dk_no_check
);
2209 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2211 pop_deferring_access_checks ();
2213 else if (BASELINK_P (expr
))
2215 /* See if any of the functions are non-static members. */
2216 /* If so, the expression may be relative to 'this'. */
2217 if ((type_dependent_expression_p (expr
)
2218 || !shared_member_p (expr
))
2219 && current_class_ptr
2220 && DERIVED_FROM_P (qualifying_class
,
2221 current_nonlambda_class_type ()))
2222 expr
= (build_class_member_access_expr
2223 (maybe_dummy_object (qualifying_class
, NULL
),
2225 BASELINK_ACCESS_BINFO (expr
),
2226 /*preserve_reference=*/false,
2229 /* The expression is a qualified name whose address is not
2231 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2234 else if (!template_p
2235 && TREE_CODE (expr
) == TEMPLATE_DECL
2236 && !DECL_FUNCTION_TEMPLATE_P (expr
))
2238 if (complain
& tf_error
)
2239 error ("%qE missing template arguments", expr
);
2240 return error_mark_node
;
2244 /* In a template, return a SCOPE_REF for most qualified-ids
2245 so that we can check access at instantiation time. But if
2246 we're looking at a member of the current instantiation, we
2247 know we have access and building up the SCOPE_REF confuses
2248 non-type template argument handling. */
2249 if (processing_template_decl
2250 && (!currently_open_class (qualifying_class
)
2251 || TREE_CODE (expr
) == IDENTIFIER_NODE
2252 || TREE_CODE (expr
) == TEMPLATE_ID_EXPR
2253 || TREE_CODE (expr
) == BIT_NOT_EXPR
))
2254 expr
= build_qualified_name (TREE_TYPE (expr
),
2255 qualifying_class
, expr
,
2257 else if (tree wrap
= maybe_get_tls_wrapper_call (expr
))
2260 expr
= convert_from_reference (expr
);
2266 /* Begin a statement-expression. The value returned must be passed to
2267 finish_stmt_expr. */
2270 begin_stmt_expr (void)
2272 return push_stmt_list ();
2275 /* Process the final expression of a statement expression. EXPR can be
2276 NULL, if the final expression is empty. Return a STATEMENT_LIST
2277 containing all the statements in the statement-expression, or
2278 ERROR_MARK_NODE if there was an error. */
2281 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2283 if (error_operand_p (expr
))
2285 /* The type of the statement-expression is the type of the last
2287 TREE_TYPE (stmt_expr
) = error_mark_node
;
2288 return error_mark_node
;
2291 /* If the last statement does not have "void" type, then the value
2292 of the last statement is the value of the entire expression. */
2295 tree type
= TREE_TYPE (expr
);
2297 if (type
&& type_unknown_p (type
))
2299 error ("a statement expression is an insufficient context"
2300 " for overload resolution");
2301 TREE_TYPE (stmt_expr
) = error_mark_node
;
2302 return error_mark_node
;
2304 else if (processing_template_decl
)
2306 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2307 expr
= add_stmt (expr
);
2308 /* Mark the last statement so that we can recognize it as such at
2309 template-instantiation time. */
2310 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2312 else if (VOID_TYPE_P (type
))
2314 /* Just treat this like an ordinary statement. */
2315 expr
= finish_expr_stmt (expr
);
2319 /* It actually has a value we need to deal with. First, force it
2320 to be an rvalue so that we won't need to build up a copy
2321 constructor call later when we try to assign it to something. */
2322 expr
= force_rvalue (expr
, tf_warning_or_error
);
2323 if (error_operand_p (expr
))
2324 return error_mark_node
;
2326 /* Update for array-to-pointer decay. */
2327 type
= TREE_TYPE (expr
);
2329 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2330 normal statement, but don't convert to void or actually add
2332 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2333 expr
= maybe_cleanup_point_expr (expr
);
2337 /* The type of the statement-expression is the type of the last
2339 TREE_TYPE (stmt_expr
) = type
;
2345 /* Finish a statement-expression. EXPR should be the value returned
2346 by the previous begin_stmt_expr. Returns an expression
2347 representing the statement-expression. */
2350 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2355 if (error_operand_p (stmt_expr
))
2357 pop_stmt_list (stmt_expr
);
2358 return error_mark_node
;
2361 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2363 type
= TREE_TYPE (stmt_expr
);
2364 result
= pop_stmt_list (stmt_expr
);
2365 TREE_TYPE (result
) = type
;
2367 if (processing_template_decl
)
2369 result
= build_min (STMT_EXPR
, type
, result
);
2370 TREE_SIDE_EFFECTS (result
) = 1;
2371 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2373 else if (CLASS_TYPE_P (type
))
2375 /* Wrap the statement-expression in a TARGET_EXPR so that the
2376 temporary object created by the final expression is destroyed at
2377 the end of the full-expression containing the
2378 statement-expression. */
2379 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2385 /* Returns the expression which provides the value of STMT_EXPR. */
2388 stmt_expr_value_expr (tree stmt_expr
)
2390 tree t
= STMT_EXPR_STMT (stmt_expr
);
2392 if (TREE_CODE (t
) == BIND_EXPR
)
2393 t
= BIND_EXPR_BODY (t
);
2395 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2396 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2398 if (TREE_CODE (t
) == EXPR_STMT
)
2399 t
= EXPR_STMT_EXPR (t
);
2404 /* Return TRUE iff EXPR_STMT is an empty list of
2405 expression statements. */
2408 empty_expr_stmt_p (tree expr_stmt
)
2410 tree body
= NULL_TREE
;
2412 if (expr_stmt
== void_node
)
2417 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2418 body
= EXPR_STMT_EXPR (expr_stmt
);
2419 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2425 if (TREE_CODE (body
) == STATEMENT_LIST
)
2426 return tsi_end_p (tsi_start (body
));
2428 return empty_expr_stmt_p (body
);
2433 /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
2434 the function (or functions) to call; ARGS are the arguments to the
2435 call. Returns the functions to be considered by overload resolution. */
2438 perform_koenig_lookup (cp_expr fn_expr
, vec
<tree
, va_gc
> *args
,
2439 tsubst_flags_t complain
)
2441 tree identifier
= NULL_TREE
;
2442 tree functions
= NULL_TREE
;
2443 tree tmpl_args
= NULL_TREE
;
2444 bool template_id
= false;
2445 location_t loc
= fn_expr
.get_location ();
2446 tree fn
= fn_expr
.get_value ();
2448 STRIP_ANY_LOCATION_WRAPPER (fn
);
2450 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2452 /* Use a separate flag to handle null args. */
2454 tmpl_args
= TREE_OPERAND (fn
, 1);
2455 fn
= TREE_OPERAND (fn
, 0);
2458 /* Find the name of the overloaded function. */
2459 if (identifier_p (fn
))
2464 identifier
= OVL_NAME (functions
);
2467 /* A call to a namespace-scope function using an unqualified name.
2469 Do Koenig lookup -- unless any of the arguments are
2471 if (!any_type_dependent_arguments_p (args
)
2472 && !any_dependent_template_arguments_p (tmpl_args
))
2474 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2477 /* The unqualified name could not be resolved. */
2478 if (complain
& tf_error
)
2479 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2485 if (fn
&& template_id
&& fn
!= error_mark_node
)
2486 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2488 return cp_expr (fn
, loc
);
2491 /* Generate an expression for `FN (ARGS)'. This may change the
2494 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2495 as a virtual call, even if FN is virtual. (This flag is set when
2496 encountering an expression where the function name is explicitly
2497 qualified. For example a call to `X::f' never generates a virtual
2500 Returns code for the call. */
2503 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2504 bool koenig_p
, tsubst_flags_t complain
)
2508 vec
<tree
, va_gc
> *orig_args
= *args
;
2510 if (fn
== error_mark_node
)
2511 return error_mark_node
;
2513 gcc_assert (!TYPE_P (fn
));
2515 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2516 it so that we can tell this is a call to a known function. */
2517 fn
= maybe_undo_parenthesized_ref (fn
);
2519 STRIP_ANY_LOCATION_WRAPPER (fn
);
2523 if (processing_template_decl
)
2525 /* If FN is a local extern declaration or set thereof, look them up
2526 again at instantiation time. */
2527 if (is_overloaded_fn (fn
))
2529 tree ifn
= get_first_fn (fn
);
2530 if (TREE_CODE (ifn
) == FUNCTION_DECL
2531 && DECL_LOCAL_DECL_P (ifn
))
2532 orig_fn
= DECL_NAME (ifn
);
2535 /* If the call expression is dependent, build a CALL_EXPR node
2536 with no type; type_dependent_expression_p recognizes
2537 expressions with no type as being dependent. */
2538 if (type_dependent_expression_p (fn
)
2539 || any_type_dependent_arguments_p (*args
))
2541 result
= build_min_nt_call_vec (orig_fn
, *args
);
2542 SET_EXPR_LOCATION (result
, cp_expr_loc_or_input_loc (fn
));
2543 KOENIG_LOOKUP_P (result
) = koenig_p
;
2544 if (is_overloaded_fn (fn
))
2549 bool abnormal
= true;
2550 for (lkp_iterator
iter (fn
); abnormal
&& iter
; ++iter
)
2552 tree fndecl
= STRIP_TEMPLATE (*iter
);
2553 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2554 || !TREE_THIS_VOLATILE (fndecl
))
2557 /* FIXME: Stop warning about falling off end of non-void
2558 function. But this is wrong. Even if we only see
2559 no-return fns at this point, we could select a
2560 future-defined return fn during instantiation. Or
2563 current_function_returns_abnormally
= 1;
2567 orig_args
= make_tree_vector_copy (*args
);
2568 if (!BASELINK_P (fn
)
2569 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2570 && TREE_TYPE (fn
) != unknown_type_node
)
2571 fn
= build_non_dependent_expr (fn
);
2572 make_args_non_dependent (*args
);
2575 if (TREE_CODE (fn
) == COMPONENT_REF
)
2577 tree member
= TREE_OPERAND (fn
, 1);
2578 if (BASELINK_P (member
))
2580 tree object
= TREE_OPERAND (fn
, 0);
2581 return build_new_method_call (object
, member
,
2584 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2591 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2592 if (TREE_CODE (fn
) == ADDR_EXPR
2593 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2594 fn
= TREE_OPERAND (fn
, 0);
2596 if (is_overloaded_fn (fn
))
2597 fn
= baselink_for_fns (fn
);
2600 if (BASELINK_P (fn
))
2604 /* A call to a member function. From [over.call.func]:
2606 If the keyword this is in scope and refers to the class of
2607 that member function, or a derived class thereof, then the
2608 function call is transformed into a qualified function call
2609 using (*this) as the postfix-expression to the left of the
2610 . operator.... [Otherwise] a contrived object of type T
2611 becomes the implied object argument.
2615 struct A { void f(); };
2616 struct B : public A {};
2617 struct C : public A { void g() { B::f(); }};
2619 "the class of that member function" refers to `A'. But 11.2
2620 [class.access.base] says that we need to convert 'this' to B* as
2621 part of the access, so we pass 'B' to maybe_dummy_object. */
2623 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2625 /* A constructor call always uses a dummy object. (This constructor
2626 call which has the form A::A () is actually invalid and we are
2627 going to reject it later in build_new_method_call.) */
2628 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2631 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2634 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2636 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2641 else if (concept_check_p (fn
))
2643 /* FN is actually a template-id referring to a concept definition. */
2644 tree id
= unpack_concept_check (fn
);
2645 tree tmpl
= TREE_OPERAND (id
, 0);
2646 tree args
= TREE_OPERAND (id
, 1);
2648 if (!function_concept_p (tmpl
))
2650 error_at (EXPR_LOC_OR_LOC (fn
, input_location
),
2651 "cannot call a concept as a function");
2652 return error_mark_node
;
2655 /* Ensure the result is wrapped as a call expression. */
2656 result
= build_concept_check (tmpl
, args
, tf_warning_or_error
);
2658 else if (is_overloaded_fn (fn
))
2660 /* If the function is an overloaded builtin, resolve it. */
2661 if (TREE_CODE (fn
) == FUNCTION_DECL
2662 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2663 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2664 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2668 if (warn_sizeof_pointer_memaccess
2669 && (complain
& tf_warning
)
2670 && !vec_safe_is_empty (*args
)
2671 && !processing_template_decl
)
2673 location_t sizeof_arg_loc
[3];
2676 for (i
= 0; i
< 3; i
++)
2680 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2681 sizeof_arg
[i
] = NULL_TREE
;
2682 if (i
>= (*args
)->length ())
2685 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2687 if (SIZEOF_EXPR_TYPE_P (t
))
2688 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2690 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2691 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2693 sizeof_pointer_memaccess_warning
2694 (sizeof_arg_loc
, fn
, *args
,
2695 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2698 if ((complain
& tf_warning
)
2699 && TREE_CODE (fn
) == FUNCTION_DECL
2700 && fndecl_built_in_p (fn
, BUILT_IN_MEMSET
)
2701 && vec_safe_length (*args
) == 3
2702 && !any_type_dependent_arguments_p (*args
))
2704 tree arg0
= (*orig_args
)[0];
2705 tree arg1
= (*orig_args
)[1];
2706 tree arg2
= (*orig_args
)[2];
2707 int literal_mask
= ((literal_integer_zerop (arg1
) << 1)
2708 | (literal_integer_zerop (arg2
) << 2));
2709 warn_for_memset (input_location
, arg0
, arg2
, literal_mask
);
2712 /* A call to a namespace-scope function. */
2713 result
= build_new_function_call (fn
, args
, complain
);
2716 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2718 if (!vec_safe_is_empty (*args
))
2719 error ("arguments to destructor are not allowed");
2720 /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
2721 which case the postfix-expression is a possibly-parenthesized class
2722 member access), the function call destroys the object of scalar type
2723 denoted by the object expression of the class member access. */
2724 tree ob
= TREE_OPERAND (fn
, 0);
2726 result
= build_trivial_dtor_call (ob
, true);
2728 /* No location to clobber. */
2729 result
= convert_to_void (ob
, ICV_STATEMENT
, complain
);
2731 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2732 /* If the "function" is really an object of class type, it might
2733 have an overloaded `operator ()'. */
2734 result
= build_op_call (fn
, args
, complain
);
2737 /* A call where the function is unknown. */
2738 result
= cp_build_function_call_vec (fn
, args
, complain
);
2740 if (processing_template_decl
&& result
!= error_mark_node
)
2742 if (INDIRECT_REF_P (result
))
2743 result
= TREE_OPERAND (result
, 0);
2744 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2745 SET_EXPR_LOCATION (result
, input_location
);
2746 KOENIG_LOOKUP_P (result
) = koenig_p
;
2747 release_tree_vector (orig_args
);
2748 result
= convert_from_reference (result
);
2754 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2755 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2756 POSTDECREMENT_EXPR.) */
2759 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2761 /* input_location holds the location of the trailing operator token.
2762 Build a location of the form:
2765 with the caret at the operator token, ranging from the start
2766 of EXPR to the end of the operator token. */
2767 location_t combined_loc
= make_location (input_location
,
2769 get_finish (input_location
));
2770 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2771 tf_warning_or_error
);
2772 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2773 result
.set_location (combined_loc
);
2777 /* Finish a use of `this'. Returns an expression for `this'. */
2780 finish_this_expr (void)
2782 tree result
= NULL_TREE
;
2784 if (current_class_ptr
)
2786 tree type
= TREE_TYPE (current_class_ref
);
2788 /* In a lambda expression, 'this' refers to the captured 'this'. */
2789 if (LAMBDA_TYPE_P (type
))
2790 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2792 result
= current_class_ptr
;
2796 /* The keyword 'this' is a prvalue expression. */
2797 return rvalue (result
);
2799 tree fn
= current_nonlambda_function ();
2800 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2801 error ("%<this%> is unavailable for static member functions");
2803 error ("invalid use of %<this%> in non-member function");
2805 error ("invalid use of %<this%> at top level");
2806 return error_mark_node
;
2809 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2810 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2811 the TYPE for the type given. If SCOPE is non-NULL, the expression
2812 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2815 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2818 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2819 return error_mark_node
;
2821 gcc_assert (TYPE_P (destructor
));
2823 if (!processing_template_decl
)
2825 if (scope
== error_mark_node
)
2827 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2828 return error_mark_node
;
2830 if (is_auto (destructor
))
2831 destructor
= TREE_TYPE (object
);
2832 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2835 "qualified type %qT does not match destructor name ~%qT",
2837 return error_mark_node
;
2841 /* [expr.pseudo] says both:
2843 The type designated by the pseudo-destructor-name shall be
2844 the same as the object type.
2848 The cv-unqualified versions of the object type and of the
2849 type designated by the pseudo-destructor-name shall be the
2852 We implement the more generous second sentence, since that is
2853 what most other compilers do. */
2854 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2857 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2858 return error_mark_node
;
2862 tree type
= (type_dependent_expression_p (object
)
2863 ? NULL_TREE
: void_type_node
);
2865 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, type
, object
,
2869 /* Finish an expression of the form CODE EXPR. */
2872 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
2873 tsubst_flags_t complain
)
2875 /* Build a location of the form:
2878 with the caret at the operator token, ranging from the start
2879 of the operator token to the end of EXPR. */
2880 location_t combined_loc
= make_location (op_loc
,
2881 op_loc
, expr
.get_finish ());
2882 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
, complain
);
2883 /* TODO: build_x_unary_op doesn't always honor the location. */
2884 result
.set_location (combined_loc
);
2886 if (result
== error_mark_node
)
2889 if (!(complain
& tf_warning
))
2892 tree result_ovl
= result
;
2893 tree expr_ovl
= expr
;
2895 if (!processing_template_decl
)
2896 expr_ovl
= cp_fully_fold (expr_ovl
);
2898 if (!CONSTANT_CLASS_P (expr_ovl
)
2899 || TREE_OVERFLOW_P (expr_ovl
))
2902 if (!processing_template_decl
)
2903 result_ovl
= cp_fully_fold (result_ovl
);
2905 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
2906 overflow_warning (combined_loc
, result_ovl
);
2911 /* Finish a compound-literal expression or C++11 functional cast with aggregate
2912 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
2916 finish_compound_literal (tree type
, tree compound_literal
,
2917 tsubst_flags_t complain
,
2920 if (type
== error_mark_node
)
2921 return error_mark_node
;
2923 if (TYPE_REF_P (type
))
2926 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2927 complain
, fcl_context
);
2928 /* The prvalue is then used to direct-initialize the reference. */
2929 tree r
= (perform_implicit_conversion_flags
2930 (type
, compound_literal
, complain
, LOOKUP_NORMAL
));
2931 return convert_from_reference (r
);
2934 if (!TYPE_OBJ_P (type
))
2936 if (complain
& tf_error
)
2937 error ("compound literal of non-object type %qT", type
);
2938 return error_mark_node
;
2941 if (tree anode
= type_uses_auto (type
))
2942 if (CLASS_PLACEHOLDER_TEMPLATE (anode
))
2944 type
= do_auto_deduction (type
, compound_literal
, anode
, complain
,
2946 if (type
== error_mark_node
)
2947 return error_mark_node
;
2950 /* Used to hold a copy of the compound literal in a template. */
2951 tree orig_cl
= NULL_TREE
;
2953 if (processing_template_decl
)
2955 const bool dependent_p
2956 = (instantiation_dependent_expression_p (compound_literal
)
2957 || dependent_type_p (type
));
2959 /* We're about to return, no need to copy. */
2960 orig_cl
= compound_literal
;
2962 /* We're going to need a copy. */
2963 orig_cl
= unshare_constructor (compound_literal
);
2964 TREE_TYPE (orig_cl
) = type
;
2965 /* Mark the expression as a compound literal. */
2966 TREE_HAS_CONSTRUCTOR (orig_cl
) = 1;
2967 /* And as instantiation-dependent. */
2968 CONSTRUCTOR_IS_DEPENDENT (orig_cl
) = dependent_p
;
2969 if (fcl_context
== fcl_c99
)
2970 CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl
) = 1;
2971 /* If the compound literal is dependent, we're done for now. */
2974 /* Otherwise, do go on to e.g. check narrowing. */
2977 type
= complete_type (type
);
2979 if (TYPE_NON_AGGREGATE_CLASS (type
))
2981 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2982 everywhere that deals with function arguments would be a pain, so
2983 just wrap it in a TREE_LIST. The parser set a flag so we know
2984 that it came from T{} rather than T({}). */
2985 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2986 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2987 return build_functional_cast (input_location
, type
,
2988 compound_literal
, complain
);
2991 if (TREE_CODE (type
) == ARRAY_TYPE
2992 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2993 return error_mark_node
;
2994 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2995 if (SCALAR_TYPE_P (type
)
2996 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
))
2998 tree t
= instantiate_non_dependent_expr_sfinae (compound_literal
,
3000 if (!check_narrowing (type
, t
, complain
))
3001 return error_mark_node
;
3003 if (TREE_CODE (type
) == ARRAY_TYPE
3004 && TYPE_DOMAIN (type
) == NULL_TREE
)
3006 cp_complete_array_type_or_error (&type
, compound_literal
,
3008 if (type
== error_mark_node
)
3009 return error_mark_node
;
3011 compound_literal
= digest_init_flags (type
, compound_literal
,
3012 LOOKUP_NORMAL
| LOOKUP_NO_NARROWING
,
3014 if (compound_literal
== error_mark_node
)
3015 return error_mark_node
;
3017 /* If we're in a template, return the original compound literal. */
3021 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
3023 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
3024 if (fcl_context
== fcl_c99
)
3025 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
3028 /* Put static/constant array temporaries in static variables. */
3029 /* FIXME all C99 compound literals should be variables rather than C++
3030 temporaries, unless they are used as an aggregate initializer. */
3031 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
3032 && fcl_context
== fcl_c99
3033 && TREE_CODE (type
) == ARRAY_TYPE
3034 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
3035 && initializer_constant_valid_p (compound_literal
, type
))
3037 tree decl
= create_temporary_var (type
);
3038 DECL_CONTEXT (decl
) = NULL_TREE
;
3039 DECL_INITIAL (decl
) = compound_literal
;
3040 TREE_STATIC (decl
) = 1;
3041 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
3043 /* 5.19 says that a constant expression can include an
3044 lvalue-rvalue conversion applied to "a glvalue of literal type
3045 that refers to a non-volatile temporary object initialized
3046 with a constant expression". Rather than try to communicate
3047 that this VAR_DECL is a temporary, just mark it constexpr. */
3048 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
3049 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
3050 TREE_CONSTANT (decl
) = true;
3052 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
3053 decl
= pushdecl_top_level (decl
);
3054 DECL_NAME (decl
) = make_anon_name ();
3055 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
3056 /* Make sure the destructor is callable. */
3057 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
3058 if (clean
== error_mark_node
)
3059 return error_mark_node
;
3063 /* Represent other compound literals with TARGET_EXPR so we produce
3064 an lvalue, but can elide copies. */
3065 if (!VECTOR_TYPE_P (type
))
3066 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
3068 return compound_literal
;
3071 /* Return the declaration for the function-name variable indicated by
3075 finish_fname (tree id
)
3079 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
3080 if (processing_template_decl
&& current_function_decl
3081 && decl
!= error_mark_node
)
3082 decl
= DECL_NAME (decl
);
3086 /* Finish a translation unit. */
3089 finish_translation_unit (void)
3091 /* In case there were missing closebraces,
3092 get us back to the global binding level. */
3094 while (current_namespace
!= global_namespace
)
3097 /* Do file scope __FUNCTION__ et al. */
3098 finish_fname_decls ();
3100 if (scope_chain
->omp_declare_target_attribute
)
3103 error ("%<#pragma omp declare target%> without corresponding "
3104 "%<#pragma omp end declare target%>");
3105 scope_chain
->omp_declare_target_attribute
= 0;
3109 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
3110 Returns the parameter. */
3113 finish_template_type_parm (tree aggr
, tree identifier
)
3115 if (aggr
!= class_type_node
)
3117 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
3118 aggr
= class_type_node
;
3121 return build_tree_list (aggr
, identifier
);
3124 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
3125 Returns the parameter. */
3128 finish_template_template_parm (tree aggr
, tree identifier
)
3130 tree decl
= build_decl (input_location
,
3131 TYPE_DECL
, identifier
, NULL_TREE
);
3133 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
3134 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
3135 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
3136 DECL_ARTIFICIAL (decl
) = 1;
3138 /* Associate the constraints with the underlying declaration,
3139 not the template. */
3140 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
3141 tree constr
= build_constraints (reqs
, NULL_TREE
);
3142 set_constraints (decl
, constr
);
3144 end_template_decl ();
3146 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
3148 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
3149 /*is_primary=*/true, /*is_partial=*/false,
3152 return finish_template_type_parm (aggr
, tmpl
);
3155 /* ARGUMENT is the default-argument value for a template template
3156 parameter. If ARGUMENT is invalid, issue error messages and return
3157 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
3160 check_template_template_default_arg (tree argument
)
3162 if (TREE_CODE (argument
) != TEMPLATE_DECL
3163 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
3164 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
3166 if (TREE_CODE (argument
) == TYPE_DECL
)
3167 error ("invalid use of type %qT as a default value for a template "
3168 "template-parameter", TREE_TYPE (argument
));
3170 error ("invalid default argument for a template template parameter");
3171 return error_mark_node
;
3177 /* Begin a class definition, as indicated by T. */
3180 begin_class_definition (tree t
)
3182 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
3183 return error_mark_node
;
3185 if (processing_template_parmlist
&& !LAMBDA_TYPE_P (t
))
3187 error ("definition of %q#T inside template parameter list", t
);
3188 return error_mark_node
;
3191 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
3192 are passed the same as decimal scalar types. */
3193 if (TREE_CODE (t
) == RECORD_TYPE
3194 && !processing_template_decl
)
3196 tree ns
= TYPE_CONTEXT (t
);
3197 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
3198 && DECL_CONTEXT (ns
) == std_node
3200 && id_equal (DECL_NAME (ns
), "decimal"))
3202 const char *n
= TYPE_NAME_STRING (t
);
3203 if ((strcmp (n
, "decimal32") == 0)
3204 || (strcmp (n
, "decimal64") == 0)
3205 || (strcmp (n
, "decimal128") == 0))
3206 TYPE_TRANSPARENT_AGGR (t
) = 1;
3210 /* A non-implicit typename comes from code like:
3212 template <typename T> struct A {
3213 template <typename U> struct A<T>::B ...
3215 This is erroneous. */
3216 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
3218 error ("invalid definition of qualified type %qT", t
);
3219 t
= error_mark_node
;
3222 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
3224 t
= make_class_type (RECORD_TYPE
);
3225 pushtag (make_anon_name (), t
);
3228 if (TYPE_BEING_DEFINED (t
))
3230 t
= make_class_type (TREE_CODE (t
));
3231 pushtag (TYPE_IDENTIFIER (t
), t
);
3236 if (!module_may_redeclare (TYPE_NAME (t
)))
3238 error ("cannot declare %qD in a different module", TYPE_NAME (t
));
3239 inform (DECL_SOURCE_LOCATION (TYPE_NAME (t
)), "declared here");
3240 return error_mark_node
;
3242 set_instantiating_module (TYPE_NAME (t
));
3243 set_defining_module (TYPE_NAME (t
));
3246 maybe_process_partial_specialization (t
);
3248 TYPE_BEING_DEFINED (t
) = 1;
3249 class_binding_level
->defining_class_p
= 1;
3251 if (flag_pack_struct
)
3254 TYPE_PACKED (t
) = 1;
3255 /* Even though the type is being defined for the first time
3256 here, there might have been a forward declaration, so there
3257 might be cv-qualified variants of T. */
3258 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
3259 TYPE_PACKED (v
) = 1;
3261 /* Reset the interface data, at the earliest possible
3262 moment, as it might have been set via a class foo;
3264 if (! TYPE_UNNAMED_P (t
))
3266 struct c_fileinfo
*finfo
= \
3267 get_fileinfo (LOCATION_FILE (input_location
));
3268 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
3269 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
3270 (t
, finfo
->interface_unknown
);
3272 reset_specialization ();
3274 /* Make a declaration for this class in its own scope. */
3275 build_self_reference ();
3280 /* Finish the member declaration given by DECL. */
3283 finish_member_declaration (tree decl
)
3285 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
3288 if (decl
== void_type_node
)
3289 /* The COMPONENT was a friend, not a member, and so there's
3290 nothing for us to do. */
3293 /* We should see only one DECL at a time. */
3294 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
3296 /* Don't add decls after definition. */
3297 gcc_assert (TYPE_BEING_DEFINED (current_class_type
)
3298 /* We can add lambda types when late parsing default
3300 || LAMBDA_TYPE_P (TREE_TYPE (decl
)));
3302 /* Set up access control for DECL. */
3304 = (current_access_specifier
== access_private_node
);
3305 TREE_PROTECTED (decl
)
3306 = (current_access_specifier
== access_protected_node
);
3307 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3309 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
3310 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
3313 /* Mark the DECL as a member of the current class, unless it's
3314 a member of an enumeration. */
3315 if (TREE_CODE (decl
) != CONST_DECL
)
3316 DECL_CONTEXT (decl
) = current_class_type
;
3318 if (TREE_CODE (decl
) == USING_DECL
)
3319 /* For now, ignore class-scope USING_DECLS, so that debugging
3320 backends do not see them. */
3321 DECL_IGNORED_P (decl
) = 1;
3323 /* Check for bare parameter packs in the non-static data member
3325 if (TREE_CODE (decl
) == FIELD_DECL
)
3327 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
3328 TREE_TYPE (decl
) = error_mark_node
;
3329 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3330 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3335 A C language linkage is ignored for the names of class members
3336 and the member function type of class member functions. */
3337 if (DECL_LANG_SPECIFIC (decl
))
3338 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3342 /* Functions and non-functions are added differently. */
3343 if (DECL_DECLARES_FUNCTION_P (decl
))
3344 add
= add_method (current_class_type
, decl
, false);
3345 /* Enter the DECL into the scope of the class, if the class
3346 isn't a closure (whose fields are supposed to be unnamed). */
3347 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3348 || pushdecl_class_level (decl
))
3353 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3354 go at the beginning. The reason is that
3355 legacy_nonfn_member_lookup searches the list in order, and we
3356 want a field name to override a type name so that the "struct
3357 stat hack" will work. In particular:
3359 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3363 if (TREE_CODE (decl
) == TYPE_DECL
)
3364 TYPE_FIELDS (current_class_type
)
3365 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3368 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3369 TYPE_FIELDS (current_class_type
) = decl
;
3372 maybe_add_class_template_decl_list (current_class_type
, decl
,
3377 /* Finish processing a complete template declaration. The PARMS are
3378 the template parameters. */
3381 finish_template_decl (tree parms
)
3384 end_template_decl ();
3386 end_specialization ();
3389 // Returns the template type of the class scope being entered. If we're
3390 // entering a constrained class scope. TYPE is the class template
3391 // scope being entered and we may need to match the intended type with
3392 // a constrained specialization. For example:
3394 // template<Object T>
3395 // struct S { void f(); }; #1
3397 // template<Object T>
3398 // void S<T>::f() { } #2
3400 // We check, in #2, that S<T> refers precisely to the type declared by
3401 // #1 (i.e., that the constraints match). Note that the following should
3402 // be an error since there is no specialization of S<T> that is
3403 // unconstrained, but this is not diagnosed here.
3405 // template<typename T>
3406 // void S<T>::f() { }
3408 // We cannot diagnose this problem here since this function also matches
3409 // qualified template names that are not part of a definition. For example:
3411 // template<Integral T, Floating_point U>
3412 // typename pair<T, U>::first_type void f(T, U);
3414 // Here, it is unlikely that there is a partial specialization of
3415 // pair constrained for for Integral and Floating_point arguments.
3417 // The general rule is: if a constrained specialization with matching
3418 // constraints is found return that type. Also note that if TYPE is not a
3419 // class-type (e.g. a typename type), then no fixup is needed.
3422 fixup_template_type (tree type
)
3424 // Find the template parameter list at the a depth appropriate to
3425 // the scope we're trying to enter.
3426 tree parms
= current_template_parms
;
3427 int depth
= template_class_depth (type
);
3428 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3429 parms
= TREE_CHAIN (parms
);
3432 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3433 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3435 // Search for a specialization whose type and constraints match.
3436 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3437 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3440 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3442 // If the type and constraints match a specialization, then we
3443 // are entering that type.
3444 if (same_type_p (type
, TREE_TYPE (specs
))
3445 && equivalent_constraints (cur_constr
, spec_constr
))
3446 return TREE_TYPE (specs
);
3447 specs
= TREE_CHAIN (specs
);
3450 // If no specialization matches, then must return the type
3451 // previously found.
3455 /* Finish processing a template-id (which names a type) of the form
3456 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3457 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3458 the scope of template-id indicated. */
3461 finish_template_type (tree name
, tree args
, int entering_scope
)
3465 type
= lookup_template_class (name
, args
,
3466 NULL_TREE
, NULL_TREE
, entering_scope
,
3467 tf_warning_or_error
| tf_user
);
3469 /* If we might be entering the scope of a partial specialization,
3470 find the one with the right constraints. */
3473 && CLASS_TYPE_P (type
)
3474 && CLASSTYPE_TEMPLATE_INFO (type
)
3475 && dependent_type_p (type
)
3476 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3477 type
= fixup_template_type (type
);
3479 if (type
== error_mark_node
)
3481 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3482 return TYPE_STUB_DECL (type
);
3484 return TYPE_NAME (type
);
3487 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3488 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3489 BASE_CLASS, or NULL_TREE if an error occurred. The
3490 ACCESS_SPECIFIER is one of
3491 access_{default,public,protected_private}_node. For a virtual base
3492 we set TREE_TYPE. */
3495 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3499 if (base
== error_mark_node
)
3501 error ("invalid base-class specification");
3504 else if (! MAYBE_CLASS_TYPE_P (base
))
3506 error ("%qT is not a class type", base
);
3511 if (cp_type_quals (base
) != 0)
3513 /* DR 484: Can a base-specifier name a cv-qualified
3515 base
= TYPE_MAIN_VARIANT (base
);
3517 result
= build_tree_list (access
, base
);
3519 TREE_TYPE (result
) = integer_type_node
;
3525 /* If FNS is a member function, a set of member functions, or a
3526 template-id referring to one or more member functions, return a
3527 BASELINK for FNS, incorporating the current access context.
3528 Otherwise, return FNS unchanged. */
3531 baselink_for_fns (tree fns
)
3536 if (BASELINK_P (fns
)
3537 || error_operand_p (fns
))
3540 scope
= ovl_scope (fns
);
3541 if (!CLASS_TYPE_P (scope
))
3544 cl
= currently_open_derived_class (scope
);
3547 cl
= TYPE_BINFO (cl
);
3548 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3551 /* Returns true iff DECL is a variable from a function outside
3555 outer_var_p (tree decl
)
3557 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3558 && DECL_FUNCTION_SCOPE_P (decl
)
3559 /* Don't get confused by temporaries. */
3561 && (DECL_CONTEXT (decl
) != current_function_decl
3562 || parsing_nsdmi ()));
3565 /* As above, but also checks that DECL is automatic. */
3568 outer_automatic_var_p (tree decl
)
3570 return (outer_var_p (decl
)
3571 && !TREE_STATIC (decl
));
3574 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3575 rewrite it for lambda capture.
3577 If ODR_USE is true, we're being called from mark_use, and we complain about
3578 use of constant variables. If ODR_USE is false, we're being called for the
3579 id-expression, and we do lambda capture. */
3582 process_outer_var_ref (tree decl
, tsubst_flags_t complain
, bool odr_use
)
3584 if (cp_unevaluated_operand
)
3586 tree type
= TREE_TYPE (decl
);
3587 if (!dependent_type_p (type
)
3588 && variably_modified_type_p (type
, NULL_TREE
))
3589 /* VLAs are used even in unevaluated context. */;
3591 /* It's not a use (3.2) if we're in an unevaluated context. */
3594 if (decl
== error_mark_node
)
3597 tree context
= DECL_CONTEXT (decl
);
3598 tree containing_function
= current_function_decl
;
3599 tree lambda_stack
= NULL_TREE
;
3600 tree lambda_expr
= NULL_TREE
;
3601 tree initializer
= convert_from_reference (decl
);
3603 /* Mark it as used now even if the use is ill-formed. */
3604 if (!mark_used (decl
, complain
))
3605 return error_mark_node
;
3607 if (parsing_nsdmi ())
3608 containing_function
= NULL_TREE
;
3610 if (containing_function
&& LAMBDA_FUNCTION_P (containing_function
))
3612 /* Check whether we've already built a proxy. */
3614 while (is_normal_capture_proxy (var
))
3615 var
= DECL_CAPTURED_VARIABLE (var
);
3616 tree d
= retrieve_local_specialization (var
);
3618 if (d
&& d
!= decl
&& is_capture_proxy (d
))
3620 if (DECL_CONTEXT (d
) == containing_function
)
3621 /* We already have an inner proxy. */
3624 /* We need to capture an outer proxy. */
3625 return process_outer_var_ref (d
, complain
, odr_use
);
3629 /* If we are in a lambda function, we can move out until we hit
3631 2. a non-lambda function, or
3632 3. a non-default capturing lambda function. */
3633 while (context
!= containing_function
3634 /* containing_function can be null with invalid generic lambdas. */
3635 && containing_function
3636 && LAMBDA_FUNCTION_P (containing_function
))
3638 tree closure
= DECL_CONTEXT (containing_function
);
3639 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3641 if (TYPE_CLASS_SCOPE_P (closure
))
3642 /* A lambda in an NSDMI (c++/64496). */
3645 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3648 lambda_stack
= tree_cons (NULL_TREE
, lambda_expr
, lambda_stack
);
3650 containing_function
= decl_function_context (containing_function
);
3653 /* In a lambda within a template, wait until instantiation time to implicitly
3654 capture a parameter pack. We want to wait because we don't know if we're
3655 capturing the whole pack or a single element, and it's OK to wait because
3656 find_parameter_packs_r walks into the lambda body. */
3657 if (context
== containing_function
3658 && DECL_PACK_P (decl
))
3661 if (lambda_expr
&& VAR_P (decl
) && DECL_ANON_UNION_VAR_P (decl
))
3663 if (complain
& tf_error
)
3664 error ("cannot capture member %qD of anonymous union", decl
);
3665 return error_mark_node
;
3667 /* Do lambda capture when processing the id-expression, not when
3668 odr-using a variable. */
3669 if (!odr_use
&& context
== containing_function
)
3670 decl
= add_default_capture (lambda_stack
,
3671 /*id=*/DECL_NAME (decl
), initializer
);
3672 /* Only an odr-use of an outer automatic variable causes an
3673 error, and a constant variable can decay to a prvalue
3674 constant without odr-use. So don't complain yet. */
3675 else if (!odr_use
&& decl_constant_var_p (decl
))
3677 else if (lambda_expr
)
3679 if (complain
& tf_error
)
3681 error ("%qD is not captured", decl
);
3682 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3683 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3684 inform (location_of (closure
),
3685 "the lambda has no capture-default");
3686 else if (TYPE_CLASS_SCOPE_P (closure
))
3687 inform (UNKNOWN_LOCATION
, "lambda in local class %q+T cannot "
3688 "capture variables from the enclosing context",
3689 TYPE_CONTEXT (closure
));
3690 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3692 return error_mark_node
;
3696 if (complain
& tf_error
)
3699 ? G_("use of local variable with automatic storage from "
3700 "containing function")
3701 : G_("use of parameter from containing function"));
3702 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3704 return error_mark_node
;
3709 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3710 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3711 if non-NULL, is the type or namespace used to explicitly qualify
3712 ID_EXPRESSION. DECL is the entity to which that name has been
3715 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3716 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3717 be set to true if this expression isn't permitted in a
3718 constant-expression, but it is otherwise not set by this function.
3719 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3720 constant-expression, but a non-constant expression is also
3723 DONE is true if this expression is a complete postfix-expression;
3724 it is false if this expression is followed by '->', '[', '(', etc.
3725 ADDRESS_P is true iff this expression is the operand of '&'.
3726 TEMPLATE_P is true iff the qualified-id was of the form
3727 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3728 appears as a template argument.
3730 If an error occurs, and it is the kind of error that might cause
3731 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3732 is the caller's responsibility to issue the message. *ERROR_MSG
3733 will be a string with static storage duration, so the caller need
3736 Return an expression for the entity, after issuing appropriate
3737 diagnostics. This function is also responsible for transforming a
3738 reference to a non-static member into a COMPONENT_REF that makes
3739 the use of "this" explicit.
3741 Upon return, *IDK will be filled in appropriately. */
3743 finish_id_expression_1 (tree id_expression
,
3747 bool integral_constant_expression_p
,
3748 bool allow_non_integral_constant_expression_p
,
3749 bool *non_integral_constant_expression_p
,
3753 bool template_arg_p
,
3754 const char **error_msg
,
3755 location_t location
)
3757 decl
= strip_using_decl (decl
);
3759 /* Initialize the output parameters. */
3760 *idk
= CP_ID_KIND_NONE
;
3763 if (id_expression
== error_mark_node
)
3764 return error_mark_node
;
3765 /* If we have a template-id, then no further lookup is
3766 required. If the template-id was for a template-class, we
3767 will sometimes have a TYPE_DECL at this point. */
3768 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3769 || TREE_CODE (decl
) == TYPE_DECL
)
3771 /* Look up the name. */
3774 if (decl
== error_mark_node
)
3776 /* Name lookup failed. */
3779 || (!dependent_type_p (scope
)
3780 && !(identifier_p (id_expression
)
3781 && IDENTIFIER_CONV_OP_P (id_expression
)
3782 && dependent_type_p (TREE_TYPE (id_expression
))))))
3784 /* If the qualifying type is non-dependent (and the name
3785 does not name a conversion operator to a dependent
3786 type), issue an error. */
3787 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3788 return error_mark_node
;
3792 /* It may be resolved via Koenig lookup. */
3793 *idk
= CP_ID_KIND_UNQUALIFIED
;
3794 return id_expression
;
3797 decl
= id_expression
;
3800 /* Remember that the name was used in the definition of
3801 the current class so that we can check later to see if
3802 the meaning would have been different after the class
3803 was entirely defined. */
3804 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3805 maybe_note_name_used_in_class (id_expression
, decl
);
3807 /* A use in unevaluated operand might not be instantiated appropriately
3808 if tsubst_copy builds a dummy parm, or if we never instantiate a
3809 generic lambda, so mark it now. */
3810 if (processing_template_decl
&& cp_unevaluated_operand
)
3811 mark_type_use (decl
);
3813 /* Disallow uses of local variables from containing functions, except
3814 within lambda-expressions. */
3815 if (outer_automatic_var_p (decl
))
3817 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3818 if (decl
== error_mark_node
)
3819 return error_mark_node
;
3822 /* Also disallow uses of function parameters outside the function
3823 body, except inside an unevaluated context (i.e. decltype). */
3824 if (TREE_CODE (decl
) == PARM_DECL
3825 && DECL_CONTEXT (decl
) == NULL_TREE
3826 && !cp_unevaluated_operand
)
3828 *error_msg
= G_("use of parameter outside function body");
3829 return error_mark_node
;
3833 /* If we didn't find anything, or what we found was a type,
3834 then this wasn't really an id-expression. */
3835 if (TREE_CODE (decl
) == TEMPLATE_DECL
3836 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3838 *error_msg
= G_("missing template arguments");
3839 return error_mark_node
;
3841 else if (TREE_CODE (decl
) == TYPE_DECL
3842 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3844 *error_msg
= G_("expected primary-expression");
3845 return error_mark_node
;
3848 /* If the name resolved to a template parameter, there is no
3849 need to look it up again later. */
3850 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3851 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3855 *idk
= CP_ID_KIND_NONE
;
3856 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3857 decl
= TEMPLATE_PARM_DECL (decl
);
3858 r
= DECL_INITIAL (decl
);
3859 if (CLASS_TYPE_P (TREE_TYPE (r
)) && !CP_TYPE_CONST_P (TREE_TYPE (r
)))
3861 /* If the entity is a template parameter object for a template
3862 parameter of type T, the type of the expression is const T. */
3863 tree ctype
= TREE_TYPE (r
);
3864 ctype
= cp_build_qualified_type (ctype
, (cp_type_quals (ctype
)
3865 | TYPE_QUAL_CONST
));
3866 r
= build1 (VIEW_CONVERT_EXPR
, ctype
, r
);
3868 r
= convert_from_reference (r
);
3869 if (integral_constant_expression_p
3870 && !dependent_type_p (TREE_TYPE (decl
))
3871 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3873 if (!allow_non_integral_constant_expression_p
)
3874 error ("template parameter %qD of type %qT is not allowed in "
3875 "an integral constant expression because it is not of "
3876 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3877 *non_integral_constant_expression_p
= true;
3883 bool dependent_p
= type_dependent_expression_p (decl
);
3885 /* If the declaration was explicitly qualified indicate
3886 that. The semantics of `A::f(3)' are different than
3887 `f(3)' if `f' is virtual. */
3889 ? CP_ID_KIND_QUALIFIED
3890 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3891 ? CP_ID_KIND_TEMPLATE_ID
3893 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3894 : CP_ID_KIND_UNQUALIFIED
)));
3898 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
3899 /* Dependent type attributes on the decl mean that the TREE_TYPE is
3900 wrong, so just return the identifier. */
3901 return id_expression
;
3903 if (DECL_CLASS_TEMPLATE_P (decl
))
3905 error ("use of class template %qT as expression", decl
);
3906 return error_mark_node
;
3909 if (TREE_CODE (decl
) == TREE_LIST
)
3911 /* Ambiguous reference to base members. */
3912 error ("request for member %qD is ambiguous in "
3913 "multiple inheritance lattice", id_expression
);
3914 print_candidates (decl
);
3915 return error_mark_node
;
3918 /* Mark variable-like entities as used. Functions are similarly
3919 marked either below or after overload resolution. */
3921 || TREE_CODE (decl
) == PARM_DECL
3922 || TREE_CODE (decl
) == CONST_DECL
3923 || TREE_CODE (decl
) == RESULT_DECL
)
3924 && !mark_used (decl
))
3925 return error_mark_node
;
3927 /* Only certain kinds of names are allowed in constant
3928 expression. Template parameters have already
3929 been handled above. */
3930 if (! error_operand_p (decl
)
3932 && integral_constant_expression_p
3933 && !decl_constant_var_p (decl
)
3934 && TREE_CODE (decl
) != CONST_DECL
3935 && !builtin_valid_in_constant_expr_p (decl
)
3936 && !concept_check_p (decl
))
3938 if (!allow_non_integral_constant_expression_p
)
3940 error ("%qD cannot appear in a constant-expression", decl
);
3941 return error_mark_node
;
3943 *non_integral_constant_expression_p
= true;
3946 if (tree wrap
= maybe_get_tls_wrapper_call (decl
))
3947 /* Replace an evaluated use of the thread_local variable with
3948 a call to its wrapper. */
3950 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3952 && variable_template_p (TREE_OPERAND (decl
, 0))
3953 && !concept_check_p (decl
))
3955 decl
= finish_template_variable (decl
);
3957 decl
= convert_from_reference (decl
);
3959 else if (concept_check_p (decl
))
3961 /* Nothing more to do. All of the analysis for concept checks
3962 is done by build_conept_id, called from the parser. */
3966 if (TREE_CODE (decl
) == SCOPE_REF
)
3968 gcc_assert (same_type_p (scope
, TREE_OPERAND (decl
, 0)));
3969 decl
= TREE_OPERAND (decl
, 1);
3972 decl
= (adjust_result_of_qualified_name_lookup
3973 (decl
, scope
, current_nonlambda_class_type()));
3975 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3978 cp_warn_deprecated_use_scopes (scope
);
3981 decl
= finish_qualified_id_expr (scope
,
3987 tf_warning_or_error
);
3989 decl
= convert_from_reference (decl
);
3991 else if (TREE_CODE (decl
) == FIELD_DECL
)
3993 /* Since SCOPE is NULL here, this is an unqualified name.
3994 Access checking has been performed during name lookup
3995 already. Turn off checking to avoid duplicate errors. */
3996 push_deferring_access_checks (dk_no_check
);
3997 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3998 /*qualifying_scope=*/NULL_TREE
);
3999 pop_deferring_access_checks ();
4001 else if (is_overloaded_fn (decl
))
4003 /* We only need to look at the first function,
4004 because all the fns share the attribute we're
4005 concerned with (all member fns or all non-members). */
4006 tree first_fn
= get_first_fn (decl
);
4007 first_fn
= STRIP_TEMPLATE (first_fn
);
4009 /* [basic.def.odr]: "A function whose name appears as a
4010 potentially-evaluated expression is odr-used if it is the unique
4013 But only mark it if it's a complete postfix-expression; in a call,
4014 ADL might select a different function, and we'll call mark_used in
4017 && !really_overloaded_fn (decl
)
4018 && !mark_used (first_fn
))
4019 return error_mark_node
;
4022 && (TREE_CODE (first_fn
) == USING_DECL
4023 || (TREE_CODE (first_fn
) == FUNCTION_DECL
4024 && DECL_FUNCTION_MEMBER_P (first_fn
)
4025 && !shared_member_p (decl
))))
4027 /* A set of member functions. */
4028 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
4029 return finish_class_member_access_expr (decl
, id_expression
,
4030 /*template_p=*/false,
4031 tf_warning_or_error
);
4034 decl
= baselink_for_fns (decl
);
4038 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
4039 && DECL_CLASS_SCOPE_P (decl
))
4041 tree context
= context_for_name_lookup (decl
);
4042 if (context
!= current_class_type
)
4044 tree path
= currently_open_derived_class (context
);
4046 /* PATH can be null for using an enum of an unrelated
4047 class; we checked its access in lookup_using_decl.
4049 ??? Should this case make a clone instead, like
4050 handle_using_decl? */
4051 gcc_assert (TREE_CODE (decl
) == CONST_DECL
);
4053 perform_or_defer_access_check (TYPE_BINFO (path
),
4055 tf_warning_or_error
);
4059 decl
= convert_from_reference (decl
);
4063 return cp_expr (decl
, location
);
4066 /* As per finish_id_expression_1, but adding a wrapper node
4067 around the result if needed to express LOCATION. */
4070 finish_id_expression (tree id_expression
,
4074 bool integral_constant_expression_p
,
4075 bool allow_non_integral_constant_expression_p
,
4076 bool *non_integral_constant_expression_p
,
4080 bool template_arg_p
,
4081 const char **error_msg
,
4082 location_t location
)
4085 = finish_id_expression_1 (id_expression
, decl
, scope
, idk
,
4086 integral_constant_expression_p
,
4087 allow_non_integral_constant_expression_p
,
4088 non_integral_constant_expression_p
,
4089 template_p
, done
, address_p
, template_arg_p
,
4090 error_msg
, location
);
4091 return result
.maybe_add_location_wrapper ();
4094 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
4095 use as a type-specifier. */
4098 finish_typeof (tree expr
)
4102 if (type_dependent_expression_p (expr
))
4104 type
= cxx_make_type (TYPEOF_TYPE
);
4105 TYPEOF_TYPE_EXPR (type
) = expr
;
4106 SET_TYPE_STRUCTURAL_EQUALITY (type
);
4111 expr
= mark_type_use (expr
);
4113 type
= unlowered_expr_type (expr
);
4115 if (!type
|| type
== unknown_type_node
)
4117 error ("type of %qE is unknown", expr
);
4118 return error_mark_node
;
4124 /* Implement the __underlying_type keyword: Return the underlying
4125 type of TYPE, suitable for use as a type-specifier. */
4128 finish_underlying_type (tree type
)
4130 tree underlying_type
;
4132 if (processing_template_decl
)
4134 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
4135 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
4136 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
4138 return underlying_type
;
4141 if (!complete_type_or_else (type
, NULL_TREE
))
4142 return error_mark_node
;
4144 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
4146 error ("%qT is not an enumeration type", type
);
4147 return error_mark_node
;
4150 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
4152 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
4153 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
4154 See finish_enum_value_list for details. */
4155 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
4157 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
4158 TYPE_UNSIGNED (underlying_type
));
4160 return underlying_type
;
4163 /* Implement the __direct_bases keyword: Return the direct base classes
4167 calculate_direct_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 vec
<tree
, va_gc
> *base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
4178 /* Virtual bases are initialized first */
4179 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4180 if (BINFO_VIRTUAL_P (binfo
))
4181 vec_safe_push (vector
, binfo
);
4183 /* Now non-virtuals */
4184 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4185 if (!BINFO_VIRTUAL_P (binfo
))
4186 vec_safe_push (vector
, binfo
);
4188 tree bases_vec
= make_tree_vec (vector
->length ());
4190 for (i
= 0; i
< vector
->length (); ++i
)
4191 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
4196 /* Implement the __bases keyword: Return the base classes
4199 /* Find morally non-virtual base classes by walking binfo hierarchy */
4200 /* Virtual base classes are handled separately in finish_bases */
4203 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
4205 /* Don't walk bases of virtual bases */
4206 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
4210 dfs_calculate_bases_post (tree binfo
, void *data_
)
4212 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
4213 if (!BINFO_VIRTUAL_P (binfo
))
4214 vec_safe_push (*data
, BINFO_TYPE (binfo
));
4218 /* Calculates the morally non-virtual base classes of a class */
4219 static vec
<tree
, va_gc
> *
4220 calculate_bases_helper (tree type
)
4222 vec
<tree
, va_gc
> *vector
= make_tree_vector ();
4224 /* Now add non-virtual base classes in order of construction */
4225 if (TYPE_BINFO (type
))
4226 dfs_walk_all (TYPE_BINFO (type
),
4227 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
4232 calculate_bases (tree type
, tsubst_flags_t complain
)
4234 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4235 || !NON_UNION_CLASS_TYPE_P (type
))
4236 return make_tree_vec (0);
4238 releasing_vec vector
;
4239 tree bases_vec
= NULL_TREE
;
4241 vec
<tree
, va_gc
> *vbases
;
4244 /* First go through virtual base classes */
4245 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
4246 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
4248 releasing_vec vbase_bases
4249 = calculate_bases_helper (BINFO_TYPE (binfo
));
4250 vec_safe_splice (vector
, vbase_bases
);
4253 /* Now for the non-virtual bases */
4254 releasing_vec nonvbases
= calculate_bases_helper (type
);
4255 vec_safe_splice (vector
, nonvbases
);
4257 /* Note that during error recovery vector->length can even be zero. */
4258 if (vector
->length () > 1)
4260 /* Last element is entire class, so don't copy */
4261 bases_vec
= make_tree_vec (vector
->length () - 1);
4263 for (i
= 0; i
< vector
->length () - 1; ++i
)
4264 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
4267 bases_vec
= make_tree_vec (0);
4273 finish_bases (tree type
, bool direct
)
4275 tree bases
= NULL_TREE
;
4277 if (!processing_template_decl
)
4279 /* Parameter packs can only be used in templates */
4280 error ("parameter pack %<__bases%> only valid in template declaration");
4281 return error_mark_node
;
4284 bases
= cxx_make_type (BASES
);
4285 BASES_TYPE (bases
) = type
;
4286 BASES_DIRECT (bases
) = direct
;
4287 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
4292 /* Perform C++-specific checks for __builtin_offsetof before calling
4296 finish_offsetof (tree object_ptr
, tree expr
, location_t loc
)
4298 /* If we're processing a template, we can't finish the semantics yet.
4299 Otherwise we can fold the entire expression now. */
4300 if (processing_template_decl
)
4302 expr
= build2 (OFFSETOF_EXPR
, size_type_node
, expr
, object_ptr
);
4303 SET_EXPR_LOCATION (expr
, loc
);
4307 if (expr
== error_mark_node
)
4308 return error_mark_node
;
4310 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4312 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4313 TREE_OPERAND (expr
, 2));
4314 return error_mark_node
;
4316 if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr
))
4317 || TREE_TYPE (expr
) == unknown_type_node
)
4319 while (TREE_CODE (expr
) == COMPONENT_REF
4320 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4321 expr
= TREE_OPERAND (expr
, 1);
4325 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4326 inform (DECL_SOURCE_LOCATION (expr
), "declared here");
4329 error ("cannot apply %<offsetof%> to member function");
4330 return error_mark_node
;
4332 if (TREE_CODE (expr
) == CONST_DECL
)
4334 error ("cannot apply %<offsetof%> to an enumerator %qD", expr
);
4335 return error_mark_node
;
4337 if (REFERENCE_REF_P (expr
))
4338 expr
= TREE_OPERAND (expr
, 0);
4339 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr
)), object_ptr
))
4340 return error_mark_node
;
4341 if (warn_invalid_offsetof
4342 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr
)))
4343 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr
)))
4344 && cp_unevaluated_operand
== 0)
4345 warning_at (loc
, OPT_Winvalid_offsetof
, "%<offsetof%> within "
4346 "non-standard-layout type %qT is conditionally-supported",
4347 TREE_TYPE (TREE_TYPE (object_ptr
)));
4348 return fold_offsetof (expr
);
4351 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4352 function is broken out from the above for the benefit of the tree-ssa
4356 simplify_aggr_init_expr (tree
*tp
)
4358 tree aggr_init_expr
= *tp
;
4360 /* Form an appropriate CALL_EXPR. */
4361 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4362 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4363 tree type
= TREE_TYPE (slot
);
4366 enum style_t
{ ctor
, arg
, pcc
} style
;
4368 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4370 #ifdef PCC_STATIC_STRUCT_RETURN
4376 gcc_assert (TREE_ADDRESSABLE (type
));
4380 call_expr
= build_call_array_loc (input_location
,
4381 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4383 aggr_init_expr_nargs (aggr_init_expr
),
4384 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4385 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4386 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4387 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4388 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4389 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4390 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4394 /* Replace the first argument to the ctor with the address of the
4396 cxx_mark_addressable (slot
);
4397 CALL_EXPR_ARG (call_expr
, 0) =
4398 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4400 else if (style
== arg
)
4402 /* Just mark it addressable here, and leave the rest to
4403 expand_call{,_inline}. */
4404 cxx_mark_addressable (slot
);
4405 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4406 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4408 else if (style
== pcc
)
4410 /* If we're using the non-reentrant PCC calling convention, then we
4411 need to copy the returned value out of the static buffer into the
4413 push_deferring_access_checks (dk_no_check
);
4414 call_expr
= build_aggr_init (slot
, call_expr
,
4415 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4416 tf_warning_or_error
);
4417 pop_deferring_access_checks ();
4418 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4421 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4423 tree init
= build_zero_init (type
, NULL_TREE
,
4424 /*static_storage_p=*/false);
4425 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4426 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4433 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4436 emit_associated_thunks (tree fn
)
4438 /* When we use vcall offsets, we emit thunks with the virtual
4439 functions to which they thunk. The whole point of vcall offsets
4440 is so that you can know statically the entire set of thunks that
4441 will ever be needed for a given virtual function, thereby
4442 enabling you to output all the thunks with the function itself. */
4443 if (DECL_VIRTUAL_P (fn
)
4444 /* Do not emit thunks for extern template instantiations. */
4445 && ! DECL_REALLY_EXTERN (fn
))
4449 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4451 if (!THUNK_ALIAS (thunk
))
4453 use_thunk (thunk
, /*emit_p=*/1);
4454 if (DECL_RESULT_THUNK_P (thunk
))
4458 for (probe
= DECL_THUNKS (thunk
);
4459 probe
; probe
= DECL_CHAIN (probe
))
4460 use_thunk (probe
, /*emit_p=*/1);
4464 gcc_assert (!DECL_THUNKS (thunk
));
4469 /* Generate RTL for FN. */
4472 expand_or_defer_fn_1 (tree fn
)
4474 /* When the parser calls us after finishing the body of a template
4475 function, we don't really want to expand the body. */
4476 if (processing_template_decl
)
4478 /* Normally, collection only occurs in rest_of_compilation. So,
4479 if we don't collect here, we never collect junk generated
4480 during the processing of templates until we hit a
4481 non-template function. It's not safe to do this inside a
4482 nested class, though, as the parser may have local state that
4483 is not a GC root. */
4484 if (!function_depth
)
4489 gcc_assert (DECL_SAVED_TREE (fn
));
4491 /* We make a decision about linkage for these functions at the end
4492 of the compilation. Until that point, we do not want the back
4493 end to output them -- but we do want it to see the bodies of
4494 these functions so that it can inline them as appropriate. */
4495 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4497 if (DECL_INTERFACE_KNOWN (fn
))
4498 /* We've already made a decision as to how this function will
4501 || DECL_IMMEDIATE_FUNCTION_P (fn
)
4502 || DECL_OMP_DECLARE_REDUCTION_P (fn
))
4503 tentative_decl_linkage (fn
);
4505 import_export_decl (fn
);
4507 /* If the user wants us to keep all inline functions, then mark
4508 this function as needed so that finish_file will make sure to
4509 output it later. Similarly, all dllexport'd functions must
4510 be emitted; there may be callers in other DLLs. */
4511 if (DECL_DECLARED_INLINE_P (fn
)
4512 && !DECL_REALLY_EXTERN (fn
)
4513 && !DECL_IMMEDIATE_FUNCTION_P (fn
)
4514 && !DECL_OMP_DECLARE_REDUCTION_P (fn
)
4515 && (flag_keep_inline_functions
4516 || (flag_keep_inline_dllexport
4517 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4520 DECL_EXTERNAL (fn
) = 0;
4524 /* If this is a constructor or destructor body, we have to clone
4526 if (maybe_clone_body (fn
))
4528 /* We don't want to process FN again, so pretend we've written
4529 it out, even though we haven't. */
4530 TREE_ASM_WRITTEN (fn
) = 1;
4531 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4532 if (!DECL_DECLARED_CONSTEXPR_P (fn
)
4533 && !(modules_p () && DECL_DECLARED_INLINE_P (fn
)))
4534 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4538 /* There's no reason to do any of the work here if we're only doing
4539 semantic analysis; this code just generates RTL. */
4540 if (flag_syntax_only
)
4542 /* Pretend that this function has been written out so that we don't try
4543 to expand it again. */
4544 TREE_ASM_WRITTEN (fn
) = 1;
4548 if (DECL_OMP_DECLARE_REDUCTION_P (fn
))
4555 expand_or_defer_fn (tree fn
)
4557 if (expand_or_defer_fn_1 (fn
))
4561 /* Expand or defer, at the whim of the compilation unit manager. */
4562 cgraph_node::finalize_function (fn
, function_depth
> 1);
4563 emit_associated_thunks (fn
);
4572 nrv_data () : visited (37) {}
4576 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4579 /* Helper function for walk_tree, used by finalize_nrv below. */
4582 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4584 class nrv_data
*dp
= (class nrv_data
*)data
;
4587 /* No need to walk into types. There wouldn't be any need to walk into
4588 non-statements, except that we have to consider STMT_EXPRs. */
4591 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4592 but differs from using NULL_TREE in that it indicates that we care
4593 about the value of the RESULT_DECL. */
4594 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4595 TREE_OPERAND (*tp
, 0) = dp
->result
;
4596 /* Change all cleanups for the NRV to only run when an exception is
4598 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4599 && CLEANUP_DECL (*tp
) == dp
->var
)
4600 CLEANUP_EH_ONLY (*tp
) = 1;
4601 /* Replace the DECL_EXPR for the NRV with an initialization of the
4602 RESULT_DECL, if needed. */
4603 else if (TREE_CODE (*tp
) == DECL_EXPR
4604 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4607 if (DECL_INITIAL (dp
->var
)
4608 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4609 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4610 DECL_INITIAL (dp
->var
));
4612 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4613 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4614 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4617 /* And replace all uses of the NRV with the RESULT_DECL. */
4618 else if (*tp
== dp
->var
)
4621 /* Avoid walking into the same tree more than once. Unfortunately, we
4622 can't just use walk_tree_without duplicates because it would only call
4623 us for the first occurrence of dp->var in the function body. */
4624 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4630 /* Keep iterating. */
4634 /* Called from finish_function to implement the named return value
4635 optimization by overriding all the RETURN_EXPRs and pertinent
4636 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4637 RESULT_DECL for the function. */
4640 finalize_nrv (tree
*tp
, tree var
, tree result
)
4642 class nrv_data data
;
4644 /* Copy name from VAR to RESULT. */
4645 DECL_NAME (result
) = DECL_NAME (var
);
4646 /* Don't forget that we take its address. */
4647 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4648 /* Finally set DECL_VALUE_EXPR to avoid assigning
4649 a stack slot at -O0 for the original var and debug info
4650 uses RESULT location for VAR. */
4651 SET_DECL_VALUE_EXPR (var
, result
);
4652 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4655 data
.result
= result
;
4656 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4659 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4662 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4663 bool need_copy_ctor
, bool need_copy_assignment
,
4666 int save_errorcount
= errorcount
;
4669 /* Always allocate 3 elements for simplicity. These are the
4670 function decls for the ctor, dtor, and assignment op.
4671 This layout is known to the three lang hooks,
4672 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4673 and cxx_omp_clause_assign_op. */
4674 info
= make_tree_vec (3);
4675 CP_OMP_CLAUSE_INFO (c
) = info
;
4677 if (need_default_ctor
|| need_copy_ctor
)
4679 if (need_default_ctor
)
4680 t
= get_default_ctor (type
);
4682 t
= get_copy_ctor (type
, tf_warning_or_error
);
4684 if (t
&& !trivial_fn_p (t
))
4685 TREE_VEC_ELT (info
, 0) = t
;
4688 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4689 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4691 if (need_copy_assignment
)
4693 t
= get_copy_assign (type
);
4695 if (t
&& !trivial_fn_p (t
))
4696 TREE_VEC_ELT (info
, 2) = t
;
4699 return errorcount
!= save_errorcount
;
4702 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4703 FIELD_DECL, otherwise return DECL itself. */
4706 omp_clause_decl_field (tree decl
)
4709 && DECL_HAS_VALUE_EXPR_P (decl
)
4710 && DECL_ARTIFICIAL (decl
)
4711 && DECL_LANG_SPECIFIC (decl
)
4712 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4714 tree f
= DECL_VALUE_EXPR (decl
);
4715 if (INDIRECT_REF_P (f
))
4716 f
= TREE_OPERAND (f
, 0);
4717 if (TREE_CODE (f
) == COMPONENT_REF
)
4719 f
= TREE_OPERAND (f
, 1);
4720 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4727 /* Adjust DECL if needed for printing using %qE. */
4730 omp_clause_printable_decl (tree decl
)
4732 tree t
= omp_clause_decl_field (decl
);
4738 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4739 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4743 omp_note_field_privatization (tree f
, tree t
)
4745 if (!omp_private_member_map
)
4746 omp_private_member_map
= new hash_map
<tree
, tree
>;
4747 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4751 omp_private_member_vec
.safe_push (f
);
4752 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4753 omp_private_member_vec
.safe_push (integer_zero_node
);
4757 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4761 omp_privatize_field (tree t
, bool shared
)
4763 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4764 if (m
== error_mark_node
)
4765 return error_mark_node
;
4766 if (!omp_private_member_map
&& !shared
)
4767 omp_private_member_map
= new hash_map
<tree
, tree
>;
4768 if (TYPE_REF_P (TREE_TYPE (t
)))
4770 gcc_assert (INDIRECT_REF_P (m
));
4771 m
= TREE_OPERAND (m
, 0);
4773 tree vb
= NULL_TREE
;
4774 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4777 v
= create_temporary_var (TREE_TYPE (m
));
4778 retrofit_lang_decl (v
);
4779 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4780 SET_DECL_VALUE_EXPR (v
, m
);
4781 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4783 omp_private_member_vec
.safe_push (t
);
4788 /* Helper function for handle_omp_array_sections. Called recursively
4789 to handle multiple array-section-subscripts. C is the clause,
4790 T current expression (initially OMP_CLAUSE_DECL), which is either
4791 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4792 expression if specified, TREE_VALUE length expression if specified,
4793 TREE_CHAIN is what it has been specified after, or some decl.
4794 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4795 set to true if any of the array-section-subscript could have length
4796 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4797 first array-section-subscript which is known not to have length
4799 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4800 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4801 all are or may have length of 1, array-section-subscript [:2] is the
4802 first one known not to have length 1. For array-section-subscript
4803 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4804 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4805 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4806 case though, as some lengths could be zero. */
4809 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4810 bool &maybe_zero_len
, unsigned int &first_non_one
,
4811 enum c_omp_region_type ort
)
4813 tree ret
, low_bound
, length
, type
;
4814 if (TREE_CODE (t
) != TREE_LIST
)
4816 if (error_operand_p (t
))
4817 return error_mark_node
;
4818 if (REFERENCE_REF_P (t
)
4819 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4820 t
= TREE_OPERAND (t
, 0);
4822 if (TREE_CODE (t
) == COMPONENT_REF
4823 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4824 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
4825 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
4826 && !type_dependent_expression_p (t
))
4828 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
4829 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
4831 error_at (OMP_CLAUSE_LOCATION (c
),
4832 "bit-field %qE in %qs clause",
4833 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4834 return error_mark_node
;
4836 while (TREE_CODE (t
) == COMPONENT_REF
)
4838 if (TREE_TYPE (TREE_OPERAND (t
, 0))
4839 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
4841 error_at (OMP_CLAUSE_LOCATION (c
),
4842 "%qE is a member of a union", t
);
4843 return error_mark_node
;
4845 t
= TREE_OPERAND (t
, 0);
4846 if (ort
== C_ORT_ACC
&& TREE_CODE (t
) == INDIRECT_REF
)
4847 t
= TREE_OPERAND (t
, 0);
4849 if (REFERENCE_REF_P (t
))
4850 t
= TREE_OPERAND (t
, 0);
4852 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
4854 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
4857 error_at (OMP_CLAUSE_LOCATION (c
),
4858 "%qD is not a variable in %qs clause", t
,
4859 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4861 error_at (OMP_CLAUSE_LOCATION (c
),
4862 "%qE is not a variable in %qs clause", t
,
4863 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4864 return error_mark_node
;
4866 else if (ort
== C_ORT_OMP
4867 && TREE_CODE (t
) == PARM_DECL
4868 && DECL_ARTIFICIAL (t
)
4869 && DECL_NAME (t
) == this_identifier
)
4871 error_at (OMP_CLAUSE_LOCATION (c
),
4872 "%<this%> allowed in OpenMP only in %<declare simd%>"
4874 return error_mark_node
;
4876 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4877 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
4879 error_at (OMP_CLAUSE_LOCATION (c
),
4880 "%qD is threadprivate variable in %qs clause", t
,
4881 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4882 return error_mark_node
;
4884 if (type_dependent_expression_p (ret
))
4886 ret
= convert_from_reference (ret
);
4890 if (ort
== C_ORT_OMP
4891 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4892 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4893 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4894 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
4895 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
4896 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4897 maybe_zero_len
, first_non_one
, ort
);
4898 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4901 type
= TREE_TYPE (ret
);
4902 low_bound
= TREE_PURPOSE (t
);
4903 length
= TREE_VALUE (t
);
4904 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4905 || (length
&& type_dependent_expression_p (length
)))
4908 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4909 return error_mark_node
;
4911 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4913 error_at (OMP_CLAUSE_LOCATION (c
),
4914 "low bound %qE of array section does not have integral type",
4916 return error_mark_node
;
4918 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4920 error_at (OMP_CLAUSE_LOCATION (c
),
4921 "length %qE of array section does not have integral type",
4923 return error_mark_node
;
4926 low_bound
= mark_rvalue_use (low_bound
);
4928 length
= mark_rvalue_use (length
);
4929 /* We need to reduce to real constant-values for checks below. */
4931 length
= fold_simple (length
);
4933 low_bound
= fold_simple (low_bound
);
4935 && TREE_CODE (low_bound
) == INTEGER_CST
4936 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4937 > TYPE_PRECISION (sizetype
))
4938 low_bound
= fold_convert (sizetype
, low_bound
);
4940 && TREE_CODE (length
) == INTEGER_CST
4941 && TYPE_PRECISION (TREE_TYPE (length
))
4942 > TYPE_PRECISION (sizetype
))
4943 length
= fold_convert (sizetype
, length
);
4944 if (low_bound
== NULL_TREE
)
4945 low_bound
= integer_zero_node
;
4947 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4948 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
4949 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
4951 if (length
!= integer_one_node
)
4953 error_at (OMP_CLAUSE_LOCATION (c
),
4954 "expected single pointer in %qs clause",
4955 c_omp_map_clause_name (c
, ort
== C_ORT_ACC
));
4956 return error_mark_node
;
4959 if (length
!= NULL_TREE
)
4961 if (!integer_nonzerop (length
))
4963 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4964 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4965 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
4966 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
4968 if (integer_zerop (length
))
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
;
4977 maybe_zero_len
= true;
4979 if (first_non_one
== types
.length ()
4980 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4983 if (TREE_CODE (type
) == ARRAY_TYPE
)
4985 if (length
== NULL_TREE
4986 && (TYPE_DOMAIN (type
) == NULL_TREE
4987 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4989 error_at (OMP_CLAUSE_LOCATION (c
),
4990 "for unknown bound array type length expression must "
4992 return error_mark_node
;
4994 if (TREE_CODE (low_bound
) == INTEGER_CST
4995 && tree_int_cst_sgn (low_bound
) == -1)
4997 error_at (OMP_CLAUSE_LOCATION (c
),
4998 "negative low bound in array section in %qs clause",
4999 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5000 return error_mark_node
;
5002 if (length
!= NULL_TREE
5003 && TREE_CODE (length
) == INTEGER_CST
5004 && tree_int_cst_sgn (length
) == -1)
5006 error_at (OMP_CLAUSE_LOCATION (c
),
5007 "negative length in array section in %qs clause",
5008 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5009 return error_mark_node
;
5011 if (TYPE_DOMAIN (type
)
5012 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
5013 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
5017 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
5018 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
5019 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5021 if (tree_int_cst_lt (size
, low_bound
))
5023 error_at (OMP_CLAUSE_LOCATION (c
),
5024 "low bound %qE above array section size "
5025 "in %qs clause", low_bound
,
5026 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5027 return error_mark_node
;
5029 if (tree_int_cst_equal (size
, low_bound
))
5031 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5032 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5033 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5034 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5036 error_at (OMP_CLAUSE_LOCATION (c
),
5037 "zero length array section in %qs clause",
5038 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5039 return error_mark_node
;
5041 maybe_zero_len
= true;
5043 else if (length
== NULL_TREE
5044 && first_non_one
== types
.length ()
5045 && tree_int_cst_equal
5046 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
5050 else if (length
== NULL_TREE
)
5052 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5053 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5054 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5055 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5056 maybe_zero_len
= true;
5057 if (first_non_one
== types
.length ())
5060 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
5062 if (tree_int_cst_lt (size
, length
))
5064 error_at (OMP_CLAUSE_LOCATION (c
),
5065 "length %qE above array section size "
5066 "in %qs clause", length
,
5067 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5068 return error_mark_node
;
5070 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5073 = size_binop (PLUS_EXPR
,
5074 fold_convert (sizetype
, low_bound
),
5075 fold_convert (sizetype
, length
));
5076 if (TREE_CODE (lbpluslen
) == INTEGER_CST
5077 && tree_int_cst_lt (size
, lbpluslen
))
5079 error_at (OMP_CLAUSE_LOCATION (c
),
5080 "high bound %qE above array section size "
5081 "in %qs clause", lbpluslen
,
5082 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5083 return error_mark_node
;
5088 else if (length
== NULL_TREE
)
5090 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5091 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5092 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5093 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5094 maybe_zero_len
= true;
5095 if (first_non_one
== types
.length ())
5099 /* For [lb:] we will need to evaluate lb more than once. */
5100 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5102 tree lb
= cp_save_expr (low_bound
);
5103 if (lb
!= low_bound
)
5105 TREE_PURPOSE (t
) = lb
;
5110 else if (TYPE_PTR_P (type
))
5112 if (length
== NULL_TREE
)
5114 if (TREE_CODE (ret
) == PARM_DECL
&& DECL_ARRAY_PARAMETER_P (ret
))
5115 error_at (OMP_CLAUSE_LOCATION (c
),
5116 "for array function parameter length expression "
5117 "must be specified");
5119 error_at (OMP_CLAUSE_LOCATION (c
),
5120 "for pointer type length expression must be specified");
5121 return error_mark_node
;
5123 if (length
!= NULL_TREE
5124 && TREE_CODE (length
) == INTEGER_CST
5125 && tree_int_cst_sgn (length
) == -1)
5127 error_at (OMP_CLAUSE_LOCATION (c
),
5128 "negative length in array section in %qs clause",
5129 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5130 return error_mark_node
;
5132 /* If there is a pointer type anywhere but in the very first
5133 array-section-subscript, the array section can't be contiguous. */
5134 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5135 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
5137 error_at (OMP_CLAUSE_LOCATION (c
),
5138 "array section is not contiguous in %qs clause",
5139 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5140 return error_mark_node
;
5145 error_at (OMP_CLAUSE_LOCATION (c
),
5146 "%qE does not have pointer or array type", ret
);
5147 return error_mark_node
;
5149 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5150 types
.safe_push (TREE_TYPE (ret
));
5151 /* We will need to evaluate lb more than once. */
5152 tree lb
= cp_save_expr (low_bound
);
5153 if (lb
!= low_bound
)
5155 TREE_PURPOSE (t
) = lb
;
5158 /* Temporarily disable -fstrong-eval-order for array reductions.
5159 The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
5160 is something the middle-end can't cope with and more importantly,
5161 it needs to be the actual base variable that is privatized, not some
5162 temporary assigned previous value of it. That, together with OpenMP
5163 saying how many times the side-effects are evaluated is unspecified,
5164 makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
5165 warning_sentinel
s (flag_strong_eval_order
,
5166 OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5167 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5168 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
);
5169 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
5173 /* Handle array sections for clause C. */
5176 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
5178 bool maybe_zero_len
= false;
5179 unsigned int first_non_one
= 0;
5180 auto_vec
<tree
, 10> types
;
5181 tree
*tp
= &OMP_CLAUSE_DECL (c
);
5182 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5183 && TREE_CODE (*tp
) == TREE_LIST
5184 && TREE_PURPOSE (*tp
)
5185 && TREE_CODE (TREE_PURPOSE (*tp
)) == TREE_VEC
)
5186 tp
= &TREE_VALUE (*tp
);
5187 tree first
= handle_omp_array_sections_1 (c
, *tp
, types
,
5188 maybe_zero_len
, first_non_one
,
5190 if (first
== error_mark_node
)
5192 if (first
== NULL_TREE
)
5194 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
5197 tree tem
= NULL_TREE
;
5198 if (processing_template_decl
)
5200 /* Need to evaluate side effects in the length expressions
5202 while (TREE_CODE (t
) == TREE_LIST
)
5204 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
5206 if (tem
== NULL_TREE
)
5207 tem
= TREE_VALUE (t
);
5209 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
5210 TREE_VALUE (t
), tem
);
5215 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
5220 unsigned int num
= types
.length (), i
;
5221 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
5222 tree condition
= NULL_TREE
;
5224 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
5225 maybe_zero_len
= true;
5226 if (processing_template_decl
&& maybe_zero_len
)
5229 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
5232 tree low_bound
= TREE_PURPOSE (t
);
5233 tree length
= TREE_VALUE (t
);
5237 && TREE_CODE (low_bound
) == INTEGER_CST
5238 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5239 > TYPE_PRECISION (sizetype
))
5240 low_bound
= fold_convert (sizetype
, low_bound
);
5242 && TREE_CODE (length
) == INTEGER_CST
5243 && TYPE_PRECISION (TREE_TYPE (length
))
5244 > TYPE_PRECISION (sizetype
))
5245 length
= fold_convert (sizetype
, length
);
5246 if (low_bound
== NULL_TREE
)
5247 low_bound
= integer_zero_node
;
5248 if (!maybe_zero_len
&& i
> first_non_one
)
5250 if (integer_nonzerop (low_bound
))
5251 goto do_warn_noncontiguous
;
5252 if (length
!= NULL_TREE
5253 && TREE_CODE (length
) == INTEGER_CST
5254 && TYPE_DOMAIN (types
[i
])
5255 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
5256 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
5260 size
= size_binop (PLUS_EXPR
,
5261 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5263 if (!tree_int_cst_equal (length
, size
))
5265 do_warn_noncontiguous
:
5266 error_at (OMP_CLAUSE_LOCATION (c
),
5267 "array section is not contiguous in %qs "
5269 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5273 if (!processing_template_decl
5274 && length
!= NULL_TREE
5275 && TREE_SIDE_EFFECTS (length
))
5277 if (side_effects
== NULL_TREE
)
5278 side_effects
= length
;
5280 side_effects
= build2 (COMPOUND_EXPR
,
5281 TREE_TYPE (side_effects
),
5282 length
, side_effects
);
5285 else if (processing_template_decl
)
5291 if (i
> first_non_one
5292 && ((length
&& integer_nonzerop (length
))
5293 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5294 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5295 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
))
5298 l
= fold_convert (sizetype
, length
);
5301 l
= size_binop (PLUS_EXPR
,
5302 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5304 l
= size_binop (MINUS_EXPR
, l
,
5305 fold_convert (sizetype
, low_bound
));
5307 if (i
> first_non_one
)
5309 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
5311 if (condition
== NULL_TREE
)
5314 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
5317 else if (size
== NULL_TREE
)
5319 size
= size_in_bytes (TREE_TYPE (types
[i
]));
5320 tree eltype
= TREE_TYPE (types
[num
- 1]);
5321 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5322 eltype
= TREE_TYPE (eltype
);
5323 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5324 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5325 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5326 size
= size_binop (EXACT_DIV_EXPR
, size
,
5327 size_in_bytes (eltype
));
5328 size
= size_binop (MULT_EXPR
, size
, l
);
5330 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
5331 size
, size_zero_node
);
5334 size
= size_binop (MULT_EXPR
, size
, l
);
5337 if (!processing_template_decl
)
5340 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
5341 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5342 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5343 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5345 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5346 size
= save_expr (size
);
5347 tree index_type
= build_index_type (size
);
5348 tree eltype
= TREE_TYPE (first
);
5349 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5350 eltype
= TREE_TYPE (eltype
);
5351 tree type
= build_array_type (eltype
, index_type
);
5352 tree ptype
= build_pointer_type (eltype
);
5353 if (TYPE_REF_P (TREE_TYPE (t
))
5354 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
5355 t
= convert_from_reference (t
);
5356 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5357 t
= build_fold_addr_expr (t
);
5358 tree t2
= build_fold_addr_expr (first
);
5359 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5360 ptrdiff_type_node
, t2
);
5361 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5362 ptrdiff_type_node
, t2
,
5363 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5364 ptrdiff_type_node
, t
));
5365 if (tree_fits_shwi_p (t2
))
5366 t
= build2 (MEM_REF
, type
, t
,
5367 build_int_cst (ptype
, tree_to_shwi (t2
)));
5370 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5372 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
5373 TREE_TYPE (t
), t
, t2
);
5374 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5376 OMP_CLAUSE_DECL (c
) = t
;
5379 OMP_CLAUSE_DECL (c
) = first
;
5380 OMP_CLAUSE_SIZE (c
) = size
;
5381 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5382 || (TREE_CODE (t
) == COMPONENT_REF
5383 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5385 if (ort
== C_ORT_OMP
|| ort
== C_ORT_ACC
)
5386 switch (OMP_CLAUSE_MAP_KIND (c
))
5388 case GOMP_MAP_ALLOC
:
5389 case GOMP_MAP_IF_PRESENT
:
5392 case GOMP_MAP_TOFROM
:
5393 case GOMP_MAP_ALWAYS_TO
:
5394 case GOMP_MAP_ALWAYS_FROM
:
5395 case GOMP_MAP_ALWAYS_TOFROM
:
5396 case GOMP_MAP_RELEASE
:
5397 case GOMP_MAP_DELETE
:
5398 case GOMP_MAP_FORCE_TO
:
5399 case GOMP_MAP_FORCE_FROM
:
5400 case GOMP_MAP_FORCE_TOFROM
:
5401 case GOMP_MAP_FORCE_PRESENT
:
5402 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5407 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5409 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
&& ort
!= C_ORT_ACC
)
5410 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
5411 else if (TREE_CODE (t
) == COMPONENT_REF
)
5412 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ATTACH_DETACH
);
5413 else if (REFERENCE_REF_P (t
)
5414 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5416 t
= TREE_OPERAND (t
, 0);
5417 gomp_map_kind k
= (ort
== C_ORT_ACC
) ? GOMP_MAP_ATTACH_DETACH
5418 : GOMP_MAP_ALWAYS_POINTER
;
5419 OMP_CLAUSE_SET_MAP_KIND (c2
, k
);
5422 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5423 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5424 && !cxx_mark_addressable (t
))
5426 OMP_CLAUSE_DECL (c2
) = t
;
5427 t
= build_fold_addr_expr (first
);
5428 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5429 ptrdiff_type_node
, t
);
5430 tree ptr
= OMP_CLAUSE_DECL (c2
);
5431 ptr
= convert_from_reference (ptr
);
5432 if (!INDIRECT_TYPE_P (TREE_TYPE (ptr
)))
5433 ptr
= build_fold_addr_expr (ptr
);
5434 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5435 ptrdiff_type_node
, t
,
5436 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5437 ptrdiff_type_node
, ptr
));
5438 OMP_CLAUSE_SIZE (c2
) = t
;
5439 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5440 OMP_CLAUSE_CHAIN (c
) = c2
;
5441 ptr
= OMP_CLAUSE_DECL (c2
);
5442 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5443 && TYPE_REF_P (TREE_TYPE (ptr
))
5444 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5446 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5448 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5449 OMP_CLAUSE_DECL (c3
) = ptr
;
5450 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
5451 || OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ATTACH_DETACH
)
5453 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5454 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5457 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5458 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5459 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5460 OMP_CLAUSE_CHAIN (c2
) = c3
;
5467 /* Return identifier to look up for omp declare reduction. */
5470 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5472 const char *p
= NULL
;
5473 const char *m
= NULL
;
5474 switch (reduction_code
)
5482 case TRUTH_ANDIF_EXPR
:
5483 case TRUTH_ORIF_EXPR
:
5484 reduction_id
= ovl_op_identifier (false, reduction_code
);
5498 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5499 return error_mark_node
;
5500 p
= IDENTIFIER_POINTER (reduction_id
);
5503 if (type
!= NULL_TREE
)
5504 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5506 const char prefix
[] = "omp declare reduction ";
5507 size_t lenp
= sizeof (prefix
);
5508 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5510 size_t len
= strlen (p
);
5511 size_t lenm
= m
? strlen (m
) + 1 : 0;
5512 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5514 memcpy (name
, prefix
, lenp
- 1);
5515 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5518 name
[lenp
+ len
- 1] = '~';
5519 memcpy (name
+ lenp
+ len
, m
, lenm
);
5521 return get_identifier (name
);
5524 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5525 FUNCTION_DECL or NULL_TREE if not found. */
5528 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5529 vec
<tree
> *ambiguousp
)
5532 tree baselink
= NULL_TREE
;
5533 if (identifier_p (id
))
5536 bool nonint_cst_expression_p
;
5537 const char *error_msg
;
5538 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5539 tree decl
= lookup_name (id
);
5540 if (decl
== NULL_TREE
)
5541 decl
= error_mark_node
;
5542 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5543 &nonint_cst_expression_p
, false, true, false,
5544 false, &error_msg
, loc
);
5545 if (idk
== CP_ID_KIND_UNQUALIFIED
5546 && identifier_p (id
))
5548 vec
<tree
, va_gc
> *args
= NULL
;
5549 vec_safe_push (args
, build_reference_type (type
));
5550 id
= perform_koenig_lookup (id
, args
, tf_none
);
5553 else if (TREE_CODE (id
) == SCOPE_REF
)
5554 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5555 omp_reduction_id (ERROR_MARK
,
5556 TREE_OPERAND (id
, 1),
5558 LOOK_want::NORMAL
, false);
5561 if (fns
&& is_overloaded_fn (fns
))
5563 for (lkp_iterator
iter (get_fns (fns
)); iter
; ++iter
)
5565 tree fndecl
= *iter
;
5566 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5568 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5569 if (same_type_p (TREE_TYPE (argtype
), type
))
5577 if (id
&& BASELINK_P (fns
))
5586 if (!id
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5588 vec
<tree
> ambiguous
= vNULL
;
5589 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5591 if (ambiguousp
== NULL
)
5592 ambiguousp
= &ambiguous
;
5593 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5595 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5596 baselinkp
? baselinkp
: &baselink
,
5598 if (id
== NULL_TREE
)
5600 if (!ambiguousp
->is_empty ())
5601 ambiguousp
->safe_push (id
);
5602 else if (ret
!= NULL_TREE
)
5604 ambiguousp
->safe_push (ret
);
5605 ambiguousp
->safe_push (id
);
5611 if (ambiguousp
!= &ambiguous
)
5613 if (!ambiguous
.is_empty ())
5615 const char *str
= _("candidates are:");
5618 error_at (loc
, "user defined reduction lookup is ambiguous");
5619 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5621 inform (DECL_SOURCE_LOCATION (udr
), "%s %#qD", str
, udr
);
5623 str
= get_spaces (str
);
5625 ambiguous
.release ();
5626 ret
= error_mark_node
;
5627 baselink
= NULL_TREE
;
5632 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5633 id
, id
, tf_warning_or_error
);
5637 /* Helper function for cp_parser_omp_declare_reduction_exprs
5639 Remove CLEANUP_STMT for data (omp_priv variable).
5640 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5644 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5648 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5649 *tp
= CLEANUP_BODY (*tp
);
5650 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5652 tree decl
= DECL_EXPR_DECL (*tp
);
5653 if (!processing_template_decl
5654 && decl
== (tree
) data
5655 && DECL_INITIAL (decl
)
5656 && DECL_INITIAL (decl
) != error_mark_node
)
5658 tree list
= NULL_TREE
;
5659 append_to_statement_list_force (*tp
, &list
);
5660 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5661 decl
, DECL_INITIAL (decl
));
5662 DECL_INITIAL (decl
) = NULL_TREE
;
5663 append_to_statement_list_force (init_expr
, &list
);
5670 /* Data passed from cp_check_omp_declare_reduction to
5671 cp_check_omp_declare_reduction_r. */
5673 struct cp_check_omp_declare_reduction_data
5680 /* Helper function for cp_check_omp_declare_reduction, called via
5684 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5686 struct cp_check_omp_declare_reduction_data
*udr_data
5687 = (struct cp_check_omp_declare_reduction_data
*) data
;
5689 && !DECL_ARTIFICIAL (*tp
)
5690 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5691 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5693 location_t loc
= udr_data
->loc
;
5694 if (udr_data
->combiner_p
)
5695 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5696 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5699 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5700 "to variable %qD which is not %<omp_priv%> nor "
5708 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5711 cp_check_omp_declare_reduction (tree udr
)
5713 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5714 gcc_assert (TYPE_REF_P (type
));
5715 type
= TREE_TYPE (type
);
5717 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5719 if (type
== error_mark_node
)
5721 if (ARITHMETIC_TYPE_P (type
))
5723 static enum tree_code predef_codes
[]
5724 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5725 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5726 for (i
= 0; i
< 8; i
++)
5728 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5729 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5730 const char *n2
= IDENTIFIER_POINTER (id
);
5731 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5732 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5733 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5738 && TREE_CODE (type
) != COMPLEX_EXPR
)
5740 const char prefix_minmax
[] = "omp declare reduction m";
5741 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5742 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5743 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5744 prefix_minmax
, prefix_size
) == 0
5745 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5746 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5747 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5752 error_at (loc
, "predeclared arithmetic type %qT in "
5753 "%<#pragma omp declare reduction%>", type
);
5757 else if (FUNC_OR_METHOD_TYPE_P (type
)
5758 || TREE_CODE (type
) == ARRAY_TYPE
)
5760 error_at (loc
, "function or array type %qT in "
5761 "%<#pragma omp declare reduction%>", type
);
5764 else if (TYPE_REF_P (type
))
5766 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5770 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5772 error_at (loc
, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
5773 "type %qT in %<#pragma omp declare reduction%>", type
);
5777 tree body
= DECL_SAVED_TREE (udr
);
5778 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5781 tree_stmt_iterator tsi
;
5782 struct cp_check_omp_declare_reduction_data data
;
5783 memset (data
.stmts
, 0, sizeof data
.stmts
);
5784 for (i
= 0, tsi
= tsi_start (body
);
5785 i
< 7 && !tsi_end_p (tsi
);
5786 i
++, tsi_next (&tsi
))
5787 data
.stmts
[i
] = tsi_stmt (tsi
);
5789 gcc_assert (tsi_end_p (tsi
));
5792 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5793 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5794 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5796 data
.combiner_p
= true;
5797 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5799 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5803 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5804 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5805 data
.combiner_p
= false;
5806 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5808 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5809 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5810 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5812 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5817 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5818 an inline call. But, remap
5819 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5820 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5823 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5824 tree decl
, tree placeholder
)
5827 hash_map
<tree
, tree
> decl_map
;
5829 decl_map
.put (omp_decl1
, placeholder
);
5830 decl_map
.put (omp_decl2
, decl
);
5831 memset (&id
, 0, sizeof (id
));
5832 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5833 id
.dst_fn
= current_function_decl
;
5834 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5835 id
.decl_map
= &decl_map
;
5837 id
.copy_decl
= copy_decl_no_change
;
5838 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5839 id
.transform_new_cfg
= true;
5840 id
.transform_return_to_modify
= false;
5841 id
.transform_lang_insert_block
= NULL
;
5843 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5847 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5848 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5851 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5853 if (*tp
== (tree
) data
)
5858 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5859 Return true if there is some error and the clause should be removed. */
5862 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5864 tree t
= OMP_CLAUSE_DECL (c
);
5865 bool predefined
= false;
5866 if (TREE_CODE (t
) == TREE_LIST
)
5868 gcc_assert (processing_template_decl
);
5871 tree type
= TREE_TYPE (t
);
5872 if (TREE_CODE (t
) == MEM_REF
)
5873 type
= TREE_TYPE (type
);
5874 if (TYPE_REF_P (type
))
5875 type
= TREE_TYPE (type
);
5876 if (TREE_CODE (type
) == ARRAY_TYPE
)
5879 gcc_assert (TREE_CODE (t
) != MEM_REF
);
5880 while (TREE_CODE (type
) == ARRAY_TYPE
)
5881 type
= TREE_TYPE (type
);
5882 if (!processing_template_decl
)
5884 t
= require_complete_type (t
);
5885 if (t
== error_mark_node
)
5887 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
5888 TYPE_SIZE_UNIT (type
));
5889 if (integer_zerop (size
))
5891 error_at (OMP_CLAUSE_LOCATION (c
),
5892 "%qE in %<reduction%> clause is a zero size array",
5893 omp_clause_printable_decl (t
));
5896 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5897 size
= save_expr (size
);
5898 tree index_type
= build_index_type (size
);
5899 tree atype
= build_array_type (type
, index_type
);
5900 tree ptype
= build_pointer_type (type
);
5901 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5902 t
= build_fold_addr_expr (t
);
5903 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
5904 OMP_CLAUSE_DECL (c
) = t
;
5907 if (type
== error_mark_node
)
5909 else if (ARITHMETIC_TYPE_P (type
))
5910 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5919 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5926 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5930 case TRUTH_ANDIF_EXPR
:
5931 case TRUTH_ORIF_EXPR
:
5932 if (FLOAT_TYPE_P (type
))
5939 else if (TYPE_READONLY (type
))
5941 error_at (OMP_CLAUSE_LOCATION (c
),
5942 "%qE has const type for %<reduction%>",
5943 omp_clause_printable_decl (t
));
5946 else if (!processing_template_decl
)
5948 t
= require_complete_type (t
);
5949 if (t
== error_mark_node
)
5951 OMP_CLAUSE_DECL (c
) = t
;
5956 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5959 else if (processing_template_decl
)
5961 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) == error_mark_node
)
5966 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5968 type
= TYPE_MAIN_VARIANT (type
);
5969 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5970 if (id
== NULL_TREE
)
5971 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5972 NULL_TREE
, NULL_TREE
);
5973 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5976 if (id
== error_mark_node
)
5979 tree body
= DECL_SAVED_TREE (id
);
5982 if (TREE_CODE (body
) == STATEMENT_LIST
)
5984 tree_stmt_iterator tsi
;
5985 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
5988 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5989 atype
= TREE_TYPE (atype
);
5990 bool need_static_cast
= !same_type_p (type
, atype
);
5991 memset (stmts
, 0, sizeof stmts
);
5992 for (i
= 0, tsi
= tsi_start (body
);
5993 i
< 7 && !tsi_end_p (tsi
);
5994 i
++, tsi_next (&tsi
))
5995 stmts
[i
] = tsi_stmt (tsi
);
5996 gcc_assert (tsi_end_p (tsi
));
6000 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
6001 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
6002 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
6003 DECL_ARTIFICIAL (placeholder
) = 1;
6004 DECL_IGNORED_P (placeholder
) = 1;
6005 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
6006 if (TREE_CODE (t
) == MEM_REF
)
6008 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
6010 DECL_ARTIFICIAL (decl_placeholder
) = 1;
6011 DECL_IGNORED_P (decl_placeholder
) = 1;
6012 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
6014 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
6015 cxx_mark_addressable (placeholder
);
6016 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
6017 && (decl_placeholder
6018 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6019 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6020 : OMP_CLAUSE_DECL (c
));
6021 tree omp_out
= placeholder
;
6022 tree omp_in
= decl_placeholder
? decl_placeholder
6023 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6024 if (need_static_cast
)
6026 tree rtype
= build_reference_type (atype
);
6027 omp_out
= build_static_cast (input_location
,
6029 tf_warning_or_error
);
6030 omp_in
= build_static_cast (input_location
,
6032 tf_warning_or_error
);
6033 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
6035 omp_out
= convert_from_reference (omp_out
);
6036 omp_in
= convert_from_reference (omp_in
);
6038 OMP_CLAUSE_REDUCTION_MERGE (c
)
6039 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
6040 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
6044 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
6045 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
6046 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3]))
6047 && (decl_placeholder
6048 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6049 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6050 : OMP_CLAUSE_DECL (c
));
6051 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
6052 cxx_mark_addressable (placeholder
);
6053 tree omp_priv
= decl_placeholder
? decl_placeholder
6054 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6055 tree omp_orig
= placeholder
;
6056 if (need_static_cast
)
6060 error_at (OMP_CLAUSE_LOCATION (c
),
6061 "user defined reduction with constructor "
6062 "initializer for base class %qT", atype
);
6065 tree rtype
= build_reference_type (atype
);
6066 omp_priv
= build_static_cast (input_location
,
6068 tf_warning_or_error
);
6069 omp_orig
= build_static_cast (input_location
,
6071 tf_warning_or_error
);
6072 if (omp_priv
== error_mark_node
6073 || omp_orig
== error_mark_node
)
6075 omp_priv
= convert_from_reference (omp_priv
);
6076 omp_orig
= convert_from_reference (omp_orig
);
6079 *need_default_ctor
= true;
6080 OMP_CLAUSE_REDUCTION_INIT (c
)
6081 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
6082 DECL_EXPR_DECL (stmts
[3]),
6083 omp_priv
, omp_orig
);
6084 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
6085 find_omp_placeholder_r
, placeholder
, NULL
))
6086 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
6090 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
6091 *need_default_ctor
= true;
6095 tree v
= decl_placeholder
? decl_placeholder
6096 : convert_from_reference (t
);
6097 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
6098 init
= build_constructor (TREE_TYPE (v
), NULL
);
6100 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
6101 OMP_CLAUSE_REDUCTION_INIT (c
)
6102 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
6107 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
6111 error_at (OMP_CLAUSE_LOCATION (c
),
6112 "user defined reduction not found for %qE",
6113 omp_clause_printable_decl (t
));
6116 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
6117 gcc_assert (TYPE_SIZE_UNIT (type
)
6118 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
6122 /* Called from finish_struct_1. linear(this) or linear(this:step)
6123 clauses might not be finalized yet because the class has been incomplete
6124 when parsing #pragma omp declare simd methods. Fix those up now. */
6127 finish_omp_declare_simd_methods (tree t
)
6129 if (processing_template_decl
)
6132 for (tree x
= TYPE_FIELDS (t
); x
; x
= DECL_CHAIN (x
))
6134 if (TREE_CODE (x
) == USING_DECL
6135 || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x
))
6137 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
6138 if (!ods
|| !TREE_VALUE (ods
))
6140 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
6141 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
6142 && integer_zerop (OMP_CLAUSE_DECL (c
))
6143 && OMP_CLAUSE_LINEAR_STEP (c
)
6144 && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
))))
6146 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
6147 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
6148 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
6149 sizetype
, s
, TYPE_SIZE_UNIT (t
));
6150 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
6155 /* Adjust sink depend clause to take into account pointer offsets.
6157 Return TRUE if there was a problem processing the offset, and the
6158 whole clause should be removed. */
6161 cp_finish_omp_clause_depend_sink (tree sink_clause
)
6163 tree t
= OMP_CLAUSE_DECL (sink_clause
);
6164 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
6166 /* Make sure we don't adjust things twice for templates. */
6167 if (processing_template_decl
)
6170 for (; t
; t
= TREE_CHAIN (t
))
6172 tree decl
= TREE_VALUE (t
);
6173 if (TYPE_PTR_P (TREE_TYPE (decl
)))
6175 tree offset
= TREE_PURPOSE (t
);
6176 bool neg
= wi::neg_p (wi::to_wide (offset
));
6177 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
6178 decl
= mark_rvalue_use (decl
);
6179 decl
= convert_from_reference (decl
);
6180 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
6181 neg
? MINUS_EXPR
: PLUS_EXPR
,
6183 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
6184 MINUS_EXPR
, sizetype
,
6185 fold_convert (sizetype
, t2
),
6186 fold_convert (sizetype
, decl
));
6187 if (t2
== error_mark_node
)
6189 TREE_PURPOSE (t
) = t2
;
6195 /* Finish OpenMP iterators ITER. Return true if they are errorneous
6196 and clauses containing them should be removed. */
6199 cp_omp_finish_iterators (tree iter
)
6202 for (tree it
= iter
; it
; it
= TREE_CHAIN (it
))
6204 tree var
= TREE_VEC_ELT (it
, 0);
6205 tree begin
= TREE_VEC_ELT (it
, 1);
6206 tree end
= TREE_VEC_ELT (it
, 2);
6207 tree step
= TREE_VEC_ELT (it
, 3);
6209 tree type
= TREE_TYPE (var
);
6210 location_t loc
= DECL_SOURCE_LOCATION (var
);
6211 if (type
== error_mark_node
)
6216 if (type_dependent_expression_p (var
))
6218 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
6220 error_at (loc
, "iterator %qD has neither integral nor pointer type",
6225 else if (TYPE_READONLY (type
))
6227 error_at (loc
, "iterator %qD has const qualified type", var
);
6231 if (type_dependent_expression_p (begin
)
6232 || type_dependent_expression_p (end
)
6233 || type_dependent_expression_p (step
))
6235 else if (error_operand_p (step
))
6240 else if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
6242 error_at (EXPR_LOC_OR_LOC (step
, loc
),
6243 "iterator step with non-integral type");
6248 begin
= mark_rvalue_use (begin
);
6249 end
= mark_rvalue_use (end
);
6250 step
= mark_rvalue_use (step
);
6251 begin
= cp_build_c_cast (input_location
, type
, begin
,
6252 tf_warning_or_error
);
6253 end
= cp_build_c_cast (input_location
, type
, end
,
6254 tf_warning_or_error
);
6256 if (!processing_template_decl
)
6257 step
= orig_step
= save_expr (step
);
6258 tree stype
= POINTER_TYPE_P (type
) ? sizetype
: type
;
6259 step
= cp_build_c_cast (input_location
, stype
, step
,
6260 tf_warning_or_error
);
6261 if (POINTER_TYPE_P (type
) && !processing_template_decl
)
6263 begin
= save_expr (begin
);
6264 step
= pointer_int_sum (loc
, PLUS_EXPR
, begin
, step
);
6265 step
= fold_build2_loc (loc
, MINUS_EXPR
, sizetype
,
6266 fold_convert (sizetype
, step
),
6267 fold_convert (sizetype
, begin
));
6268 step
= fold_convert (ssizetype
, step
);
6270 if (!processing_template_decl
)
6272 begin
= maybe_constant_value (begin
);
6273 end
= maybe_constant_value (end
);
6274 step
= maybe_constant_value (step
);
6275 orig_step
= maybe_constant_value (orig_step
);
6277 if (integer_zerop (step
))
6279 error_at (loc
, "iterator %qD has zero step", var
);
6284 if (begin
== error_mark_node
6285 || end
== error_mark_node
6286 || step
== error_mark_node
6287 || orig_step
== error_mark_node
)
6293 if (!processing_template_decl
)
6295 begin
= fold_build_cleanup_point_expr (TREE_TYPE (begin
), begin
);
6296 end
= fold_build_cleanup_point_expr (TREE_TYPE (end
), end
);
6297 step
= fold_build_cleanup_point_expr (TREE_TYPE (step
), step
);
6298 orig_step
= fold_build_cleanup_point_expr (TREE_TYPE (orig_step
),
6301 hash_set
<tree
> pset
;
6303 for (it2
= TREE_CHAIN (it
); it2
; it2
= TREE_CHAIN (it2
))
6305 tree var2
= TREE_VEC_ELT (it2
, 0);
6306 tree begin2
= TREE_VEC_ELT (it2
, 1);
6307 tree end2
= TREE_VEC_ELT (it2
, 2);
6308 tree step2
= TREE_VEC_ELT (it2
, 3);
6309 location_t loc2
= DECL_SOURCE_LOCATION (var2
);
6310 if (cp_walk_tree (&begin2
, find_omp_placeholder_r
, var
, &pset
))
6312 error_at (EXPR_LOC_OR_LOC (begin2
, loc2
),
6313 "begin expression refers to outer iterator %qD", var
);
6316 else if (cp_walk_tree (&end2
, find_omp_placeholder_r
, var
, &pset
))
6318 error_at (EXPR_LOC_OR_LOC (end2
, loc2
),
6319 "end expression refers to outer iterator %qD", var
);
6322 else if (cp_walk_tree (&step2
, find_omp_placeholder_r
, var
, &pset
))
6324 error_at (EXPR_LOC_OR_LOC (step2
, loc2
),
6325 "step expression refers to outer iterator %qD", var
);
6334 TREE_VEC_ELT (it
, 1) = begin
;
6335 TREE_VEC_ELT (it
, 2) = end
;
6336 if (processing_template_decl
)
6337 TREE_VEC_ELT (it
, 3) = orig_step
;
6340 TREE_VEC_ELT (it
, 3) = step
;
6341 TREE_VEC_ELT (it
, 4) = orig_step
;
6347 /* Ensure that pointers are used in OpenACC attach and detach clauses.
6348 Return true if an error has been detected. */
6351 cp_oacc_check_attachments (tree c
)
6353 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6356 /* OpenACC attach / detach clauses must be pointers. */
6357 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
6358 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
)
6360 tree t
= OMP_CLAUSE_DECL (c
);
6363 while (TREE_CODE (t
) == TREE_LIST
)
6366 type
= TREE_TYPE (t
);
6368 if (TREE_CODE (type
) == REFERENCE_TYPE
)
6369 type
= TREE_TYPE (type
);
6371 if (TREE_CODE (type
) != POINTER_TYPE
)
6373 error_at (OMP_CLAUSE_LOCATION (c
), "expected pointer in %qs clause",
6374 c_omp_map_clause_name (c
, true));
6382 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
6383 Remove any elements from the list that are invalid. */
6386 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
6388 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
6389 bitmap_head aligned_head
, map_head
, map_field_head
, oacc_reduction_head
;
6391 tree safelen
= NULL_TREE
;
6392 bool branch_seen
= false;
6393 bool copyprivate_seen
= false;
6394 bool ordered_seen
= false;
6395 bool order_seen
= false;
6396 bool schedule_seen
= false;
6397 bool oacc_async
= false;
6398 tree last_iterators
= NULL_TREE
;
6399 bool last_iterators_remove
= false;
6400 /* 1 if normal/task reduction has been seen, -1 if inscan reduction
6401 has been seen, -2 if mixed inscan/normal reduction diagnosed. */
6402 int reduction_seen
= 0;
6403 bool allocate_seen
= false;
6404 bool detach_seen
= false;
6405 bool mergeable_seen
= false;
6407 bitmap_obstack_initialize (NULL
);
6408 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
6409 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
6410 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
6411 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
6412 /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
6413 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
6414 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
6415 /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
6417 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
6419 if (ort
& C_ORT_ACC
)
6420 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6421 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
6427 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
6429 bool remove
= false;
6430 bool field_ok
= false;
6432 switch (OMP_CLAUSE_CODE (c
))
6434 case OMP_CLAUSE_SHARED
:
6435 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6436 goto check_dup_generic
;
6437 case OMP_CLAUSE_PRIVATE
:
6438 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6439 goto check_dup_generic
;
6440 case OMP_CLAUSE_REDUCTION
:
6441 if (reduction_seen
== 0)
6442 reduction_seen
= OMP_CLAUSE_REDUCTION_INSCAN (c
) ? -1 : 1;
6443 else if (reduction_seen
!= -2
6444 && reduction_seen
!= (OMP_CLAUSE_REDUCTION_INSCAN (c
)
6447 error_at (OMP_CLAUSE_LOCATION (c
),
6448 "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
6449 "on the same construct");
6450 reduction_seen
= -2;
6453 case OMP_CLAUSE_IN_REDUCTION
:
6454 case OMP_CLAUSE_TASK_REDUCTION
:
6455 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6456 t
= OMP_CLAUSE_DECL (c
);
6457 if (TREE_CODE (t
) == TREE_LIST
)
6459 if (handle_omp_array_sections (c
, ort
))
6464 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6465 && OMP_CLAUSE_REDUCTION_INSCAN (c
))
6467 error_at (OMP_CLAUSE_LOCATION (c
),
6468 "%<inscan%> %<reduction%> clause with array "
6473 if (TREE_CODE (t
) == TREE_LIST
)
6475 while (TREE_CODE (t
) == TREE_LIST
)
6480 gcc_assert (TREE_CODE (t
) == MEM_REF
);
6481 t
= TREE_OPERAND (t
, 0);
6482 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
6483 t
= TREE_OPERAND (t
, 0);
6484 if (TREE_CODE (t
) == ADDR_EXPR
6485 || INDIRECT_REF_P (t
))
6486 t
= TREE_OPERAND (t
, 0);
6488 tree n
= omp_clause_decl_field (t
);
6491 goto check_dup_generic_t
;
6494 cxx_mark_addressable (t
);
6495 goto check_dup_generic
;
6496 case OMP_CLAUSE_COPYPRIVATE
:
6497 copyprivate_seen
= true;
6498 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6499 goto check_dup_generic
;
6500 case OMP_CLAUSE_COPYIN
:
6501 goto check_dup_generic
;
6502 case OMP_CLAUSE_LINEAR
:
6503 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6504 t
= OMP_CLAUSE_DECL (c
);
6505 if (ort
!= C_ORT_OMP_DECLARE_SIMD
6506 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
6508 error_at (OMP_CLAUSE_LOCATION (c
),
6509 "modifier should not be specified in %<linear%> "
6510 "clause on %<simd%> or %<for%> constructs");
6511 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
6513 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6514 && !type_dependent_expression_p (t
))
6516 tree type
= TREE_TYPE (t
);
6517 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6518 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
6519 && !TYPE_REF_P (type
))
6521 error_at (OMP_CLAUSE_LOCATION (c
),
6522 "linear clause with %qs modifier applied to "
6523 "non-reference variable with %qT type",
6524 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6525 ? "ref" : "uval", TREE_TYPE (t
));
6529 if (TYPE_REF_P (type
))
6530 type
= TREE_TYPE (type
);
6531 if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
6533 if (!INTEGRAL_TYPE_P (type
)
6534 && !TYPE_PTR_P (type
))
6536 error_at (OMP_CLAUSE_LOCATION (c
),
6537 "linear clause applied to non-integral "
6538 "non-pointer variable with %qT type",
6545 t
= OMP_CLAUSE_LINEAR_STEP (c
);
6547 t
= integer_one_node
;
6548 if (t
== error_mark_node
)
6553 else if (!type_dependent_expression_p (t
)
6554 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
6555 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6556 || TREE_CODE (t
) != PARM_DECL
6557 || !TYPE_REF_P (TREE_TYPE (t
))
6558 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
6560 error_at (OMP_CLAUSE_LOCATION (c
),
6561 "linear step expression must be integral");
6567 t
= mark_rvalue_use (t
);
6568 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
6570 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
6571 goto check_dup_generic
;
6573 if (!processing_template_decl
6574 && (VAR_P (OMP_CLAUSE_DECL (c
))
6575 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
6577 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
6579 t
= maybe_constant_value (t
);
6580 if (TREE_CODE (t
) != INTEGER_CST
)
6582 error_at (OMP_CLAUSE_LOCATION (c
),
6583 "%<linear%> clause step %qE is neither "
6584 "constant nor a parameter", t
);
6589 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6590 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
6591 if (TYPE_REF_P (type
))
6592 type
= TREE_TYPE (type
);
6593 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
6595 type
= build_pointer_type (type
);
6596 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
6597 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6599 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6600 MINUS_EXPR
, sizetype
,
6601 fold_convert (sizetype
, t
),
6602 fold_convert (sizetype
, d
));
6603 if (t
== error_mark_node
)
6609 else if (TYPE_PTR_P (type
)
6610 /* Can't multiply the step yet if *this
6611 is still incomplete type. */
6612 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6613 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
6614 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
6615 || DECL_NAME (OMP_CLAUSE_DECL (c
))
6617 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
6619 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
6620 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6622 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6623 MINUS_EXPR
, sizetype
,
6624 fold_convert (sizetype
, t
),
6625 fold_convert (sizetype
, d
));
6626 if (t
== error_mark_node
)
6633 t
= fold_convert (type
, t
);
6635 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6637 goto check_dup_generic
;
6639 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6642 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6643 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6646 t
= OMP_CLAUSE_DECL (c
);
6647 check_dup_generic_t
:
6648 if (t
== current_class_ptr
6649 && ((ort
!= C_ORT_OMP_DECLARE_SIMD
&& ort
!= C_ORT_ACC
)
6650 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6651 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6653 error_at (OMP_CLAUSE_LOCATION (c
),
6654 "%<this%> allowed in OpenMP only in %<declare simd%>"
6659 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6660 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6662 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6665 error_at (OMP_CLAUSE_LOCATION (c
),
6666 "%qD is not a variable in clause %qs", t
,
6667 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6669 error_at (OMP_CLAUSE_LOCATION (c
),
6670 "%qE is not a variable in clause %qs", t
,
6671 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6674 else if ((ort
== C_ORT_ACC
6675 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
6676 || (ort
== C_ORT_OMP
6677 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
6678 || (OMP_CLAUSE_CODE (c
)
6679 == OMP_CLAUSE_USE_DEVICE_ADDR
))))
6681 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
6683 error_at (OMP_CLAUSE_LOCATION (c
),
6685 ? "%qD appears more than once in reduction clauses"
6686 : "%qD appears more than once in data clauses",
6691 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
6693 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6694 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6695 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6697 error_at (OMP_CLAUSE_LOCATION (c
),
6698 "%qD appears more than once in data clauses", t
);
6701 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6702 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6704 if (ort
== C_ORT_ACC
)
6705 error_at (OMP_CLAUSE_LOCATION (c
),
6706 "%qD appears more than once in data clauses", t
);
6708 error_at (OMP_CLAUSE_LOCATION (c
),
6709 "%qD appears both in data and map clauses", t
);
6713 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6718 && TREE_CODE (t
) == FIELD_DECL
6719 && t
== OMP_CLAUSE_DECL (c
))
6722 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
6723 == OMP_CLAUSE_SHARED
));
6724 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
6729 case OMP_CLAUSE_FIRSTPRIVATE
:
6730 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6732 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6734 t
= OMP_CLAUSE_DECL (c
);
6735 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6737 error_at (OMP_CLAUSE_LOCATION (c
),
6738 "%<this%> allowed in OpenMP only in %<declare simd%>"
6743 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6744 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6745 || TREE_CODE (t
) != FIELD_DECL
))
6747 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6750 error_at (OMP_CLAUSE_LOCATION (c
),
6751 "%qD is not a variable in clause %<firstprivate%>",
6754 error_at (OMP_CLAUSE_LOCATION (c
),
6755 "%qE is not a variable in clause %<firstprivate%>",
6759 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6760 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6762 error_at (OMP_CLAUSE_LOCATION (c
),
6763 "%qD appears more than once in data clauses", t
);
6766 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6768 if (ort
== C_ORT_ACC
)
6769 error_at (OMP_CLAUSE_LOCATION (c
),
6770 "%qD appears more than once in data clauses", t
);
6772 error_at (OMP_CLAUSE_LOCATION (c
),
6773 "%qD appears both in data and map clauses", t
);
6777 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
6778 goto handle_field_decl
;
6780 case OMP_CLAUSE_LASTPRIVATE
:
6781 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6783 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6785 t
= OMP_CLAUSE_DECL (c
);
6786 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6788 error_at (OMP_CLAUSE_LOCATION (c
),
6789 "%<this%> allowed in OpenMP only in %<declare simd%>"
6794 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6795 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6796 || TREE_CODE (t
) != FIELD_DECL
))
6798 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6801 error_at (OMP_CLAUSE_LOCATION (c
),
6802 "%qD is not a variable in clause %<lastprivate%>",
6805 error_at (OMP_CLAUSE_LOCATION (c
),
6806 "%qE is not a variable in clause %<lastprivate%>",
6810 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6811 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6813 error_at (OMP_CLAUSE_LOCATION (c
),
6814 "%qD appears more than once in data clauses", t
);
6818 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
6819 goto handle_field_decl
;
6822 t
= OMP_CLAUSE_IF_EXPR (c
);
6823 t
= maybe_convert_cond (t
);
6824 if (t
== error_mark_node
)
6826 else if (!processing_template_decl
)
6827 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6828 OMP_CLAUSE_IF_EXPR (c
) = t
;
6831 case OMP_CLAUSE_FINAL
:
6832 t
= OMP_CLAUSE_FINAL_EXPR (c
);
6833 t
= maybe_convert_cond (t
);
6834 if (t
== error_mark_node
)
6836 else if (!processing_template_decl
)
6837 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6838 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
6841 case OMP_CLAUSE_GANG
:
6842 /* Operand 1 is the gang static: argument. */
6843 t
= OMP_CLAUSE_OPERAND (c
, 1);
6846 if (t
== error_mark_node
)
6848 else if (!type_dependent_expression_p (t
)
6849 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6851 error_at (OMP_CLAUSE_LOCATION (c
),
6852 "%<gang%> static expression must be integral");
6857 t
= mark_rvalue_use (t
);
6858 if (!processing_template_decl
)
6860 t
= maybe_constant_value (t
);
6861 if (TREE_CODE (t
) == INTEGER_CST
6862 && tree_int_cst_sgn (t
) != 1
6863 && t
!= integer_minus_one_node
)
6865 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6866 "%<gang%> static value must be "
6868 t
= integer_one_node
;
6870 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6873 OMP_CLAUSE_OPERAND (c
, 1) = t
;
6875 /* Check operand 0, the num argument. */
6878 case OMP_CLAUSE_WORKER
:
6879 case OMP_CLAUSE_VECTOR
:
6880 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
6884 case OMP_CLAUSE_NUM_TASKS
:
6885 case OMP_CLAUSE_NUM_TEAMS
:
6886 case OMP_CLAUSE_NUM_THREADS
:
6887 case OMP_CLAUSE_NUM_GANGS
:
6888 case OMP_CLAUSE_NUM_WORKERS
:
6889 case OMP_CLAUSE_VECTOR_LENGTH
:
6890 t
= OMP_CLAUSE_OPERAND (c
, 0);
6891 if (t
== error_mark_node
)
6893 else if (!type_dependent_expression_p (t
)
6894 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6896 switch (OMP_CLAUSE_CODE (c
))
6898 case OMP_CLAUSE_GANG
:
6899 error_at (OMP_CLAUSE_LOCATION (c
),
6900 "%<gang%> num expression must be integral"); break;
6901 case OMP_CLAUSE_VECTOR
:
6902 error_at (OMP_CLAUSE_LOCATION (c
),
6903 "%<vector%> length expression must be integral");
6905 case OMP_CLAUSE_WORKER
:
6906 error_at (OMP_CLAUSE_LOCATION (c
),
6907 "%<worker%> num expression must be integral");
6910 error_at (OMP_CLAUSE_LOCATION (c
),
6911 "%qs expression must be integral",
6912 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6918 t
= mark_rvalue_use (t
);
6919 if (!processing_template_decl
)
6921 t
= maybe_constant_value (t
);
6922 if (TREE_CODE (t
) == INTEGER_CST
6923 && tree_int_cst_sgn (t
) != 1)
6925 switch (OMP_CLAUSE_CODE (c
))
6927 case OMP_CLAUSE_GANG
:
6928 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6929 "%<gang%> num value must be positive");
6931 case OMP_CLAUSE_VECTOR
:
6932 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6933 "%<vector%> length value must be "
6936 case OMP_CLAUSE_WORKER
:
6937 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6938 "%<worker%> num value must be "
6942 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6943 "%qs value must be positive",
6944 omp_clause_code_name
6945 [OMP_CLAUSE_CODE (c
)]);
6947 t
= integer_one_node
;
6949 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6951 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6955 case OMP_CLAUSE_SCHEDULE
:
6956 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
6959 else if (t
== error_mark_node
)
6961 else if (!type_dependent_expression_p (t
)
6962 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6964 error_at (OMP_CLAUSE_LOCATION (c
),
6965 "schedule chunk size expression must be integral");
6970 t
= mark_rvalue_use (t
);
6971 if (!processing_template_decl
)
6973 t
= maybe_constant_value (t
);
6974 if (TREE_CODE (t
) == INTEGER_CST
6975 && tree_int_cst_sgn (t
) != 1)
6977 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6978 "chunk size value must be positive");
6979 t
= integer_one_node
;
6981 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6983 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
6986 schedule_seen
= true;
6989 case OMP_CLAUSE_SIMDLEN
:
6990 case OMP_CLAUSE_SAFELEN
:
6991 t
= OMP_CLAUSE_OPERAND (c
, 0);
6992 if (t
== error_mark_node
)
6994 else if (!type_dependent_expression_p (t
)
6995 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6997 error_at (OMP_CLAUSE_LOCATION (c
),
6998 "%qs length expression must be integral",
6999 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7004 t
= mark_rvalue_use (t
);
7005 if (!processing_template_decl
)
7007 t
= maybe_constant_value (t
);
7008 if (TREE_CODE (t
) != INTEGER_CST
7009 || tree_int_cst_sgn (t
) != 1)
7011 error_at (OMP_CLAUSE_LOCATION (c
),
7012 "%qs length expression must be positive "
7013 "constant integer expression",
7014 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7018 OMP_CLAUSE_OPERAND (c
, 0) = t
;
7019 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
7024 case OMP_CLAUSE_ASYNC
:
7025 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
7026 if (t
== error_mark_node
)
7028 else if (!type_dependent_expression_p (t
)
7029 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7031 error_at (OMP_CLAUSE_LOCATION (c
),
7032 "%<async%> expression must be integral");
7037 t
= mark_rvalue_use (t
);
7038 if (!processing_template_decl
)
7039 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7040 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
7044 case OMP_CLAUSE_WAIT
:
7045 t
= OMP_CLAUSE_WAIT_EXPR (c
);
7046 if (t
== error_mark_node
)
7048 else if (!processing_template_decl
)
7049 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7050 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
7053 case OMP_CLAUSE_THREAD_LIMIT
:
7054 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
7055 if (t
== error_mark_node
)
7057 else if (!type_dependent_expression_p (t
)
7058 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7060 error_at (OMP_CLAUSE_LOCATION (c
),
7061 "%<thread_limit%> expression must be integral");
7066 t
= mark_rvalue_use (t
);
7067 if (!processing_template_decl
)
7069 t
= maybe_constant_value (t
);
7070 if (TREE_CODE (t
) == INTEGER_CST
7071 && tree_int_cst_sgn (t
) != 1)
7073 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7074 "%<thread_limit%> value must be positive");
7075 t
= integer_one_node
;
7077 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7079 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
7083 case OMP_CLAUSE_DEVICE
:
7084 t
= OMP_CLAUSE_DEVICE_ID (c
);
7085 if (t
== error_mark_node
)
7087 else if (!type_dependent_expression_p (t
)
7088 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7090 error_at (OMP_CLAUSE_LOCATION (c
),
7091 "%<device%> id must be integral");
7096 t
= mark_rvalue_use (t
);
7097 if (!processing_template_decl
)
7098 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7099 OMP_CLAUSE_DEVICE_ID (c
) = t
;
7103 case OMP_CLAUSE_DIST_SCHEDULE
:
7104 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
7107 else if (t
== error_mark_node
)
7109 else if (!type_dependent_expression_p (t
)
7110 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7112 error_at (OMP_CLAUSE_LOCATION (c
),
7113 "%<dist_schedule%> chunk size expression must be "
7119 t
= mark_rvalue_use (t
);
7120 if (!processing_template_decl
)
7121 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7122 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
7126 case OMP_CLAUSE_ALIGNED
:
7127 t
= OMP_CLAUSE_DECL (c
);
7128 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
7130 error_at (OMP_CLAUSE_LOCATION (c
),
7131 "%<this%> allowed in OpenMP only in %<declare simd%>"
7136 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7138 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7141 error_at (OMP_CLAUSE_LOCATION (c
),
7142 "%qD is not a variable in %<aligned%> clause", t
);
7144 error_at (OMP_CLAUSE_LOCATION (c
),
7145 "%qE is not a variable in %<aligned%> clause", t
);
7148 else if (!type_dependent_expression_p (t
)
7149 && !TYPE_PTR_P (TREE_TYPE (t
))
7150 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
7151 && (!TYPE_REF_P (TREE_TYPE (t
))
7152 || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
7153 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
7156 error_at (OMP_CLAUSE_LOCATION (c
),
7157 "%qE in %<aligned%> clause is neither a pointer nor "
7158 "an array nor a reference to pointer or array", t
);
7161 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7163 error_at (OMP_CLAUSE_LOCATION (c
),
7164 "%qD appears more than once in %<aligned%> clauses",
7169 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
7170 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
7171 if (t
== error_mark_node
)
7173 else if (t
== NULL_TREE
)
7175 else if (!type_dependent_expression_p (t
)
7176 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7178 error_at (OMP_CLAUSE_LOCATION (c
),
7179 "%<aligned%> clause alignment expression must "
7185 t
= mark_rvalue_use (t
);
7186 if (!processing_template_decl
)
7188 t
= maybe_constant_value (t
);
7189 if (TREE_CODE (t
) != INTEGER_CST
7190 || tree_int_cst_sgn (t
) != 1)
7192 error_at (OMP_CLAUSE_LOCATION (c
),
7193 "%<aligned%> clause alignment expression must "
7194 "be positive constant integer expression");
7198 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7200 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
7204 case OMP_CLAUSE_NONTEMPORAL
:
7205 t
= OMP_CLAUSE_DECL (c
);
7206 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7208 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7211 error_at (OMP_CLAUSE_LOCATION (c
),
7212 "%qD is not a variable in %<nontemporal%> clause",
7215 error_at (OMP_CLAUSE_LOCATION (c
),
7216 "%qE is not a variable in %<nontemporal%> clause",
7220 else if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
7222 error_at (OMP_CLAUSE_LOCATION (c
),
7223 "%qD appears more than once in %<nontemporal%> "
7228 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
7231 case OMP_CLAUSE_ALLOCATE
:
7232 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7234 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7236 t
= OMP_CLAUSE_DECL (c
);
7237 if (t
== current_class_ptr
)
7239 error_at (OMP_CLAUSE_LOCATION (c
),
7240 "%<this%> not allowed in %<allocate%> clause");
7245 && TREE_CODE (t
) != PARM_DECL
7246 && TREE_CODE (t
) != FIELD_DECL
)
7248 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7251 error_at (OMP_CLAUSE_LOCATION (c
),
7252 "%qD is not a variable in %<allocate%> clause", t
);
7254 error_at (OMP_CLAUSE_LOCATION (c
),
7255 "%qE is not a variable in %<allocate%> clause", t
);
7258 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7260 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7261 "%qD appears more than once in %<allocate%> clauses",
7267 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
7268 allocate_seen
= true;
7271 allocator
= OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
);
7272 if (error_operand_p (allocator
))
7277 if (allocator
== NULL_TREE
)
7278 goto handle_field_decl
;
7280 allocatort
= TYPE_MAIN_VARIANT (TREE_TYPE (allocator
));
7281 if (!type_dependent_expression_p (allocator
)
7282 && (TREE_CODE (allocatort
) != ENUMERAL_TYPE
7283 || TYPE_NAME (allocatort
) == NULL_TREE
7284 || TREE_CODE (TYPE_NAME (allocatort
)) != TYPE_DECL
7285 || (DECL_NAME (TYPE_NAME (allocatort
))
7286 != get_identifier ("omp_allocator_handle_t"))
7287 || (TYPE_CONTEXT (allocatort
)
7288 != DECL_CONTEXT (global_namespace
))))
7290 error_at (OMP_CLAUSE_LOCATION (c
),
7291 "%<allocate%> clause allocator expression has "
7292 "type %qT rather than %<omp_allocator_handle_t%>",
7293 TREE_TYPE (allocator
));
7298 allocator
= mark_rvalue_use (allocator
);
7299 if (!processing_template_decl
)
7300 allocator
= maybe_constant_value (allocator
);
7301 OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
) = allocator
;
7303 goto handle_field_decl
;
7305 case OMP_CLAUSE_DEPEND
:
7306 t
= OMP_CLAUSE_DECL (c
);
7309 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
7310 == OMP_CLAUSE_DEPEND_SOURCE
);
7313 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
7315 if (cp_finish_omp_clause_depend_sink (c
))
7319 if (TREE_CODE (t
) == TREE_LIST
7321 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
7323 if (TREE_PURPOSE (t
) != last_iterators
)
7324 last_iterators_remove
7325 = cp_omp_finish_iterators (TREE_PURPOSE (t
));
7326 last_iterators
= TREE_PURPOSE (t
);
7328 if (last_iterators_remove
)
7329 t
= error_mark_node
;
7332 last_iterators
= NULL_TREE
;
7334 if (TREE_CODE (t
) == TREE_LIST
)
7336 if (handle_omp_array_sections (c
, ort
))
7338 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7340 error_at (OMP_CLAUSE_LOCATION (c
),
7341 "%<depend%> clause with %<depobj%> dependence "
7342 "type on array section");
7347 if (t
== error_mark_node
)
7349 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7351 error_at (OMP_CLAUSE_LOCATION (c
),
7352 "%<this%> allowed in OpenMP only in %<declare simd%>"
7356 else if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7358 else if (!lvalue_p (t
))
7361 error_at (OMP_CLAUSE_LOCATION (c
),
7362 "%qD is not lvalue expression nor array section "
7363 "in %<depend%> clause", t
);
7365 error_at (OMP_CLAUSE_LOCATION (c
),
7366 "%qE is not lvalue expression nor array section "
7367 "in %<depend%> clause", t
);
7370 else if (TREE_CODE (t
) == COMPONENT_REF
7371 && TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7372 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7374 error_at (OMP_CLAUSE_LOCATION (c
),
7375 "bit-field %qE in %qs clause", t
, "depend");
7378 else if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7380 if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7381 ? TREE_TYPE (TREE_TYPE (t
))
7384 error_at (OMP_CLAUSE_LOCATION (c
),
7385 "%qE does not have %<omp_depend_t%> type in "
7386 "%<depend%> clause with %<depobj%> dependence "
7391 else if (c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7392 ? TREE_TYPE (TREE_TYPE (t
))
7395 error_at (OMP_CLAUSE_LOCATION (c
),
7396 "%qE should not have %<omp_depend_t%> type in "
7397 "%<depend%> clause with dependence type other than "
7403 tree addr
= cp_build_addr_expr (t
, tf_warning_or_error
);
7404 if (addr
== error_mark_node
)
7408 t
= cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c
),
7409 addr
, RO_UNARY_STAR
,
7410 tf_warning_or_error
);
7411 if (t
== error_mark_node
)
7413 else if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == TREE_LIST
7414 && TREE_PURPOSE (OMP_CLAUSE_DECL (c
))
7415 && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c
)))
7417 TREE_VALUE (OMP_CLAUSE_DECL (c
)) = t
;
7419 OMP_CLAUSE_DECL (c
) = t
;
7423 case OMP_CLAUSE_DETACH
:
7424 t
= OMP_CLAUSE_DECL (c
);
7427 error_at (OMP_CLAUSE_LOCATION (c
),
7428 "too many %qs clauses on a task construct",
7435 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
7436 if (!type_dependent_expression_p (t
)
7437 && (!INTEGRAL_TYPE_P (type
)
7438 || TREE_CODE (type
) != ENUMERAL_TYPE
7439 || (DECL_NAME (TYPE_NAME (type
))
7440 != get_identifier ("omp_event_handle_t"))))
7442 error_at (OMP_CLAUSE_LOCATION (c
),
7443 "%<detach%> clause event handle "
7444 "has type %qT rather than "
7445 "%<omp_event_handle_t%>",
7450 cxx_mark_addressable (t
);
7454 case OMP_CLAUSE_MAP
:
7456 case OMP_CLAUSE_FROM
:
7457 case OMP_CLAUSE__CACHE_
:
7458 t
= OMP_CLAUSE_DECL (c
);
7459 if (TREE_CODE (t
) == TREE_LIST
)
7461 if (handle_omp_array_sections (c
, ort
))
7465 t
= OMP_CLAUSE_DECL (c
);
7466 if (TREE_CODE (t
) != TREE_LIST
7467 && !type_dependent_expression_p (t
)
7468 && !cp_omp_mappable_type (TREE_TYPE (t
)))
7470 error_at (OMP_CLAUSE_LOCATION (c
),
7471 "array section does not have mappable type "
7473 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7474 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7477 while (TREE_CODE (t
) == ARRAY_REF
)
7478 t
= TREE_OPERAND (t
, 0);
7479 if (TREE_CODE (t
) == COMPONENT_REF
7480 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
7482 while (TREE_CODE (t
) == COMPONENT_REF
)
7483 t
= TREE_OPERAND (t
, 0);
7484 if (REFERENCE_REF_P (t
))
7485 t
= TREE_OPERAND (t
, 0);
7486 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7488 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7490 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7491 error_at (OMP_CLAUSE_LOCATION (c
),
7492 "%qD appears more than once in motion"
7494 else if (ort
== C_ORT_ACC
)
7495 error_at (OMP_CLAUSE_LOCATION (c
),
7496 "%qD appears more than once in data"
7499 error_at (OMP_CLAUSE_LOCATION (c
),
7500 "%qD appears more than once in map"
7506 bitmap_set_bit (&map_head
, DECL_UID (t
));
7507 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7511 if (cp_oacc_check_attachments (c
))
7513 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7514 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7515 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7516 /* In this case, we have a single array element which is a
7517 pointer, and we already set OMP_CLAUSE_SIZE in
7518 handle_omp_array_sections above. For attach/detach clauses,
7519 reset the OMP_CLAUSE_SIZE (representing a bias) to zero
7521 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
7524 if (t
== error_mark_node
)
7529 /* OpenACC attach / detach clauses must be pointers. */
7530 if (cp_oacc_check_attachments (c
))
7535 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7536 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7537 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7538 /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
7539 bias) to zero here, so it is not set erroneously to the pointer
7540 size later on in gimplify.c. */
7541 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
7542 if (REFERENCE_REF_P (t
)
7543 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
7545 t
= TREE_OPERAND (t
, 0);
7546 OMP_CLAUSE_DECL (c
) = t
;
7548 if ((ort
== C_ORT_ACC
|| ort
== C_ORT_OMP
)
7549 && TREE_CODE (t
) == COMPONENT_REF
7550 && TREE_CODE (TREE_OPERAND (t
, 0)) == INDIRECT_REF
)
7551 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
7552 if (TREE_CODE (t
) == COMPONENT_REF
7553 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
7554 || ort
== C_ORT_ACC
)
7555 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
7557 if (type_dependent_expression_p (t
))
7559 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7560 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7562 error_at (OMP_CLAUSE_LOCATION (c
),
7563 "bit-field %qE in %qs clause",
7564 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7567 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7569 error_at (OMP_CLAUSE_LOCATION (c
),
7570 "%qE does not have a mappable type in %qs clause",
7571 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7572 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7575 while (TREE_CODE (t
) == COMPONENT_REF
)
7577 if (TREE_TYPE (TREE_OPERAND (t
, 0))
7578 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
7581 error_at (OMP_CLAUSE_LOCATION (c
),
7582 "%qE is a member of a union", t
);
7586 t
= TREE_OPERAND (t
, 0);
7590 if (REFERENCE_REF_P (t
))
7591 t
= TREE_OPERAND (t
, 0);
7592 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7594 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
))
7595 || (ort
== C_ORT_OMP
7596 && bitmap_bit_p (&map_head
, DECL_UID (t
))))
7597 goto handle_map_references
;
7600 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7602 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7604 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7605 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7606 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
7607 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH_DETACH
))
7610 error_at (OMP_CLAUSE_LOCATION (c
),
7611 "%qD is not a variable in %qs clause", t
,
7612 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7614 error_at (OMP_CLAUSE_LOCATION (c
),
7615 "%qE is not a variable in %qs clause", t
,
7616 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7619 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7621 error_at (OMP_CLAUSE_LOCATION (c
),
7622 "%qD is threadprivate variable in %qs clause", t
,
7623 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7626 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7628 error_at (OMP_CLAUSE_LOCATION (c
),
7629 "%<this%> allowed in OpenMP only in %<declare simd%>"
7634 else if (!processing_template_decl
7635 && !TYPE_REF_P (TREE_TYPE (t
))
7636 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
7637 || (OMP_CLAUSE_MAP_KIND (c
)
7638 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
7639 && !cxx_mark_addressable (t
))
7641 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7642 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7643 || (OMP_CLAUSE_MAP_KIND (c
)
7644 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
7645 && t
== OMP_CLAUSE_DECL (c
)
7646 && !type_dependent_expression_p (t
)
7647 && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t
))
7648 ? TREE_TYPE (TREE_TYPE (t
))
7651 error_at (OMP_CLAUSE_LOCATION (c
),
7652 "%qD does not have a mappable type in %qs clause", t
,
7653 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7654 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7657 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7658 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
7659 && !type_dependent_expression_p (t
)
7660 && !INDIRECT_TYPE_P (TREE_TYPE (t
)))
7662 error_at (OMP_CLAUSE_LOCATION (c
),
7663 "%qD is not a pointer variable", t
);
7666 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7667 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
7669 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7670 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7672 error_at (OMP_CLAUSE_LOCATION (c
),
7673 "%qD appears more than once in data clauses", t
);
7676 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7678 if (ort
== C_ORT_ACC
)
7679 error_at (OMP_CLAUSE_LOCATION (c
),
7680 "%qD appears more than once in data clauses", t
);
7682 error_at (OMP_CLAUSE_LOCATION (c
),
7683 "%qD appears both in data and map clauses", t
);
7687 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7689 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
7690 && !bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7692 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7693 error_at (OMP_CLAUSE_LOCATION (c
),
7694 "%qD appears more than once in motion clauses", t
);
7695 else if (ort
== C_ORT_ACC
)
7696 error_at (OMP_CLAUSE_LOCATION (c
),
7697 "%qD appears more than once in data clauses", t
);
7699 error_at (OMP_CLAUSE_LOCATION (c
),
7700 "%qD appears more than once in map clauses", t
);
7703 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7704 && ort
== C_ORT_ACC
)
7706 error_at (OMP_CLAUSE_LOCATION (c
),
7707 "%qD appears more than once in data clauses", t
);
7710 else if (bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7712 if (ort
== C_ORT_ACC
)
7713 error_at (OMP_CLAUSE_LOCATION (c
),
7714 "%qD appears more than once in data clauses", t
);
7716 error_at (OMP_CLAUSE_LOCATION (c
),
7717 "%qD appears both in data and map clauses", t
);
7722 bitmap_set_bit (&map_head
, DECL_UID (t
));
7723 if (t
!= OMP_CLAUSE_DECL (c
)
7724 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
7725 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7727 handle_map_references
:
7729 && !processing_template_decl
7730 && ort
!= C_ORT_DECLARE_SIMD
7731 && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
))))
7733 t
= OMP_CLAUSE_DECL (c
);
7734 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7736 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7737 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7739 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7741 else if (OMP_CLAUSE_MAP_KIND (c
)
7742 != GOMP_MAP_FIRSTPRIVATE_POINTER
7743 && (OMP_CLAUSE_MAP_KIND (c
)
7744 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
7745 && (OMP_CLAUSE_MAP_KIND (c
)
7746 != GOMP_MAP_ALWAYS_POINTER
)
7747 && (OMP_CLAUSE_MAP_KIND (c
)
7748 != GOMP_MAP_ATTACH_DETACH
))
7750 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
7752 if (TREE_CODE (t
) == COMPONENT_REF
)
7753 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ATTACH_DETACH
);
7755 OMP_CLAUSE_SET_MAP_KIND (c2
,
7756 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
7757 OMP_CLAUSE_DECL (c2
) = t
;
7758 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
7759 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
7760 OMP_CLAUSE_CHAIN (c
) = c2
;
7761 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7762 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7764 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7770 case OMP_CLAUSE_TO_DECLARE
:
7771 case OMP_CLAUSE_LINK
:
7772 t
= OMP_CLAUSE_DECL (c
);
7773 if (TREE_CODE (t
) == FUNCTION_DECL
7774 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7776 else if (!VAR_P (t
))
7778 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7780 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
7781 error_at (OMP_CLAUSE_LOCATION (c
),
7782 "template %qE in clause %qs", t
,
7783 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7784 else if (really_overloaded_fn (t
))
7785 error_at (OMP_CLAUSE_LOCATION (c
),
7786 "overloaded function name %qE in clause %qs", t
,
7787 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7789 error_at (OMP_CLAUSE_LOCATION (c
),
7790 "%qE is neither a variable nor a function name "
7792 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7795 error_at (OMP_CLAUSE_LOCATION (c
),
7796 "%qE is not a variable in clause %qs", t
,
7797 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7800 else if (DECL_THREAD_LOCAL_P (t
))
7802 error_at (OMP_CLAUSE_LOCATION (c
),
7803 "%qD is threadprivate variable in %qs clause", t
,
7804 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7807 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7809 error_at (OMP_CLAUSE_LOCATION (c
),
7810 "%qD does not have a mappable type in %qs clause", t
,
7811 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7812 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7817 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
7819 error_at (OMP_CLAUSE_LOCATION (c
),
7820 "%qE appears more than once on the same "
7821 "%<declare target%> directive", t
);
7825 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7828 case OMP_CLAUSE_UNIFORM
:
7829 t
= OMP_CLAUSE_DECL (c
);
7830 if (TREE_CODE (t
) != PARM_DECL
)
7832 if (processing_template_decl
)
7835 error_at (OMP_CLAUSE_LOCATION (c
),
7836 "%qD is not an argument in %<uniform%> clause", t
);
7838 error_at (OMP_CLAUSE_LOCATION (c
),
7839 "%qE is not an argument in %<uniform%> clause", t
);
7843 /* map_head bitmap is used as uniform_head if declare_simd. */
7844 bitmap_set_bit (&map_head
, DECL_UID (t
));
7845 goto check_dup_generic
;
7847 case OMP_CLAUSE_GRAINSIZE
:
7848 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
7849 if (t
== error_mark_node
)
7851 else if (!type_dependent_expression_p (t
)
7852 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7854 error_at (OMP_CLAUSE_LOCATION (c
),
7855 "%<grainsize%> expression must be integral");
7860 t
= mark_rvalue_use (t
);
7861 if (!processing_template_decl
)
7863 t
= maybe_constant_value (t
);
7864 if (TREE_CODE (t
) == INTEGER_CST
7865 && tree_int_cst_sgn (t
) != 1)
7867 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7868 "%<grainsize%> value must be positive");
7869 t
= integer_one_node
;
7871 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7873 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
7877 case OMP_CLAUSE_PRIORITY
:
7878 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
7879 if (t
== error_mark_node
)
7881 else if (!type_dependent_expression_p (t
)
7882 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7884 error_at (OMP_CLAUSE_LOCATION (c
),
7885 "%<priority%> expression must be integral");
7890 t
= mark_rvalue_use (t
);
7891 if (!processing_template_decl
)
7893 t
= maybe_constant_value (t
);
7894 if (TREE_CODE (t
) == INTEGER_CST
7895 && tree_int_cst_sgn (t
) == -1)
7897 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7898 "%<priority%> value must be non-negative");
7899 t
= integer_one_node
;
7901 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7903 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
7907 case OMP_CLAUSE_HINT
:
7908 t
= OMP_CLAUSE_HINT_EXPR (c
);
7909 if (t
== error_mark_node
)
7911 else if (!type_dependent_expression_p (t
)
7912 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7914 error_at (OMP_CLAUSE_LOCATION (c
),
7915 "%<hint%> expression must be integral");
7920 t
= mark_rvalue_use (t
);
7921 if (!processing_template_decl
)
7923 t
= maybe_constant_value (t
);
7924 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7925 if (TREE_CODE (t
) != INTEGER_CST
)
7927 error_at (OMP_CLAUSE_LOCATION (c
),
7928 "%<hint%> expression must be constant integer "
7933 OMP_CLAUSE_HINT_EXPR (c
) = t
;
7937 case OMP_CLAUSE_IS_DEVICE_PTR
:
7938 case OMP_CLAUSE_USE_DEVICE_PTR
:
7939 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
7940 t
= OMP_CLAUSE_DECL (c
);
7941 if (!type_dependent_expression_p (t
))
7943 tree type
= TREE_TYPE (t
);
7944 if (!TYPE_PTR_P (type
)
7945 && (!TYPE_REF_P (type
) || !TYPE_PTR_P (TREE_TYPE (type
))))
7947 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
7948 && ort
== C_ORT_OMP
)
7950 error_at (OMP_CLAUSE_LOCATION (c
),
7951 "%qs variable is neither a pointer "
7952 "nor reference to pointer",
7953 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7956 else if (TREE_CODE (type
) != ARRAY_TYPE
7957 && (!TYPE_REF_P (type
)
7958 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
7960 error_at (OMP_CLAUSE_LOCATION (c
),
7961 "%qs variable is neither a pointer, nor an "
7962 "array nor reference to pointer or array",
7963 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7968 goto check_dup_generic
;
7970 case OMP_CLAUSE_USE_DEVICE_ADDR
:
7972 t
= OMP_CLAUSE_DECL (c
);
7973 if (!processing_template_decl
7974 && (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7975 && !TYPE_REF_P (TREE_TYPE (t
))
7976 && !cxx_mark_addressable (t
))
7978 goto check_dup_generic
;
7980 case OMP_CLAUSE_NOWAIT
:
7981 case OMP_CLAUSE_DEFAULT
:
7982 case OMP_CLAUSE_UNTIED
:
7983 case OMP_CLAUSE_COLLAPSE
:
7984 case OMP_CLAUSE_PARALLEL
:
7985 case OMP_CLAUSE_FOR
:
7986 case OMP_CLAUSE_SECTIONS
:
7987 case OMP_CLAUSE_TASKGROUP
:
7988 case OMP_CLAUSE_PROC_BIND
:
7989 case OMP_CLAUSE_DEVICE_TYPE
:
7990 case OMP_CLAUSE_NOGROUP
:
7991 case OMP_CLAUSE_THREADS
:
7992 case OMP_CLAUSE_SIMD
:
7993 case OMP_CLAUSE_DEFAULTMAP
:
7994 case OMP_CLAUSE_BIND
:
7995 case OMP_CLAUSE_AUTO
:
7996 case OMP_CLAUSE_INDEPENDENT
:
7997 case OMP_CLAUSE_SEQ
:
7998 case OMP_CLAUSE_IF_PRESENT
:
7999 case OMP_CLAUSE_FINALIZE
:
8002 case OMP_CLAUSE_MERGEABLE
:
8003 mergeable_seen
= true;
8006 case OMP_CLAUSE_TILE
:
8007 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
8008 list
= TREE_CHAIN (list
))
8010 t
= TREE_VALUE (list
);
8012 if (t
== error_mark_node
)
8014 else if (!type_dependent_expression_p (t
)
8015 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8017 error_at (OMP_CLAUSE_LOCATION (c
),
8018 "%<tile%> argument needs integral type");
8023 t
= mark_rvalue_use (t
);
8024 if (!processing_template_decl
)
8026 /* Zero is used to indicate '*', we permit you
8027 to get there via an ICE of value zero. */
8028 t
= maybe_constant_value (t
);
8029 if (!tree_fits_shwi_p (t
)
8030 || tree_to_shwi (t
) < 0)
8032 error_at (OMP_CLAUSE_LOCATION (c
),
8033 "%<tile%> argument needs positive "
8034 "integral constant");
8037 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8041 /* Update list item. */
8042 TREE_VALUE (list
) = t
;
8046 case OMP_CLAUSE_ORDERED
:
8047 ordered_seen
= true;
8050 case OMP_CLAUSE_ORDER
:
8057 case OMP_CLAUSE_INBRANCH
:
8058 case OMP_CLAUSE_NOTINBRANCH
:
8061 error_at (OMP_CLAUSE_LOCATION (c
),
8062 "%<inbranch%> clause is incompatible with "
8069 case OMP_CLAUSE_INCLUSIVE
:
8070 case OMP_CLAUSE_EXCLUSIVE
:
8071 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8073 t
= OMP_CLAUSE_DECL (c
);
8074 if (t
== current_class_ptr
)
8076 error_at (OMP_CLAUSE_LOCATION (c
),
8077 "%<this%> allowed in OpenMP only in %<declare simd%>"
8083 && TREE_CODE (t
) != PARM_DECL
8084 && TREE_CODE (t
) != FIELD_DECL
)
8086 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8089 error_at (OMP_CLAUSE_LOCATION (c
),
8090 "%qD is not a variable in clause %qs", t
,
8091 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8093 error_at (OMP_CLAUSE_LOCATION (c
),
8094 "%qE is not a variable in clause %qs", t
,
8095 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8105 *pc
= OMP_CLAUSE_CHAIN (c
);
8107 pc
= &OMP_CLAUSE_CHAIN (c
);
8110 if (reduction_seen
< 0 && (ordered_seen
|| schedule_seen
))
8111 reduction_seen
= -2;
8113 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
8115 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
8116 bool remove
= false;
8117 bool need_complete_type
= false;
8118 bool need_default_ctor
= false;
8119 bool need_copy_ctor
= false;
8120 bool need_copy_assignment
= false;
8121 bool need_implicitly_determined
= false;
8122 bool need_dtor
= false;
8123 tree type
, inner_type
;
8127 case OMP_CLAUSE_SHARED
:
8128 need_implicitly_determined
= true;
8130 case OMP_CLAUSE_PRIVATE
:
8131 need_complete_type
= true;
8132 need_default_ctor
= true;
8134 need_implicitly_determined
= true;
8136 case OMP_CLAUSE_FIRSTPRIVATE
:
8137 need_complete_type
= true;
8138 need_copy_ctor
= true;
8140 need_implicitly_determined
= true;
8142 case OMP_CLAUSE_LASTPRIVATE
:
8143 need_complete_type
= true;
8144 need_copy_assignment
= true;
8145 need_implicitly_determined
= true;
8147 case OMP_CLAUSE_REDUCTION
:
8148 if (reduction_seen
== -2)
8149 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
8150 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
8151 need_copy_assignment
= true;
8152 need_implicitly_determined
= true;
8154 case OMP_CLAUSE_IN_REDUCTION
:
8155 case OMP_CLAUSE_TASK_REDUCTION
:
8156 case OMP_CLAUSE_INCLUSIVE
:
8157 case OMP_CLAUSE_EXCLUSIVE
:
8158 need_implicitly_determined
= true;
8160 case OMP_CLAUSE_LINEAR
:
8161 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
8162 need_implicitly_determined
= true;
8163 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
8164 && !bitmap_bit_p (&map_head
,
8165 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
8167 error_at (OMP_CLAUSE_LOCATION (c
),
8168 "%<linear%> clause step is a parameter %qD not "
8169 "specified in %<uniform%> clause",
8170 OMP_CLAUSE_LINEAR_STEP (c
));
8171 *pc
= OMP_CLAUSE_CHAIN (c
);
8175 case OMP_CLAUSE_COPYPRIVATE
:
8176 need_copy_assignment
= true;
8178 case OMP_CLAUSE_COPYIN
:
8179 need_copy_assignment
= true;
8181 case OMP_CLAUSE_SIMDLEN
:
8183 && !processing_template_decl
8184 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
8185 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
8187 error_at (OMP_CLAUSE_LOCATION (c
),
8188 "%<simdlen%> clause value is bigger than "
8189 "%<safelen%> clause value");
8190 OMP_CLAUSE_SIMDLEN_EXPR (c
)
8191 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
8193 pc
= &OMP_CLAUSE_CHAIN (c
);
8195 case OMP_CLAUSE_SCHEDULE
:
8197 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
8198 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
8200 error_at (OMP_CLAUSE_LOCATION (c
),
8201 "%<nonmonotonic%> schedule modifier specified "
8202 "together with %<ordered%> clause");
8203 OMP_CLAUSE_SCHEDULE_KIND (c
)
8204 = (enum omp_clause_schedule_kind
)
8205 (OMP_CLAUSE_SCHEDULE_KIND (c
)
8206 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
8208 if (reduction_seen
== -2)
8209 error_at (OMP_CLAUSE_LOCATION (c
),
8210 "%qs clause specified together with %<inscan%> "
8211 "%<reduction%> clause", "schedule");
8212 pc
= &OMP_CLAUSE_CHAIN (c
);
8214 case OMP_CLAUSE_NOGROUP
:
8217 error_at (OMP_CLAUSE_LOCATION (c
),
8218 "%<nogroup%> clause must not be used together with "
8219 "%<reduction%> clause");
8220 *pc
= OMP_CLAUSE_CHAIN (c
);
8223 pc
= &OMP_CLAUSE_CHAIN (c
);
8225 case OMP_CLAUSE_ORDERED
:
8226 if (reduction_seen
== -2)
8227 error_at (OMP_CLAUSE_LOCATION (c
),
8228 "%qs clause specified together with %<inscan%> "
8229 "%<reduction%> clause", "ordered");
8230 pc
= &OMP_CLAUSE_CHAIN (c
);
8232 case OMP_CLAUSE_ORDER
:
8235 error_at (OMP_CLAUSE_LOCATION (c
),
8236 "%<order%> clause must not be used together "
8237 "with %<ordered%>");
8238 *pc
= OMP_CLAUSE_CHAIN (c
);
8241 pc
= &OMP_CLAUSE_CHAIN (c
);
8243 case OMP_CLAUSE_DETACH
:
8246 error_at (OMP_CLAUSE_LOCATION (c
),
8247 "%<detach%> clause must not be used together with "
8248 "%<mergeable%> clause");
8249 *pc
= OMP_CLAUSE_CHAIN (c
);
8252 pc
= &OMP_CLAUSE_CHAIN (c
);
8254 case OMP_CLAUSE_NOWAIT
:
8255 if (copyprivate_seen
)
8257 error_at (OMP_CLAUSE_LOCATION (c
),
8258 "%<nowait%> clause must not be used together "
8259 "with %<copyprivate%>");
8260 *pc
= OMP_CLAUSE_CHAIN (c
);
8265 pc
= &OMP_CLAUSE_CHAIN (c
);
8269 t
= OMP_CLAUSE_DECL (c
);
8272 case OMP_CLAUSE_LASTPRIVATE
:
8274 && !bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
8276 need_default_ctor
= true;
8281 case OMP_CLAUSE_REDUCTION
:
8282 case OMP_CLAUSE_IN_REDUCTION
:
8283 case OMP_CLAUSE_TASK_REDUCTION
:
8286 if (TREE_CODE (t
) == MEM_REF
)
8288 t
= TREE_OPERAND (t
, 0);
8289 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
8290 t
= TREE_OPERAND (t
, 0);
8291 if (TREE_CODE (t
) == ADDR_EXPR
8292 || TREE_CODE (t
) == INDIRECT_REF
)
8293 t
= TREE_OPERAND (t
, 0);
8295 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8297 else if (TREE_CODE (t
) == TREE_LIST
)
8299 while (TREE_CODE (t
) == TREE_LIST
)
8302 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8303 t
= OMP_CLAUSE_DECL (c
);
8305 else if (DECL_P (t
))
8306 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8307 t
= OMP_CLAUSE_DECL (c
);
8309 if (processing_template_decl
8310 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8312 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
8316 t
= OMP_CLAUSE_DECL (c
);
8319 case OMP_CLAUSE_COPYIN
:
8320 if (processing_template_decl
8321 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8323 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
8325 error_at (OMP_CLAUSE_LOCATION (c
),
8326 "%qE must be %<threadprivate%> for %<copyin%>", t
);
8335 if (processing_template_decl
8336 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8338 pc
= &OMP_CLAUSE_CHAIN (c
);
8342 if (need_complete_type
|| need_copy_assignment
)
8344 t
= require_complete_type (t
);
8345 if (t
== error_mark_node
)
8347 else if (!processing_template_decl
8348 && TYPE_REF_P (TREE_TYPE (t
))
8349 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
8352 if (need_implicitly_determined
)
8354 const char *share_name
= NULL
;
8357 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8359 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8361 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
8362 share_name
= "threadprivate";
8363 else switch (cxx_omp_predetermined_sharing_1 (t
))
8365 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
8367 case OMP_CLAUSE_DEFAULT_SHARED
:
8368 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8369 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8370 && c_omp_predefined_variable (t
))
8371 /* The __func__ variable and similar function-local predefined
8372 variables may be listed in a shared or firstprivate
8376 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8378 && cxx_omp_const_qual_no_mutable (t
))
8380 tree ctx
= CP_DECL_CONTEXT (t
);
8381 /* const qualified static data members without mutable
8382 member may be specified in firstprivate clause. */
8383 if (TYPE_P (ctx
) && MAYBE_CLASS_TYPE_P (ctx
))
8386 share_name
= "shared";
8388 case OMP_CLAUSE_DEFAULT_PRIVATE
:
8389 share_name
= "private";
8396 error_at (OMP_CLAUSE_LOCATION (c
),
8397 "%qE is predetermined %qs for %qs",
8398 omp_clause_printable_decl (t
), share_name
,
8399 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8402 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8403 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_FIRSTPRIVATE
8404 && cxx_omp_const_qual_no_mutable (t
))
8406 error_at (OMP_CLAUSE_LOCATION (c
),
8407 "%<const%> qualified %qE without %<mutable%> member "
8408 "may appear only in %<shared%> or %<firstprivate%> "
8409 "clauses", omp_clause_printable_decl (t
));
8415 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8416 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
8417 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8418 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
8419 && OMP_CLAUSE_DECL (c
) == t
)
8421 error_at (OMP_CLAUSE_LOCATION (c
),
8422 "the event handle of a %<detach%> clause "
8423 "should not be in a data-sharing clause");
8427 /* We're interested in the base element, not arrays. */
8428 inner_type
= type
= TREE_TYPE (t
);
8429 if ((need_complete_type
8430 || need_copy_assignment
8431 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
8432 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
8433 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
8434 && TYPE_REF_P (inner_type
))
8435 inner_type
= TREE_TYPE (inner_type
);
8436 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
8437 inner_type
= TREE_TYPE (inner_type
);
8439 /* Check for special function availability by building a call to one.
8440 Save the results, because later we won't be in the right context
8441 for making these queries. */
8442 if (CLASS_TYPE_P (inner_type
)
8443 && COMPLETE_TYPE_P (inner_type
)
8444 && (need_default_ctor
|| need_copy_ctor
8445 || need_copy_assignment
|| need_dtor
)
8446 && !type_dependent_expression_p (t
)
8447 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
8448 need_copy_ctor
, need_copy_assignment
,
8453 && c_kind
== OMP_CLAUSE_SHARED
8454 && processing_template_decl
)
8456 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8458 OMP_CLAUSE_DECL (c
) = t
;
8462 *pc
= OMP_CLAUSE_CHAIN (c
);
8464 pc
= &OMP_CLAUSE_CHAIN (c
);
8468 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
8470 bool remove
= false;
8471 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ALLOCATE
8472 && !OMP_CLAUSE_ALLOCATE_COMBINED (c
)
8473 && DECL_P (OMP_CLAUSE_DECL (c
))
8474 && bitmap_bit_p (&aligned_head
, DECL_UID (OMP_CLAUSE_DECL (c
))))
8476 error_at (OMP_CLAUSE_LOCATION (c
),
8477 "%qD specified in %<allocate%> clause but not in "
8478 "an explicit privatization clause", OMP_CLAUSE_DECL (c
));
8482 *pc
= OMP_CLAUSE_CHAIN (c
);
8484 pc
= &OMP_CLAUSE_CHAIN (c
);
8487 bitmap_obstack_release (NULL
);
8491 /* Start processing OpenMP clauses that can include any
8492 privatization clauses for non-static data members. */
8495 push_omp_privatization_clauses (bool ignore_next
)
8497 if (omp_private_member_ignore_next
)
8499 omp_private_member_ignore_next
= ignore_next
;
8502 omp_private_member_ignore_next
= ignore_next
;
8503 if (omp_private_member_map
)
8504 omp_private_member_vec
.safe_push (error_mark_node
);
8505 return push_stmt_list ();
8508 /* Revert remapping of any non-static data members since
8509 the last push_omp_privatization_clauses () call. */
8512 pop_omp_privatization_clauses (tree stmt
)
8514 if (stmt
== NULL_TREE
)
8516 stmt
= pop_stmt_list (stmt
);
8517 if (omp_private_member_map
)
8519 while (!omp_private_member_vec
.is_empty ())
8521 tree t
= omp_private_member_vec
.pop ();
8522 if (t
== error_mark_node
)
8527 bool no_decl_expr
= t
== integer_zero_node
;
8529 t
= omp_private_member_vec
.pop ();
8530 tree
*v
= omp_private_member_map
->get (t
);
8534 omp_private_member_map
->remove (t
);
8536 delete omp_private_member_map
;
8537 omp_private_member_map
= NULL
;
8542 /* Remember OpenMP privatization clauses mapping and clear it.
8543 Used for lambdas. */
8546 save_omp_privatization_clauses (vec
<tree
> &save
)
8549 if (omp_private_member_ignore_next
)
8550 save
.safe_push (integer_one_node
);
8551 omp_private_member_ignore_next
= false;
8552 if (!omp_private_member_map
)
8555 while (!omp_private_member_vec
.is_empty ())
8557 tree t
= omp_private_member_vec
.pop ();
8558 if (t
== error_mark_node
)
8564 if (t
== integer_zero_node
)
8565 t
= omp_private_member_vec
.pop ();
8566 tree
*v
= omp_private_member_map
->get (t
);
8568 save
.safe_push (*v
);
8573 delete omp_private_member_map
;
8574 omp_private_member_map
= NULL
;
8577 /* Restore OpenMP privatization clauses mapping saved by the
8581 restore_omp_privatization_clauses (vec
<tree
> &save
)
8583 gcc_assert (omp_private_member_vec
.is_empty ());
8584 omp_private_member_ignore_next
= false;
8585 if (save
.is_empty ())
8587 if (save
.length () == 1 && save
[0] == integer_one_node
)
8589 omp_private_member_ignore_next
= true;
8594 omp_private_member_map
= new hash_map
<tree
, tree
>;
8595 while (!save
.is_empty ())
8597 tree t
= save
.pop ();
8599 if (t
!= error_mark_node
)
8601 if (t
== integer_one_node
)
8603 omp_private_member_ignore_next
= true;
8604 gcc_assert (save
.is_empty ());
8607 if (t
== integer_zero_node
)
8609 tree
&v
= omp_private_member_map
->get_or_insert (t
);
8612 omp_private_member_vec
.safe_push (t
);
8614 omp_private_member_vec
.safe_push (n
);
8619 /* For all variables in the tree_list VARS, mark them as thread local. */
8622 finish_omp_threadprivate (tree vars
)
8626 /* Mark every variable in VARS to be assigned thread local storage. */
8627 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8629 tree v
= TREE_PURPOSE (t
);
8631 if (error_operand_p (v
))
8633 else if (!VAR_P (v
))
8634 error ("%<threadprivate%> %qD is not file, namespace "
8635 "or block scope variable", v
);
8636 /* If V had already been marked threadprivate, it doesn't matter
8637 whether it had been used prior to this point. */
8638 else if (TREE_USED (v
)
8639 && (DECL_LANG_SPECIFIC (v
) == NULL
8640 || !CP_DECL_THREADPRIVATE_P (v
)))
8641 error ("%qE declared %<threadprivate%> after first use", v
);
8642 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8643 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8644 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
8645 error ("%<threadprivate%> %qE has incomplete type", v
);
8646 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
8647 && CP_DECL_CONTEXT (v
) != current_class_type
)
8648 error ("%<threadprivate%> %qE directive not "
8649 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
8652 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
8653 if (DECL_LANG_SPECIFIC (v
) == NULL
)
8654 retrofit_lang_decl (v
);
8656 if (! CP_DECL_THREAD_LOCAL_P (v
))
8658 CP_DECL_THREAD_LOCAL_P (v
) = true;
8659 set_decl_tls_model (v
, decl_default_tls_model (v
));
8660 /* If rtl has been already set for this var, call
8661 make_decl_rtl once again, so that encode_section_info
8662 has a chance to look at the new decl flags. */
8663 if (DECL_RTL_SET_P (v
))
8666 CP_DECL_THREADPRIVATE_P (v
) = 1;
8671 /* Build an OpenMP structured block. */
8674 begin_omp_structured_block (void)
8676 return do_pushlevel (sk_omp
);
8680 finish_omp_structured_block (tree block
)
8682 return do_poplevel (block
);
8685 /* Similarly, except force the retention of the BLOCK. */
8688 begin_omp_parallel (void)
8690 keep_next_level (true);
8691 return begin_omp_structured_block ();
8694 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
8698 finish_oacc_data (tree clauses
, tree block
)
8702 block
= finish_omp_structured_block (block
);
8704 stmt
= make_node (OACC_DATA
);
8705 TREE_TYPE (stmt
) = void_type_node
;
8706 OACC_DATA_CLAUSES (stmt
) = clauses
;
8707 OACC_DATA_BODY (stmt
) = block
;
8709 return add_stmt (stmt
);
8712 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
8716 finish_oacc_host_data (tree clauses
, tree block
)
8720 block
= finish_omp_structured_block (block
);
8722 stmt
= make_node (OACC_HOST_DATA
);
8723 TREE_TYPE (stmt
) = void_type_node
;
8724 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
8725 OACC_HOST_DATA_BODY (stmt
) = block
;
8727 return add_stmt (stmt
);
8730 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
8734 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
8736 body
= finish_omp_structured_block (body
);
8738 tree stmt
= make_node (code
);
8739 TREE_TYPE (stmt
) = void_type_node
;
8740 OMP_BODY (stmt
) = body
;
8741 OMP_CLAUSES (stmt
) = clauses
;
8743 return add_stmt (stmt
);
8747 finish_omp_parallel (tree clauses
, tree body
)
8751 body
= finish_omp_structured_block (body
);
8753 stmt
= make_node (OMP_PARALLEL
);
8754 TREE_TYPE (stmt
) = void_type_node
;
8755 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
8756 OMP_PARALLEL_BODY (stmt
) = body
;
8758 return add_stmt (stmt
);
8762 begin_omp_task (void)
8764 keep_next_level (true);
8765 return begin_omp_structured_block ();
8769 finish_omp_task (tree clauses
, tree body
)
8773 body
= finish_omp_structured_block (body
);
8775 stmt
= make_node (OMP_TASK
);
8776 TREE_TYPE (stmt
) = void_type_node
;
8777 OMP_TASK_CLAUSES (stmt
) = clauses
;
8778 OMP_TASK_BODY (stmt
) = body
;
8780 return add_stmt (stmt
);
8783 /* Helper function for finish_omp_for. Convert Ith random access iterator
8784 into integral iterator. Return FALSE if successful. */
8787 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
8788 tree declv
, tree orig_declv
, tree initv
,
8789 tree condv
, tree incrv
, tree
*body
,
8790 tree
*pre_body
, tree
&clauses
,
8791 int collapse
, int ordered
)
8793 tree diff
, iter_init
, iter_incr
= NULL
, last
;
8794 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
8795 tree decl
= TREE_VEC_ELT (declv
, i
);
8796 tree init
= TREE_VEC_ELT (initv
, i
);
8797 tree cond
= TREE_VEC_ELT (condv
, i
);
8798 tree incr
= TREE_VEC_ELT (incrv
, i
);
8800 location_t elocus
= locus
;
8802 if (init
&& EXPR_HAS_LOCATION (init
))
8803 elocus
= EXPR_LOCATION (init
);
8805 switch (TREE_CODE (cond
))
8812 if (TREE_OPERAND (cond
, 1) == iter
)
8813 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
8814 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
8815 if (TREE_OPERAND (cond
, 0) != iter
)
8816 cond
= error_mark_node
;
8819 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
8822 TREE_OPERAND (cond
, 1), ERROR_MARK
,
8823 NULL
, tf_warning_or_error
);
8824 if (error_operand_p (tem
))
8829 cond
= error_mark_node
;
8832 if (cond
== error_mark_node
)
8834 error_at (elocus
, "invalid controlling predicate");
8837 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
8838 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
8839 tf_warning_or_error
);
8840 diff
= cp_fully_fold (diff
);
8841 if (error_operand_p (diff
))
8843 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
8845 error_at (elocus
, "difference between %qE and %qD does not have integer type",
8846 TREE_OPERAND (cond
, 1), iter
);
8849 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
, i
,
8850 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
8851 cond
, cp_walk_subtrees
))
8854 switch (TREE_CODE (incr
))
8856 case PREINCREMENT_EXPR
:
8857 case PREDECREMENT_EXPR
:
8858 case POSTINCREMENT_EXPR
:
8859 case POSTDECREMENT_EXPR
:
8860 if (TREE_OPERAND (incr
, 0) != iter
)
8862 incr
= error_mark_node
;
8865 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
8866 TREE_CODE (incr
), iter
,
8867 tf_warning_or_error
);
8868 if (error_operand_p (iter_incr
))
8870 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
8871 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
8872 incr
= integer_one_node
;
8874 incr
= integer_minus_one_node
;
8877 if (TREE_OPERAND (incr
, 0) != iter
)
8878 incr
= error_mark_node
;
8879 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
8880 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
8882 tree rhs
= TREE_OPERAND (incr
, 1);
8883 if (TREE_OPERAND (rhs
, 0) == iter
)
8885 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
8887 incr
= error_mark_node
;
8890 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8891 iter
, TREE_CODE (rhs
),
8892 TREE_OPERAND (rhs
, 1),
8893 tf_warning_or_error
);
8894 if (error_operand_p (iter_incr
))
8896 incr
= TREE_OPERAND (rhs
, 1);
8897 incr
= cp_convert (TREE_TYPE (diff
), incr
,
8898 tf_warning_or_error
);
8899 if (TREE_CODE (rhs
) == MINUS_EXPR
)
8901 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
8902 incr
= fold_simple (incr
);
8904 if (TREE_CODE (incr
) != INTEGER_CST
8905 && (TREE_CODE (incr
) != NOP_EXPR
8906 || (TREE_CODE (TREE_OPERAND (incr
, 0))
8911 else if (TREE_OPERAND (rhs
, 1) == iter
)
8913 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
8914 || TREE_CODE (rhs
) != PLUS_EXPR
)
8915 incr
= error_mark_node
;
8918 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
8920 TREE_OPERAND (rhs
, 0),
8923 tf_warning_or_error
);
8924 if (error_operand_p (iter_incr
))
8926 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8929 tf_warning_or_error
);
8930 if (error_operand_p (iter_incr
))
8932 incr
= TREE_OPERAND (rhs
, 0);
8937 incr
= error_mark_node
;
8940 incr
= error_mark_node
;
8943 incr
= error_mark_node
;
8947 if (incr
== error_mark_node
)
8949 error_at (elocus
, "invalid increment expression");
8953 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
8954 incr
= cp_fully_fold (incr
);
8955 tree loop_iv_seen
= NULL_TREE
;
8956 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8957 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
8958 && OMP_CLAUSE_DECL (c
) == iter
)
8960 if (code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
8963 OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
) = 1;
8967 else if ((code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
8968 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
8969 && OMP_CLAUSE_DECL (c
) == iter
)
8972 if (code
== OMP_TASKLOOP
)
8973 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
8976 decl
= create_temporary_var (TREE_TYPE (diff
));
8978 add_decl_expr (decl
);
8979 last
= create_temporary_var (TREE_TYPE (diff
));
8981 add_decl_expr (last
);
8982 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
8983 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
8985 incr_var
= create_temporary_var (TREE_TYPE (diff
));
8986 pushdecl (incr_var
);
8987 add_decl_expr (incr_var
);
8989 gcc_assert (stmts_are_full_exprs_p ());
8990 tree diffvar
= NULL_TREE
;
8991 if (code
== OMP_TASKLOOP
)
8995 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
8996 OMP_CLAUSE_DECL (ivc
) = iter
;
8997 cxx_omp_finish_clause (ivc
, NULL
, false);
8998 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
9001 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9002 OMP_CLAUSE_DECL (lvc
) = last
;
9003 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
9005 diffvar
= create_temporary_var (TREE_TYPE (diff
));
9007 add_decl_expr (diffvar
);
9009 else if (code
== OMP_LOOP
)
9013 /* While iterators on the loop construct are predetermined
9014 lastprivate, if the decl is not declared inside of the
9015 loop, OMP_CLAUSE_LASTPRIVATE should have been added
9017 loop_iv_seen
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9018 OMP_CLAUSE_DECL (loop_iv_seen
) = iter
;
9019 OMP_CLAUSE_CHAIN (loop_iv_seen
) = clauses
;
9020 clauses
= loop_iv_seen
;
9022 else if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_PRIVATE
)
9024 OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen
) = 0;
9025 OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen
) = 0;
9026 OMP_CLAUSE_CODE (loop_iv_seen
) = OMP_CLAUSE_FIRSTPRIVATE
;
9028 if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_FIRSTPRIVATE
)
9029 cxx_omp_finish_clause (loop_iv_seen
, NULL
, false);
9032 orig_pre_body
= *pre_body
;
9033 *pre_body
= push_stmt_list ();
9035 add_stmt (orig_pre_body
);
9037 finish_expr_stmt (build_x_modify_expr (elocus
,
9038 iter
, NOP_EXPR
, init
,
9039 tf_warning_or_error
));
9040 init
= build_int_cst (TREE_TYPE (diff
), 0);
9041 if (c
&& iter_incr
== NULL
9042 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
9046 finish_expr_stmt (build_x_modify_expr (elocus
,
9048 incr
, tf_warning_or_error
));
9051 iter_incr
= build_x_modify_expr (elocus
,
9052 iter
, PLUS_EXPR
, incr
,
9053 tf_warning_or_error
);
9055 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
9057 finish_expr_stmt (build_x_modify_expr (elocus
,
9058 last
, NOP_EXPR
, init
,
9059 tf_warning_or_error
));
9062 finish_expr_stmt (build_x_modify_expr (elocus
,
9064 diff
, tf_warning_or_error
));
9067 *pre_body
= pop_stmt_list (*pre_body
);
9069 cond
= cp_build_binary_op (elocus
,
9070 TREE_CODE (cond
), decl
, diff
,
9071 tf_warning_or_error
);
9072 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
9073 elocus
, incr
, NULL_TREE
);
9076 *body
= push_stmt_list ();
9077 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
9078 iter_init
= build_x_modify_expr (elocus
,
9079 iter
, PLUS_EXPR
, iter_init
,
9080 tf_warning_or_error
);
9081 if (iter_init
!= error_mark_node
)
9082 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
9083 finish_expr_stmt (iter_init
);
9084 finish_expr_stmt (build_x_modify_expr (elocus
,
9085 last
, NOP_EXPR
, decl
,
9086 tf_warning_or_error
));
9087 add_stmt (orig_body
);
9088 *body
= pop_stmt_list (*body
);
9092 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
9094 finish_expr_stmt (iter_incr
);
9098 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
9099 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
9100 iter_init
, iter_incr
);
9101 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
9102 iter_init
= build_x_modify_expr (elocus
,
9103 iter
, PLUS_EXPR
, iter_init
,
9104 tf_warning_or_error
);
9105 if (iter_init
!= error_mark_node
)
9106 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
9107 finish_expr_stmt (iter_init
);
9109 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
9110 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
9113 if (TREE_CODE (TREE_VEC_ELT (orig_declv
, i
)) == TREE_LIST
)
9115 tree t
= TREE_VEC_ELT (orig_declv
, i
);
9116 gcc_assert (TREE_PURPOSE (t
) == NULL_TREE
9117 && TREE_VALUE (t
) == NULL_TREE
9118 && TREE_CODE (TREE_CHAIN (t
)) == TREE_VEC
);
9119 TREE_PURPOSE (t
) = TREE_VEC_ELT (declv
, i
);
9120 TREE_VALUE (t
) = last
;
9123 TREE_VEC_ELT (orig_declv
, i
)
9124 = tree_cons (TREE_VEC_ELT (declv
, i
), last
, NULL_TREE
);
9125 TREE_VEC_ELT (declv
, i
) = decl
;
9126 TREE_VEC_ELT (initv
, i
) = init
;
9127 TREE_VEC_ELT (condv
, i
) = cond
;
9128 TREE_VEC_ELT (incrv
, i
) = incr
;
9133 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
9134 are directly for their associated operands in the statement. DECL
9135 and INIT are a combo; if DECL is NULL then INIT ought to be a
9136 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
9137 optional statements that need to go before the loop into its
9141 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
9142 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
9143 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
9145 tree omp_for
= NULL
, orig_incr
= NULL
;
9146 tree decl
= NULL
, init
, cond
, incr
;
9152 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
9153 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
9154 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
9155 if (TREE_VEC_LENGTH (declv
) > 1)
9159 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
9161 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
9164 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
9166 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
9167 if (collapse
!= TREE_VEC_LENGTH (declv
))
9168 ordered
= TREE_VEC_LENGTH (declv
);
9171 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
9173 decl
= TREE_VEC_ELT (declv
, i
);
9174 init
= TREE_VEC_ELT (initv
, i
);
9175 cond
= TREE_VEC_ELT (condv
, i
);
9176 incr
= TREE_VEC_ELT (incrv
, i
);
9182 switch (TREE_CODE (init
))
9185 decl
= TREE_OPERAND (init
, 0);
9186 init
= TREE_OPERAND (init
, 1);
9189 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
9191 decl
= TREE_OPERAND (init
, 0);
9192 init
= TREE_OPERAND (init
, 2);
9202 "expected iteration declaration or initialization");
9207 if (init
&& EXPR_HAS_LOCATION (init
))
9208 elocus
= EXPR_LOCATION (init
);
9210 if (cond
== global_namespace
)
9215 error_at (elocus
, "missing controlling predicate");
9221 error_at (elocus
, "missing increment expression");
9225 TREE_VEC_ELT (declv
, i
) = decl
;
9226 TREE_VEC_ELT (initv
, i
) = init
;
9233 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
9235 && !c_omp_check_loop_iv_exprs (locus
,
9236 orig_declv
? orig_declv
: declv
, i
,
9237 TREE_VEC_ELT (declv
, i
), orig_init
,
9238 NULL_TREE
, cp_walk_subtrees
))
9244 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
9248 stmt
= make_node (code
);
9250 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
9252 /* This is really just a place-holder. We'll be decomposing this
9253 again and going through the cp_build_modify_expr path below when
9254 we instantiate the thing. */
9255 TREE_VEC_ELT (initv
, i
)
9256 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
9257 TREE_VEC_ELT (initv
, i
));
9260 TREE_TYPE (stmt
) = void_type_node
;
9261 OMP_FOR_INIT (stmt
) = initv
;
9262 OMP_FOR_COND (stmt
) = condv
;
9263 OMP_FOR_INCR (stmt
) = incrv
;
9264 OMP_FOR_BODY (stmt
) = body
;
9265 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
9266 OMP_FOR_CLAUSES (stmt
) = clauses
;
9268 SET_EXPR_LOCATION (stmt
, locus
);
9269 return add_stmt (stmt
);
9273 orig_declv
= copy_node (declv
);
9275 if (processing_template_decl
)
9276 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
9278 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
9280 decl
= TREE_VEC_ELT (declv
, i
);
9281 init
= TREE_VEC_ELT (initv
, i
);
9282 cond
= TREE_VEC_ELT (condv
, i
);
9283 incr
= TREE_VEC_ELT (incrv
, i
);
9285 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9288 if (init
&& EXPR_HAS_LOCATION (init
))
9289 elocus
= EXPR_LOCATION (init
);
9293 error_at (elocus
, "expected iteration declaration or initialization");
9297 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
9300 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9301 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
9302 TREE_CODE (TREE_OPERAND (incr
, 1)),
9303 TREE_OPERAND (incr
, 2),
9304 tf_warning_or_error
);
9307 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
9309 if (code
== OMP_SIMD
)
9311 error_at (elocus
, "%<#pragma omp simd%> used with class "
9312 "iteration variable %qE", decl
);
9315 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
9316 initv
, condv
, incrv
, &body
,
9323 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
9324 && !TYPE_PTR_P (TREE_TYPE (decl
)))
9326 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
9330 if (!processing_template_decl
&& TREE_CODE (init
) != TREE_VEC
)
9331 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
9332 tf_warning_or_error
);
9334 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
9335 if (decl
== error_mark_node
|| init
== error_mark_node
)
9338 TREE_VEC_ELT (declv
, i
) = decl
;
9339 TREE_VEC_ELT (initv
, i
) = init
;
9340 TREE_VEC_ELT (condv
, i
) = cond
;
9341 TREE_VEC_ELT (incrv
, i
) = incr
;
9345 if (pre_body
&& IS_EMPTY_STMT (pre_body
))
9348 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
9349 incrv
, body
, pre_body
,
9350 !processing_template_decl
);
9352 /* Check for iterators appearing in lb, b or incr expressions. */
9353 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
9354 omp_for
= NULL_TREE
;
9356 if (omp_for
== NULL
)
9361 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
9363 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
);
9364 decl
= TREE_OPERAND (init
, 0);
9365 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), i
);
9366 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
9368 if (!processing_template_decl
)
9370 if (TREE_CODE (TREE_OPERAND (init
, 1)) == TREE_VEC
)
9372 tree t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1);
9373 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1)
9374 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9375 t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2);
9376 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2)
9377 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9381 tree t
= TREE_OPERAND (init
, 1);
9382 TREE_OPERAND (init
, 1)
9383 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9385 if (TREE_CODE (TREE_OPERAND (cond
, 1)) == TREE_VEC
)
9387 tree t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1);
9388 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1)
9389 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9390 t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2);
9391 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2)
9392 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9396 tree t
= TREE_OPERAND (cond
, 1);
9397 TREE_OPERAND (cond
, 1)
9398 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9402 if (TREE_CODE (incr
) != MODIFY_EXPR
)
9405 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
9406 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
9407 && !processing_template_decl
)
9409 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
9410 if (TREE_SIDE_EFFECTS (t
)
9412 && (TREE_CODE (t
) != NOP_EXPR
9413 || TREE_OPERAND (t
, 0) != decl
))
9414 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
9415 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9417 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
9418 if (TREE_SIDE_EFFECTS (t
)
9420 && (TREE_CODE (t
) != NOP_EXPR
9421 || TREE_OPERAND (t
, 0) != decl
))
9422 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
9423 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9427 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
9429 OMP_FOR_CLAUSES (omp_for
) = clauses
;
9431 /* For simd loops with non-static data member iterators, we could have added
9432 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
9433 step at this point, fill it in. */
9434 if (code
== OMP_SIMD
&& !processing_template_decl
9435 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
9436 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
9437 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
9438 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
9440 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
9441 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
9442 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
9444 switch (TREE_CODE (incr
))
9446 case PREINCREMENT_EXPR
:
9447 case POSTINCREMENT_EXPR
:
9448 /* c_omp_for_incr_canonicalize_ptr() should have been
9449 called to massage things appropriately. */
9450 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9451 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
9453 case PREDECREMENT_EXPR
:
9454 case POSTDECREMENT_EXPR
:
9455 /* c_omp_for_incr_canonicalize_ptr() should have been
9456 called to massage things appropriately. */
9457 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9458 OMP_CLAUSE_LINEAR_STEP (c
)
9459 = build_int_cst (TREE_TYPE (decl
), -1);
9462 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9463 incr
= TREE_OPERAND (incr
, 1);
9464 switch (TREE_CODE (incr
))
9467 if (TREE_OPERAND (incr
, 1) == decl
)
9468 step
= TREE_OPERAND (incr
, 0);
9470 step
= TREE_OPERAND (incr
, 1);
9473 case POINTER_PLUS_EXPR
:
9474 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9475 step
= TREE_OPERAND (incr
, 1);
9480 stept
= TREE_TYPE (decl
);
9481 if (INDIRECT_TYPE_P (stept
))
9483 step
= fold_convert (stept
, step
);
9484 if (TREE_CODE (incr
) == MINUS_EXPR
)
9485 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
9486 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
9492 /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
9493 clauses, we need copy ctor for those rather than default ctor,
9494 plus as for other lastprivates assignment op and dtor. */
9495 if (code
== OMP_LOOP
&& !processing_template_decl
)
9496 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9497 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9498 && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
)
9499 && cxx_omp_create_clause_info (c
, TREE_TYPE (OMP_CLAUSE_DECL (c
)),
9500 false, true, true, true))
9501 CP_OMP_CLAUSE_INFO (c
) = NULL_TREE
;
9506 /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS
9507 and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */
9510 finish_omp_for_block (tree bind
, tree omp_for
)
9512 if (omp_for
== NULL_TREE
9513 || !OMP_FOR_ORIG_DECLS (omp_for
)
9514 || bind
== NULL_TREE
9515 || TREE_CODE (bind
) != BIND_EXPR
)
9518 for (int i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for
)); i
++)
9519 if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)) == TREE_LIST
9520 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)))
9522 tree v
= TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
));
9523 gcc_assert (BIND_EXPR_BLOCK (bind
)
9524 && (BIND_EXPR_VARS (bind
)
9525 == BLOCK_VARS (BIND_EXPR_BLOCK (bind
))));
9526 for (int j
= 2; j
< TREE_VEC_LENGTH (v
); j
++)
9527 for (tree
*p
= &BIND_EXPR_VARS (bind
); *p
; p
= &DECL_CHAIN (*p
))
9529 if (*p
== TREE_VEC_ELT (v
, j
))
9532 *p
= DECL_CHAIN (*p
);
9535 b
= make_node (BLOCK
);
9536 b
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
9537 OMP_FOR_BODY (omp_for
), b
);
9538 TREE_SIDE_EFFECTS (b
) = 1;
9539 OMP_FOR_BODY (omp_for
) = b
;
9541 DECL_CHAIN (var
) = BIND_EXPR_VARS (b
);
9542 BIND_EXPR_VARS (b
) = var
;
9543 BLOCK_VARS (BIND_EXPR_BLOCK (b
)) = var
;
9546 BLOCK_VARS (BIND_EXPR_BLOCK (bind
)) = BIND_EXPR_VARS (bind
);
9552 finish_omp_atomic (location_t loc
, enum tree_code code
, enum tree_code opcode
,
9553 tree lhs
, tree rhs
, tree v
, tree lhs1
, tree rhs1
,
9554 tree clauses
, enum omp_memory_order mo
)
9569 dependent_p
= false;
9572 /* Even in a template, we can detect invalid uses of the atomic
9573 pragma if neither LHS nor RHS is type-dependent. */
9574 if (processing_template_decl
)
9576 dependent_p
= (type_dependent_expression_p (lhs
)
9577 || (rhs
&& type_dependent_expression_p (rhs
))
9578 || (v
&& type_dependent_expression_p (v
))
9579 || (lhs1
&& type_dependent_expression_p (lhs1
))
9580 || (rhs1
&& type_dependent_expression_p (rhs1
)));
9583 gcc_assert (TREE_CODE (clauses
) == OMP_CLAUSE
9584 && OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_HINT
9585 && OMP_CLAUSE_CHAIN (clauses
) == NULL_TREE
);
9586 if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses
))
9587 || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses
)) != INTEGER_CST
)
9592 lhs
= build_non_dependent_expr (lhs
);
9594 rhs
= build_non_dependent_expr (rhs
);
9596 v
= build_non_dependent_expr (v
);
9598 lhs1
= build_non_dependent_expr (lhs1
);
9600 rhs1
= build_non_dependent_expr (rhs1
);
9605 bool swapped
= false;
9606 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
9608 std::swap (rhs
, rhs1
);
9609 swapped
= !commutative_tree_code (opcode
);
9611 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
9613 if (code
== OMP_ATOMIC
)
9614 error ("%<#pragma omp atomic update%> uses two different "
9615 "expressions for memory");
9617 error ("%<#pragma omp atomic capture%> uses two different "
9618 "expressions for memory");
9621 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
9623 if (code
== OMP_ATOMIC
)
9624 error ("%<#pragma omp atomic update%> uses two different "
9625 "expressions for memory");
9627 error ("%<#pragma omp atomic capture%> uses two different "
9628 "expressions for memory");
9631 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
,
9632 v
, lhs1
, rhs1
, swapped
, mo
,
9633 processing_template_decl
!= 0);
9634 if (stmt
== error_mark_node
)
9637 if (processing_template_decl
)
9639 if (code
== OMP_ATOMIC_READ
)
9641 stmt
= build_min_nt_loc (loc
, OMP_ATOMIC_READ
, orig_lhs
);
9642 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9643 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9647 if (opcode
== NOP_EXPR
)
9648 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
9650 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
9652 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
9653 COMPOUND_EXPR
, orig_rhs1
, stmt
);
9654 if (code
!= OMP_ATOMIC
)
9656 stmt
= build_min_nt_loc (loc
, code
, orig_lhs1
, stmt
);
9657 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9658 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9661 stmt
= build2 (OMP_ATOMIC
, void_type_node
,
9662 clauses
? clauses
: integer_zero_node
, stmt
);
9663 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9664 SET_EXPR_LOCATION (stmt
, loc
);
9667 /* Avoid -Wunused-value warnings here, the whole construct has side-effects
9668 and even if it might be wrapped from fold-const.c or c-omp.c wrapped
9669 in some tree that appears to be unused, the value is not unused. */
9670 warning_sentinel
w (warn_unused_value
);
9671 finish_expr_stmt (stmt
);
9675 finish_omp_barrier (void)
9677 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
9679 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9680 finish_expr_stmt (stmt
);
9684 finish_omp_depobj (location_t loc
, tree depobj
,
9685 enum omp_clause_depend_kind kind
, tree clause
)
9687 if (!error_operand_p (depobj
) && !type_dependent_expression_p (depobj
))
9689 if (!lvalue_p (depobj
))
9691 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
9692 "%<depobj%> expression is not lvalue expression");
9693 depobj
= error_mark_node
;
9697 if (processing_template_decl
)
9699 if (clause
== NULL_TREE
)
9700 clause
= build_int_cst (integer_type_node
, kind
);
9701 add_stmt (build_min_nt_loc (loc
, OMP_DEPOBJ
, depobj
, clause
));
9705 if (!error_operand_p (depobj
))
9707 tree addr
= cp_build_addr_expr (depobj
, tf_warning_or_error
);
9708 if (addr
== error_mark_node
)
9709 depobj
= error_mark_node
;
9711 depobj
= cp_build_indirect_ref (loc
, addr
, RO_UNARY_STAR
,
9712 tf_warning_or_error
);
9715 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
9719 finish_omp_flush (int mo
)
9721 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
9723 if (mo
!= MEMMODEL_LAST
)
9725 fn
= builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE
);
9726 vec
->quick_push (build_int_cst (integer_type_node
, mo
));
9728 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9729 finish_expr_stmt (stmt
);
9733 finish_omp_taskwait (void)
9735 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
9737 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9738 finish_expr_stmt (stmt
);
9742 finish_omp_taskyield (void)
9744 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
9746 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9747 finish_expr_stmt (stmt
);
9751 finish_omp_cancel (tree clauses
)
9753 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
9755 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9757 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9759 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9761 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9765 error ("%<#pragma omp cancel%> must specify one of "
9766 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9770 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
9771 if (ifc
!= NULL_TREE
)
9773 if (OMP_CLAUSE_IF_MODIFIER (ifc
) != ERROR_MARK
9774 && OMP_CLAUSE_IF_MODIFIER (ifc
) != VOID_CST
)
9775 error_at (OMP_CLAUSE_LOCATION (ifc
),
9776 "expected %<cancel%> %<if%> clause modifier");
9779 tree ifc2
= omp_find_clause (OMP_CLAUSE_CHAIN (ifc
), OMP_CLAUSE_IF
);
9780 if (ifc2
!= NULL_TREE
)
9782 gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc
) == VOID_CST
9783 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != ERROR_MARK
9784 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != VOID_CST
);
9785 error_at (OMP_CLAUSE_LOCATION (ifc2
),
9786 "expected %<cancel%> %<if%> clause modifier");
9790 if (!processing_template_decl
)
9791 ifc
= maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc
));
9793 ifc
= build_x_binary_op (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
9794 OMP_CLAUSE_IF_EXPR (ifc
), ERROR_MARK
,
9795 integer_zero_node
, ERROR_MARK
,
9796 NULL
, tf_warning_or_error
);
9799 ifc
= boolean_true_node
;
9800 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
9801 vec
->quick_push (ifc
);
9802 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9803 finish_expr_stmt (stmt
);
9807 finish_omp_cancellation_point (tree clauses
)
9809 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
9811 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9813 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9815 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9817 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9821 error ("%<#pragma omp cancellation point%> must specify one of "
9822 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9826 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
9827 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9828 finish_expr_stmt (stmt
);
9831 /* Begin a __transaction_atomic or __transaction_relaxed statement.
9832 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
9833 should create an extra compound stmt. */
9836 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
9841 *pcompound
= begin_compound_stmt (0);
9843 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
9845 /* Only add the statement to the function if support enabled. */
9849 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
9850 ? G_("%<__transaction_relaxed%> without "
9851 "transactional memory support enabled")
9852 : G_("%<__transaction_atomic%> without "
9853 "transactional memory support enabled")));
9855 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
9856 TREE_SIDE_EFFECTS (r
) = 1;
9860 /* End a __transaction_atomic or __transaction_relaxed statement.
9861 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
9862 and we should end the compound. If NOEX is non-NULL, we wrap the body in
9863 a MUST_NOT_THROW_EXPR with NOEX as condition. */
9866 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
9868 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
9869 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
9870 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
9871 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
9873 /* noexcept specifications are not allowed for function transactions. */
9874 gcc_assert (!(noex
&& compound_stmt
));
9877 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
9879 protected_set_expr_location
9880 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
9881 TREE_SIDE_EFFECTS (body
) = 1;
9882 TRANSACTION_EXPR_BODY (stmt
) = body
;
9886 finish_compound_stmt (compound_stmt
);
9889 /* Build a __transaction_atomic or __transaction_relaxed expression. If
9890 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
9894 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
9899 expr
= build_must_not_throw_expr (expr
, noex
);
9900 protected_set_expr_location (expr
, loc
);
9901 TREE_SIDE_EFFECTS (expr
) = 1;
9903 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
9904 if (flags
& TM_STMT_ATTR_RELAXED
)
9905 TRANSACTION_EXPR_RELAXED (ret
) = 1;
9906 TREE_SIDE_EFFECTS (ret
) = 1;
9907 SET_EXPR_LOCATION (ret
, loc
);
9912 init_cp_semantics (void)
9917 /* If we have a condition in conjunctive normal form (CNF), find the first
9918 failing clause. In other words, given an expression like
9920 true && true && false && true && false
9922 return the first 'false'. EXPR is the expression. */
9925 find_failing_clause_r (tree expr
)
9927 if (TREE_CODE (expr
) == TRUTH_ANDIF_EXPR
)
9929 /* First check the left side... */
9930 tree e
= find_failing_clause_r (TREE_OPERAND (expr
, 0));
9932 /* ...if we didn't find a false clause, check the right side. */
9933 e
= find_failing_clause_r (TREE_OPERAND (expr
, 1));
9936 tree e
= contextual_conv_bool (expr
, tf_none
);
9937 e
= fold_non_dependent_expr (e
, tf_none
, /*manifestly_const_eval=*/true);
9938 if (integer_zerop (e
))
9939 /* This is the failing clause. */
9944 /* Wrapper for find_failing_clause_r. */
9947 find_failing_clause (tree expr
)
9949 if (TREE_CODE (expr
) != TRUTH_ANDIF_EXPR
)
9951 return find_failing_clause_r (expr
);
9954 /* Build a STATIC_ASSERT for a static assertion with the condition
9955 CONDITION and the message text MESSAGE. LOCATION is the location
9956 of the static assertion in the source code. When MEMBER_P, this
9957 static assertion is a member of a class. If SHOW_EXPR_P is true,
9958 print the condition (because it was instantiation-dependent). */
9961 finish_static_assert (tree condition
, tree message
, location_t location
,
9962 bool member_p
, bool show_expr_p
)
9964 tsubst_flags_t complain
= tf_warning_or_error
;
9966 if (message
== NULL_TREE
9967 || message
== error_mark_node
9968 || condition
== NULL_TREE
9969 || condition
== error_mark_node
)
9972 if (check_for_bare_parameter_packs (condition
))
9973 condition
= error_mark_node
;
9975 if (instantiation_dependent_expression_p (condition
))
9977 /* We're in a template; build a STATIC_ASSERT and put it in
9981 assertion
= make_node (STATIC_ASSERT
);
9982 STATIC_ASSERT_CONDITION (assertion
) = condition
;
9983 STATIC_ASSERT_MESSAGE (assertion
) = message
;
9984 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
9987 maybe_add_class_template_decl_list (current_class_type
,
9991 add_stmt (assertion
);
9996 /* Save the condition in case it was a concept check. */
9997 tree orig_condition
= condition
;
9999 /* Fold the expression and convert it to a boolean value. */
10000 condition
= contextual_conv_bool (condition
, complain
);
10001 condition
= fold_non_dependent_expr (condition
, complain
,
10002 /*manifestly_const_eval=*/true);
10004 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
10005 /* Do nothing; the condition is satisfied. */
10009 iloc_sentinel
ils (location
);
10011 if (integer_zerop (condition
))
10013 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
10014 (TREE_TYPE (TREE_TYPE (message
))));
10015 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
10017 /* See if we can find which clause was failing (for logical AND). */
10018 tree bad
= find_failing_clause (orig_condition
);
10019 /* If not, or its location is unusable, fall back to the previous
10021 location_t cloc
= location
;
10022 if (cp_expr_location (bad
) != UNKNOWN_LOCATION
)
10023 cloc
= cp_expr_location (bad
);
10025 /* Report the error. */
10027 error_at (cloc
, "static assertion failed");
10029 error_at (cloc
, "static assertion failed: %s",
10030 TREE_STRING_POINTER (message
));
10032 inform (cloc
, "%qE evaluates to false",
10033 /* Nobody wants to see the artificial (bool) cast. */
10034 (bad
? tree_strip_nop_conversions (bad
) : orig_condition
));
10036 /* Actually explain the failure if this is a concept check or a
10037 requires-expression. */
10038 if (concept_check_p (orig_condition
)
10039 || TREE_CODE (orig_condition
) == REQUIRES_EXPR
)
10040 diagnose_constraints (location
, orig_condition
, NULL_TREE
);
10042 else if (condition
&& condition
!= error_mark_node
)
10044 error ("non-constant condition for static assertion");
10045 if (require_rvalue_constant_expression (condition
))
10046 cxx_constant_value (condition
);
10051 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
10052 suitable for use as a type-specifier.
10054 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
10055 id-expression or a class member access, FALSE when it was parsed as
10056 a full expression. */
10059 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
10060 tsubst_flags_t complain
)
10062 tree type
= NULL_TREE
;
10064 if (!expr
|| error_operand_p (expr
))
10065 return error_mark_node
;
10068 || TREE_CODE (expr
) == TYPE_DECL
10069 || (TREE_CODE (expr
) == BIT_NOT_EXPR
10070 && TYPE_P (TREE_OPERAND (expr
, 0))))
10072 if (complain
& tf_error
)
10073 error ("argument to %<decltype%> must be an expression");
10074 return error_mark_node
;
10077 /* Depending on the resolution of DR 1172, we may later need to distinguish
10078 instantiation-dependent but not type-dependent expressions so that, say,
10079 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
10080 if (instantiation_dependent_uneval_expression_p (expr
))
10082 type
= cxx_make_type (DECLTYPE_TYPE
);
10083 DECLTYPE_TYPE_EXPR (type
) = expr
;
10084 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
10085 = id_expression_or_member_access_p
;
10086 SET_TYPE_STRUCTURAL_EQUALITY (type
);
10090 else if (processing_template_decl
)
10092 ++cp_unevaluated_operand
;
10093 expr
= instantiate_non_dependent_expr_sfinae (expr
, complain
);
10094 --cp_unevaluated_operand
;
10095 if (expr
== error_mark_node
)
10096 return error_mark_node
;
10099 /* The type denoted by decltype(e) is defined as follows: */
10101 expr
= resolve_nondeduced_context (expr
, complain
);
10103 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
10104 return error_mark_node
;
10106 if (type_unknown_p (expr
))
10108 if (complain
& tf_error
)
10109 error ("%<decltype%> cannot resolve address of overloaded function");
10110 return error_mark_node
;
10113 /* To get the size of a static data member declared as an array of
10114 unknown bound, we need to instantiate it. */
10116 && VAR_HAD_UNKNOWN_BOUND (expr
)
10117 && DECL_TEMPLATE_INSTANTIATION (expr
))
10118 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
10120 if (id_expression_or_member_access_p
)
10122 /* If e is an id-expression or a class member access (5.2.5
10123 [expr.ref]), decltype(e) is defined as the type of the entity
10124 named by e. If there is no such entity, or e names a set of
10125 overloaded functions, the program is ill-formed. */
10126 if (identifier_p (expr
))
10127 expr
= lookup_name (expr
);
10129 if (INDIRECT_REF_P (expr
)
10130 || TREE_CODE (expr
) == VIEW_CONVERT_EXPR
)
10131 /* This can happen when the expression is, e.g., "a.b". Just
10132 look at the underlying operand. */
10133 expr
= TREE_OPERAND (expr
, 0);
10135 if (TREE_CODE (expr
) == OFFSET_REF
10136 || TREE_CODE (expr
) == MEMBER_REF
10137 || TREE_CODE (expr
) == SCOPE_REF
)
10138 /* We're only interested in the field itself. If it is a
10139 BASELINK, we will need to see through it in the next
10141 expr
= TREE_OPERAND (expr
, 1);
10143 if (BASELINK_P (expr
))
10144 /* See through BASELINK nodes to the underlying function. */
10145 expr
= BASELINK_FUNCTIONS (expr
);
10147 /* decltype of a decomposition name drops references in the tuple case
10148 (unlike decltype of a normal variable) and keeps cv-qualifiers from
10149 the containing object in the other cases (unlike decltype of a member
10150 access expression). */
10151 if (DECL_DECOMPOSITION_P (expr
))
10153 if (DECL_HAS_VALUE_EXPR_P (expr
))
10154 /* Expr is an array or struct subobject proxy, handle
10155 bit-fields properly. */
10156 return unlowered_expr_type (expr
);
10158 /* Expr is a reference variable for the tuple case. */
10159 return lookup_decomp_type (expr
);
10162 switch (TREE_CODE (expr
))
10165 if (DECL_BIT_FIELD_TYPE (expr
))
10167 type
= DECL_BIT_FIELD_TYPE (expr
);
10170 /* Fall through for fields that aren't bitfields. */
10171 gcc_fallthrough ();
10173 case FUNCTION_DECL
:
10178 case TEMPLATE_PARM_INDEX
:
10179 expr
= mark_type_use (expr
);
10180 type
= TREE_TYPE (expr
);
10184 type
= error_mark_node
;
10187 case COMPONENT_REF
:
10188 case COMPOUND_EXPR
:
10189 mark_type_use (expr
);
10190 type
= is_bitfield_expr_with_lowered_type (expr
);
10192 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
10195 case BIT_FIELD_REF
:
10196 gcc_unreachable ();
10200 /* We can get here when the id-expression refers to an
10201 enumerator or non-type template parameter. */
10202 type
= TREE_TYPE (expr
);
10206 /* Handle instantiated template non-type arguments. */
10207 type
= TREE_TYPE (expr
);
10213 /* Within a lambda-expression:
10215 Every occurrence of decltype((x)) where x is a possibly
10216 parenthesized id-expression that names an entity of
10217 automatic storage duration is treated as if x were
10218 transformed into an access to a corresponding data member
10219 of the closure type that would have been declared if x
10220 were a use of the denoted entity. */
10221 if (outer_automatic_var_p (expr
)
10222 && current_function_decl
10223 && LAMBDA_FUNCTION_P (current_function_decl
))
10224 type
= capture_decltype (expr
);
10225 else if (error_operand_p (expr
))
10226 type
= error_mark_node
;
10227 else if (expr
== current_class_ptr
)
10228 /* If the expression is just "this", we want the
10229 cv-unqualified pointer for the "this" type. */
10230 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
10233 /* Otherwise, where T is the type of e, if e is an lvalue,
10234 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
10235 cp_lvalue_kind clk
= lvalue_kind (expr
);
10236 type
= unlowered_expr_type (expr
);
10237 gcc_assert (!TYPE_REF_P (type
));
10239 /* For vector types, pick a non-opaque variant. */
10240 if (VECTOR_TYPE_P (type
))
10241 type
= strip_typedefs (type
);
10243 if (clk
!= clk_none
&& !(clk
& clk_class
))
10244 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
10251 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
10252 __has_nothrow_copy, depending on assign_p. Returns true iff all
10253 the copy {ctor,assign} fns are nothrow. */
10256 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
10258 tree fns
= NULL_TREE
;
10260 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
10261 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
10262 : ctor_identifier
);
10264 bool saw_copy
= false;
10265 for (ovl_iterator
iter (fns
); iter
; ++iter
)
10269 if (copy_fn_p (fn
) > 0)
10272 if (!maybe_instantiate_noexcept (fn
)
10273 || !TYPE_NOTHROW_P (TREE_TYPE (fn
)))
10281 /* Actually evaluates the trait. */
10284 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
10286 enum tree_code type_code1
;
10289 type_code1
= TREE_CODE (type1
);
10293 case CPTK_HAS_NOTHROW_ASSIGN
:
10294 type1
= strip_array_types (type1
);
10295 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
10296 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
10297 || (CLASS_TYPE_P (type1
)
10298 && classtype_has_nothrow_assign_or_copy_p (type1
,
10301 case CPTK_HAS_TRIVIAL_ASSIGN
:
10302 /* ??? The standard seems to be missing the "or array of such a class
10303 type" wording for this trait. */
10304 type1
= strip_array_types (type1
);
10305 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
10306 && (trivial_type_p (type1
)
10307 || (CLASS_TYPE_P (type1
)
10308 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
10310 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
10311 type1
= strip_array_types (type1
);
10312 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
10313 || (CLASS_TYPE_P (type1
)
10314 && (t
= locate_ctor (type1
))
10315 && maybe_instantiate_noexcept (t
)
10316 && TYPE_NOTHROW_P (TREE_TYPE (t
))));
10318 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
10319 type1
= strip_array_types (type1
);
10320 return (trivial_type_p (type1
)
10321 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
10323 case CPTK_HAS_NOTHROW_COPY
:
10324 type1
= strip_array_types (type1
);
10325 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
10326 || (CLASS_TYPE_P (type1
)
10327 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
10329 case CPTK_HAS_TRIVIAL_COPY
:
10330 /* ??? The standard seems to be missing the "or array of such a class
10331 type" wording for this trait. */
10332 type1
= strip_array_types (type1
);
10333 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
10334 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
10336 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
10337 type1
= strip_array_types (type1
);
10338 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
10339 || (CLASS_TYPE_P (type1
)
10340 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
10342 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
10343 return type_has_virtual_destructor (type1
);
10345 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
10346 return type_has_unique_obj_representations (type1
);
10348 case CPTK_IS_ABSTRACT
:
10349 return ABSTRACT_CLASS_TYPE_P (type1
);
10351 case CPTK_IS_AGGREGATE
:
10352 return CP_AGGREGATE_TYPE_P (type1
);
10354 case CPTK_IS_BASE_OF
:
10355 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
10356 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
10357 || DERIVED_FROM_P (type1
, type2
)));
10359 case CPTK_IS_CLASS
:
10360 return NON_UNION_CLASS_TYPE_P (type1
);
10362 case CPTK_IS_EMPTY
:
10363 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
10366 return type_code1
== ENUMERAL_TYPE
;
10368 case CPTK_IS_FINAL
:
10369 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
10371 case CPTK_IS_LITERAL_TYPE
:
10372 return literal_type_p (type1
);
10375 return pod_type_p (type1
);
10377 case CPTK_IS_POLYMORPHIC
:
10378 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
10380 case CPTK_IS_SAME_AS
:
10381 return same_type_p (type1
, type2
);
10383 case CPTK_IS_STD_LAYOUT
:
10384 return std_layout_type_p (type1
);
10386 case CPTK_IS_TRIVIAL
:
10387 return trivial_type_p (type1
);
10389 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
10390 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
10392 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
10393 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
10395 case CPTK_IS_TRIVIALLY_COPYABLE
:
10396 return trivially_copyable_p (type1
);
10398 case CPTK_IS_UNION
:
10399 return type_code1
== UNION_TYPE
;
10401 case CPTK_IS_ASSIGNABLE
:
10402 return is_xible (MODIFY_EXPR
, type1
, type2
);
10404 case CPTK_IS_CONSTRUCTIBLE
:
10405 return is_xible (INIT_EXPR
, type1
, type2
);
10407 case CPTK_IS_NOTHROW_ASSIGNABLE
:
10408 return is_nothrow_xible (MODIFY_EXPR
, type1
, type2
);
10410 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
10411 return is_nothrow_xible (INIT_EXPR
, type1
, type2
);
10414 gcc_unreachable ();
10419 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
10420 void, or a complete type, returns true, otherwise false. */
10423 check_trait_type (tree type
)
10425 if (type
== NULL_TREE
)
10428 if (TREE_CODE (type
) == TREE_LIST
)
10429 return (check_trait_type (TREE_VALUE (type
))
10430 && check_trait_type (TREE_CHAIN (type
)));
10432 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
10433 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
10436 if (VOID_TYPE_P (type
))
10439 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
10442 /* Process a trait expression. */
10445 finish_trait_expr (location_t loc
, cp_trait_kind kind
, tree type1
, tree type2
)
10447 if (type1
== error_mark_node
10448 || type2
== error_mark_node
)
10449 return error_mark_node
;
10451 if (processing_template_decl
)
10453 tree trait_expr
= make_node (TRAIT_EXPR
);
10454 TREE_TYPE (trait_expr
) = boolean_type_node
;
10455 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
10456 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
10457 TRAIT_EXPR_KIND (trait_expr
) = kind
;
10458 TRAIT_EXPR_LOCATION (trait_expr
) = loc
;
10464 case CPTK_HAS_NOTHROW_ASSIGN
:
10465 case CPTK_HAS_TRIVIAL_ASSIGN
:
10466 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
10467 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
10468 case CPTK_HAS_NOTHROW_COPY
:
10469 case CPTK_HAS_TRIVIAL_COPY
:
10470 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
10471 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
10472 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
10473 case CPTK_IS_ABSTRACT
:
10474 case CPTK_IS_AGGREGATE
:
10475 case CPTK_IS_EMPTY
:
10476 case CPTK_IS_FINAL
:
10477 case CPTK_IS_LITERAL_TYPE
:
10479 case CPTK_IS_POLYMORPHIC
:
10480 case CPTK_IS_STD_LAYOUT
:
10481 case CPTK_IS_TRIVIAL
:
10482 case CPTK_IS_TRIVIALLY_COPYABLE
:
10483 if (!check_trait_type (type1
))
10484 return error_mark_node
;
10487 case CPTK_IS_ASSIGNABLE
:
10488 case CPTK_IS_CONSTRUCTIBLE
:
10491 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
10492 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
10493 case CPTK_IS_NOTHROW_ASSIGNABLE
:
10494 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
10495 if (!check_trait_type (type1
)
10496 || !check_trait_type (type2
))
10497 return error_mark_node
;
10500 case CPTK_IS_BASE_OF
:
10501 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
10502 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
10503 && !complete_type_or_else (type2
, NULL_TREE
))
10504 /* We already issued an error. */
10505 return error_mark_node
;
10508 case CPTK_IS_CLASS
:
10510 case CPTK_IS_UNION
:
10511 case CPTK_IS_SAME_AS
:
10515 gcc_unreachable ();
10518 tree val
= (trait_expr_value (kind
, type1
, type2
)
10519 ? boolean_true_node
: boolean_false_node
);
10520 return maybe_wrap_with_location (val
, loc
);
10523 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
10524 which is ignored for C++. */
10527 set_float_const_decimal64 (void)
10532 clear_float_const_decimal64 (void)
10537 float_const_decimal64_p (void)
10543 /* Return true if T designates the implied `this' parameter. */
10546 is_this_parameter (tree t
)
10548 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
10550 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
)
10551 || (cp_binding_oracle
&& TREE_CODE (t
) == VAR_DECL
));
10555 /* Insert the deduced return type for an auto function. */
10558 apply_deduced_return_type (tree fco
, tree return_type
)
10562 if (return_type
== error_mark_node
)
10565 if (DECL_CONV_FN_P (fco
))
10566 DECL_NAME (fco
) = make_conv_op_name (return_type
);
10568 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
10570 result
= DECL_RESULT (fco
);
10571 if (result
== NULL_TREE
)
10573 if (TREE_TYPE (result
) == return_type
)
10576 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
10577 && !complete_type_or_else (return_type
, NULL_TREE
))
10580 /* We already have a DECL_RESULT from start_preparsed_function.
10581 Now we need to redo the work it and allocate_struct_function
10582 did to reflect the new type. */
10583 gcc_assert (current_function_decl
== fco
);
10584 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
10585 TYPE_MAIN_VARIANT (return_type
));
10586 DECL_ARTIFICIAL (result
) = 1;
10587 DECL_IGNORED_P (result
) = 1;
10588 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
10591 DECL_RESULT (fco
) = result
;
10593 if (!processing_template_decl
)
10595 bool aggr
= aggregate_value_p (result
, fco
);
10596 #ifdef PCC_STATIC_STRUCT_RETURN
10597 cfun
->returns_pcc_struct
= aggr
;
10599 cfun
->returns_struct
= aggr
;
10603 /* DECL is a local variable or parameter from the surrounding scope of a
10604 lambda-expression. Returns the decltype for a use of the capture field
10605 for DECL even if it hasn't been captured yet. */
10608 capture_decltype (tree decl
)
10610 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
10611 tree cap
= lookup_name (DECL_NAME (decl
), LOOK_where::BLOCK
,
10612 LOOK_want::HIDDEN_LAMBDA
);
10615 if (cap
&& is_capture_proxy (cap
))
10616 type
= TREE_TYPE (cap
);
10618 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
10621 error ("%qD is not captured", decl
);
10622 return error_mark_node
;
10625 type
= TREE_TYPE (decl
);
10626 if (TYPE_REF_P (type
)
10627 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
10628 type
= TREE_TYPE (type
);
10631 case CPLD_REFERENCE
:
10632 type
= TREE_TYPE (decl
);
10633 if (!TYPE_REF_P (type
))
10634 type
= build_reference_type (TREE_TYPE (decl
));
10638 gcc_unreachable ();
10641 if (!TYPE_REF_P (type
))
10643 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
10644 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
10645 |TYPE_QUAL_CONST
));
10646 type
= build_reference_type (type
);
10651 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
10652 this is a right unary fold. Otherwise it is a left unary fold. */
10655 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
10657 /* Build a pack expansion (assuming expr has pack type). */
10658 if (!uses_parameter_packs (expr
))
10660 error_at (location_of (expr
), "operand of fold expression has no "
10661 "unexpanded parameter packs");
10662 return error_mark_node
;
10664 tree pack
= make_pack_expansion (expr
);
10666 /* Build the fold expression. */
10667 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10668 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
);
10669 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10674 finish_left_unary_fold_expr (tree expr
, int op
)
10676 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
10680 finish_right_unary_fold_expr (tree expr
, int op
)
10682 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
10685 /* Build a binary fold expression over EXPR1 and EXPR2. The
10686 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
10687 has an unexpanded parameter pack). */
10690 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
10692 pack
= make_pack_expansion (pack
);
10693 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10694 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
, init
);
10695 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10700 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
10702 // Determine which expr has an unexpanded parameter pack and
10703 // set the pack and initial term.
10704 bool pack1
= uses_parameter_packs (expr1
);
10705 bool pack2
= uses_parameter_packs (expr2
);
10706 if (pack1
&& !pack2
)
10707 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
10708 else if (pack2
&& !pack1
)
10709 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
10713 error ("both arguments in binary fold have unexpanded parameter packs");
10715 error ("no unexpanded parameter packs in binary fold");
10717 return error_mark_node
;
10720 /* Finish __builtin_launder (arg). */
10723 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
10725 tree orig_arg
= arg
;
10726 if (!type_dependent_expression_p (arg
))
10727 arg
= decay_conversion (arg
, complain
);
10728 if (error_operand_p (arg
))
10729 return error_mark_node
;
10730 if (!type_dependent_expression_p (arg
)
10731 && !TYPE_PTR_P (TREE_TYPE (arg
)))
10733 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
10734 return error_mark_node
;
10736 if (processing_template_decl
)
10738 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
10739 TREE_TYPE (arg
), 1, arg
);
10742 /* Finish __builtin_convertvector (arg, type). */
10745 cp_build_vec_convert (tree arg
, location_t loc
, tree type
,
10746 tsubst_flags_t complain
)
10748 if (error_operand_p (type
))
10749 return error_mark_node
;
10750 if (error_operand_p (arg
))
10751 return error_mark_node
;
10753 tree ret
= NULL_TREE
;
10754 if (!type_dependent_expression_p (arg
) && !dependent_type_p (type
))
10755 ret
= c_build_vec_convert (cp_expr_loc_or_input_loc (arg
),
10756 decay_conversion (arg
, complain
),
10757 loc
, type
, (complain
& tf_error
) != 0);
10759 if (!processing_template_decl
)
10762 return build_call_expr_internal_loc (loc
, IFN_VEC_CONVERT
, type
, 1, arg
);
10765 /* Finish __builtin_bit_cast (type, arg). */
10768 cp_build_bit_cast (location_t loc
, tree type
, tree arg
,
10769 tsubst_flags_t complain
)
10771 if (error_operand_p (type
))
10772 return error_mark_node
;
10773 if (!dependent_type_p (type
))
10775 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
))
10776 return error_mark_node
;
10777 if (TREE_CODE (type
) == ARRAY_TYPE
)
10779 /* std::bit_cast for destination ARRAY_TYPE is not possible,
10780 as functions may not return an array, so don't bother trying
10781 to support this (and then deal with VLAs etc.). */
10782 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
10783 "is an array type", type
);
10784 return error_mark_node
;
10786 if (!trivially_copyable_p (type
))
10788 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
10789 "is not trivially copyable", type
);
10790 return error_mark_node
;
10794 if (error_operand_p (arg
))
10795 return error_mark_node
;
10797 if (!type_dependent_expression_p (arg
))
10799 if (TREE_CODE (TREE_TYPE (arg
)) == ARRAY_TYPE
)
10801 /* Don't perform array-to-pointer conversion. */
10802 arg
= mark_rvalue_use (arg
, loc
, true);
10803 if (!complete_type_or_maybe_complain (TREE_TYPE (arg
), arg
, complain
))
10804 return error_mark_node
;
10807 arg
= decay_conversion (arg
, complain
);
10809 if (error_operand_p (arg
))
10810 return error_mark_node
;
10812 if (!trivially_copyable_p (TREE_TYPE (arg
)))
10814 error_at (cp_expr_loc_or_loc (arg
, loc
),
10815 "%<__builtin_bit_cast%> source type %qT "
10816 "is not trivially copyable", TREE_TYPE (arg
));
10817 return error_mark_node
;
10819 if (!dependent_type_p (type
)
10820 && !cp_tree_equal (TYPE_SIZE_UNIT (type
),
10821 TYPE_SIZE_UNIT (TREE_TYPE (arg
))))
10823 error_at (loc
, "%<__builtin_bit_cast%> source size %qE "
10824 "not equal to destination type size %qE",
10825 TYPE_SIZE_UNIT (TREE_TYPE (arg
)),
10826 TYPE_SIZE_UNIT (type
));
10827 return error_mark_node
;
10831 tree ret
= build_min (BIT_CAST_EXPR
, type
, arg
);
10832 SET_EXPR_LOCATION (ret
, loc
);
10834 if (!processing_template_decl
&& CLASS_TYPE_P (type
))
10835 ret
= get_target_expr_sfinae (ret
, complain
);
10840 #include "gt-cp-semantics.h"