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-2015 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 (input_location
, 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 (!processing_template_decl
)
678 if (warn_sequence_point
)
679 verify_sequence_points (expr
);
680 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
682 else if (!type_dependent_expression_p (expr
))
683 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
684 tf_warning_or_error
);
686 if (check_for_bare_parameter_packs (expr
))
687 expr
= error_mark_node
;
689 /* Simplification of inner statement expressions, compound exprs,
690 etc can result in us already having an EXPR_STMT. */
691 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
693 if (TREE_CODE (expr
) != EXPR_STMT
)
694 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
695 expr
= maybe_cleanup_point_expr_void (expr
);
705 /* Begin an if-statement. Returns a newly created IF_STMT if
712 scope
= do_pushlevel (sk_cond
);
713 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
714 NULL_TREE
, NULL_TREE
, scope
);
715 begin_cond (&IF_COND (r
));
719 /* Process the COND of an if-statement, which may be given by
723 finish_if_stmt_cond (tree cond
, tree if_stmt
)
725 finish_cond (&IF_COND (if_stmt
), maybe_convert_cond (cond
));
727 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
730 /* Finish the then-clause of an if-statement, which may be given by
734 finish_then_clause (tree if_stmt
)
736 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
740 /* Begin the else-clause of an if-statement. */
743 begin_else_clause (tree if_stmt
)
745 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
748 /* Finish the else-clause of an if-statement, which may be given by
752 finish_else_clause (tree if_stmt
)
754 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
757 /* Finish an if-statement. */
760 finish_if_stmt (tree if_stmt
)
762 tree scope
= IF_SCOPE (if_stmt
);
763 IF_SCOPE (if_stmt
) = NULL
;
764 add_stmt (do_poplevel (scope
));
767 /* Begin a while-statement. Returns a newly created WHILE_STMT if
771 begin_while_stmt (void)
774 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
776 WHILE_BODY (r
) = do_pushlevel (sk_block
);
777 begin_cond (&WHILE_COND (r
));
781 /* Process the COND of a while-statement, which may be given by
785 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
)
787 if (check_no_cilk (cond
,
788 "Cilk array notation cannot be used as a condition for while statement",
789 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
790 cond
= error_mark_node
;
791 cond
= maybe_convert_cond (cond
);
792 finish_cond (&WHILE_COND (while_stmt
), cond
);
793 begin_maybe_infinite_loop (cond
);
794 if (ivdep
&& cond
!= error_mark_node
)
795 WHILE_COND (while_stmt
) = build2 (ANNOTATE_EXPR
,
796 TREE_TYPE (WHILE_COND (while_stmt
)),
797 WHILE_COND (while_stmt
),
798 build_int_cst (integer_type_node
,
799 annot_expr_ivdep_kind
));
800 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
803 /* Finish a while-statement, which may be given by WHILE_STMT. */
806 finish_while_stmt (tree while_stmt
)
808 end_maybe_infinite_loop (boolean_true_node
);
809 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
812 /* Begin a do-statement. Returns a newly created DO_STMT if
818 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
819 begin_maybe_infinite_loop (boolean_true_node
);
821 DO_BODY (r
) = push_stmt_list ();
825 /* Finish the body of a do-statement, which may be given by DO_STMT. */
828 finish_do_body (tree do_stmt
)
830 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
832 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
833 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
835 if (IS_EMPTY_STMT (body
))
836 warning (OPT_Wempty_body
,
837 "suggest explicit braces around empty body in %<do%> statement");
840 /* Finish a do-statement, which may be given by DO_STMT, and whose
841 COND is as indicated. */
844 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
)
846 if (check_no_cilk (cond
,
847 "Cilk array notation cannot be used as a condition for a do-while statement",
848 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
849 cond
= error_mark_node
;
850 cond
= maybe_convert_cond (cond
);
851 end_maybe_infinite_loop (cond
);
852 if (ivdep
&& cond
!= error_mark_node
)
853 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
854 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
));
855 DO_COND (do_stmt
) = cond
;
858 /* Finish a return-statement. The EXPRESSION returned, if any, is as
862 finish_return_stmt (tree expr
)
867 expr
= check_return_expr (expr
, &no_warning
);
869 if (error_operand_p (expr
)
870 || (flag_openmp
&& !check_omp_return ()))
872 /* Suppress -Wreturn-type for this function. */
873 if (warn_return_type
)
874 TREE_NO_WARNING (current_function_decl
) = true;
875 return error_mark_node
;
878 if (!processing_template_decl
)
880 if (warn_sequence_point
)
881 verify_sequence_points (expr
);
883 if (DECL_DESTRUCTOR_P (current_function_decl
)
884 || (DECL_CONSTRUCTOR_P (current_function_decl
)
885 && targetm
.cxx
.cdtor_returns_this ()))
887 /* Similarly, all destructors must run destructors for
888 base-classes before returning. So, all returns in a
889 destructor get sent to the DTOR_LABEL; finish_function emits
890 code to return a value there. */
891 return finish_goto_stmt (cdtor_label
);
895 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
896 TREE_NO_WARNING (r
) |= no_warning
;
897 r
= maybe_cleanup_point_expr_void (r
);
903 /* Begin the scope of a for-statement or a range-for-statement.
904 Both the returned trees are to be used in a call to
905 begin_for_stmt or begin_range_for_stmt. */
908 begin_for_scope (tree
*init
)
910 tree scope
= NULL_TREE
;
911 if (flag_new_for_scope
> 0)
912 scope
= do_pushlevel (sk_for
);
914 if (processing_template_decl
)
915 *init
= push_stmt_list ();
922 /* Begin a for-statement. Returns a new FOR_STMT.
923 SCOPE and INIT should be the return of begin_for_scope,
927 begin_for_stmt (tree scope
, tree init
)
931 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
932 NULL_TREE
, NULL_TREE
, NULL_TREE
);
934 if (scope
== NULL_TREE
)
936 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
938 scope
= begin_for_scope (&init
);
940 FOR_INIT_STMT (r
) = init
;
941 FOR_SCOPE (r
) = scope
;
946 /* Finish the for-init-statement of a for-statement, which may be
947 given by FOR_STMT. */
950 finish_for_init_stmt (tree for_stmt
)
952 if (processing_template_decl
)
953 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
955 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
956 begin_cond (&FOR_COND (for_stmt
));
959 /* Finish the COND of a for-statement, which may be given by
963 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
)
965 if (check_no_cilk (cond
,
966 "Cilk array notation cannot be used in a condition for a for-loop",
967 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
968 cond
= error_mark_node
;
969 cond
= maybe_convert_cond (cond
);
970 finish_cond (&FOR_COND (for_stmt
), cond
);
971 begin_maybe_infinite_loop (cond
);
972 if (ivdep
&& cond
!= error_mark_node
)
973 FOR_COND (for_stmt
) = build2 (ANNOTATE_EXPR
,
974 TREE_TYPE (FOR_COND (for_stmt
)),
976 build_int_cst (integer_type_node
,
977 annot_expr_ivdep_kind
));
978 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
981 /* Finish the increment-EXPRESSION in a for-statement, which may be
982 given by FOR_STMT. */
985 finish_for_expr (tree expr
, tree for_stmt
)
989 /* If EXPR is an overloaded function, issue an error; there is no
990 context available to use to perform overload resolution. */
991 if (type_unknown_p (expr
))
993 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
994 expr
= error_mark_node
;
996 if (!processing_template_decl
)
998 if (warn_sequence_point
)
999 verify_sequence_points (expr
);
1000 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1001 tf_warning_or_error
);
1003 else if (!type_dependent_expression_p (expr
))
1004 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1005 tf_warning_or_error
);
1006 expr
= maybe_cleanup_point_expr_void (expr
);
1007 if (check_for_bare_parameter_packs (expr
))
1008 expr
= error_mark_node
;
1009 FOR_EXPR (for_stmt
) = expr
;
1012 /* Finish the body of a for-statement, which may be given by
1013 FOR_STMT. The increment-EXPR for the loop must be
1015 It can also finish RANGE_FOR_STMT. */
1018 finish_for_stmt (tree for_stmt
)
1020 end_maybe_infinite_loop (boolean_true_node
);
1022 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1023 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1025 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1027 /* Pop the scope for the body of the loop. */
1028 if (flag_new_for_scope
> 0)
1031 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1032 ? &RANGE_FOR_SCOPE (for_stmt
)
1033 : &FOR_SCOPE (for_stmt
));
1036 add_stmt (do_poplevel (scope
));
1040 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1041 SCOPE and INIT should be the return of begin_for_scope,
1043 To finish it call finish_for_stmt(). */
1046 begin_range_for_stmt (tree scope
, tree init
)
1050 begin_maybe_infinite_loop (boolean_false_node
);
1052 r
= build_stmt (input_location
, RANGE_FOR_STMT
,
1053 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1055 if (scope
== NULL_TREE
)
1057 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
1059 scope
= begin_for_scope (&init
);
1062 /* RANGE_FOR_STMTs do not use nor save the init tree, so we
1065 pop_stmt_list (init
);
1066 RANGE_FOR_SCOPE (r
) = scope
;
1071 /* Finish the head of a range-based for statement, which may
1072 be given by RANGE_FOR_STMT. DECL must be the declaration
1073 and EXPR must be the loop expression. */
1076 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1078 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1079 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1080 add_stmt (range_for_stmt
);
1081 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1084 /* Finish a break-statement. */
1087 finish_break_stmt (void)
1089 /* In switch statements break is sometimes stylistically used after
1090 a return statement. This can lead to spurious warnings about
1091 control reaching the end of a non-void function when it is
1092 inlined. Note that we are calling block_may_fallthru with
1093 language specific tree nodes; this works because
1094 block_may_fallthru returns true when given something it does not
1096 if (!block_may_fallthru (cur_stmt_list
))
1098 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1101 /* Finish a continue-statement. */
1104 finish_continue_stmt (void)
1106 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1109 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1113 begin_switch_stmt (void)
1117 scope
= do_pushlevel (sk_cond
);
1118 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1120 begin_cond (&SWITCH_STMT_COND (r
));
1125 /* Finish the cond of a switch-statement. */
1128 finish_switch_cond (tree cond
, tree switch_stmt
)
1130 tree orig_type
= NULL
;
1132 if (check_no_cilk (cond
,
1133 "Cilk array notation cannot be used as a condition for switch statement",
1134 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement"))
1135 cond
= error_mark_node
;
1137 if (!processing_template_decl
)
1139 /* Convert the condition to an integer or enumeration type. */
1140 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1141 if (cond
== NULL_TREE
)
1143 error ("switch quantity not an integer");
1144 cond
= error_mark_node
;
1146 /* We want unlowered type here to handle enum bit-fields. */
1147 orig_type
= unlowered_expr_type (cond
);
1148 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1149 orig_type
= TREE_TYPE (cond
);
1150 if (cond
!= error_mark_node
)
1154 Integral promotions are performed. */
1155 cond
= perform_integral_promotions (cond
);
1156 cond
= maybe_cleanup_point_expr (cond
);
1159 if (check_for_bare_parameter_packs (cond
))
1160 cond
= error_mark_node
;
1161 else if (!processing_template_decl
&& warn_sequence_point
)
1162 verify_sequence_points (cond
);
1164 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1165 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1166 add_stmt (switch_stmt
);
1167 push_switch (switch_stmt
);
1168 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1171 /* Finish the body of a switch-statement, which may be given by
1172 SWITCH_STMT. The COND to switch on is indicated. */
1175 finish_switch_stmt (tree switch_stmt
)
1179 SWITCH_STMT_BODY (switch_stmt
) =
1180 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1183 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1184 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1185 add_stmt (do_poplevel (scope
));
1188 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1192 begin_try_block (void)
1194 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1196 TRY_STMTS (r
) = push_stmt_list ();
1200 /* Likewise, for a function-try-block. The block returned in
1201 *COMPOUND_STMT is an artificial outer scope, containing the
1202 function-try-block. */
1205 begin_function_try_block (tree
*compound_stmt
)
1208 /* This outer scope does not exist in the C++ standard, but we need
1209 a place to put __FUNCTION__ and similar variables. */
1210 *compound_stmt
= begin_compound_stmt (0);
1211 r
= begin_try_block ();
1212 FN_TRY_BLOCK_P (r
) = 1;
1216 /* Finish a try-block, which may be given by TRY_BLOCK. */
1219 finish_try_block (tree try_block
)
1221 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1222 TRY_HANDLERS (try_block
) = push_stmt_list ();
1225 /* Finish the body of a cleanup try-block, which may be given by
1229 finish_cleanup_try_block (tree try_block
)
1231 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1234 /* Finish an implicitly generated try-block, with a cleanup is given
1238 finish_cleanup (tree cleanup
, tree try_block
)
1240 TRY_HANDLERS (try_block
) = cleanup
;
1241 CLEANUP_P (try_block
) = 1;
1244 /* Likewise, for a function-try-block. */
1247 finish_function_try_block (tree try_block
)
1249 finish_try_block (try_block
);
1250 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1251 the try block, but moving it inside. */
1252 in_function_try_handler
= 1;
1255 /* Finish a handler-sequence for a try-block, which may be given by
1259 finish_handler_sequence (tree try_block
)
1261 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1262 check_handlers (TRY_HANDLERS (try_block
));
1265 /* Finish the handler-seq for a function-try-block, given by
1266 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1267 begin_function_try_block. */
1270 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1272 in_function_try_handler
= 0;
1273 finish_handler_sequence (try_block
);
1274 finish_compound_stmt (compound_stmt
);
1277 /* Begin a handler. Returns a HANDLER if appropriate. */
1280 begin_handler (void)
1284 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1287 /* Create a binding level for the eh_info and the exception object
1289 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1294 /* Finish the handler-parameters for a handler, which may be given by
1295 HANDLER. DECL is the declaration for the catch parameter, or NULL
1296 if this is a `catch (...)' clause. */
1299 finish_handler_parms (tree decl
, tree handler
)
1301 tree type
= NULL_TREE
;
1302 if (processing_template_decl
)
1306 decl
= pushdecl (decl
);
1307 decl
= push_template_decl (decl
);
1308 HANDLER_PARMS (handler
) = decl
;
1309 type
= TREE_TYPE (decl
);
1313 type
= expand_start_catch_block (decl
);
1314 HANDLER_TYPE (handler
) = type
;
1317 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1318 the return value from the matching call to finish_handler_parms. */
1321 finish_handler (tree handler
)
1323 if (!processing_template_decl
)
1324 expand_end_catch_block ();
1325 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1328 /* Begin a compound statement. FLAGS contains some bits that control the
1329 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1330 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1331 block of a function. If BCS_TRY_BLOCK is set, this is the block
1332 created on behalf of a TRY statement. Returns a token to be passed to
1333 finish_compound_stmt. */
1336 begin_compound_stmt (unsigned int flags
)
1340 if (flags
& BCS_NO_SCOPE
)
1342 r
= push_stmt_list ();
1343 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1345 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1346 But, if it's a statement-expression with a scopeless block, there's
1347 nothing to keep, and we don't want to accidentally keep a block
1348 *inside* the scopeless block. */
1349 keep_next_level (false);
1353 scope_kind sk
= sk_block
;
1354 if (flags
& BCS_TRY_BLOCK
)
1356 else if (flags
& BCS_TRANSACTION
)
1357 sk
= sk_transaction
;
1358 r
= do_pushlevel (sk
);
1361 /* When processing a template, we need to remember where the braces were,
1362 so that we can set up identical scopes when instantiating the template
1363 later. BIND_EXPR is a handy candidate for this.
1364 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1365 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1366 processing templates. */
1367 if (processing_template_decl
)
1369 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1370 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1371 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1372 TREE_SIDE_EFFECTS (r
) = 1;
1378 /* Finish a compound-statement, which is given by STMT. */
1381 finish_compound_stmt (tree stmt
)
1383 if (TREE_CODE (stmt
) == BIND_EXPR
)
1385 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1386 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1387 discard the BIND_EXPR so it can be merged with the containing
1389 if (TREE_CODE (body
) == STATEMENT_LIST
1390 && STATEMENT_LIST_HEAD (body
) == NULL
1391 && !BIND_EXPR_BODY_BLOCK (stmt
)
1392 && !BIND_EXPR_TRY_BLOCK (stmt
))
1395 BIND_EXPR_BODY (stmt
) = body
;
1397 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1398 stmt
= pop_stmt_list (stmt
);
1401 /* Destroy any ObjC "super" receivers that may have been
1403 objc_clear_super_receiver ();
1405 stmt
= do_poplevel (stmt
);
1408 /* ??? See c_end_compound_stmt wrt statement expressions. */
1412 /* Finish an asm-statement, whose components are a STRING, some
1413 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1414 LABELS. Also note whether the asm-statement should be
1415 considered volatile. */
1418 finish_asm_stmt (int volatile_p
, tree string
, tree output_operands
,
1419 tree input_operands
, tree clobbers
, tree labels
)
1423 int ninputs
= list_length (input_operands
);
1424 int noutputs
= list_length (output_operands
);
1426 if (!processing_template_decl
)
1428 const char *constraint
;
1429 const char **oconstraints
;
1430 bool allows_mem
, allows_reg
, is_inout
;
1434 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1436 string
= resolve_asm_operand_names (string
, output_operands
,
1437 input_operands
, labels
);
1439 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1441 operand
= TREE_VALUE (t
);
1443 /* ??? Really, this should not be here. Users should be using a
1444 proper lvalue, dammit. But there's a long history of using
1445 casts in the output operands. In cases like longlong.h, this
1446 becomes a primitive form of typechecking -- if the cast can be
1447 removed, then the output operand had a type of the proper width;
1448 otherwise we'll get an error. Gross, but ... */
1449 STRIP_NOPS (operand
);
1451 operand
= mark_lvalue_use (operand
);
1453 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1454 operand
= error_mark_node
;
1456 if (operand
!= error_mark_node
1457 && (TREE_READONLY (operand
)
1458 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1459 /* Functions are not modifiable, even though they are
1461 || TREE_CODE (TREE_TYPE (operand
)) == FUNCTION_TYPE
1462 || TREE_CODE (TREE_TYPE (operand
)) == METHOD_TYPE
1463 /* If it's an aggregate and any field is const, then it is
1464 effectively const. */
1465 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1466 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1467 cxx_readonly_error (operand
, lv_asm
);
1469 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1470 oconstraints
[i
] = constraint
;
1472 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1473 &allows_mem
, &allows_reg
, &is_inout
))
1475 /* If the operand is going to end up in memory,
1476 mark it addressable. */
1477 if (!allows_reg
&& !cxx_mark_addressable (operand
))
1478 operand
= error_mark_node
;
1481 operand
= error_mark_node
;
1483 TREE_VALUE (t
) = operand
;
1486 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1488 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1489 bool constraint_parsed
1490 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1491 oconstraints
, &allows_mem
, &allows_reg
);
1492 /* If the operand is going to end up in memory, don't call
1493 decay_conversion. */
1494 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1495 operand
= mark_lvalue_use (TREE_VALUE (t
));
1497 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1499 /* If the type of the operand hasn't been determined (e.g.,
1500 because it involves an overloaded function), then issue
1501 an error message. There's no context available to
1502 resolve the overloading. */
1503 if (TREE_TYPE (operand
) == unknown_type_node
)
1505 error ("type of asm operand %qE could not be determined",
1507 operand
= error_mark_node
;
1510 if (constraint_parsed
)
1512 /* If the operand is going to end up in memory,
1513 mark it addressable. */
1514 if (!allows_reg
&& allows_mem
)
1516 /* Strip the nops as we allow this case. FIXME, this really
1517 should be rejected or made deprecated. */
1518 STRIP_NOPS (operand
);
1519 if (!cxx_mark_addressable (operand
))
1520 operand
= error_mark_node
;
1522 else if (!allows_reg
&& !allows_mem
)
1524 /* If constraint allows neither register nor memory,
1525 try harder to get a constant. */
1526 tree constop
= maybe_constant_value (operand
);
1527 if (TREE_CONSTANT (constop
))
1532 operand
= error_mark_node
;
1534 TREE_VALUE (t
) = operand
;
1538 r
= build_stmt (input_location
, ASM_EXPR
, string
,
1539 output_operands
, input_operands
,
1541 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1542 r
= maybe_cleanup_point_expr_void (r
);
1543 return add_stmt (r
);
1546 /* Finish a label with the indicated NAME. Returns the new label. */
1549 finish_label_stmt (tree name
)
1551 tree decl
= define_label (input_location
, name
);
1553 if (decl
== error_mark_node
)
1554 return error_mark_node
;
1556 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1561 /* Finish a series of declarations for local labels. G++ allows users
1562 to declare "local" labels, i.e., labels with scope. This extension
1563 is useful when writing code involving statement-expressions. */
1566 finish_label_decl (tree name
)
1568 if (!at_function_scope_p ())
1570 error ("__label__ declarations are only allowed in function scopes");
1574 add_decl_expr (declare_local_label (name
));
1577 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1580 finish_decl_cleanup (tree decl
, tree cleanup
)
1582 push_cleanup (decl
, cleanup
, false);
1585 /* If the current scope exits with an exception, run CLEANUP. */
1588 finish_eh_cleanup (tree cleanup
)
1590 push_cleanup (NULL
, cleanup
, true);
1593 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1594 order they were written by the user. Each node is as for
1595 emit_mem_initializers. */
1598 finish_mem_initializers (tree mem_inits
)
1600 /* Reorder the MEM_INITS so that they are in the order they appeared
1601 in the source program. */
1602 mem_inits
= nreverse (mem_inits
);
1604 if (processing_template_decl
)
1608 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1610 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1611 check for bare parameter packs in the TREE_VALUE, because
1612 any parameter packs in the TREE_VALUE have already been
1613 bound as part of the TREE_PURPOSE. See
1614 make_pack_expansion for more information. */
1615 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1616 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1617 TREE_VALUE (mem
) = error_mark_node
;
1620 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1621 CTOR_INITIALIZER
, mem_inits
));
1624 emit_mem_initializers (mem_inits
);
1627 /* Obfuscate EXPR if it looks like an id-expression or member access so
1628 that the call to finish_decltype in do_auto_deduction will give the
1632 force_paren_expr (tree expr
)
1634 /* This is only needed for decltype(auto) in C++14. */
1635 if (cxx_dialect
< cxx14
)
1638 /* If we're in unevaluated context, we can't be deducing a
1639 return/initializer type, so we don't need to mess with this. */
1640 if (cp_unevaluated_operand
)
1643 if (!DECL_P (expr
) && TREE_CODE (expr
) != COMPONENT_REF
1644 && TREE_CODE (expr
) != SCOPE_REF
)
1647 if (TREE_CODE (expr
) == COMPONENT_REF
)
1648 REF_PARENTHESIZED_P (expr
) = true;
1649 else if (type_dependent_expression_p (expr
))
1650 expr
= build1 (PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1651 else if (VAR_P (expr
) && DECL_HARD_REGISTER (expr
))
1652 /* We can't bind a hard register variable to a reference. */;
1655 cp_lvalue_kind kind
= lvalue_kind (expr
);
1656 if ((kind
& ~clk_class
) != clk_none
)
1658 tree type
= unlowered_expr_type (expr
);
1659 bool rval
= !!(kind
& clk_rvalueref
);
1660 type
= cp_build_reference_type (type
, rval
);
1661 /* This inhibits warnings in, eg, cxx_mark_addressable
1663 warning_sentinel
s (extra_warnings
);
1664 expr
= build_static_cast (type
, expr
, tf_error
);
1665 if (expr
!= error_mark_node
)
1666 REF_PARENTHESIZED_P (expr
) = true;
1673 /* Finish a parenthesized expression EXPR. */
1676 finish_parenthesized_expr (tree expr
)
1679 /* This inhibits warnings in c_common_truthvalue_conversion. */
1680 TREE_NO_WARNING (expr
) = 1;
1682 if (TREE_CODE (expr
) == OFFSET_REF
1683 || TREE_CODE (expr
) == SCOPE_REF
)
1684 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1685 enclosed in parentheses. */
1686 PTRMEM_OK_P (expr
) = 0;
1688 if (TREE_CODE (expr
) == STRING_CST
)
1689 PAREN_STRING_LITERAL_P (expr
) = 1;
1691 expr
= force_paren_expr (expr
);
1696 /* Finish a reference to a non-static data member (DECL) that is not
1697 preceded by `.' or `->'. */
1700 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1702 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1703 bool try_omp_private
= !object
&& omp_private_member_map
;
1708 tree scope
= qualifying_scope
;
1709 if (scope
== NULL_TREE
)
1710 scope
= context_for_name_lookup (decl
);
1711 object
= maybe_dummy_object (scope
, NULL
);
1714 object
= maybe_resolve_dummy (object
, true);
1715 if (object
== error_mark_node
)
1716 return error_mark_node
;
1718 /* DR 613/850: Can use non-static data members without an associated
1719 object in sizeof/decltype/alignof. */
1720 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
1721 && (!processing_template_decl
|| !current_class_ref
))
1723 if (current_function_decl
1724 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1725 error ("invalid use of member %qD in static member function", decl
);
1727 error ("invalid use of non-static data member %qD", decl
);
1728 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
1730 return error_mark_node
;
1733 if (current_class_ptr
)
1734 TREE_USED (current_class_ptr
) = 1;
1735 if (processing_template_decl
&& !qualifying_scope
)
1737 tree type
= TREE_TYPE (decl
);
1739 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1740 /* Quals on the object don't matter. */;
1741 else if (PACK_EXPANSION_P (type
))
1742 /* Don't bother trying to represent this. */
1746 /* Set the cv qualifiers. */
1747 int quals
= cp_type_quals (TREE_TYPE (object
));
1749 if (DECL_MUTABLE_P (decl
))
1750 quals
&= ~TYPE_QUAL_CONST
;
1752 quals
|= cp_type_quals (TREE_TYPE (decl
));
1753 type
= cp_build_qualified_type (type
, quals
);
1756 ret
= (convert_from_reference
1757 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
1759 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1760 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1762 else if (processing_template_decl
)
1763 ret
= build_qualified_name (TREE_TYPE (decl
),
1766 /*template_p=*/false);
1769 tree access_type
= TREE_TYPE (object
);
1771 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
1772 decl
, tf_warning_or_error
);
1774 /* If the data member was named `C::M', convert `*this' to `C'
1776 if (qualifying_scope
)
1778 tree binfo
= NULL_TREE
;
1779 object
= build_scoped_ref (object
, qualifying_scope
,
1783 ret
= build_class_member_access_expr (object
, decl
,
1784 /*access_path=*/NULL_TREE
,
1785 /*preserve_reference=*/false,
1786 tf_warning_or_error
);
1788 if (try_omp_private
)
1790 tree
*v
= omp_private_member_map
->get (decl
);
1792 ret
= convert_from_reference (*v
);
1797 /* If we are currently parsing a template and we encountered a typedef
1798 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1799 adds the typedef to a list tied to the current template.
1800 At template instantiation time, that list is walked and access check
1801 performed for each typedef.
1802 LOCATION is the location of the usage point of TYPEDEF_DECL. */
1805 add_typedef_to_current_template_for_access_check (tree typedef_decl
,
1807 location_t location
)
1809 tree template_info
= NULL
;
1810 tree cs
= current_scope ();
1812 if (!is_typedef_decl (typedef_decl
)
1814 || !CLASS_TYPE_P (context
)
1818 if (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
)
1819 template_info
= get_template_info (cs
);
1822 && TI_TEMPLATE (template_info
)
1823 && !currently_open_class (context
))
1824 append_type_to_template_for_access_check (cs
, typedef_decl
,
1828 /* DECL was the declaration to which a qualified-id resolved. Issue
1829 an error message if it is not accessible. If OBJECT_TYPE is
1830 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1831 type of `*x', or `x', respectively. If the DECL was named as
1832 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1835 check_accessibility_of_qualified_id (tree decl
,
1837 tree nested_name_specifier
)
1840 tree qualifying_type
= NULL_TREE
;
1842 /* If we are parsing a template declaration and if decl is a typedef,
1843 add it to a list tied to the template.
1844 At template instantiation time, that list will be walked and
1845 access check performed. */
1846 add_typedef_to_current_template_for_access_check (decl
,
1847 nested_name_specifier
1848 ? nested_name_specifier
1849 : DECL_CONTEXT (decl
),
1852 /* If we're not checking, return immediately. */
1853 if (deferred_access_no_check
)
1856 /* Determine the SCOPE of DECL. */
1857 scope
= context_for_name_lookup (decl
);
1858 /* If the SCOPE is not a type, then DECL is not a member. */
1859 if (!TYPE_P (scope
))
1861 /* Compute the scope through which DECL is being accessed. */
1863 /* OBJECT_TYPE might not be a class type; consider:
1865 class A { typedef int I; };
1869 In this case, we will have "A::I" as the DECL, but "I" as the
1871 && CLASS_TYPE_P (object_type
)
1872 && DERIVED_FROM_P (scope
, object_type
))
1873 /* If we are processing a `->' or `.' expression, use the type of the
1875 qualifying_type
= object_type
;
1876 else if (nested_name_specifier
)
1878 /* If the reference is to a non-static member of the
1879 current class, treat it as if it were referenced through
1882 if (DECL_NONSTATIC_MEMBER_P (decl
)
1883 && current_class_ptr
1884 && DERIVED_FROM_P (scope
, ct
= current_nonlambda_class_type ()))
1885 qualifying_type
= ct
;
1886 /* Otherwise, use the type indicated by the
1887 nested-name-specifier. */
1889 qualifying_type
= nested_name_specifier
;
1892 /* Otherwise, the name must be from the current class or one of
1894 qualifying_type
= currently_open_derived_class (scope
);
1897 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
1898 or similar in a default argument value. */
1899 && CLASS_TYPE_P (qualifying_type
)
1900 && !dependent_type_p (qualifying_type
))
1901 perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
1902 decl
, tf_warning_or_error
);
1905 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
1906 class named to the left of the "::" operator. DONE is true if this
1907 expression is a complete postfix-expression; it is false if this
1908 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
1909 iff this expression is the operand of '&'. TEMPLATE_P is true iff
1910 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
1911 is true iff this qualified name appears as a template argument. */
1914 finish_qualified_id_expr (tree qualifying_class
,
1919 bool template_arg_p
,
1920 tsubst_flags_t complain
)
1922 gcc_assert (TYPE_P (qualifying_class
));
1924 if (error_operand_p (expr
))
1925 return error_mark_node
;
1927 if ((DECL_P (expr
) || BASELINK_P (expr
))
1928 && !mark_used (expr
, complain
))
1929 return error_mark_node
;
1932 check_template_keyword (expr
);
1934 /* If EXPR occurs as the operand of '&', use special handling that
1935 permits a pointer-to-member. */
1936 if (address_p
&& done
)
1938 if (TREE_CODE (expr
) == SCOPE_REF
)
1939 expr
= TREE_OPERAND (expr
, 1);
1940 expr
= build_offset_ref (qualifying_class
, expr
,
1941 /*address_p=*/true, complain
);
1945 /* No need to check access within an enum. */
1946 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
)
1949 /* Within the scope of a class, turn references to non-static
1950 members into expression of the form "this->...". */
1952 /* But, within a template argument, we do not want make the
1953 transformation, as there is no "this" pointer. */
1955 else if (TREE_CODE (expr
) == FIELD_DECL
)
1957 push_deferring_access_checks (dk_no_check
);
1958 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
1960 pop_deferring_access_checks ();
1962 else if (BASELINK_P (expr
) && !processing_template_decl
)
1964 /* See if any of the functions are non-static members. */
1965 /* If so, the expression may be relative to 'this'. */
1966 if (!shared_member_p (expr
)
1967 && current_class_ptr
1968 && DERIVED_FROM_P (qualifying_class
,
1969 current_nonlambda_class_type ()))
1970 expr
= (build_class_member_access_expr
1971 (maybe_dummy_object (qualifying_class
, NULL
),
1973 BASELINK_ACCESS_BINFO (expr
),
1974 /*preserve_reference=*/false,
1977 /* The expression is a qualified name whose address is not
1979 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
1982 else if (BASELINK_P (expr
))
1986 /* In a template, return a SCOPE_REF for most qualified-ids
1987 so that we can check access at instantiation time. But if
1988 we're looking at a member of the current instantiation, we
1989 know we have access and building up the SCOPE_REF confuses
1990 non-type template argument handling. */
1991 if (processing_template_decl
1992 && !currently_open_class (qualifying_class
))
1993 expr
= build_qualified_name (TREE_TYPE (expr
),
1994 qualifying_class
, expr
,
1997 expr
= convert_from_reference (expr
);
2003 /* Begin a statement-expression. The value returned must be passed to
2004 finish_stmt_expr. */
2007 begin_stmt_expr (void)
2009 return push_stmt_list ();
2012 /* Process the final expression of a statement expression. EXPR can be
2013 NULL, if the final expression is empty. Return a STATEMENT_LIST
2014 containing all the statements in the statement-expression, or
2015 ERROR_MARK_NODE if there was an error. */
2018 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2020 if (error_operand_p (expr
))
2022 /* The type of the statement-expression is the type of the last
2024 TREE_TYPE (stmt_expr
) = error_mark_node
;
2025 return error_mark_node
;
2028 /* If the last statement does not have "void" type, then the value
2029 of the last statement is the value of the entire expression. */
2032 tree type
= TREE_TYPE (expr
);
2034 if (processing_template_decl
)
2036 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2037 expr
= add_stmt (expr
);
2038 /* Mark the last statement so that we can recognize it as such at
2039 template-instantiation time. */
2040 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2042 else if (VOID_TYPE_P (type
))
2044 /* Just treat this like an ordinary statement. */
2045 expr
= finish_expr_stmt (expr
);
2049 /* It actually has a value we need to deal with. First, force it
2050 to be an rvalue so that we won't need to build up a copy
2051 constructor call later when we try to assign it to something. */
2052 expr
= force_rvalue (expr
, tf_warning_or_error
);
2053 if (error_operand_p (expr
))
2054 return error_mark_node
;
2056 /* Update for array-to-pointer decay. */
2057 type
= TREE_TYPE (expr
);
2059 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2060 normal statement, but don't convert to void or actually add
2062 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2063 expr
= maybe_cleanup_point_expr (expr
);
2067 /* The type of the statement-expression is the type of the last
2069 TREE_TYPE (stmt_expr
) = type
;
2075 /* Finish a statement-expression. EXPR should be the value returned
2076 by the previous begin_stmt_expr. Returns an expression
2077 representing the statement-expression. */
2080 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2085 if (error_operand_p (stmt_expr
))
2087 pop_stmt_list (stmt_expr
);
2088 return error_mark_node
;
2091 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2093 type
= TREE_TYPE (stmt_expr
);
2094 result
= pop_stmt_list (stmt_expr
);
2095 TREE_TYPE (result
) = type
;
2097 if (processing_template_decl
)
2099 result
= build_min (STMT_EXPR
, type
, result
);
2100 TREE_SIDE_EFFECTS (result
) = 1;
2101 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2103 else if (CLASS_TYPE_P (type
))
2105 /* Wrap the statement-expression in a TARGET_EXPR so that the
2106 temporary object created by the final expression is destroyed at
2107 the end of the full-expression containing the
2108 statement-expression. */
2109 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2115 /* Returns the expression which provides the value of STMT_EXPR. */
2118 stmt_expr_value_expr (tree stmt_expr
)
2120 tree t
= STMT_EXPR_STMT (stmt_expr
);
2122 if (TREE_CODE (t
) == BIND_EXPR
)
2123 t
= BIND_EXPR_BODY (t
);
2125 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2126 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2128 if (TREE_CODE (t
) == EXPR_STMT
)
2129 t
= EXPR_STMT_EXPR (t
);
2134 /* Return TRUE iff EXPR_STMT is an empty list of
2135 expression statements. */
2138 empty_expr_stmt_p (tree expr_stmt
)
2140 tree body
= NULL_TREE
;
2142 if (expr_stmt
== void_node
)
2147 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2148 body
= EXPR_STMT_EXPR (expr_stmt
);
2149 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2155 if (TREE_CODE (body
) == STATEMENT_LIST
)
2156 return tsi_end_p (tsi_start (body
));
2158 return empty_expr_stmt_p (body
);
2163 /* Perform Koenig lookup. FN is the postfix-expression representing
2164 the function (or functions) to call; ARGS are the arguments to the
2165 call. Returns the functions to be considered by overload resolution. */
2168 perform_koenig_lookup (tree fn
, vec
<tree
, va_gc
> *args
,
2169 tsubst_flags_t complain
)
2171 tree identifier
= NULL_TREE
;
2172 tree functions
= NULL_TREE
;
2173 tree tmpl_args
= NULL_TREE
;
2174 bool template_id
= false;
2176 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2178 /* Use a separate flag to handle null args. */
2180 tmpl_args
= TREE_OPERAND (fn
, 1);
2181 fn
= TREE_OPERAND (fn
, 0);
2184 /* Find the name of the overloaded function. */
2185 if (identifier_p (fn
))
2187 else if (is_overloaded_fn (fn
))
2190 identifier
= DECL_NAME (get_first_fn (functions
));
2192 else if (DECL_P (fn
))
2195 identifier
= DECL_NAME (fn
);
2198 /* A call to a namespace-scope function using an unqualified name.
2200 Do Koenig lookup -- unless any of the arguments are
2202 if (!any_type_dependent_arguments_p (args
)
2203 && !any_dependent_template_arguments_p (tmpl_args
))
2205 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2208 /* The unqualified name could not be resolved. */
2210 fn
= unqualified_fn_lookup_error (identifier
);
2216 if (fn
&& template_id
)
2217 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2222 /* Generate an expression for `FN (ARGS)'. This may change the
2225 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2226 as a virtual call, even if FN is virtual. (This flag is set when
2227 encountering an expression where the function name is explicitly
2228 qualified. For example a call to `X::f' never generates a virtual
2231 Returns code for the call. */
2234 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2235 bool koenig_p
, tsubst_flags_t complain
)
2239 vec
<tree
, va_gc
> *orig_args
= NULL
;
2241 if (fn
== error_mark_node
)
2242 return error_mark_node
;
2244 gcc_assert (!TYPE_P (fn
));
2248 if (processing_template_decl
)
2250 /* If the call expression is dependent, build a CALL_EXPR node
2251 with no type; type_dependent_expression_p recognizes
2252 expressions with no type as being dependent. */
2253 if (type_dependent_expression_p (fn
)
2254 || any_type_dependent_arguments_p (*args
)
2255 /* For a non-static member function that doesn't have an
2256 explicit object argument, we need to specifically
2257 test the type dependency of the "this" pointer because it
2258 is not included in *ARGS even though it is considered to
2259 be part of the list of arguments. Note that this is
2260 related to CWG issues 515 and 1005. */
2261 || (TREE_CODE (fn
) != COMPONENT_REF
2262 && non_static_member_function_p (fn
)
2263 && current_class_ref
2264 && type_dependent_expression_p (current_class_ref
)))
2266 result
= build_nt_call_vec (fn
, *args
);
2267 SET_EXPR_LOCATION (result
, EXPR_LOC_OR_LOC (fn
, input_location
));
2268 KOENIG_LOOKUP_P (result
) = koenig_p
;
2273 tree fndecl
= OVL_CURRENT (fn
);
2274 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2275 || !TREE_THIS_VOLATILE (fndecl
))
2281 current_function_returns_abnormally
= 1;
2285 orig_args
= make_tree_vector_copy (*args
);
2286 if (!BASELINK_P (fn
)
2287 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2288 && TREE_TYPE (fn
) != unknown_type_node
)
2289 fn
= build_non_dependent_expr (fn
);
2290 make_args_non_dependent (*args
);
2293 if (TREE_CODE (fn
) == COMPONENT_REF
)
2295 tree member
= TREE_OPERAND (fn
, 1);
2296 if (BASELINK_P (member
))
2298 tree object
= TREE_OPERAND (fn
, 0);
2299 return build_new_method_call (object
, member
,
2302 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2309 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2310 if (TREE_CODE (fn
) == ADDR_EXPR
2311 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2312 fn
= TREE_OPERAND (fn
, 0);
2314 if (is_overloaded_fn (fn
))
2315 fn
= baselink_for_fns (fn
);
2318 if (BASELINK_P (fn
))
2322 /* A call to a member function. From [over.call.func]:
2324 If the keyword this is in scope and refers to the class of
2325 that member function, or a derived class thereof, then the
2326 function call is transformed into a qualified function call
2327 using (*this) as the postfix-expression to the left of the
2328 . operator.... [Otherwise] a contrived object of type T
2329 becomes the implied object argument.
2333 struct A { void f(); };
2334 struct B : public A {};
2335 struct C : public A { void g() { B::f(); }};
2337 "the class of that member function" refers to `A'. But 11.2
2338 [class.access.base] says that we need to convert 'this' to B* as
2339 part of the access, so we pass 'B' to maybe_dummy_object. */
2341 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2344 if (processing_template_decl
)
2346 if (type_dependent_expression_p (object
))
2348 tree ret
= build_nt_call_vec (orig_fn
, orig_args
);
2349 release_tree_vector (orig_args
);
2352 object
= build_non_dependent_expr (object
);
2355 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2357 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2362 else if (is_overloaded_fn (fn
))
2364 /* If the function is an overloaded builtin, resolve it. */
2365 if (TREE_CODE (fn
) == FUNCTION_DECL
2366 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2367 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2368 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2372 if (warn_sizeof_pointer_memaccess
2373 && (complain
& tf_warning
)
2374 && !vec_safe_is_empty (*args
)
2375 && !processing_template_decl
)
2377 location_t sizeof_arg_loc
[3];
2380 for (i
= 0; i
< 3; i
++)
2384 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2385 sizeof_arg
[i
] = NULL_TREE
;
2386 if (i
>= (*args
)->length ())
2389 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2391 if (SIZEOF_EXPR_TYPE_P (t
))
2392 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2394 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2395 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2397 sizeof_pointer_memaccess_warning
2398 (sizeof_arg_loc
, fn
, *args
,
2399 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2402 /* A call to a namespace-scope function. */
2403 result
= build_new_function_call (fn
, args
, koenig_p
, complain
);
2406 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2408 if (!vec_safe_is_empty (*args
))
2409 error ("arguments to destructor are not allowed");
2410 /* Mark the pseudo-destructor call as having side-effects so
2411 that we do not issue warnings about its use. */
2412 result
= build1 (NOP_EXPR
,
2414 TREE_OPERAND (fn
, 0));
2415 TREE_SIDE_EFFECTS (result
) = 1;
2417 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2418 /* If the "function" is really an object of class type, it might
2419 have an overloaded `operator ()'. */
2420 result
= build_op_call (fn
, args
, complain
);
2423 /* A call where the function is unknown. */
2424 result
= cp_build_function_call_vec (fn
, args
, complain
);
2426 if (processing_template_decl
&& result
!= error_mark_node
)
2428 if (INDIRECT_REF_P (result
))
2429 result
= TREE_OPERAND (result
, 0);
2430 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2431 SET_EXPR_LOCATION (result
, input_location
);
2432 KOENIG_LOOKUP_P (result
) = koenig_p
;
2433 release_tree_vector (orig_args
);
2434 result
= convert_from_reference (result
);
2439 /* Free garbage OVERLOADs from arg-dependent lookup. */
2440 tree next
= NULL_TREE
;
2442 fn
&& TREE_CODE (fn
) == OVERLOAD
&& OVL_ARG_DEPENDENT (fn
);
2445 if (processing_template_decl
)
2446 /* In a template, we'll re-use them at instantiation time. */
2447 OVL_ARG_DEPENDENT (fn
) = false;
2450 next
= OVL_CHAIN (fn
);
2459 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2460 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2461 POSTDECREMENT_EXPR.) */
2464 finish_increment_expr (tree expr
, enum tree_code code
)
2466 return build_x_unary_op (input_location
, code
, expr
, tf_warning_or_error
);
2469 /* Finish a use of `this'. Returns an expression for `this'. */
2472 finish_this_expr (void)
2474 tree result
= NULL_TREE
;
2476 if (current_class_ptr
)
2478 tree type
= TREE_TYPE (current_class_ref
);
2480 /* In a lambda expression, 'this' refers to the captured 'this'. */
2481 if (LAMBDA_TYPE_P (type
))
2482 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2484 result
= current_class_ptr
;
2488 /* The keyword 'this' is a prvalue expression. */
2489 return rvalue (result
);
2491 tree fn
= current_nonlambda_function ();
2492 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2493 error ("%<this%> is unavailable for static member functions");
2495 error ("invalid use of %<this%> in non-member function");
2497 error ("invalid use of %<this%> at top level");
2498 return error_mark_node
;
2501 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2502 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2503 the TYPE for the type given. If SCOPE is non-NULL, the expression
2504 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2507 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2510 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2511 return error_mark_node
;
2513 gcc_assert (TYPE_P (destructor
));
2515 if (!processing_template_decl
)
2517 if (scope
== error_mark_node
)
2519 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2520 return error_mark_node
;
2522 if (is_auto (destructor
))
2523 destructor
= TREE_TYPE (object
);
2524 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2527 "qualified type %qT does not match destructor name ~%qT",
2529 return error_mark_node
;
2533 /* [expr.pseudo] says both:
2535 The type designated by the pseudo-destructor-name shall be
2536 the same as the object type.
2540 The cv-unqualified versions of the object type and of the
2541 type designated by the pseudo-destructor-name shall be the
2544 We implement the more generous second sentence, since that is
2545 what most other compilers do. */
2546 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2549 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2550 return error_mark_node
;
2554 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, void_type_node
, object
,
2558 /* Finish an expression of the form CODE EXPR. */
2561 finish_unary_op_expr (location_t loc
, enum tree_code code
, tree expr
,
2562 tsubst_flags_t complain
)
2564 tree result
= build_x_unary_op (loc
, code
, expr
, complain
);
2565 tree result_ovl
, expr_ovl
;
2567 if (!(complain
& tf_warning
))
2570 result_ovl
= result
;
2573 if (!processing_template_decl
)
2574 expr_ovl
= cp_fully_fold (expr_ovl
);
2576 if (!CONSTANT_CLASS_P (expr_ovl
)
2577 || TREE_OVERFLOW_P (expr_ovl
))
2580 if (!processing_template_decl
)
2581 result_ovl
= cp_fully_fold (result_ovl
);
2583 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
2584 overflow_warning (input_location
, result_ovl
);
2589 /* Finish a compound-literal expression. TYPE is the type to which
2590 the CONSTRUCTOR in COMPOUND_LITERAL is being cast. */
2593 finish_compound_literal (tree type
, tree compound_literal
,
2594 tsubst_flags_t complain
)
2596 if (type
== error_mark_node
)
2597 return error_mark_node
;
2599 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2602 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2604 return cp_build_c_cast (type
, compound_literal
, complain
);
2607 if (!TYPE_OBJ_P (type
))
2609 if (complain
& tf_error
)
2610 error ("compound literal of non-object type %qT", type
);
2611 return error_mark_node
;
2614 if (processing_template_decl
)
2616 TREE_TYPE (compound_literal
) = type
;
2617 /* Mark the expression as a compound literal. */
2618 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
2619 return compound_literal
;
2622 type
= complete_type (type
);
2624 if (TYPE_NON_AGGREGATE_CLASS (type
))
2626 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2627 everywhere that deals with function arguments would be a pain, so
2628 just wrap it in a TREE_LIST. The parser set a flag so we know
2629 that it came from T{} rather than T({}). */
2630 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2631 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2632 return build_functional_cast (type
, compound_literal
, complain
);
2635 if (TREE_CODE (type
) == ARRAY_TYPE
2636 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2637 return error_mark_node
;
2638 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2639 if (SCALAR_TYPE_P (type
)
2640 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
)
2641 && !check_narrowing (type
, compound_literal
, complain
))
2642 return error_mark_node
;
2643 if (TREE_CODE (type
) == ARRAY_TYPE
2644 && TYPE_DOMAIN (type
) == NULL_TREE
)
2646 cp_complete_array_type_or_error (&type
, compound_literal
,
2648 if (type
== error_mark_node
)
2649 return error_mark_node
;
2651 compound_literal
= digest_init (type
, compound_literal
, complain
);
2652 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
2653 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
2654 /* Put static/constant array temporaries in static variables, but always
2655 represent class temporaries with TARGET_EXPR so we elide copies. */
2656 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
2657 && TREE_CODE (type
) == ARRAY_TYPE
2658 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
2659 && initializer_constant_valid_p (compound_literal
, type
))
2661 tree decl
= create_temporary_var (type
);
2662 DECL_INITIAL (decl
) = compound_literal
;
2663 TREE_STATIC (decl
) = 1;
2664 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
2666 /* 5.19 says that a constant expression can include an
2667 lvalue-rvalue conversion applied to "a glvalue of literal type
2668 that refers to a non-volatile temporary object initialized
2669 with a constant expression". Rather than try to communicate
2670 that this VAR_DECL is a temporary, just mark it constexpr. */
2671 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
2672 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
2673 TREE_CONSTANT (decl
) = true;
2675 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
2676 decl
= pushdecl_top_level (decl
);
2677 DECL_NAME (decl
) = make_anon_name ();
2678 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
2679 /* Make sure the destructor is callable. */
2680 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
2681 if (clean
== error_mark_node
)
2682 return error_mark_node
;
2686 return get_target_expr_sfinae (compound_literal
, complain
);
2689 /* Return the declaration for the function-name variable indicated by
2693 finish_fname (tree id
)
2697 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
2698 if (processing_template_decl
&& current_function_decl
2699 && decl
!= error_mark_node
)
2700 decl
= DECL_NAME (decl
);
2704 /* Finish a translation unit. */
2707 finish_translation_unit (void)
2709 /* In case there were missing closebraces,
2710 get us back to the global binding level. */
2712 while (current_namespace
!= global_namespace
)
2715 /* Do file scope __FUNCTION__ et al. */
2716 finish_fname_decls ();
2719 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2720 Returns the parameter. */
2723 finish_template_type_parm (tree aggr
, tree identifier
)
2725 if (aggr
!= class_type_node
)
2727 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
2728 aggr
= class_type_node
;
2731 return build_tree_list (aggr
, identifier
);
2734 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2735 Returns the parameter. */
2738 finish_template_template_parm (tree aggr
, tree identifier
)
2740 tree decl
= build_decl (input_location
,
2741 TYPE_DECL
, identifier
, NULL_TREE
);
2743 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
2744 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
2745 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
2746 DECL_ARTIFICIAL (decl
) = 1;
2748 // Associate the constraints with the underlying declaration,
2749 // not the template.
2750 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
2751 tree constr
= build_constraints (reqs
, NULL_TREE
);
2752 set_constraints (decl
, constr
);
2754 end_template_decl ();
2756 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
2758 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
2759 /*is_primary=*/true, /*is_partial=*/false,
2762 return finish_template_type_parm (aggr
, tmpl
);
2765 /* ARGUMENT is the default-argument value for a template template
2766 parameter. If ARGUMENT is invalid, issue error messages and return
2767 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2770 check_template_template_default_arg (tree argument
)
2772 if (TREE_CODE (argument
) != TEMPLATE_DECL
2773 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
2774 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
2776 if (TREE_CODE (argument
) == TYPE_DECL
)
2777 error ("invalid use of type %qT as a default value for a template "
2778 "template-parameter", TREE_TYPE (argument
));
2780 error ("invalid default argument for a template template parameter");
2781 return error_mark_node
;
2787 /* Begin a class definition, as indicated by T. */
2790 begin_class_definition (tree t
)
2792 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
2793 return error_mark_node
;
2795 if (processing_template_parmlist
)
2797 error ("definition of %q#T inside template parameter list", t
);
2798 return error_mark_node
;
2801 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
2802 are passed the same as decimal scalar types. */
2803 if (TREE_CODE (t
) == RECORD_TYPE
2804 && !processing_template_decl
)
2806 tree ns
= TYPE_CONTEXT (t
);
2807 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
2808 && DECL_CONTEXT (ns
) == std_node
2810 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns
)), "decimal"))
2812 const char *n
= TYPE_NAME_STRING (t
);
2813 if ((strcmp (n
, "decimal32") == 0)
2814 || (strcmp (n
, "decimal64") == 0)
2815 || (strcmp (n
, "decimal128") == 0))
2816 TYPE_TRANSPARENT_AGGR (t
) = 1;
2820 /* A non-implicit typename comes from code like:
2822 template <typename T> struct A {
2823 template <typename U> struct A<T>::B ...
2825 This is erroneous. */
2826 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
2828 error ("invalid definition of qualified type %qT", t
);
2829 t
= error_mark_node
;
2832 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
2834 t
= make_class_type (RECORD_TYPE
);
2835 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
2838 if (TYPE_BEING_DEFINED (t
))
2840 t
= make_class_type (TREE_CODE (t
));
2841 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
2843 maybe_process_partial_specialization (t
);
2845 TYPE_BEING_DEFINED (t
) = 1;
2846 class_binding_level
->defining_class_p
= 1;
2848 if (flag_pack_struct
)
2851 TYPE_PACKED (t
) = 1;
2852 /* Even though the type is being defined for the first time
2853 here, there might have been a forward declaration, so there
2854 might be cv-qualified variants of T. */
2855 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
2856 TYPE_PACKED (v
) = 1;
2858 /* Reset the interface data, at the earliest possible
2859 moment, as it might have been set via a class foo;
2861 if (! TYPE_ANONYMOUS_P (t
))
2863 struct c_fileinfo
*finfo
= \
2864 get_fileinfo (LOCATION_FILE (input_location
));
2865 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
2866 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2867 (t
, finfo
->interface_unknown
);
2869 reset_specialization();
2871 /* Make a declaration for this class in its own scope. */
2872 build_self_reference ();
2877 /* Finish the member declaration given by DECL. */
2880 finish_member_declaration (tree decl
)
2882 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
2885 if (decl
== void_type_node
)
2886 /* The COMPONENT was a friend, not a member, and so there's
2887 nothing for us to do. */
2890 /* We should see only one DECL at a time. */
2891 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
2893 /* Set up access control for DECL. */
2895 = (current_access_specifier
== access_private_node
);
2896 TREE_PROTECTED (decl
)
2897 = (current_access_specifier
== access_protected_node
);
2898 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
2900 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
2901 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
2904 /* Mark the DECL as a member of the current class, unless it's
2905 a member of an enumeration. */
2906 if (TREE_CODE (decl
) != CONST_DECL
)
2907 DECL_CONTEXT (decl
) = current_class_type
;
2909 /* Check for bare parameter packs in the member variable declaration. */
2910 if (TREE_CODE (decl
) == FIELD_DECL
)
2912 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
2913 TREE_TYPE (decl
) = error_mark_node
;
2914 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
2915 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
2920 A C language linkage is ignored for the names of class members
2921 and the member function type of class member functions. */
2922 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
2923 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
2925 /* Put functions on the TYPE_METHODS list and everything else on the
2926 TYPE_FIELDS list. Note that these are built up in reverse order.
2927 We reverse them (to obtain declaration order) in finish_struct. */
2928 if (DECL_DECLARES_FUNCTION_P (decl
))
2930 /* We also need to add this function to the
2931 CLASSTYPE_METHOD_VEC. */
2932 if (add_method (current_class_type
, decl
, NULL_TREE
))
2934 gcc_assert (TYPE_MAIN_VARIANT (current_class_type
) == current_class_type
);
2935 DECL_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
2936 TYPE_METHODS (current_class_type
) = decl
;
2938 maybe_add_class_template_decl_list (current_class_type
, decl
,
2942 /* Enter the DECL into the scope of the class, if the class
2943 isn't a closure (whose fields are supposed to be unnamed). */
2944 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
2945 || pushdecl_class_level (decl
))
2947 if (TREE_CODE (decl
) == USING_DECL
)
2949 /* For now, ignore class-scope USING_DECLS, so that
2950 debugging backends do not see them. */
2951 DECL_IGNORED_P (decl
) = 1;
2954 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2955 go at the beginning. The reason is that lookup_field_1
2956 searches the list in order, and we want a field name to
2957 override a type name so that the "struct stat hack" will
2958 work. In particular:
2960 struct S { enum E { }; int E } s;
2963 is valid. In addition, the FIELD_DECLs must be maintained in
2964 declaration order so that class layout works as expected.
2965 However, we don't need that order until class layout, so we
2966 save a little time by putting FIELD_DECLs on in reverse order
2967 here, and then reversing them in finish_struct_1. (We could
2968 also keep a pointer to the correct insertion points in the
2971 if (TREE_CODE (decl
) == TYPE_DECL
)
2972 TYPE_FIELDS (current_class_type
)
2973 = chainon (TYPE_FIELDS (current_class_type
), decl
);
2976 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
2977 TYPE_FIELDS (current_class_type
) = decl
;
2980 maybe_add_class_template_decl_list (current_class_type
, decl
,
2985 /* Finish processing a complete template declaration. The PARMS are
2986 the template parameters. */
2989 finish_template_decl (tree parms
)
2992 end_template_decl ();
2994 end_specialization ();
2997 // Returns the template type of the class scope being entered. If we're
2998 // entering a constrained class scope. TYPE is the class template
2999 // scope being entered and we may need to match the intended type with
3000 // a constrained specialization. For example:
3002 // template<Object T>
3003 // struct S { void f(); }; #1
3005 // template<Object T>
3006 // void S<T>::f() { } #2
3008 // We check, in #2, that S<T> refers precisely to the type declared by
3009 // #1 (i.e., that the constraints match). Note that the following should
3010 // be an error since there is no specialization of S<T> that is
3011 // unconstrained, but this is not diagnosed here.
3013 // template<typename T>
3014 // void S<T>::f() { }
3016 // We cannot diagnose this problem here since this function also matches
3017 // qualified template names that are not part of a definition. For example:
3019 // template<Integral T, Floating_point U>
3020 // typename pair<T, U>::first_type void f(T, U);
3022 // Here, it is unlikely that there is a partial specialization of
3023 // pair constrained for for Integral and Floating_point arguments.
3025 // The general rule is: if a constrained specialization with matching
3026 // constraints is found return that type. Also note that if TYPE is not a
3027 // class-type (e.g. a typename type), then no fixup is needed.
3030 fixup_template_type (tree type
)
3032 // Find the template parameter list at the a depth appropriate to
3033 // the scope we're trying to enter.
3034 tree parms
= current_template_parms
;
3035 int depth
= template_class_depth (type
);
3036 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3037 parms
= TREE_CHAIN (parms
);
3040 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3041 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3043 // Search for a specialization whose type and constraints match.
3044 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3045 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3048 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3050 // If the type and constraints match a specialization, then we
3051 // are entering that type.
3052 if (same_type_p (type
, TREE_TYPE (specs
))
3053 && equivalent_constraints (cur_constr
, spec_constr
))
3054 return TREE_TYPE (specs
);
3055 specs
= TREE_CHAIN (specs
);
3058 // If no specialization matches, then must return the type
3059 // previously found.
3063 /* Finish processing a template-id (which names a type) of the form
3064 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3065 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3066 the scope of template-id indicated. */
3069 finish_template_type (tree name
, tree args
, int entering_scope
)
3073 type
= lookup_template_class (name
, args
,
3074 NULL_TREE
, NULL_TREE
, entering_scope
,
3075 tf_warning_or_error
| tf_user
);
3077 /* If we might be entering the scope of a partial specialization,
3078 find the one with the right constraints. */
3081 && CLASS_TYPE_P (type
)
3082 && dependent_type_p (type
)
3083 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3084 type
= fixup_template_type (type
);
3086 if (type
== error_mark_node
)
3088 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3089 return TYPE_STUB_DECL (type
);
3091 return TYPE_NAME (type
);
3094 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3095 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3096 BASE_CLASS, or NULL_TREE if an error occurred. The
3097 ACCESS_SPECIFIER is one of
3098 access_{default,public,protected_private}_node. For a virtual base
3099 we set TREE_TYPE. */
3102 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3106 if (base
== error_mark_node
)
3108 error ("invalid base-class specification");
3111 else if (! MAYBE_CLASS_TYPE_P (base
))
3113 error ("%qT is not a class type", base
);
3118 if (cp_type_quals (base
) != 0)
3120 /* DR 484: Can a base-specifier name a cv-qualified
3122 base
= TYPE_MAIN_VARIANT (base
);
3124 result
= build_tree_list (access
, base
);
3126 TREE_TYPE (result
) = integer_type_node
;
3132 /* If FNS is a member function, a set of member functions, or a
3133 template-id referring to one or more member functions, return a
3134 BASELINK for FNS, incorporating the current access context.
3135 Otherwise, return FNS unchanged. */
3138 baselink_for_fns (tree fns
)
3143 if (BASELINK_P (fns
)
3144 || error_operand_p (fns
))
3147 scope
= ovl_scope (fns
);
3148 if (!CLASS_TYPE_P (scope
))
3151 cl
= currently_open_derived_class (scope
);
3154 cl
= TYPE_BINFO (cl
);
3155 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3158 /* Returns true iff DECL is a variable from a function outside
3162 outer_var_p (tree decl
)
3164 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3165 && DECL_FUNCTION_SCOPE_P (decl
)
3166 && (DECL_CONTEXT (decl
) != current_function_decl
3167 || parsing_nsdmi ()));
3170 /* As above, but also checks that DECL is automatic. */
3173 outer_automatic_var_p (tree decl
)
3175 return (outer_var_p (decl
)
3176 && !TREE_STATIC (decl
));
3179 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3180 rewrite it for lambda capture. */
3183 process_outer_var_ref (tree decl
, tsubst_flags_t complain
)
3185 if (cp_unevaluated_operand
)
3186 /* It's not a use (3.2) if we're in an unevaluated context. */
3188 if (decl
== error_mark_node
)
3191 tree context
= DECL_CONTEXT (decl
);
3192 tree containing_function
= current_function_decl
;
3193 tree lambda_stack
= NULL_TREE
;
3194 tree lambda_expr
= NULL_TREE
;
3195 tree initializer
= convert_from_reference (decl
);
3197 /* Mark it as used now even if the use is ill-formed. */
3198 if (!mark_used (decl
, complain
) && !(complain
& tf_error
))
3199 return error_mark_node
;
3201 /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
3202 support for an approach in which a reference to a local
3203 [constant] automatic variable in a nested class or lambda body
3204 would enter the expression as an rvalue, which would reduce
3205 the complexity of the problem"
3207 FIXME update for final resolution of core issue 696. */
3208 if (decl_maybe_constant_var_p (decl
))
3210 if (processing_template_decl
)
3211 /* In a template, the constant value may not be in a usable
3212 form, so wait until instantiation time. */
3214 else if (decl_constant_var_p (decl
))
3216 tree t
= maybe_constant_value (convert_from_reference (decl
));
3217 if (TREE_CONSTANT (t
))
3222 if (parsing_nsdmi ())
3223 containing_function
= NULL_TREE
;
3225 /* If we are in a lambda function, we can move out until we hit
3227 2. a non-lambda function, or
3228 3. a non-default capturing lambda function. */
3229 while (context
!= containing_function
3230 && LAMBDA_FUNCTION_P (containing_function
))
3232 tree closure
= DECL_CONTEXT (containing_function
);
3233 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3235 if (TYPE_CLASS_SCOPE_P (closure
))
3236 /* A lambda in an NSDMI (c++/64496). */
3239 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3243 lambda_stack
= tree_cons (NULL_TREE
,
3248 = decl_function_context (containing_function
);
3251 if (lambda_expr
&& VAR_P (decl
)
3252 && DECL_ANON_UNION_VAR_P (decl
))
3254 if (complain
& tf_error
)
3255 error ("cannot capture member %qD of anonymous union", decl
);
3256 return error_mark_node
;
3258 if (context
== containing_function
)
3260 decl
= add_default_capture (lambda_stack
,
3261 /*id=*/DECL_NAME (decl
),
3264 else if (lambda_expr
)
3266 if (complain
& tf_error
)
3268 error ("%qD is not captured", decl
);
3269 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3270 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3272 inform (location_of (closure
),
3273 "the lambda has no capture-default");
3274 else if (TYPE_CLASS_SCOPE_P (closure
))
3275 inform (0, "lambda in local class %q+T cannot "
3276 "capture variables from the enclosing context",
3277 TYPE_CONTEXT (closure
));
3278 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3280 return error_mark_node
;
3284 if (complain
& tf_error
)
3286 ? G_("use of local variable with automatic storage from containing function")
3287 : G_("use of parameter from containing function"));
3288 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3289 return error_mark_node
;
3294 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3295 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3296 if non-NULL, is the type or namespace used to explicitly qualify
3297 ID_EXPRESSION. DECL is the entity to which that name has been
3300 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3301 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3302 be set to true if this expression isn't permitted in a
3303 constant-expression, but it is otherwise not set by this function.
3304 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3305 constant-expression, but a non-constant expression is also
3308 DONE is true if this expression is a complete postfix-expression;
3309 it is false if this expression is followed by '->', '[', '(', etc.
3310 ADDRESS_P is true iff this expression is the operand of '&'.
3311 TEMPLATE_P is true iff the qualified-id was of the form
3312 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3313 appears as a template argument.
3315 If an error occurs, and it is the kind of error that might cause
3316 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3317 is the caller's responsibility to issue the message. *ERROR_MSG
3318 will be a string with static storage duration, so the caller need
3321 Return an expression for the entity, after issuing appropriate
3322 diagnostics. This function is also responsible for transforming a
3323 reference to a non-static member into a COMPONENT_REF that makes
3324 the use of "this" explicit.
3326 Upon return, *IDK will be filled in appropriately. */
3328 finish_id_expression (tree id_expression
,
3332 bool integral_constant_expression_p
,
3333 bool allow_non_integral_constant_expression_p
,
3334 bool *non_integral_constant_expression_p
,
3338 bool template_arg_p
,
3339 const char **error_msg
,
3340 location_t location
)
3342 decl
= strip_using_decl (decl
);
3344 /* Initialize the output parameters. */
3345 *idk
= CP_ID_KIND_NONE
;
3348 if (id_expression
== error_mark_node
)
3349 return error_mark_node
;
3350 /* If we have a template-id, then no further lookup is
3351 required. If the template-id was for a template-class, we
3352 will sometimes have a TYPE_DECL at this point. */
3353 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3354 || TREE_CODE (decl
) == TYPE_DECL
)
3356 /* Look up the name. */
3359 if (decl
== error_mark_node
)
3361 /* Name lookup failed. */
3364 || (!dependent_type_p (scope
)
3365 && !(identifier_p (id_expression
)
3366 && IDENTIFIER_TYPENAME_P (id_expression
)
3367 && dependent_type_p (TREE_TYPE (id_expression
))))))
3369 /* If the qualifying type is non-dependent (and the name
3370 does not name a conversion operator to a dependent
3371 type), issue an error. */
3372 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3373 return error_mark_node
;
3377 /* It may be resolved via Koenig lookup. */
3378 *idk
= CP_ID_KIND_UNQUALIFIED
;
3379 return id_expression
;
3382 decl
= id_expression
;
3384 /* If DECL is a variable that would be out of scope under
3385 ANSI/ISO rules, but in scope in the ARM, name lookup
3386 will succeed. Issue a diagnostic here. */
3388 decl
= check_for_out_of_scope_variable (decl
);
3390 /* Remember that the name was used in the definition of
3391 the current class so that we can check later to see if
3392 the meaning would have been different after the class
3393 was entirely defined. */
3394 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3395 maybe_note_name_used_in_class (id_expression
, decl
);
3397 /* Disallow uses of local variables from containing functions, except
3398 within lambda-expressions. */
3399 if (outer_automatic_var_p (decl
))
3401 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3402 if (decl
== error_mark_node
)
3403 return error_mark_node
;
3406 /* Also disallow uses of function parameters outside the function
3407 body, except inside an unevaluated context (i.e. decltype). */
3408 if (TREE_CODE (decl
) == PARM_DECL
3409 && DECL_CONTEXT (decl
) == NULL_TREE
3410 && !cp_unevaluated_operand
)
3412 *error_msg
= "use of parameter outside function body";
3413 return error_mark_node
;
3417 /* If we didn't find anything, or what we found was a type,
3418 then this wasn't really an id-expression. */
3419 if (TREE_CODE (decl
) == TEMPLATE_DECL
3420 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3422 *error_msg
= "missing template arguments";
3423 return error_mark_node
;
3425 else if (TREE_CODE (decl
) == TYPE_DECL
3426 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3428 *error_msg
= "expected primary-expression";
3429 return error_mark_node
;
3432 /* If the name resolved to a template parameter, there is no
3433 need to look it up again later. */
3434 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3435 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3439 *idk
= CP_ID_KIND_NONE
;
3440 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3441 decl
= TEMPLATE_PARM_DECL (decl
);
3442 r
= convert_from_reference (DECL_INITIAL (decl
));
3444 if (integral_constant_expression_p
3445 && !dependent_type_p (TREE_TYPE (decl
))
3446 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3448 if (!allow_non_integral_constant_expression_p
)
3449 error ("template parameter %qD of type %qT is not allowed in "
3450 "an integral constant expression because it is not of "
3451 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3452 *non_integral_constant_expression_p
= true;
3458 bool dependent_p
= type_dependent_expression_p (decl
);
3460 /* If the declaration was explicitly qualified indicate
3461 that. The semantics of `A::f(3)' are different than
3462 `f(3)' if `f' is virtual. */
3464 ? CP_ID_KIND_QUALIFIED
3465 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3466 ? CP_ID_KIND_TEMPLATE_ID
3468 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3469 : CP_ID_KIND_UNQUALIFIED
)));
3471 /* If the name was dependent on a template parameter, we will
3472 resolve the name at instantiation time. */
3475 /* If we found a variable, then name lookup during the
3476 instantiation will always resolve to the same VAR_DECL
3477 (or an instantiation thereof). */
3479 || TREE_CODE (decl
) == CONST_DECL
3480 || TREE_CODE (decl
) == PARM_DECL
)
3483 return convert_from_reference (decl
);
3486 /* Create a SCOPE_REF for qualified names, if the scope is
3492 if (address_p
&& done
)
3493 decl
= finish_qualified_id_expr (scope
, decl
,
3497 tf_warning_or_error
);
3500 tree type
= NULL_TREE
;
3501 if (DECL_P (decl
) && !dependent_scope_p (scope
))
3502 type
= TREE_TYPE (decl
);
3503 decl
= build_qualified_name (type
,
3509 if (TREE_TYPE (decl
))
3510 decl
= convert_from_reference (decl
);
3513 /* A TEMPLATE_ID already contains all the information we
3515 if (TREE_CODE (id_expression
) == TEMPLATE_ID_EXPR
)
3516 return id_expression
;
3517 /* The same is true for FIELD_DECL, but we also need to
3518 make sure that the syntax is correct. */
3519 else if (TREE_CODE (decl
) == FIELD_DECL
)
3521 /* Since SCOPE is NULL here, this is an unqualified name.
3522 Access checking has been performed during name lookup
3523 already. Turn off checking to avoid duplicate errors. */
3524 push_deferring_access_checks (dk_no_check
);
3525 decl
= finish_non_static_data_member
3527 /*qualifying_scope=*/NULL_TREE
);
3528 pop_deferring_access_checks ();
3531 return id_expression
;
3534 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3536 error ("use of namespace %qD as expression", decl
);
3537 return error_mark_node
;
3539 else if (DECL_CLASS_TEMPLATE_P (decl
))
3541 error ("use of class template %qT as expression", decl
);
3542 return error_mark_node
;
3544 else if (TREE_CODE (decl
) == TREE_LIST
)
3546 /* Ambiguous reference to base members. */
3547 error ("request for member %qD is ambiguous in "
3548 "multiple inheritance lattice", id_expression
);
3549 print_candidates (decl
);
3550 return error_mark_node
;
3553 /* Mark variable-like entities as used. Functions are similarly
3554 marked either below or after overload resolution. */
3556 || TREE_CODE (decl
) == PARM_DECL
3557 || TREE_CODE (decl
) == CONST_DECL
3558 || TREE_CODE (decl
) == RESULT_DECL
)
3559 && !mark_used (decl
))
3560 return error_mark_node
;
3562 /* Only certain kinds of names are allowed in constant
3563 expression. Template parameters have already
3564 been handled above. */
3565 if (! error_operand_p (decl
)
3566 && integral_constant_expression_p
3567 && ! decl_constant_var_p (decl
)
3568 && TREE_CODE (decl
) != CONST_DECL
3569 && ! builtin_valid_in_constant_expr_p (decl
))
3571 if (!allow_non_integral_constant_expression_p
)
3573 error ("%qD cannot appear in a constant-expression", decl
);
3574 return error_mark_node
;
3576 *non_integral_constant_expression_p
= true;
3581 && !cp_unevaluated_operand
3582 && !processing_template_decl
3583 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
3584 && CP_DECL_THREAD_LOCAL_P (decl
)
3585 && (wrap
= get_tls_wrapper_fn (decl
)))
3587 /* Replace an evaluated use of the thread_local variable with
3588 a call to its wrapper. */
3589 decl
= build_cxx_call (wrap
, 0, NULL
, tf_warning_or_error
);
3591 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3592 && variable_template_p (TREE_OPERAND (decl
, 0)))
3594 decl
= finish_template_variable (decl
);
3596 decl
= convert_from_reference (decl
);
3600 decl
= (adjust_result_of_qualified_name_lookup
3601 (decl
, scope
, current_nonlambda_class_type()));
3603 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3607 decl
= finish_qualified_id_expr (scope
,
3613 tf_warning_or_error
);
3615 decl
= convert_from_reference (decl
);
3617 else if (TREE_CODE (decl
) == FIELD_DECL
)
3619 /* Since SCOPE is NULL here, this is an unqualified name.
3620 Access checking has been performed during name lookup
3621 already. Turn off checking to avoid duplicate errors. */
3622 push_deferring_access_checks (dk_no_check
);
3623 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3624 /*qualifying_scope=*/NULL_TREE
);
3625 pop_deferring_access_checks ();
3627 else if (is_overloaded_fn (decl
))
3631 first_fn
= get_first_fn (decl
);
3632 if (TREE_CODE (first_fn
) == TEMPLATE_DECL
)
3633 first_fn
= DECL_TEMPLATE_RESULT (first_fn
);
3635 if (!really_overloaded_fn (decl
)
3636 && !mark_used (first_fn
))
3637 return error_mark_node
;
3640 && TREE_CODE (first_fn
) == FUNCTION_DECL
3641 && DECL_FUNCTION_MEMBER_P (first_fn
)
3642 && !shared_member_p (decl
))
3644 /* A set of member functions. */
3645 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
3646 return finish_class_member_access_expr (decl
, id_expression
,
3647 /*template_p=*/false,
3648 tf_warning_or_error
);
3651 decl
= baselink_for_fns (decl
);
3655 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
3656 && DECL_CLASS_SCOPE_P (decl
))
3658 tree context
= context_for_name_lookup (decl
);
3659 if (context
!= current_class_type
)
3661 tree path
= currently_open_derived_class (context
);
3662 perform_or_defer_access_check (TYPE_BINFO (path
),
3664 tf_warning_or_error
);
3668 decl
= convert_from_reference (decl
);
3675 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3676 use as a type-specifier. */
3679 finish_typeof (tree expr
)
3683 if (type_dependent_expression_p (expr
))
3685 type
= cxx_make_type (TYPEOF_TYPE
);
3686 TYPEOF_TYPE_EXPR (type
) = expr
;
3687 SET_TYPE_STRUCTURAL_EQUALITY (type
);
3692 expr
= mark_type_use (expr
);
3694 type
= unlowered_expr_type (expr
);
3696 if (!type
|| type
== unknown_type_node
)
3698 error ("type of %qE is unknown", expr
);
3699 return error_mark_node
;
3705 /* Implement the __underlying_type keyword: Return the underlying
3706 type of TYPE, suitable for use as a type-specifier. */
3709 finish_underlying_type (tree type
)
3711 tree underlying_type
;
3713 if (processing_template_decl
)
3715 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
3716 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
3717 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
3719 return underlying_type
;
3722 complete_type (type
);
3724 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
3726 error ("%qT is not an enumeration type", type
);
3727 return error_mark_node
;
3730 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
3732 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
3733 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
3734 See finish_enum_value_list for details. */
3735 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
3737 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
3738 TYPE_UNSIGNED (underlying_type
));
3740 return underlying_type
;
3743 /* Implement the __direct_bases keyword: Return the direct base classes
3747 calculate_direct_bases (tree type
)
3749 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3750 tree bases_vec
= NULL_TREE
;
3751 vec
<tree
, va_gc
> *base_binfos
;
3755 complete_type (type
);
3757 if (!NON_UNION_CLASS_TYPE_P (type
))
3758 return make_tree_vec (0);
3760 base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
3762 /* Virtual bases are initialized first */
3763 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3765 if (BINFO_VIRTUAL_P (binfo
))
3767 vec_safe_push (vector
, binfo
);
3771 /* Now non-virtuals */
3772 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3774 if (!BINFO_VIRTUAL_P (binfo
))
3776 vec_safe_push (vector
, binfo
);
3781 bases_vec
= make_tree_vec (vector
->length ());
3783 for (i
= 0; i
< vector
->length (); ++i
)
3785 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
3790 /* Implement the __bases keyword: Return the base classes
3793 /* Find morally non-virtual base classes by walking binfo hierarchy */
3794 /* Virtual base classes are handled separately in finish_bases */
3797 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
3799 /* Don't walk bases of virtual bases */
3800 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
3804 dfs_calculate_bases_post (tree binfo
, void *data_
)
3806 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
3807 if (!BINFO_VIRTUAL_P (binfo
))
3809 vec_safe_push (*data
, BINFO_TYPE (binfo
));
3814 /* Calculates the morally non-virtual base classes of a class */
3815 static vec
<tree
, va_gc
> *
3816 calculate_bases_helper (tree type
)
3818 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3820 /* Now add non-virtual base classes in order of construction */
3821 dfs_walk_all (TYPE_BINFO (type
),
3822 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
3827 calculate_bases (tree type
)
3829 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3830 tree bases_vec
= NULL_TREE
;
3832 vec
<tree
, va_gc
> *vbases
;
3833 vec
<tree
, va_gc
> *nonvbases
;
3836 complete_type (type
);
3838 if (!NON_UNION_CLASS_TYPE_P (type
))
3839 return make_tree_vec (0);
3841 /* First go through virtual base classes */
3842 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
3843 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
3845 vec
<tree
, va_gc
> *vbase_bases
;
3846 vbase_bases
= calculate_bases_helper (BINFO_TYPE (binfo
));
3847 vec_safe_splice (vector
, vbase_bases
);
3848 release_tree_vector (vbase_bases
);
3851 /* Now for the non-virtual bases */
3852 nonvbases
= calculate_bases_helper (type
);
3853 vec_safe_splice (vector
, nonvbases
);
3854 release_tree_vector (nonvbases
);
3856 /* Last element is entire class, so don't copy */
3857 bases_vec
= make_tree_vec (vector
->length () - 1);
3859 for (i
= 0; i
< vector
->length () - 1; ++i
)
3861 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
3863 release_tree_vector (vector
);
3868 finish_bases (tree type
, bool direct
)
3870 tree bases
= NULL_TREE
;
3872 if (!processing_template_decl
)
3874 /* Parameter packs can only be used in templates */
3875 error ("Parameter pack __bases only valid in template declaration");
3876 return error_mark_node
;
3879 bases
= cxx_make_type (BASES
);
3880 BASES_TYPE (bases
) = type
;
3881 BASES_DIRECT (bases
) = direct
;
3882 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
3887 /* Perform C++-specific checks for __builtin_offsetof before calling
3891 finish_offsetof (tree expr
, location_t loc
)
3893 /* If we're processing a template, we can't finish the semantics yet.
3894 Otherwise we can fold the entire expression now. */
3895 if (processing_template_decl
)
3897 expr
= build1 (OFFSETOF_EXPR
, size_type_node
, expr
);
3898 SET_EXPR_LOCATION (expr
, loc
);
3902 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
3904 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
3905 TREE_OPERAND (expr
, 2));
3906 return error_mark_node
;
3908 if (TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
3909 || TREE_CODE (TREE_TYPE (expr
)) == METHOD_TYPE
3910 || TREE_TYPE (expr
) == unknown_type_node
)
3912 if (INDIRECT_REF_P (expr
))
3913 error ("second operand of %<offsetof%> is neither a single "
3914 "identifier nor a sequence of member accesses and "
3915 "array references");
3918 if (TREE_CODE (expr
) == COMPONENT_REF
3919 || TREE_CODE (expr
) == COMPOUND_EXPR
)
3920 expr
= TREE_OPERAND (expr
, 1);
3921 error ("cannot apply %<offsetof%> to member function %qD", expr
);
3923 return error_mark_node
;
3925 if (REFERENCE_REF_P (expr
))
3926 expr
= TREE_OPERAND (expr
, 0);
3927 if (TREE_CODE (expr
) == COMPONENT_REF
)
3929 tree object
= TREE_OPERAND (expr
, 0);
3930 if (!complete_type_or_else (TREE_TYPE (object
), object
))
3931 return error_mark_node
;
3932 if (warn_invalid_offsetof
3933 && CLASS_TYPE_P (TREE_TYPE (object
))
3934 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (object
))
3935 && cp_unevaluated_operand
== 0)
3936 pedwarn (loc
, OPT_Winvalid_offsetof
,
3937 "offsetof within non-standard-layout type %qT is undefined",
3938 TREE_TYPE (object
));
3940 return fold_offsetof (expr
);
3943 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
3944 function is broken out from the above for the benefit of the tree-ssa
3948 simplify_aggr_init_expr (tree
*tp
)
3950 tree aggr_init_expr
= *tp
;
3952 /* Form an appropriate CALL_EXPR. */
3953 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
3954 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
3955 tree type
= TREE_TYPE (slot
);
3958 enum style_t
{ ctor
, arg
, pcc
} style
;
3960 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
3962 #ifdef PCC_STATIC_STRUCT_RETURN
3968 gcc_assert (TREE_ADDRESSABLE (type
));
3972 call_expr
= build_call_array_loc (input_location
,
3973 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
3975 aggr_init_expr_nargs (aggr_init_expr
),
3976 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
3977 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
3978 CALL_EXPR_LIST_INIT_P (call_expr
) = CALL_EXPR_LIST_INIT_P (aggr_init_expr
);
3982 /* Replace the first argument to the ctor with the address of the
3984 cxx_mark_addressable (slot
);
3985 CALL_EXPR_ARG (call_expr
, 0) =
3986 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
3988 else if (style
== arg
)
3990 /* Just mark it addressable here, and leave the rest to
3991 expand_call{,_inline}. */
3992 cxx_mark_addressable (slot
);
3993 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
3994 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
3996 else if (style
== pcc
)
3998 /* If we're using the non-reentrant PCC calling convention, then we
3999 need to copy the returned value out of the static buffer into the
4001 push_deferring_access_checks (dk_no_check
);
4002 call_expr
= build_aggr_init (slot
, call_expr
,
4003 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4004 tf_warning_or_error
);
4005 pop_deferring_access_checks ();
4006 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4009 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4011 tree init
= build_zero_init (type
, NULL_TREE
,
4012 /*static_storage_p=*/false);
4013 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4014 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4021 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4024 emit_associated_thunks (tree fn
)
4026 /* When we use vcall offsets, we emit thunks with the virtual
4027 functions to which they thunk. The whole point of vcall offsets
4028 is so that you can know statically the entire set of thunks that
4029 will ever be needed for a given virtual function, thereby
4030 enabling you to output all the thunks with the function itself. */
4031 if (DECL_VIRTUAL_P (fn
)
4032 /* Do not emit thunks for extern template instantiations. */
4033 && ! DECL_REALLY_EXTERN (fn
))
4037 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4039 if (!THUNK_ALIAS (thunk
))
4041 use_thunk (thunk
, /*emit_p=*/1);
4042 if (DECL_RESULT_THUNK_P (thunk
))
4046 for (probe
= DECL_THUNKS (thunk
);
4047 probe
; probe
= DECL_CHAIN (probe
))
4048 use_thunk (probe
, /*emit_p=*/1);
4052 gcc_assert (!DECL_THUNKS (thunk
));
4057 /* Generate RTL for FN. */
4060 expand_or_defer_fn_1 (tree fn
)
4062 /* When the parser calls us after finishing the body of a template
4063 function, we don't really want to expand the body. */
4064 if (processing_template_decl
)
4066 /* Normally, collection only occurs in rest_of_compilation. So,
4067 if we don't collect here, we never collect junk generated
4068 during the processing of templates until we hit a
4069 non-template function. It's not safe to do this inside a
4070 nested class, though, as the parser may have local state that
4071 is not a GC root. */
4072 if (!function_depth
)
4077 gcc_assert (DECL_SAVED_TREE (fn
));
4079 /* We make a decision about linkage for these functions at the end
4080 of the compilation. Until that point, we do not want the back
4081 end to output them -- but we do want it to see the bodies of
4082 these functions so that it can inline them as appropriate. */
4083 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4085 if (DECL_INTERFACE_KNOWN (fn
))
4086 /* We've already made a decision as to how this function will
4089 tentative_decl_linkage (fn
);
4091 import_export_decl (fn
);
4093 /* If the user wants us to keep all inline functions, then mark
4094 this function as needed so that finish_file will make sure to
4095 output it later. Similarly, all dllexport'd functions must
4096 be emitted; there may be callers in other DLLs. */
4097 if (DECL_DECLARED_INLINE_P (fn
)
4098 && !DECL_REALLY_EXTERN (fn
)
4099 && (flag_keep_inline_functions
4100 || (flag_keep_inline_dllexport
4101 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4104 DECL_EXTERNAL (fn
) = 0;
4108 /* If this is a constructor or destructor body, we have to clone
4110 if (maybe_clone_body (fn
))
4112 /* We don't want to process FN again, so pretend we've written
4113 it out, even though we haven't. */
4114 TREE_ASM_WRITTEN (fn
) = 1;
4115 /* If this is an instantiation of a constexpr function, keep
4116 DECL_SAVED_TREE for explain_invalid_constexpr_fn. */
4117 if (!is_instantiation_of_constexpr (fn
))
4118 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4122 /* There's no reason to do any of the work here if we're only doing
4123 semantic analysis; this code just generates RTL. */
4124 if (flag_syntax_only
)
4131 expand_or_defer_fn (tree fn
)
4133 if (expand_or_defer_fn_1 (fn
))
4137 /* Expand or defer, at the whim of the compilation unit manager. */
4138 cgraph_node::finalize_function (fn
, function_depth
> 1);
4139 emit_associated_thunks (fn
);
4147 nrv_data () : visited (37) {}
4151 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4154 /* Helper function for walk_tree, used by finalize_nrv below. */
4157 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4159 struct nrv_data
*dp
= (struct nrv_data
*)data
;
4162 /* No need to walk into types. There wouldn't be any need to walk into
4163 non-statements, except that we have to consider STMT_EXPRs. */
4166 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4167 but differs from using NULL_TREE in that it indicates that we care
4168 about the value of the RESULT_DECL. */
4169 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4170 TREE_OPERAND (*tp
, 0) = dp
->result
;
4171 /* Change all cleanups for the NRV to only run when an exception is
4173 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4174 && CLEANUP_DECL (*tp
) == dp
->var
)
4175 CLEANUP_EH_ONLY (*tp
) = 1;
4176 /* Replace the DECL_EXPR for the NRV with an initialization of the
4177 RESULT_DECL, if needed. */
4178 else if (TREE_CODE (*tp
) == DECL_EXPR
4179 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4182 if (DECL_INITIAL (dp
->var
)
4183 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4184 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4185 DECL_INITIAL (dp
->var
));
4187 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4188 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4189 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4192 /* And replace all uses of the NRV with the RESULT_DECL. */
4193 else if (*tp
== dp
->var
)
4196 /* Avoid walking into the same tree more than once. Unfortunately, we
4197 can't just use walk_tree_without duplicates because it would only call
4198 us for the first occurrence of dp->var in the function body. */
4199 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4205 /* Keep iterating. */
4209 /* Called from finish_function to implement the named return value
4210 optimization by overriding all the RETURN_EXPRs and pertinent
4211 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4212 RESULT_DECL for the function. */
4215 finalize_nrv (tree
*tp
, tree var
, tree result
)
4217 struct nrv_data data
;
4219 /* Copy name from VAR to RESULT. */
4220 DECL_NAME (result
) = DECL_NAME (var
);
4221 /* Don't forget that we take its address. */
4222 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4223 /* Finally set DECL_VALUE_EXPR to avoid assigning
4224 a stack slot at -O0 for the original var and debug info
4225 uses RESULT location for VAR. */
4226 SET_DECL_VALUE_EXPR (var
, result
);
4227 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4230 data
.result
= result
;
4231 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4234 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4237 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4238 bool need_copy_ctor
, bool need_copy_assignment
,
4241 int save_errorcount
= errorcount
;
4244 /* Always allocate 3 elements for simplicity. These are the
4245 function decls for the ctor, dtor, and assignment op.
4246 This layout is known to the three lang hooks,
4247 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4248 and cxx_omp_clause_assign_op. */
4249 info
= make_tree_vec (3);
4250 CP_OMP_CLAUSE_INFO (c
) = info
;
4252 if (need_default_ctor
|| need_copy_ctor
)
4254 if (need_default_ctor
)
4255 t
= get_default_ctor (type
);
4257 t
= get_copy_ctor (type
, tf_warning_or_error
);
4259 if (t
&& !trivial_fn_p (t
))
4260 TREE_VEC_ELT (info
, 0) = t
;
4263 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4264 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4266 if (need_copy_assignment
)
4268 t
= get_copy_assign (type
);
4270 if (t
&& !trivial_fn_p (t
))
4271 TREE_VEC_ELT (info
, 2) = t
;
4274 return errorcount
!= save_errorcount
;
4277 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4278 FIELD_DECL, otherwise return DECL itself. */
4281 omp_clause_decl_field (tree decl
)
4284 && DECL_HAS_VALUE_EXPR_P (decl
)
4285 && DECL_ARTIFICIAL (decl
)
4286 && DECL_LANG_SPECIFIC (decl
)
4287 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4289 tree f
= DECL_VALUE_EXPR (decl
);
4290 if (TREE_CODE (f
) == INDIRECT_REF
)
4291 f
= TREE_OPERAND (f
, 0);
4292 if (TREE_CODE (f
) == COMPONENT_REF
)
4294 f
= TREE_OPERAND (f
, 1);
4295 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4302 /* Adjust DECL if needed for printing using %qE. */
4305 omp_clause_printable_decl (tree decl
)
4307 tree t
= omp_clause_decl_field (decl
);
4313 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4314 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4318 omp_note_field_privatization (tree f
, tree t
)
4320 if (!omp_private_member_map
)
4321 omp_private_member_map
= new hash_map
<tree
, tree
>;
4322 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4326 omp_private_member_vec
.safe_push (f
);
4327 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4328 omp_private_member_vec
.safe_push (integer_zero_node
);
4332 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4336 omp_privatize_field (tree t
, bool shared
)
4338 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4339 if (m
== error_mark_node
)
4340 return error_mark_node
;
4341 if (!omp_private_member_map
&& !shared
)
4342 omp_private_member_map
= new hash_map
<tree
, tree
>;
4343 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
)
4345 gcc_assert (TREE_CODE (m
) == INDIRECT_REF
);
4346 m
= TREE_OPERAND (m
, 0);
4348 tree vb
= NULL_TREE
;
4349 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4352 v
= create_temporary_var (TREE_TYPE (m
));
4353 if (!DECL_LANG_SPECIFIC (v
))
4354 retrofit_lang_decl (v
);
4355 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4356 SET_DECL_VALUE_EXPR (v
, m
);
4357 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4359 omp_private_member_vec
.safe_push (t
);
4364 /* Helper function for handle_omp_array_sections. Called recursively
4365 to handle multiple array-section-subscripts. C is the clause,
4366 T current expression (initially OMP_CLAUSE_DECL), which is either
4367 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4368 expression if specified, TREE_VALUE length expression if specified,
4369 TREE_CHAIN is what it has been specified after, or some decl.
4370 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4371 set to true if any of the array-section-subscript could have length
4372 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4373 first array-section-subscript which is known not to have length
4375 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4376 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4377 all are or may have length of 1, array-section-subscript [:2] is the
4378 first one known not to have length 1. For array-section-subscript
4379 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4380 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4381 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4382 case though, as some lengths could be zero. */
4385 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4386 bool &maybe_zero_len
, unsigned int &first_non_one
,
4389 tree ret
, low_bound
, length
, type
;
4390 if (TREE_CODE (t
) != TREE_LIST
)
4392 if (error_operand_p (t
))
4393 return error_mark_node
;
4394 if (REFERENCE_REF_P (t
)
4395 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4396 t
= TREE_OPERAND (t
, 0);
4398 if (TREE_CODE (t
) == COMPONENT_REF
4400 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
4401 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
4402 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
4403 && !type_dependent_expression_p (t
))
4405 if (DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
4407 error_at (OMP_CLAUSE_LOCATION (c
),
4408 "bit-field %qE in %qs clause",
4409 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4410 return error_mark_node
;
4412 while (TREE_CODE (t
) == COMPONENT_REF
)
4414 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
4416 error_at (OMP_CLAUSE_LOCATION (c
),
4417 "%qE is a member of a union", t
);
4418 return error_mark_node
;
4420 t
= TREE_OPERAND (t
, 0);
4423 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
4425 if (processing_template_decl
)
4428 error_at (OMP_CLAUSE_LOCATION (c
),
4429 "%qD is not a variable in %qs clause", t
,
4430 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4432 error_at (OMP_CLAUSE_LOCATION (c
),
4433 "%qE is not a variable in %qs clause", t
,
4434 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4435 return error_mark_node
;
4437 else if (TREE_CODE (t
) == PARM_DECL
4438 && DECL_ARTIFICIAL (t
)
4439 && DECL_NAME (t
) == this_identifier
)
4441 error_at (OMP_CLAUSE_LOCATION (c
),
4442 "%<this%> allowed in OpenMP only in %<declare simd%>"
4444 return error_mark_node
;
4446 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4447 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
4449 error_at (OMP_CLAUSE_LOCATION (c
),
4450 "%qD is threadprivate variable in %qs clause", t
,
4451 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4452 return error_mark_node
;
4454 if (type_dependent_expression_p (ret
))
4456 ret
= convert_from_reference (ret
);
4460 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
4461 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
4462 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
4463 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4464 maybe_zero_len
, first_non_one
, is_omp
);
4465 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4468 type
= TREE_TYPE (ret
);
4469 low_bound
= TREE_PURPOSE (t
);
4470 length
= TREE_VALUE (t
);
4471 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4472 || (length
&& type_dependent_expression_p (length
)))
4475 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4476 return error_mark_node
;
4478 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4480 error_at (OMP_CLAUSE_LOCATION (c
),
4481 "low bound %qE of array section does not have integral type",
4483 return error_mark_node
;
4485 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4487 error_at (OMP_CLAUSE_LOCATION (c
),
4488 "length %qE of array section does not have integral type",
4490 return error_mark_node
;
4493 low_bound
= mark_rvalue_use (low_bound
);
4495 length
= mark_rvalue_use (length
);
4496 /* We need to reduce to real constant-values for checks below. */
4498 length
= fold_simple (length
);
4500 low_bound
= fold_simple (low_bound
);
4502 && TREE_CODE (low_bound
) == INTEGER_CST
4503 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4504 > TYPE_PRECISION (sizetype
))
4505 low_bound
= fold_convert (sizetype
, low_bound
);
4507 && TREE_CODE (length
) == INTEGER_CST
4508 && TYPE_PRECISION (TREE_TYPE (length
))
4509 > TYPE_PRECISION (sizetype
))
4510 length
= fold_convert (sizetype
, length
);
4511 if (low_bound
== NULL_TREE
)
4512 low_bound
= integer_zero_node
;
4514 if (length
!= NULL_TREE
)
4516 if (!integer_nonzerop (length
))
4518 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4519 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4521 if (integer_zerop (length
))
4523 error_at (OMP_CLAUSE_LOCATION (c
),
4524 "zero length array section in %qs clause",
4525 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4526 return error_mark_node
;
4530 maybe_zero_len
= true;
4532 if (first_non_one
== types
.length ()
4533 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4536 if (TREE_CODE (type
) == ARRAY_TYPE
)
4538 if (length
== NULL_TREE
4539 && (TYPE_DOMAIN (type
) == NULL_TREE
4540 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4542 error_at (OMP_CLAUSE_LOCATION (c
),
4543 "for unknown bound array type length expression must "
4545 return error_mark_node
;
4547 if (TREE_CODE (low_bound
) == INTEGER_CST
4548 && tree_int_cst_sgn (low_bound
) == -1)
4550 error_at (OMP_CLAUSE_LOCATION (c
),
4551 "negative low bound in array section in %qs clause",
4552 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4553 return error_mark_node
;
4555 if (length
!= NULL_TREE
4556 && TREE_CODE (length
) == INTEGER_CST
4557 && tree_int_cst_sgn (length
) == -1)
4559 error_at (OMP_CLAUSE_LOCATION (c
),
4560 "negative length in array section in %qs clause",
4561 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4562 return error_mark_node
;
4564 if (TYPE_DOMAIN (type
)
4565 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
4566 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
4569 tree size
= size_binop (PLUS_EXPR
,
4570 TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4572 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4574 if (tree_int_cst_lt (size
, low_bound
))
4576 error_at (OMP_CLAUSE_LOCATION (c
),
4577 "low bound %qE above array section size "
4578 "in %qs clause", low_bound
,
4579 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4580 return error_mark_node
;
4582 if (tree_int_cst_equal (size
, low_bound
))
4584 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
4585 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4587 error_at (OMP_CLAUSE_LOCATION (c
),
4588 "zero length array section in %qs clause",
4589 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4590 return error_mark_node
;
4592 maybe_zero_len
= true;
4594 else if (length
== NULL_TREE
4595 && first_non_one
== types
.length ()
4596 && tree_int_cst_equal
4597 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4601 else if (length
== NULL_TREE
)
4603 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4604 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4605 maybe_zero_len
= true;
4606 if (first_non_one
== types
.length ())
4609 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
4611 if (tree_int_cst_lt (size
, length
))
4613 error_at (OMP_CLAUSE_LOCATION (c
),
4614 "length %qE above array section size "
4615 "in %qs clause", length
,
4616 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4617 return error_mark_node
;
4619 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4622 = size_binop (PLUS_EXPR
,
4623 fold_convert (sizetype
, low_bound
),
4624 fold_convert (sizetype
, length
));
4625 if (TREE_CODE (lbpluslen
) == INTEGER_CST
4626 && tree_int_cst_lt (size
, lbpluslen
))
4628 error_at (OMP_CLAUSE_LOCATION (c
),
4629 "high bound %qE above array section size "
4630 "in %qs clause", lbpluslen
,
4631 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4632 return error_mark_node
;
4637 else if (length
== NULL_TREE
)
4639 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4640 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
)
4641 maybe_zero_len
= true;
4642 if (first_non_one
== types
.length ())
4646 /* For [lb:] we will need to evaluate lb more than once. */
4647 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4649 tree lb
= cp_save_expr (low_bound
);
4650 if (lb
!= low_bound
)
4652 TREE_PURPOSE (t
) = lb
;
4657 else if (TREE_CODE (type
) == POINTER_TYPE
)
4659 if (length
== NULL_TREE
)
4661 error_at (OMP_CLAUSE_LOCATION (c
),
4662 "for pointer type length expression must be specified");
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 there is a pointer type anywhere but in the very first
4675 array-section-subscript, the array section can't be contiguous. */
4676 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4677 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
4679 error_at (OMP_CLAUSE_LOCATION (c
),
4680 "array section is not contiguous in %qs clause",
4681 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4682 return error_mark_node
;
4687 error_at (OMP_CLAUSE_LOCATION (c
),
4688 "%qE does not have pointer or array type", ret
);
4689 return error_mark_node
;
4691 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4692 types
.safe_push (TREE_TYPE (ret
));
4693 /* We will need to evaluate lb more than once. */
4694 tree lb
= cp_save_expr (low_bound
);
4695 if (lb
!= low_bound
)
4697 TREE_PURPOSE (t
) = lb
;
4700 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
4704 /* Handle array sections for clause C. */
4707 handle_omp_array_sections (tree c
, bool is_omp
)
4709 bool maybe_zero_len
= false;
4710 unsigned int first_non_one
= 0;
4711 auto_vec
<tree
, 10> types
;
4712 tree first
= handle_omp_array_sections_1 (c
, OMP_CLAUSE_DECL (c
), types
,
4713 maybe_zero_len
, first_non_one
,
4715 if (first
== error_mark_node
)
4717 if (first
== NULL_TREE
)
4719 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
4721 tree t
= OMP_CLAUSE_DECL (c
);
4722 tree tem
= NULL_TREE
;
4723 if (processing_template_decl
)
4725 /* Need to evaluate side effects in the length expressions
4727 while (TREE_CODE (t
) == TREE_LIST
)
4729 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
4731 if (tem
== NULL_TREE
)
4732 tem
= TREE_VALUE (t
);
4734 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
4735 TREE_VALUE (t
), tem
);
4740 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
4741 OMP_CLAUSE_DECL (c
) = first
;
4745 unsigned int num
= types
.length (), i
;
4746 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
4747 tree condition
= NULL_TREE
;
4749 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
4750 maybe_zero_len
= true;
4751 if (processing_template_decl
&& maybe_zero_len
)
4754 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
4757 tree low_bound
= TREE_PURPOSE (t
);
4758 tree length
= TREE_VALUE (t
);
4762 && TREE_CODE (low_bound
) == INTEGER_CST
4763 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4764 > TYPE_PRECISION (sizetype
))
4765 low_bound
= fold_convert (sizetype
, low_bound
);
4767 && TREE_CODE (length
) == INTEGER_CST
4768 && TYPE_PRECISION (TREE_TYPE (length
))
4769 > TYPE_PRECISION (sizetype
))
4770 length
= fold_convert (sizetype
, length
);
4771 if (low_bound
== NULL_TREE
)
4772 low_bound
= integer_zero_node
;
4773 if (!maybe_zero_len
&& i
> first_non_one
)
4775 if (integer_nonzerop (low_bound
))
4776 goto do_warn_noncontiguous
;
4777 if (length
!= NULL_TREE
4778 && TREE_CODE (length
) == INTEGER_CST
4779 && TYPE_DOMAIN (types
[i
])
4780 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
4781 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
4785 size
= size_binop (PLUS_EXPR
,
4786 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4788 if (!tree_int_cst_equal (length
, size
))
4790 do_warn_noncontiguous
:
4791 error_at (OMP_CLAUSE_LOCATION (c
),
4792 "array section is not contiguous in %qs "
4794 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4798 if (!processing_template_decl
4799 && length
!= NULL_TREE
4800 && TREE_SIDE_EFFECTS (length
))
4802 if (side_effects
== NULL_TREE
)
4803 side_effects
= length
;
4805 side_effects
= build2 (COMPOUND_EXPR
,
4806 TREE_TYPE (side_effects
),
4807 length
, side_effects
);
4810 else if (processing_template_decl
)
4816 if (i
> first_non_one
4817 && ((length
&& integer_nonzerop (length
))
4818 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
))
4821 l
= fold_convert (sizetype
, length
);
4824 l
= size_binop (PLUS_EXPR
,
4825 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4827 l
= size_binop (MINUS_EXPR
, l
,
4828 fold_convert (sizetype
, low_bound
));
4830 if (i
> first_non_one
)
4832 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
4834 if (condition
== NULL_TREE
)
4837 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
4840 else if (size
== NULL_TREE
)
4842 size
= size_in_bytes (TREE_TYPE (types
[i
]));
4843 tree eltype
= TREE_TYPE (types
[num
- 1]);
4844 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4845 eltype
= TREE_TYPE (eltype
);
4846 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4847 size
= size_binop (EXACT_DIV_EXPR
, size
,
4848 size_in_bytes (eltype
));
4849 size
= size_binop (MULT_EXPR
, size
, l
);
4851 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
4852 size
, size_zero_node
);
4855 size
= size_binop (MULT_EXPR
, size
, l
);
4858 if (!processing_template_decl
)
4861 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
4862 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
4864 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
4865 tree index_type
= build_index_type (size
);
4866 tree eltype
= TREE_TYPE (first
);
4867 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
4868 eltype
= TREE_TYPE (eltype
);
4869 tree type
= build_array_type (eltype
, index_type
);
4870 tree ptype
= build_pointer_type (eltype
);
4871 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
4872 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
4873 t
= convert_from_reference (t
);
4874 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
4875 t
= build_fold_addr_expr (t
);
4876 tree t2
= build_fold_addr_expr (first
);
4877 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4878 ptrdiff_type_node
, t2
);
4879 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
4880 ptrdiff_type_node
, t2
,
4881 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4882 ptrdiff_type_node
, t
));
4883 if (tree_fits_shwi_p (t2
))
4884 t
= build2 (MEM_REF
, type
, t
,
4885 build_int_cst (ptype
, tree_to_shwi (t2
)));
4888 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4890 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
4891 TREE_TYPE (t
), t
, t2
);
4892 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
4894 OMP_CLAUSE_DECL (c
) = t
;
4897 OMP_CLAUSE_DECL (c
) = first
;
4898 OMP_CLAUSE_SIZE (c
) = size
;
4899 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
4900 || (TREE_CODE (t
) == COMPONENT_REF
4901 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
4904 switch (OMP_CLAUSE_MAP_KIND (c
))
4906 case GOMP_MAP_ALLOC
:
4909 case GOMP_MAP_TOFROM
:
4910 case GOMP_MAP_ALWAYS_TO
:
4911 case GOMP_MAP_ALWAYS_FROM
:
4912 case GOMP_MAP_ALWAYS_TOFROM
:
4913 case GOMP_MAP_RELEASE
:
4914 case GOMP_MAP_DELETE
:
4915 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
4920 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
4923 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
4924 else if (TREE_CODE (t
) == COMPONENT_REF
)
4925 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
4926 else if (REFERENCE_REF_P (t
)
4927 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4929 t
= TREE_OPERAND (t
, 0);
4930 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
4933 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
4934 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
4935 && !cxx_mark_addressable (t
))
4937 OMP_CLAUSE_DECL (c2
) = t
;
4938 t
= build_fold_addr_expr (first
);
4939 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4940 ptrdiff_type_node
, t
);
4941 tree ptr
= OMP_CLAUSE_DECL (c2
);
4942 ptr
= convert_from_reference (ptr
);
4943 if (!POINTER_TYPE_P (TREE_TYPE (ptr
)))
4944 ptr
= build_fold_addr_expr (ptr
);
4945 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
4946 ptrdiff_type_node
, t
,
4947 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4948 ptrdiff_type_node
, ptr
));
4949 OMP_CLAUSE_SIZE (c2
) = t
;
4950 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
4951 OMP_CLAUSE_CHAIN (c
) = c2
;
4952 ptr
= OMP_CLAUSE_DECL (c2
);
4953 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
4954 && TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
4955 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
4957 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
4959 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
4960 OMP_CLAUSE_DECL (c3
) = ptr
;
4961 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
)
4962 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
4964 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
4965 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
4966 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
4967 OMP_CLAUSE_CHAIN (c2
) = c3
;
4974 /* Return identifier to look up for omp declare reduction. */
4977 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
4979 const char *p
= NULL
;
4980 const char *m
= NULL
;
4981 switch (reduction_code
)
4989 case TRUTH_ANDIF_EXPR
:
4990 case TRUTH_ORIF_EXPR
:
4991 reduction_id
= ansi_opname (reduction_code
);
5005 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5006 return error_mark_node
;
5007 p
= IDENTIFIER_POINTER (reduction_id
);
5010 if (type
!= NULL_TREE
)
5011 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5013 const char prefix
[] = "omp declare reduction ";
5014 size_t lenp
= sizeof (prefix
);
5015 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5017 size_t len
= strlen (p
);
5018 size_t lenm
= m
? strlen (m
) + 1 : 0;
5019 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5021 memcpy (name
, prefix
, lenp
- 1);
5022 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5025 name
[lenp
+ len
- 1] = '~';
5026 memcpy (name
+ lenp
+ len
, m
, lenm
);
5028 return get_identifier (name
);
5031 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5032 FUNCTION_DECL or NULL_TREE if not found. */
5035 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5036 vec
<tree
> *ambiguousp
)
5039 tree baselink
= NULL_TREE
;
5040 if (identifier_p (id
))
5043 bool nonint_cst_expression_p
;
5044 const char *error_msg
;
5045 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5046 tree decl
= lookup_name (id
);
5047 if (decl
== NULL_TREE
)
5048 decl
= error_mark_node
;
5049 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5050 &nonint_cst_expression_p
, false, true, false,
5051 false, &error_msg
, loc
);
5052 if (idk
== CP_ID_KIND_UNQUALIFIED
5053 && identifier_p (id
))
5055 vec
<tree
, va_gc
> *args
= NULL
;
5056 vec_safe_push (args
, build_reference_type (type
));
5057 id
= perform_koenig_lookup (id
, args
, tf_none
);
5060 else if (TREE_CODE (id
) == SCOPE_REF
)
5061 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5062 omp_reduction_id (ERROR_MARK
,
5063 TREE_OPERAND (id
, 1),
5067 if (id
&& is_overloaded_fn (id
))
5069 for (; id
; id
= OVL_NEXT (id
))
5071 tree fndecl
= OVL_CURRENT (id
);
5072 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5074 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5075 if (same_type_p (TREE_TYPE (argtype
), type
))
5079 if (id
&& BASELINK_P (fns
))
5086 if (id
== NULL_TREE
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5088 vec
<tree
> ambiguous
= vNULL
;
5089 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5091 if (ambiguousp
== NULL
)
5092 ambiguousp
= &ambiguous
;
5093 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5095 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5096 baselinkp
? baselinkp
: &baselink
,
5098 if (id
== NULL_TREE
)
5100 if (!ambiguousp
->is_empty ())
5101 ambiguousp
->safe_push (id
);
5102 else if (ret
!= NULL_TREE
)
5104 ambiguousp
->safe_push (ret
);
5105 ambiguousp
->safe_push (id
);
5111 if (ambiguousp
!= &ambiguous
)
5113 if (!ambiguous
.is_empty ())
5115 const char *str
= _("candidates are:");
5118 error_at (loc
, "user defined reduction lookup is ambiguous");
5119 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5121 inform (DECL_SOURCE_LOCATION (udr
), "%s %#D", str
, udr
);
5123 str
= get_spaces (str
);
5125 ambiguous
.release ();
5126 ret
= error_mark_node
;
5127 baselink
= NULL_TREE
;
5132 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5133 id
, id
, tf_warning_or_error
);
5137 /* Helper function for cp_parser_omp_declare_reduction_exprs
5139 Remove CLEANUP_STMT for data (omp_priv variable).
5140 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5144 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5148 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5149 *tp
= CLEANUP_BODY (*tp
);
5150 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5152 tree decl
= DECL_EXPR_DECL (*tp
);
5153 if (!processing_template_decl
5154 && decl
== (tree
) data
5155 && DECL_INITIAL (decl
)
5156 && DECL_INITIAL (decl
) != error_mark_node
)
5158 tree list
= NULL_TREE
;
5159 append_to_statement_list_force (*tp
, &list
);
5160 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5161 decl
, DECL_INITIAL (decl
));
5162 DECL_INITIAL (decl
) = NULL_TREE
;
5163 append_to_statement_list_force (init_expr
, &list
);
5170 /* Data passed from cp_check_omp_declare_reduction to
5171 cp_check_omp_declare_reduction_r. */
5173 struct cp_check_omp_declare_reduction_data
5180 /* Helper function for cp_check_omp_declare_reduction, called via
5184 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5186 struct cp_check_omp_declare_reduction_data
*udr_data
5187 = (struct cp_check_omp_declare_reduction_data
*) data
;
5189 && !DECL_ARTIFICIAL (*tp
)
5190 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5191 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5193 location_t loc
= udr_data
->loc
;
5194 if (udr_data
->combiner_p
)
5195 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5196 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5199 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5200 "to variable %qD which is not %<omp_priv%> nor "
5208 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5211 cp_check_omp_declare_reduction (tree udr
)
5213 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5214 gcc_assert (TREE_CODE (type
) == REFERENCE_TYPE
);
5215 type
= TREE_TYPE (type
);
5217 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5219 if (type
== error_mark_node
)
5221 if (ARITHMETIC_TYPE_P (type
))
5223 static enum tree_code predef_codes
[]
5224 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5225 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5226 for (i
= 0; i
< 8; i
++)
5228 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5229 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5230 const char *n2
= IDENTIFIER_POINTER (id
);
5231 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5232 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5233 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5238 && TREE_CODE (type
) != COMPLEX_EXPR
)
5240 const char prefix_minmax
[] = "omp declare reduction m";
5241 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5242 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5243 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5244 prefix_minmax
, prefix_size
) == 0
5245 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5246 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5247 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5252 error_at (loc
, "predeclared arithmetic type %qT in "
5253 "%<#pragma omp declare reduction%>", type
);
5257 else if (TREE_CODE (type
) == FUNCTION_TYPE
5258 || TREE_CODE (type
) == METHOD_TYPE
5259 || TREE_CODE (type
) == ARRAY_TYPE
)
5261 error_at (loc
, "function or array type %qT in "
5262 "%<#pragma omp declare reduction%>", type
);
5265 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
5267 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5271 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5273 error_at (loc
, "const, volatile or __restrict qualified type %qT in "
5274 "%<#pragma omp declare reduction%>", type
);
5278 tree body
= DECL_SAVED_TREE (udr
);
5279 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5282 tree_stmt_iterator tsi
;
5283 struct cp_check_omp_declare_reduction_data data
;
5284 memset (data
.stmts
, 0, sizeof data
.stmts
);
5285 for (i
= 0, tsi
= tsi_start (body
);
5286 i
< 7 && !tsi_end_p (tsi
);
5287 i
++, tsi_next (&tsi
))
5288 data
.stmts
[i
] = tsi_stmt (tsi
);
5290 gcc_assert (tsi_end_p (tsi
));
5293 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5294 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5295 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5297 data
.combiner_p
= true;
5298 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5300 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5304 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5305 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5306 data
.combiner_p
= false;
5307 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5309 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5310 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5311 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5313 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5317 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5318 an inline call. But, remap
5319 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5320 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5323 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5324 tree decl
, tree placeholder
)
5327 hash_map
<tree
, tree
> decl_map
;
5329 decl_map
.put (omp_decl1
, placeholder
);
5330 decl_map
.put (omp_decl2
, decl
);
5331 memset (&id
, 0, sizeof (id
));
5332 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5333 id
.dst_fn
= current_function_decl
;
5334 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5335 id
.decl_map
= &decl_map
;
5337 id
.copy_decl
= copy_decl_no_change
;
5338 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5339 id
.transform_new_cfg
= true;
5340 id
.transform_return_to_modify
= false;
5341 id
.transform_lang_insert_block
= NULL
;
5343 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5347 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5348 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5351 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5353 if (*tp
== (tree
) data
)
5358 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5359 Return true if there is some error and the clause should be removed. */
5362 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5364 tree t
= OMP_CLAUSE_DECL (c
);
5365 bool predefined
= false;
5366 if (TREE_CODE (t
) == TREE_LIST
)
5368 gcc_assert (processing_template_decl
);
5371 tree type
= TREE_TYPE (t
);
5372 if (TREE_CODE (t
) == MEM_REF
)
5373 type
= TREE_TYPE (type
);
5374 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5375 type
= TREE_TYPE (type
);
5376 if (TREE_CODE (type
) == ARRAY_TYPE
)
5379 gcc_assert (TREE_CODE (t
) != MEM_REF
);
5380 while (TREE_CODE (type
) == ARRAY_TYPE
)
5381 type
= TREE_TYPE (type
);
5382 if (!processing_template_decl
)
5384 t
= require_complete_type (t
);
5385 if (t
== error_mark_node
)
5387 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
5388 TYPE_SIZE_UNIT (type
));
5389 if (integer_zerop (size
))
5391 error ("%qE in %<reduction%> clause is a zero size array",
5392 omp_clause_printable_decl (t
));
5395 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5396 tree index_type
= build_index_type (size
);
5397 tree atype
= build_array_type (type
, index_type
);
5398 tree ptype
= build_pointer_type (type
);
5399 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5400 t
= build_fold_addr_expr (t
);
5401 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
5402 OMP_CLAUSE_DECL (c
) = t
;
5405 if (type
== error_mark_node
)
5407 else if (ARITHMETIC_TYPE_P (type
))
5408 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5417 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5424 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5428 case TRUTH_ANDIF_EXPR
:
5429 case TRUTH_ORIF_EXPR
:
5430 if (FLOAT_TYPE_P (type
))
5437 else if (TYPE_READONLY (type
))
5439 error ("%qE has const type for %<reduction%>",
5440 omp_clause_printable_decl (t
));
5443 else if (!processing_template_decl
)
5445 t
= require_complete_type (t
);
5446 if (t
== error_mark_node
)
5448 OMP_CLAUSE_DECL (c
) = t
;
5453 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5456 else if (processing_template_decl
)
5459 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5461 type
= TYPE_MAIN_VARIANT (type
);
5462 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5463 if (id
== NULL_TREE
)
5464 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5465 NULL_TREE
, NULL_TREE
);
5466 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5469 if (id
== error_mark_node
)
5471 id
= OVL_CURRENT (id
);
5473 tree body
= DECL_SAVED_TREE (id
);
5476 if (TREE_CODE (body
) == STATEMENT_LIST
)
5478 tree_stmt_iterator tsi
;
5479 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
5482 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5483 atype
= TREE_TYPE (atype
);
5484 bool need_static_cast
= !same_type_p (type
, atype
);
5485 memset (stmts
, 0, sizeof stmts
);
5486 for (i
= 0, tsi
= tsi_start (body
);
5487 i
< 7 && !tsi_end_p (tsi
);
5488 i
++, tsi_next (&tsi
))
5489 stmts
[i
] = tsi_stmt (tsi
);
5490 gcc_assert (tsi_end_p (tsi
));
5494 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
5495 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
5496 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
5497 DECL_ARTIFICIAL (placeholder
) = 1;
5498 DECL_IGNORED_P (placeholder
) = 1;
5499 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
5500 if (TREE_CODE (t
) == MEM_REF
)
5502 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
5504 DECL_ARTIFICIAL (decl_placeholder
) = 1;
5505 DECL_IGNORED_P (decl_placeholder
) = 1;
5506 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
5508 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
5509 cxx_mark_addressable (placeholder
);
5510 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
5511 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
5513 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5514 : OMP_CLAUSE_DECL (c
));
5515 tree omp_out
= placeholder
;
5516 tree omp_in
= decl_placeholder
? decl_placeholder
5517 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5518 if (need_static_cast
)
5520 tree rtype
= build_reference_type (atype
);
5521 omp_out
= build_static_cast (rtype
, omp_out
,
5522 tf_warning_or_error
);
5523 omp_in
= build_static_cast (rtype
, omp_in
,
5524 tf_warning_or_error
);
5525 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
5527 omp_out
= convert_from_reference (omp_out
);
5528 omp_in
= convert_from_reference (omp_in
);
5530 OMP_CLAUSE_REDUCTION_MERGE (c
)
5531 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
5532 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
5536 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
5537 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
5538 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3])))
5539 cxx_mark_addressable (decl_placeholder
? decl_placeholder
5540 : OMP_CLAUSE_DECL (c
));
5541 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
5542 cxx_mark_addressable (placeholder
);
5543 tree omp_priv
= decl_placeholder
? decl_placeholder
5544 : convert_from_reference (OMP_CLAUSE_DECL (c
));
5545 tree omp_orig
= placeholder
;
5546 if (need_static_cast
)
5550 error_at (OMP_CLAUSE_LOCATION (c
),
5551 "user defined reduction with constructor "
5552 "initializer for base class %qT", atype
);
5555 tree rtype
= build_reference_type (atype
);
5556 omp_priv
= build_static_cast (rtype
, omp_priv
,
5557 tf_warning_or_error
);
5558 omp_orig
= build_static_cast (rtype
, omp_orig
,
5559 tf_warning_or_error
);
5560 if (omp_priv
== error_mark_node
5561 || omp_orig
== error_mark_node
)
5563 omp_priv
= convert_from_reference (omp_priv
);
5564 omp_orig
= convert_from_reference (omp_orig
);
5567 *need_default_ctor
= true;
5568 OMP_CLAUSE_REDUCTION_INIT (c
)
5569 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
5570 DECL_EXPR_DECL (stmts
[3]),
5571 omp_priv
, omp_orig
);
5572 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
5573 find_omp_placeholder_r
, placeholder
, NULL
))
5574 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
5578 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
5579 *need_default_ctor
= true;
5583 tree v
= decl_placeholder
? decl_placeholder
5584 : convert_from_reference (t
);
5585 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
5586 init
= build_constructor (TREE_TYPE (v
), NULL
);
5588 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
5589 OMP_CLAUSE_REDUCTION_INIT (c
)
5590 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
5595 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5599 error ("user defined reduction not found for %qE",
5600 omp_clause_printable_decl (t
));
5603 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
5604 gcc_assert (TYPE_SIZE_UNIT (type
)
5605 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
5609 /* Called from finish_struct_1. linear(this) or linear(this:step)
5610 clauses might not be finalized yet because the class has been incomplete
5611 when parsing #pragma omp declare simd methods. Fix those up now. */
5614 finish_omp_declare_simd_methods (tree t
)
5616 if (processing_template_decl
)
5619 for (tree x
= TYPE_METHODS (t
); x
; x
= DECL_CHAIN (x
))
5621 if (TREE_CODE (TREE_TYPE (x
)) != METHOD_TYPE
)
5623 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
5624 if (!ods
|| !TREE_VALUE (ods
))
5626 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
5627 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
5628 && integer_zerop (OMP_CLAUSE_DECL (c
))
5629 && OMP_CLAUSE_LINEAR_STEP (c
)
5630 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
)))
5633 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
5634 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
5635 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
5636 sizetype
, s
, TYPE_SIZE_UNIT (t
));
5637 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
5642 /* Adjust sink depend clause to take into account pointer offsets.
5644 Return TRUE if there was a problem processing the offset, and the
5645 whole clause should be removed. */
5648 cp_finish_omp_clause_depend_sink (tree sink_clause
)
5650 tree t
= OMP_CLAUSE_DECL (sink_clause
);
5651 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
5653 /* Make sure we don't adjust things twice for templates. */
5654 if (processing_template_decl
)
5657 for (; t
; t
= TREE_CHAIN (t
))
5659 tree decl
= TREE_VALUE (t
);
5660 if (TREE_CODE (TREE_TYPE (decl
)) == POINTER_TYPE
)
5662 tree offset
= TREE_PURPOSE (t
);
5663 bool neg
= wi::neg_p ((wide_int
) offset
);
5664 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
5665 decl
= mark_rvalue_use (decl
);
5666 decl
= convert_from_reference (decl
);
5667 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
5668 neg
? MINUS_EXPR
: PLUS_EXPR
,
5670 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
5671 MINUS_EXPR
, sizetype
,
5672 fold_convert (sizetype
, t2
),
5673 fold_convert (sizetype
, decl
));
5674 if (t2
== error_mark_node
)
5676 TREE_PURPOSE (t
) = t2
;
5682 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
5683 Remove any elements from the list that are invalid. */
5686 finish_omp_clauses (tree clauses
, bool allow_fields
, bool declare_simd
)
5688 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
5689 bitmap_head aligned_head
, map_head
, map_field_head
;
5691 tree safelen
= NULL_TREE
;
5692 bool branch_seen
= false;
5693 bool copyprivate_seen
= false;
5694 bool ordered_seen
= false;
5696 bitmap_obstack_initialize (NULL
);
5697 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
5698 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
5699 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
5700 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
5701 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
5702 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
5704 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
5706 bool remove
= false;
5707 bool field_ok
= false;
5709 switch (OMP_CLAUSE_CODE (c
))
5711 case OMP_CLAUSE_SHARED
:
5712 field_ok
= allow_fields
;
5713 goto check_dup_generic
;
5714 case OMP_CLAUSE_PRIVATE
:
5715 field_ok
= allow_fields
;
5716 goto check_dup_generic
;
5717 case OMP_CLAUSE_REDUCTION
:
5718 field_ok
= allow_fields
;
5719 t
= OMP_CLAUSE_DECL (c
);
5720 if (TREE_CODE (t
) == TREE_LIST
)
5722 if (handle_omp_array_sections (c
, allow_fields
))
5727 if (TREE_CODE (t
) == TREE_LIST
)
5729 while (TREE_CODE (t
) == TREE_LIST
)
5734 gcc_assert (TREE_CODE (t
) == MEM_REF
);
5735 t
= TREE_OPERAND (t
, 0);
5736 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
5737 t
= TREE_OPERAND (t
, 0);
5738 if (TREE_CODE (t
) == ADDR_EXPR
5739 || TREE_CODE (t
) == INDIRECT_REF
)
5740 t
= TREE_OPERAND (t
, 0);
5742 tree n
= omp_clause_decl_field (t
);
5745 goto check_dup_generic_t
;
5747 goto check_dup_generic
;
5748 case OMP_CLAUSE_COPYPRIVATE
:
5749 copyprivate_seen
= true;
5750 field_ok
= allow_fields
;
5751 goto check_dup_generic
;
5752 case OMP_CLAUSE_COPYIN
:
5753 goto check_dup_generic
;
5754 case OMP_CLAUSE_LINEAR
:
5755 field_ok
= allow_fields
;
5756 t
= OMP_CLAUSE_DECL (c
);
5758 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
5760 error_at (OMP_CLAUSE_LOCATION (c
),
5761 "modifier should not be specified in %<linear%> "
5762 "clause on %<simd%> or %<for%> constructs");
5763 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
5765 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
5766 && !type_dependent_expression_p (t
))
5768 tree type
= TREE_TYPE (t
);
5769 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5770 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
5771 && TREE_CODE (type
) != REFERENCE_TYPE
)
5773 error ("linear clause with %qs modifier applied to "
5774 "non-reference variable with %qT type",
5775 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
5776 ? "ref" : "uval", TREE_TYPE (t
));
5780 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5781 type
= TREE_TYPE (type
);
5782 if (!INTEGRAL_TYPE_P (type
)
5783 && TREE_CODE (type
) != POINTER_TYPE
)
5785 error ("linear clause applied to non-integral non-pointer "
5786 "variable with %qT type", TREE_TYPE (t
));
5791 t
= OMP_CLAUSE_LINEAR_STEP (c
);
5793 t
= integer_one_node
;
5794 if (t
== error_mark_node
)
5799 else if (!type_dependent_expression_p (t
)
5800 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
5802 || TREE_CODE (t
) != PARM_DECL
5803 || TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
5804 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
5806 error ("linear step expression must be integral");
5812 t
= mark_rvalue_use (t
);
5813 if (declare_simd
&& TREE_CODE (t
) == PARM_DECL
)
5815 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
5816 goto check_dup_generic
;
5818 if (!processing_template_decl
5819 && (VAR_P (OMP_CLAUSE_DECL (c
))
5820 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
5824 t
= maybe_constant_value (t
);
5825 if (TREE_CODE (t
) != INTEGER_CST
)
5827 error_at (OMP_CLAUSE_LOCATION (c
),
5828 "%<linear%> clause step %qE is neither "
5829 "constant nor a parameter", t
);
5834 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5835 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
5836 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5837 type
= TREE_TYPE (type
);
5838 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
5840 type
= build_pointer_type (type
);
5841 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
5842 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
5844 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
5845 MINUS_EXPR
, sizetype
,
5846 fold_convert (sizetype
, t
),
5847 fold_convert (sizetype
, d
));
5848 if (t
== error_mark_node
)
5854 else if (TREE_CODE (type
) == POINTER_TYPE
5855 /* Can't multiply the step yet if *this
5856 is still incomplete type. */
5858 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
5859 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
5860 || DECL_NAME (OMP_CLAUSE_DECL (c
))
5862 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
5864 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
5865 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
5867 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
5868 MINUS_EXPR
, sizetype
,
5869 fold_convert (sizetype
, t
),
5870 fold_convert (sizetype
, d
));
5871 if (t
== error_mark_node
)
5878 t
= fold_convert (type
, t
);
5880 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
5882 goto check_dup_generic
;
5884 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
5887 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
5888 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
5891 t
= OMP_CLAUSE_DECL (c
);
5892 check_dup_generic_t
:
5893 if (t
== current_class_ptr
5895 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
5896 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
5898 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
5903 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
5904 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
5906 if (processing_template_decl
)
5909 error ("%qD is not a variable in clause %qs", t
,
5910 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5912 error ("%qE is not a variable in clause %qs", t
,
5913 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5916 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
5917 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
5918 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
5920 error ("%qD appears more than once in data clauses", t
);
5923 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
5924 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
5926 error ("%qD appears both in data and map clauses", t
);
5930 bitmap_set_bit (&generic_head
, DECL_UID (t
));
5935 && TREE_CODE (t
) == FIELD_DECL
5936 && t
== OMP_CLAUSE_DECL (c
))
5939 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
5940 == OMP_CLAUSE_SHARED
));
5941 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
5946 case OMP_CLAUSE_FIRSTPRIVATE
:
5947 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
5949 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
5951 t
= OMP_CLAUSE_DECL (c
);
5952 if (t
== current_class_ptr
)
5954 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
5959 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
5960 && (!allow_fields
|| TREE_CODE (t
) != FIELD_DECL
))
5962 if (processing_template_decl
)
5965 error ("%qD is not a variable in clause %<firstprivate%>", t
);
5967 error ("%qE is not a variable in clause %<firstprivate%>", t
);
5970 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
5971 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
5973 error ("%qD appears more than once in data clauses", t
);
5976 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
5978 error ("%qD appears both in data and map clauses", t
);
5982 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
5983 goto handle_field_decl
;
5985 case OMP_CLAUSE_LASTPRIVATE
:
5986 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
5988 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
5990 t
= OMP_CLAUSE_DECL (c
);
5991 if (t
== current_class_ptr
)
5993 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
5998 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
5999 && (!allow_fields
|| TREE_CODE (t
) != FIELD_DECL
))
6001 if (processing_template_decl
)
6004 error ("%qD is not a variable in clause %<lastprivate%>", t
);
6006 error ("%qE is not a variable in clause %<lastprivate%>", t
);
6009 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6010 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
6012 error ("%qD appears more than once in data clauses", t
);
6016 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
6017 goto handle_field_decl
;
6020 t
= OMP_CLAUSE_IF_EXPR (c
);
6021 t
= maybe_convert_cond (t
);
6022 if (t
== error_mark_node
)
6024 else if (!processing_template_decl
)
6025 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6026 OMP_CLAUSE_IF_EXPR (c
) = t
;
6029 case OMP_CLAUSE_FINAL
:
6030 t
= OMP_CLAUSE_FINAL_EXPR (c
);
6031 t
= maybe_convert_cond (t
);
6032 if (t
== error_mark_node
)
6034 else if (!processing_template_decl
)
6035 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6036 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
6039 case OMP_CLAUSE_GANG
:
6040 /* Operand 1 is the gang static: argument. */
6041 t
= OMP_CLAUSE_OPERAND (c
, 1);
6044 if (t
== error_mark_node
)
6046 else if (!type_dependent_expression_p (t
)
6047 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6049 error ("%<gang%> static expression must be integral");
6054 t
= mark_rvalue_use (t
);
6055 if (!processing_template_decl
)
6057 t
= maybe_constant_value (t
);
6058 if (TREE_CODE (t
) == INTEGER_CST
6059 && tree_int_cst_sgn (t
) != 1
6060 && t
!= integer_minus_one_node
)
6062 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6063 "%<gang%> static value must be"
6065 t
= integer_one_node
;
6068 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6070 OMP_CLAUSE_OPERAND (c
, 1) = t
;
6072 /* Check operand 0, the num argument. */
6074 case OMP_CLAUSE_WORKER
:
6075 case OMP_CLAUSE_VECTOR
:
6076 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
6079 case OMP_CLAUSE_NUM_TASKS
:
6080 case OMP_CLAUSE_NUM_TEAMS
:
6081 case OMP_CLAUSE_NUM_THREADS
:
6082 case OMP_CLAUSE_NUM_GANGS
:
6083 case OMP_CLAUSE_NUM_WORKERS
:
6084 case OMP_CLAUSE_VECTOR_LENGTH
:
6085 t
= OMP_CLAUSE_OPERAND (c
, 0);
6086 if (t
== error_mark_node
)
6088 else if (!type_dependent_expression_p (t
)
6089 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6091 switch (OMP_CLAUSE_CODE (c
))
6093 case OMP_CLAUSE_GANG
:
6094 error_at (OMP_CLAUSE_LOCATION (c
),
6095 "%<gang%> num expression must be integral"); break;
6096 case OMP_CLAUSE_VECTOR
:
6097 error_at (OMP_CLAUSE_LOCATION (c
),
6098 "%<vector%> length expression must be integral");
6100 case OMP_CLAUSE_WORKER
:
6101 error_at (OMP_CLAUSE_LOCATION (c
),
6102 "%<worker%> num expression must be integral");
6105 error_at (OMP_CLAUSE_LOCATION (c
),
6106 "%qs expression must be integral",
6107 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6113 t
= mark_rvalue_use (t
);
6114 if (!processing_template_decl
)
6116 t
= maybe_constant_value (t
);
6117 if (TREE_CODE (t
) == INTEGER_CST
6118 && tree_int_cst_sgn (t
) != 1)
6120 switch (OMP_CLAUSE_CODE (c
))
6122 case OMP_CLAUSE_GANG
:
6123 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6124 "%<gang%> num value must be positive");
6126 case OMP_CLAUSE_VECTOR
:
6127 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6128 "%<vector%> length value must be"
6131 case OMP_CLAUSE_WORKER
:
6132 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6133 "%<worker%> num value must be"
6137 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6138 "%qs value must be positive",
6139 omp_clause_code_name
6140 [OMP_CLAUSE_CODE (c
)]);
6142 t
= integer_one_node
;
6144 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6146 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6150 case OMP_CLAUSE_SCHEDULE
:
6151 if (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
)
6153 const char *p
= NULL
;
6154 switch (OMP_CLAUSE_SCHEDULE_KIND (c
) & OMP_CLAUSE_SCHEDULE_MASK
)
6156 case OMP_CLAUSE_SCHEDULE_STATIC
: p
= "static"; break;
6157 case OMP_CLAUSE_SCHEDULE_DYNAMIC
: break;
6158 case OMP_CLAUSE_SCHEDULE_GUIDED
: break;
6159 case OMP_CLAUSE_SCHEDULE_AUTO
: p
= "auto"; break;
6160 case OMP_CLAUSE_SCHEDULE_RUNTIME
: p
= "runtime"; break;
6161 default: gcc_unreachable ();
6165 error_at (OMP_CLAUSE_LOCATION (c
),
6166 "%<nonmonotonic%> modifier specified for %qs "
6167 "schedule kind", p
);
6168 OMP_CLAUSE_SCHEDULE_KIND (c
)
6169 = (enum omp_clause_schedule_kind
)
6170 (OMP_CLAUSE_SCHEDULE_KIND (c
)
6171 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
6175 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
6178 else if (t
== error_mark_node
)
6180 else if (!type_dependent_expression_p (t
)
6181 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
6182 != OMP_CLAUSE_SCHEDULE_CILKFOR
)
6183 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6185 error ("schedule chunk size expression must be integral");
6190 t
= mark_rvalue_use (t
);
6191 if (!processing_template_decl
)
6193 if (OMP_CLAUSE_SCHEDULE_KIND (c
)
6194 == OMP_CLAUSE_SCHEDULE_CILKFOR
)
6196 t
= convert_to_integer (long_integer_type_node
, t
);
6197 if (t
== error_mark_node
)
6203 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6205 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
6209 case OMP_CLAUSE_SIMDLEN
:
6210 case OMP_CLAUSE_SAFELEN
:
6211 t
= OMP_CLAUSE_OPERAND (c
, 0);
6212 if (t
== error_mark_node
)
6214 else if (!type_dependent_expression_p (t
)
6215 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6217 error ("%qs length expression must be integral",
6218 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6223 t
= mark_rvalue_use (t
);
6224 t
= maybe_constant_value (t
);
6225 if (!processing_template_decl
)
6227 if (TREE_CODE (t
) != INTEGER_CST
6228 || tree_int_cst_sgn (t
) != 1)
6230 error ("%qs length expression must be positive constant"
6231 " integer expression",
6232 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6236 OMP_CLAUSE_OPERAND (c
, 0) = t
;
6237 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
6242 case OMP_CLAUSE_ASYNC
:
6243 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
6244 if (t
== error_mark_node
)
6246 else if (!type_dependent_expression_p (t
)
6247 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6249 error ("%<async%> expression must be integral");
6254 t
= mark_rvalue_use (t
);
6255 if (!processing_template_decl
)
6256 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6257 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
6261 case OMP_CLAUSE_WAIT
:
6262 t
= OMP_CLAUSE_WAIT_EXPR (c
);
6263 if (t
== error_mark_node
)
6265 else if (!processing_template_decl
)
6266 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6267 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
6270 case OMP_CLAUSE_THREAD_LIMIT
:
6271 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
6272 if (t
== error_mark_node
)
6274 else if (!type_dependent_expression_p (t
)
6275 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6277 error ("%<thread_limit%> expression must be integral");
6282 t
= mark_rvalue_use (t
);
6283 if (!processing_template_decl
)
6285 t
= maybe_constant_value (t
);
6286 if (TREE_CODE (t
) == INTEGER_CST
6287 && tree_int_cst_sgn (t
) != 1)
6289 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6290 "%<thread_limit%> value must be positive");
6291 t
= integer_one_node
;
6293 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6295 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
6299 case OMP_CLAUSE_DEVICE
:
6300 t
= OMP_CLAUSE_DEVICE_ID (c
);
6301 if (t
== error_mark_node
)
6303 else if (!type_dependent_expression_p (t
)
6304 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6306 error ("%<device%> id must be integral");
6311 t
= mark_rvalue_use (t
);
6312 if (!processing_template_decl
)
6313 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6314 OMP_CLAUSE_DEVICE_ID (c
) = t
;
6318 case OMP_CLAUSE_DIST_SCHEDULE
:
6319 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
6322 else if (t
== error_mark_node
)
6324 else if (!type_dependent_expression_p (t
)
6325 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6327 error ("%<dist_schedule%> chunk size expression must be "
6333 t
= mark_rvalue_use (t
);
6334 if (!processing_template_decl
)
6335 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6336 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
6340 case OMP_CLAUSE_ALIGNED
:
6341 t
= OMP_CLAUSE_DECL (c
);
6342 if (t
== current_class_ptr
&& !declare_simd
)
6344 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6349 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6351 if (processing_template_decl
)
6354 error ("%qD is not a variable in %<aligned%> clause", t
);
6356 error ("%qE is not a variable in %<aligned%> clause", t
);
6359 else if (!type_dependent_expression_p (t
)
6360 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
6361 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
6362 && (TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6363 || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
6364 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
6367 error_at (OMP_CLAUSE_LOCATION (c
),
6368 "%qE in %<aligned%> clause is neither a pointer nor "
6369 "an array nor a reference to pointer or array", t
);
6372 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
6374 error ("%qD appears more than once in %<aligned%> clauses", t
);
6378 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
6379 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
6380 if (t
== error_mark_node
)
6382 else if (t
== NULL_TREE
)
6384 else if (!type_dependent_expression_p (t
)
6385 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6387 error ("%<aligned%> clause alignment expression must "
6393 t
= mark_rvalue_use (t
);
6394 t
= maybe_constant_value (t
);
6395 if (!processing_template_decl
)
6397 if (TREE_CODE (t
) != INTEGER_CST
6398 || tree_int_cst_sgn (t
) != 1)
6400 error ("%<aligned%> clause alignment expression must be "
6401 "positive constant integer expression");
6405 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
6409 case OMP_CLAUSE_DEPEND
:
6410 t
= OMP_CLAUSE_DECL (c
);
6413 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
6414 == OMP_CLAUSE_DEPEND_SOURCE
);
6417 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
6419 if (cp_finish_omp_clause_depend_sink (c
))
6423 if (TREE_CODE (t
) == TREE_LIST
)
6425 if (handle_omp_array_sections (c
, allow_fields
))
6429 if (t
== error_mark_node
)
6431 else if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6433 if (processing_template_decl
)
6436 error ("%qD is not a variable in %<depend%> clause", t
);
6438 error ("%qE is not a variable in %<depend%> clause", t
);
6441 else if (t
== current_class_ptr
)
6443 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6447 else if (!processing_template_decl
6448 && !cxx_mark_addressable (t
))
6452 case OMP_CLAUSE_MAP
:
6454 case OMP_CLAUSE_FROM
:
6455 case OMP_CLAUSE__CACHE_
:
6456 t
= OMP_CLAUSE_DECL (c
);
6457 if (TREE_CODE (t
) == TREE_LIST
)
6459 if (handle_omp_array_sections (c
, allow_fields
))
6463 t
= OMP_CLAUSE_DECL (c
);
6464 if (TREE_CODE (t
) != TREE_LIST
6465 && !type_dependent_expression_p (t
)
6466 && !cp_omp_mappable_type (TREE_TYPE (t
)))
6468 error_at (OMP_CLAUSE_LOCATION (c
),
6469 "array section does not have mappable type "
6471 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6474 while (TREE_CODE (t
) == ARRAY_REF
)
6475 t
= TREE_OPERAND (t
, 0);
6476 if (TREE_CODE (t
) == COMPONENT_REF
6477 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6479 while (TREE_CODE (t
) == COMPONENT_REF
)
6480 t
= TREE_OPERAND (t
, 0);
6481 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6483 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6485 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6486 error ("%qD appears more than once in motion"
6489 error ("%qD appears more than once in map"
6495 bitmap_set_bit (&map_head
, DECL_UID (t
));
6496 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6502 if (t
== error_mark_node
)
6507 if (REFERENCE_REF_P (t
)
6508 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
6510 t
= TREE_OPERAND (t
, 0);
6511 OMP_CLAUSE_DECL (c
) = t
;
6513 if (TREE_CODE (t
) == COMPONENT_REF
6515 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
6517 if (type_dependent_expression_p (t
))
6519 if (DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
6521 error_at (OMP_CLAUSE_LOCATION (c
),
6522 "bit-field %qE in %qs clause",
6523 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6526 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6528 error_at (OMP_CLAUSE_LOCATION (c
),
6529 "%qE does not have a mappable type in %qs clause",
6530 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6533 while (TREE_CODE (t
) == COMPONENT_REF
)
6535 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
6538 error_at (OMP_CLAUSE_LOCATION (c
),
6539 "%qE is a member of a union", t
);
6543 t
= TREE_OPERAND (t
, 0);
6547 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6549 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
6550 goto handle_map_references
;
6553 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
6555 if (processing_template_decl
)
6557 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6558 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6559 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
))
6562 error ("%qD is not a variable in %qs clause", t
,
6563 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6565 error ("%qE is not a variable in %qs clause", t
,
6566 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6569 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
6571 error ("%qD is threadprivate variable in %qs clause", t
,
6572 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6575 else if (t
== current_class_ptr
)
6577 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6582 else if (!processing_template_decl
6583 && TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
6584 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
6585 || (OMP_CLAUSE_MAP_KIND (c
)
6586 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
6587 && !cxx_mark_addressable (t
))
6589 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6590 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
6591 || (OMP_CLAUSE_MAP_KIND (c
)
6592 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
6593 && t
== OMP_CLAUSE_DECL (c
)
6594 && !type_dependent_expression_p (t
)
6595 && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t
))
6597 ? TREE_TYPE (TREE_TYPE (t
))
6600 error_at (OMP_CLAUSE_LOCATION (c
),
6601 "%qD does not have a mappable type in %qs clause", t
,
6602 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6605 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
6606 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
6608 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6609 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6611 error ("%qD appears more than once in data clauses", t
);
6614 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6616 error ("%qD appears both in data and map clauses", t
);
6620 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6622 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
6624 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6625 error ("%qD appears more than once in motion clauses", t
);
6627 error ("%qD appears more than once in map clauses", t
);
6630 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6631 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
6633 error ("%qD appears both in data and map clauses", t
);
6638 bitmap_set_bit (&map_head
, DECL_UID (t
));
6639 if (t
!= OMP_CLAUSE_DECL (c
)
6640 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
6641 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
6643 handle_map_references
:
6645 && !processing_template_decl
6647 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
))) == REFERENCE_TYPE
)
6649 t
= OMP_CLAUSE_DECL (c
);
6650 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6652 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6653 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6655 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6657 else if (OMP_CLAUSE_MAP_KIND (c
)
6658 != GOMP_MAP_FIRSTPRIVATE_POINTER
6659 && (OMP_CLAUSE_MAP_KIND (c
)
6660 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
6661 && (OMP_CLAUSE_MAP_KIND (c
)
6662 != GOMP_MAP_ALWAYS_POINTER
))
6664 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
6666 if (TREE_CODE (t
) == COMPONENT_REF
)
6667 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
6669 OMP_CLAUSE_SET_MAP_KIND (c2
,
6670 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
6671 OMP_CLAUSE_DECL (c2
) = t
;
6672 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
6673 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
6674 OMP_CLAUSE_CHAIN (c
) = c2
;
6675 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
6676 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
6678 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
6684 case OMP_CLAUSE_TO_DECLARE
:
6685 case OMP_CLAUSE_LINK
:
6686 t
= OMP_CLAUSE_DECL (c
);
6687 if (TREE_CODE (t
) == FUNCTION_DECL
6688 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6690 else if (!VAR_P (t
))
6692 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
6694 if (TREE_CODE (t
) == OVERLOAD
&& OVL_CHAIN (t
))
6695 error_at (OMP_CLAUSE_LOCATION (c
),
6696 "overloaded function name %qE in clause %qs", t
,
6697 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6698 else if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
6699 error_at (OMP_CLAUSE_LOCATION (c
),
6700 "template %qE in clause %qs", t
,
6701 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6703 error_at (OMP_CLAUSE_LOCATION (c
),
6704 "%qE is neither a variable nor a function name "
6706 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6709 error_at (OMP_CLAUSE_LOCATION (c
),
6710 "%qE is not a variable in clause %qs", t
,
6711 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6714 else if (DECL_THREAD_LOCAL_P (t
))
6716 error_at (OMP_CLAUSE_LOCATION (c
),
6717 "%qD is threadprivate variable in %qs clause", t
,
6718 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6721 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
6723 error_at (OMP_CLAUSE_LOCATION (c
),
6724 "%qD does not have a mappable type in %qs clause", t
,
6725 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6730 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
6732 error_at (OMP_CLAUSE_LOCATION (c
),
6733 "%qE appears more than once on the same "
6734 "%<declare target%> directive", t
);
6738 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6741 case OMP_CLAUSE_UNIFORM
:
6742 t
= OMP_CLAUSE_DECL (c
);
6743 if (TREE_CODE (t
) != PARM_DECL
)
6745 if (processing_template_decl
)
6748 error ("%qD is not an argument in %<uniform%> clause", t
);
6750 error ("%qE is not an argument in %<uniform%> clause", t
);
6754 /* map_head bitmap is used as uniform_head if declare_simd. */
6755 bitmap_set_bit (&map_head
, DECL_UID (t
));
6756 goto check_dup_generic
;
6758 case OMP_CLAUSE_GRAINSIZE
:
6759 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
6760 if (t
== error_mark_node
)
6762 else if (!type_dependent_expression_p (t
)
6763 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6765 error ("%<grainsize%> expression must be integral");
6770 t
= mark_rvalue_use (t
);
6771 if (!processing_template_decl
)
6773 t
= maybe_constant_value (t
);
6774 if (TREE_CODE (t
) == INTEGER_CST
6775 && tree_int_cst_sgn (t
) != 1)
6777 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6778 "%<grainsize%> value must be positive");
6779 t
= integer_one_node
;
6781 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6783 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
6787 case OMP_CLAUSE_PRIORITY
:
6788 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
6789 if (t
== error_mark_node
)
6791 else if (!type_dependent_expression_p (t
)
6792 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6794 error ("%<priority%> expression must be integral");
6799 t
= mark_rvalue_use (t
);
6800 if (!processing_template_decl
)
6802 t
= maybe_constant_value (t
);
6803 if (TREE_CODE (t
) == INTEGER_CST
6804 && tree_int_cst_sgn (t
) == -1)
6806 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6807 "%<priority%> value must be non-negative");
6808 t
= integer_one_node
;
6810 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6812 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
6816 case OMP_CLAUSE_HINT
:
6817 t
= OMP_CLAUSE_HINT_EXPR (c
);
6818 if (t
== error_mark_node
)
6820 else if (!type_dependent_expression_p (t
)
6821 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6823 error ("%<num_tasks%> expression must be integral");
6828 t
= mark_rvalue_use (t
);
6829 if (!processing_template_decl
)
6831 t
= maybe_constant_value (t
);
6832 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6834 OMP_CLAUSE_HINT_EXPR (c
) = t
;
6838 case OMP_CLAUSE_IS_DEVICE_PTR
:
6839 case OMP_CLAUSE_USE_DEVICE_PTR
:
6840 field_ok
= allow_fields
;
6841 t
= OMP_CLAUSE_DECL (c
);
6842 if (!type_dependent_expression_p (t
))
6844 tree type
= TREE_TYPE (t
);
6845 if (TREE_CODE (type
) != POINTER_TYPE
6846 && TREE_CODE (type
) != ARRAY_TYPE
6847 && (TREE_CODE (type
) != REFERENCE_TYPE
6848 || (TREE_CODE (TREE_TYPE (type
)) != POINTER_TYPE
6849 && TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
)))
6851 error_at (OMP_CLAUSE_LOCATION (c
),
6852 "%qs variable is neither a pointer, nor an array"
6853 "nor reference to pointer or array",
6854 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6858 goto check_dup_generic
;
6860 case OMP_CLAUSE_NOWAIT
:
6861 case OMP_CLAUSE_DEFAULT
:
6862 case OMP_CLAUSE_UNTIED
:
6863 case OMP_CLAUSE_COLLAPSE
:
6864 case OMP_CLAUSE_MERGEABLE
:
6865 case OMP_CLAUSE_PARALLEL
:
6866 case OMP_CLAUSE_FOR
:
6867 case OMP_CLAUSE_SECTIONS
:
6868 case OMP_CLAUSE_TASKGROUP
:
6869 case OMP_CLAUSE_PROC_BIND
:
6870 case OMP_CLAUSE_NOGROUP
:
6871 case OMP_CLAUSE_THREADS
:
6872 case OMP_CLAUSE_SIMD
:
6873 case OMP_CLAUSE_DEFAULTMAP
:
6874 case OMP_CLAUSE__CILK_FOR_COUNT_
:
6875 case OMP_CLAUSE_AUTO
:
6876 case OMP_CLAUSE_INDEPENDENT
:
6877 case OMP_CLAUSE_SEQ
:
6880 case OMP_CLAUSE_TILE
:
6881 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
6882 list
= TREE_CHAIN (list
))
6884 t
= TREE_VALUE (list
);
6886 if (t
== error_mark_node
)
6888 else if (!type_dependent_expression_p (t
)
6889 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
6891 error ("%<tile%> value must be integral");
6896 t
= mark_rvalue_use (t
);
6897 if (!processing_template_decl
)
6899 t
= maybe_constant_value (t
);
6900 if (TREE_CODE (t
) == INTEGER_CST
6901 && tree_int_cst_sgn (t
) != 1
6902 && t
!= integer_minus_one_node
)
6904 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
6905 "%<tile%> value must be positive");
6906 t
= integer_one_node
;
6909 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6912 /* Update list item. */
6913 TREE_VALUE (list
) = t
;
6917 case OMP_CLAUSE_ORDERED
:
6918 ordered_seen
= true;
6921 case OMP_CLAUSE_INBRANCH
:
6922 case OMP_CLAUSE_NOTINBRANCH
:
6925 error ("%<inbranch%> clause is incompatible with "
6937 *pc
= OMP_CLAUSE_CHAIN (c
);
6939 pc
= &OMP_CLAUSE_CHAIN (c
);
6942 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
6944 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
6945 bool remove
= false;
6946 bool need_complete_type
= false;
6947 bool need_default_ctor
= false;
6948 bool need_copy_ctor
= false;
6949 bool need_copy_assignment
= false;
6950 bool need_implicitly_determined
= false;
6951 bool need_dtor
= false;
6952 tree type
, inner_type
;
6956 case OMP_CLAUSE_SHARED
:
6957 need_implicitly_determined
= true;
6959 case OMP_CLAUSE_PRIVATE
:
6960 need_complete_type
= true;
6961 need_default_ctor
= true;
6963 need_implicitly_determined
= true;
6965 case OMP_CLAUSE_FIRSTPRIVATE
:
6966 need_complete_type
= true;
6967 need_copy_ctor
= true;
6969 need_implicitly_determined
= true;
6971 case OMP_CLAUSE_LASTPRIVATE
:
6972 need_complete_type
= true;
6973 need_copy_assignment
= true;
6974 need_implicitly_determined
= true;
6976 case OMP_CLAUSE_REDUCTION
:
6977 need_implicitly_determined
= true;
6979 case OMP_CLAUSE_LINEAR
:
6981 need_implicitly_determined
= true;
6982 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
6983 && !bitmap_bit_p (&map_head
,
6984 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
6986 error_at (OMP_CLAUSE_LOCATION (c
),
6987 "%<linear%> clause step is a parameter %qD not "
6988 "specified in %<uniform%> clause",
6989 OMP_CLAUSE_LINEAR_STEP (c
));
6990 *pc
= OMP_CLAUSE_CHAIN (c
);
6994 case OMP_CLAUSE_COPYPRIVATE
:
6995 need_copy_assignment
= true;
6997 case OMP_CLAUSE_COPYIN
:
6998 need_copy_assignment
= true;
7000 case OMP_CLAUSE_SIMDLEN
:
7002 && !processing_template_decl
7003 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
7004 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
7006 error_at (OMP_CLAUSE_LOCATION (c
),
7007 "%<simdlen%> clause value is bigger than "
7008 "%<safelen%> clause value");
7009 OMP_CLAUSE_SIMDLEN_EXPR (c
)
7010 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
7012 pc
= &OMP_CLAUSE_CHAIN (c
);
7014 case OMP_CLAUSE_SCHEDULE
:
7016 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
7017 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
7019 error_at (OMP_CLAUSE_LOCATION (c
),
7020 "%<nonmonotonic%> schedule modifier specified "
7021 "together with %<ordered%> clause");
7022 OMP_CLAUSE_SCHEDULE_KIND (c
)
7023 = (enum omp_clause_schedule_kind
)
7024 (OMP_CLAUSE_SCHEDULE_KIND (c
)
7025 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
7027 pc
= &OMP_CLAUSE_CHAIN (c
);
7029 case OMP_CLAUSE_NOWAIT
:
7030 if (copyprivate_seen
)
7032 error_at (OMP_CLAUSE_LOCATION (c
),
7033 "%<nowait%> clause must not be used together "
7034 "with %<copyprivate%>");
7035 *pc
= OMP_CLAUSE_CHAIN (c
);
7040 pc
= &OMP_CLAUSE_CHAIN (c
);
7044 t
= OMP_CLAUSE_DECL (c
);
7045 if (processing_template_decl
7046 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7048 pc
= &OMP_CLAUSE_CHAIN (c
);
7054 case OMP_CLAUSE_LASTPRIVATE
:
7055 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7057 need_default_ctor
= true;
7062 case OMP_CLAUSE_REDUCTION
:
7063 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
7067 t
= OMP_CLAUSE_DECL (c
);
7070 case OMP_CLAUSE_COPYIN
:
7071 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
7073 error ("%qE must be %<threadprivate%> for %<copyin%>", t
);
7082 if (need_complete_type
|| need_copy_assignment
)
7084 t
= require_complete_type (t
);
7085 if (t
== error_mark_node
)
7087 else if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
7088 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
7091 if (need_implicitly_determined
)
7093 const char *share_name
= NULL
;
7095 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7096 share_name
= "threadprivate";
7097 else switch (cxx_omp_predetermined_sharing (t
))
7099 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
7101 case OMP_CLAUSE_DEFAULT_SHARED
:
7102 /* const vars may be specified in firstprivate clause. */
7103 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
7104 && cxx_omp_const_qual_no_mutable (t
))
7106 share_name
= "shared";
7108 case OMP_CLAUSE_DEFAULT_PRIVATE
:
7109 share_name
= "private";
7116 error ("%qE is predetermined %qs for %qs",
7117 omp_clause_printable_decl (t
), share_name
,
7118 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7123 /* We're interested in the base element, not arrays. */
7124 inner_type
= type
= TREE_TYPE (t
);
7125 if ((need_complete_type
7126 || need_copy_assignment
7127 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
7128 && TREE_CODE (inner_type
) == REFERENCE_TYPE
)
7129 inner_type
= TREE_TYPE (inner_type
);
7130 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
7131 inner_type
= TREE_TYPE (inner_type
);
7133 /* Check for special function availability by building a call to one.
7134 Save the results, because later we won't be in the right context
7135 for making these queries. */
7136 if (CLASS_TYPE_P (inner_type
)
7137 && COMPLETE_TYPE_P (inner_type
)
7138 && (need_default_ctor
|| need_copy_ctor
7139 || need_copy_assignment
|| need_dtor
)
7140 && !type_dependent_expression_p (t
)
7141 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
7142 need_copy_ctor
, need_copy_assignment
,
7147 && c_kind
== OMP_CLAUSE_SHARED
7148 && processing_template_decl
)
7150 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7152 OMP_CLAUSE_DECL (c
) = t
;
7156 *pc
= OMP_CLAUSE_CHAIN (c
);
7158 pc
= &OMP_CLAUSE_CHAIN (c
);
7161 bitmap_obstack_release (NULL
);
7165 /* Start processing OpenMP clauses that can include any
7166 privatization clauses for non-static data members. */
7169 push_omp_privatization_clauses (bool ignore_next
)
7171 if (omp_private_member_ignore_next
)
7173 omp_private_member_ignore_next
= ignore_next
;
7176 omp_private_member_ignore_next
= ignore_next
;
7177 if (omp_private_member_map
)
7178 omp_private_member_vec
.safe_push (error_mark_node
);
7179 return push_stmt_list ();
7182 /* Revert remapping of any non-static data members since
7183 the last push_omp_privatization_clauses () call. */
7186 pop_omp_privatization_clauses (tree stmt
)
7188 if (stmt
== NULL_TREE
)
7190 stmt
= pop_stmt_list (stmt
);
7191 if (omp_private_member_map
)
7193 while (!omp_private_member_vec
.is_empty ())
7195 tree t
= omp_private_member_vec
.pop ();
7196 if (t
== error_mark_node
)
7201 bool no_decl_expr
= t
== integer_zero_node
;
7203 t
= omp_private_member_vec
.pop ();
7204 tree
*v
= omp_private_member_map
->get (t
);
7208 omp_private_member_map
->remove (t
);
7210 delete omp_private_member_map
;
7211 omp_private_member_map
= NULL
;
7216 /* Remember OpenMP privatization clauses mapping and clear it.
7217 Used for lambdas. */
7220 save_omp_privatization_clauses (vec
<tree
> &save
)
7223 if (omp_private_member_ignore_next
)
7224 save
.safe_push (integer_one_node
);
7225 omp_private_member_ignore_next
= false;
7226 if (!omp_private_member_map
)
7229 while (!omp_private_member_vec
.is_empty ())
7231 tree t
= omp_private_member_vec
.pop ();
7232 if (t
== error_mark_node
)
7238 if (t
== integer_zero_node
)
7239 t
= omp_private_member_vec
.pop ();
7240 tree
*v
= omp_private_member_map
->get (t
);
7242 save
.safe_push (*v
);
7247 delete omp_private_member_map
;
7248 omp_private_member_map
= NULL
;
7251 /* Restore OpenMP privatization clauses mapping saved by the
7255 restore_omp_privatization_clauses (vec
<tree
> &save
)
7257 gcc_assert (omp_private_member_vec
.is_empty ());
7258 omp_private_member_ignore_next
= false;
7259 if (save
.is_empty ())
7261 if (save
.length () == 1 && save
[0] == integer_one_node
)
7263 omp_private_member_ignore_next
= true;
7268 omp_private_member_map
= new hash_map
<tree
, tree
>;
7269 while (!save
.is_empty ())
7271 tree t
= save
.pop ();
7273 if (t
!= error_mark_node
)
7275 if (t
== integer_one_node
)
7277 omp_private_member_ignore_next
= true;
7278 gcc_assert (save
.is_empty ());
7281 if (t
== integer_zero_node
)
7283 tree
&v
= omp_private_member_map
->get_or_insert (t
);
7286 omp_private_member_vec
.safe_push (t
);
7288 omp_private_member_vec
.safe_push (n
);
7293 /* For all variables in the tree_list VARS, mark them as thread local. */
7296 finish_omp_threadprivate (tree vars
)
7300 /* Mark every variable in VARS to be assigned thread local storage. */
7301 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
7303 tree v
= TREE_PURPOSE (t
);
7305 if (error_operand_p (v
))
7307 else if (!VAR_P (v
))
7308 error ("%<threadprivate%> %qD is not file, namespace "
7309 "or block scope variable", v
);
7310 /* If V had already been marked threadprivate, it doesn't matter
7311 whether it had been used prior to this point. */
7312 else if (TREE_USED (v
)
7313 && (DECL_LANG_SPECIFIC (v
) == NULL
7314 || !CP_DECL_THREADPRIVATE_P (v
)))
7315 error ("%qE declared %<threadprivate%> after first use", v
);
7316 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
7317 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
7318 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
7319 error ("%<threadprivate%> %qE has incomplete type", v
);
7320 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
7321 && CP_DECL_CONTEXT (v
) != current_class_type
)
7322 error ("%<threadprivate%> %qE directive not "
7323 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
7326 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
7327 if (DECL_LANG_SPECIFIC (v
) == NULL
)
7329 retrofit_lang_decl (v
);
7331 /* Make sure that DECL_DISCRIMINATOR_P continues to be true
7332 after the allocation of the lang_decl structure. */
7333 if (DECL_DISCRIMINATOR_P (v
))
7334 DECL_LANG_SPECIFIC (v
)->u
.base
.u2sel
= 1;
7337 if (! CP_DECL_THREAD_LOCAL_P (v
))
7339 CP_DECL_THREAD_LOCAL_P (v
) = true;
7340 set_decl_tls_model (v
, decl_default_tls_model (v
));
7341 /* If rtl has been already set for this var, call
7342 make_decl_rtl once again, so that encode_section_info
7343 has a chance to look at the new decl flags. */
7344 if (DECL_RTL_SET_P (v
))
7347 CP_DECL_THREADPRIVATE_P (v
) = 1;
7352 /* Build an OpenMP structured block. */
7355 begin_omp_structured_block (void)
7357 return do_pushlevel (sk_omp
);
7361 finish_omp_structured_block (tree block
)
7363 return do_poplevel (block
);
7366 /* Similarly, except force the retention of the BLOCK. */
7369 begin_omp_parallel (void)
7371 keep_next_level (true);
7372 return begin_omp_structured_block ();
7375 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
7379 finish_oacc_data (tree clauses
, tree block
)
7383 block
= finish_omp_structured_block (block
);
7385 stmt
= make_node (OACC_DATA
);
7386 TREE_TYPE (stmt
) = void_type_node
;
7387 OACC_DATA_CLAUSES (stmt
) = clauses
;
7388 OACC_DATA_BODY (stmt
) = block
;
7390 return add_stmt (stmt
);
7393 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
7397 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
7399 body
= finish_omp_structured_block (body
);
7401 tree stmt
= make_node (code
);
7402 TREE_TYPE (stmt
) = void_type_node
;
7403 OMP_BODY (stmt
) = body
;
7404 OMP_CLAUSES (stmt
) = clauses
;
7406 return add_stmt (stmt
);
7410 finish_omp_parallel (tree clauses
, tree body
)
7414 body
= finish_omp_structured_block (body
);
7416 stmt
= make_node (OMP_PARALLEL
);
7417 TREE_TYPE (stmt
) = void_type_node
;
7418 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
7419 OMP_PARALLEL_BODY (stmt
) = body
;
7421 return add_stmt (stmt
);
7425 begin_omp_task (void)
7427 keep_next_level (true);
7428 return begin_omp_structured_block ();
7432 finish_omp_task (tree clauses
, tree body
)
7436 body
= finish_omp_structured_block (body
);
7438 stmt
= make_node (OMP_TASK
);
7439 TREE_TYPE (stmt
) = void_type_node
;
7440 OMP_TASK_CLAUSES (stmt
) = clauses
;
7441 OMP_TASK_BODY (stmt
) = body
;
7443 return add_stmt (stmt
);
7446 /* Helper function for finish_omp_for. Convert Ith random access iterator
7447 into integral iterator. Return FALSE if successful. */
7450 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
7451 tree declv
, tree orig_declv
, tree initv
,
7452 tree condv
, tree incrv
, tree
*body
,
7453 tree
*pre_body
, tree
&clauses
, tree
*lastp
,
7454 int collapse
, int ordered
)
7456 tree diff
, iter_init
, iter_incr
= NULL
, last
;
7457 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
7458 tree decl
= TREE_VEC_ELT (declv
, i
);
7459 tree init
= TREE_VEC_ELT (initv
, i
);
7460 tree cond
= TREE_VEC_ELT (condv
, i
);
7461 tree incr
= TREE_VEC_ELT (incrv
, i
);
7463 location_t elocus
= locus
;
7465 if (init
&& EXPR_HAS_LOCATION (init
))
7466 elocus
= EXPR_LOCATION (init
);
7468 cond
= cp_fully_fold (cond
);
7469 switch (TREE_CODE (cond
))
7476 if (TREE_OPERAND (cond
, 1) == iter
)
7477 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
7478 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
7479 if (TREE_OPERAND (cond
, 0) != iter
)
7480 cond
= error_mark_node
;
7483 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
7486 TREE_OPERAND (cond
, 1), ERROR_MARK
,
7487 NULL
, tf_warning_or_error
);
7488 if (error_operand_p (tem
))
7493 cond
= error_mark_node
;
7496 if (cond
== error_mark_node
)
7498 error_at (elocus
, "invalid controlling predicate");
7501 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
7502 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
7503 tf_warning_or_error
);
7504 diff
= cp_fully_fold (diff
);
7505 if (error_operand_p (diff
))
7507 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
7509 error_at (elocus
, "difference between %qE and %qD does not have integer type",
7510 TREE_OPERAND (cond
, 1), iter
);
7513 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
,
7514 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
7515 cond
, cp_walk_subtrees
))
7518 switch (TREE_CODE (incr
))
7520 case PREINCREMENT_EXPR
:
7521 case PREDECREMENT_EXPR
:
7522 case POSTINCREMENT_EXPR
:
7523 case POSTDECREMENT_EXPR
:
7524 if (TREE_OPERAND (incr
, 0) != iter
)
7526 incr
= error_mark_node
;
7529 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
7530 TREE_CODE (incr
), iter
,
7531 tf_warning_or_error
);
7532 if (error_operand_p (iter_incr
))
7534 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
7535 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
7536 incr
= integer_one_node
;
7538 incr
= integer_minus_one_node
;
7541 if (TREE_OPERAND (incr
, 0) != iter
)
7542 incr
= error_mark_node
;
7543 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
7544 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
7546 tree rhs
= TREE_OPERAND (incr
, 1);
7547 if (TREE_OPERAND (rhs
, 0) == iter
)
7549 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
7551 incr
= error_mark_node
;
7554 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7555 iter
, TREE_CODE (rhs
),
7556 TREE_OPERAND (rhs
, 1),
7557 tf_warning_or_error
);
7558 if (error_operand_p (iter_incr
))
7560 incr
= TREE_OPERAND (rhs
, 1);
7561 incr
= cp_convert (TREE_TYPE (diff
), incr
,
7562 tf_warning_or_error
);
7563 if (TREE_CODE (rhs
) == MINUS_EXPR
)
7565 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
7566 incr
= fold_simple (incr
);
7568 if (TREE_CODE (incr
) != INTEGER_CST
7569 && (TREE_CODE (incr
) != NOP_EXPR
7570 || (TREE_CODE (TREE_OPERAND (incr
, 0))
7575 else if (TREE_OPERAND (rhs
, 1) == iter
)
7577 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
7578 || TREE_CODE (rhs
) != PLUS_EXPR
)
7579 incr
= error_mark_node
;
7582 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
7584 TREE_OPERAND (rhs
, 0),
7587 tf_warning_or_error
);
7588 if (error_operand_p (iter_incr
))
7590 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
7593 tf_warning_or_error
);
7594 if (error_operand_p (iter_incr
))
7596 incr
= TREE_OPERAND (rhs
, 0);
7601 incr
= error_mark_node
;
7604 incr
= error_mark_node
;
7607 incr
= error_mark_node
;
7611 if (incr
== error_mark_node
)
7613 error_at (elocus
, "invalid increment expression");
7617 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
7618 bool taskloop_iv_seen
= false;
7619 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7620 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
7621 && OMP_CLAUSE_DECL (c
) == iter
)
7623 if (code
== OMP_TASKLOOP
)
7625 taskloop_iv_seen
= true;
7626 OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c
) = 1;
7630 else if (code
== OMP_TASKLOOP
7631 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
7632 && OMP_CLAUSE_DECL (c
) == iter
)
7634 taskloop_iv_seen
= true;
7635 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
7638 decl
= create_temporary_var (TREE_TYPE (diff
));
7640 add_decl_expr (decl
);
7641 last
= create_temporary_var (TREE_TYPE (diff
));
7643 add_decl_expr (last
);
7644 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
7645 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7647 incr_var
= create_temporary_var (TREE_TYPE (diff
));
7648 pushdecl (incr_var
);
7649 add_decl_expr (incr_var
);
7651 gcc_assert (stmts_are_full_exprs_p ());
7652 tree diffvar
= NULL_TREE
;
7653 if (code
== OMP_TASKLOOP
)
7655 if (!taskloop_iv_seen
)
7657 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7658 OMP_CLAUSE_DECL (ivc
) = iter
;
7659 cxx_omp_finish_clause (ivc
, NULL
);
7660 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
7663 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
7664 OMP_CLAUSE_DECL (lvc
) = last
;
7665 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
7667 diffvar
= create_temporary_var (TREE_TYPE (diff
));
7669 add_decl_expr (diffvar
);
7672 orig_pre_body
= *pre_body
;
7673 *pre_body
= push_stmt_list ();
7675 add_stmt (orig_pre_body
);
7677 finish_expr_stmt (build_x_modify_expr (elocus
,
7678 iter
, NOP_EXPR
, init
,
7679 tf_warning_or_error
));
7680 init
= build_int_cst (TREE_TYPE (diff
), 0);
7681 if (c
&& iter_incr
== NULL
7682 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
7686 finish_expr_stmt (build_x_modify_expr (elocus
,
7688 incr
, tf_warning_or_error
));
7691 iter_incr
= build_x_modify_expr (elocus
,
7692 iter
, PLUS_EXPR
, incr
,
7693 tf_warning_or_error
);
7695 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
7697 finish_expr_stmt (build_x_modify_expr (elocus
,
7698 last
, NOP_EXPR
, init
,
7699 tf_warning_or_error
));
7702 finish_expr_stmt (build_x_modify_expr (elocus
,
7704 diff
, tf_warning_or_error
));
7707 *pre_body
= pop_stmt_list (*pre_body
);
7709 cond
= cp_build_binary_op (elocus
,
7710 TREE_CODE (cond
), decl
, diff
,
7711 tf_warning_or_error
);
7712 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
7713 elocus
, incr
, NULL_TREE
);
7716 *body
= push_stmt_list ();
7717 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
7718 iter_init
= build_x_modify_expr (elocus
,
7719 iter
, PLUS_EXPR
, iter_init
,
7720 tf_warning_or_error
);
7721 if (iter_init
!= error_mark_node
)
7722 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7723 finish_expr_stmt (iter_init
);
7724 finish_expr_stmt (build_x_modify_expr (elocus
,
7725 last
, NOP_EXPR
, decl
,
7726 tf_warning_or_error
));
7727 add_stmt (orig_body
);
7728 *body
= pop_stmt_list (*body
);
7732 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
7734 finish_expr_stmt (iter_incr
);
7738 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
7739 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
7740 iter_init
, iter_incr
);
7741 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
7742 iter_init
= build_x_modify_expr (elocus
,
7743 iter
, PLUS_EXPR
, iter_init
,
7744 tf_warning_or_error
);
7745 if (iter_init
!= error_mark_node
)
7746 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
7747 finish_expr_stmt (iter_init
);
7749 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
7750 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
7753 TREE_VEC_ELT (declv
, i
) = decl
;
7754 TREE_VEC_ELT (initv
, i
) = init
;
7755 TREE_VEC_ELT (condv
, i
) = cond
;
7756 TREE_VEC_ELT (incrv
, i
) = incr
;
7762 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
7763 are directly for their associated operands in the statement. DECL
7764 and INIT are a combo; if DECL is NULL then INIT ought to be a
7765 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
7766 optional statements that need to go before the loop into its
7770 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
7771 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
7772 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
7774 tree omp_for
= NULL
, orig_incr
= NULL
;
7775 tree decl
= NULL
, init
, cond
, incr
, orig_decl
= NULL_TREE
, block
= NULL_TREE
;
7776 tree last
= NULL_TREE
;
7782 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
7783 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
7784 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
7785 if (TREE_VEC_LENGTH (declv
) > 1)
7787 tree c
= find_omp_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
7789 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
7790 if (collapse
!= TREE_VEC_LENGTH (declv
))
7791 ordered
= TREE_VEC_LENGTH (declv
);
7793 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
7795 decl
= TREE_VEC_ELT (declv
, i
);
7796 init
= TREE_VEC_ELT (initv
, i
);
7797 cond
= TREE_VEC_ELT (condv
, i
);
7798 incr
= TREE_VEC_ELT (incrv
, i
);
7804 switch (TREE_CODE (init
))
7807 decl
= TREE_OPERAND (init
, 0);
7808 init
= TREE_OPERAND (init
, 1);
7811 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
7813 decl
= TREE_OPERAND (init
, 0);
7814 init
= TREE_OPERAND (init
, 2);
7824 "expected iteration declaration or initialization");
7829 if (init
&& EXPR_HAS_LOCATION (init
))
7830 elocus
= EXPR_LOCATION (init
);
7834 error_at (elocus
, "missing controlling predicate");
7840 error_at (elocus
, "missing increment expression");
7844 TREE_VEC_ELT (declv
, i
) = decl
;
7845 TREE_VEC_ELT (initv
, i
) = init
;
7852 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
7854 && !c_omp_check_loop_iv_exprs (locus
, declv
,
7855 TREE_VEC_ELT (declv
, i
), orig_init
,
7856 NULL_TREE
, cp_walk_subtrees
))
7862 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
7866 stmt
= make_node (code
);
7868 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
7870 /* This is really just a place-holder. We'll be decomposing this
7871 again and going through the cp_build_modify_expr path below when
7872 we instantiate the thing. */
7873 TREE_VEC_ELT (initv
, i
)
7874 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
7875 TREE_VEC_ELT (initv
, i
));
7878 TREE_TYPE (stmt
) = void_type_node
;
7879 OMP_FOR_INIT (stmt
) = initv
;
7880 OMP_FOR_COND (stmt
) = condv
;
7881 OMP_FOR_INCR (stmt
) = incrv
;
7882 OMP_FOR_BODY (stmt
) = body
;
7883 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
7884 OMP_FOR_CLAUSES (stmt
) = clauses
;
7886 SET_EXPR_LOCATION (stmt
, locus
);
7887 return add_stmt (stmt
);
7891 orig_declv
= copy_node (declv
);
7893 if (processing_template_decl
)
7894 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
7896 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
7898 decl
= TREE_VEC_ELT (declv
, i
);
7899 init
= TREE_VEC_ELT (initv
, i
);
7900 cond
= TREE_VEC_ELT (condv
, i
);
7901 incr
= TREE_VEC_ELT (incrv
, i
);
7903 TREE_VEC_ELT (orig_incr
, i
) = incr
;
7906 if (init
&& EXPR_HAS_LOCATION (init
))
7907 elocus
= EXPR_LOCATION (init
);
7911 error_at (elocus
, "expected iteration declaration or initialization");
7915 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
7918 TREE_VEC_ELT (orig_incr
, i
) = incr
;
7919 incr
= cp_build_modify_expr (TREE_OPERAND (incr
, 0),
7920 TREE_CODE (TREE_OPERAND (incr
, 1)),
7921 TREE_OPERAND (incr
, 2),
7922 tf_warning_or_error
);
7925 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
7927 if (code
== OMP_SIMD
)
7929 error_at (elocus
, "%<#pragma omp simd%> used with class "
7930 "iteration variable %qE", decl
);
7933 if (code
== CILK_FOR
&& i
== 0)
7935 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
7936 initv
, condv
, incrv
, &body
,
7937 &pre_body
, clauses
, &last
,
7943 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
7944 && !TYPE_PTR_P (TREE_TYPE (decl
)))
7946 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
7950 if (!processing_template_decl
)
7952 init
= fold_build_cleanup_point_expr (TREE_TYPE (init
), init
);
7953 init
= cp_build_modify_expr (decl
, NOP_EXPR
, init
, tf_warning_or_error
);
7956 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
7958 && TREE_SIDE_EFFECTS (cond
)
7959 && COMPARISON_CLASS_P (cond
)
7960 && !processing_template_decl
)
7962 tree t
= TREE_OPERAND (cond
, 0);
7963 if (TREE_SIDE_EFFECTS (t
)
7965 && (TREE_CODE (t
) != NOP_EXPR
7966 || TREE_OPERAND (t
, 0) != decl
))
7967 TREE_OPERAND (cond
, 0)
7968 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7970 t
= TREE_OPERAND (cond
, 1);
7971 if (TREE_SIDE_EFFECTS (t
)
7973 && (TREE_CODE (t
) != NOP_EXPR
7974 || TREE_OPERAND (t
, 0) != decl
))
7975 TREE_OPERAND (cond
, 1)
7976 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7978 if (decl
== error_mark_node
|| init
== error_mark_node
)
7981 TREE_VEC_ELT (declv
, i
) = decl
;
7982 TREE_VEC_ELT (initv
, i
) = init
;
7983 TREE_VEC_ELT (condv
, i
) = cond
;
7984 TREE_VEC_ELT (incrv
, i
) = incr
;
7988 if (IS_EMPTY_STMT (pre_body
))
7991 if (code
== CILK_FOR
&& !processing_template_decl
)
7992 block
= push_stmt_list ();
7994 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
7995 incrv
, body
, pre_body
);
7997 /* Check for iterators appearing in lb, b or incr expressions. */
7998 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
7999 omp_for
= NULL_TREE
;
8001 if (omp_for
== NULL
)
8004 pop_stmt_list (block
);
8010 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
8012 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
), 0);
8013 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
8015 if (TREE_CODE (incr
) != MODIFY_EXPR
)
8018 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
8019 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
8020 && !processing_template_decl
)
8022 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
8023 if (TREE_SIDE_EFFECTS (t
)
8025 && (TREE_CODE (t
) != NOP_EXPR
8026 || TREE_OPERAND (t
, 0) != decl
))
8027 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
8028 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8030 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8031 if (TREE_SIDE_EFFECTS (t
)
8033 && (TREE_CODE (t
) != NOP_EXPR
8034 || TREE_OPERAND (t
, 0) != decl
))
8035 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8036 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8040 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
8042 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8044 /* For simd loops with non-static data member iterators, we could have added
8045 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
8046 step at this point, fill it in. */
8047 if (code
== OMP_SIMD
&& !processing_template_decl
8048 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
8049 for (tree c
= find_omp_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
8050 c
= find_omp_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
8051 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
8053 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
8054 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
8055 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8057 switch (TREE_CODE (incr
))
8059 case PREINCREMENT_EXPR
:
8060 case POSTINCREMENT_EXPR
:
8061 /* c_omp_for_incr_canonicalize_ptr() should have been
8062 called to massage things appropriately. */
8063 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8064 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
8066 case PREDECREMENT_EXPR
:
8067 case POSTDECREMENT_EXPR
:
8068 /* c_omp_for_incr_canonicalize_ptr() should have been
8069 called to massage things appropriately. */
8070 gcc_assert (!POINTER_TYPE_P (TREE_TYPE (decl
)));
8071 OMP_CLAUSE_LINEAR_STEP (c
)
8072 = build_int_cst (TREE_TYPE (decl
), -1);
8075 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8076 incr
= TREE_OPERAND (incr
, 1);
8077 switch (TREE_CODE (incr
))
8080 if (TREE_OPERAND (incr
, 1) == decl
)
8081 step
= TREE_OPERAND (incr
, 0);
8083 step
= TREE_OPERAND (incr
, 1);
8086 case POINTER_PLUS_EXPR
:
8087 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
8088 step
= TREE_OPERAND (incr
, 1);
8093 stept
= TREE_TYPE (decl
);
8094 if (POINTER_TYPE_P (stept
))
8096 step
= fold_convert (stept
, step
);
8097 if (TREE_CODE (incr
) == MINUS_EXPR
)
8098 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
8099 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
8108 tree omp_par
= make_node (OMP_PARALLEL
);
8109 TREE_TYPE (omp_par
) = void_type_node
;
8110 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
8111 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
8112 TREE_SIDE_EFFECTS (bind
) = 1;
8113 BIND_EXPR_BODY (bind
) = pop_stmt_list (block
);
8114 OMP_PARALLEL_BODY (omp_par
) = bind
;
8115 if (OMP_FOR_PRE_BODY (omp_for
))
8117 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
8118 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
8120 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
8121 decl
= TREE_OPERAND (init
, 0);
8122 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
8123 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
8124 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
, *pc
;
8125 clauses
= OMP_FOR_CLAUSES (omp_for
);
8126 OMP_FOR_CLAUSES (omp_for
) = NULL_TREE
;
8127 for (pc
= &clauses
; *pc
; )
8128 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_SCHEDULE
)
8130 gcc_assert (OMP_FOR_CLAUSES (omp_for
) == NULL_TREE
);
8131 OMP_FOR_CLAUSES (omp_for
) = *pc
;
8132 *pc
= OMP_CLAUSE_CHAIN (*pc
);
8133 OMP_CLAUSE_CHAIN (OMP_FOR_CLAUSES (omp_for
)) = NULL_TREE
;
8137 gcc_assert (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_FIRSTPRIVATE
);
8138 pc
= &OMP_CLAUSE_CHAIN (*pc
);
8140 if (TREE_CODE (t
) != INTEGER_CST
)
8142 TREE_OPERAND (cond
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
8143 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8144 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
8145 OMP_CLAUSE_CHAIN (c
) = clauses
;
8148 if (TREE_CODE (incr
) == MODIFY_EXPR
)
8150 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8151 if (TREE_CODE (t
) != INTEGER_CST
)
8153 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
8154 = get_temp_regvar (TREE_TYPE (t
), t
);
8155 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8156 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
8157 OMP_CLAUSE_CHAIN (c
) = clauses
;
8161 t
= TREE_OPERAND (init
, 1);
8162 if (TREE_CODE (t
) != INTEGER_CST
)
8164 TREE_OPERAND (init
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
8165 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8166 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
8167 OMP_CLAUSE_CHAIN (c
) = clauses
;
8170 if (orig_decl
&& orig_decl
!= decl
)
8172 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8173 OMP_CLAUSE_DECL (c
) = orig_decl
;
8174 OMP_CLAUSE_CHAIN (c
) = clauses
;
8179 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8180 OMP_CLAUSE_DECL (c
) = last
;
8181 OMP_CLAUSE_CHAIN (c
) = clauses
;
8184 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
8185 OMP_CLAUSE_DECL (c
) = decl
;
8186 OMP_CLAUSE_CHAIN (c
) = clauses
;
8188 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
8189 OMP_CLAUSE_OPERAND (c
, 0)
8190 = cilk_for_number_of_iterations (omp_for
);
8191 OMP_CLAUSE_CHAIN (c
) = clauses
;
8192 OMP_PARALLEL_CLAUSES (omp_par
) = finish_omp_clauses (c
, false);
8196 else if (code
== CILK_FOR
&& processing_template_decl
)
8198 tree c
, clauses
= OMP_FOR_CLAUSES (omp_for
);
8199 if (orig_decl
&& orig_decl
!= decl
)
8201 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8202 OMP_CLAUSE_DECL (c
) = orig_decl
;
8203 OMP_CLAUSE_CHAIN (c
) = clauses
;
8208 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
8209 OMP_CLAUSE_DECL (c
) = last
;
8210 OMP_CLAUSE_CHAIN (c
) = clauses
;
8213 OMP_FOR_CLAUSES (omp_for
) = clauses
;
8219 finish_omp_atomic (enum tree_code code
, enum tree_code opcode
, tree lhs
,
8220 tree rhs
, tree v
, tree lhs1
, tree rhs1
, bool seq_cst
)
8235 dependent_p
= false;
8238 /* Even in a template, we can detect invalid uses of the atomic
8239 pragma if neither LHS nor RHS is type-dependent. */
8240 if (processing_template_decl
)
8242 dependent_p
= (type_dependent_expression_p (lhs
)
8243 || (rhs
&& type_dependent_expression_p (rhs
))
8244 || (v
&& type_dependent_expression_p (v
))
8245 || (lhs1
&& type_dependent_expression_p (lhs1
))
8246 || (rhs1
&& type_dependent_expression_p (rhs1
)));
8249 lhs
= build_non_dependent_expr (lhs
);
8251 rhs
= build_non_dependent_expr (rhs
);
8253 v
= build_non_dependent_expr (v
);
8255 lhs1
= build_non_dependent_expr (lhs1
);
8257 rhs1
= build_non_dependent_expr (rhs1
);
8262 bool swapped
= false;
8263 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
8265 std::swap (rhs
, rhs1
);
8266 swapped
= !commutative_tree_code (opcode
);
8268 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
8270 if (code
== OMP_ATOMIC
)
8271 error ("%<#pragma omp atomic update%> uses two different "
8272 "expressions for memory");
8274 error ("%<#pragma omp atomic capture%> uses two different "
8275 "expressions for memory");
8278 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
8280 if (code
== OMP_ATOMIC
)
8281 error ("%<#pragma omp atomic update%> uses two different "
8282 "expressions for memory");
8284 error ("%<#pragma omp atomic capture%> uses two different "
8285 "expressions for memory");
8288 stmt
= c_finish_omp_atomic (input_location
, code
, opcode
, lhs
, rhs
,
8289 v
, lhs1
, rhs1
, swapped
, seq_cst
,
8290 processing_template_decl
!= 0);
8291 if (stmt
== error_mark_node
)
8294 if (processing_template_decl
)
8296 if (code
== OMP_ATOMIC_READ
)
8298 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs
),
8299 OMP_ATOMIC_READ
, orig_lhs
);
8300 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8301 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8305 if (opcode
== NOP_EXPR
)
8306 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
8308 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
8310 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
8311 COMPOUND_EXPR
, orig_rhs1
, stmt
);
8312 if (code
!= OMP_ATOMIC
)
8314 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs1
),
8315 code
, orig_lhs1
, stmt
);
8316 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8317 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
8320 stmt
= build2 (OMP_ATOMIC
, void_type_node
, integer_zero_node
, stmt
);
8321 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
8323 finish_expr_stmt (stmt
);
8327 finish_omp_barrier (void)
8329 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
8330 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8331 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8332 release_tree_vector (vec
);
8333 finish_expr_stmt (stmt
);
8337 finish_omp_flush (void)
8339 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
8340 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8341 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8342 release_tree_vector (vec
);
8343 finish_expr_stmt (stmt
);
8347 finish_omp_taskwait (void)
8349 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
8350 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8351 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8352 release_tree_vector (vec
);
8353 finish_expr_stmt (stmt
);
8357 finish_omp_taskyield (void)
8359 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
8360 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8361 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8362 release_tree_vector (vec
);
8363 finish_expr_stmt (stmt
);
8367 finish_omp_cancel (tree clauses
)
8369 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
8371 if (find_omp_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8373 else if (find_omp_clause (clauses
, OMP_CLAUSE_FOR
))
8375 else if (find_omp_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8377 else if (find_omp_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8381 error ("%<#pragma omp cancel must specify one of "
8382 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8385 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
8386 tree ifc
= find_omp_clause (clauses
, OMP_CLAUSE_IF
);
8387 if (ifc
!= NULL_TREE
)
8389 tree type
= TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc
));
8390 ifc
= fold_build2_loc (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
8391 boolean_type_node
, OMP_CLAUSE_IF_EXPR (ifc
),
8392 build_zero_cst (type
));
8395 ifc
= boolean_true_node
;
8396 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
8397 vec
->quick_push (ifc
);
8398 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8399 release_tree_vector (vec
);
8400 finish_expr_stmt (stmt
);
8404 finish_omp_cancellation_point (tree clauses
)
8406 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
8408 if (find_omp_clause (clauses
, OMP_CLAUSE_PARALLEL
))
8410 else if (find_omp_clause (clauses
, OMP_CLAUSE_FOR
))
8412 else if (find_omp_clause (clauses
, OMP_CLAUSE_SECTIONS
))
8414 else if (find_omp_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
8418 error ("%<#pragma omp cancellation point must specify one of "
8419 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8422 vec
<tree
, va_gc
> *vec
8423 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
8424 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
8425 release_tree_vector (vec
);
8426 finish_expr_stmt (stmt
);
8429 /* Begin a __transaction_atomic or __transaction_relaxed statement.
8430 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
8431 should create an extra compound stmt. */
8434 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
8439 *pcompound
= begin_compound_stmt (0);
8441 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
8443 /* Only add the statement to the function if support enabled. */
8447 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
8448 ? G_("%<__transaction_relaxed%> without "
8449 "transactional memory support enabled")
8450 : G_("%<__transaction_atomic%> without "
8451 "transactional memory support enabled")));
8453 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
8454 TREE_SIDE_EFFECTS (r
) = 1;
8458 /* End a __transaction_atomic or __transaction_relaxed statement.
8459 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
8460 and we should end the compound. If NOEX is non-NULL, we wrap the body in
8461 a MUST_NOT_THROW_EXPR with NOEX as condition. */
8464 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
8466 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
8467 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
8468 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
8469 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
8471 /* noexcept specifications are not allowed for function transactions. */
8472 gcc_assert (!(noex
&& compound_stmt
));
8475 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
8477 protected_set_expr_location
8478 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
8479 TREE_SIDE_EFFECTS (body
) = 1;
8480 TRANSACTION_EXPR_BODY (stmt
) = body
;
8484 finish_compound_stmt (compound_stmt
);
8487 /* Build a __transaction_atomic or __transaction_relaxed expression. If
8488 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
8492 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
8497 expr
= build_must_not_throw_expr (expr
, noex
);
8498 protected_set_expr_location (expr
, loc
);
8499 TREE_SIDE_EFFECTS (expr
) = 1;
8501 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
8502 if (flags
& TM_STMT_ATTR_RELAXED
)
8503 TRANSACTION_EXPR_RELAXED (ret
) = 1;
8504 TREE_SIDE_EFFECTS (ret
) = 1;
8505 SET_EXPR_LOCATION (ret
, loc
);
8510 init_cp_semantics (void)
8514 /* Build a STATIC_ASSERT for a static assertion with the condition
8515 CONDITION and the message text MESSAGE. LOCATION is the location
8516 of the static assertion in the source code. When MEMBER_P, this
8517 static assertion is a member of a class. */
8519 finish_static_assert (tree condition
, tree message
, location_t location
,
8522 if (message
== NULL_TREE
8523 || message
== error_mark_node
8524 || condition
== NULL_TREE
8525 || condition
== error_mark_node
)
8528 if (check_for_bare_parameter_packs (condition
))
8529 condition
= error_mark_node
;
8531 if (type_dependent_expression_p (condition
)
8532 || value_dependent_expression_p (condition
))
8534 /* We're in a template; build a STATIC_ASSERT and put it in
8538 assertion
= make_node (STATIC_ASSERT
);
8539 STATIC_ASSERT_CONDITION (assertion
) = condition
;
8540 STATIC_ASSERT_MESSAGE (assertion
) = message
;
8541 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
8544 maybe_add_class_template_decl_list (current_class_type
,
8548 add_stmt (assertion
);
8553 /* Fold the expression and convert it to a boolean value. */
8554 condition
= instantiate_non_dependent_expr (condition
);
8555 condition
= cp_convert (boolean_type_node
, condition
, tf_warning_or_error
);
8556 condition
= maybe_constant_value (condition
);
8558 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
8559 /* Do nothing; the condition is satisfied. */
8563 location_t saved_loc
= input_location
;
8565 input_location
= location
;
8566 if (TREE_CODE (condition
) == INTEGER_CST
8567 && integer_zerop (condition
))
8569 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
8570 (TREE_TYPE (TREE_TYPE (message
))));
8571 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
8572 /* Report the error. */
8574 error ("static assertion failed");
8576 error ("static assertion failed: %s",
8577 TREE_STRING_POINTER (message
));
8579 else if (condition
&& condition
!= error_mark_node
)
8581 error ("non-constant condition for static assertion");
8582 if (require_potential_rvalue_constant_expression (condition
))
8583 cxx_constant_value (condition
);
8585 input_location
= saved_loc
;
8589 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
8590 suitable for use as a type-specifier.
8592 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
8593 id-expression or a class member access, FALSE when it was parsed as
8594 a full expression. */
8597 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
8598 tsubst_flags_t complain
)
8600 tree type
= NULL_TREE
;
8602 if (!expr
|| error_operand_p (expr
))
8603 return error_mark_node
;
8606 || TREE_CODE (expr
) == TYPE_DECL
8607 || (TREE_CODE (expr
) == BIT_NOT_EXPR
8608 && TYPE_P (TREE_OPERAND (expr
, 0))))
8610 if (complain
& tf_error
)
8611 error ("argument to decltype must be an expression");
8612 return error_mark_node
;
8615 /* Depending on the resolution of DR 1172, we may later need to distinguish
8616 instantiation-dependent but not type-dependent expressions so that, say,
8617 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
8618 if (instantiation_dependent_expression_p (expr
))
8620 type
= cxx_make_type (DECLTYPE_TYPE
);
8621 DECLTYPE_TYPE_EXPR (type
) = expr
;
8622 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
8623 = id_expression_or_member_access_p
;
8624 SET_TYPE_STRUCTURAL_EQUALITY (type
);
8629 /* The type denoted by decltype(e) is defined as follows: */
8631 expr
= resolve_nondeduced_context (expr
);
8633 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
8634 return error_mark_node
;
8636 if (type_unknown_p (expr
))
8638 if (complain
& tf_error
)
8639 error ("decltype cannot resolve address of overloaded function");
8640 return error_mark_node
;
8643 /* To get the size of a static data member declared as an array of
8644 unknown bound, we need to instantiate it. */
8646 && VAR_HAD_UNKNOWN_BOUND (expr
)
8647 && DECL_TEMPLATE_INSTANTIATION (expr
))
8648 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
8650 if (id_expression_or_member_access_p
)
8652 /* If e is an id-expression or a class member access (5.2.5
8653 [expr.ref]), decltype(e) is defined as the type of the entity
8654 named by e. If there is no such entity, or e names a set of
8655 overloaded functions, the program is ill-formed. */
8656 if (identifier_p (expr
))
8657 expr
= lookup_name (expr
);
8659 if (INDIRECT_REF_P (expr
))
8660 /* This can happen when the expression is, e.g., "a.b". Just
8661 look at the underlying operand. */
8662 expr
= TREE_OPERAND (expr
, 0);
8664 if (TREE_CODE (expr
) == OFFSET_REF
8665 || TREE_CODE (expr
) == MEMBER_REF
8666 || TREE_CODE (expr
) == SCOPE_REF
)
8667 /* We're only interested in the field itself. If it is a
8668 BASELINK, we will need to see through it in the next
8670 expr
= TREE_OPERAND (expr
, 1);
8672 if (BASELINK_P (expr
))
8673 /* See through BASELINK nodes to the underlying function. */
8674 expr
= BASELINK_FUNCTIONS (expr
);
8676 switch (TREE_CODE (expr
))
8679 if (DECL_BIT_FIELD_TYPE (expr
))
8681 type
= DECL_BIT_FIELD_TYPE (expr
);
8684 /* Fall through for fields that aren't bitfields. */
8691 case TEMPLATE_PARM_INDEX
:
8692 expr
= mark_type_use (expr
);
8693 type
= TREE_TYPE (expr
);
8697 type
= error_mark_node
;
8702 mark_type_use (expr
);
8703 type
= is_bitfield_expr_with_lowered_type (expr
);
8705 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
8713 /* We can get here when the id-expression refers to an
8714 enumerator or non-type template parameter. */
8715 type
= TREE_TYPE (expr
);
8719 /* Handle instantiated template non-type arguments. */
8720 type
= TREE_TYPE (expr
);
8726 /* Within a lambda-expression:
8728 Every occurrence of decltype((x)) where x is a possibly
8729 parenthesized id-expression that names an entity of
8730 automatic storage duration is treated as if x were
8731 transformed into an access to a corresponding data member
8732 of the closure type that would have been declared if x
8733 were a use of the denoted entity. */
8734 if (outer_automatic_var_p (expr
)
8735 && current_function_decl
8736 && LAMBDA_FUNCTION_P (current_function_decl
))
8737 type
= capture_decltype (expr
);
8738 else if (error_operand_p (expr
))
8739 type
= error_mark_node
;
8740 else if (expr
== current_class_ptr
)
8741 /* If the expression is just "this", we want the
8742 cv-unqualified pointer for the "this" type. */
8743 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
8746 /* Otherwise, where T is the type of e, if e is an lvalue,
8747 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
8748 cp_lvalue_kind clk
= lvalue_kind (expr
);
8749 type
= unlowered_expr_type (expr
);
8750 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
8752 /* For vector types, pick a non-opaque variant. */
8753 if (VECTOR_TYPE_P (type
))
8754 type
= strip_typedefs (type
);
8756 if (clk
!= clk_none
&& !(clk
& clk_class
))
8757 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
8764 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
8765 __has_nothrow_copy, depending on assign_p. */
8768 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
8775 ix
= lookup_fnfields_1 (type
, ansi_assopname (NOP_EXPR
));
8778 fns
= (*CLASSTYPE_METHOD_VEC (type
))[ix
];
8780 else if (TYPE_HAS_COPY_CTOR (type
))
8782 /* If construction of the copy constructor was postponed, create
8784 if (CLASSTYPE_LAZY_COPY_CTOR (type
))
8785 lazily_declare_fn (sfk_copy_constructor
, type
);
8786 if (CLASSTYPE_LAZY_MOVE_CTOR (type
))
8787 lazily_declare_fn (sfk_move_constructor
, type
);
8788 fns
= CLASSTYPE_CONSTRUCTORS (type
);
8793 for (; fns
; fns
= OVL_NEXT (fns
))
8795 tree fn
= OVL_CURRENT (fns
);
8799 if (copy_fn_p (fn
) == 0)
8802 else if (copy_fn_p (fn
) <= 0)
8805 maybe_instantiate_noexcept (fn
);
8806 if (!TYPE_NOTHROW_P (TREE_TYPE (fn
)))
8813 /* Actually evaluates the trait. */
8816 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
8818 enum tree_code type_code1
;
8821 type_code1
= TREE_CODE (type1
);
8825 case CPTK_HAS_NOTHROW_ASSIGN
:
8826 type1
= strip_array_types (type1
);
8827 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
8828 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
8829 || (CLASS_TYPE_P (type1
)
8830 && classtype_has_nothrow_assign_or_copy_p (type1
,
8833 case CPTK_HAS_TRIVIAL_ASSIGN
:
8834 /* ??? The standard seems to be missing the "or array of such a class
8835 type" wording for this trait. */
8836 type1
= strip_array_types (type1
);
8837 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
8838 && (trivial_type_p (type1
)
8839 || (CLASS_TYPE_P (type1
)
8840 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
8842 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
8843 type1
= strip_array_types (type1
);
8844 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
8845 || (CLASS_TYPE_P (type1
)
8846 && (t
= locate_ctor (type1
))
8847 && (maybe_instantiate_noexcept (t
),
8848 TYPE_NOTHROW_P (TREE_TYPE (t
)))));
8850 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
8851 type1
= strip_array_types (type1
);
8852 return (trivial_type_p (type1
)
8853 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
8855 case CPTK_HAS_NOTHROW_COPY
:
8856 type1
= strip_array_types (type1
);
8857 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
8858 || (CLASS_TYPE_P (type1
)
8859 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
8861 case CPTK_HAS_TRIVIAL_COPY
:
8862 /* ??? The standard seems to be missing the "or array of such a class
8863 type" wording for this trait. */
8864 type1
= strip_array_types (type1
);
8865 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
8866 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
8868 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
8869 type1
= strip_array_types (type1
);
8870 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
8871 || (CLASS_TYPE_P (type1
)
8872 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
8874 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
8875 return type_has_virtual_destructor (type1
);
8877 case CPTK_IS_ABSTRACT
:
8878 return (ABSTRACT_CLASS_TYPE_P (type1
));
8880 case CPTK_IS_BASE_OF
:
8881 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
8882 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
8883 || DERIVED_FROM_P (type1
, type2
)));
8886 return (NON_UNION_CLASS_TYPE_P (type1
));
8889 return (NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
));
8892 return (type_code1
== ENUMERAL_TYPE
);
8895 return (CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
));
8897 case CPTK_IS_LITERAL_TYPE
:
8898 return (literal_type_p (type1
));
8901 return (pod_type_p (type1
));
8903 case CPTK_IS_POLYMORPHIC
:
8904 return (CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
));
8906 case CPTK_IS_SAME_AS
:
8907 return same_type_p (type1
, type2
);
8909 case CPTK_IS_STD_LAYOUT
:
8910 return (std_layout_type_p (type1
));
8912 case CPTK_IS_TRIVIAL
:
8913 return (trivial_type_p (type1
));
8915 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
8916 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
8918 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
8919 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
8921 case CPTK_IS_TRIVIALLY_COPYABLE
:
8922 return (trivially_copyable_p (type1
));
8925 return (type_code1
== UNION_TYPE
);
8933 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
8934 void, or a complete type, returns true, otherwise false. */
8937 check_trait_type (tree type
)
8939 if (type
== NULL_TREE
)
8942 if (TREE_CODE (type
) == TREE_LIST
)
8943 return (check_trait_type (TREE_VALUE (type
))
8944 && check_trait_type (TREE_CHAIN (type
)));
8946 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
8947 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
8950 if (VOID_TYPE_P (type
))
8953 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
8956 /* Process a trait expression. */
8959 finish_trait_expr (cp_trait_kind kind
, tree type1
, tree type2
)
8961 if (type1
== error_mark_node
8962 || type2
== error_mark_node
)
8963 return error_mark_node
;
8965 if (processing_template_decl
)
8967 tree trait_expr
= make_node (TRAIT_EXPR
);
8968 TREE_TYPE (trait_expr
) = boolean_type_node
;
8969 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
8970 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
8971 TRAIT_EXPR_KIND (trait_expr
) = kind
;
8977 case CPTK_HAS_NOTHROW_ASSIGN
:
8978 case CPTK_HAS_TRIVIAL_ASSIGN
:
8979 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
8980 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
8981 case CPTK_HAS_NOTHROW_COPY
:
8982 case CPTK_HAS_TRIVIAL_COPY
:
8983 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
8984 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
8985 case CPTK_IS_ABSTRACT
:
8988 case CPTK_IS_LITERAL_TYPE
:
8990 case CPTK_IS_POLYMORPHIC
:
8991 case CPTK_IS_STD_LAYOUT
:
8992 case CPTK_IS_TRIVIAL
:
8993 case CPTK_IS_TRIVIALLY_COPYABLE
:
8994 if (!check_trait_type (type1
))
8995 return error_mark_node
;
8998 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
8999 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
9000 if (!check_trait_type (type1
)
9001 || !check_trait_type (type2
))
9002 return error_mark_node
;
9005 case CPTK_IS_BASE_OF
:
9006 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
9007 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
9008 && !complete_type_or_else (type2
, NULL_TREE
))
9009 /* We already issued an error. */
9010 return error_mark_node
;
9016 case CPTK_IS_SAME_AS
:
9023 return (trait_expr_value (kind
, type1
, type2
)
9024 ? boolean_true_node
: boolean_false_node
);
9027 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
9028 which is ignored for C++. */
9031 set_float_const_decimal64 (void)
9036 clear_float_const_decimal64 (void)
9041 float_const_decimal64_p (void)
9047 /* Return true if T designates the implied `this' parameter. */
9050 is_this_parameter (tree t
)
9052 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
9054 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
));
9058 /* Insert the deduced return type for an auto function. */
9061 apply_deduced_return_type (tree fco
, tree return_type
)
9065 if (return_type
== error_mark_node
)
9068 if (LAMBDA_FUNCTION_P (fco
))
9070 tree lambda
= CLASSTYPE_LAMBDA_EXPR (current_class_type
);
9071 LAMBDA_EXPR_RETURN_TYPE (lambda
) = return_type
;
9074 if (DECL_CONV_FN_P (fco
))
9075 DECL_NAME (fco
) = mangle_conv_op_name_for_type (return_type
);
9077 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
9079 result
= DECL_RESULT (fco
);
9080 if (result
== NULL_TREE
)
9082 if (TREE_TYPE (result
) == return_type
)
9085 /* We already have a DECL_RESULT from start_preparsed_function.
9086 Now we need to redo the work it and allocate_struct_function
9087 did to reflect the new type. */
9088 gcc_assert (current_function_decl
== fco
);
9089 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
9090 TYPE_MAIN_VARIANT (return_type
));
9091 DECL_ARTIFICIAL (result
) = 1;
9092 DECL_IGNORED_P (result
) = 1;
9093 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
9096 DECL_RESULT (fco
) = result
;
9098 if (!processing_template_decl
)
9100 if (!VOID_TYPE_P (TREE_TYPE (result
)))
9101 complete_type_or_else (TREE_TYPE (result
), NULL_TREE
);
9102 bool aggr
= aggregate_value_p (result
, fco
);
9103 #ifdef PCC_STATIC_STRUCT_RETURN
9104 cfun
->returns_pcc_struct
= aggr
;
9106 cfun
->returns_struct
= aggr
;
9111 /* DECL is a local variable or parameter from the surrounding scope of a
9112 lambda-expression. Returns the decltype for a use of the capture field
9113 for DECL even if it hasn't been captured yet. */
9116 capture_decltype (tree decl
)
9118 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
9119 /* FIXME do lookup instead of list walk? */
9120 tree cap
= value_member (decl
, LAMBDA_EXPR_CAPTURE_LIST (lam
));
9124 type
= TREE_TYPE (TREE_PURPOSE (cap
));
9126 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
9129 error ("%qD is not captured", decl
);
9130 return error_mark_node
;
9133 type
= TREE_TYPE (decl
);
9134 if (TREE_CODE (type
) == REFERENCE_TYPE
9135 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
9136 type
= TREE_TYPE (type
);
9139 case CPLD_REFERENCE
:
9140 type
= TREE_TYPE (decl
);
9141 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9142 type
= build_reference_type (TREE_TYPE (decl
));
9149 if (TREE_CODE (type
) != REFERENCE_TYPE
)
9151 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
9152 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
9154 type
= build_reference_type (type
);
9159 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
9160 this is a right unary fold. Otherwise it is a left unary fold. */
9163 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
9165 // Build a pack expansion (assuming expr has pack type).
9166 if (!uses_parameter_packs (expr
))
9168 error_at (location_of (expr
), "operand of fold expression has no "
9169 "unexpanded parameter packs");
9170 return error_mark_node
;
9172 tree pack
= make_pack_expansion (expr
);
9174 // Build the fold expression.
9175 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9176 tree fold
= build_min (dir
, unknown_type_node
, code
, pack
);
9177 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9182 finish_left_unary_fold_expr (tree expr
, int op
)
9184 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
9188 finish_right_unary_fold_expr (tree expr
, int op
)
9190 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
9193 /* Build a binary fold expression over EXPR1 and EXPR2. The
9194 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
9195 has an unexpanded parameter pack). */
9198 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
9200 pack
= make_pack_expansion (pack
);
9201 tree code
= build_int_cstu (integer_type_node
, abs (op
));
9202 tree fold
= build_min (dir
, unknown_type_node
, code
, pack
, init
);
9203 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
9208 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
9210 // Determine which expr has an unexpanded parameter pack and
9211 // set the pack and initial term.
9212 bool pack1
= uses_parameter_packs (expr1
);
9213 bool pack2
= uses_parameter_packs (expr2
);
9214 if (pack1
&& !pack2
)
9215 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
9216 else if (pack2
&& !pack1
)
9217 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
9221 error ("both arguments in binary fold have unexpanded parameter packs");
9223 error ("no unexpanded parameter packs in binary fold");
9225 return error_mark_node
;
9228 #include "gt-cp-semantics.h"