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-2018 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
);
416 /* Like maybe_cleanup_point_expr except have the type of the new expression be
417 void so we don't need to create a temporary variable to hold the inner
418 expression. The reason why we do this is because the original type might be
419 an aggregate and we cannot create a temporary variable for that type. */
422 maybe_cleanup_point_expr_void (tree expr
)
424 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
425 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
431 /* Create a declaration statement for the declaration given by the DECL. */
434 add_decl_expr (tree decl
)
436 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
437 if (DECL_INITIAL (decl
)
438 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
439 r
= maybe_cleanup_point_expr_void (r
);
443 /* Finish a scope. */
446 do_poplevel (tree stmt_list
)
450 if (stmts_are_full_exprs_p ())
451 block
= poplevel (kept_level_p (), 1, 0);
453 stmt_list
= pop_stmt_list (stmt_list
);
455 if (!processing_template_decl
)
457 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
458 /* ??? See c_end_compound_stmt re statement expressions. */
464 /* Begin a new scope. */
467 do_pushlevel (scope_kind sk
)
469 tree ret
= push_stmt_list ();
470 if (stmts_are_full_exprs_p ())
471 begin_scope (sk
, NULL
);
475 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
476 when the current scope is exited. EH_ONLY is true when this is not
477 meant to apply to normal control flow transfer. */
480 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
482 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
483 CLEANUP_EH_ONLY (stmt
) = eh_only
;
485 CLEANUP_BODY (stmt
) = push_stmt_list ();
488 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
489 the current loops, represented by 'NULL_TREE' if we've seen a possible
490 exit, and 'error_mark_node' if not. This is currently used only to
491 suppress the warning about a function with no return statements, and
492 therefore we don't bother noting returns as possible exits. We also
493 don't bother with gotos. */
496 begin_maybe_infinite_loop (tree cond
)
498 /* Only track this while parsing a function, not during instantiation. */
499 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
500 && !processing_template_decl
))
502 bool maybe_infinite
= true;
505 cond
= fold_non_dependent_expr (cond
);
506 maybe_infinite
= integer_nonzerop (cond
);
508 vec_safe_push (cp_function_chain
->infinite_loops
,
509 maybe_infinite
? error_mark_node
: NULL_TREE
);
513 /* A break is a possible exit for the current loop. */
516 break_maybe_infinite_loop (void)
520 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
523 /* If we reach the end of the loop without seeing a possible exit, we have
527 end_maybe_infinite_loop (tree cond
)
529 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
530 && !processing_template_decl
))
532 tree current
= cp_function_chain
->infinite_loops
->pop();
533 if (current
!= NULL_TREE
)
535 cond
= fold_non_dependent_expr (cond
);
536 if (integer_nonzerop (cond
))
537 current_function_infinite_loop
= 1;
542 /* Begin a conditional that might contain a declaration. When generating
543 normal code, we want the declaration to appear before the statement
544 containing the conditional. When generating template code, we want the
545 conditional to be rendered as the raw DECL_EXPR. */
548 begin_cond (tree
*cond_p
)
550 if (processing_template_decl
)
551 *cond_p
= push_stmt_list ();
554 /* Finish such a conditional. */
557 finish_cond (tree
*cond_p
, tree expr
)
559 if (processing_template_decl
)
561 tree cond
= pop_stmt_list (*cond_p
);
563 if (expr
== NULL_TREE
)
564 /* Empty condition in 'for'. */
565 gcc_assert (empty_expr_stmt_p (cond
));
566 else if (check_for_bare_parameter_packs (expr
))
567 expr
= error_mark_node
;
568 else if (!empty_expr_stmt_p (cond
))
569 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
574 /* If *COND_P specifies a conditional with a declaration, transform the
577 for (; A x = 42;) { }
579 while (true) { A x = 42; if (!x) break; }
580 for (;;) { A x = 42; if (!x) break; }
581 The statement list for BODY will be empty if the conditional did
582 not declare anything. */
585 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
589 if (!TREE_SIDE_EFFECTS (body
))
593 *cond_p
= boolean_true_node
;
595 if_stmt
= begin_if_stmt ();
596 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, false, tf_warning_or_error
);
597 finish_if_stmt_cond (cond
, if_stmt
);
598 finish_break_stmt ();
599 finish_then_clause (if_stmt
);
600 finish_if_stmt (if_stmt
);
603 /* Finish a goto-statement. */
606 finish_goto_stmt (tree destination
)
608 if (identifier_p (destination
))
609 destination
= lookup_label (destination
);
611 /* We warn about unused labels with -Wunused. That means we have to
612 mark the used labels as used. */
613 if (TREE_CODE (destination
) == LABEL_DECL
)
614 TREE_USED (destination
) = 1;
617 destination
= mark_rvalue_use (destination
);
618 if (!processing_template_decl
)
620 destination
= cp_convert (ptr_type_node
, destination
,
621 tf_warning_or_error
);
622 if (error_operand_p (destination
))
625 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
630 check_goto (destination
);
632 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
633 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
636 /* COND is the condition-expression for an if, while, etc.,
637 statement. Convert it to a boolean value, if appropriate.
638 In addition, verify sequence points if -Wsequence-point is enabled. */
641 maybe_convert_cond (tree cond
)
643 /* Empty conditions remain empty. */
647 /* Wait until we instantiate templates before doing conversion. */
648 if (processing_template_decl
)
651 if (warn_sequence_point
)
652 verify_sequence_points (cond
);
654 /* Do the conversion. */
655 cond
= convert_from_reference (cond
);
657 if (TREE_CODE (cond
) == MODIFY_EXPR
658 && !TREE_NO_WARNING (cond
)
661 warning_at (EXPR_LOC_OR_LOC (cond
, input_location
), OPT_Wparentheses
,
662 "suggest parentheses around assignment used as truth value");
663 TREE_NO_WARNING (cond
) = 1;
666 return condition_conversion (cond
);
669 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
672 finish_expr_stmt (tree expr
)
675 location_t loc
= EXPR_LOCATION (expr
);
677 if (expr
!= NULL_TREE
)
679 /* If we ran into a problem, make sure we complained. */
680 gcc_assert (expr
!= error_mark_node
|| seen_error ());
682 if (!processing_template_decl
)
684 if (warn_sequence_point
)
685 verify_sequence_points (expr
);
686 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
688 else if (!type_dependent_expression_p (expr
))
689 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
690 tf_warning_or_error
);
692 if (check_for_bare_parameter_packs (expr
))
693 expr
= error_mark_node
;
695 /* Simplification of inner statement expressions, compound exprs,
696 etc can result in us already having an EXPR_STMT. */
697 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
699 if (TREE_CODE (expr
) != EXPR_STMT
)
700 expr
= build_stmt (loc
, EXPR_STMT
, expr
);
701 expr
= maybe_cleanup_point_expr_void (expr
);
711 /* Begin an if-statement. Returns a newly created IF_STMT if
718 scope
= do_pushlevel (sk_cond
);
719 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
720 NULL_TREE
, NULL_TREE
, scope
);
721 current_binding_level
->this_entity
= r
;
722 begin_cond (&IF_COND (r
));
726 /* Process the COND of an if-statement, which may be given by
730 finish_if_stmt_cond (tree cond
, tree if_stmt
)
732 cond
= maybe_convert_cond (cond
);
733 if (IF_STMT_CONSTEXPR_P (if_stmt
)
734 && !type_dependent_expression_p (cond
)
735 && require_constant_expression (cond
)
736 && !value_dependent_expression_p (cond
))
738 cond
= instantiate_non_dependent_expr (cond
);
739 cond
= cxx_constant_value (cond
, NULL_TREE
);
741 finish_cond (&IF_COND (if_stmt
), cond
);
743 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
747 /* Finish the then-clause of an if-statement, which may be given by
751 finish_then_clause (tree if_stmt
)
753 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
757 /* Begin the else-clause of an if-statement. */
760 begin_else_clause (tree if_stmt
)
762 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
765 /* Finish the else-clause of an if-statement, which may be given by
769 finish_else_clause (tree if_stmt
)
771 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
774 /* Finish an if-statement. */
777 finish_if_stmt (tree if_stmt
)
779 tree scope
= IF_SCOPE (if_stmt
);
780 IF_SCOPE (if_stmt
) = NULL
;
781 add_stmt (do_poplevel (scope
));
784 /* Begin a while-statement. Returns a newly created WHILE_STMT if
788 begin_while_stmt (void)
791 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
793 WHILE_BODY (r
) = do_pushlevel (sk_block
);
794 begin_cond (&WHILE_COND (r
));
798 /* Process the COND of a while-statement, which may be given by
802 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
,
803 unsigned short unroll
)
805 cond
= maybe_convert_cond (cond
);
806 finish_cond (&WHILE_COND (while_stmt
), cond
);
807 begin_maybe_infinite_loop (cond
);
808 if (ivdep
&& cond
!= error_mark_node
)
809 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
810 TREE_TYPE (WHILE_COND (while_stmt
)),
811 WHILE_COND (while_stmt
),
812 build_int_cst (integer_type_node
,
813 annot_expr_ivdep_kind
),
815 if (unroll
&& cond
!= error_mark_node
)
816 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
817 TREE_TYPE (WHILE_COND (while_stmt
)),
818 WHILE_COND (while_stmt
),
819 build_int_cst (integer_type_node
,
820 annot_expr_unroll_kind
),
821 build_int_cst (integer_type_node
,
823 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
826 /* Finish a while-statement, which may be given by WHILE_STMT. */
829 finish_while_stmt (tree while_stmt
)
831 end_maybe_infinite_loop (boolean_true_node
);
832 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
835 /* Begin a do-statement. Returns a newly created DO_STMT if
841 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
842 begin_maybe_infinite_loop (boolean_true_node
);
844 DO_BODY (r
) = push_stmt_list ();
848 /* Finish the body of a do-statement, which may be given by DO_STMT. */
851 finish_do_body (tree do_stmt
)
853 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
855 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
856 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
858 if (IS_EMPTY_STMT (body
))
859 warning (OPT_Wempty_body
,
860 "suggest explicit braces around empty body in %<do%> statement");
863 /* Finish a do-statement, which may be given by DO_STMT, and whose
864 COND is as indicated. */
867 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
, unsigned short unroll
)
869 cond
= maybe_convert_cond (cond
);
870 end_maybe_infinite_loop (cond
);
871 if (ivdep
&& cond
!= error_mark_node
)
872 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
873 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
),
875 if (unroll
&& cond
!= error_mark_node
)
876 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
877 build_int_cst (integer_type_node
, annot_expr_unroll_kind
),
878 build_int_cst (integer_type_node
, unroll
));
879 DO_COND (do_stmt
) = cond
;
882 /* Finish a return-statement. The EXPRESSION returned, if any, is as
886 finish_return_stmt (tree expr
)
891 expr
= check_return_expr (expr
, &no_warning
);
893 if (error_operand_p (expr
)
894 || (flag_openmp
&& !check_omp_return ()))
896 /* Suppress -Wreturn-type for this function. */
897 if (warn_return_type
)
898 TREE_NO_WARNING (current_function_decl
) = true;
899 return error_mark_node
;
902 if (!processing_template_decl
)
904 if (warn_sequence_point
)
905 verify_sequence_points (expr
);
907 if (DECL_DESTRUCTOR_P (current_function_decl
)
908 || (DECL_CONSTRUCTOR_P (current_function_decl
)
909 && targetm
.cxx
.cdtor_returns_this ()))
911 /* Similarly, all destructors must run destructors for
912 base-classes before returning. So, all returns in a
913 destructor get sent to the DTOR_LABEL; finish_function emits
914 code to return a value there. */
915 return finish_goto_stmt (cdtor_label
);
919 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
920 TREE_NO_WARNING (r
) |= no_warning
;
921 r
= maybe_cleanup_point_expr_void (r
);
927 /* Begin the scope of a for-statement or a range-for-statement.
928 Both the returned trees are to be used in a call to
929 begin_for_stmt or begin_range_for_stmt. */
932 begin_for_scope (tree
*init
)
934 tree scope
= NULL_TREE
;
935 if (flag_new_for_scope
)
936 scope
= do_pushlevel (sk_for
);
938 if (processing_template_decl
)
939 *init
= push_stmt_list ();
946 /* Begin a for-statement. Returns a new FOR_STMT.
947 SCOPE and INIT should be the return of begin_for_scope,
951 begin_for_stmt (tree scope
, tree init
)
955 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
956 NULL_TREE
, NULL_TREE
, NULL_TREE
);
958 if (scope
== NULL_TREE
)
960 gcc_assert (!init
|| !flag_new_for_scope
);
962 scope
= begin_for_scope (&init
);
964 FOR_INIT_STMT (r
) = init
;
965 FOR_SCOPE (r
) = scope
;
970 /* Finish the init-statement of a for-statement, which may be
971 given by FOR_STMT. */
974 finish_init_stmt (tree for_stmt
)
976 if (processing_template_decl
)
977 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
979 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
980 begin_cond (&FOR_COND (for_stmt
));
983 /* Finish the COND of a for-statement, which may be given by
987 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
, unsigned short unroll
)
989 cond
= maybe_convert_cond (cond
);
990 finish_cond (&FOR_COND (for_stmt
), cond
);
991 begin_maybe_infinite_loop (cond
);
992 if (ivdep
&& cond
!= error_mark_node
)
993 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
994 TREE_TYPE (FOR_COND (for_stmt
)),
996 build_int_cst (integer_type_node
,
997 annot_expr_ivdep_kind
),
999 if (unroll
&& cond
!= error_mark_node
)
1000 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1001 TREE_TYPE (FOR_COND (for_stmt
)),
1002 FOR_COND (for_stmt
),
1003 build_int_cst (integer_type_node
,
1004 annot_expr_unroll_kind
),
1005 build_int_cst (integer_type_node
,
1007 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
1010 /* Finish the increment-EXPRESSION in a for-statement, which may be
1011 given by FOR_STMT. */
1014 finish_for_expr (tree expr
, tree for_stmt
)
1018 /* If EXPR is an overloaded function, issue an error; there is no
1019 context available to use to perform overload resolution. */
1020 if (type_unknown_p (expr
))
1022 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1023 expr
= error_mark_node
;
1025 if (!processing_template_decl
)
1027 if (warn_sequence_point
)
1028 verify_sequence_points (expr
);
1029 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1030 tf_warning_or_error
);
1032 else if (!type_dependent_expression_p (expr
))
1033 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1034 tf_warning_or_error
);
1035 expr
= maybe_cleanup_point_expr_void (expr
);
1036 if (check_for_bare_parameter_packs (expr
))
1037 expr
= error_mark_node
;
1038 FOR_EXPR (for_stmt
) = expr
;
1041 /* Finish the body of a for-statement, which may be given by
1042 FOR_STMT. The increment-EXPR for the loop must be
1044 It can also finish RANGE_FOR_STMT. */
1047 finish_for_stmt (tree for_stmt
)
1049 end_maybe_infinite_loop (boolean_true_node
);
1051 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1052 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1054 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1056 /* Pop the scope for the body of the loop. */
1057 if (flag_new_for_scope
)
1060 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1061 ? &RANGE_FOR_SCOPE (for_stmt
)
1062 : &FOR_SCOPE (for_stmt
));
1065 add_stmt (do_poplevel (scope
));
1069 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1070 SCOPE and INIT should be the return of begin_for_scope,
1072 To finish it call finish_for_stmt(). */
1075 begin_range_for_stmt (tree scope
, tree init
)
1079 begin_maybe_infinite_loop (boolean_false_node
);
1081 r
= build_stmt (input_location
, RANGE_FOR_STMT
,
1082 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1084 if (scope
== NULL_TREE
)
1086 gcc_assert (!init
|| !flag_new_for_scope
);
1088 scope
= begin_for_scope (&init
);
1091 /* RANGE_FOR_STMTs do not use nor save the init tree, so we
1094 pop_stmt_list (init
);
1095 RANGE_FOR_SCOPE (r
) = scope
;
1100 /* Finish the head of a range-based for statement, which may
1101 be given by RANGE_FOR_STMT. DECL must be the declaration
1102 and EXPR must be the loop expression. */
1105 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1107 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1108 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1109 add_stmt (range_for_stmt
);
1110 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1113 /* Finish a break-statement. */
1116 finish_break_stmt (void)
1118 /* In switch statements break is sometimes stylistically used after
1119 a return statement. This can lead to spurious warnings about
1120 control reaching the end of a non-void function when it is
1121 inlined. Note that we are calling block_may_fallthru with
1122 language specific tree nodes; this works because
1123 block_may_fallthru returns true when given something it does not
1125 if (!block_may_fallthru (cur_stmt_list
))
1128 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1131 /* Finish a continue-statement. */
1134 finish_continue_stmt (void)
1136 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1139 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1143 begin_switch_stmt (void)
1147 scope
= do_pushlevel (sk_cond
);
1148 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1150 begin_cond (&SWITCH_STMT_COND (r
));
1155 /* Finish the cond of a switch-statement. */
1158 finish_switch_cond (tree cond
, tree switch_stmt
)
1160 tree orig_type
= NULL
;
1162 if (!processing_template_decl
)
1164 /* Convert the condition to an integer or enumeration type. */
1165 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1166 if (cond
== NULL_TREE
)
1168 error ("switch quantity not an integer");
1169 cond
= error_mark_node
;
1171 /* We want unlowered type here to handle enum bit-fields. */
1172 orig_type
= unlowered_expr_type (cond
);
1173 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1174 orig_type
= TREE_TYPE (cond
);
1175 if (cond
!= error_mark_node
)
1179 Integral promotions are performed. */
1180 cond
= perform_integral_promotions (cond
);
1181 cond
= maybe_cleanup_point_expr (cond
);
1184 if (check_for_bare_parameter_packs (cond
))
1185 cond
= error_mark_node
;
1186 else if (!processing_template_decl
&& warn_sequence_point
)
1187 verify_sequence_points (cond
);
1189 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1190 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1191 add_stmt (switch_stmt
);
1192 push_switch (switch_stmt
);
1193 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1196 /* Finish the body of a switch-statement, which may be given by
1197 SWITCH_STMT. The COND to switch on is indicated. */
1200 finish_switch_stmt (tree switch_stmt
)
1204 SWITCH_STMT_BODY (switch_stmt
) =
1205 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1208 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1209 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1210 add_stmt (do_poplevel (scope
));
1213 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1217 begin_try_block (void)
1219 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1221 TRY_STMTS (r
) = push_stmt_list ();
1225 /* Likewise, for a function-try-block. The block returned in
1226 *COMPOUND_STMT is an artificial outer scope, containing the
1227 function-try-block. */
1230 begin_function_try_block (tree
*compound_stmt
)
1233 /* This outer scope does not exist in the C++ standard, but we need
1234 a place to put __FUNCTION__ and similar variables. */
1235 *compound_stmt
= begin_compound_stmt (0);
1236 r
= begin_try_block ();
1237 FN_TRY_BLOCK_P (r
) = 1;
1241 /* Finish a try-block, which may be given by TRY_BLOCK. */
1244 finish_try_block (tree try_block
)
1246 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1247 TRY_HANDLERS (try_block
) = push_stmt_list ();
1250 /* Finish the body of a cleanup try-block, which may be given by
1254 finish_cleanup_try_block (tree try_block
)
1256 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1259 /* Finish an implicitly generated try-block, with a cleanup is given
1263 finish_cleanup (tree cleanup
, tree try_block
)
1265 TRY_HANDLERS (try_block
) = cleanup
;
1266 CLEANUP_P (try_block
) = 1;
1269 /* Likewise, for a function-try-block. */
1272 finish_function_try_block (tree try_block
)
1274 finish_try_block (try_block
);
1275 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1276 the try block, but moving it inside. */
1277 in_function_try_handler
= 1;
1280 /* Finish a handler-sequence for a try-block, which may be given by
1284 finish_handler_sequence (tree try_block
)
1286 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1287 check_handlers (TRY_HANDLERS (try_block
));
1290 /* Finish the handler-seq for a function-try-block, given by
1291 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1292 begin_function_try_block. */
1295 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1297 in_function_try_handler
= 0;
1298 finish_handler_sequence (try_block
);
1299 finish_compound_stmt (compound_stmt
);
1302 /* Begin a handler. Returns a HANDLER if appropriate. */
1305 begin_handler (void)
1309 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1312 /* Create a binding level for the eh_info and the exception object
1314 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1319 /* Finish the handler-parameters for a handler, which may be given by
1320 HANDLER. DECL is the declaration for the catch parameter, or NULL
1321 if this is a `catch (...)' clause. */
1324 finish_handler_parms (tree decl
, tree handler
)
1326 tree type
= NULL_TREE
;
1327 if (processing_template_decl
)
1331 decl
= pushdecl (decl
);
1332 decl
= push_template_decl (decl
);
1333 HANDLER_PARMS (handler
) = decl
;
1334 type
= TREE_TYPE (decl
);
1339 type
= expand_start_catch_block (decl
);
1340 if (warn_catch_value
1341 && type
!= NULL_TREE
1342 && type
!= error_mark_node
1343 && TREE_CODE (TREE_TYPE (decl
)) != REFERENCE_TYPE
)
1345 tree orig_type
= TREE_TYPE (decl
);
1346 if (CLASS_TYPE_P (orig_type
))
1348 if (TYPE_POLYMORPHIC_P (orig_type
))
1349 warning (OPT_Wcatch_value_
,
1350 "catching polymorphic type %q#T by value", orig_type
);
1351 else if (warn_catch_value
> 1)
1352 warning (OPT_Wcatch_value_
,
1353 "catching type %q#T by value", orig_type
);
1355 else if (warn_catch_value
> 2)
1356 warning (OPT_Wcatch_value_
,
1357 "catching non-reference type %q#T", orig_type
);
1360 HANDLER_TYPE (handler
) = type
;
1363 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1364 the return value from the matching call to finish_handler_parms. */
1367 finish_handler (tree handler
)
1369 if (!processing_template_decl
)
1370 expand_end_catch_block ();
1371 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1374 /* Begin a compound statement. FLAGS contains some bits that control the
1375 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1376 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1377 block of a function. If BCS_TRY_BLOCK is set, this is the block
1378 created on behalf of a TRY statement. Returns a token to be passed to
1379 finish_compound_stmt. */
1382 begin_compound_stmt (unsigned int flags
)
1386 if (flags
& BCS_NO_SCOPE
)
1388 r
= push_stmt_list ();
1389 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1391 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1392 But, if it's a statement-expression with a scopeless block, there's
1393 nothing to keep, and we don't want to accidentally keep a block
1394 *inside* the scopeless block. */
1395 keep_next_level (false);
1399 scope_kind sk
= sk_block
;
1400 if (flags
& BCS_TRY_BLOCK
)
1402 else if (flags
& BCS_TRANSACTION
)
1403 sk
= sk_transaction
;
1404 r
= do_pushlevel (sk
);
1407 /* When processing a template, we need to remember where the braces were,
1408 so that we can set up identical scopes when instantiating the template
1409 later. BIND_EXPR is a handy candidate for this.
1410 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1411 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1412 processing templates. */
1413 if (processing_template_decl
)
1415 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1416 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1417 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1418 TREE_SIDE_EFFECTS (r
) = 1;
1424 /* Finish a compound-statement, which is given by STMT. */
1427 finish_compound_stmt (tree stmt
)
1429 if (TREE_CODE (stmt
) == BIND_EXPR
)
1431 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1432 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1433 discard the BIND_EXPR so it can be merged with the containing
1435 if (TREE_CODE (body
) == STATEMENT_LIST
1436 && STATEMENT_LIST_HEAD (body
) == NULL
1437 && !BIND_EXPR_BODY_BLOCK (stmt
)
1438 && !BIND_EXPR_TRY_BLOCK (stmt
))
1441 BIND_EXPR_BODY (stmt
) = body
;
1443 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1444 stmt
= pop_stmt_list (stmt
);
1447 /* Destroy any ObjC "super" receivers that may have been
1449 objc_clear_super_receiver ();
1451 stmt
= do_poplevel (stmt
);
1454 /* ??? See c_end_compound_stmt wrt statement expressions. */
1458 /* Finish an asm-statement, whose components are a STRING, some
1459 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1460 LABELS. Also note whether the asm-statement should be
1461 considered volatile. */
1464 finish_asm_stmt (int volatile_p
, tree string
, tree output_operands
,
1465 tree input_operands
, tree clobbers
, tree labels
)
1469 int ninputs
= list_length (input_operands
);
1470 int noutputs
= list_length (output_operands
);
1472 if (!processing_template_decl
)
1474 const char *constraint
;
1475 const char **oconstraints
;
1476 bool allows_mem
, allows_reg
, is_inout
;
1480 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1482 string
= resolve_asm_operand_names (string
, output_operands
,
1483 input_operands
, labels
);
1485 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1487 operand
= TREE_VALUE (t
);
1489 /* ??? Really, this should not be here. Users should be using a
1490 proper lvalue, dammit. But there's a long history of using
1491 casts in the output operands. In cases like longlong.h, this
1492 becomes a primitive form of typechecking -- if the cast can be
1493 removed, then the output operand had a type of the proper width;
1494 otherwise we'll get an error. Gross, but ... */
1495 STRIP_NOPS (operand
);
1497 operand
= mark_lvalue_use (operand
);
1499 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1500 operand
= error_mark_node
;
1502 if (operand
!= error_mark_node
1503 && (TREE_READONLY (operand
)
1504 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1505 /* Functions are not modifiable, even though they are
1507 || TREE_CODE (TREE_TYPE (operand
)) == FUNCTION_TYPE
1508 || TREE_CODE (TREE_TYPE (operand
)) == METHOD_TYPE
1509 /* If it's an aggregate and any field is const, then it is
1510 effectively const. */
1511 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1512 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1513 cxx_readonly_error (operand
, lv_asm
);
1515 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1516 oconstraints
[i
] = constraint
;
1518 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1519 &allows_mem
, &allows_reg
, &is_inout
))
1521 /* If the operand is going to end up in memory,
1522 mark it addressable. */
1523 if (!allows_reg
&& !cxx_mark_addressable (operand
))
1524 operand
= error_mark_node
;
1527 operand
= error_mark_node
;
1529 TREE_VALUE (t
) = operand
;
1532 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1534 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1535 bool constraint_parsed
1536 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1537 oconstraints
, &allows_mem
, &allows_reg
);
1538 /* If the operand is going to end up in memory, don't call
1539 decay_conversion. */
1540 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1541 operand
= mark_lvalue_use (TREE_VALUE (t
));
1543 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1545 /* If the type of the operand hasn't been determined (e.g.,
1546 because it involves an overloaded function), then issue
1547 an error message. There's no context available to
1548 resolve the overloading. */
1549 if (TREE_TYPE (operand
) == unknown_type_node
)
1551 error ("type of asm operand %qE could not be determined",
1553 operand
= error_mark_node
;
1556 if (constraint_parsed
)
1558 /* If the operand is going to end up in memory,
1559 mark it addressable. */
1560 if (!allows_reg
&& allows_mem
)
1562 /* Strip the nops as we allow this case. FIXME, this really
1563 should be rejected or made deprecated. */
1564 STRIP_NOPS (operand
);
1565 if (!cxx_mark_addressable (operand
))
1566 operand
= error_mark_node
;
1568 else if (!allows_reg
&& !allows_mem
)
1570 /* If constraint allows neither register nor memory,
1571 try harder to get a constant. */
1572 tree constop
= maybe_constant_value (operand
);
1573 if (TREE_CONSTANT (constop
))
1578 operand
= error_mark_node
;
1580 TREE_VALUE (t
) = operand
;
1584 r
= build_stmt (input_location
, ASM_EXPR
, string
,
1585 output_operands
, input_operands
,
1587 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1588 r
= maybe_cleanup_point_expr_void (r
);
1589 return add_stmt (r
);
1592 /* Finish a label with the indicated NAME. Returns the new label. */
1595 finish_label_stmt (tree name
)
1597 tree decl
= define_label (input_location
, name
);
1599 if (decl
== error_mark_node
)
1600 return error_mark_node
;
1602 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1607 /* Finish a series of declarations for local labels. G++ allows users
1608 to declare "local" labels, i.e., labels with scope. This extension
1609 is useful when writing code involving statement-expressions. */
1612 finish_label_decl (tree name
)
1614 if (!at_function_scope_p ())
1616 error ("__label__ declarations are only allowed in function scopes");
1620 add_decl_expr (declare_local_label (name
));
1623 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1626 finish_decl_cleanup (tree decl
, tree cleanup
)
1628 push_cleanup (decl
, cleanup
, false);
1631 /* If the current scope exits with an exception, run CLEANUP. */
1634 finish_eh_cleanup (tree cleanup
)
1636 push_cleanup (NULL
, cleanup
, true);
1639 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1640 order they were written by the user. Each node is as for
1641 emit_mem_initializers. */
1644 finish_mem_initializers (tree mem_inits
)
1646 /* Reorder the MEM_INITS so that they are in the order they appeared
1647 in the source program. */
1648 mem_inits
= nreverse (mem_inits
);
1650 if (processing_template_decl
)
1654 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1656 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1657 check for bare parameter packs in the TREE_VALUE, because
1658 any parameter packs in the TREE_VALUE have already been
1659 bound as part of the TREE_PURPOSE. See
1660 make_pack_expansion for more information. */
1661 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1662 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1663 TREE_VALUE (mem
) = error_mark_node
;
1666 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1667 CTOR_INITIALIZER
, mem_inits
));
1670 emit_mem_initializers (mem_inits
);
1673 /* Obfuscate EXPR if it looks like an id-expression or member access so
1674 that the call to finish_decltype in do_auto_deduction will give the
1678 force_paren_expr (tree expr
)
1680 /* This is only needed for decltype(auto) in C++14. */
1681 if (cxx_dialect
< cxx14
)
1684 /* If we're in unevaluated context, we can't be deducing a
1685 return/initializer type, so we don't need to mess with this. */
1686 if (cp_unevaluated_operand
)
1689 if (!DECL_P (expr
) && TREE_CODE (expr
) != COMPONENT_REF
1690 && TREE_CODE (expr
) != SCOPE_REF
)
1693 if (TREE_CODE (expr
) == COMPONENT_REF
1694 || TREE_CODE (expr
) == SCOPE_REF
)
1695 REF_PARENTHESIZED_P (expr
) = true;
1696 else if (processing_template_decl
)
1697 expr
= build1 (PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1698 else if (VAR_P (expr
) && DECL_HARD_REGISTER (expr
))
1699 /* We can't bind a hard register variable to a reference. */;
1702 cp_lvalue_kind kind
= lvalue_kind (expr
);
1703 if ((kind
& ~clk_class
) != clk_none
)
1705 tree type
= unlowered_expr_type (expr
);
1706 bool rval
= !!(kind
& clk_rvalueref
);
1707 type
= cp_build_reference_type (type
, rval
);
1708 /* This inhibits warnings in, eg, cxx_mark_addressable
1710 warning_sentinel
s (extra_warnings
);
1711 expr
= build_static_cast (type
, expr
, tf_error
);
1712 if (expr
!= error_mark_node
)
1713 REF_PARENTHESIZED_P (expr
) = true;
1720 /* If T is an id-expression obfuscated by force_paren_expr, undo the
1721 obfuscation and return the underlying id-expression. Otherwise
1725 maybe_undo_parenthesized_ref (tree t
)
1727 if (cxx_dialect
< cxx14
)
1730 if (INDIRECT_REF_P (t
) && 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);
1741 else if (TREE_CODE (t
) == PAREN_EXPR
)
1742 t
= TREE_OPERAND (t
, 0);
1747 /* Finish a parenthesized expression EXPR. */
1750 finish_parenthesized_expr (cp_expr expr
)
1753 /* This inhibits warnings in c_common_truthvalue_conversion. */
1754 TREE_NO_WARNING (expr
) = 1;
1756 if (TREE_CODE (expr
) == OFFSET_REF
1757 || TREE_CODE (expr
) == SCOPE_REF
)
1758 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1759 enclosed in parentheses. */
1760 PTRMEM_OK_P (expr
) = 0;
1762 if (TREE_CODE (expr
) == STRING_CST
)
1763 PAREN_STRING_LITERAL_P (expr
) = 1;
1765 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
1770 /* Finish a reference to a non-static data member (DECL) that is not
1771 preceded by `.' or `->'. */
1774 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1776 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1777 bool try_omp_private
= !object
&& omp_private_member_map
;
1782 tree scope
= qualifying_scope
;
1783 if (scope
== NULL_TREE
)
1784 scope
= context_for_name_lookup (decl
);
1785 object
= maybe_dummy_object (scope
, NULL
);
1788 object
= maybe_resolve_dummy (object
, true);
1789 if (object
== error_mark_node
)
1790 return error_mark_node
;
1792 /* DR 613/850: Can use non-static data members without an associated
1793 object in sizeof/decltype/alignof. */
1794 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
1795 && (!processing_template_decl
|| !current_class_ref
))
1797 if (current_function_decl
1798 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1799 error ("invalid use of member %qD in static member function", decl
);
1801 error ("invalid use of non-static data member %qD", decl
);
1802 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
1804 return error_mark_node
;
1807 if (current_class_ptr
)
1808 TREE_USED (current_class_ptr
) = 1;
1809 if (processing_template_decl
&& !qualifying_scope
)
1811 tree type
= TREE_TYPE (decl
);
1813 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1814 /* Quals on the object don't matter. */;
1815 else if (PACK_EXPANSION_P (type
))
1816 /* Don't bother trying to represent this. */
1820 /* Set the cv qualifiers. */
1821 int quals
= cp_type_quals (TREE_TYPE (object
));
1823 if (DECL_MUTABLE_P (decl
))
1824 quals
&= ~TYPE_QUAL_CONST
;
1826 quals
|= cp_type_quals (TREE_TYPE (decl
));
1827 type
= cp_build_qualified_type (type
, quals
);
1830 ret
= (convert_from_reference
1831 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
1833 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1834 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1836 else if (processing_template_decl
)
1837 ret
= build_qualified_name (TREE_TYPE (decl
),
1840 /*template_p=*/false);
1843 tree access_type
= TREE_TYPE (object
);
1845 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
1846 decl
, tf_warning_or_error
);
1848 /* If the data member was named `C::M', convert `*this' to `C'
1850 if (qualifying_scope
)
1852 tree binfo
= NULL_TREE
;
1853 object
= build_scoped_ref (object
, qualifying_scope
,
1857 ret
= build_class_member_access_expr (object
, decl
,
1858 /*access_path=*/NULL_TREE
,
1859 /*preserve_reference=*/false,
1860 tf_warning_or_error
);
1862 if (try_omp_private
)
1864 tree
*v
= omp_private_member_map
->get (decl
);
1866 ret
= convert_from_reference (*v
);
1871 /* If we are currently parsing a template and we encountered a typedef
1872 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1873 adds the typedef to a list tied to the current template.
1874 At template instantiation time, that list is walked and access check
1875 performed for each typedef.
1876 LOCATION is the location of the usage point of TYPEDEF_DECL. */
1879 add_typedef_to_current_template_for_access_check (tree typedef_decl
,
1881 location_t location
)
1883 tree template_info
= NULL
;
1884 tree cs
= current_scope ();
1886 if (!is_typedef_decl (typedef_decl
)
1888 || !CLASS_TYPE_P (context
)
1892 if (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
)
1893 template_info
= get_template_info (cs
);
1896 && TI_TEMPLATE (template_info
)
1897 && !currently_open_class (context
))
1898 append_type_to_template_for_access_check (cs
, typedef_decl
,
1902 /* DECL was the declaration to which a qualified-id resolved. Issue
1903 an error message if it is not accessible. If OBJECT_TYPE is
1904 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1905 type of `*x', or `x', respectively. If the DECL was named as
1906 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1909 check_accessibility_of_qualified_id (tree decl
,
1911 tree nested_name_specifier
)
1914 tree qualifying_type
= NULL_TREE
;
1916 /* If we are parsing a template declaration and if decl is a typedef,
1917 add it to a list tied to the template.
1918 At template instantiation time, that list will be walked and
1919 access check performed. */
1920 add_typedef_to_current_template_for_access_check (decl
,
1921 nested_name_specifier
1922 ? nested_name_specifier
1923 : DECL_CONTEXT (decl
),
1926 /* If we're not checking, return immediately. */
1927 if (deferred_access_no_check
)
1930 /* Determine the SCOPE of DECL. */
1931 scope
= context_for_name_lookup (decl
);
1932 /* If the SCOPE is not a type, then DECL is not a member. */
1933 if (!TYPE_P (scope
))
1935 /* Compute the scope through which DECL is being accessed. */
1937 /* OBJECT_TYPE might not be a class type; consider:
1939 class A { typedef int I; };
1943 In this case, we will have "A::I" as the DECL, but "I" as the
1945 && CLASS_TYPE_P (object_type
)
1946 && DERIVED_FROM_P (scope
, object_type
))
1947 /* If we are processing a `->' or `.' expression, use the type of the
1949 qualifying_type
= object_type
;
1950 else if (nested_name_specifier
)
1952 /* If the reference is to a non-static member of the
1953 current class, treat it as if it were referenced through
1956 if (DECL_NONSTATIC_MEMBER_P (decl
)
1957 && current_class_ptr
1958 && DERIVED_FROM_P (scope
, ct
= current_nonlambda_class_type ()))
1959 qualifying_type
= ct
;
1960 /* Otherwise, use the type indicated by the
1961 nested-name-specifier. */
1963 qualifying_type
= nested_name_specifier
;
1966 /* Otherwise, the name must be from the current class or one of
1968 qualifying_type
= currently_open_derived_class (scope
);
1971 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
1972 or similar in a default argument value. */
1973 && CLASS_TYPE_P (qualifying_type
)
1974 && !dependent_type_p (qualifying_type
))
1975 perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
1976 decl
, tf_warning_or_error
);
1979 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
1980 class named to the left of the "::" operator. DONE is true if this
1981 expression is a complete postfix-expression; it is false if this
1982 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
1983 iff this expression is the operand of '&'. TEMPLATE_P is true iff
1984 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
1985 is true iff this qualified name appears as a template argument. */
1988 finish_qualified_id_expr (tree qualifying_class
,
1993 bool template_arg_p
,
1994 tsubst_flags_t complain
)
1996 gcc_assert (TYPE_P (qualifying_class
));
1998 if (error_operand_p (expr
))
1999 return error_mark_node
;
2001 if ((DECL_P (expr
) || BASELINK_P (expr
))
2002 && !mark_used (expr
, complain
))
2003 return error_mark_node
;
2007 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
2009 /* cp_parser_lookup_name thought we were looking for a type,
2010 but we're actually looking for a declaration. */
2011 qualifying_class
= TYPE_CONTEXT (expr
);
2012 expr
= TYPE_IDENTIFIER (expr
);
2015 check_template_keyword (expr
);
2018 /* If EXPR occurs as the operand of '&', use special handling that
2019 permits a pointer-to-member. */
2020 if (address_p
&& done
)
2022 if (TREE_CODE (expr
) == SCOPE_REF
)
2023 expr
= TREE_OPERAND (expr
, 1);
2024 expr
= build_offset_ref (qualifying_class
, expr
,
2025 /*address_p=*/true, complain
);
2029 /* No need to check access within an enum. */
2030 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
)
2033 /* Within the scope of a class, turn references to non-static
2034 members into expression of the form "this->...". */
2036 /* But, within a template argument, we do not want make the
2037 transformation, as there is no "this" pointer. */
2039 else if (TREE_CODE (expr
) == FIELD_DECL
)
2041 push_deferring_access_checks (dk_no_check
);
2042 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2044 pop_deferring_access_checks ();
2046 else if (BASELINK_P (expr
))
2048 /* See if any of the functions are non-static members. */
2049 /* If so, the expression may be relative to 'this'. */
2050 if (!shared_member_p (expr
)
2051 && current_class_ptr
2052 && DERIVED_FROM_P (qualifying_class
,
2053 current_nonlambda_class_type ()))
2054 expr
= (build_class_member_access_expr
2055 (maybe_dummy_object (qualifying_class
, NULL
),
2057 BASELINK_ACCESS_BINFO (expr
),
2058 /*preserve_reference=*/false,
2061 /* The expression is a qualified name whose address is not
2063 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2068 /* In a template, return a SCOPE_REF for most qualified-ids
2069 so that we can check access at instantiation time. But if
2070 we're looking at a member of the current instantiation, we
2071 know we have access and building up the SCOPE_REF confuses
2072 non-type template argument handling. */
2073 if (processing_template_decl
2074 && (!currently_open_class (qualifying_class
)
2075 || TREE_CODE (expr
) == BIT_NOT_EXPR
))
2076 expr
= build_qualified_name (TREE_TYPE (expr
),
2077 qualifying_class
, expr
,
2080 expr
= convert_from_reference (expr
);
2086 /* Begin a statement-expression. The value returned must be passed to
2087 finish_stmt_expr. */
2090 begin_stmt_expr (void)
2092 return push_stmt_list ();
2095 /* Process the final expression of a statement expression. EXPR can be
2096 NULL, if the final expression is empty. Return a STATEMENT_LIST
2097 containing all the statements in the statement-expression, or
2098 ERROR_MARK_NODE if there was an error. */
2101 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2103 if (error_operand_p (expr
))
2105 /* The type of the statement-expression is the type of the last
2107 TREE_TYPE (stmt_expr
) = error_mark_node
;
2108 return error_mark_node
;
2111 /* If the last statement does not have "void" type, then the value
2112 of the last statement is the value of the entire expression. */
2115 tree type
= TREE_TYPE (expr
);
2117 if (type
&& type_unknown_p (type
))
2119 error ("a statement expression is an insufficient context"
2120 " for overload resolution");
2121 TREE_TYPE (stmt_expr
) = error_mark_node
;
2122 return error_mark_node
;
2124 else if (processing_template_decl
)
2126 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2127 expr
= add_stmt (expr
);
2128 /* Mark the last statement so that we can recognize it as such at
2129 template-instantiation time. */
2130 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2132 else if (VOID_TYPE_P (type
))
2134 /* Just treat this like an ordinary statement. */
2135 expr
= finish_expr_stmt (expr
);
2139 /* It actually has a value we need to deal with. First, force it
2140 to be an rvalue so that we won't need to build up a copy
2141 constructor call later when we try to assign it to something. */
2142 expr
= force_rvalue (expr
, tf_warning_or_error
);
2143 if (error_operand_p (expr
))
2144 return error_mark_node
;
2146 /* Update for array-to-pointer decay. */
2147 type
= TREE_TYPE (expr
);
2149 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2150 normal statement, but don't convert to void or actually add
2152 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2153 expr
= maybe_cleanup_point_expr (expr
);
2157 /* The type of the statement-expression is the type of the last
2159 TREE_TYPE (stmt_expr
) = type
;
2165 /* Finish a statement-expression. EXPR should be the value returned
2166 by the previous begin_stmt_expr. Returns an expression
2167 representing the statement-expression. */
2170 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2175 if (error_operand_p (stmt_expr
))
2177 pop_stmt_list (stmt_expr
);
2178 return error_mark_node
;
2181 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2183 type
= TREE_TYPE (stmt_expr
);
2184 result
= pop_stmt_list (stmt_expr
);
2185 TREE_TYPE (result
) = type
;
2187 if (processing_template_decl
)
2189 result
= build_min (STMT_EXPR
, type
, result
);
2190 TREE_SIDE_EFFECTS (result
) = 1;
2191 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2193 else if (CLASS_TYPE_P (type
))
2195 /* Wrap the statement-expression in a TARGET_EXPR so that the
2196 temporary object created by the final expression is destroyed at
2197 the end of the full-expression containing the
2198 statement-expression. */
2199 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2205 /* Returns the expression which provides the value of STMT_EXPR. */
2208 stmt_expr_value_expr (tree stmt_expr
)
2210 tree t
= STMT_EXPR_STMT (stmt_expr
);
2212 if (TREE_CODE (t
) == BIND_EXPR
)
2213 t
= BIND_EXPR_BODY (t
);
2215 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2216 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2218 if (TREE_CODE (t
) == EXPR_STMT
)
2219 t
= EXPR_STMT_EXPR (t
);
2224 /* Return TRUE iff EXPR_STMT is an empty list of
2225 expression statements. */
2228 empty_expr_stmt_p (tree expr_stmt
)
2230 tree body
= NULL_TREE
;
2232 if (expr_stmt
== void_node
)
2237 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2238 body
= EXPR_STMT_EXPR (expr_stmt
);
2239 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2245 if (TREE_CODE (body
) == STATEMENT_LIST
)
2246 return tsi_end_p (tsi_start (body
));
2248 return empty_expr_stmt_p (body
);
2253 /* Perform Koenig lookup. FN is the postfix-expression representing
2254 the function (or functions) to call; ARGS are the arguments to the
2255 call. Returns the functions to be considered by overload resolution. */
2258 perform_koenig_lookup (cp_expr fn
, vec
<tree
, va_gc
> *args
,
2259 tsubst_flags_t complain
)
2261 tree identifier
= NULL_TREE
;
2262 tree functions
= NULL_TREE
;
2263 tree tmpl_args
= NULL_TREE
;
2264 bool template_id
= false;
2265 location_t loc
= fn
.get_location ();
2267 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2269 /* Use a separate flag to handle null args. */
2271 tmpl_args
= TREE_OPERAND (fn
, 1);
2272 fn
= TREE_OPERAND (fn
, 0);
2275 /* Find the name of the overloaded function. */
2276 if (identifier_p (fn
))
2281 identifier
= OVL_NAME (functions
);
2284 /* A call to a namespace-scope function using an unqualified name.
2286 Do Koenig lookup -- unless any of the arguments are
2288 if (!any_type_dependent_arguments_p (args
)
2289 && !any_dependent_template_arguments_p (tmpl_args
))
2291 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2294 /* The unqualified name could not be resolved. */
2295 if (complain
& tf_error
)
2296 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2302 if (fn
&& template_id
&& fn
!= error_mark_node
)
2303 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2308 /* Generate an expression for `FN (ARGS)'. This may change the
2311 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2312 as a virtual call, even if FN is virtual. (This flag is set when
2313 encountering an expression where the function name is explicitly
2314 qualified. For example a call to `X::f' never generates a virtual
2317 Returns code for the call. */
2320 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2321 bool koenig_p
, tsubst_flags_t complain
)
2325 vec
<tree
, va_gc
> *orig_args
= NULL
;
2327 if (fn
== error_mark_node
)
2328 return error_mark_node
;
2330 gcc_assert (!TYPE_P (fn
));
2332 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2333 it so that we can tell this is a call to a known function. */
2334 fn
= maybe_undo_parenthesized_ref (fn
);
2338 if (processing_template_decl
)
2340 /* If FN is a local extern declaration or set thereof, look them up
2341 again at instantiation time. */
2342 if (is_overloaded_fn (fn
))
2344 tree ifn
= get_first_fn (fn
);
2345 if (TREE_CODE (ifn
) == FUNCTION_DECL
2346 && DECL_LOCAL_FUNCTION_P (ifn
))
2347 orig_fn
= DECL_NAME (ifn
);
2350 /* If the call expression is dependent, build a CALL_EXPR node
2351 with no type; type_dependent_expression_p recognizes
2352 expressions with no type as being dependent. */
2353 if (type_dependent_expression_p (fn
)
2354 || any_type_dependent_arguments_p (*args
))
2356 result
= build_min_nt_call_vec (orig_fn
, *args
);
2357 SET_EXPR_LOCATION (result
, EXPR_LOC_OR_LOC (fn
, input_location
));
2358 KOENIG_LOOKUP_P (result
) = koenig_p
;
2359 if (is_overloaded_fn (fn
))
2362 lookup_keep (fn
, true);
2367 bool abnormal
= true;
2368 for (lkp_iterator
iter (fn
); abnormal
&& iter
; ++iter
)
2370 tree fndecl
= *iter
;
2371 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2372 || !TREE_THIS_VOLATILE (fndecl
))
2375 /* FIXME: Stop warning about falling off end of non-void
2376 function. But this is wrong. Even if we only see
2377 no-return fns at this point, we could select a
2378 future-defined return fn during instantiation. Or
2381 current_function_returns_abnormally
= 1;
2385 orig_args
= make_tree_vector_copy (*args
);
2386 if (!BASELINK_P (fn
)
2387 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2388 && TREE_TYPE (fn
) != unknown_type_node
)
2389 fn
= build_non_dependent_expr (fn
);
2390 make_args_non_dependent (*args
);
2393 if (TREE_CODE (fn
) == COMPONENT_REF
)
2395 tree member
= TREE_OPERAND (fn
, 1);
2396 if (BASELINK_P (member
))
2398 tree object
= TREE_OPERAND (fn
, 0);
2399 return build_new_method_call (object
, member
,
2402 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2409 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2410 if (TREE_CODE (fn
) == ADDR_EXPR
2411 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2412 fn
= TREE_OPERAND (fn
, 0);
2414 if (is_overloaded_fn (fn
))
2415 fn
= baselink_for_fns (fn
);
2418 if (BASELINK_P (fn
))
2422 /* A call to a member function. From [over.call.func]:
2424 If the keyword this is in scope and refers to the class of
2425 that member function, or a derived class thereof, then the
2426 function call is transformed into a qualified function call
2427 using (*this) as the postfix-expression to the left of the
2428 . operator.... [Otherwise] a contrived object of type T
2429 becomes the implied object argument.
2433 struct A { void f(); };
2434 struct B : public A {};
2435 struct C : public A { void g() { B::f(); }};
2437 "the class of that member function" refers to `A'. But 11.2
2438 [class.access.base] says that we need to convert 'this' to B* as
2439 part of the access, so we pass 'B' to maybe_dummy_object. */
2441 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2443 /* A constructor call always uses a dummy object. (This constructor
2444 call which has the form A::A () is actually invalid and we are
2445 going to reject it later in build_new_method_call.) */
2446 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2449 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2452 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2454 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2459 else if (is_overloaded_fn (fn
))
2461 /* If the function is an overloaded builtin, resolve it. */
2462 if (TREE_CODE (fn
) == FUNCTION_DECL
2463 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2464 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2465 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2469 if (warn_sizeof_pointer_memaccess
2470 && (complain
& tf_warning
)
2471 && !vec_safe_is_empty (*args
)
2472 && !processing_template_decl
)
2474 location_t sizeof_arg_loc
[3];
2477 for (i
= 0; i
< 3; i
++)
2481 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2482 sizeof_arg
[i
] = NULL_TREE
;
2483 if (i
>= (*args
)->length ())
2486 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2488 if (SIZEOF_EXPR_TYPE_P (t
))
2489 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2491 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2492 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2494 sizeof_pointer_memaccess_warning
2495 (sizeof_arg_loc
, fn
, *args
,
2496 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2499 /* A call to a namespace-scope function. */
2500 result
= build_new_function_call (fn
, args
, complain
);
2503 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2505 if (!vec_safe_is_empty (*args
))
2506 error ("arguments to destructor are not allowed");
2507 /* Mark the pseudo-destructor call as having side-effects so
2508 that we do not issue warnings about its use. */
2509 result
= build1 (NOP_EXPR
,
2511 TREE_OPERAND (fn
, 0));
2512 TREE_SIDE_EFFECTS (result
) = 1;
2514 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2515 /* If the "function" is really an object of class type, it might
2516 have an overloaded `operator ()'. */
2517 result
= build_op_call (fn
, args
, complain
);
2520 /* A call where the function is unknown. */
2521 result
= cp_build_function_call_vec (fn
, args
, complain
);
2523 if (processing_template_decl
&& result
!= error_mark_node
)
2525 if (INDIRECT_REF_P (result
))
2526 result
= TREE_OPERAND (result
, 0);
2527 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2528 SET_EXPR_LOCATION (result
, input_location
);
2529 KOENIG_LOOKUP_P (result
) = koenig_p
;
2530 release_tree_vector (orig_args
);
2531 result
= convert_from_reference (result
);
2534 /* Free or retain OVERLOADs from lookup. */
2535 if (is_overloaded_fn (orig_fn
))
2536 lookup_keep (get_fns (orig_fn
), processing_template_decl
);
2541 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2542 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2543 POSTDECREMENT_EXPR.) */
2546 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2548 /* input_location holds the location of the trailing operator token.
2549 Build a location of the form:
2552 with the caret at the operator token, ranging from the start
2553 of EXPR to the end of the operator token. */
2554 location_t combined_loc
= make_location (input_location
,
2556 get_finish (input_location
));
2557 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2558 tf_warning_or_error
);
2559 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2560 result
.set_location (combined_loc
);
2564 /* Finish a use of `this'. Returns an expression for `this'. */
2567 finish_this_expr (void)
2569 tree result
= NULL_TREE
;
2571 if (current_class_ptr
)
2573 tree type
= TREE_TYPE (current_class_ref
);
2575 /* In a lambda expression, 'this' refers to the captured 'this'. */
2576 if (LAMBDA_TYPE_P (type
))
2577 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2579 result
= current_class_ptr
;
2583 /* The keyword 'this' is a prvalue expression. */
2584 return rvalue (result
);
2586 tree fn
= current_nonlambda_function ();
2587 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2588 error ("%<this%> is unavailable for static member functions");
2590 error ("invalid use of %<this%> in non-member function");
2592 error ("invalid use of %<this%> at top level");
2593 return error_mark_node
;
2596 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2597 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2598 the TYPE for the type given. If SCOPE is non-NULL, the expression
2599 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2602 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2605 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2606 return error_mark_node
;
2608 gcc_assert (TYPE_P (destructor
));
2610 if (!processing_template_decl
)
2612 if (scope
== error_mark_node
)
2614 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2615 return error_mark_node
;
2617 if (is_auto (destructor
))
2618 destructor
= TREE_TYPE (object
);
2619 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2622 "qualified type %qT does not match destructor name ~%qT",
2624 return error_mark_node
;
2628 /* [expr.pseudo] says both:
2630 The type designated by the pseudo-destructor-name shall be
2631 the same as the object type.
2635 The cv-unqualified versions of the object type and of the
2636 type designated by the pseudo-destructor-name shall be the
2639 We implement the more generous second sentence, since that is
2640 what most other compilers do. */
2641 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2644 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2645 return error_mark_node
;
2649 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, void_type_node
, object
,
2653 /* Finish an expression of the form CODE EXPR. */
2656 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
2657 tsubst_flags_t complain
)
2659 /* Build a location of the form:
2662 with the caret at the operator token, ranging from the start
2663 of the operator token to the end of EXPR. */
2664 location_t combined_loc
= make_location (op_loc
,
2665 op_loc
, expr
.get_finish ());
2666 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
, complain
);
2667 /* TODO: build_x_unary_op doesn't always honor the location. */
2668 result
.set_location (combined_loc
);
2670 tree result_ovl
, expr_ovl
;
2672 if (!(complain
& tf_warning
))
2675 result_ovl
= result
;
2678 if (!processing_template_decl
)
2679 expr_ovl
= cp_fully_fold (expr_ovl
);
2681 if (!CONSTANT_CLASS_P (expr_ovl
)
2682 || TREE_OVERFLOW_P (expr_ovl
))
2685 if (!processing_template_decl
)
2686 result_ovl
= cp_fully_fold (result_ovl
);
2688 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
2689 overflow_warning (combined_loc
, result_ovl
);
2694 /* Finish a compound-literal expression or C++11 functional cast with aggregate
2695 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
2699 finish_compound_literal (tree type
, tree compound_literal
,
2700 tsubst_flags_t complain
,
2703 if (type
== error_mark_node
)
2704 return error_mark_node
;
2706 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2709 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2710 complain
, fcl_context
);
2711 return cp_build_c_cast (type
, compound_literal
, complain
);
2714 if (!TYPE_OBJ_P (type
))
2716 if (complain
& tf_error
)
2717 error ("compound literal of non-object type %qT", type
);
2718 return error_mark_node
;
2721 if (tree anode
= type_uses_auto (type
))
2722 if (CLASS_PLACEHOLDER_TEMPLATE (anode
))
2724 type
= do_auto_deduction (type
, compound_literal
, anode
, complain
,
2726 if (type
== error_mark_node
)
2727 return error_mark_node
;
2730 if (processing_template_decl
)
2732 TREE_TYPE (compound_literal
) = type
;
2733 /* Mark the expression as a compound literal. */
2734 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
2735 if (fcl_context
== fcl_c99
)
2736 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
2737 return compound_literal
;
2740 type
= complete_type (type
);
2742 if (TYPE_NON_AGGREGATE_CLASS (type
))
2744 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2745 everywhere that deals with function arguments would be a pain, so
2746 just wrap it in a TREE_LIST. The parser set a flag so we know
2747 that it came from T{} rather than T({}). */
2748 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2749 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2750 return build_functional_cast (type
, compound_literal
, complain
);
2753 if (TREE_CODE (type
) == ARRAY_TYPE
2754 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2755 return error_mark_node
;
2756 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2757 if (SCALAR_TYPE_P (type
)
2758 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
)
2759 && !check_narrowing (type
, compound_literal
, complain
))
2760 return error_mark_node
;
2761 if (TREE_CODE (type
) == ARRAY_TYPE
2762 && TYPE_DOMAIN (type
) == NULL_TREE
)
2764 cp_complete_array_type_or_error (&type
, compound_literal
,
2766 if (type
== error_mark_node
)
2767 return error_mark_node
;
2769 compound_literal
= digest_init_flags (type
, compound_literal
, LOOKUP_NORMAL
,
2771 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
2773 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
2774 if (fcl_context
== fcl_c99
)
2775 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
2778 /* Put static/constant array temporaries in static variables. */
2779 /* FIXME all C99 compound literals should be variables rather than C++
2780 temporaries, unless they are used as an aggregate initializer. */
2781 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
2782 && fcl_context
== fcl_c99
2783 && TREE_CODE (type
) == ARRAY_TYPE
2784 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
2785 && initializer_constant_valid_p (compound_literal
, type
))
2787 tree decl
= create_temporary_var (type
);
2788 DECL_INITIAL (decl
) = compound_literal
;
2789 TREE_STATIC (decl
) = 1;
2790 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
2792 /* 5.19 says that a constant expression can include an
2793 lvalue-rvalue conversion applied to "a glvalue of literal type
2794 that refers to a non-volatile temporary object initialized
2795 with a constant expression". Rather than try to communicate
2796 that this VAR_DECL is a temporary, just mark it constexpr. */
2797 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
2798 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
2799 TREE_CONSTANT (decl
) = true;
2801 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
2802 decl
= pushdecl_top_level (decl
);
2803 DECL_NAME (decl
) = make_anon_name ();
2804 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
2805 /* Make sure the destructor is callable. */
2806 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
2807 if (clean
== error_mark_node
)
2808 return error_mark_node
;
2812 /* Represent other compound literals with TARGET_EXPR so we produce
2813 an lvalue, but can elide copies. */
2814 if (!VECTOR_TYPE_P (type
))
2815 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
2817 return compound_literal
;
2820 /* Return the declaration for the function-name variable indicated by
2824 finish_fname (tree id
)
2828 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
2829 if (processing_template_decl
&& current_function_decl
2830 && decl
!= error_mark_node
)
2831 decl
= DECL_NAME (decl
);
2835 /* Finish a translation unit. */
2838 finish_translation_unit (void)
2840 /* In case there were missing closebraces,
2841 get us back to the global binding level. */
2843 while (current_namespace
!= global_namespace
)
2846 /* Do file scope __FUNCTION__ et al. */
2847 finish_fname_decls ();
2850 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2851 Returns the parameter. */
2854 finish_template_type_parm (tree aggr
, tree identifier
)
2856 if (aggr
!= class_type_node
)
2858 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
2859 aggr
= class_type_node
;
2862 return build_tree_list (aggr
, identifier
);
2865 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2866 Returns the parameter. */
2869 finish_template_template_parm (tree aggr
, tree identifier
)
2871 tree decl
= build_decl (input_location
,
2872 TYPE_DECL
, identifier
, NULL_TREE
);
2874 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
2875 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
2876 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
2877 DECL_ARTIFICIAL (decl
) = 1;
2879 // Associate the constraints with the underlying declaration,
2880 // not the template.
2881 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
2882 tree constr
= build_constraints (reqs
, NULL_TREE
);
2883 set_constraints (decl
, constr
);
2885 end_template_decl ();
2887 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
2889 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
2890 /*is_primary=*/true, /*is_partial=*/false,
2893 return finish_template_type_parm (aggr
, tmpl
);
2896 /* ARGUMENT is the default-argument value for a template template
2897 parameter. If ARGUMENT is invalid, issue error messages and return
2898 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2901 check_template_template_default_arg (tree argument
)
2903 if (TREE_CODE (argument
) != TEMPLATE_DECL
2904 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
2905 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
2907 if (TREE_CODE (argument
) == TYPE_DECL
)
2908 error ("invalid use of type %qT as a default value for a template "
2909 "template-parameter", TREE_TYPE (argument
));
2911 error ("invalid default argument for a template template parameter");
2912 return error_mark_node
;
2918 /* Begin a class definition, as indicated by T. */
2921 begin_class_definition (tree t
)
2923 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
2924 return error_mark_node
;
2926 if (processing_template_parmlist
)
2928 error ("definition of %q#T inside template parameter list", t
);
2929 return error_mark_node
;
2932 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
2933 are passed the same as decimal scalar types. */
2934 if (TREE_CODE (t
) == RECORD_TYPE
2935 && !processing_template_decl
)
2937 tree ns
= TYPE_CONTEXT (t
);
2938 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
2939 && DECL_CONTEXT (ns
) == std_node
2941 && id_equal (DECL_NAME (ns
), "decimal"))
2943 const char *n
= TYPE_NAME_STRING (t
);
2944 if ((strcmp (n
, "decimal32") == 0)
2945 || (strcmp (n
, "decimal64") == 0)
2946 || (strcmp (n
, "decimal128") == 0))
2947 TYPE_TRANSPARENT_AGGR (t
) = 1;
2951 /* A non-implicit typename comes from code like:
2953 template <typename T> struct A {
2954 template <typename U> struct A<T>::B ...
2956 This is erroneous. */
2957 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
2959 error ("invalid definition of qualified type %qT", t
);
2960 t
= error_mark_node
;
2963 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
2965 t
= make_class_type (RECORD_TYPE
);
2966 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
2969 if (TYPE_BEING_DEFINED (t
))
2971 t
= make_class_type (TREE_CODE (t
));
2972 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
2974 maybe_process_partial_specialization (t
);
2976 TYPE_BEING_DEFINED (t
) = 1;
2977 class_binding_level
->defining_class_p
= 1;
2979 if (flag_pack_struct
)
2982 TYPE_PACKED (t
) = 1;
2983 /* Even though the type is being defined for the first time
2984 here, there might have been a forward declaration, so there
2985 might be cv-qualified variants of T. */
2986 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
2987 TYPE_PACKED (v
) = 1;
2989 /* Reset the interface data, at the earliest possible
2990 moment, as it might have been set via a class foo;
2992 if (! TYPE_UNNAMED_P (t
))
2994 struct c_fileinfo
*finfo
= \
2995 get_fileinfo (LOCATION_FILE (input_location
));
2996 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
2997 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2998 (t
, finfo
->interface_unknown
);
3000 reset_specialization();
3002 /* Make a declaration for this class in its own scope. */
3003 build_self_reference ();
3008 /* Finish the member declaration given by DECL. */
3011 finish_member_declaration (tree decl
)
3013 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
3016 if (decl
== void_type_node
)
3017 /* The COMPONENT was a friend, not a member, and so there's
3018 nothing for us to do. */
3021 /* We should see only one DECL at a time. */
3022 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
3024 /* Don't add decls after definition. */
3025 gcc_assert (TYPE_BEING_DEFINED (current_class_type
)
3026 /* We can add lambda types when late parsing default
3028 || LAMBDA_TYPE_P (TREE_TYPE (decl
)));
3030 /* Set up access control for DECL. */
3032 = (current_access_specifier
== access_private_node
);
3033 TREE_PROTECTED (decl
)
3034 = (current_access_specifier
== access_protected_node
);
3035 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3037 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
3038 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
3041 /* Mark the DECL as a member of the current class, unless it's
3042 a member of an enumeration. */
3043 if (TREE_CODE (decl
) != CONST_DECL
)
3044 DECL_CONTEXT (decl
) = current_class_type
;
3046 if (TREE_CODE (decl
) == USING_DECL
)
3047 /* For now, ignore class-scope USING_DECLS, so that debugging
3048 backends do not see them. */
3049 DECL_IGNORED_P (decl
) = 1;
3051 /* Check for bare parameter packs in the non-static data member
3053 if (TREE_CODE (decl
) == FIELD_DECL
)
3055 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
3056 TREE_TYPE (decl
) = error_mark_node
;
3057 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3058 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3063 A C language linkage is ignored for the names of class members
3064 and the member function type of class member functions. */
3065 if (DECL_LANG_SPECIFIC (decl
))
3066 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3070 /* Functions and non-functions are added differently. */
3071 if (DECL_DECLARES_FUNCTION_P (decl
))
3072 add
= add_method (current_class_type
, decl
, false);
3073 /* Enter the DECL into the scope of the class, if the class
3074 isn't a closure (whose fields are supposed to be unnamed). */
3075 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3076 || pushdecl_class_level (decl
))
3081 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3082 go at the beginning. The reason is that
3083 legacy_nonfn_member_lookup searches the list in order, and we
3084 want a field name to override a type name so that the "struct
3085 stat hack" will work. In particular:
3087 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3091 if (TREE_CODE (decl
) == TYPE_DECL
)
3092 TYPE_FIELDS (current_class_type
)
3093 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3096 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3097 TYPE_FIELDS (current_class_type
) = decl
;
3100 maybe_add_class_template_decl_list (current_class_type
, decl
,
3105 /* Finish processing a complete template declaration. The PARMS are
3106 the template parameters. */
3109 finish_template_decl (tree parms
)
3112 end_template_decl ();
3114 end_specialization ();
3117 // Returns the template type of the class scope being entered. If we're
3118 // entering a constrained class scope. TYPE is the class template
3119 // scope being entered and we may need to match the intended type with
3120 // a constrained specialization. For example:
3122 // template<Object T>
3123 // struct S { void f(); }; #1
3125 // template<Object T>
3126 // void S<T>::f() { } #2
3128 // We check, in #2, that S<T> refers precisely to the type declared by
3129 // #1 (i.e., that the constraints match). Note that the following should
3130 // be an error since there is no specialization of S<T> that is
3131 // unconstrained, but this is not diagnosed here.
3133 // template<typename T>
3134 // void S<T>::f() { }
3136 // We cannot diagnose this problem here since this function also matches
3137 // qualified template names that are not part of a definition. For example:
3139 // template<Integral T, Floating_point U>
3140 // typename pair<T, U>::first_type void f(T, U);
3142 // Here, it is unlikely that there is a partial specialization of
3143 // pair constrained for for Integral and Floating_point arguments.
3145 // The general rule is: if a constrained specialization with matching
3146 // constraints is found return that type. Also note that if TYPE is not a
3147 // class-type (e.g. a typename type), then no fixup is needed.
3150 fixup_template_type (tree type
)
3152 // Find the template parameter list at the a depth appropriate to
3153 // the scope we're trying to enter.
3154 tree parms
= current_template_parms
;
3155 int depth
= template_class_depth (type
);
3156 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3157 parms
= TREE_CHAIN (parms
);
3160 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3161 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3163 // Search for a specialization whose type and constraints match.
3164 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3165 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3168 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3170 // If the type and constraints match a specialization, then we
3171 // are entering that type.
3172 if (same_type_p (type
, TREE_TYPE (specs
))
3173 && equivalent_constraints (cur_constr
, spec_constr
))
3174 return TREE_TYPE (specs
);
3175 specs
= TREE_CHAIN (specs
);
3178 // If no specialization matches, then must return the type
3179 // previously found.
3183 /* Finish processing a template-id (which names a type) of the form
3184 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3185 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3186 the scope of template-id indicated. */
3189 finish_template_type (tree name
, tree args
, int entering_scope
)
3193 type
= lookup_template_class (name
, args
,
3194 NULL_TREE
, NULL_TREE
, entering_scope
,
3195 tf_warning_or_error
| tf_user
);
3197 /* If we might be entering the scope of a partial specialization,
3198 find the one with the right constraints. */
3201 && CLASS_TYPE_P (type
)
3202 && CLASSTYPE_TEMPLATE_INFO (type
)
3203 && dependent_type_p (type
)
3204 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3205 type
= fixup_template_type (type
);
3207 if (type
== error_mark_node
)
3209 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3210 return TYPE_STUB_DECL (type
);
3212 return TYPE_NAME (type
);
3215 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3216 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3217 BASE_CLASS, or NULL_TREE if an error occurred. The
3218 ACCESS_SPECIFIER is one of
3219 access_{default,public,protected_private}_node. For a virtual base
3220 we set TREE_TYPE. */
3223 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3227 if (base
== error_mark_node
)
3229 error ("invalid base-class specification");
3232 else if (! MAYBE_CLASS_TYPE_P (base
))
3234 error ("%qT is not a class type", base
);
3239 if (cp_type_quals (base
) != 0)
3241 /* DR 484: Can a base-specifier name a cv-qualified
3243 base
= TYPE_MAIN_VARIANT (base
);
3245 result
= build_tree_list (access
, base
);
3247 TREE_TYPE (result
) = integer_type_node
;
3253 /* If FNS is a member function, a set of member functions, or a
3254 template-id referring to one or more member functions, return a
3255 BASELINK for FNS, incorporating the current access context.
3256 Otherwise, return FNS unchanged. */
3259 baselink_for_fns (tree fns
)
3264 if (BASELINK_P (fns
)
3265 || error_operand_p (fns
))
3268 scope
= ovl_scope (fns
);
3269 if (!CLASS_TYPE_P (scope
))
3272 cl
= currently_open_derived_class (scope
);
3275 cl
= TYPE_BINFO (cl
);
3276 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3279 /* Returns true iff DECL is a variable from a function outside
3283 outer_var_p (tree decl
)
3285 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3286 && DECL_FUNCTION_SCOPE_P (decl
)
3287 /* Don't get confused by temporaries. */
3289 && (DECL_CONTEXT (decl
) != current_function_decl
3290 || parsing_nsdmi ()));
3293 /* As above, but also checks that DECL is automatic. */
3296 outer_automatic_var_p (tree decl
)
3298 return (outer_var_p (decl
)
3299 && !TREE_STATIC (decl
));
3302 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3303 rewrite it for lambda capture.
3305 If ODR_USE is true, we're being called from mark_use, and we complain about
3306 use of constant variables. If ODR_USE is false, we're being called for the
3307 id-expression, and we do lambda capture. */
3310 process_outer_var_ref (tree decl
, tsubst_flags_t complain
, bool odr_use
)
3312 if (cp_unevaluated_operand
)
3313 /* It's not a use (3.2) if we're in an unevaluated context. */
3315 if (decl
== error_mark_node
)
3318 tree context
= DECL_CONTEXT (decl
);
3319 tree containing_function
= current_function_decl
;
3320 tree lambda_stack
= NULL_TREE
;
3321 tree lambda_expr
= NULL_TREE
;
3322 tree initializer
= convert_from_reference (decl
);
3324 /* Mark it as used now even if the use is ill-formed. */
3325 if (!mark_used (decl
, complain
))
3326 return error_mark_node
;
3328 if (parsing_nsdmi ())
3329 containing_function
= NULL_TREE
;
3331 if (containing_function
&& LAMBDA_FUNCTION_P (containing_function
))
3333 /* Check whether we've already built a proxy. */
3335 while (is_capture_proxy_with_ref (var
))
3336 var
= DECL_CAPTURED_VARIABLE (var
);
3337 tree d
= retrieve_local_specialization (var
);
3339 if (d
&& d
!= decl
&& is_capture_proxy (d
))
3341 if (DECL_CONTEXT (d
) == containing_function
)
3342 /* We already have an inner proxy. */
3345 /* We need to capture an outer proxy. */
3346 return process_outer_var_ref (d
, complain
, odr_use
);
3350 /* If we are in a lambda function, we can move out until we hit
3352 2. a non-lambda function, or
3353 3. a non-default capturing lambda function. */
3354 while (context
!= containing_function
3355 /* containing_function can be null with invalid generic lambdas. */
3356 && containing_function
3357 && LAMBDA_FUNCTION_P (containing_function
))
3359 tree closure
= DECL_CONTEXT (containing_function
);
3360 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3362 if (TYPE_CLASS_SCOPE_P (closure
))
3363 /* A lambda in an NSDMI (c++/64496). */
3366 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3370 lambda_stack
= tree_cons (NULL_TREE
,
3375 = decl_function_context (containing_function
);
3378 /* In a lambda within a template, wait until instantiation
3379 time to implicitly capture. */
3380 if (context
== containing_function
3381 && DECL_TEMPLATE_INFO (containing_function
)
3382 && uses_template_parms (DECL_TI_ARGS (containing_function
)))
3385 if (lambda_expr
&& VAR_P (decl
)
3386 && DECL_ANON_UNION_VAR_P (decl
))
3388 if (complain
& tf_error
)
3389 error ("cannot capture member %qD of anonymous union", decl
);
3390 return error_mark_node
;
3392 /* Do lambda capture when processing the id-expression, not when
3393 odr-using a variable. */
3394 if (!odr_use
&& context
== containing_function
)
3396 decl
= add_default_capture (lambda_stack
,
3397 /*id=*/DECL_NAME (decl
),
3400 /* Only an odr-use of an outer automatic variable causes an
3401 error, and a constant variable can decay to a prvalue
3402 constant without odr-use. So don't complain yet. */
3403 else if (!odr_use
&& decl_constant_var_p (decl
))
3405 else if (lambda_expr
)
3407 if (complain
& tf_error
)
3409 error ("%qD is not captured", decl
);
3410 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3411 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3413 inform (location_of (closure
),
3414 "the lambda has no capture-default");
3415 else if (TYPE_CLASS_SCOPE_P (closure
))
3416 inform (UNKNOWN_LOCATION
, "lambda in local class %q+T cannot "
3417 "capture variables from the enclosing context",
3418 TYPE_CONTEXT (closure
));
3419 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3421 return error_mark_node
;
3425 if (complain
& tf_error
)
3428 ? G_("use of local variable with automatic storage from "
3429 "containing function")
3430 : G_("use of parameter from containing function"));
3431 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3433 return error_mark_node
;
3438 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3439 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3440 if non-NULL, is the type or namespace used to explicitly qualify
3441 ID_EXPRESSION. DECL is the entity to which that name has been
3444 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3445 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3446 be set to true if this expression isn't permitted in a
3447 constant-expression, but it is otherwise not set by this function.
3448 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3449 constant-expression, but a non-constant expression is also
3452 DONE is true if this expression is a complete postfix-expression;
3453 it is false if this expression is followed by '->', '[', '(', etc.
3454 ADDRESS_P is true iff this expression is the operand of '&'.
3455 TEMPLATE_P is true iff the qualified-id was of the form
3456 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3457 appears as a template argument.
3459 If an error occurs, and it is the kind of error that might cause
3460 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3461 is the caller's responsibility to issue the message. *ERROR_MSG
3462 will be a string with static storage duration, so the caller need
3465 Return an expression for the entity, after issuing appropriate
3466 diagnostics. This function is also responsible for transforming a
3467 reference to a non-static member into a COMPONENT_REF that makes
3468 the use of "this" explicit.
3470 Upon return, *IDK will be filled in appropriately. */
3472 finish_id_expression (tree id_expression
,
3476 bool integral_constant_expression_p
,
3477 bool allow_non_integral_constant_expression_p
,
3478 bool *non_integral_constant_expression_p
,
3482 bool template_arg_p
,
3483 const char **error_msg
,
3484 location_t location
)
3486 decl
= strip_using_decl (decl
);
3488 /* Initialize the output parameters. */
3489 *idk
= CP_ID_KIND_NONE
;
3492 if (id_expression
== error_mark_node
)
3493 return error_mark_node
;
3494 /* If we have a template-id, then no further lookup is
3495 required. If the template-id was for a template-class, we
3496 will sometimes have a TYPE_DECL at this point. */
3497 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3498 || TREE_CODE (decl
) == TYPE_DECL
)
3500 /* Look up the name. */
3503 if (decl
== error_mark_node
)
3505 /* Name lookup failed. */
3508 || (!dependent_type_p (scope
)
3509 && !(identifier_p (id_expression
)
3510 && IDENTIFIER_CONV_OP_P (id_expression
)
3511 && dependent_type_p (TREE_TYPE (id_expression
))))))
3513 /* If the qualifying type is non-dependent (and the name
3514 does not name a conversion operator to a dependent
3515 type), issue an error. */
3516 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3517 return error_mark_node
;
3521 /* It may be resolved via Koenig lookup. */
3522 *idk
= CP_ID_KIND_UNQUALIFIED
;
3523 return id_expression
;
3526 decl
= id_expression
;
3528 /* If DECL is a variable that would be out of scope under
3529 ANSI/ISO rules, but in scope in the ARM, name lookup
3530 will succeed. Issue a diagnostic here. */
3532 decl
= check_for_out_of_scope_variable (decl
);
3534 /* Remember that the name was used in the definition of
3535 the current class so that we can check later to see if
3536 the meaning would have been different after the class
3537 was entirely defined. */
3538 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3539 maybe_note_name_used_in_class (id_expression
, decl
);
3541 /* A use in unevaluated operand might not be instantiated appropriately
3542 if tsubst_copy builds a dummy parm, or if we never instantiate a
3543 generic lambda, so mark it now. */
3544 if (processing_template_decl
&& cp_unevaluated_operand
)
3545 mark_type_use (decl
);
3547 /* Disallow uses of local variables from containing functions, except
3548 within lambda-expressions. */
3549 if (outer_automatic_var_p (decl
))
3551 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3552 if (decl
== error_mark_node
)
3553 return error_mark_node
;
3556 /* Also disallow uses of function parameters outside the function
3557 body, except inside an unevaluated context (i.e. decltype). */
3558 if (TREE_CODE (decl
) == PARM_DECL
3559 && DECL_CONTEXT (decl
) == NULL_TREE
3560 && !cp_unevaluated_operand
)
3562 *error_msg
= G_("use of parameter outside function body");
3563 return error_mark_node
;
3567 /* If we didn't find anything, or what we found was a type,
3568 then this wasn't really an id-expression. */
3569 if (TREE_CODE (decl
) == TEMPLATE_DECL
3570 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3572 *error_msg
= G_("missing template arguments");
3573 return error_mark_node
;
3575 else if (TREE_CODE (decl
) == TYPE_DECL
3576 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3578 *error_msg
= G_("expected primary-expression");
3579 return error_mark_node
;
3582 /* If the name resolved to a template parameter, there is no
3583 need to look it up again later. */
3584 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3585 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3589 *idk
= CP_ID_KIND_NONE
;
3590 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3591 decl
= TEMPLATE_PARM_DECL (decl
);
3592 r
= convert_from_reference (DECL_INITIAL (decl
));
3594 if (integral_constant_expression_p
3595 && !dependent_type_p (TREE_TYPE (decl
))
3596 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3598 if (!allow_non_integral_constant_expression_p
)
3599 error ("template parameter %qD of type %qT is not allowed in "
3600 "an integral constant expression because it is not of "
3601 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3602 *non_integral_constant_expression_p
= true;
3608 bool dependent_p
= type_dependent_expression_p (decl
);
3610 /* If the declaration was explicitly qualified indicate
3611 that. The semantics of `A::f(3)' are different than
3612 `f(3)' if `f' is virtual. */
3614 ? CP_ID_KIND_QUALIFIED
3615 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3616 ? CP_ID_KIND_TEMPLATE_ID
3618 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3619 : CP_ID_KIND_UNQUALIFIED
)));
3623 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
3624 /* Dependent type attributes on the decl mean that the TREE_TYPE is
3625 wrong, so just return the identifier. */
3626 return id_expression
;
3628 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3630 error ("use of namespace %qD as expression", decl
);
3631 return error_mark_node
;
3633 else if (DECL_CLASS_TEMPLATE_P (decl
))
3635 error ("use of class template %qT as expression", decl
);
3636 return error_mark_node
;
3638 else if (TREE_CODE (decl
) == TREE_LIST
)
3640 /* Ambiguous reference to base members. */
3641 error ("request for member %qD is ambiguous in "
3642 "multiple inheritance lattice", id_expression
);
3643 print_candidates (decl
);
3644 return error_mark_node
;
3647 /* Mark variable-like entities as used. Functions are similarly
3648 marked either below or after overload resolution. */
3650 || TREE_CODE (decl
) == PARM_DECL
3651 || TREE_CODE (decl
) == CONST_DECL
3652 || TREE_CODE (decl
) == RESULT_DECL
)
3653 && !mark_used (decl
))
3654 return error_mark_node
;
3656 /* Only certain kinds of names are allowed in constant
3657 expression. Template parameters have already
3658 been handled above. */
3659 if (! error_operand_p (decl
)
3661 && integral_constant_expression_p
3662 && ! decl_constant_var_p (decl
)
3663 && TREE_CODE (decl
) != CONST_DECL
3664 && ! builtin_valid_in_constant_expr_p (decl
))
3666 if (!allow_non_integral_constant_expression_p
)
3668 error ("%qD cannot appear in a constant-expression", decl
);
3669 return error_mark_node
;
3671 *non_integral_constant_expression_p
= true;
3676 && !cp_unevaluated_operand
3677 && !processing_template_decl
3678 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
3679 && CP_DECL_THREAD_LOCAL_P (decl
)
3680 && (wrap
= get_tls_wrapper_fn (decl
)))
3682 /* Replace an evaluated use of the thread_local variable with
3683 a call to its wrapper. */
3684 decl
= build_cxx_call (wrap
, 0, NULL
, tf_warning_or_error
);
3686 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3688 && variable_template_p (TREE_OPERAND (decl
, 0)))
3690 decl
= finish_template_variable (decl
);
3692 decl
= convert_from_reference (decl
);
3696 if (TREE_CODE (decl
) == SCOPE_REF
)
3698 gcc_assert (same_type_p (scope
, TREE_OPERAND (decl
, 0)));
3699 decl
= TREE_OPERAND (decl
, 1);
3702 decl
= (adjust_result_of_qualified_name_lookup
3703 (decl
, scope
, current_nonlambda_class_type()));
3705 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3709 decl
= finish_qualified_id_expr (scope
,
3715 tf_warning_or_error
);
3717 decl
= convert_from_reference (decl
);
3719 else if (TREE_CODE (decl
) == FIELD_DECL
)
3721 /* Since SCOPE is NULL here, this is an unqualified name.
3722 Access checking has been performed during name lookup
3723 already. Turn off checking to avoid duplicate errors. */
3724 push_deferring_access_checks (dk_no_check
);
3725 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3726 /*qualifying_scope=*/NULL_TREE
);
3727 pop_deferring_access_checks ();
3729 else if (is_overloaded_fn (decl
))
3731 tree first_fn
= get_first_fn (decl
);
3733 if (TREE_CODE (first_fn
) == TEMPLATE_DECL
)
3734 first_fn
= DECL_TEMPLATE_RESULT (first_fn
);
3736 /* [basic.def.odr]: "A function whose name appears as a
3737 potentially-evaluated expression is odr-used if it is the unique
3740 But only mark it if it's a complete postfix-expression; in a call,
3741 ADL might select a different function, and we'll call mark_used in
3744 && !really_overloaded_fn (decl
)
3745 && !mark_used (first_fn
))
3746 return error_mark_node
;
3749 && TREE_CODE (first_fn
) == FUNCTION_DECL
3750 && DECL_FUNCTION_MEMBER_P (first_fn
)
3751 && !shared_member_p (decl
))
3753 /* A set of member functions. */
3754 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
3755 return finish_class_member_access_expr (decl
, id_expression
,
3756 /*template_p=*/false,
3757 tf_warning_or_error
);
3760 decl
= baselink_for_fns (decl
);
3764 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
3765 && DECL_CLASS_SCOPE_P (decl
))
3767 tree context
= context_for_name_lookup (decl
);
3768 if (context
!= current_class_type
)
3770 tree path
= currently_open_derived_class (context
);
3771 perform_or_defer_access_check (TYPE_BINFO (path
),
3773 tf_warning_or_error
);
3777 decl
= convert_from_reference (decl
);
3781 return cp_expr (decl
, location
);
3784 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3785 use as a type-specifier. */
3788 finish_typeof (tree expr
)
3792 if (type_dependent_expression_p (expr
))
3794 type
= cxx_make_type (TYPEOF_TYPE
);
3795 TYPEOF_TYPE_EXPR (type
) = expr
;
3796 SET_TYPE_STRUCTURAL_EQUALITY (type
);
3801 expr
= mark_type_use (expr
);
3803 type
= unlowered_expr_type (expr
);
3805 if (!type
|| type
== unknown_type_node
)
3807 error ("type of %qE is unknown", expr
);
3808 return error_mark_node
;
3814 /* Implement the __underlying_type keyword: Return the underlying
3815 type of TYPE, suitable for use as a type-specifier. */
3818 finish_underlying_type (tree type
)
3820 tree underlying_type
;
3822 if (processing_template_decl
)
3824 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
3825 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
3826 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
3828 return underlying_type
;
3831 if (!complete_type_or_else (type
, NULL_TREE
))
3832 return error_mark_node
;
3834 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
3836 error ("%qT is not an enumeration type", type
);
3837 return error_mark_node
;
3840 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
3842 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
3843 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
3844 See finish_enum_value_list for details. */
3845 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
3847 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
3848 TYPE_UNSIGNED (underlying_type
));
3850 return underlying_type
;
3853 /* Implement the __direct_bases keyword: Return the direct base classes
3857 calculate_direct_bases (tree type
)
3859 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3860 tree bases_vec
= NULL_TREE
;
3861 vec
<tree
, va_gc
> *base_binfos
;
3865 complete_type (type
);
3867 if (!NON_UNION_CLASS_TYPE_P (type
))
3868 return make_tree_vec (0);
3870 base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
3872 /* Virtual bases are initialized first */
3873 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3875 if (BINFO_VIRTUAL_P (binfo
))
3877 vec_safe_push (vector
, binfo
);
3881 /* Now non-virtuals */
3882 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3884 if (!BINFO_VIRTUAL_P (binfo
))
3886 vec_safe_push (vector
, binfo
);
3891 bases_vec
= make_tree_vec (vector
->length ());
3893 for (i
= 0; i
< vector
->length (); ++i
)
3895 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
3900 /* Implement the __bases keyword: Return the base classes
3903 /* Find morally non-virtual base classes by walking binfo hierarchy */
3904 /* Virtual base classes are handled separately in finish_bases */
3907 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
3909 /* Don't walk bases of virtual bases */
3910 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
3914 dfs_calculate_bases_post (tree binfo
, void *data_
)
3916 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
3917 if (!BINFO_VIRTUAL_P (binfo
))
3919 vec_safe_push (*data
, BINFO_TYPE (binfo
));
3924 /* Calculates the morally non-virtual base classes of a class */
3925 static vec
<tree
, va_gc
> *
3926 calculate_bases_helper (tree type
)
3928 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3930 /* Now add non-virtual base classes in order of construction */
3931 if (TYPE_BINFO (type
))
3932 dfs_walk_all (TYPE_BINFO (type
),
3933 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
3938 calculate_bases (tree type
)
3940 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3941 tree bases_vec
= NULL_TREE
;
3943 vec
<tree
, va_gc
> *vbases
;
3944 vec
<tree
, va_gc
> *nonvbases
;
3947 complete_type (type
);
3949 if (!NON_UNION_CLASS_TYPE_P (type
))
3950 return make_tree_vec (0);
3952 /* First go through virtual base classes */
3953 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
3954 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
3956 vec
<tree
, va_gc
> *vbase_bases
;
3957 vbase_bases
= calculate_bases_helper (BINFO_TYPE (binfo
));
3958 vec_safe_splice (vector
, vbase_bases
);
3959 release_tree_vector (vbase_bases
);
3962 /* Now for the non-virtual bases */
3963 nonvbases
= calculate_bases_helper (type
);
3964 vec_safe_splice (vector
, nonvbases
);
3965 release_tree_vector (nonvbases
);
3967 /* Note that during error recovery vector->length can even be zero. */
3968 if (vector
->length () > 1)
3970 /* Last element is entire class, so don't copy */
3971 bases_vec
= make_tree_vec (vector
->length() - 1);
3973 for (i
= 0; i
< vector
->length () - 1; ++i
)
3974 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
3977 bases_vec
= make_tree_vec (0);
3979 release_tree_vector (vector
);
3984 finish_bases (tree type
, bool direct
)
3986 tree bases
= NULL_TREE
;
3988 if (!processing_template_decl
)
3990 /* Parameter packs can only be used in templates */
3991 error ("Parameter pack __bases only valid in template declaration");
3992 return error_mark_node
;
3995 bases
= cxx_make_type (BASES
);
3996 BASES_TYPE (bases
) = type
;
3997 BASES_DIRECT (bases
) = direct
;
3998 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
4003 /* Perform C++-specific checks for __builtin_offsetof before calling
4007 finish_offsetof (tree object_ptr
, tree expr
, location_t loc
)
4009 /* If we're processing a template, we can't finish the semantics yet.
4010 Otherwise we can fold the entire expression now. */
4011 if (processing_template_decl
)
4013 expr
= build2 (OFFSETOF_EXPR
, size_type_node
, expr
, object_ptr
);
4014 SET_EXPR_LOCATION (expr
, loc
);
4018 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4020 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4021 TREE_OPERAND (expr
, 2));
4022 return error_mark_node
;
4024 if (TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
4025 || TREE_CODE (TREE_TYPE (expr
)) == METHOD_TYPE
4026 || TREE_TYPE (expr
) == unknown_type_node
)
4028 if (INDIRECT_REF_P (expr
))
4029 error ("second operand of %<offsetof%> is neither a single "
4030 "identifier nor a sequence of member accesses and "
4031 "array references");
4034 if (TREE_CODE (expr
) == COMPONENT_REF
4035 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4036 expr
= TREE_OPERAND (expr
, 1);
4037 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4039 return error_mark_node
;
4041 if (REFERENCE_REF_P (expr
))
4042 expr
= TREE_OPERAND (expr
, 0);
4043 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr
)), object_ptr
))
4044 return error_mark_node
;
4045 if (warn_invalid_offsetof
4046 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr
)))
4047 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr
)))
4048 && cp_unevaluated_operand
== 0)
4049 pedwarn (loc
, OPT_Winvalid_offsetof
,
4050 "offsetof within non-standard-layout type %qT is undefined",
4051 TREE_TYPE (TREE_TYPE (object_ptr
)));
4052 return fold_offsetof (expr
);
4055 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4056 function is broken out from the above for the benefit of the tree-ssa
4060 simplify_aggr_init_expr (tree
*tp
)
4062 tree aggr_init_expr
= *tp
;
4064 /* Form an appropriate CALL_EXPR. */
4065 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4066 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4067 tree type
= TREE_TYPE (slot
);
4070 enum style_t
{ ctor
, arg
, pcc
} style
;
4072 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4074 #ifdef PCC_STATIC_STRUCT_RETURN
4080 gcc_assert (TREE_ADDRESSABLE (type
));
4084 call_expr
= build_call_array_loc (input_location
,
4085 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4087 aggr_init_expr_nargs (aggr_init_expr
),
4088 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4089 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4090 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4091 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4092 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4093 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4094 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4098 /* Replace the first argument to the ctor with the address of the
4100 cxx_mark_addressable (slot
);
4101 CALL_EXPR_ARG (call_expr
, 0) =
4102 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4104 else if (style
== arg
)
4106 /* Just mark it addressable here, and leave the rest to
4107 expand_call{,_inline}. */
4108 cxx_mark_addressable (slot
);
4109 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4110 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4112 else if (style
== pcc
)
4114 /* If we're using the non-reentrant PCC calling convention, then we
4115 need to copy the returned value out of the static buffer into the
4117 push_deferring_access_checks (dk_no_check
);
4118 call_expr
= build_aggr_init (slot
, call_expr
,
4119 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4120 tf_warning_or_error
);
4121 pop_deferring_access_checks ();
4122 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4125 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4127 tree init
= build_zero_init (type
, NULL_TREE
,
4128 /*static_storage_p=*/false);
4129 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4130 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4137 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4140 emit_associated_thunks (tree fn
)
4142 /* When we use vcall offsets, we emit thunks with the virtual
4143 functions to which they thunk. The whole point of vcall offsets
4144 is so that you can know statically the entire set of thunks that
4145 will ever be needed for a given virtual function, thereby
4146 enabling you to output all the thunks with the function itself. */
4147 if (DECL_VIRTUAL_P (fn
)
4148 /* Do not emit thunks for extern template instantiations. */
4149 && ! DECL_REALLY_EXTERN (fn
))
4153 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4155 if (!THUNK_ALIAS (thunk
))
4157 use_thunk (thunk
, /*emit_p=*/1);
4158 if (DECL_RESULT_THUNK_P (thunk
))
4162 for (probe
= DECL_THUNKS (thunk
);
4163 probe
; probe
= DECL_CHAIN (probe
))
4164 use_thunk (probe
, /*emit_p=*/1);
4168 gcc_assert (!DECL_THUNKS (thunk
));
4173 /* Generate RTL for FN. */
4176 expand_or_defer_fn_1 (tree fn
)
4178 /* When the parser calls us after finishing the body of a template
4179 function, we don't really want to expand the body. */
4180 if (processing_template_decl
)
4182 /* Normally, collection only occurs in rest_of_compilation. So,
4183 if we don't collect here, we never collect junk generated
4184 during the processing of templates until we hit a
4185 non-template function. It's not safe to do this inside a
4186 nested class, though, as the parser may have local state that
4187 is not a GC root. */
4188 if (!function_depth
)
4193 gcc_assert (DECL_SAVED_TREE (fn
));
4195 /* We make a decision about linkage for these functions at the end
4196 of the compilation. Until that point, we do not want the back
4197 end to output them -- but we do want it to see the bodies of
4198 these functions so that it can inline them as appropriate. */
4199 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4201 if (DECL_INTERFACE_KNOWN (fn
))
4202 /* We've already made a decision as to how this function will
4205 tentative_decl_linkage (fn
);
4207 import_export_decl (fn
);
4209 /* If the user wants us to keep all inline functions, then mark
4210 this function as needed so that finish_file will make sure to
4211 output it later. Similarly, all dllexport'd functions must
4212 be emitted; there may be callers in other DLLs. */
4213 if (DECL_DECLARED_INLINE_P (fn
)
4214 && !DECL_REALLY_EXTERN (fn
)
4215 && (flag_keep_inline_functions
4216 || (flag_keep_inline_dllexport
4217 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4220 DECL_EXTERNAL (fn
) = 0;
4224 /* If this is a constructor or destructor body, we have to clone
4226 if (maybe_clone_body (fn
))
4228 /* We don't want to process FN again, so pretend we've written
4229 it out, even though we haven't. */
4230 TREE_ASM_WRITTEN (fn
) = 1;
4231 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4232 if (!DECL_DECLARED_CONSTEXPR_P (fn
))
4233 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4237 /* There's no reason to do any of the work here if we're only doing
4238 semantic analysis; this code just generates RTL. */
4239 if (flag_syntax_only
)
4246 expand_or_defer_fn (tree fn
)
4248 if (expand_or_defer_fn_1 (fn
))
4252 /* Expand or defer, at the whim of the compilation unit manager. */
4253 cgraph_node::finalize_function (fn
, function_depth
> 1);
4254 emit_associated_thunks (fn
);
4262 nrv_data () : visited (37) {}
4266 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4269 /* Helper function for walk_tree, used by finalize_nrv below. */
4272 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4274 struct nrv_data
*dp
= (struct nrv_data
*)data
;
4277 /* No need to walk into types. There wouldn't be any need to walk into
4278 non-statements, except that we have to consider STMT_EXPRs. */
4281 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4282 but differs from using NULL_TREE in that it indicates that we care
4283 about the value of the RESULT_DECL. */
4284 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4285 TREE_OPERAND (*tp
, 0) = dp
->result
;
4286 /* Change all cleanups for the NRV to only run when an exception is
4288 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4289 && CLEANUP_DECL (*tp
) == dp
->var
)
4290 CLEANUP_EH_ONLY (*tp
) = 1;
4291 /* Replace the DECL_EXPR for the NRV with an initialization of the
4292 RESULT_DECL, if needed. */
4293 else if (TREE_CODE (*tp
) == DECL_EXPR
4294 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4297 if (DECL_INITIAL (dp
->var
)
4298 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4299 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4300 DECL_INITIAL (dp
->var
));
4302 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4303 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4304 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4307 /* And replace all uses of the NRV with the RESULT_DECL. */
4308 else if (*tp
== dp
->var
)
4311 /* Avoid walking into the same tree more than once. Unfortunately, we
4312 can't just use walk_tree_without duplicates because it would only call
4313 us for the first occurrence of dp->var in the function body. */
4314 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4320 /* Keep iterating. */
4324 /* Called from finish_function to implement the named return value
4325 optimization by overriding all the RETURN_EXPRs and pertinent
4326 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4327 RESULT_DECL for the function. */
4330 finalize_nrv (tree
*tp
, tree var
, tree result
)
4332 struct nrv_data data
;
4334 /* Copy name from VAR to RESULT. */
4335 DECL_NAME (result
) = DECL_NAME (var
);
4336 /* Don't forget that we take its address. */
4337 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4338 /* Finally set DECL_VALUE_EXPR to avoid assigning
4339 a stack slot at -O0 for the original var and debug info
4340 uses RESULT location for VAR. */
4341 SET_DECL_VALUE_EXPR (var
, result
);
4342 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4345 data
.result
= result
;
4346 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4349 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4352 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4353 bool need_copy_ctor
, bool need_copy_assignment
,
4356 int save_errorcount
= errorcount
;
4359 /* Always allocate 3 elements for simplicity. These are the
4360 function decls for the ctor, dtor, and assignment op.
4361 This layout is known to the three lang hooks,
4362 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4363 and cxx_omp_clause_assign_op. */
4364 info
= make_tree_vec (3);
4365 CP_OMP_CLAUSE_INFO (c
) = info
;
4367 if (need_default_ctor
|| need_copy_ctor
)
4369 if (need_default_ctor
)
4370 t
= get_default_ctor (type
);
4372 t
= get_copy_ctor (type
, tf_warning_or_error
);
4374 if (t
&& !trivial_fn_p (t
))
4375 TREE_VEC_ELT (info
, 0) = t
;
4378 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4379 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4381 if (need_copy_assignment
)
4383 t
= get_copy_assign (type
);
4385 if (t
&& !trivial_fn_p (t
))
4386 TREE_VEC_ELT (info
, 2) = t
;
4389 return errorcount
!= save_errorcount
;
4392 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4393 FIELD_DECL, otherwise return DECL itself. */
4396 omp_clause_decl_field (tree decl
)
4399 && DECL_HAS_VALUE_EXPR_P (decl
)
4400 && DECL_ARTIFICIAL (decl
)
4401 && DECL_LANG_SPECIFIC (decl
)
4402 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4404 tree f
= DECL_VALUE_EXPR (decl
);
4405 if (INDIRECT_REF_P (f
))
4406 f
= TREE_OPERAND (f
, 0);
4407 if (TREE_CODE (f
) == COMPONENT_REF
)
4409 f
= TREE_OPERAND (f
, 1);
4410 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4417 /* Adjust DECL if needed for printing using %qE. */
4420 omp_clause_printable_decl (tree decl
)
4422 tree t
= omp_clause_decl_field (decl
);
4428 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4429 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4433 omp_note_field_privatization (tree f
, tree t
)
4435 if (!omp_private_member_map
)
4436 omp_private_member_map
= new hash_map
<tree
, tree
>;
4437 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4441 omp_private_member_vec
.safe_push (f
);
4442 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4443 omp_private_member_vec
.safe_push (integer_zero_node
);
4447 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4451 omp_privatize_field (tree t
, bool shared
)
4453 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4454 if (m
== error_mark_node
)
4455 return error_mark_node
;
4456 if (!omp_private_member_map
&& !shared
)
4457 omp_private_member_map
= new hash_map
<tree
, tree
>;
4458 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
)
4460 gcc_assert (INDIRECT_REF_P (m
));
4461 m
= TREE_OPERAND (m
, 0);
4463 tree vb
= NULL_TREE
;
4464 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4467 v
= create_temporary_var (TREE_TYPE (m
));
4468 retrofit_lang_decl (v
);
4469 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4470 SET_DECL_VALUE_EXPR (v
, m
);
4471 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4473 omp_private_member_vec
.safe_push (t
);
4478 /* Helper function for handle_omp_array_sections. Called recursively
4479 to handle multiple array-section-subscripts. C is the clause,
4480 T current expression (initially OMP_CLAUSE_DECL), which is either
4481 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4482 expression if specified, TREE_VALUE length expression if specified,
4483 TREE_CHAIN is what it has been specified after, or some decl.
4484 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4485 set to true if any of the array-section-subscript could have length
4486 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4487 first array-section-subscript which is known not to have length
4489 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4490 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4491 all are or may have length of 1, array-section-subscript [:2] is the
4492 first one known not to have length 1. For array-section-subscript
4493 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4494 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4495 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4496 case though, as some lengths could be zero. */
4499 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4500 bool &maybe_zero_len
, unsigned int &first_non_one
,
4501 enum c_omp_region_type ort
)
4503 tree ret
, low_bound
, length
, type
;
4504 if (TREE_CODE (t
) != TREE_LIST
)
4506 if (error_operand_p (t
))
4507 return error_mark_node
;
4508 if (REFERENCE_REF_P (t
)
4509 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4510 t
= TREE_OPERAND (t
, 0);
4512 if (TREE_CODE (t
) == COMPONENT_REF
4514 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4515 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
4516 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
4517 && !type_dependent_expression_p (t
))
4519 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
4520 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
4522 error_at (OMP_CLAUSE_LOCATION (c
),
4523 "bit-field %qE in %qs clause",
4524 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4525 return error_mark_node
;
4527 while (TREE_CODE (t
) == COMPONENT_REF
)
4529 if (TREE_TYPE (TREE_OPERAND (t
, 0))
4530 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
4532 error_at (OMP_CLAUSE_LOCATION (c
),
4533 "%qE is a member of a union", t
);
4534 return error_mark_node
;
4536 t
= TREE_OPERAND (t
, 0);
4538 if (REFERENCE_REF_P (t
))
4539 t
= TREE_OPERAND (t
, 0);
4541 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
4543 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
4546 error_at (OMP_CLAUSE_LOCATION (c
),
4547 "%qD is not a variable in %qs clause", t
,
4548 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4550 error_at (OMP_CLAUSE_LOCATION (c
),
4551 "%qE is not a variable in %qs clause", t
,
4552 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4553 return error_mark_node
;
4555 else if (TREE_CODE (t
) == PARM_DECL
4556 && DECL_ARTIFICIAL (t
)
4557 && DECL_NAME (t
) == this_identifier
)
4559 error_at (OMP_CLAUSE_LOCATION (c
),
4560 "%<this%> allowed in OpenMP only in %<declare simd%>"
4562 return error_mark_node
;
4564 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4565 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
4567 error_at (OMP_CLAUSE_LOCATION (c
),
4568 "%qD is threadprivate variable in %qs clause", t
,
4569 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4570 return error_mark_node
;
4572 if (type_dependent_expression_p (ret
))
4574 ret
= convert_from_reference (ret
);
4578 if (ort
== C_ORT_OMP
4579 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4580 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
4581 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
4582 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4583 maybe_zero_len
, first_non_one
, ort
);
4584 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4587 type
= TREE_TYPE (ret
);
4588 low_bound
= TREE_PURPOSE (t
);
4589 length
= TREE_VALUE (t
);
4590 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4591 || (length
&& type_dependent_expression_p (length
)))
4594 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4595 return error_mark_node
;
4597 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4599 error_at (OMP_CLAUSE_LOCATION (c
),
4600 "low bound %qE of array section does not have integral type",
4602 return error_mark_node
;
4604 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4606 error_at (OMP_CLAUSE_LOCATION (c
),
4607 "length %qE of array section does not have integral type",
4609 return error_mark_node
;
4612 low_bound
= mark_rvalue_use (low_bound
);
4614 length
= mark_rvalue_use (length
);
4615 /* We need to reduce to real constant-values for checks below. */
4617 length
= fold_simple (length
);
4619 low_bound
= fold_simple (low_bound
);
4621 && TREE_CODE (low_bound
) == INTEGER_CST
4622 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4623 > TYPE_PRECISION (sizetype
))
4624 low_bound
= fold_convert (sizetype
, low_bound
);
4626 && TREE_CODE (length
) == INTEGER_CST
4627 && TYPE_PRECISION (TREE_TYPE (length
))
4628 > TYPE_PRECISION (sizetype
))
4629 length
= fold_convert (sizetype
, length
);
4630 if (low_bound
== NULL_TREE
)
4631 low_bound
= integer_zero_node
;
4633 if (length
!= NULL_TREE
)
4635 if (!integer_nonzerop (length
))
4637 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4638 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4640 if (integer_zerop (length
))
4642 error_at (OMP_CLAUSE_LOCATION (c
),
4643 "zero length array section in %qs clause",
4644 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4645 return error_mark_node
;
4649 maybe_zero_len
= true;
4651 if (first_non_one
== types
.length ()
4652 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4655 if (TREE_CODE (type
) == ARRAY_TYPE
)
4657 if (length
== NULL_TREE
4658 && (TYPE_DOMAIN (type
) == NULL_TREE
4659 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4661 error_at (OMP_CLAUSE_LOCATION (c
),
4662 "for unknown bound array type length expression must "
4664 return error_mark_node
;
4666 if (TREE_CODE (low_bound
) == INTEGER_CST
4667 && tree_int_cst_sgn (low_bound
) == -1)
4669 error_at (OMP_CLAUSE_LOCATION (c
),
4670 "negative low bound in array section in %qs clause",
4671 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4672 return error_mark_node
;
4674 if (length
!= NULL_TREE
4675 && TREE_CODE (length
) == INTEGER_CST
4676 && tree_int_cst_sgn (length
) == -1)
4678 error_at (OMP_CLAUSE_LOCATION (c
),
4679 "negative length in array section in %qs clause",
4680 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4681 return error_mark_node
;
4683 if (TYPE_DOMAIN (type
)
4684 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
4685 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
4689 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
4690 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
4691 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4693 if (tree_int_cst_lt (size
, low_bound
))
4695 error_at (OMP_CLAUSE_LOCATION (c
),
4696 "low bound %qE above array section size "
4697 "in %qs clause", low_bound
,
4698 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4699 return error_mark_node
;
4701 if (tree_int_cst_equal (size
, low_bound
))
4703 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4704 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4706 error_at (OMP_CLAUSE_LOCATION (c
),
4707 "zero length array section in %qs clause",
4708 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4709 return error_mark_node
;
4711 maybe_zero_len
= true;
4713 else if (length
== NULL_TREE
4714 && first_non_one
== types
.length ()
4715 && tree_int_cst_equal
4716 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4720 else if (length
== NULL_TREE
)
4722 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4723 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4724 maybe_zero_len
= true;
4725 if (first_non_one
== types
.length ())
4728 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
4730 if (tree_int_cst_lt (size
, length
))
4732 error_at (OMP_CLAUSE_LOCATION (c
),
4733 "length %qE above array section size "
4734 "in %qs clause", length
,
4735 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4736 return error_mark_node
;
4738 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4741 = size_binop (PLUS_EXPR
,
4742 fold_convert (sizetype
, low_bound
),
4743 fold_convert (sizetype
, length
));
4744 if (TREE_CODE (lbpluslen
) == INTEGER_CST
4745 && tree_int_cst_lt (size
, lbpluslen
))
4747 error_at (OMP_CLAUSE_LOCATION (c
),
4748 "high bound %qE above array section size "
4749 "in %qs clause", lbpluslen
,
4750 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4751 return error_mark_node
;
4756 else if (length
== NULL_TREE
)
4758 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4759 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4760 maybe_zero_len
= true;
4761 if (first_non_one
== types
.length ())
4765 /* For [lb:] we will need to evaluate lb more than once. */
4766 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4768 tree lb
= cp_save_expr (low_bound
);
4769 if (lb
!= low_bound
)
4771 TREE_PURPOSE (t
) = lb
;
4776 else if (TREE_CODE (type
) == POINTER_TYPE
)
4778 if (length
== NULL_TREE
)
4780 error_at (OMP_CLAUSE_LOCATION (c
),
4781 "for pointer type length expression must be specified");
4782 return error_mark_node
;
4784 if (length
!= NULL_TREE
4785 && TREE_CODE (length
) == INTEGER_CST
4786 && tree_int_cst_sgn (length
) == -1)
4788 error_at (OMP_CLAUSE_LOCATION (c
),
4789 "negative length in array section in %qs clause",
4790 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4791 return error_mark_node
;
4793 /* If there is a pointer type anywhere but in the very first
4794 array-section-subscript, the array section can't be contiguous. */
4795 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4796 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
4798 error_at (OMP_CLAUSE_LOCATION (c
),
4799 "array section is not contiguous in %qs clause",
4800 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4801 return error_mark_node
;
4806 error_at (OMP_CLAUSE_LOCATION (c
),
4807 "%qE does not have pointer or array type", ret
);
4808 return error_mark_node
;
4810 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4811 types
.safe_push (TREE_TYPE (ret
));
4812 /* We will need to evaluate lb more than once. */
4813 tree lb
= cp_save_expr (low_bound
);
4814 if (lb
!= low_bound
)
4816 TREE_PURPOSE (t
) = lb
;
4819 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
4823 /* Handle array sections for clause C. */
4826 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
4828 bool maybe_zero_len
= false;
4829 unsigned int first_non_one
= 0;
4830 auto_vec
<tree
, 10> types
;
4831 tree first
= handle_omp_array_sections_1 (c
, OMP_CLAUSE_DECL (c
), types
,
4832 maybe_zero_len
, first_non_one
,
4834 if (first
== error_mark_node
)
4836 if (first
== NULL_TREE
)
4838 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
4840 tree t
= OMP_CLAUSE_DECL (c
);
4841 tree tem
= NULL_TREE
;
4842 if (processing_template_decl
)
4844 /* Need to evaluate side effects in the length expressions
4846 while (TREE_CODE (t
) == TREE_LIST
)
4848 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
4850 if (tem
== NULL_TREE
)
4851 tem
= TREE_VALUE (t
);
4853 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
4854 TREE_VALUE (t
), tem
);
4859 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
4860 OMP_CLAUSE_DECL (c
) = first
;
4864 unsigned int num
= types
.length (), i
;
4865 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
4866 tree condition
= NULL_TREE
;
4868 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
4869 maybe_zero_len
= true;
4870 if (processing_template_decl
&& maybe_zero_len
)
4873 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
4876 tree low_bound
= TREE_PURPOSE (t
);
4877 tree length
= TREE_VALUE (t
);
4881 && TREE_CODE (low_bound
) == INTEGER_CST
4882 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4883 > TYPE_PRECISION (sizetype
))
4884 low_bound
= fold_convert (sizetype
, low_bound
);
4886 && TREE_CODE (length
) == INTEGER_CST
4887 && TYPE_PRECISION (TREE_TYPE (length
))
4888 > TYPE_PRECISION (sizetype
))
4889 length
= fold_convert (sizetype
, length
);
4890 if (low_bound
== NULL_TREE
)
4891 low_bound
= integer_zero_node
;
4892 if (!maybe_zero_len
&& i
> first_non_one
)
4894 if (integer_nonzerop (low_bound
))
4895 goto do_warn_noncontiguous
;
4896 if (length
!= NULL_TREE
4897 && TREE_CODE (length
) == INTEGER_CST
4898 && TYPE_DOMAIN (types
[i
])
4899 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
4900 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
4904 size
= size_binop (PLUS_EXPR
,
4905 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4907 if (!tree_int_cst_equal (length
, size
))
4909 do_warn_noncontiguous
:
4910 error_at (OMP_CLAUSE_LOCATION (c
),
4911 "array section is not contiguous in %qs "
4913 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4917 if (!processing_template_decl
4918 && length
!= NULL_TREE
4919 && TREE_SIDE_EFFECTS (length
))
4921 if (side_effects
== NULL_TREE
)
4922 side_effects
= length
;
4924 side_effects
= build2 (COMPOUND_EXPR
,
4925 TREE_TYPE (side_effects
),
4926 length
, side_effects
);
4929 else if (processing_template_decl
)
4935 if (i
> first_non_one
4936 && ((length
&& integer_nonzerop (length
))
4937 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
))
4940 l
= fold_convert (sizetype
, length
);
4943 l
= size_binop (PLUS_EXPR
,
4944 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4946 l
= size_binop (MINUS_EXPR
, l
,
4947 fold_convert (sizetype
, low_bound
));
4949 if (i
> first_non_one
)
4951 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
4953 if (condition
== NULL_TREE
)
4956 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
4959 else if (size
== NULL_TREE
)
4961 size
= size_in_bytes (TREE_TYPE (types
[i
]));
4962 tree eltype
= TREE_TYPE (types
[num
- 1]);
4963 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4964 eltype
= TREE_TYPE (eltype
);
4965 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4966 size
= size_binop (EXACT_DIV_EXPR
, size
,
4967 size_in_bytes (eltype
));
4968 size
= size_binop (MULT_EXPR
, size
, l
);
4970 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
4971 size
, size_zero_node
);
4974 size
= size_binop (MULT_EXPR
, size
, l
);
4977 if (!processing_template_decl
)
4980 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
4981 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4983 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
4984 tree index_type
= build_index_type (size
);
4985 tree eltype
= TREE_TYPE (first
);
4986 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4987 eltype
= TREE_TYPE (eltype
);
4988 tree type
= build_array_type (eltype
, index_type
);
4989 tree ptype
= build_pointer_type (eltype
);
4990 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
4991 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
4992 t
= convert_from_reference (t
);
4993 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
4994 t
= build_fold_addr_expr (t
);
4995 tree t2
= build_fold_addr_expr (first
);
4996 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4997 ptrdiff_type_node
, t2
);
4998 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
4999 ptrdiff_type_node
, t2
,
5000 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5001 ptrdiff_type_node
, t
));
5002 if (tree_fits_shwi_p (t2
))
5003 t
= build2 (MEM_REF
, type
, t
,
5004 build_int_cst (ptype
, tree_to_shwi (t2
)));
5007 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5009 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
5010 TREE_TYPE (t
), t
, t2
);
5011 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5013 OMP_CLAUSE_DECL (c
) = t
;
5016 OMP_CLAUSE_DECL (c
) = first
;
5017 OMP_CLAUSE_SIZE (c
) = size
;
5018 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5019 || (TREE_CODE (t
) == COMPONENT_REF
5020 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5022 if (ort
== C_ORT_OMP
|| ort
== C_ORT_ACC
)
5023 switch (OMP_CLAUSE_MAP_KIND (c
))
5025 case GOMP_MAP_ALLOC
:
5028 case GOMP_MAP_TOFROM
:
5029 case GOMP_MAP_ALWAYS_TO
:
5030 case GOMP_MAP_ALWAYS_FROM
:
5031 case GOMP_MAP_ALWAYS_TOFROM
:
5032 case GOMP_MAP_RELEASE
:
5033 case GOMP_MAP_DELETE
:
5034 case GOMP_MAP_FORCE_TO
:
5035 case GOMP_MAP_FORCE_FROM
:
5036 case GOMP_MAP_FORCE_TOFROM
:
5037 case GOMP_MAP_FORCE_PRESENT
:
5038 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5043 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5045 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
&& ort
!= C_ORT_ACC
)
5046 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
5047 else if (TREE_CODE (t
) == COMPONENT_REF
)
5048 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5049 else if (REFERENCE_REF_P (t
)
5050 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5052 t
= TREE_OPERAND (t
, 0);
5053 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5056 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5057 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5058 && !cxx_mark_addressable (t
))
5060 OMP_CLAUSE_DECL (c2
) = t
;
5061 t
= build_fold_addr_expr (first
);
5062 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5063 ptrdiff_type_node
, t
);
5064 tree ptr
= OMP_CLAUSE_DECL (c2
);
5065 ptr
= convert_from_reference (ptr
);
5066 if (!POINTER_TYPE_P (TREE_TYPE (ptr
)))
5067 ptr
= build_fold_addr_expr (ptr
);
5068 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5069 ptrdiff_type_node
, t
,
5070 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5071 ptrdiff_type_node
, ptr
));
5072 OMP_CLAUSE_SIZE (c2
) = t
;
5073 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5074 OMP_CLAUSE_CHAIN (c
) = c2
;
5075 ptr
= OMP_CLAUSE_DECL (c2
);
5076 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5077 && TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
5078 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5080 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5082 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5083 OMP_CLAUSE_DECL (c3
) = ptr
;
5084 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
)
5085 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5087 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5088 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5089 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5090 OMP_CLAUSE_CHAIN (c2
) = c3
;
5097 /* Return identifier to look up for omp declare reduction. */
5100 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5102 const char *p
= NULL
;
5103 const char *m
= NULL
;
5104 switch (reduction_code
)
5112 case TRUTH_ANDIF_EXPR
:
5113 case TRUTH_ORIF_EXPR
:
5114 reduction_id
= ovl_op_identifier (false, reduction_code
);
5128 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5129 return error_mark_node
;
5130 p
= IDENTIFIER_POINTER (reduction_id
);
5133 if (type
!= NULL_TREE
)
5134 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5136 const char prefix
[] = "omp declare reduction ";
5137 size_t lenp
= sizeof (prefix
);
5138 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5140 size_t len
= strlen (p
);
5141 size_t lenm
= m
? strlen (m
) + 1 : 0;
5142 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5144 memcpy (name
, prefix
, lenp
- 1);
5145 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5148 name
[lenp
+ len
- 1] = '~';
5149 memcpy (name
+ lenp
+ len
, m
, lenm
);
5151 return get_identifier (name
);
5154 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5155 FUNCTION_DECL or NULL_TREE if not found. */
5158 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5159 vec
<tree
> *ambiguousp
)
5162 tree baselink
= NULL_TREE
;
5163 if (identifier_p (id
))
5166 bool nonint_cst_expression_p
;
5167 const char *error_msg
;
5168 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5169 tree decl
= lookup_name (id
);
5170 if (decl
== NULL_TREE
)
5171 decl
= error_mark_node
;
5172 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5173 &nonint_cst_expression_p
, false, true, false,
5174 false, &error_msg
, loc
);
5175 if (idk
== CP_ID_KIND_UNQUALIFIED
5176 && identifier_p (id
))
5178 vec
<tree
, va_gc
> *args
= NULL
;
5179 vec_safe_push (args
, build_reference_type (type
));
5180 id
= perform_koenig_lookup (id
, args
, tf_none
);
5183 else if (TREE_CODE (id
) == SCOPE_REF
)
5184 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5185 omp_reduction_id (ERROR_MARK
,
5186 TREE_OPERAND (id
, 1),
5191 if (fns
&& is_overloaded_fn (fns
))
5193 for (lkp_iterator
iter (get_fns (fns
)); iter
; ++iter
)
5195 tree fndecl
= *iter
;
5196 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5198 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5199 if (same_type_p (TREE_TYPE (argtype
), type
))
5207 if (id
&& BASELINK_P (fns
))
5216 if (!id
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5218 vec
<tree
> ambiguous
= vNULL
;
5219 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5221 if (ambiguousp
== NULL
)
5222 ambiguousp
= &ambiguous
;
5223 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5225 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5226 baselinkp
? baselinkp
: &baselink
,
5228 if (id
== NULL_TREE
)
5230 if (!ambiguousp
->is_empty ())
5231 ambiguousp
->safe_push (id
);
5232 else if (ret
!= NULL_TREE
)
5234 ambiguousp
->safe_push (ret
);
5235 ambiguousp
->safe_push (id
);
5241 if (ambiguousp
!= &ambiguous
)
5243 if (!ambiguous
.is_empty ())
5245 const char *str
= _("candidates are:");
5248 error_at (loc
, "user defined reduction lookup is ambiguous");
5249 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5251 inform (DECL_SOURCE_LOCATION (udr
), "%s %#qD", str
, udr
);
5253 str
= get_spaces (str
);
5255 ambiguous
.release ();
5256 ret
= error_mark_node
;
5257 baselink
= NULL_TREE
;
5262 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5263 id
, id
, tf_warning_or_error
);
5267 /* Helper function for cp_parser_omp_declare_reduction_exprs
5269 Remove CLEANUP_STMT for data (omp_priv variable).
5270 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5274 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5278 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5279 *tp
= CLEANUP_BODY (*tp
);
5280 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5282 tree decl
= DECL_EXPR_DECL (*tp
);
5283 if (!processing_template_decl
5284 && decl
== (tree
) data
5285 && DECL_INITIAL (decl
)
5286 && DECL_INITIAL (decl
) != error_mark_node
)
5288 tree list
= NULL_TREE
;
5289 append_to_statement_list_force (*tp
, &list
);
5290 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5291 decl
, DECL_INITIAL (decl
));
5292 DECL_INITIAL (decl
) = NULL_TREE
;
5293 append_to_statement_list_force (init_expr
, &list
);
5300 /* Data passed from cp_check_omp_declare_reduction to
5301 cp_check_omp_declare_reduction_r. */
5303 struct cp_check_omp_declare_reduction_data
5310 /* Helper function for cp_check_omp_declare_reduction, called via
5314 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5316 struct cp_check_omp_declare_reduction_data
*udr_data
5317 = (struct cp_check_omp_declare_reduction_data
*) data
;
5319 && !DECL_ARTIFICIAL (*tp
)
5320 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5321 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5323 location_t loc
= udr_data
->loc
;
5324 if (udr_data
->combiner_p
)
5325 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5326 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5329 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5330 "to variable %qD which is not %<omp_priv%> nor "
5338 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5341 cp_check_omp_declare_reduction (tree udr
)
5343 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5344 gcc_assert (TREE_CODE (type
) == REFERENCE_TYPE
);
5345 type
= TREE_TYPE (type
);
5347 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5349 if (type
== error_mark_node
)
5351 if (ARITHMETIC_TYPE_P (type
))
5353 static enum tree_code predef_codes
[]
5354 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5355 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5356 for (i
= 0; i
< 8; i
++)
5358 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5359 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5360 const char *n2
= IDENTIFIER_POINTER (id
);
5361 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5362 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5363 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5368 && TREE_CODE (type
) != COMPLEX_EXPR
)
5370 const char prefix_minmax
[] = "omp declare reduction m";
5371 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5372 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5373 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5374 prefix_minmax
, prefix_size
) == 0
5375 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5376 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5377 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5382 error_at (loc
, "predeclared arithmetic type %qT in "
5383 "%<#pragma omp declare reduction%>", type
);
5387 else if (TREE_CODE (type
) == FUNCTION_TYPE
5388 || TREE_CODE (type
) == METHOD_TYPE
5389 || TREE_CODE (type
) == ARRAY_TYPE
)
5391 error_at (loc
, "function or array type %qT in "
5392 "%<#pragma omp declare reduction%>", type
);
5395 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5397 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5401 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5403 error_at (loc
, "const, volatile or __restrict qualified type %qT in "
5404 "%<#pragma omp declare reduction%>", type
);
5408 tree body
= DECL_SAVED_TREE (udr
);
5409 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5412 tree_stmt_iterator tsi
;
5413 struct cp_check_omp_declare_reduction_data data
;
5414 memset (data
.stmts
, 0, sizeof data
.stmts
);
5415 for (i
= 0, tsi
= tsi_start (body
);
5416 i
< 7 && !tsi_end_p (tsi
);
5417 i
++, tsi_next (&tsi
))
5418 data
.stmts
[i
] = tsi_stmt (tsi
);
5420 gcc_assert (tsi_end_p (tsi
));
5423 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5424 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5425 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5427 data
.combiner_p
= true;
5428 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5430 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5434 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5435 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5436 data
.combiner_p
= false;
5437 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5439 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5440 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5441 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5443 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5447 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5448 an inline call. But, remap
5449 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5450 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5453 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5454 tree decl
, tree placeholder
)
5457 hash_map
<tree
, tree
> decl_map
;
5459 decl_map
.put (omp_decl1
, placeholder
);
5460 decl_map
.put (omp_decl2
, decl
);
5461 memset (&id
, 0, sizeof (id
));
5462 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5463 id
.dst_fn
= current_function_decl
;
5464 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5465 id
.decl_map
= &decl_map
;
5467 id
.copy_decl
= copy_decl_no_change
;
5468 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5469 id
.transform_new_cfg
= true;
5470 id
.transform_return_to_modify
= false;
5471 id
.transform_lang_insert_block
= NULL
;
5473 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5477 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5478 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5481 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5483 if (*tp
== (tree
) data
)
5488 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5489 Return true if there is some error and the clause should be removed. */
5492 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5494 tree t
= OMP_CLAUSE_DECL (c
);
5495 bool predefined
= false;
5496 if (TREE_CODE (t
) == TREE_LIST
)
5498 gcc_assert (processing_template_decl
);
5501 tree type
= TREE_TYPE (t
);
5502 if (TREE_CODE (t
) == MEM_REF
)
5503 type
= TREE_TYPE (type
);
5504 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5505 type
= TREE_TYPE (type
);
5506 if (TREE_CODE (type
) == ARRAY_TYPE
)
5509 gcc_assert (TREE_CODE (t
) != MEM_REF
);
5510 while (TREE_CODE (type
) == ARRAY_TYPE
)
5511 type
= TREE_TYPE (type
);
5512 if (!processing_template_decl
)
5514 t
= require_complete_type (t
);
5515 if (t
== error_mark_node
)
5517 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
5518 TYPE_SIZE_UNIT (type
));
5519 if (integer_zerop (size
))
5521 error ("%qE in %<reduction%> clause is a zero size array",
5522 omp_clause_printable_decl (t
));
5525 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5526 tree index_type
= build_index_type (size
);
5527 tree atype
= build_array_type (type
, index_type
);
5528 tree ptype
= build_pointer_type (type
);
5529 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5530 t
= build_fold_addr_expr (t
);
5531 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
5532 OMP_CLAUSE_DECL (c
) = t
;
5535 if (type
== error_mark_node
)
5537 else if (ARITHMETIC_TYPE_P (type
))
5538 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5547 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5554 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5558 case TRUTH_ANDIF_EXPR
:
5559 case TRUTH_ORIF_EXPR
:
5560 if (FLOAT_TYPE_P (type
))
5567 else if (TYPE_READONLY (type
))
5569 error ("%qE has const type for %<reduction%>",
5570 omp_clause_printable_decl (t
));
5573 else if (!processing_template_decl
)
5575 t
= require_complete_type (t
);
5576 if (t
== error_mark_node
)
5578 OMP_CLAUSE_DECL (c
) = t
;
5583 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5586 else if (processing_template_decl
)
5589 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5591 type
= TYPE_MAIN_VARIANT (type
);
5592 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5593 if (id
== NULL_TREE
)
5594 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5595 NULL_TREE
, NULL_TREE
);
5596 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5599 if (id
== error_mark_node
)
5602 tree body
= DECL_SAVED_TREE (id
);
5605 if (TREE_CODE (body
) == STATEMENT_LIST
)
5607 tree_stmt_iterator tsi
;
5608 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
5611 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5612 atype
= TREE_TYPE (atype
);
5613 bool need_static_cast
= !same_type_p (type
, atype
);
5614 memset (stmts
, 0, sizeof stmts
);
5615 for (i
= 0, tsi
= tsi_start (body
);
5616 i
< 7 && !tsi_end_p (tsi
);
5617 i
++, tsi_next (&tsi
))
5618 stmts
[i
] = tsi_stmt (tsi
);
5619 gcc_assert (tsi_end_p (tsi
));
5623 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
5624 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
5625 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
5626 DECL_ARTIFICIAL (placeholder
) = 1;
5627 DECL_IGNORED_P (placeholder
) = 1;
5628 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
5629 if (TREE_CODE (t
) == MEM_REF
)
5631 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
5633 DECL_ARTIFICIAL (decl_placeholder
) = 1;
5634 DECL_IGNORED_P (decl_placeholder
) = 1;
5635 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
5637 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
5638 cxx_mark_addressable (placeholder
);
5639 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
5640 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
5642 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5643 : OMP_CLAUSE_DECL (c
));
5644 tree omp_out
= placeholder
;
5645 tree omp_in
= decl_placeholder
? decl_placeholder
5646 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5647 if (need_static_cast
)
5649 tree rtype
= build_reference_type (atype
);
5650 omp_out
= build_static_cast (rtype
, omp_out
,
5651 tf_warning_or_error
);
5652 omp_in
= build_static_cast (rtype
, omp_in
,
5653 tf_warning_or_error
);
5654 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
5656 omp_out
= convert_from_reference (omp_out
);
5657 omp_in
= convert_from_reference (omp_in
);
5659 OMP_CLAUSE_REDUCTION_MERGE (c
)
5660 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
5661 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
5665 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
5666 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
5667 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3])))
5668 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5669 : OMP_CLAUSE_DECL (c
));
5670 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
5671 cxx_mark_addressable (placeholder
);
5672 tree omp_priv
= decl_placeholder
? decl_placeholder
5673 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5674 tree omp_orig
= placeholder
;
5675 if (need_static_cast
)
5679 error_at (OMP_CLAUSE_LOCATION (c
),
5680 "user defined reduction with constructor "
5681 "initializer for base class %qT", atype
);
5684 tree rtype
= build_reference_type (atype
);
5685 omp_priv
= build_static_cast (rtype
, omp_priv
,
5686 tf_warning_or_error
);
5687 omp_orig
= build_static_cast (rtype
, omp_orig
,
5688 tf_warning_or_error
);
5689 if (omp_priv
== error_mark_node
5690 || omp_orig
== error_mark_node
)
5692 omp_priv
= convert_from_reference (omp_priv
);
5693 omp_orig
= convert_from_reference (omp_orig
);
5696 *need_default_ctor
= true;
5697 OMP_CLAUSE_REDUCTION_INIT (c
)
5698 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
5699 DECL_EXPR_DECL (stmts
[3]),
5700 omp_priv
, omp_orig
);
5701 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
5702 find_omp_placeholder_r
, placeholder
, NULL
))
5703 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
5707 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
5708 *need_default_ctor
= true;
5712 tree v
= decl_placeholder
? decl_placeholder
5713 : convert_from_reference (t
);
5714 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
5715 init
= build_constructor (TREE_TYPE (v
), NULL
);
5717 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
5718 OMP_CLAUSE_REDUCTION_INIT (c
)
5719 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
5724 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5728 error ("user defined reduction not found for %qE",
5729 omp_clause_printable_decl (t
));
5732 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
5733 gcc_assert (TYPE_SIZE_UNIT (type
)
5734 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
5738 /* Called from finish_struct_1. linear(this) or linear(this:step)
5739 clauses might not be finalized yet because the class has been incomplete
5740 when parsing #pragma omp declare simd methods. Fix those up now. */
5743 finish_omp_declare_simd_methods (tree t
)
5745 if (processing_template_decl
)
5748 for (tree x
= TYPE_FIELDS (t
); x
; x
= DECL_CHAIN (x
))
5750 if (TREE_CODE (TREE_TYPE (x
)) != METHOD_TYPE
)
5752 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
5753 if (!ods
|| !TREE_VALUE (ods
))
5755 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
5756 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
5757 && integer_zerop (OMP_CLAUSE_DECL (c
))
5758 && OMP_CLAUSE_LINEAR_STEP (c
)
5759 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
)))
5762 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
5763 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
5764 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
5765 sizetype
, s
, TYPE_SIZE_UNIT (t
));
5766 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
5771 /* Adjust sink depend clause to take into account pointer offsets.
5773 Return TRUE if there was a problem processing the offset, and the
5774 whole clause should be removed. */
5777 cp_finish_omp_clause_depend_sink (tree sink_clause
)
5779 tree t
= OMP_CLAUSE_DECL (sink_clause
);
5780 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
5782 /* Make sure we don't adjust things twice for templates. */
5783 if (processing_template_decl
)
5786 for (; t
; t
= TREE_CHAIN (t
))
5788 tree decl
= TREE_VALUE (t
);
5789 if (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
5791 tree offset
= TREE_PURPOSE (t
);
5792 bool neg
= wi::neg_p (wi::to_wide (offset
));
5793 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
5794 decl
= mark_rvalue_use (decl
);
5795 decl
= convert_from_reference (decl
);
5796 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
5797 neg
? MINUS_EXPR
: PLUS_EXPR
,
5799 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
5800 MINUS_EXPR
, sizetype
,
5801 fold_convert (sizetype
, t2
),
5802 fold_convert (sizetype
, decl
));
5803 if (t2
== error_mark_node
)
5805 TREE_PURPOSE (t
) = t2
;
5811 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
5812 Remove any elements from the list that are invalid. */
5815 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
5817 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
5818 bitmap_head aligned_head
, map_head
, map_field_head
, oacc_reduction_head
;
5820 tree safelen
= NULL_TREE
;
5821 bool branch_seen
= false;
5822 bool copyprivate_seen
= false;
5823 bool ordered_seen
= false;
5824 bool oacc_async
= false;
5826 bitmap_obstack_initialize (NULL
);
5827 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
5828 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
5829 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
5830 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
5831 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
5832 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
5833 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
5835 if (ort
& C_ORT_ACC
)
5836 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
5837 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
5843 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
5845 bool remove
= false;
5846 bool field_ok
= false;
5848 switch (OMP_CLAUSE_CODE (c
))
5850 case OMP_CLAUSE_SHARED
:
5851 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5852 goto check_dup_generic
;
5853 case OMP_CLAUSE_PRIVATE
:
5854 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5855 goto check_dup_generic
;
5856 case OMP_CLAUSE_REDUCTION
:
5857 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5858 t
= OMP_CLAUSE_DECL (c
);
5859 if (TREE_CODE (t
) == TREE_LIST
)
5861 if (handle_omp_array_sections (c
, ort
))
5866 if (TREE_CODE (t
) == TREE_LIST
)
5868 while (TREE_CODE (t
) == TREE_LIST
)
5873 gcc_assert (TREE_CODE (t
) == MEM_REF
);
5874 t
= TREE_OPERAND (t
, 0);
5875 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
5876 t
= TREE_OPERAND (t
, 0);
5877 if (TREE_CODE (t
) == ADDR_EXPR
5878 || INDIRECT_REF_P (t
))
5879 t
= TREE_OPERAND (t
, 0);
5881 tree n
= omp_clause_decl_field (t
);
5884 goto check_dup_generic_t
;
5887 cxx_mark_addressable (t
);
5888 goto check_dup_generic
;
5889 case OMP_CLAUSE_COPYPRIVATE
:
5890 copyprivate_seen
= true;
5891 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5892 goto check_dup_generic
;
5893 case OMP_CLAUSE_COPYIN
:
5894 goto check_dup_generic
;
5895 case OMP_CLAUSE_LINEAR
:
5896 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5897 t
= OMP_CLAUSE_DECL (c
);
5898 if (ort
!= C_ORT_OMP_DECLARE_SIMD
5899 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
5901 error_at (OMP_CLAUSE_LOCATION (c
),
5902 "modifier should not be specified in %<linear%> "
5903 "clause on %<simd%> or %<for%> constructs");
5904 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
5906 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
5907 && !type_dependent_expression_p (t
))
5909 tree type
= TREE_TYPE (t
);
5910 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5911 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
5912 && TREE_CODE (type
) != REFERENCE_TYPE
)
5914 error ("linear clause with %qs modifier applied to "
5915 "non-reference variable with %qT type",
5916 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5917 ? "ref" : "uval", TREE_TYPE (t
));
5921 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5922 type
= TREE_TYPE (type
);
5923 if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
5925 if (!INTEGRAL_TYPE_P (type
)
5926 && TREE_CODE (type
) != POINTER_TYPE
)
5928 error ("linear clause applied to non-integral non-pointer"
5929 " variable with %qT type", TREE_TYPE (t
));
5935 t
= OMP_CLAUSE_LINEAR_STEP (c
);
5937 t
= integer_one_node
;
5938 if (t
== error_mark_node
)
5943 else if (!type_dependent_expression_p (t
)
5944 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
5945 && (ort
!= C_ORT_OMP_DECLARE_SIMD
5946 || TREE_CODE (t
) != PARM_DECL
5947 || TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
5948 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
5950 error ("linear step expression must be integral");
5956 t
= mark_rvalue_use (t
);
5957 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
5959 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
5960 goto check_dup_generic
;
5962 if (!processing_template_decl
5963 && (VAR_P (OMP_CLAUSE_DECL (c
))
5964 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
5966 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
5968 t
= maybe_constant_value (t
);
5969 if (TREE_CODE (t
) != INTEGER_CST
)
5971 error_at (OMP_CLAUSE_LOCATION (c
),
5972 "%<linear%> clause step %qE is neither "
5973 "constant nor a parameter", t
);
5978 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5979 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
5980 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5981 type
= TREE_TYPE (type
);
5982 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
5984 type
= build_pointer_type (type
);
5985 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
5986 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
5988 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
5989 MINUS_EXPR
, sizetype
,
5990 fold_convert (sizetype
, t
),
5991 fold_convert (sizetype
, d
));
5992 if (t
== error_mark_node
)
5998 else if (TREE_CODE (type
) == POINTER_TYPE
5999 /* Can't multiply the step yet if *this
6000 is still incomplete type. */
6001 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6002 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
6003 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
6004 || DECL_NAME (OMP_CLAUSE_DECL (c
))
6006 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
6008 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
6009 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6011 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6012 MINUS_EXPR
, sizetype
,
6013 fold_convert (sizetype
, t
),
6014 fold_convert (sizetype
, d
));
6015 if (t
== error_mark_node
)
6022 t
= fold_convert (type
, t
);
6024 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6026 goto check_dup_generic
;
6028 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6031 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6032 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6035 t
= OMP_CLAUSE_DECL (c
);
6036 check_dup_generic_t
:
6037 if (t
== current_class_ptr
6038 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6039 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6040 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6042 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6047 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6048 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6050 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6053 error ("%qD is not a variable in clause %qs", t
,
6054 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6056 error ("%qE is not a variable in clause %qs", t
,
6057 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6060 else if (ort
== C_ORT_ACC
6061 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
6063 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
6065 error ("%qD appears more than once in reduction clauses", t
);
6069 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
6071 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6072 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6073 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6075 error ("%qD appears more than once in data clauses", t
);
6078 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6079 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6081 if (ort
== C_ORT_ACC
)
6082 error ("%qD appears more than once in data clauses", t
);
6084 error ("%qD appears both in data and map clauses", t
);
6088 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6093 && TREE_CODE (t
) == FIELD_DECL
6094 && t
== OMP_CLAUSE_DECL (c
)
6095 && ort
!= C_ORT_ACC
)
6098 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
6099 == OMP_CLAUSE_SHARED
));
6100 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
6105 case OMP_CLAUSE_FIRSTPRIVATE
:
6106 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6108 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6110 t
= OMP_CLAUSE_DECL (c
);
6111 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6113 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6118 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6119 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6120 || TREE_CODE (t
) != FIELD_DECL
))
6122 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6125 error ("%qD is not a variable in clause %<firstprivate%>", t
);
6127 error ("%qE is not a variable in clause %<firstprivate%>", t
);
6130 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6131 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6133 error ("%qD appears more than once in data clauses", t
);
6136 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6138 if (ort
== C_ORT_ACC
)
6139 error ("%qD appears more than once in data clauses", t
);
6141 error ("%qD appears both in data and map clauses", t
);
6145 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
6146 goto handle_field_decl
;
6148 case OMP_CLAUSE_LASTPRIVATE
:
6149 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6151 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6153 t
= OMP_CLAUSE_DECL (c
);
6154 if (t
== current_class_ptr
)
6156 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6161 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6162 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6163 || TREE_CODE (t
) != FIELD_DECL
))
6165 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6168 error ("%qD is not a variable in clause %<lastprivate%>", t
);
6170 error ("%qE is not a variable in clause %<lastprivate%>", t
);
6173 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6174 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6176 error ("%qD appears more than once in data clauses", t
);
6180 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
6181 goto handle_field_decl
;
6184 t
= OMP_CLAUSE_IF_EXPR (c
);
6185 t
= maybe_convert_cond (t
);
6186 if (t
== error_mark_node
)
6188 else if (!processing_template_decl
)
6189 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6190 OMP_CLAUSE_IF_EXPR (c
) = t
;
6193 case OMP_CLAUSE_FINAL
:
6194 t
= OMP_CLAUSE_FINAL_EXPR (c
);
6195 t
= maybe_convert_cond (t
);
6196 if (t
== error_mark_node
)
6198 else if (!processing_template_decl
)
6199 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6200 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
6203 case OMP_CLAUSE_GANG
:
6204 /* Operand 1 is the gang static: argument. */
6205 t
= OMP_CLAUSE_OPERAND (c
, 1);
6208 if (t
== error_mark_node
)
6210 else if (!type_dependent_expression_p (t
)
6211 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6213 error ("%<gang%> static expression must be integral");
6218 t
= mark_rvalue_use (t
);
6219 if (!processing_template_decl
)
6221 t
= maybe_constant_value (t
);
6222 if (TREE_CODE (t
) == INTEGER_CST
6223 && tree_int_cst_sgn (t
) != 1
6224 && t
!= integer_minus_one_node
)
6226 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6227 "%<gang%> static value must be "
6229 t
= integer_one_node
;
6231 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6234 OMP_CLAUSE_OPERAND (c
, 1) = t
;
6236 /* Check operand 0, the num argument. */
6239 case OMP_CLAUSE_WORKER
:
6240 case OMP_CLAUSE_VECTOR
:
6241 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
6245 case OMP_CLAUSE_NUM_TASKS
:
6246 case OMP_CLAUSE_NUM_TEAMS
:
6247 case OMP_CLAUSE_NUM_THREADS
:
6248 case OMP_CLAUSE_NUM_GANGS
:
6249 case OMP_CLAUSE_NUM_WORKERS
:
6250 case OMP_CLAUSE_VECTOR_LENGTH
:
6251 t
= OMP_CLAUSE_OPERAND (c
, 0);
6252 if (t
== error_mark_node
)
6254 else if (!type_dependent_expression_p (t
)
6255 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6257 switch (OMP_CLAUSE_CODE (c
))
6259 case OMP_CLAUSE_GANG
:
6260 error_at (OMP_CLAUSE_LOCATION (c
),
6261 "%<gang%> num expression must be integral"); break;
6262 case OMP_CLAUSE_VECTOR
:
6263 error_at (OMP_CLAUSE_LOCATION (c
),
6264 "%<vector%> length expression must be integral");
6266 case OMP_CLAUSE_WORKER
:
6267 error_at (OMP_CLAUSE_LOCATION (c
),
6268 "%<worker%> num expression must be integral");
6271 error_at (OMP_CLAUSE_LOCATION (c
),
6272 "%qs expression must be integral",
6273 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6279 t
= mark_rvalue_use (t
);
6280 if (!processing_template_decl
)
6282 t
= maybe_constant_value (t
);
6283 if (TREE_CODE (t
) == INTEGER_CST
6284 && tree_int_cst_sgn (t
) != 1)
6286 switch (OMP_CLAUSE_CODE (c
))
6288 case OMP_CLAUSE_GANG
:
6289 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6290 "%<gang%> num value must be positive");
6292 case OMP_CLAUSE_VECTOR
:
6293 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6294 "%<vector%> length value must be "
6297 case OMP_CLAUSE_WORKER
:
6298 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6299 "%<worker%> num value must be "
6303 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6304 "%qs value must be positive",
6305 omp_clause_code_name
6306 [OMP_CLAUSE_CODE (c
)]);
6308 t
= integer_one_node
;
6310 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6312 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6316 case OMP_CLAUSE_SCHEDULE
:
6317 if (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
)
6319 const char *p
= NULL
;
6320 switch (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_MASK
)
6322 case OMP_CLAUSE_SCHEDULE_STATIC
: p
= "static"; break;
6323 case OMP_CLAUSE_SCHEDULE_DYNAMIC
: break;
6324 case OMP_CLAUSE_SCHEDULE_GUIDED
: break;
6325 case OMP_CLAUSE_SCHEDULE_AUTO
: p
= "auto"; break;
6326 case OMP_CLAUSE_SCHEDULE_RUNTIME
: p
= "runtime"; break;
6327 default: gcc_unreachable ();
6331 error_at (OMP_CLAUSE_LOCATION (c
),
6332 "%<nonmonotonic%> modifier specified for %qs "
6333 "schedule kind", p
);
6334 OMP_CLAUSE_SCHEDULE_KIND (c
)
6335 = (enum omp_clause_schedule_kind
)
6336 (OMP_CLAUSE_SCHEDULE_KIND (c
)
6337 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
6341 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
6344 else if (t
== error_mark_node
)
6346 else if (!type_dependent_expression_p (t
)
6347 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6349 error ("schedule chunk size expression must be integral");
6354 t
= mark_rvalue_use (t
);
6355 if (!processing_template_decl
)
6357 t
= maybe_constant_value (t
);
6358 if (TREE_CODE (t
) == INTEGER_CST
6359 && tree_int_cst_sgn (t
) != 1)
6361 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6362 "chunk size value must be positive");
6363 t
= integer_one_node
;
6365 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6367 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
6371 case OMP_CLAUSE_SIMDLEN
:
6372 case OMP_CLAUSE_SAFELEN
:
6373 t
= OMP_CLAUSE_OPERAND (c
, 0);
6374 if (t
== error_mark_node
)
6376 else if (!type_dependent_expression_p (t
)
6377 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6379 error ("%qs length expression must be integral",
6380 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6385 t
= mark_rvalue_use (t
);
6386 if (!processing_template_decl
)
6388 t
= maybe_constant_value (t
);
6389 if (TREE_CODE (t
) != INTEGER_CST
6390 || tree_int_cst_sgn (t
) != 1)
6392 error ("%qs length expression must be positive constant"
6393 " integer expression",
6394 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6398 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6399 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
6404 case OMP_CLAUSE_ASYNC
:
6405 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
6406 if (t
== error_mark_node
)
6408 else if (!type_dependent_expression_p (t
)
6409 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6411 error ("%<async%> expression must be integral");
6416 t
= mark_rvalue_use (t
);
6417 if (!processing_template_decl
)
6418 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6419 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
6423 case OMP_CLAUSE_WAIT
:
6424 t
= OMP_CLAUSE_WAIT_EXPR (c
);
6425 if (t
== error_mark_node
)
6427 else if (!processing_template_decl
)
6428 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6429 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
6432 case OMP_CLAUSE_THREAD_LIMIT
:
6433 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
6434 if (t
== error_mark_node
)
6436 else if (!type_dependent_expression_p (t
)
6437 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6439 error ("%<thread_limit%> expression must be integral");
6444 t
= mark_rvalue_use (t
);
6445 if (!processing_template_decl
)
6447 t
= maybe_constant_value (t
);
6448 if (TREE_CODE (t
) == INTEGER_CST
6449 && tree_int_cst_sgn (t
) != 1)
6451 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6452 "%<thread_limit%> value must be positive");
6453 t
= integer_one_node
;
6455 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6457 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
6461 case OMP_CLAUSE_DEVICE
:
6462 t
= OMP_CLAUSE_DEVICE_ID (c
);
6463 if (t
== error_mark_node
)
6465 else if (!type_dependent_expression_p (t
)
6466 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6468 error ("%<device%> id must be integral");
6473 t
= mark_rvalue_use (t
);
6474 if (!processing_template_decl
)
6475 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6476 OMP_CLAUSE_DEVICE_ID (c
) = t
;
6480 case OMP_CLAUSE_DIST_SCHEDULE
:
6481 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
6484 else if (t
== error_mark_node
)
6486 else if (!type_dependent_expression_p (t
)
6487 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6489 error ("%<dist_schedule%> chunk size expression must be "
6495 t
= mark_rvalue_use (t
);
6496 if (!processing_template_decl
)
6497 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6498 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
6502 case OMP_CLAUSE_ALIGNED
:
6503 t
= OMP_CLAUSE_DECL (c
);
6504 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
6506 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6511 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6513 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6516 error ("%qD is not a variable in %<aligned%> clause", t
);
6518 error ("%qE is not a variable in %<aligned%> clause", t
);
6521 else if (!type_dependent_expression_p (t
)
6522 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
6523 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
6524 && (TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6525 || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
6526 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
6529 error_at (OMP_CLAUSE_LOCATION (c
),
6530 "%qE in %<aligned%> clause is neither a pointer nor "
6531 "an array nor a reference to pointer or array", t
);
6534 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
6536 error ("%qD appears more than once in %<aligned%> clauses", t
);
6540 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
6541 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
6542 if (t
== error_mark_node
)
6544 else if (t
== NULL_TREE
)
6546 else if (!type_dependent_expression_p (t
)
6547 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6549 error ("%<aligned%> clause alignment expression must "
6555 t
= mark_rvalue_use (t
);
6556 if (!processing_template_decl
)
6558 t
= maybe_constant_value (t
);
6559 if (TREE_CODE (t
) != INTEGER_CST
6560 || tree_int_cst_sgn (t
) != 1)
6562 error ("%<aligned%> clause alignment expression must be "
6563 "positive constant integer expression");
6567 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
6571 case OMP_CLAUSE_DEPEND
:
6572 t
= OMP_CLAUSE_DECL (c
);
6575 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
6576 == OMP_CLAUSE_DEPEND_SOURCE
);
6579 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
6581 if (cp_finish_omp_clause_depend_sink (c
))
6585 if (TREE_CODE (t
) == TREE_LIST
)
6587 if (handle_omp_array_sections (c
, ort
))
6591 if (t
== error_mark_node
)
6593 else if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6595 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6598 error ("%qD is not a variable in %<depend%> clause", t
);
6600 error ("%qE is not a variable in %<depend%> clause", t
);
6603 else if (t
== current_class_ptr
)
6605 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6609 else if (!processing_template_decl
6610 && !cxx_mark_addressable (t
))
6614 case OMP_CLAUSE_MAP
:
6616 case OMP_CLAUSE_FROM
:
6617 case OMP_CLAUSE__CACHE_
:
6618 t
= OMP_CLAUSE_DECL (c
);
6619 if (TREE_CODE (t
) == TREE_LIST
)
6621 if (handle_omp_array_sections (c
, ort
))
6625 t
= OMP_CLAUSE_DECL (c
);
6626 if (TREE_CODE (t
) != TREE_LIST
6627 && !type_dependent_expression_p (t
)
6628 && !cp_omp_mappable_type (TREE_TYPE (t
)))
6630 error_at (OMP_CLAUSE_LOCATION (c
),
6631 "array section does not have mappable type "
6633 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6636 while (TREE_CODE (t
) == ARRAY_REF
)
6637 t
= TREE_OPERAND (t
, 0);
6638 if (TREE_CODE (t
) == COMPONENT_REF
6639 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6641 while (TREE_CODE (t
) == COMPONENT_REF
)
6642 t
= TREE_OPERAND (t
, 0);
6643 if (REFERENCE_REF_P (t
))
6644 t
= TREE_OPERAND (t
, 0);
6645 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6647 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6649 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6650 error ("%qD appears more than once in motion"
6652 else if (ort
== C_ORT_ACC
)
6653 error ("%qD appears more than once in data"
6656 error ("%qD appears more than once in map"
6662 bitmap_set_bit (&map_head
, DECL_UID (t
));
6663 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6669 if (t
== error_mark_node
)
6674 if (REFERENCE_REF_P (t
)
6675 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
6677 t
= TREE_OPERAND (t
, 0);
6678 OMP_CLAUSE_DECL (c
) = t
;
6680 if (TREE_CODE (t
) == COMPONENT_REF
6681 && (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
6682 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
6684 if (type_dependent_expression_p (t
))
6686 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
6687 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
6689 error_at (OMP_CLAUSE_LOCATION (c
),
6690 "bit-field %qE in %qs clause",
6691 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6694 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6696 error_at (OMP_CLAUSE_LOCATION (c
),
6697 "%qE does not have a mappable type in %qs clause",
6698 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6701 while (TREE_CODE (t
) == COMPONENT_REF
)
6703 if (TREE_TYPE (TREE_OPERAND (t
, 0))
6704 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
6707 error_at (OMP_CLAUSE_LOCATION (c
),
6708 "%qE is a member of a union", t
);
6712 t
= TREE_OPERAND (t
, 0);
6716 if (REFERENCE_REF_P (t
))
6717 t
= TREE_OPERAND (t
, 0);
6718 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6720 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6721 goto handle_map_references
;
6724 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6726 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6728 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6729 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6730 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
))
6733 error ("%qD is not a variable in %qs clause", t
,
6734 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6736 error ("%qE is not a variable in %qs clause", t
,
6737 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6740 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
6742 error ("%qD is threadprivate variable in %qs clause", t
,
6743 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6746 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6748 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6753 else if (!processing_template_decl
6754 && TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6755 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
6756 || (OMP_CLAUSE_MAP_KIND (c
)
6757 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
6758 && !cxx_mark_addressable (t
))
6760 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6761 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6762 || (OMP_CLAUSE_MAP_KIND (c
)
6763 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
6764 && t
== OMP_CLAUSE_DECL (c
)
6765 && !type_dependent_expression_p (t
)
6766 && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t
))
6768 ? TREE_TYPE (TREE_TYPE (t
))
6771 error_at (OMP_CLAUSE_LOCATION (c
),
6772 "%qD does not have a mappable type in %qs clause", t
,
6773 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6776 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6777 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
6778 && !type_dependent_expression_p (t
)
6779 && !POINTER_TYPE_P (TREE_TYPE (t
)))
6781 error ("%qD is not a pointer variable", t
);
6784 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6785 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
6787 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6788 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6790 error ("%qD appears more than once in data clauses", t
);
6793 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6795 if (ort
== C_ORT_ACC
)
6796 error ("%qD appears more than once in data clauses", t
);
6798 error ("%qD appears both in data and map clauses", t
);
6802 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6804 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6806 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6807 error ("%qD appears more than once in motion clauses", t
);
6808 if (ort
== C_ORT_ACC
)
6809 error ("%qD appears more than once in data clauses", t
);
6811 error ("%qD appears more than once in map clauses", t
);
6814 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6815 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6817 if (ort
== C_ORT_ACC
)
6818 error ("%qD appears more than once in data clauses", t
);
6820 error ("%qD appears both in data and map clauses", t
);
6825 bitmap_set_bit (&map_head
, DECL_UID (t
));
6826 if (t
!= OMP_CLAUSE_DECL (c
)
6827 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
6828 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6830 handle_map_references
:
6832 && !processing_template_decl
6833 && (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
6834 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
))) == REFERENCE_TYPE
)
6836 t
= OMP_CLAUSE_DECL (c
);
6837 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6839 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6840 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6842 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6844 else if (OMP_CLAUSE_MAP_KIND (c
)
6845 != GOMP_MAP_FIRSTPRIVATE_POINTER
6846 && (OMP_CLAUSE_MAP_KIND (c
)
6847 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
6848 && (OMP_CLAUSE_MAP_KIND (c
)
6849 != GOMP_MAP_ALWAYS_POINTER
))
6851 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
6853 if (TREE_CODE (t
) == COMPONENT_REF
)
6854 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
6856 OMP_CLAUSE_SET_MAP_KIND (c2
,
6857 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
6858 OMP_CLAUSE_DECL (c2
) = t
;
6859 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
6860 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
6861 OMP_CLAUSE_CHAIN (c
) = c2
;
6862 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6863 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6865 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6871 case OMP_CLAUSE_TO_DECLARE
:
6872 case OMP_CLAUSE_LINK
:
6873 t
= OMP_CLAUSE_DECL (c
);
6874 if (TREE_CODE (t
) == FUNCTION_DECL
6875 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6877 else if (!VAR_P (t
))
6879 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6881 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
6882 error_at (OMP_CLAUSE_LOCATION (c
),
6883 "template %qE in clause %qs", t
,
6884 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6885 else if (really_overloaded_fn (t
))
6886 error_at (OMP_CLAUSE_LOCATION (c
),
6887 "overloaded function name %qE in clause %qs", t
,
6888 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6890 error_at (OMP_CLAUSE_LOCATION (c
),
6891 "%qE is neither a variable nor a function name "
6893 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6896 error_at (OMP_CLAUSE_LOCATION (c
),
6897 "%qE is not a variable in clause %qs", t
,
6898 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6901 else if (DECL_THREAD_LOCAL_P (t
))
6903 error_at (OMP_CLAUSE_LOCATION (c
),
6904 "%qD is threadprivate variable in %qs clause", t
,
6905 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6908 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6910 error_at (OMP_CLAUSE_LOCATION (c
),
6911 "%qD does not have a mappable type in %qs clause", t
,
6912 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6917 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
6919 error_at (OMP_CLAUSE_LOCATION (c
),
6920 "%qE appears more than once on the same "
6921 "%<declare target%> directive", t
);
6925 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6928 case OMP_CLAUSE_UNIFORM
:
6929 t
= OMP_CLAUSE_DECL (c
);
6930 if (TREE_CODE (t
) != PARM_DECL
)
6932 if (processing_template_decl
)
6935 error ("%qD is not an argument in %<uniform%> clause", t
);
6937 error ("%qE is not an argument in %<uniform%> clause", t
);
6941 /* map_head bitmap is used as uniform_head if declare_simd. */
6942 bitmap_set_bit (&map_head
, DECL_UID (t
));
6943 goto check_dup_generic
;
6945 case OMP_CLAUSE_GRAINSIZE
:
6946 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
6947 if (t
== error_mark_node
)
6949 else if (!type_dependent_expression_p (t
)
6950 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6952 error ("%<grainsize%> expression must be integral");
6957 t
= mark_rvalue_use (t
);
6958 if (!processing_template_decl
)
6960 t
= maybe_constant_value (t
);
6961 if (TREE_CODE (t
) == INTEGER_CST
6962 && tree_int_cst_sgn (t
) != 1)
6964 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6965 "%<grainsize%> value must be positive");
6966 t
= integer_one_node
;
6968 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6970 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
6974 case OMP_CLAUSE_PRIORITY
:
6975 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
6976 if (t
== error_mark_node
)
6978 else if (!type_dependent_expression_p (t
)
6979 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6981 error ("%<priority%> expression must be integral");
6986 t
= mark_rvalue_use (t
);
6987 if (!processing_template_decl
)
6989 t
= maybe_constant_value (t
);
6990 if (TREE_CODE (t
) == INTEGER_CST
6991 && tree_int_cst_sgn (t
) == -1)
6993 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6994 "%<priority%> value must be non-negative");
6995 t
= integer_one_node
;
6997 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6999 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
7003 case OMP_CLAUSE_HINT
:
7004 t
= OMP_CLAUSE_HINT_EXPR (c
);
7005 if (t
== error_mark_node
)
7007 else if (!type_dependent_expression_p (t
)
7008 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7010 error ("%<num_tasks%> expression must be integral");
7015 t
= mark_rvalue_use (t
);
7016 if (!processing_template_decl
)
7018 t
= maybe_constant_value (t
);
7019 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7021 OMP_CLAUSE_HINT_EXPR (c
) = t
;
7025 case OMP_CLAUSE_IS_DEVICE_PTR
:
7026 case OMP_CLAUSE_USE_DEVICE_PTR
:
7027 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
7028 t
= OMP_CLAUSE_DECL (c
);
7029 if (!type_dependent_expression_p (t
))
7031 tree type
= TREE_TYPE (t
);
7032 if (TREE_CODE (type
) != POINTER_TYPE
7033 && TREE_CODE (type
) != ARRAY_TYPE
7034 && (TREE_CODE (type
) != REFERENCE_TYPE
7035 || (TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
7036 && TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
)))
7038 error_at (OMP_CLAUSE_LOCATION (c
),
7039 "%qs variable is neither a pointer, nor an array "
7040 "nor reference to pointer or array",
7041 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7045 goto check_dup_generic
;
7047 case OMP_CLAUSE_NOWAIT
:
7048 case OMP_CLAUSE_DEFAULT
:
7049 case OMP_CLAUSE_UNTIED
:
7050 case OMP_CLAUSE_COLLAPSE
:
7051 case OMP_CLAUSE_MERGEABLE
:
7052 case OMP_CLAUSE_PARALLEL
:
7053 case OMP_CLAUSE_FOR
:
7054 case OMP_CLAUSE_SECTIONS
:
7055 case OMP_CLAUSE_TASKGROUP
:
7056 case OMP_CLAUSE_PROC_BIND
:
7057 case OMP_CLAUSE_NOGROUP
:
7058 case OMP_CLAUSE_THREADS
:
7059 case OMP_CLAUSE_SIMD
:
7060 case OMP_CLAUSE_DEFAULTMAP
:
7061 case OMP_CLAUSE_AUTO
:
7062 case OMP_CLAUSE_INDEPENDENT
:
7063 case OMP_CLAUSE_SEQ
:
7066 case OMP_CLAUSE_TILE
:
7067 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
7068 list
= TREE_CHAIN (list
))
7070 t
= TREE_VALUE (list
);
7072 if (t
== error_mark_node
)
7074 else if (!type_dependent_expression_p (t
)
7075 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7077 error_at (OMP_CLAUSE_LOCATION (c
),
7078 "%<tile%> argument needs integral type");
7083 t
= mark_rvalue_use (t
);
7084 if (!processing_template_decl
)
7086 /* Zero is used to indicate '*', we permit you
7087 to get there via an ICE of value zero. */
7088 t
= maybe_constant_value (t
);
7089 if (!tree_fits_shwi_p (t
)
7090 || tree_to_shwi (t
) < 0)
7092 error_at (OMP_CLAUSE_LOCATION (c
),
7093 "%<tile%> argument needs positive "
7094 "integral constant");
7097 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7101 /* Update list item. */
7102 TREE_VALUE (list
) = t
;
7106 case OMP_CLAUSE_ORDERED
:
7107 ordered_seen
= true;
7110 case OMP_CLAUSE_INBRANCH
:
7111 case OMP_CLAUSE_NOTINBRANCH
:
7114 error ("%<inbranch%> clause is incompatible with "
7126 *pc
= OMP_CLAUSE_CHAIN (c
);
7128 pc
= &OMP_CLAUSE_CHAIN (c
);
7131 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
7133 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
7134 bool remove
= false;
7135 bool need_complete_type
= false;
7136 bool need_default_ctor
= false;
7137 bool need_copy_ctor
= false;
7138 bool need_copy_assignment
= false;
7139 bool need_implicitly_determined
= false;
7140 bool need_dtor
= false;
7141 tree type
, inner_type
;
7145 case OMP_CLAUSE_SHARED
:
7146 need_implicitly_determined
= true;
7148 case OMP_CLAUSE_PRIVATE
:
7149 need_complete_type
= true;
7150 need_default_ctor
= true;
7152 need_implicitly_determined
= true;
7154 case OMP_CLAUSE_FIRSTPRIVATE
:
7155 need_complete_type
= true;
7156 need_copy_ctor
= true;
7158 need_implicitly_determined
= true;
7160 case OMP_CLAUSE_LASTPRIVATE
:
7161 need_complete_type
= true;
7162 need_copy_assignment
= true;
7163 need_implicitly_determined
= true;
7165 case OMP_CLAUSE_REDUCTION
:
7166 need_implicitly_determined
= true;
7168 case OMP_CLAUSE_LINEAR
:
7169 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
7170 need_implicitly_determined
= true;
7171 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
7172 && !bitmap_bit_p (&map_head
,
7173 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
7175 error_at (OMP_CLAUSE_LOCATION (c
),
7176 "%<linear%> clause step is a parameter %qD not "
7177 "specified in %<uniform%> clause",
7178 OMP_CLAUSE_LINEAR_STEP (c
));
7179 *pc
= OMP_CLAUSE_CHAIN (c
);
7183 case OMP_CLAUSE_COPYPRIVATE
:
7184 need_copy_assignment
= true;
7186 case OMP_CLAUSE_COPYIN
:
7187 need_copy_assignment
= true;
7189 case OMP_CLAUSE_SIMDLEN
:
7191 && !processing_template_decl
7192 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
7193 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
7195 error_at (OMP_CLAUSE_LOCATION (c
),
7196 "%<simdlen%> clause value is bigger than "
7197 "%<safelen%> clause value");
7198 OMP_CLAUSE_SIMDLEN_EXPR (c
)
7199 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
7201 pc
= &OMP_CLAUSE_CHAIN (c
);
7203 case OMP_CLAUSE_SCHEDULE
:
7205 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
7206 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
7208 error_at (OMP_CLAUSE_LOCATION (c
),
7209 "%<nonmonotonic%> schedule modifier specified "
7210 "together with %<ordered%> clause");
7211 OMP_CLAUSE_SCHEDULE_KIND (c
)
7212 = (enum omp_clause_schedule_kind
)
7213 (OMP_CLAUSE_SCHEDULE_KIND (c
)
7214 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
7216 pc
= &OMP_CLAUSE_CHAIN (c
);
7218 case OMP_CLAUSE_NOWAIT
:
7219 if (copyprivate_seen
)
7221 error_at (OMP_CLAUSE_LOCATION (c
),
7222 "%<nowait%> clause must not be used together "
7223 "with %<copyprivate%>");
7224 *pc
= OMP_CLAUSE_CHAIN (c
);
7229 pc
= &OMP_CLAUSE_CHAIN (c
);
7233 t
= OMP_CLAUSE_DECL (c
);
7234 if (processing_template_decl
7235 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7237 pc
= &OMP_CLAUSE_CHAIN (c
);
7243 case OMP_CLAUSE_LASTPRIVATE
:
7244 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7246 need_default_ctor
= true;
7251 case OMP_CLAUSE_REDUCTION
:
7252 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
7256 t
= OMP_CLAUSE_DECL (c
);
7259 case OMP_CLAUSE_COPYIN
:
7260 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
7262 error ("%qE must be %<threadprivate%> for %<copyin%>", t
);
7271 if (need_complete_type
|| need_copy_assignment
)
7273 t
= require_complete_type (t
);
7274 if (t
== error_mark_node
)
7276 else if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
7277 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
7280 if (need_implicitly_determined
)
7282 const char *share_name
= NULL
;
7284 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7285 share_name
= "threadprivate";
7286 else switch (cxx_omp_predetermined_sharing (t
))
7288 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
7290 case OMP_CLAUSE_DEFAULT_SHARED
:
7291 /* const vars may be specified in firstprivate clause. */
7292 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
7293 && cxx_omp_const_qual_no_mutable (t
))
7295 share_name
= "shared";
7297 case OMP_CLAUSE_DEFAULT_PRIVATE
:
7298 share_name
= "private";
7305 error ("%qE is predetermined %qs for %qs",
7306 omp_clause_printable_decl (t
), share_name
,
7307 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7312 /* We're interested in the base element, not arrays. */
7313 inner_type
= type
= TREE_TYPE (t
);
7314 if ((need_complete_type
7315 || need_copy_assignment
7316 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
7317 && TREE_CODE (inner_type
) == REFERENCE_TYPE
)
7318 inner_type
= TREE_TYPE (inner_type
);
7319 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
7320 inner_type
= TREE_TYPE (inner_type
);
7322 /* Check for special function availability by building a call to one.
7323 Save the results, because later we won't be in the right context
7324 for making these queries. */
7325 if (CLASS_TYPE_P (inner_type
)
7326 && COMPLETE_TYPE_P (inner_type
)
7327 && (need_default_ctor
|| need_copy_ctor
7328 || need_copy_assignment
|| need_dtor
)
7329 && !type_dependent_expression_p (t
)
7330 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
7331 need_copy_ctor
, need_copy_assignment
,
7336 && c_kind
== OMP_CLAUSE_SHARED
7337 && processing_template_decl
)
7339 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7341 OMP_CLAUSE_DECL (c
) = t
;
7345 *pc
= OMP_CLAUSE_CHAIN (c
);
7347 pc
= &OMP_CLAUSE_CHAIN (c
);
7350 bitmap_obstack_release (NULL
);
7354 /* Start processing OpenMP clauses that can include any
7355 privatization clauses for non-static data members. */
7358 push_omp_privatization_clauses (bool ignore_next
)
7360 if (omp_private_member_ignore_next
)
7362 omp_private_member_ignore_next
= ignore_next
;
7365 omp_private_member_ignore_next
= ignore_next
;
7366 if (omp_private_member_map
)
7367 omp_private_member_vec
.safe_push (error_mark_node
);
7368 return push_stmt_list ();
7371 /* Revert remapping of any non-static data members since
7372 the last push_omp_privatization_clauses () call. */
7375 pop_omp_privatization_clauses (tree stmt
)
7377 if (stmt
== NULL_TREE
)
7379 stmt
= pop_stmt_list (stmt
);
7380 if (omp_private_member_map
)
7382 while (!omp_private_member_vec
.is_empty ())
7384 tree t
= omp_private_member_vec
.pop ();
7385 if (t
== error_mark_node
)
7390 bool no_decl_expr
= t
== integer_zero_node
;
7392 t
= omp_private_member_vec
.pop ();
7393 tree
*v
= omp_private_member_map
->get (t
);
7397 omp_private_member_map
->remove (t
);
7399 delete omp_private_member_map
;
7400 omp_private_member_map
= NULL
;
7405 /* Remember OpenMP privatization clauses mapping and clear it.
7406 Used for lambdas. */
7409 save_omp_privatization_clauses (vec
<tree
> &save
)
7412 if (omp_private_member_ignore_next
)
7413 save
.safe_push (integer_one_node
);
7414 omp_private_member_ignore_next
= false;
7415 if (!omp_private_member_map
)
7418 while (!omp_private_member_vec
.is_empty ())
7420 tree t
= omp_private_member_vec
.pop ();
7421 if (t
== error_mark_node
)
7427 if (t
== integer_zero_node
)
7428 t
= omp_private_member_vec
.pop ();
7429 tree
*v
= omp_private_member_map
->get (t
);
7431 save
.safe_push (*v
);
7436 delete omp_private_member_map
;
7437 omp_private_member_map
= NULL
;
7440 /* Restore OpenMP privatization clauses mapping saved by the
7444 restore_omp_privatization_clauses (vec
<tree
> &save
)
7446 gcc_assert (omp_private_member_vec
.is_empty ());
7447 omp_private_member_ignore_next
= false;
7448 if (save
.is_empty ())
7450 if (save
.length () == 1 && save
[0] == integer_one_node
)
7452 omp_private_member_ignore_next
= true;
7457 omp_private_member_map
= new hash_map
<tree
, tree
>;
7458 while (!save
.is_empty ())
7460 tree t
= save
.pop ();
7462 if (t
!= error_mark_node
)
7464 if (t
== integer_one_node
)
7466 omp_private_member_ignore_next
= true;
7467 gcc_assert (save
.is_empty ());
7470 if (t
== integer_zero_node
)
7472 tree
&v
= omp_private_member_map
->get_or_insert (t
);
7475 omp_private_member_vec
.safe_push (t
);
7477 omp_private_member_vec
.safe_push (n
);
7482 /* For all variables in the tree_list VARS, mark them as thread local. */
7485 finish_omp_threadprivate (tree vars
)
7489 /* Mark every variable in VARS to be assigned thread local storage. */
7490 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7492 tree v
= TREE_PURPOSE (t
);
7494 if (error_operand_p (v
))
7496 else if (!VAR_P (v
))
7497 error ("%<threadprivate%> %qD is not file, namespace "
7498 "or block scope variable", v
);
7499 /* If V had already been marked threadprivate, it doesn't matter
7500 whether it had been used prior to this point. */
7501 else if (TREE_USED (v
)
7502 && (DECL_LANG_SPECIFIC (v
) == NULL
7503 || !CP_DECL_THREADPRIVATE_P (v
)))
7504 error ("%qE declared %<threadprivate%> after first use", v
);
7505 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7506 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7507 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
7508 error ("%<threadprivate%> %qE has incomplete type", v
);
7509 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
7510 && CP_DECL_CONTEXT (v
) != current_class_type
)
7511 error ("%<threadprivate%> %qE directive not "
7512 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
7515 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
7516 if (DECL_LANG_SPECIFIC (v
) == NULL
)
7518 retrofit_lang_decl (v
);
7520 /* Make sure that DECL_DISCRIMINATOR_P continues to be true
7521 after the allocation of the lang_decl structure. */
7522 if (DECL_DISCRIMINATOR_P (v
))
7523 DECL_LANG_SPECIFIC (v
)->u
.base
.u2sel
= 1;
7526 if (! CP_DECL_THREAD_LOCAL_P (v
))
7528 CP_DECL_THREAD_LOCAL_P (v
) = true;
7529 set_decl_tls_model (v
, decl_default_tls_model (v
));
7530 /* If rtl has been already set for this var, call
7531 make_decl_rtl once again, so that encode_section_info
7532 has a chance to look at the new decl flags. */
7533 if (DECL_RTL_SET_P (v
))
7536 CP_DECL_THREADPRIVATE_P (v
) = 1;
7541 /* Build an OpenMP structured block. */
7544 begin_omp_structured_block (void)
7546 return do_pushlevel (sk_omp
);
7550 finish_omp_structured_block (tree block
)
7552 return do_poplevel (block
);
7555 /* Similarly, except force the retention of the BLOCK. */
7558 begin_omp_parallel (void)
7560 keep_next_level (true);
7561 return begin_omp_structured_block ();
7564 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
7568 finish_oacc_data (tree clauses
, tree block
)
7572 block
= finish_omp_structured_block (block
);
7574 stmt
= make_node (OACC_DATA
);
7575 TREE_TYPE (stmt
) = void_type_node
;
7576 OACC_DATA_CLAUSES (stmt
) = clauses
;
7577 OACC_DATA_BODY (stmt
) = block
;
7579 return add_stmt (stmt
);
7582 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
7586 finish_oacc_host_data (tree clauses
, tree block
)
7590 block
= finish_omp_structured_block (block
);
7592 stmt
= make_node (OACC_HOST_DATA
);
7593 TREE_TYPE (stmt
) = void_type_node
;
7594 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
7595 OACC_HOST_DATA_BODY (stmt
) = block
;
7597 return add_stmt (stmt
);
7600 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
7604 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
7606 body
= finish_omp_structured_block (body
);
7608 tree stmt
= make_node (code
);
7609 TREE_TYPE (stmt
) = void_type_node
;
7610 OMP_BODY (stmt
) = body
;
7611 OMP_CLAUSES (stmt
) = clauses
;
7613 return add_stmt (stmt
);
7617 finish_omp_parallel (tree clauses
, tree body
)
7621 body
= finish_omp_structured_block (body
);
7623 stmt
= make_node (OMP_PARALLEL
);
7624 TREE_TYPE (stmt
) = void_type_node
;
7625 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
7626 OMP_PARALLEL_BODY (stmt
) = body
;
7628 return add_stmt (stmt
);
7632 begin_omp_task (void)
7634 keep_next_level (true);
7635 return begin_omp_structured_block ();
7639 finish_omp_task (tree clauses
, tree body
)
7643 body
= finish_omp_structured_block (body
);
7645 stmt
= make_node (OMP_TASK
);
7646 TREE_TYPE (stmt
) = void_type_node
;
7647 OMP_TASK_CLAUSES (stmt
) = clauses
;
7648 OMP_TASK_BODY (stmt
) = body
;
7650 return add_stmt (stmt
);
7653 /* Helper function for finish_omp_for. Convert Ith random access iterator
7654 into integral iterator. Return FALSE if successful. */
7657 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
7658 tree declv
, tree orig_declv
, tree initv
,
7659 tree condv
, tree incrv
, tree
*body
,
7660 tree
*pre_body
, tree
&clauses
, tree
*lastp
,
7661 int collapse
, int ordered
)
7663 tree diff
, iter_init
, iter_incr
= NULL
, last
;
7664 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
7665 tree decl
= TREE_VEC_ELT (declv
, i
);
7666 tree init
= TREE_VEC_ELT (initv
, i
);
7667 tree cond
= TREE_VEC_ELT (condv
, i
);
7668 tree incr
= TREE_VEC_ELT (incrv
, i
);
7670 location_t elocus
= locus
;
7672 if (init
&& EXPR_HAS_LOCATION (init
))
7673 elocus
= EXPR_LOCATION (init
);
7675 cond
= cp_fully_fold (cond
);
7676 switch (TREE_CODE (cond
))
7683 if (TREE_OPERAND (cond
, 1) == iter
)
7684 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
7685 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
7686 if (TREE_OPERAND (cond
, 0) != iter
)
7687 cond
= error_mark_node
;
7690 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
7693 TREE_OPERAND (cond
, 1), ERROR_MARK
,
7694 NULL
, tf_warning_or_error
);
7695 if (error_operand_p (tem
))
7700 cond
= error_mark_node
;
7703 if (cond
== error_mark_node
)
7705 error_at (elocus
, "invalid controlling predicate");
7708 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
7709 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
7710 tf_warning_or_error
);
7711 diff
= cp_fully_fold (diff
);
7712 if (error_operand_p (diff
))
7714 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
7716 error_at (elocus
, "difference between %qE and %qD does not have integer type",
7717 TREE_OPERAND (cond
, 1), iter
);
7720 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
,
7721 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
7722 cond
, cp_walk_subtrees
))
7725 switch (TREE_CODE (incr
))
7727 case PREINCREMENT_EXPR
:
7728 case PREDECREMENT_EXPR
:
7729 case POSTINCREMENT_EXPR
:
7730 case POSTDECREMENT_EXPR
:
7731 if (TREE_OPERAND (incr
, 0) != iter
)
7733 incr
= error_mark_node
;
7736 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
7737 TREE_CODE (incr
), iter
,
7738 tf_warning_or_error
);
7739 if (error_operand_p (iter_incr
))
7741 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
7742 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
7743 incr
= integer_one_node
;
7745 incr
= integer_minus_one_node
;
7748 if (TREE_OPERAND (incr
, 0) != iter
)
7749 incr
= error_mark_node
;
7750 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
7751 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
7753 tree rhs
= TREE_OPERAND (incr
, 1);
7754 if (TREE_OPERAND (rhs
, 0) == iter
)
7756 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
7758 incr
= error_mark_node
;
7761 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7762 iter
, TREE_CODE (rhs
),
7763 TREE_OPERAND (rhs
, 1),
7764 tf_warning_or_error
);
7765 if (error_operand_p (iter_incr
))
7767 incr
= TREE_OPERAND (rhs
, 1);
7768 incr
= cp_convert (TREE_TYPE (diff
), incr
,
7769 tf_warning_or_error
);
7770 if (TREE_CODE (rhs
) == MINUS_EXPR
)
7772 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
7773 incr
= fold_simple (incr
);
7775 if (TREE_CODE (incr
) != INTEGER_CST
7776 && (TREE_CODE (incr
) != NOP_EXPR
7777 || (TREE_CODE (TREE_OPERAND (incr
, 0))
7782 else if (TREE_OPERAND (rhs
, 1) == iter
)
7784 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
7785 || TREE_CODE (rhs
) != PLUS_EXPR
)
7786 incr
= error_mark_node
;
7789 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
7791 TREE_OPERAND (rhs
, 0),
7794 tf_warning_or_error
);
7795 if (error_operand_p (iter_incr
))
7797 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7800 tf_warning_or_error
);
7801 if (error_operand_p (iter_incr
))
7803 incr
= TREE_OPERAND (rhs
, 0);
7808 incr
= error_mark_node
;
7811 incr
= error_mark_node
;
7814 incr
= error_mark_node
;
7818 if (incr
== error_mark_node
)
7820 error_at (elocus
, "invalid increment expression");
7824 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
7825 bool taskloop_iv_seen
= false;
7826 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7827 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
7828 && OMP_CLAUSE_DECL (c
) == iter
)
7830 if (code
== OMP_TASKLOOP
)
7832 taskloop_iv_seen
= true;
7833 OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c
) = 1;
7837 else if (code
== OMP_TASKLOOP
7838 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
7839 && OMP_CLAUSE_DECL (c
) == iter
)
7841 taskloop_iv_seen
= true;
7842 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
7845 decl
= create_temporary_var (TREE_TYPE (diff
));
7847 add_decl_expr (decl
);
7848 last
= create_temporary_var (TREE_TYPE (diff
));
7850 add_decl_expr (last
);
7851 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
7852 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7854 incr_var
= create_temporary_var (TREE_TYPE (diff
));
7855 pushdecl (incr_var
);
7856 add_decl_expr (incr_var
);
7858 gcc_assert (stmts_are_full_exprs_p ());
7859 tree diffvar
= NULL_TREE
;
7860 if (code
== OMP_TASKLOOP
)
7862 if (!taskloop_iv_seen
)
7864 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7865 OMP_CLAUSE_DECL (ivc
) = iter
;
7866 cxx_omp_finish_clause (ivc
, NULL
);
7867 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
7870 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7871 OMP_CLAUSE_DECL (lvc
) = last
;
7872 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
7874 diffvar
= create_temporary_var (TREE_TYPE (diff
));
7876 add_decl_expr (diffvar
);
7879 orig_pre_body
= *pre_body
;
7880 *pre_body
= push_stmt_list ();
7882 add_stmt (orig_pre_body
);
7884 finish_expr_stmt (build_x_modify_expr (elocus
,
7885 iter
, NOP_EXPR
, init
,
7886 tf_warning_or_error
));
7887 init
= build_int_cst (TREE_TYPE (diff
), 0);
7888 if (c
&& iter_incr
== NULL
7889 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7893 finish_expr_stmt (build_x_modify_expr (elocus
,
7895 incr
, tf_warning_or_error
));
7898 iter_incr
= build_x_modify_expr (elocus
,
7899 iter
, PLUS_EXPR
, incr
,
7900 tf_warning_or_error
);
7902 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
7904 finish_expr_stmt (build_x_modify_expr (elocus
,
7905 last
, NOP_EXPR
, init
,
7906 tf_warning_or_error
));
7909 finish_expr_stmt (build_x_modify_expr (elocus
,
7911 diff
, tf_warning_or_error
));
7914 *pre_body
= pop_stmt_list (*pre_body
);
7916 cond
= cp_build_binary_op (elocus
,
7917 TREE_CODE (cond
), decl
, diff
,
7918 tf_warning_or_error
);
7919 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
7920 elocus
, incr
, NULL_TREE
);
7923 *body
= push_stmt_list ();
7924 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
7925 iter_init
= build_x_modify_expr (elocus
,
7926 iter
, PLUS_EXPR
, iter_init
,
7927 tf_warning_or_error
);
7928 if (iter_init
!= error_mark_node
)
7929 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7930 finish_expr_stmt (iter_init
);
7931 finish_expr_stmt (build_x_modify_expr (elocus
,
7932 last
, NOP_EXPR
, decl
,
7933 tf_warning_or_error
));
7934 add_stmt (orig_body
);
7935 *body
= pop_stmt_list (*body
);
7939 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
7941 finish_expr_stmt (iter_incr
);
7945 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
7946 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
7947 iter_init
, iter_incr
);
7948 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
7949 iter_init
= build_x_modify_expr (elocus
,
7950 iter
, PLUS_EXPR
, iter_init
,
7951 tf_warning_or_error
);
7952 if (iter_init
!= error_mark_node
)
7953 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7954 finish_expr_stmt (iter_init
);
7956 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
7957 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
7960 TREE_VEC_ELT (declv
, i
) = decl
;
7961 TREE_VEC_ELT (initv
, i
) = init
;
7962 TREE_VEC_ELT (condv
, i
) = cond
;
7963 TREE_VEC_ELT (incrv
, i
) = incr
;
7969 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
7970 are directly for their associated operands in the statement. DECL
7971 and INIT are a combo; if DECL is NULL then INIT ought to be a
7972 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
7973 optional statements that need to go before the loop into its
7977 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
7978 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
7979 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
7981 tree omp_for
= NULL
, orig_incr
= NULL
;
7982 tree decl
= NULL
, init
, cond
, incr
;
7983 tree last
= NULL_TREE
;
7989 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
7990 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
7991 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
7992 if (TREE_VEC_LENGTH (declv
) > 1)
7996 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
7998 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
8001 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
8003 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
8004 if (collapse
!= TREE_VEC_LENGTH (declv
))
8005 ordered
= TREE_VEC_LENGTH (declv
);
8008 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8010 decl
= TREE_VEC_ELT (declv
, i
);
8011 init
= TREE_VEC_ELT (initv
, i
);
8012 cond
= TREE_VEC_ELT (condv
, i
);
8013 incr
= TREE_VEC_ELT (incrv
, i
);
8019 switch (TREE_CODE (init
))
8022 decl
= TREE_OPERAND (init
, 0);
8023 init
= TREE_OPERAND (init
, 1);
8026 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
8028 decl
= TREE_OPERAND (init
, 0);
8029 init
= TREE_OPERAND (init
, 2);
8039 "expected iteration declaration or initialization");
8044 if (init
&& EXPR_HAS_LOCATION (init
))
8045 elocus
= EXPR_LOCATION (init
);
8049 error_at (elocus
, "missing controlling predicate");
8055 error_at (elocus
, "missing increment expression");
8059 TREE_VEC_ELT (declv
, i
) = decl
;
8060 TREE_VEC_ELT (initv
, i
) = init
;
8067 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
8069 && !c_omp_check_loop_iv_exprs (locus
, declv
,
8070 TREE_VEC_ELT (declv
, i
), orig_init
,
8071 NULL_TREE
, cp_walk_subtrees
))
8077 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
8081 stmt
= make_node (code
);
8083 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8085 /* This is really just a place-holder. We'll be decomposing this
8086 again and going through the cp_build_modify_expr path below when
8087 we instantiate the thing. */
8088 TREE_VEC_ELT (initv
, i
)
8089 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
8090 TREE_VEC_ELT (initv
, i
));
8093 TREE_TYPE (stmt
) = void_type_node
;
8094 OMP_FOR_INIT (stmt
) = initv
;
8095 OMP_FOR_COND (stmt
) = condv
;
8096 OMP_FOR_INCR (stmt
) = incrv
;
8097 OMP_FOR_BODY (stmt
) = body
;
8098 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
8099 OMP_FOR_CLAUSES (stmt
) = clauses
;
8101 SET_EXPR_LOCATION (stmt
, locus
);
8102 return add_stmt (stmt
);
8106 orig_declv
= copy_node (declv
);
8108 if (processing_template_decl
)
8109 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
8111 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
8113 decl
= TREE_VEC_ELT (declv
, i
);
8114 init
= TREE_VEC_ELT (initv
, i
);
8115 cond
= TREE_VEC_ELT (condv
, i
);
8116 incr
= TREE_VEC_ELT (incrv
, i
);
8118 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8121 if (init
&& EXPR_HAS_LOCATION (init
))
8122 elocus
= EXPR_LOCATION (init
);
8126 error_at (elocus
, "expected iteration declaration or initialization");
8130 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
8133 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8134 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
8135 TREE_CODE (TREE_OPERAND (incr
, 1)),
8136 TREE_OPERAND (incr
, 2),
8137 tf_warning_or_error
);
8140 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
8142 if (code
== OMP_SIMD
)
8144 error_at (elocus
, "%<#pragma omp simd%> used with class "
8145 "iteration variable %qE", decl
);
8148 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
8149 initv
, condv
, incrv
, &body
,
8150 &pre_body
, clauses
, &last
,
8156 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
8157 && !TYPE_PTR_P (TREE_TYPE (decl
)))
8159 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
8163 if (!processing_template_decl
)
8165 init
= fold_build_cleanup_point_expr (TREE_TYPE (init
), init
);
8166 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
8167 tf_warning_or_error
);
8170 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
8172 && TREE_SIDE_EFFECTS (cond
)
8173 && COMPARISON_CLASS_P (cond
)
8174 && !processing_template_decl
)
8176 tree t
= TREE_OPERAND (cond
, 0);
8177 if (TREE_SIDE_EFFECTS (t
)
8179 && (TREE_CODE (t
) != NOP_EXPR
8180 || TREE_OPERAND (t
, 0) != decl
))
8181 TREE_OPERAND (cond
, 0)
8182 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8184 t
= TREE_OPERAND (cond
, 1);
8185 if (TREE_SIDE_EFFECTS (t
)
8187 && (TREE_CODE (t
) != NOP_EXPR
8188 || TREE_OPERAND (t
, 0) != decl
))
8189 TREE_OPERAND (cond
, 1)
8190 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8192 if (decl
== error_mark_node
|| init
== error_mark_node
)
8195 TREE_VEC_ELT (declv
, i
) = decl
;
8196 TREE_VEC_ELT (initv
, i
) = init
;
8197 TREE_VEC_ELT (condv
, i
) = cond
;
8198 TREE_VEC_ELT (incrv
, i
) = incr
;
8202 if (IS_EMPTY_STMT (pre_body
))
8205 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
8206 incrv
, body
, pre_body
);
8208 /* Check for iterators appearing in lb, b or incr expressions. */
8209 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
8210 omp_for
= NULL_TREE
;
8212 if (omp_for
== NULL
)
8219 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
8221 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
), 0);
8222 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
8224 if (TREE_CODE (incr
) != MODIFY_EXPR
)
8227 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
8228 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
8229 && !processing_template_decl
)
8231 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
8232 if (TREE_SIDE_EFFECTS (t
)
8234 && (TREE_CODE (t
) != NOP_EXPR
8235 || TREE_OPERAND (t
, 0) != decl
))
8236 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
8237 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8239 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8240 if (TREE_SIDE_EFFECTS (t
)
8242 && (TREE_CODE (t
) != NOP_EXPR
8243 || TREE_OPERAND (t
, 0) != decl
))
8244 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8245 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8249 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
8251 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8253 /* For simd loops with non-static data member iterators, we could have added
8254 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
8255 step at this point, fill it in. */
8256 if (code
== OMP_SIMD
&& !processing_template_decl
8257 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
8258 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
8259 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
8260 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
8262 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
8263 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
8264 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8266 switch (TREE_CODE (incr
))
8268 case PREINCREMENT_EXPR
:
8269 case POSTINCREMENT_EXPR
:
8270 /* c_omp_for_incr_canonicalize_ptr() should have been
8271 called to massage things appropriately. */
8272 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8273 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
8275 case PREDECREMENT_EXPR
:
8276 case POSTDECREMENT_EXPR
:
8277 /* c_omp_for_incr_canonicalize_ptr() should have been
8278 called to massage things appropriately. */
8279 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8280 OMP_CLAUSE_LINEAR_STEP (c
)
8281 = build_int_cst (TREE_TYPE (decl
), -1);
8284 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8285 incr
= TREE_OPERAND (incr
, 1);
8286 switch (TREE_CODE (incr
))
8289 if (TREE_OPERAND (incr
, 1) == decl
)
8290 step
= TREE_OPERAND (incr
, 0);
8292 step
= TREE_OPERAND (incr
, 1);
8295 case POINTER_PLUS_EXPR
:
8296 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8297 step
= TREE_OPERAND (incr
, 1);
8302 stept
= TREE_TYPE (decl
);
8303 if (POINTER_TYPE_P (stept
))
8305 step
= fold_convert (stept
, step
);
8306 if (TREE_CODE (incr
) == MINUS_EXPR
)
8307 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
8308 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
8319 finish_omp_atomic (enum tree_code code
, enum tree_code opcode
, tree lhs
,
8320 tree rhs
, tree v
, tree lhs1
, tree rhs1
, bool seq_cst
)
8335 dependent_p
= false;
8338 /* Even in a template, we can detect invalid uses of the atomic
8339 pragma if neither LHS nor RHS is type-dependent. */
8340 if (processing_template_decl
)
8342 dependent_p
= (type_dependent_expression_p (lhs
)
8343 || (rhs
&& type_dependent_expression_p (rhs
))
8344 || (v
&& type_dependent_expression_p (v
))
8345 || (lhs1
&& type_dependent_expression_p (lhs1
))
8346 || (rhs1
&& type_dependent_expression_p (rhs1
)));
8349 lhs
= build_non_dependent_expr (lhs
);
8351 rhs
= build_non_dependent_expr (rhs
);
8353 v
= build_non_dependent_expr (v
);
8355 lhs1
= build_non_dependent_expr (lhs1
);
8357 rhs1
= build_non_dependent_expr (rhs1
);
8362 bool swapped
= false;
8363 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
8365 std::swap (rhs
, rhs1
);
8366 swapped
= !commutative_tree_code (opcode
);
8368 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
8370 if (code
== OMP_ATOMIC
)
8371 error ("%<#pragma omp atomic update%> uses two different "
8372 "expressions for memory");
8374 error ("%<#pragma omp atomic capture%> uses two different "
8375 "expressions for memory");
8378 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
8380 if (code
== OMP_ATOMIC
)
8381 error ("%<#pragma omp atomic update%> uses two different "
8382 "expressions for memory");
8384 error ("%<#pragma omp atomic capture%> uses two different "
8385 "expressions for memory");
8388 stmt
= c_finish_omp_atomic (input_location
, code
, opcode
, lhs
, rhs
,
8389 v
, lhs1
, rhs1
, swapped
, seq_cst
,
8390 processing_template_decl
!= 0);
8391 if (stmt
== error_mark_node
)
8394 if (processing_template_decl
)
8396 if (code
== OMP_ATOMIC_READ
)
8398 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs
),
8399 OMP_ATOMIC_READ
, orig_lhs
);
8400 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8401 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8405 if (opcode
== NOP_EXPR
)
8406 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
8408 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
8410 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
8411 COMPOUND_EXPR
, orig_rhs1
, stmt
);
8412 if (code
!= OMP_ATOMIC
)
8414 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs1
),
8415 code
, orig_lhs1
, stmt
);
8416 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8417 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8420 stmt
= build2 (OMP_ATOMIC
, void_type_node
, integer_zero_node
, stmt
);
8421 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8423 finish_expr_stmt (stmt
);
8427 finish_omp_barrier (void)
8429 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
8430 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8431 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8432 release_tree_vector (vec
);
8433 finish_expr_stmt (stmt
);
8437 finish_omp_flush (void)
8439 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
8440 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8441 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8442 release_tree_vector (vec
);
8443 finish_expr_stmt (stmt
);
8447 finish_omp_taskwait (void)
8449 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
8450 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8451 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8452 release_tree_vector (vec
);
8453 finish_expr_stmt (stmt
);
8457 finish_omp_taskyield (void)
8459 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
8460 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8461 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8462 release_tree_vector (vec
);
8463 finish_expr_stmt (stmt
);
8467 finish_omp_cancel (tree clauses
)
8469 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
8471 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8473 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
8475 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8477 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8481 error ("%<#pragma omp cancel%> must specify one of "
8482 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8485 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8486 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
8487 if (ifc
!= NULL_TREE
)
8489 tree type
= TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc
));
8490 ifc
= fold_build2_loc (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
8491 boolean_type_node
, OMP_CLAUSE_IF_EXPR (ifc
),
8492 build_zero_cst (type
));
8495 ifc
= boolean_true_node
;
8496 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
8497 vec
->quick_push (ifc
);
8498 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8499 release_tree_vector (vec
);
8500 finish_expr_stmt (stmt
);
8504 finish_omp_cancellation_point (tree clauses
)
8506 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
8508 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8510 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
8512 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8514 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8518 error ("%<#pragma omp cancellation point%> must specify one of "
8519 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8522 vec
<tree
, va_gc
> *vec
8523 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
8524 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8525 release_tree_vector (vec
);
8526 finish_expr_stmt (stmt
);
8529 /* Begin a __transaction_atomic or __transaction_relaxed statement.
8530 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
8531 should create an extra compound stmt. */
8534 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
8539 *pcompound
= begin_compound_stmt (0);
8541 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
8543 /* Only add the statement to the function if support enabled. */
8547 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
8548 ? G_("%<__transaction_relaxed%> without "
8549 "transactional memory support enabled")
8550 : G_("%<__transaction_atomic%> without "
8551 "transactional memory support enabled")));
8553 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
8554 TREE_SIDE_EFFECTS (r
) = 1;
8558 /* End a __transaction_atomic or __transaction_relaxed statement.
8559 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
8560 and we should end the compound. If NOEX is non-NULL, we wrap the body in
8561 a MUST_NOT_THROW_EXPR with NOEX as condition. */
8564 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
8566 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
8567 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
8568 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
8569 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
8571 /* noexcept specifications are not allowed for function transactions. */
8572 gcc_assert (!(noex
&& compound_stmt
));
8575 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
8577 protected_set_expr_location
8578 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
8579 TREE_SIDE_EFFECTS (body
) = 1;
8580 TRANSACTION_EXPR_BODY (stmt
) = body
;
8584 finish_compound_stmt (compound_stmt
);
8587 /* Build a __transaction_atomic or __transaction_relaxed expression. If
8588 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
8592 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
8597 expr
= build_must_not_throw_expr (expr
, noex
);
8598 protected_set_expr_location (expr
, loc
);
8599 TREE_SIDE_EFFECTS (expr
) = 1;
8601 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
8602 if (flags
& TM_STMT_ATTR_RELAXED
)
8603 TRANSACTION_EXPR_RELAXED (ret
) = 1;
8604 TREE_SIDE_EFFECTS (ret
) = 1;
8605 SET_EXPR_LOCATION (ret
, loc
);
8610 init_cp_semantics (void)
8614 /* Build a STATIC_ASSERT for a static assertion with the condition
8615 CONDITION and the message text MESSAGE. LOCATION is the location
8616 of the static assertion in the source code. When MEMBER_P, this
8617 static assertion is a member of a class. */
8619 finish_static_assert (tree condition
, tree message
, location_t location
,
8622 tsubst_flags_t complain
= tf_warning_or_error
;
8624 if (message
== NULL_TREE
8625 || message
== error_mark_node
8626 || condition
== NULL_TREE
8627 || condition
== error_mark_node
)
8630 if (check_for_bare_parameter_packs (condition
))
8631 condition
= error_mark_node
;
8633 if (type_dependent_expression_p (condition
)
8634 || value_dependent_expression_p (condition
))
8636 /* We're in a template; build a STATIC_ASSERT and put it in
8640 assertion
= make_node (STATIC_ASSERT
);
8641 STATIC_ASSERT_CONDITION (assertion
) = condition
;
8642 STATIC_ASSERT_MESSAGE (assertion
) = message
;
8643 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
8646 maybe_add_class_template_decl_list (current_class_type
,
8650 add_stmt (assertion
);
8655 /* Fold the expression and convert it to a boolean value. */
8656 condition
= perform_implicit_conversion_flags (boolean_type_node
, condition
,
8657 complain
, LOOKUP_NORMAL
);
8658 condition
= fold_non_dependent_expr (condition
);
8660 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
8661 /* Do nothing; the condition is satisfied. */
8665 location_t saved_loc
= input_location
;
8667 input_location
= location
;
8668 if (TREE_CODE (condition
) == INTEGER_CST
8669 && integer_zerop (condition
))
8671 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
8672 (TREE_TYPE (TREE_TYPE (message
))));
8673 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
8674 /* Report the error. */
8676 error ("static assertion failed");
8678 error ("static assertion failed: %s",
8679 TREE_STRING_POINTER (message
));
8681 else if (condition
&& condition
!= error_mark_node
)
8683 error ("non-constant condition for static assertion");
8684 if (require_rvalue_constant_expression (condition
))
8685 cxx_constant_value (condition
);
8687 input_location
= saved_loc
;
8691 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
8692 suitable for use as a type-specifier.
8694 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
8695 id-expression or a class member access, FALSE when it was parsed as
8696 a full expression. */
8699 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
8700 tsubst_flags_t complain
)
8702 tree type
= NULL_TREE
;
8704 if (!expr
|| error_operand_p (expr
))
8705 return error_mark_node
;
8708 || TREE_CODE (expr
) == TYPE_DECL
8709 || (TREE_CODE (expr
) == BIT_NOT_EXPR
8710 && TYPE_P (TREE_OPERAND (expr
, 0))))
8712 if (complain
& tf_error
)
8713 error ("argument to decltype must be an expression");
8714 return error_mark_node
;
8717 /* Depending on the resolution of DR 1172, we may later need to distinguish
8718 instantiation-dependent but not type-dependent expressions so that, say,
8719 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
8720 if (instantiation_dependent_uneval_expression_p (expr
))
8722 type
= cxx_make_type (DECLTYPE_TYPE
);
8723 DECLTYPE_TYPE_EXPR (type
) = expr
;
8724 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
8725 = id_expression_or_member_access_p
;
8726 SET_TYPE_STRUCTURAL_EQUALITY (type
);
8731 /* The type denoted by decltype(e) is defined as follows: */
8733 expr
= resolve_nondeduced_context (expr
, complain
);
8735 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
8736 return error_mark_node
;
8738 if (type_unknown_p (expr
))
8740 if (complain
& tf_error
)
8741 error ("decltype cannot resolve address of overloaded function");
8742 return error_mark_node
;
8745 /* To get the size of a static data member declared as an array of
8746 unknown bound, we need to instantiate it. */
8748 && VAR_HAD_UNKNOWN_BOUND (expr
)
8749 && DECL_TEMPLATE_INSTANTIATION (expr
))
8750 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
8752 if (id_expression_or_member_access_p
)
8754 /* If e is an id-expression or a class member access (5.2.5
8755 [expr.ref]), decltype(e) is defined as the type of the entity
8756 named by e. If there is no such entity, or e names a set of
8757 overloaded functions, the program is ill-formed. */
8758 if (identifier_p (expr
))
8759 expr
= lookup_name (expr
);
8761 if (INDIRECT_REF_P (expr
))
8762 /* This can happen when the expression is, e.g., "a.b". Just
8763 look at the underlying operand. */
8764 expr
= TREE_OPERAND (expr
, 0);
8766 if (TREE_CODE (expr
) == OFFSET_REF
8767 || TREE_CODE (expr
) == MEMBER_REF
8768 || TREE_CODE (expr
) == SCOPE_REF
)
8769 /* We're only interested in the field itself. If it is a
8770 BASELINK, we will need to see through it in the next
8772 expr
= TREE_OPERAND (expr
, 1);
8774 if (BASELINK_P (expr
))
8775 /* See through BASELINK nodes to the underlying function. */
8776 expr
= BASELINK_FUNCTIONS (expr
);
8778 /* decltype of a decomposition name drops references in the tuple case
8779 (unlike decltype of a normal variable) and keeps cv-qualifiers from
8780 the containing object in the other cases (unlike decltype of a member
8781 access expression). */
8782 if (DECL_DECOMPOSITION_P (expr
))
8784 if (DECL_HAS_VALUE_EXPR_P (expr
))
8785 /* Expr is an array or struct subobject proxy, handle
8786 bit-fields properly. */
8787 return unlowered_expr_type (expr
);
8789 /* Expr is a reference variable for the tuple case. */
8790 return lookup_decomp_type (expr
);
8793 switch (TREE_CODE (expr
))
8796 if (DECL_BIT_FIELD_TYPE (expr
))
8798 type
= DECL_BIT_FIELD_TYPE (expr
);
8801 /* Fall through for fields that aren't bitfields. */
8809 case TEMPLATE_PARM_INDEX
:
8810 expr
= mark_type_use (expr
);
8811 type
= TREE_TYPE (expr
);
8815 type
= error_mark_node
;
8820 mark_type_use (expr
);
8821 type
= is_bitfield_expr_with_lowered_type (expr
);
8823 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
8831 /* We can get here when the id-expression refers to an
8832 enumerator or non-type template parameter. */
8833 type
= TREE_TYPE (expr
);
8837 /* Handle instantiated template non-type arguments. */
8838 type
= TREE_TYPE (expr
);
8844 /* Within a lambda-expression:
8846 Every occurrence of decltype((x)) where x is a possibly
8847 parenthesized id-expression that names an entity of
8848 automatic storage duration is treated as if x were
8849 transformed into an access to a corresponding data member
8850 of the closure type that would have been declared if x
8851 were a use of the denoted entity. */
8852 if (outer_automatic_var_p (expr
)
8853 && current_function_decl
8854 && LAMBDA_FUNCTION_P (current_function_decl
))
8855 type
= capture_decltype (expr
);
8856 else if (error_operand_p (expr
))
8857 type
= error_mark_node
;
8858 else if (expr
== current_class_ptr
)
8859 /* If the expression is just "this", we want the
8860 cv-unqualified pointer for the "this" type. */
8861 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
8864 /* Otherwise, where T is the type of e, if e is an lvalue,
8865 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
8866 cp_lvalue_kind clk
= lvalue_kind (expr
);
8867 type
= unlowered_expr_type (expr
);
8868 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
8870 /* For vector types, pick a non-opaque variant. */
8871 if (VECTOR_TYPE_P (type
))
8872 type
= strip_typedefs (type
);
8874 if (clk
!= clk_none
&& !(clk
& clk_class
))
8875 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
8882 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
8883 __has_nothrow_copy, depending on assign_p. Returns true iff all
8884 the copy {ctor,assign} fns are nothrow. */
8887 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
8889 tree fns
= NULL_TREE
;
8891 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
8892 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
8895 bool saw_copy
= false;
8896 for (ovl_iterator
iter (fns
); iter
; ++iter
)
8900 if (copy_fn_p (fn
) > 0)
8903 maybe_instantiate_noexcept (fn
);
8904 if (!TYPE_NOTHROW_P (TREE_TYPE (fn
)))
8912 /* Actually evaluates the trait. */
8915 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
8917 enum tree_code type_code1
;
8920 type_code1
= TREE_CODE (type1
);
8924 case CPTK_HAS_NOTHROW_ASSIGN
:
8925 type1
= strip_array_types (type1
);
8926 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
8927 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
8928 || (CLASS_TYPE_P (type1
)
8929 && classtype_has_nothrow_assign_or_copy_p (type1
,
8932 case CPTK_HAS_TRIVIAL_ASSIGN
:
8933 /* ??? The standard seems to be missing the "or array of such a class
8934 type" wording for this trait. */
8935 type1
= strip_array_types (type1
);
8936 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
8937 && (trivial_type_p (type1
)
8938 || (CLASS_TYPE_P (type1
)
8939 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
8941 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
8942 type1
= strip_array_types (type1
);
8943 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
8944 || (CLASS_TYPE_P (type1
)
8945 && (t
= locate_ctor (type1
))
8946 && (maybe_instantiate_noexcept (t
),
8947 TYPE_NOTHROW_P (TREE_TYPE (t
)))));
8949 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
8950 type1
= strip_array_types (type1
);
8951 return (trivial_type_p (type1
)
8952 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
8954 case CPTK_HAS_NOTHROW_COPY
:
8955 type1
= strip_array_types (type1
);
8956 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
8957 || (CLASS_TYPE_P (type1
)
8958 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
8960 case CPTK_HAS_TRIVIAL_COPY
:
8961 /* ??? The standard seems to be missing the "or array of such a class
8962 type" wording for this trait. */
8963 type1
= strip_array_types (type1
);
8964 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
8965 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
8967 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
8968 type1
= strip_array_types (type1
);
8969 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
8970 || (CLASS_TYPE_P (type1
)
8971 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
8973 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
8974 return type_has_virtual_destructor (type1
);
8976 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
8977 return type_has_unique_obj_representations (type1
);
8979 case CPTK_IS_ABSTRACT
:
8980 return ABSTRACT_CLASS_TYPE_P (type1
);
8982 case CPTK_IS_AGGREGATE
:
8983 return CP_AGGREGATE_TYPE_P (type1
);
8985 case CPTK_IS_BASE_OF
:
8986 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
8987 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
8988 || DERIVED_FROM_P (type1
, type2
)));
8991 return NON_UNION_CLASS_TYPE_P (type1
);
8994 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
8997 return type_code1
== ENUMERAL_TYPE
;
9000 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
9002 case CPTK_IS_LITERAL_TYPE
:
9003 return literal_type_p (type1
);
9006 return pod_type_p (type1
);
9008 case CPTK_IS_POLYMORPHIC
:
9009 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
9011 case CPTK_IS_SAME_AS
:
9012 return same_type_p (type1
, type2
);
9014 case CPTK_IS_STD_LAYOUT
:
9015 return std_layout_type_p (type1
);
9017 case CPTK_IS_TRIVIAL
:
9018 return trivial_type_p (type1
);
9020 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9021 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
9023 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9024 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
9026 case CPTK_IS_TRIVIALLY_COPYABLE
:
9027 return trivially_copyable_p (type1
);
9030 return type_code1
== UNION_TYPE
;
9032 case CPTK_IS_ASSIGNABLE
:
9033 return is_xible (MODIFY_EXPR
, type1
, type2
);
9035 case CPTK_IS_CONSTRUCTIBLE
:
9036 return is_xible (INIT_EXPR
, type1
, type2
);
9044 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
9045 void, or a complete type, returns true, otherwise false. */
9048 check_trait_type (tree type
)
9050 if (type
== NULL_TREE
)
9053 if (TREE_CODE (type
) == TREE_LIST
)
9054 return (check_trait_type (TREE_VALUE (type
))
9055 && check_trait_type (TREE_CHAIN (type
)));
9057 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
9058 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
9061 if (VOID_TYPE_P (type
))
9064 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
9067 /* Process a trait expression. */
9070 finish_trait_expr (cp_trait_kind kind
, tree type1
, tree type2
)
9072 if (type1
== error_mark_node
9073 || type2
== error_mark_node
)
9074 return error_mark_node
;
9076 if (processing_template_decl
)
9078 tree trait_expr
= make_node (TRAIT_EXPR
);
9079 TREE_TYPE (trait_expr
) = boolean_type_node
;
9080 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
9081 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
9082 TRAIT_EXPR_KIND (trait_expr
) = kind
;
9088 case CPTK_HAS_NOTHROW_ASSIGN
:
9089 case CPTK_HAS_TRIVIAL_ASSIGN
:
9090 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9091 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9092 case CPTK_HAS_NOTHROW_COPY
:
9093 case CPTK_HAS_TRIVIAL_COPY
:
9094 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9095 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
9096 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9097 case CPTK_IS_ABSTRACT
:
9098 case CPTK_IS_AGGREGATE
:
9101 case CPTK_IS_LITERAL_TYPE
:
9103 case CPTK_IS_POLYMORPHIC
:
9104 case CPTK_IS_STD_LAYOUT
:
9105 case CPTK_IS_TRIVIAL
:
9106 case CPTK_IS_TRIVIALLY_COPYABLE
:
9107 if (!check_trait_type (type1
))
9108 return error_mark_node
;
9111 case CPTK_IS_ASSIGNABLE
:
9112 case CPTK_IS_CONSTRUCTIBLE
:
9115 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9116 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9117 if (!check_trait_type (type1
)
9118 || !check_trait_type (type2
))
9119 return error_mark_node
;
9122 case CPTK_IS_BASE_OF
:
9123 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9124 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9125 && !complete_type_or_else (type2
, NULL_TREE
))
9126 /* We already issued an error. */
9127 return error_mark_node
;
9133 case CPTK_IS_SAME_AS
:
9140 return (trait_expr_value (kind
, type1
, type2
)
9141 ? boolean_true_node
: boolean_false_node
);
9144 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
9145 which is ignored for C++. */
9148 set_float_const_decimal64 (void)
9153 clear_float_const_decimal64 (void)
9158 float_const_decimal64_p (void)
9164 /* Return true if T designates the implied `this' parameter. */
9167 is_this_parameter (tree t
)
9169 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
9171 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
)
9172 || (cp_binding_oracle
&& TREE_CODE (t
) == VAR_DECL
));
9176 /* Insert the deduced return type for an auto function. */
9179 apply_deduced_return_type (tree fco
, tree return_type
)
9183 if (return_type
== error_mark_node
)
9186 if (DECL_CONV_FN_P (fco
))
9187 DECL_NAME (fco
) = make_conv_op_name (return_type
);
9189 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
9191 result
= DECL_RESULT (fco
);
9192 if (result
== NULL_TREE
)
9194 if (TREE_TYPE (result
) == return_type
)
9197 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
9198 && !complete_type_or_else (return_type
, NULL_TREE
))
9201 /* We already have a DECL_RESULT from start_preparsed_function.
9202 Now we need to redo the work it and allocate_struct_function
9203 did to reflect the new type. */
9204 gcc_assert (current_function_decl
== fco
);
9205 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
9206 TYPE_MAIN_VARIANT (return_type
));
9207 DECL_ARTIFICIAL (result
) = 1;
9208 DECL_IGNORED_P (result
) = 1;
9209 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
9212 DECL_RESULT (fco
) = result
;
9214 if (!processing_template_decl
)
9216 bool aggr
= aggregate_value_p (result
, fco
);
9217 #ifdef PCC_STATIC_STRUCT_RETURN
9218 cfun
->returns_pcc_struct
= aggr
;
9220 cfun
->returns_struct
= aggr
;
9225 /* DECL is a local variable or parameter from the surrounding scope of a
9226 lambda-expression. Returns the decltype for a use of the capture field
9227 for DECL even if it hasn't been captured yet. */
9230 capture_decltype (tree decl
)
9232 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
9233 /* FIXME do lookup instead of list walk? */
9234 tree cap
= value_member (decl
, LAMBDA_EXPR_CAPTURE_LIST (lam
));
9238 type
= TREE_TYPE (TREE_PURPOSE (cap
));
9240 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
9243 error ("%qD is not captured", decl
);
9244 return error_mark_node
;
9247 type
= TREE_TYPE (decl
);
9248 if (TREE_CODE (type
) == REFERENCE_TYPE
9249 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
9250 type
= TREE_TYPE (type
);
9253 case CPLD_REFERENCE
:
9254 type
= TREE_TYPE (decl
);
9255 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9256 type
= build_reference_type (TREE_TYPE (decl
));
9263 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9265 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
9266 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
9268 type
= build_reference_type (type
);
9273 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
9274 this is a right unary fold. Otherwise it is a left unary fold. */
9277 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
9279 // Build a pack expansion (assuming expr has pack type).
9280 if (!uses_parameter_packs (expr
))
9282 error_at (location_of (expr
), "operand of fold expression has no "
9283 "unexpanded parameter packs");
9284 return error_mark_node
;
9286 tree pack
= make_pack_expansion (expr
);
9288 // Build the fold expression.
9289 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9290 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
);
9291 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9296 finish_left_unary_fold_expr (tree expr
, int op
)
9298 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
9302 finish_right_unary_fold_expr (tree expr
, int op
)
9304 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
9307 /* Build a binary fold expression over EXPR1 and EXPR2. The
9308 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
9309 has an unexpanded parameter pack). */
9312 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
9314 pack
= make_pack_expansion (pack
);
9315 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9316 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
, init
);
9317 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9322 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
9324 // Determine which expr has an unexpanded parameter pack and
9325 // set the pack and initial term.
9326 bool pack1
= uses_parameter_packs (expr1
);
9327 bool pack2
= uses_parameter_packs (expr2
);
9328 if (pack1
&& !pack2
)
9329 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
9330 else if (pack2
&& !pack1
)
9331 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
9335 error ("both arguments in binary fold have unexpanded parameter packs");
9337 error ("no unexpanded parameter packs in binary fold");
9339 return error_mark_node
;
9342 /* Finish __builtin_launder (arg). */
9345 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
9347 tree orig_arg
= arg
;
9348 if (!type_dependent_expression_p (arg
))
9349 arg
= decay_conversion (arg
, complain
);
9350 if (error_operand_p (arg
))
9351 return error_mark_node
;
9352 if (!type_dependent_expression_p (arg
)
9353 && TREE_CODE (TREE_TYPE (arg
)) != POINTER_TYPE
)
9355 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
9356 return error_mark_node
;
9358 if (processing_template_decl
)
9360 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
9361 TREE_TYPE (arg
), 1, arg
);
9364 #include "gt-cp-semantics.h"