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-2016 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 "gomp-constants.h"
45 /* There routines provide a modular interface to perform many parsing
46 operations. They may therefore be used during actual parsing, or
47 during template instantiation, which may be regarded as a
48 degenerate form of parsing. */
50 static tree
maybe_convert_cond (tree
);
51 static tree
finalize_nrv_r (tree
*, int *, void *);
52 static tree
capture_decltype (tree
);
54 /* Used for OpenMP non-static data member privatization. */
56 static hash_map
<tree
, tree
> *omp_private_member_map
;
57 static vec
<tree
> omp_private_member_vec
;
58 static bool omp_private_member_ignore_next
;
61 /* Deferred Access Checking Overview
62 ---------------------------------
64 Most C++ expressions and declarations require access checking
65 to be performed during parsing. However, in several cases,
66 this has to be treated differently.
68 For member declarations, access checking has to be deferred
69 until more information about the declaration is known. For
81 When we are parsing the function return type `A::X', we don't
82 really know if this is allowed until we parse the function name.
84 Furthermore, some contexts require that access checking is
85 never performed at all. These include class heads, and template
88 Typical use of access checking functions is described here:
90 1. When we enter a context that requires certain access checking
91 mode, the function `push_deferring_access_checks' is called with
92 DEFERRING argument specifying the desired mode. Access checking
93 may be performed immediately (dk_no_deferred), deferred
94 (dk_deferred), or not performed (dk_no_check).
96 2. When a declaration such as a type, or a variable, is encountered,
97 the function `perform_or_defer_access_check' is called. It
98 maintains a vector of all deferred checks.
100 3. The global `current_class_type' or `current_function_decl' is then
101 setup by the parser. `enforce_access' relies on these information
104 4. Upon exiting the context mentioned in step 1,
105 `perform_deferred_access_checks' is called to check all declaration
106 stored in the vector. `pop_deferring_access_checks' is then
107 called to restore the previous access checking mode.
109 In case of parsing error, we simply call `pop_deferring_access_checks'
110 without `perform_deferred_access_checks'. */
112 struct GTY(()) deferred_access
{
113 /* A vector representing name-lookups for which we have deferred
114 checking access controls. We cannot check the accessibility of
115 names used in a decl-specifier-seq until we know what is being
116 declared because code like:
123 A::B* A::f() { return 0; }
125 is valid, even though `A::B' is not generally accessible. */
126 vec
<deferred_access_check
, va_gc
> * GTY(()) deferred_access_checks
;
128 /* The current mode of access checks. */
129 enum deferring_kind deferring_access_checks_kind
;
133 /* Data for deferred access checking. */
134 static GTY(()) vec
<deferred_access
, va_gc
> *deferred_access_stack
;
135 static GTY(()) unsigned deferred_access_no_check
;
137 /* Save the current deferred access states and start deferred
138 access checking iff DEFER_P is true. */
141 push_deferring_access_checks (deferring_kind deferring
)
143 /* For context like template instantiation, access checking
144 disabling applies to all nested context. */
145 if (deferred_access_no_check
|| deferring
== dk_no_check
)
146 deferred_access_no_check
++;
149 deferred_access e
= {NULL
, deferring
};
150 vec_safe_push (deferred_access_stack
, e
);
154 /* Save the current deferred access states and start deferred access
155 checking, continuing the set of deferred checks in CHECKS. */
158 reopen_deferring_access_checks (vec
<deferred_access_check
, va_gc
> * checks
)
160 push_deferring_access_checks (dk_deferred
);
161 if (!deferred_access_no_check
)
162 deferred_access_stack
->last().deferred_access_checks
= checks
;
165 /* Resume deferring access checks again after we stopped doing
169 resume_deferring_access_checks (void)
171 if (!deferred_access_no_check
)
172 deferred_access_stack
->last().deferring_access_checks_kind
= dk_deferred
;
175 /* Stop deferring access checks. */
178 stop_deferring_access_checks (void)
180 if (!deferred_access_no_check
)
181 deferred_access_stack
->last().deferring_access_checks_kind
= dk_no_deferred
;
184 /* Discard the current deferred access checks and restore the
188 pop_deferring_access_checks (void)
190 if (deferred_access_no_check
)
191 deferred_access_no_check
--;
193 deferred_access_stack
->pop ();
196 /* Returns a TREE_LIST representing the deferred checks.
197 The TREE_PURPOSE of each node is the type through which the
198 access occurred; the TREE_VALUE is the declaration named.
201 vec
<deferred_access_check
, va_gc
> *
202 get_deferred_access_checks (void)
204 if (deferred_access_no_check
)
207 return (deferred_access_stack
->last().deferred_access_checks
);
210 /* Take current deferred checks and combine with the
211 previous states if we also defer checks previously.
212 Otherwise perform checks now. */
215 pop_to_parent_deferring_access_checks (void)
217 if (deferred_access_no_check
)
218 deferred_access_no_check
--;
221 vec
<deferred_access_check
, va_gc
> *checks
;
222 deferred_access
*ptr
;
224 checks
= (deferred_access_stack
->last ().deferred_access_checks
);
226 deferred_access_stack
->pop ();
227 ptr
= &deferred_access_stack
->last ();
228 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
231 perform_access_checks (checks
, tf_warning_or_error
);
235 /* Merge with parent. */
237 deferred_access_check
*chk
, *probe
;
239 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
241 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, j
, probe
)
243 if (probe
->binfo
== chk
->binfo
&&
244 probe
->decl
== chk
->decl
&&
245 probe
->diag_decl
== chk
->diag_decl
)
248 /* Insert into parent's checks. */
249 vec_safe_push (ptr
->deferred_access_checks
, *chk
);
256 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
257 is the BINFO indicating the qualifying scope used to access the
258 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
259 or we aren't in SFINAE context or all the checks succeed return TRUE,
263 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
264 tsubst_flags_t complain
)
267 deferred_access_check
*chk
;
268 location_t loc
= input_location
;
274 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
276 input_location
= chk
->loc
;
277 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
280 input_location
= loc
;
281 return (complain
& tf_error
) ? true : ok
;
284 /* Perform the deferred access checks.
286 After performing the checks, we still have to keep the list
287 `deferred_access_stack->deferred_access_checks' since we may want
288 to check access for them again later in a different context.
295 A::X A::a, x; // No error for `A::a', error for `x'
297 We have to perform deferred access of `A::X', first with `A::a',
298 next with `x'. Return value like perform_access_checks above. */
301 perform_deferred_access_checks (tsubst_flags_t complain
)
303 return perform_access_checks (get_deferred_access_checks (), complain
);
306 /* Defer checking the accessibility of DECL, when looked up in
307 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
308 Return value like perform_access_checks above. */
311 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
312 tsubst_flags_t complain
)
315 deferred_access
*ptr
;
316 deferred_access_check
*chk
;
319 /* Exit if we are in a context that no access checking is performed.
321 if (deferred_access_no_check
)
324 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
326 ptr
= &deferred_access_stack
->last ();
328 /* If we are not supposed to defer access checks, just check now. */
329 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
331 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
);
332 return (complain
& tf_error
) ? true : ok
;
335 /* See if we are already going to perform this check. */
336 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
338 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
339 chk
->diag_decl
== diag_decl
)
344 /* If not, record the check. */
345 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
346 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
351 /* Returns nonzero if the current statement is a full expression,
352 i.e. temporaries created during that statement should be destroyed
353 at the end of the statement. */
356 stmts_are_full_exprs_p (void)
358 return current_stmt_tree ()->stmts_are_full_exprs_p
;
361 /* T is a statement. Add it to the statement-tree. This is the C++
362 version. The C/ObjC frontends have a slightly different version of
368 enum tree_code code
= TREE_CODE (t
);
370 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
372 if (!EXPR_HAS_LOCATION (t
))
373 SET_EXPR_LOCATION (t
, input_location
);
375 /* When we expand a statement-tree, we must know whether or not the
376 statements are full-expressions. We record that fact here. */
377 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
380 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
381 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
383 /* Add T to the statement-tree. Non-side-effect statements need to be
384 recorded during statement expressions. */
385 gcc_checking_assert (!stmt_list_stack
->is_empty ());
386 append_to_statement_list_force (t
, &cur_stmt_list
);
391 /* Returns the stmt_tree to which statements are currently being added. */
394 current_stmt_tree (void)
397 ? &cfun
->language
->base
.x_stmt_tree
398 : &scope_chain
->x_stmt_tree
);
401 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
404 maybe_cleanup_point_expr (tree expr
)
406 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
407 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
411 /* Like maybe_cleanup_point_expr except have the type of the new expression be
412 void so we don't need to create a temporary variable to hold the inner
413 expression. The reason why we do this is because the original type might be
414 an aggregate and we cannot create a temporary variable for that type. */
417 maybe_cleanup_point_expr_void (tree expr
)
419 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
420 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
426 /* Create a declaration statement for the declaration given by the DECL. */
429 add_decl_expr (tree decl
)
431 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
432 if (DECL_INITIAL (decl
)
433 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
434 r
= maybe_cleanup_point_expr_void (r
);
438 /* Finish a scope. */
441 do_poplevel (tree stmt_list
)
445 if (stmts_are_full_exprs_p ())
446 block
= poplevel (kept_level_p (), 1, 0);
448 stmt_list
= pop_stmt_list (stmt_list
);
450 if (!processing_template_decl
)
452 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
453 /* ??? See c_end_compound_stmt re statement expressions. */
459 /* Begin a new scope. */
462 do_pushlevel (scope_kind sk
)
464 tree ret
= push_stmt_list ();
465 if (stmts_are_full_exprs_p ())
466 begin_scope (sk
, NULL
);
470 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
471 when the current scope is exited. EH_ONLY is true when this is not
472 meant to apply to normal control flow transfer. */
475 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
477 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
478 CLEANUP_EH_ONLY (stmt
) = eh_only
;
480 CLEANUP_BODY (stmt
) = push_stmt_list ();
483 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
484 the current loops, represented by 'NULL_TREE' if we've seen a possible
485 exit, and 'error_mark_node' if not. This is currently used only to
486 suppress the warning about a function with no return statements, and
487 therefore we don't bother noting returns as possible exits. We also
488 don't bother with gotos. */
491 begin_maybe_infinite_loop (tree cond
)
493 /* Only track this while parsing a function, not during instantiation. */
494 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
495 && !processing_template_decl
))
497 bool maybe_infinite
= true;
500 cond
= fold_non_dependent_expr (cond
);
501 maybe_infinite
= integer_nonzerop (cond
);
503 vec_safe_push (cp_function_chain
->infinite_loops
,
504 maybe_infinite
? error_mark_node
: NULL_TREE
);
508 /* A break is a possible exit for the current loop. */
511 break_maybe_infinite_loop (void)
515 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
518 /* If we reach the end of the loop without seeing a possible exit, we have
522 end_maybe_infinite_loop (tree cond
)
524 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
525 && !processing_template_decl
))
527 tree current
= cp_function_chain
->infinite_loops
->pop();
528 if (current
!= NULL_TREE
)
530 cond
= fold_non_dependent_expr (cond
);
531 if (integer_nonzerop (cond
))
532 current_function_infinite_loop
= 1;
537 /* Begin a conditional that might contain a declaration. When generating
538 normal code, we want the declaration to appear before the statement
539 containing the conditional. When generating template code, we want the
540 conditional to be rendered as the raw DECL_EXPR. */
543 begin_cond (tree
*cond_p
)
545 if (processing_template_decl
)
546 *cond_p
= push_stmt_list ();
549 /* Finish such a conditional. */
552 finish_cond (tree
*cond_p
, tree expr
)
554 if (processing_template_decl
)
556 tree cond
= pop_stmt_list (*cond_p
);
558 if (expr
== NULL_TREE
)
559 /* Empty condition in 'for'. */
560 gcc_assert (empty_expr_stmt_p (cond
));
561 else if (check_for_bare_parameter_packs (expr
))
562 expr
= error_mark_node
;
563 else if (!empty_expr_stmt_p (cond
))
564 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
569 /* If *COND_P specifies a conditional with a declaration, transform the
572 for (; A x = 42;) { }
574 while (true) { A x = 42; if (!x) break; }
575 for (;;) { A x = 42; if (!x) break; }
576 The statement list for BODY will be empty if the conditional did
577 not declare anything. */
580 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
584 if (!TREE_SIDE_EFFECTS (body
))
588 *cond_p
= boolean_true_node
;
590 if_stmt
= begin_if_stmt ();
591 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, false, tf_warning_or_error
);
592 finish_if_stmt_cond (cond
, if_stmt
);
593 finish_break_stmt ();
594 finish_then_clause (if_stmt
);
595 finish_if_stmt (if_stmt
);
598 /* Finish a goto-statement. */
601 finish_goto_stmt (tree destination
)
603 if (identifier_p (destination
))
604 destination
= lookup_label (destination
);
606 /* We warn about unused labels with -Wunused. That means we have to
607 mark the used labels as used. */
608 if (TREE_CODE (destination
) == LABEL_DECL
)
609 TREE_USED (destination
) = 1;
612 if (check_no_cilk (destination
,
613 "Cilk array notation cannot be used as a computed goto expression",
614 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression"))
615 destination
= error_mark_node
;
616 destination
= mark_rvalue_use (destination
);
617 if (!processing_template_decl
)
619 destination
= cp_convert (ptr_type_node
, destination
,
620 tf_warning_or_error
);
621 if (error_operand_p (destination
))
624 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
629 check_goto (destination
);
631 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
634 /* COND is the condition-expression for an if, while, etc.,
635 statement. Convert it to a boolean value, if appropriate.
636 In addition, verify sequence points if -Wsequence-point is enabled. */
639 maybe_convert_cond (tree cond
)
641 /* Empty conditions remain empty. */
645 /* Wait until we instantiate templates before doing conversion. */
646 if (processing_template_decl
)
649 if (warn_sequence_point
)
650 verify_sequence_points (cond
);
652 /* Do the conversion. */
653 cond
= convert_from_reference (cond
);
655 if (TREE_CODE (cond
) == MODIFY_EXPR
656 && !TREE_NO_WARNING (cond
)
659 warning_at (EXPR_LOC_OR_LOC (cond
, input_location
), OPT_Wparentheses
,
660 "suggest parentheses around assignment used as truth value");
661 TREE_NO_WARNING (cond
) = 1;
664 return condition_conversion (cond
);
667 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
670 finish_expr_stmt (tree expr
)
674 if (expr
!= NULL_TREE
)
676 /* If we ran into a problem, make sure we complained. */
677 gcc_assert (expr
!= error_mark_node
|| seen_error ());
679 if (!processing_template_decl
)
681 if (warn_sequence_point
)
682 verify_sequence_points (expr
);
683 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
685 else if (!type_dependent_expression_p (expr
))
686 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
687 tf_warning_or_error
);
689 if (check_for_bare_parameter_packs (expr
))
690 expr
= error_mark_node
;
692 /* Simplification of inner statement expressions, compound exprs,
693 etc can result in us already having an EXPR_STMT. */
694 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
696 if (TREE_CODE (expr
) != EXPR_STMT
)
697 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
698 expr
= maybe_cleanup_point_expr_void (expr
);
708 /* Begin an if-statement. Returns a newly created IF_STMT if
715 scope
= do_pushlevel (sk_cond
);
716 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
717 NULL_TREE
, NULL_TREE
, scope
);
718 current_binding_level
->this_entity
= r
;
719 begin_cond (&IF_COND (r
));
723 /* Process the COND of an if-statement, which may be given by
727 finish_if_stmt_cond (tree cond
, tree if_stmt
)
729 cond
= maybe_convert_cond (cond
);
730 if (IF_STMT_CONSTEXPR_P (if_stmt
)
731 && require_potential_rvalue_constant_expression (cond
)
732 && !value_dependent_expression_p (cond
))
733 cond
= cxx_constant_value (cond
, NULL_TREE
);
734 finish_cond (&IF_COND (if_stmt
), cond
);
736 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
740 /* Finish the then-clause of an if-statement, which may be given by
744 finish_then_clause (tree if_stmt
)
746 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
750 /* Begin the else-clause of an if-statement. */
753 begin_else_clause (tree if_stmt
)
755 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
758 /* Finish the else-clause of an if-statement, which may be given by
762 finish_else_clause (tree if_stmt
)
764 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
767 /* Finish an if-statement. */
770 finish_if_stmt (tree if_stmt
)
772 tree scope
= IF_SCOPE (if_stmt
);
773 IF_SCOPE (if_stmt
) = NULL
;
774 add_stmt (do_poplevel (scope
));
777 /* Begin a while-statement. Returns a newly created WHILE_STMT if
781 begin_while_stmt (void)
784 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
786 WHILE_BODY (r
) = do_pushlevel (sk_block
);
787 begin_cond (&WHILE_COND (r
));
791 /* Process the COND of a while-statement, which may be given by
795 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
)
797 if (check_no_cilk (cond
,
798 "Cilk array notation cannot be used as a condition for while statement",
799 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
800 cond
= error_mark_node
;
801 cond
= maybe_convert_cond (cond
);
802 finish_cond (&WHILE_COND (while_stmt
), cond
);
803 begin_maybe_infinite_loop (cond
);
804 if (ivdep
&& cond
!= error_mark_node
)
805 WHILE_COND (while_stmt
) = build2 (ANNOTATE_EXPR
,
806 TREE_TYPE (WHILE_COND (while_stmt
)),
807 WHILE_COND (while_stmt
),
808 build_int_cst (integer_type_node
,
809 annot_expr_ivdep_kind
));
810 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
813 /* Finish a while-statement, which may be given by WHILE_STMT. */
816 finish_while_stmt (tree while_stmt
)
818 end_maybe_infinite_loop (boolean_true_node
);
819 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
822 /* Begin a do-statement. Returns a newly created DO_STMT if
828 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
829 begin_maybe_infinite_loop (boolean_true_node
);
831 DO_BODY (r
) = push_stmt_list ();
835 /* Finish the body of a do-statement, which may be given by DO_STMT. */
838 finish_do_body (tree do_stmt
)
840 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
842 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
843 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
845 if (IS_EMPTY_STMT (body
))
846 warning (OPT_Wempty_body
,
847 "suggest explicit braces around empty body in %<do%> statement");
850 /* Finish a do-statement, which may be given by DO_STMT, and whose
851 COND is as indicated. */
854 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
)
856 if (check_no_cilk (cond
,
857 "Cilk array notation cannot be used as a condition for a do-while statement",
858 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
859 cond
= error_mark_node
;
860 cond
= maybe_convert_cond (cond
);
861 end_maybe_infinite_loop (cond
);
862 if (ivdep
&& cond
!= error_mark_node
)
863 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
864 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
));
865 DO_COND (do_stmt
) = cond
;
868 /* Finish a return-statement. The EXPRESSION returned, if any, is as
872 finish_return_stmt (tree expr
)
877 expr
= check_return_expr (expr
, &no_warning
);
879 if (error_operand_p (expr
)
880 || (flag_openmp
&& !check_omp_return ()))
882 /* Suppress -Wreturn-type for this function. */
883 if (warn_return_type
)
884 TREE_NO_WARNING (current_function_decl
) = true;
885 return error_mark_node
;
888 if (!processing_template_decl
)
890 if (warn_sequence_point
)
891 verify_sequence_points (expr
);
893 if (DECL_DESTRUCTOR_P (current_function_decl
)
894 || (DECL_CONSTRUCTOR_P (current_function_decl
)
895 && targetm
.cxx
.cdtor_returns_this ()))
897 /* Similarly, all destructors must run destructors for
898 base-classes before returning. So, all returns in a
899 destructor get sent to the DTOR_LABEL; finish_function emits
900 code to return a value there. */
901 return finish_goto_stmt (cdtor_label
);
905 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
906 TREE_NO_WARNING (r
) |= no_warning
;
907 r
= maybe_cleanup_point_expr_void (r
);
913 /* Begin the scope of a for-statement or a range-for-statement.
914 Both the returned trees are to be used in a call to
915 begin_for_stmt or begin_range_for_stmt. */
918 begin_for_scope (tree
*init
)
920 tree scope
= NULL_TREE
;
921 if (flag_new_for_scope
> 0)
922 scope
= do_pushlevel (sk_for
);
924 if (processing_template_decl
)
925 *init
= push_stmt_list ();
932 /* Begin a for-statement. Returns a new FOR_STMT.
933 SCOPE and INIT should be the return of begin_for_scope,
937 begin_for_stmt (tree scope
, tree init
)
941 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
942 NULL_TREE
, NULL_TREE
, NULL_TREE
);
944 if (scope
== NULL_TREE
)
946 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
948 scope
= begin_for_scope (&init
);
950 FOR_INIT_STMT (r
) = init
;
951 FOR_SCOPE (r
) = scope
;
956 /* Finish the init-statement of a for-statement, which may be
957 given by FOR_STMT. */
960 finish_init_stmt (tree for_stmt
)
962 if (processing_template_decl
)
963 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
965 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
966 begin_cond (&FOR_COND (for_stmt
));
969 /* Finish the COND of a for-statement, which may be given by
973 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
)
975 if (check_no_cilk (cond
,
976 "Cilk array notation cannot be used in a condition for a for-loop",
977 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
978 cond
= error_mark_node
;
979 cond
= maybe_convert_cond (cond
);
980 finish_cond (&FOR_COND (for_stmt
), cond
);
981 begin_maybe_infinite_loop (cond
);
982 if (ivdep
&& cond
!= error_mark_node
)
983 FOR_COND (for_stmt
) = build2 (ANNOTATE_EXPR
,
984 TREE_TYPE (FOR_COND (for_stmt
)),
986 build_int_cst (integer_type_node
,
987 annot_expr_ivdep_kind
));
988 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
991 /* Finish the increment-EXPRESSION in a for-statement, which may be
992 given by FOR_STMT. */
995 finish_for_expr (tree expr
, tree for_stmt
)
999 /* If EXPR is an overloaded function, issue an error; there is no
1000 context available to use to perform overload resolution. */
1001 if (type_unknown_p (expr
))
1003 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1004 expr
= error_mark_node
;
1006 if (!processing_template_decl
)
1008 if (warn_sequence_point
)
1009 verify_sequence_points (expr
);
1010 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1011 tf_warning_or_error
);
1013 else if (!type_dependent_expression_p (expr
))
1014 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1015 tf_warning_or_error
);
1016 expr
= maybe_cleanup_point_expr_void (expr
);
1017 if (check_for_bare_parameter_packs (expr
))
1018 expr
= error_mark_node
;
1019 FOR_EXPR (for_stmt
) = expr
;
1022 /* Finish the body of a for-statement, which may be given by
1023 FOR_STMT. The increment-EXPR for the loop must be
1025 It can also finish RANGE_FOR_STMT. */
1028 finish_for_stmt (tree for_stmt
)
1030 end_maybe_infinite_loop (boolean_true_node
);
1032 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1033 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1035 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1037 /* Pop the scope for the body of the loop. */
1038 if (flag_new_for_scope
> 0)
1041 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1042 ? &RANGE_FOR_SCOPE (for_stmt
)
1043 : &FOR_SCOPE (for_stmt
));
1046 add_stmt (do_poplevel (scope
));
1050 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1051 SCOPE and INIT should be the return of begin_for_scope,
1053 To finish it call finish_for_stmt(). */
1056 begin_range_for_stmt (tree scope
, tree init
)
1060 begin_maybe_infinite_loop (boolean_false_node
);
1062 r
= build_stmt (input_location
, RANGE_FOR_STMT
,
1063 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1065 if (scope
== NULL_TREE
)
1067 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
1069 scope
= begin_for_scope (&init
);
1072 /* RANGE_FOR_STMTs do not use nor save the init tree, so we
1075 pop_stmt_list (init
);
1076 RANGE_FOR_SCOPE (r
) = scope
;
1081 /* Finish the head of a range-based for statement, which may
1082 be given by RANGE_FOR_STMT. DECL must be the declaration
1083 and EXPR must be the loop expression. */
1086 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1088 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1089 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1090 add_stmt (range_for_stmt
);
1091 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1094 /* Finish a break-statement. */
1097 finish_break_stmt (void)
1099 /* In switch statements break is sometimes stylistically used after
1100 a return statement. This can lead to spurious warnings about
1101 control reaching the end of a non-void function when it is
1102 inlined. Note that we are calling block_may_fallthru with
1103 language specific tree nodes; this works because
1104 block_may_fallthru returns true when given something it does not
1106 if (!block_may_fallthru (cur_stmt_list
))
1108 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1111 /* Finish a continue-statement. */
1114 finish_continue_stmt (void)
1116 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1119 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1123 begin_switch_stmt (void)
1127 scope
= do_pushlevel (sk_cond
);
1128 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1130 begin_cond (&SWITCH_STMT_COND (r
));
1135 /* Finish the cond of a switch-statement. */
1138 finish_switch_cond (tree cond
, tree switch_stmt
)
1140 tree orig_type
= NULL
;
1142 if (check_no_cilk (cond
,
1143 "Cilk array notation cannot be used as a condition for switch statement",
1144 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement"))
1145 cond
= error_mark_node
;
1147 if (!processing_template_decl
)
1149 /* Convert the condition to an integer or enumeration type. */
1150 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1151 if (cond
== NULL_TREE
)
1153 error ("switch quantity not an integer");
1154 cond
= error_mark_node
;
1156 /* We want unlowered type here to handle enum bit-fields. */
1157 orig_type
= unlowered_expr_type (cond
);
1158 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1159 orig_type
= TREE_TYPE (cond
);
1160 if (cond
!= error_mark_node
)
1164 Integral promotions are performed. */
1165 cond
= perform_integral_promotions (cond
);
1166 cond
= maybe_cleanup_point_expr (cond
);
1169 if (check_for_bare_parameter_packs (cond
))
1170 cond
= error_mark_node
;
1171 else if (!processing_template_decl
&& warn_sequence_point
)
1172 verify_sequence_points (cond
);
1174 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1175 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1176 add_stmt (switch_stmt
);
1177 push_switch (switch_stmt
);
1178 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1181 /* Finish the body of a switch-statement, which may be given by
1182 SWITCH_STMT. The COND to switch on is indicated. */
1185 finish_switch_stmt (tree switch_stmt
)
1189 SWITCH_STMT_BODY (switch_stmt
) =
1190 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1193 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1194 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1195 add_stmt (do_poplevel (scope
));
1198 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1202 begin_try_block (void)
1204 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1206 TRY_STMTS (r
) = push_stmt_list ();
1210 /* Likewise, for a function-try-block. The block returned in
1211 *COMPOUND_STMT is an artificial outer scope, containing the
1212 function-try-block. */
1215 begin_function_try_block (tree
*compound_stmt
)
1218 /* This outer scope does not exist in the C++ standard, but we need
1219 a place to put __FUNCTION__ and similar variables. */
1220 *compound_stmt
= begin_compound_stmt (0);
1221 r
= begin_try_block ();
1222 FN_TRY_BLOCK_P (r
) = 1;
1226 /* Finish a try-block, which may be given by TRY_BLOCK. */
1229 finish_try_block (tree try_block
)
1231 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1232 TRY_HANDLERS (try_block
) = push_stmt_list ();
1235 /* Finish the body of a cleanup try-block, which may be given by
1239 finish_cleanup_try_block (tree try_block
)
1241 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1244 /* Finish an implicitly generated try-block, with a cleanup is given
1248 finish_cleanup (tree cleanup
, tree try_block
)
1250 TRY_HANDLERS (try_block
) = cleanup
;
1251 CLEANUP_P (try_block
) = 1;
1254 /* Likewise, for a function-try-block. */
1257 finish_function_try_block (tree try_block
)
1259 finish_try_block (try_block
);
1260 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1261 the try block, but moving it inside. */
1262 in_function_try_handler
= 1;
1265 /* Finish a handler-sequence for a try-block, which may be given by
1269 finish_handler_sequence (tree try_block
)
1271 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1272 check_handlers (TRY_HANDLERS (try_block
));
1275 /* Finish the handler-seq for a function-try-block, given by
1276 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1277 begin_function_try_block. */
1280 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1282 in_function_try_handler
= 0;
1283 finish_handler_sequence (try_block
);
1284 finish_compound_stmt (compound_stmt
);
1287 /* Begin a handler. Returns a HANDLER if appropriate. */
1290 begin_handler (void)
1294 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1297 /* Create a binding level for the eh_info and the exception object
1299 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1304 /* Finish the handler-parameters for a handler, which may be given by
1305 HANDLER. DECL is the declaration for the catch parameter, or NULL
1306 if this is a `catch (...)' clause. */
1309 finish_handler_parms (tree decl
, tree handler
)
1311 tree type
= NULL_TREE
;
1312 if (processing_template_decl
)
1316 decl
= pushdecl (decl
);
1317 decl
= push_template_decl (decl
);
1318 HANDLER_PARMS (handler
) = decl
;
1319 type
= TREE_TYPE (decl
);
1323 type
= expand_start_catch_block (decl
);
1324 HANDLER_TYPE (handler
) = type
;
1327 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1328 the return value from the matching call to finish_handler_parms. */
1331 finish_handler (tree handler
)
1333 if (!processing_template_decl
)
1334 expand_end_catch_block ();
1335 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1338 /* Begin a compound statement. FLAGS contains some bits that control the
1339 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1340 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1341 block of a function. If BCS_TRY_BLOCK is set, this is the block
1342 created on behalf of a TRY statement. Returns a token to be passed to
1343 finish_compound_stmt. */
1346 begin_compound_stmt (unsigned int flags
)
1350 if (flags
& BCS_NO_SCOPE
)
1352 r
= push_stmt_list ();
1353 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1355 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1356 But, if it's a statement-expression with a scopeless block, there's
1357 nothing to keep, and we don't want to accidentally keep a block
1358 *inside* the scopeless block. */
1359 keep_next_level (false);
1363 scope_kind sk
= sk_block
;
1364 if (flags
& BCS_TRY_BLOCK
)
1366 else if (flags
& BCS_TRANSACTION
)
1367 sk
= sk_transaction
;
1368 r
= do_pushlevel (sk
);
1371 /* When processing a template, we need to remember where the braces were,
1372 so that we can set up identical scopes when instantiating the template
1373 later. BIND_EXPR is a handy candidate for this.
1374 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1375 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1376 processing templates. */
1377 if (processing_template_decl
)
1379 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1380 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1381 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1382 TREE_SIDE_EFFECTS (r
) = 1;
1388 /* Finish a compound-statement, which is given by STMT. */
1391 finish_compound_stmt (tree stmt
)
1393 if (TREE_CODE (stmt
) == BIND_EXPR
)
1395 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1396 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1397 discard the BIND_EXPR so it can be merged with the containing
1399 if (TREE_CODE (body
) == STATEMENT_LIST
1400 && STATEMENT_LIST_HEAD (body
) == NULL
1401 && !BIND_EXPR_BODY_BLOCK (stmt
)
1402 && !BIND_EXPR_TRY_BLOCK (stmt
))
1405 BIND_EXPR_BODY (stmt
) = body
;
1407 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1408 stmt
= pop_stmt_list (stmt
);
1411 /* Destroy any ObjC "super" receivers that may have been
1413 objc_clear_super_receiver ();
1415 stmt
= do_poplevel (stmt
);
1418 /* ??? See c_end_compound_stmt wrt statement expressions. */
1422 /* Finish an asm-statement, whose components are a STRING, some
1423 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1424 LABELS. Also note whether the asm-statement should be
1425 considered volatile. */
1428 finish_asm_stmt (int volatile_p
, tree string
, tree output_operands
,
1429 tree input_operands
, tree clobbers
, tree labels
)
1433 int ninputs
= list_length (input_operands
);
1434 int noutputs
= list_length (output_operands
);
1436 if (!processing_template_decl
)
1438 const char *constraint
;
1439 const char **oconstraints
;
1440 bool allows_mem
, allows_reg
, is_inout
;
1444 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1446 string
= resolve_asm_operand_names (string
, output_operands
,
1447 input_operands
, labels
);
1449 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1451 operand
= TREE_VALUE (t
);
1453 /* ??? Really, this should not be here. Users should be using a
1454 proper lvalue, dammit. But there's a long history of using
1455 casts in the output operands. In cases like longlong.h, this
1456 becomes a primitive form of typechecking -- if the cast can be
1457 removed, then the output operand had a type of the proper width;
1458 otherwise we'll get an error. Gross, but ... */
1459 STRIP_NOPS (operand
);
1461 operand
= mark_lvalue_use (operand
);
1463 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1464 operand
= error_mark_node
;
1466 if (operand
!= error_mark_node
1467 && (TREE_READONLY (operand
)
1468 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1469 /* Functions are not modifiable, even though they are
1471 || TREE_CODE (TREE_TYPE (operand
)) == FUNCTION_TYPE
1472 || TREE_CODE (TREE_TYPE (operand
)) == METHOD_TYPE
1473 /* If it's an aggregate and any field is const, then it is
1474 effectively const. */
1475 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1476 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1477 cxx_readonly_error (operand
, lv_asm
);
1479 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1480 oconstraints
[i
] = constraint
;
1482 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1483 &allows_mem
, &allows_reg
, &is_inout
))
1485 /* If the operand is going to end up in memory,
1486 mark it addressable. */
1487 if (!allows_reg
&& !cxx_mark_addressable (operand
))
1488 operand
= error_mark_node
;
1491 operand
= error_mark_node
;
1493 TREE_VALUE (t
) = operand
;
1496 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1498 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1499 bool constraint_parsed
1500 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1501 oconstraints
, &allows_mem
, &allows_reg
);
1502 /* If the operand is going to end up in memory, don't call
1503 decay_conversion. */
1504 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1505 operand
= mark_lvalue_use (TREE_VALUE (t
));
1507 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1509 /* If the type of the operand hasn't been determined (e.g.,
1510 because it involves an overloaded function), then issue
1511 an error message. There's no context available to
1512 resolve the overloading. */
1513 if (TREE_TYPE (operand
) == unknown_type_node
)
1515 error ("type of asm operand %qE could not be determined",
1517 operand
= error_mark_node
;
1520 if (constraint_parsed
)
1522 /* If the operand is going to end up in memory,
1523 mark it addressable. */
1524 if (!allows_reg
&& allows_mem
)
1526 /* Strip the nops as we allow this case. FIXME, this really
1527 should be rejected or made deprecated. */
1528 STRIP_NOPS (operand
);
1529 if (!cxx_mark_addressable (operand
))
1530 operand
= error_mark_node
;
1532 else if (!allows_reg
&& !allows_mem
)
1534 /* If constraint allows neither register nor memory,
1535 try harder to get a constant. */
1536 tree constop
= maybe_constant_value (operand
);
1537 if (TREE_CONSTANT (constop
))
1542 operand
= error_mark_node
;
1544 TREE_VALUE (t
) = operand
;
1548 r
= build_stmt (input_location
, ASM_EXPR
, string
,
1549 output_operands
, input_operands
,
1551 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1552 r
= maybe_cleanup_point_expr_void (r
);
1553 return add_stmt (r
);
1556 /* Finish a label with the indicated NAME. Returns the new label. */
1559 finish_label_stmt (tree name
)
1561 tree decl
= define_label (input_location
, name
);
1563 if (decl
== error_mark_node
)
1564 return error_mark_node
;
1566 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1571 /* Finish a series of declarations for local labels. G++ allows users
1572 to declare "local" labels, i.e., labels with scope. This extension
1573 is useful when writing code involving statement-expressions. */
1576 finish_label_decl (tree name
)
1578 if (!at_function_scope_p ())
1580 error ("__label__ declarations are only allowed in function scopes");
1584 add_decl_expr (declare_local_label (name
));
1587 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1590 finish_decl_cleanup (tree decl
, tree cleanup
)
1592 push_cleanup (decl
, cleanup
, false);
1595 /* If the current scope exits with an exception, run CLEANUP. */
1598 finish_eh_cleanup (tree cleanup
)
1600 push_cleanup (NULL
, cleanup
, true);
1603 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1604 order they were written by the user. Each node is as for
1605 emit_mem_initializers. */
1608 finish_mem_initializers (tree mem_inits
)
1610 /* Reorder the MEM_INITS so that they are in the order they appeared
1611 in the source program. */
1612 mem_inits
= nreverse (mem_inits
);
1614 if (processing_template_decl
)
1618 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1620 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1621 check for bare parameter packs in the TREE_VALUE, because
1622 any parameter packs in the TREE_VALUE have already been
1623 bound as part of the TREE_PURPOSE. See
1624 make_pack_expansion for more information. */
1625 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1626 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1627 TREE_VALUE (mem
) = error_mark_node
;
1630 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1631 CTOR_INITIALIZER
, mem_inits
));
1634 emit_mem_initializers (mem_inits
);
1637 /* Obfuscate EXPR if it looks like an id-expression or member access so
1638 that the call to finish_decltype in do_auto_deduction will give the
1642 force_paren_expr (tree expr
)
1644 /* This is only needed for decltype(auto) in C++14. */
1645 if (cxx_dialect
< cxx14
)
1648 /* If we're in unevaluated context, we can't be deducing a
1649 return/initializer type, so we don't need to mess with this. */
1650 if (cp_unevaluated_operand
)
1653 if (!DECL_P (expr
) && TREE_CODE (expr
) != COMPONENT_REF
1654 && TREE_CODE (expr
) != SCOPE_REF
)
1657 if (TREE_CODE (expr
) == COMPONENT_REF
1658 || TREE_CODE (expr
) == SCOPE_REF
)
1659 REF_PARENTHESIZED_P (expr
) = true;
1660 else if (type_dependent_expression_p (expr
))
1661 expr
= build1 (PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1662 else if (VAR_P (expr
) && DECL_HARD_REGISTER (expr
))
1663 /* We can't bind a hard register variable to a reference. */;
1666 cp_lvalue_kind kind
= lvalue_kind (expr
);
1667 if ((kind
& ~clk_class
) != clk_none
)
1669 tree type
= unlowered_expr_type (expr
);
1670 bool rval
= !!(kind
& clk_rvalueref
);
1671 type
= cp_build_reference_type (type
, rval
);
1672 /* This inhibits warnings in, eg, cxx_mark_addressable
1674 warning_sentinel
s (extra_warnings
);
1675 expr
= build_static_cast (type
, expr
, tf_error
);
1676 if (expr
!= error_mark_node
)
1677 REF_PARENTHESIZED_P (expr
) = true;
1684 /* If T is an id-expression obfuscated by force_paren_expr, undo the
1685 obfuscation and return the underlying id-expression. Otherwise
1689 maybe_undo_parenthesized_ref (tree t
)
1691 if (cxx_dialect
>= cxx14
1692 && INDIRECT_REF_P (t
)
1693 && REF_PARENTHESIZED_P (t
))
1695 t
= TREE_OPERAND (t
, 0);
1696 while (TREE_CODE (t
) == NON_LVALUE_EXPR
1697 || TREE_CODE (t
) == NOP_EXPR
)
1698 t
= TREE_OPERAND (t
, 0);
1700 gcc_assert (TREE_CODE (t
) == ADDR_EXPR
1701 || TREE_CODE (t
) == STATIC_CAST_EXPR
);
1702 t
= TREE_OPERAND (t
, 0);
1708 /* Finish a parenthesized expression EXPR. */
1711 finish_parenthesized_expr (cp_expr expr
)
1714 /* This inhibits warnings in c_common_truthvalue_conversion. */
1715 TREE_NO_WARNING (expr
) = 1;
1717 if (TREE_CODE (expr
) == OFFSET_REF
1718 || TREE_CODE (expr
) == SCOPE_REF
)
1719 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1720 enclosed in parentheses. */
1721 PTRMEM_OK_P (expr
) = 0;
1723 if (TREE_CODE (expr
) == STRING_CST
)
1724 PAREN_STRING_LITERAL_P (expr
) = 1;
1726 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
1731 /* Finish a reference to a non-static data member (DECL) that is not
1732 preceded by `.' or `->'. */
1735 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1737 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1738 bool try_omp_private
= !object
&& omp_private_member_map
;
1743 tree scope
= qualifying_scope
;
1744 if (scope
== NULL_TREE
)
1745 scope
= context_for_name_lookup (decl
);
1746 object
= maybe_dummy_object (scope
, NULL
);
1749 object
= maybe_resolve_dummy (object
, true);
1750 if (object
== error_mark_node
)
1751 return error_mark_node
;
1753 /* DR 613/850: Can use non-static data members without an associated
1754 object in sizeof/decltype/alignof. */
1755 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
1756 && (!processing_template_decl
|| !current_class_ref
))
1758 if (current_function_decl
1759 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1760 error ("invalid use of member %qD in static member function", decl
);
1762 error ("invalid use of non-static data member %qD", decl
);
1763 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
1765 return error_mark_node
;
1768 if (current_class_ptr
)
1769 TREE_USED (current_class_ptr
) = 1;
1770 if (processing_template_decl
&& !qualifying_scope
)
1772 tree type
= TREE_TYPE (decl
);
1774 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1775 /* Quals on the object don't matter. */;
1776 else if (PACK_EXPANSION_P (type
))
1777 /* Don't bother trying to represent this. */
1781 /* Set the cv qualifiers. */
1782 int quals
= cp_type_quals (TREE_TYPE (object
));
1784 if (DECL_MUTABLE_P (decl
))
1785 quals
&= ~TYPE_QUAL_CONST
;
1787 quals
|= cp_type_quals (TREE_TYPE (decl
));
1788 type
= cp_build_qualified_type (type
, quals
);
1791 ret
= (convert_from_reference
1792 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
1794 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1795 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1797 else if (processing_template_decl
)
1798 ret
= build_qualified_name (TREE_TYPE (decl
),
1801 /*template_p=*/false);
1804 tree access_type
= TREE_TYPE (object
);
1806 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
1807 decl
, tf_warning_or_error
);
1809 /* If the data member was named `C::M', convert `*this' to `C'
1811 if (qualifying_scope
)
1813 tree binfo
= NULL_TREE
;
1814 object
= build_scoped_ref (object
, qualifying_scope
,
1818 ret
= build_class_member_access_expr (object
, decl
,
1819 /*access_path=*/NULL_TREE
,
1820 /*preserve_reference=*/false,
1821 tf_warning_or_error
);
1823 if (try_omp_private
)
1825 tree
*v
= omp_private_member_map
->get (decl
);
1827 ret
= convert_from_reference (*v
);
1832 /* If we are currently parsing a template and we encountered a typedef
1833 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1834 adds the typedef to a list tied to the current template.
1835 At template instantiation time, that list is walked and access check
1836 performed for each typedef.
1837 LOCATION is the location of the usage point of TYPEDEF_DECL. */
1840 add_typedef_to_current_template_for_access_check (tree typedef_decl
,
1842 location_t location
)
1844 tree template_info
= NULL
;
1845 tree cs
= current_scope ();
1847 if (!is_typedef_decl (typedef_decl
)
1849 || !CLASS_TYPE_P (context
)
1853 if (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
)
1854 template_info
= get_template_info (cs
);
1857 && TI_TEMPLATE (template_info
)
1858 && !currently_open_class (context
))
1859 append_type_to_template_for_access_check (cs
, typedef_decl
,
1863 /* DECL was the declaration to which a qualified-id resolved. Issue
1864 an error message if it is not accessible. If OBJECT_TYPE is
1865 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1866 type of `*x', or `x', respectively. If the DECL was named as
1867 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1870 check_accessibility_of_qualified_id (tree decl
,
1872 tree nested_name_specifier
)
1875 tree qualifying_type
= NULL_TREE
;
1877 /* If we are parsing a template declaration and if decl is a typedef,
1878 add it to a list tied to the template.
1879 At template instantiation time, that list will be walked and
1880 access check performed. */
1881 add_typedef_to_current_template_for_access_check (decl
,
1882 nested_name_specifier
1883 ? nested_name_specifier
1884 : DECL_CONTEXT (decl
),
1887 /* If we're not checking, return immediately. */
1888 if (deferred_access_no_check
)
1891 /* Determine the SCOPE of DECL. */
1892 scope
= context_for_name_lookup (decl
);
1893 /* If the SCOPE is not a type, then DECL is not a member. */
1894 if (!TYPE_P (scope
))
1896 /* Compute the scope through which DECL is being accessed. */
1898 /* OBJECT_TYPE might not be a class type; consider:
1900 class A { typedef int I; };
1904 In this case, we will have "A::I" as the DECL, but "I" as the
1906 && CLASS_TYPE_P (object_type
)
1907 && DERIVED_FROM_P (scope
, object_type
))
1908 /* If we are processing a `->' or `.' expression, use the type of the
1910 qualifying_type
= object_type
;
1911 else if (nested_name_specifier
)
1913 /* If the reference is to a non-static member of the
1914 current class, treat it as if it were referenced through
1917 if (DECL_NONSTATIC_MEMBER_P (decl
)
1918 && current_class_ptr
1919 && DERIVED_FROM_P (scope
, ct
= current_nonlambda_class_type ()))
1920 qualifying_type
= ct
;
1921 /* Otherwise, use the type indicated by the
1922 nested-name-specifier. */
1924 qualifying_type
= nested_name_specifier
;
1927 /* Otherwise, the name must be from the current class or one of
1929 qualifying_type
= currently_open_derived_class (scope
);
1932 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
1933 or similar in a default argument value. */
1934 && CLASS_TYPE_P (qualifying_type
)
1935 && !dependent_type_p (qualifying_type
))
1936 perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
1937 decl
, tf_warning_or_error
);
1940 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
1941 class named to the left of the "::" operator. DONE is true if this
1942 expression is a complete postfix-expression; it is false if this
1943 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
1944 iff this expression is the operand of '&'. TEMPLATE_P is true iff
1945 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
1946 is true iff this qualified name appears as a template argument. */
1949 finish_qualified_id_expr (tree qualifying_class
,
1954 bool template_arg_p
,
1955 tsubst_flags_t complain
)
1957 gcc_assert (TYPE_P (qualifying_class
));
1959 if (error_operand_p (expr
))
1960 return error_mark_node
;
1962 if ((DECL_P (expr
) || BASELINK_P (expr
))
1963 && !mark_used (expr
, complain
))
1964 return error_mark_node
;
1968 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
1969 /* cp_parser_lookup_name thought we were looking for a type,
1970 but we're actually looking for a declaration. */
1971 expr
= build_qualified_name (/*type*/NULL_TREE
,
1972 TYPE_CONTEXT (expr
),
1973 TYPE_IDENTIFIER (expr
),
1974 /*template_p*/true);
1976 check_template_keyword (expr
);
1979 /* If EXPR occurs as the operand of '&', use special handling that
1980 permits a pointer-to-member. */
1981 if (address_p
&& done
)
1983 if (TREE_CODE (expr
) == SCOPE_REF
)
1984 expr
= TREE_OPERAND (expr
, 1);
1985 expr
= build_offset_ref (qualifying_class
, expr
,
1986 /*address_p=*/true, complain
);
1990 /* No need to check access within an enum. */
1991 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
)
1994 /* Within the scope of a class, turn references to non-static
1995 members into expression of the form "this->...". */
1997 /* But, within a template argument, we do not want make the
1998 transformation, as there is no "this" pointer. */
2000 else if (TREE_CODE (expr
) == FIELD_DECL
)
2002 push_deferring_access_checks (dk_no_check
);
2003 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2005 pop_deferring_access_checks ();
2007 else if (BASELINK_P (expr
) && !processing_template_decl
)
2009 /* See if any of the functions are non-static members. */
2010 /* If so, the expression may be relative to 'this'. */
2011 if (!shared_member_p (expr
)
2012 && current_class_ptr
2013 && DERIVED_FROM_P (qualifying_class
,
2014 current_nonlambda_class_type ()))
2015 expr
= (build_class_member_access_expr
2016 (maybe_dummy_object (qualifying_class
, NULL
),
2018 BASELINK_ACCESS_BINFO (expr
),
2019 /*preserve_reference=*/false,
2022 /* The expression is a qualified name whose address is not
2024 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2027 else if (BASELINK_P (expr
))
2031 /* In a template, return a SCOPE_REF for most qualified-ids
2032 so that we can check access at instantiation time. But if
2033 we're looking at a member of the current instantiation, we
2034 know we have access and building up the SCOPE_REF confuses
2035 non-type template argument handling. */
2036 if (processing_template_decl
2037 && !currently_open_class (qualifying_class
))
2038 expr
= build_qualified_name (TREE_TYPE (expr
),
2039 qualifying_class
, expr
,
2042 expr
= convert_from_reference (expr
);
2048 /* Begin a statement-expression. The value returned must be passed to
2049 finish_stmt_expr. */
2052 begin_stmt_expr (void)
2054 return push_stmt_list ();
2057 /* Process the final expression of a statement expression. EXPR can be
2058 NULL, if the final expression is empty. Return a STATEMENT_LIST
2059 containing all the statements in the statement-expression, or
2060 ERROR_MARK_NODE if there was an error. */
2063 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2065 if (error_operand_p (expr
))
2067 /* The type of the statement-expression is the type of the last
2069 TREE_TYPE (stmt_expr
) = error_mark_node
;
2070 return error_mark_node
;
2073 /* If the last statement does not have "void" type, then the value
2074 of the last statement is the value of the entire expression. */
2077 tree type
= TREE_TYPE (expr
);
2079 if (processing_template_decl
)
2081 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2082 expr
= add_stmt (expr
);
2083 /* Mark the last statement so that we can recognize it as such at
2084 template-instantiation time. */
2085 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2087 else if (VOID_TYPE_P (type
))
2089 /* Just treat this like an ordinary statement. */
2090 expr
= finish_expr_stmt (expr
);
2094 /* It actually has a value we need to deal with. First, force it
2095 to be an rvalue so that we won't need to build up a copy
2096 constructor call later when we try to assign it to something. */
2097 expr
= force_rvalue (expr
, tf_warning_or_error
);
2098 if (error_operand_p (expr
))
2099 return error_mark_node
;
2101 /* Update for array-to-pointer decay. */
2102 type
= TREE_TYPE (expr
);
2104 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2105 normal statement, but don't convert to void or actually add
2107 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2108 expr
= maybe_cleanup_point_expr (expr
);
2112 /* The type of the statement-expression is the type of the last
2114 TREE_TYPE (stmt_expr
) = type
;
2120 /* Finish a statement-expression. EXPR should be the value returned
2121 by the previous begin_stmt_expr. Returns an expression
2122 representing the statement-expression. */
2125 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2130 if (error_operand_p (stmt_expr
))
2132 pop_stmt_list (stmt_expr
);
2133 return error_mark_node
;
2136 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2138 type
= TREE_TYPE (stmt_expr
);
2139 result
= pop_stmt_list (stmt_expr
);
2140 TREE_TYPE (result
) = type
;
2142 if (processing_template_decl
)
2144 result
= build_min (STMT_EXPR
, type
, result
);
2145 TREE_SIDE_EFFECTS (result
) = 1;
2146 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2148 else if (CLASS_TYPE_P (type
))
2150 /* Wrap the statement-expression in a TARGET_EXPR so that the
2151 temporary object created by the final expression is destroyed at
2152 the end of the full-expression containing the
2153 statement-expression. */
2154 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2160 /* Returns the expression which provides the value of STMT_EXPR. */
2163 stmt_expr_value_expr (tree stmt_expr
)
2165 tree t
= STMT_EXPR_STMT (stmt_expr
);
2167 if (TREE_CODE (t
) == BIND_EXPR
)
2168 t
= BIND_EXPR_BODY (t
);
2170 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2171 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2173 if (TREE_CODE (t
) == EXPR_STMT
)
2174 t
= EXPR_STMT_EXPR (t
);
2179 /* Return TRUE iff EXPR_STMT is an empty list of
2180 expression statements. */
2183 empty_expr_stmt_p (tree expr_stmt
)
2185 tree body
= NULL_TREE
;
2187 if (expr_stmt
== void_node
)
2192 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2193 body
= EXPR_STMT_EXPR (expr_stmt
);
2194 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2200 if (TREE_CODE (body
) == STATEMENT_LIST
)
2201 return tsi_end_p (tsi_start (body
));
2203 return empty_expr_stmt_p (body
);
2208 /* Perform Koenig lookup. FN is the postfix-expression representing
2209 the function (or functions) to call; ARGS are the arguments to the
2210 call. Returns the functions to be considered by overload resolution. */
2213 perform_koenig_lookup (cp_expr fn
, vec
<tree
, va_gc
> *args
,
2214 tsubst_flags_t complain
)
2216 tree identifier
= NULL_TREE
;
2217 tree functions
= NULL_TREE
;
2218 tree tmpl_args
= NULL_TREE
;
2219 bool template_id
= false;
2220 location_t loc
= fn
.get_location ();
2222 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2224 /* Use a separate flag to handle null args. */
2226 tmpl_args
= TREE_OPERAND (fn
, 1);
2227 fn
= TREE_OPERAND (fn
, 0);
2230 /* Find the name of the overloaded function. */
2231 if (identifier_p (fn
))
2233 else if (is_overloaded_fn (fn
))
2236 identifier
= DECL_NAME (get_first_fn (functions
));
2238 else if (DECL_P (fn
))
2241 identifier
= DECL_NAME (fn
);
2244 /* A call to a namespace-scope function using an unqualified name.
2246 Do Koenig lookup -- unless any of the arguments are
2248 if (!any_type_dependent_arguments_p (args
)
2249 && !any_dependent_template_arguments_p (tmpl_args
))
2251 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2254 /* The unqualified name could not be resolved. */
2255 if (complain
& tf_error
)
2256 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2262 if (fn
&& template_id
&& fn
!= error_mark_node
)
2263 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2268 /* Generate an expression for `FN (ARGS)'. This may change the
2271 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2272 as a virtual call, even if FN is virtual. (This flag is set when
2273 encountering an expression where the function name is explicitly
2274 qualified. For example a call to `X::f' never generates a virtual
2277 Returns code for the call. */
2280 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2281 bool koenig_p
, tsubst_flags_t complain
)
2285 vec
<tree
, va_gc
> *orig_args
= NULL
;
2287 if (fn
== error_mark_node
)
2288 return error_mark_node
;
2290 gcc_assert (!TYPE_P (fn
));
2292 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2293 it so that we can tell this is a call to a known function. */
2294 fn
= maybe_undo_parenthesized_ref (fn
);
2298 if (processing_template_decl
)
2300 /* If the call expression is dependent, build a CALL_EXPR node
2301 with no type; type_dependent_expression_p recognizes
2302 expressions with no type as being dependent. */
2303 if (type_dependent_expression_p (fn
)
2304 || any_type_dependent_arguments_p (*args
))
2306 result
= build_nt_call_vec (fn
, *args
);
2307 SET_EXPR_LOCATION (result
, EXPR_LOC_OR_LOC (fn
, input_location
));
2308 KOENIG_LOOKUP_P (result
) = koenig_p
;
2313 tree fndecl
= OVL_CURRENT (fn
);
2314 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2315 || !TREE_THIS_VOLATILE (fndecl
))
2321 current_function_returns_abnormally
= 1;
2325 orig_args
= make_tree_vector_copy (*args
);
2326 if (!BASELINK_P (fn
)
2327 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2328 && TREE_TYPE (fn
) != unknown_type_node
)
2329 fn
= build_non_dependent_expr (fn
);
2330 make_args_non_dependent (*args
);
2333 if (TREE_CODE (fn
) == COMPONENT_REF
)
2335 tree member
= TREE_OPERAND (fn
, 1);
2336 if (BASELINK_P (member
))
2338 tree object
= TREE_OPERAND (fn
, 0);
2339 return build_new_method_call (object
, member
,
2342 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2349 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2350 if (TREE_CODE (fn
) == ADDR_EXPR
2351 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2352 fn
= TREE_OPERAND (fn
, 0);
2354 if (is_overloaded_fn (fn
))
2355 fn
= baselink_for_fns (fn
);
2358 if (BASELINK_P (fn
))
2362 /* A call to a member function. From [over.call.func]:
2364 If the keyword this is in scope and refers to the class of
2365 that member function, or a derived class thereof, then the
2366 function call is transformed into a qualified function call
2367 using (*this) as the postfix-expression to the left of the
2368 . operator.... [Otherwise] a contrived object of type T
2369 becomes the implied object argument.
2373 struct A { void f(); };
2374 struct B : public A {};
2375 struct C : public A { void g() { B::f(); }};
2377 "the class of that member function" refers to `A'. But 11.2
2378 [class.access.base] says that we need to convert 'this' to B* as
2379 part of the access, so we pass 'B' to maybe_dummy_object. */
2381 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2383 /* A constructor call always uses a dummy object. (This constructor
2384 call which has the form A::A () is actually invalid and we are
2385 going to reject it later in build_new_method_call.) */
2386 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2389 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2392 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2394 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2399 else if (is_overloaded_fn (fn
))
2401 /* If the function is an overloaded builtin, resolve it. */
2402 if (TREE_CODE (fn
) == FUNCTION_DECL
2403 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2404 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2405 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2409 if (warn_sizeof_pointer_memaccess
2410 && (complain
& tf_warning
)
2411 && !vec_safe_is_empty (*args
)
2412 && !processing_template_decl
)
2414 location_t sizeof_arg_loc
[3];
2417 for (i
= 0; i
< 3; i
++)
2421 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2422 sizeof_arg
[i
] = NULL_TREE
;
2423 if (i
>= (*args
)->length ())
2426 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2428 if (SIZEOF_EXPR_TYPE_P (t
))
2429 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2431 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2432 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2434 sizeof_pointer_memaccess_warning
2435 (sizeof_arg_loc
, fn
, *args
,
2436 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2439 /* A call to a namespace-scope function. */
2440 result
= build_new_function_call (fn
, args
, koenig_p
, complain
);
2443 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2445 if (!vec_safe_is_empty (*args
))
2446 error ("arguments to destructor are not allowed");
2447 /* Mark the pseudo-destructor call as having side-effects so
2448 that we do not issue warnings about its use. */
2449 result
= build1 (NOP_EXPR
,
2451 TREE_OPERAND (fn
, 0));
2452 TREE_SIDE_EFFECTS (result
) = 1;
2454 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2455 /* If the "function" is really an object of class type, it might
2456 have an overloaded `operator ()'. */
2457 result
= build_op_call (fn
, args
, complain
);
2460 /* A call where the function is unknown. */
2461 result
= cp_build_function_call_vec (fn
, args
, complain
);
2463 if (processing_template_decl
&& result
!= error_mark_node
)
2465 if (INDIRECT_REF_P (result
))
2466 result
= TREE_OPERAND (result
, 0);
2467 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2468 SET_EXPR_LOCATION (result
, input_location
);
2469 KOENIG_LOOKUP_P (result
) = koenig_p
;
2470 release_tree_vector (orig_args
);
2471 result
= convert_from_reference (result
);
2476 /* Free garbage OVERLOADs from arg-dependent lookup. */
2477 tree next
= NULL_TREE
;
2479 fn
&& TREE_CODE (fn
) == OVERLOAD
&& OVL_ARG_DEPENDENT (fn
);
2482 if (processing_template_decl
)
2483 /* In a template, we'll re-use them at instantiation time. */
2484 OVL_ARG_DEPENDENT (fn
) = false;
2487 next
= OVL_CHAIN (fn
);
2496 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2497 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2498 POSTDECREMENT_EXPR.) */
2501 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2503 /* input_location holds the location of the trailing operator token.
2504 Build a location of the form:
2507 with the caret at the operator token, ranging from the start
2508 of EXPR to the end of the operator token. */
2509 location_t combined_loc
= make_location (input_location
,
2511 get_finish (input_location
));
2512 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2513 tf_warning_or_error
);
2514 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2515 result
.set_location (combined_loc
);
2519 /* Finish a use of `this'. Returns an expression for `this'. */
2522 finish_this_expr (void)
2524 tree result
= NULL_TREE
;
2526 if (current_class_ptr
)
2528 tree type
= TREE_TYPE (current_class_ref
);
2530 /* In a lambda expression, 'this' refers to the captured 'this'. */
2531 if (LAMBDA_TYPE_P (type
))
2532 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2534 result
= current_class_ptr
;
2538 /* The keyword 'this' is a prvalue expression. */
2539 return rvalue (result
);
2541 tree fn
= current_nonlambda_function ();
2542 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2543 error ("%<this%> is unavailable for static member functions");
2545 error ("invalid use of %<this%> in non-member function");
2547 error ("invalid use of %<this%> at top level");
2548 return error_mark_node
;
2551 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2552 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2553 the TYPE for the type given. If SCOPE is non-NULL, the expression
2554 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2557 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2560 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2561 return error_mark_node
;
2563 gcc_assert (TYPE_P (destructor
));
2565 if (!processing_template_decl
)
2567 if (scope
== error_mark_node
)
2569 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2570 return error_mark_node
;
2572 if (is_auto (destructor
))
2573 destructor
= TREE_TYPE (object
);
2574 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2577 "qualified type %qT does not match destructor name ~%qT",
2579 return error_mark_node
;
2583 /* [expr.pseudo] says both:
2585 The type designated by the pseudo-destructor-name shall be
2586 the same as the object type.
2590 The cv-unqualified versions of the object type and of the
2591 type designated by the pseudo-destructor-name shall be the
2594 We implement the more generous second sentence, since that is
2595 what most other compilers do. */
2596 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2599 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2600 return error_mark_node
;
2604 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, void_type_node
, object
,
2608 /* Finish an expression of the form CODE EXPR. */
2611 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
2612 tsubst_flags_t complain
)
2614 /* Build a location of the form:
2617 with the caret at the operator token, ranging from the start
2618 of the operator token to the end of EXPR. */
2619 location_t combined_loc
= make_location (op_loc
,
2620 op_loc
, expr
.get_finish ());
2621 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
, complain
);
2622 /* TODO: build_x_unary_op doesn't always honor the location. */
2623 result
.set_location (combined_loc
);
2625 tree result_ovl
, expr_ovl
;
2627 if (!(complain
& tf_warning
))
2630 result_ovl
= result
;
2633 if (!processing_template_decl
)
2634 expr_ovl
= cp_fully_fold (expr_ovl
);
2636 if (!CONSTANT_CLASS_P (expr_ovl
)
2637 || TREE_OVERFLOW_P (expr_ovl
))
2640 if (!processing_template_decl
)
2641 result_ovl
= cp_fully_fold (result_ovl
);
2643 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
2644 overflow_warning (combined_loc
, result_ovl
);
2649 /* Finish a compound-literal expression. TYPE is the type to which
2650 the CONSTRUCTOR in COMPOUND_LITERAL is being cast. */
2653 finish_compound_literal (tree type
, tree compound_literal
,
2654 tsubst_flags_t complain
)
2656 if (type
== error_mark_node
)
2657 return error_mark_node
;
2659 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2662 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2664 return cp_build_c_cast (type
, compound_literal
, complain
);
2667 if (!TYPE_OBJ_P (type
))
2669 if (complain
& tf_error
)
2670 error ("compound literal of non-object type %qT", type
);
2671 return error_mark_node
;
2674 if (tree anode
= type_uses_auto (type
))
2675 if (CLASS_PLACEHOLDER_TEMPLATE (anode
))
2676 type
= do_auto_deduction (type
, compound_literal
, anode
, complain
,
2679 if (processing_template_decl
)
2681 TREE_TYPE (compound_literal
) = type
;
2682 /* Mark the expression as a compound literal. */
2683 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
2684 return compound_literal
;
2687 type
= complete_type (type
);
2689 if (TYPE_NON_AGGREGATE_CLASS (type
))
2691 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2692 everywhere that deals with function arguments would be a pain, so
2693 just wrap it in a TREE_LIST. The parser set a flag so we know
2694 that it came from T{} rather than T({}). */
2695 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2696 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2697 return build_functional_cast (type
, compound_literal
, complain
);
2700 if (TREE_CODE (type
) == ARRAY_TYPE
2701 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2702 return error_mark_node
;
2703 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2704 if (SCALAR_TYPE_P (type
)
2705 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
)
2706 && !check_narrowing (type
, compound_literal
, complain
))
2707 return error_mark_node
;
2708 if (TREE_CODE (type
) == ARRAY_TYPE
2709 && TYPE_DOMAIN (type
) == NULL_TREE
)
2711 cp_complete_array_type_or_error (&type
, compound_literal
,
2713 if (type
== error_mark_node
)
2714 return error_mark_node
;
2716 compound_literal
= digest_init_flags (type
, compound_literal
, LOOKUP_NORMAL
,
2718 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
2719 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
2721 /* Put static/constant array temporaries in static variables. */
2722 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
2723 && TREE_CODE (type
) == ARRAY_TYPE
2724 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
2725 && initializer_constant_valid_p (compound_literal
, type
))
2727 tree decl
= create_temporary_var (type
);
2728 DECL_INITIAL (decl
) = compound_literal
;
2729 TREE_STATIC (decl
) = 1;
2730 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
2732 /* 5.19 says that a constant expression can include an
2733 lvalue-rvalue conversion applied to "a glvalue of literal type
2734 that refers to a non-volatile temporary object initialized
2735 with a constant expression". Rather than try to communicate
2736 that this VAR_DECL is a temporary, just mark it constexpr. */
2737 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
2738 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
2739 TREE_CONSTANT (decl
) = true;
2741 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
2742 decl
= pushdecl_top_level (decl
);
2743 DECL_NAME (decl
) = make_anon_name ();
2744 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
2745 /* Make sure the destructor is callable. */
2746 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
2747 if (clean
== error_mark_node
)
2748 return error_mark_node
;
2752 /* Represent other compound literals with TARGET_EXPR so we produce
2753 an lvalue, but can elide copies. */
2754 if (!VECTOR_TYPE_P (type
))
2755 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
2757 return compound_literal
;
2760 /* Return the declaration for the function-name variable indicated by
2764 finish_fname (tree id
)
2768 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
2769 if (processing_template_decl
&& current_function_decl
2770 && decl
!= error_mark_node
)
2771 decl
= DECL_NAME (decl
);
2775 /* Finish a translation unit. */
2778 finish_translation_unit (void)
2780 /* In case there were missing closebraces,
2781 get us back to the global binding level. */
2783 while (current_namespace
!= global_namespace
)
2786 /* Do file scope __FUNCTION__ et al. */
2787 finish_fname_decls ();
2790 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2791 Returns the parameter. */
2794 finish_template_type_parm (tree aggr
, tree identifier
)
2796 if (aggr
!= class_type_node
)
2798 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
2799 aggr
= class_type_node
;
2802 return build_tree_list (aggr
, identifier
);
2805 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2806 Returns the parameter. */
2809 finish_template_template_parm (tree aggr
, tree identifier
)
2811 tree decl
= build_decl (input_location
,
2812 TYPE_DECL
, identifier
, NULL_TREE
);
2814 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
2815 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
2816 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
2817 DECL_ARTIFICIAL (decl
) = 1;
2819 // Associate the constraints with the underlying declaration,
2820 // not the template.
2821 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
2822 tree constr
= build_constraints (reqs
, NULL_TREE
);
2823 set_constraints (decl
, constr
);
2825 end_template_decl ();
2827 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
2829 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
2830 /*is_primary=*/true, /*is_partial=*/false,
2833 return finish_template_type_parm (aggr
, tmpl
);
2836 /* ARGUMENT is the default-argument value for a template template
2837 parameter. If ARGUMENT is invalid, issue error messages and return
2838 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2841 check_template_template_default_arg (tree argument
)
2843 if (TREE_CODE (argument
) != TEMPLATE_DECL
2844 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
2845 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
2847 if (TREE_CODE (argument
) == TYPE_DECL
)
2848 error ("invalid use of type %qT as a default value for a template "
2849 "template-parameter", TREE_TYPE (argument
));
2851 error ("invalid default argument for a template template parameter");
2852 return error_mark_node
;
2858 /* Begin a class definition, as indicated by T. */
2861 begin_class_definition (tree t
)
2863 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
2864 return error_mark_node
;
2866 if (processing_template_parmlist
)
2868 error ("definition of %q#T inside template parameter list", t
);
2869 return error_mark_node
;
2872 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
2873 are passed the same as decimal scalar types. */
2874 if (TREE_CODE (t
) == RECORD_TYPE
2875 && !processing_template_decl
)
2877 tree ns
= TYPE_CONTEXT (t
);
2878 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
2879 && DECL_CONTEXT (ns
) == std_node
2881 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns
)), "decimal"))
2883 const char *n
= TYPE_NAME_STRING (t
);
2884 if ((strcmp (n
, "decimal32") == 0)
2885 || (strcmp (n
, "decimal64") == 0)
2886 || (strcmp (n
, "decimal128") == 0))
2887 TYPE_TRANSPARENT_AGGR (t
) = 1;
2891 /* A non-implicit typename comes from code like:
2893 template <typename T> struct A {
2894 template <typename U> struct A<T>::B ...
2896 This is erroneous. */
2897 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
2899 error ("invalid definition of qualified type %qT", t
);
2900 t
= error_mark_node
;
2903 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
2905 t
= make_class_type (RECORD_TYPE
);
2906 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
2909 if (TYPE_BEING_DEFINED (t
))
2911 t
= make_class_type (TREE_CODE (t
));
2912 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
2914 maybe_process_partial_specialization (t
);
2916 TYPE_BEING_DEFINED (t
) = 1;
2917 class_binding_level
->defining_class_p
= 1;
2919 if (flag_pack_struct
)
2922 TYPE_PACKED (t
) = 1;
2923 /* Even though the type is being defined for the first time
2924 here, there might have been a forward declaration, so there
2925 might be cv-qualified variants of T. */
2926 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
2927 TYPE_PACKED (v
) = 1;
2929 /* Reset the interface data, at the earliest possible
2930 moment, as it might have been set via a class foo;
2932 if (! TYPE_UNNAMED_P (t
))
2934 struct c_fileinfo
*finfo
= \
2935 get_fileinfo (LOCATION_FILE (input_location
));
2936 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
2937 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2938 (t
, finfo
->interface_unknown
);
2940 reset_specialization();
2942 /* Make a declaration for this class in its own scope. */
2943 build_self_reference ();
2948 /* Finish the member declaration given by DECL. */
2951 finish_member_declaration (tree decl
)
2953 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
2956 if (decl
== void_type_node
)
2957 /* The COMPONENT was a friend, not a member, and so there's
2958 nothing for us to do. */
2961 /* We should see only one DECL at a time. */
2962 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
2964 /* Set up access control for DECL. */
2966 = (current_access_specifier
== access_private_node
);
2967 TREE_PROTECTED (decl
)
2968 = (current_access_specifier
== access_protected_node
);
2969 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
2971 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
2972 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
2975 /* Mark the DECL as a member of the current class, unless it's
2976 a member of an enumeration. */
2977 if (TREE_CODE (decl
) != CONST_DECL
)
2978 DECL_CONTEXT (decl
) = current_class_type
;
2980 /* Check for bare parameter packs in the member variable declaration. */
2981 if (TREE_CODE (decl
) == FIELD_DECL
)
2983 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
2984 TREE_TYPE (decl
) = error_mark_node
;
2985 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
2986 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
2991 A C language linkage is ignored for the names of class members
2992 and the member function type of class member functions. */
2993 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
2994 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
2996 /* Put functions on the TYPE_METHODS list and everything else on the
2997 TYPE_FIELDS list. Note that these are built up in reverse order.
2998 We reverse them (to obtain declaration order) in finish_struct. */
2999 if (DECL_DECLARES_FUNCTION_P (decl
))
3001 /* We also need to add this function to the
3002 CLASSTYPE_METHOD_VEC. */
3003 if (add_method (current_class_type
, decl
, NULL_TREE
))
3005 gcc_assert (TYPE_MAIN_VARIANT (current_class_type
) == current_class_type
);
3006 DECL_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
3007 TYPE_METHODS (current_class_type
) = decl
;
3009 maybe_add_class_template_decl_list (current_class_type
, decl
,
3013 /* Enter the DECL into the scope of the class, if the class
3014 isn't a closure (whose fields are supposed to be unnamed). */
3015 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3016 || pushdecl_class_level (decl
))
3018 if (TREE_CODE (decl
) == USING_DECL
)
3020 /* For now, ignore class-scope USING_DECLS, so that
3021 debugging backends do not see them. */
3022 DECL_IGNORED_P (decl
) = 1;
3025 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3026 go at the beginning. The reason is that lookup_field_1
3027 searches the list in order, and we want a field name to
3028 override a type name so that the "struct stat hack" will
3029 work. In particular:
3031 struct S { enum E { }; int E } s;
3034 is valid. In addition, the FIELD_DECLs must be maintained in
3035 declaration order so that class layout works as expected.
3036 However, we don't need that order until class layout, so we
3037 save a little time by putting FIELD_DECLs on in reverse order
3038 here, and then reversing them in finish_struct_1. (We could
3039 also keep a pointer to the correct insertion points in the
3042 if (TREE_CODE (decl
) == TYPE_DECL
)
3043 TYPE_FIELDS (current_class_type
)
3044 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3047 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3048 TYPE_FIELDS (current_class_type
) = decl
;
3051 maybe_add_class_template_decl_list (current_class_type
, decl
,
3056 /* Finish processing a complete template declaration. The PARMS are
3057 the template parameters. */
3060 finish_template_decl (tree parms
)
3063 end_template_decl ();
3065 end_specialization ();
3068 // Returns the template type of the class scope being entered. If we're
3069 // entering a constrained class scope. TYPE is the class template
3070 // scope being entered and we may need to match the intended type with
3071 // a constrained specialization. For example:
3073 // template<Object T>
3074 // struct S { void f(); }; #1
3076 // template<Object T>
3077 // void S<T>::f() { } #2
3079 // We check, in #2, that S<T> refers precisely to the type declared by
3080 // #1 (i.e., that the constraints match). Note that the following should
3081 // be an error since there is no specialization of S<T> that is
3082 // unconstrained, but this is not diagnosed here.
3084 // template<typename T>
3085 // void S<T>::f() { }
3087 // We cannot diagnose this problem here since this function also matches
3088 // qualified template names that are not part of a definition. For example:
3090 // template<Integral T, Floating_point U>
3091 // typename pair<T, U>::first_type void f(T, U);
3093 // Here, it is unlikely that there is a partial specialization of
3094 // pair constrained for for Integral and Floating_point arguments.
3096 // The general rule is: if a constrained specialization with matching
3097 // constraints is found return that type. Also note that if TYPE is not a
3098 // class-type (e.g. a typename type), then no fixup is needed.
3101 fixup_template_type (tree type
)
3103 // Find the template parameter list at the a depth appropriate to
3104 // the scope we're trying to enter.
3105 tree parms
= current_template_parms
;
3106 int depth
= template_class_depth (type
);
3107 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3108 parms
= TREE_CHAIN (parms
);
3111 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3112 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3114 // Search for a specialization whose type and constraints match.
3115 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3116 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3119 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3121 // If the type and constraints match a specialization, then we
3122 // are entering that type.
3123 if (same_type_p (type
, TREE_TYPE (specs
))
3124 && equivalent_constraints (cur_constr
, spec_constr
))
3125 return TREE_TYPE (specs
);
3126 specs
= TREE_CHAIN (specs
);
3129 // If no specialization matches, then must return the type
3130 // previously found.
3134 /* Finish processing a template-id (which names a type) of the form
3135 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3136 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3137 the scope of template-id indicated. */
3140 finish_template_type (tree name
, tree args
, int entering_scope
)
3144 type
= lookup_template_class (name
, args
,
3145 NULL_TREE
, NULL_TREE
, entering_scope
,
3146 tf_warning_or_error
| tf_user
);
3148 /* If we might be entering the scope of a partial specialization,
3149 find the one with the right constraints. */
3152 && CLASS_TYPE_P (type
)
3153 && dependent_type_p (type
)
3154 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3155 type
= fixup_template_type (type
);
3157 if (type
== error_mark_node
)
3159 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3160 return TYPE_STUB_DECL (type
);
3162 return TYPE_NAME (type
);
3165 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3166 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3167 BASE_CLASS, or NULL_TREE if an error occurred. The
3168 ACCESS_SPECIFIER is one of
3169 access_{default,public,protected_private}_node. For a virtual base
3170 we set TREE_TYPE. */
3173 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3177 if (base
== error_mark_node
)
3179 error ("invalid base-class specification");
3182 else if (! MAYBE_CLASS_TYPE_P (base
))
3184 error ("%qT is not a class type", base
);
3189 if (cp_type_quals (base
) != 0)
3191 /* DR 484: Can a base-specifier name a cv-qualified
3193 base
= TYPE_MAIN_VARIANT (base
);
3195 result
= build_tree_list (access
, base
);
3197 TREE_TYPE (result
) = integer_type_node
;
3203 /* If FNS is a member function, a set of member functions, or a
3204 template-id referring to one or more member functions, return a
3205 BASELINK for FNS, incorporating the current access context.
3206 Otherwise, return FNS unchanged. */
3209 baselink_for_fns (tree fns
)
3214 if (BASELINK_P (fns
)
3215 || error_operand_p (fns
))
3218 scope
= ovl_scope (fns
);
3219 if (!CLASS_TYPE_P (scope
))
3222 cl
= currently_open_derived_class (scope
);
3225 cl
= TYPE_BINFO (cl
);
3226 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3229 /* Returns true iff DECL is a variable from a function outside
3233 outer_var_p (tree decl
)
3235 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3236 && DECL_FUNCTION_SCOPE_P (decl
)
3237 && (DECL_CONTEXT (decl
) != current_function_decl
3238 || parsing_nsdmi ()));
3241 /* As above, but also checks that DECL is automatic. */
3244 outer_automatic_var_p (tree decl
)
3246 return (outer_var_p (decl
)
3247 && !TREE_STATIC (decl
));
3250 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3251 rewrite it for lambda capture. */
3254 process_outer_var_ref (tree decl
, tsubst_flags_t complain
)
3256 if (cp_unevaluated_operand
)
3257 /* It's not a use (3.2) if we're in an unevaluated context. */
3259 if (decl
== error_mark_node
)
3262 tree context
= DECL_CONTEXT (decl
);
3263 tree containing_function
= current_function_decl
;
3264 tree lambda_stack
= NULL_TREE
;
3265 tree lambda_expr
= NULL_TREE
;
3266 tree initializer
= convert_from_reference (decl
);
3268 /* Mark it as used now even if the use is ill-formed. */
3269 if (!mark_used (decl
, complain
))
3270 return error_mark_node
;
3272 bool saw_generic_lambda
= false;
3273 if (parsing_nsdmi ())
3274 containing_function
= NULL_TREE
;
3276 /* If we are in a lambda function, we can move out until we hit
3278 2. a non-lambda function, or
3279 3. a non-default capturing lambda function. */
3280 while (context
!= containing_function
3281 && LAMBDA_FUNCTION_P (containing_function
))
3283 tree closure
= DECL_CONTEXT (containing_function
);
3284 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3286 if (generic_lambda_fn_p (containing_function
))
3287 saw_generic_lambda
= true;
3289 if (TYPE_CLASS_SCOPE_P (closure
))
3290 /* A lambda in an NSDMI (c++/64496). */
3293 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3297 lambda_stack
= tree_cons (NULL_TREE
,
3302 = decl_function_context (containing_function
);
3305 /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
3306 support for an approach in which a reference to a local
3307 [constant] automatic variable in a nested class or lambda body
3308 would enter the expression as an rvalue, which would reduce
3309 the complexity of the problem"
3311 FIXME update for final resolution of core issue 696. */
3312 if (decl_maybe_constant_var_p (decl
))
3314 if (processing_template_decl
&& !saw_generic_lambda
)
3315 /* In a non-generic lambda within a template, wait until instantiation
3316 time to decide whether to capture. For a generic lambda, we can't
3317 wait until we instantiate the op() because the closure class is
3318 already defined at that point. FIXME to get the semantics exactly
3319 right we need to partially-instantiate the lambda body so the only
3320 dependencies left are on the generic parameters themselves. This
3321 probably means moving away from our current model of lambdas in
3322 templates (instantiating the closure type) to one based on creating
3323 the closure type when instantiating the lambda context. That is
3324 probably also the way to handle lambdas within pack expansions. */
3326 else if (decl_constant_var_p (decl
))
3328 tree t
= maybe_constant_value (convert_from_reference (decl
));
3329 if (TREE_CONSTANT (t
))
3334 if (lambda_expr
&& VAR_P (decl
)
3335 && DECL_ANON_UNION_VAR_P (decl
))
3337 if (complain
& tf_error
)
3338 error ("cannot capture member %qD of anonymous union", decl
);
3339 return error_mark_node
;
3341 if (context
== containing_function
)
3343 decl
= add_default_capture (lambda_stack
,
3344 /*id=*/DECL_NAME (decl
),
3347 else if (lambda_expr
)
3349 if (complain
& tf_error
)
3351 error ("%qD is not captured", decl
);
3352 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3353 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3355 inform (location_of (closure
),
3356 "the lambda has no capture-default");
3357 else if (TYPE_CLASS_SCOPE_P (closure
))
3358 inform (0, "lambda in local class %q+T cannot "
3359 "capture variables from the enclosing context",
3360 TYPE_CONTEXT (closure
));
3361 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3363 return error_mark_node
;
3367 if (complain
& tf_error
)
3369 ? G_("use of local variable with automatic storage from containing function")
3370 : G_("use of parameter from containing function"));
3371 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3372 return error_mark_node
;
3377 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3378 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3379 if non-NULL, is the type or namespace used to explicitly qualify
3380 ID_EXPRESSION. DECL is the entity to which that name has been
3383 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3384 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3385 be set to true if this expression isn't permitted in a
3386 constant-expression, but it is otherwise not set by this function.
3387 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3388 constant-expression, but a non-constant expression is also
3391 DONE is true if this expression is a complete postfix-expression;
3392 it is false if this expression is followed by '->', '[', '(', etc.
3393 ADDRESS_P is true iff this expression is the operand of '&'.
3394 TEMPLATE_P is true iff the qualified-id was of the form
3395 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3396 appears as a template argument.
3398 If an error occurs, and it is the kind of error that might cause
3399 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3400 is the caller's responsibility to issue the message. *ERROR_MSG
3401 will be a string with static storage duration, so the caller need
3404 Return an expression for the entity, after issuing appropriate
3405 diagnostics. This function is also responsible for transforming a
3406 reference to a non-static member into a COMPONENT_REF that makes
3407 the use of "this" explicit.
3409 Upon return, *IDK will be filled in appropriately. */
3411 finish_id_expression (tree id_expression
,
3415 bool integral_constant_expression_p
,
3416 bool allow_non_integral_constant_expression_p
,
3417 bool *non_integral_constant_expression_p
,
3421 bool template_arg_p
,
3422 const char **error_msg
,
3423 location_t location
)
3425 decl
= strip_using_decl (decl
);
3427 /* Initialize the output parameters. */
3428 *idk
= CP_ID_KIND_NONE
;
3431 if (id_expression
== error_mark_node
)
3432 return error_mark_node
;
3433 /* If we have a template-id, then no further lookup is
3434 required. If the template-id was for a template-class, we
3435 will sometimes have a TYPE_DECL at this point. */
3436 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3437 || TREE_CODE (decl
) == TYPE_DECL
)
3439 /* Look up the name. */
3442 if (decl
== error_mark_node
)
3444 /* Name lookup failed. */
3447 || (!dependent_type_p (scope
)
3448 && !(identifier_p (id_expression
)
3449 && IDENTIFIER_TYPENAME_P (id_expression
)
3450 && dependent_type_p (TREE_TYPE (id_expression
))))))
3452 /* If the qualifying type is non-dependent (and the name
3453 does not name a conversion operator to a dependent
3454 type), issue an error. */
3455 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3456 return error_mark_node
;
3460 /* It may be resolved via Koenig lookup. */
3461 *idk
= CP_ID_KIND_UNQUALIFIED
;
3462 return id_expression
;
3465 decl
= id_expression
;
3467 /* If DECL is a variable that would be out of scope under
3468 ANSI/ISO rules, but in scope in the ARM, name lookup
3469 will succeed. Issue a diagnostic here. */
3471 decl
= check_for_out_of_scope_variable (decl
);
3473 /* Remember that the name was used in the definition of
3474 the current class so that we can check later to see if
3475 the meaning would have been different after the class
3476 was entirely defined. */
3477 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3478 maybe_note_name_used_in_class (id_expression
, decl
);
3480 /* A use in unevaluated operand might not be instantiated appropriately
3481 if tsubst_copy builds a dummy parm, or if we never instantiate a
3482 generic lambda, so mark it now. */
3483 if (processing_template_decl
&& cp_unevaluated_operand
)
3484 mark_type_use (decl
);
3486 /* Disallow uses of local variables from containing functions, except
3487 within lambda-expressions. */
3488 if (outer_automatic_var_p (decl
))
3490 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3491 if (decl
== error_mark_node
)
3492 return error_mark_node
;
3495 /* Also disallow uses of function parameters outside the function
3496 body, except inside an unevaluated context (i.e. decltype). */
3497 if (TREE_CODE (decl
) == PARM_DECL
3498 && DECL_CONTEXT (decl
) == NULL_TREE
3499 && !cp_unevaluated_operand
)
3501 *error_msg
= "use of parameter outside function body";
3502 return error_mark_node
;
3506 /* If we didn't find anything, or what we found was a type,
3507 then this wasn't really an id-expression. */
3508 if (TREE_CODE (decl
) == TEMPLATE_DECL
3509 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3511 *error_msg
= "missing template arguments";
3512 return error_mark_node
;
3514 else if (TREE_CODE (decl
) == TYPE_DECL
3515 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3517 *error_msg
= "expected primary-expression";
3518 return error_mark_node
;
3521 /* If the name resolved to a template parameter, there is no
3522 need to look it up again later. */
3523 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3524 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3528 *idk
= CP_ID_KIND_NONE
;
3529 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3530 decl
= TEMPLATE_PARM_DECL (decl
);
3531 r
= convert_from_reference (DECL_INITIAL (decl
));
3533 if (integral_constant_expression_p
3534 && !dependent_type_p (TREE_TYPE (decl
))
3535 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3537 if (!allow_non_integral_constant_expression_p
)
3538 error ("template parameter %qD of type %qT is not allowed in "
3539 "an integral constant expression because it is not of "
3540 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3541 *non_integral_constant_expression_p
= true;
3547 bool dependent_p
= type_dependent_expression_p (decl
);
3549 /* If the declaration was explicitly qualified indicate
3550 that. The semantics of `A::f(3)' are different than
3551 `f(3)' if `f' is virtual. */
3553 ? CP_ID_KIND_QUALIFIED
3554 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3555 ? CP_ID_KIND_TEMPLATE_ID
3557 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3558 : CP_ID_KIND_UNQUALIFIED
)));
3560 /* If the name was dependent on a template parameter, we will
3561 resolve the name at instantiation time. */
3565 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
3566 /* Dependent type attributes on the decl mean that the TREE_TYPE is
3567 wrong, so just return the identifier. */
3568 return id_expression
;
3570 /* If we found a variable, then name lookup during the
3571 instantiation will always resolve to the same VAR_DECL
3572 (or an instantiation thereof). */
3574 || TREE_CODE (decl
) == CONST_DECL
3575 || TREE_CODE (decl
) == PARM_DECL
)
3578 return convert_from_reference (decl
);
3581 /* Create a SCOPE_REF for qualified names, if the scope is
3587 if (address_p
&& done
)
3588 decl
= finish_qualified_id_expr (scope
, decl
,
3592 tf_warning_or_error
);
3595 tree type
= NULL_TREE
;
3596 if (DECL_P (decl
) && !dependent_scope_p (scope
))
3597 type
= TREE_TYPE (decl
);
3598 decl
= build_qualified_name (type
,
3604 if (TREE_TYPE (decl
))
3605 decl
= convert_from_reference (decl
);
3608 /* A TEMPLATE_ID already contains all the information we
3610 if (TREE_CODE (id_expression
) == TEMPLATE_ID_EXPR
)
3611 return id_expression
;
3612 /* The same is true for FIELD_DECL, but we also need to
3613 make sure that the syntax is correct. */
3614 else if (TREE_CODE (decl
) == FIELD_DECL
)
3616 /* Since SCOPE is NULL here, this is an unqualified name.
3617 Access checking has been performed during name lookup
3618 already. Turn off checking to avoid duplicate errors. */
3619 push_deferring_access_checks (dk_no_check
);
3620 decl
= finish_non_static_data_member
3622 /*qualifying_scope=*/NULL_TREE
);
3623 pop_deferring_access_checks ();
3626 return id_expression
;
3629 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3631 error ("use of namespace %qD as expression", decl
);
3632 return error_mark_node
;
3634 else if (DECL_CLASS_TEMPLATE_P (decl
))
3636 error ("use of class template %qT as expression", decl
);
3637 return error_mark_node
;
3639 else if (TREE_CODE (decl
) == TREE_LIST
)
3641 /* Ambiguous reference to base members. */
3642 error ("request for member %qD is ambiguous in "
3643 "multiple inheritance lattice", id_expression
);
3644 print_candidates (decl
);
3645 return error_mark_node
;
3648 /* Mark variable-like entities as used. Functions are similarly
3649 marked either below or after overload resolution. */
3651 || TREE_CODE (decl
) == PARM_DECL
3652 || TREE_CODE (decl
) == CONST_DECL
3653 || TREE_CODE (decl
) == RESULT_DECL
)
3654 && !mark_used (decl
))
3655 return error_mark_node
;
3657 /* Only certain kinds of names are allowed in constant
3658 expression. Template parameters have already
3659 been handled above. */
3660 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
3687 && variable_template_p (TREE_OPERAND (decl
, 0)))
3689 decl
= finish_template_variable (decl
);
3691 decl
= convert_from_reference (decl
);
3695 decl
= (adjust_result_of_qualified_name_lookup
3696 (decl
, scope
, current_nonlambda_class_type()));
3698 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3702 decl
= finish_qualified_id_expr (scope
,
3708 tf_warning_or_error
);
3710 decl
= convert_from_reference (decl
);
3712 else if (TREE_CODE (decl
) == FIELD_DECL
)
3714 /* Since SCOPE is NULL here, this is an unqualified name.
3715 Access checking has been performed during name lookup
3716 already. Turn off checking to avoid duplicate errors. */
3717 push_deferring_access_checks (dk_no_check
);
3718 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3719 /*qualifying_scope=*/NULL_TREE
);
3720 pop_deferring_access_checks ();
3722 else if (is_overloaded_fn (decl
))
3726 first_fn
= get_first_fn (decl
);
3727 if (TREE_CODE (first_fn
) == TEMPLATE_DECL
)
3728 first_fn
= DECL_TEMPLATE_RESULT (first_fn
);
3730 if (!really_overloaded_fn (decl
)
3731 && !mark_used (first_fn
))
3732 return error_mark_node
;
3735 && TREE_CODE (first_fn
) == FUNCTION_DECL
3736 && DECL_FUNCTION_MEMBER_P (first_fn
)
3737 && !shared_member_p (decl
))
3739 /* A set of member functions. */
3740 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
3741 return finish_class_member_access_expr (decl
, id_expression
,
3742 /*template_p=*/false,
3743 tf_warning_or_error
);
3746 decl
= baselink_for_fns (decl
);
3750 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
3751 && DECL_CLASS_SCOPE_P (decl
))
3753 tree context
= context_for_name_lookup (decl
);
3754 if (context
!= current_class_type
)
3756 tree path
= currently_open_derived_class (context
);
3757 perform_or_defer_access_check (TYPE_BINFO (path
),
3759 tf_warning_or_error
);
3763 decl
= convert_from_reference (decl
);
3767 return cp_expr (decl
, location
);
3770 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3771 use as a type-specifier. */
3774 finish_typeof (tree expr
)
3778 if (type_dependent_expression_p (expr
))
3780 type
= cxx_make_type (TYPEOF_TYPE
);
3781 TYPEOF_TYPE_EXPR (type
) = expr
;
3782 SET_TYPE_STRUCTURAL_EQUALITY (type
);
3787 expr
= mark_type_use (expr
);
3789 type
= unlowered_expr_type (expr
);
3791 if (!type
|| type
== unknown_type_node
)
3793 error ("type of %qE is unknown", expr
);
3794 return error_mark_node
;
3800 /* Implement the __underlying_type keyword: Return the underlying
3801 type of TYPE, suitable for use as a type-specifier. */
3804 finish_underlying_type (tree type
)
3806 tree underlying_type
;
3808 if (processing_template_decl
)
3810 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
3811 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
3812 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
3814 return underlying_type
;
3817 complete_type (type
);
3819 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
3821 error ("%qT is not an enumeration type", type
);
3822 return error_mark_node
;
3825 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
3827 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
3828 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
3829 See finish_enum_value_list for details. */
3830 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
3832 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
3833 TYPE_UNSIGNED (underlying_type
));
3835 return underlying_type
;
3838 /* Implement the __direct_bases keyword: Return the direct base classes
3842 calculate_direct_bases (tree type
)
3844 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3845 tree bases_vec
= NULL_TREE
;
3846 vec
<tree
, va_gc
> *base_binfos
;
3850 complete_type (type
);
3852 if (!NON_UNION_CLASS_TYPE_P (type
))
3853 return make_tree_vec (0);
3855 base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
3857 /* Virtual bases are initialized first */
3858 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3860 if (BINFO_VIRTUAL_P (binfo
))
3862 vec_safe_push (vector
, binfo
);
3866 /* Now non-virtuals */
3867 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3869 if (!BINFO_VIRTUAL_P (binfo
))
3871 vec_safe_push (vector
, binfo
);
3876 bases_vec
= make_tree_vec (vector
->length ());
3878 for (i
= 0; i
< vector
->length (); ++i
)
3880 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
3885 /* Implement the __bases keyword: Return the base classes
3888 /* Find morally non-virtual base classes by walking binfo hierarchy */
3889 /* Virtual base classes are handled separately in finish_bases */
3892 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
3894 /* Don't walk bases of virtual bases */
3895 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
3899 dfs_calculate_bases_post (tree binfo
, void *data_
)
3901 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
3902 if (!BINFO_VIRTUAL_P (binfo
))
3904 vec_safe_push (*data
, BINFO_TYPE (binfo
));
3909 /* Calculates the morally non-virtual base classes of a class */
3910 static vec
<tree
, va_gc
> *
3911 calculate_bases_helper (tree type
)
3913 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3915 /* Now add non-virtual base classes in order of construction */
3916 if (TYPE_BINFO (type
))
3917 dfs_walk_all (TYPE_BINFO (type
),
3918 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
3923 calculate_bases (tree type
)
3925 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3926 tree bases_vec
= NULL_TREE
;
3928 vec
<tree
, va_gc
> *vbases
;
3929 vec
<tree
, va_gc
> *nonvbases
;
3932 complete_type (type
);
3934 if (!NON_UNION_CLASS_TYPE_P (type
))
3935 return make_tree_vec (0);
3937 /* First go through virtual base classes */
3938 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
3939 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
3941 vec
<tree
, va_gc
> *vbase_bases
;
3942 vbase_bases
= calculate_bases_helper (BINFO_TYPE (binfo
));
3943 vec_safe_splice (vector
, vbase_bases
);
3944 release_tree_vector (vbase_bases
);
3947 /* Now for the non-virtual bases */
3948 nonvbases
= calculate_bases_helper (type
);
3949 vec_safe_splice (vector
, nonvbases
);
3950 release_tree_vector (nonvbases
);
3952 /* Note that during error recovery vector->length can even be zero. */
3953 if (vector
->length () > 1)
3955 /* Last element is entire class, so don't copy */
3956 bases_vec
= make_tree_vec (vector
->length() - 1);
3958 for (i
= 0; i
< vector
->length () - 1; ++i
)
3959 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
3962 bases_vec
= make_tree_vec (0);
3964 release_tree_vector (vector
);
3969 finish_bases (tree type
, bool direct
)
3971 tree bases
= NULL_TREE
;
3973 if (!processing_template_decl
)
3975 /* Parameter packs can only be used in templates */
3976 error ("Parameter pack __bases only valid in template declaration");
3977 return error_mark_node
;
3980 bases
= cxx_make_type (BASES
);
3981 BASES_TYPE (bases
) = type
;
3982 BASES_DIRECT (bases
) = direct
;
3983 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
3988 /* Perform C++-specific checks for __builtin_offsetof before calling
3992 finish_offsetof (tree expr
, location_t loc
)
3994 /* If we're processing a template, we can't finish the semantics yet.
3995 Otherwise we can fold the entire expression now. */
3996 if (processing_template_decl
)
3998 expr
= build1 (OFFSETOF_EXPR
, size_type_node
, expr
);
3999 SET_EXPR_LOCATION (expr
, loc
);
4003 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4005 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4006 TREE_OPERAND (expr
, 2));
4007 return error_mark_node
;
4009 if (TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
4010 || TREE_CODE (TREE_TYPE (expr
)) == METHOD_TYPE
4011 || TREE_TYPE (expr
) == unknown_type_node
)
4013 if (INDIRECT_REF_P (expr
))
4014 error ("second operand of %<offsetof%> is neither a single "
4015 "identifier nor a sequence of member accesses and "
4016 "array references");
4019 if (TREE_CODE (expr
) == COMPONENT_REF
4020 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4021 expr
= TREE_OPERAND (expr
, 1);
4022 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4024 return error_mark_node
;
4026 if (REFERENCE_REF_P (expr
))
4027 expr
= TREE_OPERAND (expr
, 0);
4028 if (TREE_CODE (expr
) == COMPONENT_REF
)
4030 tree object
= TREE_OPERAND (expr
, 0);
4031 if (!complete_type_or_else (TREE_TYPE (object
), object
))
4032 return error_mark_node
;
4033 if (warn_invalid_offsetof
4034 && CLASS_TYPE_P (TREE_TYPE (object
))
4035 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (object
))
4036 && cp_unevaluated_operand
== 0)
4037 pedwarn (loc
, OPT_Winvalid_offsetof
,
4038 "offsetof within non-standard-layout type %qT is undefined",
4039 TREE_TYPE (object
));
4041 return fold_offsetof (expr
);
4044 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4045 function is broken out from the above for the benefit of the tree-ssa
4049 simplify_aggr_init_expr (tree
*tp
)
4051 tree aggr_init_expr
= *tp
;
4053 /* Form an appropriate CALL_EXPR. */
4054 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4055 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4056 tree type
= TREE_TYPE (slot
);
4059 enum style_t
{ ctor
, arg
, pcc
} style
;
4061 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4063 #ifdef PCC_STATIC_STRUCT_RETURN
4069 gcc_assert (TREE_ADDRESSABLE (type
));
4073 call_expr
= build_call_array_loc (input_location
,
4074 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4076 aggr_init_expr_nargs (aggr_init_expr
),
4077 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4078 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4079 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4080 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4081 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4082 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4083 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4087 /* Replace the first argument to the ctor with the address of the
4089 cxx_mark_addressable (slot
);
4090 CALL_EXPR_ARG (call_expr
, 0) =
4091 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4093 else if (style
== arg
)
4095 /* Just mark it addressable here, and leave the rest to
4096 expand_call{,_inline}. */
4097 cxx_mark_addressable (slot
);
4098 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4099 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4101 else if (style
== pcc
)
4103 /* If we're using the non-reentrant PCC calling convention, then we
4104 need to copy the returned value out of the static buffer into the
4106 push_deferring_access_checks (dk_no_check
);
4107 call_expr
= build_aggr_init (slot
, call_expr
,
4108 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4109 tf_warning_or_error
);
4110 pop_deferring_access_checks ();
4111 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4114 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4116 tree init
= build_zero_init (type
, NULL_TREE
,
4117 /*static_storage_p=*/false);
4118 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4119 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4126 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4129 emit_associated_thunks (tree fn
)
4131 /* When we use vcall offsets, we emit thunks with the virtual
4132 functions to which they thunk. The whole point of vcall offsets
4133 is so that you can know statically the entire set of thunks that
4134 will ever be needed for a given virtual function, thereby
4135 enabling you to output all the thunks with the function itself. */
4136 if (DECL_VIRTUAL_P (fn
)
4137 /* Do not emit thunks for extern template instantiations. */
4138 && ! DECL_REALLY_EXTERN (fn
))
4142 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4144 if (!THUNK_ALIAS (thunk
))
4146 use_thunk (thunk
, /*emit_p=*/1);
4147 if (DECL_RESULT_THUNK_P (thunk
))
4151 for (probe
= DECL_THUNKS (thunk
);
4152 probe
; probe
= DECL_CHAIN (probe
))
4153 use_thunk (probe
, /*emit_p=*/1);
4157 gcc_assert (!DECL_THUNKS (thunk
));
4162 /* Generate RTL for FN. */
4165 expand_or_defer_fn_1 (tree fn
)
4167 /* When the parser calls us after finishing the body of a template
4168 function, we don't really want to expand the body. */
4169 if (processing_template_decl
)
4171 /* Normally, collection only occurs in rest_of_compilation. So,
4172 if we don't collect here, we never collect junk generated
4173 during the processing of templates until we hit a
4174 non-template function. It's not safe to do this inside a
4175 nested class, though, as the parser may have local state that
4176 is not a GC root. */
4177 if (!function_depth
)
4182 gcc_assert (DECL_SAVED_TREE (fn
));
4184 /* We make a decision about linkage for these functions at the end
4185 of the compilation. Until that point, we do not want the back
4186 end to output them -- but we do want it to see the bodies of
4187 these functions so that it can inline them as appropriate. */
4188 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4190 if (DECL_INTERFACE_KNOWN (fn
))
4191 /* We've already made a decision as to how this function will
4194 tentative_decl_linkage (fn
);
4196 import_export_decl (fn
);
4198 /* If the user wants us to keep all inline functions, then mark
4199 this function as needed so that finish_file will make sure to
4200 output it later. Similarly, all dllexport'd functions must
4201 be emitted; there may be callers in other DLLs. */
4202 if (DECL_DECLARED_INLINE_P (fn
)
4203 && !DECL_REALLY_EXTERN (fn
)
4204 && (flag_keep_inline_functions
4205 || (flag_keep_inline_dllexport
4206 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4209 DECL_EXTERNAL (fn
) = 0;
4213 /* If this is a constructor or destructor body, we have to clone
4215 if (maybe_clone_body (fn
))
4217 /* We don't want to process FN again, so pretend we've written
4218 it out, even though we haven't. */
4219 TREE_ASM_WRITTEN (fn
) = 1;
4220 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4221 if (!DECL_DECLARED_CONSTEXPR_P (fn
))
4222 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4226 /* There's no reason to do any of the work here if we're only doing
4227 semantic analysis; this code just generates RTL. */
4228 if (flag_syntax_only
)
4235 expand_or_defer_fn (tree fn
)
4237 if (expand_or_defer_fn_1 (fn
))
4241 /* Expand or defer, at the whim of the compilation unit manager. */
4242 cgraph_node::finalize_function (fn
, function_depth
> 1);
4243 emit_associated_thunks (fn
);
4251 nrv_data () : visited (37) {}
4255 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4258 /* Helper function for walk_tree, used by finalize_nrv below. */
4261 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4263 struct nrv_data
*dp
= (struct nrv_data
*)data
;
4266 /* No need to walk into types. There wouldn't be any need to walk into
4267 non-statements, except that we have to consider STMT_EXPRs. */
4270 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4271 but differs from using NULL_TREE in that it indicates that we care
4272 about the value of the RESULT_DECL. */
4273 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4274 TREE_OPERAND (*tp
, 0) = dp
->result
;
4275 /* Change all cleanups for the NRV to only run when an exception is
4277 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4278 && CLEANUP_DECL (*tp
) == dp
->var
)
4279 CLEANUP_EH_ONLY (*tp
) = 1;
4280 /* Replace the DECL_EXPR for the NRV with an initialization of the
4281 RESULT_DECL, if needed. */
4282 else if (TREE_CODE (*tp
) == DECL_EXPR
4283 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4286 if (DECL_INITIAL (dp
->var
)
4287 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4288 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4289 DECL_INITIAL (dp
->var
));
4291 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4292 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4293 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4296 /* And replace all uses of the NRV with the RESULT_DECL. */
4297 else if (*tp
== dp
->var
)
4300 /* Avoid walking into the same tree more than once. Unfortunately, we
4301 can't just use walk_tree_without duplicates because it would only call
4302 us for the first occurrence of dp->var in the function body. */
4303 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4309 /* Keep iterating. */
4313 /* Called from finish_function to implement the named return value
4314 optimization by overriding all the RETURN_EXPRs and pertinent
4315 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4316 RESULT_DECL for the function. */
4319 finalize_nrv (tree
*tp
, tree var
, tree result
)
4321 struct nrv_data data
;
4323 /* Copy name from VAR to RESULT. */
4324 DECL_NAME (result
) = DECL_NAME (var
);
4325 /* Don't forget that we take its address. */
4326 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4327 /* Finally set DECL_VALUE_EXPR to avoid assigning
4328 a stack slot at -O0 for the original var and debug info
4329 uses RESULT location for VAR. */
4330 SET_DECL_VALUE_EXPR (var
, result
);
4331 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4334 data
.result
= result
;
4335 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4338 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4341 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4342 bool need_copy_ctor
, bool need_copy_assignment
,
4345 int save_errorcount
= errorcount
;
4348 /* Always allocate 3 elements for simplicity. These are the
4349 function decls for the ctor, dtor, and assignment op.
4350 This layout is known to the three lang hooks,
4351 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4352 and cxx_omp_clause_assign_op. */
4353 info
= make_tree_vec (3);
4354 CP_OMP_CLAUSE_INFO (c
) = info
;
4356 if (need_default_ctor
|| need_copy_ctor
)
4358 if (need_default_ctor
)
4359 t
= get_default_ctor (type
);
4361 t
= get_copy_ctor (type
, tf_warning_or_error
);
4363 if (t
&& !trivial_fn_p (t
))
4364 TREE_VEC_ELT (info
, 0) = t
;
4367 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4368 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4370 if (need_copy_assignment
)
4372 t
= get_copy_assign (type
);
4374 if (t
&& !trivial_fn_p (t
))
4375 TREE_VEC_ELT (info
, 2) = t
;
4378 return errorcount
!= save_errorcount
;
4381 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4382 FIELD_DECL, otherwise return DECL itself. */
4385 omp_clause_decl_field (tree decl
)
4388 && DECL_HAS_VALUE_EXPR_P (decl
)
4389 && DECL_ARTIFICIAL (decl
)
4390 && DECL_LANG_SPECIFIC (decl
)
4391 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4393 tree f
= DECL_VALUE_EXPR (decl
);
4394 if (TREE_CODE (f
) == INDIRECT_REF
)
4395 f
= TREE_OPERAND (f
, 0);
4396 if (TREE_CODE (f
) == COMPONENT_REF
)
4398 f
= TREE_OPERAND (f
, 1);
4399 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4406 /* Adjust DECL if needed for printing using %qE. */
4409 omp_clause_printable_decl (tree decl
)
4411 tree t
= omp_clause_decl_field (decl
);
4417 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4418 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4422 omp_note_field_privatization (tree f
, tree t
)
4424 if (!omp_private_member_map
)
4425 omp_private_member_map
= new hash_map
<tree
, tree
>;
4426 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4430 omp_private_member_vec
.safe_push (f
);
4431 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4432 omp_private_member_vec
.safe_push (integer_zero_node
);
4436 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4440 omp_privatize_field (tree t
, bool shared
)
4442 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4443 if (m
== error_mark_node
)
4444 return error_mark_node
;
4445 if (!omp_private_member_map
&& !shared
)
4446 omp_private_member_map
= new hash_map
<tree
, tree
>;
4447 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
)
4449 gcc_assert (TREE_CODE (m
) == INDIRECT_REF
);
4450 m
= TREE_OPERAND (m
, 0);
4452 tree vb
= NULL_TREE
;
4453 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4456 v
= create_temporary_var (TREE_TYPE (m
));
4457 if (!DECL_LANG_SPECIFIC (v
))
4458 retrofit_lang_decl (v
);
4459 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4460 SET_DECL_VALUE_EXPR (v
, m
);
4461 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4463 omp_private_member_vec
.safe_push (t
);
4468 /* Helper function for handle_omp_array_sections. Called recursively
4469 to handle multiple array-section-subscripts. C is the clause,
4470 T current expression (initially OMP_CLAUSE_DECL), which is either
4471 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4472 expression if specified, TREE_VALUE length expression if specified,
4473 TREE_CHAIN is what it has been specified after, or some decl.
4474 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4475 set to true if any of the array-section-subscript could have length
4476 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4477 first array-section-subscript which is known not to have length
4479 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4480 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4481 all are or may have length of 1, array-section-subscript [:2] is the
4482 first one known not to have length 1. For array-section-subscript
4483 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4484 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4485 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4486 case though, as some lengths could be zero. */
4489 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4490 bool &maybe_zero_len
, unsigned int &first_non_one
,
4491 enum c_omp_region_type ort
)
4493 tree ret
, low_bound
, length
, type
;
4494 if (TREE_CODE (t
) != TREE_LIST
)
4496 if (error_operand_p (t
))
4497 return error_mark_node
;
4498 if (REFERENCE_REF_P (t
)
4499 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4500 t
= TREE_OPERAND (t
, 0);
4502 if (TREE_CODE (t
) == COMPONENT_REF
4504 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4505 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
4506 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
4507 && !type_dependent_expression_p (t
))
4509 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
4510 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
4512 error_at (OMP_CLAUSE_LOCATION (c
),
4513 "bit-field %qE in %qs clause",
4514 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4515 return error_mark_node
;
4517 while (TREE_CODE (t
) == COMPONENT_REF
)
4519 if (TREE_TYPE (TREE_OPERAND (t
, 0))
4520 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
4522 error_at (OMP_CLAUSE_LOCATION (c
),
4523 "%qE is a member of a union", t
);
4524 return error_mark_node
;
4526 t
= TREE_OPERAND (t
, 0);
4528 if (REFERENCE_REF_P (t
))
4529 t
= TREE_OPERAND (t
, 0);
4531 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
4533 if (processing_template_decl
)
4536 error_at (OMP_CLAUSE_LOCATION (c
),
4537 "%qD is not a variable in %qs clause", t
,
4538 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4540 error_at (OMP_CLAUSE_LOCATION (c
),
4541 "%qE is not a variable in %qs clause", t
,
4542 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4543 return error_mark_node
;
4545 else if (TREE_CODE (t
) == PARM_DECL
4546 && DECL_ARTIFICIAL (t
)
4547 && DECL_NAME (t
) == this_identifier
)
4549 error_at (OMP_CLAUSE_LOCATION (c
),
4550 "%<this%> allowed in OpenMP only in %<declare simd%>"
4552 return error_mark_node
;
4554 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4555 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
4557 error_at (OMP_CLAUSE_LOCATION (c
),
4558 "%qD is threadprivate variable in %qs clause", t
,
4559 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4560 return error_mark_node
;
4562 if (type_dependent_expression_p (ret
))
4564 ret
= convert_from_reference (ret
);
4568 if (ort
== C_ORT_OMP
4569 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4570 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
4571 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
4572 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4573 maybe_zero_len
, first_non_one
, ort
);
4574 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4577 type
= TREE_TYPE (ret
);
4578 low_bound
= TREE_PURPOSE (t
);
4579 length
= TREE_VALUE (t
);
4580 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4581 || (length
&& type_dependent_expression_p (length
)))
4584 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4585 return error_mark_node
;
4587 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4589 error_at (OMP_CLAUSE_LOCATION (c
),
4590 "low bound %qE of array section does not have integral type",
4592 return error_mark_node
;
4594 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4596 error_at (OMP_CLAUSE_LOCATION (c
),
4597 "length %qE of array section does not have integral type",
4599 return error_mark_node
;
4602 low_bound
= mark_rvalue_use (low_bound
);
4604 length
= mark_rvalue_use (length
);
4605 /* We need to reduce to real constant-values for checks below. */
4607 length
= fold_simple (length
);
4609 low_bound
= fold_simple (low_bound
);
4611 && TREE_CODE (low_bound
) == INTEGER_CST
4612 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4613 > TYPE_PRECISION (sizetype
))
4614 low_bound
= fold_convert (sizetype
, low_bound
);
4616 && TREE_CODE (length
) == INTEGER_CST
4617 && TYPE_PRECISION (TREE_TYPE (length
))
4618 > TYPE_PRECISION (sizetype
))
4619 length
= fold_convert (sizetype
, length
);
4620 if (low_bound
== NULL_TREE
)
4621 low_bound
= integer_zero_node
;
4623 if (length
!= NULL_TREE
)
4625 if (!integer_nonzerop (length
))
4627 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4628 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4630 if (integer_zerop (length
))
4632 error_at (OMP_CLAUSE_LOCATION (c
),
4633 "zero length array section in %qs clause",
4634 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4635 return error_mark_node
;
4639 maybe_zero_len
= true;
4641 if (first_non_one
== types
.length ()
4642 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4645 if (TREE_CODE (type
) == ARRAY_TYPE
)
4647 if (length
== NULL_TREE
4648 && (TYPE_DOMAIN (type
) == NULL_TREE
4649 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4651 error_at (OMP_CLAUSE_LOCATION (c
),
4652 "for unknown bound array type length expression must "
4654 return error_mark_node
;
4656 if (TREE_CODE (low_bound
) == INTEGER_CST
4657 && tree_int_cst_sgn (low_bound
) == -1)
4659 error_at (OMP_CLAUSE_LOCATION (c
),
4660 "negative low bound in array section in %qs clause",
4661 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4662 return error_mark_node
;
4664 if (length
!= NULL_TREE
4665 && TREE_CODE (length
) == INTEGER_CST
4666 && tree_int_cst_sgn (length
) == -1)
4668 error_at (OMP_CLAUSE_LOCATION (c
),
4669 "negative length in array section in %qs clause",
4670 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4671 return error_mark_node
;
4673 if (TYPE_DOMAIN (type
)
4674 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
4675 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
4678 tree size
= size_binop (PLUS_EXPR
,
4679 TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4681 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4683 if (tree_int_cst_lt (size
, low_bound
))
4685 error_at (OMP_CLAUSE_LOCATION (c
),
4686 "low bound %qE above array section size "
4687 "in %qs clause", low_bound
,
4688 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4689 return error_mark_node
;
4691 if (tree_int_cst_equal (size
, low_bound
))
4693 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4694 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4696 error_at (OMP_CLAUSE_LOCATION (c
),
4697 "zero length array section in %qs clause",
4698 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4699 return error_mark_node
;
4701 maybe_zero_len
= true;
4703 else if (length
== NULL_TREE
4704 && first_non_one
== types
.length ()
4705 && tree_int_cst_equal
4706 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4710 else if (length
== NULL_TREE
)
4712 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4713 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4714 maybe_zero_len
= true;
4715 if (first_non_one
== types
.length ())
4718 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
4720 if (tree_int_cst_lt (size
, length
))
4722 error_at (OMP_CLAUSE_LOCATION (c
),
4723 "length %qE above array section size "
4724 "in %qs clause", length
,
4725 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4726 return error_mark_node
;
4728 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4731 = size_binop (PLUS_EXPR
,
4732 fold_convert (sizetype
, low_bound
),
4733 fold_convert (sizetype
, length
));
4734 if (TREE_CODE (lbpluslen
) == INTEGER_CST
4735 && tree_int_cst_lt (size
, lbpluslen
))
4737 error_at (OMP_CLAUSE_LOCATION (c
),
4738 "high bound %qE above array section size "
4739 "in %qs clause", lbpluslen
,
4740 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4741 return error_mark_node
;
4746 else if (length
== NULL_TREE
)
4748 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4749 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4750 maybe_zero_len
= true;
4751 if (first_non_one
== types
.length ())
4755 /* For [lb:] we will need to evaluate lb more than once. */
4756 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4758 tree lb
= cp_save_expr (low_bound
);
4759 if (lb
!= low_bound
)
4761 TREE_PURPOSE (t
) = lb
;
4766 else if (TREE_CODE (type
) == POINTER_TYPE
)
4768 if (length
== NULL_TREE
)
4770 error_at (OMP_CLAUSE_LOCATION (c
),
4771 "for pointer type length expression must be specified");
4772 return error_mark_node
;
4774 if (length
!= NULL_TREE
4775 && TREE_CODE (length
) == INTEGER_CST
4776 && tree_int_cst_sgn (length
) == -1)
4778 error_at (OMP_CLAUSE_LOCATION (c
),
4779 "negative length in array section in %qs clause",
4780 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4781 return error_mark_node
;
4783 /* If there is a pointer type anywhere but in the very first
4784 array-section-subscript, the array section can't be contiguous. */
4785 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4786 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
4788 error_at (OMP_CLAUSE_LOCATION (c
),
4789 "array section is not contiguous in %qs clause",
4790 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4791 return error_mark_node
;
4796 error_at (OMP_CLAUSE_LOCATION (c
),
4797 "%qE does not have pointer or array type", ret
);
4798 return error_mark_node
;
4800 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4801 types
.safe_push (TREE_TYPE (ret
));
4802 /* We will need to evaluate lb more than once. */
4803 tree lb
= cp_save_expr (low_bound
);
4804 if (lb
!= low_bound
)
4806 TREE_PURPOSE (t
) = lb
;
4809 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
4813 /* Handle array sections for clause C. */
4816 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
4818 bool maybe_zero_len
= false;
4819 unsigned int first_non_one
= 0;
4820 auto_vec
<tree
, 10> types
;
4821 tree first
= handle_omp_array_sections_1 (c
, OMP_CLAUSE_DECL (c
), types
,
4822 maybe_zero_len
, first_non_one
,
4824 if (first
== error_mark_node
)
4826 if (first
== NULL_TREE
)
4828 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
4830 tree t
= OMP_CLAUSE_DECL (c
);
4831 tree tem
= NULL_TREE
;
4832 if (processing_template_decl
)
4834 /* Need to evaluate side effects in the length expressions
4836 while (TREE_CODE (t
) == TREE_LIST
)
4838 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
4840 if (tem
== NULL_TREE
)
4841 tem
= TREE_VALUE (t
);
4843 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
4844 TREE_VALUE (t
), tem
);
4849 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
4850 OMP_CLAUSE_DECL (c
) = first
;
4854 unsigned int num
= types
.length (), i
;
4855 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
4856 tree condition
= NULL_TREE
;
4858 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
4859 maybe_zero_len
= true;
4860 if (processing_template_decl
&& maybe_zero_len
)
4863 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
4866 tree low_bound
= TREE_PURPOSE (t
);
4867 tree length
= TREE_VALUE (t
);
4871 && TREE_CODE (low_bound
) == INTEGER_CST
4872 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4873 > TYPE_PRECISION (sizetype
))
4874 low_bound
= fold_convert (sizetype
, low_bound
);
4876 && TREE_CODE (length
) == INTEGER_CST
4877 && TYPE_PRECISION (TREE_TYPE (length
))
4878 > TYPE_PRECISION (sizetype
))
4879 length
= fold_convert (sizetype
, length
);
4880 if (low_bound
== NULL_TREE
)
4881 low_bound
= integer_zero_node
;
4882 if (!maybe_zero_len
&& i
> first_non_one
)
4884 if (integer_nonzerop (low_bound
))
4885 goto do_warn_noncontiguous
;
4886 if (length
!= NULL_TREE
4887 && TREE_CODE (length
) == INTEGER_CST
4888 && TYPE_DOMAIN (types
[i
])
4889 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
4890 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
4894 size
= size_binop (PLUS_EXPR
,
4895 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4897 if (!tree_int_cst_equal (length
, size
))
4899 do_warn_noncontiguous
:
4900 error_at (OMP_CLAUSE_LOCATION (c
),
4901 "array section is not contiguous in %qs "
4903 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4907 if (!processing_template_decl
4908 && length
!= NULL_TREE
4909 && TREE_SIDE_EFFECTS (length
))
4911 if (side_effects
== NULL_TREE
)
4912 side_effects
= length
;
4914 side_effects
= build2 (COMPOUND_EXPR
,
4915 TREE_TYPE (side_effects
),
4916 length
, side_effects
);
4919 else if (processing_template_decl
)
4925 if (i
> first_non_one
4926 && ((length
&& integer_nonzerop (length
))
4927 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
))
4930 l
= fold_convert (sizetype
, length
);
4933 l
= size_binop (PLUS_EXPR
,
4934 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4936 l
= size_binop (MINUS_EXPR
, l
,
4937 fold_convert (sizetype
, low_bound
));
4939 if (i
> first_non_one
)
4941 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
4943 if (condition
== NULL_TREE
)
4946 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
4949 else if (size
== NULL_TREE
)
4951 size
= size_in_bytes (TREE_TYPE (types
[i
]));
4952 tree eltype
= TREE_TYPE (types
[num
- 1]);
4953 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4954 eltype
= TREE_TYPE (eltype
);
4955 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4956 size
= size_binop (EXACT_DIV_EXPR
, size
,
4957 size_in_bytes (eltype
));
4958 size
= size_binop (MULT_EXPR
, size
, l
);
4960 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
4961 size
, size_zero_node
);
4964 size
= size_binop (MULT_EXPR
, size
, l
);
4967 if (!processing_template_decl
)
4970 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
4971 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4973 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
4974 tree index_type
= build_index_type (size
);
4975 tree eltype
= TREE_TYPE (first
);
4976 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4977 eltype
= TREE_TYPE (eltype
);
4978 tree type
= build_array_type (eltype
, index_type
);
4979 tree ptype
= build_pointer_type (eltype
);
4980 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
4981 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
4982 t
= convert_from_reference (t
);
4983 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
4984 t
= build_fold_addr_expr (t
);
4985 tree t2
= build_fold_addr_expr (first
);
4986 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4987 ptrdiff_type_node
, t2
);
4988 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
4989 ptrdiff_type_node
, t2
,
4990 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4991 ptrdiff_type_node
, t
));
4992 if (tree_fits_shwi_p (t2
))
4993 t
= build2 (MEM_REF
, type
, t
,
4994 build_int_cst (ptype
, tree_to_shwi (t2
)));
4997 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4999 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
5000 TREE_TYPE (t
), t
, t2
);
5001 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5003 OMP_CLAUSE_DECL (c
) = t
;
5006 OMP_CLAUSE_DECL (c
) = first
;
5007 OMP_CLAUSE_SIZE (c
) = size
;
5008 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5009 || (TREE_CODE (t
) == COMPONENT_REF
5010 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5012 if (ort
== C_ORT_OMP
|| ort
== C_ORT_ACC
)
5013 switch (OMP_CLAUSE_MAP_KIND (c
))
5015 case GOMP_MAP_ALLOC
:
5018 case GOMP_MAP_TOFROM
:
5019 case GOMP_MAP_ALWAYS_TO
:
5020 case GOMP_MAP_ALWAYS_FROM
:
5021 case GOMP_MAP_ALWAYS_TOFROM
:
5022 case GOMP_MAP_RELEASE
:
5023 case GOMP_MAP_DELETE
:
5024 case GOMP_MAP_FORCE_TO
:
5025 case GOMP_MAP_FORCE_FROM
:
5026 case GOMP_MAP_FORCE_TOFROM
:
5027 case GOMP_MAP_FORCE_PRESENT
:
5028 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5033 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5035 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
&& ort
!= C_ORT_ACC
)
5036 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
5037 else if (TREE_CODE (t
) == COMPONENT_REF
)
5038 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5039 else if (REFERENCE_REF_P (t
)
5040 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5042 t
= TREE_OPERAND (t
, 0);
5043 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5046 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5047 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5048 && !cxx_mark_addressable (t
))
5050 OMP_CLAUSE_DECL (c2
) = t
;
5051 t
= build_fold_addr_expr (first
);
5052 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5053 ptrdiff_type_node
, t
);
5054 tree ptr
= OMP_CLAUSE_DECL (c2
);
5055 ptr
= convert_from_reference (ptr
);
5056 if (!POINTER_TYPE_P (TREE_TYPE (ptr
)))
5057 ptr
= build_fold_addr_expr (ptr
);
5058 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5059 ptrdiff_type_node
, t
,
5060 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5061 ptrdiff_type_node
, ptr
));
5062 OMP_CLAUSE_SIZE (c2
) = t
;
5063 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5064 OMP_CLAUSE_CHAIN (c
) = c2
;
5065 ptr
= OMP_CLAUSE_DECL (c2
);
5066 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5067 && TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
5068 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5070 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5072 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5073 OMP_CLAUSE_DECL (c3
) = ptr
;
5074 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
)
5075 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5077 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5078 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5079 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5080 OMP_CLAUSE_CHAIN (c2
) = c3
;
5087 /* Return identifier to look up for omp declare reduction. */
5090 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5092 const char *p
= NULL
;
5093 const char *m
= NULL
;
5094 switch (reduction_code
)
5102 case TRUTH_ANDIF_EXPR
:
5103 case TRUTH_ORIF_EXPR
:
5104 reduction_id
= ansi_opname (reduction_code
);
5118 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5119 return error_mark_node
;
5120 p
= IDENTIFIER_POINTER (reduction_id
);
5123 if (type
!= NULL_TREE
)
5124 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5126 const char prefix
[] = "omp declare reduction ";
5127 size_t lenp
= sizeof (prefix
);
5128 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5130 size_t len
= strlen (p
);
5131 size_t lenm
= m
? strlen (m
) + 1 : 0;
5132 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5134 memcpy (name
, prefix
, lenp
- 1);
5135 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5138 name
[lenp
+ len
- 1] = '~';
5139 memcpy (name
+ lenp
+ len
, m
, lenm
);
5141 return get_identifier (name
);
5144 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5145 FUNCTION_DECL or NULL_TREE if not found. */
5148 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5149 vec
<tree
> *ambiguousp
)
5152 tree baselink
= NULL_TREE
;
5153 if (identifier_p (id
))
5156 bool nonint_cst_expression_p
;
5157 const char *error_msg
;
5158 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5159 tree decl
= lookup_name (id
);
5160 if (decl
== NULL_TREE
)
5161 decl
= error_mark_node
;
5162 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5163 &nonint_cst_expression_p
, false, true, false,
5164 false, &error_msg
, loc
);
5165 if (idk
== CP_ID_KIND_UNQUALIFIED
5166 && identifier_p (id
))
5168 vec
<tree
, va_gc
> *args
= NULL
;
5169 vec_safe_push (args
, build_reference_type (type
));
5170 id
= perform_koenig_lookup (id
, args
, tf_none
);
5173 else if (TREE_CODE (id
) == SCOPE_REF
)
5174 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5175 omp_reduction_id (ERROR_MARK
,
5176 TREE_OPERAND (id
, 1),
5180 if (id
&& is_overloaded_fn (id
))
5182 for (; id
; id
= OVL_NEXT (id
))
5184 tree fndecl
= OVL_CURRENT (id
);
5185 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5187 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5188 if (same_type_p (TREE_TYPE (argtype
), type
))
5192 if (id
&& BASELINK_P (fns
))
5199 if (id
== NULL_TREE
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5201 vec
<tree
> ambiguous
= vNULL
;
5202 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5204 if (ambiguousp
== NULL
)
5205 ambiguousp
= &ambiguous
;
5206 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5208 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5209 baselinkp
? baselinkp
: &baselink
,
5211 if (id
== NULL_TREE
)
5213 if (!ambiguousp
->is_empty ())
5214 ambiguousp
->safe_push (id
);
5215 else if (ret
!= NULL_TREE
)
5217 ambiguousp
->safe_push (ret
);
5218 ambiguousp
->safe_push (id
);
5224 if (ambiguousp
!= &ambiguous
)
5226 if (!ambiguous
.is_empty ())
5228 const char *str
= _("candidates are:");
5231 error_at (loc
, "user defined reduction lookup is ambiguous");
5232 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5234 inform (DECL_SOURCE_LOCATION (udr
), "%s %#D", str
, udr
);
5236 str
= get_spaces (str
);
5238 ambiguous
.release ();
5239 ret
= error_mark_node
;
5240 baselink
= NULL_TREE
;
5245 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5246 id
, id
, tf_warning_or_error
);
5250 /* Helper function for cp_parser_omp_declare_reduction_exprs
5252 Remove CLEANUP_STMT for data (omp_priv variable).
5253 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5257 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5261 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5262 *tp
= CLEANUP_BODY (*tp
);
5263 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5265 tree decl
= DECL_EXPR_DECL (*tp
);
5266 if (!processing_template_decl
5267 && decl
== (tree
) data
5268 && DECL_INITIAL (decl
)
5269 && DECL_INITIAL (decl
) != error_mark_node
)
5271 tree list
= NULL_TREE
;
5272 append_to_statement_list_force (*tp
, &list
);
5273 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5274 decl
, DECL_INITIAL (decl
));
5275 DECL_INITIAL (decl
) = NULL_TREE
;
5276 append_to_statement_list_force (init_expr
, &list
);
5283 /* Data passed from cp_check_omp_declare_reduction to
5284 cp_check_omp_declare_reduction_r. */
5286 struct cp_check_omp_declare_reduction_data
5293 /* Helper function for cp_check_omp_declare_reduction, called via
5297 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5299 struct cp_check_omp_declare_reduction_data
*udr_data
5300 = (struct cp_check_omp_declare_reduction_data
*) data
;
5302 && !DECL_ARTIFICIAL (*tp
)
5303 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5304 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5306 location_t loc
= udr_data
->loc
;
5307 if (udr_data
->combiner_p
)
5308 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5309 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5312 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5313 "to variable %qD which is not %<omp_priv%> nor "
5321 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5324 cp_check_omp_declare_reduction (tree udr
)
5326 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5327 gcc_assert (TREE_CODE (type
) == REFERENCE_TYPE
);
5328 type
= TREE_TYPE (type
);
5330 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5332 if (type
== error_mark_node
)
5334 if (ARITHMETIC_TYPE_P (type
))
5336 static enum tree_code predef_codes
[]
5337 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5338 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5339 for (i
= 0; i
< 8; i
++)
5341 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5342 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5343 const char *n2
= IDENTIFIER_POINTER (id
);
5344 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5345 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5346 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5351 && TREE_CODE (type
) != COMPLEX_EXPR
)
5353 const char prefix_minmax
[] = "omp declare reduction m";
5354 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5355 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5356 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5357 prefix_minmax
, prefix_size
) == 0
5358 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5359 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5360 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5365 error_at (loc
, "predeclared arithmetic type %qT in "
5366 "%<#pragma omp declare reduction%>", type
);
5370 else if (TREE_CODE (type
) == FUNCTION_TYPE
5371 || TREE_CODE (type
) == METHOD_TYPE
5372 || TREE_CODE (type
) == ARRAY_TYPE
)
5374 error_at (loc
, "function or array type %qT in "
5375 "%<#pragma omp declare reduction%>", type
);
5378 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5380 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5384 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5386 error_at (loc
, "const, volatile or __restrict qualified type %qT in "
5387 "%<#pragma omp declare reduction%>", type
);
5391 tree body
= DECL_SAVED_TREE (udr
);
5392 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5395 tree_stmt_iterator tsi
;
5396 struct cp_check_omp_declare_reduction_data data
;
5397 memset (data
.stmts
, 0, sizeof data
.stmts
);
5398 for (i
= 0, tsi
= tsi_start (body
);
5399 i
< 7 && !tsi_end_p (tsi
);
5400 i
++, tsi_next (&tsi
))
5401 data
.stmts
[i
] = tsi_stmt (tsi
);
5403 gcc_assert (tsi_end_p (tsi
));
5406 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5407 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5408 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5410 data
.combiner_p
= true;
5411 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5413 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5417 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5418 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5419 data
.combiner_p
= false;
5420 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5422 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5423 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5424 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5426 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5430 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5431 an inline call. But, remap
5432 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5433 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5436 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5437 tree decl
, tree placeholder
)
5440 hash_map
<tree
, tree
> decl_map
;
5442 decl_map
.put (omp_decl1
, placeholder
);
5443 decl_map
.put (omp_decl2
, decl
);
5444 memset (&id
, 0, sizeof (id
));
5445 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5446 id
.dst_fn
= current_function_decl
;
5447 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5448 id
.decl_map
= &decl_map
;
5450 id
.copy_decl
= copy_decl_no_change
;
5451 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5452 id
.transform_new_cfg
= true;
5453 id
.transform_return_to_modify
= false;
5454 id
.transform_lang_insert_block
= NULL
;
5456 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5460 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5461 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5464 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5466 if (*tp
== (tree
) data
)
5471 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5472 Return true if there is some error and the clause should be removed. */
5475 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5477 tree t
= OMP_CLAUSE_DECL (c
);
5478 bool predefined
= false;
5479 if (TREE_CODE (t
) == TREE_LIST
)
5481 gcc_assert (processing_template_decl
);
5484 tree type
= TREE_TYPE (t
);
5485 if (TREE_CODE (t
) == MEM_REF
)
5486 type
= TREE_TYPE (type
);
5487 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5488 type
= TREE_TYPE (type
);
5489 if (TREE_CODE (type
) == ARRAY_TYPE
)
5492 gcc_assert (TREE_CODE (t
) != MEM_REF
);
5493 while (TREE_CODE (type
) == ARRAY_TYPE
)
5494 type
= TREE_TYPE (type
);
5495 if (!processing_template_decl
)
5497 t
= require_complete_type (t
);
5498 if (t
== error_mark_node
)
5500 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
5501 TYPE_SIZE_UNIT (type
));
5502 if (integer_zerop (size
))
5504 error ("%qE in %<reduction%> clause is a zero size array",
5505 omp_clause_printable_decl (t
));
5508 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5509 tree index_type
= build_index_type (size
);
5510 tree atype
= build_array_type (type
, index_type
);
5511 tree ptype
= build_pointer_type (type
);
5512 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5513 t
= build_fold_addr_expr (t
);
5514 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
5515 OMP_CLAUSE_DECL (c
) = t
;
5518 if (type
== error_mark_node
)
5520 else if (ARITHMETIC_TYPE_P (type
))
5521 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5530 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5537 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5541 case TRUTH_ANDIF_EXPR
:
5542 case TRUTH_ORIF_EXPR
:
5543 if (FLOAT_TYPE_P (type
))
5550 else if (TYPE_READONLY (type
))
5552 error ("%qE has const type for %<reduction%>",
5553 omp_clause_printable_decl (t
));
5556 else if (!processing_template_decl
)
5558 t
= require_complete_type (t
);
5559 if (t
== error_mark_node
)
5561 OMP_CLAUSE_DECL (c
) = t
;
5566 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5569 else if (processing_template_decl
)
5572 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5574 type
= TYPE_MAIN_VARIANT (type
);
5575 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5576 if (id
== NULL_TREE
)
5577 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5578 NULL_TREE
, NULL_TREE
);
5579 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5582 if (id
== error_mark_node
)
5584 id
= OVL_CURRENT (id
);
5586 tree body
= DECL_SAVED_TREE (id
);
5589 if (TREE_CODE (body
) == STATEMENT_LIST
)
5591 tree_stmt_iterator tsi
;
5592 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
5595 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5596 atype
= TREE_TYPE (atype
);
5597 bool need_static_cast
= !same_type_p (type
, atype
);
5598 memset (stmts
, 0, sizeof stmts
);
5599 for (i
= 0, tsi
= tsi_start (body
);
5600 i
< 7 && !tsi_end_p (tsi
);
5601 i
++, tsi_next (&tsi
))
5602 stmts
[i
] = tsi_stmt (tsi
);
5603 gcc_assert (tsi_end_p (tsi
));
5607 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
5608 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
5609 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
5610 DECL_ARTIFICIAL (placeholder
) = 1;
5611 DECL_IGNORED_P (placeholder
) = 1;
5612 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
5613 if (TREE_CODE (t
) == MEM_REF
)
5615 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
5617 DECL_ARTIFICIAL (decl_placeholder
) = 1;
5618 DECL_IGNORED_P (decl_placeholder
) = 1;
5619 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
5621 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
5622 cxx_mark_addressable (placeholder
);
5623 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
5624 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
5626 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5627 : OMP_CLAUSE_DECL (c
));
5628 tree omp_out
= placeholder
;
5629 tree omp_in
= decl_placeholder
? decl_placeholder
5630 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5631 if (need_static_cast
)
5633 tree rtype
= build_reference_type (atype
);
5634 omp_out
= build_static_cast (rtype
, omp_out
,
5635 tf_warning_or_error
);
5636 omp_in
= build_static_cast (rtype
, omp_in
,
5637 tf_warning_or_error
);
5638 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
5640 omp_out
= convert_from_reference (omp_out
);
5641 omp_in
= convert_from_reference (omp_in
);
5643 OMP_CLAUSE_REDUCTION_MERGE (c
)
5644 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
5645 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
5649 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
5650 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
5651 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3])))
5652 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5653 : OMP_CLAUSE_DECL (c
));
5654 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
5655 cxx_mark_addressable (placeholder
);
5656 tree omp_priv
= decl_placeholder
? decl_placeholder
5657 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5658 tree omp_orig
= placeholder
;
5659 if (need_static_cast
)
5663 error_at (OMP_CLAUSE_LOCATION (c
),
5664 "user defined reduction with constructor "
5665 "initializer for base class %qT", atype
);
5668 tree rtype
= build_reference_type (atype
);
5669 omp_priv
= build_static_cast (rtype
, omp_priv
,
5670 tf_warning_or_error
);
5671 omp_orig
= build_static_cast (rtype
, omp_orig
,
5672 tf_warning_or_error
);
5673 if (omp_priv
== error_mark_node
5674 || omp_orig
== error_mark_node
)
5676 omp_priv
= convert_from_reference (omp_priv
);
5677 omp_orig
= convert_from_reference (omp_orig
);
5680 *need_default_ctor
= true;
5681 OMP_CLAUSE_REDUCTION_INIT (c
)
5682 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
5683 DECL_EXPR_DECL (stmts
[3]),
5684 omp_priv
, omp_orig
);
5685 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
5686 find_omp_placeholder_r
, placeholder
, NULL
))
5687 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
5691 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
5692 *need_default_ctor
= true;
5696 tree v
= decl_placeholder
? decl_placeholder
5697 : convert_from_reference (t
);
5698 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
5699 init
= build_constructor (TREE_TYPE (v
), NULL
);
5701 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
5702 OMP_CLAUSE_REDUCTION_INIT (c
)
5703 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
5708 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5712 error ("user defined reduction not found for %qE",
5713 omp_clause_printable_decl (t
));
5716 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
5717 gcc_assert (TYPE_SIZE_UNIT (type
)
5718 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
5722 /* Called from finish_struct_1. linear(this) or linear(this:step)
5723 clauses might not be finalized yet because the class has been incomplete
5724 when parsing #pragma omp declare simd methods. Fix those up now. */
5727 finish_omp_declare_simd_methods (tree t
)
5729 if (processing_template_decl
)
5732 for (tree x
= TYPE_METHODS (t
); x
; x
= DECL_CHAIN (x
))
5734 if (TREE_CODE (TREE_TYPE (x
)) != METHOD_TYPE
)
5736 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
5737 if (!ods
|| !TREE_VALUE (ods
))
5739 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
5740 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
5741 && integer_zerop (OMP_CLAUSE_DECL (c
))
5742 && OMP_CLAUSE_LINEAR_STEP (c
)
5743 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
)))
5746 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
5747 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
5748 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
5749 sizetype
, s
, TYPE_SIZE_UNIT (t
));
5750 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
5755 /* Adjust sink depend clause to take into account pointer offsets.
5757 Return TRUE if there was a problem processing the offset, and the
5758 whole clause should be removed. */
5761 cp_finish_omp_clause_depend_sink (tree sink_clause
)
5763 tree t
= OMP_CLAUSE_DECL (sink_clause
);
5764 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
5766 /* Make sure we don't adjust things twice for templates. */
5767 if (processing_template_decl
)
5770 for (; t
; t
= TREE_CHAIN (t
))
5772 tree decl
= TREE_VALUE (t
);
5773 if (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
5775 tree offset
= TREE_PURPOSE (t
);
5776 bool neg
= wi::neg_p ((wide_int
) offset
);
5777 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
5778 decl
= mark_rvalue_use (decl
);
5779 decl
= convert_from_reference (decl
);
5780 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
5781 neg
? MINUS_EXPR
: PLUS_EXPR
,
5783 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
5784 MINUS_EXPR
, sizetype
,
5785 fold_convert (sizetype
, t2
),
5786 fold_convert (sizetype
, decl
));
5787 if (t2
== error_mark_node
)
5789 TREE_PURPOSE (t
) = t2
;
5795 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
5796 Remove any elements from the list that are invalid. */
5799 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
5801 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
5802 bitmap_head aligned_head
, map_head
, map_field_head
, oacc_reduction_head
;
5804 tree safelen
= NULL_TREE
;
5805 bool branch_seen
= false;
5806 bool copyprivate_seen
= false;
5807 bool ordered_seen
= false;
5808 bool oacc_async
= false;
5810 bitmap_obstack_initialize (NULL
);
5811 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
5812 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
5813 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
5814 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
5815 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
5816 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
5817 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
5819 if (ort
& C_ORT_ACC
)
5820 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
5821 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
5827 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
5829 bool remove
= false;
5830 bool field_ok
= false;
5832 switch (OMP_CLAUSE_CODE (c
))
5834 case OMP_CLAUSE_SHARED
:
5835 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5836 goto check_dup_generic
;
5837 case OMP_CLAUSE_PRIVATE
:
5838 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5839 goto check_dup_generic
;
5840 case OMP_CLAUSE_REDUCTION
:
5841 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5842 t
= OMP_CLAUSE_DECL (c
);
5843 if (TREE_CODE (t
) == TREE_LIST
)
5845 if (handle_omp_array_sections (c
, ort
))
5850 if (TREE_CODE (t
) == TREE_LIST
)
5852 while (TREE_CODE (t
) == TREE_LIST
)
5857 gcc_assert (TREE_CODE (t
) == MEM_REF
);
5858 t
= TREE_OPERAND (t
, 0);
5859 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
5860 t
= TREE_OPERAND (t
, 0);
5861 if (TREE_CODE (t
) == ADDR_EXPR
5862 || TREE_CODE (t
) == INDIRECT_REF
)
5863 t
= TREE_OPERAND (t
, 0);
5865 tree n
= omp_clause_decl_field (t
);
5868 goto check_dup_generic_t
;
5871 cxx_mark_addressable (t
);
5872 goto check_dup_generic
;
5873 case OMP_CLAUSE_COPYPRIVATE
:
5874 copyprivate_seen
= true;
5875 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5876 goto check_dup_generic
;
5877 case OMP_CLAUSE_COPYIN
:
5878 goto check_dup_generic
;
5879 case OMP_CLAUSE_LINEAR
:
5880 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5881 t
= OMP_CLAUSE_DECL (c
);
5882 if (ort
!= C_ORT_OMP_DECLARE_SIMD
5883 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
5885 error_at (OMP_CLAUSE_LOCATION (c
),
5886 "modifier should not be specified in %<linear%> "
5887 "clause on %<simd%> or %<for%> constructs");
5888 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
5890 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
5891 && !type_dependent_expression_p (t
))
5893 tree type
= TREE_TYPE (t
);
5894 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5895 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
5896 && TREE_CODE (type
) != REFERENCE_TYPE
)
5898 error ("linear clause with %qs modifier applied to "
5899 "non-reference variable with %qT type",
5900 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5901 ? "ref" : "uval", TREE_TYPE (t
));
5905 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5906 type
= TREE_TYPE (type
);
5907 if (ort
== C_ORT_CILK
)
5909 if (!INTEGRAL_TYPE_P (type
)
5910 && !SCALAR_FLOAT_TYPE_P (type
)
5911 && TREE_CODE (type
) != POINTER_TYPE
)
5913 error ("linear clause applied to non-integral, "
5914 "non-floating, non-pointer variable with %qT type",
5920 else if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
5922 if (!INTEGRAL_TYPE_P (type
)
5923 && TREE_CODE (type
) != POINTER_TYPE
)
5925 error ("linear clause applied to non-integral non-pointer"
5926 " variable with %qT type", TREE_TYPE (t
));
5932 t
= OMP_CLAUSE_LINEAR_STEP (c
);
5934 t
= integer_one_node
;
5935 if (t
== error_mark_node
)
5940 else if (!type_dependent_expression_p (t
)
5941 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
5942 && (ort
!= C_ORT_OMP_DECLARE_SIMD
5943 || TREE_CODE (t
) != PARM_DECL
5944 || TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
5945 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
5947 error ("linear step expression must be integral");
5953 t
= mark_rvalue_use (t
);
5954 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
5956 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
5957 goto check_dup_generic
;
5959 if (!processing_template_decl
5960 && (VAR_P (OMP_CLAUSE_DECL (c
))
5961 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
5963 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
5965 t
= maybe_constant_value (t
);
5966 if (TREE_CODE (t
) != INTEGER_CST
)
5968 error_at (OMP_CLAUSE_LOCATION (c
),
5969 "%<linear%> clause step %qE is neither "
5970 "constant nor a parameter", t
);
5975 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5976 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
5977 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5978 type
= TREE_TYPE (type
);
5979 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
5981 type
= build_pointer_type (type
);
5982 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
5983 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
5985 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
5986 MINUS_EXPR
, sizetype
,
5987 fold_convert (sizetype
, t
),
5988 fold_convert (sizetype
, d
));
5989 if (t
== error_mark_node
)
5995 else if (TREE_CODE (type
) == POINTER_TYPE
5996 /* Can't multiply the step yet if *this
5997 is still incomplete type. */
5998 && (ort
!= C_ORT_OMP_DECLARE_SIMD
5999 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
6000 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
6001 || DECL_NAME (OMP_CLAUSE_DECL (c
))
6003 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
6005 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
6006 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6008 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6009 MINUS_EXPR
, sizetype
,
6010 fold_convert (sizetype
, t
),
6011 fold_convert (sizetype
, d
));
6012 if (t
== error_mark_node
)
6019 t
= fold_convert (type
, t
);
6021 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6023 goto check_dup_generic
;
6025 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6028 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6029 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6032 t
= OMP_CLAUSE_DECL (c
);
6033 check_dup_generic_t
:
6034 if (t
== current_class_ptr
6035 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6036 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6037 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6039 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6044 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6045 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6047 if (processing_template_decl
)
6050 error ("%qD is not a variable in clause %qs", t
,
6051 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6053 error ("%qE is not a variable in clause %qs", t
,
6054 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6057 else if (ort
== C_ORT_ACC
6058 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
6060 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
6062 error ("%qD appears more than once in reduction clauses", t
);
6066 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
6068 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6069 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6070 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6072 error ("%qD appears more than once in data clauses", t
);
6075 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6076 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6078 if (ort
== C_ORT_ACC
)
6079 error ("%qD appears more than once in data clauses", t
);
6081 error ("%qD appears both in data and map clauses", t
);
6085 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6090 && TREE_CODE (t
) == FIELD_DECL
6091 && t
== OMP_CLAUSE_DECL (c
)
6092 && ort
!= C_ORT_ACC
)
6095 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
6096 == OMP_CLAUSE_SHARED
));
6097 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
6102 case OMP_CLAUSE_FIRSTPRIVATE
:
6103 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6105 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6107 t
= OMP_CLAUSE_DECL (c
);
6108 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6110 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6115 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6116 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6117 || TREE_CODE (t
) != FIELD_DECL
))
6119 if (processing_template_decl
)
6122 error ("%qD is not a variable in clause %<firstprivate%>", t
);
6124 error ("%qE is not a variable in clause %<firstprivate%>", t
);
6127 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6128 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6130 error ("%qD appears more than once in data clauses", t
);
6133 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6135 if (ort
== C_ORT_ACC
)
6136 error ("%qD appears more than once in data clauses", t
);
6138 error ("%qD appears both in data and map clauses", t
);
6142 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
6143 goto handle_field_decl
;
6145 case OMP_CLAUSE_LASTPRIVATE
:
6146 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6148 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6150 t
= OMP_CLAUSE_DECL (c
);
6151 if (t
== current_class_ptr
)
6153 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6158 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6159 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6160 || TREE_CODE (t
) != FIELD_DECL
))
6162 if (processing_template_decl
)
6165 error ("%qD is not a variable in clause %<lastprivate%>", t
);
6167 error ("%qE is not a variable in clause %<lastprivate%>", t
);
6170 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6171 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6173 error ("%qD appears more than once in data clauses", t
);
6177 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
6178 goto handle_field_decl
;
6181 t
= OMP_CLAUSE_IF_EXPR (c
);
6182 t
= maybe_convert_cond (t
);
6183 if (t
== error_mark_node
)
6185 else if (!processing_template_decl
)
6186 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6187 OMP_CLAUSE_IF_EXPR (c
) = t
;
6190 case OMP_CLAUSE_FINAL
:
6191 t
= OMP_CLAUSE_FINAL_EXPR (c
);
6192 t
= maybe_convert_cond (t
);
6193 if (t
== error_mark_node
)
6195 else if (!processing_template_decl
)
6196 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6197 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
6200 case OMP_CLAUSE_GANG
:
6201 /* Operand 1 is the gang static: argument. */
6202 t
= OMP_CLAUSE_OPERAND (c
, 1);
6205 if (t
== error_mark_node
)
6207 else if (!type_dependent_expression_p (t
)
6208 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6210 error ("%<gang%> static expression must be integral");
6215 t
= mark_rvalue_use (t
);
6216 if (!processing_template_decl
)
6218 t
= maybe_constant_value (t
);
6219 if (TREE_CODE (t
) == INTEGER_CST
6220 && tree_int_cst_sgn (t
) != 1
6221 && t
!= integer_minus_one_node
)
6223 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6224 "%<gang%> static value must be"
6226 t
= integer_one_node
;
6229 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6231 OMP_CLAUSE_OPERAND (c
, 1) = t
;
6233 /* Check operand 0, the num argument. */
6236 case OMP_CLAUSE_WORKER
:
6237 case OMP_CLAUSE_VECTOR
:
6238 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
6242 case OMP_CLAUSE_NUM_TASKS
:
6243 case OMP_CLAUSE_NUM_TEAMS
:
6244 case OMP_CLAUSE_NUM_THREADS
:
6245 case OMP_CLAUSE_NUM_GANGS
:
6246 case OMP_CLAUSE_NUM_WORKERS
:
6247 case OMP_CLAUSE_VECTOR_LENGTH
:
6248 t
= OMP_CLAUSE_OPERAND (c
, 0);
6249 if (t
== error_mark_node
)
6251 else if (!type_dependent_expression_p (t
)
6252 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6254 switch (OMP_CLAUSE_CODE (c
))
6256 case OMP_CLAUSE_GANG
:
6257 error_at (OMP_CLAUSE_LOCATION (c
),
6258 "%<gang%> num expression must be integral"); break;
6259 case OMP_CLAUSE_VECTOR
:
6260 error_at (OMP_CLAUSE_LOCATION (c
),
6261 "%<vector%> length expression must be integral");
6263 case OMP_CLAUSE_WORKER
:
6264 error_at (OMP_CLAUSE_LOCATION (c
),
6265 "%<worker%> num expression must be integral");
6268 error_at (OMP_CLAUSE_LOCATION (c
),
6269 "%qs expression must be integral",
6270 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6276 t
= mark_rvalue_use (t
);
6277 if (!processing_template_decl
)
6279 t
= maybe_constant_value (t
);
6280 if (TREE_CODE (t
) == INTEGER_CST
6281 && tree_int_cst_sgn (t
) != 1)
6283 switch (OMP_CLAUSE_CODE (c
))
6285 case OMP_CLAUSE_GANG
:
6286 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6287 "%<gang%> num value must be positive");
6289 case OMP_CLAUSE_VECTOR
:
6290 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6291 "%<vector%> length value must be"
6294 case OMP_CLAUSE_WORKER
:
6295 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6296 "%<worker%> num value must be"
6300 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6301 "%qs value must be positive",
6302 omp_clause_code_name
6303 [OMP_CLAUSE_CODE (c
)]);
6305 t
= integer_one_node
;
6307 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6309 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6313 case OMP_CLAUSE_SCHEDULE
:
6314 if (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
)
6316 const char *p
= NULL
;
6317 switch (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_MASK
)
6319 case OMP_CLAUSE_SCHEDULE_STATIC
: p
= "static"; break;
6320 case OMP_CLAUSE_SCHEDULE_DYNAMIC
: break;
6321 case OMP_CLAUSE_SCHEDULE_GUIDED
: break;
6322 case OMP_CLAUSE_SCHEDULE_AUTO
: p
= "auto"; break;
6323 case OMP_CLAUSE_SCHEDULE_RUNTIME
: p
= "runtime"; break;
6324 default: gcc_unreachable ();
6328 error_at (OMP_CLAUSE_LOCATION (c
),
6329 "%<nonmonotonic%> modifier specified for %qs "
6330 "schedule kind", p
);
6331 OMP_CLAUSE_SCHEDULE_KIND (c
)
6332 = (enum omp_clause_schedule_kind
)
6333 (OMP_CLAUSE_SCHEDULE_KIND (c
)
6334 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
6338 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
6341 else if (t
== error_mark_node
)
6343 else if (!type_dependent_expression_p (t
)
6344 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
6345 != OMP_CLAUSE_SCHEDULE_CILKFOR
)
6346 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6348 error ("schedule chunk size expression must be integral");
6353 t
= mark_rvalue_use (t
);
6354 if (!processing_template_decl
)
6356 if (OMP_CLAUSE_SCHEDULE_KIND (c
)
6357 == OMP_CLAUSE_SCHEDULE_CILKFOR
)
6359 t
= convert_to_integer (long_integer_type_node
, t
);
6360 if (t
== error_mark_node
)
6368 t
= maybe_constant_value (t
);
6369 if (TREE_CODE (t
) == INTEGER_CST
6370 && tree_int_cst_sgn (t
) != 1)
6372 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6373 "chunk size value must be positive");
6374 t
= integer_one_node
;
6377 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6379 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
6383 case OMP_CLAUSE_SIMDLEN
:
6384 case OMP_CLAUSE_SAFELEN
:
6385 t
= OMP_CLAUSE_OPERAND (c
, 0);
6386 if (t
== error_mark_node
)
6388 else if (!type_dependent_expression_p (t
)
6389 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6391 error ("%qs length expression must be integral",
6392 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6397 t
= mark_rvalue_use (t
);
6398 t
= maybe_constant_value (t
);
6399 if (!processing_template_decl
)
6401 if (TREE_CODE (t
) != INTEGER_CST
6402 || tree_int_cst_sgn (t
) != 1)
6404 error ("%qs length expression must be positive constant"
6405 " integer expression",
6406 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6410 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6411 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
6416 case OMP_CLAUSE_ASYNC
:
6417 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
6418 if (t
== error_mark_node
)
6420 else if (!type_dependent_expression_p (t
)
6421 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6423 error ("%<async%> expression must be integral");
6428 t
= mark_rvalue_use (t
);
6429 if (!processing_template_decl
)
6430 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6431 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
6435 case OMP_CLAUSE_WAIT
:
6436 t
= OMP_CLAUSE_WAIT_EXPR (c
);
6437 if (t
== error_mark_node
)
6439 else if (!processing_template_decl
)
6440 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6441 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
6444 case OMP_CLAUSE_THREAD_LIMIT
:
6445 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
6446 if (t
== error_mark_node
)
6448 else if (!type_dependent_expression_p (t
)
6449 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6451 error ("%<thread_limit%> expression must be integral");
6456 t
= mark_rvalue_use (t
);
6457 if (!processing_template_decl
)
6459 t
= maybe_constant_value (t
);
6460 if (TREE_CODE (t
) == INTEGER_CST
6461 && tree_int_cst_sgn (t
) != 1)
6463 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6464 "%<thread_limit%> value must be positive");
6465 t
= integer_one_node
;
6467 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6469 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
6473 case OMP_CLAUSE_DEVICE
:
6474 t
= OMP_CLAUSE_DEVICE_ID (c
);
6475 if (t
== error_mark_node
)
6477 else if (!type_dependent_expression_p (t
)
6478 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6480 error ("%<device%> id must be integral");
6485 t
= mark_rvalue_use (t
);
6486 if (!processing_template_decl
)
6487 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6488 OMP_CLAUSE_DEVICE_ID (c
) = t
;
6492 case OMP_CLAUSE_DIST_SCHEDULE
:
6493 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
6496 else if (t
== error_mark_node
)
6498 else if (!type_dependent_expression_p (t
)
6499 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6501 error ("%<dist_schedule%> chunk size expression must be "
6507 t
= mark_rvalue_use (t
);
6508 if (!processing_template_decl
)
6509 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6510 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
6514 case OMP_CLAUSE_ALIGNED
:
6515 t
= OMP_CLAUSE_DECL (c
);
6516 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
6518 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6523 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6525 if (processing_template_decl
)
6528 error ("%qD is not a variable in %<aligned%> clause", t
);
6530 error ("%qE is not a variable in %<aligned%> clause", t
);
6533 else if (!type_dependent_expression_p (t
)
6534 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
6535 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
6536 && (TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6537 || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
6538 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
6541 error_at (OMP_CLAUSE_LOCATION (c
),
6542 "%qE in %<aligned%> clause is neither a pointer nor "
6543 "an array nor a reference to pointer or array", t
);
6546 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
6548 error ("%qD appears more than once in %<aligned%> clauses", t
);
6552 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
6553 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
6554 if (t
== error_mark_node
)
6556 else if (t
== NULL_TREE
)
6558 else if (!type_dependent_expression_p (t
)
6559 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6561 error ("%<aligned%> clause alignment expression must "
6567 t
= mark_rvalue_use (t
);
6568 t
= maybe_constant_value (t
);
6569 if (!processing_template_decl
)
6571 if (TREE_CODE (t
) != INTEGER_CST
6572 || tree_int_cst_sgn (t
) != 1)
6574 error ("%<aligned%> clause alignment expression must be "
6575 "positive constant integer expression");
6579 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
6583 case OMP_CLAUSE_DEPEND
:
6584 t
= OMP_CLAUSE_DECL (c
);
6587 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
6588 == OMP_CLAUSE_DEPEND_SOURCE
);
6591 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
6593 if (cp_finish_omp_clause_depend_sink (c
))
6597 if (TREE_CODE (t
) == TREE_LIST
)
6599 if (handle_omp_array_sections (c
, ort
))
6603 if (t
== error_mark_node
)
6605 else if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6607 if (processing_template_decl
)
6610 error ("%qD is not a variable in %<depend%> clause", t
);
6612 error ("%qE is not a variable in %<depend%> clause", t
);
6615 else if (t
== current_class_ptr
)
6617 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6621 else if (!processing_template_decl
6622 && !cxx_mark_addressable (t
))
6626 case OMP_CLAUSE_MAP
:
6628 case OMP_CLAUSE_FROM
:
6629 case OMP_CLAUSE__CACHE_
:
6630 t
= OMP_CLAUSE_DECL (c
);
6631 if (TREE_CODE (t
) == TREE_LIST
)
6633 if (handle_omp_array_sections (c
, ort
))
6637 t
= OMP_CLAUSE_DECL (c
);
6638 if (TREE_CODE (t
) != TREE_LIST
6639 && !type_dependent_expression_p (t
)
6640 && !cp_omp_mappable_type (TREE_TYPE (t
)))
6642 error_at (OMP_CLAUSE_LOCATION (c
),
6643 "array section does not have mappable type "
6645 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6648 while (TREE_CODE (t
) == ARRAY_REF
)
6649 t
= TREE_OPERAND (t
, 0);
6650 if (TREE_CODE (t
) == COMPONENT_REF
6651 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6653 while (TREE_CODE (t
) == COMPONENT_REF
)
6654 t
= TREE_OPERAND (t
, 0);
6655 if (REFERENCE_REF_P (t
))
6656 t
= TREE_OPERAND (t
, 0);
6657 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6659 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6661 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6662 error ("%qD appears more than once in motion"
6664 else if (ort
== C_ORT_ACC
)
6665 error ("%qD appears more than once in data"
6668 error ("%qD appears more than once in map"
6674 bitmap_set_bit (&map_head
, DECL_UID (t
));
6675 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6681 if (t
== error_mark_node
)
6686 if (REFERENCE_REF_P (t
)
6687 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
6689 t
= TREE_OPERAND (t
, 0);
6690 OMP_CLAUSE_DECL (c
) = t
;
6692 if (TREE_CODE (t
) == COMPONENT_REF
6693 && (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
6694 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
6696 if (type_dependent_expression_p (t
))
6698 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
6699 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
6701 error_at (OMP_CLAUSE_LOCATION (c
),
6702 "bit-field %qE in %qs clause",
6703 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6706 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6708 error_at (OMP_CLAUSE_LOCATION (c
),
6709 "%qE does not have a mappable type in %qs clause",
6710 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6713 while (TREE_CODE (t
) == COMPONENT_REF
)
6715 if (TREE_TYPE (TREE_OPERAND (t
, 0))
6716 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
6719 error_at (OMP_CLAUSE_LOCATION (c
),
6720 "%qE is a member of a union", t
);
6724 t
= TREE_OPERAND (t
, 0);
6728 if (REFERENCE_REF_P (t
))
6729 t
= TREE_OPERAND (t
, 0);
6730 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6732 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6733 goto handle_map_references
;
6736 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6738 if (processing_template_decl
)
6740 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6741 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6742 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
))
6745 error ("%qD is not a variable in %qs clause", t
,
6746 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6748 error ("%qE is not a variable in %qs clause", t
,
6749 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6752 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
6754 error ("%qD is threadprivate variable in %qs clause", t
,
6755 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6758 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6760 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6765 else if (!processing_template_decl
6766 && TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6767 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
6768 || (OMP_CLAUSE_MAP_KIND (c
)
6769 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
6770 && !cxx_mark_addressable (t
))
6772 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6773 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6774 || (OMP_CLAUSE_MAP_KIND (c
)
6775 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
6776 && t
== OMP_CLAUSE_DECL (c
)
6777 && !type_dependent_expression_p (t
)
6778 && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t
))
6780 ? TREE_TYPE (TREE_TYPE (t
))
6783 error_at (OMP_CLAUSE_LOCATION (c
),
6784 "%qD does not have a mappable type in %qs clause", t
,
6785 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6788 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6789 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
6790 && !type_dependent_expression_p (t
)
6791 && !POINTER_TYPE_P (TREE_TYPE (t
)))
6793 error ("%qD is not a pointer variable", t
);
6796 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6797 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
6799 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6800 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6802 error ("%qD appears more than once in data clauses", t
);
6805 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6807 if (ort
== C_ORT_ACC
)
6808 error ("%qD appears more than once in data clauses", t
);
6810 error ("%qD appears both in data and map clauses", t
);
6814 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6816 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6818 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6819 error ("%qD appears more than once in motion clauses", t
);
6820 if (ort
== C_ORT_ACC
)
6821 error ("%qD appears more than once in data clauses", t
);
6823 error ("%qD appears more than once in map clauses", t
);
6826 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6827 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6829 if (ort
== C_ORT_ACC
)
6830 error ("%qD appears more than once in data clauses", t
);
6832 error ("%qD appears both in data and map clauses", t
);
6837 bitmap_set_bit (&map_head
, DECL_UID (t
));
6838 if (t
!= OMP_CLAUSE_DECL (c
)
6839 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
6840 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6842 handle_map_references
:
6844 && !processing_template_decl
6845 && (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
6846 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
))) == REFERENCE_TYPE
)
6848 t
= OMP_CLAUSE_DECL (c
);
6849 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6851 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6852 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6854 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6856 else if (OMP_CLAUSE_MAP_KIND (c
)
6857 != GOMP_MAP_FIRSTPRIVATE_POINTER
6858 && (OMP_CLAUSE_MAP_KIND (c
)
6859 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
6860 && (OMP_CLAUSE_MAP_KIND (c
)
6861 != GOMP_MAP_ALWAYS_POINTER
))
6863 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
6865 if (TREE_CODE (t
) == COMPONENT_REF
)
6866 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
6868 OMP_CLAUSE_SET_MAP_KIND (c2
,
6869 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
6870 OMP_CLAUSE_DECL (c2
) = t
;
6871 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
6872 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
6873 OMP_CLAUSE_CHAIN (c
) = c2
;
6874 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6875 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6877 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6883 case OMP_CLAUSE_TO_DECLARE
:
6884 case OMP_CLAUSE_LINK
:
6885 t
= OMP_CLAUSE_DECL (c
);
6886 if (TREE_CODE (t
) == FUNCTION_DECL
6887 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6889 else if (!VAR_P (t
))
6891 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6893 if (TREE_CODE (t
) == OVERLOAD
&& OVL_CHAIN (t
))
6894 error_at (OMP_CLAUSE_LOCATION (c
),
6895 "overloaded function name %qE in clause %qs", t
,
6896 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6897 else if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
6898 error_at (OMP_CLAUSE_LOCATION (c
),
6899 "template %qE in clause %qs", t
,
6900 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6902 error_at (OMP_CLAUSE_LOCATION (c
),
6903 "%qE is neither a variable nor a function name "
6905 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6908 error_at (OMP_CLAUSE_LOCATION (c
),
6909 "%qE is not a variable in clause %qs", t
,
6910 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6913 else if (DECL_THREAD_LOCAL_P (t
))
6915 error_at (OMP_CLAUSE_LOCATION (c
),
6916 "%qD is threadprivate variable in %qs clause", t
,
6917 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6920 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6922 error_at (OMP_CLAUSE_LOCATION (c
),
6923 "%qD does not have a mappable type in %qs clause", t
,
6924 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6929 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
6931 error_at (OMP_CLAUSE_LOCATION (c
),
6932 "%qE appears more than once on the same "
6933 "%<declare target%> directive", t
);
6937 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6940 case OMP_CLAUSE_UNIFORM
:
6941 t
= OMP_CLAUSE_DECL (c
);
6942 if (TREE_CODE (t
) != PARM_DECL
)
6944 if (processing_template_decl
)
6947 error ("%qD is not an argument in %<uniform%> clause", t
);
6949 error ("%qE is not an argument in %<uniform%> clause", t
);
6953 /* map_head bitmap is used as uniform_head if declare_simd. */
6954 bitmap_set_bit (&map_head
, DECL_UID (t
));
6955 goto check_dup_generic
;
6957 case OMP_CLAUSE_GRAINSIZE
:
6958 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
6959 if (t
== error_mark_node
)
6961 else if (!type_dependent_expression_p (t
)
6962 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6964 error ("%<grainsize%> expression must be integral");
6969 t
= mark_rvalue_use (t
);
6970 if (!processing_template_decl
)
6972 t
= maybe_constant_value (t
);
6973 if (TREE_CODE (t
) == INTEGER_CST
6974 && tree_int_cst_sgn (t
) != 1)
6976 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6977 "%<grainsize%> value must be positive");
6978 t
= integer_one_node
;
6980 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6982 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
6986 case OMP_CLAUSE_PRIORITY
:
6987 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
6988 if (t
== error_mark_node
)
6990 else if (!type_dependent_expression_p (t
)
6991 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6993 error ("%<priority%> expression must be integral");
6998 t
= mark_rvalue_use (t
);
6999 if (!processing_template_decl
)
7001 t
= maybe_constant_value (t
);
7002 if (TREE_CODE (t
) == INTEGER_CST
7003 && tree_int_cst_sgn (t
) == -1)
7005 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7006 "%<priority%> value must be non-negative");
7007 t
= integer_one_node
;
7009 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7011 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
7015 case OMP_CLAUSE_HINT
:
7016 t
= OMP_CLAUSE_HINT_EXPR (c
);
7017 if (t
== error_mark_node
)
7019 else if (!type_dependent_expression_p (t
)
7020 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7022 error ("%<num_tasks%> expression must be integral");
7027 t
= mark_rvalue_use (t
);
7028 if (!processing_template_decl
)
7030 t
= maybe_constant_value (t
);
7031 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7033 OMP_CLAUSE_HINT_EXPR (c
) = t
;
7037 case OMP_CLAUSE_IS_DEVICE_PTR
:
7038 case OMP_CLAUSE_USE_DEVICE_PTR
:
7039 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
7040 t
= OMP_CLAUSE_DECL (c
);
7041 if (!type_dependent_expression_p (t
))
7043 tree type
= TREE_TYPE (t
);
7044 if (TREE_CODE (type
) != POINTER_TYPE
7045 && TREE_CODE (type
) != ARRAY_TYPE
7046 && (TREE_CODE (type
) != REFERENCE_TYPE
7047 || (TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
7048 && TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
)))
7050 error_at (OMP_CLAUSE_LOCATION (c
),
7051 "%qs variable is neither a pointer, nor an array"
7052 "nor reference to pointer or array",
7053 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7057 goto check_dup_generic
;
7059 case OMP_CLAUSE_NOWAIT
:
7060 case OMP_CLAUSE_DEFAULT
:
7061 case OMP_CLAUSE_UNTIED
:
7062 case OMP_CLAUSE_COLLAPSE
:
7063 case OMP_CLAUSE_MERGEABLE
:
7064 case OMP_CLAUSE_PARALLEL
:
7065 case OMP_CLAUSE_FOR
:
7066 case OMP_CLAUSE_SECTIONS
:
7067 case OMP_CLAUSE_TASKGROUP
:
7068 case OMP_CLAUSE_PROC_BIND
:
7069 case OMP_CLAUSE_NOGROUP
:
7070 case OMP_CLAUSE_THREADS
:
7071 case OMP_CLAUSE_SIMD
:
7072 case OMP_CLAUSE_DEFAULTMAP
:
7073 case OMP_CLAUSE__CILK_FOR_COUNT_
:
7074 case OMP_CLAUSE_AUTO
:
7075 case OMP_CLAUSE_INDEPENDENT
:
7076 case OMP_CLAUSE_SEQ
:
7079 case OMP_CLAUSE_TILE
:
7080 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
7081 list
= TREE_CHAIN (list
))
7083 t
= TREE_VALUE (list
);
7085 if (t
== error_mark_node
)
7087 else if (!type_dependent_expression_p (t
)
7088 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7090 error ("%<tile%> value must be integral");
7095 t
= mark_rvalue_use (t
);
7096 if (!processing_template_decl
)
7098 t
= maybe_constant_value (t
);
7099 if (TREE_CODE (t
) == INTEGER_CST
7100 && tree_int_cst_sgn (t
) != 1
7101 && t
!= integer_minus_one_node
)
7103 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7104 "%<tile%> value must be positive");
7105 t
= integer_one_node
;
7108 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7111 /* Update list item. */
7112 TREE_VALUE (list
) = t
;
7116 case OMP_CLAUSE_ORDERED
:
7117 ordered_seen
= true;
7120 case OMP_CLAUSE_INBRANCH
:
7121 case OMP_CLAUSE_NOTINBRANCH
:
7124 error ("%<inbranch%> clause is incompatible with "
7136 *pc
= OMP_CLAUSE_CHAIN (c
);
7138 pc
= &OMP_CLAUSE_CHAIN (c
);
7141 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
7143 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
7144 bool remove
= false;
7145 bool need_complete_type
= false;
7146 bool need_default_ctor
= false;
7147 bool need_copy_ctor
= false;
7148 bool need_copy_assignment
= false;
7149 bool need_implicitly_determined
= false;
7150 bool need_dtor
= false;
7151 tree type
, inner_type
;
7155 case OMP_CLAUSE_SHARED
:
7156 need_implicitly_determined
= true;
7158 case OMP_CLAUSE_PRIVATE
:
7159 need_complete_type
= true;
7160 need_default_ctor
= true;
7162 need_implicitly_determined
= true;
7164 case OMP_CLAUSE_FIRSTPRIVATE
:
7165 need_complete_type
= true;
7166 need_copy_ctor
= true;
7168 need_implicitly_determined
= true;
7170 case OMP_CLAUSE_LASTPRIVATE
:
7171 need_complete_type
= true;
7172 need_copy_assignment
= true;
7173 need_implicitly_determined
= true;
7175 case OMP_CLAUSE_REDUCTION
:
7176 need_implicitly_determined
= true;
7178 case OMP_CLAUSE_LINEAR
:
7179 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
7180 need_implicitly_determined
= true;
7181 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
7182 && !bitmap_bit_p (&map_head
,
7183 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
7185 error_at (OMP_CLAUSE_LOCATION (c
),
7186 "%<linear%> clause step is a parameter %qD not "
7187 "specified in %<uniform%> clause",
7188 OMP_CLAUSE_LINEAR_STEP (c
));
7189 *pc
= OMP_CLAUSE_CHAIN (c
);
7193 case OMP_CLAUSE_COPYPRIVATE
:
7194 need_copy_assignment
= true;
7196 case OMP_CLAUSE_COPYIN
:
7197 need_copy_assignment
= true;
7199 case OMP_CLAUSE_SIMDLEN
:
7201 && !processing_template_decl
7202 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
7203 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
7205 error_at (OMP_CLAUSE_LOCATION (c
),
7206 "%<simdlen%> clause value is bigger than "
7207 "%<safelen%> clause value");
7208 OMP_CLAUSE_SIMDLEN_EXPR (c
)
7209 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
7211 pc
= &OMP_CLAUSE_CHAIN (c
);
7213 case OMP_CLAUSE_SCHEDULE
:
7215 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
7216 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
7218 error_at (OMP_CLAUSE_LOCATION (c
),
7219 "%<nonmonotonic%> schedule modifier specified "
7220 "together with %<ordered%> clause");
7221 OMP_CLAUSE_SCHEDULE_KIND (c
)
7222 = (enum omp_clause_schedule_kind
)
7223 (OMP_CLAUSE_SCHEDULE_KIND (c
)
7224 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
7226 pc
= &OMP_CLAUSE_CHAIN (c
);
7228 case OMP_CLAUSE_NOWAIT
:
7229 if (copyprivate_seen
)
7231 error_at (OMP_CLAUSE_LOCATION (c
),
7232 "%<nowait%> clause must not be used together "
7233 "with %<copyprivate%>");
7234 *pc
= OMP_CLAUSE_CHAIN (c
);
7239 pc
= &OMP_CLAUSE_CHAIN (c
);
7243 t
= OMP_CLAUSE_DECL (c
);
7244 if (processing_template_decl
7245 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7247 pc
= &OMP_CLAUSE_CHAIN (c
);
7253 case OMP_CLAUSE_LASTPRIVATE
:
7254 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7256 need_default_ctor
= true;
7261 case OMP_CLAUSE_REDUCTION
:
7262 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
7266 t
= OMP_CLAUSE_DECL (c
);
7269 case OMP_CLAUSE_COPYIN
:
7270 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
7272 error ("%qE must be %<threadprivate%> for %<copyin%>", t
);
7281 if (need_complete_type
|| need_copy_assignment
)
7283 t
= require_complete_type (t
);
7284 if (t
== error_mark_node
)
7286 else if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
7287 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
7290 if (need_implicitly_determined
)
7292 const char *share_name
= NULL
;
7294 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7295 share_name
= "threadprivate";
7296 else switch (cxx_omp_predetermined_sharing (t
))
7298 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
7300 case OMP_CLAUSE_DEFAULT_SHARED
:
7301 /* const vars may be specified in firstprivate clause. */
7302 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
7303 && cxx_omp_const_qual_no_mutable (t
))
7305 share_name
= "shared";
7307 case OMP_CLAUSE_DEFAULT_PRIVATE
:
7308 share_name
= "private";
7315 error ("%qE is predetermined %qs for %qs",
7316 omp_clause_printable_decl (t
), share_name
,
7317 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7322 /* We're interested in the base element, not arrays. */
7323 inner_type
= type
= TREE_TYPE (t
);
7324 if ((need_complete_type
7325 || need_copy_assignment
7326 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
7327 && TREE_CODE (inner_type
) == REFERENCE_TYPE
)
7328 inner_type
= TREE_TYPE (inner_type
);
7329 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
7330 inner_type
= TREE_TYPE (inner_type
);
7332 /* Check for special function availability by building a call to one.
7333 Save the results, because later we won't be in the right context
7334 for making these queries. */
7335 if (CLASS_TYPE_P (inner_type
)
7336 && COMPLETE_TYPE_P (inner_type
)
7337 && (need_default_ctor
|| need_copy_ctor
7338 || need_copy_assignment
|| need_dtor
)
7339 && !type_dependent_expression_p (t
)
7340 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
7341 need_copy_ctor
, need_copy_assignment
,
7346 && c_kind
== OMP_CLAUSE_SHARED
7347 && processing_template_decl
)
7349 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7351 OMP_CLAUSE_DECL (c
) = t
;
7355 *pc
= OMP_CLAUSE_CHAIN (c
);
7357 pc
= &OMP_CLAUSE_CHAIN (c
);
7360 bitmap_obstack_release (NULL
);
7364 /* Start processing OpenMP clauses that can include any
7365 privatization clauses for non-static data members. */
7368 push_omp_privatization_clauses (bool ignore_next
)
7370 if (omp_private_member_ignore_next
)
7372 omp_private_member_ignore_next
= ignore_next
;
7375 omp_private_member_ignore_next
= ignore_next
;
7376 if (omp_private_member_map
)
7377 omp_private_member_vec
.safe_push (error_mark_node
);
7378 return push_stmt_list ();
7381 /* Revert remapping of any non-static data members since
7382 the last push_omp_privatization_clauses () call. */
7385 pop_omp_privatization_clauses (tree stmt
)
7387 if (stmt
== NULL_TREE
)
7389 stmt
= pop_stmt_list (stmt
);
7390 if (omp_private_member_map
)
7392 while (!omp_private_member_vec
.is_empty ())
7394 tree t
= omp_private_member_vec
.pop ();
7395 if (t
== error_mark_node
)
7400 bool no_decl_expr
= t
== integer_zero_node
;
7402 t
= omp_private_member_vec
.pop ();
7403 tree
*v
= omp_private_member_map
->get (t
);
7407 omp_private_member_map
->remove (t
);
7409 delete omp_private_member_map
;
7410 omp_private_member_map
= NULL
;
7415 /* Remember OpenMP privatization clauses mapping and clear it.
7416 Used for lambdas. */
7419 save_omp_privatization_clauses (vec
<tree
> &save
)
7422 if (omp_private_member_ignore_next
)
7423 save
.safe_push (integer_one_node
);
7424 omp_private_member_ignore_next
= false;
7425 if (!omp_private_member_map
)
7428 while (!omp_private_member_vec
.is_empty ())
7430 tree t
= omp_private_member_vec
.pop ();
7431 if (t
== error_mark_node
)
7437 if (t
== integer_zero_node
)
7438 t
= omp_private_member_vec
.pop ();
7439 tree
*v
= omp_private_member_map
->get (t
);
7441 save
.safe_push (*v
);
7446 delete omp_private_member_map
;
7447 omp_private_member_map
= NULL
;
7450 /* Restore OpenMP privatization clauses mapping saved by the
7454 restore_omp_privatization_clauses (vec
<tree
> &save
)
7456 gcc_assert (omp_private_member_vec
.is_empty ());
7457 omp_private_member_ignore_next
= false;
7458 if (save
.is_empty ())
7460 if (save
.length () == 1 && save
[0] == integer_one_node
)
7462 omp_private_member_ignore_next
= true;
7467 omp_private_member_map
= new hash_map
<tree
, tree
>;
7468 while (!save
.is_empty ())
7470 tree t
= save
.pop ();
7472 if (t
!= error_mark_node
)
7474 if (t
== integer_one_node
)
7476 omp_private_member_ignore_next
= true;
7477 gcc_assert (save
.is_empty ());
7480 if (t
== integer_zero_node
)
7482 tree
&v
= omp_private_member_map
->get_or_insert (t
);
7485 omp_private_member_vec
.safe_push (t
);
7487 omp_private_member_vec
.safe_push (n
);
7492 /* For all variables in the tree_list VARS, mark them as thread local. */
7495 finish_omp_threadprivate (tree vars
)
7499 /* Mark every variable in VARS to be assigned thread local storage. */
7500 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7502 tree v
= TREE_PURPOSE (t
);
7504 if (error_operand_p (v
))
7506 else if (!VAR_P (v
))
7507 error ("%<threadprivate%> %qD is not file, namespace "
7508 "or block scope variable", v
);
7509 /* If V had already been marked threadprivate, it doesn't matter
7510 whether it had been used prior to this point. */
7511 else if (TREE_USED (v
)
7512 && (DECL_LANG_SPECIFIC (v
) == NULL
7513 || !CP_DECL_THREADPRIVATE_P (v
)))
7514 error ("%qE declared %<threadprivate%> after first use", v
);
7515 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7516 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7517 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
7518 error ("%<threadprivate%> %qE has incomplete type", v
);
7519 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
7520 && CP_DECL_CONTEXT (v
) != current_class_type
)
7521 error ("%<threadprivate%> %qE directive not "
7522 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
7525 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
7526 if (DECL_LANG_SPECIFIC (v
) == NULL
)
7528 retrofit_lang_decl (v
);
7530 /* Make sure that DECL_DISCRIMINATOR_P continues to be true
7531 after the allocation of the lang_decl structure. */
7532 if (DECL_DISCRIMINATOR_P (v
))
7533 DECL_LANG_SPECIFIC (v
)->u
.base
.u2sel
= 1;
7536 if (! CP_DECL_THREAD_LOCAL_P (v
))
7538 CP_DECL_THREAD_LOCAL_P (v
) = true;
7539 set_decl_tls_model (v
, decl_default_tls_model (v
));
7540 /* If rtl has been already set for this var, call
7541 make_decl_rtl once again, so that encode_section_info
7542 has a chance to look at the new decl flags. */
7543 if (DECL_RTL_SET_P (v
))
7546 CP_DECL_THREADPRIVATE_P (v
) = 1;
7551 /* Build an OpenMP structured block. */
7554 begin_omp_structured_block (void)
7556 return do_pushlevel (sk_omp
);
7560 finish_omp_structured_block (tree block
)
7562 return do_poplevel (block
);
7565 /* Similarly, except force the retention of the BLOCK. */
7568 begin_omp_parallel (void)
7570 keep_next_level (true);
7571 return begin_omp_structured_block ();
7574 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
7578 finish_oacc_data (tree clauses
, tree block
)
7582 block
= finish_omp_structured_block (block
);
7584 stmt
= make_node (OACC_DATA
);
7585 TREE_TYPE (stmt
) = void_type_node
;
7586 OACC_DATA_CLAUSES (stmt
) = clauses
;
7587 OACC_DATA_BODY (stmt
) = block
;
7589 return add_stmt (stmt
);
7592 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
7596 finish_oacc_host_data (tree clauses
, tree block
)
7600 block
= finish_omp_structured_block (block
);
7602 stmt
= make_node (OACC_HOST_DATA
);
7603 TREE_TYPE (stmt
) = void_type_node
;
7604 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
7605 OACC_HOST_DATA_BODY (stmt
) = block
;
7607 return add_stmt (stmt
);
7610 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
7614 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
7616 body
= finish_omp_structured_block (body
);
7618 tree stmt
= make_node (code
);
7619 TREE_TYPE (stmt
) = void_type_node
;
7620 OMP_BODY (stmt
) = body
;
7621 OMP_CLAUSES (stmt
) = clauses
;
7623 return add_stmt (stmt
);
7627 finish_omp_parallel (tree clauses
, tree body
)
7631 body
= finish_omp_structured_block (body
);
7633 stmt
= make_node (OMP_PARALLEL
);
7634 TREE_TYPE (stmt
) = void_type_node
;
7635 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
7636 OMP_PARALLEL_BODY (stmt
) = body
;
7638 return add_stmt (stmt
);
7642 begin_omp_task (void)
7644 keep_next_level (true);
7645 return begin_omp_structured_block ();
7649 finish_omp_task (tree clauses
, tree body
)
7653 body
= finish_omp_structured_block (body
);
7655 stmt
= make_node (OMP_TASK
);
7656 TREE_TYPE (stmt
) = void_type_node
;
7657 OMP_TASK_CLAUSES (stmt
) = clauses
;
7658 OMP_TASK_BODY (stmt
) = body
;
7660 return add_stmt (stmt
);
7663 /* Helper function for finish_omp_for. Convert Ith random access iterator
7664 into integral iterator. Return FALSE if successful. */
7667 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
7668 tree declv
, tree orig_declv
, tree initv
,
7669 tree condv
, tree incrv
, tree
*body
,
7670 tree
*pre_body
, tree
&clauses
, tree
*lastp
,
7671 int collapse
, int ordered
)
7673 tree diff
, iter_init
, iter_incr
= NULL
, last
;
7674 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
7675 tree decl
= TREE_VEC_ELT (declv
, i
);
7676 tree init
= TREE_VEC_ELT (initv
, i
);
7677 tree cond
= TREE_VEC_ELT (condv
, i
);
7678 tree incr
= TREE_VEC_ELT (incrv
, i
);
7680 location_t elocus
= locus
;
7682 if (init
&& EXPR_HAS_LOCATION (init
))
7683 elocus
= EXPR_LOCATION (init
);
7685 cond
= cp_fully_fold (cond
);
7686 switch (TREE_CODE (cond
))
7693 if (TREE_OPERAND (cond
, 1) == iter
)
7694 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
7695 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
7696 if (TREE_OPERAND (cond
, 0) != iter
)
7697 cond
= error_mark_node
;
7700 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
7703 TREE_OPERAND (cond
, 1), ERROR_MARK
,
7704 NULL
, tf_warning_or_error
);
7705 if (error_operand_p (tem
))
7710 cond
= error_mark_node
;
7713 if (cond
== error_mark_node
)
7715 error_at (elocus
, "invalid controlling predicate");
7718 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
7719 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
7720 tf_warning_or_error
);
7721 diff
= cp_fully_fold (diff
);
7722 if (error_operand_p (diff
))
7724 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
7726 error_at (elocus
, "difference between %qE and %qD does not have integer type",
7727 TREE_OPERAND (cond
, 1), iter
);
7730 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
,
7731 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
7732 cond
, cp_walk_subtrees
))
7735 switch (TREE_CODE (incr
))
7737 case PREINCREMENT_EXPR
:
7738 case PREDECREMENT_EXPR
:
7739 case POSTINCREMENT_EXPR
:
7740 case POSTDECREMENT_EXPR
:
7741 if (TREE_OPERAND (incr
, 0) != iter
)
7743 incr
= error_mark_node
;
7746 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
7747 TREE_CODE (incr
), iter
,
7748 tf_warning_or_error
);
7749 if (error_operand_p (iter_incr
))
7751 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
7752 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
7753 incr
= integer_one_node
;
7755 incr
= integer_minus_one_node
;
7758 if (TREE_OPERAND (incr
, 0) != iter
)
7759 incr
= error_mark_node
;
7760 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
7761 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
7763 tree rhs
= TREE_OPERAND (incr
, 1);
7764 if (TREE_OPERAND (rhs
, 0) == iter
)
7766 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
7768 incr
= error_mark_node
;
7771 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7772 iter
, TREE_CODE (rhs
),
7773 TREE_OPERAND (rhs
, 1),
7774 tf_warning_or_error
);
7775 if (error_operand_p (iter_incr
))
7777 incr
= TREE_OPERAND (rhs
, 1);
7778 incr
= cp_convert (TREE_TYPE (diff
), incr
,
7779 tf_warning_or_error
);
7780 if (TREE_CODE (rhs
) == MINUS_EXPR
)
7782 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
7783 incr
= fold_simple (incr
);
7785 if (TREE_CODE (incr
) != INTEGER_CST
7786 && (TREE_CODE (incr
) != NOP_EXPR
7787 || (TREE_CODE (TREE_OPERAND (incr
, 0))
7792 else if (TREE_OPERAND (rhs
, 1) == iter
)
7794 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
7795 || TREE_CODE (rhs
) != PLUS_EXPR
)
7796 incr
= error_mark_node
;
7799 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
7801 TREE_OPERAND (rhs
, 0),
7804 tf_warning_or_error
);
7805 if (error_operand_p (iter_incr
))
7807 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7810 tf_warning_or_error
);
7811 if (error_operand_p (iter_incr
))
7813 incr
= TREE_OPERAND (rhs
, 0);
7818 incr
= error_mark_node
;
7821 incr
= error_mark_node
;
7824 incr
= error_mark_node
;
7828 if (incr
== error_mark_node
)
7830 error_at (elocus
, "invalid increment expression");
7834 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
7835 bool taskloop_iv_seen
= false;
7836 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7837 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
7838 && OMP_CLAUSE_DECL (c
) == iter
)
7840 if (code
== OMP_TASKLOOP
)
7842 taskloop_iv_seen
= true;
7843 OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c
) = 1;
7847 else if (code
== OMP_TASKLOOP
7848 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
7849 && OMP_CLAUSE_DECL (c
) == iter
)
7851 taskloop_iv_seen
= true;
7852 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
7855 decl
= create_temporary_var (TREE_TYPE (diff
));
7857 add_decl_expr (decl
);
7858 last
= create_temporary_var (TREE_TYPE (diff
));
7860 add_decl_expr (last
);
7861 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
7862 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7864 incr_var
= create_temporary_var (TREE_TYPE (diff
));
7865 pushdecl (incr_var
);
7866 add_decl_expr (incr_var
);
7868 gcc_assert (stmts_are_full_exprs_p ());
7869 tree diffvar
= NULL_TREE
;
7870 if (code
== OMP_TASKLOOP
)
7872 if (!taskloop_iv_seen
)
7874 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7875 OMP_CLAUSE_DECL (ivc
) = iter
;
7876 cxx_omp_finish_clause (ivc
, NULL
);
7877 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
7880 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7881 OMP_CLAUSE_DECL (lvc
) = last
;
7882 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
7884 diffvar
= create_temporary_var (TREE_TYPE (diff
));
7886 add_decl_expr (diffvar
);
7889 orig_pre_body
= *pre_body
;
7890 *pre_body
= push_stmt_list ();
7892 add_stmt (orig_pre_body
);
7894 finish_expr_stmt (build_x_modify_expr (elocus
,
7895 iter
, NOP_EXPR
, init
,
7896 tf_warning_or_error
));
7897 init
= build_int_cst (TREE_TYPE (diff
), 0);
7898 if (c
&& iter_incr
== NULL
7899 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7903 finish_expr_stmt (build_x_modify_expr (elocus
,
7905 incr
, tf_warning_or_error
));
7908 iter_incr
= build_x_modify_expr (elocus
,
7909 iter
, PLUS_EXPR
, incr
,
7910 tf_warning_or_error
);
7912 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
7914 finish_expr_stmt (build_x_modify_expr (elocus
,
7915 last
, NOP_EXPR
, init
,
7916 tf_warning_or_error
));
7919 finish_expr_stmt (build_x_modify_expr (elocus
,
7921 diff
, tf_warning_or_error
));
7924 *pre_body
= pop_stmt_list (*pre_body
);
7926 cond
= cp_build_binary_op (elocus
,
7927 TREE_CODE (cond
), decl
, diff
,
7928 tf_warning_or_error
);
7929 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
7930 elocus
, incr
, NULL_TREE
);
7933 *body
= push_stmt_list ();
7934 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
7935 iter_init
= build_x_modify_expr (elocus
,
7936 iter
, PLUS_EXPR
, iter_init
,
7937 tf_warning_or_error
);
7938 if (iter_init
!= error_mark_node
)
7939 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7940 finish_expr_stmt (iter_init
);
7941 finish_expr_stmt (build_x_modify_expr (elocus
,
7942 last
, NOP_EXPR
, decl
,
7943 tf_warning_or_error
));
7944 add_stmt (orig_body
);
7945 *body
= pop_stmt_list (*body
);
7949 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
7951 finish_expr_stmt (iter_incr
);
7955 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
7956 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
7957 iter_init
, iter_incr
);
7958 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
7959 iter_init
= build_x_modify_expr (elocus
,
7960 iter
, PLUS_EXPR
, iter_init
,
7961 tf_warning_or_error
);
7962 if (iter_init
!= error_mark_node
)
7963 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7964 finish_expr_stmt (iter_init
);
7966 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
7967 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
7970 TREE_VEC_ELT (declv
, i
) = decl
;
7971 TREE_VEC_ELT (initv
, i
) = init
;
7972 TREE_VEC_ELT (condv
, i
) = cond
;
7973 TREE_VEC_ELT (incrv
, i
) = incr
;
7979 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
7980 are directly for their associated operands in the statement. DECL
7981 and INIT are a combo; if DECL is NULL then INIT ought to be a
7982 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
7983 optional statements that need to go before the loop into its
7987 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
7988 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
7989 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
7991 tree omp_for
= NULL
, orig_incr
= NULL
;
7992 tree decl
= NULL
, init
, cond
, incr
, orig_decl
= NULL_TREE
, block
= NULL_TREE
;
7993 tree last
= NULL_TREE
;
7999 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
8000 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
8001 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
8002 if (TREE_VEC_LENGTH (declv
) > 1)
8004 tree c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
8006 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
8007 if (collapse
!= TREE_VEC_LENGTH (declv
))
8008 ordered
= TREE_VEC_LENGTH (declv
);
8010 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8012 decl
= TREE_VEC_ELT (declv
, i
);
8013 init
= TREE_VEC_ELT (initv
, i
);
8014 cond
= TREE_VEC_ELT (condv
, i
);
8015 incr
= TREE_VEC_ELT (incrv
, i
);
8021 switch (TREE_CODE (init
))
8024 decl
= TREE_OPERAND (init
, 0);
8025 init
= TREE_OPERAND (init
, 1);
8028 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
8030 decl
= TREE_OPERAND (init
, 0);
8031 init
= TREE_OPERAND (init
, 2);
8041 "expected iteration declaration or initialization");
8046 if (init
&& EXPR_HAS_LOCATION (init
))
8047 elocus
= EXPR_LOCATION (init
);
8051 error_at (elocus
, "missing controlling predicate");
8057 error_at (elocus
, "missing increment expression");
8061 TREE_VEC_ELT (declv
, i
) = decl
;
8062 TREE_VEC_ELT (initv
, i
) = init
;
8069 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
8071 && !c_omp_check_loop_iv_exprs (locus
, declv
,
8072 TREE_VEC_ELT (declv
, i
), orig_init
,
8073 NULL_TREE
, cp_walk_subtrees
))
8079 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
8083 stmt
= make_node (code
);
8085 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8087 /* This is really just a place-holder. We'll be decomposing this
8088 again and going through the cp_build_modify_expr path below when
8089 we instantiate the thing. */
8090 TREE_VEC_ELT (initv
, i
)
8091 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
8092 TREE_VEC_ELT (initv
, i
));
8095 TREE_TYPE (stmt
) = void_type_node
;
8096 OMP_FOR_INIT (stmt
) = initv
;
8097 OMP_FOR_COND (stmt
) = condv
;
8098 OMP_FOR_INCR (stmt
) = incrv
;
8099 OMP_FOR_BODY (stmt
) = body
;
8100 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
8101 OMP_FOR_CLAUSES (stmt
) = clauses
;
8103 SET_EXPR_LOCATION (stmt
, locus
);
8104 return add_stmt (stmt
);
8108 orig_declv
= copy_node (declv
);
8110 if (processing_template_decl
)
8111 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
8113 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
8115 decl
= TREE_VEC_ELT (declv
, i
);
8116 init
= TREE_VEC_ELT (initv
, i
);
8117 cond
= TREE_VEC_ELT (condv
, i
);
8118 incr
= TREE_VEC_ELT (incrv
, i
);
8120 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8123 if (init
&& EXPR_HAS_LOCATION (init
))
8124 elocus
= EXPR_LOCATION (init
);
8128 error_at (elocus
, "expected iteration declaration or initialization");
8132 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
8135 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8136 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
8137 TREE_CODE (TREE_OPERAND (incr
, 1)),
8138 TREE_OPERAND (incr
, 2),
8139 tf_warning_or_error
);
8142 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
8144 if (code
== OMP_SIMD
)
8146 error_at (elocus
, "%<#pragma omp simd%> used with class "
8147 "iteration variable %qE", decl
);
8150 if (code
== CILK_FOR
&& i
== 0)
8152 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
8153 initv
, condv
, incrv
, &body
,
8154 &pre_body
, clauses
, &last
,
8160 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
8161 && !TYPE_PTR_P (TREE_TYPE (decl
)))
8163 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
8167 if (!processing_template_decl
)
8169 init
= fold_build_cleanup_point_expr (TREE_TYPE (init
), init
);
8170 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
8171 tf_warning_or_error
);
8174 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
8176 && TREE_SIDE_EFFECTS (cond
)
8177 && COMPARISON_CLASS_P (cond
)
8178 && !processing_template_decl
)
8180 tree t
= TREE_OPERAND (cond
, 0);
8181 if (TREE_SIDE_EFFECTS (t
)
8183 && (TREE_CODE (t
) != NOP_EXPR
8184 || TREE_OPERAND (t
, 0) != decl
))
8185 TREE_OPERAND (cond
, 0)
8186 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8188 t
= TREE_OPERAND (cond
, 1);
8189 if (TREE_SIDE_EFFECTS (t
)
8191 && (TREE_CODE (t
) != NOP_EXPR
8192 || TREE_OPERAND (t
, 0) != decl
))
8193 TREE_OPERAND (cond
, 1)
8194 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8196 if (decl
== error_mark_node
|| init
== error_mark_node
)
8199 TREE_VEC_ELT (declv
, i
) = decl
;
8200 TREE_VEC_ELT (initv
, i
) = init
;
8201 TREE_VEC_ELT (condv
, i
) = cond
;
8202 TREE_VEC_ELT (incrv
, i
) = incr
;
8206 if (IS_EMPTY_STMT (pre_body
))
8209 if (code
== CILK_FOR
&& !processing_template_decl
)
8210 block
= push_stmt_list ();
8212 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
8213 incrv
, body
, pre_body
);
8215 /* Check for iterators appearing in lb, b or incr expressions. */
8216 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
8217 omp_for
= NULL_TREE
;
8219 if (omp_for
== NULL
)
8222 pop_stmt_list (block
);
8228 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
8230 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
), 0);
8231 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
8233 if (TREE_CODE (incr
) != MODIFY_EXPR
)
8236 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
8237 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
8238 && !processing_template_decl
)
8240 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
8241 if (TREE_SIDE_EFFECTS (t
)
8243 && (TREE_CODE (t
) != NOP_EXPR
8244 || TREE_OPERAND (t
, 0) != decl
))
8245 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
8246 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8248 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8249 if (TREE_SIDE_EFFECTS (t
)
8251 && (TREE_CODE (t
) != NOP_EXPR
8252 || TREE_OPERAND (t
, 0) != decl
))
8253 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8254 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8258 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
8260 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8262 /* For simd loops with non-static data member iterators, we could have added
8263 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
8264 step at this point, fill it in. */
8265 if (code
== OMP_SIMD
&& !processing_template_decl
8266 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
8267 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
8268 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
8269 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
8271 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
8272 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
8273 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8275 switch (TREE_CODE (incr
))
8277 case PREINCREMENT_EXPR
:
8278 case POSTINCREMENT_EXPR
:
8279 /* c_omp_for_incr_canonicalize_ptr() should have been
8280 called to massage things appropriately. */
8281 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8282 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
8284 case PREDECREMENT_EXPR
:
8285 case POSTDECREMENT_EXPR
:
8286 /* c_omp_for_incr_canonicalize_ptr() should have been
8287 called to massage things appropriately. */
8288 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8289 OMP_CLAUSE_LINEAR_STEP (c
)
8290 = build_int_cst (TREE_TYPE (decl
), -1);
8293 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8294 incr
= TREE_OPERAND (incr
, 1);
8295 switch (TREE_CODE (incr
))
8298 if (TREE_OPERAND (incr
, 1) == decl
)
8299 step
= TREE_OPERAND (incr
, 0);
8301 step
= TREE_OPERAND (incr
, 1);
8304 case POINTER_PLUS_EXPR
:
8305 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8306 step
= TREE_OPERAND (incr
, 1);
8311 stept
= TREE_TYPE (decl
);
8312 if (POINTER_TYPE_P (stept
))
8314 step
= fold_convert (stept
, step
);
8315 if (TREE_CODE (incr
) == MINUS_EXPR
)
8316 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
8317 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
8326 tree omp_par
= make_node (OMP_PARALLEL
);
8327 TREE_TYPE (omp_par
) = void_type_node
;
8328 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
8329 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
8330 TREE_SIDE_EFFECTS (bind
) = 1;
8331 BIND_EXPR_BODY (bind
) = pop_stmt_list (block
);
8332 OMP_PARALLEL_BODY (omp_par
) = bind
;
8333 if (OMP_FOR_PRE_BODY (omp_for
))
8335 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
8336 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
8338 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
8339 decl
= TREE_OPERAND (init
, 0);
8340 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
8341 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8342 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
, *pc
;
8343 clauses
= OMP_FOR_CLAUSES (omp_for
);
8344 OMP_FOR_CLAUSES (omp_for
) = NULL_TREE
;
8345 for (pc
= &clauses
; *pc
; )
8346 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_SCHEDULE
)
8348 gcc_assert (OMP_FOR_CLAUSES (omp_for
) == NULL_TREE
);
8349 OMP_FOR_CLAUSES (omp_for
) = *pc
;
8350 *pc
= OMP_CLAUSE_CHAIN (*pc
);
8351 OMP_CLAUSE_CHAIN (OMP_FOR_CLAUSES (omp_for
)) = NULL_TREE
;
8355 gcc_assert (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_FIRSTPRIVATE
);
8356 pc
= &OMP_CLAUSE_CHAIN (*pc
);
8358 if (TREE_CODE (t
) != INTEGER_CST
)
8360 TREE_OPERAND (cond
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
8361 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8362 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
8363 OMP_CLAUSE_CHAIN (c
) = clauses
;
8366 if (TREE_CODE (incr
) == MODIFY_EXPR
)
8368 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8369 if (TREE_CODE (t
) != INTEGER_CST
)
8371 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8372 = get_temp_regvar (TREE_TYPE (t
), t
);
8373 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8374 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8375 OMP_CLAUSE_CHAIN (c
) = clauses
;
8379 t
= TREE_OPERAND (init
, 1);
8380 if (TREE_CODE (t
) != INTEGER_CST
)
8382 TREE_OPERAND (init
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
8383 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8384 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
8385 OMP_CLAUSE_CHAIN (c
) = clauses
;
8388 if (orig_decl
&& orig_decl
!= decl
)
8390 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8391 OMP_CLAUSE_DECL (c
) = orig_decl
;
8392 OMP_CLAUSE_CHAIN (c
) = clauses
;
8397 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8398 OMP_CLAUSE_DECL (c
) = last
;
8399 OMP_CLAUSE_CHAIN (c
) = clauses
;
8402 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
8403 OMP_CLAUSE_DECL (c
) = decl
;
8404 OMP_CLAUSE_CHAIN (c
) = clauses
;
8406 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
8407 OMP_CLAUSE_OPERAND (c
, 0)
8408 = cilk_for_number_of_iterations (omp_for
);
8409 OMP_CLAUSE_CHAIN (c
) = clauses
;
8410 OMP_PARALLEL_CLAUSES (omp_par
) = finish_omp_clauses (c
, C_ORT_CILK
);
8414 else if (code
== CILK_FOR
&& processing_template_decl
)
8416 tree c
, clauses
= OMP_FOR_CLAUSES (omp_for
);
8417 if (orig_decl
&& orig_decl
!= decl
)
8419 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8420 OMP_CLAUSE_DECL (c
) = orig_decl
;
8421 OMP_CLAUSE_CHAIN (c
) = clauses
;
8426 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8427 OMP_CLAUSE_DECL (c
) = last
;
8428 OMP_CLAUSE_CHAIN (c
) = clauses
;
8431 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8437 finish_omp_atomic (enum tree_code code
, enum tree_code opcode
, tree lhs
,
8438 tree rhs
, tree v
, tree lhs1
, tree rhs1
, bool seq_cst
)
8453 dependent_p
= false;
8456 /* Even in a template, we can detect invalid uses of the atomic
8457 pragma if neither LHS nor RHS is type-dependent. */
8458 if (processing_template_decl
)
8460 dependent_p
= (type_dependent_expression_p (lhs
)
8461 || (rhs
&& type_dependent_expression_p (rhs
))
8462 || (v
&& type_dependent_expression_p (v
))
8463 || (lhs1
&& type_dependent_expression_p (lhs1
))
8464 || (rhs1
&& type_dependent_expression_p (rhs1
)));
8467 lhs
= build_non_dependent_expr (lhs
);
8469 rhs
= build_non_dependent_expr (rhs
);
8471 v
= build_non_dependent_expr (v
);
8473 lhs1
= build_non_dependent_expr (lhs1
);
8475 rhs1
= build_non_dependent_expr (rhs1
);
8480 bool swapped
= false;
8481 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
8483 std::swap (rhs
, rhs1
);
8484 swapped
= !commutative_tree_code (opcode
);
8486 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
8488 if (code
== OMP_ATOMIC
)
8489 error ("%<#pragma omp atomic update%> uses two different "
8490 "expressions for memory");
8492 error ("%<#pragma omp atomic capture%> uses two different "
8493 "expressions for memory");
8496 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
8498 if (code
== OMP_ATOMIC
)
8499 error ("%<#pragma omp atomic update%> uses two different "
8500 "expressions for memory");
8502 error ("%<#pragma omp atomic capture%> uses two different "
8503 "expressions for memory");
8506 stmt
= c_finish_omp_atomic (input_location
, code
, opcode
, lhs
, rhs
,
8507 v
, lhs1
, rhs1
, swapped
, seq_cst
,
8508 processing_template_decl
!= 0);
8509 if (stmt
== error_mark_node
)
8512 if (processing_template_decl
)
8514 if (code
== OMP_ATOMIC_READ
)
8516 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs
),
8517 OMP_ATOMIC_READ
, orig_lhs
);
8518 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8519 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8523 if (opcode
== NOP_EXPR
)
8524 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
8526 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
8528 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
8529 COMPOUND_EXPR
, orig_rhs1
, stmt
);
8530 if (code
!= OMP_ATOMIC
)
8532 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs1
),
8533 code
, orig_lhs1
, stmt
);
8534 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8535 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8538 stmt
= build2 (OMP_ATOMIC
, void_type_node
, integer_zero_node
, stmt
);
8539 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8541 finish_expr_stmt (stmt
);
8545 finish_omp_barrier (void)
8547 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
8548 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8549 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8550 release_tree_vector (vec
);
8551 finish_expr_stmt (stmt
);
8555 finish_omp_flush (void)
8557 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
8558 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8559 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8560 release_tree_vector (vec
);
8561 finish_expr_stmt (stmt
);
8565 finish_omp_taskwait (void)
8567 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
8568 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8569 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8570 release_tree_vector (vec
);
8571 finish_expr_stmt (stmt
);
8575 finish_omp_taskyield (void)
8577 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
8578 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8579 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8580 release_tree_vector (vec
);
8581 finish_expr_stmt (stmt
);
8585 finish_omp_cancel (tree clauses
)
8587 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
8589 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8591 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
8593 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8595 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8599 error ("%<#pragma omp cancel%> must specify one of "
8600 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8603 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8604 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
8605 if (ifc
!= NULL_TREE
)
8607 tree type
= TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc
));
8608 ifc
= fold_build2_loc (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
8609 boolean_type_node
, OMP_CLAUSE_IF_EXPR (ifc
),
8610 build_zero_cst (type
));
8613 ifc
= boolean_true_node
;
8614 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
8615 vec
->quick_push (ifc
);
8616 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8617 release_tree_vector (vec
);
8618 finish_expr_stmt (stmt
);
8622 finish_omp_cancellation_point (tree clauses
)
8624 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
8626 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8628 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
8630 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8632 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8636 error ("%<#pragma omp cancellation point%> must specify one of "
8637 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8640 vec
<tree
, va_gc
> *vec
8641 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
8642 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8643 release_tree_vector (vec
);
8644 finish_expr_stmt (stmt
);
8647 /* Begin a __transaction_atomic or __transaction_relaxed statement.
8648 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
8649 should create an extra compound stmt. */
8652 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
8657 *pcompound
= begin_compound_stmt (0);
8659 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
8661 /* Only add the statement to the function if support enabled. */
8665 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
8666 ? G_("%<__transaction_relaxed%> without "
8667 "transactional memory support enabled")
8668 : G_("%<__transaction_atomic%> without "
8669 "transactional memory support enabled")));
8671 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
8672 TREE_SIDE_EFFECTS (r
) = 1;
8676 /* End a __transaction_atomic or __transaction_relaxed statement.
8677 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
8678 and we should end the compound. If NOEX is non-NULL, we wrap the body in
8679 a MUST_NOT_THROW_EXPR with NOEX as condition. */
8682 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
8684 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
8685 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
8686 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
8687 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
8689 /* noexcept specifications are not allowed for function transactions. */
8690 gcc_assert (!(noex
&& compound_stmt
));
8693 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
8695 protected_set_expr_location
8696 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
8697 TREE_SIDE_EFFECTS (body
) = 1;
8698 TRANSACTION_EXPR_BODY (stmt
) = body
;
8702 finish_compound_stmt (compound_stmt
);
8705 /* Build a __transaction_atomic or __transaction_relaxed expression. If
8706 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
8710 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
8715 expr
= build_must_not_throw_expr (expr
, noex
);
8716 protected_set_expr_location (expr
, loc
);
8717 TREE_SIDE_EFFECTS (expr
) = 1;
8719 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
8720 if (flags
& TM_STMT_ATTR_RELAXED
)
8721 TRANSACTION_EXPR_RELAXED (ret
) = 1;
8722 TREE_SIDE_EFFECTS (ret
) = 1;
8723 SET_EXPR_LOCATION (ret
, loc
);
8728 init_cp_semantics (void)
8732 /* Build a STATIC_ASSERT for a static assertion with the condition
8733 CONDITION and the message text MESSAGE. LOCATION is the location
8734 of the static assertion in the source code. When MEMBER_P, this
8735 static assertion is a member of a class. */
8737 finish_static_assert (tree condition
, tree message
, location_t location
,
8740 if (message
== NULL_TREE
8741 || message
== error_mark_node
8742 || condition
== NULL_TREE
8743 || condition
== error_mark_node
)
8746 if (check_for_bare_parameter_packs (condition
))
8747 condition
= error_mark_node
;
8749 if (type_dependent_expression_p (condition
)
8750 || value_dependent_expression_p (condition
))
8752 /* We're in a template; build a STATIC_ASSERT and put it in
8756 assertion
= make_node (STATIC_ASSERT
);
8757 STATIC_ASSERT_CONDITION (assertion
) = condition
;
8758 STATIC_ASSERT_MESSAGE (assertion
) = message
;
8759 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
8762 maybe_add_class_template_decl_list (current_class_type
,
8766 add_stmt (assertion
);
8771 /* Fold the expression and convert it to a boolean value. */
8772 condition
= instantiate_non_dependent_expr (condition
);
8773 condition
= cp_convert (boolean_type_node
, condition
, tf_warning_or_error
);
8774 condition
= maybe_constant_value (condition
);
8776 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
8777 /* Do nothing; the condition is satisfied. */
8781 location_t saved_loc
= input_location
;
8783 input_location
= location
;
8784 if (TREE_CODE (condition
) == INTEGER_CST
8785 && integer_zerop (condition
))
8787 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
8788 (TREE_TYPE (TREE_TYPE (message
))));
8789 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
8790 /* Report the error. */
8792 error ("static assertion failed");
8794 error ("static assertion failed: %s",
8795 TREE_STRING_POINTER (message
));
8797 else if (condition
&& condition
!= error_mark_node
)
8799 error ("non-constant condition for static assertion");
8800 if (require_potential_rvalue_constant_expression (condition
))
8801 cxx_constant_value (condition
);
8803 input_location
= saved_loc
;
8807 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
8808 suitable for use as a type-specifier.
8810 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
8811 id-expression or a class member access, FALSE when it was parsed as
8812 a full expression. */
8815 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
8816 tsubst_flags_t complain
)
8818 tree type
= NULL_TREE
;
8820 if (!expr
|| error_operand_p (expr
))
8821 return error_mark_node
;
8824 || TREE_CODE (expr
) == TYPE_DECL
8825 || (TREE_CODE (expr
) == BIT_NOT_EXPR
8826 && TYPE_P (TREE_OPERAND (expr
, 0))))
8828 if (complain
& tf_error
)
8829 error ("argument to decltype must be an expression");
8830 return error_mark_node
;
8833 /* Depending on the resolution of DR 1172, we may later need to distinguish
8834 instantiation-dependent but not type-dependent expressions so that, say,
8835 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
8836 if (instantiation_dependent_uneval_expression_p (expr
))
8838 type
= cxx_make_type (DECLTYPE_TYPE
);
8839 DECLTYPE_TYPE_EXPR (type
) = expr
;
8840 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
8841 = id_expression_or_member_access_p
;
8842 SET_TYPE_STRUCTURAL_EQUALITY (type
);
8847 /* The type denoted by decltype(e) is defined as follows: */
8849 expr
= resolve_nondeduced_context (expr
, complain
);
8851 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
8852 return error_mark_node
;
8854 if (type_unknown_p (expr
))
8856 if (complain
& tf_error
)
8857 error ("decltype cannot resolve address of overloaded function");
8858 return error_mark_node
;
8861 /* To get the size of a static data member declared as an array of
8862 unknown bound, we need to instantiate it. */
8864 && VAR_HAD_UNKNOWN_BOUND (expr
)
8865 && DECL_TEMPLATE_INSTANTIATION (expr
))
8866 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
8868 if (id_expression_or_member_access_p
)
8870 /* If e is an id-expression or a class member access (5.2.5
8871 [expr.ref]), decltype(e) is defined as the type of the entity
8872 named by e. If there is no such entity, or e names a set of
8873 overloaded functions, the program is ill-formed. */
8874 if (identifier_p (expr
))
8875 expr
= lookup_name (expr
);
8877 if (INDIRECT_REF_P (expr
))
8878 /* This can happen when the expression is, e.g., "a.b". Just
8879 look at the underlying operand. */
8880 expr
= TREE_OPERAND (expr
, 0);
8882 if (TREE_CODE (expr
) == OFFSET_REF
8883 || TREE_CODE (expr
) == MEMBER_REF
8884 || TREE_CODE (expr
) == SCOPE_REF
)
8885 /* We're only interested in the field itself. If it is a
8886 BASELINK, we will need to see through it in the next
8888 expr
= TREE_OPERAND (expr
, 1);
8890 if (BASELINK_P (expr
))
8891 /* See through BASELINK nodes to the underlying function. */
8892 expr
= BASELINK_FUNCTIONS (expr
);
8894 /* decltype of a decomposition name drops references in the tuple case
8895 (unlike decltype of a normal variable) and keeps cv-qualifiers from
8896 the containing object in the other cases (unlike decltype of a member
8897 access expression). */
8898 if (DECL_DECOMPOSITION_P (expr
))
8900 if (DECL_HAS_VALUE_EXPR_P (expr
))
8901 /* Expr is an array or struct subobject proxy, handle
8902 bit-fields properly. */
8903 return unlowered_expr_type (expr
);
8905 /* Expr is a reference variable for the tuple case. */
8906 return lookup_decomp_type (expr
);
8909 switch (TREE_CODE (expr
))
8912 if (DECL_BIT_FIELD_TYPE (expr
))
8914 type
= DECL_BIT_FIELD_TYPE (expr
);
8917 /* Fall through for fields that aren't bitfields. */
8925 case TEMPLATE_PARM_INDEX
:
8926 expr
= mark_type_use (expr
);
8927 type
= TREE_TYPE (expr
);
8931 type
= error_mark_node
;
8936 mark_type_use (expr
);
8937 type
= is_bitfield_expr_with_lowered_type (expr
);
8939 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
8947 /* We can get here when the id-expression refers to an
8948 enumerator or non-type template parameter. */
8949 type
= TREE_TYPE (expr
);
8953 /* Handle instantiated template non-type arguments. */
8954 type
= TREE_TYPE (expr
);
8960 /* Within a lambda-expression:
8962 Every occurrence of decltype((x)) where x is a possibly
8963 parenthesized id-expression that names an entity of
8964 automatic storage duration is treated as if x were
8965 transformed into an access to a corresponding data member
8966 of the closure type that would have been declared if x
8967 were a use of the denoted entity. */
8968 if (outer_automatic_var_p (expr
)
8969 && current_function_decl
8970 && LAMBDA_FUNCTION_P (current_function_decl
))
8971 type
= capture_decltype (expr
);
8972 else if (error_operand_p (expr
))
8973 type
= error_mark_node
;
8974 else if (expr
== current_class_ptr
)
8975 /* If the expression is just "this", we want the
8976 cv-unqualified pointer for the "this" type. */
8977 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
8980 /* Otherwise, where T is the type of e, if e is an lvalue,
8981 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
8982 cp_lvalue_kind clk
= lvalue_kind (expr
);
8983 type
= unlowered_expr_type (expr
);
8984 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
8986 /* For vector types, pick a non-opaque variant. */
8987 if (VECTOR_TYPE_P (type
))
8988 type
= strip_typedefs (type
);
8990 if (clk
!= clk_none
&& !(clk
& clk_class
))
8991 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
8998 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
8999 __has_nothrow_copy, depending on assign_p. */
9002 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
9009 ix
= lookup_fnfields_1 (type
, ansi_assopname (NOP_EXPR
));
9012 fns
= (*CLASSTYPE_METHOD_VEC (type
))[ix
];
9014 else if (TYPE_HAS_COPY_CTOR (type
))
9016 /* If construction of the copy constructor was postponed, create
9018 if (CLASSTYPE_LAZY_COPY_CTOR (type
))
9019 lazily_declare_fn (sfk_copy_constructor
, type
);
9020 if (CLASSTYPE_LAZY_MOVE_CTOR (type
))
9021 lazily_declare_fn (sfk_move_constructor
, type
);
9022 fns
= CLASSTYPE_CONSTRUCTORS (type
);
9027 for (; fns
; fns
= OVL_NEXT (fns
))
9029 tree fn
= OVL_CURRENT (fns
);
9033 if (copy_fn_p (fn
) == 0)
9036 else if (copy_fn_p (fn
) <= 0)
9039 maybe_instantiate_noexcept (fn
);
9040 if (!TYPE_NOTHROW_P (TREE_TYPE (fn
)))
9047 /* Actually evaluates the trait. */
9050 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
9052 enum tree_code type_code1
;
9055 type_code1
= TREE_CODE (type1
);
9059 case CPTK_HAS_NOTHROW_ASSIGN
:
9060 type1
= strip_array_types (type1
);
9061 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
9062 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
9063 || (CLASS_TYPE_P (type1
)
9064 && classtype_has_nothrow_assign_or_copy_p (type1
,
9067 case CPTK_HAS_TRIVIAL_ASSIGN
:
9068 /* ??? The standard seems to be missing the "or array of such a class
9069 type" wording for this trait. */
9070 type1
= strip_array_types (type1
);
9071 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
9072 && (trivial_type_p (type1
)
9073 || (CLASS_TYPE_P (type1
)
9074 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
9076 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9077 type1
= strip_array_types (type1
);
9078 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
9079 || (CLASS_TYPE_P (type1
)
9080 && (t
= locate_ctor (type1
))
9081 && (maybe_instantiate_noexcept (t
),
9082 TYPE_NOTHROW_P (TREE_TYPE (t
)))));
9084 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9085 type1
= strip_array_types (type1
);
9086 return (trivial_type_p (type1
)
9087 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
9089 case CPTK_HAS_NOTHROW_COPY
:
9090 type1
= strip_array_types (type1
);
9091 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
9092 || (CLASS_TYPE_P (type1
)
9093 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
9095 case CPTK_HAS_TRIVIAL_COPY
:
9096 /* ??? The standard seems to be missing the "or array of such a class
9097 type" wording for this trait. */
9098 type1
= strip_array_types (type1
);
9099 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9100 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
9102 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9103 type1
= strip_array_types (type1
);
9104 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9105 || (CLASS_TYPE_P (type1
)
9106 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
9108 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9109 return type_has_virtual_destructor (type1
);
9111 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
9112 return type_has_unique_obj_representations (type1
);
9114 case CPTK_IS_ABSTRACT
:
9115 return (ABSTRACT_CLASS_TYPE_P (type1
));
9117 case CPTK_IS_BASE_OF
:
9118 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9119 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9120 || DERIVED_FROM_P (type1
, type2
)));
9123 return (NON_UNION_CLASS_TYPE_P (type1
));
9126 return (NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
));
9129 return (type_code1
== ENUMERAL_TYPE
);
9132 return (CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
));
9134 case CPTK_IS_LITERAL_TYPE
:
9135 return (literal_type_p (type1
));
9138 return (pod_type_p (type1
));
9140 case CPTK_IS_POLYMORPHIC
:
9141 return (CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
));
9143 case CPTK_IS_SAME_AS
:
9144 return same_type_p (type1
, type2
);
9146 case CPTK_IS_STD_LAYOUT
:
9147 return (std_layout_type_p (type1
));
9149 case CPTK_IS_TRIVIAL
:
9150 return (trivial_type_p (type1
));
9152 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9153 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
9155 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9156 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
9158 case CPTK_IS_TRIVIALLY_COPYABLE
:
9159 return (trivially_copyable_p (type1
));
9162 return (type_code1
== UNION_TYPE
);
9170 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
9171 void, or a complete type, returns true, otherwise false. */
9174 check_trait_type (tree type
)
9176 if (type
== NULL_TREE
)
9179 if (TREE_CODE (type
) == TREE_LIST
)
9180 return (check_trait_type (TREE_VALUE (type
))
9181 && check_trait_type (TREE_CHAIN (type
)));
9183 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
9184 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
9187 if (VOID_TYPE_P (type
))
9190 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
9193 /* Process a trait expression. */
9196 finish_trait_expr (cp_trait_kind kind
, tree type1
, tree type2
)
9198 if (type1
== error_mark_node
9199 || type2
== error_mark_node
)
9200 return error_mark_node
;
9202 if (processing_template_decl
)
9204 tree trait_expr
= make_node (TRAIT_EXPR
);
9205 TREE_TYPE (trait_expr
) = boolean_type_node
;
9206 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
9207 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
9208 TRAIT_EXPR_KIND (trait_expr
) = kind
;
9214 case CPTK_HAS_NOTHROW_ASSIGN
:
9215 case CPTK_HAS_TRIVIAL_ASSIGN
:
9216 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9217 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9218 case CPTK_HAS_NOTHROW_COPY
:
9219 case CPTK_HAS_TRIVIAL_COPY
:
9220 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9221 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
9222 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9223 case CPTK_IS_ABSTRACT
:
9226 case CPTK_IS_LITERAL_TYPE
:
9228 case CPTK_IS_POLYMORPHIC
:
9229 case CPTK_IS_STD_LAYOUT
:
9230 case CPTK_IS_TRIVIAL
:
9231 case CPTK_IS_TRIVIALLY_COPYABLE
:
9232 if (!check_trait_type (type1
))
9233 return error_mark_node
;
9236 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9237 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9238 if (!check_trait_type (type1
)
9239 || !check_trait_type (type2
))
9240 return error_mark_node
;
9243 case CPTK_IS_BASE_OF
:
9244 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9245 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9246 && !complete_type_or_else (type2
, NULL_TREE
))
9247 /* We already issued an error. */
9248 return error_mark_node
;
9254 case CPTK_IS_SAME_AS
:
9261 return (trait_expr_value (kind
, type1
, type2
)
9262 ? boolean_true_node
: boolean_false_node
);
9265 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
9266 which is ignored for C++. */
9269 set_float_const_decimal64 (void)
9274 clear_float_const_decimal64 (void)
9279 float_const_decimal64_p (void)
9285 /* Return true if T designates the implied `this' parameter. */
9288 is_this_parameter (tree t
)
9290 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
9292 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
));
9296 /* Insert the deduced return type for an auto function. */
9299 apply_deduced_return_type (tree fco
, tree return_type
)
9303 if (return_type
== error_mark_node
)
9306 if (LAMBDA_FUNCTION_P (fco
))
9308 tree lambda
= CLASSTYPE_LAMBDA_EXPR (current_class_type
);
9309 LAMBDA_EXPR_RETURN_TYPE (lambda
) = return_type
;
9312 if (DECL_CONV_FN_P (fco
))
9313 DECL_NAME (fco
) = mangle_conv_op_name_for_type (return_type
);
9315 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
9317 result
= DECL_RESULT (fco
);
9318 if (result
== NULL_TREE
)
9320 if (TREE_TYPE (result
) == return_type
)
9323 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
9324 && !complete_type_or_else (return_type
, NULL_TREE
))
9327 /* We already have a DECL_RESULT from start_preparsed_function.
9328 Now we need to redo the work it and allocate_struct_function
9329 did to reflect the new type. */
9330 gcc_assert (current_function_decl
== fco
);
9331 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
9332 TYPE_MAIN_VARIANT (return_type
));
9333 DECL_ARTIFICIAL (result
) = 1;
9334 DECL_IGNORED_P (result
) = 1;
9335 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
9338 DECL_RESULT (fco
) = result
;
9340 if (!processing_template_decl
)
9342 bool aggr
= aggregate_value_p (result
, fco
);
9343 #ifdef PCC_STATIC_STRUCT_RETURN
9344 cfun
->returns_pcc_struct
= aggr
;
9346 cfun
->returns_struct
= aggr
;
9351 /* DECL is a local variable or parameter from the surrounding scope of a
9352 lambda-expression. Returns the decltype for a use of the capture field
9353 for DECL even if it hasn't been captured yet. */
9356 capture_decltype (tree decl
)
9358 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
9359 /* FIXME do lookup instead of list walk? */
9360 tree cap
= value_member (decl
, LAMBDA_EXPR_CAPTURE_LIST (lam
));
9364 type
= TREE_TYPE (TREE_PURPOSE (cap
));
9366 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
9369 error ("%qD is not captured", decl
);
9370 return error_mark_node
;
9373 type
= TREE_TYPE (decl
);
9374 if (TREE_CODE (type
) == REFERENCE_TYPE
9375 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
9376 type
= TREE_TYPE (type
);
9379 case CPLD_REFERENCE
:
9380 type
= TREE_TYPE (decl
);
9381 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9382 type
= build_reference_type (TREE_TYPE (decl
));
9389 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9391 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
9392 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
9394 type
= build_reference_type (type
);
9399 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
9400 this is a right unary fold. Otherwise it is a left unary fold. */
9403 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
9405 // Build a pack expansion (assuming expr has pack type).
9406 if (!uses_parameter_packs (expr
))
9408 error_at (location_of (expr
), "operand of fold expression has no "
9409 "unexpanded parameter packs");
9410 return error_mark_node
;
9412 tree pack
= make_pack_expansion (expr
);
9414 // Build the fold expression.
9415 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9416 tree fold
= build_min (dir
, unknown_type_node
, code
, pack
);
9417 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9422 finish_left_unary_fold_expr (tree expr
, int op
)
9424 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
9428 finish_right_unary_fold_expr (tree expr
, int op
)
9430 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
9433 /* Build a binary fold expression over EXPR1 and EXPR2. The
9434 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
9435 has an unexpanded parameter pack). */
9438 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
9440 pack
= make_pack_expansion (pack
);
9441 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9442 tree fold
= build_min (dir
, unknown_type_node
, code
, pack
, init
);
9443 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9448 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
9450 // Determine which expr has an unexpanded parameter pack and
9451 // set the pack and initial term.
9452 bool pack1
= uses_parameter_packs (expr1
);
9453 bool pack2
= uses_parameter_packs (expr2
);
9454 if (pack1
&& !pack2
)
9455 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
9456 else if (pack2
&& !pack1
)
9457 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
9461 error ("both arguments in binary fold have unexpanded parameter packs");
9463 error ("no unexpanded parameter packs in binary fold");
9465 return error_mark_node
;
9468 /* Finish __builtin_launder (arg). */
9471 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
9473 tree orig_arg
= arg
;
9474 if (!type_dependent_expression_p (arg
))
9475 arg
= decay_conversion (arg
, complain
);
9476 if (error_operand_p (arg
))
9477 return error_mark_node
;
9478 if (!type_dependent_expression_p (arg
)
9479 && TREE_CODE (TREE_TYPE (arg
)) != POINTER_TYPE
)
9481 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
9482 return error_mark_node
;
9484 if (processing_template_decl
)
9486 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
9487 TREE_TYPE (arg
), 1, arg
);
9490 #include "gt-cp-semantics.h"