1 /* Perform the semantic phase of parsing, i.e., the process of
2 building tree structure, checking semantic consistency, and
3 building RTL. These routines are used both during actual parsing
4 and during the instantiation of template functions.
6 Copyright (C) 1998-2015 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GCC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GCC; see the file COPYING3. If not see
24 <http://www.gnu.org/licenses/>. */
28 #include "coretypes.h"
35 #include "stor-layout.h"
36 #include "stringpool.h"
38 #include "c-family/c-common.h"
39 #include "c-family/c-objc.h"
40 #include "tree-inline.h"
45 #include "diagnostic.h"
46 #include "plugin-api.h"
47 #include "hard-reg-set.h"
51 #include "tree-iterator.h"
58 #include "gomp-constants.h"
60 /* There routines provide a modular interface to perform many parsing
61 operations. They may therefore be used during actual parsing, or
62 during template instantiation, which may be regarded as a
63 degenerate form of parsing. */
65 static tree
maybe_convert_cond (tree
);
66 static tree
finalize_nrv_r (tree
*, int *, void *);
67 static tree
capture_decltype (tree
);
70 /* Deferred Access Checking Overview
71 ---------------------------------
73 Most C++ expressions and declarations require access checking
74 to be performed during parsing. However, in several cases,
75 this has to be treated differently.
77 For member declarations, access checking has to be deferred
78 until more information about the declaration is known. For
90 When we are parsing the function return type `A::X', we don't
91 really know if this is allowed until we parse the function name.
93 Furthermore, some contexts require that access checking is
94 never performed at all. These include class heads, and template
97 Typical use of access checking functions is described here:
99 1. When we enter a context that requires certain access checking
100 mode, the function `push_deferring_access_checks' is called with
101 DEFERRING argument specifying the desired mode. Access checking
102 may be performed immediately (dk_no_deferred), deferred
103 (dk_deferred), or not performed (dk_no_check).
105 2. When a declaration such as a type, or a variable, is encountered,
106 the function `perform_or_defer_access_check' is called. It
107 maintains a vector of all deferred checks.
109 3. The global `current_class_type' or `current_function_decl' is then
110 setup by the parser. `enforce_access' relies on these information
113 4. Upon exiting the context mentioned in step 1,
114 `perform_deferred_access_checks' is called to check all declaration
115 stored in the vector. `pop_deferring_access_checks' is then
116 called to restore the previous access checking mode.
118 In case of parsing error, we simply call `pop_deferring_access_checks'
119 without `perform_deferred_access_checks'. */
121 typedef struct GTY(()) deferred_access
{
122 /* A vector representing name-lookups for which we have deferred
123 checking access controls. We cannot check the accessibility of
124 names used in a decl-specifier-seq until we know what is being
125 declared because code like:
132 A::B* A::f() { return 0; }
134 is valid, even though `A::B' is not generally accessible. */
135 vec
<deferred_access_check
, va_gc
> * GTY(()) deferred_access_checks
;
137 /* The current mode of access checks. */
138 enum deferring_kind deferring_access_checks_kind
;
142 /* Data for deferred access checking. */
143 static GTY(()) vec
<deferred_access
, va_gc
> *deferred_access_stack
;
144 static GTY(()) unsigned deferred_access_no_check
;
146 /* Save the current deferred access states and start deferred
147 access checking iff DEFER_P is true. */
150 push_deferring_access_checks (deferring_kind deferring
)
152 /* For context like template instantiation, access checking
153 disabling applies to all nested context. */
154 if (deferred_access_no_check
|| deferring
== dk_no_check
)
155 deferred_access_no_check
++;
158 deferred_access e
= {NULL
, deferring
};
159 vec_safe_push (deferred_access_stack
, e
);
163 /* Save the current deferred access states and start deferred access
164 checking, continuing the set of deferred checks in CHECKS. */
167 reopen_deferring_access_checks (vec
<deferred_access_check
, va_gc
> * checks
)
169 push_deferring_access_checks (dk_deferred
);
170 if (!deferred_access_no_check
)
171 deferred_access_stack
->last().deferred_access_checks
= checks
;
174 /* Resume deferring access checks again after we stopped doing
178 resume_deferring_access_checks (void)
180 if (!deferred_access_no_check
)
181 deferred_access_stack
->last().deferring_access_checks_kind
= dk_deferred
;
184 /* Stop deferring access checks. */
187 stop_deferring_access_checks (void)
189 if (!deferred_access_no_check
)
190 deferred_access_stack
->last().deferring_access_checks_kind
= dk_no_deferred
;
193 /* Discard the current deferred access checks and restore the
197 pop_deferring_access_checks (void)
199 if (deferred_access_no_check
)
200 deferred_access_no_check
--;
202 deferred_access_stack
->pop ();
205 /* Returns a TREE_LIST representing the deferred checks.
206 The TREE_PURPOSE of each node is the type through which the
207 access occurred; the TREE_VALUE is the declaration named.
210 vec
<deferred_access_check
, va_gc
> *
211 get_deferred_access_checks (void)
213 if (deferred_access_no_check
)
216 return (deferred_access_stack
->last().deferred_access_checks
);
219 /* Take current deferred checks and combine with the
220 previous states if we also defer checks previously.
221 Otherwise perform checks now. */
224 pop_to_parent_deferring_access_checks (void)
226 if (deferred_access_no_check
)
227 deferred_access_no_check
--;
230 vec
<deferred_access_check
, va_gc
> *checks
;
231 deferred_access
*ptr
;
233 checks
= (deferred_access_stack
->last ().deferred_access_checks
);
235 deferred_access_stack
->pop ();
236 ptr
= &deferred_access_stack
->last ();
237 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
240 perform_access_checks (checks
, tf_warning_or_error
);
244 /* Merge with parent. */
246 deferred_access_check
*chk
, *probe
;
248 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
250 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, j
, probe
)
252 if (probe
->binfo
== chk
->binfo
&&
253 probe
->decl
== chk
->decl
&&
254 probe
->diag_decl
== chk
->diag_decl
)
257 /* Insert into parent's checks. */
258 vec_safe_push (ptr
->deferred_access_checks
, *chk
);
265 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
266 is the BINFO indicating the qualifying scope used to access the
267 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
268 or we aren't in SFINAE context or all the checks succeed return TRUE,
272 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
273 tsubst_flags_t complain
)
276 deferred_access_check
*chk
;
277 location_t loc
= input_location
;
283 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
285 input_location
= chk
->loc
;
286 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
289 input_location
= loc
;
290 return (complain
& tf_error
) ? true : ok
;
293 /* Perform the deferred access checks.
295 After performing the checks, we still have to keep the list
296 `deferred_access_stack->deferred_access_checks' since we may want
297 to check access for them again later in a different context.
304 A::X A::a, x; // No error for `A::a', error for `x'
306 We have to perform deferred access of `A::X', first with `A::a',
307 next with `x'. Return value like perform_access_checks above. */
310 perform_deferred_access_checks (tsubst_flags_t complain
)
312 return perform_access_checks (get_deferred_access_checks (), complain
);
315 /* Defer checking the accessibility of DECL, when looked up in
316 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
317 Return value like perform_access_checks above. */
320 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
321 tsubst_flags_t complain
)
324 deferred_access
*ptr
;
325 deferred_access_check
*chk
;
328 /* Exit if we are in a context that no access checking is performed.
330 if (deferred_access_no_check
)
333 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
335 ptr
= &deferred_access_stack
->last ();
337 /* If we are not supposed to defer access checks, just check now. */
338 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
340 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
);
341 return (complain
& tf_error
) ? true : ok
;
344 /* See if we are already going to perform this check. */
345 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
347 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
348 chk
->diag_decl
== diag_decl
)
353 /* If not, record the check. */
354 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
355 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
360 /* Returns nonzero if the current statement is a full expression,
361 i.e. temporaries created during that statement should be destroyed
362 at the end of the statement. */
365 stmts_are_full_exprs_p (void)
367 return current_stmt_tree ()->stmts_are_full_exprs_p
;
370 /* T is a statement. Add it to the statement-tree. This is the C++
371 version. The C/ObjC frontends have a slightly different version of
377 enum tree_code code
= TREE_CODE (t
);
379 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
381 if (!EXPR_HAS_LOCATION (t
))
382 SET_EXPR_LOCATION (t
, input_location
);
384 /* When we expand a statement-tree, we must know whether or not the
385 statements are full-expressions. We record that fact here. */
386 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
389 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
390 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
392 /* Add T to the statement-tree. Non-side-effect statements need to be
393 recorded during statement expressions. */
394 gcc_checking_assert (!stmt_list_stack
->is_empty ());
395 append_to_statement_list_force (t
, &cur_stmt_list
);
400 /* Returns the stmt_tree to which statements are currently being added. */
403 current_stmt_tree (void)
406 ? &cfun
->language
->base
.x_stmt_tree
407 : &scope_chain
->x_stmt_tree
);
410 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
413 maybe_cleanup_point_expr (tree expr
)
415 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
416 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
420 /* Like maybe_cleanup_point_expr except have the type of the new expression be
421 void so we don't need to create a temporary variable to hold the inner
422 expression. The reason why we do this is because the original type might be
423 an aggregate and we cannot create a temporary variable for that type. */
426 maybe_cleanup_point_expr_void (tree expr
)
428 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
429 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
435 /* Create a declaration statement for the declaration given by the DECL. */
438 add_decl_expr (tree decl
)
440 tree r
= build_stmt (input_location
, DECL_EXPR
, decl
);
441 if (DECL_INITIAL (decl
)
442 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
443 r
= maybe_cleanup_point_expr_void (r
);
447 /* Finish a scope. */
450 do_poplevel (tree stmt_list
)
454 if (stmts_are_full_exprs_p ())
455 block
= poplevel (kept_level_p (), 1, 0);
457 stmt_list
= pop_stmt_list (stmt_list
);
459 if (!processing_template_decl
)
461 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
462 /* ??? See c_end_compound_stmt re statement expressions. */
468 /* Begin a new scope. */
471 do_pushlevel (scope_kind sk
)
473 tree ret
= push_stmt_list ();
474 if (stmts_are_full_exprs_p ())
475 begin_scope (sk
, NULL
);
479 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
480 when the current scope is exited. EH_ONLY is true when this is not
481 meant to apply to normal control flow transfer. */
484 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
486 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
487 CLEANUP_EH_ONLY (stmt
) = eh_only
;
489 CLEANUP_BODY (stmt
) = push_stmt_list ();
492 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
493 the current loops, represented by 'NULL_TREE' if we've seen a possible
494 exit, and 'error_mark_node' if not. This is currently used only to
495 suppress the warning about a function with no return statements, and
496 therefore we don't bother noting returns as possible exits. We also
497 don't bother with gotos. */
500 begin_maybe_infinite_loop (tree cond
)
502 /* Only track this while parsing a function, not during instantiation. */
503 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
504 && !processing_template_decl
))
506 bool maybe_infinite
= true;
509 cond
= fold_non_dependent_expr (cond
);
510 maybe_infinite
= integer_nonzerop (cond
);
512 vec_safe_push (cp_function_chain
->infinite_loops
,
513 maybe_infinite
? error_mark_node
: NULL_TREE
);
517 /* A break is a possible exit for the current loop. */
520 break_maybe_infinite_loop (void)
524 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
527 /* If we reach the end of the loop without seeing a possible exit, we have
531 end_maybe_infinite_loop (tree cond
)
533 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
534 && !processing_template_decl
))
536 tree current
= cp_function_chain
->infinite_loops
->pop();
537 if (current
!= NULL_TREE
)
539 cond
= fold_non_dependent_expr (cond
);
540 if (integer_nonzerop (cond
))
541 current_function_infinite_loop
= 1;
546 /* Begin a conditional that might contain a declaration. When generating
547 normal code, we want the declaration to appear before the statement
548 containing the conditional. When generating template code, we want the
549 conditional to be rendered as the raw DECL_EXPR. */
552 begin_cond (tree
*cond_p
)
554 if (processing_template_decl
)
555 *cond_p
= push_stmt_list ();
558 /* Finish such a conditional. */
561 finish_cond (tree
*cond_p
, tree expr
)
563 if (processing_template_decl
)
565 tree cond
= pop_stmt_list (*cond_p
);
567 if (expr
== NULL_TREE
)
568 /* Empty condition in 'for'. */
569 gcc_assert (empty_expr_stmt_p (cond
));
570 else if (check_for_bare_parameter_packs (expr
))
571 expr
= error_mark_node
;
572 else if (!empty_expr_stmt_p (cond
))
573 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
578 /* If *COND_P specifies a conditional with a declaration, transform the
581 for (; A x = 42;) { }
583 while (true) { A x = 42; if (!x) break; }
584 for (;;) { A x = 42; if (!x) break; }
585 The statement list for BODY will be empty if the conditional did
586 not declare anything. */
589 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
593 if (!TREE_SIDE_EFFECTS (body
))
597 *cond_p
= boolean_true_node
;
599 if_stmt
= begin_if_stmt ();
600 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, 0, tf_warning_or_error
);
601 finish_if_stmt_cond (cond
, if_stmt
);
602 finish_break_stmt ();
603 finish_then_clause (if_stmt
);
604 finish_if_stmt (if_stmt
);
607 /* Finish a goto-statement. */
610 finish_goto_stmt (tree destination
)
612 if (identifier_p (destination
))
613 destination
= lookup_label (destination
);
615 /* We warn about unused labels with -Wunused. That means we have to
616 mark the used labels as used. */
617 if (TREE_CODE (destination
) == LABEL_DECL
)
618 TREE_USED (destination
) = 1;
621 if (check_no_cilk (destination
,
622 "Cilk array notation cannot be used as a computed goto expression",
623 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression"))
624 destination
= error_mark_node
;
625 destination
= mark_rvalue_use (destination
);
626 if (!processing_template_decl
)
628 destination
= cp_convert (ptr_type_node
, destination
,
629 tf_warning_or_error
);
630 if (error_operand_p (destination
))
633 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
638 check_goto (destination
);
640 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
643 /* COND is the condition-expression for an if, while, etc.,
644 statement. Convert it to a boolean value, if appropriate.
645 In addition, verify sequence points if -Wsequence-point is enabled. */
648 maybe_convert_cond (tree cond
)
650 /* Empty conditions remain empty. */
654 /* Wait until we instantiate templates before doing conversion. */
655 if (processing_template_decl
)
658 if (warn_sequence_point
)
659 verify_sequence_points (cond
);
661 /* Do the conversion. */
662 cond
= convert_from_reference (cond
);
664 if (TREE_CODE (cond
) == MODIFY_EXPR
665 && !TREE_NO_WARNING (cond
)
668 warning (OPT_Wparentheses
,
669 "suggest parentheses around assignment used as truth value");
670 TREE_NO_WARNING (cond
) = 1;
673 return condition_conversion (cond
);
676 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
679 finish_expr_stmt (tree expr
)
683 if (expr
!= NULL_TREE
)
685 if (!processing_template_decl
)
687 if (warn_sequence_point
)
688 verify_sequence_points (expr
);
689 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
691 else if (!type_dependent_expression_p (expr
))
692 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
693 tf_warning_or_error
);
695 if (check_for_bare_parameter_packs (expr
))
696 expr
= error_mark_node
;
698 /* Simplification of inner statement expressions, compound exprs,
699 etc can result in us already having an EXPR_STMT. */
700 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
702 if (TREE_CODE (expr
) != EXPR_STMT
)
703 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
704 expr
= maybe_cleanup_point_expr_void (expr
);
714 /* Begin an if-statement. Returns a newly created IF_STMT if
721 scope
= do_pushlevel (sk_cond
);
722 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
723 NULL_TREE
, NULL_TREE
, scope
);
724 begin_cond (&IF_COND (r
));
728 /* Process the COND of an if-statement, which may be given by
732 finish_if_stmt_cond (tree cond
, tree if_stmt
)
734 finish_cond (&IF_COND (if_stmt
), maybe_convert_cond (cond
));
736 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
739 /* Finish the then-clause of an if-statement, which may be given by
743 finish_then_clause (tree if_stmt
)
745 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
749 /* Begin the else-clause of an if-statement. */
752 begin_else_clause (tree if_stmt
)
754 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
757 /* Finish the else-clause of an if-statement, which may be given by
761 finish_else_clause (tree if_stmt
)
763 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
766 /* Finish an if-statement. */
769 finish_if_stmt (tree if_stmt
)
771 tree scope
= IF_SCOPE (if_stmt
);
772 IF_SCOPE (if_stmt
) = NULL
;
773 add_stmt (do_poplevel (scope
));
776 /* Begin a while-statement. Returns a newly created WHILE_STMT if
780 begin_while_stmt (void)
783 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
785 WHILE_BODY (r
) = do_pushlevel (sk_block
);
786 begin_cond (&WHILE_COND (r
));
790 /* Process the COND of a while-statement, which may be given by
794 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
)
796 if (check_no_cilk (cond
,
797 "Cilk array notation cannot be used as a condition for while statement",
798 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
799 cond
= error_mark_node
;
800 cond
= maybe_convert_cond (cond
);
801 finish_cond (&WHILE_COND (while_stmt
), cond
);
802 begin_maybe_infinite_loop (cond
);
803 if (ivdep
&& cond
!= error_mark_node
)
804 WHILE_COND (while_stmt
) = build2 (ANNOTATE_EXPR
,
805 TREE_TYPE (WHILE_COND (while_stmt
)),
806 WHILE_COND (while_stmt
),
807 build_int_cst (integer_type_node
,
808 annot_expr_ivdep_kind
));
809 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
812 /* Finish a while-statement, which may be given by WHILE_STMT. */
815 finish_while_stmt (tree while_stmt
)
817 end_maybe_infinite_loop (boolean_true_node
);
818 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
821 /* Begin a do-statement. Returns a newly created DO_STMT if
827 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
828 begin_maybe_infinite_loop (boolean_true_node
);
830 DO_BODY (r
) = push_stmt_list ();
834 /* Finish the body of a do-statement, which may be given by DO_STMT. */
837 finish_do_body (tree do_stmt
)
839 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
841 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
842 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
844 if (IS_EMPTY_STMT (body
))
845 warning (OPT_Wempty_body
,
846 "suggest explicit braces around empty body in %<do%> statement");
849 /* Finish a do-statement, which may be given by DO_STMT, and whose
850 COND is as indicated. */
853 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
)
855 if (check_no_cilk (cond
,
856 "Cilk array notation cannot be used as a condition for a do-while statement",
857 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
858 cond
= error_mark_node
;
859 cond
= maybe_convert_cond (cond
);
860 end_maybe_infinite_loop (cond
);
861 if (ivdep
&& cond
!= error_mark_node
)
862 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
863 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
));
864 DO_COND (do_stmt
) = cond
;
867 /* Finish a return-statement. The EXPRESSION returned, if any, is as
871 finish_return_stmt (tree expr
)
876 expr
= check_return_expr (expr
, &no_warning
);
878 if (error_operand_p (expr
)
879 || (flag_openmp
&& !check_omp_return ()))
881 /* Suppress -Wreturn-type for this function. */
882 if (warn_return_type
)
883 TREE_NO_WARNING (current_function_decl
) = true;
884 return error_mark_node
;
887 if (!processing_template_decl
)
889 if (warn_sequence_point
)
890 verify_sequence_points (expr
);
892 if (DECL_DESTRUCTOR_P (current_function_decl
)
893 || (DECL_CONSTRUCTOR_P (current_function_decl
)
894 && targetm
.cxx
.cdtor_returns_this ()))
896 /* Similarly, all destructors must run destructors for
897 base-classes before returning. So, all returns in a
898 destructor get sent to the DTOR_LABEL; finish_function emits
899 code to return a value there. */
900 return finish_goto_stmt (cdtor_label
);
904 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
905 TREE_NO_WARNING (r
) |= no_warning
;
906 r
= maybe_cleanup_point_expr_void (r
);
912 /* Begin the scope of a for-statement or a range-for-statement.
913 Both the returned trees are to be used in a call to
914 begin_for_stmt or begin_range_for_stmt. */
917 begin_for_scope (tree
*init
)
919 tree scope
= NULL_TREE
;
920 if (flag_new_for_scope
> 0)
921 scope
= do_pushlevel (sk_for
);
923 if (processing_template_decl
)
924 *init
= push_stmt_list ();
931 /* Begin a for-statement. Returns a new FOR_STMT.
932 SCOPE and INIT should be the return of begin_for_scope,
936 begin_for_stmt (tree scope
, tree init
)
940 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
941 NULL_TREE
, NULL_TREE
, NULL_TREE
);
943 if (scope
== NULL_TREE
)
945 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
947 scope
= begin_for_scope (&init
);
949 FOR_INIT_STMT (r
) = init
;
950 FOR_SCOPE (r
) = scope
;
955 /* Finish the for-init-statement of a for-statement, which may be
956 given by FOR_STMT. */
959 finish_for_init_stmt (tree for_stmt
)
961 if (processing_template_decl
)
962 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
964 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
965 begin_cond (&FOR_COND (for_stmt
));
968 /* Finish the COND of a for-statement, which may be given by
972 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
)
974 if (check_no_cilk (cond
,
975 "Cilk array notation cannot be used in a condition for a for-loop",
976 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
977 cond
= error_mark_node
;
978 cond
= maybe_convert_cond (cond
);
979 finish_cond (&FOR_COND (for_stmt
), cond
);
980 begin_maybe_infinite_loop (cond
);
981 if (ivdep
&& cond
!= error_mark_node
)
982 FOR_COND (for_stmt
) = build2 (ANNOTATE_EXPR
,
983 TREE_TYPE (FOR_COND (for_stmt
)),
985 build_int_cst (integer_type_node
,
986 annot_expr_ivdep_kind
));
987 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
990 /* Finish the increment-EXPRESSION in a for-statement, which may be
991 given by FOR_STMT. */
994 finish_for_expr (tree expr
, tree for_stmt
)
998 /* If EXPR is an overloaded function, issue an error; there is no
999 context available to use to perform overload resolution. */
1000 if (type_unknown_p (expr
))
1002 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1003 expr
= error_mark_node
;
1005 if (!processing_template_decl
)
1007 if (warn_sequence_point
)
1008 verify_sequence_points (expr
);
1009 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1010 tf_warning_or_error
);
1012 else if (!type_dependent_expression_p (expr
))
1013 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1014 tf_warning_or_error
);
1015 expr
= maybe_cleanup_point_expr_void (expr
);
1016 if (check_for_bare_parameter_packs (expr
))
1017 expr
= error_mark_node
;
1018 FOR_EXPR (for_stmt
) = expr
;
1021 /* Finish the body of a for-statement, which may be given by
1022 FOR_STMT. The increment-EXPR for the loop must be
1024 It can also finish RANGE_FOR_STMT. */
1027 finish_for_stmt (tree for_stmt
)
1029 end_maybe_infinite_loop (boolean_true_node
);
1031 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1032 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1034 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1036 /* Pop the scope for the body of the loop. */
1037 if (flag_new_for_scope
> 0)
1040 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1041 ? &RANGE_FOR_SCOPE (for_stmt
)
1042 : &FOR_SCOPE (for_stmt
));
1045 add_stmt (do_poplevel (scope
));
1049 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1050 SCOPE and INIT should be the return of begin_for_scope,
1052 To finish it call finish_for_stmt(). */
1055 begin_range_for_stmt (tree scope
, tree init
)
1059 begin_maybe_infinite_loop (boolean_false_node
);
1061 r
= build_stmt (input_location
, RANGE_FOR_STMT
,
1062 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1064 if (scope
== NULL_TREE
)
1066 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
1068 scope
= begin_for_scope (&init
);
1071 /* RANGE_FOR_STMTs do not use nor save the init tree, so we
1074 pop_stmt_list (init
);
1075 RANGE_FOR_SCOPE (r
) = scope
;
1080 /* Finish the head of a range-based for statement, which may
1081 be given by RANGE_FOR_STMT. DECL must be the declaration
1082 and EXPR must be the loop expression. */
1085 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1087 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1088 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1089 add_stmt (range_for_stmt
);
1090 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1093 /* Finish a break-statement. */
1096 finish_break_stmt (void)
1098 /* In switch statements break is sometimes stylistically used after
1099 a return statement. This can lead to spurious warnings about
1100 control reaching the end of a non-void function when it is
1101 inlined. Note that we are calling block_may_fallthru with
1102 language specific tree nodes; this works because
1103 block_may_fallthru returns true when given something it does not
1105 if (!block_may_fallthru (cur_stmt_list
))
1107 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1110 /* Finish a continue-statement. */
1113 finish_continue_stmt (void)
1115 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1118 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1122 begin_switch_stmt (void)
1126 scope
= do_pushlevel (sk_cond
);
1127 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1129 begin_cond (&SWITCH_STMT_COND (r
));
1134 /* Finish the cond of a switch-statement. */
1137 finish_switch_cond (tree cond
, tree switch_stmt
)
1139 tree orig_type
= NULL
;
1141 if (check_no_cilk (cond
,
1142 "Cilk array notation cannot be used as a condition for switch statement",
1143 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement"))
1144 cond
= error_mark_node
;
1146 if (!processing_template_decl
)
1148 /* Convert the condition to an integer or enumeration type. */
1149 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1150 if (cond
== NULL_TREE
)
1152 error ("switch quantity not an integer");
1153 cond
= error_mark_node
;
1155 /* We want unlowered type here to handle enum bit-fields. */
1156 orig_type
= unlowered_expr_type (cond
);
1157 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1158 orig_type
= TREE_TYPE (cond
);
1159 if (cond
!= error_mark_node
)
1161 /* Warn if the condition has boolean value. */
1162 if (TREE_CODE (orig_type
) == BOOLEAN_TYPE
)
1163 warning_at (input_location
, OPT_Wswitch_bool
,
1164 "switch condition has type bool");
1168 Integral promotions are performed. */
1169 cond
= perform_integral_promotions (cond
);
1170 cond
= maybe_cleanup_point_expr (cond
);
1173 if (check_for_bare_parameter_packs (cond
))
1174 cond
= error_mark_node
;
1175 else if (!processing_template_decl
&& warn_sequence_point
)
1176 verify_sequence_points (cond
);
1178 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1179 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1180 add_stmt (switch_stmt
);
1181 push_switch (switch_stmt
);
1182 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1185 /* Finish the body of a switch-statement, which may be given by
1186 SWITCH_STMT. The COND to switch on is indicated. */
1189 finish_switch_stmt (tree switch_stmt
)
1193 SWITCH_STMT_BODY (switch_stmt
) =
1194 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1197 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1198 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1199 add_stmt (do_poplevel (scope
));
1202 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1206 begin_try_block (void)
1208 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1210 TRY_STMTS (r
) = push_stmt_list ();
1214 /* Likewise, for a function-try-block. The block returned in
1215 *COMPOUND_STMT is an artificial outer scope, containing the
1216 function-try-block. */
1219 begin_function_try_block (tree
*compound_stmt
)
1222 /* This outer scope does not exist in the C++ standard, but we need
1223 a place to put __FUNCTION__ and similar variables. */
1224 *compound_stmt
= begin_compound_stmt (0);
1225 r
= begin_try_block ();
1226 FN_TRY_BLOCK_P (r
) = 1;
1230 /* Finish a try-block, which may be given by TRY_BLOCK. */
1233 finish_try_block (tree try_block
)
1235 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1236 TRY_HANDLERS (try_block
) = push_stmt_list ();
1239 /* Finish the body of a cleanup try-block, which may be given by
1243 finish_cleanup_try_block (tree try_block
)
1245 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1248 /* Finish an implicitly generated try-block, with a cleanup is given
1252 finish_cleanup (tree cleanup
, tree try_block
)
1254 TRY_HANDLERS (try_block
) = cleanup
;
1255 CLEANUP_P (try_block
) = 1;
1258 /* Likewise, for a function-try-block. */
1261 finish_function_try_block (tree try_block
)
1263 finish_try_block (try_block
);
1264 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1265 the try block, but moving it inside. */
1266 in_function_try_handler
= 1;
1269 /* Finish a handler-sequence for a try-block, which may be given by
1273 finish_handler_sequence (tree try_block
)
1275 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1276 check_handlers (TRY_HANDLERS (try_block
));
1279 /* Finish the handler-seq for a function-try-block, given by
1280 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1281 begin_function_try_block. */
1284 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1286 in_function_try_handler
= 0;
1287 finish_handler_sequence (try_block
);
1288 finish_compound_stmt (compound_stmt
);
1291 /* Begin a handler. Returns a HANDLER if appropriate. */
1294 begin_handler (void)
1298 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1301 /* Create a binding level for the eh_info and the exception object
1303 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1308 /* Finish the handler-parameters for a handler, which may be given by
1309 HANDLER. DECL is the declaration for the catch parameter, or NULL
1310 if this is a `catch (...)' clause. */
1313 finish_handler_parms (tree decl
, tree handler
)
1315 tree type
= NULL_TREE
;
1316 if (processing_template_decl
)
1320 decl
= pushdecl (decl
);
1321 decl
= push_template_decl (decl
);
1322 HANDLER_PARMS (handler
) = decl
;
1323 type
= TREE_TYPE (decl
);
1327 type
= expand_start_catch_block (decl
);
1328 HANDLER_TYPE (handler
) = type
;
1331 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1332 the return value from the matching call to finish_handler_parms. */
1335 finish_handler (tree handler
)
1337 if (!processing_template_decl
)
1338 expand_end_catch_block ();
1339 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1342 /* Begin a compound statement. FLAGS contains some bits that control the
1343 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1344 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1345 block of a function. If BCS_TRY_BLOCK is set, this is the block
1346 created on behalf of a TRY statement. Returns a token to be passed to
1347 finish_compound_stmt. */
1350 begin_compound_stmt (unsigned int flags
)
1354 if (flags
& BCS_NO_SCOPE
)
1356 r
= push_stmt_list ();
1357 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1359 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1360 But, if it's a statement-expression with a scopeless block, there's
1361 nothing to keep, and we don't want to accidentally keep a block
1362 *inside* the scopeless block. */
1363 keep_next_level (false);
1366 r
= do_pushlevel (flags
& BCS_TRY_BLOCK
? sk_try
: sk_block
);
1368 /* When processing a template, we need to remember where the braces were,
1369 so that we can set up identical scopes when instantiating the template
1370 later. BIND_EXPR is a handy candidate for this.
1371 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1372 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1373 processing templates. */
1374 if (processing_template_decl
)
1376 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1377 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1378 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1379 TREE_SIDE_EFFECTS (r
) = 1;
1385 /* Finish a compound-statement, which is given by STMT. */
1388 finish_compound_stmt (tree stmt
)
1390 if (TREE_CODE (stmt
) == BIND_EXPR
)
1392 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1393 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1394 discard the BIND_EXPR so it can be merged with the containing
1396 if (TREE_CODE (body
) == STATEMENT_LIST
1397 && STATEMENT_LIST_HEAD (body
) == NULL
1398 && !BIND_EXPR_BODY_BLOCK (stmt
)
1399 && !BIND_EXPR_TRY_BLOCK (stmt
))
1402 BIND_EXPR_BODY (stmt
) = body
;
1404 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1405 stmt
= pop_stmt_list (stmt
);
1408 /* Destroy any ObjC "super" receivers that may have been
1410 objc_clear_super_receiver ();
1412 stmt
= do_poplevel (stmt
);
1415 /* ??? See c_end_compound_stmt wrt statement expressions. */
1419 /* Finish an asm-statement, whose components are a STRING, some
1420 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1421 LABELS. Also note whether the asm-statement should be
1422 considered volatile. */
1425 finish_asm_stmt (int volatile_p
, tree string
, tree output_operands
,
1426 tree input_operands
, tree clobbers
, tree labels
)
1430 int ninputs
= list_length (input_operands
);
1431 int noutputs
= list_length (output_operands
);
1433 if (!processing_template_decl
)
1435 const char *constraint
;
1436 const char **oconstraints
;
1437 bool allows_mem
, allows_reg
, is_inout
;
1441 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1443 string
= resolve_asm_operand_names (string
, output_operands
,
1444 input_operands
, labels
);
1446 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1448 operand
= TREE_VALUE (t
);
1450 /* ??? Really, this should not be here. Users should be using a
1451 proper lvalue, dammit. But there's a long history of using
1452 casts in the output operands. In cases like longlong.h, this
1453 becomes a primitive form of typechecking -- if the cast can be
1454 removed, then the output operand had a type of the proper width;
1455 otherwise we'll get an error. Gross, but ... */
1456 STRIP_NOPS (operand
);
1458 operand
= mark_lvalue_use (operand
);
1460 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1461 operand
= error_mark_node
;
1463 if (operand
!= error_mark_node
1464 && (TREE_READONLY (operand
)
1465 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1466 /* Functions are not modifiable, even though they are
1468 || TREE_CODE (TREE_TYPE (operand
)) == FUNCTION_TYPE
1469 || TREE_CODE (TREE_TYPE (operand
)) == METHOD_TYPE
1470 /* If it's an aggregate and any field is const, then it is
1471 effectively const. */
1472 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1473 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1474 cxx_readonly_error (operand
, lv_asm
);
1476 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1477 oconstraints
[i
] = constraint
;
1479 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1480 &allows_mem
, &allows_reg
, &is_inout
))
1482 /* If the operand is going to end up in memory,
1483 mark it addressable. */
1484 if (!allows_reg
&& !cxx_mark_addressable (operand
))
1485 operand
= error_mark_node
;
1488 operand
= error_mark_node
;
1490 TREE_VALUE (t
) = operand
;
1493 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1495 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1496 bool constraint_parsed
1497 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1498 oconstraints
, &allows_mem
, &allows_reg
);
1499 /* If the operand is going to end up in memory, don't call
1500 decay_conversion. */
1501 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1502 operand
= mark_lvalue_use (TREE_VALUE (t
));
1504 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1506 /* If the type of the operand hasn't been determined (e.g.,
1507 because it involves an overloaded function), then issue
1508 an error message. There's no context available to
1509 resolve the overloading. */
1510 if (TREE_TYPE (operand
) == unknown_type_node
)
1512 error ("type of asm operand %qE could not be determined",
1514 operand
= error_mark_node
;
1517 if (constraint_parsed
)
1519 /* If the operand is going to end up in memory,
1520 mark it addressable. */
1521 if (!allows_reg
&& allows_mem
)
1523 /* Strip the nops as we allow this case. FIXME, this really
1524 should be rejected or made deprecated. */
1525 STRIP_NOPS (operand
);
1526 if (!cxx_mark_addressable (operand
))
1527 operand
= error_mark_node
;
1529 else if (!allows_reg
&& !allows_mem
)
1531 /* If constraint allows neither register nor memory,
1532 try harder to get a constant. */
1533 tree constop
= maybe_constant_value (operand
);
1534 if (TREE_CONSTANT (constop
))
1539 operand
= error_mark_node
;
1541 TREE_VALUE (t
) = operand
;
1545 r
= build_stmt (input_location
, ASM_EXPR
, string
,
1546 output_operands
, input_operands
,
1548 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1549 r
= maybe_cleanup_point_expr_void (r
);
1550 return add_stmt (r
);
1553 /* Finish a label with the indicated NAME. Returns the new label. */
1556 finish_label_stmt (tree name
)
1558 tree decl
= define_label (input_location
, name
);
1560 if (decl
== error_mark_node
)
1561 return error_mark_node
;
1563 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1568 /* Finish a series of declarations for local labels. G++ allows users
1569 to declare "local" labels, i.e., labels with scope. This extension
1570 is useful when writing code involving statement-expressions. */
1573 finish_label_decl (tree name
)
1575 if (!at_function_scope_p ())
1577 error ("__label__ declarations are only allowed in function scopes");
1581 add_decl_expr (declare_local_label (name
));
1584 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1587 finish_decl_cleanup (tree decl
, tree cleanup
)
1589 push_cleanup (decl
, cleanup
, false);
1592 /* If the current scope exits with an exception, run CLEANUP. */
1595 finish_eh_cleanup (tree cleanup
)
1597 push_cleanup (NULL
, cleanup
, true);
1600 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1601 order they were written by the user. Each node is as for
1602 emit_mem_initializers. */
1605 finish_mem_initializers (tree mem_inits
)
1607 /* Reorder the MEM_INITS so that they are in the order they appeared
1608 in the source program. */
1609 mem_inits
= nreverse (mem_inits
);
1611 if (processing_template_decl
)
1615 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1617 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1618 check for bare parameter packs in the TREE_VALUE, because
1619 any parameter packs in the TREE_VALUE have already been
1620 bound as part of the TREE_PURPOSE. See
1621 make_pack_expansion for more information. */
1622 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1623 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1624 TREE_VALUE (mem
) = error_mark_node
;
1627 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1628 CTOR_INITIALIZER
, mem_inits
));
1631 emit_mem_initializers (mem_inits
);
1634 /* Obfuscate EXPR if it looks like an id-expression or member access so
1635 that the call to finish_decltype in do_auto_deduction will give the
1639 force_paren_expr (tree expr
)
1641 /* This is only needed for decltype(auto) in C++14. */
1642 if (cxx_dialect
< cxx14
)
1645 /* If we're in unevaluated context, we can't be deducing a
1646 return/initializer type, so we don't need to mess with this. */
1647 if (cp_unevaluated_operand
)
1650 if (!DECL_P (expr
) && TREE_CODE (expr
) != COMPONENT_REF
1651 && TREE_CODE (expr
) != SCOPE_REF
)
1654 if (TREE_CODE (expr
) == COMPONENT_REF
)
1655 REF_PARENTHESIZED_P (expr
) = true;
1656 else if (type_dependent_expression_p (expr
))
1657 expr
= build1 (PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1660 cp_lvalue_kind kind
= lvalue_kind (expr
);
1661 if ((kind
& ~clk_class
) != clk_none
)
1663 tree type
= unlowered_expr_type (expr
);
1664 bool rval
= !!(kind
& clk_rvalueref
);
1665 type
= cp_build_reference_type (type
, rval
);
1666 /* This inhibits warnings in, eg, cxx_mark_addressable
1668 warning_sentinel
s (extra_warnings
);
1669 expr
= build_static_cast (type
, expr
, tf_error
);
1670 if (expr
!= error_mark_node
)
1671 REF_PARENTHESIZED_P (expr
) = true;
1678 /* Finish a parenthesized expression EXPR. */
1681 finish_parenthesized_expr (tree expr
)
1684 /* This inhibits warnings in c_common_truthvalue_conversion. */
1685 TREE_NO_WARNING (expr
) = 1;
1687 if (TREE_CODE (expr
) == OFFSET_REF
1688 || TREE_CODE (expr
) == SCOPE_REF
)
1689 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1690 enclosed in parentheses. */
1691 PTRMEM_OK_P (expr
) = 0;
1693 if (TREE_CODE (expr
) == STRING_CST
)
1694 PAREN_STRING_LITERAL_P (expr
) = 1;
1696 expr
= force_paren_expr (expr
);
1701 /* Finish a reference to a non-static data member (DECL) that is not
1702 preceded by `.' or `->'. */
1705 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1707 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1711 tree scope
= qualifying_scope
;
1712 if (scope
== NULL_TREE
)
1713 scope
= context_for_name_lookup (decl
);
1714 object
= maybe_dummy_object (scope
, NULL
);
1717 object
= maybe_resolve_dummy (object
, true);
1718 if (object
== error_mark_node
)
1719 return error_mark_node
;
1721 /* DR 613/850: Can use non-static data members without an associated
1722 object in sizeof/decltype/alignof. */
1723 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
1724 && (!processing_template_decl
|| !current_class_ref
))
1726 if (current_function_decl
1727 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1728 error ("invalid use of member %qD in static member function", decl
);
1730 error ("invalid use of non-static data member %qD", decl
);
1731 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
1733 return error_mark_node
;
1736 if (current_class_ptr
)
1737 TREE_USED (current_class_ptr
) = 1;
1738 if (processing_template_decl
&& !qualifying_scope
)
1740 tree type
= TREE_TYPE (decl
);
1742 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1743 /* Quals on the object don't matter. */;
1744 else if (PACK_EXPANSION_P (type
))
1745 /* Don't bother trying to represent this. */
1749 /* Set the cv qualifiers. */
1750 int quals
= cp_type_quals (TREE_TYPE (object
));
1752 if (DECL_MUTABLE_P (decl
))
1753 quals
&= ~TYPE_QUAL_CONST
;
1755 quals
|= cp_type_quals (TREE_TYPE (decl
));
1756 type
= cp_build_qualified_type (type
, quals
);
1759 return (convert_from_reference
1760 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
1762 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1763 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1765 else if (processing_template_decl
)
1766 return build_qualified_name (TREE_TYPE (decl
),
1769 /*template_p=*/false);
1772 tree access_type
= TREE_TYPE (object
);
1774 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
1775 decl
, tf_warning_or_error
);
1777 /* If the data member was named `C::M', convert `*this' to `C'
1779 if (qualifying_scope
)
1781 tree binfo
= NULL_TREE
;
1782 object
= build_scoped_ref (object
, qualifying_scope
,
1786 return build_class_member_access_expr (object
, decl
,
1787 /*access_path=*/NULL_TREE
,
1788 /*preserve_reference=*/false,
1789 tf_warning_or_error
);
1793 /* If we are currently parsing a template and we encountered a typedef
1794 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1795 adds the typedef to a list tied to the current template.
1796 At template instantiation time, that list is walked and access check
1797 performed for each typedef.
1798 LOCATION is the location of the usage point of TYPEDEF_DECL. */
1801 add_typedef_to_current_template_for_access_check (tree typedef_decl
,
1803 location_t location
)
1805 tree template_info
= NULL
;
1806 tree cs
= current_scope ();
1808 if (!is_typedef_decl (typedef_decl
)
1810 || !CLASS_TYPE_P (context
)
1814 if (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
)
1815 template_info
= get_template_info (cs
);
1818 && TI_TEMPLATE (template_info
)
1819 && !currently_open_class (context
))
1820 append_type_to_template_for_access_check (cs
, typedef_decl
,
1824 /* DECL was the declaration to which a qualified-id resolved. Issue
1825 an error message if it is not accessible. If OBJECT_TYPE is
1826 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1827 type of `*x', or `x', respectively. If the DECL was named as
1828 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1831 check_accessibility_of_qualified_id (tree decl
,
1833 tree nested_name_specifier
)
1836 tree qualifying_type
= NULL_TREE
;
1838 /* If we are parsing a template declaration and if decl is a typedef,
1839 add it to a list tied to the template.
1840 At template instantiation time, that list will be walked and
1841 access check performed. */
1842 add_typedef_to_current_template_for_access_check (decl
,
1843 nested_name_specifier
1844 ? nested_name_specifier
1845 : DECL_CONTEXT (decl
),
1848 /* If we're not checking, return immediately. */
1849 if (deferred_access_no_check
)
1852 /* Determine the SCOPE of DECL. */
1853 scope
= context_for_name_lookup (decl
);
1854 /* If the SCOPE is not a type, then DECL is not a member. */
1855 if (!TYPE_P (scope
))
1857 /* Compute the scope through which DECL is being accessed. */
1859 /* OBJECT_TYPE might not be a class type; consider:
1861 class A { typedef int I; };
1865 In this case, we will have "A::I" as the DECL, but "I" as the
1867 && CLASS_TYPE_P (object_type
)
1868 && DERIVED_FROM_P (scope
, object_type
))
1869 /* If we are processing a `->' or `.' expression, use the type of the
1871 qualifying_type
= object_type
;
1872 else if (nested_name_specifier
)
1874 /* If the reference is to a non-static member of the
1875 current class, treat it as if it were referenced through
1878 if (DECL_NONSTATIC_MEMBER_P (decl
)
1879 && current_class_ptr
1880 && DERIVED_FROM_P (scope
, ct
= current_nonlambda_class_type ()))
1881 qualifying_type
= ct
;
1882 /* Otherwise, use the type indicated by the
1883 nested-name-specifier. */
1885 qualifying_type
= nested_name_specifier
;
1888 /* Otherwise, the name must be from the current class or one of
1890 qualifying_type
= currently_open_derived_class (scope
);
1893 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
1894 or similar in a default argument value. */
1895 && CLASS_TYPE_P (qualifying_type
)
1896 && !dependent_type_p (qualifying_type
))
1897 perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
1898 decl
, tf_warning_or_error
);
1901 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
1902 class named to the left of the "::" operator. DONE is true if this
1903 expression is a complete postfix-expression; it is false if this
1904 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
1905 iff this expression is the operand of '&'. TEMPLATE_P is true iff
1906 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
1907 is true iff this qualified name appears as a template argument. */
1910 finish_qualified_id_expr (tree qualifying_class
,
1915 bool template_arg_p
,
1916 tsubst_flags_t complain
)
1918 gcc_assert (TYPE_P (qualifying_class
));
1920 if (error_operand_p (expr
))
1921 return error_mark_node
;
1923 if ((DECL_P (expr
) || BASELINK_P (expr
))
1924 && !mark_used (expr
, complain
))
1925 return error_mark_node
;
1928 check_template_keyword (expr
);
1930 /* If EXPR occurs as the operand of '&', use special handling that
1931 permits a pointer-to-member. */
1932 if (address_p
&& done
)
1934 if (TREE_CODE (expr
) == SCOPE_REF
)
1935 expr
= TREE_OPERAND (expr
, 1);
1936 expr
= build_offset_ref (qualifying_class
, expr
,
1937 /*address_p=*/true, complain
);
1941 /* No need to check access within an enum. */
1942 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
)
1945 /* Within the scope of a class, turn references to non-static
1946 members into expression of the form "this->...". */
1948 /* But, within a template argument, we do not want make the
1949 transformation, as there is no "this" pointer. */
1951 else if (TREE_CODE (expr
) == FIELD_DECL
)
1953 push_deferring_access_checks (dk_no_check
);
1954 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
1956 pop_deferring_access_checks ();
1958 else if (BASELINK_P (expr
) && !processing_template_decl
)
1960 /* See if any of the functions are non-static members. */
1961 /* If so, the expression may be relative to 'this'. */
1962 if (!shared_member_p (expr
)
1963 && current_class_ptr
1964 && DERIVED_FROM_P (qualifying_class
,
1965 current_nonlambda_class_type ()))
1966 expr
= (build_class_member_access_expr
1967 (maybe_dummy_object (qualifying_class
, NULL
),
1969 BASELINK_ACCESS_BINFO (expr
),
1970 /*preserve_reference=*/false,
1973 /* The expression is a qualified name whose address is not
1975 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
1978 else if (BASELINK_P (expr
))
1982 /* In a template, return a SCOPE_REF for most qualified-ids
1983 so that we can check access at instantiation time. But if
1984 we're looking at a member of the current instantiation, we
1985 know we have access and building up the SCOPE_REF confuses
1986 non-type template argument handling. */
1987 if (processing_template_decl
1988 && !currently_open_class (qualifying_class
))
1989 expr
= build_qualified_name (TREE_TYPE (expr
),
1990 qualifying_class
, expr
,
1993 expr
= convert_from_reference (expr
);
1999 /* Begin a statement-expression. The value returned must be passed to
2000 finish_stmt_expr. */
2003 begin_stmt_expr (void)
2005 return push_stmt_list ();
2008 /* Process the final expression of a statement expression. EXPR can be
2009 NULL, if the final expression is empty. Return a STATEMENT_LIST
2010 containing all the statements in the statement-expression, or
2011 ERROR_MARK_NODE if there was an error. */
2014 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2016 if (error_operand_p (expr
))
2018 /* The type of the statement-expression is the type of the last
2020 TREE_TYPE (stmt_expr
) = error_mark_node
;
2021 return error_mark_node
;
2024 /* If the last statement does not have "void" type, then the value
2025 of the last statement is the value of the entire expression. */
2028 tree type
= TREE_TYPE (expr
);
2030 if (processing_template_decl
)
2032 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2033 expr
= add_stmt (expr
);
2034 /* Mark the last statement so that we can recognize it as such at
2035 template-instantiation time. */
2036 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2038 else if (VOID_TYPE_P (type
))
2040 /* Just treat this like an ordinary statement. */
2041 expr
= finish_expr_stmt (expr
);
2045 /* It actually has a value we need to deal with. First, force it
2046 to be an rvalue so that we won't need to build up a copy
2047 constructor call later when we try to assign it to something. */
2048 expr
= force_rvalue (expr
, tf_warning_or_error
);
2049 if (error_operand_p (expr
))
2050 return error_mark_node
;
2052 /* Update for array-to-pointer decay. */
2053 type
= TREE_TYPE (expr
);
2055 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2056 normal statement, but don't convert to void or actually add
2058 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2059 expr
= maybe_cleanup_point_expr (expr
);
2063 /* The type of the statement-expression is the type of the last
2065 TREE_TYPE (stmt_expr
) = type
;
2071 /* Finish a statement-expression. EXPR should be the value returned
2072 by the previous begin_stmt_expr. Returns an expression
2073 representing the statement-expression. */
2076 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2081 if (error_operand_p (stmt_expr
))
2083 pop_stmt_list (stmt_expr
);
2084 return error_mark_node
;
2087 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2089 type
= TREE_TYPE (stmt_expr
);
2090 result
= pop_stmt_list (stmt_expr
);
2091 TREE_TYPE (result
) = type
;
2093 if (processing_template_decl
)
2095 result
= build_min (STMT_EXPR
, type
, result
);
2096 TREE_SIDE_EFFECTS (result
) = 1;
2097 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2099 else if (CLASS_TYPE_P (type
))
2101 /* Wrap the statement-expression in a TARGET_EXPR so that the
2102 temporary object created by the final expression is destroyed at
2103 the end of the full-expression containing the
2104 statement-expression. */
2105 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2111 /* Returns the expression which provides the value of STMT_EXPR. */
2114 stmt_expr_value_expr (tree stmt_expr
)
2116 tree t
= STMT_EXPR_STMT (stmt_expr
);
2118 if (TREE_CODE (t
) == BIND_EXPR
)
2119 t
= BIND_EXPR_BODY (t
);
2121 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2122 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2124 if (TREE_CODE (t
) == EXPR_STMT
)
2125 t
= EXPR_STMT_EXPR (t
);
2130 /* Return TRUE iff EXPR_STMT is an empty list of
2131 expression statements. */
2134 empty_expr_stmt_p (tree expr_stmt
)
2136 tree body
= NULL_TREE
;
2138 if (expr_stmt
== void_node
)
2143 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2144 body
= EXPR_STMT_EXPR (expr_stmt
);
2145 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2151 if (TREE_CODE (body
) == STATEMENT_LIST
)
2152 return tsi_end_p (tsi_start (body
));
2154 return empty_expr_stmt_p (body
);
2159 /* Perform Koenig lookup. FN is the postfix-expression representing
2160 the function (or functions) to call; ARGS are the arguments to the
2161 call. Returns the functions to be considered by overload resolution. */
2164 perform_koenig_lookup (tree fn
, vec
<tree
, va_gc
> *args
,
2165 tsubst_flags_t complain
)
2167 tree identifier
= NULL_TREE
;
2168 tree functions
= NULL_TREE
;
2169 tree tmpl_args
= NULL_TREE
;
2170 bool template_id
= false;
2172 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2174 /* Use a separate flag to handle null args. */
2176 tmpl_args
= TREE_OPERAND (fn
, 1);
2177 fn
= TREE_OPERAND (fn
, 0);
2180 /* Find the name of the overloaded function. */
2181 if (identifier_p (fn
))
2183 else if (is_overloaded_fn (fn
))
2186 identifier
= DECL_NAME (get_first_fn (functions
));
2188 else if (DECL_P (fn
))
2191 identifier
= DECL_NAME (fn
);
2194 /* A call to a namespace-scope function using an unqualified name.
2196 Do Koenig lookup -- unless any of the arguments are
2198 if (!any_type_dependent_arguments_p (args
)
2199 && !any_dependent_template_arguments_p (tmpl_args
))
2201 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2204 /* The unqualified name could not be resolved. */
2206 fn
= unqualified_fn_lookup_error (identifier
);
2212 if (fn
&& template_id
)
2213 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2218 /* Generate an expression for `FN (ARGS)'. This may change the
2221 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2222 as a virtual call, even if FN is virtual. (This flag is set when
2223 encountering an expression where the function name is explicitly
2224 qualified. For example a call to `X::f' never generates a virtual
2227 Returns code for the call. */
2230 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2231 bool koenig_p
, tsubst_flags_t complain
)
2235 vec
<tree
, va_gc
> *orig_args
= NULL
;
2237 if (fn
== error_mark_node
)
2238 return error_mark_node
;
2240 gcc_assert (!TYPE_P (fn
));
2244 if (processing_template_decl
)
2246 /* If the call expression is dependent, build a CALL_EXPR node
2247 with no type; type_dependent_expression_p recognizes
2248 expressions with no type as being dependent. */
2249 if (type_dependent_expression_p (fn
)
2250 || any_type_dependent_arguments_p (*args
)
2251 /* For a non-static member function that doesn't have an
2252 explicit object argument, we need to specifically
2253 test the type dependency of the "this" pointer because it
2254 is not included in *ARGS even though it is considered to
2255 be part of the list of arguments. Note that this is
2256 related to CWG issues 515 and 1005. */
2257 || (TREE_CODE (fn
) != COMPONENT_REF
2258 && non_static_member_function_p (fn
)
2259 && current_class_ref
2260 && type_dependent_expression_p (current_class_ref
)))
2262 result
= build_nt_call_vec (fn
, *args
);
2263 SET_EXPR_LOCATION (result
, EXPR_LOC_OR_LOC (fn
, input_location
));
2264 KOENIG_LOOKUP_P (result
) = koenig_p
;
2269 tree fndecl
= OVL_CURRENT (fn
);
2270 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2271 || !TREE_THIS_VOLATILE (fndecl
))
2277 current_function_returns_abnormally
= 1;
2281 orig_args
= make_tree_vector_copy (*args
);
2282 if (!BASELINK_P (fn
)
2283 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2284 && TREE_TYPE (fn
) != unknown_type_node
)
2285 fn
= build_non_dependent_expr (fn
);
2286 make_args_non_dependent (*args
);
2289 if (TREE_CODE (fn
) == COMPONENT_REF
)
2291 tree member
= TREE_OPERAND (fn
, 1);
2292 if (BASELINK_P (member
))
2294 tree object
= TREE_OPERAND (fn
, 0);
2295 return build_new_method_call (object
, member
,
2298 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2305 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2306 if (TREE_CODE (fn
) == ADDR_EXPR
2307 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2308 fn
= TREE_OPERAND (fn
, 0);
2310 if (is_overloaded_fn (fn
))
2311 fn
= baselink_for_fns (fn
);
2314 if (BASELINK_P (fn
))
2318 /* A call to a member function. From [over.call.func]:
2320 If the keyword this is in scope and refers to the class of
2321 that member function, or a derived class thereof, then the
2322 function call is transformed into a qualified function call
2323 using (*this) as the postfix-expression to the left of the
2324 . operator.... [Otherwise] a contrived object of type T
2325 becomes the implied object argument.
2329 struct A { void f(); };
2330 struct B : public A {};
2331 struct C : public A { void g() { B::f(); }};
2333 "the class of that member function" refers to `A'. But 11.2
2334 [class.access.base] says that we need to convert 'this' to B* as
2335 part of the access, so we pass 'B' to maybe_dummy_object. */
2337 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2340 if (processing_template_decl
)
2342 if (type_dependent_expression_p (object
))
2344 tree ret
= build_nt_call_vec (orig_fn
, orig_args
);
2345 release_tree_vector (orig_args
);
2348 object
= build_non_dependent_expr (object
);
2351 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2353 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2358 else if (is_overloaded_fn (fn
))
2360 /* If the function is an overloaded builtin, resolve it. */
2361 if (TREE_CODE (fn
) == FUNCTION_DECL
2362 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2363 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2364 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2368 if (warn_sizeof_pointer_memaccess
2369 && (complain
& tf_warning
)
2370 && !vec_safe_is_empty (*args
)
2371 && !processing_template_decl
)
2373 location_t sizeof_arg_loc
[3];
2376 for (i
= 0; i
< 3; i
++)
2380 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2381 sizeof_arg
[i
] = NULL_TREE
;
2382 if (i
>= (*args
)->length ())
2385 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2387 if (SIZEOF_EXPR_TYPE_P (t
))
2388 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2390 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2391 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2393 sizeof_pointer_memaccess_warning
2394 (sizeof_arg_loc
, fn
, *args
,
2395 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2398 /* A call to a namespace-scope function. */
2399 result
= build_new_function_call (fn
, args
, koenig_p
, complain
);
2402 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2404 if (!vec_safe_is_empty (*args
))
2405 error ("arguments to destructor are not allowed");
2406 /* Mark the pseudo-destructor call as having side-effects so
2407 that we do not issue warnings about its use. */
2408 result
= build1 (NOP_EXPR
,
2410 TREE_OPERAND (fn
, 0));
2411 TREE_SIDE_EFFECTS (result
) = 1;
2413 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2414 /* If the "function" is really an object of class type, it might
2415 have an overloaded `operator ()'. */
2416 result
= build_op_call (fn
, args
, complain
);
2419 /* A call where the function is unknown. */
2420 result
= cp_build_function_call_vec (fn
, args
, complain
);
2422 if (processing_template_decl
&& result
!= error_mark_node
)
2424 if (INDIRECT_REF_P (result
))
2425 result
= TREE_OPERAND (result
, 0);
2426 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2427 SET_EXPR_LOCATION (result
, input_location
);
2428 KOENIG_LOOKUP_P (result
) = koenig_p
;
2429 release_tree_vector (orig_args
);
2430 result
= convert_from_reference (result
);
2435 /* Free garbage OVERLOADs from arg-dependent lookup. */
2436 tree next
= NULL_TREE
;
2438 fn
&& TREE_CODE (fn
) == OVERLOAD
&& OVL_ARG_DEPENDENT (fn
);
2441 if (processing_template_decl
)
2442 /* In a template, we'll re-use them at instantiation time. */
2443 OVL_ARG_DEPENDENT (fn
) = false;
2446 next
= OVL_CHAIN (fn
);
2455 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2456 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2457 POSTDECREMENT_EXPR.) */
2460 finish_increment_expr (tree expr
, enum tree_code code
)
2462 return build_x_unary_op (input_location
, code
, expr
, tf_warning_or_error
);
2465 /* Finish a use of `this'. Returns an expression for `this'. */
2468 finish_this_expr (void)
2470 tree result
= NULL_TREE
;
2472 if (current_class_ptr
)
2474 tree type
= TREE_TYPE (current_class_ref
);
2476 /* In a lambda expression, 'this' refers to the captured 'this'. */
2477 if (LAMBDA_TYPE_P (type
))
2478 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2480 result
= current_class_ptr
;
2484 /* The keyword 'this' is a prvalue expression. */
2485 return rvalue (result
);
2487 tree fn
= current_nonlambda_function ();
2488 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2489 error ("%<this%> is unavailable for static member functions");
2491 error ("invalid use of %<this%> in non-member function");
2493 error ("invalid use of %<this%> at top level");
2494 return error_mark_node
;
2497 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2498 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2499 the TYPE for the type given. If SCOPE is non-NULL, the expression
2500 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2503 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2506 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2507 return error_mark_node
;
2509 gcc_assert (TYPE_P (destructor
));
2511 if (!processing_template_decl
)
2513 if (scope
== error_mark_node
)
2515 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2516 return error_mark_node
;
2518 if (is_auto (destructor
))
2519 destructor
= TREE_TYPE (object
);
2520 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2523 "qualified type %qT does not match destructor name ~%qT",
2525 return error_mark_node
;
2529 /* [expr.pseudo] says both:
2531 The type designated by the pseudo-destructor-name shall be
2532 the same as the object type.
2536 The cv-unqualified versions of the object type and of the
2537 type designated by the pseudo-destructor-name shall be the
2540 We implement the more generous second sentence, since that is
2541 what most other compilers do. */
2542 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2545 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2546 return error_mark_node
;
2550 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, void_type_node
, object
,
2554 /* Finish an expression of the form CODE EXPR. */
2557 finish_unary_op_expr (location_t loc
, enum tree_code code
, tree expr
,
2558 tsubst_flags_t complain
)
2560 tree result
= build_x_unary_op (loc
, code
, expr
, complain
);
2561 if ((complain
& tf_warning
)
2562 && TREE_OVERFLOW_P (result
) && !TREE_OVERFLOW_P (expr
))
2563 overflow_warning (input_location
, result
);
2568 /* Finish a compound-literal expression. TYPE is the type to which
2569 the CONSTRUCTOR in COMPOUND_LITERAL is being cast. */
2572 finish_compound_literal (tree type
, tree compound_literal
,
2573 tsubst_flags_t complain
)
2575 if (type
== error_mark_node
)
2576 return error_mark_node
;
2578 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2581 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2583 return cp_build_c_cast (type
, compound_literal
, complain
);
2586 if (!TYPE_OBJ_P (type
))
2588 if (complain
& tf_error
)
2589 error ("compound literal of non-object type %qT", type
);
2590 return error_mark_node
;
2593 if (processing_template_decl
)
2595 TREE_TYPE (compound_literal
) = type
;
2596 /* Mark the expression as a compound literal. */
2597 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
2598 return compound_literal
;
2601 type
= complete_type (type
);
2603 if (TYPE_NON_AGGREGATE_CLASS (type
))
2605 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2606 everywhere that deals with function arguments would be a pain, so
2607 just wrap it in a TREE_LIST. The parser set a flag so we know
2608 that it came from T{} rather than T({}). */
2609 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2610 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2611 return build_functional_cast (type
, compound_literal
, complain
);
2614 if (TREE_CODE (type
) == ARRAY_TYPE
2615 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2616 return error_mark_node
;
2617 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2618 if (SCALAR_TYPE_P (type
)
2619 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
)
2620 && !check_narrowing (type
, compound_literal
, complain
))
2621 return error_mark_node
;
2622 if (TREE_CODE (type
) == ARRAY_TYPE
2623 && TYPE_DOMAIN (type
) == NULL_TREE
)
2625 cp_complete_array_type_or_error (&type
, compound_literal
,
2627 if (type
== error_mark_node
)
2628 return error_mark_node
;
2630 compound_literal
= digest_init (type
, compound_literal
, complain
);
2631 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
2632 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
2633 /* Put static/constant array temporaries in static variables, but always
2634 represent class temporaries with TARGET_EXPR so we elide copies. */
2635 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
2636 && TREE_CODE (type
) == ARRAY_TYPE
2637 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
2638 && initializer_constant_valid_p (compound_literal
, type
))
2640 tree decl
= create_temporary_var (type
);
2641 DECL_INITIAL (decl
) = compound_literal
;
2642 TREE_STATIC (decl
) = 1;
2643 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
2645 /* 5.19 says that a constant expression can include an
2646 lvalue-rvalue conversion applied to "a glvalue of literal type
2647 that refers to a non-volatile temporary object initialized
2648 with a constant expression". Rather than try to communicate
2649 that this VAR_DECL is a temporary, just mark it constexpr. */
2650 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
2651 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
2652 TREE_CONSTANT (decl
) = true;
2654 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
2655 decl
= pushdecl_top_level (decl
);
2656 DECL_NAME (decl
) = make_anon_name ();
2657 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
2658 /* Make sure the destructor is callable. */
2659 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
2660 if (clean
== error_mark_node
)
2661 return error_mark_node
;
2665 return get_target_expr_sfinae (compound_literal
, complain
);
2668 /* Return the declaration for the function-name variable indicated by
2672 finish_fname (tree id
)
2676 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
2677 if (processing_template_decl
&& current_function_decl
2678 && decl
!= error_mark_node
)
2679 decl
= DECL_NAME (decl
);
2683 /* Finish a translation unit. */
2686 finish_translation_unit (void)
2688 /* In case there were missing closebraces,
2689 get us back to the global binding level. */
2691 while (current_namespace
!= global_namespace
)
2694 /* Do file scope __FUNCTION__ et al. */
2695 finish_fname_decls ();
2698 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2699 Returns the parameter. */
2702 finish_template_type_parm (tree aggr
, tree identifier
)
2704 if (aggr
!= class_type_node
)
2706 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
2707 aggr
= class_type_node
;
2710 return build_tree_list (aggr
, identifier
);
2713 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2714 Returns the parameter. */
2717 finish_template_template_parm (tree aggr
, tree identifier
)
2719 tree decl
= build_decl (input_location
,
2720 TYPE_DECL
, identifier
, NULL_TREE
);
2721 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
2722 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
2723 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
2724 DECL_ARTIFICIAL (decl
) = 1;
2725 end_template_decl ();
2727 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
2729 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
2730 /*is_primary=*/true, /*is_partial=*/false,
2733 return finish_template_type_parm (aggr
, tmpl
);
2736 /* ARGUMENT is the default-argument value for a template template
2737 parameter. If ARGUMENT is invalid, issue error messages and return
2738 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2741 check_template_template_default_arg (tree argument
)
2743 if (TREE_CODE (argument
) != TEMPLATE_DECL
2744 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
2745 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
2747 if (TREE_CODE (argument
) == TYPE_DECL
)
2748 error ("invalid use of type %qT as a default value for a template "
2749 "template-parameter", TREE_TYPE (argument
));
2751 error ("invalid default argument for a template template parameter");
2752 return error_mark_node
;
2758 /* Begin a class definition, as indicated by T. */
2761 begin_class_definition (tree t
)
2763 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
2764 return error_mark_node
;
2766 if (processing_template_parmlist
)
2768 error ("definition of %q#T inside template parameter list", t
);
2769 return error_mark_node
;
2772 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
2773 are passed the same as decimal scalar types. */
2774 if (TREE_CODE (t
) == RECORD_TYPE
2775 && !processing_template_decl
)
2777 tree ns
= TYPE_CONTEXT (t
);
2778 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
2779 && DECL_CONTEXT (ns
) == std_node
2781 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns
)), "decimal"))
2783 const char *n
= TYPE_NAME_STRING (t
);
2784 if ((strcmp (n
, "decimal32") == 0)
2785 || (strcmp (n
, "decimal64") == 0)
2786 || (strcmp (n
, "decimal128") == 0))
2787 TYPE_TRANSPARENT_AGGR (t
) = 1;
2791 /* A non-implicit typename comes from code like:
2793 template <typename T> struct A {
2794 template <typename U> struct A<T>::B ...
2796 This is erroneous. */
2797 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
2799 error ("invalid definition of qualified type %qT", t
);
2800 t
= error_mark_node
;
2803 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
2805 t
= make_class_type (RECORD_TYPE
);
2806 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
2809 if (TYPE_BEING_DEFINED (t
))
2811 t
= make_class_type (TREE_CODE (t
));
2812 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
2814 maybe_process_partial_specialization (t
);
2816 TYPE_BEING_DEFINED (t
) = 1;
2817 class_binding_level
->defining_class_p
= 1;
2819 if (flag_pack_struct
)
2822 TYPE_PACKED (t
) = 1;
2823 /* Even though the type is being defined for the first time
2824 here, there might have been a forward declaration, so there
2825 might be cv-qualified variants of T. */
2826 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
2827 TYPE_PACKED (v
) = 1;
2829 /* Reset the interface data, at the earliest possible
2830 moment, as it might have been set via a class foo;
2832 if (! TYPE_ANONYMOUS_P (t
))
2834 struct c_fileinfo
*finfo
= \
2835 get_fileinfo (LOCATION_FILE (input_location
));
2836 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
2837 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2838 (t
, finfo
->interface_unknown
);
2840 reset_specialization();
2842 /* Make a declaration for this class in its own scope. */
2843 build_self_reference ();
2848 /* Finish the member declaration given by DECL. */
2851 finish_member_declaration (tree decl
)
2853 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
2856 if (decl
== void_type_node
)
2857 /* The COMPONENT was a friend, not a member, and so there's
2858 nothing for us to do. */
2861 /* We should see only one DECL at a time. */
2862 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
2864 /* Set up access control for DECL. */
2866 = (current_access_specifier
== access_private_node
);
2867 TREE_PROTECTED (decl
)
2868 = (current_access_specifier
== access_protected_node
);
2869 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
2871 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
2872 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
2875 /* Mark the DECL as a member of the current class, unless it's
2876 a member of an enumeration. */
2877 if (TREE_CODE (decl
) != CONST_DECL
)
2878 DECL_CONTEXT (decl
) = current_class_type
;
2880 /* Check for bare parameter packs in the member variable declaration. */
2881 if (TREE_CODE (decl
) == FIELD_DECL
)
2883 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
2884 TREE_TYPE (decl
) = error_mark_node
;
2885 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
2886 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
2891 A C language linkage is ignored for the names of class members
2892 and the member function type of class member functions. */
2893 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
2894 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
2896 /* Put functions on the TYPE_METHODS list and everything else on the
2897 TYPE_FIELDS list. Note that these are built up in reverse order.
2898 We reverse them (to obtain declaration order) in finish_struct. */
2899 if (DECL_DECLARES_FUNCTION_P (decl
))
2901 /* We also need to add this function to the
2902 CLASSTYPE_METHOD_VEC. */
2903 if (add_method (current_class_type
, decl
, NULL_TREE
))
2905 gcc_assert (TYPE_MAIN_VARIANT (current_class_type
) == current_class_type
);
2906 DECL_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
2907 TYPE_METHODS (current_class_type
) = decl
;
2909 maybe_add_class_template_decl_list (current_class_type
, decl
,
2913 /* Enter the DECL into the scope of the class, if the class
2914 isn't a closure (whose fields are supposed to be unnamed). */
2915 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
2916 || pushdecl_class_level (decl
))
2918 if (TREE_CODE (decl
) == USING_DECL
)
2920 /* For now, ignore class-scope USING_DECLS, so that
2921 debugging backends do not see them. */
2922 DECL_IGNORED_P (decl
) = 1;
2925 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2926 go at the beginning. The reason is that lookup_field_1
2927 searches the list in order, and we want a field name to
2928 override a type name so that the "struct stat hack" will
2929 work. In particular:
2931 struct S { enum E { }; int E } s;
2934 is valid. In addition, the FIELD_DECLs must be maintained in
2935 declaration order so that class layout works as expected.
2936 However, we don't need that order until class layout, so we
2937 save a little time by putting FIELD_DECLs on in reverse order
2938 here, and then reversing them in finish_struct_1. (We could
2939 also keep a pointer to the correct insertion points in the
2942 if (TREE_CODE (decl
) == TYPE_DECL
)
2943 TYPE_FIELDS (current_class_type
)
2944 = chainon (TYPE_FIELDS (current_class_type
), decl
);
2947 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
2948 TYPE_FIELDS (current_class_type
) = decl
;
2951 maybe_add_class_template_decl_list (current_class_type
, decl
,
2956 note_decl_for_pch (decl
);
2959 /* DECL has been declared while we are building a PCH file. Perform
2960 actions that we might normally undertake lazily, but which can be
2961 performed now so that they do not have to be performed in
2962 translation units which include the PCH file. */
2965 note_decl_for_pch (tree decl
)
2967 gcc_assert (pch_file
);
2969 /* There's a good chance that we'll have to mangle names at some
2970 point, even if only for emission in debugging information. */
2971 if (VAR_OR_FUNCTION_DECL_P (decl
)
2972 && !processing_template_decl
)
2976 /* Finish processing a complete template declaration. The PARMS are
2977 the template parameters. */
2980 finish_template_decl (tree parms
)
2983 end_template_decl ();
2985 end_specialization ();
2988 /* Finish processing a template-id (which names a type) of the form
2989 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2990 template-id. If ENTERING_SCOPE is nonzero we are about to enter
2991 the scope of template-id indicated. */
2994 finish_template_type (tree name
, tree args
, int entering_scope
)
2998 type
= lookup_template_class (name
, args
,
2999 NULL_TREE
, NULL_TREE
, entering_scope
,
3000 tf_warning_or_error
| tf_user
);
3001 if (type
== error_mark_node
)
3003 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3004 return TYPE_STUB_DECL (type
);
3006 return TYPE_NAME (type
);
3009 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3010 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3011 BASE_CLASS, or NULL_TREE if an error occurred. The
3012 ACCESS_SPECIFIER is one of
3013 access_{default,public,protected_private}_node. For a virtual base
3014 we set TREE_TYPE. */
3017 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3021 if (base
== error_mark_node
)
3023 error ("invalid base-class specification");
3026 else if (! MAYBE_CLASS_TYPE_P (base
))
3028 error ("%qT is not a class type", base
);
3033 if (cp_type_quals (base
) != 0)
3035 /* DR 484: Can a base-specifier name a cv-qualified
3037 base
= TYPE_MAIN_VARIANT (base
);
3039 result
= build_tree_list (access
, base
);
3041 TREE_TYPE (result
) = integer_type_node
;
3047 /* If FNS is a member function, a set of member functions, or a
3048 template-id referring to one or more member functions, return a
3049 BASELINK for FNS, incorporating the current access context.
3050 Otherwise, return FNS unchanged. */
3053 baselink_for_fns (tree fns
)
3058 if (BASELINK_P (fns
)
3059 || error_operand_p (fns
))
3062 scope
= ovl_scope (fns
);
3063 if (!CLASS_TYPE_P (scope
))
3066 cl
= currently_open_derived_class (scope
);
3069 cl
= TYPE_BINFO (cl
);
3070 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3073 /* Returns true iff DECL is a variable from a function outside
3077 outer_var_p (tree decl
)
3079 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3080 && DECL_FUNCTION_SCOPE_P (decl
)
3081 && (DECL_CONTEXT (decl
) != current_function_decl
3082 || parsing_nsdmi ()));
3085 /* As above, but also checks that DECL is automatic. */
3088 outer_automatic_var_p (tree decl
)
3090 return (outer_var_p (decl
)
3091 && !TREE_STATIC (decl
));
3094 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3095 rewrite it for lambda capture. */
3098 process_outer_var_ref (tree decl
, tsubst_flags_t complain
)
3100 if (cp_unevaluated_operand
)
3101 /* It's not a use (3.2) if we're in an unevaluated context. */
3103 if (decl
== error_mark_node
)
3106 tree context
= DECL_CONTEXT (decl
);
3107 tree containing_function
= current_function_decl
;
3108 tree lambda_stack
= NULL_TREE
;
3109 tree lambda_expr
= NULL_TREE
;
3110 tree initializer
= convert_from_reference (decl
);
3112 /* Mark it as used now even if the use is ill-formed. */
3113 if (!mark_used (decl
, complain
) && !(complain
& tf_error
))
3114 return error_mark_node
;
3116 /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
3117 support for an approach in which a reference to a local
3118 [constant] automatic variable in a nested class or lambda body
3119 would enter the expression as an rvalue, which would reduce
3120 the complexity of the problem"
3122 FIXME update for final resolution of core issue 696. */
3123 if (decl_maybe_constant_var_p (decl
))
3125 if (processing_template_decl
)
3126 /* In a template, the constant value may not be in a usable
3127 form, so wait until instantiation time. */
3129 else if (decl_constant_var_p (decl
))
3131 tree t
= maybe_constant_value (convert_from_reference (decl
));
3132 if (TREE_CONSTANT (t
))
3137 if (parsing_nsdmi ())
3138 containing_function
= NULL_TREE
;
3140 /* If we are in a lambda function, we can move out until we hit
3142 2. a non-lambda function, or
3143 3. a non-default capturing lambda function. */
3144 while (context
!= containing_function
3145 && LAMBDA_FUNCTION_P (containing_function
))
3147 tree closure
= DECL_CONTEXT (containing_function
);
3148 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3150 if (TYPE_CLASS_SCOPE_P (closure
))
3151 /* A lambda in an NSDMI (c++/64496). */
3154 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3158 lambda_stack
= tree_cons (NULL_TREE
,
3163 = decl_function_context (containing_function
);
3166 if (lambda_expr
&& TREE_CODE (decl
) == VAR_DECL
3167 && DECL_ANON_UNION_VAR_P (decl
))
3169 if (complain
& tf_error
)
3170 error ("cannot capture member %qD of anonymous union", decl
);
3171 return error_mark_node
;
3173 if (context
== containing_function
)
3175 decl
= add_default_capture (lambda_stack
,
3176 /*id=*/DECL_NAME (decl
),
3179 else if (lambda_expr
)
3181 if (complain
& tf_error
)
3183 error ("%qD is not captured", decl
);
3184 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3185 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3187 inform (location_of (closure
),
3188 "the lambda has no capture-default");
3189 else if (TYPE_CLASS_SCOPE_P (closure
))
3190 inform (0, "lambda in local class %q+T cannot "
3191 "capture variables from the enclosing context",
3192 TYPE_CONTEXT (closure
));
3193 inform (input_location
, "%q+#D declared here", decl
);
3195 return error_mark_node
;
3199 if (complain
& tf_error
)
3201 ? G_("use of local variable with automatic storage from containing function")
3202 : G_("use of parameter from containing function"));
3203 inform (input_location
, "%q+#D declared here", decl
);
3204 return error_mark_node
;
3209 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3210 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3211 if non-NULL, is the type or namespace used to explicitly qualify
3212 ID_EXPRESSION. DECL is the entity to which that name has been
3215 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3216 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3217 be set to true if this expression isn't permitted in a
3218 constant-expression, but it is otherwise not set by this function.
3219 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3220 constant-expression, but a non-constant expression is also
3223 DONE is true if this expression is a complete postfix-expression;
3224 it is false if this expression is followed by '->', '[', '(', etc.
3225 ADDRESS_P is true iff this expression is the operand of '&'.
3226 TEMPLATE_P is true iff the qualified-id was of the form
3227 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3228 appears as a template argument.
3230 If an error occurs, and it is the kind of error that might cause
3231 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3232 is the caller's responsibility to issue the message. *ERROR_MSG
3233 will be a string with static storage duration, so the caller need
3236 Return an expression for the entity, after issuing appropriate
3237 diagnostics. This function is also responsible for transforming a
3238 reference to a non-static member into a COMPONENT_REF that makes
3239 the use of "this" explicit.
3241 Upon return, *IDK will be filled in appropriately. */
3243 finish_id_expression (tree id_expression
,
3247 bool integral_constant_expression_p
,
3248 bool allow_non_integral_constant_expression_p
,
3249 bool *non_integral_constant_expression_p
,
3253 bool template_arg_p
,
3254 const char **error_msg
,
3255 location_t location
)
3257 decl
= strip_using_decl (decl
);
3259 /* Initialize the output parameters. */
3260 *idk
= CP_ID_KIND_NONE
;
3263 if (id_expression
== error_mark_node
)
3264 return error_mark_node
;
3265 /* If we have a template-id, then no further lookup is
3266 required. If the template-id was for a template-class, we
3267 will sometimes have a TYPE_DECL at this point. */
3268 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3269 || TREE_CODE (decl
) == TYPE_DECL
)
3271 /* Look up the name. */
3274 if (decl
== error_mark_node
)
3276 /* Name lookup failed. */
3279 || (!dependent_type_p (scope
)
3280 && !(identifier_p (id_expression
)
3281 && IDENTIFIER_TYPENAME_P (id_expression
)
3282 && dependent_type_p (TREE_TYPE (id_expression
))))))
3284 /* If the qualifying type is non-dependent (and the name
3285 does not name a conversion operator to a dependent
3286 type), issue an error. */
3287 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3288 return error_mark_node
;
3292 /* It may be resolved via Koenig lookup. */
3293 *idk
= CP_ID_KIND_UNQUALIFIED
;
3294 return id_expression
;
3297 decl
= id_expression
;
3299 /* If DECL is a variable that would be out of scope under
3300 ANSI/ISO rules, but in scope in the ARM, name lookup
3301 will succeed. Issue a diagnostic here. */
3303 decl
= check_for_out_of_scope_variable (decl
);
3305 /* Remember that the name was used in the definition of
3306 the current class so that we can check later to see if
3307 the meaning would have been different after the class
3308 was entirely defined. */
3309 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3310 maybe_note_name_used_in_class (id_expression
, decl
);
3312 /* Disallow uses of local variables from containing functions, except
3313 within lambda-expressions. */
3314 if (outer_automatic_var_p (decl
))
3316 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3317 if (decl
== error_mark_node
)
3318 return error_mark_node
;
3321 /* Also disallow uses of function parameters outside the function
3322 body, except inside an unevaluated context (i.e. decltype). */
3323 if (TREE_CODE (decl
) == PARM_DECL
3324 && DECL_CONTEXT (decl
) == NULL_TREE
3325 && !cp_unevaluated_operand
)
3327 *error_msg
= "use of parameter outside function body";
3328 return error_mark_node
;
3332 /* If we didn't find anything, or what we found was a type,
3333 then this wasn't really an id-expression. */
3334 if (TREE_CODE (decl
) == TEMPLATE_DECL
3335 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3337 *error_msg
= "missing template arguments";
3338 return error_mark_node
;
3340 else if (TREE_CODE (decl
) == TYPE_DECL
3341 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3343 *error_msg
= "expected primary-expression";
3344 return error_mark_node
;
3347 /* If the name resolved to a template parameter, there is no
3348 need to look it up again later. */
3349 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3350 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3354 *idk
= CP_ID_KIND_NONE
;
3355 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3356 decl
= TEMPLATE_PARM_DECL (decl
);
3357 r
= convert_from_reference (DECL_INITIAL (decl
));
3359 if (integral_constant_expression_p
3360 && !dependent_type_p (TREE_TYPE (decl
))
3361 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3363 if (!allow_non_integral_constant_expression_p
)
3364 error ("template parameter %qD of type %qT is not allowed in "
3365 "an integral constant expression because it is not of "
3366 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3367 *non_integral_constant_expression_p
= true;
3375 /* If the declaration was explicitly qualified indicate
3376 that. The semantics of `A::f(3)' are different than
3377 `f(3)' if `f' is virtual. */
3379 ? CP_ID_KIND_QUALIFIED
3380 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3381 ? CP_ID_KIND_TEMPLATE_ID
3382 : CP_ID_KIND_UNQUALIFIED
));
3387 An id-expression is type-dependent if it contains an
3388 identifier that was declared with a dependent type.
3390 The standard is not very specific about an id-expression that
3391 names a set of overloaded functions. What if some of them
3392 have dependent types and some of them do not? Presumably,
3393 such a name should be treated as a dependent name. */
3394 /* Assume the name is not dependent. */
3395 dependent_p
= false;
3396 if (!processing_template_decl
)
3397 /* No names are dependent outside a template. */
3399 else if (TREE_CODE (decl
) == CONST_DECL
)
3400 /* We don't want to treat enumerators as dependent. */
3402 /* A template-id where the name of the template was not resolved
3403 is definitely dependent. */
3404 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3405 && (identifier_p (TREE_OPERAND (decl
, 0))))
3407 /* For anything except an overloaded function, just check its
3409 else if (!is_overloaded_fn (decl
))
3411 = dependent_type_p (TREE_TYPE (decl
));
3412 /* For a set of overloaded functions, check each of the
3418 if (BASELINK_P (fns
))
3419 fns
= BASELINK_FUNCTIONS (fns
);
3421 /* For a template-id, check to see if the template
3422 arguments are dependent. */
3423 if (TREE_CODE (fns
) == TEMPLATE_ID_EXPR
)
3425 tree args
= TREE_OPERAND (fns
, 1);
3426 dependent_p
= any_dependent_template_arguments_p (args
);
3427 /* The functions are those referred to by the
3429 fns
= TREE_OPERAND (fns
, 0);
3432 /* If there are no dependent template arguments, go through
3433 the overloaded functions. */
3434 while (fns
&& !dependent_p
)
3436 tree fn
= OVL_CURRENT (fns
);
3438 /* Member functions of dependent classes are
3440 if (TREE_CODE (fn
) == FUNCTION_DECL
3441 && type_dependent_expression_p (fn
))
3443 else if (TREE_CODE (fn
) == TEMPLATE_DECL
3444 && dependent_template_p (fn
))
3447 fns
= OVL_NEXT (fns
);
3451 /* If the name was dependent on a template parameter, we will
3452 resolve the name at instantiation time. */
3455 /* Create a SCOPE_REF for qualified names, if the scope is
3461 if (address_p
&& done
)
3462 decl
= finish_qualified_id_expr (scope
, decl
,
3466 tf_warning_or_error
);
3469 tree type
= NULL_TREE
;
3470 if (DECL_P (decl
) && !dependent_scope_p (scope
))
3471 type
= TREE_TYPE (decl
);
3472 decl
= build_qualified_name (type
,
3478 if (TREE_TYPE (decl
))
3479 decl
= convert_from_reference (decl
);
3482 /* A TEMPLATE_ID already contains all the information we
3484 if (TREE_CODE (id_expression
) == TEMPLATE_ID_EXPR
)
3485 return id_expression
;
3486 *idk
= CP_ID_KIND_UNQUALIFIED_DEPENDENT
;
3487 /* If we found a variable, then name lookup during the
3488 instantiation will always resolve to the same VAR_DECL
3489 (or an instantiation thereof). */
3491 || TREE_CODE (decl
) == PARM_DECL
)
3494 return convert_from_reference (decl
);
3496 /* The same is true for FIELD_DECL, but we also need to
3497 make sure that the syntax is correct. */
3498 else if (TREE_CODE (decl
) == FIELD_DECL
)
3500 /* Since SCOPE is NULL here, this is an unqualified name.
3501 Access checking has been performed during name lookup
3502 already. Turn off checking to avoid duplicate errors. */
3503 push_deferring_access_checks (dk_no_check
);
3504 decl
= finish_non_static_data_member
3506 /*qualifying_scope=*/NULL_TREE
);
3507 pop_deferring_access_checks ();
3510 return id_expression
;
3513 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3515 error ("use of namespace %qD as expression", decl
);
3516 return error_mark_node
;
3518 else if (DECL_CLASS_TEMPLATE_P (decl
))
3520 error ("use of class template %qT as expression", decl
);
3521 return error_mark_node
;
3523 else if (TREE_CODE (decl
) == TREE_LIST
)
3525 /* Ambiguous reference to base members. */
3526 error ("request for member %qD is ambiguous in "
3527 "multiple inheritance lattice", id_expression
);
3528 print_candidates (decl
);
3529 return error_mark_node
;
3532 /* Mark variable-like entities as used. Functions are similarly
3533 marked either below or after overload resolution. */
3535 || TREE_CODE (decl
) == PARM_DECL
3536 || TREE_CODE (decl
) == CONST_DECL
3537 || TREE_CODE (decl
) == RESULT_DECL
)
3538 && !mark_used (decl
))
3539 return error_mark_node
;
3541 /* Only certain kinds of names are allowed in constant
3542 expression. Template parameters have already
3543 been handled above. */
3544 if (! error_operand_p (decl
)
3545 && integral_constant_expression_p
3546 && ! decl_constant_var_p (decl
)
3547 && TREE_CODE (decl
) != CONST_DECL
3548 && ! builtin_valid_in_constant_expr_p (decl
))
3550 if (!allow_non_integral_constant_expression_p
)
3552 error ("%qD cannot appear in a constant-expression", decl
);
3553 return error_mark_node
;
3555 *non_integral_constant_expression_p
= true;
3560 && !cp_unevaluated_operand
3561 && !processing_template_decl
3562 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
3563 && DECL_THREAD_LOCAL_P (decl
)
3564 && (wrap
= get_tls_wrapper_fn (decl
)))
3566 /* Replace an evaluated use of the thread_local variable with
3567 a call to its wrapper. */
3568 decl
= build_cxx_call (wrap
, 0, NULL
, tf_warning_or_error
);
3570 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3571 && variable_template_p (TREE_OPERAND (decl
, 0)))
3573 decl
= finish_template_variable (decl
);
3578 decl
= (adjust_result_of_qualified_name_lookup
3579 (decl
, scope
, current_nonlambda_class_type()));
3581 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3585 decl
= finish_qualified_id_expr (scope
,
3591 tf_warning_or_error
);
3593 decl
= convert_from_reference (decl
);
3595 else if (TREE_CODE (decl
) == FIELD_DECL
)
3597 /* Since SCOPE is NULL here, this is an unqualified name.
3598 Access checking has been performed during name lookup
3599 already. Turn off checking to avoid duplicate errors. */
3600 push_deferring_access_checks (dk_no_check
);
3601 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3602 /*qualifying_scope=*/NULL_TREE
);
3603 pop_deferring_access_checks ();
3605 else if (is_overloaded_fn (decl
))
3609 first_fn
= get_first_fn (decl
);
3610 if (TREE_CODE (first_fn
) == TEMPLATE_DECL
)
3611 first_fn
= DECL_TEMPLATE_RESULT (first_fn
);
3613 if (!really_overloaded_fn (decl
)
3614 && !mark_used (first_fn
))
3615 return error_mark_node
;
3618 && TREE_CODE (first_fn
) == FUNCTION_DECL
3619 && DECL_FUNCTION_MEMBER_P (first_fn
)
3620 && !shared_member_p (decl
))
3622 /* A set of member functions. */
3623 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
3624 return finish_class_member_access_expr (decl
, id_expression
,
3625 /*template_p=*/false,
3626 tf_warning_or_error
);
3629 decl
= baselink_for_fns (decl
);
3633 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
3634 && DECL_CLASS_SCOPE_P (decl
))
3636 tree context
= context_for_name_lookup (decl
);
3637 if (context
!= current_class_type
)
3639 tree path
= currently_open_derived_class (context
);
3640 perform_or_defer_access_check (TYPE_BINFO (path
),
3642 tf_warning_or_error
);
3646 decl
= convert_from_reference (decl
);
3653 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3654 use as a type-specifier. */
3657 finish_typeof (tree expr
)
3661 if (type_dependent_expression_p (expr
))
3663 type
= cxx_make_type (TYPEOF_TYPE
);
3664 TYPEOF_TYPE_EXPR (type
) = expr
;
3665 SET_TYPE_STRUCTURAL_EQUALITY (type
);
3670 expr
= mark_type_use (expr
);
3672 type
= unlowered_expr_type (expr
);
3674 if (!type
|| type
== unknown_type_node
)
3676 error ("type of %qE is unknown", expr
);
3677 return error_mark_node
;
3683 /* Implement the __underlying_type keyword: Return the underlying
3684 type of TYPE, suitable for use as a type-specifier. */
3687 finish_underlying_type (tree type
)
3689 tree underlying_type
;
3691 if (processing_template_decl
)
3693 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
3694 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
3695 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
3697 return underlying_type
;
3700 complete_type (type
);
3702 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
3704 error ("%qT is not an enumeration type", type
);
3705 return error_mark_node
;
3708 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
3710 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
3711 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
3712 See finish_enum_value_list for details. */
3713 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
3715 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
3716 TYPE_UNSIGNED (underlying_type
));
3718 return underlying_type
;
3721 /* Implement the __direct_bases keyword: Return the direct base classes
3725 calculate_direct_bases (tree type
)
3727 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3728 tree bases_vec
= NULL_TREE
;
3729 vec
<tree
, va_gc
> *base_binfos
;
3733 complete_type (type
);
3735 if (!NON_UNION_CLASS_TYPE_P (type
))
3736 return make_tree_vec (0);
3738 base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
3740 /* Virtual bases are initialized first */
3741 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3743 if (BINFO_VIRTUAL_P (binfo
))
3745 vec_safe_push (vector
, binfo
);
3749 /* Now non-virtuals */
3750 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3752 if (!BINFO_VIRTUAL_P (binfo
))
3754 vec_safe_push (vector
, binfo
);
3759 bases_vec
= make_tree_vec (vector
->length ());
3761 for (i
= 0; i
< vector
->length (); ++i
)
3763 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
3768 /* Implement the __bases keyword: Return the base classes
3771 /* Find morally non-virtual base classes by walking binfo hierarchy */
3772 /* Virtual base classes are handled separately in finish_bases */
3775 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
3777 /* Don't walk bases of virtual bases */
3778 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
3782 dfs_calculate_bases_post (tree binfo
, void *data_
)
3784 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
3785 if (!BINFO_VIRTUAL_P (binfo
))
3787 vec_safe_push (*data
, BINFO_TYPE (binfo
));
3792 /* Calculates the morally non-virtual base classes of a class */
3793 static vec
<tree
, va_gc
> *
3794 calculate_bases_helper (tree type
)
3796 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3798 /* Now add non-virtual base classes in order of construction */
3799 dfs_walk_all (TYPE_BINFO (type
),
3800 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
3805 calculate_bases (tree type
)
3807 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3808 tree bases_vec
= NULL_TREE
;
3810 vec
<tree
, va_gc
> *vbases
;
3811 vec
<tree
, va_gc
> *nonvbases
;
3814 complete_type (type
);
3816 if (!NON_UNION_CLASS_TYPE_P (type
))
3817 return make_tree_vec (0);
3819 /* First go through virtual base classes */
3820 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
3821 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
3823 vec
<tree
, va_gc
> *vbase_bases
;
3824 vbase_bases
= calculate_bases_helper (BINFO_TYPE (binfo
));
3825 vec_safe_splice (vector
, vbase_bases
);
3826 release_tree_vector (vbase_bases
);
3829 /* Now for the non-virtual bases */
3830 nonvbases
= calculate_bases_helper (type
);
3831 vec_safe_splice (vector
, nonvbases
);
3832 release_tree_vector (nonvbases
);
3834 /* Last element is entire class, so don't copy */
3835 bases_vec
= make_tree_vec (vector
->length () - 1);
3837 for (i
= 0; i
< vector
->length () - 1; ++i
)
3839 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
3841 release_tree_vector (vector
);
3846 finish_bases (tree type
, bool direct
)
3848 tree bases
= NULL_TREE
;
3850 if (!processing_template_decl
)
3852 /* Parameter packs can only be used in templates */
3853 error ("Parameter pack __bases only valid in template declaration");
3854 return error_mark_node
;
3857 bases
= cxx_make_type (BASES
);
3858 BASES_TYPE (bases
) = type
;
3859 BASES_DIRECT (bases
) = direct
;
3860 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
3865 /* Perform C++-specific checks for __builtin_offsetof before calling
3869 finish_offsetof (tree expr
, location_t loc
)
3871 /* If we're processing a template, we can't finish the semantics yet.
3872 Otherwise we can fold the entire expression now. */
3873 if (processing_template_decl
)
3875 expr
= build1 (OFFSETOF_EXPR
, size_type_node
, expr
);
3876 SET_EXPR_LOCATION (expr
, loc
);
3880 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
3882 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
3883 TREE_OPERAND (expr
, 2));
3884 return error_mark_node
;
3886 if (TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
3887 || TREE_CODE (TREE_TYPE (expr
)) == METHOD_TYPE
3888 || TREE_TYPE (expr
) == unknown_type_node
)
3890 if (INDIRECT_REF_P (expr
))
3891 error ("second operand of %<offsetof%> is neither a single "
3892 "identifier nor a sequence of member accesses and "
3893 "array references");
3896 if (TREE_CODE (expr
) == COMPONENT_REF
3897 || TREE_CODE (expr
) == COMPOUND_EXPR
)
3898 expr
= TREE_OPERAND (expr
, 1);
3899 error ("cannot apply %<offsetof%> to member function %qD", expr
);
3901 return error_mark_node
;
3903 if (REFERENCE_REF_P (expr
))
3904 expr
= TREE_OPERAND (expr
, 0);
3905 if (TREE_CODE (expr
) == COMPONENT_REF
)
3907 tree object
= TREE_OPERAND (expr
, 0);
3908 if (!complete_type_or_else (TREE_TYPE (object
), object
))
3909 return error_mark_node
;
3910 if (warn_invalid_offsetof
3911 && CLASS_TYPE_P (TREE_TYPE (object
))
3912 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (object
))
3913 && cp_unevaluated_operand
== 0)
3914 pedwarn (loc
, OPT_Winvalid_offsetof
,
3915 "offsetof within non-standard-layout type %qT is undefined",
3916 TREE_TYPE (object
));
3918 return fold_offsetof (expr
);
3921 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
3922 function is broken out from the above for the benefit of the tree-ssa
3926 simplify_aggr_init_expr (tree
*tp
)
3928 tree aggr_init_expr
= *tp
;
3930 /* Form an appropriate CALL_EXPR. */
3931 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
3932 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
3933 tree type
= TREE_TYPE (slot
);
3936 enum style_t
{ ctor
, arg
, pcc
} style
;
3938 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
3940 #ifdef PCC_STATIC_STRUCT_RETURN
3946 gcc_assert (TREE_ADDRESSABLE (type
));
3950 call_expr
= build_call_array_loc (input_location
,
3951 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
3953 aggr_init_expr_nargs (aggr_init_expr
),
3954 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
3955 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
3956 CALL_EXPR_LIST_INIT_P (call_expr
) = CALL_EXPR_LIST_INIT_P (aggr_init_expr
);
3960 /* Replace the first argument to the ctor with the address of the
3962 cxx_mark_addressable (slot
);
3963 CALL_EXPR_ARG (call_expr
, 0) =
3964 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
3966 else if (style
== arg
)
3968 /* Just mark it addressable here, and leave the rest to
3969 expand_call{,_inline}. */
3970 cxx_mark_addressable (slot
);
3971 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
3972 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
3974 else if (style
== pcc
)
3976 /* If we're using the non-reentrant PCC calling convention, then we
3977 need to copy the returned value out of the static buffer into the
3979 push_deferring_access_checks (dk_no_check
);
3980 call_expr
= build_aggr_init (slot
, call_expr
,
3981 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
3982 tf_warning_or_error
);
3983 pop_deferring_access_checks ();
3984 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
3987 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
3989 tree init
= build_zero_init (type
, NULL_TREE
,
3990 /*static_storage_p=*/false);
3991 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
3992 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
3999 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4002 emit_associated_thunks (tree fn
)
4004 /* When we use vcall offsets, we emit thunks with the virtual
4005 functions to which they thunk. The whole point of vcall offsets
4006 is so that you can know statically the entire set of thunks that
4007 will ever be needed for a given virtual function, thereby
4008 enabling you to output all the thunks with the function itself. */
4009 if (DECL_VIRTUAL_P (fn
)
4010 /* Do not emit thunks for extern template instantiations. */
4011 && ! DECL_REALLY_EXTERN (fn
))
4015 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4017 if (!THUNK_ALIAS (thunk
))
4019 use_thunk (thunk
, /*emit_p=*/1);
4020 if (DECL_RESULT_THUNK_P (thunk
))
4024 for (probe
= DECL_THUNKS (thunk
);
4025 probe
; probe
= DECL_CHAIN (probe
))
4026 use_thunk (probe
, /*emit_p=*/1);
4030 gcc_assert (!DECL_THUNKS (thunk
));
4035 /* Generate RTL for FN. */
4038 expand_or_defer_fn_1 (tree fn
)
4040 /* When the parser calls us after finishing the body of a template
4041 function, we don't really want to expand the body. */
4042 if (processing_template_decl
)
4044 /* Normally, collection only occurs in rest_of_compilation. So,
4045 if we don't collect here, we never collect junk generated
4046 during the processing of templates until we hit a
4047 non-template function. It's not safe to do this inside a
4048 nested class, though, as the parser may have local state that
4049 is not a GC root. */
4050 if (!function_depth
)
4055 gcc_assert (DECL_SAVED_TREE (fn
));
4057 /* We make a decision about linkage for these functions at the end
4058 of the compilation. Until that point, we do not want the back
4059 end to output them -- but we do want it to see the bodies of
4060 these functions so that it can inline them as appropriate. */
4061 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4063 if (DECL_INTERFACE_KNOWN (fn
))
4064 /* We've already made a decision as to how this function will
4067 tentative_decl_linkage (fn
);
4069 import_export_decl (fn
);
4071 /* If the user wants us to keep all inline functions, then mark
4072 this function as needed so that finish_file will make sure to
4073 output it later. Similarly, all dllexport'd functions must
4074 be emitted; there may be callers in other DLLs. */
4075 if (DECL_DECLARED_INLINE_P (fn
)
4076 && !DECL_REALLY_EXTERN (fn
)
4077 && (flag_keep_inline_functions
4078 || (flag_keep_inline_dllexport
4079 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4082 DECL_EXTERNAL (fn
) = 0;
4086 /* If this is a constructor or destructor body, we have to clone
4088 if (maybe_clone_body (fn
))
4090 /* We don't want to process FN again, so pretend we've written
4091 it out, even though we haven't. */
4092 TREE_ASM_WRITTEN (fn
) = 1;
4093 /* If this is an instantiation of a constexpr function, keep
4094 DECL_SAVED_TREE for explain_invalid_constexpr_fn. */
4095 if (!is_instantiation_of_constexpr (fn
))
4096 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4100 /* There's no reason to do any of the work here if we're only doing
4101 semantic analysis; this code just generates RTL. */
4102 if (flag_syntax_only
)
4109 expand_or_defer_fn (tree fn
)
4111 if (expand_or_defer_fn_1 (fn
))
4115 /* Expand or defer, at the whim of the compilation unit manager. */
4116 cgraph_node::finalize_function (fn
, function_depth
> 1);
4117 emit_associated_thunks (fn
);
4125 nrv_data () : visited (37) {}
4129 hash_table
<pointer_hash
<tree_node
> > visited
;
4132 /* Helper function for walk_tree, used by finalize_nrv below. */
4135 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4137 struct nrv_data
*dp
= (struct nrv_data
*)data
;
4140 /* No need to walk into types. There wouldn't be any need to walk into
4141 non-statements, except that we have to consider STMT_EXPRs. */
4144 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4145 but differs from using NULL_TREE in that it indicates that we care
4146 about the value of the RESULT_DECL. */
4147 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4148 TREE_OPERAND (*tp
, 0) = dp
->result
;
4149 /* Change all cleanups for the NRV to only run when an exception is
4151 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4152 && CLEANUP_DECL (*tp
) == dp
->var
)
4153 CLEANUP_EH_ONLY (*tp
) = 1;
4154 /* Replace the DECL_EXPR for the NRV with an initialization of the
4155 RESULT_DECL, if needed. */
4156 else if (TREE_CODE (*tp
) == DECL_EXPR
4157 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4160 if (DECL_INITIAL (dp
->var
)
4161 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4162 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4163 DECL_INITIAL (dp
->var
));
4165 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4166 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4167 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4170 /* And replace all uses of the NRV with the RESULT_DECL. */
4171 else if (*tp
== dp
->var
)
4174 /* Avoid walking into the same tree more than once. Unfortunately, we
4175 can't just use walk_tree_without duplicates because it would only call
4176 us for the first occurrence of dp->var in the function body. */
4177 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4183 /* Keep iterating. */
4187 /* Called from finish_function to implement the named return value
4188 optimization by overriding all the RETURN_EXPRs and pertinent
4189 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4190 RESULT_DECL for the function. */
4193 finalize_nrv (tree
*tp
, tree var
, tree result
)
4195 struct nrv_data data
;
4197 /* Copy name from VAR to RESULT. */
4198 DECL_NAME (result
) = DECL_NAME (var
);
4199 /* Don't forget that we take its address. */
4200 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4201 /* Finally set DECL_VALUE_EXPR to avoid assigning
4202 a stack slot at -O0 for the original var and debug info
4203 uses RESULT location for VAR. */
4204 SET_DECL_VALUE_EXPR (var
, result
);
4205 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4208 data
.result
= result
;
4209 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4212 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4215 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4216 bool need_copy_ctor
, bool need_copy_assignment
,
4219 int save_errorcount
= errorcount
;
4222 /* Always allocate 3 elements for simplicity. These are the
4223 function decls for the ctor, dtor, and assignment op.
4224 This layout is known to the three lang hooks,
4225 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4226 and cxx_omp_clause_assign_op. */
4227 info
= make_tree_vec (3);
4228 CP_OMP_CLAUSE_INFO (c
) = info
;
4230 if (need_default_ctor
|| need_copy_ctor
)
4232 if (need_default_ctor
)
4233 t
= get_default_ctor (type
);
4235 t
= get_copy_ctor (type
, tf_warning_or_error
);
4237 if (t
&& !trivial_fn_p (t
))
4238 TREE_VEC_ELT (info
, 0) = t
;
4241 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4242 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4244 if (need_copy_assignment
)
4246 t
= get_copy_assign (type
);
4248 if (t
&& !trivial_fn_p (t
))
4249 TREE_VEC_ELT (info
, 2) = t
;
4252 return errorcount
!= save_errorcount
;
4255 /* Helper function for handle_omp_array_sections. Called recursively
4256 to handle multiple array-section-subscripts. C is the clause,
4257 T current expression (initially OMP_CLAUSE_DECL), which is either
4258 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4259 expression if specified, TREE_VALUE length expression if specified,
4260 TREE_CHAIN is what it has been specified after, or some decl.
4261 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4262 set to true if any of the array-section-subscript could have length
4263 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4264 first array-section-subscript which is known not to have length
4266 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4267 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4268 all are or may have length of 1, array-section-subscript [:2] is the
4269 first one knonwn not to have length 1. For array-section-subscript
4270 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4271 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4272 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4273 case though, as some lengths could be zero. */
4276 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4277 bool &maybe_zero_len
, unsigned int &first_non_one
)
4279 tree ret
, low_bound
, length
, type
;
4280 if (TREE_CODE (t
) != TREE_LIST
)
4282 if (error_operand_p (t
))
4283 return error_mark_node
;
4284 if (type_dependent_expression_p (t
))
4286 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
4288 if (processing_template_decl
)
4291 error_at (OMP_CLAUSE_LOCATION (c
),
4292 "%qD is not a variable in %qs clause", t
,
4293 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4295 error_at (OMP_CLAUSE_LOCATION (c
),
4296 "%qE is not a variable in %qs clause", t
,
4297 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4298 return error_mark_node
;
4300 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4301 && TREE_CODE (t
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (t
))
4303 error_at (OMP_CLAUSE_LOCATION (c
),
4304 "%qD is threadprivate variable in %qs clause", t
,
4305 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4306 return error_mark_node
;
4308 t
= convert_from_reference (t
);
4312 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4313 maybe_zero_len
, first_non_one
);
4314 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4317 type
= TREE_TYPE (ret
);
4318 low_bound
= TREE_PURPOSE (t
);
4319 length
= TREE_VALUE (t
);
4320 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4321 || (length
&& type_dependent_expression_p (length
)))
4324 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4325 return error_mark_node
;
4327 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4329 error_at (OMP_CLAUSE_LOCATION (c
),
4330 "low bound %qE of array section does not have integral type",
4332 return error_mark_node
;
4334 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4336 error_at (OMP_CLAUSE_LOCATION (c
),
4337 "length %qE of array section does not have integral type",
4339 return error_mark_node
;
4342 low_bound
= mark_rvalue_use (low_bound
);
4344 length
= mark_rvalue_use (length
);
4346 && TREE_CODE (low_bound
) == INTEGER_CST
4347 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4348 > TYPE_PRECISION (sizetype
))
4349 low_bound
= fold_convert (sizetype
, low_bound
);
4351 && TREE_CODE (length
) == INTEGER_CST
4352 && TYPE_PRECISION (TREE_TYPE (length
))
4353 > TYPE_PRECISION (sizetype
))
4354 length
= fold_convert (sizetype
, length
);
4355 if (low_bound
== NULL_TREE
)
4356 low_bound
= integer_zero_node
;
4358 if (length
!= NULL_TREE
)
4360 if (!integer_nonzerop (length
))
4361 maybe_zero_len
= true;
4362 if (first_non_one
== types
.length ()
4363 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4366 if (TREE_CODE (type
) == ARRAY_TYPE
)
4368 if (length
== NULL_TREE
4369 && (TYPE_DOMAIN (type
) == NULL_TREE
4370 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4372 error_at (OMP_CLAUSE_LOCATION (c
),
4373 "for unknown bound array type length expression must "
4375 return error_mark_node
;
4377 if (TREE_CODE (low_bound
) == INTEGER_CST
4378 && tree_int_cst_sgn (low_bound
) == -1)
4380 error_at (OMP_CLAUSE_LOCATION (c
),
4381 "negative low bound in array section in %qs clause",
4382 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4383 return error_mark_node
;
4385 if (length
!= NULL_TREE
4386 && TREE_CODE (length
) == INTEGER_CST
4387 && tree_int_cst_sgn (length
) == -1)
4389 error_at (OMP_CLAUSE_LOCATION (c
),
4390 "negative length in array section in %qs clause",
4391 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4392 return error_mark_node
;
4394 if (TYPE_DOMAIN (type
)
4395 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
4396 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
4399 tree size
= size_binop (PLUS_EXPR
,
4400 TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4402 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4404 if (tree_int_cst_lt (size
, low_bound
))
4406 error_at (OMP_CLAUSE_LOCATION (c
),
4407 "low bound %qE above array section size "
4408 "in %qs clause", low_bound
,
4409 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4410 return error_mark_node
;
4412 if (tree_int_cst_equal (size
, low_bound
))
4413 maybe_zero_len
= true;
4414 else if (length
== NULL_TREE
4415 && first_non_one
== types
.length ()
4416 && tree_int_cst_equal
4417 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4421 else if (length
== NULL_TREE
)
4423 maybe_zero_len
= true;
4424 if (first_non_one
== types
.length ())
4427 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
4429 if (tree_int_cst_lt (size
, length
))
4431 error_at (OMP_CLAUSE_LOCATION (c
),
4432 "length %qE above array section size "
4433 "in %qs clause", length
,
4434 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4435 return error_mark_node
;
4437 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4440 = size_binop (PLUS_EXPR
,
4441 fold_convert (sizetype
, low_bound
),
4442 fold_convert (sizetype
, length
));
4443 if (TREE_CODE (lbpluslen
) == INTEGER_CST
4444 && tree_int_cst_lt (size
, lbpluslen
))
4446 error_at (OMP_CLAUSE_LOCATION (c
),
4447 "high bound %qE above array section size "
4448 "in %qs clause", lbpluslen
,
4449 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4450 return error_mark_node
;
4455 else if (length
== NULL_TREE
)
4457 maybe_zero_len
= true;
4458 if (first_non_one
== types
.length ())
4462 /* For [lb:] we will need to evaluate lb more than once. */
4463 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4465 tree lb
= cp_save_expr (low_bound
);
4466 if (lb
!= low_bound
)
4468 TREE_PURPOSE (t
) = lb
;
4473 else if (TREE_CODE (type
) == POINTER_TYPE
)
4475 if (length
== NULL_TREE
)
4477 error_at (OMP_CLAUSE_LOCATION (c
),
4478 "for pointer type length expression must be specified");
4479 return error_mark_node
;
4481 /* If there is a pointer type anywhere but in the very first
4482 array-section-subscript, the array section can't be contiguous. */
4483 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4484 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
4486 error_at (OMP_CLAUSE_LOCATION (c
),
4487 "array section is not contiguous in %qs clause",
4488 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4489 return error_mark_node
;
4494 error_at (OMP_CLAUSE_LOCATION (c
),
4495 "%qE does not have pointer or array type", ret
);
4496 return error_mark_node
;
4498 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4499 types
.safe_push (TREE_TYPE (ret
));
4500 /* We will need to evaluate lb more than once. */
4501 tree lb
= cp_save_expr (low_bound
);
4502 if (lb
!= low_bound
)
4504 TREE_PURPOSE (t
) = lb
;
4507 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
4511 /* Handle array sections for clause C. */
4514 handle_omp_array_sections (tree c
)
4516 bool maybe_zero_len
= false;
4517 unsigned int first_non_one
= 0;
4518 auto_vec
<tree
> types
;
4519 tree first
= handle_omp_array_sections_1 (c
, OMP_CLAUSE_DECL (c
), types
,
4520 maybe_zero_len
, first_non_one
);
4521 if (first
== error_mark_node
)
4523 if (first
== NULL_TREE
)
4525 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
4527 tree t
= OMP_CLAUSE_DECL (c
);
4528 tree tem
= NULL_TREE
;
4529 if (processing_template_decl
)
4531 /* Need to evaluate side effects in the length expressions
4533 while (TREE_CODE (t
) == TREE_LIST
)
4535 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
4537 if (tem
== NULL_TREE
)
4538 tem
= TREE_VALUE (t
);
4540 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
4541 TREE_VALUE (t
), tem
);
4546 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
4547 OMP_CLAUSE_DECL (c
) = first
;
4551 unsigned int num
= types
.length (), i
;
4552 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
4553 tree condition
= NULL_TREE
;
4555 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
4556 maybe_zero_len
= true;
4557 if (processing_template_decl
&& maybe_zero_len
)
4560 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
4563 tree low_bound
= TREE_PURPOSE (t
);
4564 tree length
= TREE_VALUE (t
);
4568 && TREE_CODE (low_bound
) == INTEGER_CST
4569 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4570 > TYPE_PRECISION (sizetype
))
4571 low_bound
= fold_convert (sizetype
, low_bound
);
4573 && TREE_CODE (length
) == INTEGER_CST
4574 && TYPE_PRECISION (TREE_TYPE (length
))
4575 > TYPE_PRECISION (sizetype
))
4576 length
= fold_convert (sizetype
, length
);
4577 if (low_bound
== NULL_TREE
)
4578 low_bound
= integer_zero_node
;
4579 if (!maybe_zero_len
&& i
> first_non_one
)
4581 if (integer_nonzerop (low_bound
))
4582 goto do_warn_noncontiguous
;
4583 if (length
!= NULL_TREE
4584 && TREE_CODE (length
) == INTEGER_CST
4585 && TYPE_DOMAIN (types
[i
])
4586 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
4587 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
4591 size
= size_binop (PLUS_EXPR
,
4592 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4594 if (!tree_int_cst_equal (length
, size
))
4596 do_warn_noncontiguous
:
4597 error_at (OMP_CLAUSE_LOCATION (c
),
4598 "array section is not contiguous in %qs "
4600 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4604 if (!processing_template_decl
4605 && length
!= NULL_TREE
4606 && TREE_SIDE_EFFECTS (length
))
4608 if (side_effects
== NULL_TREE
)
4609 side_effects
= length
;
4611 side_effects
= build2 (COMPOUND_EXPR
,
4612 TREE_TYPE (side_effects
),
4613 length
, side_effects
);
4616 else if (processing_template_decl
)
4622 if (i
> first_non_one
&& length
&& integer_nonzerop (length
))
4625 l
= fold_convert (sizetype
, length
);
4628 l
= size_binop (PLUS_EXPR
,
4629 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4631 l
= size_binop (MINUS_EXPR
, l
,
4632 fold_convert (sizetype
, low_bound
));
4634 if (i
> first_non_one
)
4636 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
4638 if (condition
== NULL_TREE
)
4641 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
4644 else if (size
== NULL_TREE
)
4646 size
= size_in_bytes (TREE_TYPE (types
[i
]));
4647 size
= size_binop (MULT_EXPR
, size
, l
);
4649 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
4650 size
, size_zero_node
);
4653 size
= size_binop (MULT_EXPR
, size
, l
);
4656 if (!processing_template_decl
)
4659 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
4660 OMP_CLAUSE_DECL (c
) = first
;
4661 OMP_CLAUSE_SIZE (c
) = size
;
4662 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
4664 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
4666 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_POINTER
);
4667 if (!cxx_mark_addressable (t
))
4669 OMP_CLAUSE_DECL (c2
) = t
;
4670 t
= build_fold_addr_expr (first
);
4671 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4672 ptrdiff_type_node
, t
);
4673 tree ptr
= OMP_CLAUSE_DECL (c2
);
4674 ptr
= convert_from_reference (ptr
);
4675 if (!POINTER_TYPE_P (TREE_TYPE (ptr
)))
4676 ptr
= build_fold_addr_expr (ptr
);
4677 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
4678 ptrdiff_type_node
, t
,
4679 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4680 ptrdiff_type_node
, ptr
));
4681 OMP_CLAUSE_SIZE (c2
) = t
;
4682 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
4683 OMP_CLAUSE_CHAIN (c
) = c2
;
4684 ptr
= OMP_CLAUSE_DECL (c2
);
4685 if (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
4686 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
4688 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
4690 OMP_CLAUSE_SET_MAP_KIND (c3
, GOMP_MAP_POINTER
);
4691 OMP_CLAUSE_DECL (c3
) = ptr
;
4692 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
4693 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
4694 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
4695 OMP_CLAUSE_CHAIN (c2
) = c3
;
4702 /* Return identifier to look up for omp declare reduction. */
4705 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
4707 const char *p
= NULL
;
4708 const char *m
= NULL
;
4709 switch (reduction_code
)
4717 case TRUTH_ANDIF_EXPR
:
4718 case TRUTH_ORIF_EXPR
:
4719 reduction_id
= ansi_opname (reduction_code
);
4733 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
4734 return error_mark_node
;
4735 p
= IDENTIFIER_POINTER (reduction_id
);
4738 if (type
!= NULL_TREE
)
4739 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
4741 const char prefix
[] = "omp declare reduction ";
4742 size_t lenp
= sizeof (prefix
);
4743 if (strncmp (p
, prefix
, lenp
- 1) == 0)
4745 size_t len
= strlen (p
);
4746 size_t lenm
= m
? strlen (m
) + 1 : 0;
4747 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
4749 memcpy (name
, prefix
, lenp
- 1);
4750 memcpy (name
+ lenp
- 1, p
, len
+ 1);
4753 name
[lenp
+ len
- 1] = '~';
4754 memcpy (name
+ lenp
+ len
, m
, lenm
);
4756 return get_identifier (name
);
4759 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
4760 FUNCTION_DECL or NULL_TREE if not found. */
4763 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
4764 vec
<tree
> *ambiguousp
)
4767 tree baselink
= NULL_TREE
;
4768 if (identifier_p (id
))
4771 bool nonint_cst_expression_p
;
4772 const char *error_msg
;
4773 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
4774 tree decl
= lookup_name (id
);
4775 if (decl
== NULL_TREE
)
4776 decl
= error_mark_node
;
4777 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
4778 &nonint_cst_expression_p
, false, true, false,
4779 false, &error_msg
, loc
);
4780 if (idk
== CP_ID_KIND_UNQUALIFIED
4781 && identifier_p (id
))
4783 vec
<tree
, va_gc
> *args
= NULL
;
4784 vec_safe_push (args
, build_reference_type (type
));
4785 id
= perform_koenig_lookup (id
, args
, tf_none
);
4788 else if (TREE_CODE (id
) == SCOPE_REF
)
4789 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
4790 omp_reduction_id (ERROR_MARK
,
4791 TREE_OPERAND (id
, 1),
4795 if (id
&& is_overloaded_fn (id
))
4797 for (; id
; id
= OVL_NEXT (id
))
4799 tree fndecl
= OVL_CURRENT (id
);
4800 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
4802 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
4803 if (same_type_p (TREE_TYPE (argtype
), type
))
4807 if (id
&& BASELINK_P (fns
))
4814 if (id
== NULL_TREE
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
4816 vec
<tree
> ambiguous
= vNULL
;
4817 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
4819 if (ambiguousp
== NULL
)
4820 ambiguousp
= &ambiguous
;
4821 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
4823 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
4824 baselinkp
? baselinkp
: &baselink
,
4826 if (id
== NULL_TREE
)
4828 if (!ambiguousp
->is_empty ())
4829 ambiguousp
->safe_push (id
);
4830 else if (ret
!= NULL_TREE
)
4832 ambiguousp
->safe_push (ret
);
4833 ambiguousp
->safe_push (id
);
4839 if (ambiguousp
!= &ambiguous
)
4841 if (!ambiguous
.is_empty ())
4843 const char *str
= _("candidates are:");
4846 error_at (loc
, "user defined reduction lookup is ambiguous");
4847 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
4849 inform (DECL_SOURCE_LOCATION (udr
), "%s %#D", str
, udr
);
4851 str
= get_spaces (str
);
4853 ambiguous
.release ();
4854 ret
= error_mark_node
;
4855 baselink
= NULL_TREE
;
4860 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
4861 id
, id
, tf_warning_or_error
);
4865 /* Helper function for cp_parser_omp_declare_reduction_exprs
4867 Remove CLEANUP_STMT for data (omp_priv variable).
4868 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
4872 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
4876 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
4877 *tp
= CLEANUP_BODY (*tp
);
4878 else if (TREE_CODE (*tp
) == DECL_EXPR
)
4880 tree decl
= DECL_EXPR_DECL (*tp
);
4881 if (!processing_template_decl
4882 && decl
== (tree
) data
4883 && DECL_INITIAL (decl
)
4884 && DECL_INITIAL (decl
) != error_mark_node
)
4886 tree list
= NULL_TREE
;
4887 append_to_statement_list_force (*tp
, &list
);
4888 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
4889 decl
, DECL_INITIAL (decl
));
4890 DECL_INITIAL (decl
) = NULL_TREE
;
4891 append_to_statement_list_force (init_expr
, &list
);
4898 /* Data passed from cp_check_omp_declare_reduction to
4899 cp_check_omp_declare_reduction_r. */
4901 struct cp_check_omp_declare_reduction_data
4908 /* Helper function for cp_check_omp_declare_reduction, called via
4912 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
4914 struct cp_check_omp_declare_reduction_data
*udr_data
4915 = (struct cp_check_omp_declare_reduction_data
*) data
;
4917 && !DECL_ARTIFICIAL (*tp
)
4918 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
4919 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
4921 location_t loc
= udr_data
->loc
;
4922 if (udr_data
->combiner_p
)
4923 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
4924 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
4927 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
4928 "to variable %qD which is not %<omp_priv%> nor "
4936 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
4939 cp_check_omp_declare_reduction (tree udr
)
4941 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
4942 gcc_assert (TREE_CODE (type
) == REFERENCE_TYPE
);
4943 type
= TREE_TYPE (type
);
4945 location_t loc
= DECL_SOURCE_LOCATION (udr
);
4947 if (type
== error_mark_node
)
4949 if (ARITHMETIC_TYPE_P (type
))
4951 static enum tree_code predef_codes
[]
4952 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
4953 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
4954 for (i
= 0; i
< 8; i
++)
4956 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
4957 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
4958 const char *n2
= IDENTIFIER_POINTER (id
);
4959 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
4960 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
4961 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
4966 && TREE_CODE (type
) != COMPLEX_EXPR
)
4968 const char prefix_minmax
[] = "omp declare reduction m";
4969 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
4970 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
4971 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
4972 prefix_minmax
, prefix_size
) == 0
4973 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
4974 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
4975 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
4980 error_at (loc
, "predeclared arithmetic type %qT in "
4981 "%<#pragma omp declare reduction%>", type
);
4985 else if (TREE_CODE (type
) == FUNCTION_TYPE
4986 || TREE_CODE (type
) == METHOD_TYPE
4987 || TREE_CODE (type
) == ARRAY_TYPE
)
4989 error_at (loc
, "function or array type %qT in "
4990 "%<#pragma omp declare reduction%>", type
);
4993 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
4995 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
4999 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5001 error_at (loc
, "const, volatile or __restrict qualified type %qT in "
5002 "%<#pragma omp declare reduction%>", type
);
5006 tree body
= DECL_SAVED_TREE (udr
);
5007 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5010 tree_stmt_iterator tsi
;
5011 struct cp_check_omp_declare_reduction_data data
;
5012 memset (data
.stmts
, 0, sizeof data
.stmts
);
5013 for (i
= 0, tsi
= tsi_start (body
);
5014 i
< 7 && !tsi_end_p (tsi
);
5015 i
++, tsi_next (&tsi
))
5016 data
.stmts
[i
] = tsi_stmt (tsi
);
5018 gcc_assert (tsi_end_p (tsi
));
5021 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5022 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5023 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
5025 data
.combiner_p
= true;
5026 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5028 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5032 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5033 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5034 data
.combiner_p
= false;
5035 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5037 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5038 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5039 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5041 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5045 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5046 an inline call. But, remap
5047 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5048 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5051 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5052 tree decl
, tree placeholder
)
5055 hash_map
<tree
, tree
> decl_map
;
5057 decl_map
.put (omp_decl1
, placeholder
);
5058 decl_map
.put (omp_decl2
, decl
);
5059 memset (&id
, 0, sizeof (id
));
5060 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5061 id
.dst_fn
= current_function_decl
;
5062 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5063 id
.decl_map
= &decl_map
;
5065 id
.copy_decl
= copy_decl_no_change
;
5066 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5067 id
.transform_new_cfg
= true;
5068 id
.transform_return_to_modify
= false;
5069 id
.transform_lang_insert_block
= NULL
;
5071 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5075 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5076 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5079 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5081 if (*tp
== (tree
) data
)
5086 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5087 Return true if there is some error and the clause should be removed. */
5090 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5092 tree t
= OMP_CLAUSE_DECL (c
);
5093 bool predefined
= false;
5094 tree type
= TREE_TYPE (t
);
5095 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5096 type
= TREE_TYPE (type
);
5097 if (type
== error_mark_node
)
5099 else if (ARITHMETIC_TYPE_P (type
))
5100 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5109 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5116 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5120 case TRUTH_ANDIF_EXPR
:
5121 case TRUTH_ORIF_EXPR
:
5122 if (FLOAT_TYPE_P (type
))
5129 else if (TREE_CODE (type
) == ARRAY_TYPE
|| TYPE_READONLY (type
))
5131 error ("%qE has invalid type for %<reduction%>", t
);
5134 else if (!processing_template_decl
)
5136 t
= require_complete_type (t
);
5137 if (t
== error_mark_node
)
5139 OMP_CLAUSE_DECL (c
) = t
;
5144 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5147 else if (processing_template_decl
)
5150 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5152 type
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
5153 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5154 type
= TREE_TYPE (type
);
5155 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5156 if (id
== NULL_TREE
)
5157 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5158 NULL_TREE
, NULL_TREE
);
5159 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5162 if (id
== error_mark_node
)
5164 id
= OVL_CURRENT (id
);
5166 tree body
= DECL_SAVED_TREE (id
);
5169 if (TREE_CODE (body
) == STATEMENT_LIST
)
5171 tree_stmt_iterator tsi
;
5172 tree placeholder
= NULL_TREE
;
5175 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5176 atype
= TREE_TYPE (atype
);
5177 bool need_static_cast
= !same_type_p (type
, atype
);
5178 memset (stmts
, 0, sizeof stmts
);
5179 for (i
= 0, tsi
= tsi_start (body
);
5180 i
< 7 && !tsi_end_p (tsi
);
5181 i
++, tsi_next (&tsi
))
5182 stmts
[i
] = tsi_stmt (tsi
);
5183 gcc_assert (tsi_end_p (tsi
));
5187 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
5188 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
5189 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
5190 DECL_ARTIFICIAL (placeholder
) = 1;
5191 DECL_IGNORED_P (placeholder
) = 1;
5192 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
5193 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
5194 cxx_mark_addressable (placeholder
);
5195 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
5196 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
5198 cxx_mark_addressable (OMP_CLAUSE_DECL (c
));
5199 tree omp_out
= placeholder
;
5200 tree omp_in
= convert_from_reference (OMP_CLAUSE_DECL (c
));
5201 if (need_static_cast
)
5203 tree rtype
= build_reference_type (atype
);
5204 omp_out
= build_static_cast (rtype
, omp_out
,
5205 tf_warning_or_error
);
5206 omp_in
= build_static_cast (rtype
, omp_in
,
5207 tf_warning_or_error
);
5208 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
5210 omp_out
= convert_from_reference (omp_out
);
5211 omp_in
= convert_from_reference (omp_in
);
5213 OMP_CLAUSE_REDUCTION_MERGE (c
)
5214 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
5215 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
5219 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
5220 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
5221 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3])))
5222 cxx_mark_addressable (OMP_CLAUSE_DECL (c
));
5223 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
5224 cxx_mark_addressable (placeholder
);
5225 tree omp_priv
= convert_from_reference (OMP_CLAUSE_DECL (c
));
5226 tree omp_orig
= placeholder
;
5227 if (need_static_cast
)
5231 error_at (OMP_CLAUSE_LOCATION (c
),
5232 "user defined reduction with constructor "
5233 "initializer for base class %qT", atype
);
5236 tree rtype
= build_reference_type (atype
);
5237 omp_priv
= build_static_cast (rtype
, omp_priv
,
5238 tf_warning_or_error
);
5239 omp_orig
= build_static_cast (rtype
, omp_orig
,
5240 tf_warning_or_error
);
5241 if (omp_priv
== error_mark_node
5242 || omp_orig
== error_mark_node
)
5244 omp_priv
= convert_from_reference (omp_priv
);
5245 omp_orig
= convert_from_reference (omp_orig
);
5248 *need_default_ctor
= true;
5249 OMP_CLAUSE_REDUCTION_INIT (c
)
5250 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
5251 DECL_EXPR_DECL (stmts
[3]),
5252 omp_priv
, omp_orig
);
5253 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
5254 find_omp_placeholder_r
, placeholder
, NULL
))
5255 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
5259 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
5260 *need_default_ctor
= true;
5264 tree v
= convert_from_reference (t
);
5265 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
5266 init
= build_constructor (TREE_TYPE (v
), NULL
);
5268 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
5269 OMP_CLAUSE_REDUCTION_INIT (c
)
5270 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
5275 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5279 error ("user defined reduction not found for %qD", t
);
5285 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
5286 Remove any elements from the list that are invalid. */
5289 finish_omp_clauses (tree clauses
)
5291 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
5292 bitmap_head aligned_head
;
5294 bool branch_seen
= false;
5295 bool copyprivate_seen
= false;
5297 bitmap_obstack_initialize (NULL
);
5298 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
5299 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
5300 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
5301 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
5303 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
5305 bool remove
= false;
5307 switch (OMP_CLAUSE_CODE (c
))
5309 case OMP_CLAUSE_SHARED
:
5310 goto check_dup_generic
;
5311 case OMP_CLAUSE_PRIVATE
:
5312 goto check_dup_generic
;
5313 case OMP_CLAUSE_REDUCTION
:
5314 goto check_dup_generic
;
5315 case OMP_CLAUSE_COPYPRIVATE
:
5316 copyprivate_seen
= true;
5317 goto check_dup_generic
;
5318 case OMP_CLAUSE_COPYIN
:
5319 goto check_dup_generic
;
5320 case OMP_CLAUSE_LINEAR
:
5321 t
= OMP_CLAUSE_DECL (c
);
5322 if (!type_dependent_expression_p (t
)
5323 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
5324 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
)
5326 error ("linear clause applied to non-integral non-pointer "
5327 "variable with %qT type", TREE_TYPE (t
));
5331 t
= OMP_CLAUSE_LINEAR_STEP (c
);
5333 t
= integer_one_node
;
5334 if (t
== error_mark_node
)
5339 else if (!type_dependent_expression_p (t
)
5340 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5342 error ("linear step expression must be integral");
5348 t
= mark_rvalue_use (t
);
5349 if (!processing_template_decl
)
5351 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
)
5352 t
= maybe_constant_value (t
);
5353 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5354 if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
5357 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
5358 OMP_CLAUSE_DECL (c
), t
);
5359 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
5360 MINUS_EXPR
, sizetype
, t
,
5361 OMP_CLAUSE_DECL (c
));
5362 if (t
== error_mark_node
)
5369 t
= fold_convert (TREE_TYPE (OMP_CLAUSE_DECL (c
)), t
);
5371 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
5373 goto check_dup_generic
;
5375 t
= OMP_CLAUSE_DECL (c
);
5376 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5378 if (processing_template_decl
)
5381 error ("%qD is not a variable in clause %qs", t
,
5382 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5384 error ("%qE is not a variable in clause %qs", t
,
5385 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5388 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
5389 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
5390 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
5392 error ("%qD appears more than once in data clauses", t
);
5396 bitmap_set_bit (&generic_head
, DECL_UID (t
));
5399 case OMP_CLAUSE_FIRSTPRIVATE
:
5400 t
= OMP_CLAUSE_DECL (c
);
5401 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5403 if (processing_template_decl
)
5406 error ("%qD is not a variable in clause %<firstprivate%>", t
);
5408 error ("%qE is not a variable in clause %<firstprivate%>", t
);
5411 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
5412 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
5414 error ("%qD appears more than once in data clauses", t
);
5418 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
5421 case OMP_CLAUSE_LASTPRIVATE
:
5422 t
= OMP_CLAUSE_DECL (c
);
5423 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5425 if (processing_template_decl
)
5428 error ("%qD is not a variable in clause %<lastprivate%>", t
);
5430 error ("%qE is not a variable in clause %<lastprivate%>", t
);
5433 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
5434 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
5436 error ("%qD appears more than once in data clauses", t
);
5440 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
5444 t
= OMP_CLAUSE_IF_EXPR (c
);
5445 t
= maybe_convert_cond (t
);
5446 if (t
== error_mark_node
)
5448 else if (!processing_template_decl
)
5449 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5450 OMP_CLAUSE_IF_EXPR (c
) = t
;
5453 case OMP_CLAUSE_FINAL
:
5454 t
= OMP_CLAUSE_FINAL_EXPR (c
);
5455 t
= maybe_convert_cond (t
);
5456 if (t
== error_mark_node
)
5458 else if (!processing_template_decl
)
5459 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5460 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
5463 case OMP_CLAUSE_NUM_THREADS
:
5464 t
= OMP_CLAUSE_NUM_THREADS_EXPR (c
);
5465 if (t
== error_mark_node
)
5467 else if (!type_dependent_expression_p (t
)
5468 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5470 error ("num_threads expression must be integral");
5475 t
= mark_rvalue_use (t
);
5476 if (!processing_template_decl
)
5477 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5478 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
5482 case OMP_CLAUSE_SCHEDULE
:
5483 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
5486 else if (t
== error_mark_node
)
5488 else if (!type_dependent_expression_p (t
)
5489 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
5490 != OMP_CLAUSE_SCHEDULE_CILKFOR
)
5491 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5493 error ("schedule chunk size expression must be integral");
5498 t
= mark_rvalue_use (t
);
5499 if (!processing_template_decl
)
5501 if (OMP_CLAUSE_SCHEDULE_KIND (c
)
5502 == OMP_CLAUSE_SCHEDULE_CILKFOR
)
5504 t
= convert_to_integer (long_integer_type_node
, t
);
5505 if (t
== error_mark_node
)
5511 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5513 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
5517 case OMP_CLAUSE_SIMDLEN
:
5518 case OMP_CLAUSE_SAFELEN
:
5519 t
= OMP_CLAUSE_OPERAND (c
, 0);
5520 if (t
== error_mark_node
)
5522 else if (!type_dependent_expression_p (t
)
5523 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5525 error ("%qs length expression must be integral",
5526 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5531 t
= mark_rvalue_use (t
);
5532 t
= maybe_constant_value (t
);
5533 if (!processing_template_decl
)
5535 if (TREE_CODE (t
) != INTEGER_CST
5536 || tree_int_cst_sgn (t
) != 1)
5538 error ("%qs length expression must be positive constant"
5539 " integer expression",
5540 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5544 OMP_CLAUSE_OPERAND (c
, 0) = t
;
5548 case OMP_CLAUSE_NUM_TEAMS
:
5549 t
= OMP_CLAUSE_NUM_TEAMS_EXPR (c
);
5550 if (t
== error_mark_node
)
5552 else if (!type_dependent_expression_p (t
)
5553 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5555 error ("%<num_teams%> expression must be integral");
5560 t
= mark_rvalue_use (t
);
5561 if (!processing_template_decl
)
5562 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5563 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
5567 case OMP_CLAUSE_ASYNC
:
5568 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
5569 if (t
== error_mark_node
)
5571 else if (!type_dependent_expression_p (t
)
5572 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5574 error ("%<async%> expression must be integral");
5579 t
= mark_rvalue_use (t
);
5580 if (!processing_template_decl
)
5581 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5582 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
5586 case OMP_CLAUSE_VECTOR_LENGTH
:
5587 t
= OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
);
5588 t
= maybe_convert_cond (t
);
5589 if (t
== error_mark_node
)
5591 else if (!processing_template_decl
)
5592 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5593 OMP_CLAUSE_VECTOR_LENGTH_EXPR (c
) = t
;
5596 case OMP_CLAUSE_WAIT
:
5597 t
= OMP_CLAUSE_WAIT_EXPR (c
);
5598 if (t
== error_mark_node
)
5600 else if (!processing_template_decl
)
5601 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5602 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
5605 case OMP_CLAUSE_THREAD_LIMIT
:
5606 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
5607 if (t
== error_mark_node
)
5609 else if (!type_dependent_expression_p (t
)
5610 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5612 error ("%<thread_limit%> expression must be integral");
5617 t
= mark_rvalue_use (t
);
5618 if (!processing_template_decl
)
5619 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5620 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
5624 case OMP_CLAUSE_DEVICE
:
5625 t
= OMP_CLAUSE_DEVICE_ID (c
);
5626 if (t
== error_mark_node
)
5628 else if (!type_dependent_expression_p (t
)
5629 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5631 error ("%<device%> id must be integral");
5636 t
= mark_rvalue_use (t
);
5637 if (!processing_template_decl
)
5638 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5639 OMP_CLAUSE_DEVICE_ID (c
) = t
;
5643 case OMP_CLAUSE_DIST_SCHEDULE
:
5644 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
5647 else if (t
== error_mark_node
)
5649 else if (!type_dependent_expression_p (t
)
5650 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5652 error ("%<dist_schedule%> chunk size expression must be "
5658 t
= mark_rvalue_use (t
);
5659 if (!processing_template_decl
)
5660 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5661 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
5665 case OMP_CLAUSE_ALIGNED
:
5666 t
= OMP_CLAUSE_DECL (c
);
5667 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
5669 if (processing_template_decl
)
5672 error ("%qD is not a variable in %<aligned%> clause", t
);
5674 error ("%qE is not a variable in %<aligned%> clause", t
);
5677 else if (!type_dependent_expression_p (t
)
5678 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
5679 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
5680 && (TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
5681 || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
5682 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
5685 error_at (OMP_CLAUSE_LOCATION (c
),
5686 "%qE in %<aligned%> clause is neither a pointer nor "
5687 "an array nor a reference to pointer or array", t
);
5690 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
5692 error ("%qD appears more than once in %<aligned%> clauses", t
);
5696 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
5697 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
5698 if (t
== error_mark_node
)
5700 else if (t
== NULL_TREE
)
5702 else if (!type_dependent_expression_p (t
)
5703 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5705 error ("%<aligned%> clause alignment expression must "
5711 t
= mark_rvalue_use (t
);
5712 t
= maybe_constant_value (t
);
5713 if (!processing_template_decl
)
5715 if (TREE_CODE (t
) != INTEGER_CST
5716 || tree_int_cst_sgn (t
) != 1)
5718 error ("%<aligned%> clause alignment expression must be "
5719 "positive constant integer expression");
5723 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
5727 case OMP_CLAUSE_DEPEND
:
5728 t
= OMP_CLAUSE_DECL (c
);
5729 if (TREE_CODE (t
) == TREE_LIST
)
5731 if (handle_omp_array_sections (c
))
5735 if (t
== error_mark_node
)
5737 else if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
5739 if (processing_template_decl
)
5742 error ("%qD is not a variable in %<depend%> clause", t
);
5744 error ("%qE is not a variable in %<depend%> clause", t
);
5747 else if (!processing_template_decl
5748 && !cxx_mark_addressable (t
))
5752 case OMP_CLAUSE_MAP
:
5754 case OMP_CLAUSE_FROM
:
5755 case OMP_CLAUSE__CACHE_
:
5756 t
= OMP_CLAUSE_DECL (c
);
5757 if (TREE_CODE (t
) == TREE_LIST
)
5759 if (handle_omp_array_sections (c
))
5763 t
= OMP_CLAUSE_DECL (c
);
5764 if (TREE_CODE (t
) != TREE_LIST
5765 && !type_dependent_expression_p (t
)
5766 && !cp_omp_mappable_type (TREE_TYPE (t
)))
5768 error_at (OMP_CLAUSE_LOCATION (c
),
5769 "array section does not have mappable type "
5771 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5777 if (t
== error_mark_node
)
5779 else if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
5781 if (processing_template_decl
)
5783 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5784 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
)
5787 error ("%qD is not a variable in %qs clause", t
,
5788 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5790 error ("%qE is not a variable in %qs clause", t
,
5791 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5794 else if (TREE_CODE (t
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (t
))
5796 error ("%qD is threadprivate variable in %qs clause", t
,
5797 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5800 else if (!processing_template_decl
5801 && TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
5802 && !cxx_mark_addressable (t
))
5804 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5805 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
)
5806 && !type_dependent_expression_p (t
)
5807 && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t
))
5809 ? TREE_TYPE (TREE_TYPE (t
))
5812 error_at (OMP_CLAUSE_LOCATION (c
),
5813 "%qD does not have a mappable type in %qs clause", t
,
5814 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5817 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
5819 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
5820 error ("%qD appears more than once in motion clauses", t
);
5822 error ("%qD appears more than once in map clauses", t
);
5826 bitmap_set_bit (&generic_head
, DECL_UID (t
));
5829 case OMP_CLAUSE_UNIFORM
:
5830 t
= OMP_CLAUSE_DECL (c
);
5831 if (TREE_CODE (t
) != PARM_DECL
)
5833 if (processing_template_decl
)
5836 error ("%qD is not an argument in %<uniform%> clause", t
);
5838 error ("%qE is not an argument in %<uniform%> clause", t
);
5842 goto check_dup_generic
;
5844 case OMP_CLAUSE_NOWAIT
:
5845 case OMP_CLAUSE_ORDERED
:
5846 case OMP_CLAUSE_DEFAULT
:
5847 case OMP_CLAUSE_UNTIED
:
5848 case OMP_CLAUSE_COLLAPSE
:
5849 case OMP_CLAUSE_MERGEABLE
:
5850 case OMP_CLAUSE_PARALLEL
:
5851 case OMP_CLAUSE_FOR
:
5852 case OMP_CLAUSE_SECTIONS
:
5853 case OMP_CLAUSE_TASKGROUP
:
5854 case OMP_CLAUSE_PROC_BIND
:
5855 case OMP_CLAUSE__CILK_FOR_COUNT_
:
5858 case OMP_CLAUSE_INBRANCH
:
5859 case OMP_CLAUSE_NOTINBRANCH
:
5862 error ("%<inbranch%> clause is incompatible with "
5874 *pc
= OMP_CLAUSE_CHAIN (c
);
5876 pc
= &OMP_CLAUSE_CHAIN (c
);
5879 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
5881 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
5882 bool remove
= false;
5883 bool need_complete_non_reference
= false;
5884 bool need_default_ctor
= false;
5885 bool need_copy_ctor
= false;
5886 bool need_copy_assignment
= false;
5887 bool need_implicitly_determined
= false;
5888 bool need_dtor
= false;
5889 tree type
, inner_type
;
5893 case OMP_CLAUSE_SHARED
:
5894 need_implicitly_determined
= true;
5896 case OMP_CLAUSE_PRIVATE
:
5897 need_complete_non_reference
= true;
5898 need_default_ctor
= true;
5900 need_implicitly_determined
= true;
5902 case OMP_CLAUSE_FIRSTPRIVATE
:
5903 need_complete_non_reference
= true;
5904 need_copy_ctor
= true;
5906 need_implicitly_determined
= true;
5908 case OMP_CLAUSE_LASTPRIVATE
:
5909 need_complete_non_reference
= true;
5910 need_copy_assignment
= true;
5911 need_implicitly_determined
= true;
5913 case OMP_CLAUSE_REDUCTION
:
5914 need_implicitly_determined
= true;
5916 case OMP_CLAUSE_COPYPRIVATE
:
5917 need_copy_assignment
= true;
5919 case OMP_CLAUSE_COPYIN
:
5920 need_copy_assignment
= true;
5922 case OMP_CLAUSE_NOWAIT
:
5923 if (copyprivate_seen
)
5925 error_at (OMP_CLAUSE_LOCATION (c
),
5926 "%<nowait%> clause must not be used together "
5927 "with %<copyprivate%>");
5928 *pc
= OMP_CLAUSE_CHAIN (c
);
5933 pc
= &OMP_CLAUSE_CHAIN (c
);
5937 t
= OMP_CLAUSE_DECL (c
);
5938 if (processing_template_decl
5939 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5941 pc
= &OMP_CLAUSE_CHAIN (c
);
5947 case OMP_CLAUSE_LASTPRIVATE
:
5948 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
5950 need_default_ctor
= true;
5955 case OMP_CLAUSE_REDUCTION
:
5956 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
5960 t
= OMP_CLAUSE_DECL (c
);
5963 case OMP_CLAUSE_COPYIN
:
5964 if (!VAR_P (t
) || !DECL_THREAD_LOCAL_P (t
))
5966 error ("%qE must be %<threadprivate%> for %<copyin%>", t
);
5975 if (need_complete_non_reference
|| need_copy_assignment
)
5977 t
= require_complete_type (t
);
5978 if (t
== error_mark_node
)
5980 else if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
5981 && need_complete_non_reference
)
5983 error ("%qE has reference type for %qs", t
,
5984 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5988 if (need_implicitly_determined
)
5990 const char *share_name
= NULL
;
5992 if (VAR_P (t
) && DECL_THREAD_LOCAL_P (t
))
5993 share_name
= "threadprivate";
5994 else switch (cxx_omp_predetermined_sharing (t
))
5996 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
5998 case OMP_CLAUSE_DEFAULT_SHARED
:
5999 /* const vars may be specified in firstprivate clause. */
6000 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
6001 && cxx_omp_const_qual_no_mutable (t
))
6003 share_name
= "shared";
6005 case OMP_CLAUSE_DEFAULT_PRIVATE
:
6006 share_name
= "private";
6013 error ("%qE is predetermined %qs for %qs",
6014 t
, share_name
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6019 /* We're interested in the base element, not arrays. */
6020 inner_type
= type
= TREE_TYPE (t
);
6021 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
6022 inner_type
= TREE_TYPE (inner_type
);
6024 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6025 && TREE_CODE (inner_type
) == REFERENCE_TYPE
)
6026 inner_type
= TREE_TYPE (inner_type
);
6028 /* Check for special function availability by building a call to one.
6029 Save the results, because later we won't be in the right context
6030 for making these queries. */
6031 if (CLASS_TYPE_P (inner_type
)
6032 && COMPLETE_TYPE_P (inner_type
)
6033 && (need_default_ctor
|| need_copy_ctor
6034 || need_copy_assignment
|| need_dtor
)
6035 && !type_dependent_expression_p (t
)
6036 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
6037 need_copy_ctor
, need_copy_assignment
,
6042 *pc
= OMP_CLAUSE_CHAIN (c
);
6044 pc
= &OMP_CLAUSE_CHAIN (c
);
6047 bitmap_obstack_release (NULL
);
6051 /* For all variables in the tree_list VARS, mark them as thread local. */
6054 finish_omp_threadprivate (tree vars
)
6058 /* Mark every variable in VARS to be assigned thread local storage. */
6059 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
6061 tree v
= TREE_PURPOSE (t
);
6063 if (error_operand_p (v
))
6065 else if (!VAR_P (v
))
6066 error ("%<threadprivate%> %qD is not file, namespace "
6067 "or block scope variable", v
);
6068 /* If V had already been marked threadprivate, it doesn't matter
6069 whether it had been used prior to this point. */
6070 else if (TREE_USED (v
)
6071 && (DECL_LANG_SPECIFIC (v
) == NULL
6072 || !CP_DECL_THREADPRIVATE_P (v
)))
6073 error ("%qE declared %<threadprivate%> after first use", v
);
6074 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
6075 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
6076 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
6077 error ("%<threadprivate%> %qE has incomplete type", v
);
6078 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
6079 && CP_DECL_CONTEXT (v
) != current_class_type
)
6080 error ("%<threadprivate%> %qE directive not "
6081 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
6084 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
6085 if (DECL_LANG_SPECIFIC (v
) == NULL
)
6087 retrofit_lang_decl (v
);
6089 /* Make sure that DECL_DISCRIMINATOR_P continues to be true
6090 after the allocation of the lang_decl structure. */
6091 if (DECL_DISCRIMINATOR_P (v
))
6092 DECL_LANG_SPECIFIC (v
)->u
.base
.u2sel
= 1;
6095 if (! DECL_THREAD_LOCAL_P (v
))
6097 set_decl_tls_model (v
, decl_default_tls_model (v
));
6098 /* If rtl has been already set for this var, call
6099 make_decl_rtl once again, so that encode_section_info
6100 has a chance to look at the new decl flags. */
6101 if (DECL_RTL_SET_P (v
))
6104 CP_DECL_THREADPRIVATE_P (v
) = 1;
6109 /* Build an OpenMP structured block. */
6112 begin_omp_structured_block (void)
6114 return do_pushlevel (sk_omp
);
6118 finish_omp_structured_block (tree block
)
6120 return do_poplevel (block
);
6123 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
6124 statement. LOC is the location of the OACC_DATA. */
6127 finish_oacc_data (tree clauses
, tree block
)
6131 block
= finish_omp_structured_block (block
);
6133 stmt
= make_node (OACC_DATA
);
6134 TREE_TYPE (stmt
) = void_type_node
;
6135 OACC_DATA_CLAUSES (stmt
) = clauses
;
6136 OACC_DATA_BODY (stmt
) = block
;
6138 return add_stmt (stmt
);
6141 /* Generate OACC_KERNELS, with CLAUSES and BLOCK as its compound
6142 statement. LOC is the location of the OACC_KERNELS. */
6145 finish_oacc_kernels (tree clauses
, tree block
)
6149 block
= finish_omp_structured_block (block
);
6151 stmt
= make_node (OACC_KERNELS
);
6152 TREE_TYPE (stmt
) = void_type_node
;
6153 OACC_KERNELS_CLAUSES (stmt
) = clauses
;
6154 OACC_KERNELS_BODY (stmt
) = block
;
6156 return add_stmt (stmt
);
6159 /* Generate OACC_PARALLEL, with CLAUSES and BLOCK as its compound
6160 statement. LOC is the location of the OACC_PARALLEL. */
6163 finish_oacc_parallel (tree clauses
, tree block
)
6167 block
= finish_omp_structured_block (block
);
6169 stmt
= make_node (OACC_PARALLEL
);
6170 TREE_TYPE (stmt
) = void_type_node
;
6171 OACC_PARALLEL_CLAUSES (stmt
) = clauses
;
6172 OACC_PARALLEL_BODY (stmt
) = block
;
6174 return add_stmt (stmt
);
6177 /* Similarly, except force the retention of the BLOCK. */
6180 begin_omp_parallel (void)
6182 keep_next_level (true);
6183 return begin_omp_structured_block ();
6187 finish_omp_parallel (tree clauses
, tree body
)
6191 body
= finish_omp_structured_block (body
);
6193 stmt
= make_node (OMP_PARALLEL
);
6194 TREE_TYPE (stmt
) = void_type_node
;
6195 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
6196 OMP_PARALLEL_BODY (stmt
) = body
;
6198 return add_stmt (stmt
);
6202 begin_omp_task (void)
6204 keep_next_level (true);
6205 return begin_omp_structured_block ();
6209 finish_omp_task (tree clauses
, tree body
)
6213 body
= finish_omp_structured_block (body
);
6215 stmt
= make_node (OMP_TASK
);
6216 TREE_TYPE (stmt
) = void_type_node
;
6217 OMP_TASK_CLAUSES (stmt
) = clauses
;
6218 OMP_TASK_BODY (stmt
) = body
;
6220 return add_stmt (stmt
);
6223 /* Helper function for finish_omp_for. Convert Ith random access iterator
6224 into integral iterator. Return FALSE if successful. */
6227 handle_omp_for_class_iterator (int i
, location_t locus
, tree declv
, tree initv
,
6228 tree condv
, tree incrv
, tree
*body
,
6229 tree
*pre_body
, tree clauses
, tree
*lastp
)
6231 tree diff
, iter_init
, iter_incr
= NULL
, last
;
6232 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
6233 tree decl
= TREE_VEC_ELT (declv
, i
);
6234 tree init
= TREE_VEC_ELT (initv
, i
);
6235 tree cond
= TREE_VEC_ELT (condv
, i
);
6236 tree incr
= TREE_VEC_ELT (incrv
, i
);
6238 location_t elocus
= locus
;
6240 if (init
&& EXPR_HAS_LOCATION (init
))
6241 elocus
= EXPR_LOCATION (init
);
6243 switch (TREE_CODE (cond
))
6250 if (TREE_OPERAND (cond
, 1) == iter
)
6251 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
6252 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
6253 if (TREE_OPERAND (cond
, 0) != iter
)
6254 cond
= error_mark_node
;
6257 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
6260 TREE_OPERAND (cond
, 1), ERROR_MARK
,
6261 NULL
, tf_warning_or_error
);
6262 if (error_operand_p (tem
))
6267 cond
= error_mark_node
;
6270 if (cond
== error_mark_node
)
6272 error_at (elocus
, "invalid controlling predicate");
6275 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
6276 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
6277 tf_warning_or_error
);
6278 if (error_operand_p (diff
))
6280 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
6282 error_at (elocus
, "difference between %qE and %qD does not have integer type",
6283 TREE_OPERAND (cond
, 1), iter
);
6287 switch (TREE_CODE (incr
))
6289 case PREINCREMENT_EXPR
:
6290 case PREDECREMENT_EXPR
:
6291 case POSTINCREMENT_EXPR
:
6292 case POSTDECREMENT_EXPR
:
6293 if (TREE_OPERAND (incr
, 0) != iter
)
6295 incr
= error_mark_node
;
6298 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
6299 TREE_CODE (incr
), iter
,
6300 tf_warning_or_error
);
6301 if (error_operand_p (iter_incr
))
6303 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
6304 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
6305 incr
= integer_one_node
;
6307 incr
= integer_minus_one_node
;
6310 if (TREE_OPERAND (incr
, 0) != iter
)
6311 incr
= error_mark_node
;
6312 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
6313 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
6315 tree rhs
= TREE_OPERAND (incr
, 1);
6316 if (TREE_OPERAND (rhs
, 0) == iter
)
6318 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
6320 incr
= error_mark_node
;
6323 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
6324 iter
, TREE_CODE (rhs
),
6325 TREE_OPERAND (rhs
, 1),
6326 tf_warning_or_error
);
6327 if (error_operand_p (iter_incr
))
6329 incr
= TREE_OPERAND (rhs
, 1);
6330 incr
= cp_convert (TREE_TYPE (diff
), incr
,
6331 tf_warning_or_error
);
6332 if (TREE_CODE (rhs
) == MINUS_EXPR
)
6334 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
6335 incr
= fold_if_not_in_template (incr
);
6337 if (TREE_CODE (incr
) != INTEGER_CST
6338 && (TREE_CODE (incr
) != NOP_EXPR
6339 || (TREE_CODE (TREE_OPERAND (incr
, 0))
6344 else if (TREE_OPERAND (rhs
, 1) == iter
)
6346 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
6347 || TREE_CODE (rhs
) != PLUS_EXPR
)
6348 incr
= error_mark_node
;
6351 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
6353 TREE_OPERAND (rhs
, 0),
6356 tf_warning_or_error
);
6357 if (error_operand_p (iter_incr
))
6359 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
6362 tf_warning_or_error
);
6363 if (error_operand_p (iter_incr
))
6365 incr
= TREE_OPERAND (rhs
, 0);
6370 incr
= error_mark_node
;
6373 incr
= error_mark_node
;
6376 incr
= error_mark_node
;
6380 if (incr
== error_mark_node
)
6382 error_at (elocus
, "invalid increment expression");
6386 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
6387 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6388 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
6389 && OMP_CLAUSE_DECL (c
) == iter
)
6392 decl
= create_temporary_var (TREE_TYPE (diff
));
6394 add_decl_expr (decl
);
6395 last
= create_temporary_var (TREE_TYPE (diff
));
6397 add_decl_expr (last
);
6398 if (c
&& iter_incr
== NULL
)
6400 incr_var
= create_temporary_var (TREE_TYPE (diff
));
6401 pushdecl (incr_var
);
6402 add_decl_expr (incr_var
);
6404 gcc_assert (stmts_are_full_exprs_p ());
6406 orig_pre_body
= *pre_body
;
6407 *pre_body
= push_stmt_list ();
6409 add_stmt (orig_pre_body
);
6411 finish_expr_stmt (build_x_modify_expr (elocus
,
6412 iter
, NOP_EXPR
, init
,
6413 tf_warning_or_error
));
6414 init
= build_int_cst (TREE_TYPE (diff
), 0);
6415 if (c
&& iter_incr
== NULL
)
6417 finish_expr_stmt (build_x_modify_expr (elocus
,
6419 incr
, tf_warning_or_error
));
6421 iter_incr
= build_x_modify_expr (elocus
,
6422 iter
, PLUS_EXPR
, incr
,
6423 tf_warning_or_error
);
6425 finish_expr_stmt (build_x_modify_expr (elocus
,
6426 last
, NOP_EXPR
, init
,
6427 tf_warning_or_error
));
6428 *pre_body
= pop_stmt_list (*pre_body
);
6430 cond
= cp_build_binary_op (elocus
,
6431 TREE_CODE (cond
), decl
, diff
,
6432 tf_warning_or_error
);
6433 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
6434 elocus
, incr
, NULL_TREE
);
6437 *body
= push_stmt_list ();
6438 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
6439 iter_init
= build_x_modify_expr (elocus
,
6440 iter
, PLUS_EXPR
, iter_init
,
6441 tf_warning_or_error
);
6442 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
6443 finish_expr_stmt (iter_init
);
6444 finish_expr_stmt (build_x_modify_expr (elocus
,
6445 last
, NOP_EXPR
, decl
,
6446 tf_warning_or_error
));
6447 add_stmt (orig_body
);
6448 *body
= pop_stmt_list (*body
);
6452 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
6453 finish_expr_stmt (iter_incr
);
6454 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
6455 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
6458 TREE_VEC_ELT (declv
, i
) = decl
;
6459 TREE_VEC_ELT (initv
, i
) = init
;
6460 TREE_VEC_ELT (condv
, i
) = cond
;
6461 TREE_VEC_ELT (incrv
, i
) = incr
;
6467 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
6468 are directly for their associated operands in the statement. DECL
6469 and INIT are a combo; if DECL is NULL then INIT ought to be a
6470 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
6471 optional statements that need to go before the loop into its
6475 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
, tree initv
,
6476 tree condv
, tree incrv
, tree body
, tree pre_body
, tree clauses
)
6478 tree omp_for
= NULL
, orig_incr
= NULL
;
6479 tree decl
= NULL
, init
, cond
, incr
, orig_decl
= NULL_TREE
, block
= NULL_TREE
;
6480 tree last
= NULL_TREE
;
6484 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
6485 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
6486 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
6487 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
6489 decl
= TREE_VEC_ELT (declv
, i
);
6490 init
= TREE_VEC_ELT (initv
, i
);
6491 cond
= TREE_VEC_ELT (condv
, i
);
6492 incr
= TREE_VEC_ELT (incrv
, i
);
6498 switch (TREE_CODE (init
))
6501 decl
= TREE_OPERAND (init
, 0);
6502 init
= TREE_OPERAND (init
, 1);
6505 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
6507 decl
= TREE_OPERAND (init
, 0);
6508 init
= TREE_OPERAND (init
, 2);
6518 "expected iteration declaration or initialization");
6523 if (init
&& EXPR_HAS_LOCATION (init
))
6524 elocus
= EXPR_LOCATION (init
);
6528 error_at (elocus
, "missing controlling predicate");
6534 error_at (elocus
, "missing increment expression");
6538 TREE_VEC_ELT (declv
, i
) = decl
;
6539 TREE_VEC_ELT (initv
, i
) = init
;
6542 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
6546 stmt
= make_node (code
);
6548 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
6550 /* This is really just a place-holder. We'll be decomposing this
6551 again and going through the cp_build_modify_expr path below when
6552 we instantiate the thing. */
6553 TREE_VEC_ELT (initv
, i
)
6554 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
6555 TREE_VEC_ELT (initv
, i
));
6558 TREE_TYPE (stmt
) = void_type_node
;
6559 OMP_FOR_INIT (stmt
) = initv
;
6560 OMP_FOR_COND (stmt
) = condv
;
6561 OMP_FOR_INCR (stmt
) = incrv
;
6562 OMP_FOR_BODY (stmt
) = body
;
6563 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
6564 OMP_FOR_CLAUSES (stmt
) = clauses
;
6566 SET_EXPR_LOCATION (stmt
, locus
);
6567 return add_stmt (stmt
);
6570 if (processing_template_decl
)
6571 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
6573 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
6575 decl
= TREE_VEC_ELT (declv
, i
);
6576 init
= TREE_VEC_ELT (initv
, i
);
6577 cond
= TREE_VEC_ELT (condv
, i
);
6578 incr
= TREE_VEC_ELT (incrv
, i
);
6580 TREE_VEC_ELT (orig_incr
, i
) = incr
;
6583 if (init
&& EXPR_HAS_LOCATION (init
))
6584 elocus
= EXPR_LOCATION (init
);
6588 error_at (elocus
, "expected iteration declaration or initialization");
6592 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
6595 TREE_VEC_ELT (orig_incr
, i
) = incr
;
6596 incr
= cp_build_modify_expr (TREE_OPERAND (incr
, 0),
6597 TREE_CODE (TREE_OPERAND (incr
, 1)),
6598 TREE_OPERAND (incr
, 2),
6599 tf_warning_or_error
);
6602 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
6604 if (code
== OMP_SIMD
)
6606 error_at (elocus
, "%<#pragma omp simd%> used with class "
6607 "iteration variable %qE", decl
);
6610 if (code
== CILK_FOR
&& i
== 0)
6612 if (handle_omp_for_class_iterator (i
, locus
, declv
, initv
, condv
,
6613 incrv
, &body
, &pre_body
,
6619 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
6620 && !TYPE_PTR_P (TREE_TYPE (decl
)))
6622 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
6626 if (!processing_template_decl
)
6628 init
= fold_build_cleanup_point_expr (TREE_TYPE (init
), init
);
6629 init
= cp_build_modify_expr (decl
, NOP_EXPR
, init
, tf_warning_or_error
);
6632 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
6634 && TREE_SIDE_EFFECTS (cond
)
6635 && COMPARISON_CLASS_P (cond
)
6636 && !processing_template_decl
)
6638 tree t
= TREE_OPERAND (cond
, 0);
6639 if (TREE_SIDE_EFFECTS (t
)
6641 && (TREE_CODE (t
) != NOP_EXPR
6642 || TREE_OPERAND (t
, 0) != decl
))
6643 TREE_OPERAND (cond
, 0)
6644 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6646 t
= TREE_OPERAND (cond
, 1);
6647 if (TREE_SIDE_EFFECTS (t
)
6649 && (TREE_CODE (t
) != NOP_EXPR
6650 || TREE_OPERAND (t
, 0) != decl
))
6651 TREE_OPERAND (cond
, 1)
6652 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6654 if (decl
== error_mark_node
|| init
== error_mark_node
)
6657 TREE_VEC_ELT (declv
, i
) = decl
;
6658 TREE_VEC_ELT (initv
, i
) = init
;
6659 TREE_VEC_ELT (condv
, i
) = cond
;
6660 TREE_VEC_ELT (incrv
, i
) = incr
;
6664 if (IS_EMPTY_STMT (pre_body
))
6667 if (code
== CILK_FOR
&& !processing_template_decl
)
6668 block
= push_stmt_list ();
6670 omp_for
= c_finish_omp_for (locus
, code
, declv
, initv
, condv
, incrv
,
6673 if (omp_for
== NULL
)
6676 pop_stmt_list (block
);
6680 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
6682 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
), 0);
6683 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
6685 if (TREE_CODE (incr
) != MODIFY_EXPR
)
6688 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
6689 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
6690 && !processing_template_decl
)
6692 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
6693 if (TREE_SIDE_EFFECTS (t
)
6695 && (TREE_CODE (t
) != NOP_EXPR
6696 || TREE_OPERAND (t
, 0) != decl
))
6697 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
6698 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6700 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
6701 if (TREE_SIDE_EFFECTS (t
)
6703 && (TREE_CODE (t
) != NOP_EXPR
6704 || TREE_OPERAND (t
, 0) != decl
))
6705 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
6706 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6710 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
6712 OMP_FOR_CLAUSES (omp_for
) = clauses
;
6716 tree omp_par
= make_node (OMP_PARALLEL
);
6717 TREE_TYPE (omp_par
) = void_type_node
;
6718 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
6719 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
6720 TREE_SIDE_EFFECTS (bind
) = 1;
6721 BIND_EXPR_BODY (bind
) = pop_stmt_list (block
);
6722 OMP_PARALLEL_BODY (omp_par
) = bind
;
6723 if (OMP_FOR_PRE_BODY (omp_for
))
6725 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
6726 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
6728 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
6729 decl
= TREE_OPERAND (init
, 0);
6730 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
6731 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
6732 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
, *pc
;
6733 clauses
= OMP_FOR_CLAUSES (omp_for
);
6734 OMP_FOR_CLAUSES (omp_for
) = NULL_TREE
;
6735 for (pc
= &clauses
; *pc
; )
6736 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_SCHEDULE
)
6738 gcc_assert (OMP_FOR_CLAUSES (omp_for
) == NULL_TREE
);
6739 OMP_FOR_CLAUSES (omp_for
) = *pc
;
6740 *pc
= OMP_CLAUSE_CHAIN (*pc
);
6741 OMP_CLAUSE_CHAIN (OMP_FOR_CLAUSES (omp_for
)) = NULL_TREE
;
6745 gcc_assert (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_FIRSTPRIVATE
);
6746 pc
= &OMP_CLAUSE_CHAIN (*pc
);
6748 if (TREE_CODE (t
) != INTEGER_CST
)
6750 TREE_OPERAND (cond
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
6751 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6752 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
6753 OMP_CLAUSE_CHAIN (c
) = clauses
;
6756 if (TREE_CODE (incr
) == MODIFY_EXPR
)
6758 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
6759 if (TREE_CODE (t
) != INTEGER_CST
)
6761 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
6762 = get_temp_regvar (TREE_TYPE (t
), t
);
6763 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6764 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
6765 OMP_CLAUSE_CHAIN (c
) = clauses
;
6769 t
= TREE_OPERAND (init
, 1);
6770 if (TREE_CODE (t
) != INTEGER_CST
)
6772 TREE_OPERAND (init
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
6773 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6774 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
6775 OMP_CLAUSE_CHAIN (c
) = clauses
;
6778 if (orig_decl
&& orig_decl
!= decl
)
6780 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6781 OMP_CLAUSE_DECL (c
) = orig_decl
;
6782 OMP_CLAUSE_CHAIN (c
) = clauses
;
6787 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6788 OMP_CLAUSE_DECL (c
) = last
;
6789 OMP_CLAUSE_CHAIN (c
) = clauses
;
6792 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
6793 OMP_CLAUSE_DECL (c
) = decl
;
6794 OMP_CLAUSE_CHAIN (c
) = clauses
;
6796 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
6797 OMP_CLAUSE_OPERAND (c
, 0)
6798 = cilk_for_number_of_iterations (omp_for
);
6799 OMP_CLAUSE_CHAIN (c
) = clauses
;
6800 OMP_PARALLEL_CLAUSES (omp_par
) = finish_omp_clauses (c
);
6804 else if (code
== CILK_FOR
&& processing_template_decl
)
6806 tree c
, clauses
= OMP_FOR_CLAUSES (omp_for
);
6807 if (orig_decl
&& orig_decl
!= decl
)
6809 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6810 OMP_CLAUSE_DECL (c
) = orig_decl
;
6811 OMP_CLAUSE_CHAIN (c
) = clauses
;
6816 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6817 OMP_CLAUSE_DECL (c
) = last
;
6818 OMP_CLAUSE_CHAIN (c
) = clauses
;
6821 OMP_FOR_CLAUSES (omp_for
) = clauses
;
6827 finish_omp_atomic (enum tree_code code
, enum tree_code opcode
, tree lhs
,
6828 tree rhs
, tree v
, tree lhs1
, tree rhs1
, bool seq_cst
)
6843 dependent_p
= false;
6846 /* Even in a template, we can detect invalid uses of the atomic
6847 pragma if neither LHS nor RHS is type-dependent. */
6848 if (processing_template_decl
)
6850 dependent_p
= (type_dependent_expression_p (lhs
)
6851 || (rhs
&& type_dependent_expression_p (rhs
))
6852 || (v
&& type_dependent_expression_p (v
))
6853 || (lhs1
&& type_dependent_expression_p (lhs1
))
6854 || (rhs1
&& type_dependent_expression_p (rhs1
)));
6857 lhs
= build_non_dependent_expr (lhs
);
6859 rhs
= build_non_dependent_expr (rhs
);
6861 v
= build_non_dependent_expr (v
);
6863 lhs1
= build_non_dependent_expr (lhs1
);
6865 rhs1
= build_non_dependent_expr (rhs1
);
6870 bool swapped
= false;
6871 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
6873 std::swap (rhs
, rhs1
);
6874 swapped
= !commutative_tree_code (opcode
);
6876 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
6878 if (code
== OMP_ATOMIC
)
6879 error ("%<#pragma omp atomic update%> uses two different "
6880 "expressions for memory");
6882 error ("%<#pragma omp atomic capture%> uses two different "
6883 "expressions for memory");
6886 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
6888 if (code
== OMP_ATOMIC
)
6889 error ("%<#pragma omp atomic update%> uses two different "
6890 "expressions for memory");
6892 error ("%<#pragma omp atomic capture%> uses two different "
6893 "expressions for memory");
6896 stmt
= c_finish_omp_atomic (input_location
, code
, opcode
, lhs
, rhs
,
6897 v
, lhs1
, rhs1
, swapped
, seq_cst
);
6898 if (stmt
== error_mark_node
)
6901 if (processing_template_decl
)
6903 if (code
== OMP_ATOMIC_READ
)
6905 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs
),
6906 OMP_ATOMIC_READ
, orig_lhs
);
6907 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
6908 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
6912 if (opcode
== NOP_EXPR
)
6913 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
6915 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
6917 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
6918 COMPOUND_EXPR
, orig_rhs1
, stmt
);
6919 if (code
!= OMP_ATOMIC
)
6921 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs1
),
6922 code
, orig_lhs1
, stmt
);
6923 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
6924 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
6927 stmt
= build2 (OMP_ATOMIC
, void_type_node
, integer_zero_node
, stmt
);
6928 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
6930 finish_expr_stmt (stmt
);
6934 finish_omp_barrier (void)
6936 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
6937 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6938 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6939 release_tree_vector (vec
);
6940 finish_expr_stmt (stmt
);
6944 finish_omp_flush (void)
6946 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
6947 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6948 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6949 release_tree_vector (vec
);
6950 finish_expr_stmt (stmt
);
6954 finish_omp_taskwait (void)
6956 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
6957 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6958 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6959 release_tree_vector (vec
);
6960 finish_expr_stmt (stmt
);
6964 finish_omp_taskyield (void)
6966 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
6967 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6968 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6969 release_tree_vector (vec
);
6970 finish_expr_stmt (stmt
);
6974 finish_omp_cancel (tree clauses
)
6976 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
6978 if (find_omp_clause (clauses
, OMP_CLAUSE_PARALLEL
))
6980 else if (find_omp_clause (clauses
, OMP_CLAUSE_FOR
))
6982 else if (find_omp_clause (clauses
, OMP_CLAUSE_SECTIONS
))
6984 else if (find_omp_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
6988 error ("%<#pragma omp cancel must specify one of "
6989 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
6992 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6993 tree ifc
= find_omp_clause (clauses
, OMP_CLAUSE_IF
);
6994 if (ifc
!= NULL_TREE
)
6996 tree type
= TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc
));
6997 ifc
= fold_build2_loc (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
6998 boolean_type_node
, OMP_CLAUSE_IF_EXPR (ifc
),
6999 build_zero_cst (type
));
7002 ifc
= boolean_true_node
;
7003 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
7004 vec
->quick_push (ifc
);
7005 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
7006 release_tree_vector (vec
);
7007 finish_expr_stmt (stmt
);
7011 finish_omp_cancellation_point (tree clauses
)
7013 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
7015 if (find_omp_clause (clauses
, OMP_CLAUSE_PARALLEL
))
7017 else if (find_omp_clause (clauses
, OMP_CLAUSE_FOR
))
7019 else if (find_omp_clause (clauses
, OMP_CLAUSE_SECTIONS
))
7021 else if (find_omp_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
7025 error ("%<#pragma omp cancellation point must specify one of "
7026 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
7029 vec
<tree
, va_gc
> *vec
7030 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
7031 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
7032 release_tree_vector (vec
);
7033 finish_expr_stmt (stmt
);
7036 /* Begin a __transaction_atomic or __transaction_relaxed statement.
7037 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
7038 should create an extra compound stmt. */
7041 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
7046 *pcompound
= begin_compound_stmt (0);
7048 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
7050 /* Only add the statement to the function if support enabled. */
7054 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
7055 ? G_("%<__transaction_relaxed%> without "
7056 "transactional memory support enabled")
7057 : G_("%<__transaction_atomic%> without "
7058 "transactional memory support enabled")));
7060 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
7061 TREE_SIDE_EFFECTS (r
) = 1;
7065 /* End a __transaction_atomic or __transaction_relaxed statement.
7066 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
7067 and we should end the compound. If NOEX is non-NULL, we wrap the body in
7068 a MUST_NOT_THROW_EXPR with NOEX as condition. */
7071 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
7073 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
7074 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
7075 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
7076 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
7078 /* noexcept specifications are not allowed for function transactions. */
7079 gcc_assert (!(noex
&& compound_stmt
));
7082 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
7084 /* This may not be true when the STATEMENT_LIST is empty. */
7086 SET_EXPR_LOCATION (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
7087 TREE_SIDE_EFFECTS (body
) = 1;
7088 TRANSACTION_EXPR_BODY (stmt
) = body
;
7092 finish_compound_stmt (compound_stmt
);
7095 /* Build a __transaction_atomic or __transaction_relaxed expression. If
7096 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
7100 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
7105 expr
= build_must_not_throw_expr (expr
, noex
);
7107 SET_EXPR_LOCATION (expr
, loc
);
7108 TREE_SIDE_EFFECTS (expr
) = 1;
7110 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
7111 if (flags
& TM_STMT_ATTR_RELAXED
)
7112 TRANSACTION_EXPR_RELAXED (ret
) = 1;
7113 TREE_SIDE_EFFECTS (ret
) = 1;
7114 SET_EXPR_LOCATION (ret
, loc
);
7119 init_cp_semantics (void)
7123 /* Build a STATIC_ASSERT for a static assertion with the condition
7124 CONDITION and the message text MESSAGE. LOCATION is the location
7125 of the static assertion in the source code. When MEMBER_P, this
7126 static assertion is a member of a class. */
7128 finish_static_assert (tree condition
, tree message
, location_t location
,
7131 if (message
== NULL_TREE
7132 || message
== error_mark_node
7133 || condition
== NULL_TREE
7134 || condition
== error_mark_node
)
7137 if (check_for_bare_parameter_packs (condition
))
7138 condition
= error_mark_node
;
7140 if (type_dependent_expression_p (condition
)
7141 || value_dependent_expression_p (condition
))
7143 /* We're in a template; build a STATIC_ASSERT and put it in
7147 assertion
= make_node (STATIC_ASSERT
);
7148 STATIC_ASSERT_CONDITION (assertion
) = condition
;
7149 STATIC_ASSERT_MESSAGE (assertion
) = message
;
7150 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
7153 maybe_add_class_template_decl_list (current_class_type
,
7157 add_stmt (assertion
);
7162 /* Fold the expression and convert it to a boolean value. */
7163 condition
= instantiate_non_dependent_expr (condition
);
7164 condition
= cp_convert (boolean_type_node
, condition
, tf_warning_or_error
);
7165 condition
= maybe_constant_value (condition
);
7167 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
7168 /* Do nothing; the condition is satisfied. */
7172 location_t saved_loc
= input_location
;
7174 input_location
= location
;
7175 if (TREE_CODE (condition
) == INTEGER_CST
7176 && integer_zerop (condition
))
7177 /* Report the error. */
7178 error ("static assertion failed: %s", TREE_STRING_POINTER (message
));
7179 else if (condition
&& condition
!= error_mark_node
)
7181 error ("non-constant condition for static assertion");
7182 if (require_potential_rvalue_constant_expression (condition
))
7183 cxx_constant_value (condition
);
7185 input_location
= saved_loc
;
7189 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
7190 suitable for use as a type-specifier.
7192 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
7193 id-expression or a class member access, FALSE when it was parsed as
7194 a full expression. */
7197 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
7198 tsubst_flags_t complain
)
7200 tree type
= NULL_TREE
;
7202 if (!expr
|| error_operand_p (expr
))
7203 return error_mark_node
;
7206 || TREE_CODE (expr
) == TYPE_DECL
7207 || (TREE_CODE (expr
) == BIT_NOT_EXPR
7208 && TYPE_P (TREE_OPERAND (expr
, 0))))
7210 if (complain
& tf_error
)
7211 error ("argument to decltype must be an expression");
7212 return error_mark_node
;
7215 /* Depending on the resolution of DR 1172, we may later need to distinguish
7216 instantiation-dependent but not type-dependent expressions so that, say,
7217 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
7218 if (instantiation_dependent_expression_p (expr
))
7220 type
= cxx_make_type (DECLTYPE_TYPE
);
7221 DECLTYPE_TYPE_EXPR (type
) = expr
;
7222 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
7223 = id_expression_or_member_access_p
;
7224 SET_TYPE_STRUCTURAL_EQUALITY (type
);
7229 /* The type denoted by decltype(e) is defined as follows: */
7231 expr
= resolve_nondeduced_context (expr
);
7233 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
7234 return error_mark_node
;
7236 if (type_unknown_p (expr
))
7238 if (complain
& tf_error
)
7239 error ("decltype cannot resolve address of overloaded function");
7240 return error_mark_node
;
7243 /* To get the size of a static data member declared as an array of
7244 unknown bound, we need to instantiate it. */
7246 && VAR_HAD_UNKNOWN_BOUND (expr
)
7247 && DECL_TEMPLATE_INSTANTIATION (expr
))
7248 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
7250 if (id_expression_or_member_access_p
)
7252 /* If e is an id-expression or a class member access (5.2.5
7253 [expr.ref]), decltype(e) is defined as the type of the entity
7254 named by e. If there is no such entity, or e names a set of
7255 overloaded functions, the program is ill-formed. */
7256 if (identifier_p (expr
))
7257 expr
= lookup_name (expr
);
7259 if (INDIRECT_REF_P (expr
))
7260 /* This can happen when the expression is, e.g., "a.b". Just
7261 look at the underlying operand. */
7262 expr
= TREE_OPERAND (expr
, 0);
7264 if (TREE_CODE (expr
) == OFFSET_REF
7265 || TREE_CODE (expr
) == MEMBER_REF
7266 || TREE_CODE (expr
) == SCOPE_REF
)
7267 /* We're only interested in the field itself. If it is a
7268 BASELINK, we will need to see through it in the next
7270 expr
= TREE_OPERAND (expr
, 1);
7272 if (BASELINK_P (expr
))
7273 /* See through BASELINK nodes to the underlying function. */
7274 expr
= BASELINK_FUNCTIONS (expr
);
7276 switch (TREE_CODE (expr
))
7279 if (DECL_BIT_FIELD_TYPE (expr
))
7281 type
= DECL_BIT_FIELD_TYPE (expr
);
7284 /* Fall through for fields that aren't bitfields. */
7291 case TEMPLATE_PARM_INDEX
:
7292 expr
= mark_type_use (expr
);
7293 type
= TREE_TYPE (expr
);
7297 type
= error_mark_node
;
7302 mark_type_use (expr
);
7303 type
= is_bitfield_expr_with_lowered_type (expr
);
7305 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
7313 /* We can get here when the id-expression refers to an
7314 enumerator or non-type template parameter. */
7315 type
= TREE_TYPE (expr
);
7319 /* Handle instantiated template non-type arguments. */
7320 type
= TREE_TYPE (expr
);
7326 /* Within a lambda-expression:
7328 Every occurrence of decltype((x)) where x is a possibly
7329 parenthesized id-expression that names an entity of
7330 automatic storage duration is treated as if x were
7331 transformed into an access to a corresponding data member
7332 of the closure type that would have been declared if x
7333 were a use of the denoted entity. */
7334 if (outer_automatic_var_p (expr
)
7335 && current_function_decl
7336 && LAMBDA_FUNCTION_P (current_function_decl
))
7337 type
= capture_decltype (expr
);
7338 else if (error_operand_p (expr
))
7339 type
= error_mark_node
;
7340 else if (expr
== current_class_ptr
)
7341 /* If the expression is just "this", we want the
7342 cv-unqualified pointer for the "this" type. */
7343 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
7346 /* Otherwise, where T is the type of e, if e is an lvalue,
7347 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
7348 cp_lvalue_kind clk
= lvalue_kind (expr
);
7349 type
= unlowered_expr_type (expr
);
7350 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
7352 /* For vector types, pick a non-opaque variant. */
7353 if (TREE_CODE (type
) == VECTOR_TYPE
)
7354 type
= strip_typedefs (type
);
7356 if (clk
!= clk_none
&& !(clk
& clk_class
))
7357 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
7364 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
7365 __has_nothrow_copy, depending on assign_p. */
7368 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
7375 ix
= lookup_fnfields_1 (type
, ansi_assopname (NOP_EXPR
));
7378 fns
= (*CLASSTYPE_METHOD_VEC (type
))[ix
];
7380 else if (TYPE_HAS_COPY_CTOR (type
))
7382 /* If construction of the copy constructor was postponed, create
7384 if (CLASSTYPE_LAZY_COPY_CTOR (type
))
7385 lazily_declare_fn (sfk_copy_constructor
, type
);
7386 if (CLASSTYPE_LAZY_MOVE_CTOR (type
))
7387 lazily_declare_fn (sfk_move_constructor
, type
);
7388 fns
= CLASSTYPE_CONSTRUCTORS (type
);
7393 for (; fns
; fns
= OVL_NEXT (fns
))
7395 tree fn
= OVL_CURRENT (fns
);
7399 if (copy_fn_p (fn
) == 0)
7402 else if (copy_fn_p (fn
) <= 0)
7405 maybe_instantiate_noexcept (fn
);
7406 if (!TYPE_NOTHROW_P (TREE_TYPE (fn
)))
7413 /* Actually evaluates the trait. */
7416 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
7418 enum tree_code type_code1
;
7421 type_code1
= TREE_CODE (type1
);
7425 case CPTK_HAS_NOTHROW_ASSIGN
:
7426 type1
= strip_array_types (type1
);
7427 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
7428 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
7429 || (CLASS_TYPE_P (type1
)
7430 && classtype_has_nothrow_assign_or_copy_p (type1
,
7433 case CPTK_HAS_TRIVIAL_ASSIGN
:
7434 /* ??? The standard seems to be missing the "or array of such a class
7435 type" wording for this trait. */
7436 type1
= strip_array_types (type1
);
7437 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
7438 && (trivial_type_p (type1
)
7439 || (CLASS_TYPE_P (type1
)
7440 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
7442 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
7443 type1
= strip_array_types (type1
);
7444 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
7445 || (CLASS_TYPE_P (type1
)
7446 && (t
= locate_ctor (type1
))
7447 && (maybe_instantiate_noexcept (t
),
7448 TYPE_NOTHROW_P (TREE_TYPE (t
)))));
7450 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
7451 type1
= strip_array_types (type1
);
7452 return (trivial_type_p (type1
)
7453 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
7455 case CPTK_HAS_NOTHROW_COPY
:
7456 type1
= strip_array_types (type1
);
7457 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
7458 || (CLASS_TYPE_P (type1
)
7459 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
7461 case CPTK_HAS_TRIVIAL_COPY
:
7462 /* ??? The standard seems to be missing the "or array of such a class
7463 type" wording for this trait. */
7464 type1
= strip_array_types (type1
);
7465 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
7466 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
7468 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
7469 type1
= strip_array_types (type1
);
7470 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
7471 || (CLASS_TYPE_P (type1
)
7472 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
7474 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
7475 return type_has_virtual_destructor (type1
);
7477 case CPTK_IS_ABSTRACT
:
7478 return (ABSTRACT_CLASS_TYPE_P (type1
));
7480 case CPTK_IS_BASE_OF
:
7481 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
7482 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
7483 || DERIVED_FROM_P (type1
, type2
)));
7486 return (NON_UNION_CLASS_TYPE_P (type1
));
7489 return (NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
));
7492 return (type_code1
== ENUMERAL_TYPE
);
7495 return (CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
));
7497 case CPTK_IS_LITERAL_TYPE
:
7498 return (literal_type_p (type1
));
7501 return (pod_type_p (type1
));
7503 case CPTK_IS_POLYMORPHIC
:
7504 return (CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
));
7506 case CPTK_IS_STD_LAYOUT
:
7507 return (std_layout_type_p (type1
));
7509 case CPTK_IS_TRIVIAL
:
7510 return (trivial_type_p (type1
));
7512 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
7513 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
7515 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
7516 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
7518 case CPTK_IS_TRIVIALLY_COPYABLE
:
7519 return (trivially_copyable_p (type1
));
7522 return (type_code1
== UNION_TYPE
);
7530 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
7531 void, or a complete type, returns true, otherwise false. */
7534 check_trait_type (tree type
)
7536 if (type
== NULL_TREE
)
7539 if (TREE_CODE (type
) == TREE_LIST
)
7540 return (check_trait_type (TREE_VALUE (type
))
7541 && check_trait_type (TREE_CHAIN (type
)));
7543 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
7544 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
7547 if (VOID_TYPE_P (type
))
7550 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
7553 /* Process a trait expression. */
7556 finish_trait_expr (cp_trait_kind kind
, tree type1
, tree type2
)
7558 if (type1
== error_mark_node
7559 || type2
== error_mark_node
)
7560 return error_mark_node
;
7562 if (processing_template_decl
)
7564 tree trait_expr
= make_node (TRAIT_EXPR
);
7565 TREE_TYPE (trait_expr
) = boolean_type_node
;
7566 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
7567 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
7568 TRAIT_EXPR_KIND (trait_expr
) = kind
;
7574 case CPTK_HAS_NOTHROW_ASSIGN
:
7575 case CPTK_HAS_TRIVIAL_ASSIGN
:
7576 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
7577 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
7578 case CPTK_HAS_NOTHROW_COPY
:
7579 case CPTK_HAS_TRIVIAL_COPY
:
7580 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
7581 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
7582 case CPTK_IS_ABSTRACT
:
7585 case CPTK_IS_LITERAL_TYPE
:
7587 case CPTK_IS_POLYMORPHIC
:
7588 case CPTK_IS_STD_LAYOUT
:
7589 case CPTK_IS_TRIVIAL
:
7590 case CPTK_IS_TRIVIALLY_COPYABLE
:
7591 if (!check_trait_type (type1
))
7592 return error_mark_node
;
7595 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
7596 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
7597 if (!check_trait_type (type1
)
7598 || !check_trait_type (type2
))
7599 return error_mark_node
;
7602 case CPTK_IS_BASE_OF
:
7603 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
7604 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
7605 && !complete_type_or_else (type2
, NULL_TREE
))
7606 /* We already issued an error. */
7607 return error_mark_node
;
7619 return (trait_expr_value (kind
, type1
, type2
)
7620 ? boolean_true_node
: boolean_false_node
);
7623 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
7624 which is ignored for C++. */
7627 set_float_const_decimal64 (void)
7632 clear_float_const_decimal64 (void)
7637 float_const_decimal64_p (void)
7643 /* Return true if T designates the implied `this' parameter. */
7646 is_this_parameter (tree t
)
7648 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
7650 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
));
7654 /* Insert the deduced return type for an auto function. */
7657 apply_deduced_return_type (tree fco
, tree return_type
)
7661 if (return_type
== error_mark_node
)
7664 if (LAMBDA_FUNCTION_P (fco
))
7666 tree lambda
= CLASSTYPE_LAMBDA_EXPR (current_class_type
);
7667 LAMBDA_EXPR_RETURN_TYPE (lambda
) = return_type
;
7670 if (DECL_CONV_FN_P (fco
))
7671 DECL_NAME (fco
) = mangle_conv_op_name_for_type (return_type
);
7673 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
7675 result
= DECL_RESULT (fco
);
7676 if (result
== NULL_TREE
)
7678 if (TREE_TYPE (result
) == return_type
)
7681 /* We already have a DECL_RESULT from start_preparsed_function.
7682 Now we need to redo the work it and allocate_struct_function
7683 did to reflect the new type. */
7684 gcc_assert (current_function_decl
== fco
);
7685 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
7686 TYPE_MAIN_VARIANT (return_type
));
7687 DECL_ARTIFICIAL (result
) = 1;
7688 DECL_IGNORED_P (result
) = 1;
7689 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
7692 DECL_RESULT (fco
) = result
;
7694 if (!processing_template_decl
)
7696 if (!VOID_TYPE_P (TREE_TYPE (result
)))
7697 complete_type_or_else (TREE_TYPE (result
), NULL_TREE
);
7698 bool aggr
= aggregate_value_p (result
, fco
);
7699 #ifdef PCC_STATIC_STRUCT_RETURN
7700 cfun
->returns_pcc_struct
= aggr
;
7702 cfun
->returns_struct
= aggr
;
7707 /* DECL is a local variable or parameter from the surrounding scope of a
7708 lambda-expression. Returns the decltype for a use of the capture field
7709 for DECL even if it hasn't been captured yet. */
7712 capture_decltype (tree decl
)
7714 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
7715 /* FIXME do lookup instead of list walk? */
7716 tree cap
= value_member (decl
, LAMBDA_EXPR_CAPTURE_LIST (lam
));
7720 type
= TREE_TYPE (TREE_PURPOSE (cap
));
7722 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
7725 error ("%qD is not captured", decl
);
7726 return error_mark_node
;
7729 type
= TREE_TYPE (decl
);
7730 if (TREE_CODE (type
) == REFERENCE_TYPE
7731 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
7732 type
= TREE_TYPE (type
);
7735 case CPLD_REFERENCE
:
7736 type
= TREE_TYPE (decl
);
7737 if (TREE_CODE (type
) != REFERENCE_TYPE
)
7738 type
= build_reference_type (TREE_TYPE (decl
));
7745 if (TREE_CODE (type
) != REFERENCE_TYPE
)
7747 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
7748 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
7750 type
= build_reference_type (type
);
7755 #include "gt-cp-semantics.h"