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",
7433 else if (error_operand_p (t
))
7440 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
7441 if (!type_dependent_expression_p (t
)
7442 && (!INTEGRAL_TYPE_P (type
)
7443 || TREE_CODE (type
) != ENUMERAL_TYPE
7444 || TYPE_NAME (type
) == NULL_TREE
7445 || (DECL_NAME (TYPE_NAME (type
))
7446 != get_identifier ("omp_event_handle_t"))))
7448 error_at (OMP_CLAUSE_LOCATION (c
),
7449 "%<detach%> clause event handle "
7450 "has type %qT rather than "
7451 "%<omp_event_handle_t%>",
7456 cxx_mark_addressable (t
);
7460 case OMP_CLAUSE_MAP
:
7462 case OMP_CLAUSE_FROM
:
7463 case OMP_CLAUSE__CACHE_
:
7464 t
= OMP_CLAUSE_DECL (c
);
7465 if (TREE_CODE (t
) == TREE_LIST
)
7467 if (handle_omp_array_sections (c
, ort
))
7471 t
= OMP_CLAUSE_DECL (c
);
7472 if (TREE_CODE (t
) != TREE_LIST
7473 && !type_dependent_expression_p (t
)
7474 && !cp_omp_mappable_type (TREE_TYPE (t
)))
7476 error_at (OMP_CLAUSE_LOCATION (c
),
7477 "array section does not have mappable type "
7479 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7480 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7483 while (TREE_CODE (t
) == ARRAY_REF
)
7484 t
= TREE_OPERAND (t
, 0);
7485 if (TREE_CODE (t
) == COMPONENT_REF
7486 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
7488 while (TREE_CODE (t
) == COMPONENT_REF
)
7489 t
= TREE_OPERAND (t
, 0);
7490 if (REFERENCE_REF_P (t
))
7491 t
= TREE_OPERAND (t
, 0);
7492 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7494 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7496 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7497 error_at (OMP_CLAUSE_LOCATION (c
),
7498 "%qD appears more than once in motion"
7500 else if (ort
== C_ORT_ACC
)
7501 error_at (OMP_CLAUSE_LOCATION (c
),
7502 "%qD appears more than once in data"
7505 error_at (OMP_CLAUSE_LOCATION (c
),
7506 "%qD appears more than once in map"
7512 bitmap_set_bit (&map_head
, DECL_UID (t
));
7513 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7517 if (cp_oacc_check_attachments (c
))
7519 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7520 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7521 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7522 /* In this case, we have a single array element which is a
7523 pointer, and we already set OMP_CLAUSE_SIZE in
7524 handle_omp_array_sections above. For attach/detach clauses,
7525 reset the OMP_CLAUSE_SIZE (representing a bias) to zero
7527 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
7530 if (t
== error_mark_node
)
7535 /* OpenACC attach / detach clauses must be pointers. */
7536 if (cp_oacc_check_attachments (c
))
7541 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7542 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7543 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7544 /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
7545 bias) to zero here, so it is not set erroneously to the pointer
7546 size later on in gimplify.c. */
7547 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
7548 if (REFERENCE_REF_P (t
)
7549 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
7551 t
= TREE_OPERAND (t
, 0);
7552 OMP_CLAUSE_DECL (c
) = t
;
7554 if ((ort
== C_ORT_ACC
|| ort
== C_ORT_OMP
)
7555 && TREE_CODE (t
) == COMPONENT_REF
7556 && TREE_CODE (TREE_OPERAND (t
, 0)) == INDIRECT_REF
)
7557 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
7558 if (TREE_CODE (t
) == COMPONENT_REF
7559 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
7560 || ort
== C_ORT_ACC
)
7561 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
7563 if (type_dependent_expression_p (t
))
7565 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7566 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7568 error_at (OMP_CLAUSE_LOCATION (c
),
7569 "bit-field %qE in %qs clause",
7570 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7573 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7575 error_at (OMP_CLAUSE_LOCATION (c
),
7576 "%qE does not have a mappable type in %qs clause",
7577 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7578 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7581 while (TREE_CODE (t
) == COMPONENT_REF
)
7583 if (TREE_TYPE (TREE_OPERAND (t
, 0))
7584 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
7587 error_at (OMP_CLAUSE_LOCATION (c
),
7588 "%qE is a member of a union", t
);
7592 t
= TREE_OPERAND (t
, 0);
7596 if (REFERENCE_REF_P (t
))
7597 t
= TREE_OPERAND (t
, 0);
7598 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7600 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
))
7601 || (ort
== C_ORT_OMP
7602 && bitmap_bit_p (&map_head
, DECL_UID (t
))))
7603 goto handle_map_references
;
7606 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7608 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7610 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7611 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7612 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
7613 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH_DETACH
))
7616 error_at (OMP_CLAUSE_LOCATION (c
),
7617 "%qD is not a variable in %qs clause", t
,
7618 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7620 error_at (OMP_CLAUSE_LOCATION (c
),
7621 "%qE is not a variable in %qs clause", t
,
7622 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7625 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7627 error_at (OMP_CLAUSE_LOCATION (c
),
7628 "%qD is threadprivate variable in %qs clause", t
,
7629 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7632 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7634 error_at (OMP_CLAUSE_LOCATION (c
),
7635 "%<this%> allowed in OpenMP only in %<declare simd%>"
7640 else if (!processing_template_decl
7641 && !TYPE_REF_P (TREE_TYPE (t
))
7642 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
7643 || (OMP_CLAUSE_MAP_KIND (c
)
7644 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
7645 && !cxx_mark_addressable (t
))
7647 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7648 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7649 || (OMP_CLAUSE_MAP_KIND (c
)
7650 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
7651 && t
== OMP_CLAUSE_DECL (c
)
7652 && !type_dependent_expression_p (t
)
7653 && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t
))
7654 ? TREE_TYPE (TREE_TYPE (t
))
7657 error_at (OMP_CLAUSE_LOCATION (c
),
7658 "%qD does not have a mappable type in %qs clause", t
,
7659 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7660 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7663 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7664 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
7665 && !type_dependent_expression_p (t
)
7666 && !INDIRECT_TYPE_P (TREE_TYPE (t
)))
7668 error_at (OMP_CLAUSE_LOCATION (c
),
7669 "%qD is not a pointer variable", t
);
7672 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7673 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
7675 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7676 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7678 error_at (OMP_CLAUSE_LOCATION (c
),
7679 "%qD appears more than once in data clauses", t
);
7682 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7684 if (ort
== C_ORT_ACC
)
7685 error_at (OMP_CLAUSE_LOCATION (c
),
7686 "%qD appears more than once in data clauses", t
);
7688 error_at (OMP_CLAUSE_LOCATION (c
),
7689 "%qD appears both in data and map clauses", t
);
7693 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7695 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
7696 && !bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7698 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7699 error_at (OMP_CLAUSE_LOCATION (c
),
7700 "%qD appears more than once in motion clauses", t
);
7701 else if (ort
== C_ORT_ACC
)
7702 error_at (OMP_CLAUSE_LOCATION (c
),
7703 "%qD appears more than once in data clauses", t
);
7705 error_at (OMP_CLAUSE_LOCATION (c
),
7706 "%qD appears more than once in map clauses", t
);
7709 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7710 && ort
== C_ORT_ACC
)
7712 error_at (OMP_CLAUSE_LOCATION (c
),
7713 "%qD appears more than once in data clauses", t
);
7716 else if (bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7718 if (ort
== C_ORT_ACC
)
7719 error_at (OMP_CLAUSE_LOCATION (c
),
7720 "%qD appears more than once in data clauses", t
);
7722 error_at (OMP_CLAUSE_LOCATION (c
),
7723 "%qD appears both in data and map clauses", t
);
7728 bitmap_set_bit (&map_head
, DECL_UID (t
));
7729 if (t
!= OMP_CLAUSE_DECL (c
)
7730 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
7731 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7733 handle_map_references
:
7735 && !processing_template_decl
7736 && ort
!= C_ORT_DECLARE_SIMD
7737 && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
))))
7739 t
= OMP_CLAUSE_DECL (c
);
7740 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7742 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7743 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7745 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7747 else if (OMP_CLAUSE_MAP_KIND (c
)
7748 != GOMP_MAP_FIRSTPRIVATE_POINTER
7749 && (OMP_CLAUSE_MAP_KIND (c
)
7750 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
7751 && (OMP_CLAUSE_MAP_KIND (c
)
7752 != GOMP_MAP_ALWAYS_POINTER
)
7753 && (OMP_CLAUSE_MAP_KIND (c
)
7754 != GOMP_MAP_ATTACH_DETACH
))
7756 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
7758 if (TREE_CODE (t
) == COMPONENT_REF
)
7759 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ATTACH_DETACH
);
7761 OMP_CLAUSE_SET_MAP_KIND (c2
,
7762 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
7763 OMP_CLAUSE_DECL (c2
) = t
;
7764 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
7765 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
7766 OMP_CLAUSE_CHAIN (c
) = c2
;
7767 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
7768 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
7770 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
7776 case OMP_CLAUSE_TO_DECLARE
:
7777 case OMP_CLAUSE_LINK
:
7778 t
= OMP_CLAUSE_DECL (c
);
7779 if (TREE_CODE (t
) == FUNCTION_DECL
7780 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7782 else if (!VAR_P (t
))
7784 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
7786 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
7787 error_at (OMP_CLAUSE_LOCATION (c
),
7788 "template %qE in clause %qs", t
,
7789 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7790 else if (really_overloaded_fn (t
))
7791 error_at (OMP_CLAUSE_LOCATION (c
),
7792 "overloaded function name %qE in clause %qs", t
,
7793 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7795 error_at (OMP_CLAUSE_LOCATION (c
),
7796 "%qE is neither a variable nor a function name "
7798 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7801 error_at (OMP_CLAUSE_LOCATION (c
),
7802 "%qE is not a variable in clause %qs", t
,
7803 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7806 else if (DECL_THREAD_LOCAL_P (t
))
7808 error_at (OMP_CLAUSE_LOCATION (c
),
7809 "%qD is threadprivate variable in %qs clause", t
,
7810 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7813 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7815 error_at (OMP_CLAUSE_LOCATION (c
),
7816 "%qD does not have a mappable type in %qs clause", t
,
7817 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7818 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7823 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
7825 error_at (OMP_CLAUSE_LOCATION (c
),
7826 "%qE appears more than once on the same "
7827 "%<declare target%> directive", t
);
7831 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7834 case OMP_CLAUSE_UNIFORM
:
7835 t
= OMP_CLAUSE_DECL (c
);
7836 if (TREE_CODE (t
) != PARM_DECL
)
7838 if (processing_template_decl
)
7841 error_at (OMP_CLAUSE_LOCATION (c
),
7842 "%qD is not an argument in %<uniform%> clause", t
);
7844 error_at (OMP_CLAUSE_LOCATION (c
),
7845 "%qE is not an argument in %<uniform%> clause", t
);
7849 /* map_head bitmap is used as uniform_head if declare_simd. */
7850 bitmap_set_bit (&map_head
, DECL_UID (t
));
7851 goto check_dup_generic
;
7853 case OMP_CLAUSE_GRAINSIZE
:
7854 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
7855 if (t
== error_mark_node
)
7857 else if (!type_dependent_expression_p (t
)
7858 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7860 error_at (OMP_CLAUSE_LOCATION (c
),
7861 "%<grainsize%> expression must be integral");
7866 t
= mark_rvalue_use (t
);
7867 if (!processing_template_decl
)
7869 t
= maybe_constant_value (t
);
7870 if (TREE_CODE (t
) == INTEGER_CST
7871 && tree_int_cst_sgn (t
) != 1)
7873 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7874 "%<grainsize%> value must be positive");
7875 t
= integer_one_node
;
7877 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7879 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
7883 case OMP_CLAUSE_PRIORITY
:
7884 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
7885 if (t
== error_mark_node
)
7887 else if (!type_dependent_expression_p (t
)
7888 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7890 error_at (OMP_CLAUSE_LOCATION (c
),
7891 "%<priority%> expression must be integral");
7896 t
= mark_rvalue_use (t
);
7897 if (!processing_template_decl
)
7899 t
= maybe_constant_value (t
);
7900 if (TREE_CODE (t
) == INTEGER_CST
7901 && tree_int_cst_sgn (t
) == -1)
7903 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7904 "%<priority%> value must be non-negative");
7905 t
= integer_one_node
;
7907 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7909 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
7913 case OMP_CLAUSE_HINT
:
7914 t
= OMP_CLAUSE_HINT_EXPR (c
);
7915 if (t
== error_mark_node
)
7917 else if (!type_dependent_expression_p (t
)
7918 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7920 error_at (OMP_CLAUSE_LOCATION (c
),
7921 "%<hint%> expression must be integral");
7926 t
= mark_rvalue_use (t
);
7927 if (!processing_template_decl
)
7929 t
= maybe_constant_value (t
);
7930 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7931 if (TREE_CODE (t
) != INTEGER_CST
)
7933 error_at (OMP_CLAUSE_LOCATION (c
),
7934 "%<hint%> expression must be constant integer "
7939 OMP_CLAUSE_HINT_EXPR (c
) = t
;
7943 case OMP_CLAUSE_IS_DEVICE_PTR
:
7944 case OMP_CLAUSE_USE_DEVICE_PTR
:
7945 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
7946 t
= OMP_CLAUSE_DECL (c
);
7947 if (!type_dependent_expression_p (t
))
7949 tree type
= TREE_TYPE (t
);
7950 if (!TYPE_PTR_P (type
)
7951 && (!TYPE_REF_P (type
) || !TYPE_PTR_P (TREE_TYPE (type
))))
7953 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
7954 && ort
== C_ORT_OMP
)
7956 error_at (OMP_CLAUSE_LOCATION (c
),
7957 "%qs variable is neither a pointer "
7958 "nor reference to pointer",
7959 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7962 else if (TREE_CODE (type
) != ARRAY_TYPE
7963 && (!TYPE_REF_P (type
)
7964 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
7966 error_at (OMP_CLAUSE_LOCATION (c
),
7967 "%qs variable is neither a pointer, nor an "
7968 "array nor reference to pointer or array",
7969 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7974 goto check_dup_generic
;
7976 case OMP_CLAUSE_USE_DEVICE_ADDR
:
7978 t
= OMP_CLAUSE_DECL (c
);
7979 if (!processing_template_decl
7980 && (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7981 && !TYPE_REF_P (TREE_TYPE (t
))
7982 && !cxx_mark_addressable (t
))
7984 goto check_dup_generic
;
7986 case OMP_CLAUSE_NOWAIT
:
7987 case OMP_CLAUSE_DEFAULT
:
7988 case OMP_CLAUSE_UNTIED
:
7989 case OMP_CLAUSE_COLLAPSE
:
7990 case OMP_CLAUSE_PARALLEL
:
7991 case OMP_CLAUSE_FOR
:
7992 case OMP_CLAUSE_SECTIONS
:
7993 case OMP_CLAUSE_TASKGROUP
:
7994 case OMP_CLAUSE_PROC_BIND
:
7995 case OMP_CLAUSE_DEVICE_TYPE
:
7996 case OMP_CLAUSE_NOGROUP
:
7997 case OMP_CLAUSE_THREADS
:
7998 case OMP_CLAUSE_SIMD
:
7999 case OMP_CLAUSE_DEFAULTMAP
:
8000 case OMP_CLAUSE_BIND
:
8001 case OMP_CLAUSE_AUTO
:
8002 case OMP_CLAUSE_INDEPENDENT
:
8003 case OMP_CLAUSE_SEQ
:
8004 case OMP_CLAUSE_IF_PRESENT
:
8005 case OMP_CLAUSE_FINALIZE
:
8008 case OMP_CLAUSE_MERGEABLE
:
8009 mergeable_seen
= true;
8012 case OMP_CLAUSE_TILE
:
8013 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
8014 list
= TREE_CHAIN (list
))
8016 t
= TREE_VALUE (list
);
8018 if (t
== error_mark_node
)
8020 else if (!type_dependent_expression_p (t
)
8021 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8023 error_at (OMP_CLAUSE_LOCATION (c
),
8024 "%<tile%> argument needs integral type");
8029 t
= mark_rvalue_use (t
);
8030 if (!processing_template_decl
)
8032 /* Zero is used to indicate '*', we permit you
8033 to get there via an ICE of value zero. */
8034 t
= maybe_constant_value (t
);
8035 if (!tree_fits_shwi_p (t
)
8036 || tree_to_shwi (t
) < 0)
8038 error_at (OMP_CLAUSE_LOCATION (c
),
8039 "%<tile%> argument needs positive "
8040 "integral constant");
8043 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8047 /* Update list item. */
8048 TREE_VALUE (list
) = t
;
8052 case OMP_CLAUSE_ORDERED
:
8053 ordered_seen
= true;
8056 case OMP_CLAUSE_ORDER
:
8063 case OMP_CLAUSE_INBRANCH
:
8064 case OMP_CLAUSE_NOTINBRANCH
:
8067 error_at (OMP_CLAUSE_LOCATION (c
),
8068 "%<inbranch%> clause is incompatible with "
8075 case OMP_CLAUSE_INCLUSIVE
:
8076 case OMP_CLAUSE_EXCLUSIVE
:
8077 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8079 t
= OMP_CLAUSE_DECL (c
);
8080 if (t
== current_class_ptr
)
8082 error_at (OMP_CLAUSE_LOCATION (c
),
8083 "%<this%> allowed in OpenMP only in %<declare simd%>"
8089 && TREE_CODE (t
) != PARM_DECL
8090 && TREE_CODE (t
) != FIELD_DECL
)
8092 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8095 error_at (OMP_CLAUSE_LOCATION (c
),
8096 "%qD is not a variable in clause %qs", t
,
8097 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8099 error_at (OMP_CLAUSE_LOCATION (c
),
8100 "%qE is not a variable in clause %qs", t
,
8101 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8111 *pc
= OMP_CLAUSE_CHAIN (c
);
8113 pc
= &OMP_CLAUSE_CHAIN (c
);
8116 if (reduction_seen
< 0 && (ordered_seen
|| schedule_seen
))
8117 reduction_seen
= -2;
8119 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
8121 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
8122 bool remove
= false;
8123 bool need_complete_type
= false;
8124 bool need_default_ctor
= false;
8125 bool need_copy_ctor
= false;
8126 bool need_copy_assignment
= false;
8127 bool need_implicitly_determined
= false;
8128 bool need_dtor
= false;
8129 tree type
, inner_type
;
8133 case OMP_CLAUSE_SHARED
:
8134 need_implicitly_determined
= true;
8136 case OMP_CLAUSE_PRIVATE
:
8137 need_complete_type
= true;
8138 need_default_ctor
= true;
8140 need_implicitly_determined
= true;
8142 case OMP_CLAUSE_FIRSTPRIVATE
:
8143 need_complete_type
= true;
8144 need_copy_ctor
= true;
8146 need_implicitly_determined
= true;
8148 case OMP_CLAUSE_LASTPRIVATE
:
8149 need_complete_type
= true;
8150 need_copy_assignment
= true;
8151 need_implicitly_determined
= true;
8153 case OMP_CLAUSE_REDUCTION
:
8154 if (reduction_seen
== -2)
8155 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
8156 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
8157 need_copy_assignment
= true;
8158 need_implicitly_determined
= true;
8160 case OMP_CLAUSE_IN_REDUCTION
:
8161 case OMP_CLAUSE_TASK_REDUCTION
:
8162 case OMP_CLAUSE_INCLUSIVE
:
8163 case OMP_CLAUSE_EXCLUSIVE
:
8164 need_implicitly_determined
= true;
8166 case OMP_CLAUSE_LINEAR
:
8167 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
8168 need_implicitly_determined
= true;
8169 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
8170 && !bitmap_bit_p (&map_head
,
8171 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
8173 error_at (OMP_CLAUSE_LOCATION (c
),
8174 "%<linear%> clause step is a parameter %qD not "
8175 "specified in %<uniform%> clause",
8176 OMP_CLAUSE_LINEAR_STEP (c
));
8177 *pc
= OMP_CLAUSE_CHAIN (c
);
8181 case OMP_CLAUSE_COPYPRIVATE
:
8182 need_copy_assignment
= true;
8184 case OMP_CLAUSE_COPYIN
:
8185 need_copy_assignment
= true;
8187 case OMP_CLAUSE_SIMDLEN
:
8189 && !processing_template_decl
8190 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
8191 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
8193 error_at (OMP_CLAUSE_LOCATION (c
),
8194 "%<simdlen%> clause value is bigger than "
8195 "%<safelen%> clause value");
8196 OMP_CLAUSE_SIMDLEN_EXPR (c
)
8197 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
8199 pc
= &OMP_CLAUSE_CHAIN (c
);
8201 case OMP_CLAUSE_SCHEDULE
:
8203 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
8204 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
8206 error_at (OMP_CLAUSE_LOCATION (c
),
8207 "%<nonmonotonic%> schedule modifier specified "
8208 "together with %<ordered%> clause");
8209 OMP_CLAUSE_SCHEDULE_KIND (c
)
8210 = (enum omp_clause_schedule_kind
)
8211 (OMP_CLAUSE_SCHEDULE_KIND (c
)
8212 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
8214 if (reduction_seen
== -2)
8215 error_at (OMP_CLAUSE_LOCATION (c
),
8216 "%qs clause specified together with %<inscan%> "
8217 "%<reduction%> clause", "schedule");
8218 pc
= &OMP_CLAUSE_CHAIN (c
);
8220 case OMP_CLAUSE_NOGROUP
:
8223 error_at (OMP_CLAUSE_LOCATION (c
),
8224 "%<nogroup%> clause must not be used together with "
8225 "%<reduction%> clause");
8226 *pc
= OMP_CLAUSE_CHAIN (c
);
8229 pc
= &OMP_CLAUSE_CHAIN (c
);
8231 case OMP_CLAUSE_ORDERED
:
8232 if (reduction_seen
== -2)
8233 error_at (OMP_CLAUSE_LOCATION (c
),
8234 "%qs clause specified together with %<inscan%> "
8235 "%<reduction%> clause", "ordered");
8236 pc
= &OMP_CLAUSE_CHAIN (c
);
8238 case OMP_CLAUSE_ORDER
:
8241 error_at (OMP_CLAUSE_LOCATION (c
),
8242 "%<order%> clause must not be used together "
8243 "with %<ordered%>");
8244 *pc
= OMP_CLAUSE_CHAIN (c
);
8247 pc
= &OMP_CLAUSE_CHAIN (c
);
8249 case OMP_CLAUSE_DETACH
:
8252 error_at (OMP_CLAUSE_LOCATION (c
),
8253 "%<detach%> clause must not be used together with "
8254 "%<mergeable%> clause");
8255 *pc
= OMP_CLAUSE_CHAIN (c
);
8258 pc
= &OMP_CLAUSE_CHAIN (c
);
8260 case OMP_CLAUSE_NOWAIT
:
8261 if (copyprivate_seen
)
8263 error_at (OMP_CLAUSE_LOCATION (c
),
8264 "%<nowait%> clause must not be used together "
8265 "with %<copyprivate%>");
8266 *pc
= OMP_CLAUSE_CHAIN (c
);
8271 pc
= &OMP_CLAUSE_CHAIN (c
);
8275 t
= OMP_CLAUSE_DECL (c
);
8278 case OMP_CLAUSE_LASTPRIVATE
:
8280 && !bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
8282 need_default_ctor
= true;
8287 case OMP_CLAUSE_REDUCTION
:
8288 case OMP_CLAUSE_IN_REDUCTION
:
8289 case OMP_CLAUSE_TASK_REDUCTION
:
8292 if (TREE_CODE (t
) == MEM_REF
)
8294 t
= TREE_OPERAND (t
, 0);
8295 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
8296 t
= TREE_OPERAND (t
, 0);
8297 if (TREE_CODE (t
) == ADDR_EXPR
8298 || TREE_CODE (t
) == INDIRECT_REF
)
8299 t
= TREE_OPERAND (t
, 0);
8301 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8303 else if (TREE_CODE (t
) == TREE_LIST
)
8305 while (TREE_CODE (t
) == TREE_LIST
)
8308 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8309 t
= OMP_CLAUSE_DECL (c
);
8311 else if (DECL_P (t
))
8312 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8313 t
= OMP_CLAUSE_DECL (c
);
8315 if (processing_template_decl
8316 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8318 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
8322 t
= OMP_CLAUSE_DECL (c
);
8325 case OMP_CLAUSE_COPYIN
:
8326 if (processing_template_decl
8327 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8329 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
8331 error_at (OMP_CLAUSE_LOCATION (c
),
8332 "%qE must be %<threadprivate%> for %<copyin%>", t
);
8341 if (processing_template_decl
8342 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8344 pc
= &OMP_CLAUSE_CHAIN (c
);
8348 if (need_complete_type
|| need_copy_assignment
)
8350 t
= require_complete_type (t
);
8351 if (t
== error_mark_node
)
8353 else if (!processing_template_decl
8354 && TYPE_REF_P (TREE_TYPE (t
))
8355 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
8358 if (need_implicitly_determined
)
8360 const char *share_name
= NULL
;
8363 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8365 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8367 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
8368 share_name
= "threadprivate";
8369 else switch (cxx_omp_predetermined_sharing_1 (t
))
8371 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
8373 case OMP_CLAUSE_DEFAULT_SHARED
:
8374 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8375 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8376 && c_omp_predefined_variable (t
))
8377 /* The __func__ variable and similar function-local predefined
8378 variables may be listed in a shared or firstprivate
8382 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8384 && cxx_omp_const_qual_no_mutable (t
))
8386 tree ctx
= CP_DECL_CONTEXT (t
);
8387 /* const qualified static data members without mutable
8388 member may be specified in firstprivate clause. */
8389 if (TYPE_P (ctx
) && MAYBE_CLASS_TYPE_P (ctx
))
8392 share_name
= "shared";
8394 case OMP_CLAUSE_DEFAULT_PRIVATE
:
8395 share_name
= "private";
8402 error_at (OMP_CLAUSE_LOCATION (c
),
8403 "%qE is predetermined %qs for %qs",
8404 omp_clause_printable_decl (t
), share_name
,
8405 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8408 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8409 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_FIRSTPRIVATE
8410 && cxx_omp_const_qual_no_mutable (t
))
8412 error_at (OMP_CLAUSE_LOCATION (c
),
8413 "%<const%> qualified %qE without %<mutable%> member "
8414 "may appear only in %<shared%> or %<firstprivate%> "
8415 "clauses", omp_clause_printable_decl (t
));
8421 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8422 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
8423 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8424 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
8425 && OMP_CLAUSE_DECL (c
) == t
)
8427 error_at (OMP_CLAUSE_LOCATION (c
),
8428 "the event handle of a %<detach%> clause "
8429 "should not be in a data-sharing clause");
8433 /* We're interested in the base element, not arrays. */
8434 inner_type
= type
= TREE_TYPE (t
);
8435 if ((need_complete_type
8436 || need_copy_assignment
8437 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
8438 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
8439 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
8440 && TYPE_REF_P (inner_type
))
8441 inner_type
= TREE_TYPE (inner_type
);
8442 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
8443 inner_type
= TREE_TYPE (inner_type
);
8445 /* Check for special function availability by building a call to one.
8446 Save the results, because later we won't be in the right context
8447 for making these queries. */
8448 if (CLASS_TYPE_P (inner_type
)
8449 && COMPLETE_TYPE_P (inner_type
)
8450 && (need_default_ctor
|| need_copy_ctor
8451 || need_copy_assignment
|| need_dtor
)
8452 && !type_dependent_expression_p (t
)
8453 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
8454 need_copy_ctor
, need_copy_assignment
,
8459 && c_kind
== OMP_CLAUSE_SHARED
8460 && processing_template_decl
)
8462 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8464 OMP_CLAUSE_DECL (c
) = t
;
8468 *pc
= OMP_CLAUSE_CHAIN (c
);
8470 pc
= &OMP_CLAUSE_CHAIN (c
);
8474 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
8476 bool remove
= false;
8477 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ALLOCATE
8478 && !OMP_CLAUSE_ALLOCATE_COMBINED (c
)
8479 && DECL_P (OMP_CLAUSE_DECL (c
))
8480 && bitmap_bit_p (&aligned_head
, DECL_UID (OMP_CLAUSE_DECL (c
))))
8482 error_at (OMP_CLAUSE_LOCATION (c
),
8483 "%qD specified in %<allocate%> clause but not in "
8484 "an explicit privatization clause", OMP_CLAUSE_DECL (c
));
8488 *pc
= OMP_CLAUSE_CHAIN (c
);
8490 pc
= &OMP_CLAUSE_CHAIN (c
);
8493 bitmap_obstack_release (NULL
);
8497 /* Start processing OpenMP clauses that can include any
8498 privatization clauses for non-static data members. */
8501 push_omp_privatization_clauses (bool ignore_next
)
8503 if (omp_private_member_ignore_next
)
8505 omp_private_member_ignore_next
= ignore_next
;
8508 omp_private_member_ignore_next
= ignore_next
;
8509 if (omp_private_member_map
)
8510 omp_private_member_vec
.safe_push (error_mark_node
);
8511 return push_stmt_list ();
8514 /* Revert remapping of any non-static data members since
8515 the last push_omp_privatization_clauses () call. */
8518 pop_omp_privatization_clauses (tree stmt
)
8520 if (stmt
== NULL_TREE
)
8522 stmt
= pop_stmt_list (stmt
);
8523 if (omp_private_member_map
)
8525 while (!omp_private_member_vec
.is_empty ())
8527 tree t
= omp_private_member_vec
.pop ();
8528 if (t
== error_mark_node
)
8533 bool no_decl_expr
= t
== integer_zero_node
;
8535 t
= omp_private_member_vec
.pop ();
8536 tree
*v
= omp_private_member_map
->get (t
);
8540 omp_private_member_map
->remove (t
);
8542 delete omp_private_member_map
;
8543 omp_private_member_map
= NULL
;
8548 /* Remember OpenMP privatization clauses mapping and clear it.
8549 Used for lambdas. */
8552 save_omp_privatization_clauses (vec
<tree
> &save
)
8555 if (omp_private_member_ignore_next
)
8556 save
.safe_push (integer_one_node
);
8557 omp_private_member_ignore_next
= false;
8558 if (!omp_private_member_map
)
8561 while (!omp_private_member_vec
.is_empty ())
8563 tree t
= omp_private_member_vec
.pop ();
8564 if (t
== error_mark_node
)
8570 if (t
== integer_zero_node
)
8571 t
= omp_private_member_vec
.pop ();
8572 tree
*v
= omp_private_member_map
->get (t
);
8574 save
.safe_push (*v
);
8579 delete omp_private_member_map
;
8580 omp_private_member_map
= NULL
;
8583 /* Restore OpenMP privatization clauses mapping saved by the
8587 restore_omp_privatization_clauses (vec
<tree
> &save
)
8589 gcc_assert (omp_private_member_vec
.is_empty ());
8590 omp_private_member_ignore_next
= false;
8591 if (save
.is_empty ())
8593 if (save
.length () == 1 && save
[0] == integer_one_node
)
8595 omp_private_member_ignore_next
= true;
8600 omp_private_member_map
= new hash_map
<tree
, tree
>;
8601 while (!save
.is_empty ())
8603 tree t
= save
.pop ();
8605 if (t
!= error_mark_node
)
8607 if (t
== integer_one_node
)
8609 omp_private_member_ignore_next
= true;
8610 gcc_assert (save
.is_empty ());
8613 if (t
== integer_zero_node
)
8615 tree
&v
= omp_private_member_map
->get_or_insert (t
);
8618 omp_private_member_vec
.safe_push (t
);
8620 omp_private_member_vec
.safe_push (n
);
8625 /* For all variables in the tree_list VARS, mark them as thread local. */
8628 finish_omp_threadprivate (tree vars
)
8632 /* Mark every variable in VARS to be assigned thread local storage. */
8633 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8635 tree v
= TREE_PURPOSE (t
);
8637 if (error_operand_p (v
))
8639 else if (!VAR_P (v
))
8640 error ("%<threadprivate%> %qD is not file, namespace "
8641 "or block scope variable", v
);
8642 /* If V had already been marked threadprivate, it doesn't matter
8643 whether it had been used prior to this point. */
8644 else if (TREE_USED (v
)
8645 && (DECL_LANG_SPECIFIC (v
) == NULL
8646 || !CP_DECL_THREADPRIVATE_P (v
)))
8647 error ("%qE declared %<threadprivate%> after first use", v
);
8648 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8649 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8650 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
8651 error ("%<threadprivate%> %qE has incomplete type", v
);
8652 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
8653 && CP_DECL_CONTEXT (v
) != current_class_type
)
8654 error ("%<threadprivate%> %qE directive not "
8655 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
8658 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
8659 if (DECL_LANG_SPECIFIC (v
) == NULL
)
8660 retrofit_lang_decl (v
);
8662 if (! CP_DECL_THREAD_LOCAL_P (v
))
8664 CP_DECL_THREAD_LOCAL_P (v
) = true;
8665 set_decl_tls_model (v
, decl_default_tls_model (v
));
8666 /* If rtl has been already set for this var, call
8667 make_decl_rtl once again, so that encode_section_info
8668 has a chance to look at the new decl flags. */
8669 if (DECL_RTL_SET_P (v
))
8672 CP_DECL_THREADPRIVATE_P (v
) = 1;
8677 /* Build an OpenMP structured block. */
8680 begin_omp_structured_block (void)
8682 return do_pushlevel (sk_omp
);
8686 finish_omp_structured_block (tree block
)
8688 return do_poplevel (block
);
8691 /* Similarly, except force the retention of the BLOCK. */
8694 begin_omp_parallel (void)
8696 keep_next_level (true);
8697 return begin_omp_structured_block ();
8700 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
8704 finish_oacc_data (tree clauses
, tree block
)
8708 block
= finish_omp_structured_block (block
);
8710 stmt
= make_node (OACC_DATA
);
8711 TREE_TYPE (stmt
) = void_type_node
;
8712 OACC_DATA_CLAUSES (stmt
) = clauses
;
8713 OACC_DATA_BODY (stmt
) = block
;
8715 return add_stmt (stmt
);
8718 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
8722 finish_oacc_host_data (tree clauses
, tree block
)
8726 block
= finish_omp_structured_block (block
);
8728 stmt
= make_node (OACC_HOST_DATA
);
8729 TREE_TYPE (stmt
) = void_type_node
;
8730 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
8731 OACC_HOST_DATA_BODY (stmt
) = block
;
8733 return add_stmt (stmt
);
8736 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
8740 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
8742 body
= finish_omp_structured_block (body
);
8744 tree stmt
= make_node (code
);
8745 TREE_TYPE (stmt
) = void_type_node
;
8746 OMP_BODY (stmt
) = body
;
8747 OMP_CLAUSES (stmt
) = clauses
;
8749 return add_stmt (stmt
);
8753 finish_omp_parallel (tree clauses
, tree body
)
8757 body
= finish_omp_structured_block (body
);
8759 stmt
= make_node (OMP_PARALLEL
);
8760 TREE_TYPE (stmt
) = void_type_node
;
8761 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
8762 OMP_PARALLEL_BODY (stmt
) = body
;
8764 return add_stmt (stmt
);
8768 begin_omp_task (void)
8770 keep_next_level (true);
8771 return begin_omp_structured_block ();
8775 finish_omp_task (tree clauses
, tree body
)
8779 body
= finish_omp_structured_block (body
);
8781 stmt
= make_node (OMP_TASK
);
8782 TREE_TYPE (stmt
) = void_type_node
;
8783 OMP_TASK_CLAUSES (stmt
) = clauses
;
8784 OMP_TASK_BODY (stmt
) = body
;
8786 return add_stmt (stmt
);
8789 /* Helper function for finish_omp_for. Convert Ith random access iterator
8790 into integral iterator. Return FALSE if successful. */
8793 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
8794 tree declv
, tree orig_declv
, tree initv
,
8795 tree condv
, tree incrv
, tree
*body
,
8796 tree
*pre_body
, tree
&clauses
,
8797 int collapse
, int ordered
)
8799 tree diff
, iter_init
, iter_incr
= NULL
, last
;
8800 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
8801 tree decl
= TREE_VEC_ELT (declv
, i
);
8802 tree init
= TREE_VEC_ELT (initv
, i
);
8803 tree cond
= TREE_VEC_ELT (condv
, i
);
8804 tree incr
= TREE_VEC_ELT (incrv
, i
);
8806 location_t elocus
= locus
;
8808 if (init
&& EXPR_HAS_LOCATION (init
))
8809 elocus
= EXPR_LOCATION (init
);
8811 switch (TREE_CODE (cond
))
8818 if (TREE_OPERAND (cond
, 1) == iter
)
8819 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
8820 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
8821 if (TREE_OPERAND (cond
, 0) != iter
)
8822 cond
= error_mark_node
;
8825 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
8828 TREE_OPERAND (cond
, 1), ERROR_MARK
,
8829 NULL
, tf_warning_or_error
);
8830 if (error_operand_p (tem
))
8835 cond
= error_mark_node
;
8838 if (cond
== error_mark_node
)
8840 error_at (elocus
, "invalid controlling predicate");
8843 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
8844 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
8845 tf_warning_or_error
);
8846 diff
= cp_fully_fold (diff
);
8847 if (error_operand_p (diff
))
8849 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
8851 error_at (elocus
, "difference between %qE and %qD does not have integer type",
8852 TREE_OPERAND (cond
, 1), iter
);
8855 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
, i
,
8856 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
8857 cond
, cp_walk_subtrees
))
8860 switch (TREE_CODE (incr
))
8862 case PREINCREMENT_EXPR
:
8863 case PREDECREMENT_EXPR
:
8864 case POSTINCREMENT_EXPR
:
8865 case POSTDECREMENT_EXPR
:
8866 if (TREE_OPERAND (incr
, 0) != iter
)
8868 incr
= error_mark_node
;
8871 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
8872 TREE_CODE (incr
), iter
,
8873 tf_warning_or_error
);
8874 if (error_operand_p (iter_incr
))
8876 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
8877 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
8878 incr
= integer_one_node
;
8880 incr
= integer_minus_one_node
;
8883 if (TREE_OPERAND (incr
, 0) != iter
)
8884 incr
= error_mark_node
;
8885 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
8886 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
8888 tree rhs
= TREE_OPERAND (incr
, 1);
8889 if (TREE_OPERAND (rhs
, 0) == iter
)
8891 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
8893 incr
= error_mark_node
;
8896 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8897 iter
, TREE_CODE (rhs
),
8898 TREE_OPERAND (rhs
, 1),
8899 tf_warning_or_error
);
8900 if (error_operand_p (iter_incr
))
8902 incr
= TREE_OPERAND (rhs
, 1);
8903 incr
= cp_convert (TREE_TYPE (diff
), incr
,
8904 tf_warning_or_error
);
8905 if (TREE_CODE (rhs
) == MINUS_EXPR
)
8907 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
8908 incr
= fold_simple (incr
);
8910 if (TREE_CODE (incr
) != INTEGER_CST
8911 && (TREE_CODE (incr
) != NOP_EXPR
8912 || (TREE_CODE (TREE_OPERAND (incr
, 0))
8917 else if (TREE_OPERAND (rhs
, 1) == iter
)
8919 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
8920 || TREE_CODE (rhs
) != PLUS_EXPR
)
8921 incr
= error_mark_node
;
8924 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
8926 TREE_OPERAND (rhs
, 0),
8929 tf_warning_or_error
);
8930 if (error_operand_p (iter_incr
))
8932 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
8935 tf_warning_or_error
);
8936 if (error_operand_p (iter_incr
))
8938 incr
= TREE_OPERAND (rhs
, 0);
8943 incr
= error_mark_node
;
8946 incr
= error_mark_node
;
8949 incr
= error_mark_node
;
8953 if (incr
== error_mark_node
)
8955 error_at (elocus
, "invalid increment expression");
8959 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
8960 incr
= cp_fully_fold (incr
);
8961 tree loop_iv_seen
= NULL_TREE
;
8962 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
8963 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
8964 && OMP_CLAUSE_DECL (c
) == iter
)
8966 if (code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
8969 OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
) = 1;
8973 else if ((code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
8974 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
8975 && OMP_CLAUSE_DECL (c
) == iter
)
8978 if (code
== OMP_TASKLOOP
)
8979 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
8982 decl
= create_temporary_var (TREE_TYPE (diff
));
8984 add_decl_expr (decl
);
8985 last
= create_temporary_var (TREE_TYPE (diff
));
8987 add_decl_expr (last
);
8988 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
8989 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
8991 incr_var
= create_temporary_var (TREE_TYPE (diff
));
8992 pushdecl (incr_var
);
8993 add_decl_expr (incr_var
);
8995 gcc_assert (stmts_are_full_exprs_p ());
8996 tree diffvar
= NULL_TREE
;
8997 if (code
== OMP_TASKLOOP
)
9001 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9002 OMP_CLAUSE_DECL (ivc
) = iter
;
9003 cxx_omp_finish_clause (ivc
, NULL
, false);
9004 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
9007 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9008 OMP_CLAUSE_DECL (lvc
) = last
;
9009 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
9011 diffvar
= create_temporary_var (TREE_TYPE (diff
));
9013 add_decl_expr (diffvar
);
9015 else if (code
== OMP_LOOP
)
9019 /* While iterators on the loop construct are predetermined
9020 lastprivate, if the decl is not declared inside of the
9021 loop, OMP_CLAUSE_LASTPRIVATE should have been added
9023 loop_iv_seen
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9024 OMP_CLAUSE_DECL (loop_iv_seen
) = iter
;
9025 OMP_CLAUSE_CHAIN (loop_iv_seen
) = clauses
;
9026 clauses
= loop_iv_seen
;
9028 else if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_PRIVATE
)
9030 OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen
) = 0;
9031 OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen
) = 0;
9032 OMP_CLAUSE_CODE (loop_iv_seen
) = OMP_CLAUSE_FIRSTPRIVATE
;
9034 if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_FIRSTPRIVATE
)
9035 cxx_omp_finish_clause (loop_iv_seen
, NULL
, false);
9038 orig_pre_body
= *pre_body
;
9039 *pre_body
= push_stmt_list ();
9041 add_stmt (orig_pre_body
);
9043 finish_expr_stmt (build_x_modify_expr (elocus
,
9044 iter
, NOP_EXPR
, init
,
9045 tf_warning_or_error
));
9046 init
= build_int_cst (TREE_TYPE (diff
), 0);
9047 if (c
&& iter_incr
== NULL
9048 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
9052 finish_expr_stmt (build_x_modify_expr (elocus
,
9054 incr
, tf_warning_or_error
));
9057 iter_incr
= build_x_modify_expr (elocus
,
9058 iter
, PLUS_EXPR
, incr
,
9059 tf_warning_or_error
);
9061 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
9063 finish_expr_stmt (build_x_modify_expr (elocus
,
9064 last
, NOP_EXPR
, init
,
9065 tf_warning_or_error
));
9068 finish_expr_stmt (build_x_modify_expr (elocus
,
9070 diff
, tf_warning_or_error
));
9073 *pre_body
= pop_stmt_list (*pre_body
);
9075 cond
= cp_build_binary_op (elocus
,
9076 TREE_CODE (cond
), decl
, diff
,
9077 tf_warning_or_error
);
9078 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
9079 elocus
, incr
, NULL_TREE
);
9082 *body
= push_stmt_list ();
9083 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
9084 iter_init
= build_x_modify_expr (elocus
,
9085 iter
, PLUS_EXPR
, iter_init
,
9086 tf_warning_or_error
);
9087 if (iter_init
!= error_mark_node
)
9088 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
9089 finish_expr_stmt (iter_init
);
9090 finish_expr_stmt (build_x_modify_expr (elocus
,
9091 last
, NOP_EXPR
, decl
,
9092 tf_warning_or_error
));
9093 add_stmt (orig_body
);
9094 *body
= pop_stmt_list (*body
);
9098 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
9100 finish_expr_stmt (iter_incr
);
9104 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
9105 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
9106 iter_init
, iter_incr
);
9107 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
9108 iter_init
= build_x_modify_expr (elocus
,
9109 iter
, PLUS_EXPR
, iter_init
,
9110 tf_warning_or_error
);
9111 if (iter_init
!= error_mark_node
)
9112 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
9113 finish_expr_stmt (iter_init
);
9115 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
9116 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
9119 if (TREE_CODE (TREE_VEC_ELT (orig_declv
, i
)) == TREE_LIST
)
9121 tree t
= TREE_VEC_ELT (orig_declv
, i
);
9122 gcc_assert (TREE_PURPOSE (t
) == NULL_TREE
9123 && TREE_VALUE (t
) == NULL_TREE
9124 && TREE_CODE (TREE_CHAIN (t
)) == TREE_VEC
);
9125 TREE_PURPOSE (t
) = TREE_VEC_ELT (declv
, i
);
9126 TREE_VALUE (t
) = last
;
9129 TREE_VEC_ELT (orig_declv
, i
)
9130 = tree_cons (TREE_VEC_ELT (declv
, i
), last
, NULL_TREE
);
9131 TREE_VEC_ELT (declv
, i
) = decl
;
9132 TREE_VEC_ELT (initv
, i
) = init
;
9133 TREE_VEC_ELT (condv
, i
) = cond
;
9134 TREE_VEC_ELT (incrv
, i
) = incr
;
9139 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
9140 are directly for their associated operands in the statement. DECL
9141 and INIT are a combo; if DECL is NULL then INIT ought to be a
9142 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
9143 optional statements that need to go before the loop into its
9147 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
9148 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
9149 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
9151 tree omp_for
= NULL
, orig_incr
= NULL
;
9152 tree decl
= NULL
, init
, cond
, incr
;
9158 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
9159 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
9160 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
9161 if (TREE_VEC_LENGTH (declv
) > 1)
9165 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
9167 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
9170 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
9172 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
9173 if (collapse
!= TREE_VEC_LENGTH (declv
))
9174 ordered
= TREE_VEC_LENGTH (declv
);
9177 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
9179 decl
= TREE_VEC_ELT (declv
, i
);
9180 init
= TREE_VEC_ELT (initv
, i
);
9181 cond
= TREE_VEC_ELT (condv
, i
);
9182 incr
= TREE_VEC_ELT (incrv
, i
);
9188 switch (TREE_CODE (init
))
9191 decl
= TREE_OPERAND (init
, 0);
9192 init
= TREE_OPERAND (init
, 1);
9195 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
9197 decl
= TREE_OPERAND (init
, 0);
9198 init
= TREE_OPERAND (init
, 2);
9208 "expected iteration declaration or initialization");
9213 if (init
&& EXPR_HAS_LOCATION (init
))
9214 elocus
= EXPR_LOCATION (init
);
9216 if (cond
== global_namespace
)
9221 error_at (elocus
, "missing controlling predicate");
9227 error_at (elocus
, "missing increment expression");
9231 TREE_VEC_ELT (declv
, i
) = decl
;
9232 TREE_VEC_ELT (initv
, i
) = init
;
9239 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
9241 && !c_omp_check_loop_iv_exprs (locus
,
9242 orig_declv
? orig_declv
: declv
, i
,
9243 TREE_VEC_ELT (declv
, i
), orig_init
,
9244 NULL_TREE
, cp_walk_subtrees
))
9250 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
9254 stmt
= make_node (code
);
9256 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
9258 /* This is really just a place-holder. We'll be decomposing this
9259 again and going through the cp_build_modify_expr path below when
9260 we instantiate the thing. */
9261 TREE_VEC_ELT (initv
, i
)
9262 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
9263 TREE_VEC_ELT (initv
, i
));
9266 TREE_TYPE (stmt
) = void_type_node
;
9267 OMP_FOR_INIT (stmt
) = initv
;
9268 OMP_FOR_COND (stmt
) = condv
;
9269 OMP_FOR_INCR (stmt
) = incrv
;
9270 OMP_FOR_BODY (stmt
) = body
;
9271 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
9272 OMP_FOR_CLAUSES (stmt
) = clauses
;
9274 SET_EXPR_LOCATION (stmt
, locus
);
9275 return add_stmt (stmt
);
9279 orig_declv
= copy_node (declv
);
9281 if (processing_template_decl
)
9282 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
9284 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
9286 decl
= TREE_VEC_ELT (declv
, i
);
9287 init
= TREE_VEC_ELT (initv
, i
);
9288 cond
= TREE_VEC_ELT (condv
, i
);
9289 incr
= TREE_VEC_ELT (incrv
, i
);
9291 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9294 if (init
&& EXPR_HAS_LOCATION (init
))
9295 elocus
= EXPR_LOCATION (init
);
9299 error_at (elocus
, "expected iteration declaration or initialization");
9303 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
9306 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9307 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
9308 TREE_CODE (TREE_OPERAND (incr
, 1)),
9309 TREE_OPERAND (incr
, 2),
9310 tf_warning_or_error
);
9313 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
9315 if (code
== OMP_SIMD
)
9317 error_at (elocus
, "%<#pragma omp simd%> used with class "
9318 "iteration variable %qE", decl
);
9321 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
9322 initv
, condv
, incrv
, &body
,
9329 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
9330 && !TYPE_PTR_P (TREE_TYPE (decl
)))
9332 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
9336 if (!processing_template_decl
&& TREE_CODE (init
) != TREE_VEC
)
9337 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
9338 tf_warning_or_error
);
9340 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
9341 if (decl
== error_mark_node
|| init
== error_mark_node
)
9344 TREE_VEC_ELT (declv
, i
) = decl
;
9345 TREE_VEC_ELT (initv
, i
) = init
;
9346 TREE_VEC_ELT (condv
, i
) = cond
;
9347 TREE_VEC_ELT (incrv
, i
) = incr
;
9351 if (pre_body
&& IS_EMPTY_STMT (pre_body
))
9354 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
9355 incrv
, body
, pre_body
,
9356 !processing_template_decl
);
9358 /* Check for iterators appearing in lb, b or incr expressions. */
9359 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
9360 omp_for
= NULL_TREE
;
9362 if (omp_for
== NULL
)
9367 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
9369 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
);
9370 decl
= TREE_OPERAND (init
, 0);
9371 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), i
);
9372 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
9374 if (!processing_template_decl
)
9376 if (TREE_CODE (TREE_OPERAND (init
, 1)) == TREE_VEC
)
9378 tree t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1);
9379 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1)
9380 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9381 t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2);
9382 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2)
9383 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9387 tree t
= TREE_OPERAND (init
, 1);
9388 TREE_OPERAND (init
, 1)
9389 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9391 if (TREE_CODE (TREE_OPERAND (cond
, 1)) == TREE_VEC
)
9393 tree t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1);
9394 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1)
9395 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9396 t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2);
9397 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2)
9398 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9402 tree t
= TREE_OPERAND (cond
, 1);
9403 TREE_OPERAND (cond
, 1)
9404 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9408 if (TREE_CODE (incr
) != MODIFY_EXPR
)
9411 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
9412 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
9413 && !processing_template_decl
)
9415 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
9416 if (TREE_SIDE_EFFECTS (t
)
9418 && (TREE_CODE (t
) != NOP_EXPR
9419 || TREE_OPERAND (t
, 0) != decl
))
9420 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
9421 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9423 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
9424 if (TREE_SIDE_EFFECTS (t
)
9426 && (TREE_CODE (t
) != NOP_EXPR
9427 || TREE_OPERAND (t
, 0) != decl
))
9428 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
9429 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9433 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
9435 OMP_FOR_CLAUSES (omp_for
) = clauses
;
9437 /* For simd loops with non-static data member iterators, we could have added
9438 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
9439 step at this point, fill it in. */
9440 if (code
== OMP_SIMD
&& !processing_template_decl
9441 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
9442 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
9443 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
9444 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
9446 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
9447 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
9448 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
9450 switch (TREE_CODE (incr
))
9452 case PREINCREMENT_EXPR
:
9453 case POSTINCREMENT_EXPR
:
9454 /* c_omp_for_incr_canonicalize_ptr() should have been
9455 called to massage things appropriately. */
9456 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9457 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
9459 case PREDECREMENT_EXPR
:
9460 case POSTDECREMENT_EXPR
:
9461 /* c_omp_for_incr_canonicalize_ptr() should have been
9462 called to massage things appropriately. */
9463 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9464 OMP_CLAUSE_LINEAR_STEP (c
)
9465 = build_int_cst (TREE_TYPE (decl
), -1);
9468 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9469 incr
= TREE_OPERAND (incr
, 1);
9470 switch (TREE_CODE (incr
))
9473 if (TREE_OPERAND (incr
, 1) == decl
)
9474 step
= TREE_OPERAND (incr
, 0);
9476 step
= TREE_OPERAND (incr
, 1);
9479 case POINTER_PLUS_EXPR
:
9480 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9481 step
= TREE_OPERAND (incr
, 1);
9486 stept
= TREE_TYPE (decl
);
9487 if (INDIRECT_TYPE_P (stept
))
9489 step
= fold_convert (stept
, step
);
9490 if (TREE_CODE (incr
) == MINUS_EXPR
)
9491 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
9492 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
9498 /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
9499 clauses, we need copy ctor for those rather than default ctor,
9500 plus as for other lastprivates assignment op and dtor. */
9501 if (code
== OMP_LOOP
&& !processing_template_decl
)
9502 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9503 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9504 && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
)
9505 && cxx_omp_create_clause_info (c
, TREE_TYPE (OMP_CLAUSE_DECL (c
)),
9506 false, true, true, true))
9507 CP_OMP_CLAUSE_INFO (c
) = NULL_TREE
;
9512 /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS
9513 and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */
9516 finish_omp_for_block (tree bind
, tree omp_for
)
9518 if (omp_for
== NULL_TREE
9519 || !OMP_FOR_ORIG_DECLS (omp_for
)
9520 || bind
== NULL_TREE
9521 || TREE_CODE (bind
) != BIND_EXPR
)
9524 for (int i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for
)); i
++)
9525 if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)) == TREE_LIST
9526 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)))
9528 tree v
= TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
));
9529 gcc_assert (BIND_EXPR_BLOCK (bind
)
9530 && (BIND_EXPR_VARS (bind
)
9531 == BLOCK_VARS (BIND_EXPR_BLOCK (bind
))));
9532 for (int j
= 2; j
< TREE_VEC_LENGTH (v
); j
++)
9533 for (tree
*p
= &BIND_EXPR_VARS (bind
); *p
; p
= &DECL_CHAIN (*p
))
9535 if (*p
== TREE_VEC_ELT (v
, j
))
9538 *p
= DECL_CHAIN (*p
);
9541 b
= make_node (BLOCK
);
9542 b
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
9543 OMP_FOR_BODY (omp_for
), b
);
9544 TREE_SIDE_EFFECTS (b
) = 1;
9545 OMP_FOR_BODY (omp_for
) = b
;
9547 DECL_CHAIN (var
) = BIND_EXPR_VARS (b
);
9548 BIND_EXPR_VARS (b
) = var
;
9549 BLOCK_VARS (BIND_EXPR_BLOCK (b
)) = var
;
9552 BLOCK_VARS (BIND_EXPR_BLOCK (bind
)) = BIND_EXPR_VARS (bind
);
9558 finish_omp_atomic (location_t loc
, enum tree_code code
, enum tree_code opcode
,
9559 tree lhs
, tree rhs
, tree v
, tree lhs1
, tree rhs1
,
9560 tree clauses
, enum omp_memory_order mo
)
9575 dependent_p
= false;
9578 /* Even in a template, we can detect invalid uses of the atomic
9579 pragma if neither LHS nor RHS is type-dependent. */
9580 if (processing_template_decl
)
9582 dependent_p
= (type_dependent_expression_p (lhs
)
9583 || (rhs
&& type_dependent_expression_p (rhs
))
9584 || (v
&& type_dependent_expression_p (v
))
9585 || (lhs1
&& type_dependent_expression_p (lhs1
))
9586 || (rhs1
&& type_dependent_expression_p (rhs1
)));
9589 gcc_assert (TREE_CODE (clauses
) == OMP_CLAUSE
9590 && OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_HINT
9591 && OMP_CLAUSE_CHAIN (clauses
) == NULL_TREE
);
9592 if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses
))
9593 || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses
)) != INTEGER_CST
)
9598 lhs
= build_non_dependent_expr (lhs
);
9600 rhs
= build_non_dependent_expr (rhs
);
9602 v
= build_non_dependent_expr (v
);
9604 lhs1
= build_non_dependent_expr (lhs1
);
9606 rhs1
= build_non_dependent_expr (rhs1
);
9611 bool swapped
= false;
9612 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
9614 std::swap (rhs
, rhs1
);
9615 swapped
= !commutative_tree_code (opcode
);
9617 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
9619 if (code
== OMP_ATOMIC
)
9620 error ("%<#pragma omp atomic update%> uses two different "
9621 "expressions for memory");
9623 error ("%<#pragma omp atomic capture%> uses two different "
9624 "expressions for memory");
9627 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
9629 if (code
== OMP_ATOMIC
)
9630 error ("%<#pragma omp atomic update%> uses two different "
9631 "expressions for memory");
9633 error ("%<#pragma omp atomic capture%> uses two different "
9634 "expressions for memory");
9637 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
,
9638 v
, lhs1
, rhs1
, swapped
, mo
,
9639 processing_template_decl
!= 0);
9640 if (stmt
== error_mark_node
)
9643 if (processing_template_decl
)
9645 if (code
== OMP_ATOMIC_READ
)
9647 stmt
= build_min_nt_loc (loc
, OMP_ATOMIC_READ
, orig_lhs
);
9648 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9649 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9653 if (opcode
== NOP_EXPR
)
9654 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
9656 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
9658 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
9659 COMPOUND_EXPR
, orig_rhs1
, stmt
);
9660 if (code
!= OMP_ATOMIC
)
9662 stmt
= build_min_nt_loc (loc
, code
, orig_lhs1
, stmt
);
9663 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9664 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9667 stmt
= build2 (OMP_ATOMIC
, void_type_node
,
9668 clauses
? clauses
: integer_zero_node
, stmt
);
9669 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9670 SET_EXPR_LOCATION (stmt
, loc
);
9673 /* Avoid -Wunused-value warnings here, the whole construct has side-effects
9674 and even if it might be wrapped from fold-const.c or c-omp.c wrapped
9675 in some tree that appears to be unused, the value is not unused. */
9676 warning_sentinel
w (warn_unused_value
);
9677 finish_expr_stmt (stmt
);
9681 finish_omp_barrier (void)
9683 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
9685 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9686 finish_expr_stmt (stmt
);
9690 finish_omp_depobj (location_t loc
, tree depobj
,
9691 enum omp_clause_depend_kind kind
, tree clause
)
9693 if (!error_operand_p (depobj
) && !type_dependent_expression_p (depobj
))
9695 if (!lvalue_p (depobj
))
9697 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
9698 "%<depobj%> expression is not lvalue expression");
9699 depobj
= error_mark_node
;
9703 if (processing_template_decl
)
9705 if (clause
== NULL_TREE
)
9706 clause
= build_int_cst (integer_type_node
, kind
);
9707 add_stmt (build_min_nt_loc (loc
, OMP_DEPOBJ
, depobj
, clause
));
9711 if (!error_operand_p (depobj
))
9713 tree addr
= cp_build_addr_expr (depobj
, tf_warning_or_error
);
9714 if (addr
== error_mark_node
)
9715 depobj
= error_mark_node
;
9717 depobj
= cp_build_indirect_ref (loc
, addr
, RO_UNARY_STAR
,
9718 tf_warning_or_error
);
9721 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
9725 finish_omp_flush (int mo
)
9727 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
9729 if (mo
!= MEMMODEL_LAST
)
9731 fn
= builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE
);
9732 vec
->quick_push (build_int_cst (integer_type_node
, mo
));
9734 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9735 finish_expr_stmt (stmt
);
9739 finish_omp_taskwait (void)
9741 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
9743 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9744 finish_expr_stmt (stmt
);
9748 finish_omp_taskyield (void)
9750 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
9752 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9753 finish_expr_stmt (stmt
);
9757 finish_omp_cancel (tree clauses
)
9759 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
9761 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9763 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9765 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9767 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9771 error ("%<#pragma omp cancel%> must specify one of "
9772 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9776 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
9777 if (ifc
!= NULL_TREE
)
9779 if (OMP_CLAUSE_IF_MODIFIER (ifc
) != ERROR_MARK
9780 && OMP_CLAUSE_IF_MODIFIER (ifc
) != VOID_CST
)
9781 error_at (OMP_CLAUSE_LOCATION (ifc
),
9782 "expected %<cancel%> %<if%> clause modifier");
9785 tree ifc2
= omp_find_clause (OMP_CLAUSE_CHAIN (ifc
), OMP_CLAUSE_IF
);
9786 if (ifc2
!= NULL_TREE
)
9788 gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc
) == VOID_CST
9789 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != ERROR_MARK
9790 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != VOID_CST
);
9791 error_at (OMP_CLAUSE_LOCATION (ifc2
),
9792 "expected %<cancel%> %<if%> clause modifier");
9796 if (!processing_template_decl
)
9797 ifc
= maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc
));
9799 ifc
= build_x_binary_op (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
9800 OMP_CLAUSE_IF_EXPR (ifc
), ERROR_MARK
,
9801 integer_zero_node
, ERROR_MARK
,
9802 NULL
, tf_warning_or_error
);
9805 ifc
= boolean_true_node
;
9806 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
9807 vec
->quick_push (ifc
);
9808 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9809 finish_expr_stmt (stmt
);
9813 finish_omp_cancellation_point (tree clauses
)
9815 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
9817 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
9819 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
9821 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
9823 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
9827 error ("%<#pragma omp cancellation point%> must specify one of "
9828 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
9832 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
9833 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9834 finish_expr_stmt (stmt
);
9837 /* Begin a __transaction_atomic or __transaction_relaxed statement.
9838 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
9839 should create an extra compound stmt. */
9842 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
9847 *pcompound
= begin_compound_stmt (0);
9849 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
9851 /* Only add the statement to the function if support enabled. */
9855 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
9856 ? G_("%<__transaction_relaxed%> without "
9857 "transactional memory support enabled")
9858 : G_("%<__transaction_atomic%> without "
9859 "transactional memory support enabled")));
9861 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
9862 TREE_SIDE_EFFECTS (r
) = 1;
9866 /* End a __transaction_atomic or __transaction_relaxed statement.
9867 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
9868 and we should end the compound. If NOEX is non-NULL, we wrap the body in
9869 a MUST_NOT_THROW_EXPR with NOEX as condition. */
9872 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
9874 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
9875 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
9876 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
9877 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
9879 /* noexcept specifications are not allowed for function transactions. */
9880 gcc_assert (!(noex
&& compound_stmt
));
9883 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
9885 protected_set_expr_location
9886 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
9887 TREE_SIDE_EFFECTS (body
) = 1;
9888 TRANSACTION_EXPR_BODY (stmt
) = body
;
9892 finish_compound_stmt (compound_stmt
);
9895 /* Build a __transaction_atomic or __transaction_relaxed expression. If
9896 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
9900 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
9905 expr
= build_must_not_throw_expr (expr
, noex
);
9906 protected_set_expr_location (expr
, loc
);
9907 TREE_SIDE_EFFECTS (expr
) = 1;
9909 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
9910 if (flags
& TM_STMT_ATTR_RELAXED
)
9911 TRANSACTION_EXPR_RELAXED (ret
) = 1;
9912 TREE_SIDE_EFFECTS (ret
) = 1;
9913 SET_EXPR_LOCATION (ret
, loc
);
9918 init_cp_semantics (void)
9923 /* If we have a condition in conjunctive normal form (CNF), find the first
9924 failing clause. In other words, given an expression like
9926 true && true && false && true && false
9928 return the first 'false'. EXPR is the expression. */
9931 find_failing_clause_r (tree expr
)
9933 if (TREE_CODE (expr
) == TRUTH_ANDIF_EXPR
)
9935 /* First check the left side... */
9936 tree e
= find_failing_clause_r (TREE_OPERAND (expr
, 0));
9938 /* ...if we didn't find a false clause, check the right side. */
9939 e
= find_failing_clause_r (TREE_OPERAND (expr
, 1));
9942 tree e
= contextual_conv_bool (expr
, tf_none
);
9943 e
= fold_non_dependent_expr (e
, tf_none
, /*manifestly_const_eval=*/true);
9944 if (integer_zerop (e
))
9945 /* This is the failing clause. */
9950 /* Wrapper for find_failing_clause_r. */
9953 find_failing_clause (tree expr
)
9955 if (TREE_CODE (expr
) != TRUTH_ANDIF_EXPR
)
9957 return find_failing_clause_r (expr
);
9960 /* Build a STATIC_ASSERT for a static assertion with the condition
9961 CONDITION and the message text MESSAGE. LOCATION is the location
9962 of the static assertion in the source code. When MEMBER_P, this
9963 static assertion is a member of a class. If SHOW_EXPR_P is true,
9964 print the condition (because it was instantiation-dependent). */
9967 finish_static_assert (tree condition
, tree message
, location_t location
,
9968 bool member_p
, bool show_expr_p
)
9970 tsubst_flags_t complain
= tf_warning_or_error
;
9972 if (message
== NULL_TREE
9973 || message
== error_mark_node
9974 || condition
== NULL_TREE
9975 || condition
== error_mark_node
)
9978 if (check_for_bare_parameter_packs (condition
))
9979 condition
= error_mark_node
;
9981 if (instantiation_dependent_expression_p (condition
))
9983 /* We're in a template; build a STATIC_ASSERT and put it in
9987 assertion
= make_node (STATIC_ASSERT
);
9988 STATIC_ASSERT_CONDITION (assertion
) = condition
;
9989 STATIC_ASSERT_MESSAGE (assertion
) = message
;
9990 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
9993 maybe_add_class_template_decl_list (current_class_type
,
9997 add_stmt (assertion
);
10002 /* Save the condition in case it was a concept check. */
10003 tree orig_condition
= condition
;
10005 /* Fold the expression and convert it to a boolean value. */
10006 condition
= contextual_conv_bool (condition
, complain
);
10007 condition
= fold_non_dependent_expr (condition
, complain
,
10008 /*manifestly_const_eval=*/true);
10010 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
10011 /* Do nothing; the condition is satisfied. */
10015 iloc_sentinel
ils (location
);
10017 if (integer_zerop (condition
))
10019 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
10020 (TREE_TYPE (TREE_TYPE (message
))));
10021 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
10023 /* See if we can find which clause was failing (for logical AND). */
10024 tree bad
= find_failing_clause (orig_condition
);
10025 /* If not, or its location is unusable, fall back to the previous
10027 location_t cloc
= location
;
10028 if (cp_expr_location (bad
) != UNKNOWN_LOCATION
)
10029 cloc
= cp_expr_location (bad
);
10031 /* Report the error. */
10033 error_at (cloc
, "static assertion failed");
10035 error_at (cloc
, "static assertion failed: %s",
10036 TREE_STRING_POINTER (message
));
10038 inform (cloc
, "%qE evaluates to false",
10039 /* Nobody wants to see the artificial (bool) cast. */
10040 (bad
? tree_strip_nop_conversions (bad
) : orig_condition
));
10042 /* Actually explain the failure if this is a concept check or a
10043 requires-expression. */
10044 if (concept_check_p (orig_condition
)
10045 || TREE_CODE (orig_condition
) == REQUIRES_EXPR
)
10046 diagnose_constraints (location
, orig_condition
, NULL_TREE
);
10048 else if (condition
&& condition
!= error_mark_node
)
10050 error ("non-constant condition for static assertion");
10051 if (require_rvalue_constant_expression (condition
))
10052 cxx_constant_value (condition
);
10057 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
10058 suitable for use as a type-specifier.
10060 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
10061 id-expression or a class member access, FALSE when it was parsed as
10062 a full expression. */
10065 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
10066 tsubst_flags_t complain
)
10068 tree type
= NULL_TREE
;
10070 if (!expr
|| error_operand_p (expr
))
10071 return error_mark_node
;
10074 || TREE_CODE (expr
) == TYPE_DECL
10075 || (TREE_CODE (expr
) == BIT_NOT_EXPR
10076 && TYPE_P (TREE_OPERAND (expr
, 0))))
10078 if (complain
& tf_error
)
10079 error ("argument to %<decltype%> must be an expression");
10080 return error_mark_node
;
10083 /* decltype is an unevaluated context. */
10086 /* Depending on the resolution of DR 1172, we may later need to distinguish
10087 instantiation-dependent but not type-dependent expressions so that, say,
10088 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
10089 if (instantiation_dependent_uneval_expression_p (expr
))
10091 type
= cxx_make_type (DECLTYPE_TYPE
);
10092 DECLTYPE_TYPE_EXPR (type
) = expr
;
10093 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
10094 = id_expression_or_member_access_p
;
10095 SET_TYPE_STRUCTURAL_EQUALITY (type
);
10099 else if (processing_template_decl
)
10101 expr
= instantiate_non_dependent_expr_sfinae (expr
, complain
);
10102 if (expr
== error_mark_node
)
10103 return error_mark_node
;
10106 /* The type denoted by decltype(e) is defined as follows: */
10108 expr
= resolve_nondeduced_context (expr
, complain
);
10110 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
10111 return error_mark_node
;
10113 if (type_unknown_p (expr
))
10115 if (complain
& tf_error
)
10116 error ("%<decltype%> cannot resolve address of overloaded function");
10117 return error_mark_node
;
10120 /* To get the size of a static data member declared as an array of
10121 unknown bound, we need to instantiate it. */
10123 && VAR_HAD_UNKNOWN_BOUND (expr
)
10124 && DECL_TEMPLATE_INSTANTIATION (expr
))
10125 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
10127 if (id_expression_or_member_access_p
)
10129 /* If e is an id-expression or a class member access (5.2.5
10130 [expr.ref]), decltype(e) is defined as the type of the entity
10131 named by e. If there is no such entity, or e names a set of
10132 overloaded functions, the program is ill-formed. */
10133 if (identifier_p (expr
))
10134 expr
= lookup_name (expr
);
10136 if (INDIRECT_REF_P (expr
)
10137 || TREE_CODE (expr
) == VIEW_CONVERT_EXPR
)
10138 /* This can happen when the expression is, e.g., "a.b". Just
10139 look at the underlying operand. */
10140 expr
= TREE_OPERAND (expr
, 0);
10142 if (TREE_CODE (expr
) == OFFSET_REF
10143 || TREE_CODE (expr
) == MEMBER_REF
10144 || TREE_CODE (expr
) == SCOPE_REF
)
10145 /* We're only interested in the field itself. If it is a
10146 BASELINK, we will need to see through it in the next
10148 expr
= TREE_OPERAND (expr
, 1);
10150 if (BASELINK_P (expr
))
10151 /* See through BASELINK nodes to the underlying function. */
10152 expr
= BASELINK_FUNCTIONS (expr
);
10154 /* decltype of a decomposition name drops references in the tuple case
10155 (unlike decltype of a normal variable) and keeps cv-qualifiers from
10156 the containing object in the other cases (unlike decltype of a member
10157 access expression). */
10158 if (DECL_DECOMPOSITION_P (expr
))
10160 if (DECL_HAS_VALUE_EXPR_P (expr
))
10161 /* Expr is an array or struct subobject proxy, handle
10162 bit-fields properly. */
10163 return unlowered_expr_type (expr
);
10165 /* Expr is a reference variable for the tuple case. */
10166 return lookup_decomp_type (expr
);
10169 switch (TREE_CODE (expr
))
10172 if (DECL_BIT_FIELD_TYPE (expr
))
10174 type
= DECL_BIT_FIELD_TYPE (expr
);
10177 /* Fall through for fields that aren't bitfields. */
10178 gcc_fallthrough ();
10180 case FUNCTION_DECL
:
10185 case TEMPLATE_PARM_INDEX
:
10186 expr
= mark_type_use (expr
);
10187 type
= TREE_TYPE (expr
);
10191 type
= error_mark_node
;
10194 case COMPONENT_REF
:
10195 case COMPOUND_EXPR
:
10196 mark_type_use (expr
);
10197 type
= is_bitfield_expr_with_lowered_type (expr
);
10199 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
10202 case BIT_FIELD_REF
:
10203 gcc_unreachable ();
10207 /* We can get here when the id-expression refers to an
10208 enumerator or non-type template parameter. */
10209 type
= TREE_TYPE (expr
);
10213 /* Handle instantiated template non-type arguments. */
10214 type
= TREE_TYPE (expr
);
10220 /* Within a lambda-expression:
10222 Every occurrence of decltype((x)) where x is a possibly
10223 parenthesized id-expression that names an entity of
10224 automatic storage duration is treated as if x were
10225 transformed into an access to a corresponding data member
10226 of the closure type that would have been declared if x
10227 were a use of the denoted entity. */
10228 if (outer_automatic_var_p (expr
)
10229 && current_function_decl
10230 && LAMBDA_FUNCTION_P (current_function_decl
))
10231 type
= capture_decltype (expr
);
10232 else if (error_operand_p (expr
))
10233 type
= error_mark_node
;
10234 else if (expr
== current_class_ptr
)
10235 /* If the expression is just "this", we want the
10236 cv-unqualified pointer for the "this" type. */
10237 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
10240 /* Otherwise, where T is the type of e, if e is an lvalue,
10241 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
10242 cp_lvalue_kind clk
= lvalue_kind (expr
);
10243 type
= unlowered_expr_type (expr
);
10244 gcc_assert (!TYPE_REF_P (type
));
10246 /* For vector types, pick a non-opaque variant. */
10247 if (VECTOR_TYPE_P (type
))
10248 type
= strip_typedefs (type
);
10250 if (clk
!= clk_none
&& !(clk
& clk_class
))
10251 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
10258 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
10259 __has_nothrow_copy, depending on assign_p. Returns true iff all
10260 the copy {ctor,assign} fns are nothrow. */
10263 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
10265 tree fns
= NULL_TREE
;
10267 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
10268 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
10269 : ctor_identifier
);
10271 bool saw_copy
= false;
10272 for (ovl_iterator
iter (fns
); iter
; ++iter
)
10276 if (copy_fn_p (fn
) > 0)
10279 if (!maybe_instantiate_noexcept (fn
)
10280 || !TYPE_NOTHROW_P (TREE_TYPE (fn
)))
10288 /* Actually evaluates the trait. */
10291 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
10293 enum tree_code type_code1
;
10296 type_code1
= TREE_CODE (type1
);
10300 case CPTK_HAS_NOTHROW_ASSIGN
:
10301 type1
= strip_array_types (type1
);
10302 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
10303 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
10304 || (CLASS_TYPE_P (type1
)
10305 && classtype_has_nothrow_assign_or_copy_p (type1
,
10308 case CPTK_HAS_TRIVIAL_ASSIGN
:
10309 /* ??? The standard seems to be missing the "or array of such a class
10310 type" wording for this trait. */
10311 type1
= strip_array_types (type1
);
10312 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
10313 && (trivial_type_p (type1
)
10314 || (CLASS_TYPE_P (type1
)
10315 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
10317 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
10318 type1
= strip_array_types (type1
);
10319 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
10320 || (CLASS_TYPE_P (type1
)
10321 && (t
= locate_ctor (type1
))
10322 && maybe_instantiate_noexcept (t
)
10323 && TYPE_NOTHROW_P (TREE_TYPE (t
))));
10325 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
10326 type1
= strip_array_types (type1
);
10327 return (trivial_type_p (type1
)
10328 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
10330 case CPTK_HAS_NOTHROW_COPY
:
10331 type1
= strip_array_types (type1
);
10332 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
10333 || (CLASS_TYPE_P (type1
)
10334 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
10336 case CPTK_HAS_TRIVIAL_COPY
:
10337 /* ??? The standard seems to be missing the "or array of such a class
10338 type" wording for this trait. */
10339 type1
= strip_array_types (type1
);
10340 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
10341 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
10343 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
10344 type1
= strip_array_types (type1
);
10345 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
10346 || (CLASS_TYPE_P (type1
)
10347 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
10349 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
10350 return type_has_virtual_destructor (type1
);
10352 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
10353 return type_has_unique_obj_representations (type1
);
10355 case CPTK_IS_ABSTRACT
:
10356 return ABSTRACT_CLASS_TYPE_P (type1
);
10358 case CPTK_IS_AGGREGATE
:
10359 return CP_AGGREGATE_TYPE_P (type1
);
10361 case CPTK_IS_BASE_OF
:
10362 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
10363 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
10364 || DERIVED_FROM_P (type1
, type2
)));
10366 case CPTK_IS_CLASS
:
10367 return NON_UNION_CLASS_TYPE_P (type1
);
10369 case CPTK_IS_EMPTY
:
10370 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
10373 return type_code1
== ENUMERAL_TYPE
;
10375 case CPTK_IS_FINAL
:
10376 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
10378 case CPTK_IS_LITERAL_TYPE
:
10379 return literal_type_p (type1
);
10382 return pod_type_p (type1
);
10384 case CPTK_IS_POLYMORPHIC
:
10385 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
10387 case CPTK_IS_SAME_AS
:
10388 return same_type_p (type1
, type2
);
10390 case CPTK_IS_STD_LAYOUT
:
10391 return std_layout_type_p (type1
);
10393 case CPTK_IS_TRIVIAL
:
10394 return trivial_type_p (type1
);
10396 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
10397 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
10399 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
10400 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
10402 case CPTK_IS_TRIVIALLY_COPYABLE
:
10403 return trivially_copyable_p (type1
);
10405 case CPTK_IS_UNION
:
10406 return type_code1
== UNION_TYPE
;
10408 case CPTK_IS_ASSIGNABLE
:
10409 return is_xible (MODIFY_EXPR
, type1
, type2
);
10411 case CPTK_IS_CONSTRUCTIBLE
:
10412 return is_xible (INIT_EXPR
, type1
, type2
);
10414 case CPTK_IS_NOTHROW_ASSIGNABLE
:
10415 return is_nothrow_xible (MODIFY_EXPR
, type1
, type2
);
10417 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
10418 return is_nothrow_xible (INIT_EXPR
, type1
, type2
);
10421 gcc_unreachable ();
10426 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
10427 void, or a complete type, returns true, otherwise false. */
10430 check_trait_type (tree type
)
10432 if (type
== NULL_TREE
)
10435 if (TREE_CODE (type
) == TREE_LIST
)
10436 return (check_trait_type (TREE_VALUE (type
))
10437 && check_trait_type (TREE_CHAIN (type
)));
10439 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
10440 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
10443 if (VOID_TYPE_P (type
))
10446 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
10449 /* Process a trait expression. */
10452 finish_trait_expr (location_t loc
, cp_trait_kind kind
, tree type1
, tree type2
)
10454 if (type1
== error_mark_node
10455 || type2
== error_mark_node
)
10456 return error_mark_node
;
10458 if (processing_template_decl
)
10460 tree trait_expr
= make_node (TRAIT_EXPR
);
10461 TREE_TYPE (trait_expr
) = boolean_type_node
;
10462 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
10463 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
10464 TRAIT_EXPR_KIND (trait_expr
) = kind
;
10465 TRAIT_EXPR_LOCATION (trait_expr
) = loc
;
10471 case CPTK_HAS_NOTHROW_ASSIGN
:
10472 case CPTK_HAS_TRIVIAL_ASSIGN
:
10473 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
10474 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
10475 case CPTK_HAS_NOTHROW_COPY
:
10476 case CPTK_HAS_TRIVIAL_COPY
:
10477 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
10478 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
10479 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
10480 case CPTK_IS_ABSTRACT
:
10481 case CPTK_IS_AGGREGATE
:
10482 case CPTK_IS_EMPTY
:
10483 case CPTK_IS_FINAL
:
10484 case CPTK_IS_LITERAL_TYPE
:
10486 case CPTK_IS_POLYMORPHIC
:
10487 case CPTK_IS_STD_LAYOUT
:
10488 case CPTK_IS_TRIVIAL
:
10489 case CPTK_IS_TRIVIALLY_COPYABLE
:
10490 if (!check_trait_type (type1
))
10491 return error_mark_node
;
10494 case CPTK_IS_ASSIGNABLE
:
10495 case CPTK_IS_CONSTRUCTIBLE
:
10498 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
10499 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
10500 case CPTK_IS_NOTHROW_ASSIGNABLE
:
10501 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
10502 if (!check_trait_type (type1
)
10503 || !check_trait_type (type2
))
10504 return error_mark_node
;
10507 case CPTK_IS_BASE_OF
:
10508 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
10509 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
10510 && !complete_type_or_else (type2
, NULL_TREE
))
10511 /* We already issued an error. */
10512 return error_mark_node
;
10515 case CPTK_IS_CLASS
:
10517 case CPTK_IS_UNION
:
10518 case CPTK_IS_SAME_AS
:
10522 gcc_unreachable ();
10525 tree val
= (trait_expr_value (kind
, type1
, type2
)
10526 ? boolean_true_node
: boolean_false_node
);
10527 return maybe_wrap_with_location (val
, loc
);
10530 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
10531 which is ignored for C++. */
10534 set_float_const_decimal64 (void)
10539 clear_float_const_decimal64 (void)
10544 float_const_decimal64_p (void)
10550 /* Return true if T designates the implied `this' parameter. */
10553 is_this_parameter (tree t
)
10555 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
10557 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
)
10558 || (cp_binding_oracle
&& TREE_CODE (t
) == VAR_DECL
));
10562 /* Insert the deduced return type for an auto function. */
10565 apply_deduced_return_type (tree fco
, tree return_type
)
10569 if (return_type
== error_mark_node
)
10572 if (DECL_CONV_FN_P (fco
))
10573 DECL_NAME (fco
) = make_conv_op_name (return_type
);
10575 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
10577 result
= DECL_RESULT (fco
);
10578 if (result
== NULL_TREE
)
10580 if (TREE_TYPE (result
) == return_type
)
10583 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
10584 && !complete_type_or_else (return_type
, NULL_TREE
))
10587 /* We already have a DECL_RESULT from start_preparsed_function.
10588 Now we need to redo the work it and allocate_struct_function
10589 did to reflect the new type. */
10590 gcc_assert (current_function_decl
== fco
);
10591 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
10592 TYPE_MAIN_VARIANT (return_type
));
10593 DECL_ARTIFICIAL (result
) = 1;
10594 DECL_IGNORED_P (result
) = 1;
10595 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
10598 DECL_RESULT (fco
) = result
;
10600 if (!processing_template_decl
)
10602 bool aggr
= aggregate_value_p (result
, fco
);
10603 #ifdef PCC_STATIC_STRUCT_RETURN
10604 cfun
->returns_pcc_struct
= aggr
;
10606 cfun
->returns_struct
= aggr
;
10610 /* DECL is a local variable or parameter from the surrounding scope of a
10611 lambda-expression. Returns the decltype for a use of the capture field
10612 for DECL even if it hasn't been captured yet. */
10615 capture_decltype (tree decl
)
10617 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
10618 tree cap
= lookup_name (DECL_NAME (decl
), LOOK_where::BLOCK
,
10619 LOOK_want::HIDDEN_LAMBDA
);
10622 if (cap
&& is_capture_proxy (cap
))
10623 type
= TREE_TYPE (cap
);
10625 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
10628 error ("%qD is not captured", decl
);
10629 return error_mark_node
;
10632 type
= TREE_TYPE (decl
);
10633 if (TYPE_REF_P (type
)
10634 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
10635 type
= TREE_TYPE (type
);
10638 case CPLD_REFERENCE
:
10639 type
= TREE_TYPE (decl
);
10640 if (!TYPE_REF_P (type
))
10641 type
= build_reference_type (TREE_TYPE (decl
));
10645 gcc_unreachable ();
10648 if (!TYPE_REF_P (type
))
10650 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
10651 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
10652 |TYPE_QUAL_CONST
));
10653 type
= build_reference_type (type
);
10658 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
10659 this is a right unary fold. Otherwise it is a left unary fold. */
10662 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
10664 /* Build a pack expansion (assuming expr has pack type). */
10665 if (!uses_parameter_packs (expr
))
10667 error_at (location_of (expr
), "operand of fold expression has no "
10668 "unexpanded parameter packs");
10669 return error_mark_node
;
10671 tree pack
= make_pack_expansion (expr
);
10673 /* Build the fold expression. */
10674 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10675 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
);
10676 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10681 finish_left_unary_fold_expr (tree expr
, int op
)
10683 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
10687 finish_right_unary_fold_expr (tree expr
, int op
)
10689 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
10692 /* Build a binary fold expression over EXPR1 and EXPR2. The
10693 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
10694 has an unexpanded parameter pack). */
10697 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
10699 pack
= make_pack_expansion (pack
);
10700 tree code
= build_int_cstu (integer_type_node
, abs (op
));
10701 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
, init
);
10702 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
10707 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
10709 // Determine which expr has an unexpanded parameter pack and
10710 // set the pack and initial term.
10711 bool pack1
= uses_parameter_packs (expr1
);
10712 bool pack2
= uses_parameter_packs (expr2
);
10713 if (pack1
&& !pack2
)
10714 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
10715 else if (pack2
&& !pack1
)
10716 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
10720 error ("both arguments in binary fold have unexpanded parameter packs");
10722 error ("no unexpanded parameter packs in binary fold");
10724 return error_mark_node
;
10727 /* Finish __builtin_launder (arg). */
10730 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
10732 tree orig_arg
= arg
;
10733 if (!type_dependent_expression_p (arg
))
10734 arg
= decay_conversion (arg
, complain
);
10735 if (error_operand_p (arg
))
10736 return error_mark_node
;
10737 if (!type_dependent_expression_p (arg
)
10738 && !TYPE_PTR_P (TREE_TYPE (arg
)))
10740 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
10741 return error_mark_node
;
10743 if (processing_template_decl
)
10745 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
10746 TREE_TYPE (arg
), 1, arg
);
10749 /* Finish __builtin_convertvector (arg, type). */
10752 cp_build_vec_convert (tree arg
, location_t loc
, tree type
,
10753 tsubst_flags_t complain
)
10755 if (error_operand_p (type
))
10756 return error_mark_node
;
10757 if (error_operand_p (arg
))
10758 return error_mark_node
;
10760 tree ret
= NULL_TREE
;
10761 if (!type_dependent_expression_p (arg
) && !dependent_type_p (type
))
10762 ret
= c_build_vec_convert (cp_expr_loc_or_input_loc (arg
),
10763 decay_conversion (arg
, complain
),
10764 loc
, type
, (complain
& tf_error
) != 0);
10766 if (!processing_template_decl
)
10769 return build_call_expr_internal_loc (loc
, IFN_VEC_CONVERT
, type
, 1, arg
);
10772 /* Finish __builtin_bit_cast (type, arg). */
10775 cp_build_bit_cast (location_t loc
, tree type
, tree arg
,
10776 tsubst_flags_t complain
)
10778 if (error_operand_p (type
))
10779 return error_mark_node
;
10780 if (!dependent_type_p (type
))
10782 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
))
10783 return error_mark_node
;
10784 if (TREE_CODE (type
) == ARRAY_TYPE
)
10786 /* std::bit_cast for destination ARRAY_TYPE is not possible,
10787 as functions may not return an array, so don't bother trying
10788 to support this (and then deal with VLAs etc.). */
10789 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
10790 "is an array type", type
);
10791 return error_mark_node
;
10793 if (!trivially_copyable_p (type
))
10795 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
10796 "is not trivially copyable", type
);
10797 return error_mark_node
;
10801 if (error_operand_p (arg
))
10802 return error_mark_node
;
10804 if (!type_dependent_expression_p (arg
))
10806 if (TREE_CODE (TREE_TYPE (arg
)) == ARRAY_TYPE
)
10808 /* Don't perform array-to-pointer conversion. */
10809 arg
= mark_rvalue_use (arg
, loc
, true);
10810 if (!complete_type_or_maybe_complain (TREE_TYPE (arg
), arg
, complain
))
10811 return error_mark_node
;
10814 arg
= decay_conversion (arg
, complain
);
10816 if (error_operand_p (arg
))
10817 return error_mark_node
;
10819 if (!trivially_copyable_p (TREE_TYPE (arg
)))
10821 error_at (cp_expr_loc_or_loc (arg
, loc
),
10822 "%<__builtin_bit_cast%> source type %qT "
10823 "is not trivially copyable", TREE_TYPE (arg
));
10824 return error_mark_node
;
10826 if (!dependent_type_p (type
)
10827 && !cp_tree_equal (TYPE_SIZE_UNIT (type
),
10828 TYPE_SIZE_UNIT (TREE_TYPE (arg
))))
10830 error_at (loc
, "%<__builtin_bit_cast%> source size %qE "
10831 "not equal to destination type size %qE",
10832 TYPE_SIZE_UNIT (TREE_TYPE (arg
)),
10833 TYPE_SIZE_UNIT (type
));
10834 return error_mark_node
;
10838 tree ret
= build_min (BIT_CAST_EXPR
, type
, arg
);
10839 SET_EXPR_LOCATION (ret
, loc
);
10841 if (!processing_template_decl
&& CLASS_TYPE_P (type
))
10842 ret
= get_target_expr_sfinae (ret
, complain
);
10847 #include "gt-cp-semantics.h"