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"
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
, 0, 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 (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 begin_cond (&IF_COND (r
));
722 /* Process the COND of an if-statement, which may be given by
726 finish_if_stmt_cond (tree cond
, tree if_stmt
)
728 finish_cond (&IF_COND (if_stmt
), maybe_convert_cond (cond
));
730 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
733 /* Finish the then-clause of an if-statement, which may be given by
737 finish_then_clause (tree if_stmt
)
739 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
743 /* Begin the else-clause of an if-statement. */
746 begin_else_clause (tree if_stmt
)
748 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
751 /* Finish the else-clause of an if-statement, which may be given by
755 finish_else_clause (tree if_stmt
)
757 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
760 /* Finish an if-statement. */
763 finish_if_stmt (tree if_stmt
)
765 tree scope
= IF_SCOPE (if_stmt
);
766 IF_SCOPE (if_stmt
) = NULL
;
767 add_stmt (do_poplevel (scope
));
770 /* Begin a while-statement. Returns a newly created WHILE_STMT if
774 begin_while_stmt (void)
777 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
779 WHILE_BODY (r
) = do_pushlevel (sk_block
);
780 begin_cond (&WHILE_COND (r
));
784 /* Process the COND of a while-statement, which may be given by
788 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
)
790 if (check_no_cilk (cond
,
791 "Cilk array notation cannot be used as a condition for while statement",
792 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
793 cond
= error_mark_node
;
794 cond
= maybe_convert_cond (cond
);
795 finish_cond (&WHILE_COND (while_stmt
), cond
);
796 begin_maybe_infinite_loop (cond
);
797 if (ivdep
&& cond
!= error_mark_node
)
798 WHILE_COND (while_stmt
) = build2 (ANNOTATE_EXPR
,
799 TREE_TYPE (WHILE_COND (while_stmt
)),
800 WHILE_COND (while_stmt
),
801 build_int_cst (integer_type_node
,
802 annot_expr_ivdep_kind
));
803 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
806 /* Finish a while-statement, which may be given by WHILE_STMT. */
809 finish_while_stmt (tree while_stmt
)
811 end_maybe_infinite_loop (boolean_true_node
);
812 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
815 /* Begin a do-statement. Returns a newly created DO_STMT if
821 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
822 begin_maybe_infinite_loop (boolean_true_node
);
824 DO_BODY (r
) = push_stmt_list ();
828 /* Finish the body of a do-statement, which may be given by DO_STMT. */
831 finish_do_body (tree do_stmt
)
833 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
835 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
836 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
838 if (IS_EMPTY_STMT (body
))
839 warning (OPT_Wempty_body
,
840 "suggest explicit braces around empty body in %<do%> statement");
843 /* Finish a do-statement, which may be given by DO_STMT, and whose
844 COND is as indicated. */
847 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
)
849 if (check_no_cilk (cond
,
850 "Cilk array notation cannot be used as a condition for a do-while statement",
851 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
852 cond
= error_mark_node
;
853 cond
= maybe_convert_cond (cond
);
854 end_maybe_infinite_loop (cond
);
855 if (ivdep
&& cond
!= error_mark_node
)
856 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
857 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
));
858 DO_COND (do_stmt
) = cond
;
861 /* Finish a return-statement. The EXPRESSION returned, if any, is as
865 finish_return_stmt (tree expr
)
870 expr
= check_return_expr (expr
, &no_warning
);
872 if (error_operand_p (expr
)
873 || (flag_openmp
&& !check_omp_return ()))
875 /* Suppress -Wreturn-type for this function. */
876 if (warn_return_type
)
877 TREE_NO_WARNING (current_function_decl
) = true;
878 return error_mark_node
;
881 if (!processing_template_decl
)
883 if (warn_sequence_point
)
884 verify_sequence_points (expr
);
886 if (DECL_DESTRUCTOR_P (current_function_decl
)
887 || (DECL_CONSTRUCTOR_P (current_function_decl
)
888 && targetm
.cxx
.cdtor_returns_this ()))
890 /* Similarly, all destructors must run destructors for
891 base-classes before returning. So, all returns in a
892 destructor get sent to the DTOR_LABEL; finish_function emits
893 code to return a value there. */
894 return finish_goto_stmt (cdtor_label
);
898 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
899 TREE_NO_WARNING (r
) |= no_warning
;
900 r
= maybe_cleanup_point_expr_void (r
);
906 /* Begin the scope of a for-statement or a range-for-statement.
907 Both the returned trees are to be used in a call to
908 begin_for_stmt or begin_range_for_stmt. */
911 begin_for_scope (tree
*init
)
913 tree scope
= NULL_TREE
;
914 if (flag_new_for_scope
> 0)
915 scope
= do_pushlevel (sk_for
);
917 if (processing_template_decl
)
918 *init
= push_stmt_list ();
925 /* Begin a for-statement. Returns a new FOR_STMT.
926 SCOPE and INIT should be the return of begin_for_scope,
930 begin_for_stmt (tree scope
, tree init
)
934 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
935 NULL_TREE
, NULL_TREE
, NULL_TREE
);
937 if (scope
== NULL_TREE
)
939 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
941 scope
= begin_for_scope (&init
);
943 FOR_INIT_STMT (r
) = init
;
944 FOR_SCOPE (r
) = scope
;
949 /* Finish the for-init-statement of a for-statement, which may be
950 given by FOR_STMT. */
953 finish_for_init_stmt (tree for_stmt
)
955 if (processing_template_decl
)
956 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
958 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
959 begin_cond (&FOR_COND (for_stmt
));
962 /* Finish the COND of a for-statement, which may be given by
966 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
)
968 if (check_no_cilk (cond
,
969 "Cilk array notation cannot be used in a condition for a for-loop",
970 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
971 cond
= error_mark_node
;
972 cond
= maybe_convert_cond (cond
);
973 finish_cond (&FOR_COND (for_stmt
), cond
);
974 begin_maybe_infinite_loop (cond
);
975 if (ivdep
&& cond
!= error_mark_node
)
976 FOR_COND (for_stmt
) = build2 (ANNOTATE_EXPR
,
977 TREE_TYPE (FOR_COND (for_stmt
)),
979 build_int_cst (integer_type_node
,
980 annot_expr_ivdep_kind
));
981 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
984 /* Finish the increment-EXPRESSION in a for-statement, which may be
985 given by FOR_STMT. */
988 finish_for_expr (tree expr
, tree for_stmt
)
992 /* If EXPR is an overloaded function, issue an error; there is no
993 context available to use to perform overload resolution. */
994 if (type_unknown_p (expr
))
996 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
997 expr
= error_mark_node
;
999 if (!processing_template_decl
)
1001 if (warn_sequence_point
)
1002 verify_sequence_points (expr
);
1003 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1004 tf_warning_or_error
);
1006 else if (!type_dependent_expression_p (expr
))
1007 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1008 tf_warning_or_error
);
1009 expr
= maybe_cleanup_point_expr_void (expr
);
1010 if (check_for_bare_parameter_packs (expr
))
1011 expr
= error_mark_node
;
1012 FOR_EXPR (for_stmt
) = expr
;
1015 /* Finish the body of a for-statement, which may be given by
1016 FOR_STMT. The increment-EXPR for the loop must be
1018 It can also finish RANGE_FOR_STMT. */
1021 finish_for_stmt (tree for_stmt
)
1023 end_maybe_infinite_loop (boolean_true_node
);
1025 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1026 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1028 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1030 /* Pop the scope for the body of the loop. */
1031 if (flag_new_for_scope
> 0)
1034 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1035 ? &RANGE_FOR_SCOPE (for_stmt
)
1036 : &FOR_SCOPE (for_stmt
));
1039 add_stmt (do_poplevel (scope
));
1043 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1044 SCOPE and INIT should be the return of begin_for_scope,
1046 To finish it call finish_for_stmt(). */
1049 begin_range_for_stmt (tree scope
, tree init
)
1053 begin_maybe_infinite_loop (boolean_false_node
);
1055 r
= build_stmt (input_location
, RANGE_FOR_STMT
,
1056 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1058 if (scope
== NULL_TREE
)
1060 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
1062 scope
= begin_for_scope (&init
);
1065 /* RANGE_FOR_STMTs do not use nor save the init tree, so we
1068 pop_stmt_list (init
);
1069 RANGE_FOR_SCOPE (r
) = scope
;
1074 /* Finish the head of a range-based for statement, which may
1075 be given by RANGE_FOR_STMT. DECL must be the declaration
1076 and EXPR must be the loop expression. */
1079 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1081 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1082 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1083 add_stmt (range_for_stmt
);
1084 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1087 /* Finish a break-statement. */
1090 finish_break_stmt (void)
1092 /* In switch statements break is sometimes stylistically used after
1093 a return statement. This can lead to spurious warnings about
1094 control reaching the end of a non-void function when it is
1095 inlined. Note that we are calling block_may_fallthru with
1096 language specific tree nodes; this works because
1097 block_may_fallthru returns true when given something it does not
1099 if (!block_may_fallthru (cur_stmt_list
))
1101 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1104 /* Finish a continue-statement. */
1107 finish_continue_stmt (void)
1109 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1112 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1116 begin_switch_stmt (void)
1120 scope
= do_pushlevel (sk_cond
);
1121 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1123 begin_cond (&SWITCH_STMT_COND (r
));
1128 /* Finish the cond of a switch-statement. */
1131 finish_switch_cond (tree cond
, tree switch_stmt
)
1133 tree orig_type
= NULL
;
1135 if (check_no_cilk (cond
,
1136 "Cilk array notation cannot be used as a condition for switch statement",
1137 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement"))
1138 cond
= error_mark_node
;
1140 if (!processing_template_decl
)
1142 /* Convert the condition to an integer or enumeration type. */
1143 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1144 if (cond
== NULL_TREE
)
1146 error ("switch quantity not an integer");
1147 cond
= error_mark_node
;
1149 /* We want unlowered type here to handle enum bit-fields. */
1150 orig_type
= unlowered_expr_type (cond
);
1151 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1152 orig_type
= TREE_TYPE (cond
);
1153 if (cond
!= error_mark_node
)
1157 Integral promotions are performed. */
1158 cond
= perform_integral_promotions (cond
);
1159 cond
= maybe_cleanup_point_expr (cond
);
1162 if (check_for_bare_parameter_packs (cond
))
1163 cond
= error_mark_node
;
1164 else if (!processing_template_decl
&& warn_sequence_point
)
1165 verify_sequence_points (cond
);
1167 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1168 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1169 add_stmt (switch_stmt
);
1170 push_switch (switch_stmt
);
1171 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1174 /* Finish the body of a switch-statement, which may be given by
1175 SWITCH_STMT. The COND to switch on is indicated. */
1178 finish_switch_stmt (tree switch_stmt
)
1182 SWITCH_STMT_BODY (switch_stmt
) =
1183 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1186 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1187 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1188 add_stmt (do_poplevel (scope
));
1191 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1195 begin_try_block (void)
1197 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1199 TRY_STMTS (r
) = push_stmt_list ();
1203 /* Likewise, for a function-try-block. The block returned in
1204 *COMPOUND_STMT is an artificial outer scope, containing the
1205 function-try-block. */
1208 begin_function_try_block (tree
*compound_stmt
)
1211 /* This outer scope does not exist in the C++ standard, but we need
1212 a place to put __FUNCTION__ and similar variables. */
1213 *compound_stmt
= begin_compound_stmt (0);
1214 r
= begin_try_block ();
1215 FN_TRY_BLOCK_P (r
) = 1;
1219 /* Finish a try-block, which may be given by TRY_BLOCK. */
1222 finish_try_block (tree try_block
)
1224 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1225 TRY_HANDLERS (try_block
) = push_stmt_list ();
1228 /* Finish the body of a cleanup try-block, which may be given by
1232 finish_cleanup_try_block (tree try_block
)
1234 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1237 /* Finish an implicitly generated try-block, with a cleanup is given
1241 finish_cleanup (tree cleanup
, tree try_block
)
1243 TRY_HANDLERS (try_block
) = cleanup
;
1244 CLEANUP_P (try_block
) = 1;
1247 /* Likewise, for a function-try-block. */
1250 finish_function_try_block (tree try_block
)
1252 finish_try_block (try_block
);
1253 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1254 the try block, but moving it inside. */
1255 in_function_try_handler
= 1;
1258 /* Finish a handler-sequence for a try-block, which may be given by
1262 finish_handler_sequence (tree try_block
)
1264 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1265 check_handlers (TRY_HANDLERS (try_block
));
1268 /* Finish the handler-seq for a function-try-block, given by
1269 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1270 begin_function_try_block. */
1273 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1275 in_function_try_handler
= 0;
1276 finish_handler_sequence (try_block
);
1277 finish_compound_stmt (compound_stmt
);
1280 /* Begin a handler. Returns a HANDLER if appropriate. */
1283 begin_handler (void)
1287 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1290 /* Create a binding level for the eh_info and the exception object
1292 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1297 /* Finish the handler-parameters for a handler, which may be given by
1298 HANDLER. DECL is the declaration for the catch parameter, or NULL
1299 if this is a `catch (...)' clause. */
1302 finish_handler_parms (tree decl
, tree handler
)
1304 tree type
= NULL_TREE
;
1305 if (processing_template_decl
)
1309 decl
= pushdecl (decl
);
1310 decl
= push_template_decl (decl
);
1311 HANDLER_PARMS (handler
) = decl
;
1312 type
= TREE_TYPE (decl
);
1316 type
= expand_start_catch_block (decl
);
1317 HANDLER_TYPE (handler
) = type
;
1320 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1321 the return value from the matching call to finish_handler_parms. */
1324 finish_handler (tree handler
)
1326 if (!processing_template_decl
)
1327 expand_end_catch_block ();
1328 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1331 /* Begin a compound statement. FLAGS contains some bits that control the
1332 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1333 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1334 block of a function. If BCS_TRY_BLOCK is set, this is the block
1335 created on behalf of a TRY statement. Returns a token to be passed to
1336 finish_compound_stmt. */
1339 begin_compound_stmt (unsigned int flags
)
1343 if (flags
& BCS_NO_SCOPE
)
1345 r
= push_stmt_list ();
1346 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1348 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1349 But, if it's a statement-expression with a scopeless block, there's
1350 nothing to keep, and we don't want to accidentally keep a block
1351 *inside* the scopeless block. */
1352 keep_next_level (false);
1356 scope_kind sk
= sk_block
;
1357 if (flags
& BCS_TRY_BLOCK
)
1359 else if (flags
& BCS_TRANSACTION
)
1360 sk
= sk_transaction
;
1361 r
= do_pushlevel (sk
);
1364 /* When processing a template, we need to remember where the braces were,
1365 so that we can set up identical scopes when instantiating the template
1366 later. BIND_EXPR is a handy candidate for this.
1367 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1368 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1369 processing templates. */
1370 if (processing_template_decl
)
1372 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1373 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1374 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1375 TREE_SIDE_EFFECTS (r
) = 1;
1381 /* Finish a compound-statement, which is given by STMT. */
1384 finish_compound_stmt (tree stmt
)
1386 if (TREE_CODE (stmt
) == BIND_EXPR
)
1388 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1389 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1390 discard the BIND_EXPR so it can be merged with the containing
1392 if (TREE_CODE (body
) == STATEMENT_LIST
1393 && STATEMENT_LIST_HEAD (body
) == NULL
1394 && !BIND_EXPR_BODY_BLOCK (stmt
)
1395 && !BIND_EXPR_TRY_BLOCK (stmt
))
1398 BIND_EXPR_BODY (stmt
) = body
;
1400 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1401 stmt
= pop_stmt_list (stmt
);
1404 /* Destroy any ObjC "super" receivers that may have been
1406 objc_clear_super_receiver ();
1408 stmt
= do_poplevel (stmt
);
1411 /* ??? See c_end_compound_stmt wrt statement expressions. */
1415 /* Finish an asm-statement, whose components are a STRING, some
1416 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1417 LABELS. Also note whether the asm-statement should be
1418 considered volatile. */
1421 finish_asm_stmt (int volatile_p
, tree string
, tree output_operands
,
1422 tree input_operands
, tree clobbers
, tree labels
)
1426 int ninputs
= list_length (input_operands
);
1427 int noutputs
= list_length (output_operands
);
1429 if (!processing_template_decl
)
1431 const char *constraint
;
1432 const char **oconstraints
;
1433 bool allows_mem
, allows_reg
, is_inout
;
1437 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1439 string
= resolve_asm_operand_names (string
, output_operands
,
1440 input_operands
, labels
);
1442 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1444 operand
= TREE_VALUE (t
);
1446 /* ??? Really, this should not be here. Users should be using a
1447 proper lvalue, dammit. But there's a long history of using
1448 casts in the output operands. In cases like longlong.h, this
1449 becomes a primitive form of typechecking -- if the cast can be
1450 removed, then the output operand had a type of the proper width;
1451 otherwise we'll get an error. Gross, but ... */
1452 STRIP_NOPS (operand
);
1454 operand
= mark_lvalue_use (operand
);
1456 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1457 operand
= error_mark_node
;
1459 if (operand
!= error_mark_node
1460 && (TREE_READONLY (operand
)
1461 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1462 /* Functions are not modifiable, even though they are
1464 || TREE_CODE (TREE_TYPE (operand
)) == FUNCTION_TYPE
1465 || TREE_CODE (TREE_TYPE (operand
)) == METHOD_TYPE
1466 /* If it's an aggregate and any field is const, then it is
1467 effectively const. */
1468 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1469 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1470 cxx_readonly_error (operand
, lv_asm
);
1472 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1473 oconstraints
[i
] = constraint
;
1475 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1476 &allows_mem
, &allows_reg
, &is_inout
))
1478 /* If the operand is going to end up in memory,
1479 mark it addressable. */
1480 if (!allows_reg
&& !cxx_mark_addressable (operand
))
1481 operand
= error_mark_node
;
1484 operand
= error_mark_node
;
1486 TREE_VALUE (t
) = operand
;
1489 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1491 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1492 bool constraint_parsed
1493 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1494 oconstraints
, &allows_mem
, &allows_reg
);
1495 /* If the operand is going to end up in memory, don't call
1496 decay_conversion. */
1497 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1498 operand
= mark_lvalue_use (TREE_VALUE (t
));
1500 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1502 /* If the type of the operand hasn't been determined (e.g.,
1503 because it involves an overloaded function), then issue
1504 an error message. There's no context available to
1505 resolve the overloading. */
1506 if (TREE_TYPE (operand
) == unknown_type_node
)
1508 error ("type of asm operand %qE could not be determined",
1510 operand
= error_mark_node
;
1513 if (constraint_parsed
)
1515 /* If the operand is going to end up in memory,
1516 mark it addressable. */
1517 if (!allows_reg
&& allows_mem
)
1519 /* Strip the nops as we allow this case. FIXME, this really
1520 should be rejected or made deprecated. */
1521 STRIP_NOPS (operand
);
1522 if (!cxx_mark_addressable (operand
))
1523 operand
= error_mark_node
;
1525 else if (!allows_reg
&& !allows_mem
)
1527 /* If constraint allows neither register nor memory,
1528 try harder to get a constant. */
1529 tree constop
= maybe_constant_value (operand
);
1530 if (TREE_CONSTANT (constop
))
1535 operand
= error_mark_node
;
1537 TREE_VALUE (t
) = operand
;
1541 r
= build_stmt (input_location
, ASM_EXPR
, string
,
1542 output_operands
, input_operands
,
1544 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1545 r
= maybe_cleanup_point_expr_void (r
);
1546 return add_stmt (r
);
1549 /* Finish a label with the indicated NAME. Returns the new label. */
1552 finish_label_stmt (tree name
)
1554 tree decl
= define_label (input_location
, name
);
1556 if (decl
== error_mark_node
)
1557 return error_mark_node
;
1559 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1564 /* Finish a series of declarations for local labels. G++ allows users
1565 to declare "local" labels, i.e., labels with scope. This extension
1566 is useful when writing code involving statement-expressions. */
1569 finish_label_decl (tree name
)
1571 if (!at_function_scope_p ())
1573 error ("__label__ declarations are only allowed in function scopes");
1577 add_decl_expr (declare_local_label (name
));
1580 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1583 finish_decl_cleanup (tree decl
, tree cleanup
)
1585 push_cleanup (decl
, cleanup
, false);
1588 /* If the current scope exits with an exception, run CLEANUP. */
1591 finish_eh_cleanup (tree cleanup
)
1593 push_cleanup (NULL
, cleanup
, true);
1596 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1597 order they were written by the user. Each node is as for
1598 emit_mem_initializers. */
1601 finish_mem_initializers (tree mem_inits
)
1603 /* Reorder the MEM_INITS so that they are in the order they appeared
1604 in the source program. */
1605 mem_inits
= nreverse (mem_inits
);
1607 if (processing_template_decl
)
1611 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1613 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1614 check for bare parameter packs in the TREE_VALUE, because
1615 any parameter packs in the TREE_VALUE have already been
1616 bound as part of the TREE_PURPOSE. See
1617 make_pack_expansion for more information. */
1618 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1619 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1620 TREE_VALUE (mem
) = error_mark_node
;
1623 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1624 CTOR_INITIALIZER
, mem_inits
));
1627 emit_mem_initializers (mem_inits
);
1630 /* Obfuscate EXPR if it looks like an id-expression or member access so
1631 that the call to finish_decltype in do_auto_deduction will give the
1635 force_paren_expr (tree expr
)
1637 /* This is only needed for decltype(auto) in C++14. */
1638 if (cxx_dialect
< cxx14
)
1641 /* If we're in unevaluated context, we can't be deducing a
1642 return/initializer type, so we don't need to mess with this. */
1643 if (cp_unevaluated_operand
)
1646 if (!DECL_P (expr
) && TREE_CODE (expr
) != COMPONENT_REF
1647 && TREE_CODE (expr
) != SCOPE_REF
)
1650 if (TREE_CODE (expr
) == COMPONENT_REF
)
1651 REF_PARENTHESIZED_P (expr
) = true;
1652 else if (type_dependent_expression_p (expr
)
1653 /* When processing_template_decl, a SCOPE_REF may actually be
1654 referring to a non-static data member of the current class, in
1655 which case its TREE_TYPE may not be properly cv-qualified (the
1656 cv-qualifiers of the implicit *this object haven't yet been taken
1657 into account) so we have to delay building a static_cast until
1659 || (processing_template_decl
1660 && TREE_CODE (expr
) == SCOPE_REF
))
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;
2221 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2223 /* Use a separate flag to handle null args. */
2225 tmpl_args
= TREE_OPERAND (fn
, 1);
2226 fn
= TREE_OPERAND (fn
, 0);
2229 /* Find the name of the overloaded function. */
2230 if (identifier_p (fn
))
2232 else if (is_overloaded_fn (fn
))
2235 identifier
= DECL_NAME (get_first_fn (functions
));
2237 else if (DECL_P (fn
))
2240 identifier
= DECL_NAME (fn
);
2243 /* A call to a namespace-scope function using an unqualified name.
2245 Do Koenig lookup -- unless any of the arguments are
2247 if (!any_type_dependent_arguments_p (args
)
2248 && !any_dependent_template_arguments_p (tmpl_args
))
2250 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2253 /* The unqualified name could not be resolved. */
2255 fn
= unqualified_fn_lookup_error (identifier
);
2261 if (fn
&& template_id
)
2262 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2267 /* Generate an expression for `FN (ARGS)'. This may change the
2270 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2271 as a virtual call, even if FN is virtual. (This flag is set when
2272 encountering an expression where the function name is explicitly
2273 qualified. For example a call to `X::f' never generates a virtual
2276 Returns code for the call. */
2279 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2280 bool koenig_p
, tsubst_flags_t complain
)
2284 vec
<tree
, va_gc
> *orig_args
= NULL
;
2286 if (fn
== error_mark_node
)
2287 return error_mark_node
;
2289 gcc_assert (!TYPE_P (fn
));
2291 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2292 it so that we can tell this is a call to a known function. */
2293 fn
= maybe_undo_parenthesized_ref (fn
);
2297 if (processing_template_decl
)
2299 /* If the call expression is dependent, build a CALL_EXPR node
2300 with no type; type_dependent_expression_p recognizes
2301 expressions with no type as being dependent. */
2302 if (type_dependent_expression_p (fn
)
2303 || any_type_dependent_arguments_p (*args
)
2304 /* For a non-static member function that doesn't have an
2305 explicit object argument, we need to specifically
2306 test the type dependency of the "this" pointer because it
2307 is not included in *ARGS even though it is considered to
2308 be part of the list of arguments. Note that this is
2309 related to CWG issues 515 and 1005. */
2310 || (TREE_CODE (fn
) != COMPONENT_REF
2311 && non_static_member_function_p (fn
)
2312 && !DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
))
2313 && current_class_ref
2314 && type_dependent_expression_p (current_class_ref
)))
2316 result
= build_nt_call_vec (fn
, *args
);
2317 SET_EXPR_LOCATION (result
, EXPR_LOC_OR_LOC (fn
, input_location
));
2318 KOENIG_LOOKUP_P (result
) = koenig_p
;
2323 tree fndecl
= OVL_CURRENT (fn
);
2324 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2325 || !TREE_THIS_VOLATILE (fndecl
))
2331 current_function_returns_abnormally
= 1;
2335 orig_args
= make_tree_vector_copy (*args
);
2336 if (!BASELINK_P (fn
)
2337 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2338 && TREE_TYPE (fn
) != unknown_type_node
)
2339 fn
= build_non_dependent_expr (fn
);
2340 make_args_non_dependent (*args
);
2343 if (TREE_CODE (fn
) == COMPONENT_REF
)
2345 tree member
= TREE_OPERAND (fn
, 1);
2346 if (BASELINK_P (member
))
2348 tree object
= TREE_OPERAND (fn
, 0);
2349 return build_new_method_call (object
, member
,
2352 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2359 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2360 if (TREE_CODE (fn
) == ADDR_EXPR
2361 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2362 fn
= TREE_OPERAND (fn
, 0);
2364 if (is_overloaded_fn (fn
))
2365 fn
= baselink_for_fns (fn
);
2368 if (BASELINK_P (fn
))
2372 /* A call to a member function. From [over.call.func]:
2374 If the keyword this is in scope and refers to the class of
2375 that member function, or a derived class thereof, then the
2376 function call is transformed into a qualified function call
2377 using (*this) as the postfix-expression to the left of the
2378 . operator.... [Otherwise] a contrived object of type T
2379 becomes the implied object argument.
2383 struct A { void f(); };
2384 struct B : public A {};
2385 struct C : public A { void g() { B::f(); }};
2387 "the class of that member function" refers to `A'. But 11.2
2388 [class.access.base] says that we need to convert 'this' to B* as
2389 part of the access, so we pass 'B' to maybe_dummy_object. */
2391 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2393 /* A constructor call always uses a dummy object. (This constructor
2394 call which has the form A::A () is actually invalid and we are
2395 going to reject it later in build_new_method_call.) */
2396 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2399 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2402 if (processing_template_decl
)
2404 if (type_dependent_expression_p (object
))
2406 tree ret
= build_nt_call_vec (orig_fn
, orig_args
);
2407 release_tree_vector (orig_args
);
2410 object
= build_non_dependent_expr (object
);
2413 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2415 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2420 else if (is_overloaded_fn (fn
))
2422 /* If the function is an overloaded builtin, resolve it. */
2423 if (TREE_CODE (fn
) == FUNCTION_DECL
2424 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2425 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2426 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2430 if (warn_sizeof_pointer_memaccess
2431 && (complain
& tf_warning
)
2432 && !vec_safe_is_empty (*args
)
2433 && !processing_template_decl
)
2435 location_t sizeof_arg_loc
[3];
2438 for (i
= 0; i
< 3; i
++)
2442 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2443 sizeof_arg
[i
] = NULL_TREE
;
2444 if (i
>= (*args
)->length ())
2447 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2449 if (SIZEOF_EXPR_TYPE_P (t
))
2450 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2452 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2453 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2455 sizeof_pointer_memaccess_warning
2456 (sizeof_arg_loc
, fn
, *args
,
2457 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2460 /* A call to a namespace-scope function. */
2461 result
= build_new_function_call (fn
, args
, koenig_p
, complain
);
2464 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2466 if (!vec_safe_is_empty (*args
))
2467 error ("arguments to destructor are not allowed");
2468 /* Mark the pseudo-destructor call as having side-effects so
2469 that we do not issue warnings about its use. */
2470 result
= build1 (NOP_EXPR
,
2472 TREE_OPERAND (fn
, 0));
2473 TREE_SIDE_EFFECTS (result
) = 1;
2475 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2476 /* If the "function" is really an object of class type, it might
2477 have an overloaded `operator ()'. */
2478 result
= build_op_call (fn
, args
, complain
);
2481 /* A call where the function is unknown. */
2482 result
= cp_build_function_call_vec (fn
, args
, complain
);
2484 if (processing_template_decl
&& result
!= error_mark_node
)
2486 if (INDIRECT_REF_P (result
))
2487 result
= TREE_OPERAND (result
, 0);
2488 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2489 SET_EXPR_LOCATION (result
, input_location
);
2490 KOENIG_LOOKUP_P (result
) = koenig_p
;
2491 release_tree_vector (orig_args
);
2492 result
= convert_from_reference (result
);
2497 /* Free garbage OVERLOADs from arg-dependent lookup. */
2498 tree next
= NULL_TREE
;
2500 fn
&& TREE_CODE (fn
) == OVERLOAD
&& OVL_ARG_DEPENDENT (fn
);
2503 if (processing_template_decl
)
2504 /* In a template, we'll re-use them at instantiation time. */
2505 OVL_ARG_DEPENDENT (fn
) = false;
2508 next
= OVL_CHAIN (fn
);
2517 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2518 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2519 POSTDECREMENT_EXPR.) */
2522 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2524 /* input_location holds the location of the trailing operator token.
2525 Build a location of the form:
2528 with the caret at the operator token, ranging from the start
2529 of EXPR to the end of the operator token. */
2530 location_t combined_loc
= make_location (input_location
,
2532 get_finish (input_location
));
2533 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2534 tf_warning_or_error
);
2535 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2536 result
.set_location (combined_loc
);
2540 /* Finish a use of `this'. Returns an expression for `this'. */
2543 finish_this_expr (void)
2545 tree result
= NULL_TREE
;
2547 if (current_class_ptr
)
2549 tree type
= TREE_TYPE (current_class_ref
);
2551 /* In a lambda expression, 'this' refers to the captured 'this'. */
2552 if (LAMBDA_TYPE_P (type
))
2553 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2555 result
= current_class_ptr
;
2559 /* The keyword 'this' is a prvalue expression. */
2560 return rvalue (result
);
2562 tree fn
= current_nonlambda_function ();
2563 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2564 error ("%<this%> is unavailable for static member functions");
2566 error ("invalid use of %<this%> in non-member function");
2568 error ("invalid use of %<this%> at top level");
2569 return error_mark_node
;
2572 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2573 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2574 the TYPE for the type given. If SCOPE is non-NULL, the expression
2575 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2578 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2581 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2582 return error_mark_node
;
2584 gcc_assert (TYPE_P (destructor
));
2586 if (!processing_template_decl
)
2588 if (scope
== error_mark_node
)
2590 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2591 return error_mark_node
;
2593 if (is_auto (destructor
))
2594 destructor
= TREE_TYPE (object
);
2595 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2598 "qualified type %qT does not match destructor name ~%qT",
2600 return error_mark_node
;
2604 /* [expr.pseudo] says both:
2606 The type designated by the pseudo-destructor-name shall be
2607 the same as the object type.
2611 The cv-unqualified versions of the object type and of the
2612 type designated by the pseudo-destructor-name shall be the
2615 We implement the more generous second sentence, since that is
2616 what most other compilers do. */
2617 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2620 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2621 return error_mark_node
;
2625 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, void_type_node
, object
,
2629 /* Finish an expression of the form CODE EXPR. */
2632 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
2633 tsubst_flags_t complain
)
2635 /* Build a location of the form:
2638 with the caret at the operator token, ranging from the start
2639 of the operator token to the end of EXPR. */
2640 location_t combined_loc
= make_location (op_loc
,
2641 op_loc
, expr
.get_finish ());
2642 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
, complain
);
2643 /* TODO: build_x_unary_op doesn't always honor the location. */
2644 result
.set_location (combined_loc
);
2646 tree result_ovl
, expr_ovl
;
2648 if (!(complain
& tf_warning
))
2651 result_ovl
= result
;
2654 if (!processing_template_decl
)
2655 expr_ovl
= cp_fully_fold (expr_ovl
);
2657 if (!CONSTANT_CLASS_P (expr_ovl
)
2658 || TREE_OVERFLOW_P (expr_ovl
))
2661 if (!processing_template_decl
)
2662 result_ovl
= cp_fully_fold (result_ovl
);
2664 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
2665 overflow_warning (combined_loc
, result_ovl
);
2670 /* Finish a compound-literal expression. TYPE is the type to which
2671 the CONSTRUCTOR in COMPOUND_LITERAL is being cast. */
2674 finish_compound_literal (tree type
, tree compound_literal
,
2675 tsubst_flags_t complain
)
2677 if (type
== error_mark_node
)
2678 return error_mark_node
;
2680 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2683 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2685 return cp_build_c_cast (type
, compound_literal
, complain
);
2688 if (!TYPE_OBJ_P (type
))
2690 if (complain
& tf_error
)
2691 error ("compound literal of non-object type %qT", type
);
2692 return error_mark_node
;
2695 if (processing_template_decl
)
2697 TREE_TYPE (compound_literal
) = type
;
2698 /* Mark the expression as a compound literal. */
2699 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
2700 return compound_literal
;
2703 type
= complete_type (type
);
2705 if (TYPE_NON_AGGREGATE_CLASS (type
))
2707 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2708 everywhere that deals with function arguments would be a pain, so
2709 just wrap it in a TREE_LIST. The parser set a flag so we know
2710 that it came from T{} rather than T({}). */
2711 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2712 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2713 return build_functional_cast (type
, compound_literal
, complain
);
2716 if (TREE_CODE (type
) == ARRAY_TYPE
2717 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2718 return error_mark_node
;
2719 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2720 if (SCALAR_TYPE_P (type
)
2721 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
)
2722 && !check_narrowing (type
, compound_literal
, complain
))
2723 return error_mark_node
;
2724 if (TREE_CODE (type
) == ARRAY_TYPE
2725 && TYPE_DOMAIN (type
) == NULL_TREE
)
2727 cp_complete_array_type_or_error (&type
, compound_literal
,
2729 if (type
== error_mark_node
)
2730 return error_mark_node
;
2732 compound_literal
= digest_init (type
, compound_literal
, complain
);
2733 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
2734 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
2736 /* Put static/constant array temporaries in static variables. */
2737 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
2738 && TREE_CODE (type
) == ARRAY_TYPE
2739 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
2740 && initializer_constant_valid_p (compound_literal
, type
))
2742 tree decl
= create_temporary_var (type
);
2743 DECL_INITIAL (decl
) = compound_literal
;
2744 TREE_STATIC (decl
) = 1;
2745 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
2747 /* 5.19 says that a constant expression can include an
2748 lvalue-rvalue conversion applied to "a glvalue of literal type
2749 that refers to a non-volatile temporary object initialized
2750 with a constant expression". Rather than try to communicate
2751 that this VAR_DECL is a temporary, just mark it constexpr. */
2752 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
2753 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
2754 TREE_CONSTANT (decl
) = true;
2756 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
2757 decl
= pushdecl_top_level (decl
);
2758 DECL_NAME (decl
) = make_anon_name ();
2759 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
2760 /* Make sure the destructor is callable. */
2761 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
2762 if (clean
== error_mark_node
)
2763 return error_mark_node
;
2767 /* Represent other compound literals with TARGET_EXPR so we produce
2768 an lvalue, but can elide copies. */
2769 if (!VECTOR_TYPE_P (type
))
2770 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
2772 return compound_literal
;
2775 /* Return the declaration for the function-name variable indicated by
2779 finish_fname (tree id
)
2783 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
2784 if (processing_template_decl
&& current_function_decl
2785 && decl
!= error_mark_node
)
2786 decl
= DECL_NAME (decl
);
2790 /* Finish a translation unit. */
2793 finish_translation_unit (void)
2795 /* In case there were missing closebraces,
2796 get us back to the global binding level. */
2798 while (current_namespace
!= global_namespace
)
2801 /* Do file scope __FUNCTION__ et al. */
2802 finish_fname_decls ();
2805 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2806 Returns the parameter. */
2809 finish_template_type_parm (tree aggr
, tree identifier
)
2811 if (aggr
!= class_type_node
)
2813 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
2814 aggr
= class_type_node
;
2817 return build_tree_list (aggr
, identifier
);
2820 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2821 Returns the parameter. */
2824 finish_template_template_parm (tree aggr
, tree identifier
)
2826 tree decl
= build_decl (input_location
,
2827 TYPE_DECL
, identifier
, NULL_TREE
);
2829 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
2830 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
2831 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
2832 DECL_ARTIFICIAL (decl
) = 1;
2834 // Associate the constraints with the underlying declaration,
2835 // not the template.
2836 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
2837 tree constr
= build_constraints (reqs
, NULL_TREE
);
2838 set_constraints (decl
, constr
);
2840 end_template_decl ();
2842 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
2844 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
2845 /*is_primary=*/true, /*is_partial=*/false,
2848 return finish_template_type_parm (aggr
, tmpl
);
2851 /* ARGUMENT is the default-argument value for a template template
2852 parameter. If ARGUMENT is invalid, issue error messages and return
2853 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2856 check_template_template_default_arg (tree argument
)
2858 if (TREE_CODE (argument
) != TEMPLATE_DECL
2859 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
2860 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
2862 if (TREE_CODE (argument
) == TYPE_DECL
)
2863 error ("invalid use of type %qT as a default value for a template "
2864 "template-parameter", TREE_TYPE (argument
));
2866 error ("invalid default argument for a template template parameter");
2867 return error_mark_node
;
2873 /* Begin a class definition, as indicated by T. */
2876 begin_class_definition (tree t
)
2878 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
2879 return error_mark_node
;
2881 if (processing_template_parmlist
)
2883 error ("definition of %q#T inside template parameter list", t
);
2884 return error_mark_node
;
2887 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
2888 are passed the same as decimal scalar types. */
2889 if (TREE_CODE (t
) == RECORD_TYPE
2890 && !processing_template_decl
)
2892 tree ns
= TYPE_CONTEXT (t
);
2893 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
2894 && DECL_CONTEXT (ns
) == std_node
2896 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns
)), "decimal"))
2898 const char *n
= TYPE_NAME_STRING (t
);
2899 if ((strcmp (n
, "decimal32") == 0)
2900 || (strcmp (n
, "decimal64") == 0)
2901 || (strcmp (n
, "decimal128") == 0))
2902 TYPE_TRANSPARENT_AGGR (t
) = 1;
2906 /* A non-implicit typename comes from code like:
2908 template <typename T> struct A {
2909 template <typename U> struct A<T>::B ...
2911 This is erroneous. */
2912 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
2914 error ("invalid definition of qualified type %qT", t
);
2915 t
= error_mark_node
;
2918 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
2920 t
= make_class_type (RECORD_TYPE
);
2921 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
2924 if (TYPE_BEING_DEFINED (t
))
2926 t
= make_class_type (TREE_CODE (t
));
2927 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
2929 maybe_process_partial_specialization (t
);
2931 TYPE_BEING_DEFINED (t
) = 1;
2932 class_binding_level
->defining_class_p
= 1;
2934 if (flag_pack_struct
)
2937 TYPE_PACKED (t
) = 1;
2938 /* Even though the type is being defined for the first time
2939 here, there might have been a forward declaration, so there
2940 might be cv-qualified variants of T. */
2941 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
2942 TYPE_PACKED (v
) = 1;
2944 /* Reset the interface data, at the earliest possible
2945 moment, as it might have been set via a class foo;
2947 if (! TYPE_ANONYMOUS_P (t
))
2949 struct c_fileinfo
*finfo
= \
2950 get_fileinfo (LOCATION_FILE (input_location
));
2951 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
2952 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2953 (t
, finfo
->interface_unknown
);
2955 reset_specialization();
2957 /* Make a declaration for this class in its own scope. */
2958 build_self_reference ();
2963 /* Finish the member declaration given by DECL. */
2966 finish_member_declaration (tree decl
)
2968 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
2971 if (decl
== void_type_node
)
2972 /* The COMPONENT was a friend, not a member, and so there's
2973 nothing for us to do. */
2976 /* We should see only one DECL at a time. */
2977 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
2979 /* Set up access control for DECL. */
2981 = (current_access_specifier
== access_private_node
);
2982 TREE_PROTECTED (decl
)
2983 = (current_access_specifier
== access_protected_node
);
2984 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
2986 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
2987 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
2990 /* Mark the DECL as a member of the current class, unless it's
2991 a member of an enumeration. */
2992 if (TREE_CODE (decl
) != CONST_DECL
)
2993 DECL_CONTEXT (decl
) = current_class_type
;
2995 /* Check for bare parameter packs in the member variable declaration. */
2996 if (TREE_CODE (decl
) == FIELD_DECL
)
2998 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
2999 TREE_TYPE (decl
) = error_mark_node
;
3000 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3001 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3006 A C language linkage is ignored for the names of class members
3007 and the member function type of class member functions. */
3008 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
3009 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3011 /* Put functions on the TYPE_METHODS list and everything else on the
3012 TYPE_FIELDS list. Note that these are built up in reverse order.
3013 We reverse them (to obtain declaration order) in finish_struct. */
3014 if (DECL_DECLARES_FUNCTION_P (decl
))
3016 /* We also need to add this function to the
3017 CLASSTYPE_METHOD_VEC. */
3018 if (add_method (current_class_type
, decl
, NULL_TREE
))
3020 gcc_assert (TYPE_MAIN_VARIANT (current_class_type
) == current_class_type
);
3021 DECL_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
3022 TYPE_METHODS (current_class_type
) = decl
;
3024 maybe_add_class_template_decl_list (current_class_type
, decl
,
3028 /* Enter the DECL into the scope of the class, if the class
3029 isn't a closure (whose fields are supposed to be unnamed). */
3030 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3031 || pushdecl_class_level (decl
))
3033 if (TREE_CODE (decl
) == USING_DECL
)
3035 /* For now, ignore class-scope USING_DECLS, so that
3036 debugging backends do not see them. */
3037 DECL_IGNORED_P (decl
) = 1;
3040 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3041 go at the beginning. The reason is that lookup_field_1
3042 searches the list in order, and we want a field name to
3043 override a type name so that the "struct stat hack" will
3044 work. In particular:
3046 struct S { enum E { }; int E } s;
3049 is valid. In addition, the FIELD_DECLs must be maintained in
3050 declaration order so that class layout works as expected.
3051 However, we don't need that order until class layout, so we
3052 save a little time by putting FIELD_DECLs on in reverse order
3053 here, and then reversing them in finish_struct_1. (We could
3054 also keep a pointer to the correct insertion points in the
3057 if (TREE_CODE (decl
) == TYPE_DECL
)
3058 TYPE_FIELDS (current_class_type
)
3059 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3062 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3063 TYPE_FIELDS (current_class_type
) = decl
;
3066 maybe_add_class_template_decl_list (current_class_type
, decl
,
3071 /* Finish processing a complete template declaration. The PARMS are
3072 the template parameters. */
3075 finish_template_decl (tree parms
)
3078 end_template_decl ();
3080 end_specialization ();
3083 // Returns the template type of the class scope being entered. If we're
3084 // entering a constrained class scope. TYPE is the class template
3085 // scope being entered and we may need to match the intended type with
3086 // a constrained specialization. For example:
3088 // template<Object T>
3089 // struct S { void f(); }; #1
3091 // template<Object T>
3092 // void S<T>::f() { } #2
3094 // We check, in #2, that S<T> refers precisely to the type declared by
3095 // #1 (i.e., that the constraints match). Note that the following should
3096 // be an error since there is no specialization of S<T> that is
3097 // unconstrained, but this is not diagnosed here.
3099 // template<typename T>
3100 // void S<T>::f() { }
3102 // We cannot diagnose this problem here since this function also matches
3103 // qualified template names that are not part of a definition. For example:
3105 // template<Integral T, Floating_point U>
3106 // typename pair<T, U>::first_type void f(T, U);
3108 // Here, it is unlikely that there is a partial specialization of
3109 // pair constrained for for Integral and Floating_point arguments.
3111 // The general rule is: if a constrained specialization with matching
3112 // constraints is found return that type. Also note that if TYPE is not a
3113 // class-type (e.g. a typename type), then no fixup is needed.
3116 fixup_template_type (tree type
)
3118 // Find the template parameter list at the a depth appropriate to
3119 // the scope we're trying to enter.
3120 tree parms
= current_template_parms
;
3121 int depth
= template_class_depth (type
);
3122 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3123 parms
= TREE_CHAIN (parms
);
3126 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3127 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3129 // Search for a specialization whose type and constraints match.
3130 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3131 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3134 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3136 // If the type and constraints match a specialization, then we
3137 // are entering that type.
3138 if (same_type_p (type
, TREE_TYPE (specs
))
3139 && equivalent_constraints (cur_constr
, spec_constr
))
3140 return TREE_TYPE (specs
);
3141 specs
= TREE_CHAIN (specs
);
3144 // If no specialization matches, then must return the type
3145 // previously found.
3149 /* Finish processing a template-id (which names a type) of the form
3150 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3151 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3152 the scope of template-id indicated. */
3155 finish_template_type (tree name
, tree args
, int entering_scope
)
3159 type
= lookup_template_class (name
, args
,
3160 NULL_TREE
, NULL_TREE
, entering_scope
,
3161 tf_warning_or_error
| tf_user
);
3163 /* If we might be entering the scope of a partial specialization,
3164 find the one with the right constraints. */
3167 && CLASS_TYPE_P (type
)
3168 && dependent_type_p (type
)
3169 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3170 type
= fixup_template_type (type
);
3172 if (type
== error_mark_node
)
3174 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3175 return TYPE_STUB_DECL (type
);
3177 return TYPE_NAME (type
);
3180 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3181 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3182 BASE_CLASS, or NULL_TREE if an error occurred. The
3183 ACCESS_SPECIFIER is one of
3184 access_{default,public,protected_private}_node. For a virtual base
3185 we set TREE_TYPE. */
3188 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3192 if (base
== error_mark_node
)
3194 error ("invalid base-class specification");
3197 else if (! MAYBE_CLASS_TYPE_P (base
))
3199 error ("%qT is not a class type", base
);
3204 if (cp_type_quals (base
) != 0)
3206 /* DR 484: Can a base-specifier name a cv-qualified
3208 base
= TYPE_MAIN_VARIANT (base
);
3210 result
= build_tree_list (access
, base
);
3212 TREE_TYPE (result
) = integer_type_node
;
3218 /* If FNS is a member function, a set of member functions, or a
3219 template-id referring to one or more member functions, return a
3220 BASELINK for FNS, incorporating the current access context.
3221 Otherwise, return FNS unchanged. */
3224 baselink_for_fns (tree fns
)
3229 if (BASELINK_P (fns
)
3230 || error_operand_p (fns
))
3233 scope
= ovl_scope (fns
);
3234 if (!CLASS_TYPE_P (scope
))
3237 cl
= currently_open_derived_class (scope
);
3240 cl
= TYPE_BINFO (cl
);
3241 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3244 /* Returns true iff DECL is a variable from a function outside
3248 outer_var_p (tree decl
)
3250 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3251 && DECL_FUNCTION_SCOPE_P (decl
)
3252 && (DECL_CONTEXT (decl
) != current_function_decl
3253 || parsing_nsdmi ()));
3256 /* As above, but also checks that DECL is automatic. */
3259 outer_automatic_var_p (tree decl
)
3261 return (outer_var_p (decl
)
3262 && !TREE_STATIC (decl
));
3265 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3266 rewrite it for lambda capture. */
3269 process_outer_var_ref (tree decl
, tsubst_flags_t complain
)
3271 if (cp_unevaluated_operand
)
3272 /* It's not a use (3.2) if we're in an unevaluated context. */
3274 if (decl
== error_mark_node
)
3277 tree context
= DECL_CONTEXT (decl
);
3278 tree containing_function
= current_function_decl
;
3279 tree lambda_stack
= NULL_TREE
;
3280 tree lambda_expr
= NULL_TREE
;
3281 tree initializer
= convert_from_reference (decl
);
3283 /* Mark it as used now even if the use is ill-formed. */
3284 if (!mark_used (decl
, complain
))
3285 return error_mark_node
;
3287 bool saw_generic_lambda
= false;
3288 if (parsing_nsdmi ())
3289 containing_function
= NULL_TREE
;
3291 /* If we are in a lambda function, we can move out until we hit
3293 2. a non-lambda function, or
3294 3. a non-default capturing lambda function. */
3295 while (context
!= containing_function
3296 && LAMBDA_FUNCTION_P (containing_function
))
3298 tree closure
= DECL_CONTEXT (containing_function
);
3299 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3301 if (generic_lambda_fn_p (containing_function
))
3302 saw_generic_lambda
= true;
3304 if (TYPE_CLASS_SCOPE_P (closure
))
3305 /* A lambda in an NSDMI (c++/64496). */
3308 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3312 lambda_stack
= tree_cons (NULL_TREE
,
3317 = decl_function_context (containing_function
);
3320 /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
3321 support for an approach in which a reference to a local
3322 [constant] automatic variable in a nested class or lambda body
3323 would enter the expression as an rvalue, which would reduce
3324 the complexity of the problem"
3326 FIXME update for final resolution of core issue 696. */
3327 if (decl_maybe_constant_var_p (decl
))
3329 if (processing_template_decl
&& !saw_generic_lambda
)
3330 /* In a non-generic lambda within a template, wait until instantiation
3331 time to decide whether to capture. For a generic lambda, we can't
3332 wait until we instantiate the op() because the closure class is
3333 already defined at that point. FIXME to get the semantics exactly
3334 right we need to partially-instantiate the lambda body so the only
3335 dependencies left are on the generic parameters themselves. This
3336 probably means moving away from our current model of lambdas in
3337 templates (instantiating the closure type) to one based on creating
3338 the closure type when instantiating the lambda context. That is
3339 probably also the way to handle lambdas within pack expansions. */
3341 else if (decl_constant_var_p (decl
))
3343 tree t
= maybe_constant_value (convert_from_reference (decl
));
3344 if (TREE_CONSTANT (t
))
3349 if (lambda_expr
&& VAR_P (decl
)
3350 && DECL_ANON_UNION_VAR_P (decl
))
3352 if (complain
& tf_error
)
3353 error ("cannot capture member %qD of anonymous union", decl
);
3354 return error_mark_node
;
3356 if (context
== containing_function
)
3358 decl
= add_default_capture (lambda_stack
,
3359 /*id=*/DECL_NAME (decl
),
3362 else if (lambda_expr
)
3364 if (complain
& tf_error
)
3366 error ("%qD is not captured", decl
);
3367 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3368 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3370 inform (location_of (closure
),
3371 "the lambda has no capture-default");
3372 else if (TYPE_CLASS_SCOPE_P (closure
))
3373 inform (0, "lambda in local class %q+T cannot "
3374 "capture variables from the enclosing context",
3375 TYPE_CONTEXT (closure
));
3376 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3378 return error_mark_node
;
3382 if (complain
& tf_error
)
3384 ? G_("use of local variable with automatic storage from containing function")
3385 : G_("use of parameter from containing function"));
3386 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3387 return error_mark_node
;
3392 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3393 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3394 if non-NULL, is the type or namespace used to explicitly qualify
3395 ID_EXPRESSION. DECL is the entity to which that name has been
3398 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3399 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3400 be set to true if this expression isn't permitted in a
3401 constant-expression, but it is otherwise not set by this function.
3402 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3403 constant-expression, but a non-constant expression is also
3406 DONE is true if this expression is a complete postfix-expression;
3407 it is false if this expression is followed by '->', '[', '(', etc.
3408 ADDRESS_P is true iff this expression is the operand of '&'.
3409 TEMPLATE_P is true iff the qualified-id was of the form
3410 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3411 appears as a template argument.
3413 If an error occurs, and it is the kind of error that might cause
3414 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3415 is the caller's responsibility to issue the message. *ERROR_MSG
3416 will be a string with static storage duration, so the caller need
3419 Return an expression for the entity, after issuing appropriate
3420 diagnostics. This function is also responsible for transforming a
3421 reference to a non-static member into a COMPONENT_REF that makes
3422 the use of "this" explicit.
3424 Upon return, *IDK will be filled in appropriately. */
3426 finish_id_expression (tree id_expression
,
3430 bool integral_constant_expression_p
,
3431 bool allow_non_integral_constant_expression_p
,
3432 bool *non_integral_constant_expression_p
,
3436 bool template_arg_p
,
3437 const char **error_msg
,
3438 location_t location
)
3440 decl
= strip_using_decl (decl
);
3442 /* Initialize the output parameters. */
3443 *idk
= CP_ID_KIND_NONE
;
3446 if (id_expression
== error_mark_node
)
3447 return error_mark_node
;
3448 /* If we have a template-id, then no further lookup is
3449 required. If the template-id was for a template-class, we
3450 will sometimes have a TYPE_DECL at this point. */
3451 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3452 || TREE_CODE (decl
) == TYPE_DECL
)
3454 /* Look up the name. */
3457 if (decl
== error_mark_node
)
3459 /* Name lookup failed. */
3462 || (!dependent_type_p (scope
)
3463 && !(identifier_p (id_expression
)
3464 && IDENTIFIER_TYPENAME_P (id_expression
)
3465 && dependent_type_p (TREE_TYPE (id_expression
))))))
3467 /* If the qualifying type is non-dependent (and the name
3468 does not name a conversion operator to a dependent
3469 type), issue an error. */
3470 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3471 return error_mark_node
;
3475 /* It may be resolved via Koenig lookup. */
3476 *idk
= CP_ID_KIND_UNQUALIFIED
;
3477 return id_expression
;
3480 decl
= id_expression
;
3482 /* If DECL is a variable that would be out of scope under
3483 ANSI/ISO rules, but in scope in the ARM, name lookup
3484 will succeed. Issue a diagnostic here. */
3486 decl
= check_for_out_of_scope_variable (decl
);
3488 /* Remember that the name was used in the definition of
3489 the current class so that we can check later to see if
3490 the meaning would have been different after the class
3491 was entirely defined. */
3492 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3493 maybe_note_name_used_in_class (id_expression
, decl
);
3495 /* A use in unevaluated operand might not be instantiated appropriately
3496 if tsubst_copy builds a dummy parm, or if we never instantiate a
3497 generic lambda, so mark it now. */
3498 if (processing_template_decl
&& cp_unevaluated_operand
)
3499 mark_type_use (decl
);
3501 /* Disallow uses of local variables from containing functions, except
3502 within lambda-expressions. */
3503 if (outer_automatic_var_p (decl
))
3505 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3506 if (decl
== error_mark_node
)
3507 return error_mark_node
;
3510 /* Also disallow uses of function parameters outside the function
3511 body, except inside an unevaluated context (i.e. decltype). */
3512 if (TREE_CODE (decl
) == PARM_DECL
3513 && DECL_CONTEXT (decl
) == NULL_TREE
3514 && !cp_unevaluated_operand
)
3516 *error_msg
= "use of parameter outside function body";
3517 return error_mark_node
;
3521 /* If we didn't find anything, or what we found was a type,
3522 then this wasn't really an id-expression. */
3523 if (TREE_CODE (decl
) == TEMPLATE_DECL
3524 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3526 *error_msg
= "missing template arguments";
3527 return error_mark_node
;
3529 else if (TREE_CODE (decl
) == TYPE_DECL
3530 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3532 *error_msg
= "expected primary-expression";
3533 return error_mark_node
;
3536 /* If the name resolved to a template parameter, there is no
3537 need to look it up again later. */
3538 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3539 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3543 *idk
= CP_ID_KIND_NONE
;
3544 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3545 decl
= TEMPLATE_PARM_DECL (decl
);
3546 r
= convert_from_reference (DECL_INITIAL (decl
));
3548 if (integral_constant_expression_p
3549 && !dependent_type_p (TREE_TYPE (decl
))
3550 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3552 if (!allow_non_integral_constant_expression_p
)
3553 error ("template parameter %qD of type %qT is not allowed in "
3554 "an integral constant expression because it is not of "
3555 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3556 *non_integral_constant_expression_p
= true;
3562 bool dependent_p
= type_dependent_expression_p (decl
);
3564 /* If the declaration was explicitly qualified indicate
3565 that. The semantics of `A::f(3)' are different than
3566 `f(3)' if `f' is virtual. */
3568 ? CP_ID_KIND_QUALIFIED
3569 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3570 ? CP_ID_KIND_TEMPLATE_ID
3572 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3573 : CP_ID_KIND_UNQUALIFIED
)));
3575 /* If the name was dependent on a template parameter, we will
3576 resolve the name at instantiation time. */
3579 /* If we found a variable, then name lookup during the
3580 instantiation will always resolve to the same VAR_DECL
3581 (or an instantiation thereof). */
3583 || TREE_CODE (decl
) == CONST_DECL
3584 || TREE_CODE (decl
) == PARM_DECL
)
3587 return convert_from_reference (decl
);
3590 /* Create a SCOPE_REF for qualified names, if the scope is
3596 if (address_p
&& done
)
3597 decl
= finish_qualified_id_expr (scope
, decl
,
3601 tf_warning_or_error
);
3604 tree type
= NULL_TREE
;
3605 if (DECL_P (decl
) && !dependent_scope_p (scope
))
3606 type
= TREE_TYPE (decl
);
3607 decl
= build_qualified_name (type
,
3613 if (TREE_TYPE (decl
))
3614 decl
= convert_from_reference (decl
);
3617 /* A TEMPLATE_ID already contains all the information we
3619 if (TREE_CODE (id_expression
) == TEMPLATE_ID_EXPR
)
3620 return id_expression
;
3621 /* The same is true for FIELD_DECL, but we also need to
3622 make sure that the syntax is correct. */
3623 else if (TREE_CODE (decl
) == FIELD_DECL
)
3625 /* Since SCOPE is NULL here, this is an unqualified name.
3626 Access checking has been performed during name lookup
3627 already. Turn off checking to avoid duplicate errors. */
3628 push_deferring_access_checks (dk_no_check
);
3629 decl
= finish_non_static_data_member
3631 /*qualifying_scope=*/NULL_TREE
);
3632 pop_deferring_access_checks ();
3635 return id_expression
;
3638 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3640 error ("use of namespace %qD as expression", decl
);
3641 return error_mark_node
;
3643 else if (DECL_CLASS_TEMPLATE_P (decl
))
3645 error ("use of class template %qT as expression", decl
);
3646 return error_mark_node
;
3648 else if (TREE_CODE (decl
) == TREE_LIST
)
3650 /* Ambiguous reference to base members. */
3651 error ("request for member %qD is ambiguous in "
3652 "multiple inheritance lattice", id_expression
);
3653 print_candidates (decl
);
3654 return error_mark_node
;
3657 /* Mark variable-like entities as used. Functions are similarly
3658 marked either below or after overload resolution. */
3660 || TREE_CODE (decl
) == PARM_DECL
3661 || TREE_CODE (decl
) == CONST_DECL
3662 || TREE_CODE (decl
) == RESULT_DECL
)
3663 && !mark_used (decl
))
3664 return error_mark_node
;
3666 /* Only certain kinds of names are allowed in constant
3667 expression. Template parameters have already
3668 been handled above. */
3669 if (! error_operand_p (decl
)
3670 && integral_constant_expression_p
3671 && ! decl_constant_var_p (decl
)
3672 && TREE_CODE (decl
) != CONST_DECL
3673 && ! builtin_valid_in_constant_expr_p (decl
))
3675 if (!allow_non_integral_constant_expression_p
)
3677 error ("%qD cannot appear in a constant-expression", decl
);
3678 return error_mark_node
;
3680 *non_integral_constant_expression_p
= true;
3685 && !cp_unevaluated_operand
3686 && !processing_template_decl
3687 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
3688 && CP_DECL_THREAD_LOCAL_P (decl
)
3689 && (wrap
= get_tls_wrapper_fn (decl
)))
3691 /* Replace an evaluated use of the thread_local variable with
3692 a call to its wrapper. */
3693 decl
= build_cxx_call (wrap
, 0, NULL
, tf_warning_or_error
);
3695 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3696 && variable_template_p (TREE_OPERAND (decl
, 0)))
3698 decl
= finish_template_variable (decl
);
3700 decl
= convert_from_reference (decl
);
3704 decl
= (adjust_result_of_qualified_name_lookup
3705 (decl
, scope
, current_nonlambda_class_type()));
3707 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3711 decl
= finish_qualified_id_expr (scope
,
3717 tf_warning_or_error
);
3719 decl
= convert_from_reference (decl
);
3721 else if (TREE_CODE (decl
) == FIELD_DECL
)
3723 /* Since SCOPE is NULL here, this is an unqualified name.
3724 Access checking has been performed during name lookup
3725 already. Turn off checking to avoid duplicate errors. */
3726 push_deferring_access_checks (dk_no_check
);
3727 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3728 /*qualifying_scope=*/NULL_TREE
);
3729 pop_deferring_access_checks ();
3731 else if (is_overloaded_fn (decl
))
3735 first_fn
= get_first_fn (decl
);
3736 if (TREE_CODE (first_fn
) == TEMPLATE_DECL
)
3737 first_fn
= DECL_TEMPLATE_RESULT (first_fn
);
3739 if (!really_overloaded_fn (decl
)
3740 && !mark_used (first_fn
))
3741 return error_mark_node
;
3744 && TREE_CODE (first_fn
) == FUNCTION_DECL
3745 && DECL_FUNCTION_MEMBER_P (first_fn
)
3746 && !shared_member_p (decl
))
3748 /* A set of member functions. */
3749 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
3750 return finish_class_member_access_expr (decl
, id_expression
,
3751 /*template_p=*/false,
3752 tf_warning_or_error
);
3755 decl
= baselink_for_fns (decl
);
3759 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
3760 && DECL_CLASS_SCOPE_P (decl
))
3762 tree context
= context_for_name_lookup (decl
);
3763 if (context
!= current_class_type
)
3765 tree path
= currently_open_derived_class (context
);
3766 perform_or_defer_access_check (TYPE_BINFO (path
),
3768 tf_warning_or_error
);
3772 decl
= convert_from_reference (decl
);
3776 return cp_expr (decl
, location
);
3779 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3780 use as a type-specifier. */
3783 finish_typeof (tree expr
)
3787 if (type_dependent_expression_p (expr
))
3789 type
= cxx_make_type (TYPEOF_TYPE
);
3790 TYPEOF_TYPE_EXPR (type
) = expr
;
3791 SET_TYPE_STRUCTURAL_EQUALITY (type
);
3796 expr
= mark_type_use (expr
);
3798 type
= unlowered_expr_type (expr
);
3800 if (!type
|| type
== unknown_type_node
)
3802 error ("type of %qE is unknown", expr
);
3803 return error_mark_node
;
3809 /* Implement the __underlying_type keyword: Return the underlying
3810 type of TYPE, suitable for use as a type-specifier. */
3813 finish_underlying_type (tree type
)
3815 tree underlying_type
;
3817 if (processing_template_decl
)
3819 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
3820 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
3821 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
3823 return underlying_type
;
3826 complete_type (type
);
3828 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
3830 error ("%qT is not an enumeration type", type
);
3831 return error_mark_node
;
3834 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
3836 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
3837 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
3838 See finish_enum_value_list for details. */
3839 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
3841 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
3842 TYPE_UNSIGNED (underlying_type
));
3844 return underlying_type
;
3847 /* Implement the __direct_bases keyword: Return the direct base classes
3851 calculate_direct_bases (tree type
)
3853 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3854 tree bases_vec
= NULL_TREE
;
3855 vec
<tree
, va_gc
> *base_binfos
;
3859 complete_type (type
);
3861 if (!NON_UNION_CLASS_TYPE_P (type
))
3862 return make_tree_vec (0);
3864 base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
3866 /* Virtual bases are initialized first */
3867 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3869 if (BINFO_VIRTUAL_P (binfo
))
3871 vec_safe_push (vector
, binfo
);
3875 /* Now non-virtuals */
3876 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3878 if (!BINFO_VIRTUAL_P (binfo
))
3880 vec_safe_push (vector
, binfo
);
3885 bases_vec
= make_tree_vec (vector
->length ());
3887 for (i
= 0; i
< vector
->length (); ++i
)
3889 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
3894 /* Implement the __bases keyword: Return the base classes
3897 /* Find morally non-virtual base classes by walking binfo hierarchy */
3898 /* Virtual base classes are handled separately in finish_bases */
3901 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
3903 /* Don't walk bases of virtual bases */
3904 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
3908 dfs_calculate_bases_post (tree binfo
, void *data_
)
3910 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
3911 if (!BINFO_VIRTUAL_P (binfo
))
3913 vec_safe_push (*data
, BINFO_TYPE (binfo
));
3918 /* Calculates the morally non-virtual base classes of a class */
3919 static vec
<tree
, va_gc
> *
3920 calculate_bases_helper (tree type
)
3922 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3924 /* Now add non-virtual base classes in order of construction */
3925 if (TYPE_BINFO (type
))
3926 dfs_walk_all (TYPE_BINFO (type
),
3927 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
3932 calculate_bases (tree type
)
3934 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3935 tree bases_vec
= NULL_TREE
;
3937 vec
<tree
, va_gc
> *vbases
;
3938 vec
<tree
, va_gc
> *nonvbases
;
3941 complete_type (type
);
3943 if (!NON_UNION_CLASS_TYPE_P (type
))
3944 return make_tree_vec (0);
3946 /* First go through virtual base classes */
3947 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
3948 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
3950 vec
<tree
, va_gc
> *vbase_bases
;
3951 vbase_bases
= calculate_bases_helper (BINFO_TYPE (binfo
));
3952 vec_safe_splice (vector
, vbase_bases
);
3953 release_tree_vector (vbase_bases
);
3956 /* Now for the non-virtual bases */
3957 nonvbases
= calculate_bases_helper (type
);
3958 vec_safe_splice (vector
, nonvbases
);
3959 release_tree_vector (nonvbases
);
3961 /* Note that during error recovery vector->length can even be zero. */
3962 if (vector
->length () > 1)
3964 /* Last element is entire class, so don't copy */
3965 bases_vec
= make_tree_vec (vector
->length() - 1);
3967 for (i
= 0; i
< vector
->length () - 1; ++i
)
3968 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
3971 bases_vec
= make_tree_vec (0);
3973 release_tree_vector (vector
);
3978 finish_bases (tree type
, bool direct
)
3980 tree bases
= NULL_TREE
;
3982 if (!processing_template_decl
)
3984 /* Parameter packs can only be used in templates */
3985 error ("Parameter pack __bases only valid in template declaration");
3986 return error_mark_node
;
3989 bases
= cxx_make_type (BASES
);
3990 BASES_TYPE (bases
) = type
;
3991 BASES_DIRECT (bases
) = direct
;
3992 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
3997 /* Perform C++-specific checks for __builtin_offsetof before calling
4001 finish_offsetof (tree expr
, location_t loc
)
4003 /* If we're processing a template, we can't finish the semantics yet.
4004 Otherwise we can fold the entire expression now. */
4005 if (processing_template_decl
)
4007 expr
= build1 (OFFSETOF_EXPR
, size_type_node
, expr
);
4008 SET_EXPR_LOCATION (expr
, loc
);
4012 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4014 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4015 TREE_OPERAND (expr
, 2));
4016 return error_mark_node
;
4018 if (TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
4019 || TREE_CODE (TREE_TYPE (expr
)) == METHOD_TYPE
4020 || TREE_TYPE (expr
) == unknown_type_node
)
4022 if (INDIRECT_REF_P (expr
))
4023 error ("second operand of %<offsetof%> is neither a single "
4024 "identifier nor a sequence of member accesses and "
4025 "array references");
4028 if (TREE_CODE (expr
) == COMPONENT_REF
4029 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4030 expr
= TREE_OPERAND (expr
, 1);
4031 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4033 return error_mark_node
;
4035 if (REFERENCE_REF_P (expr
))
4036 expr
= TREE_OPERAND (expr
, 0);
4037 if (TREE_CODE (expr
) == COMPONENT_REF
)
4039 tree object
= TREE_OPERAND (expr
, 0);
4040 if (!complete_type_or_else (TREE_TYPE (object
), object
))
4041 return error_mark_node
;
4042 if (warn_invalid_offsetof
4043 && CLASS_TYPE_P (TREE_TYPE (object
))
4044 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (object
))
4045 && cp_unevaluated_operand
== 0)
4046 pedwarn (loc
, OPT_Winvalid_offsetof
,
4047 "offsetof within non-standard-layout type %qT is undefined",
4048 TREE_TYPE (object
));
4050 return fold_offsetof (expr
);
4053 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4054 function is broken out from the above for the benefit of the tree-ssa
4058 simplify_aggr_init_expr (tree
*tp
)
4060 tree aggr_init_expr
= *tp
;
4062 /* Form an appropriate CALL_EXPR. */
4063 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4064 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4065 tree type
= TREE_TYPE (slot
);
4068 enum style_t
{ ctor
, arg
, pcc
} style
;
4070 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4072 #ifdef PCC_STATIC_STRUCT_RETURN
4078 gcc_assert (TREE_ADDRESSABLE (type
));
4082 call_expr
= build_call_array_loc (input_location
,
4083 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4085 aggr_init_expr_nargs (aggr_init_expr
),
4086 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4087 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4088 CALL_EXPR_LIST_INIT_P (call_expr
) = CALL_EXPR_LIST_INIT_P (aggr_init_expr
);
4089 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4093 /* Replace the first argument to the ctor with the address of the
4095 cxx_mark_addressable (slot
);
4096 CALL_EXPR_ARG (call_expr
, 0) =
4097 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4099 else if (style
== arg
)
4101 /* Just mark it addressable here, and leave the rest to
4102 expand_call{,_inline}. */
4103 cxx_mark_addressable (slot
);
4104 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4105 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4107 else if (style
== pcc
)
4109 /* If we're using the non-reentrant PCC calling convention, then we
4110 need to copy the returned value out of the static buffer into the
4112 push_deferring_access_checks (dk_no_check
);
4113 call_expr
= build_aggr_init (slot
, call_expr
,
4114 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4115 tf_warning_or_error
);
4116 pop_deferring_access_checks ();
4117 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4120 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4122 tree init
= build_zero_init (type
, NULL_TREE
,
4123 /*static_storage_p=*/false);
4124 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4125 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4132 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4135 emit_associated_thunks (tree fn
)
4137 /* When we use vcall offsets, we emit thunks with the virtual
4138 functions to which they thunk. The whole point of vcall offsets
4139 is so that you can know statically the entire set of thunks that
4140 will ever be needed for a given virtual function, thereby
4141 enabling you to output all the thunks with the function itself. */
4142 if (DECL_VIRTUAL_P (fn
)
4143 /* Do not emit thunks for extern template instantiations. */
4144 && ! DECL_REALLY_EXTERN (fn
))
4148 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4150 if (!THUNK_ALIAS (thunk
))
4152 use_thunk (thunk
, /*emit_p=*/1);
4153 if (DECL_RESULT_THUNK_P (thunk
))
4157 for (probe
= DECL_THUNKS (thunk
);
4158 probe
; probe
= DECL_CHAIN (probe
))
4159 use_thunk (probe
, /*emit_p=*/1);
4163 gcc_assert (!DECL_THUNKS (thunk
));
4168 /* Generate RTL for FN. */
4171 expand_or_defer_fn_1 (tree fn
)
4173 /* When the parser calls us after finishing the body of a template
4174 function, we don't really want to expand the body. */
4175 if (processing_template_decl
)
4177 /* Normally, collection only occurs in rest_of_compilation. So,
4178 if we don't collect here, we never collect junk generated
4179 during the processing of templates until we hit a
4180 non-template function. It's not safe to do this inside a
4181 nested class, though, as the parser may have local state that
4182 is not a GC root. */
4183 if (!function_depth
)
4188 gcc_assert (DECL_SAVED_TREE (fn
));
4190 /* We make a decision about linkage for these functions at the end
4191 of the compilation. Until that point, we do not want the back
4192 end to output them -- but we do want it to see the bodies of
4193 these functions so that it can inline them as appropriate. */
4194 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4196 if (DECL_INTERFACE_KNOWN (fn
))
4197 /* We've already made a decision as to how this function will
4200 tentative_decl_linkage (fn
);
4202 import_export_decl (fn
);
4204 /* If the user wants us to keep all inline functions, then mark
4205 this function as needed so that finish_file will make sure to
4206 output it later. Similarly, all dllexport'd functions must
4207 be emitted; there may be callers in other DLLs. */
4208 if (DECL_DECLARED_INLINE_P (fn
)
4209 && !DECL_REALLY_EXTERN (fn
)
4210 && (flag_keep_inline_functions
4211 || (flag_keep_inline_dllexport
4212 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4215 DECL_EXTERNAL (fn
) = 0;
4219 /* If this is a constructor or destructor body, we have to clone
4221 if (maybe_clone_body (fn
))
4223 /* We don't want to process FN again, so pretend we've written
4224 it out, even though we haven't. */
4225 TREE_ASM_WRITTEN (fn
) = 1;
4226 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4227 if (!DECL_DECLARED_CONSTEXPR_P (fn
))
4228 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4232 /* There's no reason to do any of the work here if we're only doing
4233 semantic analysis; this code just generates RTL. */
4234 if (flag_syntax_only
)
4241 expand_or_defer_fn (tree fn
)
4243 if (expand_or_defer_fn_1 (fn
))
4247 /* Expand or defer, at the whim of the compilation unit manager. */
4248 cgraph_node::finalize_function (fn
, function_depth
> 1);
4249 emit_associated_thunks (fn
);
4257 nrv_data () : visited (37) {}
4261 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4264 /* Helper function for walk_tree, used by finalize_nrv below. */
4267 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4269 struct nrv_data
*dp
= (struct nrv_data
*)data
;
4272 /* No need to walk into types. There wouldn't be any need to walk into
4273 non-statements, except that we have to consider STMT_EXPRs. */
4276 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4277 but differs from using NULL_TREE in that it indicates that we care
4278 about the value of the RESULT_DECL. */
4279 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4280 TREE_OPERAND (*tp
, 0) = dp
->result
;
4281 /* Change all cleanups for the NRV to only run when an exception is
4283 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4284 && CLEANUP_DECL (*tp
) == dp
->var
)
4285 CLEANUP_EH_ONLY (*tp
) = 1;
4286 /* Replace the DECL_EXPR for the NRV with an initialization of the
4287 RESULT_DECL, if needed. */
4288 else if (TREE_CODE (*tp
) == DECL_EXPR
4289 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4292 if (DECL_INITIAL (dp
->var
)
4293 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4294 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4295 DECL_INITIAL (dp
->var
));
4297 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4298 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4299 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4302 /* And replace all uses of the NRV with the RESULT_DECL. */
4303 else if (*tp
== dp
->var
)
4306 /* Avoid walking into the same tree more than once. Unfortunately, we
4307 can't just use walk_tree_without duplicates because it would only call
4308 us for the first occurrence of dp->var in the function body. */
4309 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4315 /* Keep iterating. */
4319 /* Called from finish_function to implement the named return value
4320 optimization by overriding all the RETURN_EXPRs and pertinent
4321 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4322 RESULT_DECL for the function. */
4325 finalize_nrv (tree
*tp
, tree var
, tree result
)
4327 struct nrv_data data
;
4329 /* Copy name from VAR to RESULT. */
4330 DECL_NAME (result
) = DECL_NAME (var
);
4331 /* Don't forget that we take its address. */
4332 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4333 /* Finally set DECL_VALUE_EXPR to avoid assigning
4334 a stack slot at -O0 for the original var and debug info
4335 uses RESULT location for VAR. */
4336 SET_DECL_VALUE_EXPR (var
, result
);
4337 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4340 data
.result
= result
;
4341 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4344 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4347 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4348 bool need_copy_ctor
, bool need_copy_assignment
,
4351 int save_errorcount
= errorcount
;
4354 /* Always allocate 3 elements for simplicity. These are the
4355 function decls for the ctor, dtor, and assignment op.
4356 This layout is known to the three lang hooks,
4357 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4358 and cxx_omp_clause_assign_op. */
4359 info
= make_tree_vec (3);
4360 CP_OMP_CLAUSE_INFO (c
) = info
;
4362 if (need_default_ctor
|| need_copy_ctor
)
4364 if (need_default_ctor
)
4365 t
= get_default_ctor (type
);
4367 t
= get_copy_ctor (type
, tf_warning_or_error
);
4369 if (t
&& !trivial_fn_p (t
))
4370 TREE_VEC_ELT (info
, 0) = t
;
4373 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4374 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4376 if (need_copy_assignment
)
4378 t
= get_copy_assign (type
);
4380 if (t
&& !trivial_fn_p (t
))
4381 TREE_VEC_ELT (info
, 2) = t
;
4384 return errorcount
!= save_errorcount
;
4387 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4388 FIELD_DECL, otherwise return DECL itself. */
4391 omp_clause_decl_field (tree decl
)
4394 && DECL_HAS_VALUE_EXPR_P (decl
)
4395 && DECL_ARTIFICIAL (decl
)
4396 && DECL_LANG_SPECIFIC (decl
)
4397 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4399 tree f
= DECL_VALUE_EXPR (decl
);
4400 if (TREE_CODE (f
) == INDIRECT_REF
)
4401 f
= TREE_OPERAND (f
, 0);
4402 if (TREE_CODE (f
) == COMPONENT_REF
)
4404 f
= TREE_OPERAND (f
, 1);
4405 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4412 /* Adjust DECL if needed for printing using %qE. */
4415 omp_clause_printable_decl (tree decl
)
4417 tree t
= omp_clause_decl_field (decl
);
4423 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4424 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4428 omp_note_field_privatization (tree f
, tree t
)
4430 if (!omp_private_member_map
)
4431 omp_private_member_map
= new hash_map
<tree
, tree
>;
4432 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4436 omp_private_member_vec
.safe_push (f
);
4437 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4438 omp_private_member_vec
.safe_push (integer_zero_node
);
4442 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4446 omp_privatize_field (tree t
, bool shared
)
4448 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4449 if (m
== error_mark_node
)
4450 return error_mark_node
;
4451 if (!omp_private_member_map
&& !shared
)
4452 omp_private_member_map
= new hash_map
<tree
, tree
>;
4453 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
)
4455 gcc_assert (TREE_CODE (m
) == INDIRECT_REF
);
4456 m
= TREE_OPERAND (m
, 0);
4458 tree vb
= NULL_TREE
;
4459 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4462 v
= create_temporary_var (TREE_TYPE (m
));
4463 if (!DECL_LANG_SPECIFIC (v
))
4464 retrofit_lang_decl (v
);
4465 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4466 SET_DECL_VALUE_EXPR (v
, m
);
4467 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4469 omp_private_member_vec
.safe_push (t
);
4474 /* Helper function for handle_omp_array_sections. Called recursively
4475 to handle multiple array-section-subscripts. C is the clause,
4476 T current expression (initially OMP_CLAUSE_DECL), which is either
4477 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4478 expression if specified, TREE_VALUE length expression if specified,
4479 TREE_CHAIN is what it has been specified after, or some decl.
4480 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4481 set to true if any of the array-section-subscript could have length
4482 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4483 first array-section-subscript which is known not to have length
4485 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4486 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4487 all are or may have length of 1, array-section-subscript [:2] is the
4488 first one known not to have length 1. For array-section-subscript
4489 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4490 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4491 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4492 case though, as some lengths could be zero. */
4495 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4496 bool &maybe_zero_len
, unsigned int &first_non_one
,
4499 tree ret
, low_bound
, length
, type
;
4500 if (TREE_CODE (t
) != TREE_LIST
)
4502 if (error_operand_p (t
))
4503 return error_mark_node
;
4504 if (REFERENCE_REF_P (t
)
4505 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4506 t
= TREE_OPERAND (t
, 0);
4508 if (TREE_CODE (t
) == COMPONENT_REF
4510 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4511 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
4512 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
4513 && !type_dependent_expression_p (t
))
4515 if (DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
4517 error_at (OMP_CLAUSE_LOCATION (c
),
4518 "bit-field %qE in %qs clause",
4519 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4520 return error_mark_node
;
4522 while (TREE_CODE (t
) == COMPONENT_REF
)
4524 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
4526 error_at (OMP_CLAUSE_LOCATION (c
),
4527 "%qE is a member of a union", t
);
4528 return error_mark_node
;
4530 t
= TREE_OPERAND (t
, 0);
4533 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
4535 if (processing_template_decl
)
4538 error_at (OMP_CLAUSE_LOCATION (c
),
4539 "%qD is not a variable in %qs clause", t
,
4540 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4542 error_at (OMP_CLAUSE_LOCATION (c
),
4543 "%qE is not a variable in %qs clause", t
,
4544 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4545 return error_mark_node
;
4547 else if (TREE_CODE (t
) == PARM_DECL
4548 && DECL_ARTIFICIAL (t
)
4549 && DECL_NAME (t
) == this_identifier
)
4551 error_at (OMP_CLAUSE_LOCATION (c
),
4552 "%<this%> allowed in OpenMP only in %<declare simd%>"
4554 return error_mark_node
;
4556 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4557 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
4559 error_at (OMP_CLAUSE_LOCATION (c
),
4560 "%qD is threadprivate variable in %qs clause", t
,
4561 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4562 return error_mark_node
;
4564 if (type_dependent_expression_p (ret
))
4566 ret
= convert_from_reference (ret
);
4570 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4571 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
4572 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
4573 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4574 maybe_zero_len
, first_non_one
, is_omp
);
4575 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4578 type
= TREE_TYPE (ret
);
4579 low_bound
= TREE_PURPOSE (t
);
4580 length
= TREE_VALUE (t
);
4581 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4582 || (length
&& type_dependent_expression_p (length
)))
4585 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4586 return error_mark_node
;
4588 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4590 error_at (OMP_CLAUSE_LOCATION (c
),
4591 "low bound %qE of array section does not have integral type",
4593 return error_mark_node
;
4595 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4597 error_at (OMP_CLAUSE_LOCATION (c
),
4598 "length %qE of array section does not have integral type",
4600 return error_mark_node
;
4603 low_bound
= mark_rvalue_use (low_bound
);
4605 length
= mark_rvalue_use (length
);
4606 /* We need to reduce to real constant-values for checks below. */
4608 length
= fold_simple (length
);
4610 low_bound
= fold_simple (low_bound
);
4612 && TREE_CODE (low_bound
) == INTEGER_CST
4613 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4614 > TYPE_PRECISION (sizetype
))
4615 low_bound
= fold_convert (sizetype
, low_bound
);
4617 && TREE_CODE (length
) == INTEGER_CST
4618 && TYPE_PRECISION (TREE_TYPE (length
))
4619 > TYPE_PRECISION (sizetype
))
4620 length
= fold_convert (sizetype
, length
);
4621 if (low_bound
== NULL_TREE
)
4622 low_bound
= integer_zero_node
;
4624 if (length
!= NULL_TREE
)
4626 if (!integer_nonzerop (length
))
4628 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4629 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4631 if (integer_zerop (length
))
4633 error_at (OMP_CLAUSE_LOCATION (c
),
4634 "zero length array section in %qs clause",
4635 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4636 return error_mark_node
;
4640 maybe_zero_len
= true;
4642 if (first_non_one
== types
.length ()
4643 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4646 if (TREE_CODE (type
) == ARRAY_TYPE
)
4648 if (length
== NULL_TREE
4649 && (TYPE_DOMAIN (type
) == NULL_TREE
4650 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4652 error_at (OMP_CLAUSE_LOCATION (c
),
4653 "for unknown bound array type length expression must "
4655 return error_mark_node
;
4657 if (TREE_CODE (low_bound
) == INTEGER_CST
4658 && tree_int_cst_sgn (low_bound
) == -1)
4660 error_at (OMP_CLAUSE_LOCATION (c
),
4661 "negative low bound in array section in %qs clause",
4662 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4663 return error_mark_node
;
4665 if (length
!= NULL_TREE
4666 && TREE_CODE (length
) == INTEGER_CST
4667 && tree_int_cst_sgn (length
) == -1)
4669 error_at (OMP_CLAUSE_LOCATION (c
),
4670 "negative length in array section in %qs clause",
4671 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4672 return error_mark_node
;
4674 if (TYPE_DOMAIN (type
)
4675 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
4676 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
4679 tree size
= size_binop (PLUS_EXPR
,
4680 TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4682 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4684 if (tree_int_cst_lt (size
, low_bound
))
4686 error_at (OMP_CLAUSE_LOCATION (c
),
4687 "low bound %qE above array section size "
4688 "in %qs clause", low_bound
,
4689 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4690 return error_mark_node
;
4692 if (tree_int_cst_equal (size
, low_bound
))
4694 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4695 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4697 error_at (OMP_CLAUSE_LOCATION (c
),
4698 "zero length array section in %qs clause",
4699 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4700 return error_mark_node
;
4702 maybe_zero_len
= true;
4704 else if (length
== NULL_TREE
4705 && first_non_one
== types
.length ()
4706 && tree_int_cst_equal
4707 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4711 else if (length
== NULL_TREE
)
4713 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4714 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4715 maybe_zero_len
= true;
4716 if (first_non_one
== types
.length ())
4719 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
4721 if (tree_int_cst_lt (size
, length
))
4723 error_at (OMP_CLAUSE_LOCATION (c
),
4724 "length %qE above array section size "
4725 "in %qs clause", length
,
4726 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4727 return error_mark_node
;
4729 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4732 = size_binop (PLUS_EXPR
,
4733 fold_convert (sizetype
, low_bound
),
4734 fold_convert (sizetype
, length
));
4735 if (TREE_CODE (lbpluslen
) == INTEGER_CST
4736 && tree_int_cst_lt (size
, lbpluslen
))
4738 error_at (OMP_CLAUSE_LOCATION (c
),
4739 "high bound %qE above array section size "
4740 "in %qs clause", lbpluslen
,
4741 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4742 return error_mark_node
;
4747 else if (length
== NULL_TREE
)
4749 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4750 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4751 maybe_zero_len
= true;
4752 if (first_non_one
== types
.length ())
4756 /* For [lb:] we will need to evaluate lb more than once. */
4757 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4759 tree lb
= cp_save_expr (low_bound
);
4760 if (lb
!= low_bound
)
4762 TREE_PURPOSE (t
) = lb
;
4767 else if (TREE_CODE (type
) == POINTER_TYPE
)
4769 if (length
== NULL_TREE
)
4771 error_at (OMP_CLAUSE_LOCATION (c
),
4772 "for pointer type length expression must be specified");
4773 return error_mark_node
;
4775 if (length
!= NULL_TREE
4776 && TREE_CODE (length
) == INTEGER_CST
4777 && tree_int_cst_sgn (length
) == -1)
4779 error_at (OMP_CLAUSE_LOCATION (c
),
4780 "negative length in array section in %qs clause",
4781 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4782 return error_mark_node
;
4784 /* If there is a pointer type anywhere but in the very first
4785 array-section-subscript, the array section can't be contiguous. */
4786 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4787 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
4789 error_at (OMP_CLAUSE_LOCATION (c
),
4790 "array section is not contiguous in %qs clause",
4791 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4792 return error_mark_node
;
4797 error_at (OMP_CLAUSE_LOCATION (c
),
4798 "%qE does not have pointer or array type", ret
);
4799 return error_mark_node
;
4801 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4802 types
.safe_push (TREE_TYPE (ret
));
4803 /* We will need to evaluate lb more than once. */
4804 tree lb
= cp_save_expr (low_bound
);
4805 if (lb
!= low_bound
)
4807 TREE_PURPOSE (t
) = lb
;
4810 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
4814 /* Handle array sections for clause C. */
4817 handle_omp_array_sections (tree c
, bool is_omp
)
4819 bool maybe_zero_len
= false;
4820 unsigned int first_non_one
= 0;
4821 auto_vec
<tree
, 10> types
;
4822 tree first
= handle_omp_array_sections_1 (c
, OMP_CLAUSE_DECL (c
), types
,
4823 maybe_zero_len
, first_non_one
,
4825 if (first
== error_mark_node
)
4827 if (first
== NULL_TREE
)
4829 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
4831 tree t
= OMP_CLAUSE_DECL (c
);
4832 tree tem
= NULL_TREE
;
4833 if (processing_template_decl
)
4835 /* Need to evaluate side effects in the length expressions
4837 while (TREE_CODE (t
) == TREE_LIST
)
4839 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
4841 if (tem
== NULL_TREE
)
4842 tem
= TREE_VALUE (t
);
4844 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
4845 TREE_VALUE (t
), tem
);
4850 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
4851 OMP_CLAUSE_DECL (c
) = first
;
4855 unsigned int num
= types
.length (), i
;
4856 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
4857 tree condition
= NULL_TREE
;
4859 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
4860 maybe_zero_len
= true;
4861 if (processing_template_decl
&& maybe_zero_len
)
4864 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
4867 tree low_bound
= TREE_PURPOSE (t
);
4868 tree length
= TREE_VALUE (t
);
4872 && TREE_CODE (low_bound
) == INTEGER_CST
4873 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4874 > TYPE_PRECISION (sizetype
))
4875 low_bound
= fold_convert (sizetype
, low_bound
);
4877 && TREE_CODE (length
) == INTEGER_CST
4878 && TYPE_PRECISION (TREE_TYPE (length
))
4879 > TYPE_PRECISION (sizetype
))
4880 length
= fold_convert (sizetype
, length
);
4881 if (low_bound
== NULL_TREE
)
4882 low_bound
= integer_zero_node
;
4883 if (!maybe_zero_len
&& i
> first_non_one
)
4885 if (integer_nonzerop (low_bound
))
4886 goto do_warn_noncontiguous
;
4887 if (length
!= NULL_TREE
4888 && TREE_CODE (length
) == INTEGER_CST
4889 && TYPE_DOMAIN (types
[i
])
4890 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
4891 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
4895 size
= size_binop (PLUS_EXPR
,
4896 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4898 if (!tree_int_cst_equal (length
, size
))
4900 do_warn_noncontiguous
:
4901 error_at (OMP_CLAUSE_LOCATION (c
),
4902 "array section is not contiguous in %qs "
4904 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4908 if (!processing_template_decl
4909 && length
!= NULL_TREE
4910 && TREE_SIDE_EFFECTS (length
))
4912 if (side_effects
== NULL_TREE
)
4913 side_effects
= length
;
4915 side_effects
= build2 (COMPOUND_EXPR
,
4916 TREE_TYPE (side_effects
),
4917 length
, side_effects
);
4920 else if (processing_template_decl
)
4926 if (i
> first_non_one
4927 && ((length
&& integer_nonzerop (length
))
4928 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
))
4931 l
= fold_convert (sizetype
, length
);
4934 l
= size_binop (PLUS_EXPR
,
4935 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4937 l
= size_binop (MINUS_EXPR
, l
,
4938 fold_convert (sizetype
, low_bound
));
4940 if (i
> first_non_one
)
4942 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
4944 if (condition
== NULL_TREE
)
4947 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
4950 else if (size
== NULL_TREE
)
4952 size
= size_in_bytes (TREE_TYPE (types
[i
]));
4953 tree eltype
= TREE_TYPE (types
[num
- 1]);
4954 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4955 eltype
= TREE_TYPE (eltype
);
4956 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4957 size
= size_binop (EXACT_DIV_EXPR
, size
,
4958 size_in_bytes (eltype
));
4959 size
= size_binop (MULT_EXPR
, size
, l
);
4961 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
4962 size
, size_zero_node
);
4965 size
= size_binop (MULT_EXPR
, size
, l
);
4968 if (!processing_template_decl
)
4971 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
4972 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4974 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
4975 tree index_type
= build_index_type (size
);
4976 tree eltype
= TREE_TYPE (first
);
4977 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4978 eltype
= TREE_TYPE (eltype
);
4979 tree type
= build_array_type (eltype
, index_type
);
4980 tree ptype
= build_pointer_type (eltype
);
4981 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
4982 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
4983 t
= convert_from_reference (t
);
4984 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
4985 t
= build_fold_addr_expr (t
);
4986 tree t2
= build_fold_addr_expr (first
);
4987 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4988 ptrdiff_type_node
, t2
);
4989 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
4990 ptrdiff_type_node
, t2
,
4991 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4992 ptrdiff_type_node
, t
));
4993 if (tree_fits_shwi_p (t2
))
4994 t
= build2 (MEM_REF
, type
, t
,
4995 build_int_cst (ptype
, tree_to_shwi (t2
)));
4998 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5000 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
5001 TREE_TYPE (t
), t
, t2
);
5002 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5004 OMP_CLAUSE_DECL (c
) = t
;
5007 OMP_CLAUSE_DECL (c
) = first
;
5008 OMP_CLAUSE_SIZE (c
) = size
;
5009 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5010 || (TREE_CODE (t
) == COMPONENT_REF
5011 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5014 switch (OMP_CLAUSE_MAP_KIND (c
))
5016 case GOMP_MAP_ALLOC
:
5019 case GOMP_MAP_TOFROM
:
5020 case GOMP_MAP_ALWAYS_TO
:
5021 case GOMP_MAP_ALWAYS_FROM
:
5022 case GOMP_MAP_ALWAYS_TOFROM
:
5023 case GOMP_MAP_RELEASE
:
5024 case GOMP_MAP_DELETE
:
5025 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5030 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5033 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
5034 else if (TREE_CODE (t
) == COMPONENT_REF
)
5035 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5036 else if (REFERENCE_REF_P (t
)
5037 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5039 t
= TREE_OPERAND (t
, 0);
5040 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5043 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5044 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5045 && !cxx_mark_addressable (t
))
5047 OMP_CLAUSE_DECL (c2
) = t
;
5048 t
= build_fold_addr_expr (first
);
5049 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5050 ptrdiff_type_node
, t
);
5051 tree ptr
= OMP_CLAUSE_DECL (c2
);
5052 ptr
= convert_from_reference (ptr
);
5053 if (!POINTER_TYPE_P (TREE_TYPE (ptr
)))
5054 ptr
= build_fold_addr_expr (ptr
);
5055 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5056 ptrdiff_type_node
, t
,
5057 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5058 ptrdiff_type_node
, ptr
));
5059 OMP_CLAUSE_SIZE (c2
) = t
;
5060 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5061 OMP_CLAUSE_CHAIN (c
) = c2
;
5062 ptr
= OMP_CLAUSE_DECL (c2
);
5063 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5064 && TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
5065 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5067 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5069 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5070 OMP_CLAUSE_DECL (c3
) = ptr
;
5071 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
)
5072 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5074 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5075 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5076 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5077 OMP_CLAUSE_CHAIN (c2
) = c3
;
5084 /* Return identifier to look up for omp declare reduction. */
5087 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5089 const char *p
= NULL
;
5090 const char *m
= NULL
;
5091 switch (reduction_code
)
5099 case TRUTH_ANDIF_EXPR
:
5100 case TRUTH_ORIF_EXPR
:
5101 reduction_id
= ansi_opname (reduction_code
);
5115 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5116 return error_mark_node
;
5117 p
= IDENTIFIER_POINTER (reduction_id
);
5120 if (type
!= NULL_TREE
)
5121 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5123 const char prefix
[] = "omp declare reduction ";
5124 size_t lenp
= sizeof (prefix
);
5125 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5127 size_t len
= strlen (p
);
5128 size_t lenm
= m
? strlen (m
) + 1 : 0;
5129 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5131 memcpy (name
, prefix
, lenp
- 1);
5132 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5135 name
[lenp
+ len
- 1] = '~';
5136 memcpy (name
+ lenp
+ len
, m
, lenm
);
5138 return get_identifier (name
);
5141 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5142 FUNCTION_DECL or NULL_TREE if not found. */
5145 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5146 vec
<tree
> *ambiguousp
)
5149 tree baselink
= NULL_TREE
;
5150 if (identifier_p (id
))
5153 bool nonint_cst_expression_p
;
5154 const char *error_msg
;
5155 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5156 tree decl
= lookup_name (id
);
5157 if (decl
== NULL_TREE
)
5158 decl
= error_mark_node
;
5159 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5160 &nonint_cst_expression_p
, false, true, false,
5161 false, &error_msg
, loc
);
5162 if (idk
== CP_ID_KIND_UNQUALIFIED
5163 && identifier_p (id
))
5165 vec
<tree
, va_gc
> *args
= NULL
;
5166 vec_safe_push (args
, build_reference_type (type
));
5167 id
= perform_koenig_lookup (id
, args
, tf_none
);
5170 else if (TREE_CODE (id
) == SCOPE_REF
)
5171 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5172 omp_reduction_id (ERROR_MARK
,
5173 TREE_OPERAND (id
, 1),
5177 if (id
&& is_overloaded_fn (id
))
5179 for (; id
; id
= OVL_NEXT (id
))
5181 tree fndecl
= OVL_CURRENT (id
);
5182 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5184 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5185 if (same_type_p (TREE_TYPE (argtype
), type
))
5189 if (id
&& BASELINK_P (fns
))
5196 if (id
== NULL_TREE
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5198 vec
<tree
> ambiguous
= vNULL
;
5199 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5201 if (ambiguousp
== NULL
)
5202 ambiguousp
= &ambiguous
;
5203 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5205 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5206 baselinkp
? baselinkp
: &baselink
,
5208 if (id
== NULL_TREE
)
5210 if (!ambiguousp
->is_empty ())
5211 ambiguousp
->safe_push (id
);
5212 else if (ret
!= NULL_TREE
)
5214 ambiguousp
->safe_push (ret
);
5215 ambiguousp
->safe_push (id
);
5221 if (ambiguousp
!= &ambiguous
)
5223 if (!ambiguous
.is_empty ())
5225 const char *str
= _("candidates are:");
5228 error_at (loc
, "user defined reduction lookup is ambiguous");
5229 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5231 inform (DECL_SOURCE_LOCATION (udr
), "%s %#D", str
, udr
);
5233 str
= get_spaces (str
);
5235 ambiguous
.release ();
5236 ret
= error_mark_node
;
5237 baselink
= NULL_TREE
;
5242 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5243 id
, id
, tf_warning_or_error
);
5247 /* Helper function for cp_parser_omp_declare_reduction_exprs
5249 Remove CLEANUP_STMT for data (omp_priv variable).
5250 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5254 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5258 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5259 *tp
= CLEANUP_BODY (*tp
);
5260 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5262 tree decl
= DECL_EXPR_DECL (*tp
);
5263 if (!processing_template_decl
5264 && decl
== (tree
) data
5265 && DECL_INITIAL (decl
)
5266 && DECL_INITIAL (decl
) != error_mark_node
)
5268 tree list
= NULL_TREE
;
5269 append_to_statement_list_force (*tp
, &list
);
5270 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5271 decl
, DECL_INITIAL (decl
));
5272 DECL_INITIAL (decl
) = NULL_TREE
;
5273 append_to_statement_list_force (init_expr
, &list
);
5280 /* Data passed from cp_check_omp_declare_reduction to
5281 cp_check_omp_declare_reduction_r. */
5283 struct cp_check_omp_declare_reduction_data
5290 /* Helper function for cp_check_omp_declare_reduction, called via
5294 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5296 struct cp_check_omp_declare_reduction_data
*udr_data
5297 = (struct cp_check_omp_declare_reduction_data
*) data
;
5299 && !DECL_ARTIFICIAL (*tp
)
5300 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5301 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5303 location_t loc
= udr_data
->loc
;
5304 if (udr_data
->combiner_p
)
5305 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5306 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5309 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5310 "to variable %qD which is not %<omp_priv%> nor "
5318 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5321 cp_check_omp_declare_reduction (tree udr
)
5323 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5324 gcc_assert (TREE_CODE (type
) == REFERENCE_TYPE
);
5325 type
= TREE_TYPE (type
);
5327 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5329 if (type
== error_mark_node
)
5331 if (ARITHMETIC_TYPE_P (type
))
5333 static enum tree_code predef_codes
[]
5334 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5335 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5336 for (i
= 0; i
< 8; i
++)
5338 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5339 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5340 const char *n2
= IDENTIFIER_POINTER (id
);
5341 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5342 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5343 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5348 && TREE_CODE (type
) != COMPLEX_EXPR
)
5350 const char prefix_minmax
[] = "omp declare reduction m";
5351 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5352 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5353 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5354 prefix_minmax
, prefix_size
) == 0
5355 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5356 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5357 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5362 error_at (loc
, "predeclared arithmetic type %qT in "
5363 "%<#pragma omp declare reduction%>", type
);
5367 else if (TREE_CODE (type
) == FUNCTION_TYPE
5368 || TREE_CODE (type
) == METHOD_TYPE
5369 || TREE_CODE (type
) == ARRAY_TYPE
)
5371 error_at (loc
, "function or array type %qT in "
5372 "%<#pragma omp declare reduction%>", type
);
5375 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5377 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5381 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5383 error_at (loc
, "const, volatile or __restrict qualified type %qT in "
5384 "%<#pragma omp declare reduction%>", type
);
5388 tree body
= DECL_SAVED_TREE (udr
);
5389 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5392 tree_stmt_iterator tsi
;
5393 struct cp_check_omp_declare_reduction_data data
;
5394 memset (data
.stmts
, 0, sizeof data
.stmts
);
5395 for (i
= 0, tsi
= tsi_start (body
);
5396 i
< 7 && !tsi_end_p (tsi
);
5397 i
++, tsi_next (&tsi
))
5398 data
.stmts
[i
] = tsi_stmt (tsi
);
5400 gcc_assert (tsi_end_p (tsi
));
5403 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5404 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5405 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5407 data
.combiner_p
= true;
5408 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5410 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5414 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5415 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5416 data
.combiner_p
= false;
5417 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5419 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5420 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5421 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5423 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5427 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5428 an inline call. But, remap
5429 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5430 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5433 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5434 tree decl
, tree placeholder
)
5437 hash_map
<tree
, tree
> decl_map
;
5439 decl_map
.put (omp_decl1
, placeholder
);
5440 decl_map
.put (omp_decl2
, decl
);
5441 memset (&id
, 0, sizeof (id
));
5442 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5443 id
.dst_fn
= current_function_decl
;
5444 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5445 id
.decl_map
= &decl_map
;
5447 id
.copy_decl
= copy_decl_no_change
;
5448 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5449 id
.transform_new_cfg
= true;
5450 id
.transform_return_to_modify
= false;
5451 id
.transform_lang_insert_block
= NULL
;
5453 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5457 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5458 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5461 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5463 if (*tp
== (tree
) data
)
5468 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5469 Return true if there is some error and the clause should be removed. */
5472 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5474 tree t
= OMP_CLAUSE_DECL (c
);
5475 bool predefined
= false;
5476 if (TREE_CODE (t
) == TREE_LIST
)
5478 gcc_assert (processing_template_decl
);
5481 tree type
= TREE_TYPE (t
);
5482 if (TREE_CODE (t
) == MEM_REF
)
5483 type
= TREE_TYPE (type
);
5484 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5485 type
= TREE_TYPE (type
);
5486 if (TREE_CODE (type
) == ARRAY_TYPE
)
5489 gcc_assert (TREE_CODE (t
) != MEM_REF
);
5490 while (TREE_CODE (type
) == ARRAY_TYPE
)
5491 type
= TREE_TYPE (type
);
5492 if (!processing_template_decl
)
5494 t
= require_complete_type (t
);
5495 if (t
== error_mark_node
)
5497 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
5498 TYPE_SIZE_UNIT (type
));
5499 if (integer_zerop (size
))
5501 error ("%qE in %<reduction%> clause is a zero size array",
5502 omp_clause_printable_decl (t
));
5505 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5506 tree index_type
= build_index_type (size
);
5507 tree atype
= build_array_type (type
, index_type
);
5508 tree ptype
= build_pointer_type (type
);
5509 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5510 t
= build_fold_addr_expr (t
);
5511 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
5512 OMP_CLAUSE_DECL (c
) = t
;
5515 if (type
== error_mark_node
)
5517 else if (ARITHMETIC_TYPE_P (type
))
5518 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5527 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5534 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5538 case TRUTH_ANDIF_EXPR
:
5539 case TRUTH_ORIF_EXPR
:
5540 if (FLOAT_TYPE_P (type
))
5547 else if (TYPE_READONLY (type
))
5549 error ("%qE has const type for %<reduction%>",
5550 omp_clause_printable_decl (t
));
5553 else if (!processing_template_decl
)
5555 t
= require_complete_type (t
);
5556 if (t
== error_mark_node
)
5558 OMP_CLAUSE_DECL (c
) = t
;
5563 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5566 else if (processing_template_decl
)
5569 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5571 type
= TYPE_MAIN_VARIANT (type
);
5572 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5573 if (id
== NULL_TREE
)
5574 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5575 NULL_TREE
, NULL_TREE
);
5576 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5579 if (id
== error_mark_node
)
5581 id
= OVL_CURRENT (id
);
5583 tree body
= DECL_SAVED_TREE (id
);
5586 if (TREE_CODE (body
) == STATEMENT_LIST
)
5588 tree_stmt_iterator tsi
;
5589 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
5592 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5593 atype
= TREE_TYPE (atype
);
5594 bool need_static_cast
= !same_type_p (type
, atype
);
5595 memset (stmts
, 0, sizeof stmts
);
5596 for (i
= 0, tsi
= tsi_start (body
);
5597 i
< 7 && !tsi_end_p (tsi
);
5598 i
++, tsi_next (&tsi
))
5599 stmts
[i
] = tsi_stmt (tsi
);
5600 gcc_assert (tsi_end_p (tsi
));
5604 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
5605 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
5606 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
5607 DECL_ARTIFICIAL (placeholder
) = 1;
5608 DECL_IGNORED_P (placeholder
) = 1;
5609 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
5610 if (TREE_CODE (t
) == MEM_REF
)
5612 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
5614 DECL_ARTIFICIAL (decl_placeholder
) = 1;
5615 DECL_IGNORED_P (decl_placeholder
) = 1;
5616 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
5618 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
5619 cxx_mark_addressable (placeholder
);
5620 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
5621 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
5623 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5624 : OMP_CLAUSE_DECL (c
));
5625 tree omp_out
= placeholder
;
5626 tree omp_in
= decl_placeholder
? decl_placeholder
5627 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5628 if (need_static_cast
)
5630 tree rtype
= build_reference_type (atype
);
5631 omp_out
= build_static_cast (rtype
, omp_out
,
5632 tf_warning_or_error
);
5633 omp_in
= build_static_cast (rtype
, omp_in
,
5634 tf_warning_or_error
);
5635 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
5637 omp_out
= convert_from_reference (omp_out
);
5638 omp_in
= convert_from_reference (omp_in
);
5640 OMP_CLAUSE_REDUCTION_MERGE (c
)
5641 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
5642 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
5646 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
5647 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
5648 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3])))
5649 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5650 : OMP_CLAUSE_DECL (c
));
5651 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
5652 cxx_mark_addressable (placeholder
);
5653 tree omp_priv
= decl_placeholder
? decl_placeholder
5654 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5655 tree omp_orig
= placeholder
;
5656 if (need_static_cast
)
5660 error_at (OMP_CLAUSE_LOCATION (c
),
5661 "user defined reduction with constructor "
5662 "initializer for base class %qT", atype
);
5665 tree rtype
= build_reference_type (atype
);
5666 omp_priv
= build_static_cast (rtype
, omp_priv
,
5667 tf_warning_or_error
);
5668 omp_orig
= build_static_cast (rtype
, omp_orig
,
5669 tf_warning_or_error
);
5670 if (omp_priv
== error_mark_node
5671 || omp_orig
== error_mark_node
)
5673 omp_priv
= convert_from_reference (omp_priv
);
5674 omp_orig
= convert_from_reference (omp_orig
);
5677 *need_default_ctor
= true;
5678 OMP_CLAUSE_REDUCTION_INIT (c
)
5679 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
5680 DECL_EXPR_DECL (stmts
[3]),
5681 omp_priv
, omp_orig
);
5682 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
5683 find_omp_placeholder_r
, placeholder
, NULL
))
5684 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
5688 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
5689 *need_default_ctor
= true;
5693 tree v
= decl_placeholder
? decl_placeholder
5694 : convert_from_reference (t
);
5695 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
5696 init
= build_constructor (TREE_TYPE (v
), NULL
);
5698 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
5699 OMP_CLAUSE_REDUCTION_INIT (c
)
5700 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
5705 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5709 error ("user defined reduction not found for %qE",
5710 omp_clause_printable_decl (t
));
5713 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
5714 gcc_assert (TYPE_SIZE_UNIT (type
)
5715 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
5719 /* Called from finish_struct_1. linear(this) or linear(this:step)
5720 clauses might not be finalized yet because the class has been incomplete
5721 when parsing #pragma omp declare simd methods. Fix those up now. */
5724 finish_omp_declare_simd_methods (tree t
)
5726 if (processing_template_decl
)
5729 for (tree x
= TYPE_METHODS (t
); x
; x
= DECL_CHAIN (x
))
5731 if (TREE_CODE (TREE_TYPE (x
)) != METHOD_TYPE
)
5733 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
5734 if (!ods
|| !TREE_VALUE (ods
))
5736 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
5737 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
5738 && integer_zerop (OMP_CLAUSE_DECL (c
))
5739 && OMP_CLAUSE_LINEAR_STEP (c
)
5740 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
)))
5743 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
5744 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
5745 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
5746 sizetype
, s
, TYPE_SIZE_UNIT (t
));
5747 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
5752 /* Adjust sink depend clause to take into account pointer offsets.
5754 Return TRUE if there was a problem processing the offset, and the
5755 whole clause should be removed. */
5758 cp_finish_omp_clause_depend_sink (tree sink_clause
)
5760 tree t
= OMP_CLAUSE_DECL (sink_clause
);
5761 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
5763 /* Make sure we don't adjust things twice for templates. */
5764 if (processing_template_decl
)
5767 for (; t
; t
= TREE_CHAIN (t
))
5769 tree decl
= TREE_VALUE (t
);
5770 if (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
5772 tree offset
= TREE_PURPOSE (t
);
5773 bool neg
= wi::neg_p ((wide_int
) offset
);
5774 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
5775 decl
= mark_rvalue_use (decl
);
5776 decl
= convert_from_reference (decl
);
5777 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
5778 neg
? MINUS_EXPR
: PLUS_EXPR
,
5780 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
5781 MINUS_EXPR
, sizetype
,
5782 fold_convert (sizetype
, t2
),
5783 fold_convert (sizetype
, decl
));
5784 if (t2
== error_mark_node
)
5786 TREE_PURPOSE (t
) = t2
;
5792 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
5793 Remove any elements from the list that are invalid. */
5796 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
5798 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
5799 bitmap_head aligned_head
, map_head
, map_field_head
;
5801 tree safelen
= NULL_TREE
;
5802 bool branch_seen
= false;
5803 bool copyprivate_seen
= false;
5804 bool ordered_seen
= false;
5806 bitmap_obstack_initialize (NULL
);
5807 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
5808 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
5809 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
5810 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
5811 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
5812 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
5814 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
5816 bool remove
= false;
5817 bool field_ok
= false;
5819 switch (OMP_CLAUSE_CODE (c
))
5821 case OMP_CLAUSE_SHARED
:
5822 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5823 goto check_dup_generic
;
5824 case OMP_CLAUSE_PRIVATE
:
5825 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5826 goto check_dup_generic
;
5827 case OMP_CLAUSE_REDUCTION
:
5828 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5829 t
= OMP_CLAUSE_DECL (c
);
5830 if (TREE_CODE (t
) == TREE_LIST
)
5832 if (handle_omp_array_sections (c
, ((ort
& C_ORT_OMP_DECLARE_SIMD
)
5838 if (TREE_CODE (t
) == TREE_LIST
)
5840 while (TREE_CODE (t
) == TREE_LIST
)
5845 gcc_assert (TREE_CODE (t
) == MEM_REF
);
5846 t
= TREE_OPERAND (t
, 0);
5847 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
5848 t
= TREE_OPERAND (t
, 0);
5849 if (TREE_CODE (t
) == ADDR_EXPR
5850 || TREE_CODE (t
) == INDIRECT_REF
)
5851 t
= TREE_OPERAND (t
, 0);
5853 tree n
= omp_clause_decl_field (t
);
5856 goto check_dup_generic_t
;
5858 goto check_dup_generic
;
5859 case OMP_CLAUSE_COPYPRIVATE
:
5860 copyprivate_seen
= true;
5861 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5862 goto check_dup_generic
;
5863 case OMP_CLAUSE_COPYIN
:
5864 goto check_dup_generic
;
5865 case OMP_CLAUSE_LINEAR
:
5866 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
5867 t
= OMP_CLAUSE_DECL (c
);
5868 if (ort
!= C_ORT_OMP_DECLARE_SIMD
5869 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
5871 error_at (OMP_CLAUSE_LOCATION (c
),
5872 "modifier should not be specified in %<linear%> "
5873 "clause on %<simd%> or %<for%> constructs");
5874 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
5876 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
5877 && !type_dependent_expression_p (t
))
5879 tree type
= TREE_TYPE (t
);
5880 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5881 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
5882 && TREE_CODE (type
) != REFERENCE_TYPE
)
5884 error ("linear clause with %qs modifier applied to "
5885 "non-reference variable with %qT type",
5886 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5887 ? "ref" : "uval", TREE_TYPE (t
));
5891 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5892 type
= TREE_TYPE (type
);
5893 if (ort
== C_ORT_CILK
)
5895 if (!INTEGRAL_TYPE_P (type
)
5896 && !SCALAR_FLOAT_TYPE_P (type
)
5897 && TREE_CODE (type
) != POINTER_TYPE
)
5899 error ("linear clause applied to non-integral, "
5900 "non-floating, non-pointer variable with %qT type",
5908 if (!INTEGRAL_TYPE_P (type
)
5909 && TREE_CODE (type
) != POINTER_TYPE
)
5911 error ("linear clause applied to non-integral non-pointer"
5912 " variable with %qT type", TREE_TYPE (t
));
5918 t
= OMP_CLAUSE_LINEAR_STEP (c
);
5920 t
= integer_one_node
;
5921 if (t
== error_mark_node
)
5926 else if (!type_dependent_expression_p (t
)
5927 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
5928 && (ort
!= C_ORT_OMP_DECLARE_SIMD
5929 || TREE_CODE (t
) != PARM_DECL
5930 || TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
5931 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
5933 error ("linear step expression must be integral");
5939 t
= mark_rvalue_use (t
);
5940 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
5942 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
5943 goto check_dup_generic
;
5945 if (!processing_template_decl
5946 && (VAR_P (OMP_CLAUSE_DECL (c
))
5947 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
5949 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
5951 t
= maybe_constant_value (t
);
5952 if (TREE_CODE (t
) != INTEGER_CST
)
5954 error_at (OMP_CLAUSE_LOCATION (c
),
5955 "%<linear%> clause step %qE is neither "
5956 "constant nor a parameter", t
);
5961 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5962 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
5963 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5964 type
= TREE_TYPE (type
);
5965 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
5967 type
= build_pointer_type (type
);
5968 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
5969 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
5971 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
5972 MINUS_EXPR
, sizetype
,
5973 fold_convert (sizetype
, t
),
5974 fold_convert (sizetype
, d
));
5975 if (t
== error_mark_node
)
5981 else if (TREE_CODE (type
) == POINTER_TYPE
5982 /* Can't multiply the step yet if *this
5983 is still incomplete type. */
5984 && (ort
!= C_ORT_OMP_DECLARE_SIMD
5985 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
5986 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
5987 || DECL_NAME (OMP_CLAUSE_DECL (c
))
5989 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
5991 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
5992 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
5994 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
5995 MINUS_EXPR
, sizetype
,
5996 fold_convert (sizetype
, t
),
5997 fold_convert (sizetype
, d
));
5998 if (t
== error_mark_node
)
6005 t
= fold_convert (type
, t
);
6007 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6009 goto check_dup_generic
;
6011 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6014 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6015 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6018 t
= OMP_CLAUSE_DECL (c
);
6019 check_dup_generic_t
:
6020 if (t
== current_class_ptr
6021 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6022 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6023 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6025 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6030 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6031 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6033 if (processing_template_decl
)
6036 error ("%qD is not a variable in clause %qs", t
,
6037 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6039 error ("%qE is not a variable in clause %qs", t
,
6040 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6043 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6044 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6045 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6047 error ("%qD appears more than once in data clauses", t
);
6050 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6051 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6053 error ("%qD appears both in data and map clauses", t
);
6057 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6062 && TREE_CODE (t
) == FIELD_DECL
6063 && t
== OMP_CLAUSE_DECL (c
))
6066 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
6067 == OMP_CLAUSE_SHARED
));
6068 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
6073 case OMP_CLAUSE_FIRSTPRIVATE
:
6074 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6076 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6078 t
= OMP_CLAUSE_DECL (c
);
6079 if (t
== current_class_ptr
)
6081 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6086 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6087 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6088 || TREE_CODE (t
) != FIELD_DECL
))
6090 if (processing_template_decl
)
6093 error ("%qD is not a variable in clause %<firstprivate%>", t
);
6095 error ("%qE is not a variable in clause %<firstprivate%>", t
);
6098 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6099 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6101 error ("%qD appears more than once in data clauses", t
);
6104 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6106 error ("%qD appears both in data and map clauses", t
);
6110 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
6111 goto handle_field_decl
;
6113 case OMP_CLAUSE_LASTPRIVATE
:
6114 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6116 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6118 t
= OMP_CLAUSE_DECL (c
);
6119 if (t
== current_class_ptr
)
6121 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6126 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6127 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6128 || TREE_CODE (t
) != FIELD_DECL
))
6130 if (processing_template_decl
)
6133 error ("%qD is not a variable in clause %<lastprivate%>", t
);
6135 error ("%qE is not a variable in clause %<lastprivate%>", t
);
6138 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6139 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6141 error ("%qD appears more than once in data clauses", t
);
6145 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
6146 goto handle_field_decl
;
6149 t
= OMP_CLAUSE_IF_EXPR (c
);
6150 t
= maybe_convert_cond (t
);
6151 if (t
== error_mark_node
)
6153 else if (!processing_template_decl
)
6154 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6155 OMP_CLAUSE_IF_EXPR (c
) = t
;
6158 case OMP_CLAUSE_FINAL
:
6159 t
= OMP_CLAUSE_FINAL_EXPR (c
);
6160 t
= maybe_convert_cond (t
);
6161 if (t
== error_mark_node
)
6163 else if (!processing_template_decl
)
6164 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6165 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
6168 case OMP_CLAUSE_GANG
:
6169 /* Operand 1 is the gang static: argument. */
6170 t
= OMP_CLAUSE_OPERAND (c
, 1);
6173 if (t
== error_mark_node
)
6175 else if (!type_dependent_expression_p (t
)
6176 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6178 error ("%<gang%> static expression must be integral");
6183 t
= mark_rvalue_use (t
);
6184 if (!processing_template_decl
)
6186 t
= maybe_constant_value (t
);
6187 if (TREE_CODE (t
) == INTEGER_CST
6188 && tree_int_cst_sgn (t
) != 1
6189 && t
!= integer_minus_one_node
)
6191 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6192 "%<gang%> static value must be"
6194 t
= integer_one_node
;
6197 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6199 OMP_CLAUSE_OPERAND (c
, 1) = t
;
6201 /* Check operand 0, the num argument. */
6203 case OMP_CLAUSE_WORKER
:
6204 case OMP_CLAUSE_VECTOR
:
6205 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
6208 case OMP_CLAUSE_NUM_TASKS
:
6209 case OMP_CLAUSE_NUM_TEAMS
:
6210 case OMP_CLAUSE_NUM_THREADS
:
6211 case OMP_CLAUSE_NUM_GANGS
:
6212 case OMP_CLAUSE_NUM_WORKERS
:
6213 case OMP_CLAUSE_VECTOR_LENGTH
:
6214 t
= OMP_CLAUSE_OPERAND (c
, 0);
6215 if (t
== error_mark_node
)
6217 else if (!type_dependent_expression_p (t
)
6218 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6220 switch (OMP_CLAUSE_CODE (c
))
6222 case OMP_CLAUSE_GANG
:
6223 error_at (OMP_CLAUSE_LOCATION (c
),
6224 "%<gang%> num expression must be integral"); break;
6225 case OMP_CLAUSE_VECTOR
:
6226 error_at (OMP_CLAUSE_LOCATION (c
),
6227 "%<vector%> length expression must be integral");
6229 case OMP_CLAUSE_WORKER
:
6230 error_at (OMP_CLAUSE_LOCATION (c
),
6231 "%<worker%> num expression must be integral");
6234 error_at (OMP_CLAUSE_LOCATION (c
),
6235 "%qs expression must be integral",
6236 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6242 t
= mark_rvalue_use (t
);
6243 if (!processing_template_decl
)
6245 t
= maybe_constant_value (t
);
6246 if (TREE_CODE (t
) == INTEGER_CST
6247 && tree_int_cst_sgn (t
) != 1)
6249 switch (OMP_CLAUSE_CODE (c
))
6251 case OMP_CLAUSE_GANG
:
6252 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6253 "%<gang%> num value must be positive");
6255 case OMP_CLAUSE_VECTOR
:
6256 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6257 "%<vector%> length value must be"
6260 case OMP_CLAUSE_WORKER
:
6261 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6262 "%<worker%> num value must be"
6266 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6267 "%qs value must be positive",
6268 omp_clause_code_name
6269 [OMP_CLAUSE_CODE (c
)]);
6271 t
= integer_one_node
;
6273 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6275 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6279 case OMP_CLAUSE_SCHEDULE
:
6280 if (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
)
6282 const char *p
= NULL
;
6283 switch (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_MASK
)
6285 case OMP_CLAUSE_SCHEDULE_STATIC
: p
= "static"; break;
6286 case OMP_CLAUSE_SCHEDULE_DYNAMIC
: break;
6287 case OMP_CLAUSE_SCHEDULE_GUIDED
: break;
6288 case OMP_CLAUSE_SCHEDULE_AUTO
: p
= "auto"; break;
6289 case OMP_CLAUSE_SCHEDULE_RUNTIME
: p
= "runtime"; break;
6290 default: gcc_unreachable ();
6294 error_at (OMP_CLAUSE_LOCATION (c
),
6295 "%<nonmonotonic%> modifier specified for %qs "
6296 "schedule kind", p
);
6297 OMP_CLAUSE_SCHEDULE_KIND (c
)
6298 = (enum omp_clause_schedule_kind
)
6299 (OMP_CLAUSE_SCHEDULE_KIND (c
)
6300 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
6304 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
6307 else if (t
== error_mark_node
)
6309 else if (!type_dependent_expression_p (t
)
6310 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
6311 != OMP_CLAUSE_SCHEDULE_CILKFOR
)
6312 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6314 error ("schedule chunk size expression must be integral");
6319 t
= mark_rvalue_use (t
);
6320 if (!processing_template_decl
)
6322 if (OMP_CLAUSE_SCHEDULE_KIND (c
)
6323 == OMP_CLAUSE_SCHEDULE_CILKFOR
)
6325 t
= convert_to_integer (long_integer_type_node
, t
);
6326 if (t
== error_mark_node
)
6332 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6334 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
6338 case OMP_CLAUSE_SIMDLEN
:
6339 case OMP_CLAUSE_SAFELEN
:
6340 t
= OMP_CLAUSE_OPERAND (c
, 0);
6341 if (t
== error_mark_node
)
6343 else if (!type_dependent_expression_p (t
)
6344 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6346 error ("%qs length expression must be integral",
6347 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6352 t
= mark_rvalue_use (t
);
6353 t
= maybe_constant_value (t
);
6354 if (!processing_template_decl
)
6356 if (TREE_CODE (t
) != INTEGER_CST
6357 || tree_int_cst_sgn (t
) != 1)
6359 error ("%qs length expression must be positive constant"
6360 " integer expression",
6361 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6365 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6366 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
6371 case OMP_CLAUSE_ASYNC
:
6372 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
6373 if (t
== error_mark_node
)
6375 else if (!type_dependent_expression_p (t
)
6376 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6378 error ("%<async%> expression must be integral");
6383 t
= mark_rvalue_use (t
);
6384 if (!processing_template_decl
)
6385 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6386 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
6390 case OMP_CLAUSE_WAIT
:
6391 t
= OMP_CLAUSE_WAIT_EXPR (c
);
6392 if (t
== error_mark_node
)
6394 else if (!processing_template_decl
)
6395 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6396 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
6399 case OMP_CLAUSE_THREAD_LIMIT
:
6400 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
6401 if (t
== error_mark_node
)
6403 else if (!type_dependent_expression_p (t
)
6404 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6406 error ("%<thread_limit%> expression must be integral");
6411 t
= mark_rvalue_use (t
);
6412 if (!processing_template_decl
)
6414 t
= maybe_constant_value (t
);
6415 if (TREE_CODE (t
) == INTEGER_CST
6416 && tree_int_cst_sgn (t
) != 1)
6418 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6419 "%<thread_limit%> value must be positive");
6420 t
= integer_one_node
;
6422 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6424 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
6428 case OMP_CLAUSE_DEVICE
:
6429 t
= OMP_CLAUSE_DEVICE_ID (c
);
6430 if (t
== error_mark_node
)
6432 else if (!type_dependent_expression_p (t
)
6433 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6435 error ("%<device%> id must be integral");
6440 t
= mark_rvalue_use (t
);
6441 if (!processing_template_decl
)
6442 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6443 OMP_CLAUSE_DEVICE_ID (c
) = t
;
6447 case OMP_CLAUSE_DIST_SCHEDULE
:
6448 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
6451 else if (t
== error_mark_node
)
6453 else if (!type_dependent_expression_p (t
)
6454 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6456 error ("%<dist_schedule%> chunk size expression must be "
6462 t
= mark_rvalue_use (t
);
6463 if (!processing_template_decl
)
6464 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6465 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
6469 case OMP_CLAUSE_ALIGNED
:
6470 t
= OMP_CLAUSE_DECL (c
);
6471 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
6473 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6478 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6480 if (processing_template_decl
)
6483 error ("%qD is not a variable in %<aligned%> clause", t
);
6485 error ("%qE is not a variable in %<aligned%> clause", t
);
6488 else if (!type_dependent_expression_p (t
)
6489 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
6490 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
6491 && (TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6492 || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
6493 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
6496 error_at (OMP_CLAUSE_LOCATION (c
),
6497 "%qE in %<aligned%> clause is neither a pointer nor "
6498 "an array nor a reference to pointer or array", t
);
6501 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
6503 error ("%qD appears more than once in %<aligned%> clauses", t
);
6507 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
6508 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
6509 if (t
== error_mark_node
)
6511 else if (t
== NULL_TREE
)
6513 else if (!type_dependent_expression_p (t
)
6514 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6516 error ("%<aligned%> clause alignment expression must "
6522 t
= mark_rvalue_use (t
);
6523 t
= maybe_constant_value (t
);
6524 if (!processing_template_decl
)
6526 if (TREE_CODE (t
) != INTEGER_CST
6527 || tree_int_cst_sgn (t
) != 1)
6529 error ("%<aligned%> clause alignment expression must be "
6530 "positive constant integer expression");
6534 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
6538 case OMP_CLAUSE_DEPEND
:
6539 t
= OMP_CLAUSE_DECL (c
);
6542 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
6543 == OMP_CLAUSE_DEPEND_SOURCE
);
6546 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
6548 if (cp_finish_omp_clause_depend_sink (c
))
6552 if (TREE_CODE (t
) == TREE_LIST
)
6554 if (handle_omp_array_sections (c
, ((ort
& C_ORT_OMP_DECLARE_SIMD
)
6559 if (t
== error_mark_node
)
6561 else if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6563 if (processing_template_decl
)
6566 error ("%qD is not a variable in %<depend%> clause", t
);
6568 error ("%qE is not a variable in %<depend%> clause", t
);
6571 else if (t
== current_class_ptr
)
6573 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6577 else if (!processing_template_decl
6578 && !cxx_mark_addressable (t
))
6582 case OMP_CLAUSE_MAP
:
6584 case OMP_CLAUSE_FROM
:
6585 case OMP_CLAUSE__CACHE_
:
6586 t
= OMP_CLAUSE_DECL (c
);
6587 if (TREE_CODE (t
) == TREE_LIST
)
6589 if (handle_omp_array_sections (c
, ((ort
& C_ORT_OMP_DECLARE_SIMD
)
6594 t
= OMP_CLAUSE_DECL (c
);
6595 if (TREE_CODE (t
) != TREE_LIST
6596 && !type_dependent_expression_p (t
)
6597 && !cp_omp_mappable_type (TREE_TYPE (t
)))
6599 error_at (OMP_CLAUSE_LOCATION (c
),
6600 "array section does not have mappable type "
6602 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6605 while (TREE_CODE (t
) == ARRAY_REF
)
6606 t
= TREE_OPERAND (t
, 0);
6607 if (TREE_CODE (t
) == COMPONENT_REF
6608 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6610 while (TREE_CODE (t
) == COMPONENT_REF
)
6611 t
= TREE_OPERAND (t
, 0);
6612 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6614 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6616 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6617 error ("%qD appears more than once in motion"
6620 error ("%qD appears more than once in map"
6626 bitmap_set_bit (&map_head
, DECL_UID (t
));
6627 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6633 if (t
== error_mark_node
)
6638 if (REFERENCE_REF_P (t
)
6639 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
6641 t
= TREE_OPERAND (t
, 0);
6642 OMP_CLAUSE_DECL (c
) = t
;
6644 if (TREE_CODE (t
) == COMPONENT_REF
6645 && (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
6646 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
6648 if (type_dependent_expression_p (t
))
6650 if (DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
6652 error_at (OMP_CLAUSE_LOCATION (c
),
6653 "bit-field %qE in %qs clause",
6654 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6657 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6659 error_at (OMP_CLAUSE_LOCATION (c
),
6660 "%qE does not have a mappable type in %qs clause",
6661 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6664 while (TREE_CODE (t
) == COMPONENT_REF
)
6666 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
6669 error_at (OMP_CLAUSE_LOCATION (c
),
6670 "%qE is a member of a union", t
);
6674 t
= TREE_OPERAND (t
, 0);
6678 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6680 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6681 goto handle_map_references
;
6684 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6686 if (processing_template_decl
)
6688 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6689 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6690 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
))
6693 error ("%qD is not a variable in %qs clause", t
,
6694 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6696 error ("%qE is not a variable in %qs clause", t
,
6697 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6700 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
6702 error ("%qD is threadprivate variable in %qs clause", t
,
6703 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6706 else if (t
== current_class_ptr
)
6708 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6713 else if (!processing_template_decl
6714 && TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6715 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
6716 || (OMP_CLAUSE_MAP_KIND (c
)
6717 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
6718 && !cxx_mark_addressable (t
))
6720 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6721 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6722 || (OMP_CLAUSE_MAP_KIND (c
)
6723 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
6724 && t
== OMP_CLAUSE_DECL (c
)
6725 && !type_dependent_expression_p (t
)
6726 && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t
))
6728 ? TREE_TYPE (TREE_TYPE (t
))
6731 error_at (OMP_CLAUSE_LOCATION (c
),
6732 "%qD does not have a mappable type in %qs clause", t
,
6733 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6736 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6737 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
6738 && !type_dependent_expression_p (t
)
6739 && !POINTER_TYPE_P (TREE_TYPE (t
)))
6741 error ("%qD is not a pointer variable", t
);
6744 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6745 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
6747 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6748 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6750 error ("%qD appears more than once in data clauses", t
);
6753 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6755 error ("%qD appears both in data and map clauses", t
);
6759 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6761 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6763 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6764 error ("%qD appears more than once in motion clauses", t
);
6766 error ("%qD appears more than once in map clauses", t
);
6769 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6770 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6772 error ("%qD appears both in data and map clauses", t
);
6777 bitmap_set_bit (&map_head
, DECL_UID (t
));
6778 if (t
!= OMP_CLAUSE_DECL (c
)
6779 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
6780 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6782 handle_map_references
:
6784 && !processing_template_decl
6785 && (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
6786 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
))) == REFERENCE_TYPE
)
6788 t
= OMP_CLAUSE_DECL (c
);
6789 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6791 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6792 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6794 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6796 else if (OMP_CLAUSE_MAP_KIND (c
)
6797 != GOMP_MAP_FIRSTPRIVATE_POINTER
6798 && (OMP_CLAUSE_MAP_KIND (c
)
6799 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
6800 && (OMP_CLAUSE_MAP_KIND (c
)
6801 != GOMP_MAP_ALWAYS_POINTER
))
6803 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
6805 if (TREE_CODE (t
) == COMPONENT_REF
)
6806 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
6808 OMP_CLAUSE_SET_MAP_KIND (c2
,
6809 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
6810 OMP_CLAUSE_DECL (c2
) = t
;
6811 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
6812 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
6813 OMP_CLAUSE_CHAIN (c
) = c2
;
6814 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6815 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6817 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6823 case OMP_CLAUSE_TO_DECLARE
:
6824 case OMP_CLAUSE_LINK
:
6825 t
= OMP_CLAUSE_DECL (c
);
6826 if (TREE_CODE (t
) == FUNCTION_DECL
6827 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6829 else if (!VAR_P (t
))
6831 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6833 if (TREE_CODE (t
) == OVERLOAD
&& OVL_CHAIN (t
))
6834 error_at (OMP_CLAUSE_LOCATION (c
),
6835 "overloaded function name %qE in clause %qs", t
,
6836 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6837 else if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
6838 error_at (OMP_CLAUSE_LOCATION (c
),
6839 "template %qE in clause %qs", t
,
6840 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6842 error_at (OMP_CLAUSE_LOCATION (c
),
6843 "%qE is neither a variable nor a function name "
6845 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6848 error_at (OMP_CLAUSE_LOCATION (c
),
6849 "%qE is not a variable in clause %qs", t
,
6850 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6853 else if (DECL_THREAD_LOCAL_P (t
))
6855 error_at (OMP_CLAUSE_LOCATION (c
),
6856 "%qD is threadprivate variable in %qs clause", t
,
6857 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6860 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6862 error_at (OMP_CLAUSE_LOCATION (c
),
6863 "%qD does not have a mappable type in %qs clause", t
,
6864 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6869 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
6871 error_at (OMP_CLAUSE_LOCATION (c
),
6872 "%qE appears more than once on the same "
6873 "%<declare target%> directive", t
);
6877 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6880 case OMP_CLAUSE_UNIFORM
:
6881 t
= OMP_CLAUSE_DECL (c
);
6882 if (TREE_CODE (t
) != PARM_DECL
)
6884 if (processing_template_decl
)
6887 error ("%qD is not an argument in %<uniform%> clause", t
);
6889 error ("%qE is not an argument in %<uniform%> clause", t
);
6893 /* map_head bitmap is used as uniform_head if declare_simd. */
6894 bitmap_set_bit (&map_head
, DECL_UID (t
));
6895 goto check_dup_generic
;
6897 case OMP_CLAUSE_GRAINSIZE
:
6898 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
6899 if (t
== error_mark_node
)
6901 else if (!type_dependent_expression_p (t
)
6902 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6904 error ("%<grainsize%> expression must be integral");
6909 t
= mark_rvalue_use (t
);
6910 if (!processing_template_decl
)
6912 t
= maybe_constant_value (t
);
6913 if (TREE_CODE (t
) == INTEGER_CST
6914 && tree_int_cst_sgn (t
) != 1)
6916 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6917 "%<grainsize%> value must be positive");
6918 t
= integer_one_node
;
6920 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6922 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
6926 case OMP_CLAUSE_PRIORITY
:
6927 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
6928 if (t
== error_mark_node
)
6930 else if (!type_dependent_expression_p (t
)
6931 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6933 error ("%<priority%> expression must be integral");
6938 t
= mark_rvalue_use (t
);
6939 if (!processing_template_decl
)
6941 t
= maybe_constant_value (t
);
6942 if (TREE_CODE (t
) == INTEGER_CST
6943 && tree_int_cst_sgn (t
) == -1)
6945 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6946 "%<priority%> value must be non-negative");
6947 t
= integer_one_node
;
6949 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6951 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
6955 case OMP_CLAUSE_HINT
:
6956 t
= OMP_CLAUSE_HINT_EXPR (c
);
6957 if (t
== error_mark_node
)
6959 else if (!type_dependent_expression_p (t
)
6960 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6962 error ("%<num_tasks%> expression must be integral");
6967 t
= mark_rvalue_use (t
);
6968 if (!processing_template_decl
)
6970 t
= maybe_constant_value (t
);
6971 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6973 OMP_CLAUSE_HINT_EXPR (c
) = t
;
6977 case OMP_CLAUSE_IS_DEVICE_PTR
:
6978 case OMP_CLAUSE_USE_DEVICE_PTR
:
6979 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
6980 t
= OMP_CLAUSE_DECL (c
);
6981 if (!type_dependent_expression_p (t
))
6983 tree type
= TREE_TYPE (t
);
6984 if (TREE_CODE (type
) != POINTER_TYPE
6985 && TREE_CODE (type
) != ARRAY_TYPE
6986 && (TREE_CODE (type
) != REFERENCE_TYPE
6987 || (TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
6988 && TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
)))
6990 error_at (OMP_CLAUSE_LOCATION (c
),
6991 "%qs variable is neither a pointer, nor an array"
6992 "nor reference to pointer or array",
6993 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6997 goto check_dup_generic
;
6999 case OMP_CLAUSE_NOWAIT
:
7000 case OMP_CLAUSE_DEFAULT
:
7001 case OMP_CLAUSE_UNTIED
:
7002 case OMP_CLAUSE_COLLAPSE
:
7003 case OMP_CLAUSE_MERGEABLE
:
7004 case OMP_CLAUSE_PARALLEL
:
7005 case OMP_CLAUSE_FOR
:
7006 case OMP_CLAUSE_SECTIONS
:
7007 case OMP_CLAUSE_TASKGROUP
:
7008 case OMP_CLAUSE_PROC_BIND
:
7009 case OMP_CLAUSE_NOGROUP
:
7010 case OMP_CLAUSE_THREADS
:
7011 case OMP_CLAUSE_SIMD
:
7012 case OMP_CLAUSE_DEFAULTMAP
:
7013 case OMP_CLAUSE__CILK_FOR_COUNT_
:
7014 case OMP_CLAUSE_AUTO
:
7015 case OMP_CLAUSE_INDEPENDENT
:
7016 case OMP_CLAUSE_SEQ
:
7019 case OMP_CLAUSE_TILE
:
7020 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
7021 list
= TREE_CHAIN (list
))
7023 t
= TREE_VALUE (list
);
7025 if (t
== error_mark_node
)
7027 else if (!type_dependent_expression_p (t
)
7028 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7030 error ("%<tile%> value must be integral");
7035 t
= mark_rvalue_use (t
);
7036 if (!processing_template_decl
)
7038 t
= maybe_constant_value (t
);
7039 if (TREE_CODE (t
) == INTEGER_CST
7040 && tree_int_cst_sgn (t
) != 1
7041 && t
!= integer_minus_one_node
)
7043 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7044 "%<tile%> value must be positive");
7045 t
= integer_one_node
;
7048 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7051 /* Update list item. */
7052 TREE_VALUE (list
) = t
;
7056 case OMP_CLAUSE_ORDERED
:
7057 ordered_seen
= true;
7060 case OMP_CLAUSE_INBRANCH
:
7061 case OMP_CLAUSE_NOTINBRANCH
:
7064 error ("%<inbranch%> clause is incompatible with "
7076 *pc
= OMP_CLAUSE_CHAIN (c
);
7078 pc
= &OMP_CLAUSE_CHAIN (c
);
7081 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
7083 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
7084 bool remove
= false;
7085 bool need_complete_type
= false;
7086 bool need_default_ctor
= false;
7087 bool need_copy_ctor
= false;
7088 bool need_copy_assignment
= false;
7089 bool need_implicitly_determined
= false;
7090 bool need_dtor
= false;
7091 tree type
, inner_type
;
7095 case OMP_CLAUSE_SHARED
:
7096 need_implicitly_determined
= true;
7098 case OMP_CLAUSE_PRIVATE
:
7099 need_complete_type
= true;
7100 need_default_ctor
= true;
7102 need_implicitly_determined
= true;
7104 case OMP_CLAUSE_FIRSTPRIVATE
:
7105 need_complete_type
= true;
7106 need_copy_ctor
= true;
7108 need_implicitly_determined
= true;
7110 case OMP_CLAUSE_LASTPRIVATE
:
7111 need_complete_type
= true;
7112 need_copy_assignment
= true;
7113 need_implicitly_determined
= true;
7115 case OMP_CLAUSE_REDUCTION
:
7116 need_implicitly_determined
= true;
7118 case OMP_CLAUSE_LINEAR
:
7119 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
7120 need_implicitly_determined
= true;
7121 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
7122 && !bitmap_bit_p (&map_head
,
7123 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
7125 error_at (OMP_CLAUSE_LOCATION (c
),
7126 "%<linear%> clause step is a parameter %qD not "
7127 "specified in %<uniform%> clause",
7128 OMP_CLAUSE_LINEAR_STEP (c
));
7129 *pc
= OMP_CLAUSE_CHAIN (c
);
7133 case OMP_CLAUSE_COPYPRIVATE
:
7134 need_copy_assignment
= true;
7136 case OMP_CLAUSE_COPYIN
:
7137 need_copy_assignment
= true;
7139 case OMP_CLAUSE_SIMDLEN
:
7141 && !processing_template_decl
7142 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
7143 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
7145 error_at (OMP_CLAUSE_LOCATION (c
),
7146 "%<simdlen%> clause value is bigger than "
7147 "%<safelen%> clause value");
7148 OMP_CLAUSE_SIMDLEN_EXPR (c
)
7149 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
7151 pc
= &OMP_CLAUSE_CHAIN (c
);
7153 case OMP_CLAUSE_SCHEDULE
:
7155 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
7156 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
7158 error_at (OMP_CLAUSE_LOCATION (c
),
7159 "%<nonmonotonic%> schedule modifier specified "
7160 "together with %<ordered%> clause");
7161 OMP_CLAUSE_SCHEDULE_KIND (c
)
7162 = (enum omp_clause_schedule_kind
)
7163 (OMP_CLAUSE_SCHEDULE_KIND (c
)
7164 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
7166 pc
= &OMP_CLAUSE_CHAIN (c
);
7168 case OMP_CLAUSE_NOWAIT
:
7169 if (copyprivate_seen
)
7171 error_at (OMP_CLAUSE_LOCATION (c
),
7172 "%<nowait%> clause must not be used together "
7173 "with %<copyprivate%>");
7174 *pc
= OMP_CLAUSE_CHAIN (c
);
7179 pc
= &OMP_CLAUSE_CHAIN (c
);
7183 t
= OMP_CLAUSE_DECL (c
);
7184 if (processing_template_decl
7185 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7187 pc
= &OMP_CLAUSE_CHAIN (c
);
7193 case OMP_CLAUSE_LASTPRIVATE
:
7194 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7196 need_default_ctor
= true;
7201 case OMP_CLAUSE_REDUCTION
:
7202 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
7206 t
= OMP_CLAUSE_DECL (c
);
7209 case OMP_CLAUSE_COPYIN
:
7210 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
7212 error ("%qE must be %<threadprivate%> for %<copyin%>", t
);
7221 if (need_complete_type
|| need_copy_assignment
)
7223 t
= require_complete_type (t
);
7224 if (t
== error_mark_node
)
7226 else if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
7227 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
7230 if (need_implicitly_determined
)
7232 const char *share_name
= NULL
;
7234 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7235 share_name
= "threadprivate";
7236 else switch (cxx_omp_predetermined_sharing (t
))
7238 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
7240 case OMP_CLAUSE_DEFAULT_SHARED
:
7241 /* const vars may be specified in firstprivate clause. */
7242 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
7243 && cxx_omp_const_qual_no_mutable (t
))
7245 share_name
= "shared";
7247 case OMP_CLAUSE_DEFAULT_PRIVATE
:
7248 share_name
= "private";
7255 error ("%qE is predetermined %qs for %qs",
7256 omp_clause_printable_decl (t
), share_name
,
7257 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7262 /* We're interested in the base element, not arrays. */
7263 inner_type
= type
= TREE_TYPE (t
);
7264 if ((need_complete_type
7265 || need_copy_assignment
7266 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
7267 && TREE_CODE (inner_type
) == REFERENCE_TYPE
)
7268 inner_type
= TREE_TYPE (inner_type
);
7269 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
7270 inner_type
= TREE_TYPE (inner_type
);
7272 /* Check for special function availability by building a call to one.
7273 Save the results, because later we won't be in the right context
7274 for making these queries. */
7275 if (CLASS_TYPE_P (inner_type
)
7276 && COMPLETE_TYPE_P (inner_type
)
7277 && (need_default_ctor
|| need_copy_ctor
7278 || need_copy_assignment
|| need_dtor
)
7279 && !type_dependent_expression_p (t
)
7280 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
7281 need_copy_ctor
, need_copy_assignment
,
7286 && c_kind
== OMP_CLAUSE_SHARED
7287 && processing_template_decl
)
7289 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7291 OMP_CLAUSE_DECL (c
) = t
;
7295 *pc
= OMP_CLAUSE_CHAIN (c
);
7297 pc
= &OMP_CLAUSE_CHAIN (c
);
7300 bitmap_obstack_release (NULL
);
7304 /* Start processing OpenMP clauses that can include any
7305 privatization clauses for non-static data members. */
7308 push_omp_privatization_clauses (bool ignore_next
)
7310 if (omp_private_member_ignore_next
)
7312 omp_private_member_ignore_next
= ignore_next
;
7315 omp_private_member_ignore_next
= ignore_next
;
7316 if (omp_private_member_map
)
7317 omp_private_member_vec
.safe_push (error_mark_node
);
7318 return push_stmt_list ();
7321 /* Revert remapping of any non-static data members since
7322 the last push_omp_privatization_clauses () call. */
7325 pop_omp_privatization_clauses (tree stmt
)
7327 if (stmt
== NULL_TREE
)
7329 stmt
= pop_stmt_list (stmt
);
7330 if (omp_private_member_map
)
7332 while (!omp_private_member_vec
.is_empty ())
7334 tree t
= omp_private_member_vec
.pop ();
7335 if (t
== error_mark_node
)
7340 bool no_decl_expr
= t
== integer_zero_node
;
7342 t
= omp_private_member_vec
.pop ();
7343 tree
*v
= omp_private_member_map
->get (t
);
7347 omp_private_member_map
->remove (t
);
7349 delete omp_private_member_map
;
7350 omp_private_member_map
= NULL
;
7355 /* Remember OpenMP privatization clauses mapping and clear it.
7356 Used for lambdas. */
7359 save_omp_privatization_clauses (vec
<tree
> &save
)
7362 if (omp_private_member_ignore_next
)
7363 save
.safe_push (integer_one_node
);
7364 omp_private_member_ignore_next
= false;
7365 if (!omp_private_member_map
)
7368 while (!omp_private_member_vec
.is_empty ())
7370 tree t
= omp_private_member_vec
.pop ();
7371 if (t
== error_mark_node
)
7377 if (t
== integer_zero_node
)
7378 t
= omp_private_member_vec
.pop ();
7379 tree
*v
= omp_private_member_map
->get (t
);
7381 save
.safe_push (*v
);
7386 delete omp_private_member_map
;
7387 omp_private_member_map
= NULL
;
7390 /* Restore OpenMP privatization clauses mapping saved by the
7394 restore_omp_privatization_clauses (vec
<tree
> &save
)
7396 gcc_assert (omp_private_member_vec
.is_empty ());
7397 omp_private_member_ignore_next
= false;
7398 if (save
.is_empty ())
7400 if (save
.length () == 1 && save
[0] == integer_one_node
)
7402 omp_private_member_ignore_next
= true;
7407 omp_private_member_map
= new hash_map
<tree
, tree
>;
7408 while (!save
.is_empty ())
7410 tree t
= save
.pop ();
7412 if (t
!= error_mark_node
)
7414 if (t
== integer_one_node
)
7416 omp_private_member_ignore_next
= true;
7417 gcc_assert (save
.is_empty ());
7420 if (t
== integer_zero_node
)
7422 tree
&v
= omp_private_member_map
->get_or_insert (t
);
7425 omp_private_member_vec
.safe_push (t
);
7427 omp_private_member_vec
.safe_push (n
);
7432 /* For all variables in the tree_list VARS, mark them as thread local. */
7435 finish_omp_threadprivate (tree vars
)
7439 /* Mark every variable in VARS to be assigned thread local storage. */
7440 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7442 tree v
= TREE_PURPOSE (t
);
7444 if (error_operand_p (v
))
7446 else if (!VAR_P (v
))
7447 error ("%<threadprivate%> %qD is not file, namespace "
7448 "or block scope variable", v
);
7449 /* If V had already been marked threadprivate, it doesn't matter
7450 whether it had been used prior to this point. */
7451 else if (TREE_USED (v
)
7452 && (DECL_LANG_SPECIFIC (v
) == NULL
7453 || !CP_DECL_THREADPRIVATE_P (v
)))
7454 error ("%qE declared %<threadprivate%> after first use", v
);
7455 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7456 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7457 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
7458 error ("%<threadprivate%> %qE has incomplete type", v
);
7459 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
7460 && CP_DECL_CONTEXT (v
) != current_class_type
)
7461 error ("%<threadprivate%> %qE directive not "
7462 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
7465 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
7466 if (DECL_LANG_SPECIFIC (v
) == NULL
)
7468 retrofit_lang_decl (v
);
7470 /* Make sure that DECL_DISCRIMINATOR_P continues to be true
7471 after the allocation of the lang_decl structure. */
7472 if (DECL_DISCRIMINATOR_P (v
))
7473 DECL_LANG_SPECIFIC (v
)->u
.base
.u2sel
= 1;
7476 if (! CP_DECL_THREAD_LOCAL_P (v
))
7478 CP_DECL_THREAD_LOCAL_P (v
) = true;
7479 set_decl_tls_model (v
, decl_default_tls_model (v
));
7480 /* If rtl has been already set for this var, call
7481 make_decl_rtl once again, so that encode_section_info
7482 has a chance to look at the new decl flags. */
7483 if (DECL_RTL_SET_P (v
))
7486 CP_DECL_THREADPRIVATE_P (v
) = 1;
7491 /* Build an OpenMP structured block. */
7494 begin_omp_structured_block (void)
7496 return do_pushlevel (sk_omp
);
7500 finish_omp_structured_block (tree block
)
7502 return do_poplevel (block
);
7505 /* Similarly, except force the retention of the BLOCK. */
7508 begin_omp_parallel (void)
7510 keep_next_level (true);
7511 return begin_omp_structured_block ();
7514 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
7518 finish_oacc_data (tree clauses
, tree block
)
7522 block
= finish_omp_structured_block (block
);
7524 stmt
= make_node (OACC_DATA
);
7525 TREE_TYPE (stmt
) = void_type_node
;
7526 OACC_DATA_CLAUSES (stmt
) = clauses
;
7527 OACC_DATA_BODY (stmt
) = block
;
7529 return add_stmt (stmt
);
7532 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
7536 finish_oacc_host_data (tree clauses
, tree block
)
7540 block
= finish_omp_structured_block (block
);
7542 stmt
= make_node (OACC_HOST_DATA
);
7543 TREE_TYPE (stmt
) = void_type_node
;
7544 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
7545 OACC_HOST_DATA_BODY (stmt
) = block
;
7547 return add_stmt (stmt
);
7550 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
7554 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
7556 body
= finish_omp_structured_block (body
);
7558 tree stmt
= make_node (code
);
7559 TREE_TYPE (stmt
) = void_type_node
;
7560 OMP_BODY (stmt
) = body
;
7561 OMP_CLAUSES (stmt
) = clauses
;
7563 return add_stmt (stmt
);
7567 finish_omp_parallel (tree clauses
, tree body
)
7571 body
= finish_omp_structured_block (body
);
7573 stmt
= make_node (OMP_PARALLEL
);
7574 TREE_TYPE (stmt
) = void_type_node
;
7575 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
7576 OMP_PARALLEL_BODY (stmt
) = body
;
7578 return add_stmt (stmt
);
7582 begin_omp_task (void)
7584 keep_next_level (true);
7585 return begin_omp_structured_block ();
7589 finish_omp_task (tree clauses
, tree body
)
7593 body
= finish_omp_structured_block (body
);
7595 stmt
= make_node (OMP_TASK
);
7596 TREE_TYPE (stmt
) = void_type_node
;
7597 OMP_TASK_CLAUSES (stmt
) = clauses
;
7598 OMP_TASK_BODY (stmt
) = body
;
7600 return add_stmt (stmt
);
7603 /* Helper function for finish_omp_for. Convert Ith random access iterator
7604 into integral iterator. Return FALSE if successful. */
7607 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
7608 tree declv
, tree orig_declv
, tree initv
,
7609 tree condv
, tree incrv
, tree
*body
,
7610 tree
*pre_body
, tree
&clauses
, tree
*lastp
,
7611 int collapse
, int ordered
)
7613 tree diff
, iter_init
, iter_incr
= NULL
, last
;
7614 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
7615 tree decl
= TREE_VEC_ELT (declv
, i
);
7616 tree init
= TREE_VEC_ELT (initv
, i
);
7617 tree cond
= TREE_VEC_ELT (condv
, i
);
7618 tree incr
= TREE_VEC_ELT (incrv
, i
);
7620 location_t elocus
= locus
;
7622 if (init
&& EXPR_HAS_LOCATION (init
))
7623 elocus
= EXPR_LOCATION (init
);
7625 cond
= cp_fully_fold (cond
);
7626 switch (TREE_CODE (cond
))
7633 if (TREE_OPERAND (cond
, 1) == iter
)
7634 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
7635 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
7636 if (TREE_OPERAND (cond
, 0) != iter
)
7637 cond
= error_mark_node
;
7640 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
7643 TREE_OPERAND (cond
, 1), ERROR_MARK
,
7644 NULL
, tf_warning_or_error
);
7645 if (error_operand_p (tem
))
7650 cond
= error_mark_node
;
7653 if (cond
== error_mark_node
)
7655 error_at (elocus
, "invalid controlling predicate");
7658 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
7659 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
7660 tf_warning_or_error
);
7661 diff
= cp_fully_fold (diff
);
7662 if (error_operand_p (diff
))
7664 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
7666 error_at (elocus
, "difference between %qE and %qD does not have integer type",
7667 TREE_OPERAND (cond
, 1), iter
);
7670 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
,
7671 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
7672 cond
, cp_walk_subtrees
))
7675 switch (TREE_CODE (incr
))
7677 case PREINCREMENT_EXPR
:
7678 case PREDECREMENT_EXPR
:
7679 case POSTINCREMENT_EXPR
:
7680 case POSTDECREMENT_EXPR
:
7681 if (TREE_OPERAND (incr
, 0) != iter
)
7683 incr
= error_mark_node
;
7686 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
7687 TREE_CODE (incr
), iter
,
7688 tf_warning_or_error
);
7689 if (error_operand_p (iter_incr
))
7691 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
7692 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
7693 incr
= integer_one_node
;
7695 incr
= integer_minus_one_node
;
7698 if (TREE_OPERAND (incr
, 0) != iter
)
7699 incr
= error_mark_node
;
7700 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
7701 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
7703 tree rhs
= TREE_OPERAND (incr
, 1);
7704 if (TREE_OPERAND (rhs
, 0) == iter
)
7706 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
7708 incr
= error_mark_node
;
7711 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7712 iter
, TREE_CODE (rhs
),
7713 TREE_OPERAND (rhs
, 1),
7714 tf_warning_or_error
);
7715 if (error_operand_p (iter_incr
))
7717 incr
= TREE_OPERAND (rhs
, 1);
7718 incr
= cp_convert (TREE_TYPE (diff
), incr
,
7719 tf_warning_or_error
);
7720 if (TREE_CODE (rhs
) == MINUS_EXPR
)
7722 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
7723 incr
= fold_simple (incr
);
7725 if (TREE_CODE (incr
) != INTEGER_CST
7726 && (TREE_CODE (incr
) != NOP_EXPR
7727 || (TREE_CODE (TREE_OPERAND (incr
, 0))
7732 else if (TREE_OPERAND (rhs
, 1) == iter
)
7734 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
7735 || TREE_CODE (rhs
) != PLUS_EXPR
)
7736 incr
= error_mark_node
;
7739 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
7741 TREE_OPERAND (rhs
, 0),
7744 tf_warning_or_error
);
7745 if (error_operand_p (iter_incr
))
7747 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7750 tf_warning_or_error
);
7751 if (error_operand_p (iter_incr
))
7753 incr
= TREE_OPERAND (rhs
, 0);
7758 incr
= error_mark_node
;
7761 incr
= error_mark_node
;
7764 incr
= error_mark_node
;
7768 if (incr
== error_mark_node
)
7770 error_at (elocus
, "invalid increment expression");
7774 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
7775 bool taskloop_iv_seen
= false;
7776 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7777 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
7778 && OMP_CLAUSE_DECL (c
) == iter
)
7780 if (code
== OMP_TASKLOOP
)
7782 taskloop_iv_seen
= true;
7783 OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c
) = 1;
7787 else if (code
== OMP_TASKLOOP
7788 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
7789 && OMP_CLAUSE_DECL (c
) == iter
)
7791 taskloop_iv_seen
= true;
7792 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
7795 decl
= create_temporary_var (TREE_TYPE (diff
));
7797 add_decl_expr (decl
);
7798 last
= create_temporary_var (TREE_TYPE (diff
));
7800 add_decl_expr (last
);
7801 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
7802 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7804 incr_var
= create_temporary_var (TREE_TYPE (diff
));
7805 pushdecl (incr_var
);
7806 add_decl_expr (incr_var
);
7808 gcc_assert (stmts_are_full_exprs_p ());
7809 tree diffvar
= NULL_TREE
;
7810 if (code
== OMP_TASKLOOP
)
7812 if (!taskloop_iv_seen
)
7814 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7815 OMP_CLAUSE_DECL (ivc
) = iter
;
7816 cxx_omp_finish_clause (ivc
, NULL
);
7817 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
7820 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7821 OMP_CLAUSE_DECL (lvc
) = last
;
7822 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
7824 diffvar
= create_temporary_var (TREE_TYPE (diff
));
7826 add_decl_expr (diffvar
);
7829 orig_pre_body
= *pre_body
;
7830 *pre_body
= push_stmt_list ();
7832 add_stmt (orig_pre_body
);
7834 finish_expr_stmt (build_x_modify_expr (elocus
,
7835 iter
, NOP_EXPR
, init
,
7836 tf_warning_or_error
));
7837 init
= build_int_cst (TREE_TYPE (diff
), 0);
7838 if (c
&& iter_incr
== NULL
7839 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7843 finish_expr_stmt (build_x_modify_expr (elocus
,
7845 incr
, tf_warning_or_error
));
7848 iter_incr
= build_x_modify_expr (elocus
,
7849 iter
, PLUS_EXPR
, incr
,
7850 tf_warning_or_error
);
7852 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
7854 finish_expr_stmt (build_x_modify_expr (elocus
,
7855 last
, NOP_EXPR
, init
,
7856 tf_warning_or_error
));
7859 finish_expr_stmt (build_x_modify_expr (elocus
,
7861 diff
, tf_warning_or_error
));
7864 *pre_body
= pop_stmt_list (*pre_body
);
7866 cond
= cp_build_binary_op (elocus
,
7867 TREE_CODE (cond
), decl
, diff
,
7868 tf_warning_or_error
);
7869 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
7870 elocus
, incr
, NULL_TREE
);
7873 *body
= push_stmt_list ();
7874 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
7875 iter_init
= build_x_modify_expr (elocus
,
7876 iter
, PLUS_EXPR
, iter_init
,
7877 tf_warning_or_error
);
7878 if (iter_init
!= error_mark_node
)
7879 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7880 finish_expr_stmt (iter_init
);
7881 finish_expr_stmt (build_x_modify_expr (elocus
,
7882 last
, NOP_EXPR
, decl
,
7883 tf_warning_or_error
));
7884 add_stmt (orig_body
);
7885 *body
= pop_stmt_list (*body
);
7889 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
7891 finish_expr_stmt (iter_incr
);
7895 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
7896 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
7897 iter_init
, iter_incr
);
7898 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
7899 iter_init
= build_x_modify_expr (elocus
,
7900 iter
, PLUS_EXPR
, iter_init
,
7901 tf_warning_or_error
);
7902 if (iter_init
!= error_mark_node
)
7903 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7904 finish_expr_stmt (iter_init
);
7906 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
7907 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
7910 TREE_VEC_ELT (declv
, i
) = decl
;
7911 TREE_VEC_ELT (initv
, i
) = init
;
7912 TREE_VEC_ELT (condv
, i
) = cond
;
7913 TREE_VEC_ELT (incrv
, i
) = incr
;
7919 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
7920 are directly for their associated operands in the statement. DECL
7921 and INIT are a combo; if DECL is NULL then INIT ought to be a
7922 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
7923 optional statements that need to go before the loop into its
7927 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
7928 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
7929 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
7931 tree omp_for
= NULL
, orig_incr
= NULL
;
7932 tree decl
= NULL
, init
, cond
, incr
, orig_decl
= NULL_TREE
, block
= NULL_TREE
;
7933 tree last
= NULL_TREE
;
7939 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
7940 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
7941 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
7942 if (TREE_VEC_LENGTH (declv
) > 1)
7944 tree c
= find_omp_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
7946 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
7947 if (collapse
!= TREE_VEC_LENGTH (declv
))
7948 ordered
= TREE_VEC_LENGTH (declv
);
7950 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
7952 decl
= TREE_VEC_ELT (declv
, i
);
7953 init
= TREE_VEC_ELT (initv
, i
);
7954 cond
= TREE_VEC_ELT (condv
, i
);
7955 incr
= TREE_VEC_ELT (incrv
, i
);
7961 switch (TREE_CODE (init
))
7964 decl
= TREE_OPERAND (init
, 0);
7965 init
= TREE_OPERAND (init
, 1);
7968 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
7970 decl
= TREE_OPERAND (init
, 0);
7971 init
= TREE_OPERAND (init
, 2);
7981 "expected iteration declaration or initialization");
7986 if (init
&& EXPR_HAS_LOCATION (init
))
7987 elocus
= EXPR_LOCATION (init
);
7991 error_at (elocus
, "missing controlling predicate");
7997 error_at (elocus
, "missing increment expression");
8001 TREE_VEC_ELT (declv
, i
) = decl
;
8002 TREE_VEC_ELT (initv
, i
) = init
;
8009 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
8011 && !c_omp_check_loop_iv_exprs (locus
, declv
,
8012 TREE_VEC_ELT (declv
, i
), orig_init
,
8013 NULL_TREE
, cp_walk_subtrees
))
8019 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
8023 stmt
= make_node (code
);
8025 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
8027 /* This is really just a place-holder. We'll be decomposing this
8028 again and going through the cp_build_modify_expr path below when
8029 we instantiate the thing. */
8030 TREE_VEC_ELT (initv
, i
)
8031 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
8032 TREE_VEC_ELT (initv
, i
));
8035 TREE_TYPE (stmt
) = void_type_node
;
8036 OMP_FOR_INIT (stmt
) = initv
;
8037 OMP_FOR_COND (stmt
) = condv
;
8038 OMP_FOR_INCR (stmt
) = incrv
;
8039 OMP_FOR_BODY (stmt
) = body
;
8040 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
8041 OMP_FOR_CLAUSES (stmt
) = clauses
;
8043 SET_EXPR_LOCATION (stmt
, locus
);
8044 return add_stmt (stmt
);
8048 orig_declv
= copy_node (declv
);
8050 if (processing_template_decl
)
8051 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
8053 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
8055 decl
= TREE_VEC_ELT (declv
, i
);
8056 init
= TREE_VEC_ELT (initv
, i
);
8057 cond
= TREE_VEC_ELT (condv
, i
);
8058 incr
= TREE_VEC_ELT (incrv
, i
);
8060 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8063 if (init
&& EXPR_HAS_LOCATION (init
))
8064 elocus
= EXPR_LOCATION (init
);
8068 error_at (elocus
, "expected iteration declaration or initialization");
8072 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
8075 TREE_VEC_ELT (orig_incr
, i
) = incr
;
8076 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
8077 TREE_CODE (TREE_OPERAND (incr
, 1)),
8078 TREE_OPERAND (incr
, 2),
8079 tf_warning_or_error
);
8082 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
8084 if (code
== OMP_SIMD
)
8086 error_at (elocus
, "%<#pragma omp simd%> used with class "
8087 "iteration variable %qE", decl
);
8090 if (code
== CILK_FOR
&& i
== 0)
8092 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
8093 initv
, condv
, incrv
, &body
,
8094 &pre_body
, clauses
, &last
,
8100 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
8101 && !TYPE_PTR_P (TREE_TYPE (decl
)))
8103 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
8107 if (!processing_template_decl
)
8109 init
= fold_build_cleanup_point_expr (TREE_TYPE (init
), init
);
8110 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
8111 tf_warning_or_error
);
8114 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
8116 && TREE_SIDE_EFFECTS (cond
)
8117 && COMPARISON_CLASS_P (cond
)
8118 && !processing_template_decl
)
8120 tree t
= TREE_OPERAND (cond
, 0);
8121 if (TREE_SIDE_EFFECTS (t
)
8123 && (TREE_CODE (t
) != NOP_EXPR
8124 || TREE_OPERAND (t
, 0) != decl
))
8125 TREE_OPERAND (cond
, 0)
8126 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8128 t
= TREE_OPERAND (cond
, 1);
8129 if (TREE_SIDE_EFFECTS (t
)
8131 && (TREE_CODE (t
) != NOP_EXPR
8132 || TREE_OPERAND (t
, 0) != decl
))
8133 TREE_OPERAND (cond
, 1)
8134 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8136 if (decl
== error_mark_node
|| init
== error_mark_node
)
8139 TREE_VEC_ELT (declv
, i
) = decl
;
8140 TREE_VEC_ELT (initv
, i
) = init
;
8141 TREE_VEC_ELT (condv
, i
) = cond
;
8142 TREE_VEC_ELT (incrv
, i
) = incr
;
8146 if (IS_EMPTY_STMT (pre_body
))
8149 if (code
== CILK_FOR
&& !processing_template_decl
)
8150 block
= push_stmt_list ();
8152 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
8153 incrv
, body
, pre_body
);
8155 /* Check for iterators appearing in lb, b or incr expressions. */
8156 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
8157 omp_for
= NULL_TREE
;
8159 if (omp_for
== NULL
)
8162 pop_stmt_list (block
);
8168 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
8170 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
), 0);
8171 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
8173 if (TREE_CODE (incr
) != MODIFY_EXPR
)
8176 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
8177 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
8178 && !processing_template_decl
)
8180 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
8181 if (TREE_SIDE_EFFECTS (t
)
8183 && (TREE_CODE (t
) != NOP_EXPR
8184 || TREE_OPERAND (t
, 0) != decl
))
8185 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
8186 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8188 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8189 if (TREE_SIDE_EFFECTS (t
)
8191 && (TREE_CODE (t
) != NOP_EXPR
8192 || TREE_OPERAND (t
, 0) != decl
))
8193 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8194 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8198 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
8200 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8202 /* For simd loops with non-static data member iterators, we could have added
8203 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
8204 step at this point, fill it in. */
8205 if (code
== OMP_SIMD
&& !processing_template_decl
8206 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
8207 for (tree c
= find_omp_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
8208 c
= find_omp_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
8209 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
8211 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
8212 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
8213 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8215 switch (TREE_CODE (incr
))
8217 case PREINCREMENT_EXPR
:
8218 case POSTINCREMENT_EXPR
:
8219 /* c_omp_for_incr_canonicalize_ptr() should have been
8220 called to massage things appropriately. */
8221 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8222 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
8224 case PREDECREMENT_EXPR
:
8225 case POSTDECREMENT_EXPR
:
8226 /* c_omp_for_incr_canonicalize_ptr() should have been
8227 called to massage things appropriately. */
8228 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8229 OMP_CLAUSE_LINEAR_STEP (c
)
8230 = build_int_cst (TREE_TYPE (decl
), -1);
8233 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8234 incr
= TREE_OPERAND (incr
, 1);
8235 switch (TREE_CODE (incr
))
8238 if (TREE_OPERAND (incr
, 1) == decl
)
8239 step
= TREE_OPERAND (incr
, 0);
8241 step
= TREE_OPERAND (incr
, 1);
8244 case POINTER_PLUS_EXPR
:
8245 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8246 step
= TREE_OPERAND (incr
, 1);
8251 stept
= TREE_TYPE (decl
);
8252 if (POINTER_TYPE_P (stept
))
8254 step
= fold_convert (stept
, step
);
8255 if (TREE_CODE (incr
) == MINUS_EXPR
)
8256 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
8257 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
8266 tree omp_par
= make_node (OMP_PARALLEL
);
8267 TREE_TYPE (omp_par
) = void_type_node
;
8268 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
8269 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
8270 TREE_SIDE_EFFECTS (bind
) = 1;
8271 BIND_EXPR_BODY (bind
) = pop_stmt_list (block
);
8272 OMP_PARALLEL_BODY (omp_par
) = bind
;
8273 if (OMP_FOR_PRE_BODY (omp_for
))
8275 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
8276 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
8278 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
8279 decl
= TREE_OPERAND (init
, 0);
8280 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
8281 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8282 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
, *pc
;
8283 clauses
= OMP_FOR_CLAUSES (omp_for
);
8284 OMP_FOR_CLAUSES (omp_for
) = NULL_TREE
;
8285 for (pc
= &clauses
; *pc
; )
8286 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_SCHEDULE
)
8288 gcc_assert (OMP_FOR_CLAUSES (omp_for
) == NULL_TREE
);
8289 OMP_FOR_CLAUSES (omp_for
) = *pc
;
8290 *pc
= OMP_CLAUSE_CHAIN (*pc
);
8291 OMP_CLAUSE_CHAIN (OMP_FOR_CLAUSES (omp_for
)) = NULL_TREE
;
8295 gcc_assert (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_FIRSTPRIVATE
);
8296 pc
= &OMP_CLAUSE_CHAIN (*pc
);
8298 if (TREE_CODE (t
) != INTEGER_CST
)
8300 TREE_OPERAND (cond
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
8301 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8302 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
8303 OMP_CLAUSE_CHAIN (c
) = clauses
;
8306 if (TREE_CODE (incr
) == MODIFY_EXPR
)
8308 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8309 if (TREE_CODE (t
) != INTEGER_CST
)
8311 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8312 = get_temp_regvar (TREE_TYPE (t
), t
);
8313 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8314 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8315 OMP_CLAUSE_CHAIN (c
) = clauses
;
8319 t
= TREE_OPERAND (init
, 1);
8320 if (TREE_CODE (t
) != INTEGER_CST
)
8322 TREE_OPERAND (init
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
8323 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8324 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
8325 OMP_CLAUSE_CHAIN (c
) = clauses
;
8328 if (orig_decl
&& orig_decl
!= decl
)
8330 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8331 OMP_CLAUSE_DECL (c
) = orig_decl
;
8332 OMP_CLAUSE_CHAIN (c
) = clauses
;
8337 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8338 OMP_CLAUSE_DECL (c
) = last
;
8339 OMP_CLAUSE_CHAIN (c
) = clauses
;
8342 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
8343 OMP_CLAUSE_DECL (c
) = decl
;
8344 OMP_CLAUSE_CHAIN (c
) = clauses
;
8346 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
8347 OMP_CLAUSE_OPERAND (c
, 0)
8348 = cilk_for_number_of_iterations (omp_for
);
8349 OMP_CLAUSE_CHAIN (c
) = clauses
;
8350 OMP_PARALLEL_CLAUSES (omp_par
) = finish_omp_clauses (c
, C_ORT_CILK
);
8354 else if (code
== CILK_FOR
&& processing_template_decl
)
8356 tree c
, clauses
= OMP_FOR_CLAUSES (omp_for
);
8357 if (orig_decl
&& orig_decl
!= decl
)
8359 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8360 OMP_CLAUSE_DECL (c
) = orig_decl
;
8361 OMP_CLAUSE_CHAIN (c
) = clauses
;
8366 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8367 OMP_CLAUSE_DECL (c
) = last
;
8368 OMP_CLAUSE_CHAIN (c
) = clauses
;
8371 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8377 finish_omp_atomic (enum tree_code code
, enum tree_code opcode
, tree lhs
,
8378 tree rhs
, tree v
, tree lhs1
, tree rhs1
, bool seq_cst
)
8393 dependent_p
= false;
8396 /* Even in a template, we can detect invalid uses of the atomic
8397 pragma if neither LHS nor RHS is type-dependent. */
8398 if (processing_template_decl
)
8400 dependent_p
= (type_dependent_expression_p (lhs
)
8401 || (rhs
&& type_dependent_expression_p (rhs
))
8402 || (v
&& type_dependent_expression_p (v
))
8403 || (lhs1
&& type_dependent_expression_p (lhs1
))
8404 || (rhs1
&& type_dependent_expression_p (rhs1
)));
8407 lhs
= build_non_dependent_expr (lhs
);
8409 rhs
= build_non_dependent_expr (rhs
);
8411 v
= build_non_dependent_expr (v
);
8413 lhs1
= build_non_dependent_expr (lhs1
);
8415 rhs1
= build_non_dependent_expr (rhs1
);
8420 bool swapped
= false;
8421 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
8423 std::swap (rhs
, rhs1
);
8424 swapped
= !commutative_tree_code (opcode
);
8426 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
8428 if (code
== OMP_ATOMIC
)
8429 error ("%<#pragma omp atomic update%> uses two different "
8430 "expressions for memory");
8432 error ("%<#pragma omp atomic capture%> uses two different "
8433 "expressions for memory");
8436 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
8438 if (code
== OMP_ATOMIC
)
8439 error ("%<#pragma omp atomic update%> uses two different "
8440 "expressions for memory");
8442 error ("%<#pragma omp atomic capture%> uses two different "
8443 "expressions for memory");
8446 stmt
= c_finish_omp_atomic (input_location
, code
, opcode
, lhs
, rhs
,
8447 v
, lhs1
, rhs1
, swapped
, seq_cst
,
8448 processing_template_decl
!= 0);
8449 if (stmt
== error_mark_node
)
8452 if (processing_template_decl
)
8454 if (code
== OMP_ATOMIC_READ
)
8456 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs
),
8457 OMP_ATOMIC_READ
, orig_lhs
);
8458 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8459 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8463 if (opcode
== NOP_EXPR
)
8464 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
8466 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
8468 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
8469 COMPOUND_EXPR
, orig_rhs1
, stmt
);
8470 if (code
!= OMP_ATOMIC
)
8472 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs1
),
8473 code
, orig_lhs1
, stmt
);
8474 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8475 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8478 stmt
= build2 (OMP_ATOMIC
, void_type_node
, integer_zero_node
, stmt
);
8479 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8481 finish_expr_stmt (stmt
);
8485 finish_omp_barrier (void)
8487 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
8488 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8489 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8490 release_tree_vector (vec
);
8491 finish_expr_stmt (stmt
);
8495 finish_omp_flush (void)
8497 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
8498 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8499 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8500 release_tree_vector (vec
);
8501 finish_expr_stmt (stmt
);
8505 finish_omp_taskwait (void)
8507 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
8508 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8509 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8510 release_tree_vector (vec
);
8511 finish_expr_stmt (stmt
);
8515 finish_omp_taskyield (void)
8517 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
8518 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8519 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8520 release_tree_vector (vec
);
8521 finish_expr_stmt (stmt
);
8525 finish_omp_cancel (tree clauses
)
8527 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
8529 if (find_omp_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8531 else if (find_omp_clause (clauses
, OMP_CLAUSE_FOR
))
8533 else if (find_omp_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8535 else if (find_omp_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8539 error ("%<#pragma omp cancel must specify one of "
8540 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8543 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8544 tree ifc
= find_omp_clause (clauses
, OMP_CLAUSE_IF
);
8545 if (ifc
!= NULL_TREE
)
8547 tree type
= TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc
));
8548 ifc
= fold_build2_loc (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
8549 boolean_type_node
, OMP_CLAUSE_IF_EXPR (ifc
),
8550 build_zero_cst (type
));
8553 ifc
= boolean_true_node
;
8554 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
8555 vec
->quick_push (ifc
);
8556 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8557 release_tree_vector (vec
);
8558 finish_expr_stmt (stmt
);
8562 finish_omp_cancellation_point (tree clauses
)
8564 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
8566 if (find_omp_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8568 else if (find_omp_clause (clauses
, OMP_CLAUSE_FOR
))
8570 else if (find_omp_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8572 else if (find_omp_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8576 error ("%<#pragma omp cancellation point must specify one of "
8577 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8580 vec
<tree
, va_gc
> *vec
8581 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
8582 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8583 release_tree_vector (vec
);
8584 finish_expr_stmt (stmt
);
8587 /* Begin a __transaction_atomic or __transaction_relaxed statement.
8588 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
8589 should create an extra compound stmt. */
8592 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
8597 *pcompound
= begin_compound_stmt (0);
8599 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
8601 /* Only add the statement to the function if support enabled. */
8605 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
8606 ? G_("%<__transaction_relaxed%> without "
8607 "transactional memory support enabled")
8608 : G_("%<__transaction_atomic%> without "
8609 "transactional memory support enabled")));
8611 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
8612 TREE_SIDE_EFFECTS (r
) = 1;
8616 /* End a __transaction_atomic or __transaction_relaxed statement.
8617 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
8618 and we should end the compound. If NOEX is non-NULL, we wrap the body in
8619 a MUST_NOT_THROW_EXPR with NOEX as condition. */
8622 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
8624 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
8625 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
8626 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
8627 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
8629 /* noexcept specifications are not allowed for function transactions. */
8630 gcc_assert (!(noex
&& compound_stmt
));
8633 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
8635 protected_set_expr_location
8636 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
8637 TREE_SIDE_EFFECTS (body
) = 1;
8638 TRANSACTION_EXPR_BODY (stmt
) = body
;
8642 finish_compound_stmt (compound_stmt
);
8645 /* Build a __transaction_atomic or __transaction_relaxed expression. If
8646 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
8650 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
8655 expr
= build_must_not_throw_expr (expr
, noex
);
8656 protected_set_expr_location (expr
, loc
);
8657 TREE_SIDE_EFFECTS (expr
) = 1;
8659 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
8660 if (flags
& TM_STMT_ATTR_RELAXED
)
8661 TRANSACTION_EXPR_RELAXED (ret
) = 1;
8662 TREE_SIDE_EFFECTS (ret
) = 1;
8663 SET_EXPR_LOCATION (ret
, loc
);
8668 init_cp_semantics (void)
8672 /* Build a STATIC_ASSERT for a static assertion with the condition
8673 CONDITION and the message text MESSAGE. LOCATION is the location
8674 of the static assertion in the source code. When MEMBER_P, this
8675 static assertion is a member of a class. */
8677 finish_static_assert (tree condition
, tree message
, location_t location
,
8680 if (message
== NULL_TREE
8681 || message
== error_mark_node
8682 || condition
== NULL_TREE
8683 || condition
== error_mark_node
)
8686 if (check_for_bare_parameter_packs (condition
))
8687 condition
= error_mark_node
;
8689 if (type_dependent_expression_p (condition
)
8690 || value_dependent_expression_p (condition
))
8692 /* We're in a template; build a STATIC_ASSERT and put it in
8696 assertion
= make_node (STATIC_ASSERT
);
8697 STATIC_ASSERT_CONDITION (assertion
) = condition
;
8698 STATIC_ASSERT_MESSAGE (assertion
) = message
;
8699 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
8702 maybe_add_class_template_decl_list (current_class_type
,
8706 add_stmt (assertion
);
8711 /* Fold the expression and convert it to a boolean value. */
8712 condition
= instantiate_non_dependent_expr (condition
);
8713 condition
= cp_convert (boolean_type_node
, condition
, tf_warning_or_error
);
8714 condition
= maybe_constant_value (condition
);
8716 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
8717 /* Do nothing; the condition is satisfied. */
8721 location_t saved_loc
= input_location
;
8723 input_location
= location
;
8724 if (TREE_CODE (condition
) == INTEGER_CST
8725 && integer_zerop (condition
))
8727 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
8728 (TREE_TYPE (TREE_TYPE (message
))));
8729 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
8730 /* Report the error. */
8732 error ("static assertion failed");
8734 error ("static assertion failed: %s",
8735 TREE_STRING_POINTER (message
));
8737 else if (condition
&& condition
!= error_mark_node
)
8739 error ("non-constant condition for static assertion");
8740 if (require_potential_rvalue_constant_expression (condition
))
8741 cxx_constant_value (condition
);
8743 input_location
= saved_loc
;
8747 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
8748 suitable for use as a type-specifier.
8750 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
8751 id-expression or a class member access, FALSE when it was parsed as
8752 a full expression. */
8755 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
8756 tsubst_flags_t complain
)
8758 tree type
= NULL_TREE
;
8760 if (!expr
|| error_operand_p (expr
))
8761 return error_mark_node
;
8764 || TREE_CODE (expr
) == TYPE_DECL
8765 || (TREE_CODE (expr
) == BIT_NOT_EXPR
8766 && TYPE_P (TREE_OPERAND (expr
, 0))))
8768 if (complain
& tf_error
)
8769 error ("argument to decltype must be an expression");
8770 return error_mark_node
;
8773 /* Depending on the resolution of DR 1172, we may later need to distinguish
8774 instantiation-dependent but not type-dependent expressions so that, say,
8775 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
8776 if (instantiation_dependent_uneval_expression_p (expr
))
8778 type
= cxx_make_type (DECLTYPE_TYPE
);
8779 DECLTYPE_TYPE_EXPR (type
) = expr
;
8780 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
8781 = id_expression_or_member_access_p
;
8782 SET_TYPE_STRUCTURAL_EQUALITY (type
);
8787 /* The type denoted by decltype(e) is defined as follows: */
8789 expr
= resolve_nondeduced_context (expr
, complain
);
8791 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
8792 return error_mark_node
;
8794 if (type_unknown_p (expr
))
8796 if (complain
& tf_error
)
8797 error ("decltype cannot resolve address of overloaded function");
8798 return error_mark_node
;
8801 /* To get the size of a static data member declared as an array of
8802 unknown bound, we need to instantiate it. */
8804 && VAR_HAD_UNKNOWN_BOUND (expr
)
8805 && DECL_TEMPLATE_INSTANTIATION (expr
))
8806 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
8808 if (id_expression_or_member_access_p
)
8810 /* If e is an id-expression or a class member access (5.2.5
8811 [expr.ref]), decltype(e) is defined as the type of the entity
8812 named by e. If there is no such entity, or e names a set of
8813 overloaded functions, the program is ill-formed. */
8814 if (identifier_p (expr
))
8815 expr
= lookup_name (expr
);
8817 if (INDIRECT_REF_P (expr
))
8818 /* This can happen when the expression is, e.g., "a.b". Just
8819 look at the underlying operand. */
8820 expr
= TREE_OPERAND (expr
, 0);
8822 if (TREE_CODE (expr
) == OFFSET_REF
8823 || TREE_CODE (expr
) == MEMBER_REF
8824 || TREE_CODE (expr
) == SCOPE_REF
)
8825 /* We're only interested in the field itself. If it is a
8826 BASELINK, we will need to see through it in the next
8828 expr
= TREE_OPERAND (expr
, 1);
8830 if (BASELINK_P (expr
))
8831 /* See through BASELINK nodes to the underlying function. */
8832 expr
= BASELINK_FUNCTIONS (expr
);
8834 switch (TREE_CODE (expr
))
8837 if (DECL_BIT_FIELD_TYPE (expr
))
8839 type
= DECL_BIT_FIELD_TYPE (expr
);
8842 /* Fall through for fields that aren't bitfields. */
8849 case TEMPLATE_PARM_INDEX
:
8850 expr
= mark_type_use (expr
);
8851 type
= TREE_TYPE (expr
);
8855 type
= error_mark_node
;
8860 mark_type_use (expr
);
8861 type
= is_bitfield_expr_with_lowered_type (expr
);
8863 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
8871 /* We can get here when the id-expression refers to an
8872 enumerator or non-type template parameter. */
8873 type
= TREE_TYPE (expr
);
8877 /* Handle instantiated template non-type arguments. */
8878 type
= TREE_TYPE (expr
);
8884 /* Within a lambda-expression:
8886 Every occurrence of decltype((x)) where x is a possibly
8887 parenthesized id-expression that names an entity of
8888 automatic storage duration is treated as if x were
8889 transformed into an access to a corresponding data member
8890 of the closure type that would have been declared if x
8891 were a use of the denoted entity. */
8892 if (outer_automatic_var_p (expr
)
8893 && current_function_decl
8894 && LAMBDA_FUNCTION_P (current_function_decl
))
8895 type
= capture_decltype (expr
);
8896 else if (error_operand_p (expr
))
8897 type
= error_mark_node
;
8898 else if (expr
== current_class_ptr
)
8899 /* If the expression is just "this", we want the
8900 cv-unqualified pointer for the "this" type. */
8901 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
8904 /* Otherwise, where T is the type of e, if e is an lvalue,
8905 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
8906 cp_lvalue_kind clk
= lvalue_kind (expr
);
8907 type
= unlowered_expr_type (expr
);
8908 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
8910 /* For vector types, pick a non-opaque variant. */
8911 if (VECTOR_TYPE_P (type
))
8912 type
= strip_typedefs (type
);
8914 if (clk
!= clk_none
&& !(clk
& clk_class
))
8915 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
8922 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
8923 __has_nothrow_copy, depending on assign_p. */
8926 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
8933 ix
= lookup_fnfields_1 (type
, ansi_assopname (NOP_EXPR
));
8936 fns
= (*CLASSTYPE_METHOD_VEC (type
))[ix
];
8938 else if (TYPE_HAS_COPY_CTOR (type
))
8940 /* If construction of the copy constructor was postponed, create
8942 if (CLASSTYPE_LAZY_COPY_CTOR (type
))
8943 lazily_declare_fn (sfk_copy_constructor
, type
);
8944 if (CLASSTYPE_LAZY_MOVE_CTOR (type
))
8945 lazily_declare_fn (sfk_move_constructor
, type
);
8946 fns
= CLASSTYPE_CONSTRUCTORS (type
);
8951 for (; fns
; fns
= OVL_NEXT (fns
))
8953 tree fn
= OVL_CURRENT (fns
);
8957 if (copy_fn_p (fn
) == 0)
8960 else if (copy_fn_p (fn
) <= 0)
8963 maybe_instantiate_noexcept (fn
);
8964 if (!TYPE_NOTHROW_P (TREE_TYPE (fn
)))
8971 /* Actually evaluates the trait. */
8974 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
8976 enum tree_code type_code1
;
8979 type_code1
= TREE_CODE (type1
);
8983 case CPTK_HAS_NOTHROW_ASSIGN
:
8984 type1
= strip_array_types (type1
);
8985 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
8986 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
8987 || (CLASS_TYPE_P (type1
)
8988 && classtype_has_nothrow_assign_or_copy_p (type1
,
8991 case CPTK_HAS_TRIVIAL_ASSIGN
:
8992 /* ??? The standard seems to be missing the "or array of such a class
8993 type" wording for this trait. */
8994 type1
= strip_array_types (type1
);
8995 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
8996 && (trivial_type_p (type1
)
8997 || (CLASS_TYPE_P (type1
)
8998 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
9000 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9001 type1
= strip_array_types (type1
);
9002 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
9003 || (CLASS_TYPE_P (type1
)
9004 && (t
= locate_ctor (type1
))
9005 && (maybe_instantiate_noexcept (t
),
9006 TYPE_NOTHROW_P (TREE_TYPE (t
)))));
9008 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9009 type1
= strip_array_types (type1
);
9010 return (trivial_type_p (type1
)
9011 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
9013 case CPTK_HAS_NOTHROW_COPY
:
9014 type1
= strip_array_types (type1
);
9015 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
9016 || (CLASS_TYPE_P (type1
)
9017 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
9019 case CPTK_HAS_TRIVIAL_COPY
:
9020 /* ??? The standard seems to be missing the "or array of such a class
9021 type" wording for this trait. */
9022 type1
= strip_array_types (type1
);
9023 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9024 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
9026 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9027 type1
= strip_array_types (type1
);
9028 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
9029 || (CLASS_TYPE_P (type1
)
9030 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
9032 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9033 return type_has_virtual_destructor (type1
);
9035 case CPTK_IS_ABSTRACT
:
9036 return (ABSTRACT_CLASS_TYPE_P (type1
));
9038 case CPTK_IS_BASE_OF
:
9039 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9040 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9041 || DERIVED_FROM_P (type1
, type2
)));
9044 return (NON_UNION_CLASS_TYPE_P (type1
));
9047 return (NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
));
9050 return (type_code1
== ENUMERAL_TYPE
);
9053 return (CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
));
9055 case CPTK_IS_LITERAL_TYPE
:
9056 return (literal_type_p (type1
));
9059 return (pod_type_p (type1
));
9061 case CPTK_IS_POLYMORPHIC
:
9062 return (CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
));
9064 case CPTK_IS_SAME_AS
:
9065 return same_type_p (type1
, type2
);
9067 case CPTK_IS_STD_LAYOUT
:
9068 return (std_layout_type_p (type1
));
9070 case CPTK_IS_TRIVIAL
:
9071 return (trivial_type_p (type1
));
9073 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9074 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
9076 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9077 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
9079 case CPTK_IS_TRIVIALLY_COPYABLE
:
9080 return (trivially_copyable_p (type1
));
9083 return (type_code1
== UNION_TYPE
);
9091 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
9092 void, or a complete type, returns true, otherwise false. */
9095 check_trait_type (tree type
)
9097 if (type
== NULL_TREE
)
9100 if (TREE_CODE (type
) == TREE_LIST
)
9101 return (check_trait_type (TREE_VALUE (type
))
9102 && check_trait_type (TREE_CHAIN (type
)));
9104 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
9105 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
9108 if (VOID_TYPE_P (type
))
9111 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
9114 /* Process a trait expression. */
9117 finish_trait_expr (cp_trait_kind kind
, tree type1
, tree type2
)
9119 if (type1
== error_mark_node
9120 || type2
== error_mark_node
)
9121 return error_mark_node
;
9123 if (processing_template_decl
)
9125 tree trait_expr
= make_node (TRAIT_EXPR
);
9126 TREE_TYPE (trait_expr
) = boolean_type_node
;
9127 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
9128 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
9129 TRAIT_EXPR_KIND (trait_expr
) = kind
;
9135 case CPTK_HAS_NOTHROW_ASSIGN
:
9136 case CPTK_HAS_TRIVIAL_ASSIGN
:
9137 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
9138 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
9139 case CPTK_HAS_NOTHROW_COPY
:
9140 case CPTK_HAS_TRIVIAL_COPY
:
9141 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
9142 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
9143 case CPTK_IS_ABSTRACT
:
9146 case CPTK_IS_LITERAL_TYPE
:
9148 case CPTK_IS_POLYMORPHIC
:
9149 case CPTK_IS_STD_LAYOUT
:
9150 case CPTK_IS_TRIVIAL
:
9151 case CPTK_IS_TRIVIALLY_COPYABLE
:
9152 if (!check_trait_type (type1
))
9153 return error_mark_node
;
9156 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
9157 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9158 if (!check_trait_type (type1
)
9159 || !check_trait_type (type2
))
9160 return error_mark_node
;
9163 case CPTK_IS_BASE_OF
:
9164 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9165 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9166 && !complete_type_or_else (type2
, NULL_TREE
))
9167 /* We already issued an error. */
9168 return error_mark_node
;
9174 case CPTK_IS_SAME_AS
:
9181 return (trait_expr_value (kind
, type1
, type2
)
9182 ? boolean_true_node
: boolean_false_node
);
9185 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
9186 which is ignored for C++. */
9189 set_float_const_decimal64 (void)
9194 clear_float_const_decimal64 (void)
9199 float_const_decimal64_p (void)
9205 /* Return true if T designates the implied `this' parameter. */
9208 is_this_parameter (tree t
)
9210 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
9212 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
));
9216 /* Insert the deduced return type for an auto function. */
9219 apply_deduced_return_type (tree fco
, tree return_type
)
9223 if (return_type
== error_mark_node
)
9226 if (LAMBDA_FUNCTION_P (fco
))
9228 tree lambda
= CLASSTYPE_LAMBDA_EXPR (current_class_type
);
9229 LAMBDA_EXPR_RETURN_TYPE (lambda
) = return_type
;
9232 if (DECL_CONV_FN_P (fco
))
9233 DECL_NAME (fco
) = mangle_conv_op_name_for_type (return_type
);
9235 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
9237 result
= DECL_RESULT (fco
);
9238 if (result
== NULL_TREE
)
9240 if (TREE_TYPE (result
) == return_type
)
9243 /* We already have a DECL_RESULT from start_preparsed_function.
9244 Now we need to redo the work it and allocate_struct_function
9245 did to reflect the new type. */
9246 gcc_assert (current_function_decl
== fco
);
9247 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
9248 TYPE_MAIN_VARIANT (return_type
));
9249 DECL_ARTIFICIAL (result
) = 1;
9250 DECL_IGNORED_P (result
) = 1;
9251 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
9254 DECL_RESULT (fco
) = result
;
9256 if (!processing_template_decl
)
9258 if (!VOID_TYPE_P (TREE_TYPE (result
)))
9259 complete_type_or_else (TREE_TYPE (result
), NULL_TREE
);
9260 bool aggr
= aggregate_value_p (result
, fco
);
9261 #ifdef PCC_STATIC_STRUCT_RETURN
9262 cfun
->returns_pcc_struct
= aggr
;
9264 cfun
->returns_struct
= aggr
;
9269 /* DECL is a local variable or parameter from the surrounding scope of a
9270 lambda-expression. Returns the decltype for a use of the capture field
9271 for DECL even if it hasn't been captured yet. */
9274 capture_decltype (tree decl
)
9276 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
9277 /* FIXME do lookup instead of list walk? */
9278 tree cap
= value_member (decl
, LAMBDA_EXPR_CAPTURE_LIST (lam
));
9282 type
= TREE_TYPE (TREE_PURPOSE (cap
));
9284 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
9287 error ("%qD is not captured", decl
);
9288 return error_mark_node
;
9291 type
= TREE_TYPE (decl
);
9292 if (TREE_CODE (type
) == REFERENCE_TYPE
9293 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
9294 type
= TREE_TYPE (type
);
9297 case CPLD_REFERENCE
:
9298 type
= TREE_TYPE (decl
);
9299 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9300 type
= build_reference_type (TREE_TYPE (decl
));
9307 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9309 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
9310 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
9312 type
= build_reference_type (type
);
9317 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
9318 this is a right unary fold. Otherwise it is a left unary fold. */
9321 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
9323 // Build a pack expansion (assuming expr has pack type).
9324 if (!uses_parameter_packs (expr
))
9326 error_at (location_of (expr
), "operand of fold expression has no "
9327 "unexpanded parameter packs");
9328 return error_mark_node
;
9330 tree pack
= make_pack_expansion (expr
);
9332 // Build the fold expression.
9333 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9334 tree fold
= build_min (dir
, unknown_type_node
, code
, pack
);
9335 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9340 finish_left_unary_fold_expr (tree expr
, int op
)
9342 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
9346 finish_right_unary_fold_expr (tree expr
, int op
)
9348 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
9351 /* Build a binary fold expression over EXPR1 and EXPR2. The
9352 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
9353 has an unexpanded parameter pack). */
9356 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
9358 pack
= make_pack_expansion (pack
);
9359 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9360 tree fold
= build_min (dir
, unknown_type_node
, code
, pack
, init
);
9361 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9366 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
9368 // Determine which expr has an unexpanded parameter pack and
9369 // set the pack and initial term.
9370 bool pack1
= uses_parameter_packs (expr1
);
9371 bool pack2
= uses_parameter_packs (expr2
);
9372 if (pack1
&& !pack2
)
9373 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
9374 else if (pack2
&& !pack1
)
9375 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
9379 error ("both arguments in binary fold have unexpanded parameter packs");
9381 error ("no unexpanded parameter packs in binary fold");
9383 return error_mark_node
;
9386 #include "gt-cp-semantics.h"