/cp
[official-gcc.git] / gcc / cp / semantics.c
blobc7f53d1206e853acaa60d4fa1e78d02661956f94
1 /* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
6 Copyright (C) 1998-2018 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
15 any later version.
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/>. */
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "target.h"
30 #include "bitmap.h"
31 #include "cp-tree.h"
32 #include "stringpool.h"
33 #include "cgraph.h"
34 #include "stmt.h"
35 #include "varasm.h"
36 #include "stor-layout.h"
37 #include "c-family/c-objc.h"
38 #include "tree-inline.h"
39 #include "intl.h"
40 #include "tree-iterator.h"
41 #include "omp-general.h"
42 #include "convert.h"
43 #include "stringpool.h"
44 #include "attribs.h"
45 #include "gomp-constants.h"
46 #include "predict.h"
48 /* There routines provide a modular interface to perform many parsing
49 operations. They may therefore be used during actual parsing, or
50 during template instantiation, which may be regarded as a
51 degenerate form of parsing. */
53 static tree maybe_convert_cond (tree);
54 static tree finalize_nrv_r (tree *, int *, void *);
55 static tree capture_decltype (tree);
57 /* Used for OpenMP non-static data member privatization. */
59 static hash_map<tree, tree> *omp_private_member_map;
60 static vec<tree> omp_private_member_vec;
61 static bool omp_private_member_ignore_next;
64 /* Deferred Access Checking Overview
65 ---------------------------------
67 Most C++ expressions and declarations require access checking
68 to be performed during parsing. However, in several cases,
69 this has to be treated differently.
71 For member declarations, access checking has to be deferred
72 until more information about the declaration is known. For
73 example:
75 class A {
76 typedef int X;
77 public:
78 X f();
81 A::X A::f();
82 A::X g();
84 When we are parsing the function return type `A::X', we don't
85 really know if this is allowed until we parse the function name.
87 Furthermore, some contexts require that access checking is
88 never performed at all. These include class heads, and template
89 instantiations.
91 Typical use of access checking functions is described here:
93 1. When we enter a context that requires certain access checking
94 mode, the function `push_deferring_access_checks' is called with
95 DEFERRING argument specifying the desired mode. Access checking
96 may be performed immediately (dk_no_deferred), deferred
97 (dk_deferred), or not performed (dk_no_check).
99 2. When a declaration such as a type, or a variable, is encountered,
100 the function `perform_or_defer_access_check' is called. It
101 maintains a vector of all deferred checks.
103 3. The global `current_class_type' or `current_function_decl' is then
104 setup by the parser. `enforce_access' relies on these information
105 to check access.
107 4. Upon exiting the context mentioned in step 1,
108 `perform_deferred_access_checks' is called to check all declaration
109 stored in the vector. `pop_deferring_access_checks' is then
110 called to restore the previous access checking mode.
112 In case of parsing error, we simply call `pop_deferring_access_checks'
113 without `perform_deferred_access_checks'. */
115 struct GTY(()) deferred_access {
116 /* A vector representing name-lookups for which we have deferred
117 checking access controls. We cannot check the accessibility of
118 names used in a decl-specifier-seq until we know what is being
119 declared because code like:
121 class A {
122 class B {};
123 B* f();
126 A::B* A::f() { return 0; }
128 is valid, even though `A::B' is not generally accessible. */
129 vec<deferred_access_check, va_gc> * GTY(()) deferred_access_checks;
131 /* The current mode of access checks. */
132 enum deferring_kind deferring_access_checks_kind;
136 /* Data for deferred access checking. */
137 static GTY(()) vec<deferred_access, va_gc> *deferred_access_stack;
138 static GTY(()) unsigned deferred_access_no_check;
140 /* Save the current deferred access states and start deferred
141 access checking iff DEFER_P is true. */
143 void
144 push_deferring_access_checks (deferring_kind deferring)
146 /* For context like template instantiation, access checking
147 disabling applies to all nested context. */
148 if (deferred_access_no_check || deferring == dk_no_check)
149 deferred_access_no_check++;
150 else
152 deferred_access e = {NULL, deferring};
153 vec_safe_push (deferred_access_stack, e);
157 /* Save the current deferred access states and start deferred access
158 checking, continuing the set of deferred checks in CHECKS. */
160 void
161 reopen_deferring_access_checks (vec<deferred_access_check, va_gc> * checks)
163 push_deferring_access_checks (dk_deferred);
164 if (!deferred_access_no_check)
165 deferred_access_stack->last().deferred_access_checks = checks;
168 /* Resume deferring access checks again after we stopped doing
169 this previously. */
171 void
172 resume_deferring_access_checks (void)
174 if (!deferred_access_no_check)
175 deferred_access_stack->last().deferring_access_checks_kind = dk_deferred;
178 /* Stop deferring access checks. */
180 void
181 stop_deferring_access_checks (void)
183 if (!deferred_access_no_check)
184 deferred_access_stack->last().deferring_access_checks_kind = dk_no_deferred;
187 /* Discard the current deferred access checks and restore the
188 previous states. */
190 void
191 pop_deferring_access_checks (void)
193 if (deferred_access_no_check)
194 deferred_access_no_check--;
195 else
196 deferred_access_stack->pop ();
199 /* Returns a TREE_LIST representing the deferred checks.
200 The TREE_PURPOSE of each node is the type through which the
201 access occurred; the TREE_VALUE is the declaration named.
204 vec<deferred_access_check, va_gc> *
205 get_deferred_access_checks (void)
207 if (deferred_access_no_check)
208 return NULL;
209 else
210 return (deferred_access_stack->last().deferred_access_checks);
213 /* Take current deferred checks and combine with the
214 previous states if we also defer checks previously.
215 Otherwise perform checks now. */
217 void
218 pop_to_parent_deferring_access_checks (void)
220 if (deferred_access_no_check)
221 deferred_access_no_check--;
222 else
224 vec<deferred_access_check, va_gc> *checks;
225 deferred_access *ptr;
227 checks = (deferred_access_stack->last ().deferred_access_checks);
229 deferred_access_stack->pop ();
230 ptr = &deferred_access_stack->last ();
231 if (ptr->deferring_access_checks_kind == dk_no_deferred)
233 /* Check access. */
234 perform_access_checks (checks, tf_warning_or_error);
236 else
238 /* Merge with parent. */
239 int i, j;
240 deferred_access_check *chk, *probe;
242 FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
244 FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, j, probe)
246 if (probe->binfo == chk->binfo &&
247 probe->decl == chk->decl &&
248 probe->diag_decl == chk->diag_decl)
249 goto found;
251 /* Insert into parent's checks. */
252 vec_safe_push (ptr->deferred_access_checks, *chk);
253 found:;
259 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
260 is the BINFO indicating the qualifying scope used to access the
261 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
262 or we aren't in SFINAE context or all the checks succeed return TRUE,
263 otherwise FALSE. */
265 bool
266 perform_access_checks (vec<deferred_access_check, va_gc> *checks,
267 tsubst_flags_t complain)
269 int i;
270 deferred_access_check *chk;
271 location_t loc = input_location;
272 bool ok = true;
274 if (!checks)
275 return true;
277 FOR_EACH_VEC_SAFE_ELT (checks, i, chk)
279 input_location = chk->loc;
280 ok &= enforce_access (chk->binfo, chk->decl, chk->diag_decl, complain);
283 input_location = loc;
284 return (complain & tf_error) ? true : ok;
287 /* Perform the deferred access checks.
289 After performing the checks, we still have to keep the list
290 `deferred_access_stack->deferred_access_checks' since we may want
291 to check access for them again later in a different context.
292 For example:
294 class A {
295 typedef int X;
296 static X a;
298 A::X A::a, x; // No error for `A::a', error for `x'
300 We have to perform deferred access of `A::X', first with `A::a',
301 next with `x'. Return value like perform_access_checks above. */
303 bool
304 perform_deferred_access_checks (tsubst_flags_t complain)
306 return perform_access_checks (get_deferred_access_checks (), complain);
309 /* Defer checking the accessibility of DECL, when looked up in
310 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
311 Return value like perform_access_checks above.
312 If non-NULL, report failures to AFI. */
314 bool
315 perform_or_defer_access_check (tree binfo, tree decl, tree diag_decl,
316 tsubst_flags_t complain,
317 access_failure_info *afi)
319 int i;
320 deferred_access *ptr;
321 deferred_access_check *chk;
324 /* Exit if we are in a context that no access checking is performed.
326 if (deferred_access_no_check)
327 return true;
329 gcc_assert (TREE_CODE (binfo) == TREE_BINFO);
331 ptr = &deferred_access_stack->last ();
333 /* If we are not supposed to defer access checks, just check now. */
334 if (ptr->deferring_access_checks_kind == dk_no_deferred)
336 bool ok = enforce_access (binfo, decl, diag_decl, complain, afi);
337 return (complain & tf_error) ? true : ok;
340 /* See if we are already going to perform this check. */
341 FOR_EACH_VEC_SAFE_ELT (ptr->deferred_access_checks, i, chk)
343 if (chk->decl == decl && chk->binfo == binfo &&
344 chk->diag_decl == diag_decl)
346 return true;
349 /* If not, record the check. */
350 deferred_access_check new_access = {binfo, decl, diag_decl, input_location};
351 vec_safe_push (ptr->deferred_access_checks, new_access);
353 return true;
356 /* Returns nonzero if the current statement is a full expression,
357 i.e. temporaries created during that statement should be destroyed
358 at the end of the statement. */
361 stmts_are_full_exprs_p (void)
363 return current_stmt_tree ()->stmts_are_full_exprs_p;
366 /* T is a statement. Add it to the statement-tree. This is the C++
367 version. The C/ObjC frontends have a slightly different version of
368 this function. */
370 tree
371 add_stmt (tree t)
373 enum tree_code code = TREE_CODE (t);
375 if (EXPR_P (t) && code != LABEL_EXPR)
377 if (!EXPR_HAS_LOCATION (t))
378 SET_EXPR_LOCATION (t, input_location);
380 /* When we expand a statement-tree, we must know whether or not the
381 statements are full-expressions. We record that fact here. */
382 STMT_IS_FULL_EXPR_P (t) = stmts_are_full_exprs_p ();
385 if (code == LABEL_EXPR || code == CASE_LABEL_EXPR)
386 STATEMENT_LIST_HAS_LABEL (cur_stmt_list) = 1;
388 /* Add T to the statement-tree. Non-side-effect statements need to be
389 recorded during statement expressions. */
390 gcc_checking_assert (!stmt_list_stack->is_empty ());
391 append_to_statement_list_force (t, &cur_stmt_list);
393 return t;
396 /* Returns the stmt_tree to which statements are currently being added. */
398 stmt_tree
399 current_stmt_tree (void)
401 return (cfun
402 ? &cfun->language->base.x_stmt_tree
403 : &scope_chain->x_stmt_tree);
406 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
408 static tree
409 maybe_cleanup_point_expr (tree expr)
411 if (!processing_template_decl && stmts_are_full_exprs_p ())
412 expr = fold_build_cleanup_point_expr (TREE_TYPE (expr), expr);
413 return expr;
416 /* Like maybe_cleanup_point_expr except have the type of the new expression be
417 void so we don't need to create a temporary variable to hold the inner
418 expression. The reason why we do this is because the original type might be
419 an aggregate and we cannot create a temporary variable for that type. */
421 tree
422 maybe_cleanup_point_expr_void (tree expr)
424 if (!processing_template_decl && stmts_are_full_exprs_p ())
425 expr = fold_build_cleanup_point_expr (void_type_node, expr);
426 return expr;
431 /* Create a declaration statement for the declaration given by the DECL. */
433 void
434 add_decl_expr (tree decl)
436 tree r = build_stmt (DECL_SOURCE_LOCATION (decl), DECL_EXPR, decl);
437 if (DECL_INITIAL (decl)
438 || (DECL_SIZE (decl) && TREE_SIDE_EFFECTS (DECL_SIZE (decl))))
439 r = maybe_cleanup_point_expr_void (r);
440 add_stmt (r);
443 /* Finish a scope. */
445 tree
446 do_poplevel (tree stmt_list)
448 tree block = NULL;
450 if (stmts_are_full_exprs_p ())
451 block = poplevel (kept_level_p (), 1, 0);
453 stmt_list = pop_stmt_list (stmt_list);
455 if (!processing_template_decl)
457 stmt_list = c_build_bind_expr (input_location, block, stmt_list);
458 /* ??? See c_end_compound_stmt re statement expressions. */
461 return stmt_list;
464 /* Begin a new scope. */
466 static tree
467 do_pushlevel (scope_kind sk)
469 tree ret = push_stmt_list ();
470 if (stmts_are_full_exprs_p ())
471 begin_scope (sk, NULL);
472 return ret;
475 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
476 when the current scope is exited. EH_ONLY is true when this is not
477 meant to apply to normal control flow transfer. */
479 void
480 push_cleanup (tree decl, tree cleanup, bool eh_only)
482 tree stmt = build_stmt (input_location, CLEANUP_STMT, NULL, cleanup, decl);
483 CLEANUP_EH_ONLY (stmt) = eh_only;
484 add_stmt (stmt);
485 CLEANUP_BODY (stmt) = push_stmt_list ();
488 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
489 the current loops, represented by 'NULL_TREE' if we've seen a possible
490 exit, and 'error_mark_node' if not. This is currently used only to
491 suppress the warning about a function with no return statements, and
492 therefore we don't bother noting returns as possible exits. We also
493 don't bother with gotos. */
495 static void
496 begin_maybe_infinite_loop (tree cond)
498 /* Only track this while parsing a function, not during instantiation. */
499 if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
500 && !processing_template_decl))
501 return;
502 bool maybe_infinite = true;
503 if (cond)
505 cond = fold_non_dependent_expr (cond);
506 maybe_infinite = integer_nonzerop (cond);
508 vec_safe_push (cp_function_chain->infinite_loops,
509 maybe_infinite ? error_mark_node : NULL_TREE);
513 /* A break is a possible exit for the current loop. */
515 void
516 break_maybe_infinite_loop (void)
518 if (!cfun)
519 return;
520 cp_function_chain->infinite_loops->last() = NULL_TREE;
523 /* If we reach the end of the loop without seeing a possible exit, we have
524 an infinite loop. */
526 static void
527 end_maybe_infinite_loop (tree cond)
529 if (!cfun || (DECL_TEMPLATE_INSTANTIATION (current_function_decl)
530 && !processing_template_decl))
531 return;
532 tree current = cp_function_chain->infinite_loops->pop();
533 if (current != NULL_TREE)
535 cond = fold_non_dependent_expr (cond);
536 if (integer_nonzerop (cond))
537 current_function_infinite_loop = 1;
542 /* Begin a conditional that might contain a declaration. When generating
543 normal code, we want the declaration to appear before the statement
544 containing the conditional. When generating template code, we want the
545 conditional to be rendered as the raw DECL_EXPR. */
547 static void
548 begin_cond (tree *cond_p)
550 if (processing_template_decl)
551 *cond_p = push_stmt_list ();
554 /* Finish such a conditional. */
556 static void
557 finish_cond (tree *cond_p, tree expr)
559 if (processing_template_decl)
561 tree cond = pop_stmt_list (*cond_p);
563 if (expr == NULL_TREE)
564 /* Empty condition in 'for'. */
565 gcc_assert (empty_expr_stmt_p (cond));
566 else if (check_for_bare_parameter_packs (expr))
567 expr = error_mark_node;
568 else if (!empty_expr_stmt_p (cond))
569 expr = build2 (COMPOUND_EXPR, TREE_TYPE (expr), cond, expr);
571 *cond_p = expr;
574 /* If *COND_P specifies a conditional with a declaration, transform the
575 loop such that
576 while (A x = 42) { }
577 for (; A x = 42;) { }
578 becomes
579 while (true) { A x = 42; if (!x) break; }
580 for (;;) { A x = 42; if (!x) break; }
581 The statement list for BODY will be empty if the conditional did
582 not declare anything. */
584 static void
585 simplify_loop_decl_cond (tree *cond_p, tree body)
587 tree cond, if_stmt;
589 if (!TREE_SIDE_EFFECTS (body))
590 return;
592 cond = *cond_p;
593 *cond_p = boolean_true_node;
595 if_stmt = begin_if_stmt ();
596 cond = cp_build_unary_op (TRUTH_NOT_EXPR, cond, false, tf_warning_or_error);
597 finish_if_stmt_cond (cond, if_stmt);
598 finish_break_stmt ();
599 finish_then_clause (if_stmt);
600 finish_if_stmt (if_stmt);
603 /* Finish a goto-statement. */
605 tree
606 finish_goto_stmt (tree destination)
608 if (identifier_p (destination))
609 destination = lookup_label (destination);
611 /* We warn about unused labels with -Wunused. That means we have to
612 mark the used labels as used. */
613 if (TREE_CODE (destination) == LABEL_DECL)
614 TREE_USED (destination) = 1;
615 else
617 destination = mark_rvalue_use (destination);
618 if (!processing_template_decl)
620 destination = cp_convert (ptr_type_node, destination,
621 tf_warning_or_error);
622 if (error_operand_p (destination))
623 return NULL_TREE;
624 destination
625 = fold_build_cleanup_point_expr (TREE_TYPE (destination),
626 destination);
630 check_goto (destination);
632 add_stmt (build_predict_expr (PRED_GOTO, NOT_TAKEN));
633 return add_stmt (build_stmt (input_location, GOTO_EXPR, destination));
636 /* COND is the condition-expression for an if, while, etc.,
637 statement. Convert it to a boolean value, if appropriate.
638 In addition, verify sequence points if -Wsequence-point is enabled. */
640 static tree
641 maybe_convert_cond (tree cond)
643 /* Empty conditions remain empty. */
644 if (!cond)
645 return NULL_TREE;
647 /* Wait until we instantiate templates before doing conversion. */
648 if (processing_template_decl)
649 return cond;
651 if (warn_sequence_point)
652 verify_sequence_points (cond);
654 /* Do the conversion. */
655 cond = convert_from_reference (cond);
657 if (TREE_CODE (cond) == MODIFY_EXPR
658 && !TREE_NO_WARNING (cond)
659 && warn_parentheses)
661 warning_at (cp_expr_loc_or_loc (cond, input_location), OPT_Wparentheses,
662 "suggest parentheses around assignment used as truth value");
663 TREE_NO_WARNING (cond) = 1;
666 return condition_conversion (cond);
669 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
671 tree
672 finish_expr_stmt (tree expr)
674 tree r = NULL_TREE;
675 location_t loc = EXPR_LOCATION (expr);
677 if (expr != NULL_TREE)
679 /* If we ran into a problem, make sure we complained. */
680 gcc_assert (expr != error_mark_node || seen_error ());
682 if (!processing_template_decl)
684 if (warn_sequence_point)
685 verify_sequence_points (expr);
686 expr = convert_to_void (expr, ICV_STATEMENT, tf_warning_or_error);
688 else if (!type_dependent_expression_p (expr))
689 convert_to_void (build_non_dependent_expr (expr), ICV_STATEMENT,
690 tf_warning_or_error);
692 if (check_for_bare_parameter_packs (expr))
693 expr = error_mark_node;
695 /* Simplification of inner statement expressions, compound exprs,
696 etc can result in us already having an EXPR_STMT. */
697 if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
699 if (TREE_CODE (expr) != EXPR_STMT)
700 expr = build_stmt (loc, EXPR_STMT, expr);
701 expr = maybe_cleanup_point_expr_void (expr);
704 r = add_stmt (expr);
707 return r;
711 /* Begin an if-statement. Returns a newly created IF_STMT if
712 appropriate. */
714 tree
715 begin_if_stmt (void)
717 tree r, scope;
718 scope = do_pushlevel (sk_cond);
719 r = build_stmt (input_location, IF_STMT, NULL_TREE,
720 NULL_TREE, NULL_TREE, scope);
721 current_binding_level->this_entity = r;
722 begin_cond (&IF_COND (r));
723 return r;
726 /* Process the COND of an if-statement, which may be given by
727 IF_STMT. */
729 tree
730 finish_if_stmt_cond (tree cond, tree if_stmt)
732 cond = maybe_convert_cond (cond);
733 if (IF_STMT_CONSTEXPR_P (if_stmt)
734 && !type_dependent_expression_p (cond)
735 && require_constant_expression (cond)
736 && !instantiation_dependent_expression_p (cond)
737 /* Wait until instantiation time, since only then COND has been
738 converted to bool. */
739 && TYPE_MAIN_VARIANT (TREE_TYPE (cond)) == boolean_type_node)
741 cond = instantiate_non_dependent_expr (cond);
742 cond = cxx_constant_value (cond, NULL_TREE);
744 finish_cond (&IF_COND (if_stmt), cond);
745 add_stmt (if_stmt);
746 THEN_CLAUSE (if_stmt) = push_stmt_list ();
747 return cond;
750 /* Finish the then-clause of an if-statement, which may be given by
751 IF_STMT. */
753 tree
754 finish_then_clause (tree if_stmt)
756 THEN_CLAUSE (if_stmt) = pop_stmt_list (THEN_CLAUSE (if_stmt));
757 return if_stmt;
760 /* Begin the else-clause of an if-statement. */
762 void
763 begin_else_clause (tree if_stmt)
765 ELSE_CLAUSE (if_stmt) = push_stmt_list ();
768 /* Finish the else-clause of an if-statement, which may be given by
769 IF_STMT. */
771 void
772 finish_else_clause (tree if_stmt)
774 ELSE_CLAUSE (if_stmt) = pop_stmt_list (ELSE_CLAUSE (if_stmt));
777 /* Finish an if-statement. */
779 void
780 finish_if_stmt (tree if_stmt)
782 tree scope = IF_SCOPE (if_stmt);
783 IF_SCOPE (if_stmt) = NULL;
784 add_stmt (do_poplevel (scope));
787 /* Begin a while-statement. Returns a newly created WHILE_STMT if
788 appropriate. */
790 tree
791 begin_while_stmt (void)
793 tree r;
794 r = build_stmt (input_location, WHILE_STMT, NULL_TREE, NULL_TREE);
795 add_stmt (r);
796 WHILE_BODY (r) = do_pushlevel (sk_block);
797 begin_cond (&WHILE_COND (r));
798 return r;
801 /* Process the COND of a while-statement, which may be given by
802 WHILE_STMT. */
804 void
805 finish_while_stmt_cond (tree cond, tree while_stmt, bool ivdep,
806 unsigned short unroll)
808 cond = maybe_convert_cond (cond);
809 finish_cond (&WHILE_COND (while_stmt), cond);
810 begin_maybe_infinite_loop (cond);
811 if (ivdep && cond != error_mark_node)
812 WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
813 TREE_TYPE (WHILE_COND (while_stmt)),
814 WHILE_COND (while_stmt),
815 build_int_cst (integer_type_node,
816 annot_expr_ivdep_kind),
817 integer_zero_node);
818 if (unroll && cond != error_mark_node)
819 WHILE_COND (while_stmt) = build3 (ANNOTATE_EXPR,
820 TREE_TYPE (WHILE_COND (while_stmt)),
821 WHILE_COND (while_stmt),
822 build_int_cst (integer_type_node,
823 annot_expr_unroll_kind),
824 build_int_cst (integer_type_node,
825 unroll));
826 simplify_loop_decl_cond (&WHILE_COND (while_stmt), WHILE_BODY (while_stmt));
829 /* Finish a while-statement, which may be given by WHILE_STMT. */
831 void
832 finish_while_stmt (tree while_stmt)
834 end_maybe_infinite_loop (boolean_true_node);
835 WHILE_BODY (while_stmt) = do_poplevel (WHILE_BODY (while_stmt));
838 /* Begin a do-statement. Returns a newly created DO_STMT if
839 appropriate. */
841 tree
842 begin_do_stmt (void)
844 tree r = build_stmt (input_location, DO_STMT, NULL_TREE, NULL_TREE);
845 begin_maybe_infinite_loop (boolean_true_node);
846 add_stmt (r);
847 DO_BODY (r) = push_stmt_list ();
848 return r;
851 /* Finish the body of a do-statement, which may be given by DO_STMT. */
853 void
854 finish_do_body (tree do_stmt)
856 tree body = DO_BODY (do_stmt) = pop_stmt_list (DO_BODY (do_stmt));
858 if (TREE_CODE (body) == STATEMENT_LIST && STATEMENT_LIST_TAIL (body))
859 body = STATEMENT_LIST_TAIL (body)->stmt;
861 if (IS_EMPTY_STMT (body))
862 warning (OPT_Wempty_body,
863 "suggest explicit braces around empty body in %<do%> statement");
866 /* Finish a do-statement, which may be given by DO_STMT, and whose
867 COND is as indicated. */
869 void
870 finish_do_stmt (tree cond, tree do_stmt, bool ivdep, unsigned short unroll)
872 cond = maybe_convert_cond (cond);
873 end_maybe_infinite_loop (cond);
874 if (ivdep && cond != error_mark_node)
875 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
876 build_int_cst (integer_type_node, annot_expr_ivdep_kind),
877 integer_zero_node);
878 if (unroll && cond != error_mark_node)
879 cond = build3 (ANNOTATE_EXPR, TREE_TYPE (cond), cond,
880 build_int_cst (integer_type_node, annot_expr_unroll_kind),
881 build_int_cst (integer_type_node, unroll));
882 DO_COND (do_stmt) = cond;
885 /* Finish a return-statement. The EXPRESSION returned, if any, is as
886 indicated. */
888 tree
889 finish_return_stmt (tree expr)
891 tree r;
892 bool no_warning;
894 expr = check_return_expr (expr, &no_warning);
896 if (error_operand_p (expr)
897 || (flag_openmp && !check_omp_return ()))
899 /* Suppress -Wreturn-type for this function. */
900 if (warn_return_type)
901 TREE_NO_WARNING (current_function_decl) = true;
902 return error_mark_node;
905 if (!processing_template_decl)
907 if (warn_sequence_point)
908 verify_sequence_points (expr);
910 if (DECL_DESTRUCTOR_P (current_function_decl)
911 || (DECL_CONSTRUCTOR_P (current_function_decl)
912 && targetm.cxx.cdtor_returns_this ()))
914 /* Similarly, all destructors must run destructors for
915 base-classes before returning. So, all returns in a
916 destructor get sent to the DTOR_LABEL; finish_function emits
917 code to return a value there. */
918 return finish_goto_stmt (cdtor_label);
922 r = build_stmt (input_location, RETURN_EXPR, expr);
923 TREE_NO_WARNING (r) |= no_warning;
924 r = maybe_cleanup_point_expr_void (r);
925 r = add_stmt (r);
927 return r;
930 /* Begin the scope of a for-statement or a range-for-statement.
931 Both the returned trees are to be used in a call to
932 begin_for_stmt or begin_range_for_stmt. */
934 tree
935 begin_for_scope (tree *init)
937 tree scope = do_pushlevel (sk_for);
939 if (processing_template_decl)
940 *init = push_stmt_list ();
941 else
942 *init = NULL_TREE;
944 return scope;
947 /* Begin a for-statement. Returns a new FOR_STMT.
948 SCOPE and INIT should be the return of begin_for_scope,
949 or both NULL_TREE */
951 tree
952 begin_for_stmt (tree scope, tree init)
954 tree r;
956 r = build_stmt (input_location, FOR_STMT, NULL_TREE, NULL_TREE,
957 NULL_TREE, NULL_TREE, NULL_TREE);
959 if (scope == NULL_TREE)
961 gcc_assert (!init);
962 scope = begin_for_scope (&init);
965 FOR_INIT_STMT (r) = init;
966 FOR_SCOPE (r) = scope;
968 return r;
971 /* Finish the init-statement of a for-statement, which may be
972 given by FOR_STMT. */
974 void
975 finish_init_stmt (tree for_stmt)
977 if (processing_template_decl)
978 FOR_INIT_STMT (for_stmt) = pop_stmt_list (FOR_INIT_STMT (for_stmt));
979 add_stmt (for_stmt);
980 FOR_BODY (for_stmt) = do_pushlevel (sk_block);
981 begin_cond (&FOR_COND (for_stmt));
984 /* Finish the COND of a for-statement, which may be given by
985 FOR_STMT. */
987 void
988 finish_for_cond (tree cond, tree for_stmt, bool ivdep, unsigned short unroll)
990 cond = maybe_convert_cond (cond);
991 finish_cond (&FOR_COND (for_stmt), cond);
992 begin_maybe_infinite_loop (cond);
993 if (ivdep && cond != error_mark_node)
994 FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
995 TREE_TYPE (FOR_COND (for_stmt)),
996 FOR_COND (for_stmt),
997 build_int_cst (integer_type_node,
998 annot_expr_ivdep_kind),
999 integer_zero_node);
1000 if (unroll && cond != error_mark_node)
1001 FOR_COND (for_stmt) = build3 (ANNOTATE_EXPR,
1002 TREE_TYPE (FOR_COND (for_stmt)),
1003 FOR_COND (for_stmt),
1004 build_int_cst (integer_type_node,
1005 annot_expr_unroll_kind),
1006 build_int_cst (integer_type_node,
1007 unroll));
1008 simplify_loop_decl_cond (&FOR_COND (for_stmt), FOR_BODY (for_stmt));
1011 /* Finish the increment-EXPRESSION in a for-statement, which may be
1012 given by FOR_STMT. */
1014 void
1015 finish_for_expr (tree expr, tree for_stmt)
1017 if (!expr)
1018 return;
1019 /* If EXPR is an overloaded function, issue an error; there is no
1020 context available to use to perform overload resolution. */
1021 if (type_unknown_p (expr))
1023 cxx_incomplete_type_error (expr, TREE_TYPE (expr));
1024 expr = error_mark_node;
1026 if (!processing_template_decl)
1028 if (warn_sequence_point)
1029 verify_sequence_points (expr);
1030 expr = convert_to_void (expr, ICV_THIRD_IN_FOR,
1031 tf_warning_or_error);
1033 else if (!type_dependent_expression_p (expr))
1034 convert_to_void (build_non_dependent_expr (expr), ICV_THIRD_IN_FOR,
1035 tf_warning_or_error);
1036 expr = maybe_cleanup_point_expr_void (expr);
1037 if (check_for_bare_parameter_packs (expr))
1038 expr = error_mark_node;
1039 FOR_EXPR (for_stmt) = expr;
1042 /* Finish the body of a for-statement, which may be given by
1043 FOR_STMT. The increment-EXPR for the loop must be
1044 provided.
1045 It can also finish RANGE_FOR_STMT. */
1047 void
1048 finish_for_stmt (tree for_stmt)
1050 end_maybe_infinite_loop (boolean_true_node);
1052 if (TREE_CODE (for_stmt) == RANGE_FOR_STMT)
1053 RANGE_FOR_BODY (for_stmt) = do_poplevel (RANGE_FOR_BODY (for_stmt));
1054 else
1055 FOR_BODY (for_stmt) = do_poplevel (FOR_BODY (for_stmt));
1057 /* Pop the scope for the body of the loop. */
1058 tree *scope_ptr = (TREE_CODE (for_stmt) == RANGE_FOR_STMT
1059 ? &RANGE_FOR_SCOPE (for_stmt)
1060 : &FOR_SCOPE (for_stmt));
1061 tree scope = *scope_ptr;
1062 *scope_ptr = NULL;
1064 /* During parsing of the body, range for uses "__for_{range,begin,end} "
1065 decl names to make those unaccessible by code in the body.
1066 Change it to ones with underscore instead of space, so that it can
1067 be inspected in the debugger. */
1068 tree range_for_decl[3] = { NULL_TREE, NULL_TREE, NULL_TREE };
1069 gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 1
1070 && CPTI_FOR_END__IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 2
1071 && CPTI_FOR_RANGE_IDENTIFIER == CPTI_FOR_RANGE__IDENTIFIER + 3
1072 && CPTI_FOR_BEGIN_IDENTIFIER == CPTI_FOR_BEGIN__IDENTIFIER + 3
1073 && CPTI_FOR_END_IDENTIFIER == CPTI_FOR_END__IDENTIFIER + 3);
1074 for (int i = 0; i < 3; i++)
1076 tree id = cp_global_trees[CPTI_FOR_RANGE__IDENTIFIER + i];
1077 if (IDENTIFIER_BINDING (id)
1078 && IDENTIFIER_BINDING (id)->scope == current_binding_level)
1080 range_for_decl[i] = IDENTIFIER_BINDING (id)->value;
1081 gcc_assert (VAR_P (range_for_decl[i])
1082 && DECL_ARTIFICIAL (range_for_decl[i]));
1086 add_stmt (do_poplevel (scope));
1088 for (int i = 0; i < 3; i++)
1089 if (range_for_decl[i])
1090 DECL_NAME (range_for_decl[i])
1091 = cp_global_trees[CPTI_FOR_RANGE_IDENTIFIER + i];
1094 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1095 SCOPE and INIT should be the return of begin_for_scope,
1096 or both NULL_TREE .
1097 To finish it call finish_for_stmt(). */
1099 tree
1100 begin_range_for_stmt (tree scope, tree init)
1102 begin_maybe_infinite_loop (boolean_false_node);
1104 tree r = build_stmt (input_location, RANGE_FOR_STMT, NULL_TREE, NULL_TREE,
1105 NULL_TREE, NULL_TREE, NULL_TREE, NULL_TREE);
1107 if (scope == NULL_TREE)
1109 gcc_assert (!init);
1110 scope = begin_for_scope (&init);
1113 /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1114 RANGE_FOR_INIT_STMT (r) = init;
1115 RANGE_FOR_SCOPE (r) = scope;
1117 return r;
1120 /* Finish the head of a range-based for statement, which may
1121 be given by RANGE_FOR_STMT. DECL must be the declaration
1122 and EXPR must be the loop expression. */
1124 void
1125 finish_range_for_decl (tree range_for_stmt, tree decl, tree expr)
1127 if (processing_template_decl)
1128 RANGE_FOR_INIT_STMT (range_for_stmt)
1129 = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt));
1130 RANGE_FOR_DECL (range_for_stmt) = decl;
1131 RANGE_FOR_EXPR (range_for_stmt) = expr;
1132 add_stmt (range_for_stmt);
1133 RANGE_FOR_BODY (range_for_stmt) = do_pushlevel (sk_block);
1136 /* Finish a break-statement. */
1138 tree
1139 finish_break_stmt (void)
1141 /* In switch statements break is sometimes stylistically used after
1142 a return statement. This can lead to spurious warnings about
1143 control reaching the end of a non-void function when it is
1144 inlined. Note that we are calling block_may_fallthru with
1145 language specific tree nodes; this works because
1146 block_may_fallthru returns true when given something it does not
1147 understand. */
1148 if (!block_may_fallthru (cur_stmt_list))
1149 return void_node;
1150 note_break_stmt ();
1151 return add_stmt (build_stmt (input_location, BREAK_STMT));
1154 /* Finish a continue-statement. */
1156 tree
1157 finish_continue_stmt (void)
1159 return add_stmt (build_stmt (input_location, CONTINUE_STMT));
1162 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1163 appropriate. */
1165 tree
1166 begin_switch_stmt (void)
1168 tree r, scope;
1170 scope = do_pushlevel (sk_cond);
1171 r = build_stmt (input_location, SWITCH_STMT, NULL_TREE, NULL_TREE, NULL_TREE, scope);
1173 begin_cond (&SWITCH_STMT_COND (r));
1175 return r;
1178 /* Finish the cond of a switch-statement. */
1180 void
1181 finish_switch_cond (tree cond, tree switch_stmt)
1183 tree orig_type = NULL;
1185 if (!processing_template_decl)
1187 /* Convert the condition to an integer or enumeration type. */
1188 cond = build_expr_type_conversion (WANT_INT | WANT_ENUM, cond, true);
1189 if (cond == NULL_TREE)
1191 error ("switch quantity not an integer");
1192 cond = error_mark_node;
1194 /* We want unlowered type here to handle enum bit-fields. */
1195 orig_type = unlowered_expr_type (cond);
1196 if (TREE_CODE (orig_type) != ENUMERAL_TYPE)
1197 orig_type = TREE_TYPE (cond);
1198 if (cond != error_mark_node)
1200 /* [stmt.switch]
1202 Integral promotions are performed. */
1203 cond = perform_integral_promotions (cond);
1204 cond = maybe_cleanup_point_expr (cond);
1207 if (check_for_bare_parameter_packs (cond))
1208 cond = error_mark_node;
1209 else if (!processing_template_decl && warn_sequence_point)
1210 verify_sequence_points (cond);
1212 finish_cond (&SWITCH_STMT_COND (switch_stmt), cond);
1213 SWITCH_STMT_TYPE (switch_stmt) = orig_type;
1214 add_stmt (switch_stmt);
1215 push_switch (switch_stmt);
1216 SWITCH_STMT_BODY (switch_stmt) = push_stmt_list ();
1219 /* Finish the body of a switch-statement, which may be given by
1220 SWITCH_STMT. The COND to switch on is indicated. */
1222 void
1223 finish_switch_stmt (tree switch_stmt)
1225 tree scope;
1227 SWITCH_STMT_BODY (switch_stmt) =
1228 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt));
1229 pop_switch ();
1231 scope = SWITCH_STMT_SCOPE (switch_stmt);
1232 SWITCH_STMT_SCOPE (switch_stmt) = NULL;
1233 add_stmt (do_poplevel (scope));
1236 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1237 appropriate. */
1239 tree
1240 begin_try_block (void)
1242 tree r = build_stmt (input_location, TRY_BLOCK, NULL_TREE, NULL_TREE);
1243 add_stmt (r);
1244 TRY_STMTS (r) = push_stmt_list ();
1245 return r;
1248 /* Likewise, for a function-try-block. The block returned in
1249 *COMPOUND_STMT is an artificial outer scope, containing the
1250 function-try-block. */
1252 tree
1253 begin_function_try_block (tree *compound_stmt)
1255 tree r;
1256 /* This outer scope does not exist in the C++ standard, but we need
1257 a place to put __FUNCTION__ and similar variables. */
1258 *compound_stmt = begin_compound_stmt (0);
1259 r = begin_try_block ();
1260 FN_TRY_BLOCK_P (r) = 1;
1261 return r;
1264 /* Finish a try-block, which may be given by TRY_BLOCK. */
1266 void
1267 finish_try_block (tree try_block)
1269 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
1270 TRY_HANDLERS (try_block) = push_stmt_list ();
1273 /* Finish the body of a cleanup try-block, which may be given by
1274 TRY_BLOCK. */
1276 void
1277 finish_cleanup_try_block (tree try_block)
1279 TRY_STMTS (try_block) = pop_stmt_list (TRY_STMTS (try_block));
1282 /* Finish an implicitly generated try-block, with a cleanup is given
1283 by CLEANUP. */
1285 void
1286 finish_cleanup (tree cleanup, tree try_block)
1288 TRY_HANDLERS (try_block) = cleanup;
1289 CLEANUP_P (try_block) = 1;
1292 /* Likewise, for a function-try-block. */
1294 void
1295 finish_function_try_block (tree try_block)
1297 finish_try_block (try_block);
1298 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1299 the try block, but moving it inside. */
1300 in_function_try_handler = 1;
1303 /* Finish a handler-sequence for a try-block, which may be given by
1304 TRY_BLOCK. */
1306 void
1307 finish_handler_sequence (tree try_block)
1309 TRY_HANDLERS (try_block) = pop_stmt_list (TRY_HANDLERS (try_block));
1310 check_handlers (TRY_HANDLERS (try_block));
1313 /* Finish the handler-seq for a function-try-block, given by
1314 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1315 begin_function_try_block. */
1317 void
1318 finish_function_handler_sequence (tree try_block, tree compound_stmt)
1320 in_function_try_handler = 0;
1321 finish_handler_sequence (try_block);
1322 finish_compound_stmt (compound_stmt);
1325 /* Begin a handler. Returns a HANDLER if appropriate. */
1327 tree
1328 begin_handler (void)
1330 tree r;
1332 r = build_stmt (input_location, HANDLER, NULL_TREE, NULL_TREE);
1333 add_stmt (r);
1335 /* Create a binding level for the eh_info and the exception object
1336 cleanup. */
1337 HANDLER_BODY (r) = do_pushlevel (sk_catch);
1339 return r;
1342 /* Finish the handler-parameters for a handler, which may be given by
1343 HANDLER. DECL is the declaration for the catch parameter, or NULL
1344 if this is a `catch (...)' clause. */
1346 void
1347 finish_handler_parms (tree decl, tree handler)
1349 tree type = NULL_TREE;
1350 if (processing_template_decl)
1352 if (decl)
1354 decl = pushdecl (decl);
1355 decl = push_template_decl (decl);
1356 HANDLER_PARMS (handler) = decl;
1357 type = TREE_TYPE (decl);
1360 else
1362 type = expand_start_catch_block (decl);
1363 if (warn_catch_value
1364 && type != NULL_TREE
1365 && type != error_mark_node
1366 && !TYPE_REF_P (TREE_TYPE (decl)))
1368 tree orig_type = TREE_TYPE (decl);
1369 if (CLASS_TYPE_P (orig_type))
1371 if (TYPE_POLYMORPHIC_P (orig_type))
1372 warning (OPT_Wcatch_value_,
1373 "catching polymorphic type %q#T by value", orig_type);
1374 else if (warn_catch_value > 1)
1375 warning (OPT_Wcatch_value_,
1376 "catching type %q#T by value", orig_type);
1378 else if (warn_catch_value > 2)
1379 warning (OPT_Wcatch_value_,
1380 "catching non-reference type %q#T", orig_type);
1383 HANDLER_TYPE (handler) = type;
1386 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1387 the return value from the matching call to finish_handler_parms. */
1389 void
1390 finish_handler (tree handler)
1392 if (!processing_template_decl)
1393 expand_end_catch_block ();
1394 HANDLER_BODY (handler) = do_poplevel (HANDLER_BODY (handler));
1397 /* Begin a compound statement. FLAGS contains some bits that control the
1398 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1399 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1400 block of a function. If BCS_TRY_BLOCK is set, this is the block
1401 created on behalf of a TRY statement. Returns a token to be passed to
1402 finish_compound_stmt. */
1404 tree
1405 begin_compound_stmt (unsigned int flags)
1407 tree r;
1409 if (flags & BCS_NO_SCOPE)
1411 r = push_stmt_list ();
1412 STATEMENT_LIST_NO_SCOPE (r) = 1;
1414 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1415 But, if it's a statement-expression with a scopeless block, there's
1416 nothing to keep, and we don't want to accidentally keep a block
1417 *inside* the scopeless block. */
1418 keep_next_level (false);
1420 else
1422 scope_kind sk = sk_block;
1423 if (flags & BCS_TRY_BLOCK)
1424 sk = sk_try;
1425 else if (flags & BCS_TRANSACTION)
1426 sk = sk_transaction;
1427 r = do_pushlevel (sk);
1430 /* When processing a template, we need to remember where the braces were,
1431 so that we can set up identical scopes when instantiating the template
1432 later. BIND_EXPR is a handy candidate for this.
1433 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1434 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1435 processing templates. */
1436 if (processing_template_decl)
1438 r = build3 (BIND_EXPR, NULL, NULL, r, NULL);
1439 BIND_EXPR_TRY_BLOCK (r) = (flags & BCS_TRY_BLOCK) != 0;
1440 BIND_EXPR_BODY_BLOCK (r) = (flags & BCS_FN_BODY) != 0;
1441 TREE_SIDE_EFFECTS (r) = 1;
1444 return r;
1447 /* Finish a compound-statement, which is given by STMT. */
1449 void
1450 finish_compound_stmt (tree stmt)
1452 if (TREE_CODE (stmt) == BIND_EXPR)
1454 tree body = do_poplevel (BIND_EXPR_BODY (stmt));
1455 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1456 discard the BIND_EXPR so it can be merged with the containing
1457 STATEMENT_LIST. */
1458 if (TREE_CODE (body) == STATEMENT_LIST
1459 && STATEMENT_LIST_HEAD (body) == NULL
1460 && !BIND_EXPR_BODY_BLOCK (stmt)
1461 && !BIND_EXPR_TRY_BLOCK (stmt))
1462 stmt = body;
1463 else
1464 BIND_EXPR_BODY (stmt) = body;
1466 else if (STATEMENT_LIST_NO_SCOPE (stmt))
1467 stmt = pop_stmt_list (stmt);
1468 else
1470 /* Destroy any ObjC "super" receivers that may have been
1471 created. */
1472 objc_clear_super_receiver ();
1474 stmt = do_poplevel (stmt);
1477 /* ??? See c_end_compound_stmt wrt statement expressions. */
1478 add_stmt (stmt);
1481 /* Finish an asm-statement, whose components are a STRING, some
1482 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1483 LABELS. Also note whether the asm-statement should be
1484 considered volatile. */
1486 tree
1487 finish_asm_stmt (int volatile_p, tree string, tree output_operands,
1488 tree input_operands, tree clobbers, tree labels)
1490 tree r;
1491 tree t;
1492 int ninputs = list_length (input_operands);
1493 int noutputs = list_length (output_operands);
1495 if (!processing_template_decl)
1497 const char *constraint;
1498 const char **oconstraints;
1499 bool allows_mem, allows_reg, is_inout;
1500 tree operand;
1501 int i;
1503 oconstraints = XALLOCAVEC (const char *, noutputs);
1505 string = resolve_asm_operand_names (string, output_operands,
1506 input_operands, labels);
1508 for (i = 0, t = output_operands; t; t = TREE_CHAIN (t), ++i)
1510 operand = TREE_VALUE (t);
1512 /* ??? Really, this should not be here. Users should be using a
1513 proper lvalue, dammit. But there's a long history of using
1514 casts in the output operands. In cases like longlong.h, this
1515 becomes a primitive form of typechecking -- if the cast can be
1516 removed, then the output operand had a type of the proper width;
1517 otherwise we'll get an error. Gross, but ... */
1518 STRIP_NOPS (operand);
1520 operand = mark_lvalue_use (operand);
1522 if (!lvalue_or_else (operand, lv_asm, tf_warning_or_error))
1523 operand = error_mark_node;
1525 if (operand != error_mark_node
1526 && (TREE_READONLY (operand)
1527 || CP_TYPE_CONST_P (TREE_TYPE (operand))
1528 /* Functions are not modifiable, even though they are
1529 lvalues. */
1530 || TREE_CODE (TREE_TYPE (operand)) == FUNCTION_TYPE
1531 || TREE_CODE (TREE_TYPE (operand)) == METHOD_TYPE
1532 /* If it's an aggregate and any field is const, then it is
1533 effectively const. */
1534 || (CLASS_TYPE_P (TREE_TYPE (operand))
1535 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand)))))
1536 cxx_readonly_error (input_location, operand, lv_asm);
1538 tree *op = &operand;
1539 while (TREE_CODE (*op) == COMPOUND_EXPR)
1540 op = &TREE_OPERAND (*op, 1);
1541 switch (TREE_CODE (*op))
1543 case PREINCREMENT_EXPR:
1544 case PREDECREMENT_EXPR:
1545 case MODIFY_EXPR:
1546 *op = genericize_compound_lvalue (*op);
1547 op = &TREE_OPERAND (*op, 1);
1548 break;
1549 default:
1550 break;
1553 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
1554 oconstraints[i] = constraint;
1556 if (parse_output_constraint (&constraint, i, ninputs, noutputs,
1557 &allows_mem, &allows_reg, &is_inout))
1559 /* If the operand is going to end up in memory,
1560 mark it addressable. */
1561 if (!allows_reg && !cxx_mark_addressable (*op))
1562 operand = error_mark_node;
1564 else
1565 operand = error_mark_node;
1567 TREE_VALUE (t) = operand;
1570 for (i = 0, t = input_operands; t; ++i, t = TREE_CHAIN (t))
1572 constraint = TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t)));
1573 bool constraint_parsed
1574 = parse_input_constraint (&constraint, i, ninputs, noutputs, 0,
1575 oconstraints, &allows_mem, &allows_reg);
1576 /* If the operand is going to end up in memory, don't call
1577 decay_conversion. */
1578 if (constraint_parsed && !allows_reg && allows_mem)
1579 operand = mark_lvalue_use (TREE_VALUE (t));
1580 else
1581 operand = decay_conversion (TREE_VALUE (t), tf_warning_or_error);
1583 /* If the type of the operand hasn't been determined (e.g.,
1584 because it involves an overloaded function), then issue
1585 an error message. There's no context available to
1586 resolve the overloading. */
1587 if (TREE_TYPE (operand) == unknown_type_node)
1589 error ("type of asm operand %qE could not be determined",
1590 TREE_VALUE (t));
1591 operand = error_mark_node;
1594 if (constraint_parsed)
1596 /* If the operand is going to end up in memory,
1597 mark it addressable. */
1598 if (!allows_reg && allows_mem)
1600 /* Strip the nops as we allow this case. FIXME, this really
1601 should be rejected or made deprecated. */
1602 STRIP_NOPS (operand);
1604 tree *op = &operand;
1605 while (TREE_CODE (*op) == COMPOUND_EXPR)
1606 op = &TREE_OPERAND (*op, 1);
1607 switch (TREE_CODE (*op))
1609 case PREINCREMENT_EXPR:
1610 case PREDECREMENT_EXPR:
1611 case MODIFY_EXPR:
1612 *op = genericize_compound_lvalue (*op);
1613 op = &TREE_OPERAND (*op, 1);
1614 break;
1615 default:
1616 break;
1619 if (!cxx_mark_addressable (*op))
1620 operand = error_mark_node;
1622 else if (!allows_reg && !allows_mem)
1624 /* If constraint allows neither register nor memory,
1625 try harder to get a constant. */
1626 tree constop = maybe_constant_value (operand);
1627 if (TREE_CONSTANT (constop))
1628 operand = constop;
1631 else
1632 operand = error_mark_node;
1634 TREE_VALUE (t) = operand;
1638 r = build_stmt (input_location, ASM_EXPR, string,
1639 output_operands, input_operands,
1640 clobbers, labels);
1641 ASM_VOLATILE_P (r) = volatile_p || noutputs == 0;
1642 r = maybe_cleanup_point_expr_void (r);
1643 return add_stmt (r);
1646 /* Finish a label with the indicated NAME. Returns the new label. */
1648 tree
1649 finish_label_stmt (tree name)
1651 tree decl = define_label (input_location, name);
1653 if (decl == error_mark_node)
1654 return error_mark_node;
1656 add_stmt (build_stmt (input_location, LABEL_EXPR, decl));
1658 return decl;
1661 /* Finish a series of declarations for local labels. G++ allows users
1662 to declare "local" labels, i.e., labels with scope. This extension
1663 is useful when writing code involving statement-expressions. */
1665 void
1666 finish_label_decl (tree name)
1668 if (!at_function_scope_p ())
1670 error ("__label__ declarations are only allowed in function scopes");
1671 return;
1674 add_decl_expr (declare_local_label (name));
1677 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1679 void
1680 finish_decl_cleanup (tree decl, tree cleanup)
1682 push_cleanup (decl, cleanup, false);
1685 /* If the current scope exits with an exception, run CLEANUP. */
1687 void
1688 finish_eh_cleanup (tree cleanup)
1690 push_cleanup (NULL, cleanup, true);
1693 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1694 order they were written by the user. Each node is as for
1695 emit_mem_initializers. */
1697 void
1698 finish_mem_initializers (tree mem_inits)
1700 /* Reorder the MEM_INITS so that they are in the order they appeared
1701 in the source program. */
1702 mem_inits = nreverse (mem_inits);
1704 if (processing_template_decl)
1706 tree mem;
1708 for (mem = mem_inits; mem; mem = TREE_CHAIN (mem))
1710 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1711 check for bare parameter packs in the TREE_VALUE, because
1712 any parameter packs in the TREE_VALUE have already been
1713 bound as part of the TREE_PURPOSE. See
1714 make_pack_expansion for more information. */
1715 if (TREE_CODE (TREE_PURPOSE (mem)) != TYPE_PACK_EXPANSION
1716 && check_for_bare_parameter_packs (TREE_VALUE (mem)))
1717 TREE_VALUE (mem) = error_mark_node;
1720 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION,
1721 CTOR_INITIALIZER, mem_inits));
1723 else
1724 emit_mem_initializers (mem_inits);
1727 /* Obfuscate EXPR if it looks like an id-expression or member access so
1728 that the call to finish_decltype in do_auto_deduction will give the
1729 right result. */
1731 tree
1732 force_paren_expr (tree expr)
1734 /* This is only needed for decltype(auto) in C++14. */
1735 if (cxx_dialect < cxx14)
1736 return expr;
1738 /* If we're in unevaluated context, we can't be deducing a
1739 return/initializer type, so we don't need to mess with this. */
1740 if (cp_unevaluated_operand)
1741 return expr;
1743 if (!DECL_P (expr) && TREE_CODE (expr) != COMPONENT_REF
1744 && TREE_CODE (expr) != SCOPE_REF)
1745 return expr;
1747 if (TREE_CODE (expr) == COMPONENT_REF
1748 || TREE_CODE (expr) == SCOPE_REF)
1749 REF_PARENTHESIZED_P (expr) = true;
1750 else if (processing_template_decl)
1751 expr = build1 (PAREN_EXPR, TREE_TYPE (expr), expr);
1752 else
1754 expr = build1 (VIEW_CONVERT_EXPR, TREE_TYPE (expr), expr);
1755 REF_PARENTHESIZED_P (expr) = true;
1758 return expr;
1761 /* If T is an id-expression obfuscated by force_paren_expr, undo the
1762 obfuscation and return the underlying id-expression. Otherwise
1763 return T. */
1765 tree
1766 maybe_undo_parenthesized_ref (tree t)
1768 if (cxx_dialect < cxx14)
1769 return t;
1771 if (INDIRECT_REF_P (t) && REF_PARENTHESIZED_P (t))
1773 t = TREE_OPERAND (t, 0);
1774 while (TREE_CODE (t) == NON_LVALUE_EXPR
1775 || TREE_CODE (t) == NOP_EXPR)
1776 t = TREE_OPERAND (t, 0);
1778 gcc_assert (TREE_CODE (t) == ADDR_EXPR
1779 || TREE_CODE (t) == STATIC_CAST_EXPR);
1780 t = TREE_OPERAND (t, 0);
1782 else if (TREE_CODE (t) == PAREN_EXPR)
1783 t = TREE_OPERAND (t, 0);
1784 else if (TREE_CODE (t) == VIEW_CONVERT_EXPR
1785 && REF_PARENTHESIZED_P (t))
1786 t = TREE_OPERAND (t, 0);
1788 return t;
1791 /* Finish a parenthesized expression EXPR. */
1793 cp_expr
1794 finish_parenthesized_expr (cp_expr expr)
1796 if (EXPR_P (expr))
1797 /* This inhibits warnings in c_common_truthvalue_conversion. */
1798 TREE_NO_WARNING (expr) = 1;
1800 if (TREE_CODE (expr) == OFFSET_REF
1801 || TREE_CODE (expr) == SCOPE_REF)
1802 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1803 enclosed in parentheses. */
1804 PTRMEM_OK_P (expr) = 0;
1806 if (TREE_CODE (expr) == STRING_CST)
1807 PAREN_STRING_LITERAL_P (expr) = 1;
1809 expr = cp_expr (force_paren_expr (expr), expr.get_location ());
1811 return expr;
1814 /* Finish a reference to a non-static data member (DECL) that is not
1815 preceded by `.' or `->'. */
1817 tree
1818 finish_non_static_data_member (tree decl, tree object, tree qualifying_scope)
1820 gcc_assert (TREE_CODE (decl) == FIELD_DECL);
1821 bool try_omp_private = !object && omp_private_member_map;
1822 tree ret;
1824 if (!object)
1826 tree scope = qualifying_scope;
1827 if (scope == NULL_TREE)
1828 scope = context_for_name_lookup (decl);
1829 object = maybe_dummy_object (scope, NULL);
1832 object = maybe_resolve_dummy (object, true);
1833 if (object == error_mark_node)
1834 return error_mark_node;
1836 /* DR 613/850: Can use non-static data members without an associated
1837 object in sizeof/decltype/alignof. */
1838 if (is_dummy_object (object) && cp_unevaluated_operand == 0
1839 && (!processing_template_decl || !current_class_ref))
1841 if (current_function_decl
1842 && DECL_STATIC_FUNCTION_P (current_function_decl))
1843 error ("invalid use of member %qD in static member function", decl);
1844 else
1845 error ("invalid use of non-static data member %qD", decl);
1846 inform (DECL_SOURCE_LOCATION (decl), "declared here");
1848 return error_mark_node;
1851 if (current_class_ptr)
1852 TREE_USED (current_class_ptr) = 1;
1853 if (processing_template_decl && !qualifying_scope)
1855 tree type = TREE_TYPE (decl);
1857 if (TYPE_REF_P (type))
1858 /* Quals on the object don't matter. */;
1859 else if (PACK_EXPANSION_P (type))
1860 /* Don't bother trying to represent this. */
1861 type = NULL_TREE;
1862 else
1864 /* Set the cv qualifiers. */
1865 int quals = cp_type_quals (TREE_TYPE (object));
1867 if (DECL_MUTABLE_P (decl))
1868 quals &= ~TYPE_QUAL_CONST;
1870 quals |= cp_type_quals (TREE_TYPE (decl));
1871 type = cp_build_qualified_type (type, quals);
1874 ret = (convert_from_reference
1875 (build_min (COMPONENT_REF, type, object, decl, NULL_TREE)));
1877 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1878 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1879 for now. */
1880 else if (processing_template_decl)
1881 ret = build_qualified_name (TREE_TYPE (decl),
1882 qualifying_scope,
1883 decl,
1884 /*template_p=*/false);
1885 else
1887 tree access_type = TREE_TYPE (object);
1889 perform_or_defer_access_check (TYPE_BINFO (access_type), decl,
1890 decl, tf_warning_or_error);
1892 /* If the data member was named `C::M', convert `*this' to `C'
1893 first. */
1894 if (qualifying_scope)
1896 tree binfo = NULL_TREE;
1897 object = build_scoped_ref (object, qualifying_scope,
1898 &binfo);
1901 ret = build_class_member_access_expr (object, decl,
1902 /*access_path=*/NULL_TREE,
1903 /*preserve_reference=*/false,
1904 tf_warning_or_error);
1906 if (try_omp_private)
1908 tree *v = omp_private_member_map->get (decl);
1909 if (v)
1910 ret = convert_from_reference (*v);
1912 return ret;
1915 /* If we are currently parsing a template and we encountered a typedef
1916 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1917 adds the typedef to a list tied to the current template.
1918 At template instantiation time, that list is walked and access check
1919 performed for each typedef.
1920 LOCATION is the location of the usage point of TYPEDEF_DECL. */
1922 void
1923 add_typedef_to_current_template_for_access_check (tree typedef_decl,
1924 tree context,
1925 location_t location)
1927 tree template_info = NULL;
1928 tree cs = current_scope ();
1930 if (!is_typedef_decl (typedef_decl)
1931 || !context
1932 || !CLASS_TYPE_P (context)
1933 || !cs)
1934 return;
1936 if (CLASS_TYPE_P (cs) || TREE_CODE (cs) == FUNCTION_DECL)
1937 template_info = get_template_info (cs);
1939 if (template_info
1940 && TI_TEMPLATE (template_info)
1941 && !currently_open_class (context))
1942 append_type_to_template_for_access_check (cs, typedef_decl,
1943 context, location);
1946 /* DECL was the declaration to which a qualified-id resolved. Issue
1947 an error message if it is not accessible. If OBJECT_TYPE is
1948 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1949 type of `*x', or `x', respectively. If the DECL was named as
1950 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1952 void
1953 check_accessibility_of_qualified_id (tree decl,
1954 tree object_type,
1955 tree nested_name_specifier)
1957 tree scope;
1958 tree qualifying_type = NULL_TREE;
1960 /* If we are parsing a template declaration and if decl is a typedef,
1961 add it to a list tied to the template.
1962 At template instantiation time, that list will be walked and
1963 access check performed. */
1964 add_typedef_to_current_template_for_access_check (decl,
1965 nested_name_specifier
1966 ? nested_name_specifier
1967 : DECL_CONTEXT (decl),
1968 input_location);
1970 /* If we're not checking, return immediately. */
1971 if (deferred_access_no_check)
1972 return;
1974 /* Determine the SCOPE of DECL. */
1975 scope = context_for_name_lookup (decl);
1976 /* If the SCOPE is not a type, then DECL is not a member. */
1977 if (!TYPE_P (scope))
1978 return;
1979 /* Compute the scope through which DECL is being accessed. */
1980 if (object_type
1981 /* OBJECT_TYPE might not be a class type; consider:
1983 class A { typedef int I; };
1984 I *p;
1985 p->A::I::~I();
1987 In this case, we will have "A::I" as the DECL, but "I" as the
1988 OBJECT_TYPE. */
1989 && CLASS_TYPE_P (object_type)
1990 && DERIVED_FROM_P (scope, object_type))
1991 /* If we are processing a `->' or `.' expression, use the type of the
1992 left-hand side. */
1993 qualifying_type = object_type;
1994 else if (nested_name_specifier)
1996 /* If the reference is to a non-static member of the
1997 current class, treat it as if it were referenced through
1998 `this'. */
1999 tree ct;
2000 if (DECL_NONSTATIC_MEMBER_P (decl)
2001 && current_class_ptr
2002 && DERIVED_FROM_P (scope, ct = current_nonlambda_class_type ()))
2003 qualifying_type = ct;
2004 /* Otherwise, use the type indicated by the
2005 nested-name-specifier. */
2006 else
2007 qualifying_type = nested_name_specifier;
2009 else
2010 /* Otherwise, the name must be from the current class or one of
2011 its bases. */
2012 qualifying_type = currently_open_derived_class (scope);
2014 if (qualifying_type
2015 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2016 or similar in a default argument value. */
2017 && CLASS_TYPE_P (qualifying_type)
2018 && !dependent_type_p (qualifying_type))
2019 perform_or_defer_access_check (TYPE_BINFO (qualifying_type), decl,
2020 decl, tf_warning_or_error);
2023 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2024 class named to the left of the "::" operator. DONE is true if this
2025 expression is a complete postfix-expression; it is false if this
2026 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2027 iff this expression is the operand of '&'. TEMPLATE_P is true iff
2028 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2029 is true iff this qualified name appears as a template argument. */
2031 tree
2032 finish_qualified_id_expr (tree qualifying_class,
2033 tree expr,
2034 bool done,
2035 bool address_p,
2036 bool template_p,
2037 bool template_arg_p,
2038 tsubst_flags_t complain)
2040 gcc_assert (TYPE_P (qualifying_class));
2042 if (error_operand_p (expr))
2043 return error_mark_node;
2045 if ((DECL_P (expr) || BASELINK_P (expr))
2046 && !mark_used (expr, complain))
2047 return error_mark_node;
2049 if (template_p)
2051 if (TREE_CODE (expr) == UNBOUND_CLASS_TEMPLATE)
2053 /* cp_parser_lookup_name thought we were looking for a type,
2054 but we're actually looking for a declaration. */
2055 qualifying_class = TYPE_CONTEXT (expr);
2056 expr = TYPE_IDENTIFIER (expr);
2058 else
2059 check_template_keyword (expr);
2062 /* If EXPR occurs as the operand of '&', use special handling that
2063 permits a pointer-to-member. */
2064 if (address_p && done)
2066 if (TREE_CODE (expr) == SCOPE_REF)
2067 expr = TREE_OPERAND (expr, 1);
2068 expr = build_offset_ref (qualifying_class, expr,
2069 /*address_p=*/true, complain);
2070 return expr;
2073 /* No need to check access within an enum. */
2074 if (TREE_CODE (qualifying_class) == ENUMERAL_TYPE
2075 && TREE_CODE (expr) != IDENTIFIER_NODE)
2076 return expr;
2078 /* Within the scope of a class, turn references to non-static
2079 members into expression of the form "this->...". */
2080 if (template_arg_p)
2081 /* But, within a template argument, we do not want make the
2082 transformation, as there is no "this" pointer. */
2084 else if (TREE_CODE (expr) == FIELD_DECL)
2086 push_deferring_access_checks (dk_no_check);
2087 expr = finish_non_static_data_member (expr, NULL_TREE,
2088 qualifying_class);
2089 pop_deferring_access_checks ();
2091 else if (BASELINK_P (expr))
2093 /* See if any of the functions are non-static members. */
2094 /* If so, the expression may be relative to 'this'. */
2095 if (!shared_member_p (expr)
2096 && current_class_ptr
2097 && DERIVED_FROM_P (qualifying_class,
2098 current_nonlambda_class_type ()))
2099 expr = (build_class_member_access_expr
2100 (maybe_dummy_object (qualifying_class, NULL),
2101 expr,
2102 BASELINK_ACCESS_BINFO (expr),
2103 /*preserve_reference=*/false,
2104 complain));
2105 else if (done)
2106 /* The expression is a qualified name whose address is not
2107 being taken. */
2108 expr = build_offset_ref (qualifying_class, expr, /*address_p=*/false,
2109 complain);
2111 else
2113 /* In a template, return a SCOPE_REF for most qualified-ids
2114 so that we can check access at instantiation time. But if
2115 we're looking at a member of the current instantiation, we
2116 know we have access and building up the SCOPE_REF confuses
2117 non-type template argument handling. */
2118 if (processing_template_decl
2119 && (!currently_open_class (qualifying_class)
2120 || TREE_CODE (expr) == IDENTIFIER_NODE
2121 || TREE_CODE (expr) == TEMPLATE_ID_EXPR
2122 || TREE_CODE (expr) == BIT_NOT_EXPR))
2123 expr = build_qualified_name (TREE_TYPE (expr),
2124 qualifying_class, expr,
2125 template_p);
2127 expr = convert_from_reference (expr);
2130 return expr;
2133 /* Begin a statement-expression. The value returned must be passed to
2134 finish_stmt_expr. */
2136 tree
2137 begin_stmt_expr (void)
2139 return push_stmt_list ();
2142 /* Process the final expression of a statement expression. EXPR can be
2143 NULL, if the final expression is empty. Return a STATEMENT_LIST
2144 containing all the statements in the statement-expression, or
2145 ERROR_MARK_NODE if there was an error. */
2147 tree
2148 finish_stmt_expr_expr (tree expr, tree stmt_expr)
2150 if (error_operand_p (expr))
2152 /* The type of the statement-expression is the type of the last
2153 expression. */
2154 TREE_TYPE (stmt_expr) = error_mark_node;
2155 return error_mark_node;
2158 /* If the last statement does not have "void" type, then the value
2159 of the last statement is the value of the entire expression. */
2160 if (expr)
2162 tree type = TREE_TYPE (expr);
2164 if (type && type_unknown_p (type))
2166 error ("a statement expression is an insufficient context"
2167 " for overload resolution");
2168 TREE_TYPE (stmt_expr) = error_mark_node;
2169 return error_mark_node;
2171 else if (processing_template_decl)
2173 expr = build_stmt (input_location, EXPR_STMT, expr);
2174 expr = add_stmt (expr);
2175 /* Mark the last statement so that we can recognize it as such at
2176 template-instantiation time. */
2177 EXPR_STMT_STMT_EXPR_RESULT (expr) = 1;
2179 else if (VOID_TYPE_P (type))
2181 /* Just treat this like an ordinary statement. */
2182 expr = finish_expr_stmt (expr);
2184 else
2186 /* It actually has a value we need to deal with. First, force it
2187 to be an rvalue so that we won't need to build up a copy
2188 constructor call later when we try to assign it to something. */
2189 expr = force_rvalue (expr, tf_warning_or_error);
2190 if (error_operand_p (expr))
2191 return error_mark_node;
2193 /* Update for array-to-pointer decay. */
2194 type = TREE_TYPE (expr);
2196 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2197 normal statement, but don't convert to void or actually add
2198 the EXPR_STMT. */
2199 if (TREE_CODE (expr) != CLEANUP_POINT_EXPR)
2200 expr = maybe_cleanup_point_expr (expr);
2201 add_stmt (expr);
2204 /* The type of the statement-expression is the type of the last
2205 expression. */
2206 TREE_TYPE (stmt_expr) = type;
2209 return stmt_expr;
2212 /* Finish a statement-expression. EXPR should be the value returned
2213 by the previous begin_stmt_expr. Returns an expression
2214 representing the statement-expression. */
2216 tree
2217 finish_stmt_expr (tree stmt_expr, bool has_no_scope)
2219 tree type;
2220 tree result;
2222 if (error_operand_p (stmt_expr))
2224 pop_stmt_list (stmt_expr);
2225 return error_mark_node;
2228 gcc_assert (TREE_CODE (stmt_expr) == STATEMENT_LIST);
2230 type = TREE_TYPE (stmt_expr);
2231 result = pop_stmt_list (stmt_expr);
2232 TREE_TYPE (result) = type;
2234 if (processing_template_decl)
2236 result = build_min (STMT_EXPR, type, result);
2237 TREE_SIDE_EFFECTS (result) = 1;
2238 STMT_EXPR_NO_SCOPE (result) = has_no_scope;
2240 else if (CLASS_TYPE_P (type))
2242 /* Wrap the statement-expression in a TARGET_EXPR so that the
2243 temporary object created by the final expression is destroyed at
2244 the end of the full-expression containing the
2245 statement-expression. */
2246 result = force_target_expr (type, result, tf_warning_or_error);
2249 return result;
2252 /* Returns the expression which provides the value of STMT_EXPR. */
2254 tree
2255 stmt_expr_value_expr (tree stmt_expr)
2257 tree t = STMT_EXPR_STMT (stmt_expr);
2259 if (TREE_CODE (t) == BIND_EXPR)
2260 t = BIND_EXPR_BODY (t);
2262 if (TREE_CODE (t) == STATEMENT_LIST && STATEMENT_LIST_TAIL (t))
2263 t = STATEMENT_LIST_TAIL (t)->stmt;
2265 if (TREE_CODE (t) == EXPR_STMT)
2266 t = EXPR_STMT_EXPR (t);
2268 return t;
2271 /* Return TRUE iff EXPR_STMT is an empty list of
2272 expression statements. */
2274 bool
2275 empty_expr_stmt_p (tree expr_stmt)
2277 tree body = NULL_TREE;
2279 if (expr_stmt == void_node)
2280 return true;
2282 if (expr_stmt)
2284 if (TREE_CODE (expr_stmt) == EXPR_STMT)
2285 body = EXPR_STMT_EXPR (expr_stmt);
2286 else if (TREE_CODE (expr_stmt) == STATEMENT_LIST)
2287 body = expr_stmt;
2290 if (body)
2292 if (TREE_CODE (body) == STATEMENT_LIST)
2293 return tsi_end_p (tsi_start (body));
2294 else
2295 return empty_expr_stmt_p (body);
2297 return false;
2300 /* Perform Koenig lookup. FN is the postfix-expression representing
2301 the function (or functions) to call; ARGS are the arguments to the
2302 call. Returns the functions to be considered by overload resolution. */
2304 cp_expr
2305 perform_koenig_lookup (cp_expr fn, vec<tree, va_gc> *args,
2306 tsubst_flags_t complain)
2308 tree identifier = NULL_TREE;
2309 tree functions = NULL_TREE;
2310 tree tmpl_args = NULL_TREE;
2311 bool template_id = false;
2312 location_t loc = fn.get_location ();
2314 if (TREE_CODE (fn) == TEMPLATE_ID_EXPR)
2316 /* Use a separate flag to handle null args. */
2317 template_id = true;
2318 tmpl_args = TREE_OPERAND (fn, 1);
2319 fn = TREE_OPERAND (fn, 0);
2322 /* Find the name of the overloaded function. */
2323 if (identifier_p (fn))
2324 identifier = fn;
2325 else
2327 functions = fn;
2328 identifier = OVL_NAME (functions);
2331 /* A call to a namespace-scope function using an unqualified name.
2333 Do Koenig lookup -- unless any of the arguments are
2334 type-dependent. */
2335 if (!any_type_dependent_arguments_p (args)
2336 && !any_dependent_template_arguments_p (tmpl_args))
2338 fn = lookup_arg_dependent (identifier, functions, args);
2339 if (!fn)
2341 /* The unqualified name could not be resolved. */
2342 if (complain & tf_error)
2343 fn = unqualified_fn_lookup_error (cp_expr (identifier, loc));
2344 else
2345 fn = identifier;
2347 else if (TREE_CODE (fn) == OVERLOAD && processing_template_decl)
2348 /* FIXME: We shouldn't really need to mark the lookup here, as
2349 resolving the (non-dependent) call should save the single
2350 function we resolve to. Related to PR c++/83529. */
2351 lookup_keep (fn);
2354 if (fn && template_id && fn != error_mark_node)
2355 fn = build2 (TEMPLATE_ID_EXPR, unknown_type_node, fn, tmpl_args);
2357 return fn;
2360 /* Generate an expression for `FN (ARGS)'. This may change the
2361 contents of ARGS.
2363 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2364 as a virtual call, even if FN is virtual. (This flag is set when
2365 encountering an expression where the function name is explicitly
2366 qualified. For example a call to `X::f' never generates a virtual
2367 call.)
2369 Returns code for the call. */
2371 tree
2372 finish_call_expr (tree fn, vec<tree, va_gc> **args, bool disallow_virtual,
2373 bool koenig_p, tsubst_flags_t complain)
2375 tree result;
2376 tree orig_fn;
2377 vec<tree, va_gc> *orig_args = *args;
2379 if (fn == error_mark_node)
2380 return error_mark_node;
2382 gcc_assert (!TYPE_P (fn));
2384 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2385 it so that we can tell this is a call to a known function. */
2386 fn = maybe_undo_parenthesized_ref (fn);
2388 orig_fn = fn;
2390 if (processing_template_decl)
2392 /* If FN is a local extern declaration or set thereof, look them up
2393 again at instantiation time. */
2394 if (is_overloaded_fn (fn))
2396 tree ifn = get_first_fn (fn);
2397 if (TREE_CODE (ifn) == FUNCTION_DECL
2398 && DECL_LOCAL_FUNCTION_P (ifn))
2399 orig_fn = DECL_NAME (ifn);
2402 /* If the call expression is dependent, build a CALL_EXPR node
2403 with no type; type_dependent_expression_p recognizes
2404 expressions with no type as being dependent. */
2405 if (type_dependent_expression_p (fn)
2406 || any_type_dependent_arguments_p (*args))
2408 result = build_min_nt_call_vec (orig_fn, *args);
2409 SET_EXPR_LOCATION (result, cp_expr_loc_or_loc (fn, input_location));
2410 KOENIG_LOOKUP_P (result) = koenig_p;
2411 if (is_overloaded_fn (fn))
2412 fn = get_fns (fn);
2414 if (cfun)
2416 bool abnormal = true;
2417 for (lkp_iterator iter (fn); abnormal && iter; ++iter)
2419 tree fndecl = *iter;
2420 if (TREE_CODE (fndecl) != FUNCTION_DECL
2421 || !TREE_THIS_VOLATILE (fndecl))
2422 abnormal = false;
2424 /* FIXME: Stop warning about falling off end of non-void
2425 function. But this is wrong. Even if we only see
2426 no-return fns at this point, we could select a
2427 future-defined return fn during instantiation. Or
2428 vice-versa. */
2429 if (abnormal)
2430 current_function_returns_abnormally = 1;
2432 return result;
2434 orig_args = make_tree_vector_copy (*args);
2435 if (!BASELINK_P (fn)
2436 && TREE_CODE (fn) != PSEUDO_DTOR_EXPR
2437 && TREE_TYPE (fn) != unknown_type_node)
2438 fn = build_non_dependent_expr (fn);
2439 make_args_non_dependent (*args);
2442 if (TREE_CODE (fn) == COMPONENT_REF)
2444 tree member = TREE_OPERAND (fn, 1);
2445 if (BASELINK_P (member))
2447 tree object = TREE_OPERAND (fn, 0);
2448 return build_new_method_call (object, member,
2449 args, NULL_TREE,
2450 (disallow_virtual
2451 ? LOOKUP_NORMAL | LOOKUP_NONVIRTUAL
2452 : LOOKUP_NORMAL),
2453 /*fn_p=*/NULL,
2454 complain);
2458 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2459 if (TREE_CODE (fn) == ADDR_EXPR
2460 && TREE_CODE (TREE_OPERAND (fn, 0)) == OVERLOAD)
2461 fn = TREE_OPERAND (fn, 0);
2463 if (is_overloaded_fn (fn))
2464 fn = baselink_for_fns (fn);
2466 result = NULL_TREE;
2467 if (BASELINK_P (fn))
2469 tree object;
2471 /* A call to a member function. From [over.call.func]:
2473 If the keyword this is in scope and refers to the class of
2474 that member function, or a derived class thereof, then the
2475 function call is transformed into a qualified function call
2476 using (*this) as the postfix-expression to the left of the
2477 . operator.... [Otherwise] a contrived object of type T
2478 becomes the implied object argument.
2480 In this situation:
2482 struct A { void f(); };
2483 struct B : public A {};
2484 struct C : public A { void g() { B::f(); }};
2486 "the class of that member function" refers to `A'. But 11.2
2487 [class.access.base] says that we need to convert 'this' to B* as
2488 part of the access, so we pass 'B' to maybe_dummy_object. */
2490 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn)))
2492 /* A constructor call always uses a dummy object. (This constructor
2493 call which has the form A::A () is actually invalid and we are
2494 going to reject it later in build_new_method_call.) */
2495 object = build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)));
2497 else
2498 object = maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn)),
2499 NULL);
2501 result = build_new_method_call (object, fn, args, NULL_TREE,
2502 (disallow_virtual
2503 ? LOOKUP_NORMAL|LOOKUP_NONVIRTUAL
2504 : LOOKUP_NORMAL),
2505 /*fn_p=*/NULL,
2506 complain);
2508 else if (is_overloaded_fn (fn))
2510 /* If the function is an overloaded builtin, resolve it. */
2511 if (TREE_CODE (fn) == FUNCTION_DECL
2512 && (DECL_BUILT_IN_CLASS (fn) == BUILT_IN_NORMAL
2513 || DECL_BUILT_IN_CLASS (fn) == BUILT_IN_MD))
2514 result = resolve_overloaded_builtin (input_location, fn, *args);
2516 if (!result)
2518 if (warn_sizeof_pointer_memaccess
2519 && (complain & tf_warning)
2520 && !vec_safe_is_empty (*args)
2521 && !processing_template_decl)
2523 location_t sizeof_arg_loc[3];
2524 tree sizeof_arg[3];
2525 unsigned int i;
2526 for (i = 0; i < 3; i++)
2528 tree t;
2530 sizeof_arg_loc[i] = UNKNOWN_LOCATION;
2531 sizeof_arg[i] = NULL_TREE;
2532 if (i >= (*args)->length ())
2533 continue;
2534 t = (**args)[i];
2535 if (TREE_CODE (t) != SIZEOF_EXPR)
2536 continue;
2537 if (SIZEOF_EXPR_TYPE_P (t))
2538 sizeof_arg[i] = TREE_TYPE (TREE_OPERAND (t, 0));
2539 else
2540 sizeof_arg[i] = TREE_OPERAND (t, 0);
2541 sizeof_arg_loc[i] = EXPR_LOCATION (t);
2543 sizeof_pointer_memaccess_warning
2544 (sizeof_arg_loc, fn, *args,
2545 sizeof_arg, same_type_ignoring_top_level_qualifiers_p);
2548 if ((complain & tf_warning)
2549 && TREE_CODE (fn) == FUNCTION_DECL
2550 && fndecl_built_in_p (fn, BUILT_IN_MEMSET)
2551 && vec_safe_length (*args) == 3
2552 && !any_type_dependent_arguments_p (*args))
2554 tree arg0 = (*orig_args)[0];
2555 tree arg1 = (*orig_args)[1];
2556 tree arg2 = (*orig_args)[2];
2557 int literal_mask = ((literal_integer_zerop (arg1) << 1)
2558 | (literal_integer_zerop (arg2) << 2));
2559 arg2 = instantiate_non_dependent_expr (arg2);
2560 warn_for_memset (input_location, arg0, arg2, literal_mask);
2563 /* A call to a namespace-scope function. */
2564 result = build_new_function_call (fn, args, complain);
2567 else if (TREE_CODE (fn) == PSEUDO_DTOR_EXPR)
2569 if (!vec_safe_is_empty (*args))
2570 error ("arguments to destructor are not allowed");
2571 /* Mark the pseudo-destructor call as having side-effects so
2572 that we do not issue warnings about its use. */
2573 result = build1 (NOP_EXPR,
2574 void_type_node,
2575 TREE_OPERAND (fn, 0));
2576 TREE_SIDE_EFFECTS (result) = 1;
2578 else if (CLASS_TYPE_P (TREE_TYPE (fn)))
2579 /* If the "function" is really an object of class type, it might
2580 have an overloaded `operator ()'. */
2581 result = build_op_call (fn, args, complain);
2583 if (!result)
2584 /* A call where the function is unknown. */
2585 result = cp_build_function_call_vec (fn, args, complain);
2587 if (processing_template_decl && result != error_mark_node)
2589 if (INDIRECT_REF_P (result))
2590 result = TREE_OPERAND (result, 0);
2591 result = build_call_vec (TREE_TYPE (result), orig_fn, orig_args);
2592 SET_EXPR_LOCATION (result, input_location);
2593 KOENIG_LOOKUP_P (result) = koenig_p;
2594 release_tree_vector (orig_args);
2595 result = convert_from_reference (result);
2598 return result;
2601 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2602 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2603 POSTDECREMENT_EXPR.) */
2605 cp_expr
2606 finish_increment_expr (cp_expr expr, enum tree_code code)
2608 /* input_location holds the location of the trailing operator token.
2609 Build a location of the form:
2610 expr++
2611 ~~~~^~
2612 with the caret at the operator token, ranging from the start
2613 of EXPR to the end of the operator token. */
2614 location_t combined_loc = make_location (input_location,
2615 expr.get_start (),
2616 get_finish (input_location));
2617 cp_expr result = build_x_unary_op (combined_loc, code, expr,
2618 tf_warning_or_error);
2619 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2620 result.set_location (combined_loc);
2621 return result;
2624 /* Finish a use of `this'. Returns an expression for `this'. */
2626 tree
2627 finish_this_expr (void)
2629 tree result = NULL_TREE;
2631 if (current_class_ptr)
2633 tree type = TREE_TYPE (current_class_ref);
2635 /* In a lambda expression, 'this' refers to the captured 'this'. */
2636 if (LAMBDA_TYPE_P (type))
2637 result = lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type), true);
2638 else
2639 result = current_class_ptr;
2642 if (result)
2643 /* The keyword 'this' is a prvalue expression. */
2644 return rvalue (result);
2646 tree fn = current_nonlambda_function ();
2647 if (fn && DECL_STATIC_FUNCTION_P (fn))
2648 error ("%<this%> is unavailable for static member functions");
2649 else if (fn)
2650 error ("invalid use of %<this%> in non-member function");
2651 else
2652 error ("invalid use of %<this%> at top level");
2653 return error_mark_node;
2656 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2657 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2658 the TYPE for the type given. If SCOPE is non-NULL, the expression
2659 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2661 tree
2662 finish_pseudo_destructor_expr (tree object, tree scope, tree destructor,
2663 location_t loc)
2665 if (object == error_mark_node || destructor == error_mark_node)
2666 return error_mark_node;
2668 gcc_assert (TYPE_P (destructor));
2670 if (!processing_template_decl)
2672 if (scope == error_mark_node)
2674 error_at (loc, "invalid qualifying scope in pseudo-destructor name");
2675 return error_mark_node;
2677 if (is_auto (destructor))
2678 destructor = TREE_TYPE (object);
2679 if (scope && TYPE_P (scope) && !check_dtor_name (scope, destructor))
2681 error_at (loc,
2682 "qualified type %qT does not match destructor name ~%qT",
2683 scope, destructor);
2684 return error_mark_node;
2688 /* [expr.pseudo] says both:
2690 The type designated by the pseudo-destructor-name shall be
2691 the same as the object type.
2693 and:
2695 The cv-unqualified versions of the object type and of the
2696 type designated by the pseudo-destructor-name shall be the
2697 same type.
2699 We implement the more generous second sentence, since that is
2700 what most other compilers do. */
2701 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object),
2702 destructor))
2704 error_at (loc, "%qE is not of type %qT", object, destructor);
2705 return error_mark_node;
2709 return build3_loc (loc, PSEUDO_DTOR_EXPR, void_type_node, object,
2710 scope, destructor);
2713 /* Finish an expression of the form CODE EXPR. */
2715 cp_expr
2716 finish_unary_op_expr (location_t op_loc, enum tree_code code, cp_expr expr,
2717 tsubst_flags_t complain)
2719 /* Build a location of the form:
2720 ++expr
2721 ^~~~~~
2722 with the caret at the operator token, ranging from the start
2723 of the operator token to the end of EXPR. */
2724 location_t combined_loc = make_location (op_loc,
2725 op_loc, expr.get_finish ());
2726 cp_expr result = build_x_unary_op (combined_loc, code, expr, complain);
2727 /* TODO: build_x_unary_op doesn't always honor the location. */
2728 result.set_location (combined_loc);
2730 if (result == error_mark_node)
2731 return result;
2733 if (!(complain & tf_warning))
2734 return result;
2736 tree result_ovl = result;
2737 tree expr_ovl = expr;
2739 if (!processing_template_decl)
2740 expr_ovl = cp_fully_fold (expr_ovl);
2742 if (!CONSTANT_CLASS_P (expr_ovl)
2743 || TREE_OVERFLOW_P (expr_ovl))
2744 return result;
2746 if (!processing_template_decl)
2747 result_ovl = cp_fully_fold (result_ovl);
2749 if (CONSTANT_CLASS_P (result_ovl) && TREE_OVERFLOW_P (result_ovl))
2750 overflow_warning (combined_loc, result_ovl);
2752 return result;
2755 /* Finish a compound-literal expression or C++11 functional cast with aggregate
2756 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
2757 is being cast. */
2759 tree
2760 finish_compound_literal (tree type, tree compound_literal,
2761 tsubst_flags_t complain,
2762 fcl_t fcl_context)
2764 if (type == error_mark_node)
2765 return error_mark_node;
2767 if (TYPE_REF_P (type))
2769 compound_literal
2770 = finish_compound_literal (TREE_TYPE (type), compound_literal,
2771 complain, fcl_context);
2772 /* The prvalue is then used to direct-initialize the reference. */
2773 tree r = (perform_implicit_conversion_flags
2774 (type, compound_literal, complain, LOOKUP_NORMAL));
2775 return convert_from_reference (r);
2778 if (!TYPE_OBJ_P (type))
2780 if (complain & tf_error)
2781 error ("compound literal of non-object type %qT", type);
2782 return error_mark_node;
2785 if (tree anode = type_uses_auto (type))
2786 if (CLASS_PLACEHOLDER_TEMPLATE (anode))
2788 type = do_auto_deduction (type, compound_literal, anode, complain,
2789 adc_variable_type);
2790 if (type == error_mark_node)
2791 return error_mark_node;
2794 if (processing_template_decl)
2796 TREE_TYPE (compound_literal) = type;
2797 /* Mark the expression as a compound literal. */
2798 TREE_HAS_CONSTRUCTOR (compound_literal) = 1;
2799 if (fcl_context == fcl_c99)
2800 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
2801 return compound_literal;
2804 type = complete_type (type);
2806 if (TYPE_NON_AGGREGATE_CLASS (type))
2808 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2809 everywhere that deals with function arguments would be a pain, so
2810 just wrap it in a TREE_LIST. The parser set a flag so we know
2811 that it came from T{} rather than T({}). */
2812 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal) = 1;
2813 compound_literal = build_tree_list (NULL_TREE, compound_literal);
2814 return build_functional_cast (type, compound_literal, complain);
2817 if (TREE_CODE (type) == ARRAY_TYPE
2818 && check_array_initializer (NULL_TREE, type, compound_literal))
2819 return error_mark_node;
2820 compound_literal = reshape_init (type, compound_literal, complain);
2821 if (SCALAR_TYPE_P (type)
2822 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal)
2823 && !check_narrowing (type, compound_literal, complain))
2824 return error_mark_node;
2825 if (TREE_CODE (type) == ARRAY_TYPE
2826 && TYPE_DOMAIN (type) == NULL_TREE)
2828 cp_complete_array_type_or_error (&type, compound_literal,
2829 false, complain);
2830 if (type == error_mark_node)
2831 return error_mark_node;
2833 compound_literal = digest_init_flags (type, compound_literal, LOOKUP_NORMAL,
2834 complain);
2835 if (TREE_CODE (compound_literal) == CONSTRUCTOR)
2837 TREE_HAS_CONSTRUCTOR (compound_literal) = true;
2838 if (fcl_context == fcl_c99)
2839 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal) = 1;
2842 /* Put static/constant array temporaries in static variables. */
2843 /* FIXME all C99 compound literals should be variables rather than C++
2844 temporaries, unless they are used as an aggregate initializer. */
2845 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type))
2846 && fcl_context == fcl_c99
2847 && TREE_CODE (type) == ARRAY_TYPE
2848 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type)
2849 && initializer_constant_valid_p (compound_literal, type))
2851 tree decl = create_temporary_var (type);
2852 DECL_INITIAL (decl) = compound_literal;
2853 TREE_STATIC (decl) = 1;
2854 if (literal_type_p (type) && CP_TYPE_CONST_NON_VOLATILE_P (type))
2856 /* 5.19 says that a constant expression can include an
2857 lvalue-rvalue conversion applied to "a glvalue of literal type
2858 that refers to a non-volatile temporary object initialized
2859 with a constant expression". Rather than try to communicate
2860 that this VAR_DECL is a temporary, just mark it constexpr. */
2861 DECL_DECLARED_CONSTEXPR_P (decl) = true;
2862 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl) = true;
2863 TREE_CONSTANT (decl) = true;
2865 cp_apply_type_quals_to_decl (cp_type_quals (type), decl);
2866 decl = pushdecl_top_level (decl);
2867 DECL_NAME (decl) = make_anon_name ();
2868 SET_DECL_ASSEMBLER_NAME (decl, DECL_NAME (decl));
2869 /* Make sure the destructor is callable. */
2870 tree clean = cxx_maybe_build_cleanup (decl, complain);
2871 if (clean == error_mark_node)
2872 return error_mark_node;
2873 return decl;
2876 /* Represent other compound literals with TARGET_EXPR so we produce
2877 an lvalue, but can elide copies. */
2878 if (!VECTOR_TYPE_P (type))
2879 compound_literal = get_target_expr_sfinae (compound_literal, complain);
2881 return compound_literal;
2884 /* Return the declaration for the function-name variable indicated by
2885 ID. */
2887 tree
2888 finish_fname (tree id)
2890 tree decl;
2892 decl = fname_decl (input_location, C_RID_CODE (id), id);
2893 if (processing_template_decl && current_function_decl
2894 && decl != error_mark_node)
2895 decl = DECL_NAME (decl);
2896 return decl;
2899 /* Finish a translation unit. */
2901 void
2902 finish_translation_unit (void)
2904 /* In case there were missing closebraces,
2905 get us back to the global binding level. */
2906 pop_everything ();
2907 while (current_namespace != global_namespace)
2908 pop_namespace ();
2910 /* Do file scope __FUNCTION__ et al. */
2911 finish_fname_decls ();
2914 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2915 Returns the parameter. */
2917 tree
2918 finish_template_type_parm (tree aggr, tree identifier)
2920 if (aggr != class_type_node)
2922 permerror (input_location, "template type parameters must use the keyword %<class%> or %<typename%>");
2923 aggr = class_type_node;
2926 return build_tree_list (aggr, identifier);
2929 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2930 Returns the parameter. */
2932 tree
2933 finish_template_template_parm (tree aggr, tree identifier)
2935 tree decl = build_decl (input_location,
2936 TYPE_DECL, identifier, NULL_TREE);
2938 tree tmpl = build_lang_decl (TEMPLATE_DECL, identifier, NULL_TREE);
2939 DECL_TEMPLATE_PARMS (tmpl) = current_template_parms;
2940 DECL_TEMPLATE_RESULT (tmpl) = decl;
2941 DECL_ARTIFICIAL (decl) = 1;
2943 // Associate the constraints with the underlying declaration,
2944 // not the template.
2945 tree reqs = TEMPLATE_PARMS_CONSTRAINTS (current_template_parms);
2946 tree constr = build_constraints (reqs, NULL_TREE);
2947 set_constraints (decl, constr);
2949 end_template_decl ();
2951 gcc_assert (DECL_TEMPLATE_PARMS (tmpl));
2953 check_default_tmpl_args (decl, DECL_TEMPLATE_PARMS (tmpl),
2954 /*is_primary=*/true, /*is_partial=*/false,
2955 /*is_friend=*/0);
2957 return finish_template_type_parm (aggr, tmpl);
2960 /* ARGUMENT is the default-argument value for a template template
2961 parameter. If ARGUMENT is invalid, issue error messages and return
2962 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2964 tree
2965 check_template_template_default_arg (tree argument)
2967 if (TREE_CODE (argument) != TEMPLATE_DECL
2968 && TREE_CODE (argument) != TEMPLATE_TEMPLATE_PARM
2969 && TREE_CODE (argument) != UNBOUND_CLASS_TEMPLATE)
2971 if (TREE_CODE (argument) == TYPE_DECL)
2972 error ("invalid use of type %qT as a default value for a template "
2973 "template-parameter", TREE_TYPE (argument));
2974 else
2975 error ("invalid default argument for a template template parameter");
2976 return error_mark_node;
2979 return argument;
2982 /* Begin a class definition, as indicated by T. */
2984 tree
2985 begin_class_definition (tree t)
2987 if (error_operand_p (t) || error_operand_p (TYPE_MAIN_DECL (t)))
2988 return error_mark_node;
2990 if (processing_template_parmlist)
2992 error ("definition of %q#T inside template parameter list", t);
2993 return error_mark_node;
2996 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
2997 are passed the same as decimal scalar types. */
2998 if (TREE_CODE (t) == RECORD_TYPE
2999 && !processing_template_decl)
3001 tree ns = TYPE_CONTEXT (t);
3002 if (ns && TREE_CODE (ns) == NAMESPACE_DECL
3003 && DECL_CONTEXT (ns) == std_node
3004 && DECL_NAME (ns)
3005 && id_equal (DECL_NAME (ns), "decimal"))
3007 const char *n = TYPE_NAME_STRING (t);
3008 if ((strcmp (n, "decimal32") == 0)
3009 || (strcmp (n, "decimal64") == 0)
3010 || (strcmp (n, "decimal128") == 0))
3011 TYPE_TRANSPARENT_AGGR (t) = 1;
3015 /* A non-implicit typename comes from code like:
3017 template <typename T> struct A {
3018 template <typename U> struct A<T>::B ...
3020 This is erroneous. */
3021 else if (TREE_CODE (t) == TYPENAME_TYPE)
3023 error ("invalid definition of qualified type %qT", t);
3024 t = error_mark_node;
3027 if (t == error_mark_node || ! MAYBE_CLASS_TYPE_P (t))
3029 t = make_class_type (RECORD_TYPE);
3030 pushtag (make_anon_name (), t, /*tag_scope=*/ts_current);
3033 if (TYPE_BEING_DEFINED (t))
3035 t = make_class_type (TREE_CODE (t));
3036 pushtag (TYPE_IDENTIFIER (t), t, /*tag_scope=*/ts_current);
3038 maybe_process_partial_specialization (t);
3039 pushclass (t);
3040 TYPE_BEING_DEFINED (t) = 1;
3041 class_binding_level->defining_class_p = 1;
3043 if (flag_pack_struct)
3045 tree v;
3046 TYPE_PACKED (t) = 1;
3047 /* Even though the type is being defined for the first time
3048 here, there might have been a forward declaration, so there
3049 might be cv-qualified variants of T. */
3050 for (v = TYPE_NEXT_VARIANT (t); v; v = TYPE_NEXT_VARIANT (v))
3051 TYPE_PACKED (v) = 1;
3053 /* Reset the interface data, at the earliest possible
3054 moment, as it might have been set via a class foo;
3055 before. */
3056 if (! TYPE_UNNAMED_P (t))
3058 struct c_fileinfo *finfo = \
3059 get_fileinfo (LOCATION_FILE (input_location));
3060 CLASSTYPE_INTERFACE_ONLY (t) = finfo->interface_only;
3061 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
3062 (t, finfo->interface_unknown);
3064 reset_specialization();
3066 /* Make a declaration for this class in its own scope. */
3067 build_self_reference ();
3069 return t;
3072 /* Finish the member declaration given by DECL. */
3074 void
3075 finish_member_declaration (tree decl)
3077 if (decl == error_mark_node || decl == NULL_TREE)
3078 return;
3080 if (decl == void_type_node)
3081 /* The COMPONENT was a friend, not a member, and so there's
3082 nothing for us to do. */
3083 return;
3085 /* We should see only one DECL at a time. */
3086 gcc_assert (DECL_CHAIN (decl) == NULL_TREE);
3088 /* Don't add decls after definition. */
3089 gcc_assert (TYPE_BEING_DEFINED (current_class_type)
3090 /* We can add lambda types when late parsing default
3091 arguments. */
3092 || LAMBDA_TYPE_P (TREE_TYPE (decl)));
3094 /* Set up access control for DECL. */
3095 TREE_PRIVATE (decl)
3096 = (current_access_specifier == access_private_node);
3097 TREE_PROTECTED (decl)
3098 = (current_access_specifier == access_protected_node);
3099 if (TREE_CODE (decl) == TEMPLATE_DECL)
3101 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl)) = TREE_PRIVATE (decl);
3102 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl)) = TREE_PROTECTED (decl);
3105 /* Mark the DECL as a member of the current class, unless it's
3106 a member of an enumeration. */
3107 if (TREE_CODE (decl) != CONST_DECL)
3108 DECL_CONTEXT (decl) = current_class_type;
3110 if (TREE_CODE (decl) == USING_DECL)
3111 /* For now, ignore class-scope USING_DECLS, so that debugging
3112 backends do not see them. */
3113 DECL_IGNORED_P (decl) = 1;
3115 /* Check for bare parameter packs in the non-static data member
3116 declaration. */
3117 if (TREE_CODE (decl) == FIELD_DECL)
3119 if (check_for_bare_parameter_packs (TREE_TYPE (decl)))
3120 TREE_TYPE (decl) = error_mark_node;
3121 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl)))
3122 DECL_ATTRIBUTES (decl) = NULL_TREE;
3125 /* [dcl.link]
3127 A C language linkage is ignored for the names of class members
3128 and the member function type of class member functions. */
3129 if (DECL_LANG_SPECIFIC (decl))
3130 SET_DECL_LANGUAGE (decl, lang_cplusplus);
3132 bool add = false;
3134 /* Functions and non-functions are added differently. */
3135 if (DECL_DECLARES_FUNCTION_P (decl))
3136 add = add_method (current_class_type, decl, false);
3137 /* Enter the DECL into the scope of the class, if the class
3138 isn't a closure (whose fields are supposed to be unnamed). */
3139 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type)
3140 || pushdecl_class_level (decl))
3141 add = true;
3143 if (add)
3145 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3146 go at the beginning. The reason is that
3147 legacy_nonfn_member_lookup searches the list in order, and we
3148 want a field name to override a type name so that the "struct
3149 stat hack" will work. In particular:
3151 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3153 is valid. */
3155 if (TREE_CODE (decl) == TYPE_DECL)
3156 TYPE_FIELDS (current_class_type)
3157 = chainon (TYPE_FIELDS (current_class_type), decl);
3158 else
3160 DECL_CHAIN (decl) = TYPE_FIELDS (current_class_type);
3161 TYPE_FIELDS (current_class_type) = decl;
3164 maybe_add_class_template_decl_list (current_class_type, decl,
3165 /*friend_p=*/0);
3169 /* Finish processing a complete template declaration. The PARMS are
3170 the template parameters. */
3172 void
3173 finish_template_decl (tree parms)
3175 if (parms)
3176 end_template_decl ();
3177 else
3178 end_specialization ();
3181 // Returns the template type of the class scope being entered. If we're
3182 // entering a constrained class scope. TYPE is the class template
3183 // scope being entered and we may need to match the intended type with
3184 // a constrained specialization. For example:
3186 // template<Object T>
3187 // struct S { void f(); }; #1
3189 // template<Object T>
3190 // void S<T>::f() { } #2
3192 // We check, in #2, that S<T> refers precisely to the type declared by
3193 // #1 (i.e., that the constraints match). Note that the following should
3194 // be an error since there is no specialization of S<T> that is
3195 // unconstrained, but this is not diagnosed here.
3197 // template<typename T>
3198 // void S<T>::f() { }
3200 // We cannot diagnose this problem here since this function also matches
3201 // qualified template names that are not part of a definition. For example:
3203 // template<Integral T, Floating_point U>
3204 // typename pair<T, U>::first_type void f(T, U);
3206 // Here, it is unlikely that there is a partial specialization of
3207 // pair constrained for for Integral and Floating_point arguments.
3209 // The general rule is: if a constrained specialization with matching
3210 // constraints is found return that type. Also note that if TYPE is not a
3211 // class-type (e.g. a typename type), then no fixup is needed.
3213 static tree
3214 fixup_template_type (tree type)
3216 // Find the template parameter list at the a depth appropriate to
3217 // the scope we're trying to enter.
3218 tree parms = current_template_parms;
3219 int depth = template_class_depth (type);
3220 for (int n = processing_template_decl; n > depth && parms; --n)
3221 parms = TREE_CHAIN (parms);
3222 if (!parms)
3223 return type;
3224 tree cur_reqs = TEMPLATE_PARMS_CONSTRAINTS (parms);
3225 tree cur_constr = build_constraints (cur_reqs, NULL_TREE);
3227 // Search for a specialization whose type and constraints match.
3228 tree tmpl = CLASSTYPE_TI_TEMPLATE (type);
3229 tree specs = DECL_TEMPLATE_SPECIALIZATIONS (tmpl);
3230 while (specs)
3232 tree spec_constr = get_constraints (TREE_VALUE (specs));
3234 // If the type and constraints match a specialization, then we
3235 // are entering that type.
3236 if (same_type_p (type, TREE_TYPE (specs))
3237 && equivalent_constraints (cur_constr, spec_constr))
3238 return TREE_TYPE (specs);
3239 specs = TREE_CHAIN (specs);
3242 // If no specialization matches, then must return the type
3243 // previously found.
3244 return type;
3247 /* Finish processing a template-id (which names a type) of the form
3248 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3249 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3250 the scope of template-id indicated. */
3252 tree
3253 finish_template_type (tree name, tree args, int entering_scope)
3255 tree type;
3257 type = lookup_template_class (name, args,
3258 NULL_TREE, NULL_TREE, entering_scope,
3259 tf_warning_or_error | tf_user);
3261 /* If we might be entering the scope of a partial specialization,
3262 find the one with the right constraints. */
3263 if (flag_concepts
3264 && entering_scope
3265 && CLASS_TYPE_P (type)
3266 && CLASSTYPE_TEMPLATE_INFO (type)
3267 && dependent_type_p (type)
3268 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type)))
3269 type = fixup_template_type (type);
3271 if (type == error_mark_node)
3272 return type;
3273 else if (CLASS_TYPE_P (type) && !alias_type_or_template_p (type))
3274 return TYPE_STUB_DECL (type);
3275 else
3276 return TYPE_NAME (type);
3279 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3280 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3281 BASE_CLASS, or NULL_TREE if an error occurred. The
3282 ACCESS_SPECIFIER is one of
3283 access_{default,public,protected_private}_node. For a virtual base
3284 we set TREE_TYPE. */
3286 tree
3287 finish_base_specifier (tree base, tree access, bool virtual_p)
3289 tree result;
3291 if (base == error_mark_node)
3293 error ("invalid base-class specification");
3294 result = NULL_TREE;
3296 else if (! MAYBE_CLASS_TYPE_P (base))
3298 error ("%qT is not a class type", base);
3299 result = NULL_TREE;
3301 else
3303 if (cp_type_quals (base) != 0)
3305 /* DR 484: Can a base-specifier name a cv-qualified
3306 class type? */
3307 base = TYPE_MAIN_VARIANT (base);
3309 result = build_tree_list (access, base);
3310 if (virtual_p)
3311 TREE_TYPE (result) = integer_type_node;
3314 return result;
3317 /* If FNS is a member function, a set of member functions, or a
3318 template-id referring to one or more member functions, return a
3319 BASELINK for FNS, incorporating the current access context.
3320 Otherwise, return FNS unchanged. */
3322 tree
3323 baselink_for_fns (tree fns)
3325 tree scope;
3326 tree cl;
3328 if (BASELINK_P (fns)
3329 || error_operand_p (fns))
3330 return fns;
3332 scope = ovl_scope (fns);
3333 if (!CLASS_TYPE_P (scope))
3334 return fns;
3336 cl = currently_open_derived_class (scope);
3337 if (!cl)
3338 cl = scope;
3339 cl = TYPE_BINFO (cl);
3340 return build_baselink (cl, cl, fns, /*optype=*/NULL_TREE);
3343 /* Returns true iff DECL is a variable from a function outside
3344 the current one. */
3346 static bool
3347 outer_var_p (tree decl)
3349 return ((VAR_P (decl) || TREE_CODE (decl) == PARM_DECL)
3350 && DECL_FUNCTION_SCOPE_P (decl)
3351 /* Don't get confused by temporaries. */
3352 && DECL_NAME (decl)
3353 && (DECL_CONTEXT (decl) != current_function_decl
3354 || parsing_nsdmi ()));
3357 /* As above, but also checks that DECL is automatic. */
3359 bool
3360 outer_automatic_var_p (tree decl)
3362 return (outer_var_p (decl)
3363 && !TREE_STATIC (decl));
3366 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3367 rewrite it for lambda capture.
3369 If ODR_USE is true, we're being called from mark_use, and we complain about
3370 use of constant variables. If ODR_USE is false, we're being called for the
3371 id-expression, and we do lambda capture. */
3373 tree
3374 process_outer_var_ref (tree decl, tsubst_flags_t complain, bool odr_use)
3376 if (cp_unevaluated_operand)
3377 /* It's not a use (3.2) if we're in an unevaluated context. */
3378 return decl;
3379 if (decl == error_mark_node)
3380 return decl;
3382 tree context = DECL_CONTEXT (decl);
3383 tree containing_function = current_function_decl;
3384 tree lambda_stack = NULL_TREE;
3385 tree lambda_expr = NULL_TREE;
3386 tree initializer = convert_from_reference (decl);
3388 /* Mark it as used now even if the use is ill-formed. */
3389 if (!mark_used (decl, complain))
3390 return error_mark_node;
3392 if (parsing_nsdmi ())
3393 containing_function = NULL_TREE;
3395 if (containing_function && LAMBDA_FUNCTION_P (containing_function))
3397 /* Check whether we've already built a proxy. */
3398 tree var = decl;
3399 while (is_normal_capture_proxy (var))
3400 var = DECL_CAPTURED_VARIABLE (var);
3401 tree d = retrieve_local_specialization (var);
3403 if (d && d != decl && is_capture_proxy (d))
3405 if (DECL_CONTEXT (d) == containing_function)
3406 /* We already have an inner proxy. */
3407 return d;
3408 else
3409 /* We need to capture an outer proxy. */
3410 return process_outer_var_ref (d, complain, odr_use);
3414 /* If we are in a lambda function, we can move out until we hit
3415 1. the context,
3416 2. a non-lambda function, or
3417 3. a non-default capturing lambda function. */
3418 while (context != containing_function
3419 /* containing_function can be null with invalid generic lambdas. */
3420 && containing_function
3421 && LAMBDA_FUNCTION_P (containing_function))
3423 tree closure = DECL_CONTEXT (containing_function);
3424 lambda_expr = CLASSTYPE_LAMBDA_EXPR (closure);
3426 if (TYPE_CLASS_SCOPE_P (closure))
3427 /* A lambda in an NSDMI (c++/64496). */
3428 break;
3430 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr)
3431 == CPLD_NONE)
3432 break;
3434 lambda_stack = tree_cons (NULL_TREE,
3435 lambda_expr,
3436 lambda_stack);
3438 containing_function
3439 = decl_function_context (containing_function);
3442 /* In a lambda within a template, wait until instantiation
3443 time to implicitly capture. */
3444 if (context == containing_function
3445 && DECL_TEMPLATE_INFO (containing_function)
3446 && uses_template_parms (DECL_TI_ARGS (containing_function)))
3447 return decl;
3449 if (lambda_expr && VAR_P (decl)
3450 && DECL_ANON_UNION_VAR_P (decl))
3452 if (complain & tf_error)
3453 error ("cannot capture member %qD of anonymous union", decl);
3454 return error_mark_node;
3456 /* Do lambda capture when processing the id-expression, not when
3457 odr-using a variable. */
3458 if (!odr_use && context == containing_function)
3460 decl = add_default_capture (lambda_stack,
3461 /*id=*/DECL_NAME (decl),
3462 initializer);
3464 /* Only an odr-use of an outer automatic variable causes an
3465 error, and a constant variable can decay to a prvalue
3466 constant without odr-use. So don't complain yet. */
3467 else if (!odr_use && decl_constant_var_p (decl))
3468 return decl;
3469 else if (lambda_expr)
3471 if (complain & tf_error)
3473 error ("%qD is not captured", decl);
3474 tree closure = LAMBDA_EXPR_CLOSURE (lambda_expr);
3475 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr)
3476 == CPLD_NONE)
3477 inform (location_of (closure),
3478 "the lambda has no capture-default");
3479 else if (TYPE_CLASS_SCOPE_P (closure))
3480 inform (UNKNOWN_LOCATION, "lambda in local class %q+T cannot "
3481 "capture variables from the enclosing context",
3482 TYPE_CONTEXT (closure));
3483 inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
3485 return error_mark_node;
3487 else
3489 if (complain & tf_error)
3491 error (VAR_P (decl)
3492 ? G_("use of local variable with automatic storage from "
3493 "containing function")
3494 : G_("use of parameter from containing function"));
3495 inform (DECL_SOURCE_LOCATION (decl), "%q#D declared here", decl);
3497 return error_mark_node;
3499 return decl;
3502 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3503 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3504 if non-NULL, is the type or namespace used to explicitly qualify
3505 ID_EXPRESSION. DECL is the entity to which that name has been
3506 resolved.
3508 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3509 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3510 be set to true if this expression isn't permitted in a
3511 constant-expression, but it is otherwise not set by this function.
3512 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3513 constant-expression, but a non-constant expression is also
3514 permissible.
3516 DONE is true if this expression is a complete postfix-expression;
3517 it is false if this expression is followed by '->', '[', '(', etc.
3518 ADDRESS_P is true iff this expression is the operand of '&'.
3519 TEMPLATE_P is true iff the qualified-id was of the form
3520 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3521 appears as a template argument.
3523 If an error occurs, and it is the kind of error that might cause
3524 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3525 is the caller's responsibility to issue the message. *ERROR_MSG
3526 will be a string with static storage duration, so the caller need
3527 not "free" it.
3529 Return an expression for the entity, after issuing appropriate
3530 diagnostics. This function is also responsible for transforming a
3531 reference to a non-static member into a COMPONENT_REF that makes
3532 the use of "this" explicit.
3534 Upon return, *IDK will be filled in appropriately. */
3535 cp_expr
3536 finish_id_expression (tree id_expression,
3537 tree decl,
3538 tree scope,
3539 cp_id_kind *idk,
3540 bool integral_constant_expression_p,
3541 bool allow_non_integral_constant_expression_p,
3542 bool *non_integral_constant_expression_p,
3543 bool template_p,
3544 bool done,
3545 bool address_p,
3546 bool template_arg_p,
3547 const char **error_msg,
3548 location_t location)
3550 decl = strip_using_decl (decl);
3552 /* Initialize the output parameters. */
3553 *idk = CP_ID_KIND_NONE;
3554 *error_msg = NULL;
3556 if (id_expression == error_mark_node)
3557 return error_mark_node;
3558 /* If we have a template-id, then no further lookup is
3559 required. If the template-id was for a template-class, we
3560 will sometimes have a TYPE_DECL at this point. */
3561 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
3562 || TREE_CODE (decl) == TYPE_DECL)
3564 /* Look up the name. */
3565 else
3567 if (decl == error_mark_node)
3569 /* Name lookup failed. */
3570 if (scope
3571 && (!TYPE_P (scope)
3572 || (!dependent_type_p (scope)
3573 && !(identifier_p (id_expression)
3574 && IDENTIFIER_CONV_OP_P (id_expression)
3575 && dependent_type_p (TREE_TYPE (id_expression))))))
3577 /* If the qualifying type is non-dependent (and the name
3578 does not name a conversion operator to a dependent
3579 type), issue an error. */
3580 qualified_name_lookup_error (scope, id_expression, decl, location);
3581 return error_mark_node;
3583 else if (!scope)
3585 /* It may be resolved via Koenig lookup. */
3586 *idk = CP_ID_KIND_UNQUALIFIED;
3587 return id_expression;
3589 else
3590 decl = id_expression;
3593 /* Remember that the name was used in the definition of
3594 the current class so that we can check later to see if
3595 the meaning would have been different after the class
3596 was entirely defined. */
3597 if (!scope && decl != error_mark_node && identifier_p (id_expression))
3598 maybe_note_name_used_in_class (id_expression, decl);
3600 /* A use in unevaluated operand might not be instantiated appropriately
3601 if tsubst_copy builds a dummy parm, or if we never instantiate a
3602 generic lambda, so mark it now. */
3603 if (processing_template_decl && cp_unevaluated_operand)
3604 mark_type_use (decl);
3606 /* Disallow uses of local variables from containing functions, except
3607 within lambda-expressions. */
3608 if (outer_automatic_var_p (decl))
3610 decl = process_outer_var_ref (decl, tf_warning_or_error);
3611 if (decl == error_mark_node)
3612 return error_mark_node;
3615 /* Also disallow uses of function parameters outside the function
3616 body, except inside an unevaluated context (i.e. decltype). */
3617 if (TREE_CODE (decl) == PARM_DECL
3618 && DECL_CONTEXT (decl) == NULL_TREE
3619 && !cp_unevaluated_operand)
3621 *error_msg = G_("use of parameter outside function body");
3622 return error_mark_node;
3626 /* If we didn't find anything, or what we found was a type,
3627 then this wasn't really an id-expression. */
3628 if (TREE_CODE (decl) == TEMPLATE_DECL
3629 && !DECL_FUNCTION_TEMPLATE_P (decl))
3631 *error_msg = G_("missing template arguments");
3632 return error_mark_node;
3634 else if (TREE_CODE (decl) == TYPE_DECL
3635 || TREE_CODE (decl) == NAMESPACE_DECL)
3637 *error_msg = G_("expected primary-expression");
3638 return error_mark_node;
3641 /* If the name resolved to a template parameter, there is no
3642 need to look it up again later. */
3643 if ((TREE_CODE (decl) == CONST_DECL && DECL_TEMPLATE_PARM_P (decl))
3644 || TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
3646 tree r;
3648 *idk = CP_ID_KIND_NONE;
3649 if (TREE_CODE (decl) == TEMPLATE_PARM_INDEX)
3650 decl = TEMPLATE_PARM_DECL (decl);
3651 r = convert_from_reference (DECL_INITIAL (decl));
3653 if (integral_constant_expression_p
3654 && !dependent_type_p (TREE_TYPE (decl))
3655 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r))))
3657 if (!allow_non_integral_constant_expression_p)
3658 error ("template parameter %qD of type %qT is not allowed in "
3659 "an integral constant expression because it is not of "
3660 "integral or enumeration type", decl, TREE_TYPE (decl));
3661 *non_integral_constant_expression_p = true;
3663 return r;
3665 else
3667 bool dependent_p = type_dependent_expression_p (decl);
3669 /* If the declaration was explicitly qualified indicate
3670 that. The semantics of `A::f(3)' are different than
3671 `f(3)' if `f' is virtual. */
3672 *idk = (scope
3673 ? CP_ID_KIND_QUALIFIED
3674 : (TREE_CODE (decl) == TEMPLATE_ID_EXPR
3675 ? CP_ID_KIND_TEMPLATE_ID
3676 : (dependent_p
3677 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
3678 : CP_ID_KIND_UNQUALIFIED)));
3680 if (dependent_p
3681 && DECL_P (decl)
3682 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl)))
3683 /* Dependent type attributes on the decl mean that the TREE_TYPE is
3684 wrong, so just return the identifier. */
3685 return id_expression;
3687 if (TREE_CODE (decl) == NAMESPACE_DECL)
3689 error ("use of namespace %qD as expression", decl);
3690 return error_mark_node;
3692 else if (DECL_CLASS_TEMPLATE_P (decl))
3694 error ("use of class template %qT as expression", decl);
3695 return error_mark_node;
3697 else if (TREE_CODE (decl) == TREE_LIST)
3699 /* Ambiguous reference to base members. */
3700 error ("request for member %qD is ambiguous in "
3701 "multiple inheritance lattice", id_expression);
3702 print_candidates (decl);
3703 return error_mark_node;
3706 /* Mark variable-like entities as used. Functions are similarly
3707 marked either below or after overload resolution. */
3708 if ((VAR_P (decl)
3709 || TREE_CODE (decl) == PARM_DECL
3710 || TREE_CODE (decl) == CONST_DECL
3711 || TREE_CODE (decl) == RESULT_DECL)
3712 && !mark_used (decl))
3713 return error_mark_node;
3715 /* Only certain kinds of names are allowed in constant
3716 expression. Template parameters have already
3717 been handled above. */
3718 if (! error_operand_p (decl)
3719 && !dependent_p
3720 && integral_constant_expression_p
3721 && ! decl_constant_var_p (decl)
3722 && TREE_CODE (decl) != CONST_DECL
3723 && ! builtin_valid_in_constant_expr_p (decl))
3725 if (!allow_non_integral_constant_expression_p)
3727 error ("%qD cannot appear in a constant-expression", decl);
3728 return error_mark_node;
3730 *non_integral_constant_expression_p = true;
3733 tree wrap;
3734 if (VAR_P (decl)
3735 && !cp_unevaluated_operand
3736 && !processing_template_decl
3737 && (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
3738 && CP_DECL_THREAD_LOCAL_P (decl)
3739 && (wrap = get_tls_wrapper_fn (decl)))
3741 /* Replace an evaluated use of the thread_local variable with
3742 a call to its wrapper. */
3743 decl = build_cxx_call (wrap, 0, NULL, tf_warning_or_error);
3745 else if (TREE_CODE (decl) == TEMPLATE_ID_EXPR
3746 && !dependent_p
3747 && variable_template_p (TREE_OPERAND (decl, 0)))
3749 decl = finish_template_variable (decl);
3750 mark_used (decl);
3751 decl = convert_from_reference (decl);
3753 else if (scope)
3755 if (TREE_CODE (decl) == SCOPE_REF)
3757 gcc_assert (same_type_p (scope, TREE_OPERAND (decl, 0)));
3758 decl = TREE_OPERAND (decl, 1);
3761 decl = (adjust_result_of_qualified_name_lookup
3762 (decl, scope, current_nonlambda_class_type()));
3764 if (TREE_CODE (decl) == FUNCTION_DECL)
3765 mark_used (decl);
3767 if (TYPE_P (scope))
3768 decl = finish_qualified_id_expr (scope,
3769 decl,
3770 done,
3771 address_p,
3772 template_p,
3773 template_arg_p,
3774 tf_warning_or_error);
3775 else
3776 decl = convert_from_reference (decl);
3778 else if (TREE_CODE (decl) == FIELD_DECL)
3780 /* Since SCOPE is NULL here, this is an unqualified name.
3781 Access checking has been performed during name lookup
3782 already. Turn off checking to avoid duplicate errors. */
3783 push_deferring_access_checks (dk_no_check);
3784 decl = finish_non_static_data_member (decl, NULL_TREE,
3785 /*qualifying_scope=*/NULL_TREE);
3786 pop_deferring_access_checks ();
3788 else if (is_overloaded_fn (decl))
3790 tree first_fn = get_first_fn (decl);
3792 if (TREE_CODE (first_fn) == TEMPLATE_DECL)
3793 first_fn = DECL_TEMPLATE_RESULT (first_fn);
3795 /* [basic.def.odr]: "A function whose name appears as a
3796 potentially-evaluated expression is odr-used if it is the unique
3797 lookup result".
3799 But only mark it if it's a complete postfix-expression; in a call,
3800 ADL might select a different function, and we'll call mark_used in
3801 build_over_call. */
3802 if (done
3803 && !really_overloaded_fn (decl)
3804 && !mark_used (first_fn))
3805 return error_mark_node;
3807 if (!template_arg_p
3808 && TREE_CODE (first_fn) == FUNCTION_DECL
3809 && DECL_FUNCTION_MEMBER_P (first_fn)
3810 && !shared_member_p (decl))
3812 /* A set of member functions. */
3813 decl = maybe_dummy_object (DECL_CONTEXT (first_fn), 0);
3814 return finish_class_member_access_expr (decl, id_expression,
3815 /*template_p=*/false,
3816 tf_warning_or_error);
3819 decl = baselink_for_fns (decl);
3821 else
3823 if (DECL_P (decl) && DECL_NONLOCAL (decl)
3824 && DECL_CLASS_SCOPE_P (decl))
3826 tree context = context_for_name_lookup (decl);
3827 if (context != current_class_type)
3829 tree path = currently_open_derived_class (context);
3830 perform_or_defer_access_check (TYPE_BINFO (path),
3831 decl, decl,
3832 tf_warning_or_error);
3836 decl = convert_from_reference (decl);
3840 return cp_expr (decl, location);
3843 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3844 use as a type-specifier. */
3846 tree
3847 finish_typeof (tree expr)
3849 tree type;
3851 if (type_dependent_expression_p (expr))
3853 type = cxx_make_type (TYPEOF_TYPE);
3854 TYPEOF_TYPE_EXPR (type) = expr;
3855 SET_TYPE_STRUCTURAL_EQUALITY (type);
3857 return type;
3860 expr = mark_type_use (expr);
3862 type = unlowered_expr_type (expr);
3864 if (!type || type == unknown_type_node)
3866 error ("type of %qE is unknown", expr);
3867 return error_mark_node;
3870 return type;
3873 /* Implement the __underlying_type keyword: Return the underlying
3874 type of TYPE, suitable for use as a type-specifier. */
3876 tree
3877 finish_underlying_type (tree type)
3879 tree underlying_type;
3881 if (processing_template_decl)
3883 underlying_type = cxx_make_type (UNDERLYING_TYPE);
3884 UNDERLYING_TYPE_TYPE (underlying_type) = type;
3885 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type);
3887 return underlying_type;
3890 if (!complete_type_or_else (type, NULL_TREE))
3891 return error_mark_node;
3893 if (TREE_CODE (type) != ENUMERAL_TYPE)
3895 error ("%qT is not an enumeration type", type);
3896 return error_mark_node;
3899 underlying_type = ENUM_UNDERLYING_TYPE (type);
3901 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
3902 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
3903 See finish_enum_value_list for details. */
3904 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type))
3905 underlying_type
3906 = c_common_type_for_mode (TYPE_MODE (underlying_type),
3907 TYPE_UNSIGNED (underlying_type));
3909 return underlying_type;
3912 /* Implement the __direct_bases keyword: Return the direct base classes
3913 of type. */
3915 tree
3916 calculate_direct_bases (tree type, tsubst_flags_t complain)
3918 if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
3919 || !NON_UNION_CLASS_TYPE_P (type))
3920 return make_tree_vec (0);
3922 vec<tree, va_gc> *vector = make_tree_vector ();
3923 vec<tree, va_gc> *base_binfos = BINFO_BASE_BINFOS (TYPE_BINFO (type));
3924 tree binfo;
3925 unsigned i;
3927 /* Virtual bases are initialized first */
3928 for (i = 0; base_binfos->iterate (i, &binfo); i++)
3929 if (BINFO_VIRTUAL_P (binfo))
3930 vec_safe_push (vector, binfo);
3932 /* Now non-virtuals */
3933 for (i = 0; base_binfos->iterate (i, &binfo); i++)
3934 if (!BINFO_VIRTUAL_P (binfo))
3935 vec_safe_push (vector, binfo);
3937 tree bases_vec = make_tree_vec (vector->length ());
3939 for (i = 0; i < vector->length (); ++i)
3940 TREE_VEC_ELT (bases_vec, i) = BINFO_TYPE ((*vector)[i]);
3942 release_tree_vector (vector);
3943 return bases_vec;
3946 /* Implement the __bases keyword: Return the base classes
3947 of type */
3949 /* Find morally non-virtual base classes by walking binfo hierarchy */
3950 /* Virtual base classes are handled separately in finish_bases */
3952 static tree
3953 dfs_calculate_bases_pre (tree binfo, void * /*data_*/)
3955 /* Don't walk bases of virtual bases */
3956 return BINFO_VIRTUAL_P (binfo) ? dfs_skip_bases : NULL_TREE;
3959 static tree
3960 dfs_calculate_bases_post (tree binfo, void *data_)
3962 vec<tree, va_gc> **data = ((vec<tree, va_gc> **) data_);
3963 if (!BINFO_VIRTUAL_P (binfo))
3964 vec_safe_push (*data, BINFO_TYPE (binfo));
3965 return NULL_TREE;
3968 /* Calculates the morally non-virtual base classes of a class */
3969 static vec<tree, va_gc> *
3970 calculate_bases_helper (tree type)
3972 vec<tree, va_gc> *vector = make_tree_vector ();
3974 /* Now add non-virtual base classes in order of construction */
3975 if (TYPE_BINFO (type))
3976 dfs_walk_all (TYPE_BINFO (type),
3977 dfs_calculate_bases_pre, dfs_calculate_bases_post, &vector);
3978 return vector;
3981 tree
3982 calculate_bases (tree type, tsubst_flags_t complain)
3984 if (!complete_type_or_maybe_complain (type, NULL_TREE, complain)
3985 || !NON_UNION_CLASS_TYPE_P (type))
3986 return make_tree_vec (0);
3988 vec<tree, va_gc> *vector = make_tree_vector ();
3989 tree bases_vec = NULL_TREE;
3990 unsigned i;
3991 vec<tree, va_gc> *vbases;
3992 vec<tree, va_gc> *nonvbases;
3993 tree binfo;
3995 /* First go through virtual base classes */
3996 for (vbases = CLASSTYPE_VBASECLASSES (type), i = 0;
3997 vec_safe_iterate (vbases, i, &binfo); i++)
3999 vec<tree, va_gc> *vbase_bases
4000 = calculate_bases_helper (BINFO_TYPE (binfo));
4001 vec_safe_splice (vector, vbase_bases);
4002 release_tree_vector (vbase_bases);
4005 /* Now for the non-virtual bases */
4006 nonvbases = calculate_bases_helper (type);
4007 vec_safe_splice (vector, nonvbases);
4008 release_tree_vector (nonvbases);
4010 /* Note that during error recovery vector->length can even be zero. */
4011 if (vector->length () > 1)
4013 /* Last element is entire class, so don't copy */
4014 bases_vec = make_tree_vec (vector->length () - 1);
4016 for (i = 0; i < vector->length () - 1; ++i)
4017 TREE_VEC_ELT (bases_vec, i) = (*vector)[i];
4019 else
4020 bases_vec = make_tree_vec (0);
4022 release_tree_vector (vector);
4023 return bases_vec;
4026 tree
4027 finish_bases (tree type, bool direct)
4029 tree bases = NULL_TREE;
4031 if (!processing_template_decl)
4033 /* Parameter packs can only be used in templates */
4034 error ("Parameter pack __bases only valid in template declaration");
4035 return error_mark_node;
4038 bases = cxx_make_type (BASES);
4039 BASES_TYPE (bases) = type;
4040 BASES_DIRECT (bases) = direct;
4041 SET_TYPE_STRUCTURAL_EQUALITY (bases);
4043 return bases;
4046 /* Perform C++-specific checks for __builtin_offsetof before calling
4047 fold_offsetof. */
4049 tree
4050 finish_offsetof (tree object_ptr, tree expr, location_t loc)
4052 /* If we're processing a template, we can't finish the semantics yet.
4053 Otherwise we can fold the entire expression now. */
4054 if (processing_template_decl)
4056 expr = build2 (OFFSETOF_EXPR, size_type_node, expr, object_ptr);
4057 SET_EXPR_LOCATION (expr, loc);
4058 return expr;
4061 if (TREE_CODE (expr) == PSEUDO_DTOR_EXPR)
4063 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4064 TREE_OPERAND (expr, 2));
4065 return error_mark_node;
4067 if (TREE_CODE (TREE_TYPE (expr)) == FUNCTION_TYPE
4068 || TREE_CODE (TREE_TYPE (expr)) == METHOD_TYPE
4069 || TREE_TYPE (expr) == unknown_type_node)
4071 while (TREE_CODE (expr) == COMPONENT_REF
4072 || TREE_CODE (expr) == COMPOUND_EXPR)
4073 expr = TREE_OPERAND (expr, 1);
4075 if (DECL_P (expr))
4077 error ("cannot apply %<offsetof%> to member function %qD", expr);
4078 inform (DECL_SOURCE_LOCATION (expr), "declared here");
4080 else
4081 error ("cannot apply %<offsetof%> to member function");
4082 return error_mark_node;
4084 if (TREE_CODE (expr) == CONST_DECL)
4086 error ("cannot apply %<offsetof%> to an enumerator %qD", expr);
4087 return error_mark_node;
4089 if (REFERENCE_REF_P (expr))
4090 expr = TREE_OPERAND (expr, 0);
4091 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr)), object_ptr))
4092 return error_mark_node;
4093 if (warn_invalid_offsetof
4094 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr)))
4095 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr)))
4096 && cp_unevaluated_operand == 0)
4097 warning_at (loc, OPT_Winvalid_offsetof, "offsetof within "
4098 "non-standard-layout type %qT is conditionally-supported",
4099 TREE_TYPE (TREE_TYPE (object_ptr)));
4100 return fold_offsetof (expr);
4103 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4104 function is broken out from the above for the benefit of the tree-ssa
4105 project. */
4107 void
4108 simplify_aggr_init_expr (tree *tp)
4110 tree aggr_init_expr = *tp;
4112 /* Form an appropriate CALL_EXPR. */
4113 tree fn = AGGR_INIT_EXPR_FN (aggr_init_expr);
4114 tree slot = AGGR_INIT_EXPR_SLOT (aggr_init_expr);
4115 tree type = TREE_TYPE (slot);
4117 tree call_expr;
4118 enum style_t { ctor, arg, pcc } style;
4120 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr))
4121 style = ctor;
4122 #ifdef PCC_STATIC_STRUCT_RETURN
4123 else if (1)
4124 style = pcc;
4125 #endif
4126 else
4128 gcc_assert (TREE_ADDRESSABLE (type));
4129 style = arg;
4132 call_expr = build_call_array_loc (input_location,
4133 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn))),
4135 aggr_init_expr_nargs (aggr_init_expr),
4136 AGGR_INIT_EXPR_ARGP (aggr_init_expr));
4137 TREE_NOTHROW (call_expr) = TREE_NOTHROW (aggr_init_expr);
4138 CALL_FROM_THUNK_P (call_expr) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr);
4139 CALL_EXPR_OPERATOR_SYNTAX (call_expr)
4140 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr);
4141 CALL_EXPR_ORDERED_ARGS (call_expr) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr);
4142 CALL_EXPR_REVERSE_ARGS (call_expr) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr);
4144 if (style == ctor)
4146 /* Replace the first argument to the ctor with the address of the
4147 slot. */
4148 cxx_mark_addressable (slot);
4149 CALL_EXPR_ARG (call_expr, 0) =
4150 build1 (ADDR_EXPR, build_pointer_type (type), slot);
4152 else if (style == arg)
4154 /* Just mark it addressable here, and leave the rest to
4155 expand_call{,_inline}. */
4156 cxx_mark_addressable (slot);
4157 CALL_EXPR_RETURN_SLOT_OPT (call_expr) = true;
4158 call_expr = build2 (INIT_EXPR, TREE_TYPE (call_expr), slot, call_expr);
4160 else if (style == pcc)
4162 /* If we're using the non-reentrant PCC calling convention, then we
4163 need to copy the returned value out of the static buffer into the
4164 SLOT. */
4165 push_deferring_access_checks (dk_no_check);
4166 call_expr = build_aggr_init (slot, call_expr,
4167 DIRECT_BIND | LOOKUP_ONLYCONVERTING,
4168 tf_warning_or_error);
4169 pop_deferring_access_checks ();
4170 call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (slot), call_expr, slot);
4173 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr))
4175 tree init = build_zero_init (type, NULL_TREE,
4176 /*static_storage_p=*/false);
4177 init = build2 (INIT_EXPR, void_type_node, slot, init);
4178 call_expr = build2 (COMPOUND_EXPR, TREE_TYPE (call_expr),
4179 init, call_expr);
4182 *tp = call_expr;
4185 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4187 void
4188 emit_associated_thunks (tree fn)
4190 /* When we use vcall offsets, we emit thunks with the virtual
4191 functions to which they thunk. The whole point of vcall offsets
4192 is so that you can know statically the entire set of thunks that
4193 will ever be needed for a given virtual function, thereby
4194 enabling you to output all the thunks with the function itself. */
4195 if (DECL_VIRTUAL_P (fn)
4196 /* Do not emit thunks for extern template instantiations. */
4197 && ! DECL_REALLY_EXTERN (fn))
4199 tree thunk;
4201 for (thunk = DECL_THUNKS (fn); thunk; thunk = DECL_CHAIN (thunk))
4203 if (!THUNK_ALIAS (thunk))
4205 use_thunk (thunk, /*emit_p=*/1);
4206 if (DECL_RESULT_THUNK_P (thunk))
4208 tree probe;
4210 for (probe = DECL_THUNKS (thunk);
4211 probe; probe = DECL_CHAIN (probe))
4212 use_thunk (probe, /*emit_p=*/1);
4215 else
4216 gcc_assert (!DECL_THUNKS (thunk));
4221 /* Generate RTL for FN. */
4223 bool
4224 expand_or_defer_fn_1 (tree fn)
4226 /* When the parser calls us after finishing the body of a template
4227 function, we don't really want to expand the body. */
4228 if (processing_template_decl)
4230 /* Normally, collection only occurs in rest_of_compilation. So,
4231 if we don't collect here, we never collect junk generated
4232 during the processing of templates until we hit a
4233 non-template function. It's not safe to do this inside a
4234 nested class, though, as the parser may have local state that
4235 is not a GC root. */
4236 if (!function_depth)
4237 ggc_collect ();
4238 return false;
4241 gcc_assert (DECL_SAVED_TREE (fn));
4243 /* We make a decision about linkage for these functions at the end
4244 of the compilation. Until that point, we do not want the back
4245 end to output them -- but we do want it to see the bodies of
4246 these functions so that it can inline them as appropriate. */
4247 if (DECL_DECLARED_INLINE_P (fn) || DECL_IMPLICIT_INSTANTIATION (fn))
4249 if (DECL_INTERFACE_KNOWN (fn))
4250 /* We've already made a decision as to how this function will
4251 be handled. */;
4252 else if (!at_eof)
4253 tentative_decl_linkage (fn);
4254 else
4255 import_export_decl (fn);
4257 /* If the user wants us to keep all inline functions, then mark
4258 this function as needed so that finish_file will make sure to
4259 output it later. Similarly, all dllexport'd functions must
4260 be emitted; there may be callers in other DLLs. */
4261 if (DECL_DECLARED_INLINE_P (fn)
4262 && !DECL_REALLY_EXTERN (fn)
4263 && (flag_keep_inline_functions
4264 || (flag_keep_inline_dllexport
4265 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn)))))
4267 mark_needed (fn);
4268 DECL_EXTERNAL (fn) = 0;
4272 /* If this is a constructor or destructor body, we have to clone
4273 it. */
4274 if (maybe_clone_body (fn))
4276 /* We don't want to process FN again, so pretend we've written
4277 it out, even though we haven't. */
4278 TREE_ASM_WRITTEN (fn) = 1;
4279 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4280 if (!DECL_DECLARED_CONSTEXPR_P (fn))
4281 DECL_SAVED_TREE (fn) = NULL_TREE;
4282 return false;
4285 /* There's no reason to do any of the work here if we're only doing
4286 semantic analysis; this code just generates RTL. */
4287 if (flag_syntax_only)
4288 return false;
4290 return true;
4293 void
4294 expand_or_defer_fn (tree fn)
4296 if (expand_or_defer_fn_1 (fn))
4298 function_depth++;
4300 /* Expand or defer, at the whim of the compilation unit manager. */
4301 cgraph_node::finalize_function (fn, function_depth > 1);
4302 emit_associated_thunks (fn);
4304 function_depth--;
4308 struct nrv_data
4310 nrv_data () : visited (37) {}
4312 tree var;
4313 tree result;
4314 hash_table<nofree_ptr_hash <tree_node> > visited;
4317 /* Helper function for walk_tree, used by finalize_nrv below. */
4319 static tree
4320 finalize_nrv_r (tree* tp, int* walk_subtrees, void* data)
4322 struct nrv_data *dp = (struct nrv_data *)data;
4323 tree_node **slot;
4325 /* No need to walk into types. There wouldn't be any need to walk into
4326 non-statements, except that we have to consider STMT_EXPRs. */
4327 if (TYPE_P (*tp))
4328 *walk_subtrees = 0;
4329 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4330 but differs from using NULL_TREE in that it indicates that we care
4331 about the value of the RESULT_DECL. */
4332 else if (TREE_CODE (*tp) == RETURN_EXPR)
4333 TREE_OPERAND (*tp, 0) = dp->result;
4334 /* Change all cleanups for the NRV to only run when an exception is
4335 thrown. */
4336 else if (TREE_CODE (*tp) == CLEANUP_STMT
4337 && CLEANUP_DECL (*tp) == dp->var)
4338 CLEANUP_EH_ONLY (*tp) = 1;
4339 /* Replace the DECL_EXPR for the NRV with an initialization of the
4340 RESULT_DECL, if needed. */
4341 else if (TREE_CODE (*tp) == DECL_EXPR
4342 && DECL_EXPR_DECL (*tp) == dp->var)
4344 tree init;
4345 if (DECL_INITIAL (dp->var)
4346 && DECL_INITIAL (dp->var) != error_mark_node)
4347 init = build2 (INIT_EXPR, void_type_node, dp->result,
4348 DECL_INITIAL (dp->var));
4349 else
4350 init = build_empty_stmt (EXPR_LOCATION (*tp));
4351 DECL_INITIAL (dp->var) = NULL_TREE;
4352 SET_EXPR_LOCATION (init, EXPR_LOCATION (*tp));
4353 *tp = init;
4355 /* And replace all uses of the NRV with the RESULT_DECL. */
4356 else if (*tp == dp->var)
4357 *tp = dp->result;
4359 /* Avoid walking into the same tree more than once. Unfortunately, we
4360 can't just use walk_tree_without duplicates because it would only call
4361 us for the first occurrence of dp->var in the function body. */
4362 slot = dp->visited.find_slot (*tp, INSERT);
4363 if (*slot)
4364 *walk_subtrees = 0;
4365 else
4366 *slot = *tp;
4368 /* Keep iterating. */
4369 return NULL_TREE;
4372 /* Called from finish_function to implement the named return value
4373 optimization by overriding all the RETURN_EXPRs and pertinent
4374 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4375 RESULT_DECL for the function. */
4377 void
4378 finalize_nrv (tree *tp, tree var, tree result)
4380 struct nrv_data data;
4382 /* Copy name from VAR to RESULT. */
4383 DECL_NAME (result) = DECL_NAME (var);
4384 /* Don't forget that we take its address. */
4385 TREE_ADDRESSABLE (result) = TREE_ADDRESSABLE (var);
4386 /* Finally set DECL_VALUE_EXPR to avoid assigning
4387 a stack slot at -O0 for the original var and debug info
4388 uses RESULT location for VAR. */
4389 SET_DECL_VALUE_EXPR (var, result);
4390 DECL_HAS_VALUE_EXPR_P (var) = 1;
4392 data.var = var;
4393 data.result = result;
4394 cp_walk_tree (tp, finalize_nrv_r, &data, 0);
4397 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4399 bool
4400 cxx_omp_create_clause_info (tree c, tree type, bool need_default_ctor,
4401 bool need_copy_ctor, bool need_copy_assignment,
4402 bool need_dtor)
4404 int save_errorcount = errorcount;
4405 tree info, t;
4407 /* Always allocate 3 elements for simplicity. These are the
4408 function decls for the ctor, dtor, and assignment op.
4409 This layout is known to the three lang hooks,
4410 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4411 and cxx_omp_clause_assign_op. */
4412 info = make_tree_vec (3);
4413 CP_OMP_CLAUSE_INFO (c) = info;
4415 if (need_default_ctor || need_copy_ctor)
4417 if (need_default_ctor)
4418 t = get_default_ctor (type);
4419 else
4420 t = get_copy_ctor (type, tf_warning_or_error);
4422 if (t && !trivial_fn_p (t))
4423 TREE_VEC_ELT (info, 0) = t;
4426 if (need_dtor && TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
4427 TREE_VEC_ELT (info, 1) = get_dtor (type, tf_warning_or_error);
4429 if (need_copy_assignment)
4431 t = get_copy_assign (type);
4433 if (t && !trivial_fn_p (t))
4434 TREE_VEC_ELT (info, 2) = t;
4437 return errorcount != save_errorcount;
4440 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4441 FIELD_DECL, otherwise return DECL itself. */
4443 static tree
4444 omp_clause_decl_field (tree decl)
4446 if (VAR_P (decl)
4447 && DECL_HAS_VALUE_EXPR_P (decl)
4448 && DECL_ARTIFICIAL (decl)
4449 && DECL_LANG_SPECIFIC (decl)
4450 && DECL_OMP_PRIVATIZED_MEMBER (decl))
4452 tree f = DECL_VALUE_EXPR (decl);
4453 if (INDIRECT_REF_P (f))
4454 f = TREE_OPERAND (f, 0);
4455 if (TREE_CODE (f) == COMPONENT_REF)
4457 f = TREE_OPERAND (f, 1);
4458 gcc_assert (TREE_CODE (f) == FIELD_DECL);
4459 return f;
4462 return NULL_TREE;
4465 /* Adjust DECL if needed for printing using %qE. */
4467 static tree
4468 omp_clause_printable_decl (tree decl)
4470 tree t = omp_clause_decl_field (decl);
4471 if (t)
4472 return t;
4473 return decl;
4476 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4477 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4478 privatization. */
4480 static void
4481 omp_note_field_privatization (tree f, tree t)
4483 if (!omp_private_member_map)
4484 omp_private_member_map = new hash_map<tree, tree>;
4485 tree &v = omp_private_member_map->get_or_insert (f);
4486 if (v == NULL_TREE)
4488 v = t;
4489 omp_private_member_vec.safe_push (f);
4490 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4491 omp_private_member_vec.safe_push (integer_zero_node);
4495 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4496 dummy VAR_DECL. */
4498 tree
4499 omp_privatize_field (tree t, bool shared)
4501 tree m = finish_non_static_data_member (t, NULL_TREE, NULL_TREE);
4502 if (m == error_mark_node)
4503 return error_mark_node;
4504 if (!omp_private_member_map && !shared)
4505 omp_private_member_map = new hash_map<tree, tree>;
4506 if (TYPE_REF_P (TREE_TYPE (t)))
4508 gcc_assert (INDIRECT_REF_P (m));
4509 m = TREE_OPERAND (m, 0);
4511 tree vb = NULL_TREE;
4512 tree &v = shared ? vb : omp_private_member_map->get_or_insert (t);
4513 if (v == NULL_TREE)
4515 v = create_temporary_var (TREE_TYPE (m));
4516 retrofit_lang_decl (v);
4517 DECL_OMP_PRIVATIZED_MEMBER (v) = 1;
4518 SET_DECL_VALUE_EXPR (v, m);
4519 DECL_HAS_VALUE_EXPR_P (v) = 1;
4520 if (!shared)
4521 omp_private_member_vec.safe_push (t);
4523 return v;
4526 /* Helper function for handle_omp_array_sections. Called recursively
4527 to handle multiple array-section-subscripts. C is the clause,
4528 T current expression (initially OMP_CLAUSE_DECL), which is either
4529 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4530 expression if specified, TREE_VALUE length expression if specified,
4531 TREE_CHAIN is what it has been specified after, or some decl.
4532 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4533 set to true if any of the array-section-subscript could have length
4534 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4535 first array-section-subscript which is known not to have length
4536 of one. Given say:
4537 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4538 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4539 all are or may have length of 1, array-section-subscript [:2] is the
4540 first one known not to have length 1. For array-section-subscript
4541 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4542 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4543 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4544 case though, as some lengths could be zero. */
4546 static tree
4547 handle_omp_array_sections_1 (tree c, tree t, vec<tree> &types,
4548 bool &maybe_zero_len, unsigned int &first_non_one,
4549 enum c_omp_region_type ort)
4551 tree ret, low_bound, length, type;
4552 if (TREE_CODE (t) != TREE_LIST)
4554 if (error_operand_p (t))
4555 return error_mark_node;
4556 if (REFERENCE_REF_P (t)
4557 && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF)
4558 t = TREE_OPERAND (t, 0);
4559 ret = t;
4560 if (TREE_CODE (t) == COMPONENT_REF
4561 && ort == C_ORT_OMP
4562 && (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
4563 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO
4564 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM)
4565 && !type_dependent_expression_p (t))
4567 if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
4568 && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
4570 error_at (OMP_CLAUSE_LOCATION (c),
4571 "bit-field %qE in %qs clause",
4572 t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4573 return error_mark_node;
4575 while (TREE_CODE (t) == COMPONENT_REF)
4577 if (TREE_TYPE (TREE_OPERAND (t, 0))
4578 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0))) == UNION_TYPE)
4580 error_at (OMP_CLAUSE_LOCATION (c),
4581 "%qE is a member of a union", t);
4582 return error_mark_node;
4584 t = TREE_OPERAND (t, 0);
4586 if (REFERENCE_REF_P (t))
4587 t = TREE_OPERAND (t, 0);
4589 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
4591 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
4592 return NULL_TREE;
4593 if (DECL_P (t))
4594 error_at (OMP_CLAUSE_LOCATION (c),
4595 "%qD is not a variable in %qs clause", t,
4596 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4597 else
4598 error_at (OMP_CLAUSE_LOCATION (c),
4599 "%qE is not a variable in %qs clause", t,
4600 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4601 return error_mark_node;
4603 else if (TREE_CODE (t) == PARM_DECL
4604 && DECL_ARTIFICIAL (t)
4605 && DECL_NAME (t) == this_identifier)
4607 error_at (OMP_CLAUSE_LOCATION (c),
4608 "%<this%> allowed in OpenMP only in %<declare simd%>"
4609 " clauses");
4610 return error_mark_node;
4612 else if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
4613 && VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
4615 error_at (OMP_CLAUSE_LOCATION (c),
4616 "%qD is threadprivate variable in %qs clause", t,
4617 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4618 return error_mark_node;
4620 if (type_dependent_expression_p (ret))
4621 return NULL_TREE;
4622 ret = convert_from_reference (ret);
4623 return ret;
4626 if (ort == C_ORT_OMP
4627 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION
4628 && TREE_CODE (TREE_CHAIN (t)) == FIELD_DECL)
4629 TREE_CHAIN (t) = omp_privatize_field (TREE_CHAIN (t), false);
4630 ret = handle_omp_array_sections_1 (c, TREE_CHAIN (t), types,
4631 maybe_zero_len, first_non_one, ort);
4632 if (ret == error_mark_node || ret == NULL_TREE)
4633 return ret;
4635 type = TREE_TYPE (ret);
4636 low_bound = TREE_PURPOSE (t);
4637 length = TREE_VALUE (t);
4638 if ((low_bound && type_dependent_expression_p (low_bound))
4639 || (length && type_dependent_expression_p (length)))
4640 return NULL_TREE;
4642 if (low_bound == error_mark_node || length == error_mark_node)
4643 return error_mark_node;
4645 if (low_bound && !INTEGRAL_TYPE_P (TREE_TYPE (low_bound)))
4647 error_at (OMP_CLAUSE_LOCATION (c),
4648 "low bound %qE of array section does not have integral type",
4649 low_bound);
4650 return error_mark_node;
4652 if (length && !INTEGRAL_TYPE_P (TREE_TYPE (length)))
4654 error_at (OMP_CLAUSE_LOCATION (c),
4655 "length %qE of array section does not have integral type",
4656 length);
4657 return error_mark_node;
4659 if (low_bound)
4660 low_bound = mark_rvalue_use (low_bound);
4661 if (length)
4662 length = mark_rvalue_use (length);
4663 /* We need to reduce to real constant-values for checks below. */
4664 if (length)
4665 length = fold_simple (length);
4666 if (low_bound)
4667 low_bound = fold_simple (low_bound);
4668 if (low_bound
4669 && TREE_CODE (low_bound) == INTEGER_CST
4670 && TYPE_PRECISION (TREE_TYPE (low_bound))
4671 > TYPE_PRECISION (sizetype))
4672 low_bound = fold_convert (sizetype, low_bound);
4673 if (length
4674 && TREE_CODE (length) == INTEGER_CST
4675 && TYPE_PRECISION (TREE_TYPE (length))
4676 > TYPE_PRECISION (sizetype))
4677 length = fold_convert (sizetype, length);
4678 if (low_bound == NULL_TREE)
4679 low_bound = integer_zero_node;
4681 if (length != NULL_TREE)
4683 if (!integer_nonzerop (length))
4685 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
4686 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
4688 if (integer_zerop (length))
4690 error_at (OMP_CLAUSE_LOCATION (c),
4691 "zero length array section in %qs clause",
4692 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4693 return error_mark_node;
4696 else
4697 maybe_zero_len = true;
4699 if (first_non_one == types.length ()
4700 && (TREE_CODE (length) != INTEGER_CST || integer_onep (length)))
4701 first_non_one++;
4703 if (TREE_CODE (type) == ARRAY_TYPE)
4705 if (length == NULL_TREE
4706 && (TYPE_DOMAIN (type) == NULL_TREE
4707 || TYPE_MAX_VALUE (TYPE_DOMAIN (type)) == NULL_TREE))
4709 error_at (OMP_CLAUSE_LOCATION (c),
4710 "for unknown bound array type length expression must "
4711 "be specified");
4712 return error_mark_node;
4714 if (TREE_CODE (low_bound) == INTEGER_CST
4715 && tree_int_cst_sgn (low_bound) == -1)
4717 error_at (OMP_CLAUSE_LOCATION (c),
4718 "negative low bound in array section in %qs clause",
4719 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4720 return error_mark_node;
4722 if (length != NULL_TREE
4723 && TREE_CODE (length) == INTEGER_CST
4724 && tree_int_cst_sgn (length) == -1)
4726 error_at (OMP_CLAUSE_LOCATION (c),
4727 "negative length in array section in %qs clause",
4728 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4729 return error_mark_node;
4731 if (TYPE_DOMAIN (type)
4732 && TYPE_MAX_VALUE (TYPE_DOMAIN (type))
4733 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
4734 == INTEGER_CST)
4736 tree size
4737 = fold_convert (sizetype, TYPE_MAX_VALUE (TYPE_DOMAIN (type)));
4738 size = size_binop (PLUS_EXPR, size, size_one_node);
4739 if (TREE_CODE (low_bound) == INTEGER_CST)
4741 if (tree_int_cst_lt (size, low_bound))
4743 error_at (OMP_CLAUSE_LOCATION (c),
4744 "low bound %qE above array section size "
4745 "in %qs clause", low_bound,
4746 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4747 return error_mark_node;
4749 if (tree_int_cst_equal (size, low_bound))
4751 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND
4752 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
4754 error_at (OMP_CLAUSE_LOCATION (c),
4755 "zero length array section in %qs clause",
4756 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4757 return error_mark_node;
4759 maybe_zero_len = true;
4761 else if (length == NULL_TREE
4762 && first_non_one == types.length ()
4763 && tree_int_cst_equal
4764 (TYPE_MAX_VALUE (TYPE_DOMAIN (type)),
4765 low_bound))
4766 first_non_one++;
4768 else if (length == NULL_TREE)
4770 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
4771 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
4772 maybe_zero_len = true;
4773 if (first_non_one == types.length ())
4774 first_non_one++;
4776 if (length && TREE_CODE (length) == INTEGER_CST)
4778 if (tree_int_cst_lt (size, length))
4780 error_at (OMP_CLAUSE_LOCATION (c),
4781 "length %qE above array section size "
4782 "in %qs clause", length,
4783 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4784 return error_mark_node;
4786 if (TREE_CODE (low_bound) == INTEGER_CST)
4788 tree lbpluslen
4789 = size_binop (PLUS_EXPR,
4790 fold_convert (sizetype, low_bound),
4791 fold_convert (sizetype, length));
4792 if (TREE_CODE (lbpluslen) == INTEGER_CST
4793 && tree_int_cst_lt (size, lbpluslen))
4795 error_at (OMP_CLAUSE_LOCATION (c),
4796 "high bound %qE above array section size "
4797 "in %qs clause", lbpluslen,
4798 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4799 return error_mark_node;
4804 else if (length == NULL_TREE)
4806 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
4807 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_REDUCTION)
4808 maybe_zero_len = true;
4809 if (first_non_one == types.length ())
4810 first_non_one++;
4813 /* For [lb:] we will need to evaluate lb more than once. */
4814 if (length == NULL_TREE && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
4816 tree lb = cp_save_expr (low_bound);
4817 if (lb != low_bound)
4819 TREE_PURPOSE (t) = lb;
4820 low_bound = lb;
4824 else if (TYPE_PTR_P (type))
4826 if (length == NULL_TREE)
4828 error_at (OMP_CLAUSE_LOCATION (c),
4829 "for pointer type length expression must be specified");
4830 return error_mark_node;
4832 if (length != NULL_TREE
4833 && TREE_CODE (length) == INTEGER_CST
4834 && tree_int_cst_sgn (length) == -1)
4836 error_at (OMP_CLAUSE_LOCATION (c),
4837 "negative length in array section in %qs clause",
4838 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4839 return error_mark_node;
4841 /* If there is a pointer type anywhere but in the very first
4842 array-section-subscript, the array section can't be contiguous. */
4843 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND
4844 && TREE_CODE (TREE_CHAIN (t)) == TREE_LIST)
4846 error_at (OMP_CLAUSE_LOCATION (c),
4847 "array section is not contiguous in %qs clause",
4848 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4849 return error_mark_node;
4852 else
4854 error_at (OMP_CLAUSE_LOCATION (c),
4855 "%qE does not have pointer or array type", ret);
4856 return error_mark_node;
4858 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_DEPEND)
4859 types.safe_push (TREE_TYPE (ret));
4860 /* We will need to evaluate lb more than once. */
4861 tree lb = cp_save_expr (low_bound);
4862 if (lb != low_bound)
4864 TREE_PURPOSE (t) = lb;
4865 low_bound = lb;
4867 ret = grok_array_decl (OMP_CLAUSE_LOCATION (c), ret, low_bound, false);
4868 return ret;
4871 /* Handle array sections for clause C. */
4873 static bool
4874 handle_omp_array_sections (tree c, enum c_omp_region_type ort)
4876 bool maybe_zero_len = false;
4877 unsigned int first_non_one = 0;
4878 auto_vec<tree, 10> types;
4879 tree first = handle_omp_array_sections_1 (c, OMP_CLAUSE_DECL (c), types,
4880 maybe_zero_len, first_non_one,
4881 ort);
4882 if (first == error_mark_node)
4883 return true;
4884 if (first == NULL_TREE)
4885 return false;
4886 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_DEPEND)
4888 tree t = OMP_CLAUSE_DECL (c);
4889 tree tem = NULL_TREE;
4890 if (processing_template_decl)
4891 return false;
4892 /* Need to evaluate side effects in the length expressions
4893 if any. */
4894 while (TREE_CODE (t) == TREE_LIST)
4896 if (TREE_VALUE (t) && TREE_SIDE_EFFECTS (TREE_VALUE (t)))
4898 if (tem == NULL_TREE)
4899 tem = TREE_VALUE (t);
4900 else
4901 tem = build2 (COMPOUND_EXPR, TREE_TYPE (tem),
4902 TREE_VALUE (t), tem);
4904 t = TREE_CHAIN (t);
4906 if (tem)
4907 first = build2 (COMPOUND_EXPR, TREE_TYPE (first), tem, first);
4908 OMP_CLAUSE_DECL (c) = first;
4910 else
4912 unsigned int num = types.length (), i;
4913 tree t, side_effects = NULL_TREE, size = NULL_TREE;
4914 tree condition = NULL_TREE;
4916 if (int_size_in_bytes (TREE_TYPE (first)) <= 0)
4917 maybe_zero_len = true;
4918 if (processing_template_decl && maybe_zero_len)
4919 return false;
4921 for (i = num, t = OMP_CLAUSE_DECL (c); i > 0;
4922 t = TREE_CHAIN (t))
4924 tree low_bound = TREE_PURPOSE (t);
4925 tree length = TREE_VALUE (t);
4927 i--;
4928 if (low_bound
4929 && TREE_CODE (low_bound) == INTEGER_CST
4930 && TYPE_PRECISION (TREE_TYPE (low_bound))
4931 > TYPE_PRECISION (sizetype))
4932 low_bound = fold_convert (sizetype, low_bound);
4933 if (length
4934 && TREE_CODE (length) == INTEGER_CST
4935 && TYPE_PRECISION (TREE_TYPE (length))
4936 > TYPE_PRECISION (sizetype))
4937 length = fold_convert (sizetype, length);
4938 if (low_bound == NULL_TREE)
4939 low_bound = integer_zero_node;
4940 if (!maybe_zero_len && i > first_non_one)
4942 if (integer_nonzerop (low_bound))
4943 goto do_warn_noncontiguous;
4944 if (length != NULL_TREE
4945 && TREE_CODE (length) == INTEGER_CST
4946 && TYPE_DOMAIN (types[i])
4947 && TYPE_MAX_VALUE (TYPE_DOMAIN (types[i]))
4948 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])))
4949 == INTEGER_CST)
4951 tree size;
4952 size = size_binop (PLUS_EXPR,
4953 TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
4954 size_one_node);
4955 if (!tree_int_cst_equal (length, size))
4957 do_warn_noncontiguous:
4958 error_at (OMP_CLAUSE_LOCATION (c),
4959 "array section is not contiguous in %qs "
4960 "clause",
4961 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
4962 return true;
4965 if (!processing_template_decl
4966 && length != NULL_TREE
4967 && TREE_SIDE_EFFECTS (length))
4969 if (side_effects == NULL_TREE)
4970 side_effects = length;
4971 else
4972 side_effects = build2 (COMPOUND_EXPR,
4973 TREE_TYPE (side_effects),
4974 length, side_effects);
4977 else if (processing_template_decl)
4978 continue;
4979 else
4981 tree l;
4983 if (i > first_non_one
4984 && ((length && integer_nonzerop (length))
4985 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION))
4986 continue;
4987 if (length)
4988 l = fold_convert (sizetype, length);
4989 else
4991 l = size_binop (PLUS_EXPR,
4992 TYPE_MAX_VALUE (TYPE_DOMAIN (types[i])),
4993 size_one_node);
4994 l = size_binop (MINUS_EXPR, l,
4995 fold_convert (sizetype, low_bound));
4997 if (i > first_non_one)
4999 l = fold_build2 (NE_EXPR, boolean_type_node, l,
5000 size_zero_node);
5001 if (condition == NULL_TREE)
5002 condition = l;
5003 else
5004 condition = fold_build2 (BIT_AND_EXPR, boolean_type_node,
5005 l, condition);
5007 else if (size == NULL_TREE)
5009 size = size_in_bytes (TREE_TYPE (types[i]));
5010 tree eltype = TREE_TYPE (types[num - 1]);
5011 while (TREE_CODE (eltype) == ARRAY_TYPE)
5012 eltype = TREE_TYPE (eltype);
5013 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
5014 size = size_binop (EXACT_DIV_EXPR, size,
5015 size_in_bytes (eltype));
5016 size = size_binop (MULT_EXPR, size, l);
5017 if (condition)
5018 size = fold_build3 (COND_EXPR, sizetype, condition,
5019 size, size_zero_node);
5021 else
5022 size = size_binop (MULT_EXPR, size, l);
5025 if (!processing_template_decl)
5027 if (side_effects)
5028 size = build2 (COMPOUND_EXPR, sizetype, side_effects, size);
5029 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
5031 size = size_binop (MINUS_EXPR, size, size_one_node);
5032 tree index_type = build_index_type (size);
5033 tree eltype = TREE_TYPE (first);
5034 while (TREE_CODE (eltype) == ARRAY_TYPE)
5035 eltype = TREE_TYPE (eltype);
5036 tree type = build_array_type (eltype, index_type);
5037 tree ptype = build_pointer_type (eltype);
5038 if (TYPE_REF_P (TREE_TYPE (t))
5039 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t))))
5040 t = convert_from_reference (t);
5041 else if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
5042 t = build_fold_addr_expr (t);
5043 tree t2 = build_fold_addr_expr (first);
5044 t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5045 ptrdiff_type_node, t2);
5046 t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
5047 ptrdiff_type_node, t2,
5048 fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5049 ptrdiff_type_node, t));
5050 if (tree_fits_shwi_p (t2))
5051 t = build2 (MEM_REF, type, t,
5052 build_int_cst (ptype, tree_to_shwi (t2)));
5053 else
5055 t2 = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5056 sizetype, t2);
5057 t = build2_loc (OMP_CLAUSE_LOCATION (c), POINTER_PLUS_EXPR,
5058 TREE_TYPE (t), t, t2);
5059 t = build2 (MEM_REF, type, t, build_int_cst (ptype, 0));
5061 OMP_CLAUSE_DECL (c) = t;
5062 return false;
5064 OMP_CLAUSE_DECL (c) = first;
5065 OMP_CLAUSE_SIZE (c) = size;
5066 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
5067 || (TREE_CODE (t) == COMPONENT_REF
5068 && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE))
5069 return false;
5070 if (ort == C_ORT_OMP || ort == C_ORT_ACC)
5071 switch (OMP_CLAUSE_MAP_KIND (c))
5073 case GOMP_MAP_ALLOC:
5074 case GOMP_MAP_TO:
5075 case GOMP_MAP_FROM:
5076 case GOMP_MAP_TOFROM:
5077 case GOMP_MAP_ALWAYS_TO:
5078 case GOMP_MAP_ALWAYS_FROM:
5079 case GOMP_MAP_ALWAYS_TOFROM:
5080 case GOMP_MAP_RELEASE:
5081 case GOMP_MAP_DELETE:
5082 case GOMP_MAP_FORCE_TO:
5083 case GOMP_MAP_FORCE_FROM:
5084 case GOMP_MAP_FORCE_TOFROM:
5085 case GOMP_MAP_FORCE_PRESENT:
5086 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c) = 1;
5087 break;
5088 default:
5089 break;
5091 tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
5092 OMP_CLAUSE_MAP);
5093 if ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP && ort != C_ORT_ACC)
5094 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_POINTER);
5095 else if (TREE_CODE (t) == COMPONENT_REF)
5096 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER);
5097 else if (REFERENCE_REF_P (t)
5098 && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF)
5100 t = TREE_OPERAND (t, 0);
5101 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER);
5103 else
5104 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_FIRSTPRIVATE_POINTER);
5105 if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER
5106 && !cxx_mark_addressable (t))
5107 return false;
5108 OMP_CLAUSE_DECL (c2) = t;
5109 t = build_fold_addr_expr (first);
5110 t = fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5111 ptrdiff_type_node, t);
5112 tree ptr = OMP_CLAUSE_DECL (c2);
5113 ptr = convert_from_reference (ptr);
5114 if (!INDIRECT_TYPE_P (TREE_TYPE (ptr)))
5115 ptr = build_fold_addr_expr (ptr);
5116 t = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MINUS_EXPR,
5117 ptrdiff_type_node, t,
5118 fold_convert_loc (OMP_CLAUSE_LOCATION (c),
5119 ptrdiff_type_node, ptr));
5120 OMP_CLAUSE_SIZE (c2) = t;
5121 OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c);
5122 OMP_CLAUSE_CHAIN (c) = c2;
5123 ptr = OMP_CLAUSE_DECL (c2);
5124 if (OMP_CLAUSE_MAP_KIND (c2) != GOMP_MAP_FIRSTPRIVATE_POINTER
5125 && TYPE_REF_P (TREE_TYPE (ptr))
5126 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr))))
5128 tree c3 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
5129 OMP_CLAUSE_MAP);
5130 OMP_CLAUSE_SET_MAP_KIND (c3, OMP_CLAUSE_MAP_KIND (c2));
5131 OMP_CLAUSE_DECL (c3) = ptr;
5132 if (OMP_CLAUSE_MAP_KIND (c2) == GOMP_MAP_ALWAYS_POINTER)
5133 OMP_CLAUSE_DECL (c2) = build_simple_mem_ref (ptr);
5134 else
5135 OMP_CLAUSE_DECL (c2) = convert_from_reference (ptr);
5136 OMP_CLAUSE_SIZE (c3) = size_zero_node;
5137 OMP_CLAUSE_CHAIN (c3) = OMP_CLAUSE_CHAIN (c2);
5138 OMP_CLAUSE_CHAIN (c2) = c3;
5142 return false;
5145 /* Return identifier to look up for omp declare reduction. */
5147 tree
5148 omp_reduction_id (enum tree_code reduction_code, tree reduction_id, tree type)
5150 const char *p = NULL;
5151 const char *m = NULL;
5152 switch (reduction_code)
5154 case PLUS_EXPR:
5155 case MULT_EXPR:
5156 case MINUS_EXPR:
5157 case BIT_AND_EXPR:
5158 case BIT_XOR_EXPR:
5159 case BIT_IOR_EXPR:
5160 case TRUTH_ANDIF_EXPR:
5161 case TRUTH_ORIF_EXPR:
5162 reduction_id = ovl_op_identifier (false, reduction_code);
5163 break;
5164 case MIN_EXPR:
5165 p = "min";
5166 break;
5167 case MAX_EXPR:
5168 p = "max";
5169 break;
5170 default:
5171 break;
5174 if (p == NULL)
5176 if (TREE_CODE (reduction_id) != IDENTIFIER_NODE)
5177 return error_mark_node;
5178 p = IDENTIFIER_POINTER (reduction_id);
5181 if (type != NULL_TREE)
5182 m = mangle_type_string (TYPE_MAIN_VARIANT (type));
5184 const char prefix[] = "omp declare reduction ";
5185 size_t lenp = sizeof (prefix);
5186 if (strncmp (p, prefix, lenp - 1) == 0)
5187 lenp = 1;
5188 size_t len = strlen (p);
5189 size_t lenm = m ? strlen (m) + 1 : 0;
5190 char *name = XALLOCAVEC (char, lenp + len + lenm);
5191 if (lenp > 1)
5192 memcpy (name, prefix, lenp - 1);
5193 memcpy (name + lenp - 1, p, len + 1);
5194 if (m)
5196 name[lenp + len - 1] = '~';
5197 memcpy (name + lenp + len, m, lenm);
5199 return get_identifier (name);
5202 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5203 FUNCTION_DECL or NULL_TREE if not found. */
5205 static tree
5206 omp_reduction_lookup (location_t loc, tree id, tree type, tree *baselinkp,
5207 vec<tree> *ambiguousp)
5209 tree orig_id = id;
5210 tree baselink = NULL_TREE;
5211 if (identifier_p (id))
5213 cp_id_kind idk;
5214 bool nonint_cst_expression_p;
5215 const char *error_msg;
5216 id = omp_reduction_id (ERROR_MARK, id, type);
5217 tree decl = lookup_name (id);
5218 if (decl == NULL_TREE)
5219 decl = error_mark_node;
5220 id = finish_id_expression (id, decl, NULL_TREE, &idk, false, true,
5221 &nonint_cst_expression_p, false, true, false,
5222 false, &error_msg, loc);
5223 if (idk == CP_ID_KIND_UNQUALIFIED
5224 && identifier_p (id))
5226 vec<tree, va_gc> *args = NULL;
5227 vec_safe_push (args, build_reference_type (type));
5228 id = perform_koenig_lookup (id, args, tf_none);
5231 else if (TREE_CODE (id) == SCOPE_REF)
5232 id = lookup_qualified_name (TREE_OPERAND (id, 0),
5233 omp_reduction_id (ERROR_MARK,
5234 TREE_OPERAND (id, 1),
5235 type),
5236 false, false);
5237 tree fns = id;
5238 id = NULL_TREE;
5239 if (fns && is_overloaded_fn (fns))
5241 for (lkp_iterator iter (get_fns (fns)); iter; ++iter)
5243 tree fndecl = *iter;
5244 if (TREE_CODE (fndecl) == FUNCTION_DECL)
5246 tree argtype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl)));
5247 if (same_type_p (TREE_TYPE (argtype), type))
5249 id = fndecl;
5250 break;
5255 if (id && BASELINK_P (fns))
5257 if (baselinkp)
5258 *baselinkp = fns;
5259 else
5260 baselink = fns;
5264 if (!id && CLASS_TYPE_P (type) && TYPE_BINFO (type))
5266 vec<tree> ambiguous = vNULL;
5267 tree binfo = TYPE_BINFO (type), base_binfo, ret = NULL_TREE;
5268 unsigned int ix;
5269 if (ambiguousp == NULL)
5270 ambiguousp = &ambiguous;
5271 for (ix = 0; BINFO_BASE_ITERATE (binfo, ix, base_binfo); ix++)
5273 id = omp_reduction_lookup (loc, orig_id, BINFO_TYPE (base_binfo),
5274 baselinkp ? baselinkp : &baselink,
5275 ambiguousp);
5276 if (id == NULL_TREE)
5277 continue;
5278 if (!ambiguousp->is_empty ())
5279 ambiguousp->safe_push (id);
5280 else if (ret != NULL_TREE)
5282 ambiguousp->safe_push (ret);
5283 ambiguousp->safe_push (id);
5284 ret = NULL_TREE;
5286 else
5287 ret = id;
5289 if (ambiguousp != &ambiguous)
5290 return ret;
5291 if (!ambiguous.is_empty ())
5293 const char *str = _("candidates are:");
5294 unsigned int idx;
5295 tree udr;
5296 error_at (loc, "user defined reduction lookup is ambiguous");
5297 FOR_EACH_VEC_ELT (ambiguous, idx, udr)
5299 inform (DECL_SOURCE_LOCATION (udr), "%s %#qD", str, udr);
5300 if (idx == 0)
5301 str = get_spaces (str);
5303 ambiguous.release ();
5304 ret = error_mark_node;
5305 baselink = NULL_TREE;
5307 id = ret;
5309 if (id && baselink)
5310 perform_or_defer_access_check (BASELINK_BINFO (baselink),
5311 id, id, tf_warning_or_error);
5312 return id;
5315 /* Helper function for cp_parser_omp_declare_reduction_exprs
5316 and tsubst_omp_udr.
5317 Remove CLEANUP_STMT for data (omp_priv variable).
5318 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5319 DECL_EXPR. */
5321 tree
5322 cp_remove_omp_priv_cleanup_stmt (tree *tp, int *walk_subtrees, void *data)
5324 if (TYPE_P (*tp))
5325 *walk_subtrees = 0;
5326 else if (TREE_CODE (*tp) == CLEANUP_STMT && CLEANUP_DECL (*tp) == (tree) data)
5327 *tp = CLEANUP_BODY (*tp);
5328 else if (TREE_CODE (*tp) == DECL_EXPR)
5330 tree decl = DECL_EXPR_DECL (*tp);
5331 if (!processing_template_decl
5332 && decl == (tree) data
5333 && DECL_INITIAL (decl)
5334 && DECL_INITIAL (decl) != error_mark_node)
5336 tree list = NULL_TREE;
5337 append_to_statement_list_force (*tp, &list);
5338 tree init_expr = build2 (INIT_EXPR, void_type_node,
5339 decl, DECL_INITIAL (decl));
5340 DECL_INITIAL (decl) = NULL_TREE;
5341 append_to_statement_list_force (init_expr, &list);
5342 *tp = list;
5345 return NULL_TREE;
5348 /* Data passed from cp_check_omp_declare_reduction to
5349 cp_check_omp_declare_reduction_r. */
5351 struct cp_check_omp_declare_reduction_data
5353 location_t loc;
5354 tree stmts[7];
5355 bool combiner_p;
5358 /* Helper function for cp_check_omp_declare_reduction, called via
5359 cp_walk_tree. */
5361 static tree
5362 cp_check_omp_declare_reduction_r (tree *tp, int *, void *data)
5364 struct cp_check_omp_declare_reduction_data *udr_data
5365 = (struct cp_check_omp_declare_reduction_data *) data;
5366 if (SSA_VAR_P (*tp)
5367 && !DECL_ARTIFICIAL (*tp)
5368 && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 0 : 3])
5369 && *tp != DECL_EXPR_DECL (udr_data->stmts[udr_data->combiner_p ? 1 : 4]))
5371 location_t loc = udr_data->loc;
5372 if (udr_data->combiner_p)
5373 error_at (loc, "%<#pragma omp declare reduction%> combiner refers to "
5374 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5375 *tp);
5376 else
5377 error_at (loc, "%<#pragma omp declare reduction%> initializer refers "
5378 "to variable %qD which is not %<omp_priv%> nor "
5379 "%<omp_orig%>",
5380 *tp);
5381 return *tp;
5383 return NULL_TREE;
5386 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5388 void
5389 cp_check_omp_declare_reduction (tree udr)
5391 tree type = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr)));
5392 gcc_assert (TYPE_REF_P (type));
5393 type = TREE_TYPE (type);
5394 int i;
5395 location_t loc = DECL_SOURCE_LOCATION (udr);
5397 if (type == error_mark_node)
5398 return;
5399 if (ARITHMETIC_TYPE_P (type))
5401 static enum tree_code predef_codes[]
5402 = { PLUS_EXPR, MULT_EXPR, MINUS_EXPR, BIT_AND_EXPR, BIT_XOR_EXPR,
5403 BIT_IOR_EXPR, TRUTH_ANDIF_EXPR, TRUTH_ORIF_EXPR };
5404 for (i = 0; i < 8; i++)
5406 tree id = omp_reduction_id (predef_codes[i], NULL_TREE, NULL_TREE);
5407 const char *n1 = IDENTIFIER_POINTER (DECL_NAME (udr));
5408 const char *n2 = IDENTIFIER_POINTER (id);
5409 if (strncmp (n1, n2, IDENTIFIER_LENGTH (id)) == 0
5410 && (n1[IDENTIFIER_LENGTH (id)] == '~'
5411 || n1[IDENTIFIER_LENGTH (id)] == '\0'))
5412 break;
5415 if (i == 8
5416 && TREE_CODE (type) != COMPLEX_EXPR)
5418 const char prefix_minmax[] = "omp declare reduction m";
5419 size_t prefix_size = sizeof (prefix_minmax) - 1;
5420 const char *n = IDENTIFIER_POINTER (DECL_NAME (udr));
5421 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr)),
5422 prefix_minmax, prefix_size) == 0
5423 && ((n[prefix_size] == 'i' && n[prefix_size + 1] == 'n')
5424 || (n[prefix_size] == 'a' && n[prefix_size + 1] == 'x'))
5425 && (n[prefix_size + 2] == '~' || n[prefix_size + 2] == '\0'))
5426 i = 0;
5428 if (i < 8)
5430 error_at (loc, "predeclared arithmetic type %qT in "
5431 "%<#pragma omp declare reduction%>", type);
5432 return;
5435 else if (TREE_CODE (type) == FUNCTION_TYPE
5436 || TREE_CODE (type) == METHOD_TYPE
5437 || TREE_CODE (type) == ARRAY_TYPE)
5439 error_at (loc, "function or array type %qT in "
5440 "%<#pragma omp declare reduction%>", type);
5441 return;
5443 else if (TYPE_REF_P (type))
5445 error_at (loc, "reference type %qT in %<#pragma omp declare reduction%>",
5446 type);
5447 return;
5449 else if (TYPE_QUALS_NO_ADDR_SPACE (type))
5451 error_at (loc, "const, volatile or __restrict qualified type %qT in "
5452 "%<#pragma omp declare reduction%>", type);
5453 return;
5456 tree body = DECL_SAVED_TREE (udr);
5457 if (body == NULL_TREE || TREE_CODE (body) != STATEMENT_LIST)
5458 return;
5460 tree_stmt_iterator tsi;
5461 struct cp_check_omp_declare_reduction_data data;
5462 memset (data.stmts, 0, sizeof data.stmts);
5463 for (i = 0, tsi = tsi_start (body);
5464 i < 7 && !tsi_end_p (tsi);
5465 i++, tsi_next (&tsi))
5466 data.stmts[i] = tsi_stmt (tsi);
5467 data.loc = loc;
5468 gcc_assert (tsi_end_p (tsi));
5469 if (i >= 3)
5471 gcc_assert (TREE_CODE (data.stmts[0]) == DECL_EXPR
5472 && TREE_CODE (data.stmts[1]) == DECL_EXPR);
5473 if (TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])))
5474 return;
5475 data.combiner_p = true;
5476 if (cp_walk_tree (&data.stmts[2], cp_check_omp_declare_reduction_r,
5477 &data, NULL))
5478 TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1;
5480 if (i >= 6)
5482 gcc_assert (TREE_CODE (data.stmts[3]) == DECL_EXPR
5483 && TREE_CODE (data.stmts[4]) == DECL_EXPR);
5484 data.combiner_p = false;
5485 if (cp_walk_tree (&data.stmts[5], cp_check_omp_declare_reduction_r,
5486 &data, NULL)
5487 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data.stmts[3])),
5488 cp_check_omp_declare_reduction_r, &data, NULL))
5489 TREE_NO_WARNING (DECL_EXPR_DECL (data.stmts[0])) = 1;
5490 if (i == 7)
5491 gcc_assert (TREE_CODE (data.stmts[6]) == DECL_EXPR);
5495 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5496 an inline call. But, remap
5497 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5498 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5500 static tree
5501 clone_omp_udr (tree stmt, tree omp_decl1, tree omp_decl2,
5502 tree decl, tree placeholder)
5504 copy_body_data id;
5505 hash_map<tree, tree> decl_map;
5507 decl_map.put (omp_decl1, placeholder);
5508 decl_map.put (omp_decl2, decl);
5509 memset (&id, 0, sizeof (id));
5510 id.src_fn = DECL_CONTEXT (omp_decl1);
5511 id.dst_fn = current_function_decl;
5512 id.src_cfun = DECL_STRUCT_FUNCTION (id.src_fn);
5513 id.decl_map = &decl_map;
5515 id.copy_decl = copy_decl_no_change;
5516 id.transform_call_graph_edges = CB_CGE_DUPLICATE;
5517 id.transform_new_cfg = true;
5518 id.transform_return_to_modify = false;
5519 id.transform_lang_insert_block = NULL;
5520 id.eh_lp_nr = 0;
5521 walk_tree (&stmt, copy_tree_body_r, &id, NULL);
5522 return stmt;
5525 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5526 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5528 static tree
5529 find_omp_placeholder_r (tree *tp, int *, void *data)
5531 if (*tp == (tree) data)
5532 return *tp;
5533 return NULL_TREE;
5536 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5537 Return true if there is some error and the clause should be removed. */
5539 static bool
5540 finish_omp_reduction_clause (tree c, bool *need_default_ctor, bool *need_dtor)
5542 tree t = OMP_CLAUSE_DECL (c);
5543 bool predefined = false;
5544 if (TREE_CODE (t) == TREE_LIST)
5546 gcc_assert (processing_template_decl);
5547 return false;
5549 tree type = TREE_TYPE (t);
5550 if (TREE_CODE (t) == MEM_REF)
5551 type = TREE_TYPE (type);
5552 if (TYPE_REF_P (type))
5553 type = TREE_TYPE (type);
5554 if (TREE_CODE (type) == ARRAY_TYPE)
5556 tree oatype = type;
5557 gcc_assert (TREE_CODE (t) != MEM_REF);
5558 while (TREE_CODE (type) == ARRAY_TYPE)
5559 type = TREE_TYPE (type);
5560 if (!processing_template_decl)
5562 t = require_complete_type (t);
5563 if (t == error_mark_node)
5564 return true;
5565 tree size = size_binop (EXACT_DIV_EXPR, TYPE_SIZE_UNIT (oatype),
5566 TYPE_SIZE_UNIT (type));
5567 if (integer_zerop (size))
5569 error ("%qE in %<reduction%> clause is a zero size array",
5570 omp_clause_printable_decl (t));
5571 return true;
5573 size = size_binop (MINUS_EXPR, size, size_one_node);
5574 tree index_type = build_index_type (size);
5575 tree atype = build_array_type (type, index_type);
5576 tree ptype = build_pointer_type (type);
5577 if (TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
5578 t = build_fold_addr_expr (t);
5579 t = build2 (MEM_REF, atype, t, build_int_cst (ptype, 0));
5580 OMP_CLAUSE_DECL (c) = t;
5583 if (type == error_mark_node)
5584 return true;
5585 else if (ARITHMETIC_TYPE_P (type))
5586 switch (OMP_CLAUSE_REDUCTION_CODE (c))
5588 case PLUS_EXPR:
5589 case MULT_EXPR:
5590 case MINUS_EXPR:
5591 predefined = true;
5592 break;
5593 case MIN_EXPR:
5594 case MAX_EXPR:
5595 if (TREE_CODE (type) == COMPLEX_TYPE)
5596 break;
5597 predefined = true;
5598 break;
5599 case BIT_AND_EXPR:
5600 case BIT_IOR_EXPR:
5601 case BIT_XOR_EXPR:
5602 if (FLOAT_TYPE_P (type) || TREE_CODE (type) == COMPLEX_TYPE)
5603 break;
5604 predefined = true;
5605 break;
5606 case TRUTH_ANDIF_EXPR:
5607 case TRUTH_ORIF_EXPR:
5608 if (FLOAT_TYPE_P (type))
5609 break;
5610 predefined = true;
5611 break;
5612 default:
5613 break;
5615 else if (TYPE_READONLY (type))
5617 error ("%qE has const type for %<reduction%>",
5618 omp_clause_printable_decl (t));
5619 return true;
5621 else if (!processing_template_decl)
5623 t = require_complete_type (t);
5624 if (t == error_mark_node)
5625 return true;
5626 OMP_CLAUSE_DECL (c) = t;
5629 if (predefined)
5631 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
5632 return false;
5634 else if (processing_template_decl)
5636 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) == error_mark_node)
5637 return true;
5638 return false;
5641 tree id = OMP_CLAUSE_REDUCTION_PLACEHOLDER (c);
5643 type = TYPE_MAIN_VARIANT (type);
5644 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = NULL_TREE;
5645 if (id == NULL_TREE)
5646 id = omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c),
5647 NULL_TREE, NULL_TREE);
5648 id = omp_reduction_lookup (OMP_CLAUSE_LOCATION (c), id, type, NULL, NULL);
5649 if (id)
5651 if (id == error_mark_node)
5652 return true;
5653 mark_used (id);
5654 tree body = DECL_SAVED_TREE (id);
5655 if (!body)
5656 return true;
5657 if (TREE_CODE (body) == STATEMENT_LIST)
5659 tree_stmt_iterator tsi;
5660 tree placeholder = NULL_TREE, decl_placeholder = NULL_TREE;
5661 int i;
5662 tree stmts[7];
5663 tree atype = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id)));
5664 atype = TREE_TYPE (atype);
5665 bool need_static_cast = !same_type_p (type, atype);
5666 memset (stmts, 0, sizeof stmts);
5667 for (i = 0, tsi = tsi_start (body);
5668 i < 7 && !tsi_end_p (tsi);
5669 i++, tsi_next (&tsi))
5670 stmts[i] = tsi_stmt (tsi);
5671 gcc_assert (tsi_end_p (tsi));
5673 if (i >= 3)
5675 gcc_assert (TREE_CODE (stmts[0]) == DECL_EXPR
5676 && TREE_CODE (stmts[1]) == DECL_EXPR);
5677 placeholder = build_lang_decl (VAR_DECL, NULL_TREE, type);
5678 DECL_ARTIFICIAL (placeholder) = 1;
5679 DECL_IGNORED_P (placeholder) = 1;
5680 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c) = placeholder;
5681 if (TREE_CODE (t) == MEM_REF)
5683 decl_placeholder = build_lang_decl (VAR_DECL, NULL_TREE,
5684 type);
5685 DECL_ARTIFICIAL (decl_placeholder) = 1;
5686 DECL_IGNORED_P (decl_placeholder) = 1;
5687 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c) = decl_placeholder;
5689 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[0])))
5690 cxx_mark_addressable (placeholder);
5691 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[1]))
5692 && !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))
5693 cxx_mark_addressable (decl_placeholder ? decl_placeholder
5694 : OMP_CLAUSE_DECL (c));
5695 tree omp_out = placeholder;
5696 tree omp_in = decl_placeholder ? decl_placeholder
5697 : convert_from_reference (OMP_CLAUSE_DECL (c));
5698 if (need_static_cast)
5700 tree rtype = build_reference_type (atype);
5701 omp_out = build_static_cast (rtype, omp_out,
5702 tf_warning_or_error);
5703 omp_in = build_static_cast (rtype, omp_in,
5704 tf_warning_or_error);
5705 if (omp_out == error_mark_node || omp_in == error_mark_node)
5706 return true;
5707 omp_out = convert_from_reference (omp_out);
5708 omp_in = convert_from_reference (omp_in);
5710 OMP_CLAUSE_REDUCTION_MERGE (c)
5711 = clone_omp_udr (stmts[2], DECL_EXPR_DECL (stmts[0]),
5712 DECL_EXPR_DECL (stmts[1]), omp_in, omp_out);
5714 if (i >= 6)
5716 gcc_assert (TREE_CODE (stmts[3]) == DECL_EXPR
5717 && TREE_CODE (stmts[4]) == DECL_EXPR);
5718 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[3])))
5719 cxx_mark_addressable (decl_placeholder ? decl_placeholder
5720 : OMP_CLAUSE_DECL (c));
5721 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts[4])))
5722 cxx_mark_addressable (placeholder);
5723 tree omp_priv = decl_placeholder ? decl_placeholder
5724 : convert_from_reference (OMP_CLAUSE_DECL (c));
5725 tree omp_orig = placeholder;
5726 if (need_static_cast)
5728 if (i == 7)
5730 error_at (OMP_CLAUSE_LOCATION (c),
5731 "user defined reduction with constructor "
5732 "initializer for base class %qT", atype);
5733 return true;
5735 tree rtype = build_reference_type (atype);
5736 omp_priv = build_static_cast (rtype, omp_priv,
5737 tf_warning_or_error);
5738 omp_orig = build_static_cast (rtype, omp_orig,
5739 tf_warning_or_error);
5740 if (omp_priv == error_mark_node
5741 || omp_orig == error_mark_node)
5742 return true;
5743 omp_priv = convert_from_reference (omp_priv);
5744 omp_orig = convert_from_reference (omp_orig);
5746 if (i == 6)
5747 *need_default_ctor = true;
5748 OMP_CLAUSE_REDUCTION_INIT (c)
5749 = clone_omp_udr (stmts[5], DECL_EXPR_DECL (stmts[4]),
5750 DECL_EXPR_DECL (stmts[3]),
5751 omp_priv, omp_orig);
5752 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c),
5753 find_omp_placeholder_r, placeholder, NULL))
5754 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c) = 1;
5756 else if (i >= 3)
5758 if (CLASS_TYPE_P (type) && !pod_type_p (type))
5759 *need_default_ctor = true;
5760 else
5762 tree init;
5763 tree v = decl_placeholder ? decl_placeholder
5764 : convert_from_reference (t);
5765 if (AGGREGATE_TYPE_P (TREE_TYPE (v)))
5766 init = build_constructor (TREE_TYPE (v), NULL);
5767 else
5768 init = fold_convert (TREE_TYPE (v), integer_zero_node);
5769 OMP_CLAUSE_REDUCTION_INIT (c)
5770 = build2 (INIT_EXPR, TREE_TYPE (v), v, init);
5775 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c))
5776 *need_dtor = true;
5777 else
5779 error ("user defined reduction not found for %qE",
5780 omp_clause_printable_decl (t));
5781 return true;
5783 if (TREE_CODE (OMP_CLAUSE_DECL (c)) == MEM_REF)
5784 gcc_assert (TYPE_SIZE_UNIT (type)
5785 && TREE_CODE (TYPE_SIZE_UNIT (type)) == INTEGER_CST);
5786 return false;
5789 /* Called from finish_struct_1. linear(this) or linear(this:step)
5790 clauses might not be finalized yet because the class has been incomplete
5791 when parsing #pragma omp declare simd methods. Fix those up now. */
5793 void
5794 finish_omp_declare_simd_methods (tree t)
5796 if (processing_template_decl)
5797 return;
5799 for (tree x = TYPE_FIELDS (t); x; x = DECL_CHAIN (x))
5801 if (TREE_CODE (TREE_TYPE (x)) != METHOD_TYPE)
5802 continue;
5803 tree ods = lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x));
5804 if (!ods || !TREE_VALUE (ods))
5805 continue;
5806 for (tree c = TREE_VALUE (TREE_VALUE (ods)); c; c = OMP_CLAUSE_CHAIN (c))
5807 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LINEAR
5808 && integer_zerop (OMP_CLAUSE_DECL (c))
5809 && OMP_CLAUSE_LINEAR_STEP (c)
5810 && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c))))
5812 tree s = OMP_CLAUSE_LINEAR_STEP (c);
5813 s = fold_convert_loc (OMP_CLAUSE_LOCATION (c), sizetype, s);
5814 s = fold_build2_loc (OMP_CLAUSE_LOCATION (c), MULT_EXPR,
5815 sizetype, s, TYPE_SIZE_UNIT (t));
5816 OMP_CLAUSE_LINEAR_STEP (c) = s;
5821 /* Adjust sink depend clause to take into account pointer offsets.
5823 Return TRUE if there was a problem processing the offset, and the
5824 whole clause should be removed. */
5826 static bool
5827 cp_finish_omp_clause_depend_sink (tree sink_clause)
5829 tree t = OMP_CLAUSE_DECL (sink_clause);
5830 gcc_assert (TREE_CODE (t) == TREE_LIST);
5832 /* Make sure we don't adjust things twice for templates. */
5833 if (processing_template_decl)
5834 return false;
5836 for (; t; t = TREE_CHAIN (t))
5838 tree decl = TREE_VALUE (t);
5839 if (TYPE_PTR_P (TREE_TYPE (decl)))
5841 tree offset = TREE_PURPOSE (t);
5842 bool neg = wi::neg_p (wi::to_wide (offset));
5843 offset = fold_unary (ABS_EXPR, TREE_TYPE (offset), offset);
5844 decl = mark_rvalue_use (decl);
5845 decl = convert_from_reference (decl);
5846 tree t2 = pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause),
5847 neg ? MINUS_EXPR : PLUS_EXPR,
5848 decl, offset);
5849 t2 = fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause),
5850 MINUS_EXPR, sizetype,
5851 fold_convert (sizetype, t2),
5852 fold_convert (sizetype, decl));
5853 if (t2 == error_mark_node)
5854 return true;
5855 TREE_PURPOSE (t) = t2;
5858 return false;
5861 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
5862 Remove any elements from the list that are invalid. */
5864 tree
5865 finish_omp_clauses (tree clauses, enum c_omp_region_type ort)
5867 bitmap_head generic_head, firstprivate_head, lastprivate_head;
5868 bitmap_head aligned_head, map_head, map_field_head, oacc_reduction_head;
5869 tree c, t, *pc;
5870 tree safelen = NULL_TREE;
5871 bool branch_seen = false;
5872 bool copyprivate_seen = false;
5873 bool ordered_seen = false;
5874 bool oacc_async = false;
5876 bitmap_obstack_initialize (NULL);
5877 bitmap_initialize (&generic_head, &bitmap_default_obstack);
5878 bitmap_initialize (&firstprivate_head, &bitmap_default_obstack);
5879 bitmap_initialize (&lastprivate_head, &bitmap_default_obstack);
5880 bitmap_initialize (&aligned_head, &bitmap_default_obstack);
5881 bitmap_initialize (&map_head, &bitmap_default_obstack);
5882 bitmap_initialize (&map_field_head, &bitmap_default_obstack);
5883 bitmap_initialize (&oacc_reduction_head, &bitmap_default_obstack);
5885 if (ort & C_ORT_ACC)
5886 for (c = clauses; c; c = OMP_CLAUSE_CHAIN (c))
5887 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_ASYNC)
5889 oacc_async = true;
5890 break;
5893 for (pc = &clauses, c = clauses; c ; c = *pc)
5895 bool remove = false;
5896 bool field_ok = false;
5898 switch (OMP_CLAUSE_CODE (c))
5900 case OMP_CLAUSE_SHARED:
5901 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
5902 goto check_dup_generic;
5903 case OMP_CLAUSE_PRIVATE:
5904 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
5905 goto check_dup_generic;
5906 case OMP_CLAUSE_REDUCTION:
5907 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
5908 t = OMP_CLAUSE_DECL (c);
5909 if (TREE_CODE (t) == TREE_LIST)
5911 if (handle_omp_array_sections (c, ort))
5913 remove = true;
5914 break;
5916 if (TREE_CODE (t) == TREE_LIST)
5918 while (TREE_CODE (t) == TREE_LIST)
5919 t = TREE_CHAIN (t);
5921 else
5923 gcc_assert (TREE_CODE (t) == MEM_REF);
5924 t = TREE_OPERAND (t, 0);
5925 if (TREE_CODE (t) == POINTER_PLUS_EXPR)
5926 t = TREE_OPERAND (t, 0);
5927 if (TREE_CODE (t) == ADDR_EXPR
5928 || INDIRECT_REF_P (t))
5929 t = TREE_OPERAND (t, 0);
5931 tree n = omp_clause_decl_field (t);
5932 if (n)
5933 t = n;
5934 goto check_dup_generic_t;
5936 if (oacc_async)
5937 cxx_mark_addressable (t);
5938 goto check_dup_generic;
5939 case OMP_CLAUSE_COPYPRIVATE:
5940 copyprivate_seen = true;
5941 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
5942 goto check_dup_generic;
5943 case OMP_CLAUSE_COPYIN:
5944 goto check_dup_generic;
5945 case OMP_CLAUSE_LINEAR:
5946 field_ok = ((ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP);
5947 t = OMP_CLAUSE_DECL (c);
5948 if (ort != C_ORT_OMP_DECLARE_SIMD
5949 && OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_DEFAULT)
5951 error_at (OMP_CLAUSE_LOCATION (c),
5952 "modifier should not be specified in %<linear%> "
5953 "clause on %<simd%> or %<for%> constructs");
5954 OMP_CLAUSE_LINEAR_KIND (c) = OMP_CLAUSE_LINEAR_DEFAULT;
5956 if ((VAR_P (t) || TREE_CODE (t) == PARM_DECL)
5957 && !type_dependent_expression_p (t))
5959 tree type = TREE_TYPE (t);
5960 if ((OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
5961 || OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_UVAL)
5962 && !TYPE_REF_P (type))
5964 error ("linear clause with %qs modifier applied to "
5965 "non-reference variable with %qT type",
5966 OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF
5967 ? "ref" : "uval", TREE_TYPE (t));
5968 remove = true;
5969 break;
5971 if (TYPE_REF_P (type))
5972 type = TREE_TYPE (type);
5973 if (OMP_CLAUSE_LINEAR_KIND (c) != OMP_CLAUSE_LINEAR_REF)
5975 if (!INTEGRAL_TYPE_P (type)
5976 && !TYPE_PTR_P (type))
5978 error ("linear clause applied to non-integral non-pointer"
5979 " variable with %qT type", TREE_TYPE (t));
5980 remove = true;
5981 break;
5985 t = OMP_CLAUSE_LINEAR_STEP (c);
5986 if (t == NULL_TREE)
5987 t = integer_one_node;
5988 if (t == error_mark_node)
5990 remove = true;
5991 break;
5993 else if (!type_dependent_expression_p (t)
5994 && !INTEGRAL_TYPE_P (TREE_TYPE (t))
5995 && (ort != C_ORT_OMP_DECLARE_SIMD
5996 || TREE_CODE (t) != PARM_DECL
5997 || !TYPE_REF_P (TREE_TYPE (t))
5998 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t)))))
6000 error ("linear step expression must be integral");
6001 remove = true;
6002 break;
6004 else
6006 t = mark_rvalue_use (t);
6007 if (ort == C_ORT_OMP_DECLARE_SIMD && TREE_CODE (t) == PARM_DECL)
6009 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c) = 1;
6010 goto check_dup_generic;
6012 if (!processing_template_decl
6013 && (VAR_P (OMP_CLAUSE_DECL (c))
6014 || TREE_CODE (OMP_CLAUSE_DECL (c)) == PARM_DECL))
6016 if (ort == C_ORT_OMP_DECLARE_SIMD)
6018 t = maybe_constant_value (t);
6019 if (TREE_CODE (t) != INTEGER_CST)
6021 error_at (OMP_CLAUSE_LOCATION (c),
6022 "%<linear%> clause step %qE is neither "
6023 "constant nor a parameter", t);
6024 remove = true;
6025 break;
6028 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6029 tree type = TREE_TYPE (OMP_CLAUSE_DECL (c));
6030 if (TYPE_REF_P (type))
6031 type = TREE_TYPE (type);
6032 if (OMP_CLAUSE_LINEAR_KIND (c) == OMP_CLAUSE_LINEAR_REF)
6034 type = build_pointer_type (type);
6035 tree d = fold_convert (type, OMP_CLAUSE_DECL (c));
6036 t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
6037 d, t);
6038 t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
6039 MINUS_EXPR, sizetype,
6040 fold_convert (sizetype, t),
6041 fold_convert (sizetype, d));
6042 if (t == error_mark_node)
6044 remove = true;
6045 break;
6048 else if (TYPE_PTR_P (type)
6049 /* Can't multiply the step yet if *this
6050 is still incomplete type. */
6051 && (ort != C_ORT_OMP_DECLARE_SIMD
6052 || TREE_CODE (OMP_CLAUSE_DECL (c)) != PARM_DECL
6053 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c))
6054 || DECL_NAME (OMP_CLAUSE_DECL (c))
6055 != this_identifier
6056 || !TYPE_BEING_DEFINED (TREE_TYPE (type))))
6058 tree d = convert_from_reference (OMP_CLAUSE_DECL (c));
6059 t = pointer_int_sum (OMP_CLAUSE_LOCATION (c), PLUS_EXPR,
6060 d, t);
6061 t = fold_build2_loc (OMP_CLAUSE_LOCATION (c),
6062 MINUS_EXPR, sizetype,
6063 fold_convert (sizetype, t),
6064 fold_convert (sizetype, d));
6065 if (t == error_mark_node)
6067 remove = true;
6068 break;
6071 else
6072 t = fold_convert (type, t);
6074 OMP_CLAUSE_LINEAR_STEP (c) = t;
6076 goto check_dup_generic;
6077 check_dup_generic:
6078 t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
6079 if (t)
6081 if (!remove && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_SHARED)
6082 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
6084 else
6085 t = OMP_CLAUSE_DECL (c);
6086 check_dup_generic_t:
6087 if (t == current_class_ptr
6088 && (ort != C_ORT_OMP_DECLARE_SIMD
6089 || (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_LINEAR
6090 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE_UNIFORM)))
6092 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6093 " clauses");
6094 remove = true;
6095 break;
6097 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
6098 && (!field_ok || TREE_CODE (t) != FIELD_DECL))
6100 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6101 break;
6102 if (DECL_P (t))
6103 error ("%qD is not a variable in clause %qs", t,
6104 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6105 else
6106 error ("%qE is not a variable in clause %qs", t,
6107 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6108 remove = true;
6110 else if (ort == C_ORT_ACC
6111 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
6113 if (bitmap_bit_p (&oacc_reduction_head, DECL_UID (t)))
6115 error ("%qD appears more than once in reduction clauses", t);
6116 remove = true;
6118 else
6119 bitmap_set_bit (&oacc_reduction_head, DECL_UID (t));
6121 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
6122 || bitmap_bit_p (&firstprivate_head, DECL_UID (t))
6123 || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
6125 error ("%qD appears more than once in data clauses", t);
6126 remove = true;
6128 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
6129 && bitmap_bit_p (&map_head, DECL_UID (t)))
6131 if (ort == C_ORT_ACC)
6132 error ("%qD appears more than once in data clauses", t);
6133 else
6134 error ("%qD appears both in data and map clauses", t);
6135 remove = true;
6137 else
6138 bitmap_set_bit (&generic_head, DECL_UID (t));
6139 if (!field_ok)
6140 break;
6141 handle_field_decl:
6142 if (!remove
6143 && TREE_CODE (t) == FIELD_DECL
6144 && t == OMP_CLAUSE_DECL (c)
6145 && ort != C_ORT_ACC)
6147 OMP_CLAUSE_DECL (c)
6148 = omp_privatize_field (t, (OMP_CLAUSE_CODE (c)
6149 == OMP_CLAUSE_SHARED));
6150 if (OMP_CLAUSE_DECL (c) == error_mark_node)
6151 remove = true;
6153 break;
6155 case OMP_CLAUSE_FIRSTPRIVATE:
6156 t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
6157 if (t)
6158 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
6159 else
6160 t = OMP_CLAUSE_DECL (c);
6161 if (ort != C_ORT_ACC && t == current_class_ptr)
6163 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6164 " clauses");
6165 remove = true;
6166 break;
6168 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
6169 && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
6170 || TREE_CODE (t) != FIELD_DECL))
6172 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6173 break;
6174 if (DECL_P (t))
6175 error ("%qD is not a variable in clause %<firstprivate%>", t);
6176 else
6177 error ("%qE is not a variable in clause %<firstprivate%>", t);
6178 remove = true;
6180 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
6181 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
6183 error ("%qD appears more than once in data clauses", t);
6184 remove = true;
6186 else if (bitmap_bit_p (&map_head, DECL_UID (t)))
6188 if (ort == C_ORT_ACC)
6189 error ("%qD appears more than once in data clauses", t);
6190 else
6191 error ("%qD appears both in data and map clauses", t);
6192 remove = true;
6194 else
6195 bitmap_set_bit (&firstprivate_head, DECL_UID (t));
6196 goto handle_field_decl;
6198 case OMP_CLAUSE_LASTPRIVATE:
6199 t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
6200 if (t)
6201 omp_note_field_privatization (t, OMP_CLAUSE_DECL (c));
6202 else
6203 t = OMP_CLAUSE_DECL (c);
6204 if (t == current_class_ptr)
6206 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6207 " clauses");
6208 remove = true;
6209 break;
6211 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL
6212 && ((ort & C_ORT_OMP_DECLARE_SIMD) != C_ORT_OMP
6213 || TREE_CODE (t) != FIELD_DECL))
6215 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6216 break;
6217 if (DECL_P (t))
6218 error ("%qD is not a variable in clause %<lastprivate%>", t);
6219 else
6220 error ("%qE is not a variable in clause %<lastprivate%>", t);
6221 remove = true;
6223 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
6224 || bitmap_bit_p (&lastprivate_head, DECL_UID (t)))
6226 error ("%qD appears more than once in data clauses", t);
6227 remove = true;
6229 else
6230 bitmap_set_bit (&lastprivate_head, DECL_UID (t));
6231 goto handle_field_decl;
6233 case OMP_CLAUSE_IF:
6234 t = OMP_CLAUSE_IF_EXPR (c);
6235 t = maybe_convert_cond (t);
6236 if (t == error_mark_node)
6237 remove = true;
6238 else if (!processing_template_decl)
6239 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6240 OMP_CLAUSE_IF_EXPR (c) = t;
6241 break;
6243 case OMP_CLAUSE_FINAL:
6244 t = OMP_CLAUSE_FINAL_EXPR (c);
6245 t = maybe_convert_cond (t);
6246 if (t == error_mark_node)
6247 remove = true;
6248 else if (!processing_template_decl)
6249 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6250 OMP_CLAUSE_FINAL_EXPR (c) = t;
6251 break;
6253 case OMP_CLAUSE_GANG:
6254 /* Operand 1 is the gang static: argument. */
6255 t = OMP_CLAUSE_OPERAND (c, 1);
6256 if (t != NULL_TREE)
6258 if (t == error_mark_node)
6259 remove = true;
6260 else if (!type_dependent_expression_p (t)
6261 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
6263 error ("%<gang%> static expression must be integral");
6264 remove = true;
6266 else
6268 t = mark_rvalue_use (t);
6269 if (!processing_template_decl)
6271 t = maybe_constant_value (t);
6272 if (TREE_CODE (t) == INTEGER_CST
6273 && tree_int_cst_sgn (t) != 1
6274 && t != integer_minus_one_node)
6276 warning_at (OMP_CLAUSE_LOCATION (c), 0,
6277 "%<gang%> static value must be "
6278 "positive");
6279 t = integer_one_node;
6281 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6284 OMP_CLAUSE_OPERAND (c, 1) = t;
6286 /* Check operand 0, the num argument. */
6287 /* FALLTHRU */
6289 case OMP_CLAUSE_WORKER:
6290 case OMP_CLAUSE_VECTOR:
6291 if (OMP_CLAUSE_OPERAND (c, 0) == NULL_TREE)
6292 break;
6293 /* FALLTHRU */
6295 case OMP_CLAUSE_NUM_TASKS:
6296 case OMP_CLAUSE_NUM_TEAMS:
6297 case OMP_CLAUSE_NUM_THREADS:
6298 case OMP_CLAUSE_NUM_GANGS:
6299 case OMP_CLAUSE_NUM_WORKERS:
6300 case OMP_CLAUSE_VECTOR_LENGTH:
6301 t = OMP_CLAUSE_OPERAND (c, 0);
6302 if (t == error_mark_node)
6303 remove = true;
6304 else if (!type_dependent_expression_p (t)
6305 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
6307 switch (OMP_CLAUSE_CODE (c))
6309 case OMP_CLAUSE_GANG:
6310 error_at (OMP_CLAUSE_LOCATION (c),
6311 "%<gang%> num expression must be integral"); break;
6312 case OMP_CLAUSE_VECTOR:
6313 error_at (OMP_CLAUSE_LOCATION (c),
6314 "%<vector%> length expression must be integral");
6315 break;
6316 case OMP_CLAUSE_WORKER:
6317 error_at (OMP_CLAUSE_LOCATION (c),
6318 "%<worker%> num expression must be integral");
6319 break;
6320 default:
6321 error_at (OMP_CLAUSE_LOCATION (c),
6322 "%qs expression must be integral",
6323 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6325 remove = true;
6327 else
6329 t = mark_rvalue_use (t);
6330 if (!processing_template_decl)
6332 t = maybe_constant_value (t);
6333 if (TREE_CODE (t) == INTEGER_CST
6334 && tree_int_cst_sgn (t) != 1)
6336 switch (OMP_CLAUSE_CODE (c))
6338 case OMP_CLAUSE_GANG:
6339 warning_at (OMP_CLAUSE_LOCATION (c), 0,
6340 "%<gang%> num value must be positive");
6341 break;
6342 case OMP_CLAUSE_VECTOR:
6343 warning_at (OMP_CLAUSE_LOCATION (c), 0,
6344 "%<vector%> length value must be "
6345 "positive");
6346 break;
6347 case OMP_CLAUSE_WORKER:
6348 warning_at (OMP_CLAUSE_LOCATION (c), 0,
6349 "%<worker%> num value must be "
6350 "positive");
6351 break;
6352 default:
6353 warning_at (OMP_CLAUSE_LOCATION (c), 0,
6354 "%qs value must be positive",
6355 omp_clause_code_name
6356 [OMP_CLAUSE_CODE (c)]);
6358 t = integer_one_node;
6360 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6362 OMP_CLAUSE_OPERAND (c, 0) = t;
6364 break;
6366 case OMP_CLAUSE_SCHEDULE:
6367 if (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_NONMONOTONIC)
6369 const char *p = NULL;
6370 switch (OMP_CLAUSE_SCHEDULE_KIND (c) & OMP_CLAUSE_SCHEDULE_MASK)
6372 case OMP_CLAUSE_SCHEDULE_STATIC: p = "static"; break;
6373 case OMP_CLAUSE_SCHEDULE_DYNAMIC: break;
6374 case OMP_CLAUSE_SCHEDULE_GUIDED: break;
6375 case OMP_CLAUSE_SCHEDULE_AUTO: p = "auto"; break;
6376 case OMP_CLAUSE_SCHEDULE_RUNTIME: p = "runtime"; break;
6377 default: gcc_unreachable ();
6379 if (p)
6381 error_at (OMP_CLAUSE_LOCATION (c),
6382 "%<nonmonotonic%> modifier specified for %qs "
6383 "schedule kind", p);
6384 OMP_CLAUSE_SCHEDULE_KIND (c)
6385 = (enum omp_clause_schedule_kind)
6386 (OMP_CLAUSE_SCHEDULE_KIND (c)
6387 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
6391 t = OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c);
6392 if (t == NULL)
6394 else if (t == error_mark_node)
6395 remove = true;
6396 else if (!type_dependent_expression_p (t)
6397 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
6399 error ("schedule chunk size expression must be integral");
6400 remove = true;
6402 else
6404 t = mark_rvalue_use (t);
6405 if (!processing_template_decl)
6407 t = maybe_constant_value (t);
6408 if (TREE_CODE (t) == INTEGER_CST
6409 && tree_int_cst_sgn (t) != 1)
6411 warning_at (OMP_CLAUSE_LOCATION (c), 0,
6412 "chunk size value must be positive");
6413 t = integer_one_node;
6415 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6417 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c) = t;
6419 break;
6421 case OMP_CLAUSE_SIMDLEN:
6422 case OMP_CLAUSE_SAFELEN:
6423 t = OMP_CLAUSE_OPERAND (c, 0);
6424 if (t == error_mark_node)
6425 remove = true;
6426 else if (!type_dependent_expression_p (t)
6427 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
6429 error ("%qs length expression must be integral",
6430 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6431 remove = true;
6433 else
6435 t = mark_rvalue_use (t);
6436 if (!processing_template_decl)
6438 t = maybe_constant_value (t);
6439 if (TREE_CODE (t) != INTEGER_CST
6440 || tree_int_cst_sgn (t) != 1)
6442 error ("%qs length expression must be positive constant"
6443 " integer expression",
6444 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6445 remove = true;
6448 OMP_CLAUSE_OPERAND (c, 0) = t;
6449 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_SAFELEN)
6450 safelen = c;
6452 break;
6454 case OMP_CLAUSE_ASYNC:
6455 t = OMP_CLAUSE_ASYNC_EXPR (c);
6456 if (t == error_mark_node)
6457 remove = true;
6458 else if (!type_dependent_expression_p (t)
6459 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
6461 error ("%<async%> expression must be integral");
6462 remove = true;
6464 else
6466 t = mark_rvalue_use (t);
6467 if (!processing_template_decl)
6468 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6469 OMP_CLAUSE_ASYNC_EXPR (c) = t;
6471 break;
6473 case OMP_CLAUSE_WAIT:
6474 t = OMP_CLAUSE_WAIT_EXPR (c);
6475 if (t == error_mark_node)
6476 remove = true;
6477 else if (!processing_template_decl)
6478 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6479 OMP_CLAUSE_WAIT_EXPR (c) = t;
6480 break;
6482 case OMP_CLAUSE_THREAD_LIMIT:
6483 t = OMP_CLAUSE_THREAD_LIMIT_EXPR (c);
6484 if (t == error_mark_node)
6485 remove = true;
6486 else if (!type_dependent_expression_p (t)
6487 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
6489 error ("%<thread_limit%> expression must be integral");
6490 remove = true;
6492 else
6494 t = mark_rvalue_use (t);
6495 if (!processing_template_decl)
6497 t = maybe_constant_value (t);
6498 if (TREE_CODE (t) == INTEGER_CST
6499 && tree_int_cst_sgn (t) != 1)
6501 warning_at (OMP_CLAUSE_LOCATION (c), 0,
6502 "%<thread_limit%> value must be positive");
6503 t = integer_one_node;
6505 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6507 OMP_CLAUSE_THREAD_LIMIT_EXPR (c) = t;
6509 break;
6511 case OMP_CLAUSE_DEVICE:
6512 t = OMP_CLAUSE_DEVICE_ID (c);
6513 if (t == error_mark_node)
6514 remove = true;
6515 else if (!type_dependent_expression_p (t)
6516 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
6518 error ("%<device%> id must be integral");
6519 remove = true;
6521 else
6523 t = mark_rvalue_use (t);
6524 if (!processing_template_decl)
6525 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6526 OMP_CLAUSE_DEVICE_ID (c) = t;
6528 break;
6530 case OMP_CLAUSE_DIST_SCHEDULE:
6531 t = OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c);
6532 if (t == NULL)
6534 else if (t == error_mark_node)
6535 remove = true;
6536 else if (!type_dependent_expression_p (t)
6537 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
6539 error ("%<dist_schedule%> chunk size expression must be "
6540 "integral");
6541 remove = true;
6543 else
6545 t = mark_rvalue_use (t);
6546 if (!processing_template_decl)
6547 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
6548 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c) = t;
6550 break;
6552 case OMP_CLAUSE_ALIGNED:
6553 t = OMP_CLAUSE_DECL (c);
6554 if (t == current_class_ptr && ort != C_ORT_OMP_DECLARE_SIMD)
6556 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6557 " clauses");
6558 remove = true;
6559 break;
6561 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
6563 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6564 break;
6565 if (DECL_P (t))
6566 error ("%qD is not a variable in %<aligned%> clause", t);
6567 else
6568 error ("%qE is not a variable in %<aligned%> clause", t);
6569 remove = true;
6571 else if (!type_dependent_expression_p (t)
6572 && !TYPE_PTR_P (TREE_TYPE (t))
6573 && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
6574 && (!TYPE_REF_P (TREE_TYPE (t))
6575 || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
6576 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
6577 != ARRAY_TYPE))))
6579 error_at (OMP_CLAUSE_LOCATION (c),
6580 "%qE in %<aligned%> clause is neither a pointer nor "
6581 "an array nor a reference to pointer or array", t);
6582 remove = true;
6584 else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
6586 error ("%qD appears more than once in %<aligned%> clauses", t);
6587 remove = true;
6589 else
6590 bitmap_set_bit (&aligned_head, DECL_UID (t));
6591 t = OMP_CLAUSE_ALIGNED_ALIGNMENT (c);
6592 if (t == error_mark_node)
6593 remove = true;
6594 else if (t == NULL_TREE)
6595 break;
6596 else if (!type_dependent_expression_p (t)
6597 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
6599 error ("%<aligned%> clause alignment expression must "
6600 "be integral");
6601 remove = true;
6603 else
6605 t = mark_rvalue_use (t);
6606 if (!processing_template_decl)
6608 t = maybe_constant_value (t);
6609 if (TREE_CODE (t) != INTEGER_CST
6610 || tree_int_cst_sgn (t) != 1)
6612 error ("%<aligned%> clause alignment expression must be "
6613 "positive constant integer expression");
6614 remove = true;
6617 OMP_CLAUSE_ALIGNED_ALIGNMENT (c) = t;
6619 break;
6621 case OMP_CLAUSE_DEPEND:
6622 t = OMP_CLAUSE_DECL (c);
6623 if (t == NULL_TREE)
6625 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c)
6626 == OMP_CLAUSE_DEPEND_SOURCE);
6627 break;
6629 if (OMP_CLAUSE_DEPEND_KIND (c) == OMP_CLAUSE_DEPEND_SINK)
6631 if (cp_finish_omp_clause_depend_sink (c))
6632 remove = true;
6633 break;
6635 if (TREE_CODE (t) == TREE_LIST)
6637 if (handle_omp_array_sections (c, ort))
6638 remove = true;
6639 break;
6641 if (t == error_mark_node)
6642 remove = true;
6643 else if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
6645 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6646 break;
6647 if (DECL_P (t))
6648 error ("%qD is not a variable in %<depend%> clause", t);
6649 else
6650 error ("%qE is not a variable in %<depend%> clause", t);
6651 remove = true;
6653 else if (t == current_class_ptr)
6655 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6656 " clauses");
6657 remove = true;
6659 else if (!processing_template_decl
6660 && !cxx_mark_addressable (t))
6661 remove = true;
6662 break;
6664 case OMP_CLAUSE_MAP:
6665 case OMP_CLAUSE_TO:
6666 case OMP_CLAUSE_FROM:
6667 case OMP_CLAUSE__CACHE_:
6668 t = OMP_CLAUSE_DECL (c);
6669 if (TREE_CODE (t) == TREE_LIST)
6671 if (handle_omp_array_sections (c, ort))
6672 remove = true;
6673 else
6675 t = OMP_CLAUSE_DECL (c);
6676 if (TREE_CODE (t) != TREE_LIST
6677 && !type_dependent_expression_p (t)
6678 && !cp_omp_mappable_type (TREE_TYPE (t)))
6680 error_at (OMP_CLAUSE_LOCATION (c),
6681 "array section does not have mappable type "
6682 "in %qs clause",
6683 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6684 remove = true;
6686 while (TREE_CODE (t) == ARRAY_REF)
6687 t = TREE_OPERAND (t, 0);
6688 if (TREE_CODE (t) == COMPONENT_REF
6689 && TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE)
6691 while (TREE_CODE (t) == COMPONENT_REF)
6692 t = TREE_OPERAND (t, 0);
6693 if (REFERENCE_REF_P (t))
6694 t = TREE_OPERAND (t, 0);
6695 if (bitmap_bit_p (&map_field_head, DECL_UID (t)))
6696 break;
6697 if (bitmap_bit_p (&map_head, DECL_UID (t)))
6699 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6700 error ("%qD appears more than once in motion"
6701 " clauses", t);
6702 else if (ort == C_ORT_ACC)
6703 error ("%qD appears more than once in data"
6704 " clauses", t);
6705 else
6706 error ("%qD appears more than once in map"
6707 " clauses", t);
6708 remove = true;
6710 else
6712 bitmap_set_bit (&map_head, DECL_UID (t));
6713 bitmap_set_bit (&map_field_head, DECL_UID (t));
6717 break;
6719 if (t == error_mark_node)
6721 remove = true;
6722 break;
6724 if (REFERENCE_REF_P (t)
6725 && TREE_CODE (TREE_OPERAND (t, 0)) == COMPONENT_REF)
6727 t = TREE_OPERAND (t, 0);
6728 OMP_CLAUSE_DECL (c) = t;
6730 if (TREE_CODE (t) == COMPONENT_REF
6731 && (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP
6732 && OMP_CLAUSE_CODE (c) != OMP_CLAUSE__CACHE_)
6734 if (type_dependent_expression_p (t))
6735 break;
6736 if (TREE_CODE (TREE_OPERAND (t, 1)) == FIELD_DECL
6737 && DECL_BIT_FIELD (TREE_OPERAND (t, 1)))
6739 error_at (OMP_CLAUSE_LOCATION (c),
6740 "bit-field %qE in %qs clause",
6741 t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6742 remove = true;
6744 else if (!cp_omp_mappable_type (TREE_TYPE (t)))
6746 error_at (OMP_CLAUSE_LOCATION (c),
6747 "%qE does not have a mappable type in %qs clause",
6748 t, omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6749 remove = true;
6751 while (TREE_CODE (t) == COMPONENT_REF)
6753 if (TREE_TYPE (TREE_OPERAND (t, 0))
6754 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t, 0)))
6755 == UNION_TYPE))
6757 error_at (OMP_CLAUSE_LOCATION (c),
6758 "%qE is a member of a union", t);
6759 remove = true;
6760 break;
6762 t = TREE_OPERAND (t, 0);
6764 if (remove)
6765 break;
6766 if (REFERENCE_REF_P (t))
6767 t = TREE_OPERAND (t, 0);
6768 if (VAR_P (t) || TREE_CODE (t) == PARM_DECL)
6770 if (bitmap_bit_p (&map_field_head, DECL_UID (t)))
6771 goto handle_map_references;
6774 if (!VAR_P (t) && TREE_CODE (t) != PARM_DECL)
6776 if (processing_template_decl && TREE_CODE (t) != OVERLOAD)
6777 break;
6778 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6779 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
6780 || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_ALWAYS_POINTER))
6781 break;
6782 if (DECL_P (t))
6783 error ("%qD is not a variable in %qs clause", t,
6784 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6785 else
6786 error ("%qE is not a variable in %qs clause", t,
6787 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6788 remove = true;
6790 else if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
6792 error ("%qD is threadprivate variable in %qs clause", t,
6793 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6794 remove = true;
6796 else if (ort != C_ORT_ACC && t == current_class_ptr)
6798 error ("%<this%> allowed in OpenMP only in %<declare simd%>"
6799 " clauses");
6800 remove = true;
6801 break;
6803 else if (!processing_template_decl
6804 && !TYPE_REF_P (TREE_TYPE (t))
6805 && (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP
6806 || (OMP_CLAUSE_MAP_KIND (c)
6807 != GOMP_MAP_FIRSTPRIVATE_POINTER))
6808 && !cxx_mark_addressable (t))
6809 remove = true;
6810 else if (!(OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6811 && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_POINTER
6812 || (OMP_CLAUSE_MAP_KIND (c)
6813 == GOMP_MAP_FIRSTPRIVATE_POINTER)))
6814 && t == OMP_CLAUSE_DECL (c)
6815 && !type_dependent_expression_p (t)
6816 && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t))
6817 ? TREE_TYPE (TREE_TYPE (t))
6818 : TREE_TYPE (t)))
6820 error_at (OMP_CLAUSE_LOCATION (c),
6821 "%qD does not have a mappable type in %qs clause", t,
6822 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6823 remove = true;
6825 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6826 && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FORCE_DEVICEPTR
6827 && !type_dependent_expression_p (t)
6828 && !INDIRECT_TYPE_P (TREE_TYPE (t)))
6830 error ("%qD is not a pointer variable", t);
6831 remove = true;
6833 else if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP
6834 && OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FIRSTPRIVATE_POINTER)
6836 if (bitmap_bit_p (&generic_head, DECL_UID (t))
6837 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
6839 error ("%qD appears more than once in data clauses", t);
6840 remove = true;
6842 else if (bitmap_bit_p (&map_head, DECL_UID (t)))
6844 if (ort == C_ORT_ACC)
6845 error ("%qD appears more than once in data clauses", t);
6846 else
6847 error ("%qD appears both in data and map clauses", t);
6848 remove = true;
6850 else
6851 bitmap_set_bit (&generic_head, DECL_UID (t));
6853 else if (bitmap_bit_p (&map_head, DECL_UID (t)))
6855 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6856 error ("%qD appears more than once in motion clauses", t);
6857 if (ort == C_ORT_ACC)
6858 error ("%qD appears more than once in data clauses", t);
6859 else
6860 error ("%qD appears more than once in map clauses", t);
6861 remove = true;
6863 else if (bitmap_bit_p (&generic_head, DECL_UID (t))
6864 || bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
6866 if (ort == C_ORT_ACC)
6867 error ("%qD appears more than once in data clauses", t);
6868 else
6869 error ("%qD appears both in data and map clauses", t);
6870 remove = true;
6872 else
6874 bitmap_set_bit (&map_head, DECL_UID (t));
6875 if (t != OMP_CLAUSE_DECL (c)
6876 && TREE_CODE (OMP_CLAUSE_DECL (c)) == COMPONENT_REF)
6877 bitmap_set_bit (&map_field_head, DECL_UID (t));
6879 handle_map_references:
6880 if (!remove
6881 && !processing_template_decl
6882 && ort != C_ORT_DECLARE_SIMD
6883 && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c))))
6885 t = OMP_CLAUSE_DECL (c);
6886 if (OMP_CLAUSE_CODE (c) != OMP_CLAUSE_MAP)
6888 OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t);
6889 if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
6890 OMP_CLAUSE_SIZE (c)
6891 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t)));
6893 else if (OMP_CLAUSE_MAP_KIND (c)
6894 != GOMP_MAP_FIRSTPRIVATE_POINTER
6895 && (OMP_CLAUSE_MAP_KIND (c)
6896 != GOMP_MAP_FIRSTPRIVATE_REFERENCE)
6897 && (OMP_CLAUSE_MAP_KIND (c)
6898 != GOMP_MAP_ALWAYS_POINTER))
6900 tree c2 = build_omp_clause (OMP_CLAUSE_LOCATION (c),
6901 OMP_CLAUSE_MAP);
6902 if (TREE_CODE (t) == COMPONENT_REF)
6903 OMP_CLAUSE_SET_MAP_KIND (c2, GOMP_MAP_ALWAYS_POINTER);
6904 else
6905 OMP_CLAUSE_SET_MAP_KIND (c2,
6906 GOMP_MAP_FIRSTPRIVATE_REFERENCE);
6907 OMP_CLAUSE_DECL (c2) = t;
6908 OMP_CLAUSE_SIZE (c2) = size_zero_node;
6909 OMP_CLAUSE_CHAIN (c2) = OMP_CLAUSE_CHAIN (c);
6910 OMP_CLAUSE_CHAIN (c) = c2;
6911 OMP_CLAUSE_DECL (c) = build_simple_mem_ref (t);
6912 if (OMP_CLAUSE_SIZE (c) == NULL_TREE)
6913 OMP_CLAUSE_SIZE (c)
6914 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t)));
6915 c = c2;
6918 break;
6920 case OMP_CLAUSE_TO_DECLARE:
6921 case OMP_CLAUSE_LINK:
6922 t = OMP_CLAUSE_DECL (c);
6923 if (TREE_CODE (t) == FUNCTION_DECL
6924 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE)
6926 else if (!VAR_P (t))
6928 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO_DECLARE)
6930 if (TREE_CODE (t) == TEMPLATE_ID_EXPR)
6931 error_at (OMP_CLAUSE_LOCATION (c),
6932 "template %qE in clause %qs", t,
6933 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6934 else if (really_overloaded_fn (t))
6935 error_at (OMP_CLAUSE_LOCATION (c),
6936 "overloaded function name %qE in clause %qs", t,
6937 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6938 else
6939 error_at (OMP_CLAUSE_LOCATION (c),
6940 "%qE is neither a variable nor a function name "
6941 "in clause %qs", t,
6942 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6944 else
6945 error_at (OMP_CLAUSE_LOCATION (c),
6946 "%qE is not a variable in clause %qs", t,
6947 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6948 remove = true;
6950 else if (DECL_THREAD_LOCAL_P (t))
6952 error_at (OMP_CLAUSE_LOCATION (c),
6953 "%qD is threadprivate variable in %qs clause", t,
6954 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6955 remove = true;
6957 else if (!cp_omp_mappable_type (TREE_TYPE (t)))
6959 error_at (OMP_CLAUSE_LOCATION (c),
6960 "%qD does not have a mappable type in %qs clause", t,
6961 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
6962 remove = true;
6964 if (remove)
6965 break;
6966 if (bitmap_bit_p (&generic_head, DECL_UID (t)))
6968 error_at (OMP_CLAUSE_LOCATION (c),
6969 "%qE appears more than once on the same "
6970 "%<declare target%> directive", t);
6971 remove = true;
6973 else
6974 bitmap_set_bit (&generic_head, DECL_UID (t));
6975 break;
6977 case OMP_CLAUSE_UNIFORM:
6978 t = OMP_CLAUSE_DECL (c);
6979 if (TREE_CODE (t) != PARM_DECL)
6981 if (processing_template_decl)
6982 break;
6983 if (DECL_P (t))
6984 error ("%qD is not an argument in %<uniform%> clause", t);
6985 else
6986 error ("%qE is not an argument in %<uniform%> clause", t);
6987 remove = true;
6988 break;
6990 /* map_head bitmap is used as uniform_head if declare_simd. */
6991 bitmap_set_bit (&map_head, DECL_UID (t));
6992 goto check_dup_generic;
6994 case OMP_CLAUSE_GRAINSIZE:
6995 t = OMP_CLAUSE_GRAINSIZE_EXPR (c);
6996 if (t == error_mark_node)
6997 remove = true;
6998 else if (!type_dependent_expression_p (t)
6999 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7001 error ("%<grainsize%> expression must be integral");
7002 remove = true;
7004 else
7006 t = mark_rvalue_use (t);
7007 if (!processing_template_decl)
7009 t = maybe_constant_value (t);
7010 if (TREE_CODE (t) == INTEGER_CST
7011 && tree_int_cst_sgn (t) != 1)
7013 warning_at (OMP_CLAUSE_LOCATION (c), 0,
7014 "%<grainsize%> value must be positive");
7015 t = integer_one_node;
7017 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7019 OMP_CLAUSE_GRAINSIZE_EXPR (c) = t;
7021 break;
7023 case OMP_CLAUSE_PRIORITY:
7024 t = OMP_CLAUSE_PRIORITY_EXPR (c);
7025 if (t == error_mark_node)
7026 remove = true;
7027 else if (!type_dependent_expression_p (t)
7028 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7030 error ("%<priority%> expression must be integral");
7031 remove = true;
7033 else
7035 t = mark_rvalue_use (t);
7036 if (!processing_template_decl)
7038 t = maybe_constant_value (t);
7039 if (TREE_CODE (t) == INTEGER_CST
7040 && tree_int_cst_sgn (t) == -1)
7042 warning_at (OMP_CLAUSE_LOCATION (c), 0,
7043 "%<priority%> value must be non-negative");
7044 t = integer_one_node;
7046 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7048 OMP_CLAUSE_PRIORITY_EXPR (c) = t;
7050 break;
7052 case OMP_CLAUSE_HINT:
7053 t = OMP_CLAUSE_HINT_EXPR (c);
7054 if (t == error_mark_node)
7055 remove = true;
7056 else if (!type_dependent_expression_p (t)
7057 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7059 error ("%<num_tasks%> expression must be integral");
7060 remove = true;
7062 else
7064 t = mark_rvalue_use (t);
7065 if (!processing_template_decl)
7067 t = maybe_constant_value (t);
7068 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7070 OMP_CLAUSE_HINT_EXPR (c) = t;
7072 break;
7074 case OMP_CLAUSE_IS_DEVICE_PTR:
7075 case OMP_CLAUSE_USE_DEVICE_PTR:
7076 field_ok = (ort & C_ORT_OMP_DECLARE_SIMD) == C_ORT_OMP;
7077 t = OMP_CLAUSE_DECL (c);
7078 if (!type_dependent_expression_p (t))
7080 tree type = TREE_TYPE (t);
7081 if (!TYPE_PTR_P (type)
7082 && TREE_CODE (type) != ARRAY_TYPE
7083 && (!TYPE_REF_P (type)
7084 || (!TYPE_PTR_P (TREE_TYPE (type))
7085 && TREE_CODE (TREE_TYPE (type)) != ARRAY_TYPE)))
7087 error_at (OMP_CLAUSE_LOCATION (c),
7088 "%qs variable is neither a pointer, nor an array "
7089 "nor reference to pointer or array",
7090 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7091 remove = true;
7094 goto check_dup_generic;
7096 case OMP_CLAUSE_NOWAIT:
7097 case OMP_CLAUSE_DEFAULT:
7098 case OMP_CLAUSE_UNTIED:
7099 case OMP_CLAUSE_COLLAPSE:
7100 case OMP_CLAUSE_MERGEABLE:
7101 case OMP_CLAUSE_PARALLEL:
7102 case OMP_CLAUSE_FOR:
7103 case OMP_CLAUSE_SECTIONS:
7104 case OMP_CLAUSE_TASKGROUP:
7105 case OMP_CLAUSE_PROC_BIND:
7106 case OMP_CLAUSE_NOGROUP:
7107 case OMP_CLAUSE_THREADS:
7108 case OMP_CLAUSE_SIMD:
7109 case OMP_CLAUSE_DEFAULTMAP:
7110 case OMP_CLAUSE_AUTO:
7111 case OMP_CLAUSE_INDEPENDENT:
7112 case OMP_CLAUSE_SEQ:
7113 case OMP_CLAUSE_IF_PRESENT:
7114 case OMP_CLAUSE_FINALIZE:
7115 break;
7117 case OMP_CLAUSE_TILE:
7118 for (tree list = OMP_CLAUSE_TILE_LIST (c); !remove && list;
7119 list = TREE_CHAIN (list))
7121 t = TREE_VALUE (list);
7123 if (t == error_mark_node)
7124 remove = true;
7125 else if (!type_dependent_expression_p (t)
7126 && !INTEGRAL_TYPE_P (TREE_TYPE (t)))
7128 error_at (OMP_CLAUSE_LOCATION (c),
7129 "%<tile%> argument needs integral type");
7130 remove = true;
7132 else
7134 t = mark_rvalue_use (t);
7135 if (!processing_template_decl)
7137 /* Zero is used to indicate '*', we permit you
7138 to get there via an ICE of value zero. */
7139 t = maybe_constant_value (t);
7140 if (!tree_fits_shwi_p (t)
7141 || tree_to_shwi (t) < 0)
7143 error_at (OMP_CLAUSE_LOCATION (c),
7144 "%<tile%> argument needs positive "
7145 "integral constant");
7146 remove = true;
7148 t = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
7152 /* Update list item. */
7153 TREE_VALUE (list) = t;
7155 break;
7157 case OMP_CLAUSE_ORDERED:
7158 ordered_seen = true;
7159 break;
7161 case OMP_CLAUSE_INBRANCH:
7162 case OMP_CLAUSE_NOTINBRANCH:
7163 if (branch_seen)
7165 error ("%<inbranch%> clause is incompatible with "
7166 "%<notinbranch%>");
7167 remove = true;
7169 branch_seen = true;
7170 break;
7172 default:
7173 gcc_unreachable ();
7176 if (remove)
7177 *pc = OMP_CLAUSE_CHAIN (c);
7178 else
7179 pc = &OMP_CLAUSE_CHAIN (c);
7182 for (pc = &clauses, c = clauses; c ; c = *pc)
7184 enum omp_clause_code c_kind = OMP_CLAUSE_CODE (c);
7185 bool remove = false;
7186 bool need_complete_type = false;
7187 bool need_default_ctor = false;
7188 bool need_copy_ctor = false;
7189 bool need_copy_assignment = false;
7190 bool need_implicitly_determined = false;
7191 bool need_dtor = false;
7192 tree type, inner_type;
7194 switch (c_kind)
7196 case OMP_CLAUSE_SHARED:
7197 need_implicitly_determined = true;
7198 break;
7199 case OMP_CLAUSE_PRIVATE:
7200 need_complete_type = true;
7201 need_default_ctor = true;
7202 need_dtor = true;
7203 need_implicitly_determined = true;
7204 break;
7205 case OMP_CLAUSE_FIRSTPRIVATE:
7206 need_complete_type = true;
7207 need_copy_ctor = true;
7208 need_dtor = true;
7209 need_implicitly_determined = true;
7210 break;
7211 case OMP_CLAUSE_LASTPRIVATE:
7212 need_complete_type = true;
7213 need_copy_assignment = true;
7214 need_implicitly_determined = true;
7215 break;
7216 case OMP_CLAUSE_REDUCTION:
7217 need_implicitly_determined = true;
7218 break;
7219 case OMP_CLAUSE_LINEAR:
7220 if (ort != C_ORT_OMP_DECLARE_SIMD)
7221 need_implicitly_determined = true;
7222 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c)
7223 && !bitmap_bit_p (&map_head,
7224 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c))))
7226 error_at (OMP_CLAUSE_LOCATION (c),
7227 "%<linear%> clause step is a parameter %qD not "
7228 "specified in %<uniform%> clause",
7229 OMP_CLAUSE_LINEAR_STEP (c));
7230 *pc = OMP_CLAUSE_CHAIN (c);
7231 continue;
7233 break;
7234 case OMP_CLAUSE_COPYPRIVATE:
7235 need_copy_assignment = true;
7236 break;
7237 case OMP_CLAUSE_COPYIN:
7238 need_copy_assignment = true;
7239 break;
7240 case OMP_CLAUSE_SIMDLEN:
7241 if (safelen
7242 && !processing_template_decl
7243 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen),
7244 OMP_CLAUSE_SIMDLEN_EXPR (c)))
7246 error_at (OMP_CLAUSE_LOCATION (c),
7247 "%<simdlen%> clause value is bigger than "
7248 "%<safelen%> clause value");
7249 OMP_CLAUSE_SIMDLEN_EXPR (c)
7250 = OMP_CLAUSE_SAFELEN_EXPR (safelen);
7252 pc = &OMP_CLAUSE_CHAIN (c);
7253 continue;
7254 case OMP_CLAUSE_SCHEDULE:
7255 if (ordered_seen
7256 && (OMP_CLAUSE_SCHEDULE_KIND (c)
7257 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC))
7259 error_at (OMP_CLAUSE_LOCATION (c),
7260 "%<nonmonotonic%> schedule modifier specified "
7261 "together with %<ordered%> clause");
7262 OMP_CLAUSE_SCHEDULE_KIND (c)
7263 = (enum omp_clause_schedule_kind)
7264 (OMP_CLAUSE_SCHEDULE_KIND (c)
7265 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC);
7267 pc = &OMP_CLAUSE_CHAIN (c);
7268 continue;
7269 case OMP_CLAUSE_NOWAIT:
7270 if (copyprivate_seen)
7272 error_at (OMP_CLAUSE_LOCATION (c),
7273 "%<nowait%> clause must not be used together "
7274 "with %<copyprivate%>");
7275 *pc = OMP_CLAUSE_CHAIN (c);
7276 continue;
7278 /* FALLTHRU */
7279 default:
7280 pc = &OMP_CLAUSE_CHAIN (c);
7281 continue;
7284 t = OMP_CLAUSE_DECL (c);
7285 if (processing_template_decl
7286 && !VAR_P (t) && TREE_CODE (t) != PARM_DECL)
7288 pc = &OMP_CLAUSE_CHAIN (c);
7289 continue;
7292 switch (c_kind)
7294 case OMP_CLAUSE_LASTPRIVATE:
7295 if (!bitmap_bit_p (&firstprivate_head, DECL_UID (t)))
7297 need_default_ctor = true;
7298 need_dtor = true;
7300 break;
7302 case OMP_CLAUSE_REDUCTION:
7303 if (finish_omp_reduction_clause (c, &need_default_ctor,
7304 &need_dtor))
7305 remove = true;
7306 else
7307 t = OMP_CLAUSE_DECL (c);
7308 break;
7310 case OMP_CLAUSE_COPYIN:
7311 if (!VAR_P (t) || !CP_DECL_THREAD_LOCAL_P (t))
7313 error ("%qE must be %<threadprivate%> for %<copyin%>", t);
7314 remove = true;
7316 break;
7318 default:
7319 break;
7322 if (need_complete_type || need_copy_assignment)
7324 t = require_complete_type (t);
7325 if (t == error_mark_node)
7326 remove = true;
7327 else if (TYPE_REF_P (TREE_TYPE (t))
7328 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t)), t))
7329 remove = true;
7331 if (need_implicitly_determined)
7333 const char *share_name = NULL;
7335 if (VAR_P (t) && CP_DECL_THREAD_LOCAL_P (t))
7336 share_name = "threadprivate";
7337 else switch (cxx_omp_predetermined_sharing_1 (t))
7339 case OMP_CLAUSE_DEFAULT_UNSPECIFIED:
7340 break;
7341 case OMP_CLAUSE_DEFAULT_SHARED:
7342 /* const vars may be specified in firstprivate clause. */
7343 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FIRSTPRIVATE
7344 && cxx_omp_const_qual_no_mutable (t))
7345 break;
7346 share_name = "shared";
7347 break;
7348 case OMP_CLAUSE_DEFAULT_PRIVATE:
7349 share_name = "private";
7350 break;
7351 default:
7352 gcc_unreachable ();
7354 if (share_name)
7356 error ("%qE is predetermined %qs for %qs",
7357 omp_clause_printable_decl (t), share_name,
7358 omp_clause_code_name[OMP_CLAUSE_CODE (c)]);
7359 remove = true;
7363 /* We're interested in the base element, not arrays. */
7364 inner_type = type = TREE_TYPE (t);
7365 if ((need_complete_type
7366 || need_copy_assignment
7367 || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_REDUCTION)
7368 && TYPE_REF_P (inner_type))
7369 inner_type = TREE_TYPE (inner_type);
7370 while (TREE_CODE (inner_type) == ARRAY_TYPE)
7371 inner_type = TREE_TYPE (inner_type);
7373 /* Check for special function availability by building a call to one.
7374 Save the results, because later we won't be in the right context
7375 for making these queries. */
7376 if (CLASS_TYPE_P (inner_type)
7377 && COMPLETE_TYPE_P (inner_type)
7378 && (need_default_ctor || need_copy_ctor
7379 || need_copy_assignment || need_dtor)
7380 && !type_dependent_expression_p (t)
7381 && cxx_omp_create_clause_info (c, inner_type, need_default_ctor,
7382 need_copy_ctor, need_copy_assignment,
7383 need_dtor))
7384 remove = true;
7386 if (!remove
7387 && c_kind == OMP_CLAUSE_SHARED
7388 && processing_template_decl)
7390 t = omp_clause_decl_field (OMP_CLAUSE_DECL (c));
7391 if (t)
7392 OMP_CLAUSE_DECL (c) = t;
7395 if (remove)
7396 *pc = OMP_CLAUSE_CHAIN (c);
7397 else
7398 pc = &OMP_CLAUSE_CHAIN (c);
7401 bitmap_obstack_release (NULL);
7402 return clauses;
7405 /* Start processing OpenMP clauses that can include any
7406 privatization clauses for non-static data members. */
7408 tree
7409 push_omp_privatization_clauses (bool ignore_next)
7411 if (omp_private_member_ignore_next)
7413 omp_private_member_ignore_next = ignore_next;
7414 return NULL_TREE;
7416 omp_private_member_ignore_next = ignore_next;
7417 if (omp_private_member_map)
7418 omp_private_member_vec.safe_push (error_mark_node);
7419 return push_stmt_list ();
7422 /* Revert remapping of any non-static data members since
7423 the last push_omp_privatization_clauses () call. */
7425 void
7426 pop_omp_privatization_clauses (tree stmt)
7428 if (stmt == NULL_TREE)
7429 return;
7430 stmt = pop_stmt_list (stmt);
7431 if (omp_private_member_map)
7433 while (!omp_private_member_vec.is_empty ())
7435 tree t = omp_private_member_vec.pop ();
7436 if (t == error_mark_node)
7438 add_stmt (stmt);
7439 return;
7441 bool no_decl_expr = t == integer_zero_node;
7442 if (no_decl_expr)
7443 t = omp_private_member_vec.pop ();
7444 tree *v = omp_private_member_map->get (t);
7445 gcc_assert (v);
7446 if (!no_decl_expr)
7447 add_decl_expr (*v);
7448 omp_private_member_map->remove (t);
7450 delete omp_private_member_map;
7451 omp_private_member_map = NULL;
7453 add_stmt (stmt);
7456 /* Remember OpenMP privatization clauses mapping and clear it.
7457 Used for lambdas. */
7459 void
7460 save_omp_privatization_clauses (vec<tree> &save)
7462 save = vNULL;
7463 if (omp_private_member_ignore_next)
7464 save.safe_push (integer_one_node);
7465 omp_private_member_ignore_next = false;
7466 if (!omp_private_member_map)
7467 return;
7469 while (!omp_private_member_vec.is_empty ())
7471 tree t = omp_private_member_vec.pop ();
7472 if (t == error_mark_node)
7474 save.safe_push (t);
7475 continue;
7477 tree n = t;
7478 if (t == integer_zero_node)
7479 t = omp_private_member_vec.pop ();
7480 tree *v = omp_private_member_map->get (t);
7481 gcc_assert (v);
7482 save.safe_push (*v);
7483 save.safe_push (t);
7484 if (n != t)
7485 save.safe_push (n);
7487 delete omp_private_member_map;
7488 omp_private_member_map = NULL;
7491 /* Restore OpenMP privatization clauses mapping saved by the
7492 above function. */
7494 void
7495 restore_omp_privatization_clauses (vec<tree> &save)
7497 gcc_assert (omp_private_member_vec.is_empty ());
7498 omp_private_member_ignore_next = false;
7499 if (save.is_empty ())
7500 return;
7501 if (save.length () == 1 && save[0] == integer_one_node)
7503 omp_private_member_ignore_next = true;
7504 save.release ();
7505 return;
7508 omp_private_member_map = new hash_map <tree, tree>;
7509 while (!save.is_empty ())
7511 tree t = save.pop ();
7512 tree n = t;
7513 if (t != error_mark_node)
7515 if (t == integer_one_node)
7517 omp_private_member_ignore_next = true;
7518 gcc_assert (save.is_empty ());
7519 break;
7521 if (t == integer_zero_node)
7522 t = save.pop ();
7523 tree &v = omp_private_member_map->get_or_insert (t);
7524 v = save.pop ();
7526 omp_private_member_vec.safe_push (t);
7527 if (n != t)
7528 omp_private_member_vec.safe_push (n);
7530 save.release ();
7533 /* For all variables in the tree_list VARS, mark them as thread local. */
7535 void
7536 finish_omp_threadprivate (tree vars)
7538 tree t;
7540 /* Mark every variable in VARS to be assigned thread local storage. */
7541 for (t = vars; t; t = TREE_CHAIN (t))
7543 tree v = TREE_PURPOSE (t);
7545 if (error_operand_p (v))
7547 else if (!VAR_P (v))
7548 error ("%<threadprivate%> %qD is not file, namespace "
7549 "or block scope variable", v);
7550 /* If V had already been marked threadprivate, it doesn't matter
7551 whether it had been used prior to this point. */
7552 else if (TREE_USED (v)
7553 && (DECL_LANG_SPECIFIC (v) == NULL
7554 || !CP_DECL_THREADPRIVATE_P (v)))
7555 error ("%qE declared %<threadprivate%> after first use", v);
7556 else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
7557 error ("automatic variable %qE cannot be %<threadprivate%>", v);
7558 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v))))
7559 error ("%<threadprivate%> %qE has incomplete type", v);
7560 else if (TREE_STATIC (v) && TYPE_P (CP_DECL_CONTEXT (v))
7561 && CP_DECL_CONTEXT (v) != current_class_type)
7562 error ("%<threadprivate%> %qE directive not "
7563 "in %qT definition", v, CP_DECL_CONTEXT (v));
7564 else
7566 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
7567 if (DECL_LANG_SPECIFIC (v) == NULL)
7569 retrofit_lang_decl (v);
7571 /* Make sure that DECL_DISCRIMINATOR_P continues to be true
7572 after the allocation of the lang_decl structure. */
7573 if (DECL_DISCRIMINATOR_P (v))
7574 DECL_LANG_SPECIFIC (v)->u.base.u2sel = 1;
7577 if (! CP_DECL_THREAD_LOCAL_P (v))
7579 CP_DECL_THREAD_LOCAL_P (v) = true;
7580 set_decl_tls_model (v, decl_default_tls_model (v));
7581 /* If rtl has been already set for this var, call
7582 make_decl_rtl once again, so that encode_section_info
7583 has a chance to look at the new decl flags. */
7584 if (DECL_RTL_SET_P (v))
7585 make_decl_rtl (v);
7587 CP_DECL_THREADPRIVATE_P (v) = 1;
7592 /* Build an OpenMP structured block. */
7594 tree
7595 begin_omp_structured_block (void)
7597 return do_pushlevel (sk_omp);
7600 tree
7601 finish_omp_structured_block (tree block)
7603 return do_poplevel (block);
7606 /* Similarly, except force the retention of the BLOCK. */
7608 tree
7609 begin_omp_parallel (void)
7611 keep_next_level (true);
7612 return begin_omp_structured_block ();
7615 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
7616 statement. */
7618 tree
7619 finish_oacc_data (tree clauses, tree block)
7621 tree stmt;
7623 block = finish_omp_structured_block (block);
7625 stmt = make_node (OACC_DATA);
7626 TREE_TYPE (stmt) = void_type_node;
7627 OACC_DATA_CLAUSES (stmt) = clauses;
7628 OACC_DATA_BODY (stmt) = block;
7630 return add_stmt (stmt);
7633 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
7634 statement. */
7636 tree
7637 finish_oacc_host_data (tree clauses, tree block)
7639 tree stmt;
7641 block = finish_omp_structured_block (block);
7643 stmt = make_node (OACC_HOST_DATA);
7644 TREE_TYPE (stmt) = void_type_node;
7645 OACC_HOST_DATA_CLAUSES (stmt) = clauses;
7646 OACC_HOST_DATA_BODY (stmt) = block;
7648 return add_stmt (stmt);
7651 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
7652 statement. */
7654 tree
7655 finish_omp_construct (enum tree_code code, tree body, tree clauses)
7657 body = finish_omp_structured_block (body);
7659 tree stmt = make_node (code);
7660 TREE_TYPE (stmt) = void_type_node;
7661 OMP_BODY (stmt) = body;
7662 OMP_CLAUSES (stmt) = clauses;
7664 return add_stmt (stmt);
7667 tree
7668 finish_omp_parallel (tree clauses, tree body)
7670 tree stmt;
7672 body = finish_omp_structured_block (body);
7674 stmt = make_node (OMP_PARALLEL);
7675 TREE_TYPE (stmt) = void_type_node;
7676 OMP_PARALLEL_CLAUSES (stmt) = clauses;
7677 OMP_PARALLEL_BODY (stmt) = body;
7679 return add_stmt (stmt);
7682 tree
7683 begin_omp_task (void)
7685 keep_next_level (true);
7686 return begin_omp_structured_block ();
7689 tree
7690 finish_omp_task (tree clauses, tree body)
7692 tree stmt;
7694 body = finish_omp_structured_block (body);
7696 stmt = make_node (OMP_TASK);
7697 TREE_TYPE (stmt) = void_type_node;
7698 OMP_TASK_CLAUSES (stmt) = clauses;
7699 OMP_TASK_BODY (stmt) = body;
7701 return add_stmt (stmt);
7704 /* Helper function for finish_omp_for. Convert Ith random access iterator
7705 into integral iterator. Return FALSE if successful. */
7707 static bool
7708 handle_omp_for_class_iterator (int i, location_t locus, enum tree_code code,
7709 tree declv, tree orig_declv, tree initv,
7710 tree condv, tree incrv, tree *body,
7711 tree *pre_body, tree &clauses,
7712 int collapse, int ordered)
7714 tree diff, iter_init, iter_incr = NULL, last;
7715 tree incr_var = NULL, orig_pre_body, orig_body, c;
7716 tree decl = TREE_VEC_ELT (declv, i);
7717 tree init = TREE_VEC_ELT (initv, i);
7718 tree cond = TREE_VEC_ELT (condv, i);
7719 tree incr = TREE_VEC_ELT (incrv, i);
7720 tree iter = decl;
7721 location_t elocus = locus;
7723 if (init && EXPR_HAS_LOCATION (init))
7724 elocus = EXPR_LOCATION (init);
7726 cond = cp_fully_fold (cond);
7727 switch (TREE_CODE (cond))
7729 case GT_EXPR:
7730 case GE_EXPR:
7731 case LT_EXPR:
7732 case LE_EXPR:
7733 case NE_EXPR:
7734 if (TREE_OPERAND (cond, 1) == iter)
7735 cond = build2 (swap_tree_comparison (TREE_CODE (cond)),
7736 TREE_TYPE (cond), iter, TREE_OPERAND (cond, 0));
7737 if (TREE_OPERAND (cond, 0) != iter)
7738 cond = error_mark_node;
7739 else
7741 tree tem = build_x_binary_op (EXPR_LOCATION (cond),
7742 TREE_CODE (cond),
7743 iter, ERROR_MARK,
7744 TREE_OPERAND (cond, 1), ERROR_MARK,
7745 NULL, tf_warning_or_error);
7746 if (error_operand_p (tem))
7747 return true;
7749 break;
7750 default:
7751 cond = error_mark_node;
7752 break;
7754 if (cond == error_mark_node)
7756 error_at (elocus, "invalid controlling predicate");
7757 return true;
7759 diff = build_x_binary_op (elocus, MINUS_EXPR, TREE_OPERAND (cond, 1),
7760 ERROR_MARK, iter, ERROR_MARK, NULL,
7761 tf_warning_or_error);
7762 diff = cp_fully_fold (diff);
7763 if (error_operand_p (diff))
7764 return true;
7765 if (TREE_CODE (TREE_TYPE (diff)) != INTEGER_TYPE)
7767 error_at (elocus, "difference between %qE and %qD does not have integer type",
7768 TREE_OPERAND (cond, 1), iter);
7769 return true;
7771 if (!c_omp_check_loop_iv_exprs (locus, orig_declv,
7772 TREE_VEC_ELT (declv, i), NULL_TREE,
7773 cond, cp_walk_subtrees))
7774 return true;
7776 switch (TREE_CODE (incr))
7778 case PREINCREMENT_EXPR:
7779 case PREDECREMENT_EXPR:
7780 case POSTINCREMENT_EXPR:
7781 case POSTDECREMENT_EXPR:
7782 if (TREE_OPERAND (incr, 0) != iter)
7784 incr = error_mark_node;
7785 break;
7787 iter_incr = build_x_unary_op (EXPR_LOCATION (incr),
7788 TREE_CODE (incr), iter,
7789 tf_warning_or_error);
7790 if (error_operand_p (iter_incr))
7791 return true;
7792 else if (TREE_CODE (incr) == PREINCREMENT_EXPR
7793 || TREE_CODE (incr) == POSTINCREMENT_EXPR)
7794 incr = integer_one_node;
7795 else
7796 incr = integer_minus_one_node;
7797 break;
7798 case MODIFY_EXPR:
7799 if (TREE_OPERAND (incr, 0) != iter)
7800 incr = error_mark_node;
7801 else if (TREE_CODE (TREE_OPERAND (incr, 1)) == PLUS_EXPR
7802 || TREE_CODE (TREE_OPERAND (incr, 1)) == MINUS_EXPR)
7804 tree rhs = TREE_OPERAND (incr, 1);
7805 if (TREE_OPERAND (rhs, 0) == iter)
7807 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 1)))
7808 != INTEGER_TYPE)
7809 incr = error_mark_node;
7810 else
7812 iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
7813 iter, TREE_CODE (rhs),
7814 TREE_OPERAND (rhs, 1),
7815 tf_warning_or_error);
7816 if (error_operand_p (iter_incr))
7817 return true;
7818 incr = TREE_OPERAND (rhs, 1);
7819 incr = cp_convert (TREE_TYPE (diff), incr,
7820 tf_warning_or_error);
7821 if (TREE_CODE (rhs) == MINUS_EXPR)
7823 incr = build1 (NEGATE_EXPR, TREE_TYPE (diff), incr);
7824 incr = fold_simple (incr);
7826 if (TREE_CODE (incr) != INTEGER_CST
7827 && (TREE_CODE (incr) != NOP_EXPR
7828 || (TREE_CODE (TREE_OPERAND (incr, 0))
7829 != INTEGER_CST)))
7830 iter_incr = NULL;
7833 else if (TREE_OPERAND (rhs, 1) == iter)
7835 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs, 0))) != INTEGER_TYPE
7836 || TREE_CODE (rhs) != PLUS_EXPR)
7837 incr = error_mark_node;
7838 else
7840 iter_incr = build_x_binary_op (EXPR_LOCATION (rhs),
7841 PLUS_EXPR,
7842 TREE_OPERAND (rhs, 0),
7843 ERROR_MARK, iter,
7844 ERROR_MARK, NULL,
7845 tf_warning_or_error);
7846 if (error_operand_p (iter_incr))
7847 return true;
7848 iter_incr = build_x_modify_expr (EXPR_LOCATION (rhs),
7849 iter, NOP_EXPR,
7850 iter_incr,
7851 tf_warning_or_error);
7852 if (error_operand_p (iter_incr))
7853 return true;
7854 incr = TREE_OPERAND (rhs, 0);
7855 iter_incr = NULL;
7858 else
7859 incr = error_mark_node;
7861 else
7862 incr = error_mark_node;
7863 break;
7864 default:
7865 incr = error_mark_node;
7866 break;
7869 if (incr == error_mark_node)
7871 error_at (elocus, "invalid increment expression");
7872 return true;
7875 incr = cp_convert (TREE_TYPE (diff), incr, tf_warning_or_error);
7876 bool taskloop_iv_seen = false;
7877 for (c = clauses; c ; c = OMP_CLAUSE_CHAIN (c))
7878 if (OMP_CLAUSE_CODE (c) == OMP_CLAUSE_LASTPRIVATE
7879 && OMP_CLAUSE_DECL (c) == iter)
7881 if (code == OMP_TASKLOOP)
7883 taskloop_iv_seen = true;
7884 OMP_CLAUSE_LASTPRIVATE_TASKLOOP_IV (c) = 1;
7886 break;
7888 else if (code == OMP_TASKLOOP
7889 && OMP_CLAUSE_CODE (c) == OMP_CLAUSE_PRIVATE
7890 && OMP_CLAUSE_DECL (c) == iter)
7892 taskloop_iv_seen = true;
7893 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c) = 1;
7896 decl = create_temporary_var (TREE_TYPE (diff));
7897 pushdecl (decl);
7898 add_decl_expr (decl);
7899 last = create_temporary_var (TREE_TYPE (diff));
7900 pushdecl (last);
7901 add_decl_expr (last);
7902 if (c && iter_incr == NULL && TREE_CODE (incr) != INTEGER_CST
7903 && (!ordered || (i < collapse && collapse > 1)))
7905 incr_var = create_temporary_var (TREE_TYPE (diff));
7906 pushdecl (incr_var);
7907 add_decl_expr (incr_var);
7909 gcc_assert (stmts_are_full_exprs_p ());
7910 tree diffvar = NULL_TREE;
7911 if (code == OMP_TASKLOOP)
7913 if (!taskloop_iv_seen)
7915 tree ivc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
7916 OMP_CLAUSE_DECL (ivc) = iter;
7917 cxx_omp_finish_clause (ivc, NULL);
7918 OMP_CLAUSE_CHAIN (ivc) = clauses;
7919 clauses = ivc;
7921 tree lvc = build_omp_clause (locus, OMP_CLAUSE_FIRSTPRIVATE);
7922 OMP_CLAUSE_DECL (lvc) = last;
7923 OMP_CLAUSE_CHAIN (lvc) = clauses;
7924 clauses = lvc;
7925 diffvar = create_temporary_var (TREE_TYPE (diff));
7926 pushdecl (diffvar);
7927 add_decl_expr (diffvar);
7930 orig_pre_body = *pre_body;
7931 *pre_body = push_stmt_list ();
7932 if (orig_pre_body)
7933 add_stmt (orig_pre_body);
7934 if (init != NULL)
7935 finish_expr_stmt (build_x_modify_expr (elocus,
7936 iter, NOP_EXPR, init,
7937 tf_warning_or_error));
7938 init = build_int_cst (TREE_TYPE (diff), 0);
7939 if (c && iter_incr == NULL
7940 && (!ordered || (i < collapse && collapse > 1)))
7942 if (incr_var)
7944 finish_expr_stmt (build_x_modify_expr (elocus,
7945 incr_var, NOP_EXPR,
7946 incr, tf_warning_or_error));
7947 incr = incr_var;
7949 iter_incr = build_x_modify_expr (elocus,
7950 iter, PLUS_EXPR, incr,
7951 tf_warning_or_error);
7953 if (c && ordered && i < collapse && collapse > 1)
7954 iter_incr = incr;
7955 finish_expr_stmt (build_x_modify_expr (elocus,
7956 last, NOP_EXPR, init,
7957 tf_warning_or_error));
7958 if (diffvar)
7960 finish_expr_stmt (build_x_modify_expr (elocus,
7961 diffvar, NOP_EXPR,
7962 diff, tf_warning_or_error));
7963 diff = diffvar;
7965 *pre_body = pop_stmt_list (*pre_body);
7967 cond = cp_build_binary_op (elocus,
7968 TREE_CODE (cond), decl, diff,
7969 tf_warning_or_error);
7970 incr = build_modify_expr (elocus, decl, NULL_TREE, PLUS_EXPR,
7971 elocus, incr, NULL_TREE);
7973 orig_body = *body;
7974 *body = push_stmt_list ();
7975 iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), decl, last);
7976 iter_init = build_x_modify_expr (elocus,
7977 iter, PLUS_EXPR, iter_init,
7978 tf_warning_or_error);
7979 if (iter_init != error_mark_node)
7980 iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
7981 finish_expr_stmt (iter_init);
7982 finish_expr_stmt (build_x_modify_expr (elocus,
7983 last, NOP_EXPR, decl,
7984 tf_warning_or_error));
7985 add_stmt (orig_body);
7986 *body = pop_stmt_list (*body);
7988 if (c)
7990 OMP_CLAUSE_LASTPRIVATE_STMT (c) = push_stmt_list ();
7991 if (!ordered)
7992 finish_expr_stmt (iter_incr);
7993 else
7995 iter_init = decl;
7996 if (i < collapse && collapse > 1 && !error_operand_p (iter_incr))
7997 iter_init = build2 (PLUS_EXPR, TREE_TYPE (diff),
7998 iter_init, iter_incr);
7999 iter_init = build2 (MINUS_EXPR, TREE_TYPE (diff), iter_init, last);
8000 iter_init = build_x_modify_expr (elocus,
8001 iter, PLUS_EXPR, iter_init,
8002 tf_warning_or_error);
8003 if (iter_init != error_mark_node)
8004 iter_init = build1 (NOP_EXPR, void_type_node, iter_init);
8005 finish_expr_stmt (iter_init);
8007 OMP_CLAUSE_LASTPRIVATE_STMT (c)
8008 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c));
8011 TREE_VEC_ELT (declv, i) = decl;
8012 TREE_VEC_ELT (initv, i) = init;
8013 TREE_VEC_ELT (condv, i) = cond;
8014 TREE_VEC_ELT (incrv, i) = incr;
8015 TREE_VEC_ELT (orig_declv, i)
8016 = tree_cons (TREE_VEC_ELT (orig_declv, i), last, NULL_TREE);
8018 return false;
8021 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
8022 are directly for their associated operands in the statement. DECL
8023 and INIT are a combo; if DECL is NULL then INIT ought to be a
8024 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
8025 optional statements that need to go before the loop into its
8026 sk_omp scope. */
8028 tree
8029 finish_omp_for (location_t locus, enum tree_code code, tree declv,
8030 tree orig_declv, tree initv, tree condv, tree incrv,
8031 tree body, tree pre_body, vec<tree> *orig_inits, tree clauses)
8033 tree omp_for = NULL, orig_incr = NULL;
8034 tree decl = NULL, init, cond, incr;
8035 location_t elocus;
8036 int i;
8037 int collapse = 1;
8038 int ordered = 0;
8040 gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (initv));
8041 gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (condv));
8042 gcc_assert (TREE_VEC_LENGTH (declv) == TREE_VEC_LENGTH (incrv));
8043 if (TREE_VEC_LENGTH (declv) > 1)
8045 tree c;
8047 c = omp_find_clause (clauses, OMP_CLAUSE_TILE);
8048 if (c)
8049 collapse = list_length (OMP_CLAUSE_TILE_LIST (c));
8050 else
8052 c = omp_find_clause (clauses, OMP_CLAUSE_COLLAPSE);
8053 if (c)
8054 collapse = tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c));
8055 if (collapse != TREE_VEC_LENGTH (declv))
8056 ordered = TREE_VEC_LENGTH (declv);
8059 for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
8061 decl = TREE_VEC_ELT (declv, i);
8062 init = TREE_VEC_ELT (initv, i);
8063 cond = TREE_VEC_ELT (condv, i);
8064 incr = TREE_VEC_ELT (incrv, i);
8065 elocus = locus;
8067 if (decl == NULL)
8069 if (init != NULL)
8070 switch (TREE_CODE (init))
8072 case MODIFY_EXPR:
8073 decl = TREE_OPERAND (init, 0);
8074 init = TREE_OPERAND (init, 1);
8075 break;
8076 case MODOP_EXPR:
8077 if (TREE_CODE (TREE_OPERAND (init, 1)) == NOP_EXPR)
8079 decl = TREE_OPERAND (init, 0);
8080 init = TREE_OPERAND (init, 2);
8082 break;
8083 default:
8084 break;
8087 if (decl == NULL)
8089 error_at (locus,
8090 "expected iteration declaration or initialization");
8091 return NULL;
8095 if (init && EXPR_HAS_LOCATION (init))
8096 elocus = EXPR_LOCATION (init);
8098 if (cond == NULL)
8100 error_at (elocus, "missing controlling predicate");
8101 return NULL;
8104 if (incr == NULL)
8106 error_at (elocus, "missing increment expression");
8107 return NULL;
8110 TREE_VEC_ELT (declv, i) = decl;
8111 TREE_VEC_ELT (initv, i) = init;
8114 if (orig_inits)
8116 bool fail = false;
8117 tree orig_init;
8118 FOR_EACH_VEC_ELT (*orig_inits, i, orig_init)
8119 if (orig_init
8120 && !c_omp_check_loop_iv_exprs (locus, declv,
8121 TREE_VEC_ELT (declv, i), orig_init,
8122 NULL_TREE, cp_walk_subtrees))
8123 fail = true;
8124 if (fail)
8125 return NULL;
8128 if (dependent_omp_for_p (declv, initv, condv, incrv))
8130 tree stmt;
8132 stmt = make_node (code);
8134 for (i = 0; i < TREE_VEC_LENGTH (declv); i++)
8136 /* This is really just a place-holder. We'll be decomposing this
8137 again and going through the cp_build_modify_expr path below when
8138 we instantiate the thing. */
8139 TREE_VEC_ELT (initv, i)
8140 = build2 (MODIFY_EXPR, void_type_node, TREE_VEC_ELT (declv, i),
8141 TREE_VEC_ELT (initv, i));
8144 TREE_TYPE (stmt) = void_type_node;
8145 OMP_FOR_INIT (stmt) = initv;
8146 OMP_FOR_COND (stmt) = condv;
8147 OMP_FOR_INCR (stmt) = incrv;
8148 OMP_FOR_BODY (stmt) = body;
8149 OMP_FOR_PRE_BODY (stmt) = pre_body;
8150 OMP_FOR_CLAUSES (stmt) = clauses;
8152 SET_EXPR_LOCATION (stmt, locus);
8153 return add_stmt (stmt);
8156 if (!orig_declv)
8157 orig_declv = copy_node (declv);
8159 if (processing_template_decl)
8160 orig_incr = make_tree_vec (TREE_VEC_LENGTH (incrv));
8162 for (i = 0; i < TREE_VEC_LENGTH (declv); )
8164 decl = TREE_VEC_ELT (declv, i);
8165 init = TREE_VEC_ELT (initv, i);
8166 cond = TREE_VEC_ELT (condv, i);
8167 incr = TREE_VEC_ELT (incrv, i);
8168 if (orig_incr)
8169 TREE_VEC_ELT (orig_incr, i) = incr;
8170 elocus = locus;
8172 if (init && EXPR_HAS_LOCATION (init))
8173 elocus = EXPR_LOCATION (init);
8175 if (!DECL_P (decl))
8177 error_at (elocus, "expected iteration declaration or initialization");
8178 return NULL;
8181 if (incr && TREE_CODE (incr) == MODOP_EXPR)
8183 if (orig_incr)
8184 TREE_VEC_ELT (orig_incr, i) = incr;
8185 incr = cp_build_modify_expr (elocus, TREE_OPERAND (incr, 0),
8186 TREE_CODE (TREE_OPERAND (incr, 1)),
8187 TREE_OPERAND (incr, 2),
8188 tf_warning_or_error);
8191 if (CLASS_TYPE_P (TREE_TYPE (decl)))
8193 if (code == OMP_SIMD)
8195 error_at (elocus, "%<#pragma omp simd%> used with class "
8196 "iteration variable %qE", decl);
8197 return NULL;
8199 if (handle_omp_for_class_iterator (i, locus, code, declv, orig_declv,
8200 initv, condv, incrv, &body,
8201 &pre_body, clauses,
8202 collapse, ordered))
8203 return NULL;
8204 continue;
8207 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl))
8208 && !TYPE_PTR_P (TREE_TYPE (decl)))
8210 error_at (elocus, "invalid type for iteration variable %qE", decl);
8211 return NULL;
8214 if (!processing_template_decl)
8216 init = fold_build_cleanup_point_expr (TREE_TYPE (init), init);
8217 init = cp_build_modify_expr (elocus, decl, NOP_EXPR, init,
8218 tf_warning_or_error);
8220 else
8221 init = build2 (MODIFY_EXPR, void_type_node, decl, init);
8222 if (cond
8223 && TREE_SIDE_EFFECTS (cond)
8224 && COMPARISON_CLASS_P (cond)
8225 && !processing_template_decl)
8227 tree t = TREE_OPERAND (cond, 0);
8228 if (TREE_SIDE_EFFECTS (t)
8229 && t != decl
8230 && (TREE_CODE (t) != NOP_EXPR
8231 || TREE_OPERAND (t, 0) != decl))
8232 TREE_OPERAND (cond, 0)
8233 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8235 t = TREE_OPERAND (cond, 1);
8236 if (TREE_SIDE_EFFECTS (t)
8237 && t != decl
8238 && (TREE_CODE (t) != NOP_EXPR
8239 || TREE_OPERAND (t, 0) != decl))
8240 TREE_OPERAND (cond, 1)
8241 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8243 if (decl == error_mark_node || init == error_mark_node)
8244 return NULL;
8246 TREE_VEC_ELT (declv, i) = decl;
8247 TREE_VEC_ELT (initv, i) = init;
8248 TREE_VEC_ELT (condv, i) = cond;
8249 TREE_VEC_ELT (incrv, i) = incr;
8250 i++;
8253 if (IS_EMPTY_STMT (pre_body))
8254 pre_body = NULL;
8256 omp_for = c_finish_omp_for (locus, code, declv, orig_declv, initv, condv,
8257 incrv, body, pre_body);
8259 /* Check for iterators appearing in lb, b or incr expressions. */
8260 if (omp_for && !c_omp_check_loop_iv (omp_for, orig_declv, cp_walk_subtrees))
8261 omp_for = NULL_TREE;
8263 if (omp_for == NULL)
8265 return NULL;
8268 add_stmt (omp_for);
8270 for (i = 0; i < TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)); i++)
8272 decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), i), 0);
8273 incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i);
8275 if (TREE_CODE (incr) != MODIFY_EXPR)
8276 continue;
8278 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr, 1))
8279 && BINARY_CLASS_P (TREE_OPERAND (incr, 1))
8280 && !processing_template_decl)
8282 tree t = TREE_OPERAND (TREE_OPERAND (incr, 1), 0);
8283 if (TREE_SIDE_EFFECTS (t)
8284 && t != decl
8285 && (TREE_CODE (t) != NOP_EXPR
8286 || TREE_OPERAND (t, 0) != decl))
8287 TREE_OPERAND (TREE_OPERAND (incr, 1), 0)
8288 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8290 t = TREE_OPERAND (TREE_OPERAND (incr, 1), 1);
8291 if (TREE_SIDE_EFFECTS (t)
8292 && t != decl
8293 && (TREE_CODE (t) != NOP_EXPR
8294 || TREE_OPERAND (t, 0) != decl))
8295 TREE_OPERAND (TREE_OPERAND (incr, 1), 1)
8296 = fold_build_cleanup_point_expr (TREE_TYPE (t), t);
8299 if (orig_incr)
8300 TREE_VEC_ELT (OMP_FOR_INCR (omp_for), i) = TREE_VEC_ELT (orig_incr, i);
8302 OMP_FOR_CLAUSES (omp_for) = clauses;
8304 /* For simd loops with non-static data member iterators, we could have added
8305 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
8306 step at this point, fill it in. */
8307 if (code == OMP_SIMD && !processing_template_decl
8308 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for)) == 1)
8309 for (tree c = omp_find_clause (clauses, OMP_CLAUSE_LINEAR); c;
8310 c = omp_find_clause (OMP_CLAUSE_CHAIN (c), OMP_CLAUSE_LINEAR))
8311 if (OMP_CLAUSE_LINEAR_STEP (c) == NULL_TREE)
8313 decl = TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for), 0), 0);
8314 gcc_assert (decl == OMP_CLAUSE_DECL (c));
8315 incr = TREE_VEC_ELT (OMP_FOR_INCR (omp_for), 0);
8316 tree step, stept;
8317 switch (TREE_CODE (incr))
8319 case PREINCREMENT_EXPR:
8320 case POSTINCREMENT_EXPR:
8321 /* c_omp_for_incr_canonicalize_ptr() should have been
8322 called to massage things appropriately. */
8323 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
8324 OMP_CLAUSE_LINEAR_STEP (c) = build_int_cst (TREE_TYPE (decl), 1);
8325 break;
8326 case PREDECREMENT_EXPR:
8327 case POSTDECREMENT_EXPR:
8328 /* c_omp_for_incr_canonicalize_ptr() should have been
8329 called to massage things appropriately. */
8330 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl)));
8331 OMP_CLAUSE_LINEAR_STEP (c)
8332 = build_int_cst (TREE_TYPE (decl), -1);
8333 break;
8334 case MODIFY_EXPR:
8335 gcc_assert (TREE_OPERAND (incr, 0) == decl);
8336 incr = TREE_OPERAND (incr, 1);
8337 switch (TREE_CODE (incr))
8339 case PLUS_EXPR:
8340 if (TREE_OPERAND (incr, 1) == decl)
8341 step = TREE_OPERAND (incr, 0);
8342 else
8343 step = TREE_OPERAND (incr, 1);
8344 break;
8345 case MINUS_EXPR:
8346 case POINTER_PLUS_EXPR:
8347 gcc_assert (TREE_OPERAND (incr, 0) == decl);
8348 step = TREE_OPERAND (incr, 1);
8349 break;
8350 default:
8351 gcc_unreachable ();
8353 stept = TREE_TYPE (decl);
8354 if (INDIRECT_TYPE_P (stept))
8355 stept = sizetype;
8356 step = fold_convert (stept, step);
8357 if (TREE_CODE (incr) == MINUS_EXPR)
8358 step = fold_build1 (NEGATE_EXPR, stept, step);
8359 OMP_CLAUSE_LINEAR_STEP (c) = step;
8360 break;
8361 default:
8362 gcc_unreachable ();
8366 return omp_for;
8369 void
8370 finish_omp_atomic (enum tree_code code, enum tree_code opcode, tree lhs,
8371 tree rhs, tree v, tree lhs1, tree rhs1, bool seq_cst)
8373 tree orig_lhs;
8374 tree orig_rhs;
8375 tree orig_v;
8376 tree orig_lhs1;
8377 tree orig_rhs1;
8378 bool dependent_p;
8379 tree stmt;
8381 orig_lhs = lhs;
8382 orig_rhs = rhs;
8383 orig_v = v;
8384 orig_lhs1 = lhs1;
8385 orig_rhs1 = rhs1;
8386 dependent_p = false;
8387 stmt = NULL_TREE;
8389 /* Even in a template, we can detect invalid uses of the atomic
8390 pragma if neither LHS nor RHS is type-dependent. */
8391 if (processing_template_decl)
8393 dependent_p = (type_dependent_expression_p (lhs)
8394 || (rhs && type_dependent_expression_p (rhs))
8395 || (v && type_dependent_expression_p (v))
8396 || (lhs1 && type_dependent_expression_p (lhs1))
8397 || (rhs1 && type_dependent_expression_p (rhs1)));
8398 if (!dependent_p)
8400 lhs = build_non_dependent_expr (lhs);
8401 if (rhs)
8402 rhs = build_non_dependent_expr (rhs);
8403 if (v)
8404 v = build_non_dependent_expr (v);
8405 if (lhs1)
8406 lhs1 = build_non_dependent_expr (lhs1);
8407 if (rhs1)
8408 rhs1 = build_non_dependent_expr (rhs1);
8411 if (!dependent_p)
8413 bool swapped = false;
8414 if (rhs1 && cp_tree_equal (lhs, rhs))
8416 std::swap (rhs, rhs1);
8417 swapped = !commutative_tree_code (opcode);
8419 if (rhs1 && !cp_tree_equal (lhs, rhs1))
8421 if (code == OMP_ATOMIC)
8422 error ("%<#pragma omp atomic update%> uses two different "
8423 "expressions for memory");
8424 else
8425 error ("%<#pragma omp atomic capture%> uses two different "
8426 "expressions for memory");
8427 return;
8429 if (lhs1 && !cp_tree_equal (lhs, lhs1))
8431 if (code == OMP_ATOMIC)
8432 error ("%<#pragma omp atomic update%> uses two different "
8433 "expressions for memory");
8434 else
8435 error ("%<#pragma omp atomic capture%> uses two different "
8436 "expressions for memory");
8437 return;
8439 stmt = c_finish_omp_atomic (input_location, code, opcode, lhs, rhs,
8440 v, lhs1, rhs1, swapped, seq_cst,
8441 processing_template_decl != 0);
8442 if (stmt == error_mark_node)
8443 return;
8445 if (processing_template_decl)
8447 if (code == OMP_ATOMIC_READ)
8449 stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs),
8450 OMP_ATOMIC_READ, orig_lhs);
8451 OMP_ATOMIC_SEQ_CST (stmt) = seq_cst;
8452 stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
8454 else
8456 if (opcode == NOP_EXPR)
8457 stmt = build2 (MODIFY_EXPR, void_type_node, orig_lhs, orig_rhs);
8458 else
8459 stmt = build2 (opcode, void_type_node, orig_lhs, orig_rhs);
8460 if (orig_rhs1)
8461 stmt = build_min_nt_loc (EXPR_LOCATION (orig_rhs1),
8462 COMPOUND_EXPR, orig_rhs1, stmt);
8463 if (code != OMP_ATOMIC)
8465 stmt = build_min_nt_loc (EXPR_LOCATION (orig_lhs1),
8466 code, orig_lhs1, stmt);
8467 OMP_ATOMIC_SEQ_CST (stmt) = seq_cst;
8468 stmt = build2 (MODIFY_EXPR, void_type_node, orig_v, stmt);
8471 stmt = build2 (OMP_ATOMIC, void_type_node, integer_zero_node, stmt);
8472 OMP_ATOMIC_SEQ_CST (stmt) = seq_cst;
8474 finish_expr_stmt (stmt);
8477 void
8478 finish_omp_barrier (void)
8480 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_BARRIER);
8481 vec<tree, va_gc> *vec = make_tree_vector ();
8482 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
8483 release_tree_vector (vec);
8484 finish_expr_stmt (stmt);
8487 void
8488 finish_omp_flush (void)
8490 tree fn = builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE);
8491 vec<tree, va_gc> *vec = make_tree_vector ();
8492 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
8493 release_tree_vector (vec);
8494 finish_expr_stmt (stmt);
8497 void
8498 finish_omp_taskwait (void)
8500 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT);
8501 vec<tree, va_gc> *vec = make_tree_vector ();
8502 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
8503 release_tree_vector (vec);
8504 finish_expr_stmt (stmt);
8507 void
8508 finish_omp_taskyield (void)
8510 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD);
8511 vec<tree, va_gc> *vec = make_tree_vector ();
8512 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
8513 release_tree_vector (vec);
8514 finish_expr_stmt (stmt);
8517 void
8518 finish_omp_cancel (tree clauses)
8520 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCEL);
8521 int mask = 0;
8522 if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
8523 mask = 1;
8524 else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
8525 mask = 2;
8526 else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
8527 mask = 4;
8528 else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
8529 mask = 8;
8530 else
8532 error ("%<#pragma omp cancel%> must specify one of "
8533 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8534 return;
8536 vec<tree, va_gc> *vec = make_tree_vector ();
8537 tree ifc = omp_find_clause (clauses, OMP_CLAUSE_IF);
8538 if (ifc != NULL_TREE)
8540 tree type = TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc));
8541 ifc = fold_build2_loc (OMP_CLAUSE_LOCATION (ifc), NE_EXPR,
8542 boolean_type_node, OMP_CLAUSE_IF_EXPR (ifc),
8543 build_zero_cst (type));
8545 else
8546 ifc = boolean_true_node;
8547 vec->quick_push (build_int_cst (integer_type_node, mask));
8548 vec->quick_push (ifc);
8549 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
8550 release_tree_vector (vec);
8551 finish_expr_stmt (stmt);
8554 void
8555 finish_omp_cancellation_point (tree clauses)
8557 tree fn = builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT);
8558 int mask = 0;
8559 if (omp_find_clause (clauses, OMP_CLAUSE_PARALLEL))
8560 mask = 1;
8561 else if (omp_find_clause (clauses, OMP_CLAUSE_FOR))
8562 mask = 2;
8563 else if (omp_find_clause (clauses, OMP_CLAUSE_SECTIONS))
8564 mask = 4;
8565 else if (omp_find_clause (clauses, OMP_CLAUSE_TASKGROUP))
8566 mask = 8;
8567 else
8569 error ("%<#pragma omp cancellation point%> must specify one of "
8570 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
8571 return;
8573 vec<tree, va_gc> *vec
8574 = make_tree_vector_single (build_int_cst (integer_type_node, mask));
8575 tree stmt = finish_call_expr (fn, &vec, false, false, tf_warning_or_error);
8576 release_tree_vector (vec);
8577 finish_expr_stmt (stmt);
8580 /* Begin a __transaction_atomic or __transaction_relaxed statement.
8581 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
8582 should create an extra compound stmt. */
8584 tree
8585 begin_transaction_stmt (location_t loc, tree *pcompound, int flags)
8587 tree r;
8589 if (pcompound)
8590 *pcompound = begin_compound_stmt (0);
8592 r = build_stmt (loc, TRANSACTION_EXPR, NULL_TREE);
8594 /* Only add the statement to the function if support enabled. */
8595 if (flag_tm)
8596 add_stmt (r);
8597 else
8598 error_at (loc, ((flags & TM_STMT_ATTR_RELAXED) != 0
8599 ? G_("%<__transaction_relaxed%> without "
8600 "transactional memory support enabled")
8601 : G_("%<__transaction_atomic%> without "
8602 "transactional memory support enabled")));
8604 TRANSACTION_EXPR_BODY (r) = push_stmt_list ();
8605 TREE_SIDE_EFFECTS (r) = 1;
8606 return r;
8609 /* End a __transaction_atomic or __transaction_relaxed statement.
8610 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
8611 and we should end the compound. If NOEX is non-NULL, we wrap the body in
8612 a MUST_NOT_THROW_EXPR with NOEX as condition. */
8614 void
8615 finish_transaction_stmt (tree stmt, tree compound_stmt, int flags, tree noex)
8617 TRANSACTION_EXPR_BODY (stmt) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt));
8618 TRANSACTION_EXPR_OUTER (stmt) = (flags & TM_STMT_ATTR_OUTER) != 0;
8619 TRANSACTION_EXPR_RELAXED (stmt) = (flags & TM_STMT_ATTR_RELAXED) != 0;
8620 TRANSACTION_EXPR_IS_STMT (stmt) = 1;
8622 /* noexcept specifications are not allowed for function transactions. */
8623 gcc_assert (!(noex && compound_stmt));
8624 if (noex)
8626 tree body = build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt),
8627 noex);
8628 protected_set_expr_location
8629 (body, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt)));
8630 TREE_SIDE_EFFECTS (body) = 1;
8631 TRANSACTION_EXPR_BODY (stmt) = body;
8634 if (compound_stmt)
8635 finish_compound_stmt (compound_stmt);
8638 /* Build a __transaction_atomic or __transaction_relaxed expression. If
8639 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
8640 condition. */
8642 tree
8643 build_transaction_expr (location_t loc, tree expr, int flags, tree noex)
8645 tree ret;
8646 if (noex)
8648 expr = build_must_not_throw_expr (expr, noex);
8649 protected_set_expr_location (expr, loc);
8650 TREE_SIDE_EFFECTS (expr) = 1;
8652 ret = build1 (TRANSACTION_EXPR, TREE_TYPE (expr), expr);
8653 if (flags & TM_STMT_ATTR_RELAXED)
8654 TRANSACTION_EXPR_RELAXED (ret) = 1;
8655 TREE_SIDE_EFFECTS (ret) = 1;
8656 SET_EXPR_LOCATION (ret, loc);
8657 return ret;
8660 void
8661 init_cp_semantics (void)
8665 /* Build a STATIC_ASSERT for a static assertion with the condition
8666 CONDITION and the message text MESSAGE. LOCATION is the location
8667 of the static assertion in the source code. When MEMBER_P, this
8668 static assertion is a member of a class. */
8669 void
8670 finish_static_assert (tree condition, tree message, location_t location,
8671 bool member_p)
8673 tsubst_flags_t complain = tf_warning_or_error;
8675 if (message == NULL_TREE
8676 || message == error_mark_node
8677 || condition == NULL_TREE
8678 || condition == error_mark_node)
8679 return;
8681 if (check_for_bare_parameter_packs (condition))
8682 condition = error_mark_node;
8684 if (instantiation_dependent_expression_p (condition))
8686 /* We're in a template; build a STATIC_ASSERT and put it in
8687 the right place. */
8688 tree assertion;
8690 assertion = make_node (STATIC_ASSERT);
8691 STATIC_ASSERT_CONDITION (assertion) = condition;
8692 STATIC_ASSERT_MESSAGE (assertion) = message;
8693 STATIC_ASSERT_SOURCE_LOCATION (assertion) = location;
8695 if (member_p)
8696 maybe_add_class_template_decl_list (current_class_type,
8697 assertion,
8698 /*friend_p=*/0);
8699 else
8700 add_stmt (assertion);
8702 return;
8705 /* Fold the expression and convert it to a boolean value. */
8706 condition = perform_implicit_conversion_flags (boolean_type_node, condition,
8707 complain, LOOKUP_NORMAL);
8708 condition = fold_non_dependent_expr (condition, complain);
8710 if (TREE_CODE (condition) == INTEGER_CST && !integer_zerop (condition))
8711 /* Do nothing; the condition is satisfied. */
8713 else
8715 location_t saved_loc = input_location;
8717 input_location = location;
8718 if (TREE_CODE (condition) == INTEGER_CST
8719 && integer_zerop (condition))
8721 int sz = TREE_INT_CST_LOW (TYPE_SIZE_UNIT
8722 (TREE_TYPE (TREE_TYPE (message))));
8723 int len = TREE_STRING_LENGTH (message) / sz - 1;
8724 /* Report the error. */
8725 if (len == 0)
8726 error ("static assertion failed");
8727 else
8728 error ("static assertion failed: %s",
8729 TREE_STRING_POINTER (message));
8731 else if (condition && condition != error_mark_node)
8733 error ("non-constant condition for static assertion");
8734 if (require_rvalue_constant_expression (condition))
8735 cxx_constant_value (condition);
8737 input_location = saved_loc;
8741 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
8742 suitable for use as a type-specifier.
8744 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
8745 id-expression or a class member access, FALSE when it was parsed as
8746 a full expression. */
8748 tree
8749 finish_decltype_type (tree expr, bool id_expression_or_member_access_p,
8750 tsubst_flags_t complain)
8752 tree type = NULL_TREE;
8754 if (!expr || error_operand_p (expr))
8755 return error_mark_node;
8757 if (TYPE_P (expr)
8758 || TREE_CODE (expr) == TYPE_DECL
8759 || (TREE_CODE (expr) == BIT_NOT_EXPR
8760 && TYPE_P (TREE_OPERAND (expr, 0))))
8762 if (complain & tf_error)
8763 error ("argument to decltype must be an expression");
8764 return error_mark_node;
8767 /* Depending on the resolution of DR 1172, we may later need to distinguish
8768 instantiation-dependent but not type-dependent expressions so that, say,
8769 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
8770 if (instantiation_dependent_uneval_expression_p (expr))
8772 type = cxx_make_type (DECLTYPE_TYPE);
8773 DECLTYPE_TYPE_EXPR (type) = expr;
8774 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type)
8775 = id_expression_or_member_access_p;
8776 SET_TYPE_STRUCTURAL_EQUALITY (type);
8778 return type;
8781 /* The type denoted by decltype(e) is defined as follows: */
8783 expr = resolve_nondeduced_context (expr, complain);
8785 if (invalid_nonstatic_memfn_p (input_location, expr, complain))
8786 return error_mark_node;
8788 if (type_unknown_p (expr))
8790 if (complain & tf_error)
8791 error ("decltype cannot resolve address of overloaded function");
8792 return error_mark_node;
8795 /* To get the size of a static data member declared as an array of
8796 unknown bound, we need to instantiate it. */
8797 if (VAR_P (expr)
8798 && VAR_HAD_UNKNOWN_BOUND (expr)
8799 && DECL_TEMPLATE_INSTANTIATION (expr))
8800 instantiate_decl (expr, /*defer_ok*/true, /*expl_inst_mem*/false);
8802 if (id_expression_or_member_access_p)
8804 /* If e is an id-expression or a class member access (5.2.5
8805 [expr.ref]), decltype(e) is defined as the type of the entity
8806 named by e. If there is no such entity, or e names a set of
8807 overloaded functions, the program is ill-formed. */
8808 if (identifier_p (expr))
8809 expr = lookup_name (expr);
8811 if (INDIRECT_REF_P (expr))
8812 /* This can happen when the expression is, e.g., "a.b". Just
8813 look at the underlying operand. */
8814 expr = TREE_OPERAND (expr, 0);
8816 if (TREE_CODE (expr) == OFFSET_REF
8817 || TREE_CODE (expr) == MEMBER_REF
8818 || TREE_CODE (expr) == SCOPE_REF)
8819 /* We're only interested in the field itself. If it is a
8820 BASELINK, we will need to see through it in the next
8821 step. */
8822 expr = TREE_OPERAND (expr, 1);
8824 if (BASELINK_P (expr))
8825 /* See through BASELINK nodes to the underlying function. */
8826 expr = BASELINK_FUNCTIONS (expr);
8828 /* decltype of a decomposition name drops references in the tuple case
8829 (unlike decltype of a normal variable) and keeps cv-qualifiers from
8830 the containing object in the other cases (unlike decltype of a member
8831 access expression). */
8832 if (DECL_DECOMPOSITION_P (expr))
8834 if (DECL_HAS_VALUE_EXPR_P (expr))
8835 /* Expr is an array or struct subobject proxy, handle
8836 bit-fields properly. */
8837 return unlowered_expr_type (expr);
8838 else
8839 /* Expr is a reference variable for the tuple case. */
8840 return lookup_decomp_type (expr);
8843 switch (TREE_CODE (expr))
8845 case FIELD_DECL:
8846 if (DECL_BIT_FIELD_TYPE (expr))
8848 type = DECL_BIT_FIELD_TYPE (expr);
8849 break;
8851 /* Fall through for fields that aren't bitfields. */
8852 gcc_fallthrough ();
8854 case FUNCTION_DECL:
8855 case VAR_DECL:
8856 case CONST_DECL:
8857 case PARM_DECL:
8858 case RESULT_DECL:
8859 case TEMPLATE_PARM_INDEX:
8860 expr = mark_type_use (expr);
8861 type = TREE_TYPE (expr);
8862 break;
8864 case ERROR_MARK:
8865 type = error_mark_node;
8866 break;
8868 case COMPONENT_REF:
8869 case COMPOUND_EXPR:
8870 mark_type_use (expr);
8871 type = is_bitfield_expr_with_lowered_type (expr);
8872 if (!type)
8873 type = TREE_TYPE (TREE_OPERAND (expr, 1));
8874 break;
8876 case BIT_FIELD_REF:
8877 gcc_unreachable ();
8879 case INTEGER_CST:
8880 case PTRMEM_CST:
8881 /* We can get here when the id-expression refers to an
8882 enumerator or non-type template parameter. */
8883 type = TREE_TYPE (expr);
8884 break;
8886 default:
8887 /* Handle instantiated template non-type arguments. */
8888 type = TREE_TYPE (expr);
8889 break;
8892 else
8894 /* Within a lambda-expression:
8896 Every occurrence of decltype((x)) where x is a possibly
8897 parenthesized id-expression that names an entity of
8898 automatic storage duration is treated as if x were
8899 transformed into an access to a corresponding data member
8900 of the closure type that would have been declared if x
8901 were a use of the denoted entity. */
8902 if (outer_automatic_var_p (expr)
8903 && current_function_decl
8904 && LAMBDA_FUNCTION_P (current_function_decl))
8905 type = capture_decltype (expr);
8906 else if (error_operand_p (expr))
8907 type = error_mark_node;
8908 else if (expr == current_class_ptr)
8909 /* If the expression is just "this", we want the
8910 cv-unqualified pointer for the "this" type. */
8911 type = TYPE_MAIN_VARIANT (TREE_TYPE (expr));
8912 else
8914 /* Otherwise, where T is the type of e, if e is an lvalue,
8915 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
8916 cp_lvalue_kind clk = lvalue_kind (expr);
8917 type = unlowered_expr_type (expr);
8918 gcc_assert (!TYPE_REF_P (type));
8920 /* For vector types, pick a non-opaque variant. */
8921 if (VECTOR_TYPE_P (type))
8922 type = strip_typedefs (type);
8924 if (clk != clk_none && !(clk & clk_class))
8925 type = cp_build_reference_type (type, (clk & clk_rvalueref));
8929 return type;
8932 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
8933 __has_nothrow_copy, depending on assign_p. Returns true iff all
8934 the copy {ctor,assign} fns are nothrow. */
8936 static bool
8937 classtype_has_nothrow_assign_or_copy_p (tree type, bool assign_p)
8939 tree fns = NULL_TREE;
8941 if (assign_p || TYPE_HAS_COPY_CTOR (type))
8942 fns = get_class_binding (type, assign_p ? assign_op_identifier
8943 : ctor_identifier);
8945 bool saw_copy = false;
8946 for (ovl_iterator iter (fns); iter; ++iter)
8948 tree fn = *iter;
8950 if (copy_fn_p (fn) > 0)
8952 saw_copy = true;
8953 maybe_instantiate_noexcept (fn);
8954 if (!TYPE_NOTHROW_P (TREE_TYPE (fn)))
8955 return false;
8959 return saw_copy;
8962 /* Actually evaluates the trait. */
8964 static bool
8965 trait_expr_value (cp_trait_kind kind, tree type1, tree type2)
8967 enum tree_code type_code1;
8968 tree t;
8970 type_code1 = TREE_CODE (type1);
8972 switch (kind)
8974 case CPTK_HAS_NOTHROW_ASSIGN:
8975 type1 = strip_array_types (type1);
8976 return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
8977 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN, type1, type2)
8978 || (CLASS_TYPE_P (type1)
8979 && classtype_has_nothrow_assign_or_copy_p (type1,
8980 true))));
8982 case CPTK_HAS_TRIVIAL_ASSIGN:
8983 /* ??? The standard seems to be missing the "or array of such a class
8984 type" wording for this trait. */
8985 type1 = strip_array_types (type1);
8986 return (!CP_TYPE_CONST_P (type1) && type_code1 != REFERENCE_TYPE
8987 && (trivial_type_p (type1)
8988 || (CLASS_TYPE_P (type1)
8989 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1))));
8991 case CPTK_HAS_NOTHROW_CONSTRUCTOR:
8992 type1 = strip_array_types (type1);
8993 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR, type1, type2)
8994 || (CLASS_TYPE_P (type1)
8995 && (t = locate_ctor (type1))
8996 && (maybe_instantiate_noexcept (t),
8997 TYPE_NOTHROW_P (TREE_TYPE (t)))));
8999 case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
9000 type1 = strip_array_types (type1);
9001 return (trivial_type_p (type1)
9002 || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_DFLT (type1)));
9004 case CPTK_HAS_NOTHROW_COPY:
9005 type1 = strip_array_types (type1);
9006 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY, type1, type2)
9007 || (CLASS_TYPE_P (type1)
9008 && classtype_has_nothrow_assign_or_copy_p (type1, false)));
9010 case CPTK_HAS_TRIVIAL_COPY:
9011 /* ??? The standard seems to be missing the "or array of such a class
9012 type" wording for this trait. */
9013 type1 = strip_array_types (type1);
9014 return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
9015 || (CLASS_TYPE_P (type1) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1)));
9017 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
9018 type1 = strip_array_types (type1);
9019 return (trivial_type_p (type1) || type_code1 == REFERENCE_TYPE
9020 || (CLASS_TYPE_P (type1)
9021 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1)));
9023 case CPTK_HAS_VIRTUAL_DESTRUCTOR:
9024 return type_has_virtual_destructor (type1);
9026 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
9027 return type_has_unique_obj_representations (type1);
9029 case CPTK_IS_ABSTRACT:
9030 return ABSTRACT_CLASS_TYPE_P (type1);
9032 case CPTK_IS_AGGREGATE:
9033 return CP_AGGREGATE_TYPE_P (type1);
9035 case CPTK_IS_BASE_OF:
9036 return (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
9037 && (same_type_ignoring_top_level_qualifiers_p (type1, type2)
9038 || DERIVED_FROM_P (type1, type2)));
9040 case CPTK_IS_CLASS:
9041 return NON_UNION_CLASS_TYPE_P (type1);
9043 case CPTK_IS_EMPTY:
9044 return NON_UNION_CLASS_TYPE_P (type1) && CLASSTYPE_EMPTY_P (type1);
9046 case CPTK_IS_ENUM:
9047 return type_code1 == ENUMERAL_TYPE;
9049 case CPTK_IS_FINAL:
9050 return CLASS_TYPE_P (type1) && CLASSTYPE_FINAL (type1);
9052 case CPTK_IS_LITERAL_TYPE:
9053 return literal_type_p (type1);
9055 case CPTK_IS_POD:
9056 return pod_type_p (type1);
9058 case CPTK_IS_POLYMORPHIC:
9059 return CLASS_TYPE_P (type1) && TYPE_POLYMORPHIC_P (type1);
9061 case CPTK_IS_SAME_AS:
9062 return same_type_p (type1, type2);
9064 case CPTK_IS_STD_LAYOUT:
9065 return std_layout_type_p (type1);
9067 case CPTK_IS_TRIVIAL:
9068 return trivial_type_p (type1);
9070 case CPTK_IS_TRIVIALLY_ASSIGNABLE:
9071 return is_trivially_xible (MODIFY_EXPR, type1, type2);
9073 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
9074 return is_trivially_xible (INIT_EXPR, type1, type2);
9076 case CPTK_IS_TRIVIALLY_COPYABLE:
9077 return trivially_copyable_p (type1);
9079 case CPTK_IS_UNION:
9080 return type_code1 == UNION_TYPE;
9082 case CPTK_IS_ASSIGNABLE:
9083 return is_xible (MODIFY_EXPR, type1, type2);
9085 case CPTK_IS_CONSTRUCTIBLE:
9086 return is_xible (INIT_EXPR, type1, type2);
9088 default:
9089 gcc_unreachable ();
9090 return false;
9094 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
9095 void, or a complete type, returns true, otherwise false. */
9097 static bool
9098 check_trait_type (tree type)
9100 if (type == NULL_TREE)
9101 return true;
9103 if (TREE_CODE (type) == TREE_LIST)
9104 return (check_trait_type (TREE_VALUE (type))
9105 && check_trait_type (TREE_CHAIN (type)));
9107 if (TREE_CODE (type) == ARRAY_TYPE && !TYPE_DOMAIN (type)
9108 && COMPLETE_TYPE_P (TREE_TYPE (type)))
9109 return true;
9111 if (VOID_TYPE_P (type))
9112 return true;
9114 return !!complete_type_or_else (strip_array_types (type), NULL_TREE);
9117 /* Process a trait expression. */
9119 tree
9120 finish_trait_expr (cp_trait_kind kind, tree type1, tree type2)
9122 if (type1 == error_mark_node
9123 || type2 == error_mark_node)
9124 return error_mark_node;
9126 if (processing_template_decl)
9128 tree trait_expr = make_node (TRAIT_EXPR);
9129 TREE_TYPE (trait_expr) = boolean_type_node;
9130 TRAIT_EXPR_TYPE1 (trait_expr) = type1;
9131 TRAIT_EXPR_TYPE2 (trait_expr) = type2;
9132 TRAIT_EXPR_KIND (trait_expr) = kind;
9133 return trait_expr;
9136 switch (kind)
9138 case CPTK_HAS_NOTHROW_ASSIGN:
9139 case CPTK_HAS_TRIVIAL_ASSIGN:
9140 case CPTK_HAS_NOTHROW_CONSTRUCTOR:
9141 case CPTK_HAS_TRIVIAL_CONSTRUCTOR:
9142 case CPTK_HAS_NOTHROW_COPY:
9143 case CPTK_HAS_TRIVIAL_COPY:
9144 case CPTK_HAS_TRIVIAL_DESTRUCTOR:
9145 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS:
9146 case CPTK_HAS_VIRTUAL_DESTRUCTOR:
9147 case CPTK_IS_ABSTRACT:
9148 case CPTK_IS_AGGREGATE:
9149 case CPTK_IS_EMPTY:
9150 case CPTK_IS_FINAL:
9151 case CPTK_IS_LITERAL_TYPE:
9152 case CPTK_IS_POD:
9153 case CPTK_IS_POLYMORPHIC:
9154 case CPTK_IS_STD_LAYOUT:
9155 case CPTK_IS_TRIVIAL:
9156 case CPTK_IS_TRIVIALLY_COPYABLE:
9157 if (!check_trait_type (type1))
9158 return error_mark_node;
9159 break;
9161 case CPTK_IS_ASSIGNABLE:
9162 case CPTK_IS_CONSTRUCTIBLE:
9163 break;
9165 case CPTK_IS_TRIVIALLY_ASSIGNABLE:
9166 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE:
9167 if (!check_trait_type (type1)
9168 || !check_trait_type (type2))
9169 return error_mark_node;
9170 break;
9172 case CPTK_IS_BASE_OF:
9173 if (NON_UNION_CLASS_TYPE_P (type1) && NON_UNION_CLASS_TYPE_P (type2)
9174 && !same_type_ignoring_top_level_qualifiers_p (type1, type2)
9175 && !complete_type_or_else (type2, NULL_TREE))
9176 /* We already issued an error. */
9177 return error_mark_node;
9178 break;
9180 case CPTK_IS_CLASS:
9181 case CPTK_IS_ENUM:
9182 case CPTK_IS_UNION:
9183 case CPTK_IS_SAME_AS:
9184 break;
9186 default:
9187 gcc_unreachable ();
9190 return (trait_expr_value (kind, type1, type2)
9191 ? boolean_true_node : boolean_false_node);
9194 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
9195 which is ignored for C++. */
9197 void
9198 set_float_const_decimal64 (void)
9202 void
9203 clear_float_const_decimal64 (void)
9207 bool
9208 float_const_decimal64_p (void)
9210 return 0;
9214 /* Return true if T designates the implied `this' parameter. */
9216 bool
9217 is_this_parameter (tree t)
9219 if (!DECL_P (t) || DECL_NAME (t) != this_identifier)
9220 return false;
9221 gcc_assert (TREE_CODE (t) == PARM_DECL || is_capture_proxy (t)
9222 || (cp_binding_oracle && TREE_CODE (t) == VAR_DECL));
9223 return true;
9226 /* Insert the deduced return type for an auto function. */
9228 void
9229 apply_deduced_return_type (tree fco, tree return_type)
9231 tree result;
9233 if (return_type == error_mark_node)
9234 return;
9236 if (DECL_CONV_FN_P (fco))
9237 DECL_NAME (fco) = make_conv_op_name (return_type);
9239 TREE_TYPE (fco) = change_return_type (return_type, TREE_TYPE (fco));
9241 result = DECL_RESULT (fco);
9242 if (result == NULL_TREE)
9243 return;
9244 if (TREE_TYPE (result) == return_type)
9245 return;
9247 if (!processing_template_decl && !VOID_TYPE_P (return_type)
9248 && !complete_type_or_else (return_type, NULL_TREE))
9249 return;
9251 /* We already have a DECL_RESULT from start_preparsed_function.
9252 Now we need to redo the work it and allocate_struct_function
9253 did to reflect the new type. */
9254 gcc_assert (current_function_decl == fco);
9255 result = build_decl (input_location, RESULT_DECL, NULL_TREE,
9256 TYPE_MAIN_VARIANT (return_type));
9257 DECL_ARTIFICIAL (result) = 1;
9258 DECL_IGNORED_P (result) = 1;
9259 cp_apply_type_quals_to_decl (cp_type_quals (return_type),
9260 result);
9262 DECL_RESULT (fco) = result;
9264 if (!processing_template_decl)
9266 bool aggr = aggregate_value_p (result, fco);
9267 #ifdef PCC_STATIC_STRUCT_RETURN
9268 cfun->returns_pcc_struct = aggr;
9269 #endif
9270 cfun->returns_struct = aggr;
9275 /* DECL is a local variable or parameter from the surrounding scope of a
9276 lambda-expression. Returns the decltype for a use of the capture field
9277 for DECL even if it hasn't been captured yet. */
9279 static tree
9280 capture_decltype (tree decl)
9282 tree lam = CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl));
9283 /* FIXME do lookup instead of list walk? */
9284 tree cap = value_member (decl, LAMBDA_EXPR_CAPTURE_LIST (lam));
9285 tree type;
9287 if (cap)
9288 type = TREE_TYPE (TREE_PURPOSE (cap));
9289 else
9290 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam))
9292 case CPLD_NONE:
9293 error ("%qD is not captured", decl);
9294 return error_mark_node;
9296 case CPLD_COPY:
9297 type = TREE_TYPE (decl);
9298 if (TYPE_REF_P (type)
9299 && TREE_CODE (TREE_TYPE (type)) != FUNCTION_TYPE)
9300 type = TREE_TYPE (type);
9301 break;
9303 case CPLD_REFERENCE:
9304 type = TREE_TYPE (decl);
9305 if (!TYPE_REF_P (type))
9306 type = build_reference_type (TREE_TYPE (decl));
9307 break;
9309 default:
9310 gcc_unreachable ();
9313 if (!TYPE_REF_P (type))
9315 if (!LAMBDA_EXPR_MUTABLE_P (lam))
9316 type = cp_build_qualified_type (type, (cp_type_quals (type)
9317 |TYPE_QUAL_CONST));
9318 type = build_reference_type (type);
9320 return type;
9323 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
9324 this is a right unary fold. Otherwise it is a left unary fold. */
9326 static tree
9327 finish_unary_fold_expr (tree expr, int op, tree_code dir)
9329 // Build a pack expansion (assuming expr has pack type).
9330 if (!uses_parameter_packs (expr))
9332 error_at (location_of (expr), "operand of fold expression has no "
9333 "unexpanded parameter packs");
9334 return error_mark_node;
9336 tree pack = make_pack_expansion (expr);
9338 // Build the fold expression.
9339 tree code = build_int_cstu (integer_type_node, abs (op));
9340 tree fold = build_min_nt_loc (UNKNOWN_LOCATION, dir, code, pack);
9341 FOLD_EXPR_MODIFY_P (fold) = (op < 0);
9342 return fold;
9345 tree
9346 finish_left_unary_fold_expr (tree expr, int op)
9348 return finish_unary_fold_expr (expr, op, UNARY_LEFT_FOLD_EXPR);
9351 tree
9352 finish_right_unary_fold_expr (tree expr, int op)
9354 return finish_unary_fold_expr (expr, op, UNARY_RIGHT_FOLD_EXPR);
9357 /* Build a binary fold expression over EXPR1 and EXPR2. The
9358 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
9359 has an unexpanded parameter pack). */
9361 tree
9362 finish_binary_fold_expr (tree pack, tree init, int op, tree_code dir)
9364 pack = make_pack_expansion (pack);
9365 tree code = build_int_cstu (integer_type_node, abs (op));
9366 tree fold = build_min_nt_loc (UNKNOWN_LOCATION, dir, code, pack, init);
9367 FOLD_EXPR_MODIFY_P (fold) = (op < 0);
9368 return fold;
9371 tree
9372 finish_binary_fold_expr (tree expr1, tree expr2, int op)
9374 // Determine which expr has an unexpanded parameter pack and
9375 // set the pack and initial term.
9376 bool pack1 = uses_parameter_packs (expr1);
9377 bool pack2 = uses_parameter_packs (expr2);
9378 if (pack1 && !pack2)
9379 return finish_binary_fold_expr (expr1, expr2, op, BINARY_RIGHT_FOLD_EXPR);
9380 else if (pack2 && !pack1)
9381 return finish_binary_fold_expr (expr2, expr1, op, BINARY_LEFT_FOLD_EXPR);
9382 else
9384 if (pack1)
9385 error ("both arguments in binary fold have unexpanded parameter packs");
9386 else
9387 error ("no unexpanded parameter packs in binary fold");
9389 return error_mark_node;
9392 /* Finish __builtin_launder (arg). */
9394 tree
9395 finish_builtin_launder (location_t loc, tree arg, tsubst_flags_t complain)
9397 tree orig_arg = arg;
9398 if (!type_dependent_expression_p (arg))
9399 arg = decay_conversion (arg, complain);
9400 if (error_operand_p (arg))
9401 return error_mark_node;
9402 if (!type_dependent_expression_p (arg)
9403 && !TYPE_PTR_P (TREE_TYPE (arg)))
9405 error_at (loc, "non-pointer argument to %<__builtin_launder%>");
9406 return error_mark_node;
9408 if (processing_template_decl)
9409 arg = orig_arg;
9410 return build_call_expr_internal_loc (loc, IFN_LAUNDER,
9411 TREE_TYPE (arg), 1, arg);
9414 #include "gt-cp-semantics.h"