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-2017 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"
48 /* There routines provide a modular interface to perform many parsing
49 operations. They may therefore be used during actual parsing, or
50 during template instantiation, which may be regarded as a
51 degenerate form of parsing. */
53 static tree
maybe_convert_cond (tree
);
54 static tree
finalize_nrv_r (tree
*, int *, void *);
55 static tree
capture_decltype (tree
);
57 /* Used for OpenMP non-static data member privatization. */
59 static hash_map
<tree
, tree
> *omp_private_member_map
;
60 static vec
<tree
> omp_private_member_vec
;
61 static bool omp_private_member_ignore_next
;
64 /* Deferred Access Checking Overview
65 ---------------------------------
67 Most C++ expressions and declarations require access checking
68 to be performed during parsing. However, in several cases,
69 this has to be treated differently.
71 For member declarations, access checking has to be deferred
72 until more information about the declaration is known. For
84 When we are parsing the function return type `A::X', we don't
85 really know if this is allowed until we parse the function name.
87 Furthermore, some contexts require that access checking is
88 never performed at all. These include class heads, and template
91 Typical use of access checking functions is described here:
93 1. When we enter a context that requires certain access checking
94 mode, the function `push_deferring_access_checks' is called with
95 DEFERRING argument specifying the desired mode. Access checking
96 may be performed immediately (dk_no_deferred), deferred
97 (dk_deferred), or not performed (dk_no_check).
99 2. When a declaration such as a type, or a variable, is encountered,
100 the function `perform_or_defer_access_check' is called. It
101 maintains a vector of all deferred checks.
103 3. The global `current_class_type' or `current_function_decl' is then
104 setup by the parser. `enforce_access' relies on these information
107 4. Upon exiting the context mentioned in step 1,
108 `perform_deferred_access_checks' is called to check all declaration
109 stored in the vector. `pop_deferring_access_checks' is then
110 called to restore the previous access checking mode.
112 In case of parsing error, we simply call `pop_deferring_access_checks'
113 without `perform_deferred_access_checks'. */
115 struct GTY(()) deferred_access
{
116 /* A vector representing name-lookups for which we have deferred
117 checking access controls. We cannot check the accessibility of
118 names used in a decl-specifier-seq until we know what is being
119 declared because code like:
126 A::B* A::f() { return 0; }
128 is valid, even though `A::B' is not generally accessible. */
129 vec
<deferred_access_check
, va_gc
> * GTY(()) deferred_access_checks
;
131 /* The current mode of access checks. */
132 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 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
260 is the BINFO indicating the qualifying scope used to access the
261 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
262 or we aren't in SFINAE context or all the checks succeed return TRUE,
266 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
267 tsubst_flags_t complain
)
270 deferred_access_check
*chk
;
271 location_t loc
= input_location
;
277 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
279 input_location
= chk
->loc
;
280 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
283 input_location
= loc
;
284 return (complain
& tf_error
) ? true : ok
;
287 /* Perform the deferred access checks.
289 After performing the checks, we still have to keep the list
290 `deferred_access_stack->deferred_access_checks' since we may want
291 to check access for them again later in a different context.
298 A::X A::a, x; // No error for `A::a', error for `x'
300 We have to perform deferred access of `A::X', first with `A::a',
301 next with `x'. Return value like perform_access_checks above. */
304 perform_deferred_access_checks (tsubst_flags_t complain
)
306 return perform_access_checks (get_deferred_access_checks (), complain
);
309 /* Defer checking the accessibility of DECL, when looked up in
310 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
311 Return value like perform_access_checks above.
312 If non-NULL, report failures to AFI. */
315 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
316 tsubst_flags_t complain
,
317 access_failure_info
*afi
)
320 deferred_access
*ptr
;
321 deferred_access_check
*chk
;
324 /* Exit if we are in a context that no access checking is performed.
326 if (deferred_access_no_check
)
329 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
331 ptr
= &deferred_access_stack
->last ();
333 /* If we are not supposed to defer access checks, just check now. */
334 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
336 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
, afi
);
337 return (complain
& tf_error
) ? true : ok
;
340 /* See if we are already going to perform this check. */
341 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
343 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
344 chk
->diag_decl
== diag_decl
)
349 /* If not, record the check. */
350 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
351 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
356 /* Returns nonzero if the current statement is a full expression,
357 i.e. temporaries created during that statement should be destroyed
358 at the end of the statement. */
361 stmts_are_full_exprs_p (void)
363 return current_stmt_tree ()->stmts_are_full_exprs_p
;
366 /* T is a statement. Add it to the statement-tree. This is the C++
367 version. The C/ObjC frontends have a slightly different version of
373 enum tree_code code
= TREE_CODE (t
);
375 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
377 if (!EXPR_HAS_LOCATION (t
))
378 SET_EXPR_LOCATION (t
, input_location
);
380 /* When we expand a statement-tree, we must know whether or not the
381 statements are full-expressions. We record that fact here. */
382 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
385 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
386 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
388 /* Add T to the statement-tree. Non-side-effect statements need to be
389 recorded during statement expressions. */
390 gcc_checking_assert (!stmt_list_stack
->is_empty ());
391 append_to_statement_list_force (t
, &cur_stmt_list
);
396 /* Returns the stmt_tree to which statements are currently being added. */
399 current_stmt_tree (void)
402 ? &cfun
->language
->base
.x_stmt_tree
403 : &scope_chain
->x_stmt_tree
);
406 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
409 maybe_cleanup_point_expr (tree expr
)
411 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
412 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
414 expr
= do_dependent_capture (expr
);
418 /* Like maybe_cleanup_point_expr except have the type of the new expression be
419 void so we don't need to create a temporary variable to hold the inner
420 expression. The reason why we do this is because the original type might be
421 an aggregate and we cannot create a temporary variable for that type. */
424 maybe_cleanup_point_expr_void (tree expr
)
426 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
427 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
429 expr
= do_dependent_capture (expr
);
435 /* Create a declaration statement for the declaration given by the DECL. */
438 add_decl_expr (tree decl
)
440 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
441 if (DECL_INITIAL (decl
)
442 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
443 r
= maybe_cleanup_point_expr_void (r
);
447 /* Finish a scope. */
450 do_poplevel (tree stmt_list
)
454 if (stmts_are_full_exprs_p ())
455 block
= poplevel (kept_level_p (), 1, 0);
457 stmt_list
= pop_stmt_list (stmt_list
);
459 if (!processing_template_decl
)
461 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
462 /* ??? See c_end_compound_stmt re statement expressions. */
468 /* Begin a new scope. */
471 do_pushlevel (scope_kind sk
)
473 tree ret
= push_stmt_list ();
474 if (stmts_are_full_exprs_p ())
475 begin_scope (sk
, NULL
);
479 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
480 when the current scope is exited. EH_ONLY is true when this is not
481 meant to apply to normal control flow transfer. */
484 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
486 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
487 CLEANUP_EH_ONLY (stmt
) = eh_only
;
489 CLEANUP_BODY (stmt
) = push_stmt_list ();
492 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
493 the current loops, represented by 'NULL_TREE' if we've seen a possible
494 exit, and 'error_mark_node' if not. This is currently used only to
495 suppress the warning about a function with no return statements, and
496 therefore we don't bother noting returns as possible exits. We also
497 don't bother with gotos. */
500 begin_maybe_infinite_loop (tree cond
)
502 /* Only track this while parsing a function, not during instantiation. */
503 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
504 && !processing_template_decl
))
506 bool maybe_infinite
= true;
509 cond
= fold_non_dependent_expr (cond
);
510 maybe_infinite
= integer_nonzerop (cond
);
512 vec_safe_push (cp_function_chain
->infinite_loops
,
513 maybe_infinite
? error_mark_node
: NULL_TREE
);
517 /* A break is a possible exit for the current loop. */
520 break_maybe_infinite_loop (void)
524 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
527 /* If we reach the end of the loop without seeing a possible exit, we have
531 end_maybe_infinite_loop (tree cond
)
533 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
534 && !processing_template_decl
))
536 tree current
= cp_function_chain
->infinite_loops
->pop();
537 if (current
!= NULL_TREE
)
539 cond
= fold_non_dependent_expr (cond
);
540 if (integer_nonzerop (cond
))
541 current_function_infinite_loop
= 1;
546 /* Begin a conditional that might contain a declaration. When generating
547 normal code, we want the declaration to appear before the statement
548 containing the conditional. When generating template code, we want the
549 conditional to be rendered as the raw DECL_EXPR. */
552 begin_cond (tree
*cond_p
)
554 if (processing_template_decl
)
555 *cond_p
= push_stmt_list ();
558 /* Finish such a conditional. */
561 finish_cond (tree
*cond_p
, tree expr
)
563 if (processing_template_decl
)
565 tree cond
= pop_stmt_list (*cond_p
);
567 if (expr
== NULL_TREE
)
568 /* Empty condition in 'for'. */
569 gcc_assert (empty_expr_stmt_p (cond
));
570 else if (check_for_bare_parameter_packs (expr
))
571 expr
= error_mark_node
;
572 else if (!empty_expr_stmt_p (cond
))
573 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
578 /* If *COND_P specifies a conditional with a declaration, transform the
581 for (; A x = 42;) { }
583 while (true) { A x = 42; if (!x) break; }
584 for (;;) { A x = 42; if (!x) break; }
585 The statement list for BODY will be empty if the conditional did
586 not declare anything. */
589 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
593 if (!TREE_SIDE_EFFECTS (body
))
597 *cond_p
= boolean_true_node
;
599 if_stmt
= begin_if_stmt ();
600 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, false, tf_warning_or_error
);
601 finish_if_stmt_cond (cond
, if_stmt
);
602 finish_break_stmt ();
603 finish_then_clause (if_stmt
);
604 finish_if_stmt (if_stmt
);
607 /* Finish a goto-statement. */
610 finish_goto_stmt (tree destination
)
612 if (identifier_p (destination
))
613 destination
= lookup_label (destination
);
615 /* We warn about unused labels with -Wunused. That means we have to
616 mark the used labels as used. */
617 if (TREE_CODE (destination
) == LABEL_DECL
)
618 TREE_USED (destination
) = 1;
621 if (check_no_cilk (destination
,
622 "Cilk array notation cannot be used as a computed goto expression",
623 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression"))
624 destination
= error_mark_node
;
625 destination
= mark_rvalue_use (destination
);
626 if (!processing_template_decl
)
628 destination
= cp_convert (ptr_type_node
, destination
,
629 tf_warning_or_error
);
630 if (error_operand_p (destination
))
633 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
637 destination
= do_dependent_capture (destination
);
640 check_goto (destination
);
642 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
643 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
646 /* COND is the condition-expression for an if, while, etc.,
647 statement. Convert it to a boolean value, if appropriate.
648 In addition, verify sequence points if -Wsequence-point is enabled. */
651 maybe_convert_cond (tree cond
)
653 /* Empty conditions remain empty. */
657 /* Wait until we instantiate templates before doing conversion. */
658 if (processing_template_decl
)
659 return do_dependent_capture (cond
);
661 if (warn_sequence_point
)
662 verify_sequence_points (cond
);
664 /* Do the conversion. */
665 cond
= convert_from_reference (cond
);
667 if (TREE_CODE (cond
) == MODIFY_EXPR
668 && !TREE_NO_WARNING (cond
)
671 warning_at (EXPR_LOC_OR_LOC (cond
, input_location
), OPT_Wparentheses
,
672 "suggest parentheses around assignment used as truth value");
673 TREE_NO_WARNING (cond
) = 1;
676 return condition_conversion (cond
);
679 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
682 finish_expr_stmt (tree expr
)
685 location_t loc
= EXPR_LOCATION (expr
);
687 if (expr
!= NULL_TREE
)
689 /* If we ran into a problem, make sure we complained. */
690 gcc_assert (expr
!= error_mark_node
|| seen_error ());
692 if (!processing_template_decl
)
694 if (warn_sequence_point
)
695 verify_sequence_points (expr
);
696 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
698 else if (!type_dependent_expression_p (expr
))
699 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
700 tf_warning_or_error
);
702 if (check_for_bare_parameter_packs (expr
))
703 expr
= error_mark_node
;
705 /* Simplification of inner statement expressions, compound exprs,
706 etc can result in us already having an EXPR_STMT. */
707 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
709 if (TREE_CODE (expr
) != EXPR_STMT
)
710 expr
= build_stmt (loc
, EXPR_STMT
, expr
);
711 expr
= maybe_cleanup_point_expr_void (expr
);
721 /* Begin an if-statement. Returns a newly created IF_STMT if
728 scope
= do_pushlevel (sk_cond
);
729 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
730 NULL_TREE
, NULL_TREE
, scope
);
731 current_binding_level
->this_entity
= r
;
732 begin_cond (&IF_COND (r
));
736 /* Process the COND of an if-statement, which may be given by
740 finish_if_stmt_cond (tree cond
, tree if_stmt
)
742 cond
= maybe_convert_cond (cond
);
743 if (IF_STMT_CONSTEXPR_P (if_stmt
)
744 && is_constant_expression (cond
)
745 && !value_dependent_expression_p (cond
))
747 cond
= instantiate_non_dependent_expr (cond
);
748 cond
= cxx_constant_value (cond
, NULL_TREE
);
750 finish_cond (&IF_COND (if_stmt
), cond
);
752 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
756 /* Finish the then-clause of an if-statement, which may be given by
760 finish_then_clause (tree if_stmt
)
762 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
766 /* Begin the else-clause of an if-statement. */
769 begin_else_clause (tree if_stmt
)
771 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
774 /* Finish the else-clause of an if-statement, which may be given by
778 finish_else_clause (tree if_stmt
)
780 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
783 /* Finish an if-statement. */
786 finish_if_stmt (tree if_stmt
)
788 tree scope
= IF_SCOPE (if_stmt
);
789 IF_SCOPE (if_stmt
) = NULL
;
790 add_stmt (do_poplevel (scope
));
793 /* Begin a while-statement. Returns a newly created WHILE_STMT if
797 begin_while_stmt (void)
800 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
802 WHILE_BODY (r
) = do_pushlevel (sk_block
);
803 begin_cond (&WHILE_COND (r
));
807 /* Process the COND of a while-statement, which may be given by
811 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
)
813 if (check_no_cilk (cond
,
814 "Cilk array notation cannot be used as a condition for while statement",
815 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
816 cond
= error_mark_node
;
817 cond
= maybe_convert_cond (cond
);
818 finish_cond (&WHILE_COND (while_stmt
), cond
);
819 begin_maybe_infinite_loop (cond
);
820 if (ivdep
&& cond
!= error_mark_node
)
821 WHILE_COND (while_stmt
) = build2 (ANNOTATE_EXPR
,
822 TREE_TYPE (WHILE_COND (while_stmt
)),
823 WHILE_COND (while_stmt
),
824 build_int_cst (integer_type_node
,
825 annot_expr_ivdep_kind
));
826 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
829 /* Finish a while-statement, which may be given by WHILE_STMT. */
832 finish_while_stmt (tree while_stmt
)
834 end_maybe_infinite_loop (boolean_true_node
);
835 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
838 /* Begin a do-statement. Returns a newly created DO_STMT if
844 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
845 begin_maybe_infinite_loop (boolean_true_node
);
847 DO_BODY (r
) = push_stmt_list ();
851 /* Finish the body of a do-statement, which may be given by DO_STMT. */
854 finish_do_body (tree do_stmt
)
856 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
858 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
859 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
861 if (IS_EMPTY_STMT (body
))
862 warning (OPT_Wempty_body
,
863 "suggest explicit braces around empty body in %<do%> statement");
866 /* Finish a do-statement, which may be given by DO_STMT, and whose
867 COND is as indicated. */
870 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
)
872 if (check_no_cilk (cond
,
873 "Cilk array notation cannot be used as a condition for a do-while statement",
874 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
875 cond
= error_mark_node
;
876 cond
= maybe_convert_cond (cond
);
877 end_maybe_infinite_loop (cond
);
878 if (ivdep
&& cond
!= error_mark_node
)
879 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
880 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
));
881 DO_COND (do_stmt
) = cond
;
884 /* Finish a return-statement. The EXPRESSION returned, if any, is as
888 finish_return_stmt (tree expr
)
893 expr
= check_return_expr (expr
, &no_warning
);
895 if (error_operand_p (expr
)
896 || (flag_openmp
&& !check_omp_return ()))
898 /* Suppress -Wreturn-type for this function. */
899 if (warn_return_type
)
900 TREE_NO_WARNING (current_function_decl
) = true;
901 return error_mark_node
;
904 if (!processing_template_decl
)
906 if (warn_sequence_point
)
907 verify_sequence_points (expr
);
909 if (DECL_DESTRUCTOR_P (current_function_decl
)
910 || (DECL_CONSTRUCTOR_P (current_function_decl
)
911 && targetm
.cxx
.cdtor_returns_this ()))
913 /* Similarly, all destructors must run destructors for
914 base-classes before returning. So, all returns in a
915 destructor get sent to the DTOR_LABEL; finish_function emits
916 code to return a value there. */
917 return finish_goto_stmt (cdtor_label
);
921 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
922 TREE_NO_WARNING (r
) |= no_warning
;
923 r
= maybe_cleanup_point_expr_void (r
);
929 /* Begin the scope of a for-statement or a range-for-statement.
930 Both the returned trees are to be used in a call to
931 begin_for_stmt or begin_range_for_stmt. */
934 begin_for_scope (tree
*init
)
936 tree scope
= NULL_TREE
;
937 if (flag_new_for_scope
> 0)
938 scope
= do_pushlevel (sk_for
);
940 if (processing_template_decl
)
941 *init
= push_stmt_list ();
948 /* Begin a for-statement. Returns a new FOR_STMT.
949 SCOPE and INIT should be the return of begin_for_scope,
953 begin_for_stmt (tree scope
, tree init
)
957 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
958 NULL_TREE
, NULL_TREE
, NULL_TREE
);
960 if (scope
== NULL_TREE
)
962 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
964 scope
= begin_for_scope (&init
);
966 FOR_INIT_STMT (r
) = init
;
967 FOR_SCOPE (r
) = scope
;
972 /* Finish the init-statement of a for-statement, which may be
973 given by FOR_STMT. */
976 finish_init_stmt (tree for_stmt
)
978 if (processing_template_decl
)
979 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
981 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
982 begin_cond (&FOR_COND (for_stmt
));
985 /* Finish the COND of a for-statement, which may be given by
989 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
)
991 if (check_no_cilk (cond
,
992 "Cilk array notation cannot be used in a condition for a for-loop",
993 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
994 cond
= error_mark_node
;
995 cond
= maybe_convert_cond (cond
);
996 finish_cond (&FOR_COND (for_stmt
), cond
);
997 begin_maybe_infinite_loop (cond
);
998 if (ivdep
&& cond
!= error_mark_node
)
999 FOR_COND (for_stmt
) = build2 (ANNOTATE_EXPR
,
1000 TREE_TYPE (FOR_COND (for_stmt
)),
1001 FOR_COND (for_stmt
),
1002 build_int_cst (integer_type_node
,
1003 annot_expr_ivdep_kind
));
1004 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
1007 /* Finish the increment-EXPRESSION in a for-statement, which may be
1008 given by FOR_STMT. */
1011 finish_for_expr (tree expr
, tree for_stmt
)
1015 /* If EXPR is an overloaded function, issue an error; there is no
1016 context available to use to perform overload resolution. */
1017 if (type_unknown_p (expr
))
1019 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1020 expr
= error_mark_node
;
1022 if (!processing_template_decl
)
1024 if (warn_sequence_point
)
1025 verify_sequence_points (expr
);
1026 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1027 tf_warning_or_error
);
1029 else if (!type_dependent_expression_p (expr
))
1030 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1031 tf_warning_or_error
);
1032 expr
= maybe_cleanup_point_expr_void (expr
);
1033 if (check_for_bare_parameter_packs (expr
))
1034 expr
= error_mark_node
;
1035 FOR_EXPR (for_stmt
) = expr
;
1038 /* Finish the body of a for-statement, which may be given by
1039 FOR_STMT. The increment-EXPR for the loop must be
1041 It can also finish RANGE_FOR_STMT. */
1044 finish_for_stmt (tree for_stmt
)
1046 end_maybe_infinite_loop (boolean_true_node
);
1048 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1049 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1051 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1053 /* Pop the scope for the body of the loop. */
1054 if (flag_new_for_scope
> 0)
1057 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1058 ? &RANGE_FOR_SCOPE (for_stmt
)
1059 : &FOR_SCOPE (for_stmt
));
1062 add_stmt (do_poplevel (scope
));
1066 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1067 SCOPE and INIT should be the return of begin_for_scope,
1069 To finish it call finish_for_stmt(). */
1072 begin_range_for_stmt (tree scope
, tree init
)
1076 begin_maybe_infinite_loop (boolean_false_node
);
1078 r
= build_stmt (input_location
, RANGE_FOR_STMT
,
1079 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1081 if (scope
== NULL_TREE
)
1083 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
1085 scope
= begin_for_scope (&init
);
1088 /* RANGE_FOR_STMTs do not use nor save the init tree, so we
1091 pop_stmt_list (init
);
1092 RANGE_FOR_SCOPE (r
) = scope
;
1097 /* Finish the head of a range-based for statement, which may
1098 be given by RANGE_FOR_STMT. DECL must be the declaration
1099 and EXPR must be the loop expression. */
1102 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1104 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1105 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1106 add_stmt (range_for_stmt
);
1107 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1110 /* Finish a break-statement. */
1113 finish_break_stmt (void)
1115 /* In switch statements break is sometimes stylistically used after
1116 a return statement. This can lead to spurious warnings about
1117 control reaching the end of a non-void function when it is
1118 inlined. Note that we are calling block_may_fallthru with
1119 language specific tree nodes; this works because
1120 block_may_fallthru returns true when given something it does not
1122 if (!block_may_fallthru (cur_stmt_list
))
1124 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1127 /* Finish a continue-statement. */
1130 finish_continue_stmt (void)
1132 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1135 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1139 begin_switch_stmt (void)
1143 scope
= do_pushlevel (sk_cond
);
1144 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1146 begin_cond (&SWITCH_STMT_COND (r
));
1151 /* Finish the cond of a switch-statement. */
1154 finish_switch_cond (tree cond
, tree switch_stmt
)
1156 tree orig_type
= NULL
;
1158 if (check_no_cilk (cond
,
1159 "Cilk array notation cannot be used as a condition for switch statement",
1160 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement"))
1161 cond
= error_mark_node
;
1163 if (!processing_template_decl
)
1165 /* Convert the condition to an integer or enumeration type. */
1166 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1167 if (cond
== NULL_TREE
)
1169 error ("switch quantity not an integer");
1170 cond
= error_mark_node
;
1172 /* We want unlowered type here to handle enum bit-fields. */
1173 orig_type
= unlowered_expr_type (cond
);
1174 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1175 orig_type
= TREE_TYPE (cond
);
1176 if (cond
!= error_mark_node
)
1180 Integral promotions are performed. */
1181 cond
= perform_integral_promotions (cond
);
1182 cond
= maybe_cleanup_point_expr (cond
);
1185 if (check_for_bare_parameter_packs (cond
))
1186 cond
= error_mark_node
;
1187 else if (!processing_template_decl
&& warn_sequence_point
)
1188 verify_sequence_points (cond
);
1190 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1191 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1192 add_stmt (switch_stmt
);
1193 push_switch (switch_stmt
);
1194 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1197 /* Finish the body of a switch-statement, which may be given by
1198 SWITCH_STMT. The COND to switch on is indicated. */
1201 finish_switch_stmt (tree switch_stmt
)
1205 SWITCH_STMT_BODY (switch_stmt
) =
1206 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1209 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1210 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1211 add_stmt (do_poplevel (scope
));
1214 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1218 begin_try_block (void)
1220 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1222 TRY_STMTS (r
) = push_stmt_list ();
1226 /* Likewise, for a function-try-block. The block returned in
1227 *COMPOUND_STMT is an artificial outer scope, containing the
1228 function-try-block. */
1231 begin_function_try_block (tree
*compound_stmt
)
1234 /* This outer scope does not exist in the C++ standard, but we need
1235 a place to put __FUNCTION__ and similar variables. */
1236 *compound_stmt
= begin_compound_stmt (0);
1237 r
= begin_try_block ();
1238 FN_TRY_BLOCK_P (r
) = 1;
1242 /* Finish a try-block, which may be given by TRY_BLOCK. */
1245 finish_try_block (tree try_block
)
1247 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1248 TRY_HANDLERS (try_block
) = push_stmt_list ();
1251 /* Finish the body of a cleanup try-block, which may be given by
1255 finish_cleanup_try_block (tree try_block
)
1257 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1260 /* Finish an implicitly generated try-block, with a cleanup is given
1264 finish_cleanup (tree cleanup
, tree try_block
)
1266 TRY_HANDLERS (try_block
) = cleanup
;
1267 CLEANUP_P (try_block
) = 1;
1270 /* Likewise, for a function-try-block. */
1273 finish_function_try_block (tree try_block
)
1275 finish_try_block (try_block
);
1276 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1277 the try block, but moving it inside. */
1278 in_function_try_handler
= 1;
1281 /* Finish a handler-sequence for a try-block, which may be given by
1285 finish_handler_sequence (tree try_block
)
1287 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1288 check_handlers (TRY_HANDLERS (try_block
));
1291 /* Finish the handler-seq for a function-try-block, given by
1292 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1293 begin_function_try_block. */
1296 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1298 in_function_try_handler
= 0;
1299 finish_handler_sequence (try_block
);
1300 finish_compound_stmt (compound_stmt
);
1303 /* Begin a handler. Returns a HANDLER if appropriate. */
1306 begin_handler (void)
1310 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1313 /* Create a binding level for the eh_info and the exception object
1315 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1320 /* Finish the handler-parameters for a handler, which may be given by
1321 HANDLER. DECL is the declaration for the catch parameter, or NULL
1322 if this is a `catch (...)' clause. */
1325 finish_handler_parms (tree decl
, tree handler
)
1327 tree type
= NULL_TREE
;
1328 if (processing_template_decl
)
1332 decl
= pushdecl (decl
);
1333 decl
= push_template_decl (decl
);
1334 HANDLER_PARMS (handler
) = decl
;
1335 type
= TREE_TYPE (decl
);
1340 type
= expand_start_catch_block (decl
);
1341 if (warn_catch_value
1342 && type
!= NULL_TREE
1343 && type
!= error_mark_node
1344 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
)
1346 tree orig_type
= TREE_TYPE (decl
);
1347 if (CLASS_TYPE_P (orig_type
))
1349 if (TYPE_POLYMORPHIC_P (orig_type
))
1350 warning (OPT_Wcatch_value_
,
1351 "catching polymorphic type %q#T by value", orig_type
);
1352 else if (warn_catch_value
> 1)
1353 warning (OPT_Wcatch_value_
,
1354 "catching type %q#T by value", orig_type
);
1356 else if (warn_catch_value
> 2)
1357 warning (OPT_Wcatch_value_
,
1358 "catching non-reference type %q#T", orig_type
);
1361 HANDLER_TYPE (handler
) = type
;
1364 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1365 the return value from the matching call to finish_handler_parms. */
1368 finish_handler (tree handler
)
1370 if (!processing_template_decl
)
1371 expand_end_catch_block ();
1372 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1375 /* Begin a compound statement. FLAGS contains some bits that control the
1376 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1377 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1378 block of a function. If BCS_TRY_BLOCK is set, this is the block
1379 created on behalf of a TRY statement. Returns a token to be passed to
1380 finish_compound_stmt. */
1383 begin_compound_stmt (unsigned int flags
)
1387 if (flags
& BCS_NO_SCOPE
)
1389 r
= push_stmt_list ();
1390 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1392 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1393 But, if it's a statement-expression with a scopeless block, there's
1394 nothing to keep, and we don't want to accidentally keep a block
1395 *inside* the scopeless block. */
1396 keep_next_level (false);
1400 scope_kind sk
= sk_block
;
1401 if (flags
& BCS_TRY_BLOCK
)
1403 else if (flags
& BCS_TRANSACTION
)
1404 sk
= sk_transaction
;
1405 r
= do_pushlevel (sk
);
1408 /* When processing a template, we need to remember where the braces were,
1409 so that we can set up identical scopes when instantiating the template
1410 later. BIND_EXPR is a handy candidate for this.
1411 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1412 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1413 processing templates. */
1414 if (processing_template_decl
)
1416 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1417 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1418 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1419 TREE_SIDE_EFFECTS (r
) = 1;
1425 /* Finish a compound-statement, which is given by STMT. */
1428 finish_compound_stmt (tree stmt
)
1430 if (TREE_CODE (stmt
) == BIND_EXPR
)
1432 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1433 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1434 discard the BIND_EXPR so it can be merged with the containing
1436 if (TREE_CODE (body
) == STATEMENT_LIST
1437 && STATEMENT_LIST_HEAD (body
) == NULL
1438 && !BIND_EXPR_BODY_BLOCK (stmt
)
1439 && !BIND_EXPR_TRY_BLOCK (stmt
))
1442 BIND_EXPR_BODY (stmt
) = body
;
1444 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1445 stmt
= pop_stmt_list (stmt
);
1448 /* Destroy any ObjC "super" receivers that may have been
1450 objc_clear_super_receiver ();
1452 stmt
= do_poplevel (stmt
);
1455 /* ??? See c_end_compound_stmt wrt statement expressions. */
1459 /* Finish an asm-statement, whose components are a STRING, some
1460 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1461 LABELS. Also note whether the asm-statement should be
1462 considered volatile. */
1465 finish_asm_stmt (int volatile_p
, tree string
, tree output_operands
,
1466 tree input_operands
, tree clobbers
, tree labels
)
1470 int ninputs
= list_length (input_operands
);
1471 int noutputs
= list_length (output_operands
);
1473 if (!processing_template_decl
)
1475 const char *constraint
;
1476 const char **oconstraints
;
1477 bool allows_mem
, allows_reg
, is_inout
;
1481 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1483 string
= resolve_asm_operand_names (string
, output_operands
,
1484 input_operands
, labels
);
1486 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1488 operand
= TREE_VALUE (t
);
1490 /* ??? Really, this should not be here. Users should be using a
1491 proper lvalue, dammit. But there's a long history of using
1492 casts in the output operands. In cases like longlong.h, this
1493 becomes a primitive form of typechecking -- if the cast can be
1494 removed, then the output operand had a type of the proper width;
1495 otherwise we'll get an error. Gross, but ... */
1496 STRIP_NOPS (operand
);
1498 operand
= mark_lvalue_use (operand
);
1500 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1501 operand
= error_mark_node
;
1503 if (operand
!= error_mark_node
1504 && (TREE_READONLY (operand
)
1505 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1506 /* Functions are not modifiable, even though they are
1508 || TREE_CODE (TREE_TYPE (operand
)) == FUNCTION_TYPE
1509 || TREE_CODE (TREE_TYPE (operand
)) == METHOD_TYPE
1510 /* If it's an aggregate and any field is const, then it is
1511 effectively const. */
1512 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1513 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1514 cxx_readonly_error (operand
, lv_asm
);
1516 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1517 oconstraints
[i
] = constraint
;
1519 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1520 &allows_mem
, &allows_reg
, &is_inout
))
1522 /* If the operand is going to end up in memory,
1523 mark it addressable. */
1524 if (!allows_reg
&& !cxx_mark_addressable (operand
))
1525 operand
= error_mark_node
;
1528 operand
= error_mark_node
;
1530 TREE_VALUE (t
) = operand
;
1533 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1535 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1536 bool constraint_parsed
1537 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1538 oconstraints
, &allows_mem
, &allows_reg
);
1539 /* If the operand is going to end up in memory, don't call
1540 decay_conversion. */
1541 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1542 operand
= mark_lvalue_use (TREE_VALUE (t
));
1544 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1546 /* If the type of the operand hasn't been determined (e.g.,
1547 because it involves an overloaded function), then issue
1548 an error message. There's no context available to
1549 resolve the overloading. */
1550 if (TREE_TYPE (operand
) == unknown_type_node
)
1552 error ("type of asm operand %qE could not be determined",
1554 operand
= error_mark_node
;
1557 if (constraint_parsed
)
1559 /* If the operand is going to end up in memory,
1560 mark it addressable. */
1561 if (!allows_reg
&& allows_mem
)
1563 /* Strip the nops as we allow this case. FIXME, this really
1564 should be rejected or made deprecated. */
1565 STRIP_NOPS (operand
);
1566 if (!cxx_mark_addressable (operand
))
1567 operand
= error_mark_node
;
1569 else if (!allows_reg
&& !allows_mem
)
1571 /* If constraint allows neither register nor memory,
1572 try harder to get a constant. */
1573 tree constop
= maybe_constant_value (operand
);
1574 if (TREE_CONSTANT (constop
))
1579 operand
= error_mark_node
;
1581 TREE_VALUE (t
) = operand
;
1585 r
= build_stmt (input_location
, ASM_EXPR
, string
,
1586 output_operands
, input_operands
,
1588 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1589 r
= maybe_cleanup_point_expr_void (r
);
1590 return add_stmt (r
);
1593 /* Finish a label with the indicated NAME. Returns the new label. */
1596 finish_label_stmt (tree name
)
1598 tree decl
= define_label (input_location
, name
);
1600 if (decl
== error_mark_node
)
1601 return error_mark_node
;
1603 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1608 /* Finish a series of declarations for local labels. G++ allows users
1609 to declare "local" labels, i.e., labels with scope. This extension
1610 is useful when writing code involving statement-expressions. */
1613 finish_label_decl (tree name
)
1615 if (!at_function_scope_p ())
1617 error ("__label__ declarations are only allowed in function scopes");
1621 add_decl_expr (declare_local_label (name
));
1624 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1627 finish_decl_cleanup (tree decl
, tree cleanup
)
1629 push_cleanup (decl
, cleanup
, false);
1632 /* If the current scope exits with an exception, run CLEANUP. */
1635 finish_eh_cleanup (tree cleanup
)
1637 push_cleanup (NULL
, cleanup
, true);
1640 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1641 order they were written by the user. Each node is as for
1642 emit_mem_initializers. */
1645 finish_mem_initializers (tree mem_inits
)
1647 /* Reorder the MEM_INITS so that they are in the order they appeared
1648 in the source program. */
1649 mem_inits
= nreverse (mem_inits
);
1651 if (processing_template_decl
)
1655 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1657 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1658 check for bare parameter packs in the TREE_VALUE, because
1659 any parameter packs in the TREE_VALUE have already been
1660 bound as part of the TREE_PURPOSE. See
1661 make_pack_expansion for more information. */
1662 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1663 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1664 TREE_VALUE (mem
) = error_mark_node
;
1667 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1668 CTOR_INITIALIZER
, mem_inits
));
1671 emit_mem_initializers (mem_inits
);
1674 /* Obfuscate EXPR if it looks like an id-expression or member access so
1675 that the call to finish_decltype in do_auto_deduction will give the
1679 force_paren_expr (tree expr
)
1681 /* This is only needed for decltype(auto) in C++14. */
1682 if (cxx_dialect
< cxx14
)
1685 /* If we're in unevaluated context, we can't be deducing a
1686 return/initializer type, so we don't need to mess with this. */
1687 if (cp_unevaluated_operand
)
1690 if (!DECL_P (expr
) && TREE_CODE (expr
) != COMPONENT_REF
1691 && TREE_CODE (expr
) != SCOPE_REF
)
1694 if (TREE_CODE (expr
) == COMPONENT_REF
1695 || TREE_CODE (expr
) == SCOPE_REF
)
1696 REF_PARENTHESIZED_P (expr
) = true;
1697 else if (type_dependent_expression_p (expr
))
1698 expr
= build1 (PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1699 else if (VAR_P (expr
) && DECL_HARD_REGISTER (expr
))
1700 /* We can't bind a hard register variable to a reference. */;
1703 cp_lvalue_kind kind
= lvalue_kind (expr
);
1704 if ((kind
& ~clk_class
) != clk_none
)
1706 tree type
= unlowered_expr_type (expr
);
1707 bool rval
= !!(kind
& clk_rvalueref
);
1708 type
= cp_build_reference_type (type
, rval
);
1709 /* This inhibits warnings in, eg, cxx_mark_addressable
1711 warning_sentinel
s (extra_warnings
);
1712 expr
= build_static_cast (type
, expr
, tf_error
);
1713 if (expr
!= error_mark_node
)
1714 REF_PARENTHESIZED_P (expr
) = true;
1721 /* If T is an id-expression obfuscated by force_paren_expr, undo the
1722 obfuscation and return the underlying id-expression. Otherwise
1726 maybe_undo_parenthesized_ref (tree t
)
1728 if (cxx_dialect
>= cxx14
1729 && INDIRECT_REF_P (t
)
1730 && REF_PARENTHESIZED_P (t
))
1732 t
= TREE_OPERAND (t
, 0);
1733 while (TREE_CODE (t
) == NON_LVALUE_EXPR
1734 || TREE_CODE (t
) == NOP_EXPR
)
1735 t
= TREE_OPERAND (t
, 0);
1737 gcc_assert (TREE_CODE (t
) == ADDR_EXPR
1738 || TREE_CODE (t
) == STATIC_CAST_EXPR
);
1739 t
= TREE_OPERAND (t
, 0);
1745 /* Finish a parenthesized expression EXPR. */
1748 finish_parenthesized_expr (cp_expr expr
)
1751 /* This inhibits warnings in c_common_truthvalue_conversion. */
1752 TREE_NO_WARNING (expr
) = 1;
1754 if (TREE_CODE (expr
) == OFFSET_REF
1755 || TREE_CODE (expr
) == SCOPE_REF
)
1756 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1757 enclosed in parentheses. */
1758 PTRMEM_OK_P (expr
) = 0;
1760 if (TREE_CODE (expr
) == STRING_CST
)
1761 PAREN_STRING_LITERAL_P (expr
) = 1;
1763 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
1768 /* Finish a reference to a non-static data member (DECL) that is not
1769 preceded by `.' or `->'. */
1772 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1774 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1775 bool try_omp_private
= !object
&& omp_private_member_map
;
1780 tree scope
= qualifying_scope
;
1781 if (scope
== NULL_TREE
)
1782 scope
= context_for_name_lookup (decl
);
1783 object
= maybe_dummy_object (scope
, NULL
);
1786 object
= maybe_resolve_dummy (object
, true);
1787 if (object
== error_mark_node
)
1788 return error_mark_node
;
1790 /* DR 613/850: Can use non-static data members without an associated
1791 object in sizeof/decltype/alignof. */
1792 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
1793 && (!processing_template_decl
|| !current_class_ref
))
1795 if (current_function_decl
1796 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1797 error ("invalid use of member %qD in static member function", decl
);
1799 error ("invalid use of non-static data member %qD", decl
);
1800 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
1802 return error_mark_node
;
1805 if (current_class_ptr
)
1806 TREE_USED (current_class_ptr
) = 1;
1807 if (processing_template_decl
&& !qualifying_scope
)
1809 tree type
= TREE_TYPE (decl
);
1811 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1812 /* Quals on the object don't matter. */;
1813 else if (PACK_EXPANSION_P (type
))
1814 /* Don't bother trying to represent this. */
1818 /* Set the cv qualifiers. */
1819 int quals
= cp_type_quals (TREE_TYPE (object
));
1821 if (DECL_MUTABLE_P (decl
))
1822 quals
&= ~TYPE_QUAL_CONST
;
1824 quals
|= cp_type_quals (TREE_TYPE (decl
));
1825 type
= cp_build_qualified_type (type
, quals
);
1828 ret
= (convert_from_reference
1829 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
1831 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1832 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1834 else if (processing_template_decl
)
1835 ret
= build_qualified_name (TREE_TYPE (decl
),
1838 /*template_p=*/false);
1841 tree access_type
= TREE_TYPE (object
);
1843 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
1844 decl
, tf_warning_or_error
);
1846 /* If the data member was named `C::M', convert `*this' to `C'
1848 if (qualifying_scope
)
1850 tree binfo
= NULL_TREE
;
1851 object
= build_scoped_ref (object
, qualifying_scope
,
1855 ret
= build_class_member_access_expr (object
, decl
,
1856 /*access_path=*/NULL_TREE
,
1857 /*preserve_reference=*/false,
1858 tf_warning_or_error
);
1860 if (try_omp_private
)
1862 tree
*v
= omp_private_member_map
->get (decl
);
1864 ret
= convert_from_reference (*v
);
1869 /* If we are currently parsing a template and we encountered a typedef
1870 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1871 adds the typedef to a list tied to the current template.
1872 At template instantiation time, that list is walked and access check
1873 performed for each typedef.
1874 LOCATION is the location of the usage point of TYPEDEF_DECL. */
1877 add_typedef_to_current_template_for_access_check (tree typedef_decl
,
1879 location_t location
)
1881 tree template_info
= NULL
;
1882 tree cs
= current_scope ();
1884 if (!is_typedef_decl (typedef_decl
)
1886 || !CLASS_TYPE_P (context
)
1890 if (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
)
1891 template_info
= get_template_info (cs
);
1894 && TI_TEMPLATE (template_info
)
1895 && !currently_open_class (context
))
1896 append_type_to_template_for_access_check (cs
, typedef_decl
,
1900 /* DECL was the declaration to which a qualified-id resolved. Issue
1901 an error message if it is not accessible. If OBJECT_TYPE is
1902 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1903 type of `*x', or `x', respectively. If the DECL was named as
1904 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1907 check_accessibility_of_qualified_id (tree decl
,
1909 tree nested_name_specifier
)
1912 tree qualifying_type
= NULL_TREE
;
1914 /* If we are parsing a template declaration and if decl is a typedef,
1915 add it to a list tied to the template.
1916 At template instantiation time, that list will be walked and
1917 access check performed. */
1918 add_typedef_to_current_template_for_access_check (decl
,
1919 nested_name_specifier
1920 ? nested_name_specifier
1921 : DECL_CONTEXT (decl
),
1924 /* If we're not checking, return immediately. */
1925 if (deferred_access_no_check
)
1928 /* Determine the SCOPE of DECL. */
1929 scope
= context_for_name_lookup (decl
);
1930 /* If the SCOPE is not a type, then DECL is not a member. */
1931 if (!TYPE_P (scope
))
1933 /* Compute the scope through which DECL is being accessed. */
1935 /* OBJECT_TYPE might not be a class type; consider:
1937 class A { typedef int I; };
1941 In this case, we will have "A::I" as the DECL, but "I" as the
1943 && CLASS_TYPE_P (object_type
)
1944 && DERIVED_FROM_P (scope
, object_type
))
1945 /* If we are processing a `->' or `.' expression, use the type of the
1947 qualifying_type
= object_type
;
1948 else if (nested_name_specifier
)
1950 /* If the reference is to a non-static member of the
1951 current class, treat it as if it were referenced through
1954 if (DECL_NONSTATIC_MEMBER_P (decl
)
1955 && current_class_ptr
1956 && DERIVED_FROM_P (scope
, ct
= current_nonlambda_class_type ()))
1957 qualifying_type
= ct
;
1958 /* Otherwise, use the type indicated by the
1959 nested-name-specifier. */
1961 qualifying_type
= nested_name_specifier
;
1964 /* Otherwise, the name must be from the current class or one of
1966 qualifying_type
= currently_open_derived_class (scope
);
1969 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
1970 or similar in a default argument value. */
1971 && CLASS_TYPE_P (qualifying_type
)
1972 && !dependent_type_p (qualifying_type
))
1973 perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
1974 decl
, tf_warning_or_error
);
1977 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
1978 class named to the left of the "::" operator. DONE is true if this
1979 expression is a complete postfix-expression; it is false if this
1980 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
1981 iff this expression is the operand of '&'. TEMPLATE_P is true iff
1982 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
1983 is true iff this qualified name appears as a template argument. */
1986 finish_qualified_id_expr (tree qualifying_class
,
1991 bool template_arg_p
,
1992 tsubst_flags_t complain
)
1994 gcc_assert (TYPE_P (qualifying_class
));
1996 if (error_operand_p (expr
))
1997 return error_mark_node
;
1999 if ((DECL_P (expr
) || BASELINK_P (expr
))
2000 && !mark_used (expr
, complain
))
2001 return error_mark_node
;
2005 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
2006 /* cp_parser_lookup_name thought we were looking for a type,
2007 but we're actually looking for a declaration. */
2008 expr
= build_qualified_name (/*type*/NULL_TREE
,
2009 TYPE_CONTEXT (expr
),
2010 TYPE_IDENTIFIER (expr
),
2011 /*template_p*/true);
2013 check_template_keyword (expr
);
2016 /* If EXPR occurs as the operand of '&', use special handling that
2017 permits a pointer-to-member. */
2018 if (address_p
&& done
)
2020 if (TREE_CODE (expr
) == SCOPE_REF
)
2021 expr
= TREE_OPERAND (expr
, 1);
2022 expr
= build_offset_ref (qualifying_class
, expr
,
2023 /*address_p=*/true, complain
);
2027 /* No need to check access within an enum. */
2028 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
)
2031 /* Within the scope of a class, turn references to non-static
2032 members into expression of the form "this->...". */
2034 /* But, within a template argument, we do not want make the
2035 transformation, as there is no "this" pointer. */
2037 else if (TREE_CODE (expr
) == FIELD_DECL
)
2039 push_deferring_access_checks (dk_no_check
);
2040 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2042 pop_deferring_access_checks ();
2044 else if (BASELINK_P (expr
))
2046 /* See if any of the functions are non-static members. */
2047 /* If so, the expression may be relative to 'this'. */
2048 if (!shared_member_p (expr
)
2049 && current_class_ptr
2050 && DERIVED_FROM_P (qualifying_class
,
2051 current_nonlambda_class_type ()))
2052 expr
= (build_class_member_access_expr
2053 (maybe_dummy_object (qualifying_class
, NULL
),
2055 BASELINK_ACCESS_BINFO (expr
),
2056 /*preserve_reference=*/false,
2059 /* The expression is a qualified name whose address is not
2061 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2066 /* In a template, return a SCOPE_REF for most qualified-ids
2067 so that we can check access at instantiation time. But if
2068 we're looking at a member of the current instantiation, we
2069 know we have access and building up the SCOPE_REF confuses
2070 non-type template argument handling. */
2071 if (processing_template_decl
2072 && (!currently_open_class (qualifying_class
)
2073 || TREE_CODE (expr
) == BIT_NOT_EXPR
))
2074 expr
= build_qualified_name (TREE_TYPE (expr
),
2075 qualifying_class
, expr
,
2078 expr
= convert_from_reference (expr
);
2084 /* Begin a statement-expression. The value returned must be passed to
2085 finish_stmt_expr. */
2088 begin_stmt_expr (void)
2090 return push_stmt_list ();
2093 /* Process the final expression of a statement expression. EXPR can be
2094 NULL, if the final expression is empty. Return a STATEMENT_LIST
2095 containing all the statements in the statement-expression, or
2096 ERROR_MARK_NODE if there was an error. */
2099 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2101 if (error_operand_p (expr
))
2103 /* The type of the statement-expression is the type of the last
2105 TREE_TYPE (stmt_expr
) = error_mark_node
;
2106 return error_mark_node
;
2109 /* If the last statement does not have "void" type, then the value
2110 of the last statement is the value of the entire expression. */
2113 tree type
= TREE_TYPE (expr
);
2115 if (processing_template_decl
)
2117 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2118 expr
= add_stmt (expr
);
2119 /* Mark the last statement so that we can recognize it as such at
2120 template-instantiation time. */
2121 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2123 else if (VOID_TYPE_P (type
))
2125 /* Just treat this like an ordinary statement. */
2126 expr
= finish_expr_stmt (expr
);
2130 /* It actually has a value we need to deal with. First, force it
2131 to be an rvalue so that we won't need to build up a copy
2132 constructor call later when we try to assign it to something. */
2133 expr
= force_rvalue (expr
, tf_warning_or_error
);
2134 if (error_operand_p (expr
))
2135 return error_mark_node
;
2137 /* Update for array-to-pointer decay. */
2138 type
= TREE_TYPE (expr
);
2140 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2141 normal statement, but don't convert to void or actually add
2143 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2144 expr
= maybe_cleanup_point_expr (expr
);
2148 /* The type of the statement-expression is the type of the last
2150 TREE_TYPE (stmt_expr
) = type
;
2156 /* Finish a statement-expression. EXPR should be the value returned
2157 by the previous begin_stmt_expr. Returns an expression
2158 representing the statement-expression. */
2161 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2166 if (error_operand_p (stmt_expr
))
2168 pop_stmt_list (stmt_expr
);
2169 return error_mark_node
;
2172 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2174 type
= TREE_TYPE (stmt_expr
);
2175 result
= pop_stmt_list (stmt_expr
);
2176 TREE_TYPE (result
) = type
;
2178 if (processing_template_decl
)
2180 result
= build_min (STMT_EXPR
, type
, result
);
2181 TREE_SIDE_EFFECTS (result
) = 1;
2182 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2184 else if (CLASS_TYPE_P (type
))
2186 /* Wrap the statement-expression in a TARGET_EXPR so that the
2187 temporary object created by the final expression is destroyed at
2188 the end of the full-expression containing the
2189 statement-expression. */
2190 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2196 /* Returns the expression which provides the value of STMT_EXPR. */
2199 stmt_expr_value_expr (tree stmt_expr
)
2201 tree t
= STMT_EXPR_STMT (stmt_expr
);
2203 if (TREE_CODE (t
) == BIND_EXPR
)
2204 t
= BIND_EXPR_BODY (t
);
2206 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2207 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2209 if (TREE_CODE (t
) == EXPR_STMT
)
2210 t
= EXPR_STMT_EXPR (t
);
2215 /* Return TRUE iff EXPR_STMT is an empty list of
2216 expression statements. */
2219 empty_expr_stmt_p (tree expr_stmt
)
2221 tree body
= NULL_TREE
;
2223 if (expr_stmt
== void_node
)
2228 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2229 body
= EXPR_STMT_EXPR (expr_stmt
);
2230 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2236 if (TREE_CODE (body
) == STATEMENT_LIST
)
2237 return tsi_end_p (tsi_start (body
));
2239 return empty_expr_stmt_p (body
);
2244 /* Perform Koenig lookup. FN is the postfix-expression representing
2245 the function (or functions) to call; ARGS are the arguments to the
2246 call. Returns the functions to be considered by overload resolution. */
2249 perform_koenig_lookup (cp_expr fn
, vec
<tree
, va_gc
> *args
,
2250 tsubst_flags_t complain
)
2252 tree identifier
= NULL_TREE
;
2253 tree functions
= NULL_TREE
;
2254 tree tmpl_args
= NULL_TREE
;
2255 bool template_id
= false;
2256 location_t loc
= fn
.get_location ();
2258 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2260 /* Use a separate flag to handle null args. */
2262 tmpl_args
= TREE_OPERAND (fn
, 1);
2263 fn
= TREE_OPERAND (fn
, 0);
2266 /* Find the name of the overloaded function. */
2267 if (identifier_p (fn
))
2272 identifier
= OVL_NAME (functions
);
2275 /* A call to a namespace-scope function using an unqualified name.
2277 Do Koenig lookup -- unless any of the arguments are
2279 if (!any_type_dependent_arguments_p (args
)
2280 && !any_dependent_template_arguments_p (tmpl_args
))
2282 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2285 /* The unqualified name could not be resolved. */
2286 if (complain
& tf_error
)
2287 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2293 if (fn
&& template_id
&& fn
!= error_mark_node
)
2294 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2299 /* Generate an expression for `FN (ARGS)'. This may change the
2302 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2303 as a virtual call, even if FN is virtual. (This flag is set when
2304 encountering an expression where the function name is explicitly
2305 qualified. For example a call to `X::f' never generates a virtual
2308 Returns code for the call. */
2311 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2312 bool koenig_p
, tsubst_flags_t complain
)
2316 vec
<tree
, va_gc
> *orig_args
= NULL
;
2318 if (fn
== error_mark_node
)
2319 return error_mark_node
;
2321 gcc_assert (!TYPE_P (fn
));
2323 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2324 it so that we can tell this is a call to a known function. */
2325 fn
= maybe_undo_parenthesized_ref (fn
);
2329 if (processing_template_decl
)
2331 /* If FN is a local extern declaration or set thereof, look them up
2332 again at instantiation time. */
2333 if (is_overloaded_fn (fn
))
2335 tree ifn
= get_first_fn (fn
);
2336 if (TREE_CODE (ifn
) == FUNCTION_DECL
2337 && DECL_LOCAL_FUNCTION_P (ifn
))
2338 orig_fn
= DECL_NAME (ifn
);
2341 /* If the call expression is dependent, build a CALL_EXPR node
2342 with no type; type_dependent_expression_p recognizes
2343 expressions with no type as being dependent. */
2344 if (type_dependent_expression_p (fn
)
2345 || any_type_dependent_arguments_p (*args
))
2347 result
= build_min_nt_call_vec (orig_fn
, *args
);
2348 SET_EXPR_LOCATION (result
, EXPR_LOC_OR_LOC (fn
, input_location
));
2349 KOENIG_LOOKUP_P (result
) = koenig_p
;
2350 if (is_overloaded_fn (fn
))
2353 lookup_keep (fn
, true);
2358 bool abnormal
= true;
2359 for (lkp_iterator
iter (fn
); abnormal
&& iter
; ++iter
)
2361 tree fndecl
= *iter
;
2362 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2363 || !TREE_THIS_VOLATILE (fndecl
))
2366 /* FIXME: Stop warning about falling off end of non-void
2367 function. But this is wrong. Even if we only see
2368 no-return fns at this point, we could select a
2369 future-defined return fn during instantiation. Or
2372 current_function_returns_abnormally
= 1;
2376 orig_args
= make_tree_vector_copy (*args
);
2377 if (!BASELINK_P (fn
)
2378 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2379 && TREE_TYPE (fn
) != unknown_type_node
)
2380 fn
= build_non_dependent_expr (fn
);
2381 make_args_non_dependent (*args
);
2384 if (TREE_CODE (fn
) == COMPONENT_REF
)
2386 tree member
= TREE_OPERAND (fn
, 1);
2387 if (BASELINK_P (member
))
2389 tree object
= TREE_OPERAND (fn
, 0);
2390 return build_new_method_call (object
, member
,
2393 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2400 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2401 if (TREE_CODE (fn
) == ADDR_EXPR
2402 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2403 fn
= TREE_OPERAND (fn
, 0);
2405 if (is_overloaded_fn (fn
))
2406 fn
= baselink_for_fns (fn
);
2409 if (BASELINK_P (fn
))
2413 /* A call to a member function. From [over.call.func]:
2415 If the keyword this is in scope and refers to the class of
2416 that member function, or a derived class thereof, then the
2417 function call is transformed into a qualified function call
2418 using (*this) as the postfix-expression to the left of the
2419 . operator.... [Otherwise] a contrived object of type T
2420 becomes the implied object argument.
2424 struct A { void f(); };
2425 struct B : public A {};
2426 struct C : public A { void g() { B::f(); }};
2428 "the class of that member function" refers to `A'. But 11.2
2429 [class.access.base] says that we need to convert 'this' to B* as
2430 part of the access, so we pass 'B' to maybe_dummy_object. */
2432 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2434 /* A constructor call always uses a dummy object. (This constructor
2435 call which has the form A::A () is actually invalid and we are
2436 going to reject it later in build_new_method_call.) */
2437 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2440 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2443 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2445 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2450 else if (is_overloaded_fn (fn
))
2452 /* If the function is an overloaded builtin, resolve it. */
2453 if (TREE_CODE (fn
) == FUNCTION_DECL
2454 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2455 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2456 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2460 if (warn_sizeof_pointer_memaccess
2461 && (complain
& tf_warning
)
2462 && !vec_safe_is_empty (*args
)
2463 && !processing_template_decl
)
2465 location_t sizeof_arg_loc
[3];
2468 for (i
= 0; i
< 3; i
++)
2472 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2473 sizeof_arg
[i
] = NULL_TREE
;
2474 if (i
>= (*args
)->length ())
2477 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2479 if (SIZEOF_EXPR_TYPE_P (t
))
2480 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2482 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2483 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2485 sizeof_pointer_memaccess_warning
2486 (sizeof_arg_loc
, fn
, *args
,
2487 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2490 /* A call to a namespace-scope function. */
2491 result
= build_new_function_call (fn
, args
, complain
);
2494 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2496 if (!vec_safe_is_empty (*args
))
2497 error ("arguments to destructor are not allowed");
2498 /* Mark the pseudo-destructor call as having side-effects so
2499 that we do not issue warnings about its use. */
2500 result
= build1 (NOP_EXPR
,
2502 TREE_OPERAND (fn
, 0));
2503 TREE_SIDE_EFFECTS (result
) = 1;
2505 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2506 /* If the "function" is really an object of class type, it might
2507 have an overloaded `operator ()'. */
2508 result
= build_op_call (fn
, args
, complain
);
2511 /* A call where the function is unknown. */
2512 result
= cp_build_function_call_vec (fn
, args
, complain
);
2514 if (processing_template_decl
&& result
!= error_mark_node
)
2516 if (INDIRECT_REF_P (result
))
2517 result
= TREE_OPERAND (result
, 0);
2518 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2519 SET_EXPR_LOCATION (result
, input_location
);
2520 KOENIG_LOOKUP_P (result
) = koenig_p
;
2521 release_tree_vector (orig_args
);
2522 result
= convert_from_reference (result
);
2525 /* Free or retain OVERLOADs from lookup. */
2526 if (is_overloaded_fn (orig_fn
))
2527 lookup_keep (get_fns (orig_fn
), processing_template_decl
);
2532 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2533 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2534 POSTDECREMENT_EXPR.) */
2537 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2539 /* input_location holds the location of the trailing operator token.
2540 Build a location of the form:
2543 with the caret at the operator token, ranging from the start
2544 of EXPR to the end of the operator token. */
2545 location_t combined_loc
= make_location (input_location
,
2547 get_finish (input_location
));
2548 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2549 tf_warning_or_error
);
2550 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2551 result
.set_location (combined_loc
);
2555 /* Finish a use of `this'. Returns an expression for `this'. */
2558 finish_this_expr (void)
2560 tree result
= NULL_TREE
;
2562 if (current_class_ptr
)
2564 tree type
= TREE_TYPE (current_class_ref
);
2566 /* In a lambda expression, 'this' refers to the captured 'this'. */
2567 if (LAMBDA_TYPE_P (type
))
2568 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2570 result
= current_class_ptr
;
2574 /* The keyword 'this' is a prvalue expression. */
2575 return rvalue (result
);
2577 tree fn
= current_nonlambda_function ();
2578 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2579 error ("%<this%> is unavailable for static member functions");
2581 error ("invalid use of %<this%> in non-member function");
2583 error ("invalid use of %<this%> at top level");
2584 return error_mark_node
;
2587 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2588 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2589 the TYPE for the type given. If SCOPE is non-NULL, the expression
2590 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2593 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2596 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2597 return error_mark_node
;
2599 gcc_assert (TYPE_P (destructor
));
2601 if (!processing_template_decl
)
2603 if (scope
== error_mark_node
)
2605 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2606 return error_mark_node
;
2608 if (is_auto (destructor
))
2609 destructor
= TREE_TYPE (object
);
2610 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2613 "qualified type %qT does not match destructor name ~%qT",
2615 return error_mark_node
;
2619 /* [expr.pseudo] says both:
2621 The type designated by the pseudo-destructor-name shall be
2622 the same as the object type.
2626 The cv-unqualified versions of the object type and of the
2627 type designated by the pseudo-destructor-name shall be the
2630 We implement the more generous second sentence, since that is
2631 what most other compilers do. */
2632 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2635 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2636 return error_mark_node
;
2640 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, void_type_node
, object
,
2644 /* Finish an expression of the form CODE EXPR. */
2647 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
2648 tsubst_flags_t complain
)
2650 /* Build a location of the form:
2653 with the caret at the operator token, ranging from the start
2654 of the operator token to the end of EXPR. */
2655 location_t combined_loc
= make_location (op_loc
,
2656 op_loc
, expr
.get_finish ());
2657 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
, complain
);
2658 /* TODO: build_x_unary_op doesn't always honor the location. */
2659 result
.set_location (combined_loc
);
2661 tree result_ovl
, expr_ovl
;
2663 if (!(complain
& tf_warning
))
2666 result_ovl
= result
;
2669 if (!processing_template_decl
)
2670 expr_ovl
= cp_fully_fold (expr_ovl
);
2672 if (!CONSTANT_CLASS_P (expr_ovl
)
2673 || TREE_OVERFLOW_P (expr_ovl
))
2676 if (!processing_template_decl
)
2677 result_ovl
= cp_fully_fold (result_ovl
);
2679 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
2680 overflow_warning (combined_loc
, result_ovl
);
2685 /* Finish a compound-literal expression or C++11 functional cast with aggregate
2686 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
2690 finish_compound_literal (tree type
, tree compound_literal
,
2691 tsubst_flags_t complain
,
2694 if (type
== error_mark_node
)
2695 return error_mark_node
;
2697 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2700 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2701 complain
, fcl_context
);
2702 return cp_build_c_cast (type
, compound_literal
, complain
);
2705 if (!TYPE_OBJ_P (type
))
2707 if (complain
& tf_error
)
2708 error ("compound literal of non-object type %qT", type
);
2709 return error_mark_node
;
2712 if (tree anode
= type_uses_auto (type
))
2713 if (CLASS_PLACEHOLDER_TEMPLATE (anode
))
2715 type
= do_auto_deduction (type
, compound_literal
, anode
, complain
,
2717 if (type
== error_mark_node
)
2718 return error_mark_node
;
2721 if (processing_template_decl
)
2723 TREE_TYPE (compound_literal
) = type
;
2724 /* Mark the expression as a compound literal. */
2725 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
2726 if (fcl_context
== fcl_c99
)
2727 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
2728 return compound_literal
;
2731 type
= complete_type (type
);
2733 if (TYPE_NON_AGGREGATE_CLASS (type
))
2735 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2736 everywhere that deals with function arguments would be a pain, so
2737 just wrap it in a TREE_LIST. The parser set a flag so we know
2738 that it came from T{} rather than T({}). */
2739 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2740 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2741 return build_functional_cast (type
, compound_literal
, complain
);
2744 if (TREE_CODE (type
) == ARRAY_TYPE
2745 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2746 return error_mark_node
;
2747 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2748 if (SCALAR_TYPE_P (type
)
2749 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
)
2750 && !check_narrowing (type
, compound_literal
, complain
))
2751 return error_mark_node
;
2752 if (TREE_CODE (type
) == ARRAY_TYPE
2753 && TYPE_DOMAIN (type
) == NULL_TREE
)
2755 cp_complete_array_type_or_error (&type
, compound_literal
,
2757 if (type
== error_mark_node
)
2758 return error_mark_node
;
2760 compound_literal
= digest_init_flags (type
, compound_literal
, LOOKUP_NORMAL
,
2762 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
2764 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
2765 if (fcl_context
== fcl_c99
)
2766 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
2769 /* Put static/constant array temporaries in static variables. */
2770 /* FIXME all C99 compound literals should be variables rather than C++
2771 temporaries, unless they are used as an aggregate initializer. */
2772 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
2773 && fcl_context
== fcl_c99
2774 && TREE_CODE (type
) == ARRAY_TYPE
2775 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
2776 && initializer_constant_valid_p (compound_literal
, type
))
2778 tree decl
= create_temporary_var (type
);
2779 DECL_INITIAL (decl
) = compound_literal
;
2780 TREE_STATIC (decl
) = 1;
2781 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
2783 /* 5.19 says that a constant expression can include an
2784 lvalue-rvalue conversion applied to "a glvalue of literal type
2785 that refers to a non-volatile temporary object initialized
2786 with a constant expression". Rather than try to communicate
2787 that this VAR_DECL is a temporary, just mark it constexpr. */
2788 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
2789 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
2790 TREE_CONSTANT (decl
) = true;
2792 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
2793 decl
= pushdecl_top_level (decl
);
2794 DECL_NAME (decl
) = make_anon_name ();
2795 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
2796 /* Make sure the destructor is callable. */
2797 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
2798 if (clean
== error_mark_node
)
2799 return error_mark_node
;
2803 /* Represent other compound literals with TARGET_EXPR so we produce
2804 an lvalue, but can elide copies. */
2805 if (!VECTOR_TYPE_P (type
))
2806 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
2808 return compound_literal
;
2811 /* Return the declaration for the function-name variable indicated by
2815 finish_fname (tree id
)
2819 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
2820 if (processing_template_decl
&& current_function_decl
2821 && decl
!= error_mark_node
)
2822 decl
= DECL_NAME (decl
);
2826 /* Finish a translation unit. */
2829 finish_translation_unit (void)
2831 /* In case there were missing closebraces,
2832 get us back to the global binding level. */
2834 while (current_namespace
!= global_namespace
)
2837 /* Do file scope __FUNCTION__ et al. */
2838 finish_fname_decls ();
2841 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2842 Returns the parameter. */
2845 finish_template_type_parm (tree aggr
, tree identifier
)
2847 if (aggr
!= class_type_node
)
2849 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
2850 aggr
= class_type_node
;
2853 return build_tree_list (aggr
, identifier
);
2856 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2857 Returns the parameter. */
2860 finish_template_template_parm (tree aggr
, tree identifier
)
2862 tree decl
= build_decl (input_location
,
2863 TYPE_DECL
, identifier
, NULL_TREE
);
2865 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
2866 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
2867 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
2868 DECL_ARTIFICIAL (decl
) = 1;
2870 // Associate the constraints with the underlying declaration,
2871 // not the template.
2872 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
2873 tree constr
= build_constraints (reqs
, NULL_TREE
);
2874 set_constraints (decl
, constr
);
2876 end_template_decl ();
2878 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
2880 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
2881 /*is_primary=*/true, /*is_partial=*/false,
2884 return finish_template_type_parm (aggr
, tmpl
);
2887 /* ARGUMENT is the default-argument value for a template template
2888 parameter. If ARGUMENT is invalid, issue error messages and return
2889 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2892 check_template_template_default_arg (tree argument
)
2894 if (TREE_CODE (argument
) != TEMPLATE_DECL
2895 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
2896 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
2898 if (TREE_CODE (argument
) == TYPE_DECL
)
2899 error ("invalid use of type %qT as a default value for a template "
2900 "template-parameter", TREE_TYPE (argument
));
2902 error ("invalid default argument for a template template parameter");
2903 return error_mark_node
;
2909 /* Begin a class definition, as indicated by T. */
2912 begin_class_definition (tree t
)
2914 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
2915 return error_mark_node
;
2917 if (processing_template_parmlist
)
2919 error ("definition of %q#T inside template parameter list", t
);
2920 return error_mark_node
;
2923 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
2924 are passed the same as decimal scalar types. */
2925 if (TREE_CODE (t
) == RECORD_TYPE
2926 && !processing_template_decl
)
2928 tree ns
= TYPE_CONTEXT (t
);
2929 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
2930 && DECL_CONTEXT (ns
) == std_node
2932 && id_equal (DECL_NAME (ns
), "decimal"))
2934 const char *n
= TYPE_NAME_STRING (t
);
2935 if ((strcmp (n
, "decimal32") == 0)
2936 || (strcmp (n
, "decimal64") == 0)
2937 || (strcmp (n
, "decimal128") == 0))
2938 TYPE_TRANSPARENT_AGGR (t
) = 1;
2942 /* A non-implicit typename comes from code like:
2944 template <typename T> struct A {
2945 template <typename U> struct A<T>::B ...
2947 This is erroneous. */
2948 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
2950 error ("invalid definition of qualified type %qT", t
);
2951 t
= error_mark_node
;
2954 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
2956 t
= make_class_type (RECORD_TYPE
);
2957 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
2960 if (TYPE_BEING_DEFINED (t
))
2962 t
= make_class_type (TREE_CODE (t
));
2963 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
2965 maybe_process_partial_specialization (t
);
2967 TYPE_BEING_DEFINED (t
) = 1;
2968 class_binding_level
->defining_class_p
= 1;
2970 if (flag_pack_struct
)
2973 TYPE_PACKED (t
) = 1;
2974 /* Even though the type is being defined for the first time
2975 here, there might have been a forward declaration, so there
2976 might be cv-qualified variants of T. */
2977 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
2978 TYPE_PACKED (v
) = 1;
2980 /* Reset the interface data, at the earliest possible
2981 moment, as it might have been set via a class foo;
2983 if (! TYPE_UNNAMED_P (t
))
2985 struct c_fileinfo
*finfo
= \
2986 get_fileinfo (LOCATION_FILE (input_location
));
2987 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
2988 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2989 (t
, finfo
->interface_unknown
);
2991 reset_specialization();
2993 /* Make a declaration for this class in its own scope. */
2994 build_self_reference ();
2999 /* Finish the member declaration given by DECL. */
3002 finish_member_declaration (tree decl
)
3004 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
3007 if (decl
== void_type_node
)
3008 /* The COMPONENT was a friend, not a member, and so there's
3009 nothing for us to do. */
3012 /* We should see only one DECL at a time. */
3013 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
3015 /* Don't add decls after definition. */
3016 gcc_assert (TYPE_BEING_DEFINED (current_class_type
)
3017 /* We can add lambda types when late parsing default
3019 || LAMBDA_TYPE_P (TREE_TYPE (decl
)));
3021 /* Set up access control for DECL. */
3023 = (current_access_specifier
== access_private_node
);
3024 TREE_PROTECTED (decl
)
3025 = (current_access_specifier
== access_protected_node
);
3026 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3028 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
3029 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
3032 /* Mark the DECL as a member of the current class, unless it's
3033 a member of an enumeration. */
3034 if (TREE_CODE (decl
) != CONST_DECL
)
3035 DECL_CONTEXT (decl
) = current_class_type
;
3037 if (TREE_CODE (decl
) == USING_DECL
)
3038 /* For now, ignore class-scope USING_DECLS, so that debugging
3039 backends do not see them. */
3040 DECL_IGNORED_P (decl
) = 1;
3042 /* Check for bare parameter packs in the non-static data member
3044 if (TREE_CODE (decl
) == FIELD_DECL
)
3046 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
3047 TREE_TYPE (decl
) = error_mark_node
;
3048 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3049 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3054 A C language linkage is ignored for the names of class members
3055 and the member function type of class member functions. */
3056 if (DECL_LANG_SPECIFIC (decl
))
3057 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3061 /* Functions and non-functions are added differently. */
3062 if (DECL_DECLARES_FUNCTION_P (decl
))
3063 add
= add_method (current_class_type
, decl
, false);
3064 /* Enter the DECL into the scope of the class, if the class
3065 isn't a closure (whose fields are supposed to be unnamed). */
3066 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3067 || pushdecl_class_level (decl
))
3072 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3073 go at the beginning. The reason is that
3074 legacy_nonfn_member_lookup searches the list in order, and we
3075 want a field name to override a type name so that the "struct
3076 stat hack" will work. In particular:
3078 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3082 if (TREE_CODE (decl
) == TYPE_DECL
)
3083 TYPE_FIELDS (current_class_type
)
3084 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3087 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3088 TYPE_FIELDS (current_class_type
) = decl
;
3091 maybe_add_class_template_decl_list (current_class_type
, decl
,
3096 /* Finish processing a complete template declaration. The PARMS are
3097 the template parameters. */
3100 finish_template_decl (tree parms
)
3103 end_template_decl ();
3105 end_specialization ();
3108 // Returns the template type of the class scope being entered. If we're
3109 // entering a constrained class scope. TYPE is the class template
3110 // scope being entered and we may need to match the intended type with
3111 // a constrained specialization. For example:
3113 // template<Object T>
3114 // struct S { void f(); }; #1
3116 // template<Object T>
3117 // void S<T>::f() { } #2
3119 // We check, in #2, that S<T> refers precisely to the type declared by
3120 // #1 (i.e., that the constraints match). Note that the following should
3121 // be an error since there is no specialization of S<T> that is
3122 // unconstrained, but this is not diagnosed here.
3124 // template<typename T>
3125 // void S<T>::f() { }
3127 // We cannot diagnose this problem here since this function also matches
3128 // qualified template names that are not part of a definition. For example:
3130 // template<Integral T, Floating_point U>
3131 // typename pair<T, U>::first_type void f(T, U);
3133 // Here, it is unlikely that there is a partial specialization of
3134 // pair constrained for for Integral and Floating_point arguments.
3136 // The general rule is: if a constrained specialization with matching
3137 // constraints is found return that type. Also note that if TYPE is not a
3138 // class-type (e.g. a typename type), then no fixup is needed.
3141 fixup_template_type (tree type
)
3143 // Find the template parameter list at the a depth appropriate to
3144 // the scope we're trying to enter.
3145 tree parms
= current_template_parms
;
3146 int depth
= template_class_depth (type
);
3147 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3148 parms
= TREE_CHAIN (parms
);
3151 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3152 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3154 // Search for a specialization whose type and constraints match.
3155 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3156 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3159 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3161 // If the type and constraints match a specialization, then we
3162 // are entering that type.
3163 if (same_type_p (type
, TREE_TYPE (specs
))
3164 && equivalent_constraints (cur_constr
, spec_constr
))
3165 return TREE_TYPE (specs
);
3166 specs
= TREE_CHAIN (specs
);
3169 // If no specialization matches, then must return the type
3170 // previously found.
3174 /* Finish processing a template-id (which names a type) of the form
3175 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3176 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3177 the scope of template-id indicated. */
3180 finish_template_type (tree name
, tree args
, int entering_scope
)
3184 type
= lookup_template_class (name
, args
,
3185 NULL_TREE
, NULL_TREE
, entering_scope
,
3186 tf_warning_or_error
| tf_user
);
3188 /* If we might be entering the scope of a partial specialization,
3189 find the one with the right constraints. */
3192 && CLASS_TYPE_P (type
)
3193 && CLASSTYPE_TEMPLATE_INFO (type
)
3194 && dependent_type_p (type
)
3195 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3196 type
= fixup_template_type (type
);
3198 if (type
== error_mark_node
)
3200 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3201 return TYPE_STUB_DECL (type
);
3203 return TYPE_NAME (type
);
3206 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3207 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3208 BASE_CLASS, or NULL_TREE if an error occurred. The
3209 ACCESS_SPECIFIER is one of
3210 access_{default,public,protected_private}_node. For a virtual base
3211 we set TREE_TYPE. */
3214 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3218 if (base
== error_mark_node
)
3220 error ("invalid base-class specification");
3223 else if (! MAYBE_CLASS_TYPE_P (base
))
3225 error ("%qT is not a class type", base
);
3230 if (cp_type_quals (base
) != 0)
3232 /* DR 484: Can a base-specifier name a cv-qualified
3234 base
= TYPE_MAIN_VARIANT (base
);
3236 result
= build_tree_list (access
, base
);
3238 TREE_TYPE (result
) = integer_type_node
;
3244 /* If FNS is a member function, a set of member functions, or a
3245 template-id referring to one or more member functions, return a
3246 BASELINK for FNS, incorporating the current access context.
3247 Otherwise, return FNS unchanged. */
3250 baselink_for_fns (tree fns
)
3255 if (BASELINK_P (fns
)
3256 || error_operand_p (fns
))
3259 scope
= ovl_scope (fns
);
3260 if (!CLASS_TYPE_P (scope
))
3263 cl
= currently_open_derived_class (scope
);
3266 cl
= TYPE_BINFO (cl
);
3267 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3270 /* Returns true iff DECL is a variable from a function outside
3274 outer_var_p (tree decl
)
3276 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3277 && DECL_FUNCTION_SCOPE_P (decl
)
3278 /* Don't get confused by temporaries. */
3280 && (DECL_CONTEXT (decl
) != current_function_decl
3281 || parsing_nsdmi ()));
3284 /* As above, but also checks that DECL is automatic. */
3287 outer_automatic_var_p (tree decl
)
3289 return (outer_var_p (decl
)
3290 && !TREE_STATIC (decl
));
3293 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3294 rewrite it for lambda capture. */
3297 process_outer_var_ref (tree decl
, tsubst_flags_t complain
, bool force_use
)
3299 if (cp_unevaluated_operand
)
3300 /* It's not a use (3.2) if we're in an unevaluated context. */
3302 if (decl
== error_mark_node
)
3305 tree context
= DECL_CONTEXT (decl
);
3306 tree containing_function
= current_function_decl
;
3307 tree lambda_stack
= NULL_TREE
;
3308 tree lambda_expr
= NULL_TREE
;
3309 tree initializer
= convert_from_reference (decl
);
3311 /* Mark it as used now even if the use is ill-formed. */
3312 if (!mark_used (decl
, complain
))
3313 return error_mark_node
;
3315 if (parsing_nsdmi ())
3316 containing_function
= NULL_TREE
;
3318 /* Core issue 696: Only an odr-use of an outer automatic variable causes a
3319 capture (or error), and a constant variable can decay to a prvalue
3320 constant without odr-use. So don't capture yet. */
3321 if (decl_constant_var_p (decl
) && !force_use
)
3324 if (containing_function
&& LAMBDA_FUNCTION_P (containing_function
))
3326 /* Check whether we've already built a proxy. */
3328 while (is_normal_capture_proxy (var
))
3329 var
= DECL_CAPTURED_VARIABLE (var
);
3330 tree d
= retrieve_local_specialization (var
);
3332 if (d
&& d
!= decl
&& is_capture_proxy (d
))
3334 if (DECL_CONTEXT (d
) == containing_function
)
3335 /* We already have an inner proxy. */
3338 /* We need to capture an outer proxy. */
3339 return process_outer_var_ref (d
, complain
, force_use
);
3343 /* If we are in a lambda function, we can move out until we hit
3345 2. a non-lambda function, or
3346 3. a non-default capturing lambda function. */
3347 while (context
!= containing_function
3348 /* containing_function can be null with invalid generic lambdas. */
3349 && containing_function
3350 && LAMBDA_FUNCTION_P (containing_function
))
3352 tree closure
= DECL_CONTEXT (containing_function
);
3353 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3355 if (TYPE_CLASS_SCOPE_P (closure
))
3356 /* A lambda in an NSDMI (c++/64496). */
3359 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3363 lambda_stack
= tree_cons (NULL_TREE
,
3368 = decl_function_context (containing_function
);
3371 /* In a lambda within a template, wait until instantiation
3372 time to implicitly capture. */
3373 if (context
== containing_function
3374 && DECL_TEMPLATE_INFO (containing_function
)
3375 && uses_template_parms (DECL_TI_ARGS (containing_function
)))
3378 if (lambda_expr
&& VAR_P (decl
)
3379 && DECL_ANON_UNION_VAR_P (decl
))
3381 if (complain
& tf_error
)
3382 error ("cannot capture member %qD of anonymous union", decl
);
3383 return error_mark_node
;
3385 if (context
== containing_function
)
3387 decl
= add_default_capture (lambda_stack
,
3388 /*id=*/DECL_NAME (decl
),
3391 else if (lambda_expr
)
3393 if (complain
& tf_error
)
3395 error ("%qD is not captured", decl
);
3396 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3397 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3399 inform (location_of (closure
),
3400 "the lambda has no capture-default");
3401 else if (TYPE_CLASS_SCOPE_P (closure
))
3402 inform (UNKNOWN_LOCATION
, "lambda in local class %q+T cannot "
3403 "capture variables from the enclosing context",
3404 TYPE_CONTEXT (closure
));
3405 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3407 return error_mark_node
;
3411 if (complain
& tf_error
)
3414 ? G_("use of local variable with automatic storage from "
3415 "containing function")
3416 : G_("use of parameter from containing function"));
3417 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3419 return error_mark_node
;
3424 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3425 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3426 if non-NULL, is the type or namespace used to explicitly qualify
3427 ID_EXPRESSION. DECL is the entity to which that name has been
3430 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3431 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3432 be set to true if this expression isn't permitted in a
3433 constant-expression, but it is otherwise not set by this function.
3434 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3435 constant-expression, but a non-constant expression is also
3438 DONE is true if this expression is a complete postfix-expression;
3439 it is false if this expression is followed by '->', '[', '(', etc.
3440 ADDRESS_P is true iff this expression is the operand of '&'.
3441 TEMPLATE_P is true iff the qualified-id was of the form
3442 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3443 appears as a template argument.
3445 If an error occurs, and it is the kind of error that might cause
3446 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3447 is the caller's responsibility to issue the message. *ERROR_MSG
3448 will be a string with static storage duration, so the caller need
3451 Return an expression for the entity, after issuing appropriate
3452 diagnostics. This function is also responsible for transforming a
3453 reference to a non-static member into a COMPONENT_REF that makes
3454 the use of "this" explicit.
3456 Upon return, *IDK will be filled in appropriately. */
3458 finish_id_expression (tree id_expression
,
3462 bool integral_constant_expression_p
,
3463 bool allow_non_integral_constant_expression_p
,
3464 bool *non_integral_constant_expression_p
,
3468 bool template_arg_p
,
3469 const char **error_msg
,
3470 location_t location
)
3472 decl
= strip_using_decl (decl
);
3474 /* Initialize the output parameters. */
3475 *idk
= CP_ID_KIND_NONE
;
3478 if (id_expression
== error_mark_node
)
3479 return error_mark_node
;
3480 /* If we have a template-id, then no further lookup is
3481 required. If the template-id was for a template-class, we
3482 will sometimes have a TYPE_DECL at this point. */
3483 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3484 || TREE_CODE (decl
) == TYPE_DECL
)
3486 /* Look up the name. */
3489 if (decl
== error_mark_node
)
3491 /* Name lookup failed. */
3494 || (!dependent_type_p (scope
)
3495 && !(identifier_p (id_expression
)
3496 && IDENTIFIER_CONV_OP_P (id_expression
)
3497 && dependent_type_p (TREE_TYPE (id_expression
))))))
3499 /* If the qualifying type is non-dependent (and the name
3500 does not name a conversion operator to a dependent
3501 type), issue an error. */
3502 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3503 return error_mark_node
;
3507 /* It may be resolved via Koenig lookup. */
3508 *idk
= CP_ID_KIND_UNQUALIFIED
;
3509 return id_expression
;
3512 decl
= id_expression
;
3514 /* If DECL is a variable that would be out of scope under
3515 ANSI/ISO rules, but in scope in the ARM, name lookup
3516 will succeed. Issue a diagnostic here. */
3518 decl
= check_for_out_of_scope_variable (decl
);
3520 /* Remember that the name was used in the definition of
3521 the current class so that we can check later to see if
3522 the meaning would have been different after the class
3523 was entirely defined. */
3524 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3525 maybe_note_name_used_in_class (id_expression
, decl
);
3527 /* A use in unevaluated operand might not be instantiated appropriately
3528 if tsubst_copy builds a dummy parm, or if we never instantiate a
3529 generic lambda, so mark it now. */
3530 if (processing_template_decl
&& cp_unevaluated_operand
)
3531 mark_type_use (decl
);
3533 /* Disallow uses of local variables from containing functions, except
3534 within lambda-expressions. */
3535 if (outer_automatic_var_p (decl
))
3537 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3538 if (decl
== error_mark_node
)
3539 return error_mark_node
;
3542 /* Also disallow uses of function parameters outside the function
3543 body, except inside an unevaluated context (i.e. decltype). */
3544 if (TREE_CODE (decl
) == PARM_DECL
3545 && DECL_CONTEXT (decl
) == NULL_TREE
3546 && !cp_unevaluated_operand
)
3548 *error_msg
= G_("use of parameter outside function body");
3549 return error_mark_node
;
3553 /* If we didn't find anything, or what we found was a type,
3554 then this wasn't really an id-expression. */
3555 if (TREE_CODE (decl
) == TEMPLATE_DECL
3556 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3558 *error_msg
= G_("missing template arguments");
3559 return error_mark_node
;
3561 else if (TREE_CODE (decl
) == TYPE_DECL
3562 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3564 *error_msg
= G_("expected primary-expression");
3565 return error_mark_node
;
3568 /* If the name resolved to a template parameter, there is no
3569 need to look it up again later. */
3570 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3571 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3575 *idk
= CP_ID_KIND_NONE
;
3576 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3577 decl
= TEMPLATE_PARM_DECL (decl
);
3578 r
= convert_from_reference (DECL_INITIAL (decl
));
3580 if (integral_constant_expression_p
3581 && !dependent_type_p (TREE_TYPE (decl
))
3582 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3584 if (!allow_non_integral_constant_expression_p
)
3585 error ("template parameter %qD of type %qT is not allowed in "
3586 "an integral constant expression because it is not of "
3587 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3588 *non_integral_constant_expression_p
= true;
3594 bool dependent_p
= type_dependent_expression_p (decl
);
3596 /* If the declaration was explicitly qualified indicate
3597 that. The semantics of `A::f(3)' are different than
3598 `f(3)' if `f' is virtual. */
3600 ? CP_ID_KIND_QUALIFIED
3601 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3602 ? CP_ID_KIND_TEMPLATE_ID
3604 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3605 : CP_ID_KIND_UNQUALIFIED
)));
3609 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
3610 /* Dependent type attributes on the decl mean that the TREE_TYPE is
3611 wrong, so just return the identifier. */
3612 return id_expression
;
3614 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3616 error ("use of namespace %qD as expression", decl
);
3617 return error_mark_node
;
3619 else if (DECL_CLASS_TEMPLATE_P (decl
))
3621 error ("use of class template %qT as expression", decl
);
3622 return error_mark_node
;
3624 else if (TREE_CODE (decl
) == TREE_LIST
)
3626 /* Ambiguous reference to base members. */
3627 error ("request for member %qD is ambiguous in "
3628 "multiple inheritance lattice", id_expression
);
3629 print_candidates (decl
);
3630 return error_mark_node
;
3633 /* Mark variable-like entities as used. Functions are similarly
3634 marked either below or after overload resolution. */
3636 || TREE_CODE (decl
) == PARM_DECL
3637 || TREE_CODE (decl
) == CONST_DECL
3638 || TREE_CODE (decl
) == RESULT_DECL
)
3639 && !mark_used (decl
))
3640 return error_mark_node
;
3642 /* Only certain kinds of names are allowed in constant
3643 expression. Template parameters have already
3644 been handled above. */
3645 if (! error_operand_p (decl
)
3647 && integral_constant_expression_p
3648 && ! decl_constant_var_p (decl
)
3649 && TREE_CODE (decl
) != CONST_DECL
3650 && ! builtin_valid_in_constant_expr_p (decl
))
3652 if (!allow_non_integral_constant_expression_p
)
3654 error ("%qD cannot appear in a constant-expression", decl
);
3655 return error_mark_node
;
3657 *non_integral_constant_expression_p
= true;
3662 && !cp_unevaluated_operand
3663 && !processing_template_decl
3664 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
3665 && CP_DECL_THREAD_LOCAL_P (decl
)
3666 && (wrap
= get_tls_wrapper_fn (decl
)))
3668 /* Replace an evaluated use of the thread_local variable with
3669 a call to its wrapper. */
3670 decl
= build_cxx_call (wrap
, 0, NULL
, tf_warning_or_error
);
3672 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3674 && variable_template_p (TREE_OPERAND (decl
, 0)))
3676 decl
= finish_template_variable (decl
);
3678 decl
= convert_from_reference (decl
);
3682 if (TREE_CODE (decl
) == SCOPE_REF
)
3684 gcc_assert (same_type_p (scope
, TREE_OPERAND (decl
, 0)));
3685 decl
= TREE_OPERAND (decl
, 1);
3688 decl
= (adjust_result_of_qualified_name_lookup
3689 (decl
, scope
, current_nonlambda_class_type()));
3691 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3695 decl
= finish_qualified_id_expr (scope
,
3701 tf_warning_or_error
);
3703 decl
= convert_from_reference (decl
);
3705 else if (TREE_CODE (decl
) == FIELD_DECL
)
3707 /* Since SCOPE is NULL here, this is an unqualified name.
3708 Access checking has been performed during name lookup
3709 already. Turn off checking to avoid duplicate errors. */
3710 push_deferring_access_checks (dk_no_check
);
3711 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3712 /*qualifying_scope=*/NULL_TREE
);
3713 pop_deferring_access_checks ();
3715 else if (is_overloaded_fn (decl
))
3717 tree first_fn
= get_first_fn (decl
);
3719 if (TREE_CODE (first_fn
) == TEMPLATE_DECL
)
3720 first_fn
= DECL_TEMPLATE_RESULT (first_fn
);
3722 /* [basic.def.odr]: "A function whose name appears as a
3723 potentially-evaluated expression is odr-used if it is the unique
3726 But only mark it if it's a complete postfix-expression; in a call,
3727 ADL might select a different function, and we'll call mark_used in
3730 && !really_overloaded_fn (decl
)
3731 && !mark_used (first_fn
))
3732 return error_mark_node
;
3735 && TREE_CODE (first_fn
) == FUNCTION_DECL
3736 && DECL_FUNCTION_MEMBER_P (first_fn
)
3737 && !shared_member_p (decl
))
3739 /* A set of member functions. */
3740 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
3741 return finish_class_member_access_expr (decl
, id_expression
,
3742 /*template_p=*/false,
3743 tf_warning_or_error
);
3746 decl
= baselink_for_fns (decl
);
3750 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
3751 && DECL_CLASS_SCOPE_P (decl
))
3753 tree context
= context_for_name_lookup (decl
);
3754 if (context
!= current_class_type
)
3756 tree path
= currently_open_derived_class (context
);
3757 perform_or_defer_access_check (TYPE_BINFO (path
),
3759 tf_warning_or_error
);
3763 decl
= convert_from_reference (decl
);
3767 return cp_expr (decl
, location
);
3770 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3771 use as a type-specifier. */
3774 finish_typeof (tree expr
)
3778 if (type_dependent_expression_p (expr
))
3780 type
= cxx_make_type (TYPEOF_TYPE
);
3781 TYPEOF_TYPE_EXPR (type
) = expr
;
3782 SET_TYPE_STRUCTURAL_EQUALITY (type
);
3787 expr
= mark_type_use (expr
);
3789 type
= unlowered_expr_type (expr
);
3791 if (!type
|| type
== unknown_type_node
)
3793 error ("type of %qE is unknown", expr
);
3794 return error_mark_node
;
3800 /* Implement the __underlying_type keyword: Return the underlying
3801 type of TYPE, suitable for use as a type-specifier. */
3804 finish_underlying_type (tree type
)
3806 tree underlying_type
;
3808 if (processing_template_decl
)
3810 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
3811 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
3812 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
3814 return underlying_type
;
3817 if (!complete_type_or_else (type
, NULL_TREE
))
3818 return error_mark_node
;
3820 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
3822 error ("%qT is not an enumeration type", type
);
3823 return error_mark_node
;
3826 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
3828 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
3829 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
3830 See finish_enum_value_list for details. */
3831 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
3833 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
3834 TYPE_UNSIGNED (underlying_type
));
3836 return underlying_type
;
3839 /* Implement the __direct_bases keyword: Return the direct base classes
3843 calculate_direct_bases (tree type
)
3845 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3846 tree bases_vec
= NULL_TREE
;
3847 vec
<tree
, va_gc
> *base_binfos
;
3851 complete_type (type
);
3853 if (!NON_UNION_CLASS_TYPE_P (type
))
3854 return make_tree_vec (0);
3856 base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
3858 /* Virtual bases are initialized first */
3859 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3861 if (BINFO_VIRTUAL_P (binfo
))
3863 vec_safe_push (vector
, binfo
);
3867 /* Now non-virtuals */
3868 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3870 if (!BINFO_VIRTUAL_P (binfo
))
3872 vec_safe_push (vector
, binfo
);
3877 bases_vec
= make_tree_vec (vector
->length ());
3879 for (i
= 0; i
< vector
->length (); ++i
)
3881 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
3886 /* Implement the __bases keyword: Return the base classes
3889 /* Find morally non-virtual base classes by walking binfo hierarchy */
3890 /* Virtual base classes are handled separately in finish_bases */
3893 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
3895 /* Don't walk bases of virtual bases */
3896 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
3900 dfs_calculate_bases_post (tree binfo
, void *data_
)
3902 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
3903 if (!BINFO_VIRTUAL_P (binfo
))
3905 vec_safe_push (*data
, BINFO_TYPE (binfo
));
3910 /* Calculates the morally non-virtual base classes of a class */
3911 static vec
<tree
, va_gc
> *
3912 calculate_bases_helper (tree type
)
3914 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3916 /* Now add non-virtual base classes in order of construction */
3917 if (TYPE_BINFO (type
))
3918 dfs_walk_all (TYPE_BINFO (type
),
3919 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
3924 calculate_bases (tree type
)
3926 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3927 tree bases_vec
= NULL_TREE
;
3929 vec
<tree
, va_gc
> *vbases
;
3930 vec
<tree
, va_gc
> *nonvbases
;
3933 complete_type (type
);
3935 if (!NON_UNION_CLASS_TYPE_P (type
))
3936 return make_tree_vec (0);
3938 /* First go through virtual base classes */
3939 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
3940 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
3942 vec
<tree
, va_gc
> *vbase_bases
;
3943 vbase_bases
= calculate_bases_helper (BINFO_TYPE (binfo
));
3944 vec_safe_splice (vector
, vbase_bases
);
3945 release_tree_vector (vbase_bases
);
3948 /* Now for the non-virtual bases */
3949 nonvbases
= calculate_bases_helper (type
);
3950 vec_safe_splice (vector
, nonvbases
);
3951 release_tree_vector (nonvbases
);
3953 /* Note that during error recovery vector->length can even be zero. */
3954 if (vector
->length () > 1)
3956 /* Last element is entire class, so don't copy */
3957 bases_vec
= make_tree_vec (vector
->length() - 1);
3959 for (i
= 0; i
< vector
->length () - 1; ++i
)
3960 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
3963 bases_vec
= make_tree_vec (0);
3965 release_tree_vector (vector
);
3970 finish_bases (tree type
, bool direct
)
3972 tree bases
= NULL_TREE
;
3974 if (!processing_template_decl
)
3976 /* Parameter packs can only be used in templates */
3977 error ("Parameter pack __bases only valid in template declaration");
3978 return error_mark_node
;
3981 bases
= cxx_make_type (BASES
);
3982 BASES_TYPE (bases
) = type
;
3983 BASES_DIRECT (bases
) = direct
;
3984 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
3989 /* Perform C++-specific checks for __builtin_offsetof before calling
3993 finish_offsetof (tree object_ptr
, tree expr
, location_t loc
)
3995 /* If we're processing a template, we can't finish the semantics yet.
3996 Otherwise we can fold the entire expression now. */
3997 if (processing_template_decl
)
3999 expr
= build2 (OFFSETOF_EXPR
, size_type_node
, expr
, object_ptr
);
4000 SET_EXPR_LOCATION (expr
, loc
);
4004 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4006 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4007 TREE_OPERAND (expr
, 2));
4008 return error_mark_node
;
4010 if (TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
4011 || TREE_CODE (TREE_TYPE (expr
)) == METHOD_TYPE
4012 || TREE_TYPE (expr
) == unknown_type_node
)
4014 if (INDIRECT_REF_P (expr
))
4015 error ("second operand of %<offsetof%> is neither a single "
4016 "identifier nor a sequence of member accesses and "
4017 "array references");
4020 if (TREE_CODE (expr
) == COMPONENT_REF
4021 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4022 expr
= TREE_OPERAND (expr
, 1);
4023 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4025 return error_mark_node
;
4027 if (REFERENCE_REF_P (expr
))
4028 expr
= TREE_OPERAND (expr
, 0);
4029 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr
)), object_ptr
))
4030 return error_mark_node
;
4031 if (warn_invalid_offsetof
4032 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr
)))
4033 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr
)))
4034 && cp_unevaluated_operand
== 0)
4035 pedwarn (loc
, OPT_Winvalid_offsetof
,
4036 "offsetof within non-standard-layout type %qT is undefined",
4037 TREE_TYPE (TREE_TYPE (object_ptr
)));
4038 return fold_offsetof (expr
);
4041 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4042 function is broken out from the above for the benefit of the tree-ssa
4046 simplify_aggr_init_expr (tree
*tp
)
4048 tree aggr_init_expr
= *tp
;
4050 /* Form an appropriate CALL_EXPR. */
4051 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4052 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4053 tree type
= TREE_TYPE (slot
);
4056 enum style_t
{ ctor
, arg
, pcc
} style
;
4058 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4060 #ifdef PCC_STATIC_STRUCT_RETURN
4066 gcc_assert (TREE_ADDRESSABLE (type
));
4070 call_expr
= build_call_array_loc (input_location
,
4071 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4073 aggr_init_expr_nargs (aggr_init_expr
),
4074 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4075 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4076 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4077 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4078 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4079 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4080 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4081 /* Preserve CILK_SPAWN flag. */
4082 EXPR_CILK_SPAWN (call_expr
) = EXPR_CILK_SPAWN (aggr_init_expr
);
4086 /* Replace the first argument to the ctor with the address of the
4088 cxx_mark_addressable (slot
);
4089 CALL_EXPR_ARG (call_expr
, 0) =
4090 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4092 else if (style
== arg
)
4094 /* Just mark it addressable here, and leave the rest to
4095 expand_call{,_inline}. */
4096 cxx_mark_addressable (slot
);
4097 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4098 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4100 else if (style
== pcc
)
4102 /* If we're using the non-reentrant PCC calling convention, then we
4103 need to copy the returned value out of the static buffer into the
4105 push_deferring_access_checks (dk_no_check
);
4106 call_expr
= build_aggr_init (slot
, call_expr
,
4107 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4108 tf_warning_or_error
);
4109 pop_deferring_access_checks ();
4110 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4113 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4115 tree init
= build_zero_init (type
, NULL_TREE
,
4116 /*static_storage_p=*/false);
4117 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4118 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4125 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4128 emit_associated_thunks (tree fn
)
4130 /* When we use vcall offsets, we emit thunks with the virtual
4131 functions to which they thunk. The whole point of vcall offsets
4132 is so that you can know statically the entire set of thunks that
4133 will ever be needed for a given virtual function, thereby
4134 enabling you to output all the thunks with the function itself. */
4135 if (DECL_VIRTUAL_P (fn
)
4136 /* Do not emit thunks for extern template instantiations. */
4137 && ! DECL_REALLY_EXTERN (fn
))
4141 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4143 if (!THUNK_ALIAS (thunk
))
4145 use_thunk (thunk
, /*emit_p=*/1);
4146 if (DECL_RESULT_THUNK_P (thunk
))
4150 for (probe
= DECL_THUNKS (thunk
);
4151 probe
; probe
= DECL_CHAIN (probe
))
4152 use_thunk (probe
, /*emit_p=*/1);
4156 gcc_assert (!DECL_THUNKS (thunk
));
4161 /* Generate RTL for FN. */
4164 expand_or_defer_fn_1 (tree fn
)
4166 /* When the parser calls us after finishing the body of a template
4167 function, we don't really want to expand the body. */
4168 if (processing_template_decl
)
4170 /* Normally, collection only occurs in rest_of_compilation. So,
4171 if we don't collect here, we never collect junk generated
4172 during the processing of templates until we hit a
4173 non-template function. It's not safe to do this inside a
4174 nested class, though, as the parser may have local state that
4175 is not a GC root. */
4176 if (!function_depth
)
4181 gcc_assert (DECL_SAVED_TREE (fn
));
4183 /* We make a decision about linkage for these functions at the end
4184 of the compilation. Until that point, we do not want the back
4185 end to output them -- but we do want it to see the bodies of
4186 these functions so that it can inline them as appropriate. */
4187 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4189 if (DECL_INTERFACE_KNOWN (fn
))
4190 /* We've already made a decision as to how this function will
4193 tentative_decl_linkage (fn
);
4195 import_export_decl (fn
);
4197 /* If the user wants us to keep all inline functions, then mark
4198 this function as needed so that finish_file will make sure to
4199 output it later. Similarly, all dllexport'd functions must
4200 be emitted; there may be callers in other DLLs. */
4201 if (DECL_DECLARED_INLINE_P (fn
)
4202 && !DECL_REALLY_EXTERN (fn
)
4203 && (flag_keep_inline_functions
4204 || (flag_keep_inline_dllexport
4205 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4208 DECL_EXTERNAL (fn
) = 0;
4212 /* If this is a constructor or destructor body, we have to clone
4214 if (maybe_clone_body (fn
))
4216 /* We don't want to process FN again, so pretend we've written
4217 it out, even though we haven't. */
4218 TREE_ASM_WRITTEN (fn
) = 1;
4219 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4220 if (!DECL_DECLARED_CONSTEXPR_P (fn
))
4221 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4225 /* There's no reason to do any of the work here if we're only doing
4226 semantic analysis; this code just generates RTL. */
4227 if (flag_syntax_only
)
4234 expand_or_defer_fn (tree fn
)
4236 if (expand_or_defer_fn_1 (fn
))
4240 /* Expand or defer, at the whim of the compilation unit manager. */
4241 cgraph_node::finalize_function (fn
, function_depth
> 1);
4242 emit_associated_thunks (fn
);
4250 nrv_data () : visited (37) {}
4254 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4257 /* Helper function for walk_tree, used by finalize_nrv below. */
4260 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4262 struct nrv_data
*dp
= (struct nrv_data
*)data
;
4265 /* No need to walk into types. There wouldn't be any need to walk into
4266 non-statements, except that we have to consider STMT_EXPRs. */
4269 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4270 but differs from using NULL_TREE in that it indicates that we care
4271 about the value of the RESULT_DECL. */
4272 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4273 TREE_OPERAND (*tp
, 0) = dp
->result
;
4274 /* Change all cleanups for the NRV to only run when an exception is
4276 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4277 && CLEANUP_DECL (*tp
) == dp
->var
)
4278 CLEANUP_EH_ONLY (*tp
) = 1;
4279 /* Replace the DECL_EXPR for the NRV with an initialization of the
4280 RESULT_DECL, if needed. */
4281 else if (TREE_CODE (*tp
) == DECL_EXPR
4282 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4285 if (DECL_INITIAL (dp
->var
)
4286 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4287 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4288 DECL_INITIAL (dp
->var
));
4290 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4291 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4292 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4295 /* And replace all uses of the NRV with the RESULT_DECL. */
4296 else if (*tp
== dp
->var
)
4299 /* Avoid walking into the same tree more than once. Unfortunately, we
4300 can't just use walk_tree_without duplicates because it would only call
4301 us for the first occurrence of dp->var in the function body. */
4302 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4308 /* Keep iterating. */
4312 /* Called from finish_function to implement the named return value
4313 optimization by overriding all the RETURN_EXPRs and pertinent
4314 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4315 RESULT_DECL for the function. */
4318 finalize_nrv (tree
*tp
, tree var
, tree result
)
4320 struct nrv_data data
;
4322 /* Copy name from VAR to RESULT. */
4323 DECL_NAME (result
) = DECL_NAME (var
);
4324 /* Don't forget that we take its address. */
4325 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4326 /* Finally set DECL_VALUE_EXPR to avoid assigning
4327 a stack slot at -O0 for the original var and debug info
4328 uses RESULT location for VAR. */
4329 SET_DECL_VALUE_EXPR (var
, result
);
4330 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4333 data
.result
= result
;
4334 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4337 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4340 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4341 bool need_copy_ctor
, bool need_copy_assignment
,
4344 int save_errorcount
= errorcount
;
4347 /* Always allocate 3 elements for simplicity. These are the
4348 function decls for the ctor, dtor, and assignment op.
4349 This layout is known to the three lang hooks,
4350 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4351 and cxx_omp_clause_assign_op. */
4352 info
= make_tree_vec (3);
4353 CP_OMP_CLAUSE_INFO (c
) = info
;
4355 if (need_default_ctor
|| need_copy_ctor
)
4357 if (need_default_ctor
)
4358 t
= get_default_ctor (type
);
4360 t
= get_copy_ctor (type
, tf_warning_or_error
);
4362 if (t
&& !trivial_fn_p (t
))
4363 TREE_VEC_ELT (info
, 0) = t
;
4366 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4367 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4369 if (need_copy_assignment
)
4371 t
= get_copy_assign (type
);
4373 if (t
&& !trivial_fn_p (t
))
4374 TREE_VEC_ELT (info
, 2) = t
;
4377 return errorcount
!= save_errorcount
;
4380 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4381 FIELD_DECL, otherwise return DECL itself. */
4384 omp_clause_decl_field (tree decl
)
4387 && DECL_HAS_VALUE_EXPR_P (decl
)
4388 && DECL_ARTIFICIAL (decl
)
4389 && DECL_LANG_SPECIFIC (decl
)
4390 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4392 tree f
= DECL_VALUE_EXPR (decl
);
4393 if (TREE_CODE (f
) == INDIRECT_REF
)
4394 f
= TREE_OPERAND (f
, 0);
4395 if (TREE_CODE (f
) == COMPONENT_REF
)
4397 f
= TREE_OPERAND (f
, 1);
4398 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4405 /* Adjust DECL if needed for printing using %qE. */
4408 omp_clause_printable_decl (tree decl
)
4410 tree t
= omp_clause_decl_field (decl
);
4416 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4417 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4421 omp_note_field_privatization (tree f
, tree t
)
4423 if (!omp_private_member_map
)
4424 omp_private_member_map
= new hash_map
<tree
, tree
>;
4425 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4429 omp_private_member_vec
.safe_push (f
);
4430 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4431 omp_private_member_vec
.safe_push (integer_zero_node
);
4435 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4439 omp_privatize_field (tree t
, bool shared
)
4441 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4442 if (m
== error_mark_node
)
4443 return error_mark_node
;
4444 if (!omp_private_member_map
&& !shared
)
4445 omp_private_member_map
= new hash_map
<tree
, tree
>;
4446 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
)
4448 gcc_assert (TREE_CODE (m
) == INDIRECT_REF
);
4449 m
= TREE_OPERAND (m
, 0);
4451 tree vb
= NULL_TREE
;
4452 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4455 v
= create_temporary_var (TREE_TYPE (m
));
4456 retrofit_lang_decl (v
);
4457 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4458 SET_DECL_VALUE_EXPR (v
, m
);
4459 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4461 omp_private_member_vec
.safe_push (t
);
4466 /* Helper function for handle_omp_array_sections. Called recursively
4467 to handle multiple array-section-subscripts. C is the clause,
4468 T current expression (initially OMP_CLAUSE_DECL), which is either
4469 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4470 expression if specified, TREE_VALUE length expression if specified,
4471 TREE_CHAIN is what it has been specified after, or some decl.
4472 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4473 set to true if any of the array-section-subscript could have length
4474 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4475 first array-section-subscript which is known not to have length
4477 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4478 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4479 all are or may have length of 1, array-section-subscript [:2] is the
4480 first one known not to have length 1. For array-section-subscript
4481 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4482 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4483 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4484 case though, as some lengths could be zero. */
4487 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4488 bool &maybe_zero_len
, unsigned int &first_non_one
,
4489 enum c_omp_region_type ort
)
4491 tree ret
, low_bound
, length
, type
;
4492 if (TREE_CODE (t
) != TREE_LIST
)
4494 if (error_operand_p (t
))
4495 return error_mark_node
;
4496 if (REFERENCE_REF_P (t
)
4497 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4498 t
= TREE_OPERAND (t
, 0);
4500 if (TREE_CODE (t
) == COMPONENT_REF
4502 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4503 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
4504 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
4505 && !type_dependent_expression_p (t
))
4507 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
4508 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
4510 error_at (OMP_CLAUSE_LOCATION (c
),
4511 "bit-field %qE in %qs clause",
4512 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4513 return error_mark_node
;
4515 while (TREE_CODE (t
) == COMPONENT_REF
)
4517 if (TREE_TYPE (TREE_OPERAND (t
, 0))
4518 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
4520 error_at (OMP_CLAUSE_LOCATION (c
),
4521 "%qE is a member of a union", t
);
4522 return error_mark_node
;
4524 t
= TREE_OPERAND (t
, 0);
4526 if (REFERENCE_REF_P (t
))
4527 t
= TREE_OPERAND (t
, 0);
4529 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
4531 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
4534 error_at (OMP_CLAUSE_LOCATION (c
),
4535 "%qD is not a variable in %qs clause", t
,
4536 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4538 error_at (OMP_CLAUSE_LOCATION (c
),
4539 "%qE is not a variable in %qs clause", t
,
4540 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4541 return error_mark_node
;
4543 else if (TREE_CODE (t
) == PARM_DECL
4544 && DECL_ARTIFICIAL (t
)
4545 && DECL_NAME (t
) == this_identifier
)
4547 error_at (OMP_CLAUSE_LOCATION (c
),
4548 "%<this%> allowed in OpenMP only in %<declare simd%>"
4550 return error_mark_node
;
4552 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4553 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
4555 error_at (OMP_CLAUSE_LOCATION (c
),
4556 "%qD is threadprivate variable in %qs clause", t
,
4557 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4558 return error_mark_node
;
4560 if (type_dependent_expression_p (ret
))
4562 ret
= convert_from_reference (ret
);
4566 if (ort
== C_ORT_OMP
4567 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4568 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
4569 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
4570 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4571 maybe_zero_len
, first_non_one
, ort
);
4572 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4575 type
= TREE_TYPE (ret
);
4576 low_bound
= TREE_PURPOSE (t
);
4577 length
= TREE_VALUE (t
);
4578 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4579 || (length
&& type_dependent_expression_p (length
)))
4582 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4583 return error_mark_node
;
4585 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4587 error_at (OMP_CLAUSE_LOCATION (c
),
4588 "low bound %qE of array section does not have integral type",
4590 return error_mark_node
;
4592 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4594 error_at (OMP_CLAUSE_LOCATION (c
),
4595 "length %qE of array section does not have integral type",
4597 return error_mark_node
;
4600 low_bound
= mark_rvalue_use (low_bound
);
4602 length
= mark_rvalue_use (length
);
4603 /* We need to reduce to real constant-values for checks below. */
4605 length
= fold_simple (length
);
4607 low_bound
= fold_simple (low_bound
);
4609 && TREE_CODE (low_bound
) == INTEGER_CST
4610 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4611 > TYPE_PRECISION (sizetype
))
4612 low_bound
= fold_convert (sizetype
, low_bound
);
4614 && TREE_CODE (length
) == INTEGER_CST
4615 && TYPE_PRECISION (TREE_TYPE (length
))
4616 > TYPE_PRECISION (sizetype
))
4617 length
= fold_convert (sizetype
, length
);
4618 if (low_bound
== NULL_TREE
)
4619 low_bound
= integer_zero_node
;
4621 if (length
!= NULL_TREE
)
4623 if (!integer_nonzerop (length
))
4625 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4626 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4628 if (integer_zerop (length
))
4630 error_at (OMP_CLAUSE_LOCATION (c
),
4631 "zero length array section in %qs clause",
4632 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4633 return error_mark_node
;
4637 maybe_zero_len
= true;
4639 if (first_non_one
== types
.length ()
4640 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4643 if (TREE_CODE (type
) == ARRAY_TYPE
)
4645 if (length
== NULL_TREE
4646 && (TYPE_DOMAIN (type
) == NULL_TREE
4647 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4649 error_at (OMP_CLAUSE_LOCATION (c
),
4650 "for unknown bound array type length expression must "
4652 return error_mark_node
;
4654 if (TREE_CODE (low_bound
) == INTEGER_CST
4655 && tree_int_cst_sgn (low_bound
) == -1)
4657 error_at (OMP_CLAUSE_LOCATION (c
),
4658 "negative low bound in array section in %qs clause",
4659 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4660 return error_mark_node
;
4662 if (length
!= NULL_TREE
4663 && TREE_CODE (length
) == INTEGER_CST
4664 && tree_int_cst_sgn (length
) == -1)
4666 error_at (OMP_CLAUSE_LOCATION (c
),
4667 "negative length in array section in %qs clause",
4668 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4669 return error_mark_node
;
4671 if (TYPE_DOMAIN (type
)
4672 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
4673 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
4677 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
4678 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
4679 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4681 if (tree_int_cst_lt (size
, low_bound
))
4683 error_at (OMP_CLAUSE_LOCATION (c
),
4684 "low bound %qE above array section size "
4685 "in %qs clause", low_bound
,
4686 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4687 return error_mark_node
;
4689 if (tree_int_cst_equal (size
, low_bound
))
4691 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4692 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4694 error_at (OMP_CLAUSE_LOCATION (c
),
4695 "zero length array section in %qs clause",
4696 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4697 return error_mark_node
;
4699 maybe_zero_len
= true;
4701 else if (length
== NULL_TREE
4702 && first_non_one
== types
.length ()
4703 && tree_int_cst_equal
4704 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4708 else if (length
== NULL_TREE
)
4710 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4711 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4712 maybe_zero_len
= true;
4713 if (first_non_one
== types
.length ())
4716 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
4718 if (tree_int_cst_lt (size
, length
))
4720 error_at (OMP_CLAUSE_LOCATION (c
),
4721 "length %qE above array section size "
4722 "in %qs clause", length
,
4723 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4724 return error_mark_node
;
4726 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4729 = size_binop (PLUS_EXPR
,
4730 fold_convert (sizetype
, low_bound
),
4731 fold_convert (sizetype
, length
));
4732 if (TREE_CODE (lbpluslen
) == INTEGER_CST
4733 && tree_int_cst_lt (size
, lbpluslen
))
4735 error_at (OMP_CLAUSE_LOCATION (c
),
4736 "high bound %qE above array section size "
4737 "in %qs clause", lbpluslen
,
4738 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4739 return error_mark_node
;
4744 else if (length
== NULL_TREE
)
4746 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4747 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4748 maybe_zero_len
= true;
4749 if (first_non_one
== types
.length ())
4753 /* For [lb:] we will need to evaluate lb more than once. */
4754 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4756 tree lb
= cp_save_expr (low_bound
);
4757 if (lb
!= low_bound
)
4759 TREE_PURPOSE (t
) = lb
;
4764 else if (TREE_CODE (type
) == POINTER_TYPE
)
4766 if (length
== NULL_TREE
)
4768 error_at (OMP_CLAUSE_LOCATION (c
),
4769 "for pointer type length expression must be specified");
4770 return error_mark_node
;
4772 if (length
!= NULL_TREE
4773 && TREE_CODE (length
) == INTEGER_CST
4774 && tree_int_cst_sgn (length
) == -1)
4776 error_at (OMP_CLAUSE_LOCATION (c
),
4777 "negative length in array section in %qs clause",
4778 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4779 return error_mark_node
;
4781 /* If there is a pointer type anywhere but in the very first
4782 array-section-subscript, the array section can't be contiguous. */
4783 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4784 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
4786 error_at (OMP_CLAUSE_LOCATION (c
),
4787 "array section is not contiguous in %qs clause",
4788 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4789 return error_mark_node
;
4794 error_at (OMP_CLAUSE_LOCATION (c
),
4795 "%qE does not have pointer or array type", ret
);
4796 return error_mark_node
;
4798 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4799 types
.safe_push (TREE_TYPE (ret
));
4800 /* We will need to evaluate lb more than once. */
4801 tree lb
= cp_save_expr (low_bound
);
4802 if (lb
!= low_bound
)
4804 TREE_PURPOSE (t
) = lb
;
4807 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
4811 /* Handle array sections for clause C. */
4814 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
4816 bool maybe_zero_len
= false;
4817 unsigned int first_non_one
= 0;
4818 auto_vec
<tree
, 10> types
;
4819 tree first
= handle_omp_array_sections_1 (c
, OMP_CLAUSE_DECL (c
), types
,
4820 maybe_zero_len
, first_non_one
,
4822 if (first
== error_mark_node
)
4824 if (first
== NULL_TREE
)
4826 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
4828 tree t
= OMP_CLAUSE_DECL (c
);
4829 tree tem
= NULL_TREE
;
4830 if (processing_template_decl
)
4832 /* Need to evaluate side effects in the length expressions
4834 while (TREE_CODE (t
) == TREE_LIST
)
4836 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
4838 if (tem
== NULL_TREE
)
4839 tem
= TREE_VALUE (t
);
4841 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
4842 TREE_VALUE (t
), tem
);
4847 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
4848 OMP_CLAUSE_DECL (c
) = first
;
4852 unsigned int num
= types
.length (), i
;
4853 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
4854 tree condition
= NULL_TREE
;
4856 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
4857 maybe_zero_len
= true;
4858 if (processing_template_decl
&& maybe_zero_len
)
4861 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
4864 tree low_bound
= TREE_PURPOSE (t
);
4865 tree length
= TREE_VALUE (t
);
4869 && TREE_CODE (low_bound
) == INTEGER_CST
4870 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4871 > TYPE_PRECISION (sizetype
))
4872 low_bound
= fold_convert (sizetype
, low_bound
);
4874 && TREE_CODE (length
) == INTEGER_CST
4875 && TYPE_PRECISION (TREE_TYPE (length
))
4876 > TYPE_PRECISION (sizetype
))
4877 length
= fold_convert (sizetype
, length
);
4878 if (low_bound
== NULL_TREE
)
4879 low_bound
= integer_zero_node
;
4880 if (!maybe_zero_len
&& i
> first_non_one
)
4882 if (integer_nonzerop (low_bound
))
4883 goto do_warn_noncontiguous
;
4884 if (length
!= NULL_TREE
4885 && TREE_CODE (length
) == INTEGER_CST
4886 && TYPE_DOMAIN (types
[i
])
4887 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
4888 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
4892 size
= size_binop (PLUS_EXPR
,
4893 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4895 if (!tree_int_cst_equal (length
, size
))
4897 do_warn_noncontiguous
:
4898 error_at (OMP_CLAUSE_LOCATION (c
),
4899 "array section is not contiguous in %qs "
4901 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4905 if (!processing_template_decl
4906 && length
!= NULL_TREE
4907 && TREE_SIDE_EFFECTS (length
))
4909 if (side_effects
== NULL_TREE
)
4910 side_effects
= length
;
4912 side_effects
= build2 (COMPOUND_EXPR
,
4913 TREE_TYPE (side_effects
),
4914 length
, side_effects
);
4917 else if (processing_template_decl
)
4923 if (i
> first_non_one
4924 && ((length
&& integer_nonzerop (length
))
4925 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
))
4928 l
= fold_convert (sizetype
, length
);
4931 l
= size_binop (PLUS_EXPR
,
4932 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4934 l
= size_binop (MINUS_EXPR
, l
,
4935 fold_convert (sizetype
, low_bound
));
4937 if (i
> first_non_one
)
4939 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
4941 if (condition
== NULL_TREE
)
4944 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
4947 else if (size
== NULL_TREE
)
4949 size
= size_in_bytes (TREE_TYPE (types
[i
]));
4950 tree eltype
= TREE_TYPE (types
[num
- 1]);
4951 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4952 eltype
= TREE_TYPE (eltype
);
4953 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4954 size
= size_binop (EXACT_DIV_EXPR
, size
,
4955 size_in_bytes (eltype
));
4956 size
= size_binop (MULT_EXPR
, size
, l
);
4958 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
4959 size
, size_zero_node
);
4962 size
= size_binop (MULT_EXPR
, size
, l
);
4965 if (!processing_template_decl
)
4968 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
4969 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4971 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
4972 tree index_type
= build_index_type (size
);
4973 tree eltype
= TREE_TYPE (first
);
4974 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4975 eltype
= TREE_TYPE (eltype
);
4976 tree type
= build_array_type (eltype
, index_type
);
4977 tree ptype
= build_pointer_type (eltype
);
4978 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
4979 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
4980 t
= convert_from_reference (t
);
4981 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
4982 t
= build_fold_addr_expr (t
);
4983 tree t2
= build_fold_addr_expr (first
);
4984 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4985 ptrdiff_type_node
, t2
);
4986 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
4987 ptrdiff_type_node
, t2
,
4988 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4989 ptrdiff_type_node
, t
));
4990 if (tree_fits_shwi_p (t2
))
4991 t
= build2 (MEM_REF
, type
, t
,
4992 build_int_cst (ptype
, tree_to_shwi (t2
)));
4995 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4997 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
4998 TREE_TYPE (t
), t
, t2
);
4999 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5001 OMP_CLAUSE_DECL (c
) = t
;
5004 OMP_CLAUSE_DECL (c
) = first
;
5005 OMP_CLAUSE_SIZE (c
) = size
;
5006 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5007 || (TREE_CODE (t
) == COMPONENT_REF
5008 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5010 if (ort
== C_ORT_OMP
|| ort
== C_ORT_ACC
)
5011 switch (OMP_CLAUSE_MAP_KIND (c
))
5013 case GOMP_MAP_ALLOC
:
5016 case GOMP_MAP_TOFROM
:
5017 case GOMP_MAP_ALWAYS_TO
:
5018 case GOMP_MAP_ALWAYS_FROM
:
5019 case GOMP_MAP_ALWAYS_TOFROM
:
5020 case GOMP_MAP_RELEASE
:
5021 case GOMP_MAP_DELETE
:
5022 case GOMP_MAP_FORCE_TO
:
5023 case GOMP_MAP_FORCE_FROM
:
5024 case GOMP_MAP_FORCE_TOFROM
:
5025 case GOMP_MAP_FORCE_PRESENT
:
5026 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5031 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5033 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
&& ort
!= C_ORT_ACC
)
5034 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
5035 else if (TREE_CODE (t
) == COMPONENT_REF
)
5036 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5037 else if (REFERENCE_REF_P (t
)
5038 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5040 t
= TREE_OPERAND (t
, 0);
5041 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5044 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5045 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5046 && !cxx_mark_addressable (t
))
5048 OMP_CLAUSE_DECL (c2
) = t
;
5049 t
= build_fold_addr_expr (first
);
5050 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5051 ptrdiff_type_node
, t
);
5052 tree ptr
= OMP_CLAUSE_DECL (c2
);
5053 ptr
= convert_from_reference (ptr
);
5054 if (!POINTER_TYPE_P (TREE_TYPE (ptr
)))
5055 ptr
= build_fold_addr_expr (ptr
);
5056 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5057 ptrdiff_type_node
, t
,
5058 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5059 ptrdiff_type_node
, ptr
));
5060 OMP_CLAUSE_SIZE (c2
) = t
;
5061 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5062 OMP_CLAUSE_CHAIN (c
) = c2
;
5063 ptr
= OMP_CLAUSE_DECL (c2
);
5064 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5065 && TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
5066 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5068 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5070 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5071 OMP_CLAUSE_DECL (c3
) = ptr
;
5072 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
)
5073 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5075 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5076 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5077 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5078 OMP_CLAUSE_CHAIN (c2
) = c3
;
5085 /* Return identifier to look up for omp declare reduction. */
5088 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5090 const char *p
= NULL
;
5091 const char *m
= NULL
;
5092 switch (reduction_code
)
5100 case TRUTH_ANDIF_EXPR
:
5101 case TRUTH_ORIF_EXPR
:
5102 reduction_id
= ovl_op_identifier (false, reduction_code
);
5116 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5117 return error_mark_node
;
5118 p
= IDENTIFIER_POINTER (reduction_id
);
5121 if (type
!= NULL_TREE
)
5122 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5124 const char prefix
[] = "omp declare reduction ";
5125 size_t lenp
= sizeof (prefix
);
5126 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5128 size_t len
= strlen (p
);
5129 size_t lenm
= m
? strlen (m
) + 1 : 0;
5130 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5132 memcpy (name
, prefix
, lenp
- 1);
5133 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5136 name
[lenp
+ len
- 1] = '~';
5137 memcpy (name
+ lenp
+ len
, m
, lenm
);
5139 return get_identifier (name
);
5142 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5143 FUNCTION_DECL or NULL_TREE if not found. */
5146 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5147 vec
<tree
> *ambiguousp
)
5150 tree baselink
= NULL_TREE
;
5151 if (identifier_p (id
))
5154 bool nonint_cst_expression_p
;
5155 const char *error_msg
;
5156 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5157 tree decl
= lookup_name (id
);
5158 if (decl
== NULL_TREE
)
5159 decl
= error_mark_node
;
5160 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5161 &nonint_cst_expression_p
, false, true, false,
5162 false, &error_msg
, loc
);
5163 if (idk
== CP_ID_KIND_UNQUALIFIED
5164 && identifier_p (id
))
5166 vec
<tree
, va_gc
> *args
= NULL
;
5167 vec_safe_push (args
, build_reference_type (type
));
5168 id
= perform_koenig_lookup (id
, args
, tf_none
);
5171 else if (TREE_CODE (id
) == SCOPE_REF
)
5172 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5173 omp_reduction_id (ERROR_MARK
,
5174 TREE_OPERAND (id
, 1),
5179 if (fns
&& is_overloaded_fn (fns
))
5181 for (lkp_iterator
iter (get_fns (fns
)); iter
; ++iter
)
5183 tree fndecl
= *iter
;
5184 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5186 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5187 if (same_type_p (TREE_TYPE (argtype
), type
))
5195 if (id
&& BASELINK_P (fns
))
5204 if (!id
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5206 vec
<tree
> ambiguous
= vNULL
;
5207 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5209 if (ambiguousp
== NULL
)
5210 ambiguousp
= &ambiguous
;
5211 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5213 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5214 baselinkp
? baselinkp
: &baselink
,
5216 if (id
== NULL_TREE
)
5218 if (!ambiguousp
->is_empty ())
5219 ambiguousp
->safe_push (id
);
5220 else if (ret
!= NULL_TREE
)
5222 ambiguousp
->safe_push (ret
);
5223 ambiguousp
->safe_push (id
);
5229 if (ambiguousp
!= &ambiguous
)
5231 if (!ambiguous
.is_empty ())
5233 const char *str
= _("candidates are:");
5236 error_at (loc
, "user defined reduction lookup is ambiguous");
5237 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5239 inform (DECL_SOURCE_LOCATION (udr
), "%s %#qD", str
, udr
);
5241 str
= get_spaces (str
);
5243 ambiguous
.release ();
5244 ret
= error_mark_node
;
5245 baselink
= NULL_TREE
;
5250 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5251 id
, id
, tf_warning_or_error
);
5255 /* Helper function for cp_parser_omp_declare_reduction_exprs
5257 Remove CLEANUP_STMT for data (omp_priv variable).
5258 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5262 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5266 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5267 *tp
= CLEANUP_BODY (*tp
);
5268 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5270 tree decl
= DECL_EXPR_DECL (*tp
);
5271 if (!processing_template_decl
5272 && decl
== (tree
) data
5273 && DECL_INITIAL (decl
)
5274 && DECL_INITIAL (decl
) != error_mark_node
)
5276 tree list
= NULL_TREE
;
5277 append_to_statement_list_force (*tp
, &list
);
5278 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5279 decl
, DECL_INITIAL (decl
));
5280 DECL_INITIAL (decl
) = NULL_TREE
;
5281 append_to_statement_list_force (init_expr
, &list
);
5288 /* Data passed from cp_check_omp_declare_reduction to
5289 cp_check_omp_declare_reduction_r. */
5291 struct cp_check_omp_declare_reduction_data
5298 /* Helper function for cp_check_omp_declare_reduction, called via
5302 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5304 struct cp_check_omp_declare_reduction_data
*udr_data
5305 = (struct cp_check_omp_declare_reduction_data
*) data
;
5307 && !DECL_ARTIFICIAL (*tp
)
5308 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5309 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5311 location_t loc
= udr_data
->loc
;
5312 if (udr_data
->combiner_p
)
5313 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5314 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5317 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5318 "to variable %qD which is not %<omp_priv%> nor "
5326 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5329 cp_check_omp_declare_reduction (tree udr
)
5331 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5332 gcc_assert (TREE_CODE (type
) == REFERENCE_TYPE
);
5333 type
= TREE_TYPE (type
);
5335 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5337 if (type
== error_mark_node
)
5339 if (ARITHMETIC_TYPE_P (type
))
5341 static enum tree_code predef_codes
[]
5342 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5343 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5344 for (i
= 0; i
< 8; i
++)
5346 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5347 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5348 const char *n2
= IDENTIFIER_POINTER (id
);
5349 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5350 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5351 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5356 && TREE_CODE (type
) != COMPLEX_EXPR
)
5358 const char prefix_minmax
[] = "omp declare reduction m";
5359 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5360 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5361 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5362 prefix_minmax
, prefix_size
) == 0
5363 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5364 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5365 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5370 error_at (loc
, "predeclared arithmetic type %qT in "
5371 "%<#pragma omp declare reduction%>", type
);
5375 else if (TREE_CODE (type
) == FUNCTION_TYPE
5376 || TREE_CODE (type
) == METHOD_TYPE
5377 || TREE_CODE (type
) == ARRAY_TYPE
)
5379 error_at (loc
, "function or array type %qT in "
5380 "%<#pragma omp declare reduction%>", type
);
5383 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5385 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5389 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5391 error_at (loc
, "const, volatile or __restrict qualified type %qT in "
5392 "%<#pragma omp declare reduction%>", type
);
5396 tree body
= DECL_SAVED_TREE (udr
);
5397 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5400 tree_stmt_iterator tsi
;
5401 struct cp_check_omp_declare_reduction_data data
;
5402 memset (data
.stmts
, 0, sizeof data
.stmts
);
5403 for (i
= 0, tsi
= tsi_start (body
);
5404 i
< 7 && !tsi_end_p (tsi
);
5405 i
++, tsi_next (&tsi
))
5406 data
.stmts
[i
] = tsi_stmt (tsi
);
5408 gcc_assert (tsi_end_p (tsi
));
5411 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5412 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5413 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5415 data
.combiner_p
= true;
5416 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5418 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5422 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5423 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5424 data
.combiner_p
= false;
5425 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5427 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5428 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5429 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5431 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5435 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5436 an inline call. But, remap
5437 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5438 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5441 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5442 tree decl
, tree placeholder
)
5445 hash_map
<tree
, tree
> decl_map
;
5447 decl_map
.put (omp_decl1
, placeholder
);
5448 decl_map
.put (omp_decl2
, decl
);
5449 memset (&id
, 0, sizeof (id
));
5450 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5451 id
.dst_fn
= current_function_decl
;
5452 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5453 id
.decl_map
= &decl_map
;
5455 id
.copy_decl
= copy_decl_no_change
;
5456 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5457 id
.transform_new_cfg
= true;
5458 id
.transform_return_to_modify
= false;
5459 id
.transform_lang_insert_block
= NULL
;
5461 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5465 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5466 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5469 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5471 if (*tp
== (tree
) data
)
5476 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5477 Return true if there is some error and the clause should be removed. */
5480 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5482 tree t
= OMP_CLAUSE_DECL (c
);
5483 bool predefined
= false;
5484 if (TREE_CODE (t
) == TREE_LIST
)
5486 gcc_assert (processing_template_decl
);
5489 tree type
= TREE_TYPE (t
);
5490 if (TREE_CODE (t
) == MEM_REF
)
5491 type
= TREE_TYPE (type
);
5492 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5493 type
= TREE_TYPE (type
);
5494 if (TREE_CODE (type
) == ARRAY_TYPE
)
5497 gcc_assert (TREE_CODE (t
) != MEM_REF
);
5498 while (TREE_CODE (type
) == ARRAY_TYPE
)
5499 type
= TREE_TYPE (type
);
5500 if (!processing_template_decl
)
5502 t
= require_complete_type (t
);
5503 if (t
== error_mark_node
)
5505 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
5506 TYPE_SIZE_UNIT (type
));
5507 if (integer_zerop (size
))
5509 error ("%qE in %<reduction%> clause is a zero size array",
5510 omp_clause_printable_decl (t
));
5513 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5514 tree index_type
= build_index_type (size
);
5515 tree atype
= build_array_type (type
, index_type
);
5516 tree ptype
= build_pointer_type (type
);
5517 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5518 t
= build_fold_addr_expr (t
);
5519 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
5520 OMP_CLAUSE_DECL (c
) = t
;
5523 if (type
== error_mark_node
)
5525 else if (ARITHMETIC_TYPE_P (type
))
5526 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5535 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5542 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5546 case TRUTH_ANDIF_EXPR
:
5547 case TRUTH_ORIF_EXPR
:
5548 if (FLOAT_TYPE_P (type
))
5555 else if (TYPE_READONLY (type
))
5557 error ("%qE has const type for %<reduction%>",
5558 omp_clause_printable_decl (t
));
5561 else if (!processing_template_decl
)
5563 t
= require_complete_type (t
);
5564 if (t
== error_mark_node
)
5566 OMP_CLAUSE_DECL (c
) = t
;
5571 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5574 else if (processing_template_decl
)
5577 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5579 type
= TYPE_MAIN_VARIANT (type
);
5580 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5581 if (id
== NULL_TREE
)
5582 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5583 NULL_TREE
, NULL_TREE
);
5584 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5587 if (id
== error_mark_node
)
5590 tree body
= DECL_SAVED_TREE (id
);
5593 if (TREE_CODE (body
) == STATEMENT_LIST
)
5595 tree_stmt_iterator tsi
;
5596 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
5599 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5600 atype
= TREE_TYPE (atype
);
5601 bool need_static_cast
= !same_type_p (type
, atype
);
5602 memset (stmts
, 0, sizeof stmts
);
5603 for (i
= 0, tsi
= tsi_start (body
);
5604 i
< 7 && !tsi_end_p (tsi
);
5605 i
++, tsi_next (&tsi
))
5606 stmts
[i
] = tsi_stmt (tsi
);
5607 gcc_assert (tsi_end_p (tsi
));
5611 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
5612 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
5613 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
5614 DECL_ARTIFICIAL (placeholder
) = 1;
5615 DECL_IGNORED_P (placeholder
) = 1;
5616 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
5617 if (TREE_CODE (t
) == MEM_REF
)
5619 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
5621 DECL_ARTIFICIAL (decl_placeholder
) = 1;
5622 DECL_IGNORED_P (decl_placeholder
) = 1;
5623 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
5625 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
5626 cxx_mark_addressable (placeholder
);
5627 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
5628 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
5630 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5631 : OMP_CLAUSE_DECL (c
));
5632 tree omp_out
= placeholder
;
5633 tree omp_in
= decl_placeholder
? decl_placeholder
5634 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5635 if (need_static_cast
)
5637 tree rtype
= build_reference_type (atype
);
5638 omp_out
= build_static_cast (rtype
, omp_out
,
5639 tf_warning_or_error
);
5640 omp_in
= build_static_cast (rtype
, omp_in
,
5641 tf_warning_or_error
);
5642 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
5644 omp_out
= convert_from_reference (omp_out
);
5645 omp_in
= convert_from_reference (omp_in
);
5647 OMP_CLAUSE_REDUCTION_MERGE (c
)
5648 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
5649 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
5653 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
5654 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
5655 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3])))
5656 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5657 : OMP_CLAUSE_DECL (c
));
5658 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
5659 cxx_mark_addressable (placeholder
);
5660 tree omp_priv
= decl_placeholder
? decl_placeholder
5661 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5662 tree omp_orig
= placeholder
;
5663 if (need_static_cast
)
5667 error_at (OMP_CLAUSE_LOCATION (c
),
5668 "user defined reduction with constructor "
5669 "initializer for base class %qT", atype
);
5672 tree rtype
= build_reference_type (atype
);
5673 omp_priv
= build_static_cast (rtype
, omp_priv
,
5674 tf_warning_or_error
);
5675 omp_orig
= build_static_cast (rtype
, omp_orig
,
5676 tf_warning_or_error
);
5677 if (omp_priv
== error_mark_node
5678 || omp_orig
== error_mark_node
)
5680 omp_priv
= convert_from_reference (omp_priv
);
5681 omp_orig
= convert_from_reference (omp_orig
);
5684 *need_default_ctor
= true;
5685 OMP_CLAUSE_REDUCTION_INIT (c
)
5686 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
5687 DECL_EXPR_DECL (stmts
[3]),
5688 omp_priv
, omp_orig
);
5689 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
5690 find_omp_placeholder_r
, placeholder
, NULL
))
5691 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
5695 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
5696 *need_default_ctor
= true;
5700 tree v
= decl_placeholder
? decl_placeholder
5701 : convert_from_reference (t
);
5702 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
5703 init
= build_constructor (TREE_TYPE (v
), NULL
);
5705 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
5706 OMP_CLAUSE_REDUCTION_INIT (c
)
5707 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
5712 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5716 error ("user defined reduction not found for %qE",
5717 omp_clause_printable_decl (t
));
5720 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
5721 gcc_assert (TYPE_SIZE_UNIT (type
)
5722 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
5726 /* Called from finish_struct_1. linear(this) or linear(this:step)
5727 clauses might not be finalized yet because the class has been incomplete
5728 when parsing #pragma omp declare simd methods. Fix those up now. */
5731 finish_omp_declare_simd_methods (tree t
)
5733 if (processing_template_decl
)
5736 for (tree x
= TYPE_FIELDS (t
); x
; x
= DECL_CHAIN (x
))
5738 if (TREE_CODE (TREE_TYPE (x
)) != METHOD_TYPE
)
5740 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
5741 if (!ods
|| !TREE_VALUE (ods
))
5743 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
5744 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
5745 && integer_zerop (OMP_CLAUSE_DECL (c
))
5746 && OMP_CLAUSE_LINEAR_STEP (c
)
5747 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
)))
5750 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
5751 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
5752 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
5753 sizetype
, s
, TYPE_SIZE_UNIT (t
));
5754 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
5759 /* Adjust sink depend clause to take into account pointer offsets.
5761 Return TRUE if there was a problem processing the offset, and the
5762 whole clause should be removed. */
5765 cp_finish_omp_clause_depend_sink (tree sink_clause
)
5767 tree t
= OMP_CLAUSE_DECL (sink_clause
);
5768 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
5770 /* Make sure we don't adjust things twice for templates. */
5771 if (processing_template_decl
)
5774 for (; t
; t
= TREE_CHAIN (t
))
5776 tree decl
= TREE_VALUE (t
);
5777 if (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
5779 tree offset
= TREE_PURPOSE (t
);
5780 bool neg
= wi::neg_p (wi::to_wide (offset
));
5781 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
5782 decl
= mark_rvalue_use (decl
);
5783 decl
= convert_from_reference (decl
);
5784 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
5785 neg
? MINUS_EXPR
: PLUS_EXPR
,
5787 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
5788 MINUS_EXPR
, sizetype
,
5789 fold_convert (sizetype
, t2
),
5790 fold_convert (sizetype
, decl
));
5791 if (t2
== error_mark_node
)
5793 TREE_PURPOSE (t
) = t2
;
5799 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
5800 Remove any elements from the list that are invalid. */
5803 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
5805 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
5806 bitmap_head aligned_head
, map_head
, map_field_head
, oacc_reduction_head
;
5808 tree safelen
= NULL_TREE
;
5809 bool branch_seen
= false;
5810 bool copyprivate_seen
= false;
5811 bool ordered_seen
= false;
5812 bool oacc_async
= false;
5814 bitmap_obstack_initialize (NULL
);
5815 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
5816 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
5817 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
5818 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
5819 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
5820 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
5821 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
5823 if (ort
& C_ORT_ACC
)
5824 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
5825 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
5831 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
5833 bool remove
= false;
5834 bool field_ok
= false;
5836 switch (OMP_CLAUSE_CODE (c
))
5838 case OMP_CLAUSE_SHARED
:
5839 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5840 goto check_dup_generic
;
5841 case OMP_CLAUSE_PRIVATE
:
5842 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5843 goto check_dup_generic
;
5844 case OMP_CLAUSE_REDUCTION
:
5845 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5846 t
= OMP_CLAUSE_DECL (c
);
5847 if (TREE_CODE (t
) == TREE_LIST
)
5849 if (handle_omp_array_sections (c
, ort
))
5854 if (TREE_CODE (t
) == TREE_LIST
)
5856 while (TREE_CODE (t
) == TREE_LIST
)
5861 gcc_assert (TREE_CODE (t
) == MEM_REF
);
5862 t
= TREE_OPERAND (t
, 0);
5863 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
5864 t
= TREE_OPERAND (t
, 0);
5865 if (TREE_CODE (t
) == ADDR_EXPR
5866 || TREE_CODE (t
) == INDIRECT_REF
)
5867 t
= TREE_OPERAND (t
, 0);
5869 tree n
= omp_clause_decl_field (t
);
5872 goto check_dup_generic_t
;
5875 cxx_mark_addressable (t
);
5876 goto check_dup_generic
;
5877 case OMP_CLAUSE_COPYPRIVATE
:
5878 copyprivate_seen
= true;
5879 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5880 goto check_dup_generic
;
5881 case OMP_CLAUSE_COPYIN
:
5882 goto check_dup_generic
;
5883 case OMP_CLAUSE_LINEAR
:
5884 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5885 t
= OMP_CLAUSE_DECL (c
);
5886 if (ort
!= C_ORT_OMP_DECLARE_SIMD
5887 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
5889 error_at (OMP_CLAUSE_LOCATION (c
),
5890 "modifier should not be specified in %<linear%> "
5891 "clause on %<simd%> or %<for%> constructs");
5892 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
5894 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
5895 && !type_dependent_expression_p (t
))
5897 tree type
= TREE_TYPE (t
);
5898 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5899 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
5900 && TREE_CODE (type
) != REFERENCE_TYPE
)
5902 error ("linear clause with %qs modifier applied to "
5903 "non-reference variable with %qT type",
5904 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5905 ? "ref" : "uval", TREE_TYPE (t
));
5909 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5910 type
= TREE_TYPE (type
);
5911 if (ort
== C_ORT_CILK
)
5913 if (!INTEGRAL_TYPE_P (type
)
5914 && !SCALAR_FLOAT_TYPE_P (type
)
5915 && TREE_CODE (type
) != POINTER_TYPE
)
5917 error ("linear clause applied to non-integral, "
5918 "non-floating, non-pointer variable with %qT type",
5924 else if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
5926 if (!INTEGRAL_TYPE_P (type
)
5927 && TREE_CODE (type
) != POINTER_TYPE
)
5929 error ("linear clause applied to non-integral non-pointer"
5930 " variable with %qT type", TREE_TYPE (t
));
5936 t
= OMP_CLAUSE_LINEAR_STEP (c
);
5938 t
= integer_one_node
;
5939 if (t
== error_mark_node
)
5944 else if (!type_dependent_expression_p (t
)
5945 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
5946 && (ort
!= C_ORT_OMP_DECLARE_SIMD
5947 || TREE_CODE (t
) != PARM_DECL
5948 || TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
5949 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
5951 error ("linear step expression must be integral");
5957 t
= mark_rvalue_use (t
);
5958 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
5960 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
5961 goto check_dup_generic
;
5963 if (!processing_template_decl
5964 && (VAR_P (OMP_CLAUSE_DECL (c
))
5965 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
5967 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
5969 t
= maybe_constant_value (t
);
5970 if (TREE_CODE (t
) != INTEGER_CST
)
5972 error_at (OMP_CLAUSE_LOCATION (c
),
5973 "%<linear%> clause step %qE is neither "
5974 "constant nor a parameter", t
);
5979 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5980 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
5981 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5982 type
= TREE_TYPE (type
);
5983 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
5985 type
= build_pointer_type (type
);
5986 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
5987 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
5989 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
5990 MINUS_EXPR
, sizetype
,
5991 fold_convert (sizetype
, t
),
5992 fold_convert (sizetype
, d
));
5993 if (t
== error_mark_node
)
5999 else if (TREE_CODE (type
) == POINTER_TYPE
6000 /* Can't multiply the step yet if *this
6001 is still incomplete type. */
6002 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6003 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
6004 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
6005 || DECL_NAME (OMP_CLAUSE_DECL (c
))
6007 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
6009 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
6010 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6012 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6013 MINUS_EXPR
, sizetype
,
6014 fold_convert (sizetype
, t
),
6015 fold_convert (sizetype
, d
));
6016 if (t
== error_mark_node
)
6023 t
= fold_convert (type
, t
);
6025 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6027 goto check_dup_generic
;
6029 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6032 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6033 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6036 t
= OMP_CLAUSE_DECL (c
);
6037 check_dup_generic_t
:
6038 if (t
== current_class_ptr
6039 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6040 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6041 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6043 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6048 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6049 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6051 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6054 error ("%qD is not a variable in clause %qs", t
,
6055 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6057 error ("%qE is not a variable in clause %qs", t
,
6058 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6061 else if (ort
== C_ORT_ACC
6062 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
6064 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
6066 error ("%qD appears more than once in reduction clauses", t
);
6070 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
6072 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6073 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6074 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6076 error ("%qD appears more than once in data clauses", t
);
6079 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6080 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6082 if (ort
== C_ORT_ACC
)
6083 error ("%qD appears more than once in data clauses", t
);
6085 error ("%qD appears both in data and map clauses", t
);
6089 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6094 && TREE_CODE (t
) == FIELD_DECL
6095 && t
== OMP_CLAUSE_DECL (c
)
6096 && ort
!= C_ORT_ACC
)
6099 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
6100 == OMP_CLAUSE_SHARED
));
6101 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
6106 case OMP_CLAUSE_FIRSTPRIVATE
:
6107 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6109 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6111 t
= OMP_CLAUSE_DECL (c
);
6112 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6114 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6119 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6120 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6121 || TREE_CODE (t
) != FIELD_DECL
))
6123 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6126 error ("%qD is not a variable in clause %<firstprivate%>", t
);
6128 error ("%qE is not a variable in clause %<firstprivate%>", t
);
6131 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6132 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6134 error ("%qD appears more than once in data clauses", t
);
6137 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6139 if (ort
== C_ORT_ACC
)
6140 error ("%qD appears more than once in data clauses", t
);
6142 error ("%qD appears both in data and map clauses", t
);
6146 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
6147 goto handle_field_decl
;
6149 case OMP_CLAUSE_LASTPRIVATE
:
6150 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6152 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6154 t
= OMP_CLAUSE_DECL (c
);
6155 if (t
== current_class_ptr
)
6157 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6162 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6163 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6164 || TREE_CODE (t
) != FIELD_DECL
))
6166 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6169 error ("%qD is not a variable in clause %<lastprivate%>", t
);
6171 error ("%qE is not a variable in clause %<lastprivate%>", t
);
6174 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6175 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6177 error ("%qD appears more than once in data clauses", t
);
6181 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
6182 goto handle_field_decl
;
6185 t
= OMP_CLAUSE_IF_EXPR (c
);
6186 t
= maybe_convert_cond (t
);
6187 if (t
== error_mark_node
)
6189 else if (!processing_template_decl
)
6190 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6191 OMP_CLAUSE_IF_EXPR (c
) = t
;
6194 case OMP_CLAUSE_FINAL
:
6195 t
= OMP_CLAUSE_FINAL_EXPR (c
);
6196 t
= maybe_convert_cond (t
);
6197 if (t
== error_mark_node
)
6199 else if (!processing_template_decl
)
6200 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6201 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
6204 case OMP_CLAUSE_GANG
:
6205 /* Operand 1 is the gang static: argument. */
6206 t
= OMP_CLAUSE_OPERAND (c
, 1);
6209 if (t
== error_mark_node
)
6211 else if (!type_dependent_expression_p (t
)
6212 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6214 error ("%<gang%> static expression must be integral");
6219 t
= mark_rvalue_use (t
);
6220 if (!processing_template_decl
)
6222 t
= maybe_constant_value (t
);
6223 if (TREE_CODE (t
) == INTEGER_CST
6224 && tree_int_cst_sgn (t
) != 1
6225 && t
!= integer_minus_one_node
)
6227 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6228 "%<gang%> static value must be "
6230 t
= integer_one_node
;
6232 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6235 OMP_CLAUSE_OPERAND (c
, 1) = t
;
6237 /* Check operand 0, the num argument. */
6240 case OMP_CLAUSE_WORKER
:
6241 case OMP_CLAUSE_VECTOR
:
6242 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
6246 case OMP_CLAUSE_NUM_TASKS
:
6247 case OMP_CLAUSE_NUM_TEAMS
:
6248 case OMP_CLAUSE_NUM_THREADS
:
6249 case OMP_CLAUSE_NUM_GANGS
:
6250 case OMP_CLAUSE_NUM_WORKERS
:
6251 case OMP_CLAUSE_VECTOR_LENGTH
:
6252 t
= OMP_CLAUSE_OPERAND (c
, 0);
6253 if (t
== error_mark_node
)
6255 else if (!type_dependent_expression_p (t
)
6256 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6258 switch (OMP_CLAUSE_CODE (c
))
6260 case OMP_CLAUSE_GANG
:
6261 error_at (OMP_CLAUSE_LOCATION (c
),
6262 "%<gang%> num expression must be integral"); break;
6263 case OMP_CLAUSE_VECTOR
:
6264 error_at (OMP_CLAUSE_LOCATION (c
),
6265 "%<vector%> length expression must be integral");
6267 case OMP_CLAUSE_WORKER
:
6268 error_at (OMP_CLAUSE_LOCATION (c
),
6269 "%<worker%> num expression must be integral");
6272 error_at (OMP_CLAUSE_LOCATION (c
),
6273 "%qs expression must be integral",
6274 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6280 t
= mark_rvalue_use (t
);
6281 if (!processing_template_decl
)
6283 t
= maybe_constant_value (t
);
6284 if (TREE_CODE (t
) == INTEGER_CST
6285 && tree_int_cst_sgn (t
) != 1)
6287 switch (OMP_CLAUSE_CODE (c
))
6289 case OMP_CLAUSE_GANG
:
6290 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6291 "%<gang%> num value must be positive");
6293 case OMP_CLAUSE_VECTOR
:
6294 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6295 "%<vector%> length value must be "
6298 case OMP_CLAUSE_WORKER
:
6299 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6300 "%<worker%> num value must be "
6304 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6305 "%qs value must be positive",
6306 omp_clause_code_name
6307 [OMP_CLAUSE_CODE (c
)]);
6309 t
= integer_one_node
;
6311 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6313 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6317 case OMP_CLAUSE_SCHEDULE
:
6318 if (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
)
6320 const char *p
= NULL
;
6321 switch (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_MASK
)
6323 case OMP_CLAUSE_SCHEDULE_STATIC
: p
= "static"; break;
6324 case OMP_CLAUSE_SCHEDULE_DYNAMIC
: break;
6325 case OMP_CLAUSE_SCHEDULE_GUIDED
: break;
6326 case OMP_CLAUSE_SCHEDULE_AUTO
: p
= "auto"; break;
6327 case OMP_CLAUSE_SCHEDULE_RUNTIME
: p
= "runtime"; break;
6328 default: gcc_unreachable ();
6332 error_at (OMP_CLAUSE_LOCATION (c
),
6333 "%<nonmonotonic%> modifier specified for %qs "
6334 "schedule kind", p
);
6335 OMP_CLAUSE_SCHEDULE_KIND (c
)
6336 = (enum omp_clause_schedule_kind
)
6337 (OMP_CLAUSE_SCHEDULE_KIND (c
)
6338 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
6342 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
6345 else if (t
== error_mark_node
)
6347 else if (!type_dependent_expression_p (t
)
6348 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
6349 != OMP_CLAUSE_SCHEDULE_CILKFOR
)
6350 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6352 error ("schedule chunk size expression must be integral");
6357 t
= mark_rvalue_use (t
);
6358 if (!processing_template_decl
)
6360 if (OMP_CLAUSE_SCHEDULE_KIND (c
)
6361 == OMP_CLAUSE_SCHEDULE_CILKFOR
)
6363 t
= convert_to_integer (long_integer_type_node
, t
);
6364 if (t
== error_mark_node
)
6372 t
= maybe_constant_value (t
);
6373 if (TREE_CODE (t
) == INTEGER_CST
6374 && tree_int_cst_sgn (t
) != 1)
6376 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6377 "chunk size value must be positive");
6378 t
= integer_one_node
;
6381 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6383 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
6387 case OMP_CLAUSE_SIMDLEN
:
6388 case OMP_CLAUSE_SAFELEN
:
6389 t
= OMP_CLAUSE_OPERAND (c
, 0);
6390 if (t
== error_mark_node
)
6392 else if (!type_dependent_expression_p (t
)
6393 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6395 error ("%qs length expression must be integral",
6396 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6401 t
= mark_rvalue_use (t
);
6402 if (!processing_template_decl
)
6404 t
= maybe_constant_value (t
);
6405 if (TREE_CODE (t
) != INTEGER_CST
6406 || tree_int_cst_sgn (t
) != 1)
6408 error ("%qs length expression must be positive constant"
6409 " integer expression",
6410 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6414 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6415 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
6420 case OMP_CLAUSE_ASYNC
:
6421 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
6422 if (t
== error_mark_node
)
6424 else if (!type_dependent_expression_p (t
)
6425 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6427 error ("%<async%> expression must be integral");
6432 t
= mark_rvalue_use (t
);
6433 if (!processing_template_decl
)
6434 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6435 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
6439 case OMP_CLAUSE_WAIT
:
6440 t
= OMP_CLAUSE_WAIT_EXPR (c
);
6441 if (t
== error_mark_node
)
6443 else if (!processing_template_decl
)
6444 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6445 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
6448 case OMP_CLAUSE_THREAD_LIMIT
:
6449 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
6450 if (t
== error_mark_node
)
6452 else if (!type_dependent_expression_p (t
)
6453 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6455 error ("%<thread_limit%> expression must be integral");
6460 t
= mark_rvalue_use (t
);
6461 if (!processing_template_decl
)
6463 t
= maybe_constant_value (t
);
6464 if (TREE_CODE (t
) == INTEGER_CST
6465 && tree_int_cst_sgn (t
) != 1)
6467 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6468 "%<thread_limit%> value must be positive");
6469 t
= integer_one_node
;
6471 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6473 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
6477 case OMP_CLAUSE_DEVICE
:
6478 t
= OMP_CLAUSE_DEVICE_ID (c
);
6479 if (t
== error_mark_node
)
6481 else if (!type_dependent_expression_p (t
)
6482 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6484 error ("%<device%> id must be integral");
6489 t
= mark_rvalue_use (t
);
6490 if (!processing_template_decl
)
6491 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6492 OMP_CLAUSE_DEVICE_ID (c
) = t
;
6496 case OMP_CLAUSE_DIST_SCHEDULE
:
6497 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
6500 else if (t
== error_mark_node
)
6502 else if (!type_dependent_expression_p (t
)
6503 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6505 error ("%<dist_schedule%> chunk size expression must be "
6511 t
= mark_rvalue_use (t
);
6512 if (!processing_template_decl
)
6513 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6514 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
6518 case OMP_CLAUSE_ALIGNED
:
6519 t
= OMP_CLAUSE_DECL (c
);
6520 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
6522 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6527 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6529 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6532 error ("%qD is not a variable in %<aligned%> clause", t
);
6534 error ("%qE is not a variable in %<aligned%> clause", t
);
6537 else if (!type_dependent_expression_p (t
)
6538 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
6539 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
6540 && (TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6541 || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
6542 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
6545 error_at (OMP_CLAUSE_LOCATION (c
),
6546 "%qE in %<aligned%> clause is neither a pointer nor "
6547 "an array nor a reference to pointer or array", t
);
6550 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
6552 error ("%qD appears more than once in %<aligned%> clauses", t
);
6556 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
6557 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
6558 if (t
== error_mark_node
)
6560 else if (t
== NULL_TREE
)
6562 else if (!type_dependent_expression_p (t
)
6563 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6565 error ("%<aligned%> clause alignment expression must "
6571 t
= mark_rvalue_use (t
);
6572 if (!processing_template_decl
)
6574 t
= maybe_constant_value (t
);
6575 if (TREE_CODE (t
) != INTEGER_CST
6576 || tree_int_cst_sgn (t
) != 1)
6578 error ("%<aligned%> clause alignment expression must be "
6579 "positive constant integer expression");
6583 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
6587 case OMP_CLAUSE_DEPEND
:
6588 t
= OMP_CLAUSE_DECL (c
);
6591 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
6592 == OMP_CLAUSE_DEPEND_SOURCE
);
6595 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
6597 if (cp_finish_omp_clause_depend_sink (c
))
6601 if (TREE_CODE (t
) == TREE_LIST
)
6603 if (handle_omp_array_sections (c
, ort
))
6607 if (t
== error_mark_node
)
6609 else if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6611 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6614 error ("%qD is not a variable in %<depend%> clause", t
);
6616 error ("%qE is not a variable in %<depend%> clause", t
);
6619 else if (t
== current_class_ptr
)
6621 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6625 else if (!processing_template_decl
6626 && !cxx_mark_addressable (t
))
6630 case OMP_CLAUSE_MAP
:
6632 case OMP_CLAUSE_FROM
:
6633 case OMP_CLAUSE__CACHE_
:
6634 t
= OMP_CLAUSE_DECL (c
);
6635 if (TREE_CODE (t
) == TREE_LIST
)
6637 if (handle_omp_array_sections (c
, ort
))
6641 t
= OMP_CLAUSE_DECL (c
);
6642 if (TREE_CODE (t
) != TREE_LIST
6643 && !type_dependent_expression_p (t
)
6644 && !cp_omp_mappable_type (TREE_TYPE (t
)))
6646 error_at (OMP_CLAUSE_LOCATION (c
),
6647 "array section does not have mappable type "
6649 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6652 while (TREE_CODE (t
) == ARRAY_REF
)
6653 t
= TREE_OPERAND (t
, 0);
6654 if (TREE_CODE (t
) == COMPONENT_REF
6655 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6657 while (TREE_CODE (t
) == COMPONENT_REF
)
6658 t
= TREE_OPERAND (t
, 0);
6659 if (REFERENCE_REF_P (t
))
6660 t
= TREE_OPERAND (t
, 0);
6661 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6663 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6665 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6666 error ("%qD appears more than once in motion"
6668 else if (ort
== C_ORT_ACC
)
6669 error ("%qD appears more than once in data"
6672 error ("%qD appears more than once in map"
6678 bitmap_set_bit (&map_head
, DECL_UID (t
));
6679 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6685 if (t
== error_mark_node
)
6690 if (REFERENCE_REF_P (t
)
6691 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
6693 t
= TREE_OPERAND (t
, 0);
6694 OMP_CLAUSE_DECL (c
) = t
;
6696 if (TREE_CODE (t
) == COMPONENT_REF
6697 && (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
6698 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
6700 if (type_dependent_expression_p (t
))
6702 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
6703 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
6705 error_at (OMP_CLAUSE_LOCATION (c
),
6706 "bit-field %qE in %qs clause",
6707 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6710 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6712 error_at (OMP_CLAUSE_LOCATION (c
),
6713 "%qE does not have a mappable type in %qs clause",
6714 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6717 while (TREE_CODE (t
) == COMPONENT_REF
)
6719 if (TREE_TYPE (TREE_OPERAND (t
, 0))
6720 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
6723 error_at (OMP_CLAUSE_LOCATION (c
),
6724 "%qE is a member of a union", t
);
6728 t
= TREE_OPERAND (t
, 0);
6732 if (REFERENCE_REF_P (t
))
6733 t
= TREE_OPERAND (t
, 0);
6734 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6736 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6737 goto handle_map_references
;
6740 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6742 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6744 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6745 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6746 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
))
6749 error ("%qD is not a variable in %qs clause", t
,
6750 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6752 error ("%qE is not a variable in %qs clause", t
,
6753 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6756 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
6758 error ("%qD is threadprivate variable in %qs clause", t
,
6759 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6762 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6764 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6769 else if (!processing_template_decl
6770 && TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6771 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
6772 || (OMP_CLAUSE_MAP_KIND (c
)
6773 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
6774 && !cxx_mark_addressable (t
))
6776 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6777 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6778 || (OMP_CLAUSE_MAP_KIND (c
)
6779 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
6780 && t
== OMP_CLAUSE_DECL (c
)
6781 && !type_dependent_expression_p (t
)
6782 && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t
))
6784 ? TREE_TYPE (TREE_TYPE (t
))
6787 error_at (OMP_CLAUSE_LOCATION (c
),
6788 "%qD does not have a mappable type in %qs clause", t
,
6789 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6792 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6793 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
6794 && !type_dependent_expression_p (t
)
6795 && !POINTER_TYPE_P (TREE_TYPE (t
)))
6797 error ("%qD is not a pointer variable", t
);
6800 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6801 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
6803 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6804 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6806 error ("%qD appears more than once in data clauses", t
);
6809 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6811 if (ort
== C_ORT_ACC
)
6812 error ("%qD appears more than once in data clauses", t
);
6814 error ("%qD appears both in data and map clauses", t
);
6818 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6820 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6822 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6823 error ("%qD appears more than once in motion clauses", t
);
6824 if (ort
== C_ORT_ACC
)
6825 error ("%qD appears more than once in data clauses", t
);
6827 error ("%qD appears more than once in map clauses", t
);
6830 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6831 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6833 if (ort
== C_ORT_ACC
)
6834 error ("%qD appears more than once in data clauses", t
);
6836 error ("%qD appears both in data and map clauses", t
);
6841 bitmap_set_bit (&map_head
, DECL_UID (t
));
6842 if (t
!= OMP_CLAUSE_DECL (c
)
6843 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
6844 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6846 handle_map_references
:
6848 && !processing_template_decl
6849 && (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
6850 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
))) == REFERENCE_TYPE
)
6852 t
= OMP_CLAUSE_DECL (c
);
6853 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6855 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6856 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6858 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6860 else if (OMP_CLAUSE_MAP_KIND (c
)
6861 != GOMP_MAP_FIRSTPRIVATE_POINTER
6862 && (OMP_CLAUSE_MAP_KIND (c
)
6863 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
6864 && (OMP_CLAUSE_MAP_KIND (c
)
6865 != GOMP_MAP_ALWAYS_POINTER
))
6867 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
6869 if (TREE_CODE (t
) == COMPONENT_REF
)
6870 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
6872 OMP_CLAUSE_SET_MAP_KIND (c2
,
6873 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
6874 OMP_CLAUSE_DECL (c2
) = t
;
6875 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
6876 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
6877 OMP_CLAUSE_CHAIN (c
) = c2
;
6878 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6879 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6881 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6887 case OMP_CLAUSE_TO_DECLARE
:
6888 case OMP_CLAUSE_LINK
:
6889 t
= OMP_CLAUSE_DECL (c
);
6890 if (TREE_CODE (t
) == FUNCTION_DECL
6891 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6893 else if (!VAR_P (t
))
6895 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6897 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
6898 error_at (OMP_CLAUSE_LOCATION (c
),
6899 "template %qE in clause %qs", t
,
6900 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6901 else if (really_overloaded_fn (t
))
6902 error_at (OMP_CLAUSE_LOCATION (c
),
6903 "overloaded function name %qE in clause %qs", t
,
6904 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6906 error_at (OMP_CLAUSE_LOCATION (c
),
6907 "%qE is neither a variable nor a function name "
6909 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6912 error_at (OMP_CLAUSE_LOCATION (c
),
6913 "%qE is not a variable in clause %qs", t
,
6914 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6917 else if (DECL_THREAD_LOCAL_P (t
))
6919 error_at (OMP_CLAUSE_LOCATION (c
),
6920 "%qD is threadprivate variable in %qs clause", t
,
6921 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6924 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6926 error_at (OMP_CLAUSE_LOCATION (c
),
6927 "%qD does not have a mappable type in %qs clause", t
,
6928 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6933 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
6935 error_at (OMP_CLAUSE_LOCATION (c
),
6936 "%qE appears more than once on the same "
6937 "%<declare target%> directive", t
);
6941 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6944 case OMP_CLAUSE_UNIFORM
:
6945 t
= OMP_CLAUSE_DECL (c
);
6946 if (TREE_CODE (t
) != PARM_DECL
)
6948 if (processing_template_decl
)
6951 error ("%qD is not an argument in %<uniform%> clause", t
);
6953 error ("%qE is not an argument in %<uniform%> clause", t
);
6957 /* map_head bitmap is used as uniform_head if declare_simd. */
6958 bitmap_set_bit (&map_head
, DECL_UID (t
));
6959 goto check_dup_generic
;
6961 case OMP_CLAUSE_GRAINSIZE
:
6962 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
6963 if (t
== error_mark_node
)
6965 else if (!type_dependent_expression_p (t
)
6966 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6968 error ("%<grainsize%> expression must be integral");
6973 t
= mark_rvalue_use (t
);
6974 if (!processing_template_decl
)
6976 t
= maybe_constant_value (t
);
6977 if (TREE_CODE (t
) == INTEGER_CST
6978 && tree_int_cst_sgn (t
) != 1)
6980 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6981 "%<grainsize%> value must be positive");
6982 t
= integer_one_node
;
6984 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6986 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
6990 case OMP_CLAUSE_PRIORITY
:
6991 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
6992 if (t
== error_mark_node
)
6994 else if (!type_dependent_expression_p (t
)
6995 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6997 error ("%<priority%> expression must be integral");
7002 t
= mark_rvalue_use (t
);
7003 if (!processing_template_decl
)
7005 t
= maybe_constant_value (t
);
7006 if (TREE_CODE (t
) == INTEGER_CST
7007 && tree_int_cst_sgn (t
) == -1)
7009 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7010 "%<priority%> value must be non-negative");
7011 t
= integer_one_node
;
7013 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7015 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
7019 case OMP_CLAUSE_HINT
:
7020 t
= OMP_CLAUSE_HINT_EXPR (c
);
7021 if (t
== error_mark_node
)
7023 else if (!type_dependent_expression_p (t
)
7024 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7026 error ("%<num_tasks%> expression must be integral");
7031 t
= mark_rvalue_use (t
);
7032 if (!processing_template_decl
)
7034 t
= maybe_constant_value (t
);
7035 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7037 OMP_CLAUSE_HINT_EXPR (c
) = t
;
7041 case OMP_CLAUSE_IS_DEVICE_PTR
:
7042 case OMP_CLAUSE_USE_DEVICE_PTR
:
7043 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
7044 t
= OMP_CLAUSE_DECL (c
);
7045 if (!type_dependent_expression_p (t
))
7047 tree type
= TREE_TYPE (t
);
7048 if (TREE_CODE (type
) != POINTER_TYPE
7049 && TREE_CODE (type
) != ARRAY_TYPE
7050 && (TREE_CODE (type
) != REFERENCE_TYPE
7051 || (TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
7052 && TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
)))
7054 error_at (OMP_CLAUSE_LOCATION (c
),
7055 "%qs variable is neither a pointer, nor an array "
7056 "nor reference to pointer or array",
7057 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7061 goto check_dup_generic
;
7063 case OMP_CLAUSE_NOWAIT
:
7064 case OMP_CLAUSE_DEFAULT
:
7065 case OMP_CLAUSE_UNTIED
:
7066 case OMP_CLAUSE_COLLAPSE
:
7067 case OMP_CLAUSE_MERGEABLE
:
7068 case OMP_CLAUSE_PARALLEL
:
7069 case OMP_CLAUSE_FOR
:
7070 case OMP_CLAUSE_SECTIONS
:
7071 case OMP_CLAUSE_TASKGROUP
:
7072 case OMP_CLAUSE_PROC_BIND
:
7073 case OMP_CLAUSE_NOGROUP
:
7074 case OMP_CLAUSE_THREADS
:
7075 case OMP_CLAUSE_SIMD
:
7076 case OMP_CLAUSE_DEFAULTMAP
:
7077 case OMP_CLAUSE__CILK_FOR_COUNT_
:
7078 case OMP_CLAUSE_AUTO
:
7079 case OMP_CLAUSE_INDEPENDENT
:
7080 case OMP_CLAUSE_SEQ
:
7083 case OMP_CLAUSE_TILE
:
7084 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
7085 list
= TREE_CHAIN (list
))
7087 t
= TREE_VALUE (list
);
7089 if (t
== error_mark_node
)
7091 else if (!type_dependent_expression_p (t
)
7092 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7094 error_at (OMP_CLAUSE_LOCATION (c
),
7095 "%<tile%> argument needs integral type");
7100 t
= mark_rvalue_use (t
);
7101 if (!processing_template_decl
)
7103 /* Zero is used to indicate '*', we permit you
7104 to get there via an ICE of value zero. */
7105 t
= maybe_constant_value (t
);
7106 if (!tree_fits_shwi_p (t
)
7107 || tree_to_shwi (t
) < 0)
7109 error_at (OMP_CLAUSE_LOCATION (c
),
7110 "%<tile%> argument needs positive "
7111 "integral constant");
7114 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7118 /* Update list item. */
7119 TREE_VALUE (list
) = t
;
7123 case OMP_CLAUSE_ORDERED
:
7124 ordered_seen
= true;
7127 case OMP_CLAUSE_INBRANCH
:
7128 case OMP_CLAUSE_NOTINBRANCH
:
7131 error ("%<inbranch%> clause is incompatible with "
7143 *pc
= OMP_CLAUSE_CHAIN (c
);
7145 pc
= &OMP_CLAUSE_CHAIN (c
);
7148 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
7150 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
7151 bool remove
= false;
7152 bool need_complete_type
= false;
7153 bool need_default_ctor
= false;
7154 bool need_copy_ctor
= false;
7155 bool need_copy_assignment
= false;
7156 bool need_implicitly_determined
= false;
7157 bool need_dtor
= false;
7158 tree type
, inner_type
;
7162 case OMP_CLAUSE_SHARED
:
7163 need_implicitly_determined
= true;
7165 case OMP_CLAUSE_PRIVATE
:
7166 need_complete_type
= true;
7167 need_default_ctor
= true;
7169 need_implicitly_determined
= true;
7171 case OMP_CLAUSE_FIRSTPRIVATE
:
7172 need_complete_type
= true;
7173 need_copy_ctor
= true;
7175 need_implicitly_determined
= true;
7177 case OMP_CLAUSE_LASTPRIVATE
:
7178 need_complete_type
= true;
7179 need_copy_assignment
= true;
7180 need_implicitly_determined
= true;
7182 case OMP_CLAUSE_REDUCTION
:
7183 need_implicitly_determined
= true;
7185 case OMP_CLAUSE_LINEAR
:
7186 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
7187 need_implicitly_determined
= true;
7188 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
7189 && !bitmap_bit_p (&map_head
,
7190 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
7192 error_at (OMP_CLAUSE_LOCATION (c
),
7193 "%<linear%> clause step is a parameter %qD not "
7194 "specified in %<uniform%> clause",
7195 OMP_CLAUSE_LINEAR_STEP (c
));
7196 *pc
= OMP_CLAUSE_CHAIN (c
);
7200 case OMP_CLAUSE_COPYPRIVATE
:
7201 need_copy_assignment
= true;
7203 case OMP_CLAUSE_COPYIN
:
7204 need_copy_assignment
= true;
7206 case OMP_CLAUSE_SIMDLEN
:
7208 && !processing_template_decl
7209 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
7210 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
7212 error_at (OMP_CLAUSE_LOCATION (c
),
7213 "%<simdlen%> clause value is bigger than "
7214 "%<safelen%> clause value");
7215 OMP_CLAUSE_SIMDLEN_EXPR (c
)
7216 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
7218 pc
= &OMP_CLAUSE_CHAIN (c
);
7220 case OMP_CLAUSE_SCHEDULE
:
7222 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
7223 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
7225 error_at (OMP_CLAUSE_LOCATION (c
),
7226 "%<nonmonotonic%> schedule modifier specified "
7227 "together with %<ordered%> clause");
7228 OMP_CLAUSE_SCHEDULE_KIND (c
)
7229 = (enum omp_clause_schedule_kind
)
7230 (OMP_CLAUSE_SCHEDULE_KIND (c
)
7231 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
7233 pc
= &OMP_CLAUSE_CHAIN (c
);
7235 case OMP_CLAUSE_NOWAIT
:
7236 if (copyprivate_seen
)
7238 error_at (OMP_CLAUSE_LOCATION (c
),
7239 "%<nowait%> clause must not be used together "
7240 "with %<copyprivate%>");
7241 *pc
= OMP_CLAUSE_CHAIN (c
);
7246 pc
= &OMP_CLAUSE_CHAIN (c
);
7250 t
= OMP_CLAUSE_DECL (c
);
7251 if (processing_template_decl
7252 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7254 pc
= &OMP_CLAUSE_CHAIN (c
);
7260 case OMP_CLAUSE_LASTPRIVATE
:
7261 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7263 need_default_ctor
= true;
7268 case OMP_CLAUSE_REDUCTION
:
7269 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
7273 t
= OMP_CLAUSE_DECL (c
);
7276 case OMP_CLAUSE_COPYIN
:
7277 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
7279 error ("%qE must be %<threadprivate%> for %<copyin%>", t
);
7288 if (need_complete_type
|| need_copy_assignment
)
7290 t
= require_complete_type (t
);
7291 if (t
== error_mark_node
)
7293 else if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
7294 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
7297 if (need_implicitly_determined
)
7299 const char *share_name
= NULL
;
7301 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7302 share_name
= "threadprivate";
7303 else switch (cxx_omp_predetermined_sharing (t
))
7305 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
7307 case OMP_CLAUSE_DEFAULT_SHARED
:
7308 /* const vars may be specified in firstprivate clause. */
7309 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
7310 && cxx_omp_const_qual_no_mutable (t
))
7312 share_name
= "shared";
7314 case OMP_CLAUSE_DEFAULT_PRIVATE
:
7315 share_name
= "private";
7322 error ("%qE is predetermined %qs for %qs",
7323 omp_clause_printable_decl (t
), share_name
,
7324 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7329 /* We're interested in the base element, not arrays. */
7330 inner_type
= type
= TREE_TYPE (t
);
7331 if ((need_complete_type
7332 || need_copy_assignment
7333 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
7334 && TREE_CODE (inner_type
) == REFERENCE_TYPE
)
7335 inner_type
= TREE_TYPE (inner_type
);
7336 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
7337 inner_type
= TREE_TYPE (inner_type
);
7339 /* Check for special function availability by building a call to one.
7340 Save the results, because later we won't be in the right context
7341 for making these queries. */
7342 if (CLASS_TYPE_P (inner_type
)
7343 && COMPLETE_TYPE_P (inner_type
)
7344 && (need_default_ctor
|| need_copy_ctor
7345 || need_copy_assignment
|| need_dtor
)
7346 && !type_dependent_expression_p (t
)
7347 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
7348 need_copy_ctor
, need_copy_assignment
,
7353 && c_kind
== OMP_CLAUSE_SHARED
7354 && processing_template_decl
)
7356 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7358 OMP_CLAUSE_DECL (c
) = t
;
7362 *pc
= OMP_CLAUSE_CHAIN (c
);
7364 pc
= &OMP_CLAUSE_CHAIN (c
);
7367 bitmap_obstack_release (NULL
);
7371 /* Start processing OpenMP clauses that can include any
7372 privatization clauses for non-static data members. */
7375 push_omp_privatization_clauses (bool ignore_next
)
7377 if (omp_private_member_ignore_next
)
7379 omp_private_member_ignore_next
= ignore_next
;
7382 omp_private_member_ignore_next
= ignore_next
;
7383 if (omp_private_member_map
)
7384 omp_private_member_vec
.safe_push (error_mark_node
);
7385 return push_stmt_list ();
7388 /* Revert remapping of any non-static data members since
7389 the last push_omp_privatization_clauses () call. */
7392 pop_omp_privatization_clauses (tree stmt
)
7394 if (stmt
== NULL_TREE
)
7396 stmt
= pop_stmt_list (stmt
);
7397 if (omp_private_member_map
)
7399 while (!omp_private_member_vec
.is_empty ())
7401 tree t
= omp_private_member_vec
.pop ();
7402 if (t
== error_mark_node
)
7407 bool no_decl_expr
= t
== integer_zero_node
;
7409 t
= omp_private_member_vec
.pop ();
7410 tree
*v
= omp_private_member_map
->get (t
);
7414 omp_private_member_map
->remove (t
);
7416 delete omp_private_member_map
;
7417 omp_private_member_map
= NULL
;
7422 /* Remember OpenMP privatization clauses mapping and clear it.
7423 Used for lambdas. */
7426 save_omp_privatization_clauses (vec
<tree
> &save
)
7429 if (omp_private_member_ignore_next
)
7430 save
.safe_push (integer_one_node
);
7431 omp_private_member_ignore_next
= false;
7432 if (!omp_private_member_map
)
7435 while (!omp_private_member_vec
.is_empty ())
7437 tree t
= omp_private_member_vec
.pop ();
7438 if (t
== error_mark_node
)
7444 if (t
== integer_zero_node
)
7445 t
= omp_private_member_vec
.pop ();
7446 tree
*v
= omp_private_member_map
->get (t
);
7448 save
.safe_push (*v
);
7453 delete omp_private_member_map
;
7454 omp_private_member_map
= NULL
;
7457 /* Restore OpenMP privatization clauses mapping saved by the
7461 restore_omp_privatization_clauses (vec
<tree
> &save
)
7463 gcc_assert (omp_private_member_vec
.is_empty ());
7464 omp_private_member_ignore_next
= false;
7465 if (save
.is_empty ())
7467 if (save
.length () == 1 && save
[0] == integer_one_node
)
7469 omp_private_member_ignore_next
= true;
7474 omp_private_member_map
= new hash_map
<tree
, tree
>;
7475 while (!save
.is_empty ())
7477 tree t
= save
.pop ();
7479 if (t
!= error_mark_node
)
7481 if (t
== integer_one_node
)
7483 omp_private_member_ignore_next
= true;
7484 gcc_assert (save
.is_empty ());
7487 if (t
== integer_zero_node
)
7489 tree
&v
= omp_private_member_map
->get_or_insert (t
);
7492 omp_private_member_vec
.safe_push (t
);
7494 omp_private_member_vec
.safe_push (n
);
7499 /* For all variables in the tree_list VARS, mark them as thread local. */
7502 finish_omp_threadprivate (tree vars
)
7506 /* Mark every variable in VARS to be assigned thread local storage. */
7507 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7509 tree v
= TREE_PURPOSE (t
);
7511 if (error_operand_p (v
))
7513 else if (!VAR_P (v
))
7514 error ("%<threadprivate%> %qD is not file, namespace "
7515 "or block scope variable", v
);
7516 /* If V had already been marked threadprivate, it doesn't matter
7517 whether it had been used prior to this point. */
7518 else if (TREE_USED (v
)
7519 && (DECL_LANG_SPECIFIC (v
) == NULL
7520 || !CP_DECL_THREADPRIVATE_P (v
)))
7521 error ("%qE declared %<threadprivate%> after first use", v
);
7522 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7523 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7524 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
7525 error ("%<threadprivate%> %qE has incomplete type", v
);
7526 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
7527 && CP_DECL_CONTEXT (v
) != current_class_type
)
7528 error ("%<threadprivate%> %qE directive not "
7529 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
7532 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
7533 if (DECL_LANG_SPECIFIC (v
) == NULL
)
7535 retrofit_lang_decl (v
);
7537 /* Make sure that DECL_DISCRIMINATOR_P continues to be true
7538 after the allocation of the lang_decl structure. */
7539 if (DECL_DISCRIMINATOR_P (v
))
7540 DECL_LANG_SPECIFIC (v
)->u
.base
.u2sel
= 1;
7543 if (! CP_DECL_THREAD_LOCAL_P (v
))
7545 CP_DECL_THREAD_LOCAL_P (v
) = true;
7546 set_decl_tls_model (v
, decl_default_tls_model (v
));
7547 /* If rtl has been already set for this var, call
7548 make_decl_rtl once again, so that encode_section_info
7549 has a chance to look at the new decl flags. */
7550 if (DECL_RTL_SET_P (v
))
7553 CP_DECL_THREADPRIVATE_P (v
) = 1;
7558 /* Build an OpenMP structured block. */
7561 begin_omp_structured_block (void)
7563 return do_pushlevel (sk_omp
);
7567 finish_omp_structured_block (tree block
)
7569 return do_poplevel (block
);
7572 /* Similarly, except force the retention of the BLOCK. */
7575 begin_omp_parallel (void)
7577 keep_next_level (true);
7578 return begin_omp_structured_block ();
7581 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
7585 finish_oacc_data (tree clauses
, tree block
)
7589 block
= finish_omp_structured_block (block
);
7591 stmt
= make_node (OACC_DATA
);
7592 TREE_TYPE (stmt
) = void_type_node
;
7593 OACC_DATA_CLAUSES (stmt
) = clauses
;
7594 OACC_DATA_BODY (stmt
) = block
;
7596 return add_stmt (stmt
);
7599 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
7603 finish_oacc_host_data (tree clauses
, tree block
)
7607 block
= finish_omp_structured_block (block
);
7609 stmt
= make_node (OACC_HOST_DATA
);
7610 TREE_TYPE (stmt
) = void_type_node
;
7611 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
7612 OACC_HOST_DATA_BODY (stmt
) = block
;
7614 return add_stmt (stmt
);
7617 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
7621 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
7623 body
= finish_omp_structured_block (body
);
7625 tree stmt
= make_node (code
);
7626 TREE_TYPE (stmt
) = void_type_node
;
7627 OMP_BODY (stmt
) = body
;
7628 OMP_CLAUSES (stmt
) = clauses
;
7630 return add_stmt (stmt
);
7634 finish_omp_parallel (tree clauses
, tree body
)
7638 body
= finish_omp_structured_block (body
);
7640 stmt
= make_node (OMP_PARALLEL
);
7641 TREE_TYPE (stmt
) = void_type_node
;
7642 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
7643 OMP_PARALLEL_BODY (stmt
) = body
;
7645 return add_stmt (stmt
);
7649 begin_omp_task (void)
7651 keep_next_level (true);
7652 return begin_omp_structured_block ();
7656 finish_omp_task (tree clauses
, tree body
)
7660 body
= finish_omp_structured_block (body
);
7662 stmt
= make_node (OMP_TASK
);
7663 TREE_TYPE (stmt
) = void_type_node
;
7664 OMP_TASK_CLAUSES (stmt
) = clauses
;
7665 OMP_TASK_BODY (stmt
) = body
;
7667 return add_stmt (stmt
);
7670 /* Helper function for finish_omp_for. Convert Ith random access iterator
7671 into integral iterator. Return FALSE if successful. */
7674 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
7675 tree declv
, tree orig_declv
, tree initv
,
7676 tree condv
, tree incrv
, tree
*body
,
7677 tree
*pre_body
, tree
&clauses
, tree
*lastp
,
7678 int collapse
, int ordered
)
7680 tree diff
, iter_init
, iter_incr
= NULL
, last
;
7681 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
7682 tree decl
= TREE_VEC_ELT (declv
, i
);
7683 tree init
= TREE_VEC_ELT (initv
, i
);
7684 tree cond
= TREE_VEC_ELT (condv
, i
);
7685 tree incr
= TREE_VEC_ELT (incrv
, i
);
7687 location_t elocus
= locus
;
7689 if (init
&& EXPR_HAS_LOCATION (init
))
7690 elocus
= EXPR_LOCATION (init
);
7692 cond
= cp_fully_fold (cond
);
7693 switch (TREE_CODE (cond
))
7700 if (TREE_OPERAND (cond
, 1) == iter
)
7701 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
7702 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
7703 if (TREE_OPERAND (cond
, 0) != iter
)
7704 cond
= error_mark_node
;
7707 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
7710 TREE_OPERAND (cond
, 1), ERROR_MARK
,
7711 NULL
, tf_warning_or_error
);
7712 if (error_operand_p (tem
))
7717 cond
= error_mark_node
;
7720 if (cond
== error_mark_node
)
7722 error_at (elocus
, "invalid controlling predicate");
7725 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
7726 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
7727 tf_warning_or_error
);
7728 diff
= cp_fully_fold (diff
);
7729 if (error_operand_p (diff
))
7731 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
7733 error_at (elocus
, "difference between %qE and %qD does not have integer type",
7734 TREE_OPERAND (cond
, 1), iter
);
7737 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
,
7738 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
7739 cond
, cp_walk_subtrees
))
7742 switch (TREE_CODE (incr
))
7744 case PREINCREMENT_EXPR
:
7745 case PREDECREMENT_EXPR
:
7746 case POSTINCREMENT_EXPR
:
7747 case POSTDECREMENT_EXPR
:
7748 if (TREE_OPERAND (incr
, 0) != iter
)
7750 incr
= error_mark_node
;
7753 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
7754 TREE_CODE (incr
), iter
,
7755 tf_warning_or_error
);
7756 if (error_operand_p (iter_incr
))
7758 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
7759 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
7760 incr
= integer_one_node
;
7762 incr
= integer_minus_one_node
;
7765 if (TREE_OPERAND (incr
, 0) != iter
)
7766 incr
= error_mark_node
;
7767 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
7768 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
7770 tree rhs
= TREE_OPERAND (incr
, 1);
7771 if (TREE_OPERAND (rhs
, 0) == iter
)
7773 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
7775 incr
= error_mark_node
;
7778 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7779 iter
, TREE_CODE (rhs
),
7780 TREE_OPERAND (rhs
, 1),
7781 tf_warning_or_error
);
7782 if (error_operand_p (iter_incr
))
7784 incr
= TREE_OPERAND (rhs
, 1);
7785 incr
= cp_convert (TREE_TYPE (diff
), incr
,
7786 tf_warning_or_error
);
7787 if (TREE_CODE (rhs
) == MINUS_EXPR
)
7789 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
7790 incr
= fold_simple (incr
);
7792 if (TREE_CODE (incr
) != INTEGER_CST
7793 && (TREE_CODE (incr
) != NOP_EXPR
7794 || (TREE_CODE (TREE_OPERAND (incr
, 0))
7799 else if (TREE_OPERAND (rhs
, 1) == iter
)
7801 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
7802 || TREE_CODE (rhs
) != PLUS_EXPR
)
7803 incr
= error_mark_node
;
7806 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
7808 TREE_OPERAND (rhs
, 0),
7811 tf_warning_or_error
);
7812 if (error_operand_p (iter_incr
))
7814 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7817 tf_warning_or_error
);
7818 if (error_operand_p (iter_incr
))
7820 incr
= TREE_OPERAND (rhs
, 0);
7825 incr
= error_mark_node
;
7828 incr
= error_mark_node
;
7831 incr
= error_mark_node
;
7835 if (incr
== error_mark_node
)
7837 error_at (elocus
, "invalid increment expression");
7841 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
7842 bool taskloop_iv_seen
= false;
7843 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7844 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
7845 && OMP_CLAUSE_DECL (c
) == iter
)
7847 if (code
== OMP_TASKLOOP
)
7849 taskloop_iv_seen
= true;
7850 OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c
) = 1;
7854 else if (code
== OMP_TASKLOOP
7855 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
7856 && OMP_CLAUSE_DECL (c
) == iter
)
7858 taskloop_iv_seen
= true;
7859 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
7862 decl
= create_temporary_var (TREE_TYPE (diff
));
7864 add_decl_expr (decl
);
7865 last
= create_temporary_var (TREE_TYPE (diff
));
7867 add_decl_expr (last
);
7868 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
7869 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7871 incr_var
= create_temporary_var (TREE_TYPE (diff
));
7872 pushdecl (incr_var
);
7873 add_decl_expr (incr_var
);
7875 gcc_assert (stmts_are_full_exprs_p ());
7876 tree diffvar
= NULL_TREE
;
7877 if (code
== OMP_TASKLOOP
)
7879 if (!taskloop_iv_seen
)
7881 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7882 OMP_CLAUSE_DECL (ivc
) = iter
;
7883 cxx_omp_finish_clause (ivc
, NULL
);
7884 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
7887 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7888 OMP_CLAUSE_DECL (lvc
) = last
;
7889 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
7891 diffvar
= create_temporary_var (TREE_TYPE (diff
));
7893 add_decl_expr (diffvar
);
7896 orig_pre_body
= *pre_body
;
7897 *pre_body
= push_stmt_list ();
7899 add_stmt (orig_pre_body
);
7901 finish_expr_stmt (build_x_modify_expr (elocus
,
7902 iter
, NOP_EXPR
, init
,
7903 tf_warning_or_error
));
7904 init
= build_int_cst (TREE_TYPE (diff
), 0);
7905 if (c
&& iter_incr
== NULL
7906 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7910 finish_expr_stmt (build_x_modify_expr (elocus
,
7912 incr
, tf_warning_or_error
));
7915 iter_incr
= build_x_modify_expr (elocus
,
7916 iter
, PLUS_EXPR
, incr
,
7917 tf_warning_or_error
);
7919 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
7921 finish_expr_stmt (build_x_modify_expr (elocus
,
7922 last
, NOP_EXPR
, init
,
7923 tf_warning_or_error
));
7926 finish_expr_stmt (build_x_modify_expr (elocus
,
7928 diff
, tf_warning_or_error
));
7931 *pre_body
= pop_stmt_list (*pre_body
);
7933 cond
= cp_build_binary_op (elocus
,
7934 TREE_CODE (cond
), decl
, diff
,
7935 tf_warning_or_error
);
7936 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
7937 elocus
, incr
, NULL_TREE
);
7940 *body
= push_stmt_list ();
7941 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
7942 iter_init
= build_x_modify_expr (elocus
,
7943 iter
, PLUS_EXPR
, iter_init
,
7944 tf_warning_or_error
);
7945 if (iter_init
!= error_mark_node
)
7946 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7947 finish_expr_stmt (iter_init
);
7948 finish_expr_stmt (build_x_modify_expr (elocus
,
7949 last
, NOP_EXPR
, decl
,
7950 tf_warning_or_error
));
7951 add_stmt (orig_body
);
7952 *body
= pop_stmt_list (*body
);
7956 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
7958 finish_expr_stmt (iter_incr
);
7962 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
7963 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
7964 iter_init
, iter_incr
);
7965 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
7966 iter_init
= build_x_modify_expr (elocus
,
7967 iter
, PLUS_EXPR
, iter_init
,
7968 tf_warning_or_error
);
7969 if (iter_init
!= error_mark_node
)
7970 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7971 finish_expr_stmt (iter_init
);
7973 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
7974 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
7977 TREE_VEC_ELT (declv
, i
) = decl
;
7978 TREE_VEC_ELT (initv
, i
) = init
;
7979 TREE_VEC_ELT (condv
, i
) = cond
;
7980 TREE_VEC_ELT (incrv
, i
) = incr
;
7986 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
7987 are directly for their associated operands in the statement. DECL
7988 and INIT are a combo; if DECL is NULL then INIT ought to be a
7989 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
7990 optional statements that need to go before the loop into its
7994 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
7995 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
7996 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
7998 tree omp_for
= NULL
, orig_incr
= NULL
;
7999 tree decl
= NULL
, init
, cond
, incr
, orig_decl
= NULL_TREE
, block
= NULL_TREE
;
8000 tree last
= NULL_TREE
;
8006 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
8007 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
8008 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
8009 if (TREE_VEC_LENGTH (declv
) > 1)
8013 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
8015 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
8018 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
8020 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
8021 if (collapse
!= TREE_VEC_LENGTH (declv
))
8022 ordered
= TREE_VEC_LENGTH (declv
);
8025 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8027 decl
= TREE_VEC_ELT (declv
, i
);
8028 init
= TREE_VEC_ELT (initv
, i
);
8029 cond
= TREE_VEC_ELT (condv
, i
);
8030 incr
= TREE_VEC_ELT (incrv
, i
);
8036 switch (TREE_CODE (init
))
8039 decl
= TREE_OPERAND (init
, 0);
8040 init
= TREE_OPERAND (init
, 1);
8043 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
8045 decl
= TREE_OPERAND (init
, 0);
8046 init
= TREE_OPERAND (init
, 2);
8056 "expected iteration declaration or initialization");
8061 if (init
&& EXPR_HAS_LOCATION (init
))
8062 elocus
= EXPR_LOCATION (init
);
8066 error_at (elocus
, "missing controlling predicate");
8072 error_at (elocus
, "missing increment expression");
8076 TREE_VEC_ELT (declv
, i
) = decl
;
8077 TREE_VEC_ELT (initv
, i
) = init
;
8084 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
8086 && !c_omp_check_loop_iv_exprs (locus
, declv
,
8087 TREE_VEC_ELT (declv
, i
), orig_init
,
8088 NULL_TREE
, cp_walk_subtrees
))
8094 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
8098 stmt
= make_node (code
);
8100 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8102 /* This is really just a place-holder. We'll be decomposing this
8103 again and going through the cp_build_modify_expr path below when
8104 we instantiate the thing. */
8105 TREE_VEC_ELT (initv
, i
)
8106 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
8107 TREE_VEC_ELT (initv
, i
));
8110 TREE_TYPE (stmt
) = void_type_node
;
8111 OMP_FOR_INIT (stmt
) = initv
;
8112 OMP_FOR_COND (stmt
) = condv
;
8113 OMP_FOR_INCR (stmt
) = incrv
;
8114 OMP_FOR_BODY (stmt
) = body
;
8115 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
8116 OMP_FOR_CLAUSES (stmt
) = clauses
;
8118 SET_EXPR_LOCATION (stmt
, locus
);
8119 return add_stmt (stmt
);
8123 orig_declv
= copy_node (declv
);
8125 if (processing_template_decl
)
8126 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
8128 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
8130 decl
= TREE_VEC_ELT (declv
, i
);
8131 init
= TREE_VEC_ELT (initv
, i
);
8132 cond
= TREE_VEC_ELT (condv
, i
);
8133 incr
= TREE_VEC_ELT (incrv
, i
);
8135 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8138 if (init
&& EXPR_HAS_LOCATION (init
))
8139 elocus
= EXPR_LOCATION (init
);
8143 error_at (elocus
, "expected iteration declaration or initialization");
8147 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
8150 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8151 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
8152 TREE_CODE (TREE_OPERAND (incr
, 1)),
8153 TREE_OPERAND (incr
, 2),
8154 tf_warning_or_error
);
8157 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
8159 if (code
== OMP_SIMD
)
8161 error_at (elocus
, "%<#pragma omp simd%> used with class "
8162 "iteration variable %qE", decl
);
8165 if (code
== CILK_FOR
&& i
== 0)
8167 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
8168 initv
, condv
, incrv
, &body
,
8169 &pre_body
, clauses
, &last
,
8175 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
8176 && !TYPE_PTR_P (TREE_TYPE (decl
)))
8178 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
8182 if (!processing_template_decl
)
8184 init
= fold_build_cleanup_point_expr (TREE_TYPE (init
), init
);
8185 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
8186 tf_warning_or_error
);
8189 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
8191 && TREE_SIDE_EFFECTS (cond
)
8192 && COMPARISON_CLASS_P (cond
)
8193 && !processing_template_decl
)
8195 tree t
= TREE_OPERAND (cond
, 0);
8196 if (TREE_SIDE_EFFECTS (t
)
8198 && (TREE_CODE (t
) != NOP_EXPR
8199 || TREE_OPERAND (t
, 0) != decl
))
8200 TREE_OPERAND (cond
, 0)
8201 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8203 t
= TREE_OPERAND (cond
, 1);
8204 if (TREE_SIDE_EFFECTS (t
)
8206 && (TREE_CODE (t
) != NOP_EXPR
8207 || TREE_OPERAND (t
, 0) != decl
))
8208 TREE_OPERAND (cond
, 1)
8209 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8211 if (decl
== error_mark_node
|| init
== error_mark_node
)
8214 TREE_VEC_ELT (declv
, i
) = decl
;
8215 TREE_VEC_ELT (initv
, i
) = init
;
8216 TREE_VEC_ELT (condv
, i
) = cond
;
8217 TREE_VEC_ELT (incrv
, i
) = incr
;
8221 if (IS_EMPTY_STMT (pre_body
))
8224 if (code
== CILK_FOR
&& !processing_template_decl
)
8225 block
= push_stmt_list ();
8227 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
8228 incrv
, body
, pre_body
);
8230 /* Check for iterators appearing in lb, b or incr expressions. */
8231 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
8232 omp_for
= NULL_TREE
;
8234 if (omp_for
== NULL
)
8237 pop_stmt_list (block
);
8243 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
8245 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
), 0);
8246 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
8248 if (TREE_CODE (incr
) != MODIFY_EXPR
)
8251 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
8252 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
8253 && !processing_template_decl
)
8255 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
8256 if (TREE_SIDE_EFFECTS (t
)
8258 && (TREE_CODE (t
) != NOP_EXPR
8259 || TREE_OPERAND (t
, 0) != decl
))
8260 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
8261 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8263 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8264 if (TREE_SIDE_EFFECTS (t
)
8266 && (TREE_CODE (t
) != NOP_EXPR
8267 || TREE_OPERAND (t
, 0) != decl
))
8268 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8269 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8273 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
8275 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8277 /* For simd loops with non-static data member iterators, we could have added
8278 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
8279 step at this point, fill it in. */
8280 if (code
== OMP_SIMD
&& !processing_template_decl
8281 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
8282 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
8283 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
8284 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
8286 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
8287 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
8288 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8290 switch (TREE_CODE (incr
))
8292 case PREINCREMENT_EXPR
:
8293 case POSTINCREMENT_EXPR
:
8294 /* c_omp_for_incr_canonicalize_ptr() should have been
8295 called to massage things appropriately. */
8296 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8297 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
8299 case PREDECREMENT_EXPR
:
8300 case POSTDECREMENT_EXPR
:
8301 /* c_omp_for_incr_canonicalize_ptr() should have been
8302 called to massage things appropriately. */
8303 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8304 OMP_CLAUSE_LINEAR_STEP (c
)
8305 = build_int_cst (TREE_TYPE (decl
), -1);
8308 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8309 incr
= TREE_OPERAND (incr
, 1);
8310 switch (TREE_CODE (incr
))
8313 if (TREE_OPERAND (incr
, 1) == decl
)
8314 step
= TREE_OPERAND (incr
, 0);
8316 step
= TREE_OPERAND (incr
, 1);
8319 case POINTER_PLUS_EXPR
:
8320 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8321 step
= TREE_OPERAND (incr
, 1);
8326 stept
= TREE_TYPE (decl
);
8327 if (POINTER_TYPE_P (stept
))
8329 step
= fold_convert (stept
, step
);
8330 if (TREE_CODE (incr
) == MINUS_EXPR
)
8331 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
8332 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
8341 tree omp_par
= make_node (OMP_PARALLEL
);
8342 TREE_TYPE (omp_par
) = void_type_node
;
8343 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
8344 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
8345 TREE_SIDE_EFFECTS (bind
) = 1;
8346 BIND_EXPR_BODY (bind
) = pop_stmt_list (block
);
8347 OMP_PARALLEL_BODY (omp_par
) = bind
;
8348 if (OMP_FOR_PRE_BODY (omp_for
))
8350 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
8351 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
8353 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
8354 decl
= TREE_OPERAND (init
, 0);
8355 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
8356 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8357 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
, *pc
;
8358 clauses
= OMP_FOR_CLAUSES (omp_for
);
8359 OMP_FOR_CLAUSES (omp_for
) = NULL_TREE
;
8360 for (pc
= &clauses
; *pc
; )
8361 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_SCHEDULE
)
8363 gcc_assert (OMP_FOR_CLAUSES (omp_for
) == NULL_TREE
);
8364 OMP_FOR_CLAUSES (omp_for
) = *pc
;
8365 *pc
= OMP_CLAUSE_CHAIN (*pc
);
8366 OMP_CLAUSE_CHAIN (OMP_FOR_CLAUSES (omp_for
)) = NULL_TREE
;
8370 gcc_assert (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_FIRSTPRIVATE
);
8371 pc
= &OMP_CLAUSE_CHAIN (*pc
);
8373 if (TREE_CODE (t
) != INTEGER_CST
)
8375 TREE_OPERAND (cond
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
8376 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8377 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
8378 OMP_CLAUSE_CHAIN (c
) = clauses
;
8381 if (TREE_CODE (incr
) == MODIFY_EXPR
)
8383 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8384 if (TREE_CODE (t
) != INTEGER_CST
)
8386 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8387 = get_temp_regvar (TREE_TYPE (t
), t
);
8388 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8389 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8390 OMP_CLAUSE_CHAIN (c
) = clauses
;
8394 t
= TREE_OPERAND (init
, 1);
8395 if (TREE_CODE (t
) != INTEGER_CST
)
8397 TREE_OPERAND (init
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
8398 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8399 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
8400 OMP_CLAUSE_CHAIN (c
) = clauses
;
8403 if (orig_decl
&& orig_decl
!= decl
)
8405 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8406 OMP_CLAUSE_DECL (c
) = orig_decl
;
8407 OMP_CLAUSE_CHAIN (c
) = clauses
;
8412 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8413 OMP_CLAUSE_DECL (c
) = last
;
8414 OMP_CLAUSE_CHAIN (c
) = clauses
;
8417 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
8418 OMP_CLAUSE_DECL (c
) = decl
;
8419 OMP_CLAUSE_CHAIN (c
) = clauses
;
8421 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
8422 OMP_CLAUSE_OPERAND (c
, 0)
8423 = cilk_for_number_of_iterations (omp_for
);
8424 OMP_CLAUSE_CHAIN (c
) = clauses
;
8425 OMP_PARALLEL_CLAUSES (omp_par
) = finish_omp_clauses (c
, C_ORT_CILK
);
8429 else if (code
== CILK_FOR
&& processing_template_decl
)
8431 tree c
, clauses
= OMP_FOR_CLAUSES (omp_for
);
8432 if (orig_decl
&& orig_decl
!= decl
)
8434 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8435 OMP_CLAUSE_DECL (c
) = orig_decl
;
8436 OMP_CLAUSE_CHAIN (c
) = clauses
;
8441 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8442 OMP_CLAUSE_DECL (c
) = last
;
8443 OMP_CLAUSE_CHAIN (c
) = clauses
;
8446 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8452 finish_omp_atomic (enum tree_code code
, enum tree_code opcode
, tree lhs
,
8453 tree rhs
, tree v
, tree lhs1
, tree rhs1
, bool seq_cst
)
8468 dependent_p
= false;
8471 /* Even in a template, we can detect invalid uses of the atomic
8472 pragma if neither LHS nor RHS is type-dependent. */
8473 if (processing_template_decl
)
8475 dependent_p
= (type_dependent_expression_p (lhs
)
8476 || (rhs
&& type_dependent_expression_p (rhs
))
8477 || (v
&& type_dependent_expression_p (v
))
8478 || (lhs1
&& type_dependent_expression_p (lhs1
))
8479 || (rhs1
&& type_dependent_expression_p (rhs1
)));
8482 lhs
= build_non_dependent_expr (lhs
);
8484 rhs
= build_non_dependent_expr (rhs
);
8486 v
= build_non_dependent_expr (v
);
8488 lhs1
= build_non_dependent_expr (lhs1
);
8490 rhs1
= build_non_dependent_expr (rhs1
);
8495 bool swapped
= false;
8496 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
8498 std::swap (rhs
, rhs1
);
8499 swapped
= !commutative_tree_code (opcode
);
8501 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
8503 if (code
== OMP_ATOMIC
)
8504 error ("%<#pragma omp atomic update%> uses two different "
8505 "expressions for memory");
8507 error ("%<#pragma omp atomic capture%> uses two different "
8508 "expressions for memory");
8511 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
8513 if (code
== OMP_ATOMIC
)
8514 error ("%<#pragma omp atomic update%> uses two different "
8515 "expressions for memory");
8517 error ("%<#pragma omp atomic capture%> uses two different "
8518 "expressions for memory");
8521 stmt
= c_finish_omp_atomic (input_location
, code
, opcode
, lhs
, rhs
,
8522 v
, lhs1
, rhs1
, swapped
, seq_cst
,
8523 processing_template_decl
!= 0);
8524 if (stmt
== error_mark_node
)
8527 if (processing_template_decl
)
8529 if (code
== OMP_ATOMIC_READ
)
8531 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs
),
8532 OMP_ATOMIC_READ
, orig_lhs
);
8533 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8534 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8538 if (opcode
== NOP_EXPR
)
8539 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
8541 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
8543 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
8544 COMPOUND_EXPR
, orig_rhs1
, stmt
);
8545 if (code
!= OMP_ATOMIC
)
8547 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs1
),
8548 code
, orig_lhs1
, stmt
);
8549 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8550 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8553 stmt
= build2 (OMP_ATOMIC
, void_type_node
, integer_zero_node
, stmt
);
8554 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8556 finish_expr_stmt (stmt
);
8560 finish_omp_barrier (void)
8562 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
8563 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8564 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8565 release_tree_vector (vec
);
8566 finish_expr_stmt (stmt
);
8570 finish_omp_flush (void)
8572 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
8573 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8574 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8575 release_tree_vector (vec
);
8576 finish_expr_stmt (stmt
);
8580 finish_omp_taskwait (void)
8582 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
8583 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8584 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8585 release_tree_vector (vec
);
8586 finish_expr_stmt (stmt
);
8590 finish_omp_taskyield (void)
8592 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
8593 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8594 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8595 release_tree_vector (vec
);
8596 finish_expr_stmt (stmt
);
8600 finish_omp_cancel (tree clauses
)
8602 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
8604 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8606 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
8608 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8610 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8614 error ("%<#pragma omp cancel%> must specify one of "
8615 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8618 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8619 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
8620 if (ifc
!= NULL_TREE
)
8622 tree type
= TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc
));
8623 ifc
= fold_build2_loc (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
8624 boolean_type_node
, OMP_CLAUSE_IF_EXPR (ifc
),
8625 build_zero_cst (type
));
8628 ifc
= boolean_true_node
;
8629 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
8630 vec
->quick_push (ifc
);
8631 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8632 release_tree_vector (vec
);
8633 finish_expr_stmt (stmt
);
8637 finish_omp_cancellation_point (tree clauses
)
8639 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
8641 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8643 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
8645 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8647 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8651 error ("%<#pragma omp cancellation point%> must specify one of "
8652 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8655 vec
<tree
, va_gc
> *vec
8656 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
8657 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8658 release_tree_vector (vec
);
8659 finish_expr_stmt (stmt
);
8662 /* Begin a __transaction_atomic or __transaction_relaxed statement.
8663 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
8664 should create an extra compound stmt. */
8667 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
8672 *pcompound
= begin_compound_stmt (0);
8674 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
8676 /* Only add the statement to the function if support enabled. */
8680 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
8681 ? G_("%<__transaction_relaxed%> without "
8682 "transactional memory support enabled")
8683 : G_("%<__transaction_atomic%> without "
8684 "transactional memory support enabled")));
8686 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
8687 TREE_SIDE_EFFECTS (r
) = 1;
8691 /* End a __transaction_atomic or __transaction_relaxed statement.
8692 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
8693 and we should end the compound. If NOEX is non-NULL, we wrap the body in
8694 a MUST_NOT_THROW_EXPR with NOEX as condition. */
8697 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
8699 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
8700 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
8701 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
8702 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
8704 /* noexcept specifications are not allowed for function transactions. */
8705 gcc_assert (!(noex
&& compound_stmt
));
8708 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
8710 protected_set_expr_location
8711 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
8712 TREE_SIDE_EFFECTS (body
) = 1;
8713 TRANSACTION_EXPR_BODY (stmt
) = body
;
8717 finish_compound_stmt (compound_stmt
);
8720 /* Build a __transaction_atomic or __transaction_relaxed expression. If
8721 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
8725 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
8730 expr
= build_must_not_throw_expr (expr
, noex
);
8731 protected_set_expr_location (expr
, loc
);
8732 TREE_SIDE_EFFECTS (expr
) = 1;
8734 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
8735 if (flags
& TM_STMT_ATTR_RELAXED
)
8736 TRANSACTION_EXPR_RELAXED (ret
) = 1;
8737 TREE_SIDE_EFFECTS (ret
) = 1;
8738 SET_EXPR_LOCATION (ret
, loc
);
8743 init_cp_semantics (void)
8747 /* Build a STATIC_ASSERT for a static assertion with the condition
8748 CONDITION and the message text MESSAGE. LOCATION is the location
8749 of the static assertion in the source code. When MEMBER_P, this
8750 static assertion is a member of a class. */
8752 finish_static_assert (tree condition
, tree message
, location_t location
,
8755 if (message
== NULL_TREE
8756 || message
== error_mark_node
8757 || condition
== NULL_TREE
8758 || condition
== error_mark_node
)
8761 if (check_for_bare_parameter_packs (condition
))
8762 condition
= error_mark_node
;
8764 if (type_dependent_expression_p (condition
)
8765 || value_dependent_expression_p (condition
))
8767 /* We're in a template; build a STATIC_ASSERT and put it in
8771 assertion
= make_node (STATIC_ASSERT
);
8772 STATIC_ASSERT_CONDITION (assertion
) = condition
;
8773 STATIC_ASSERT_MESSAGE (assertion
) = message
;
8774 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
8777 maybe_add_class_template_decl_list (current_class_type
,
8781 add_stmt (assertion
);
8786 /* Fold the expression and convert it to a boolean value. */
8787 condition
= instantiate_non_dependent_expr (condition
);
8788 condition
= cp_convert (boolean_type_node
, condition
, tf_warning_or_error
);
8789 condition
= maybe_constant_value (condition
);
8791 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
8792 /* Do nothing; the condition is satisfied. */
8796 location_t saved_loc
= input_location
;
8798 input_location
= location
;
8799 if (TREE_CODE (condition
) == INTEGER_CST
8800 && integer_zerop (condition
))
8802 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
8803 (TREE_TYPE (TREE_TYPE (message
))));
8804 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
8805 /* Report the error. */
8807 error ("static assertion failed");
8809 error ("static assertion failed: %s",
8810 TREE_STRING_POINTER (message
));
8812 else if (condition
&& condition
!= error_mark_node
)
8814 error ("non-constant condition for static assertion");
8815 if (require_potential_rvalue_constant_expression (condition
))
8816 cxx_constant_value (condition
);
8818 input_location
= saved_loc
;
8822 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
8823 suitable for use as a type-specifier.
8825 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
8826 id-expression or a class member access, FALSE when it was parsed as
8827 a full expression. */
8830 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
8831 tsubst_flags_t complain
)
8833 tree type
= NULL_TREE
;
8835 if (!expr
|| error_operand_p (expr
))
8836 return error_mark_node
;
8839 || TREE_CODE (expr
) == TYPE_DECL
8840 || (TREE_CODE (expr
) == BIT_NOT_EXPR
8841 && TYPE_P (TREE_OPERAND (expr
, 0))))
8843 if (complain
& tf_error
)
8844 error ("argument to decltype must be an expression");
8845 return error_mark_node
;
8848 /* Depending on the resolution of DR 1172, we may later need to distinguish
8849 instantiation-dependent but not type-dependent expressions so that, say,
8850 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
8851 if (instantiation_dependent_uneval_expression_p (expr
))
8853 type
= cxx_make_type (DECLTYPE_TYPE
);
8854 DECLTYPE_TYPE_EXPR (type
) = expr
;
8855 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
8856 = id_expression_or_member_access_p
;
8857 SET_TYPE_STRUCTURAL_EQUALITY (type
);
8862 /* The type denoted by decltype(e) is defined as follows: */
8864 expr
= resolve_nondeduced_context (expr
, complain
);
8866 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
8867 return error_mark_node
;
8869 if (type_unknown_p (expr
))
8871 if (complain
& tf_error
)
8872 error ("decltype cannot resolve address of overloaded function");
8873 return error_mark_node
;
8876 /* To get the size of a static data member declared as an array of
8877 unknown bound, we need to instantiate it. */
8879 && VAR_HAD_UNKNOWN_BOUND (expr
)
8880 && DECL_TEMPLATE_INSTANTIATION (expr
))
8881 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
8883 if (id_expression_or_member_access_p
)
8885 /* If e is an id-expression or a class member access (5.2.5
8886 [expr.ref]), decltype(e) is defined as the type of the entity
8887 named by e. If there is no such entity, or e names a set of
8888 overloaded functions, the program is ill-formed. */
8889 if (identifier_p (expr
))
8890 expr
= lookup_name (expr
);
8892 if (INDIRECT_REF_P (expr
))
8893 /* This can happen when the expression is, e.g., "a.b". Just
8894 look at the underlying operand. */
8895 expr
= TREE_OPERAND (expr
, 0);
8897 if (TREE_CODE (expr
) == OFFSET_REF
8898 || TREE_CODE (expr
) == MEMBER_REF
8899 || TREE_CODE (expr
) == SCOPE_REF
)
8900 /* We're only interested in the field itself. If it is a
8901 BASELINK, we will need to see through it in the next
8903 expr
= TREE_OPERAND (expr
, 1);
8905 if (BASELINK_P (expr
))
8906 /* See through BASELINK nodes to the underlying function. */
8907 expr
= BASELINK_FUNCTIONS (expr
);
8909 /* decltype of a decomposition name drops references in the tuple case
8910 (unlike decltype of a normal variable) and keeps cv-qualifiers from
8911 the containing object in the other cases (unlike decltype of a member
8912 access expression). */
8913 if (DECL_DECOMPOSITION_P (expr
))
8915 if (DECL_HAS_VALUE_EXPR_P (expr
))
8916 /* Expr is an array or struct subobject proxy, handle
8917 bit-fields properly. */
8918 return unlowered_expr_type (expr
);
8920 /* Expr is a reference variable for the tuple case. */
8921 return lookup_decomp_type (expr
);
8924 switch (TREE_CODE (expr
))
8927 if (DECL_BIT_FIELD_TYPE (expr
))
8929 type
= DECL_BIT_FIELD_TYPE (expr
);
8932 /* Fall through for fields that aren't bitfields. */
8940 case TEMPLATE_PARM_INDEX
:
8941 expr
= mark_type_use (expr
);
8942 type
= TREE_TYPE (expr
);
8946 type
= error_mark_node
;
8951 mark_type_use (expr
);
8952 type
= is_bitfield_expr_with_lowered_type (expr
);
8954 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
8962 /* We can get here when the id-expression refers to an
8963 enumerator or non-type template parameter. */
8964 type
= TREE_TYPE (expr
);
8968 /* Handle instantiated template non-type arguments. */
8969 type
= TREE_TYPE (expr
);
8975 /* Within a lambda-expression:
8977 Every occurrence of decltype((x)) where x is a possibly
8978 parenthesized id-expression that names an entity of
8979 automatic storage duration is treated as if x were
8980 transformed into an access to a corresponding data member
8981 of the closure type that would have been declared if x
8982 were a use of the denoted entity. */
8983 if (outer_automatic_var_p (expr
)
8984 && current_function_decl
8985 && LAMBDA_FUNCTION_P (current_function_decl
))
8986 type
= capture_decltype (expr
);
8987 else if (error_operand_p (expr
))
8988 type
= error_mark_node
;
8989 else if (expr
== current_class_ptr
)
8990 /* If the expression is just "this", we want the
8991 cv-unqualified pointer for the "this" type. */
8992 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
8995 /* Otherwise, where T is the type of e, if e is an lvalue,
8996 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
8997 cp_lvalue_kind clk
= lvalue_kind (expr
);
8998 type
= unlowered_expr_type (expr
);
8999 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
9001 /* For vector types, pick a non-opaque variant. */
9002 if (VECTOR_TYPE_P (type
))
9003 type
= strip_typedefs (type
);
9005 if (clk
!= clk_none
&& !(clk
& clk_class
))
9006 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
9013 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
9014 __has_nothrow_copy, depending on assign_p. Returns true iff all
9015 the copy {ctor,assign} fns are nothrow. */
9018 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
9020 tree fns
= NULL_TREE
;
9022 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
9023 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
9026 bool saw_copy
= false;
9027 for (ovl_iterator
iter (fns
); iter
; ++iter
)
9031 if (copy_fn_p (fn
) > 0)
9034 maybe_instantiate_noexcept (fn
);
9035 if (!TYPE_NOTHROW_P (TREE_TYPE (fn
)))
9043 /* Actually evaluates the trait. */
9046 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
9048 enum tree_code type_code1
;
9051 type_code1
= TREE_CODE (type1
);
9055 case CPTK_HAS_NOTHROW_ASSIGN
:
9056 type1
= strip_array_types (type1
);
9057 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
9058 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
9059 || (CLASS_TYPE_P (type1
)
9060 && classtype_has_nothrow_assign_or_copy_p (type1
,
9063 case CPTK_HAS_TRIVIAL_ASSIGN
:
9064 /* ??? The standard seems to be missing the "or array of such a class
9065 type" wording for this trait. */
9066 type1
= strip_array_types (type1
);
9067 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
9068 && (trivial_type_p (type1
)
9069 || (CLASS_TYPE_P (type1
)
9070 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
9072 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9073 type1
= strip_array_types (type1
);
9074 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
9075 || (CLASS_TYPE_P (type1
)
9076 && (t
= locate_ctor (type1
))
9077 && (maybe_instantiate_noexcept (t
),
9078 TYPE_NOTHROW_P (TREE_TYPE (t
)))));
9080 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9081 type1
= strip_array_types (type1
);
9082 return (trivial_type_p (type1
)
9083 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
9085 case CPTK_HAS_NOTHROW_COPY
:
9086 type1
= strip_array_types (type1
);
9087 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
9088 || (CLASS_TYPE_P (type1
)
9089 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
9091 case CPTK_HAS_TRIVIAL_COPY
:
9092 /* ??? The standard seems to be missing the "or array of such a class
9093 type" wording for this trait. */
9094 type1
= strip_array_types (type1
);
9095 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9096 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
9098 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9099 type1
= strip_array_types (type1
);
9100 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9101 || (CLASS_TYPE_P (type1
)
9102 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
9104 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9105 return type_has_virtual_destructor (type1
);
9107 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
9108 return type_has_unique_obj_representations (type1
);
9110 case CPTK_IS_ABSTRACT
:
9111 return ABSTRACT_CLASS_TYPE_P (type1
);
9113 case CPTK_IS_AGGREGATE
:
9114 return CP_AGGREGATE_TYPE_P (type1
);
9116 case CPTK_IS_BASE_OF
:
9117 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9118 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9119 || DERIVED_FROM_P (type1
, type2
)));
9122 return NON_UNION_CLASS_TYPE_P (type1
);
9125 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
9128 return type_code1
== ENUMERAL_TYPE
;
9131 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
9133 case CPTK_IS_LITERAL_TYPE
:
9134 return literal_type_p (type1
);
9137 return pod_type_p (type1
);
9139 case CPTK_IS_POLYMORPHIC
:
9140 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
9142 case CPTK_IS_SAME_AS
:
9143 return same_type_p (type1
, type2
);
9145 case CPTK_IS_STD_LAYOUT
:
9146 return std_layout_type_p (type1
);
9148 case CPTK_IS_TRIVIAL
:
9149 return trivial_type_p (type1
);
9151 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9152 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
9154 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9155 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
9157 case CPTK_IS_TRIVIALLY_COPYABLE
:
9158 return trivially_copyable_p (type1
);
9161 return type_code1
== UNION_TYPE
;
9163 case CPTK_IS_ASSIGNABLE
:
9164 return is_xible (MODIFY_EXPR
, type1
, type2
);
9166 case CPTK_IS_CONSTRUCTIBLE
:
9167 return is_xible (INIT_EXPR
, type1
, type2
);
9175 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
9176 void, or a complete type, returns true, otherwise false. */
9179 check_trait_type (tree type
)
9181 if (type
== NULL_TREE
)
9184 if (TREE_CODE (type
) == TREE_LIST
)
9185 return (check_trait_type (TREE_VALUE (type
))
9186 && check_trait_type (TREE_CHAIN (type
)));
9188 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
9189 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
9192 if (VOID_TYPE_P (type
))
9195 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
9198 /* Process a trait expression. */
9201 finish_trait_expr (cp_trait_kind kind
, tree type1
, tree type2
)
9203 if (type1
== error_mark_node
9204 || type2
== error_mark_node
)
9205 return error_mark_node
;
9207 if (processing_template_decl
)
9209 tree trait_expr
= make_node (TRAIT_EXPR
);
9210 TREE_TYPE (trait_expr
) = boolean_type_node
;
9211 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
9212 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
9213 TRAIT_EXPR_KIND (trait_expr
) = kind
;
9219 case CPTK_HAS_NOTHROW_ASSIGN
:
9220 case CPTK_HAS_TRIVIAL_ASSIGN
:
9221 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9222 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9223 case CPTK_HAS_NOTHROW_COPY
:
9224 case CPTK_HAS_TRIVIAL_COPY
:
9225 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9226 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
9227 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9228 case CPTK_IS_ABSTRACT
:
9229 case CPTK_IS_AGGREGATE
:
9232 case CPTK_IS_LITERAL_TYPE
:
9234 case CPTK_IS_POLYMORPHIC
:
9235 case CPTK_IS_STD_LAYOUT
:
9236 case CPTK_IS_TRIVIAL
:
9237 case CPTK_IS_TRIVIALLY_COPYABLE
:
9238 if (!check_trait_type (type1
))
9239 return error_mark_node
;
9242 case CPTK_IS_ASSIGNABLE
:
9243 case CPTK_IS_CONSTRUCTIBLE
:
9246 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9247 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9248 if (!check_trait_type (type1
)
9249 || !check_trait_type (type2
))
9250 return error_mark_node
;
9253 case CPTK_IS_BASE_OF
:
9254 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9255 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9256 && !complete_type_or_else (type2
, NULL_TREE
))
9257 /* We already issued an error. */
9258 return error_mark_node
;
9264 case CPTK_IS_SAME_AS
:
9271 return (trait_expr_value (kind
, type1
, type2
)
9272 ? boolean_true_node
: boolean_false_node
);
9275 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
9276 which is ignored for C++. */
9279 set_float_const_decimal64 (void)
9284 clear_float_const_decimal64 (void)
9289 float_const_decimal64_p (void)
9295 /* Return true if T designates the implied `this' parameter. */
9298 is_this_parameter (tree t
)
9300 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
9302 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
)
9303 || (cp_binding_oracle
&& TREE_CODE (t
) == VAR_DECL
));
9307 /* Insert the deduced return type for an auto function. */
9310 apply_deduced_return_type (tree fco
, tree return_type
)
9314 if (return_type
== error_mark_node
)
9317 if (DECL_CONV_FN_P (fco
))
9318 DECL_NAME (fco
) = make_conv_op_name (return_type
);
9320 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
9322 result
= DECL_RESULT (fco
);
9323 if (result
== NULL_TREE
)
9325 if (TREE_TYPE (result
) == return_type
)
9328 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
9329 && !complete_type_or_else (return_type
, NULL_TREE
))
9332 /* We already have a DECL_RESULT from start_preparsed_function.
9333 Now we need to redo the work it and allocate_struct_function
9334 did to reflect the new type. */
9335 gcc_assert (current_function_decl
== fco
);
9336 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
9337 TYPE_MAIN_VARIANT (return_type
));
9338 DECL_ARTIFICIAL (result
) = 1;
9339 DECL_IGNORED_P (result
) = 1;
9340 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
9343 DECL_RESULT (fco
) = result
;
9345 if (!processing_template_decl
)
9347 bool aggr
= aggregate_value_p (result
, fco
);
9348 #ifdef PCC_STATIC_STRUCT_RETURN
9349 cfun
->returns_pcc_struct
= aggr
;
9351 cfun
->returns_struct
= aggr
;
9356 /* DECL is a local variable or parameter from the surrounding scope of a
9357 lambda-expression. Returns the decltype for a use of the capture field
9358 for DECL even if it hasn't been captured yet. */
9361 capture_decltype (tree decl
)
9363 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
9364 /* FIXME do lookup instead of list walk? */
9365 tree cap
= value_member (decl
, LAMBDA_EXPR_CAPTURE_LIST (lam
));
9369 type
= TREE_TYPE (TREE_PURPOSE (cap
));
9371 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
9374 error ("%qD is not captured", decl
);
9375 return error_mark_node
;
9378 type
= TREE_TYPE (decl
);
9379 if (TREE_CODE (type
) == REFERENCE_TYPE
9380 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
9381 type
= TREE_TYPE (type
);
9384 case CPLD_REFERENCE
:
9385 type
= TREE_TYPE (decl
);
9386 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9387 type
= build_reference_type (TREE_TYPE (decl
));
9394 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9396 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
9397 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
9399 type
= build_reference_type (type
);
9404 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
9405 this is a right unary fold. Otherwise it is a left unary fold. */
9408 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
9410 // Build a pack expansion (assuming expr has pack type).
9411 if (!uses_parameter_packs (expr
))
9413 error_at (location_of (expr
), "operand of fold expression has no "
9414 "unexpanded parameter packs");
9415 return error_mark_node
;
9417 tree pack
= make_pack_expansion (expr
);
9419 // Build the fold expression.
9420 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9421 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
);
9422 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9427 finish_left_unary_fold_expr (tree expr
, int op
)
9429 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
9433 finish_right_unary_fold_expr (tree expr
, int op
)
9435 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
9438 /* Build a binary fold expression over EXPR1 and EXPR2. The
9439 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
9440 has an unexpanded parameter pack). */
9443 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
9445 pack
= make_pack_expansion (pack
);
9446 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9447 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
, init
);
9448 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9453 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
9455 // Determine which expr has an unexpanded parameter pack and
9456 // set the pack and initial term.
9457 bool pack1
= uses_parameter_packs (expr1
);
9458 bool pack2
= uses_parameter_packs (expr2
);
9459 if (pack1
&& !pack2
)
9460 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
9461 else if (pack2
&& !pack1
)
9462 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
9466 error ("both arguments in binary fold have unexpanded parameter packs");
9468 error ("no unexpanded parameter packs in binary fold");
9470 return error_mark_node
;
9473 /* Finish __builtin_launder (arg). */
9476 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
9478 tree orig_arg
= arg
;
9479 if (!type_dependent_expression_p (arg
))
9480 arg
= decay_conversion (arg
, complain
);
9481 if (error_operand_p (arg
))
9482 return error_mark_node
;
9483 if (!type_dependent_expression_p (arg
)
9484 && TREE_CODE (TREE_TYPE (arg
)) != POINTER_TYPE
)
9486 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
9487 return error_mark_node
;
9489 if (processing_template_decl
)
9491 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
9492 TREE_TYPE (arg
), 1, arg
);
9495 #include "gt-cp-semantics.h"