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-2014 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"
33 #include "stor-layout.h"
34 #include "stringpool.h"
36 #include "c-family/c-common.h"
37 #include "c-family/c-objc.h"
38 #include "tree-inline.h"
43 #include "diagnostic.h"
46 #include "plugin-api.h"
51 #include "hard-reg-set.h"
56 #include "tree-iterator.h"
58 #include "hash-table.h"
65 /* There routines provide a modular interface to perform many parsing
66 operations. They may therefore be used during actual parsing, or
67 during template instantiation, which may be regarded as a
68 degenerate form of parsing. */
70 static tree
maybe_convert_cond (tree
);
71 static tree
finalize_nrv_r (tree
*, int *, void *);
72 static tree
capture_decltype (tree
);
75 /* Deferred Access Checking Overview
76 ---------------------------------
78 Most C++ expressions and declarations require access checking
79 to be performed during parsing. However, in several cases,
80 this has to be treated differently.
82 For member declarations, access checking has to be deferred
83 until more information about the declaration is known. For
95 When we are parsing the function return type `A::X', we don't
96 really know if this is allowed until we parse the function name.
98 Furthermore, some contexts require that access checking is
99 never performed at all. These include class heads, and template
102 Typical use of access checking functions is described here:
104 1. When we enter a context that requires certain access checking
105 mode, the function `push_deferring_access_checks' is called with
106 DEFERRING argument specifying the desired mode. Access checking
107 may be performed immediately (dk_no_deferred), deferred
108 (dk_deferred), or not performed (dk_no_check).
110 2. When a declaration such as a type, or a variable, is encountered,
111 the function `perform_or_defer_access_check' is called. It
112 maintains a vector of all deferred checks.
114 3. The global `current_class_type' or `current_function_decl' is then
115 setup by the parser. `enforce_access' relies on these information
118 4. Upon exiting the context mentioned in step 1,
119 `perform_deferred_access_checks' is called to check all declaration
120 stored in the vector. `pop_deferring_access_checks' is then
121 called to restore the previous access checking mode.
123 In case of parsing error, we simply call `pop_deferring_access_checks'
124 without `perform_deferred_access_checks'. */
126 typedef struct GTY(()) deferred_access
{
127 /* A vector representing name-lookups for which we have deferred
128 checking access controls. We cannot check the accessibility of
129 names used in a decl-specifier-seq until we know what is being
130 declared because code like:
137 A::B* A::f() { return 0; }
139 is valid, even though `A::B' is not generally accessible. */
140 vec
<deferred_access_check
, va_gc
> * GTY(()) deferred_access_checks
;
142 /* The current mode of access checks. */
143 enum deferring_kind deferring_access_checks_kind
;
147 /* Data for deferred access checking. */
148 static GTY(()) vec
<deferred_access
, va_gc
> *deferred_access_stack
;
149 static GTY(()) unsigned deferred_access_no_check
;
151 /* Save the current deferred access states and start deferred
152 access checking iff DEFER_P is true. */
155 push_deferring_access_checks (deferring_kind deferring
)
157 /* For context like template instantiation, access checking
158 disabling applies to all nested context. */
159 if (deferred_access_no_check
|| deferring
== dk_no_check
)
160 deferred_access_no_check
++;
163 deferred_access e
= {NULL
, deferring
};
164 vec_safe_push (deferred_access_stack
, e
);
168 /* Save the current deferred access states and start deferred access
169 checking, continuing the set of deferred checks in CHECKS. */
172 reopen_deferring_access_checks (vec
<deferred_access_check
, va_gc
> * checks
)
174 push_deferring_access_checks (dk_deferred
);
175 if (!deferred_access_no_check
)
176 deferred_access_stack
->last().deferred_access_checks
= checks
;
179 /* Resume deferring access checks again after we stopped doing
183 resume_deferring_access_checks (void)
185 if (!deferred_access_no_check
)
186 deferred_access_stack
->last().deferring_access_checks_kind
= dk_deferred
;
189 /* Stop deferring access checks. */
192 stop_deferring_access_checks (void)
194 if (!deferred_access_no_check
)
195 deferred_access_stack
->last().deferring_access_checks_kind
= dk_no_deferred
;
198 /* Discard the current deferred access checks and restore the
202 pop_deferring_access_checks (void)
204 if (deferred_access_no_check
)
205 deferred_access_no_check
--;
207 deferred_access_stack
->pop ();
210 /* Returns a TREE_LIST representing the deferred checks.
211 The TREE_PURPOSE of each node is the type through which the
212 access occurred; the TREE_VALUE is the declaration named.
215 vec
<deferred_access_check
, va_gc
> *
216 get_deferred_access_checks (void)
218 if (deferred_access_no_check
)
221 return (deferred_access_stack
->last().deferred_access_checks
);
224 /* Take current deferred checks and combine with the
225 previous states if we also defer checks previously.
226 Otherwise perform checks now. */
229 pop_to_parent_deferring_access_checks (void)
231 if (deferred_access_no_check
)
232 deferred_access_no_check
--;
235 vec
<deferred_access_check
, va_gc
> *checks
;
236 deferred_access
*ptr
;
238 checks
= (deferred_access_stack
->last ().deferred_access_checks
);
240 deferred_access_stack
->pop ();
241 ptr
= &deferred_access_stack
->last ();
242 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
245 perform_access_checks (checks
, tf_warning_or_error
);
249 /* Merge with parent. */
251 deferred_access_check
*chk
, *probe
;
253 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
255 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, j
, probe
)
257 if (probe
->binfo
== chk
->binfo
&&
258 probe
->decl
== chk
->decl
&&
259 probe
->diag_decl
== chk
->diag_decl
)
262 /* Insert into parent's checks. */
263 vec_safe_push (ptr
->deferred_access_checks
, *chk
);
270 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
271 is the BINFO indicating the qualifying scope used to access the
272 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
273 or we aren't in SFINAE context or all the checks succeed return TRUE,
277 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
278 tsubst_flags_t complain
)
281 deferred_access_check
*chk
;
282 location_t loc
= input_location
;
288 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
290 input_location
= chk
->loc
;
291 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
294 input_location
= loc
;
295 return (complain
& tf_error
) ? true : ok
;
298 /* Perform the deferred access checks.
300 After performing the checks, we still have to keep the list
301 `deferred_access_stack->deferred_access_checks' since we may want
302 to check access for them again later in a different context.
309 A::X A::a, x; // No error for `A::a', error for `x'
311 We have to perform deferred access of `A::X', first with `A::a',
312 next with `x'. Return value like perform_access_checks above. */
315 perform_deferred_access_checks (tsubst_flags_t complain
)
317 return perform_access_checks (get_deferred_access_checks (), complain
);
320 /* Defer checking the accessibility of DECL, when looked up in
321 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
322 Return value like perform_access_checks above. */
325 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
326 tsubst_flags_t complain
)
329 deferred_access
*ptr
;
330 deferred_access_check
*chk
;
333 /* Exit if we are in a context that no access checking is performed.
335 if (deferred_access_no_check
)
338 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
340 ptr
= &deferred_access_stack
->last ();
342 /* If we are not supposed to defer access checks, just check now. */
343 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
345 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
);
346 return (complain
& tf_error
) ? true : ok
;
349 /* See if we are already going to perform this check. */
350 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
352 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
353 chk
->diag_decl
== diag_decl
)
358 /* If not, record the check. */
359 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
360 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
365 /* Returns nonzero if the current statement is a full expression,
366 i.e. temporaries created during that statement should be destroyed
367 at the end of the statement. */
370 stmts_are_full_exprs_p (void)
372 return current_stmt_tree ()->stmts_are_full_exprs_p
;
375 /* T is a statement. Add it to the statement-tree. This is the C++
376 version. The C/ObjC frontends have a slightly different version of
382 enum tree_code code
= TREE_CODE (t
);
384 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
386 if (!EXPR_HAS_LOCATION (t
))
387 SET_EXPR_LOCATION (t
, input_location
);
389 /* When we expand a statement-tree, we must know whether or not the
390 statements are full-expressions. We record that fact here. */
391 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
394 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
395 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
397 /* Add T to the statement-tree. Non-side-effect statements need to be
398 recorded during statement expressions. */
399 gcc_checking_assert (!stmt_list_stack
->is_empty ());
400 append_to_statement_list_force (t
, &cur_stmt_list
);
405 /* Returns the stmt_tree to which statements are currently being added. */
408 current_stmt_tree (void)
411 ? &cfun
->language
->base
.x_stmt_tree
412 : &scope_chain
->x_stmt_tree
);
415 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
418 maybe_cleanup_point_expr (tree expr
)
420 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
421 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
425 /* Like maybe_cleanup_point_expr except have the type of the new expression be
426 void so we don't need to create a temporary variable to hold the inner
427 expression. The reason why we do this is because the original type might be
428 an aggregate and we cannot create a temporary variable for that type. */
431 maybe_cleanup_point_expr_void (tree expr
)
433 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
434 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
440 /* Create a declaration statement for the declaration given by the DECL. */
443 add_decl_expr (tree decl
)
445 tree r
= build_stmt (input_location
, DECL_EXPR
, decl
);
446 if (DECL_INITIAL (decl
)
447 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
448 r
= maybe_cleanup_point_expr_void (r
);
452 /* Finish a scope. */
455 do_poplevel (tree stmt_list
)
459 if (stmts_are_full_exprs_p ())
460 block
= poplevel (kept_level_p (), 1, 0);
462 stmt_list
= pop_stmt_list (stmt_list
);
464 if (!processing_template_decl
)
466 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
467 /* ??? See c_end_compound_stmt re statement expressions. */
473 /* Begin a new scope. */
476 do_pushlevel (scope_kind sk
)
478 tree ret
= push_stmt_list ();
479 if (stmts_are_full_exprs_p ())
480 begin_scope (sk
, NULL
);
484 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
485 when the current scope is exited. EH_ONLY is true when this is not
486 meant to apply to normal control flow transfer. */
489 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
491 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
492 CLEANUP_EH_ONLY (stmt
) = eh_only
;
494 CLEANUP_BODY (stmt
) = push_stmt_list ();
497 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
498 the current loops, represented by 'NULL_TREE' if we've seen a possible
499 exit, and 'error_mark_node' if not. This is currently used only to
500 suppress the warning about a function with no return statements, and
501 therefore we don't bother noting returns as possible exits. We also
502 don't bother with gotos. */
505 begin_maybe_infinite_loop (tree cond
)
507 /* Only track this while parsing a function, not during instantiation. */
508 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
509 && !processing_template_decl
))
511 bool maybe_infinite
= true;
514 cond
= fold_non_dependent_expr (cond
);
515 maybe_infinite
= integer_nonzerop (cond
);
517 vec_safe_push (cp_function_chain
->infinite_loops
,
518 maybe_infinite
? error_mark_node
: NULL_TREE
);
522 /* A break is a possible exit for the current loop. */
525 break_maybe_infinite_loop (void)
529 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
532 /* If we reach the end of the loop without seeing a possible exit, we have
536 end_maybe_infinite_loop (tree cond
)
538 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
539 && !processing_template_decl
))
541 tree current
= cp_function_chain
->infinite_loops
->pop();
542 if (current
!= NULL_TREE
)
544 cond
= fold_non_dependent_expr (cond
);
545 if (integer_nonzerop (cond
))
546 current_function_infinite_loop
= 1;
551 /* Begin a conditional that might contain a declaration. When generating
552 normal code, we want the declaration to appear before the statement
553 containing the conditional. When generating template code, we want the
554 conditional to be rendered as the raw DECL_EXPR. */
557 begin_cond (tree
*cond_p
)
559 if (processing_template_decl
)
560 *cond_p
= push_stmt_list ();
563 /* Finish such a conditional. */
566 finish_cond (tree
*cond_p
, tree expr
)
568 if (processing_template_decl
)
570 tree cond
= pop_stmt_list (*cond_p
);
572 if (expr
== NULL_TREE
)
573 /* Empty condition in 'for'. */
574 gcc_assert (empty_expr_stmt_p (cond
));
575 else if (check_for_bare_parameter_packs (expr
))
576 expr
= error_mark_node
;
577 else if (!empty_expr_stmt_p (cond
))
578 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
583 /* If *COND_P specifies a conditional with a declaration, transform the
586 for (; A x = 42;) { }
588 while (true) { A x = 42; if (!x) break; }
589 for (;;) { A x = 42; if (!x) break; }
590 The statement list for BODY will be empty if the conditional did
591 not declare anything. */
594 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
598 if (!TREE_SIDE_EFFECTS (body
))
602 *cond_p
= boolean_true_node
;
604 if_stmt
= begin_if_stmt ();
605 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, 0, tf_warning_or_error
);
606 finish_if_stmt_cond (cond
, if_stmt
);
607 finish_break_stmt ();
608 finish_then_clause (if_stmt
);
609 finish_if_stmt (if_stmt
);
612 /* Finish a goto-statement. */
615 finish_goto_stmt (tree destination
)
617 if (identifier_p (destination
))
618 destination
= lookup_label (destination
);
620 /* We warn about unused labels with -Wunused. That means we have to
621 mark the used labels as used. */
622 if (TREE_CODE (destination
) == LABEL_DECL
)
623 TREE_USED (destination
) = 1;
626 if (check_no_cilk (destination
,
627 "Cilk array notation cannot be used as a computed goto expression",
628 "%<_Cilk_spawn%> statement cannot be used as a computed goto expression"))
629 destination
= error_mark_node
;
630 destination
= mark_rvalue_use (destination
);
631 if (!processing_template_decl
)
633 destination
= cp_convert (ptr_type_node
, destination
,
634 tf_warning_or_error
);
635 if (error_operand_p (destination
))
638 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
643 check_goto (destination
);
645 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
648 /* COND is the condition-expression for an if, while, etc.,
649 statement. Convert it to a boolean value, if appropriate.
650 In addition, verify sequence points if -Wsequence-point is enabled. */
653 maybe_convert_cond (tree cond
)
655 /* Empty conditions remain empty. */
659 /* Wait until we instantiate templates before doing conversion. */
660 if (processing_template_decl
)
663 if (warn_sequence_point
)
664 verify_sequence_points (cond
);
666 /* Do the conversion. */
667 cond
= convert_from_reference (cond
);
669 if (TREE_CODE (cond
) == MODIFY_EXPR
670 && !TREE_NO_WARNING (cond
)
673 warning (OPT_Wparentheses
,
674 "suggest parentheses around assignment used as truth value");
675 TREE_NO_WARNING (cond
) = 1;
678 return condition_conversion (cond
);
681 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
684 finish_expr_stmt (tree expr
)
688 if (expr
!= NULL_TREE
)
690 if (!processing_template_decl
)
692 if (warn_sequence_point
)
693 verify_sequence_points (expr
);
694 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
696 else if (!type_dependent_expression_p (expr
))
697 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
698 tf_warning_or_error
);
700 if (check_for_bare_parameter_packs (expr
))
701 expr
= error_mark_node
;
703 /* Simplification of inner statement expressions, compound exprs,
704 etc can result in us already having an EXPR_STMT. */
705 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
707 if (TREE_CODE (expr
) != EXPR_STMT
)
708 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
709 expr
= maybe_cleanup_point_expr_void (expr
);
719 /* Begin an if-statement. Returns a newly created IF_STMT if
726 scope
= do_pushlevel (sk_cond
);
727 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
728 NULL_TREE
, NULL_TREE
, scope
);
729 begin_cond (&IF_COND (r
));
733 /* Process the COND of an if-statement, which may be given by
737 finish_if_stmt_cond (tree cond
, tree if_stmt
)
739 finish_cond (&IF_COND (if_stmt
), maybe_convert_cond (cond
));
741 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
744 /* Finish the then-clause of an if-statement, which may be given by
748 finish_then_clause (tree if_stmt
)
750 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
754 /* Begin the else-clause of an if-statement. */
757 begin_else_clause (tree if_stmt
)
759 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
762 /* Finish the else-clause of an if-statement, which may be given by
766 finish_else_clause (tree if_stmt
)
768 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
771 /* Finish an if-statement. */
774 finish_if_stmt (tree if_stmt
)
776 tree scope
= IF_SCOPE (if_stmt
);
777 IF_SCOPE (if_stmt
) = NULL
;
778 add_stmt (do_poplevel (scope
));
781 /* Begin a while-statement. Returns a newly created WHILE_STMT if
785 begin_while_stmt (void)
788 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
790 WHILE_BODY (r
) = do_pushlevel (sk_block
);
791 begin_cond (&WHILE_COND (r
));
795 /* Process the COND of a while-statement, which may be given by
799 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
)
801 if (check_no_cilk (cond
,
802 "Cilk array notation cannot be used as a condition for while statement",
803 "%<_Cilk_spawn%> statement cannot be used as a condition for while statement"))
804 cond
= error_mark_node
;
805 cond
= maybe_convert_cond (cond
);
806 finish_cond (&WHILE_COND (while_stmt
), cond
);
807 begin_maybe_infinite_loop (cond
);
808 if (ivdep
&& cond
!= error_mark_node
)
809 WHILE_COND (while_stmt
) = build2 (ANNOTATE_EXPR
,
810 TREE_TYPE (WHILE_COND (while_stmt
)),
811 WHILE_COND (while_stmt
),
812 build_int_cst (integer_type_node
,
813 annot_expr_ivdep_kind
));
814 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
817 /* Finish a while-statement, which may be given by WHILE_STMT. */
820 finish_while_stmt (tree while_stmt
)
822 end_maybe_infinite_loop (boolean_true_node
);
823 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
826 /* Begin a do-statement. Returns a newly created DO_STMT if
832 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
833 begin_maybe_infinite_loop (boolean_true_node
);
835 DO_BODY (r
) = push_stmt_list ();
839 /* Finish the body of a do-statement, which may be given by DO_STMT. */
842 finish_do_body (tree do_stmt
)
844 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
846 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
847 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
849 if (IS_EMPTY_STMT (body
))
850 warning (OPT_Wempty_body
,
851 "suggest explicit braces around empty body in %<do%> statement");
854 /* Finish a do-statement, which may be given by DO_STMT, and whose
855 COND is as indicated. */
858 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
)
860 if (check_no_cilk (cond
,
861 "Cilk array notation cannot be used as a condition for a do-while statement",
862 "%<_Cilk_spawn%> statement cannot be used as a condition for a do-while statement"))
863 cond
= error_mark_node
;
864 cond
= maybe_convert_cond (cond
);
865 end_maybe_infinite_loop (cond
);
866 if (ivdep
&& cond
!= error_mark_node
)
867 cond
= build2 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
868 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
));
869 DO_COND (do_stmt
) = cond
;
872 /* Finish a return-statement. The EXPRESSION returned, if any, is as
876 finish_return_stmt (tree expr
)
881 expr
= check_return_expr (expr
, &no_warning
);
883 if (error_operand_p (expr
)
884 || (flag_openmp
&& !check_omp_return ()))
885 return error_mark_node
;
886 if (!processing_template_decl
)
888 if (warn_sequence_point
)
889 verify_sequence_points (expr
);
891 if (DECL_DESTRUCTOR_P (current_function_decl
)
892 || (DECL_CONSTRUCTOR_P (current_function_decl
)
893 && targetm
.cxx
.cdtor_returns_this ()))
895 /* Similarly, all destructors must run destructors for
896 base-classes before returning. So, all returns in a
897 destructor get sent to the DTOR_LABEL; finish_function emits
898 code to return a value there. */
899 return finish_goto_stmt (cdtor_label
);
903 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
904 TREE_NO_WARNING (r
) |= no_warning
;
905 r
= maybe_cleanup_point_expr_void (r
);
911 /* Begin the scope of a for-statement or a range-for-statement.
912 Both the returned trees are to be used in a call to
913 begin_for_stmt or begin_range_for_stmt. */
916 begin_for_scope (tree
*init
)
918 tree scope
= NULL_TREE
;
919 if (flag_new_for_scope
> 0)
920 scope
= do_pushlevel (sk_for
);
922 if (processing_template_decl
)
923 *init
= push_stmt_list ();
930 /* Begin a for-statement. Returns a new FOR_STMT.
931 SCOPE and INIT should be the return of begin_for_scope,
935 begin_for_stmt (tree scope
, tree init
)
939 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
940 NULL_TREE
, NULL_TREE
, NULL_TREE
);
942 if (scope
== NULL_TREE
)
944 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
946 scope
= begin_for_scope (&init
);
948 FOR_INIT_STMT (r
) = init
;
949 FOR_SCOPE (r
) = scope
;
954 /* Finish the for-init-statement of a for-statement, which may be
955 given by FOR_STMT. */
958 finish_for_init_stmt (tree for_stmt
)
960 if (processing_template_decl
)
961 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
963 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
964 begin_cond (&FOR_COND (for_stmt
));
967 /* Finish the COND of a for-statement, which may be given by
971 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
)
973 if (check_no_cilk (cond
,
974 "Cilk array notation cannot be used in a condition for a for-loop",
975 "%<_Cilk_spawn%> statement cannot be used in a condition for a for-loop"))
976 cond
= error_mark_node
;
977 cond
= maybe_convert_cond (cond
);
978 finish_cond (&FOR_COND (for_stmt
), cond
);
979 begin_maybe_infinite_loop (cond
);
980 if (ivdep
&& cond
!= error_mark_node
)
981 FOR_COND (for_stmt
) = build2 (ANNOTATE_EXPR
,
982 TREE_TYPE (FOR_COND (for_stmt
)),
984 build_int_cst (integer_type_node
,
985 annot_expr_ivdep_kind
));
986 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
989 /* Finish the increment-EXPRESSION in a for-statement, which may be
990 given by FOR_STMT. */
993 finish_for_expr (tree expr
, tree for_stmt
)
997 /* If EXPR is an overloaded function, issue an error; there is no
998 context available to use to perform overload resolution. */
999 if (type_unknown_p (expr
))
1001 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1002 expr
= error_mark_node
;
1004 if (!processing_template_decl
)
1006 if (warn_sequence_point
)
1007 verify_sequence_points (expr
);
1008 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1009 tf_warning_or_error
);
1011 else if (!type_dependent_expression_p (expr
))
1012 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1013 tf_warning_or_error
);
1014 expr
= maybe_cleanup_point_expr_void (expr
);
1015 if (check_for_bare_parameter_packs (expr
))
1016 expr
= error_mark_node
;
1017 FOR_EXPR (for_stmt
) = expr
;
1020 /* Finish the body of a for-statement, which may be given by
1021 FOR_STMT. The increment-EXPR for the loop must be
1023 It can also finish RANGE_FOR_STMT. */
1026 finish_for_stmt (tree for_stmt
)
1028 end_maybe_infinite_loop (boolean_true_node
);
1030 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1031 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1033 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1035 /* Pop the scope for the body of the loop. */
1036 if (flag_new_for_scope
> 0)
1039 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1040 ? &RANGE_FOR_SCOPE (for_stmt
)
1041 : &FOR_SCOPE (for_stmt
));
1044 add_stmt (do_poplevel (scope
));
1048 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1049 SCOPE and INIT should be the return of begin_for_scope,
1051 To finish it call finish_for_stmt(). */
1054 begin_range_for_stmt (tree scope
, tree init
)
1058 begin_maybe_infinite_loop (boolean_false_node
);
1060 r
= build_stmt (input_location
, RANGE_FOR_STMT
,
1061 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1063 if (scope
== NULL_TREE
)
1065 gcc_assert (!init
|| !(flag_new_for_scope
> 0));
1067 scope
= begin_for_scope (&init
);
1070 /* RANGE_FOR_STMTs do not use nor save the init tree, so we
1073 pop_stmt_list (init
);
1074 RANGE_FOR_SCOPE (r
) = scope
;
1079 /* Finish the head of a range-based for statement, which may
1080 be given by RANGE_FOR_STMT. DECL must be the declaration
1081 and EXPR must be the loop expression. */
1084 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1086 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1087 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1088 add_stmt (range_for_stmt
);
1089 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1092 /* Finish a break-statement. */
1095 finish_break_stmt (void)
1097 /* In switch statements break is sometimes stylistically used after
1098 a return statement. This can lead to spurious warnings about
1099 control reaching the end of a non-void function when it is
1100 inlined. Note that we are calling block_may_fallthru with
1101 language specific tree nodes; this works because
1102 block_may_fallthru returns true when given something it does not
1104 if (!block_may_fallthru (cur_stmt_list
))
1106 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1109 /* Finish a continue-statement. */
1112 finish_continue_stmt (void)
1114 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1117 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1121 begin_switch_stmt (void)
1125 scope
= do_pushlevel (sk_cond
);
1126 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1128 begin_cond (&SWITCH_STMT_COND (r
));
1133 /* Finish the cond of a switch-statement. */
1136 finish_switch_cond (tree cond
, tree switch_stmt
)
1138 tree orig_type
= NULL
;
1140 if (check_no_cilk (cond
,
1141 "Cilk array notation cannot be used as a condition for switch statement",
1142 "%<_Cilk_spawn%> statement cannot be used as a condition for switch statement"))
1143 cond
= error_mark_node
;
1145 if (!processing_template_decl
)
1147 /* Convert the condition to an integer or enumeration type. */
1148 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1149 if (cond
== NULL_TREE
)
1151 error ("switch quantity not an integer");
1152 cond
= error_mark_node
;
1154 /* We want unlowered type here to handle enum bit-fields. */
1155 orig_type
= unlowered_expr_type (cond
);
1156 if (cond
!= error_mark_node
)
1158 /* Warn if the condition has boolean value. */
1159 if (TREE_CODE (orig_type
) == BOOLEAN_TYPE
)
1160 warning_at (input_location
, OPT_Wswitch_bool
,
1161 "switch condition has type bool");
1165 Integral promotions are performed. */
1166 cond
= perform_integral_promotions (cond
);
1167 cond
= maybe_cleanup_point_expr (cond
);
1170 if (check_for_bare_parameter_packs (cond
))
1171 cond
= error_mark_node
;
1172 else if (!processing_template_decl
&& warn_sequence_point
)
1173 verify_sequence_points (cond
);
1175 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1176 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1177 add_stmt (switch_stmt
);
1178 push_switch (switch_stmt
);
1179 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1182 /* Finish the body of a switch-statement, which may be given by
1183 SWITCH_STMT. The COND to switch on is indicated. */
1186 finish_switch_stmt (tree switch_stmt
)
1190 SWITCH_STMT_BODY (switch_stmt
) =
1191 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1194 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1195 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1196 add_stmt (do_poplevel (scope
));
1199 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1203 begin_try_block (void)
1205 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1207 TRY_STMTS (r
) = push_stmt_list ();
1211 /* Likewise, for a function-try-block. The block returned in
1212 *COMPOUND_STMT is an artificial outer scope, containing the
1213 function-try-block. */
1216 begin_function_try_block (tree
*compound_stmt
)
1219 /* This outer scope does not exist in the C++ standard, but we need
1220 a place to put __FUNCTION__ and similar variables. */
1221 *compound_stmt
= begin_compound_stmt (0);
1222 r
= begin_try_block ();
1223 FN_TRY_BLOCK_P (r
) = 1;
1227 /* Finish a try-block, which may be given by TRY_BLOCK. */
1230 finish_try_block (tree try_block
)
1232 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1233 TRY_HANDLERS (try_block
) = push_stmt_list ();
1236 /* Finish the body of a cleanup try-block, which may be given by
1240 finish_cleanup_try_block (tree try_block
)
1242 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1245 /* Finish an implicitly generated try-block, with a cleanup is given
1249 finish_cleanup (tree cleanup
, tree try_block
)
1251 TRY_HANDLERS (try_block
) = cleanup
;
1252 CLEANUP_P (try_block
) = 1;
1255 /* Likewise, for a function-try-block. */
1258 finish_function_try_block (tree try_block
)
1260 finish_try_block (try_block
);
1261 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1262 the try block, but moving it inside. */
1263 in_function_try_handler
= 1;
1266 /* Finish a handler-sequence for a try-block, which may be given by
1270 finish_handler_sequence (tree try_block
)
1272 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1273 check_handlers (TRY_HANDLERS (try_block
));
1276 /* Finish the handler-seq for a function-try-block, given by
1277 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1278 begin_function_try_block. */
1281 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1283 in_function_try_handler
= 0;
1284 finish_handler_sequence (try_block
);
1285 finish_compound_stmt (compound_stmt
);
1288 /* Begin a handler. Returns a HANDLER if appropriate. */
1291 begin_handler (void)
1295 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1298 /* Create a binding level for the eh_info and the exception object
1300 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1305 /* Finish the handler-parameters for a handler, which may be given by
1306 HANDLER. DECL is the declaration for the catch parameter, or NULL
1307 if this is a `catch (...)' clause. */
1310 finish_handler_parms (tree decl
, tree handler
)
1312 tree type
= NULL_TREE
;
1313 if (processing_template_decl
)
1317 decl
= pushdecl (decl
);
1318 decl
= push_template_decl (decl
);
1319 HANDLER_PARMS (handler
) = decl
;
1320 type
= TREE_TYPE (decl
);
1324 type
= expand_start_catch_block (decl
);
1325 HANDLER_TYPE (handler
) = type
;
1328 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1329 the return value from the matching call to finish_handler_parms. */
1332 finish_handler (tree handler
)
1334 if (!processing_template_decl
)
1335 expand_end_catch_block ();
1336 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1339 /* Begin a compound statement. FLAGS contains some bits that control the
1340 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1341 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1342 block of a function. If BCS_TRY_BLOCK is set, this is the block
1343 created on behalf of a TRY statement. Returns a token to be passed to
1344 finish_compound_stmt. */
1347 begin_compound_stmt (unsigned int flags
)
1351 if (flags
& BCS_NO_SCOPE
)
1353 r
= push_stmt_list ();
1354 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1356 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1357 But, if it's a statement-expression with a scopeless block, there's
1358 nothing to keep, and we don't want to accidentally keep a block
1359 *inside* the scopeless block. */
1360 keep_next_level (false);
1363 r
= do_pushlevel (flags
& BCS_TRY_BLOCK
? sk_try
: sk_block
);
1365 /* When processing a template, we need to remember where the braces were,
1366 so that we can set up identical scopes when instantiating the template
1367 later. BIND_EXPR is a handy candidate for this.
1368 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1369 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1370 processing templates. */
1371 if (processing_template_decl
)
1373 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1374 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1375 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1376 TREE_SIDE_EFFECTS (r
) = 1;
1382 /* Finish a compound-statement, which is given by STMT. */
1385 finish_compound_stmt (tree stmt
)
1387 if (TREE_CODE (stmt
) == BIND_EXPR
)
1389 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1390 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1391 discard the BIND_EXPR so it can be merged with the containing
1393 if (TREE_CODE (body
) == STATEMENT_LIST
1394 && STATEMENT_LIST_HEAD (body
) == NULL
1395 && !BIND_EXPR_BODY_BLOCK (stmt
)
1396 && !BIND_EXPR_TRY_BLOCK (stmt
))
1399 BIND_EXPR_BODY (stmt
) = body
;
1401 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1402 stmt
= pop_stmt_list (stmt
);
1405 /* Destroy any ObjC "super" receivers that may have been
1407 objc_clear_super_receiver ();
1409 stmt
= do_poplevel (stmt
);
1412 /* ??? See c_end_compound_stmt wrt statement expressions. */
1416 /* Finish an asm-statement, whose components are a STRING, some
1417 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1418 LABELS. Also note whether the asm-statement should be
1419 considered volatile. */
1422 finish_asm_stmt (int volatile_p
, tree string
, tree output_operands
,
1423 tree input_operands
, tree clobbers
, tree labels
)
1427 int ninputs
= list_length (input_operands
);
1428 int noutputs
= list_length (output_operands
);
1430 if (!processing_template_decl
)
1432 const char *constraint
;
1433 const char **oconstraints
;
1434 bool allows_mem
, allows_reg
, is_inout
;
1438 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1440 string
= resolve_asm_operand_names (string
, output_operands
,
1441 input_operands
, labels
);
1443 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1445 operand
= TREE_VALUE (t
);
1447 /* ??? Really, this should not be here. Users should be using a
1448 proper lvalue, dammit. But there's a long history of using
1449 casts in the output operands. In cases like longlong.h, this
1450 becomes a primitive form of typechecking -- if the cast can be
1451 removed, then the output operand had a type of the proper width;
1452 otherwise we'll get an error. Gross, but ... */
1453 STRIP_NOPS (operand
);
1455 operand
= mark_lvalue_use (operand
);
1457 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1458 operand
= error_mark_node
;
1460 if (operand
!= error_mark_node
1461 && (TREE_READONLY (operand
)
1462 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1463 /* Functions are not modifiable, even though they are
1465 || TREE_CODE (TREE_TYPE (operand
)) == FUNCTION_TYPE
1466 || TREE_CODE (TREE_TYPE (operand
)) == METHOD_TYPE
1467 /* If it's an aggregate and any field is const, then it is
1468 effectively const. */
1469 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1470 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1471 cxx_readonly_error (operand
, lv_asm
);
1473 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1474 oconstraints
[i
] = constraint
;
1476 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1477 &allows_mem
, &allows_reg
, &is_inout
))
1479 /* If the operand is going to end up in memory,
1480 mark it addressable. */
1481 if (!allows_reg
&& !cxx_mark_addressable (operand
))
1482 operand
= error_mark_node
;
1485 operand
= error_mark_node
;
1487 TREE_VALUE (t
) = operand
;
1490 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1492 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1493 bool constraint_parsed
1494 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1495 oconstraints
, &allows_mem
, &allows_reg
);
1496 /* If the operand is going to end up in memory, don't call
1497 decay_conversion. */
1498 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1499 operand
= mark_lvalue_use (TREE_VALUE (t
));
1501 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1503 /* If the type of the operand hasn't been determined (e.g.,
1504 because it involves an overloaded function), then issue
1505 an error message. There's no context available to
1506 resolve the overloading. */
1507 if (TREE_TYPE (operand
) == unknown_type_node
)
1509 error ("type of asm operand %qE could not be determined",
1511 operand
= error_mark_node
;
1514 if (constraint_parsed
)
1516 /* If the operand is going to end up in memory,
1517 mark it addressable. */
1518 if (!allows_reg
&& allows_mem
)
1520 /* Strip the nops as we allow this case. FIXME, this really
1521 should be rejected or made deprecated. */
1522 STRIP_NOPS (operand
);
1523 if (!cxx_mark_addressable (operand
))
1524 operand
= error_mark_node
;
1526 else if (!allows_reg
&& !allows_mem
)
1528 /* If constraint allows neither register nor memory,
1529 try harder to get a constant. */
1530 tree constop
= maybe_constant_value (operand
);
1531 if (TREE_CONSTANT (constop
))
1536 operand
= error_mark_node
;
1538 TREE_VALUE (t
) = operand
;
1542 r
= build_stmt (input_location
, ASM_EXPR
, string
,
1543 output_operands
, input_operands
,
1545 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1546 r
= maybe_cleanup_point_expr_void (r
);
1547 return add_stmt (r
);
1550 /* Finish a label with the indicated NAME. Returns the new label. */
1553 finish_label_stmt (tree name
)
1555 tree decl
= define_label (input_location
, name
);
1557 if (decl
== error_mark_node
)
1558 return error_mark_node
;
1560 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1565 /* Finish a series of declarations for local labels. G++ allows users
1566 to declare "local" labels, i.e., labels with scope. This extension
1567 is useful when writing code involving statement-expressions. */
1570 finish_label_decl (tree name
)
1572 if (!at_function_scope_p ())
1574 error ("__label__ declarations are only allowed in function scopes");
1578 add_decl_expr (declare_local_label (name
));
1581 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1584 finish_decl_cleanup (tree decl
, tree cleanup
)
1586 push_cleanup (decl
, cleanup
, false);
1589 /* If the current scope exits with an exception, run CLEANUP. */
1592 finish_eh_cleanup (tree cleanup
)
1594 push_cleanup (NULL
, cleanup
, true);
1597 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1598 order they were written by the user. Each node is as for
1599 emit_mem_initializers. */
1602 finish_mem_initializers (tree mem_inits
)
1604 /* Reorder the MEM_INITS so that they are in the order they appeared
1605 in the source program. */
1606 mem_inits
= nreverse (mem_inits
);
1608 if (processing_template_decl
)
1612 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
1614 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
1615 check for bare parameter packs in the TREE_VALUE, because
1616 any parameter packs in the TREE_VALUE have already been
1617 bound as part of the TREE_PURPOSE. See
1618 make_pack_expansion for more information. */
1619 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
1620 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
1621 TREE_VALUE (mem
) = error_mark_node
;
1624 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
1625 CTOR_INITIALIZER
, mem_inits
));
1628 emit_mem_initializers (mem_inits
);
1631 /* Obfuscate EXPR if it looks like an id-expression or member access so
1632 that the call to finish_decltype in do_auto_deduction will give the
1636 force_paren_expr (tree expr
)
1638 /* This is only needed for decltype(auto) in C++14. */
1639 if (cxx_dialect
< cxx14
)
1642 /* If we're in unevaluated context, we can't be deducing a
1643 return/initializer type, so we don't need to mess with this. */
1644 if (cp_unevaluated_operand
)
1647 if (!DECL_P (expr
) && TREE_CODE (expr
) != COMPONENT_REF
1648 && TREE_CODE (expr
) != SCOPE_REF
)
1651 if (TREE_CODE (expr
) == COMPONENT_REF
)
1652 REF_PARENTHESIZED_P (expr
) = true;
1653 else if (type_dependent_expression_p (expr
))
1654 expr
= build1 (PAREN_EXPR
, TREE_TYPE (expr
), expr
);
1657 cp_lvalue_kind kind
= lvalue_kind (expr
);
1658 if ((kind
& ~clk_class
) != clk_none
)
1660 tree type
= unlowered_expr_type (expr
);
1661 bool rval
= !!(kind
& clk_rvalueref
);
1662 type
= cp_build_reference_type (type
, rval
);
1663 expr
= build_static_cast (type
, expr
, tf_error
);
1664 if (expr
!= error_mark_node
)
1665 REF_PARENTHESIZED_P (expr
) = true;
1672 /* Finish a parenthesized expression EXPR. */
1675 finish_parenthesized_expr (tree expr
)
1678 /* This inhibits warnings in c_common_truthvalue_conversion. */
1679 TREE_NO_WARNING (expr
) = 1;
1681 if (TREE_CODE (expr
) == OFFSET_REF
1682 || TREE_CODE (expr
) == SCOPE_REF
)
1683 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1684 enclosed in parentheses. */
1685 PTRMEM_OK_P (expr
) = 0;
1687 if (TREE_CODE (expr
) == STRING_CST
)
1688 PAREN_STRING_LITERAL_P (expr
) = 1;
1690 expr
= force_paren_expr (expr
);
1695 /* Finish a reference to a non-static data member (DECL) that is not
1696 preceded by `.' or `->'. */
1699 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1701 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1705 tree scope
= qualifying_scope
;
1706 if (scope
== NULL_TREE
)
1707 scope
= context_for_name_lookup (decl
);
1708 object
= maybe_dummy_object (scope
, NULL
);
1711 object
= maybe_resolve_dummy (object
, true);
1712 if (object
== error_mark_node
)
1713 return error_mark_node
;
1715 /* DR 613/850: Can use non-static data members without an associated
1716 object in sizeof/decltype/alignof. */
1717 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
1718 && (!processing_template_decl
|| !current_class_ref
))
1720 if (current_function_decl
1721 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1722 error ("invalid use of member %qD in static member function", decl
);
1724 error ("invalid use of non-static data member %qD", decl
);
1725 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
1727 return error_mark_node
;
1730 if (current_class_ptr
)
1731 TREE_USED (current_class_ptr
) = 1;
1732 if (processing_template_decl
&& !qualifying_scope
)
1734 tree type
= TREE_TYPE (decl
);
1736 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1737 /* Quals on the object don't matter. */;
1738 else if (PACK_EXPANSION_P (type
))
1739 /* Don't bother trying to represent this. */
1743 /* Set the cv qualifiers. */
1744 int quals
= cp_type_quals (TREE_TYPE (object
));
1746 if (DECL_MUTABLE_P (decl
))
1747 quals
&= ~TYPE_QUAL_CONST
;
1749 quals
|= cp_type_quals (TREE_TYPE (decl
));
1750 type
= cp_build_qualified_type (type
, quals
);
1753 return (convert_from_reference
1754 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
1756 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1757 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1759 else if (processing_template_decl
)
1760 return build_qualified_name (TREE_TYPE (decl
),
1763 /*template_p=*/false);
1766 tree access_type
= TREE_TYPE (object
);
1768 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
1769 decl
, tf_warning_or_error
);
1771 /* If the data member was named `C::M', convert `*this' to `C'
1773 if (qualifying_scope
)
1775 tree binfo
= NULL_TREE
;
1776 object
= build_scoped_ref (object
, qualifying_scope
,
1780 return build_class_member_access_expr (object
, decl
,
1781 /*access_path=*/NULL_TREE
,
1782 /*preserve_reference=*/false,
1783 tf_warning_or_error
);
1787 /* If we are currently parsing a template and we encountered a typedef
1788 TYPEDEF_DECL that is being accessed though CONTEXT, this function
1789 adds the typedef to a list tied to the current template.
1790 At template instantiation time, that list is walked and access check
1791 performed for each typedef.
1792 LOCATION is the location of the usage point of TYPEDEF_DECL. */
1795 add_typedef_to_current_template_for_access_check (tree typedef_decl
,
1797 location_t location
)
1799 tree template_info
= NULL
;
1800 tree cs
= current_scope ();
1802 if (!is_typedef_decl (typedef_decl
)
1804 || !CLASS_TYPE_P (context
)
1808 if (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
)
1809 template_info
= get_template_info (cs
);
1812 && TI_TEMPLATE (template_info
)
1813 && !currently_open_class (context
))
1814 append_type_to_template_for_access_check (cs
, typedef_decl
,
1818 /* DECL was the declaration to which a qualified-id resolved. Issue
1819 an error message if it is not accessible. If OBJECT_TYPE is
1820 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1821 type of `*x', or `x', respectively. If the DECL was named as
1822 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1825 check_accessibility_of_qualified_id (tree decl
,
1827 tree nested_name_specifier
)
1830 tree qualifying_type
= NULL_TREE
;
1832 /* If we are parsing a template declaration and if decl is a typedef,
1833 add it to a list tied to the template.
1834 At template instantiation time, that list will be walked and
1835 access check performed. */
1836 add_typedef_to_current_template_for_access_check (decl
,
1837 nested_name_specifier
1838 ? nested_name_specifier
1839 : DECL_CONTEXT (decl
),
1842 /* If we're not checking, return immediately. */
1843 if (deferred_access_no_check
)
1846 /* Determine the SCOPE of DECL. */
1847 scope
= context_for_name_lookup (decl
);
1848 /* If the SCOPE is not a type, then DECL is not a member. */
1849 if (!TYPE_P (scope
))
1851 /* Compute the scope through which DECL is being accessed. */
1853 /* OBJECT_TYPE might not be a class type; consider:
1855 class A { typedef int I; };
1859 In this case, we will have "A::I" as the DECL, but "I" as the
1861 && CLASS_TYPE_P (object_type
)
1862 && DERIVED_FROM_P (scope
, object_type
))
1863 /* If we are processing a `->' or `.' expression, use the type of the
1865 qualifying_type
= object_type
;
1866 else if (nested_name_specifier
)
1868 /* If the reference is to a non-static member of the
1869 current class, treat it as if it were referenced through
1872 if (DECL_NONSTATIC_MEMBER_P (decl
)
1873 && current_class_ptr
1874 && DERIVED_FROM_P (scope
, ct
= current_nonlambda_class_type ()))
1875 qualifying_type
= ct
;
1876 /* Otherwise, use the type indicated by the
1877 nested-name-specifier. */
1879 qualifying_type
= nested_name_specifier
;
1882 /* Otherwise, the name must be from the current class or one of
1884 qualifying_type
= currently_open_derived_class (scope
);
1887 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
1888 or similar in a default argument value. */
1889 && CLASS_TYPE_P (qualifying_type
)
1890 && !dependent_type_p (qualifying_type
))
1891 perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
1892 decl
, tf_warning_or_error
);
1895 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
1896 class named to the left of the "::" operator. DONE is true if this
1897 expression is a complete postfix-expression; it is false if this
1898 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
1899 iff this expression is the operand of '&'. TEMPLATE_P is true iff
1900 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
1901 is true iff this qualified name appears as a template argument. */
1904 finish_qualified_id_expr (tree qualifying_class
,
1909 bool template_arg_p
,
1910 tsubst_flags_t complain
)
1912 gcc_assert (TYPE_P (qualifying_class
));
1914 if (error_operand_p (expr
))
1915 return error_mark_node
;
1917 if ((DECL_P (expr
) || BASELINK_P (expr
))
1918 && !mark_used (expr
, complain
))
1919 return error_mark_node
;
1922 check_template_keyword (expr
);
1924 /* If EXPR occurs as the operand of '&', use special handling that
1925 permits a pointer-to-member. */
1926 if (address_p
&& done
)
1928 if (TREE_CODE (expr
) == SCOPE_REF
)
1929 expr
= TREE_OPERAND (expr
, 1);
1930 expr
= build_offset_ref (qualifying_class
, expr
,
1931 /*address_p=*/true, complain
);
1935 /* No need to check access within an enum. */
1936 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
)
1939 /* Within the scope of a class, turn references to non-static
1940 members into expression of the form "this->...". */
1942 /* But, within a template argument, we do not want make the
1943 transformation, as there is no "this" pointer. */
1945 else if (TREE_CODE (expr
) == FIELD_DECL
)
1947 push_deferring_access_checks (dk_no_check
);
1948 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
1950 pop_deferring_access_checks ();
1952 else if (BASELINK_P (expr
) && !processing_template_decl
)
1954 /* See if any of the functions are non-static members. */
1955 /* If so, the expression may be relative to 'this'. */
1956 if (!shared_member_p (expr
)
1957 && current_class_ptr
1958 && DERIVED_FROM_P (qualifying_class
,
1959 current_nonlambda_class_type ()))
1960 expr
= (build_class_member_access_expr
1961 (maybe_dummy_object (qualifying_class
, NULL
),
1963 BASELINK_ACCESS_BINFO (expr
),
1964 /*preserve_reference=*/false,
1967 /* The expression is a qualified name whose address is not
1969 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
1972 else if (BASELINK_P (expr
))
1976 /* In a template, return a SCOPE_REF for most qualified-ids
1977 so that we can check access at instantiation time. But if
1978 we're looking at a member of the current instantiation, we
1979 know we have access and building up the SCOPE_REF confuses
1980 non-type template argument handling. */
1981 if (processing_template_decl
1982 && !currently_open_class (qualifying_class
))
1983 expr
= build_qualified_name (TREE_TYPE (expr
),
1984 qualifying_class
, expr
,
1987 expr
= convert_from_reference (expr
);
1993 /* Begin a statement-expression. The value returned must be passed to
1994 finish_stmt_expr. */
1997 begin_stmt_expr (void)
1999 return push_stmt_list ();
2002 /* Process the final expression of a statement expression. EXPR can be
2003 NULL, if the final expression is empty. Return a STATEMENT_LIST
2004 containing all the statements in the statement-expression, or
2005 ERROR_MARK_NODE if there was an error. */
2008 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2010 if (error_operand_p (expr
))
2012 /* The type of the statement-expression is the type of the last
2014 TREE_TYPE (stmt_expr
) = error_mark_node
;
2015 return error_mark_node
;
2018 /* If the last statement does not have "void" type, then the value
2019 of the last statement is the value of the entire expression. */
2022 tree type
= TREE_TYPE (expr
);
2024 if (processing_template_decl
)
2026 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2027 expr
= add_stmt (expr
);
2028 /* Mark the last statement so that we can recognize it as such at
2029 template-instantiation time. */
2030 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2032 else if (VOID_TYPE_P (type
))
2034 /* Just treat this like an ordinary statement. */
2035 expr
= finish_expr_stmt (expr
);
2039 /* It actually has a value we need to deal with. First, force it
2040 to be an rvalue so that we won't need to build up a copy
2041 constructor call later when we try to assign it to something. */
2042 expr
= force_rvalue (expr
, tf_warning_or_error
);
2043 if (error_operand_p (expr
))
2044 return error_mark_node
;
2046 /* Update for array-to-pointer decay. */
2047 type
= TREE_TYPE (expr
);
2049 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2050 normal statement, but don't convert to void or actually add
2052 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2053 expr
= maybe_cleanup_point_expr (expr
);
2057 /* The type of the statement-expression is the type of the last
2059 TREE_TYPE (stmt_expr
) = type
;
2065 /* Finish a statement-expression. EXPR should be the value returned
2066 by the previous begin_stmt_expr. Returns an expression
2067 representing the statement-expression. */
2070 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2075 if (error_operand_p (stmt_expr
))
2077 pop_stmt_list (stmt_expr
);
2078 return error_mark_node
;
2081 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2083 type
= TREE_TYPE (stmt_expr
);
2084 result
= pop_stmt_list (stmt_expr
);
2085 TREE_TYPE (result
) = type
;
2087 if (processing_template_decl
)
2089 result
= build_min (STMT_EXPR
, type
, result
);
2090 TREE_SIDE_EFFECTS (result
) = 1;
2091 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2093 else if (CLASS_TYPE_P (type
))
2095 /* Wrap the statement-expression in a TARGET_EXPR so that the
2096 temporary object created by the final expression is destroyed at
2097 the end of the full-expression containing the
2098 statement-expression. */
2099 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2105 /* Returns the expression which provides the value of STMT_EXPR. */
2108 stmt_expr_value_expr (tree stmt_expr
)
2110 tree t
= STMT_EXPR_STMT (stmt_expr
);
2112 if (TREE_CODE (t
) == BIND_EXPR
)
2113 t
= BIND_EXPR_BODY (t
);
2115 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2116 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2118 if (TREE_CODE (t
) == EXPR_STMT
)
2119 t
= EXPR_STMT_EXPR (t
);
2124 /* Return TRUE iff EXPR_STMT is an empty list of
2125 expression statements. */
2128 empty_expr_stmt_p (tree expr_stmt
)
2130 tree body
= NULL_TREE
;
2132 if (expr_stmt
== void_node
)
2137 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2138 body
= EXPR_STMT_EXPR (expr_stmt
);
2139 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2145 if (TREE_CODE (body
) == STATEMENT_LIST
)
2146 return tsi_end_p (tsi_start (body
));
2148 return empty_expr_stmt_p (body
);
2153 /* Perform Koenig lookup. FN is the postfix-expression representing
2154 the function (or functions) to call; ARGS are the arguments to the
2155 call. Returns the functions to be considered by overload resolution. */
2158 perform_koenig_lookup (tree fn
, vec
<tree
, va_gc
> *args
,
2159 tsubst_flags_t complain
)
2161 tree identifier
= NULL_TREE
;
2162 tree functions
= NULL_TREE
;
2163 tree tmpl_args
= NULL_TREE
;
2164 bool template_id
= false;
2166 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2168 /* Use a separate flag to handle null args. */
2170 tmpl_args
= TREE_OPERAND (fn
, 1);
2171 fn
= TREE_OPERAND (fn
, 0);
2174 /* Find the name of the overloaded function. */
2175 if (identifier_p (fn
))
2177 else if (is_overloaded_fn (fn
))
2180 identifier
= DECL_NAME (get_first_fn (functions
));
2182 else if (DECL_P (fn
))
2185 identifier
= DECL_NAME (fn
);
2188 /* A call to a namespace-scope function using an unqualified name.
2190 Do Koenig lookup -- unless any of the arguments are
2192 if (!any_type_dependent_arguments_p (args
)
2193 && !any_dependent_template_arguments_p (tmpl_args
))
2195 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2198 /* The unqualified name could not be resolved. */
2200 fn
= unqualified_fn_lookup_error (identifier
);
2206 if (fn
&& template_id
)
2207 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2212 /* Generate an expression for `FN (ARGS)'. This may change the
2215 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2216 as a virtual call, even if FN is virtual. (This flag is set when
2217 encountering an expression where the function name is explicitly
2218 qualified. For example a call to `X::f' never generates a virtual
2221 Returns code for the call. */
2224 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2225 bool koenig_p
, tsubst_flags_t complain
)
2229 vec
<tree
, va_gc
> *orig_args
= NULL
;
2231 if (fn
== error_mark_node
)
2232 return error_mark_node
;
2234 gcc_assert (!TYPE_P (fn
));
2238 if (processing_template_decl
)
2240 /* If the call expression is dependent, build a CALL_EXPR node
2241 with no type; type_dependent_expression_p recognizes
2242 expressions with no type as being dependent. */
2243 if (type_dependent_expression_p (fn
)
2244 || any_type_dependent_arguments_p (*args
)
2245 /* For a non-static member function that doesn't have an
2246 explicit object argument, we need to specifically
2247 test the type dependency of the "this" pointer because it
2248 is not included in *ARGS even though it is considered to
2249 be part of the list of arguments. Note that this is
2250 related to CWG issues 515 and 1005. */
2251 || (TREE_CODE (fn
) != COMPONENT_REF
2252 && non_static_member_function_p (fn
)
2253 && current_class_ref
2254 && type_dependent_expression_p (current_class_ref
)))
2256 result
= build_nt_call_vec (fn
, *args
);
2257 SET_EXPR_LOCATION (result
, EXPR_LOC_OR_LOC (fn
, input_location
));
2258 KOENIG_LOOKUP_P (result
) = koenig_p
;
2263 tree fndecl
= OVL_CURRENT (fn
);
2264 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2265 || !TREE_THIS_VOLATILE (fndecl
))
2271 current_function_returns_abnormally
= 1;
2275 orig_args
= make_tree_vector_copy (*args
);
2276 if (!BASELINK_P (fn
)
2277 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2278 && TREE_TYPE (fn
) != unknown_type_node
)
2279 fn
= build_non_dependent_expr (fn
);
2280 make_args_non_dependent (*args
);
2283 if (TREE_CODE (fn
) == COMPONENT_REF
)
2285 tree member
= TREE_OPERAND (fn
, 1);
2286 if (BASELINK_P (member
))
2288 tree object
= TREE_OPERAND (fn
, 0);
2289 return build_new_method_call (object
, member
,
2292 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2299 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2300 if (TREE_CODE (fn
) == ADDR_EXPR
2301 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2302 fn
= TREE_OPERAND (fn
, 0);
2304 if (is_overloaded_fn (fn
))
2305 fn
= baselink_for_fns (fn
);
2308 if (BASELINK_P (fn
))
2312 /* A call to a member function. From [over.call.func]:
2314 If the keyword this is in scope and refers to the class of
2315 that member function, or a derived class thereof, then the
2316 function call is transformed into a qualified function call
2317 using (*this) as the postfix-expression to the left of the
2318 . operator.... [Otherwise] a contrived object of type T
2319 becomes the implied object argument.
2323 struct A { void f(); };
2324 struct B : public A {};
2325 struct C : public A { void g() { B::f(); }};
2327 "the class of that member function" refers to `A'. But 11.2
2328 [class.access.base] says that we need to convert 'this' to B* as
2329 part of the access, so we pass 'B' to maybe_dummy_object. */
2331 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2334 if (processing_template_decl
)
2336 if (type_dependent_expression_p (object
))
2338 tree ret
= build_nt_call_vec (orig_fn
, orig_args
);
2339 release_tree_vector (orig_args
);
2342 object
= build_non_dependent_expr (object
);
2345 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2347 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2352 else if (is_overloaded_fn (fn
))
2354 /* If the function is an overloaded builtin, resolve it. */
2355 if (TREE_CODE (fn
) == FUNCTION_DECL
2356 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2357 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2358 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2362 if (warn_sizeof_pointer_memaccess
2363 && !vec_safe_is_empty (*args
)
2364 && !processing_template_decl
)
2366 location_t sizeof_arg_loc
[3];
2369 for (i
= 0; i
< 3; i
++)
2373 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2374 sizeof_arg
[i
] = NULL_TREE
;
2375 if (i
>= (*args
)->length ())
2378 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2380 if (SIZEOF_EXPR_TYPE_P (t
))
2381 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2383 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2384 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2386 sizeof_pointer_memaccess_warning
2387 (sizeof_arg_loc
, fn
, *args
,
2388 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2391 /* A call to a namespace-scope function. */
2392 result
= build_new_function_call (fn
, args
, koenig_p
, complain
);
2395 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2397 if (!vec_safe_is_empty (*args
))
2398 error ("arguments to destructor are not allowed");
2399 /* Mark the pseudo-destructor call as having side-effects so
2400 that we do not issue warnings about its use. */
2401 result
= build1 (NOP_EXPR
,
2403 TREE_OPERAND (fn
, 0));
2404 TREE_SIDE_EFFECTS (result
) = 1;
2406 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2407 /* If the "function" is really an object of class type, it might
2408 have an overloaded `operator ()'. */
2409 result
= build_op_call (fn
, args
, complain
);
2412 /* A call where the function is unknown. */
2413 result
= cp_build_function_call_vec (fn
, args
, complain
);
2415 if (processing_template_decl
&& result
!= error_mark_node
)
2417 if (INDIRECT_REF_P (result
))
2418 result
= TREE_OPERAND (result
, 0);
2419 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2420 SET_EXPR_LOCATION (result
, input_location
);
2421 KOENIG_LOOKUP_P (result
) = koenig_p
;
2422 release_tree_vector (orig_args
);
2423 result
= convert_from_reference (result
);
2428 /* Free garbage OVERLOADs from arg-dependent lookup. */
2429 tree next
= NULL_TREE
;
2431 fn
&& TREE_CODE (fn
) == OVERLOAD
&& OVL_ARG_DEPENDENT (fn
);
2434 if (processing_template_decl
)
2435 /* In a template, we'll re-use them at instantiation time. */
2436 OVL_ARG_DEPENDENT (fn
) = false;
2439 next
= OVL_CHAIN (fn
);
2448 /* Instantiate a variable declaration from a TEMPLATE_ID_EXPR for use. */
2451 finish_template_variable (tree var
)
2453 return instantiate_template (TREE_OPERAND (var
, 0), TREE_OPERAND (var
, 1),
2457 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2458 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2459 POSTDECREMENT_EXPR.) */
2462 finish_increment_expr (tree expr
, enum tree_code code
)
2464 return build_x_unary_op (input_location
, code
, expr
, tf_warning_or_error
);
2467 /* Finish a use of `this'. Returns an expression for `this'. */
2470 finish_this_expr (void)
2472 tree result
= NULL_TREE
;
2474 if (current_class_ptr
)
2476 tree type
= TREE_TYPE (current_class_ref
);
2478 /* In a lambda expression, 'this' refers to the captured 'this'. */
2479 if (LAMBDA_TYPE_P (type
))
2480 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2482 result
= current_class_ptr
;
2486 /* The keyword 'this' is a prvalue expression. */
2487 return rvalue (result
);
2489 tree fn
= current_nonlambda_function ();
2490 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2491 error ("%<this%> is unavailable for static member functions");
2493 error ("invalid use of %<this%> in non-member function");
2495 error ("invalid use of %<this%> at top level");
2496 return error_mark_node
;
2499 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2500 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2501 the TYPE for the type given. If SCOPE is non-NULL, the expression
2502 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2505 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2508 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2509 return error_mark_node
;
2511 gcc_assert (TYPE_P (destructor
));
2513 if (!processing_template_decl
)
2515 if (scope
== error_mark_node
)
2517 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2518 return error_mark_node
;
2520 if (is_auto (destructor
))
2521 destructor
= TREE_TYPE (object
);
2522 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
2525 "qualified type %qT does not match destructor name ~%qT",
2527 return error_mark_node
;
2531 /* [expr.pseudo] says both:
2533 The type designated by the pseudo-destructor-name shall be
2534 the same as the object type.
2538 The cv-unqualified versions of the object type and of the
2539 type designated by the pseudo-destructor-name shall be the
2542 We implement the more generous second sentence, since that is
2543 what most other compilers do. */
2544 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
2547 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
2548 return error_mark_node
;
2552 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, void_type_node
, object
,
2556 /* Finish an expression of the form CODE EXPR. */
2559 finish_unary_op_expr (location_t loc
, enum tree_code code
, tree expr
,
2560 tsubst_flags_t complain
)
2562 tree result
= build_x_unary_op (loc
, code
, expr
, complain
);
2563 if ((complain
& tf_warning
)
2564 && TREE_OVERFLOW_P (result
) && !TREE_OVERFLOW_P (expr
))
2565 overflow_warning (input_location
, result
);
2570 /* Finish a compound-literal expression. TYPE is the type to which
2571 the CONSTRUCTOR in COMPOUND_LITERAL is being cast. */
2574 finish_compound_literal (tree type
, tree compound_literal
,
2575 tsubst_flags_t complain
)
2577 if (type
== error_mark_node
)
2578 return error_mark_node
;
2580 if (TREE_CODE (type
) == REFERENCE_TYPE
)
2583 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
2585 return cp_build_c_cast (type
, compound_literal
, complain
);
2588 if (!TYPE_OBJ_P (type
))
2590 if (complain
& tf_error
)
2591 error ("compound literal of non-object type %qT", type
);
2592 return error_mark_node
;
2595 if (processing_template_decl
)
2597 TREE_TYPE (compound_literal
) = type
;
2598 /* Mark the expression as a compound literal. */
2599 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
2600 return compound_literal
;
2603 type
= complete_type (type
);
2605 if (TYPE_NON_AGGREGATE_CLASS (type
))
2607 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
2608 everywhere that deals with function arguments would be a pain, so
2609 just wrap it in a TREE_LIST. The parser set a flag so we know
2610 that it came from T{} rather than T({}). */
2611 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
2612 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
2613 return build_functional_cast (type
, compound_literal
, complain
);
2616 if (TREE_CODE (type
) == ARRAY_TYPE
2617 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
2618 return error_mark_node
;
2619 compound_literal
= reshape_init (type
, compound_literal
, complain
);
2620 if (SCALAR_TYPE_P (type
)
2621 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
)
2622 && !check_narrowing (type
, compound_literal
, complain
))
2623 return error_mark_node
;
2624 if (TREE_CODE (type
) == ARRAY_TYPE
2625 && TYPE_DOMAIN (type
) == NULL_TREE
)
2627 cp_complete_array_type_or_error (&type
, compound_literal
,
2629 if (type
== error_mark_node
)
2630 return error_mark_node
;
2632 compound_literal
= digest_init (type
, compound_literal
, complain
);
2633 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
2634 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
2635 /* Put static/constant array temporaries in static variables, but always
2636 represent class temporaries with TARGET_EXPR so we elide copies. */
2637 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
2638 && TREE_CODE (type
) == ARRAY_TYPE
2639 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
2640 && initializer_constant_valid_p (compound_literal
, type
))
2642 tree decl
= create_temporary_var (type
);
2643 DECL_INITIAL (decl
) = compound_literal
;
2644 TREE_STATIC (decl
) = 1;
2645 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
2647 /* 5.19 says that a constant expression can include an
2648 lvalue-rvalue conversion applied to "a glvalue of literal type
2649 that refers to a non-volatile temporary object initialized
2650 with a constant expression". Rather than try to communicate
2651 that this VAR_DECL is a temporary, just mark it constexpr. */
2652 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
2653 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
2654 TREE_CONSTANT (decl
) = true;
2656 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
2657 decl
= pushdecl_top_level (decl
);
2658 DECL_NAME (decl
) = make_anon_name ();
2659 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
2660 /* Make sure the destructor is callable. */
2661 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
2662 if (clean
== error_mark_node
)
2663 return error_mark_node
;
2667 return get_target_expr_sfinae (compound_literal
, complain
);
2670 /* Return the declaration for the function-name variable indicated by
2674 finish_fname (tree id
)
2678 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
2679 if (processing_template_decl
&& current_function_decl
2680 && decl
!= error_mark_node
)
2681 decl
= DECL_NAME (decl
);
2685 /* Finish a translation unit. */
2688 finish_translation_unit (void)
2690 /* In case there were missing closebraces,
2691 get us back to the global binding level. */
2693 while (current_namespace
!= global_namespace
)
2696 /* Do file scope __FUNCTION__ et al. */
2697 finish_fname_decls ();
2700 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2701 Returns the parameter. */
2704 finish_template_type_parm (tree aggr
, tree identifier
)
2706 if (aggr
!= class_type_node
)
2708 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
2709 aggr
= class_type_node
;
2712 return build_tree_list (aggr
, identifier
);
2715 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2716 Returns the parameter. */
2719 finish_template_template_parm (tree aggr
, tree identifier
)
2721 tree decl
= build_decl (input_location
,
2722 TYPE_DECL
, identifier
, NULL_TREE
);
2723 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
2724 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
2725 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
2726 DECL_ARTIFICIAL (decl
) = 1;
2727 end_template_decl ();
2729 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
2731 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
2732 /*is_primary=*/true, /*is_partial=*/false,
2735 return finish_template_type_parm (aggr
, tmpl
);
2738 /* ARGUMENT is the default-argument value for a template template
2739 parameter. If ARGUMENT is invalid, issue error messages and return
2740 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2743 check_template_template_default_arg (tree argument
)
2745 if (TREE_CODE (argument
) != TEMPLATE_DECL
2746 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
2747 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
2749 if (TREE_CODE (argument
) == TYPE_DECL
)
2750 error ("invalid use of type %qT as a default value for a template "
2751 "template-parameter", TREE_TYPE (argument
));
2753 error ("invalid default argument for a template template parameter");
2754 return error_mark_node
;
2760 /* Begin a class definition, as indicated by T. */
2763 begin_class_definition (tree t
)
2765 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
2766 return error_mark_node
;
2768 if (processing_template_parmlist
)
2770 error ("definition of %q#T inside template parameter list", t
);
2771 return error_mark_node
;
2774 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
2775 are passed the same as decimal scalar types. */
2776 if (TREE_CODE (t
) == RECORD_TYPE
2777 && !processing_template_decl
)
2779 tree ns
= TYPE_CONTEXT (t
);
2780 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
2781 && DECL_CONTEXT (ns
) == std_node
2783 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (ns
)), "decimal"))
2785 const char *n
= TYPE_NAME_STRING (t
);
2786 if ((strcmp (n
, "decimal32") == 0)
2787 || (strcmp (n
, "decimal64") == 0)
2788 || (strcmp (n
, "decimal128") == 0))
2789 TYPE_TRANSPARENT_AGGR (t
) = 1;
2793 /* A non-implicit typename comes from code like:
2795 template <typename T> struct A {
2796 template <typename U> struct A<T>::B ...
2798 This is erroneous. */
2799 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
2801 error ("invalid definition of qualified type %qT", t
);
2802 t
= error_mark_node
;
2805 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
2807 t
= make_class_type (RECORD_TYPE
);
2808 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
2811 if (TYPE_BEING_DEFINED (t
))
2813 t
= make_class_type (TREE_CODE (t
));
2814 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
2816 maybe_process_partial_specialization (t
);
2818 TYPE_BEING_DEFINED (t
) = 1;
2819 class_binding_level
->defining_class_p
= 1;
2821 if (flag_pack_struct
)
2824 TYPE_PACKED (t
) = 1;
2825 /* Even though the type is being defined for the first time
2826 here, there might have been a forward declaration, so there
2827 might be cv-qualified variants of T. */
2828 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
2829 TYPE_PACKED (v
) = 1;
2831 /* Reset the interface data, at the earliest possible
2832 moment, as it might have been set via a class foo;
2834 if (! TYPE_ANONYMOUS_P (t
))
2836 struct c_fileinfo
*finfo
= \
2837 get_fileinfo (LOCATION_FILE (input_location
));
2838 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
2839 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2840 (t
, finfo
->interface_unknown
);
2842 reset_specialization();
2844 /* Make a declaration for this class in its own scope. */
2845 build_self_reference ();
2850 /* Finish the member declaration given by DECL. */
2853 finish_member_declaration (tree decl
)
2855 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
2858 if (decl
== void_type_node
)
2859 /* The COMPONENT was a friend, not a member, and so there's
2860 nothing for us to do. */
2863 /* We should see only one DECL at a time. */
2864 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
2866 /* Set up access control for DECL. */
2868 = (current_access_specifier
== access_private_node
);
2869 TREE_PROTECTED (decl
)
2870 = (current_access_specifier
== access_protected_node
);
2871 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
2873 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
2874 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
2877 /* Mark the DECL as a member of the current class, unless it's
2878 a member of an enumeration. */
2879 if (TREE_CODE (decl
) != CONST_DECL
)
2880 DECL_CONTEXT (decl
) = current_class_type
;
2882 /* Check for bare parameter packs in the member variable declaration. */
2883 if (TREE_CODE (decl
) == FIELD_DECL
)
2885 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
2886 TREE_TYPE (decl
) = error_mark_node
;
2887 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
2888 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
2893 A C language linkage is ignored for the names of class members
2894 and the member function type of class member functions. */
2895 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
2896 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
2898 /* Put functions on the TYPE_METHODS list and everything else on the
2899 TYPE_FIELDS list. Note that these are built up in reverse order.
2900 We reverse them (to obtain declaration order) in finish_struct. */
2901 if (DECL_DECLARES_FUNCTION_P (decl
))
2903 /* We also need to add this function to the
2904 CLASSTYPE_METHOD_VEC. */
2905 if (add_method (current_class_type
, decl
, NULL_TREE
))
2907 DECL_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
2908 TYPE_METHODS (current_class_type
) = decl
;
2910 maybe_add_class_template_decl_list (current_class_type
, decl
,
2914 /* Enter the DECL into the scope of the class, if the class
2915 isn't a closure (whose fields are supposed to be unnamed). */
2916 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
2917 || pushdecl_class_level (decl
))
2919 if (TREE_CODE (decl
) == USING_DECL
)
2921 /* For now, ignore class-scope USING_DECLS, so that
2922 debugging backends do not see them. */
2923 DECL_IGNORED_P (decl
) = 1;
2926 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2927 go at the beginning. The reason is that lookup_field_1
2928 searches the list in order, and we want a field name to
2929 override a type name so that the "struct stat hack" will
2930 work. In particular:
2932 struct S { enum E { }; int E } s;
2935 is valid. In addition, the FIELD_DECLs must be maintained in
2936 declaration order so that class layout works as expected.
2937 However, we don't need that order until class layout, so we
2938 save a little time by putting FIELD_DECLs on in reverse order
2939 here, and then reversing them in finish_struct_1. (We could
2940 also keep a pointer to the correct insertion points in the
2943 if (TREE_CODE (decl
) == TYPE_DECL
)
2944 TYPE_FIELDS (current_class_type
)
2945 = chainon (TYPE_FIELDS (current_class_type
), decl
);
2948 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
2949 TYPE_FIELDS (current_class_type
) = decl
;
2952 maybe_add_class_template_decl_list (current_class_type
, decl
,
2957 note_decl_for_pch (decl
);
2960 /* DECL has been declared while we are building a PCH file. Perform
2961 actions that we might normally undertake lazily, but which can be
2962 performed now so that they do not have to be performed in
2963 translation units which include the PCH file. */
2966 note_decl_for_pch (tree decl
)
2968 gcc_assert (pch_file
);
2970 /* There's a good chance that we'll have to mangle names at some
2971 point, even if only for emission in debugging information. */
2972 if (VAR_OR_FUNCTION_DECL_P (decl
)
2973 && !processing_template_decl
)
2977 /* Finish processing a complete template declaration. The PARMS are
2978 the template parameters. */
2981 finish_template_decl (tree parms
)
2984 end_template_decl ();
2986 end_specialization ();
2989 /* Finish processing a template-id (which names a type) of the form
2990 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2991 template-id. If ENTERING_SCOPE is nonzero we are about to enter
2992 the scope of template-id indicated. */
2995 finish_template_type (tree name
, tree args
, int entering_scope
)
2999 type
= lookup_template_class (name
, args
,
3000 NULL_TREE
, NULL_TREE
, entering_scope
,
3001 tf_warning_or_error
| tf_user
);
3002 if (type
== error_mark_node
)
3004 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3005 return TYPE_STUB_DECL (type
);
3007 return TYPE_NAME (type
);
3010 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3011 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3012 BASE_CLASS, or NULL_TREE if an error occurred. The
3013 ACCESS_SPECIFIER is one of
3014 access_{default,public,protected_private}_node. For a virtual base
3015 we set TREE_TYPE. */
3018 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3022 if (base
== error_mark_node
)
3024 error ("invalid base-class specification");
3027 else if (! MAYBE_CLASS_TYPE_P (base
))
3029 error ("%qT is not a class type", base
);
3034 if (cp_type_quals (base
) != 0)
3036 /* DR 484: Can a base-specifier name a cv-qualified
3038 base
= TYPE_MAIN_VARIANT (base
);
3040 result
= build_tree_list (access
, base
);
3042 TREE_TYPE (result
) = integer_type_node
;
3048 /* If FNS is a member function, a set of member functions, or a
3049 template-id referring to one or more member functions, return a
3050 BASELINK for FNS, incorporating the current access context.
3051 Otherwise, return FNS unchanged. */
3054 baselink_for_fns (tree fns
)
3059 if (BASELINK_P (fns
)
3060 || error_operand_p (fns
))
3063 scope
= ovl_scope (fns
);
3064 if (!CLASS_TYPE_P (scope
))
3067 cl
= currently_open_derived_class (scope
);
3070 cl
= TYPE_BINFO (cl
);
3071 return build_baselink (cl
, cl
, fns
, /*optype=*/NULL_TREE
);
3074 /* Returns true iff DECL is a variable from a function outside
3078 outer_var_p (tree decl
)
3080 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3081 && DECL_FUNCTION_SCOPE_P (decl
)
3082 && (DECL_CONTEXT (decl
) != current_function_decl
3083 || parsing_nsdmi ()));
3086 /* As above, but also checks that DECL is automatic. */
3089 outer_automatic_var_p (tree decl
)
3091 return (outer_var_p (decl
)
3092 && !TREE_STATIC (decl
));
3095 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3096 rewrite it for lambda capture. */
3099 process_outer_var_ref (tree decl
, tsubst_flags_t complain
)
3101 if (cp_unevaluated_operand
)
3102 /* It's not a use (3.2) if we're in an unevaluated context. */
3105 tree context
= DECL_CONTEXT (decl
);
3106 tree containing_function
= current_function_decl
;
3107 tree lambda_stack
= NULL_TREE
;
3108 tree lambda_expr
= NULL_TREE
;
3109 tree initializer
= convert_from_reference (decl
);
3111 /* Mark it as used now even if the use is ill-formed. */
3114 /* Core issue 696: "[At the July 2009 meeting] the CWG expressed
3115 support for an approach in which a reference to a local
3116 [constant] automatic variable in a nested class or lambda body
3117 would enter the expression as an rvalue, which would reduce
3118 the complexity of the problem"
3120 FIXME update for final resolution of core issue 696. */
3121 if (decl_maybe_constant_var_p (decl
))
3123 if (processing_template_decl
)
3124 /* In a template, the constant value may not be in a usable
3125 form, so wait until instantiation time. */
3127 else if (decl_constant_var_p (decl
))
3128 return scalar_constant_value (decl
);
3131 if (parsing_nsdmi ())
3132 containing_function
= NULL_TREE
;
3134 /* If we are in a lambda function, we can move out until we hit
3136 2. a non-lambda function, or
3137 3. a non-default capturing lambda function. */
3138 while (context
!= containing_function
3139 && LAMBDA_FUNCTION_P (containing_function
))
3141 lambda_expr
= CLASSTYPE_LAMBDA_EXPR
3142 (DECL_CONTEXT (containing_function
));
3144 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
)
3148 lambda_stack
= tree_cons (NULL_TREE
,
3153 = decl_function_context (containing_function
);
3156 if (lambda_expr
&& TREE_CODE (decl
) == VAR_DECL
3157 && DECL_ANON_UNION_VAR_P (decl
))
3159 if (complain
& tf_error
)
3160 error ("cannot capture member %qD of anonymous union", decl
);
3161 return error_mark_node
;
3163 if (context
== containing_function
)
3165 decl
= add_default_capture (lambda_stack
,
3166 /*id=*/DECL_NAME (decl
),
3169 else if (lambda_expr
)
3171 if (complain
& tf_error
)
3172 error ("%qD is not captured", decl
);
3173 return error_mark_node
;
3177 if (complain
& tf_error
)
3179 ? G_("use of local variable with automatic storage from containing function")
3180 : G_("use of parameter from containing function"));
3181 inform (input_location
, "%q+#D declared here", decl
);
3182 return error_mark_node
;
3187 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3188 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3189 if non-NULL, is the type or namespace used to explicitly qualify
3190 ID_EXPRESSION. DECL is the entity to which that name has been
3193 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3194 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3195 be set to true if this expression isn't permitted in a
3196 constant-expression, but it is otherwise not set by this function.
3197 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3198 constant-expression, but a non-constant expression is also
3201 DONE is true if this expression is a complete postfix-expression;
3202 it is false if this expression is followed by '->', '[', '(', etc.
3203 ADDRESS_P is true iff this expression is the operand of '&'.
3204 TEMPLATE_P is true iff the qualified-id was of the form
3205 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3206 appears as a template argument.
3208 If an error occurs, and it is the kind of error that might cause
3209 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3210 is the caller's responsibility to issue the message. *ERROR_MSG
3211 will be a string with static storage duration, so the caller need
3214 Return an expression for the entity, after issuing appropriate
3215 diagnostics. This function is also responsible for transforming a
3216 reference to a non-static member into a COMPONENT_REF that makes
3217 the use of "this" explicit.
3219 Upon return, *IDK will be filled in appropriately. */
3221 finish_id_expression (tree id_expression
,
3225 bool integral_constant_expression_p
,
3226 bool allow_non_integral_constant_expression_p
,
3227 bool *non_integral_constant_expression_p
,
3231 bool template_arg_p
,
3232 const char **error_msg
,
3233 location_t location
)
3235 decl
= strip_using_decl (decl
);
3237 /* Initialize the output parameters. */
3238 *idk
= CP_ID_KIND_NONE
;
3241 if (id_expression
== error_mark_node
)
3242 return error_mark_node
;
3243 /* If we have a template-id, then no further lookup is
3244 required. If the template-id was for a template-class, we
3245 will sometimes have a TYPE_DECL at this point. */
3246 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3247 || TREE_CODE (decl
) == TYPE_DECL
)
3249 /* Look up the name. */
3252 if (decl
== error_mark_node
)
3254 /* Name lookup failed. */
3257 || (!dependent_type_p (scope
)
3258 && !(identifier_p (id_expression
)
3259 && IDENTIFIER_TYPENAME_P (id_expression
)
3260 && dependent_type_p (TREE_TYPE (id_expression
))))))
3262 /* If the qualifying type is non-dependent (and the name
3263 does not name a conversion operator to a dependent
3264 type), issue an error. */
3265 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3266 return error_mark_node
;
3270 /* It may be resolved via Koenig lookup. */
3271 *idk
= CP_ID_KIND_UNQUALIFIED
;
3272 return id_expression
;
3275 decl
= id_expression
;
3277 /* If DECL is a variable that would be out of scope under
3278 ANSI/ISO rules, but in scope in the ARM, name lookup
3279 will succeed. Issue a diagnostic here. */
3281 decl
= check_for_out_of_scope_variable (decl
);
3283 /* Remember that the name was used in the definition of
3284 the current class so that we can check later to see if
3285 the meaning would have been different after the class
3286 was entirely defined. */
3287 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3288 maybe_note_name_used_in_class (id_expression
, decl
);
3290 /* Disallow uses of local variables from containing functions, except
3291 within lambda-expressions. */
3292 if (outer_automatic_var_p (decl
))
3294 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3295 if (decl
== error_mark_node
)
3296 return error_mark_node
;
3299 /* Also disallow uses of function parameters outside the function
3300 body, except inside an unevaluated context (i.e. decltype). */
3301 if (TREE_CODE (decl
) == PARM_DECL
3302 && DECL_CONTEXT (decl
) == NULL_TREE
3303 && !cp_unevaluated_operand
)
3305 *error_msg
= "use of parameter outside function body";
3306 return error_mark_node
;
3310 /* If we didn't find anything, or what we found was a type,
3311 then this wasn't really an id-expression. */
3312 if (TREE_CODE (decl
) == TEMPLATE_DECL
3313 && !DECL_FUNCTION_TEMPLATE_P (decl
))
3315 *error_msg
= "missing template arguments";
3316 return error_mark_node
;
3318 else if (TREE_CODE (decl
) == TYPE_DECL
3319 || TREE_CODE (decl
) == NAMESPACE_DECL
)
3321 *error_msg
= "expected primary-expression";
3322 return error_mark_node
;
3325 /* If the name resolved to a template parameter, there is no
3326 need to look it up again later. */
3327 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
3328 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3332 *idk
= CP_ID_KIND_NONE
;
3333 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
3334 decl
= TEMPLATE_PARM_DECL (decl
);
3335 r
= convert_from_reference (DECL_INITIAL (decl
));
3337 if (integral_constant_expression_p
3338 && !dependent_type_p (TREE_TYPE (decl
))
3339 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
3341 if (!allow_non_integral_constant_expression_p
)
3342 error ("template parameter %qD of type %qT is not allowed in "
3343 "an integral constant expression because it is not of "
3344 "integral or enumeration type", decl
, TREE_TYPE (decl
));
3345 *non_integral_constant_expression_p
= true;
3353 /* If the declaration was explicitly qualified indicate
3354 that. The semantics of `A::f(3)' are different than
3355 `f(3)' if `f' is virtual. */
3357 ? CP_ID_KIND_QUALIFIED
3358 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3359 ? CP_ID_KIND_TEMPLATE_ID
3360 : CP_ID_KIND_UNQUALIFIED
));
3365 An id-expression is type-dependent if it contains an
3366 identifier that was declared with a dependent type.
3368 The standard is not very specific about an id-expression that
3369 names a set of overloaded functions. What if some of them
3370 have dependent types and some of them do not? Presumably,
3371 such a name should be treated as a dependent name. */
3372 /* Assume the name is not dependent. */
3373 dependent_p
= false;
3374 if (!processing_template_decl
)
3375 /* No names are dependent outside a template. */
3377 else if (TREE_CODE (decl
) == CONST_DECL
)
3378 /* We don't want to treat enumerators as dependent. */
3380 /* A template-id where the name of the template was not resolved
3381 is definitely dependent. */
3382 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3383 && (identifier_p (TREE_OPERAND (decl
, 0))))
3385 /* For anything except an overloaded function, just check its
3387 else if (!is_overloaded_fn (decl
))
3389 = dependent_type_p (TREE_TYPE (decl
));
3390 /* For a set of overloaded functions, check each of the
3396 if (BASELINK_P (fns
))
3397 fns
= BASELINK_FUNCTIONS (fns
);
3399 /* For a template-id, check to see if the template
3400 arguments are dependent. */
3401 if (TREE_CODE (fns
) == TEMPLATE_ID_EXPR
)
3403 tree args
= TREE_OPERAND (fns
, 1);
3404 dependent_p
= any_dependent_template_arguments_p (args
);
3405 /* The functions are those referred to by the
3407 fns
= TREE_OPERAND (fns
, 0);
3410 /* If there are no dependent template arguments, go through
3411 the overloaded functions. */
3412 while (fns
&& !dependent_p
)
3414 tree fn
= OVL_CURRENT (fns
);
3416 /* Member functions of dependent classes are
3418 if (TREE_CODE (fn
) == FUNCTION_DECL
3419 && type_dependent_expression_p (fn
))
3421 else if (TREE_CODE (fn
) == TEMPLATE_DECL
3422 && dependent_template_p (fn
))
3425 fns
= OVL_NEXT (fns
);
3429 /* If the name was dependent on a template parameter, we will
3430 resolve the name at instantiation time. */
3433 /* Create a SCOPE_REF for qualified names, if the scope is
3439 if (address_p
&& done
)
3440 decl
= finish_qualified_id_expr (scope
, decl
,
3444 tf_warning_or_error
);
3447 tree type
= NULL_TREE
;
3448 if (DECL_P (decl
) && !dependent_scope_p (scope
))
3449 type
= TREE_TYPE (decl
);
3450 decl
= build_qualified_name (type
,
3456 if (TREE_TYPE (decl
))
3457 decl
= convert_from_reference (decl
);
3460 /* A TEMPLATE_ID already contains all the information we
3462 if (TREE_CODE (id_expression
) == TEMPLATE_ID_EXPR
)
3463 return id_expression
;
3464 *idk
= CP_ID_KIND_UNQUALIFIED_DEPENDENT
;
3465 /* If we found a variable, then name lookup during the
3466 instantiation will always resolve to the same VAR_DECL
3467 (or an instantiation thereof). */
3469 || TREE_CODE (decl
) == PARM_DECL
)
3472 return convert_from_reference (decl
);
3474 /* The same is true for FIELD_DECL, but we also need to
3475 make sure that the syntax is correct. */
3476 else if (TREE_CODE (decl
) == FIELD_DECL
)
3478 /* Since SCOPE is NULL here, this is an unqualified name.
3479 Access checking has been performed during name lookup
3480 already. Turn off checking to avoid duplicate errors. */
3481 push_deferring_access_checks (dk_no_check
);
3482 decl
= finish_non_static_data_member
3484 /*qualifying_scope=*/NULL_TREE
);
3485 pop_deferring_access_checks ();
3488 return id_expression
;
3491 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
3493 error ("use of namespace %qD as expression", decl
);
3494 return error_mark_node
;
3496 else if (DECL_CLASS_TEMPLATE_P (decl
))
3498 error ("use of class template %qT as expression", decl
);
3499 return error_mark_node
;
3501 else if (TREE_CODE (decl
) == TREE_LIST
)
3503 /* Ambiguous reference to base members. */
3504 error ("request for member %qD is ambiguous in "
3505 "multiple inheritance lattice", id_expression
);
3506 print_candidates (decl
);
3507 return error_mark_node
;
3510 /* Mark variable-like entities as used. Functions are similarly
3511 marked either below or after overload resolution. */
3513 || TREE_CODE (decl
) == PARM_DECL
3514 || TREE_CODE (decl
) == CONST_DECL
3515 || TREE_CODE (decl
) == RESULT_DECL
)
3516 && !mark_used (decl
))
3517 return error_mark_node
;
3519 /* Only certain kinds of names are allowed in constant
3520 expression. Template parameters have already
3521 been handled above. */
3522 if (! error_operand_p (decl
)
3523 && integral_constant_expression_p
3524 && ! decl_constant_var_p (decl
)
3525 && TREE_CODE (decl
) != CONST_DECL
3526 && ! builtin_valid_in_constant_expr_p (decl
))
3528 if (!allow_non_integral_constant_expression_p
)
3530 error ("%qD cannot appear in a constant-expression", decl
);
3531 return error_mark_node
;
3533 *non_integral_constant_expression_p
= true;
3538 && !cp_unevaluated_operand
3539 && !processing_template_decl
3540 && (TREE_STATIC (decl
) || DECL_EXTERNAL (decl
))
3541 && DECL_THREAD_LOCAL_P (decl
)
3542 && (wrap
= get_tls_wrapper_fn (decl
)))
3544 /* Replace an evaluated use of the thread_local variable with
3545 a call to its wrapper. */
3546 decl
= build_cxx_call (wrap
, 0, NULL
, tf_warning_or_error
);
3548 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3549 && variable_template_p (TREE_OPERAND (decl
, 0)))
3551 decl
= finish_template_variable (decl
);
3556 decl
= (adjust_result_of_qualified_name_lookup
3557 (decl
, scope
, current_nonlambda_class_type()));
3559 if (TREE_CODE (decl
) == FUNCTION_DECL
)
3563 decl
= finish_qualified_id_expr (scope
,
3569 tf_warning_or_error
);
3571 decl
= convert_from_reference (decl
);
3573 else if (TREE_CODE (decl
) == FIELD_DECL
)
3575 /* Since SCOPE is NULL here, this is an unqualified name.
3576 Access checking has been performed during name lookup
3577 already. Turn off checking to avoid duplicate errors. */
3578 push_deferring_access_checks (dk_no_check
);
3579 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
3580 /*qualifying_scope=*/NULL_TREE
);
3581 pop_deferring_access_checks ();
3583 else if (is_overloaded_fn (decl
))
3587 first_fn
= get_first_fn (decl
);
3588 if (TREE_CODE (first_fn
) == TEMPLATE_DECL
)
3589 first_fn
= DECL_TEMPLATE_RESULT (first_fn
);
3591 if (!really_overloaded_fn (decl
)
3592 && !mark_used (first_fn
))
3593 return error_mark_node
;
3596 && TREE_CODE (first_fn
) == FUNCTION_DECL
3597 && DECL_FUNCTION_MEMBER_P (first_fn
)
3598 && !shared_member_p (decl
))
3600 /* A set of member functions. */
3601 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
3602 return finish_class_member_access_expr (decl
, id_expression
,
3603 /*template_p=*/false,
3604 tf_warning_or_error
);
3607 decl
= baselink_for_fns (decl
);
3611 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
3612 && DECL_CLASS_SCOPE_P (decl
))
3614 tree context
= context_for_name_lookup (decl
);
3615 if (context
!= current_class_type
)
3617 tree path
= currently_open_derived_class (context
);
3618 perform_or_defer_access_check (TYPE_BINFO (path
),
3620 tf_warning_or_error
);
3624 decl
= convert_from_reference (decl
);
3628 /* Handle references (c++/56130). */
3629 tree t
= REFERENCE_REF_P (decl
) ? TREE_OPERAND (decl
, 0) : decl
;
3630 if (TREE_DEPRECATED (t
))
3631 warn_deprecated_use (t
, NULL_TREE
);
3636 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
3637 use as a type-specifier. */
3640 finish_typeof (tree expr
)
3644 if (type_dependent_expression_p (expr
))
3646 type
= cxx_make_type (TYPEOF_TYPE
);
3647 TYPEOF_TYPE_EXPR (type
) = expr
;
3648 SET_TYPE_STRUCTURAL_EQUALITY (type
);
3653 expr
= mark_type_use (expr
);
3655 type
= unlowered_expr_type (expr
);
3657 if (!type
|| type
== unknown_type_node
)
3659 error ("type of %qE is unknown", expr
);
3660 return error_mark_node
;
3666 /* Implement the __underlying_type keyword: Return the underlying
3667 type of TYPE, suitable for use as a type-specifier. */
3670 finish_underlying_type (tree type
)
3672 tree underlying_type
;
3674 if (processing_template_decl
)
3676 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
3677 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
3678 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
3680 return underlying_type
;
3683 complete_type (type
);
3685 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
3687 error ("%qT is not an enumeration type", type
);
3688 return error_mark_node
;
3691 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
3693 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
3694 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
3695 See finish_enum_value_list for details. */
3696 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
3698 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
3699 TYPE_UNSIGNED (underlying_type
));
3701 return underlying_type
;
3704 /* Implement the __direct_bases keyword: Return the direct base classes
3708 calculate_direct_bases (tree type
)
3710 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3711 tree bases_vec
= NULL_TREE
;
3712 vec
<tree
, va_gc
> *base_binfos
;
3716 complete_type (type
);
3718 if (!NON_UNION_CLASS_TYPE_P (type
))
3719 return make_tree_vec (0);
3721 base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
3723 /* Virtual bases are initialized first */
3724 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3726 if (BINFO_VIRTUAL_P (binfo
))
3728 vec_safe_push (vector
, binfo
);
3732 /* Now non-virtuals */
3733 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
3735 if (!BINFO_VIRTUAL_P (binfo
))
3737 vec_safe_push (vector
, binfo
);
3742 bases_vec
= make_tree_vec (vector
->length ());
3744 for (i
= 0; i
< vector
->length (); ++i
)
3746 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
3751 /* Implement the __bases keyword: Return the base classes
3754 /* Find morally non-virtual base classes by walking binfo hierarchy */
3755 /* Virtual base classes are handled separately in finish_bases */
3758 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
3760 /* Don't walk bases of virtual bases */
3761 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
3765 dfs_calculate_bases_post (tree binfo
, void *data_
)
3767 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
3768 if (!BINFO_VIRTUAL_P (binfo
))
3770 vec_safe_push (*data
, BINFO_TYPE (binfo
));
3775 /* Calculates the morally non-virtual base classes of a class */
3776 static vec
<tree
, va_gc
> *
3777 calculate_bases_helper (tree type
)
3779 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3781 /* Now add non-virtual base classes in order of construction */
3782 dfs_walk_all (TYPE_BINFO (type
),
3783 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
3788 calculate_bases (tree type
)
3790 vec
<tree
, va_gc
> *vector
= make_tree_vector();
3791 tree bases_vec
= NULL_TREE
;
3793 vec
<tree
, va_gc
> *vbases
;
3794 vec
<tree
, va_gc
> *nonvbases
;
3797 complete_type (type
);
3799 if (!NON_UNION_CLASS_TYPE_P (type
))
3800 return make_tree_vec (0);
3802 /* First go through virtual base classes */
3803 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
3804 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
3806 vec
<tree
, va_gc
> *vbase_bases
;
3807 vbase_bases
= calculate_bases_helper (BINFO_TYPE (binfo
));
3808 vec_safe_splice (vector
, vbase_bases
);
3809 release_tree_vector (vbase_bases
);
3812 /* Now for the non-virtual bases */
3813 nonvbases
= calculate_bases_helper (type
);
3814 vec_safe_splice (vector
, nonvbases
);
3815 release_tree_vector (nonvbases
);
3817 /* Last element is entire class, so don't copy */
3818 bases_vec
= make_tree_vec (vector
->length () - 1);
3820 for (i
= 0; i
< vector
->length () - 1; ++i
)
3822 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
3824 release_tree_vector (vector
);
3829 finish_bases (tree type
, bool direct
)
3831 tree bases
= NULL_TREE
;
3833 if (!processing_template_decl
)
3835 /* Parameter packs can only be used in templates */
3836 error ("Parameter pack __bases only valid in template declaration");
3837 return error_mark_node
;
3840 bases
= cxx_make_type (BASES
);
3841 BASES_TYPE (bases
) = type
;
3842 BASES_DIRECT (bases
) = direct
;
3843 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
3848 /* Perform C++-specific checks for __builtin_offsetof before calling
3852 finish_offsetof (tree expr
, location_t loc
)
3854 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
3856 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
3857 TREE_OPERAND (expr
, 2));
3858 return error_mark_node
;
3860 if (TREE_CODE (TREE_TYPE (expr
)) == FUNCTION_TYPE
3861 || TREE_CODE (TREE_TYPE (expr
)) == METHOD_TYPE
3862 || TREE_TYPE (expr
) == unknown_type_node
)
3864 if (INDIRECT_REF_P (expr
))
3865 error ("second operand of %<offsetof%> is neither a single "
3866 "identifier nor a sequence of member accesses and "
3867 "array references");
3870 if (TREE_CODE (expr
) == COMPONENT_REF
3871 || TREE_CODE (expr
) == COMPOUND_EXPR
)
3872 expr
= TREE_OPERAND (expr
, 1);
3873 error ("cannot apply %<offsetof%> to member function %qD", expr
);
3875 return error_mark_node
;
3877 if (REFERENCE_REF_P (expr
))
3878 expr
= TREE_OPERAND (expr
, 0);
3879 if (TREE_CODE (expr
) == COMPONENT_REF
)
3881 tree object
= TREE_OPERAND (expr
, 0);
3882 if (!complete_type_or_else (TREE_TYPE (object
), object
))
3883 return error_mark_node
;
3884 if (warn_invalid_offsetof
3885 && CLASS_TYPE_P (TREE_TYPE (object
))
3886 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (object
))
3887 && cp_unevaluated_operand
== 0)
3888 pedwarn (loc
, OPT_Winvalid_offsetof
,
3889 "offsetof within non-standard-layout type %qT is undefined",
3890 TREE_TYPE (object
));
3892 return fold_offsetof (expr
);
3895 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
3896 function is broken out from the above for the benefit of the tree-ssa
3900 simplify_aggr_init_expr (tree
*tp
)
3902 tree aggr_init_expr
= *tp
;
3904 /* Form an appropriate CALL_EXPR. */
3905 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
3906 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
3907 tree type
= TREE_TYPE (slot
);
3910 enum style_t
{ ctor
, arg
, pcc
} style
;
3912 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
3914 #ifdef PCC_STATIC_STRUCT_RETURN
3920 gcc_assert (TREE_ADDRESSABLE (type
));
3924 call_expr
= build_call_array_loc (input_location
,
3925 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
3927 aggr_init_expr_nargs (aggr_init_expr
),
3928 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
3929 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
3930 CALL_EXPR_LIST_INIT_P (call_expr
) = CALL_EXPR_LIST_INIT_P (aggr_init_expr
);
3934 /* Replace the first argument to the ctor with the address of the
3936 cxx_mark_addressable (slot
);
3937 CALL_EXPR_ARG (call_expr
, 0) =
3938 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
3940 else if (style
== arg
)
3942 /* Just mark it addressable here, and leave the rest to
3943 expand_call{,_inline}. */
3944 cxx_mark_addressable (slot
);
3945 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
3946 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
3948 else if (style
== pcc
)
3950 /* If we're using the non-reentrant PCC calling convention, then we
3951 need to copy the returned value out of the static buffer into the
3953 push_deferring_access_checks (dk_no_check
);
3954 call_expr
= build_aggr_init (slot
, call_expr
,
3955 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
3956 tf_warning_or_error
);
3957 pop_deferring_access_checks ();
3958 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
3961 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
3963 tree init
= build_zero_init (type
, NULL_TREE
,
3964 /*static_storage_p=*/false);
3965 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
3966 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
3973 /* Emit all thunks to FN that should be emitted when FN is emitted. */
3976 emit_associated_thunks (tree fn
)
3978 /* When we use vcall offsets, we emit thunks with the virtual
3979 functions to which they thunk. The whole point of vcall offsets
3980 is so that you can know statically the entire set of thunks that
3981 will ever be needed for a given virtual function, thereby
3982 enabling you to output all the thunks with the function itself. */
3983 if (DECL_VIRTUAL_P (fn
)
3984 /* Do not emit thunks for extern template instantiations. */
3985 && ! DECL_REALLY_EXTERN (fn
))
3989 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
3991 if (!THUNK_ALIAS (thunk
))
3993 use_thunk (thunk
, /*emit_p=*/1);
3994 if (DECL_RESULT_THUNK_P (thunk
))
3998 for (probe
= DECL_THUNKS (thunk
);
3999 probe
; probe
= DECL_CHAIN (probe
))
4000 use_thunk (probe
, /*emit_p=*/1);
4004 gcc_assert (!DECL_THUNKS (thunk
));
4009 /* Generate RTL for FN. */
4012 expand_or_defer_fn_1 (tree fn
)
4014 /* When the parser calls us after finishing the body of a template
4015 function, we don't really want to expand the body. */
4016 if (processing_template_decl
)
4018 /* Normally, collection only occurs in rest_of_compilation. So,
4019 if we don't collect here, we never collect junk generated
4020 during the processing of templates until we hit a
4021 non-template function. It's not safe to do this inside a
4022 nested class, though, as the parser may have local state that
4023 is not a GC root. */
4024 if (!function_depth
)
4029 gcc_assert (DECL_SAVED_TREE (fn
));
4031 /* We make a decision about linkage for these functions at the end
4032 of the compilation. Until that point, we do not want the back
4033 end to output them -- but we do want it to see the bodies of
4034 these functions so that it can inline them as appropriate. */
4035 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4037 if (DECL_INTERFACE_KNOWN (fn
))
4038 /* We've already made a decision as to how this function will
4041 tentative_decl_linkage (fn
);
4043 import_export_decl (fn
);
4045 /* If the user wants us to keep all inline functions, then mark
4046 this function as needed so that finish_file will make sure to
4047 output it later. Similarly, all dllexport'd functions must
4048 be emitted; there may be callers in other DLLs. */
4049 if (DECL_DECLARED_INLINE_P (fn
)
4050 && !DECL_REALLY_EXTERN (fn
)
4051 && (flag_keep_inline_functions
4052 || (flag_keep_inline_dllexport
4053 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4056 DECL_EXTERNAL (fn
) = 0;
4060 /* If this is a constructor or destructor body, we have to clone
4062 if (maybe_clone_body (fn
))
4064 /* We don't want to process FN again, so pretend we've written
4065 it out, even though we haven't. */
4066 TREE_ASM_WRITTEN (fn
) = 1;
4067 /* If this is an instantiation of a constexpr function, keep
4068 DECL_SAVED_TREE for explain_invalid_constexpr_fn. */
4069 if (!is_instantiation_of_constexpr (fn
))
4070 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4074 /* There's no reason to do any of the work here if we're only doing
4075 semantic analysis; this code just generates RTL. */
4076 if (flag_syntax_only
)
4083 expand_or_defer_fn (tree fn
)
4085 if (expand_or_defer_fn_1 (fn
))
4089 /* Expand or defer, at the whim of the compilation unit manager. */
4090 cgraph_node::finalize_function (fn
, function_depth
> 1);
4091 emit_associated_thunks (fn
);
4099 nrv_data () : visited (37) {}
4103 hash_table
<pointer_hash
<tree_node
> > visited
;
4106 /* Helper function for walk_tree, used by finalize_nrv below. */
4109 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4111 struct nrv_data
*dp
= (struct nrv_data
*)data
;
4114 /* No need to walk into types. There wouldn't be any need to walk into
4115 non-statements, except that we have to consider STMT_EXPRs. */
4118 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4119 but differs from using NULL_TREE in that it indicates that we care
4120 about the value of the RESULT_DECL. */
4121 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4122 TREE_OPERAND (*tp
, 0) = dp
->result
;
4123 /* Change all cleanups for the NRV to only run when an exception is
4125 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4126 && CLEANUP_DECL (*tp
) == dp
->var
)
4127 CLEANUP_EH_ONLY (*tp
) = 1;
4128 /* Replace the DECL_EXPR for the NRV with an initialization of the
4129 RESULT_DECL, if needed. */
4130 else if (TREE_CODE (*tp
) == DECL_EXPR
4131 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4134 if (DECL_INITIAL (dp
->var
)
4135 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4136 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4137 DECL_INITIAL (dp
->var
));
4139 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4140 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4141 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4144 /* And replace all uses of the NRV with the RESULT_DECL. */
4145 else if (*tp
== dp
->var
)
4148 /* Avoid walking into the same tree more than once. Unfortunately, we
4149 can't just use walk_tree_without duplicates because it would only call
4150 us for the first occurrence of dp->var in the function body. */
4151 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4157 /* Keep iterating. */
4161 /* Called from finish_function to implement the named return value
4162 optimization by overriding all the RETURN_EXPRs and pertinent
4163 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4164 RESULT_DECL for the function. */
4167 finalize_nrv (tree
*tp
, tree var
, tree result
)
4169 struct nrv_data data
;
4171 /* Copy name from VAR to RESULT. */
4172 DECL_NAME (result
) = DECL_NAME (var
);
4173 /* Don't forget that we take its address. */
4174 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4175 /* Finally set DECL_VALUE_EXPR to avoid assigning
4176 a stack slot at -O0 for the original var and debug info
4177 uses RESULT location for VAR. */
4178 SET_DECL_VALUE_EXPR (var
, result
);
4179 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4182 data
.result
= result
;
4183 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4186 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4189 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4190 bool need_copy_ctor
, bool need_copy_assignment
,
4193 int save_errorcount
= errorcount
;
4196 /* Always allocate 3 elements for simplicity. These are the
4197 function decls for the ctor, dtor, and assignment op.
4198 This layout is known to the three lang hooks,
4199 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4200 and cxx_omp_clause_assign_op. */
4201 info
= make_tree_vec (3);
4202 CP_OMP_CLAUSE_INFO (c
) = info
;
4204 if (need_default_ctor
|| need_copy_ctor
)
4206 if (need_default_ctor
)
4207 t
= get_default_ctor (type
);
4209 t
= get_copy_ctor (type
, tf_warning_or_error
);
4211 if (t
&& !trivial_fn_p (t
))
4212 TREE_VEC_ELT (info
, 0) = t
;
4215 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4216 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4218 if (need_copy_assignment
)
4220 t
= get_copy_assign (type
);
4222 if (t
&& !trivial_fn_p (t
))
4223 TREE_VEC_ELT (info
, 2) = t
;
4226 return errorcount
!= save_errorcount
;
4229 /* Helper function for handle_omp_array_sections. Called recursively
4230 to handle multiple array-section-subscripts. C is the clause,
4231 T current expression (initially OMP_CLAUSE_DECL), which is either
4232 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4233 expression if specified, TREE_VALUE length expression if specified,
4234 TREE_CHAIN is what it has been specified after, or some decl.
4235 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4236 set to true if any of the array-section-subscript could have length
4237 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4238 first array-section-subscript which is known not to have length
4240 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4241 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4242 all are or may have length of 1, array-section-subscript [:2] is the
4243 first one knonwn not to have length 1. For array-section-subscript
4244 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4245 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4246 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4247 case though, as some lengths could be zero. */
4250 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4251 bool &maybe_zero_len
, unsigned int &first_non_one
)
4253 tree ret
, low_bound
, length
, type
;
4254 if (TREE_CODE (t
) != TREE_LIST
)
4256 if (error_operand_p (t
))
4257 return error_mark_node
;
4258 if (type_dependent_expression_p (t
))
4260 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
4262 if (processing_template_decl
)
4265 error_at (OMP_CLAUSE_LOCATION (c
),
4266 "%qD is not a variable in %qs clause", t
,
4267 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4269 error_at (OMP_CLAUSE_LOCATION (c
),
4270 "%qE is not a variable in %qs clause", t
,
4271 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4272 return error_mark_node
;
4274 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4275 && TREE_CODE (t
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (t
))
4277 error_at (OMP_CLAUSE_LOCATION (c
),
4278 "%qD is threadprivate variable in %qs clause", t
,
4279 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4280 return error_mark_node
;
4282 t
= convert_from_reference (t
);
4286 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
4287 maybe_zero_len
, first_non_one
);
4288 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
4291 type
= TREE_TYPE (ret
);
4292 low_bound
= TREE_PURPOSE (t
);
4293 length
= TREE_VALUE (t
);
4294 if ((low_bound
&& type_dependent_expression_p (low_bound
))
4295 || (length
&& type_dependent_expression_p (length
)))
4298 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
4299 return error_mark_node
;
4301 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
4303 error_at (OMP_CLAUSE_LOCATION (c
),
4304 "low bound %qE of array section does not have integral type",
4306 return error_mark_node
;
4308 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
4310 error_at (OMP_CLAUSE_LOCATION (c
),
4311 "length %qE of array section does not have integral type",
4313 return error_mark_node
;
4316 low_bound
= mark_rvalue_use (low_bound
);
4318 length
= mark_rvalue_use (length
);
4320 && TREE_CODE (low_bound
) == INTEGER_CST
4321 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4322 > TYPE_PRECISION (sizetype
))
4323 low_bound
= fold_convert (sizetype
, low_bound
);
4325 && TREE_CODE (length
) == INTEGER_CST
4326 && TYPE_PRECISION (TREE_TYPE (length
))
4327 > TYPE_PRECISION (sizetype
))
4328 length
= fold_convert (sizetype
, length
);
4329 if (low_bound
== NULL_TREE
)
4330 low_bound
= integer_zero_node
;
4332 if (length
!= NULL_TREE
)
4334 if (!integer_nonzerop (length
))
4335 maybe_zero_len
= true;
4336 if (first_non_one
== types
.length ()
4337 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
4340 if (TREE_CODE (type
) == ARRAY_TYPE
)
4342 if (length
== NULL_TREE
4343 && (TYPE_DOMAIN (type
) == NULL_TREE
4344 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
4346 error_at (OMP_CLAUSE_LOCATION (c
),
4347 "for unknown bound array type length expression must "
4349 return error_mark_node
;
4351 if (TREE_CODE (low_bound
) == INTEGER_CST
4352 && tree_int_cst_sgn (low_bound
) == -1)
4354 error_at (OMP_CLAUSE_LOCATION (c
),
4355 "negative low bound in array section in %qs clause",
4356 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4357 return error_mark_node
;
4359 if (length
!= NULL_TREE
4360 && TREE_CODE (length
) == INTEGER_CST
4361 && tree_int_cst_sgn (length
) == -1)
4363 error_at (OMP_CLAUSE_LOCATION (c
),
4364 "negative length in array section in %qs clause",
4365 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4366 return error_mark_node
;
4368 if (TYPE_DOMAIN (type
)
4369 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
4370 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
4373 tree size
= size_binop (PLUS_EXPR
,
4374 TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4376 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4378 if (tree_int_cst_lt (size
, low_bound
))
4380 error_at (OMP_CLAUSE_LOCATION (c
),
4381 "low bound %qE above array section size "
4382 "in %qs clause", low_bound
,
4383 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4384 return error_mark_node
;
4386 if (tree_int_cst_equal (size
, low_bound
))
4387 maybe_zero_len
= true;
4388 else if (length
== NULL_TREE
4389 && first_non_one
== types
.length ()
4390 && tree_int_cst_equal
4391 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
4395 else if (length
== NULL_TREE
)
4397 maybe_zero_len
= true;
4398 if (first_non_one
== types
.length ())
4401 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
4403 if (tree_int_cst_lt (size
, length
))
4405 error_at (OMP_CLAUSE_LOCATION (c
),
4406 "length %qE above array section size "
4407 "in %qs clause", length
,
4408 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4409 return error_mark_node
;
4411 if (TREE_CODE (low_bound
) == INTEGER_CST
)
4414 = size_binop (PLUS_EXPR
,
4415 fold_convert (sizetype
, low_bound
),
4416 fold_convert (sizetype
, length
));
4417 if (TREE_CODE (lbpluslen
) == INTEGER_CST
4418 && tree_int_cst_lt (size
, lbpluslen
))
4420 error_at (OMP_CLAUSE_LOCATION (c
),
4421 "high bound %qE above array section size "
4422 "in %qs clause", lbpluslen
,
4423 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4424 return error_mark_node
;
4429 else if (length
== NULL_TREE
)
4431 maybe_zero_len
= true;
4432 if (first_non_one
== types
.length ())
4436 /* For [lb:] we will need to evaluate lb more than once. */
4437 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4439 tree lb
= cp_save_expr (low_bound
);
4440 if (lb
!= low_bound
)
4442 TREE_PURPOSE (t
) = lb
;
4447 else if (TREE_CODE (type
) == POINTER_TYPE
)
4449 if (length
== NULL_TREE
)
4451 error_at (OMP_CLAUSE_LOCATION (c
),
4452 "for pointer type length expression must be specified");
4453 return error_mark_node
;
4455 /* If there is a pointer type anywhere but in the very first
4456 array-section-subscript, the array section can't be contiguous. */
4457 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
4458 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
4460 error_at (OMP_CLAUSE_LOCATION (c
),
4461 "array section is not contiguous in %qs clause",
4462 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4463 return error_mark_node
;
4468 error_at (OMP_CLAUSE_LOCATION (c
),
4469 "%qE does not have pointer or array type", ret
);
4470 return error_mark_node
;
4472 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
4473 types
.safe_push (TREE_TYPE (ret
));
4474 /* We will need to evaluate lb more than once. */
4475 tree lb
= cp_save_expr (low_bound
);
4476 if (lb
!= low_bound
)
4478 TREE_PURPOSE (t
) = lb
;
4481 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
4485 /* Handle array sections for clause C. */
4488 handle_omp_array_sections (tree c
)
4490 bool maybe_zero_len
= false;
4491 unsigned int first_non_one
= 0;
4492 auto_vec
<tree
> types
;
4493 tree first
= handle_omp_array_sections_1 (c
, OMP_CLAUSE_DECL (c
), types
,
4494 maybe_zero_len
, first_non_one
);
4495 if (first
== error_mark_node
)
4497 if (first
== NULL_TREE
)
4499 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
)
4501 tree t
= OMP_CLAUSE_DECL (c
);
4502 tree tem
= NULL_TREE
;
4503 if (processing_template_decl
)
4505 /* Need to evaluate side effects in the length expressions
4507 while (TREE_CODE (t
) == TREE_LIST
)
4509 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
4511 if (tem
== NULL_TREE
)
4512 tem
= TREE_VALUE (t
);
4514 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
4515 TREE_VALUE (t
), tem
);
4520 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
4521 OMP_CLAUSE_DECL (c
) = first
;
4525 unsigned int num
= types
.length (), i
;
4526 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
4527 tree condition
= NULL_TREE
;
4529 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
4530 maybe_zero_len
= true;
4531 if (processing_template_decl
&& maybe_zero_len
)
4534 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
4537 tree low_bound
= TREE_PURPOSE (t
);
4538 tree length
= TREE_VALUE (t
);
4542 && TREE_CODE (low_bound
) == INTEGER_CST
4543 && TYPE_PRECISION (TREE_TYPE (low_bound
))
4544 > TYPE_PRECISION (sizetype
))
4545 low_bound
= fold_convert (sizetype
, low_bound
);
4547 && TREE_CODE (length
) == INTEGER_CST
4548 && TYPE_PRECISION (TREE_TYPE (length
))
4549 > TYPE_PRECISION (sizetype
))
4550 length
= fold_convert (sizetype
, length
);
4551 if (low_bound
== NULL_TREE
)
4552 low_bound
= integer_zero_node
;
4553 if (!maybe_zero_len
&& i
> first_non_one
)
4555 if (integer_nonzerop (low_bound
))
4556 goto do_warn_noncontiguous
;
4557 if (length
!= NULL_TREE
4558 && TREE_CODE (length
) == INTEGER_CST
4559 && TYPE_DOMAIN (types
[i
])
4560 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
4561 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
4565 size
= size_binop (PLUS_EXPR
,
4566 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4568 if (!tree_int_cst_equal (length
, size
))
4570 do_warn_noncontiguous
:
4571 error_at (OMP_CLAUSE_LOCATION (c
),
4572 "array section is not contiguous in %qs "
4574 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
4578 if (!processing_template_decl
4579 && length
!= NULL_TREE
4580 && TREE_SIDE_EFFECTS (length
))
4582 if (side_effects
== NULL_TREE
)
4583 side_effects
= length
;
4585 side_effects
= build2 (COMPOUND_EXPR
,
4586 TREE_TYPE (side_effects
),
4587 length
, side_effects
);
4590 else if (processing_template_decl
)
4596 if (i
> first_non_one
&& length
&& integer_nonzerop (length
))
4599 l
= fold_convert (sizetype
, length
);
4602 l
= size_binop (PLUS_EXPR
,
4603 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
4605 l
= size_binop (MINUS_EXPR
, l
,
4606 fold_convert (sizetype
, low_bound
));
4608 if (i
> first_non_one
)
4610 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
4612 if (condition
== NULL_TREE
)
4615 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
4618 else if (size
== NULL_TREE
)
4620 size
= size_in_bytes (TREE_TYPE (types
[i
]));
4621 size
= size_binop (MULT_EXPR
, size
, l
);
4623 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
4624 size
, size_zero_node
);
4627 size
= size_binop (MULT_EXPR
, size
, l
);
4630 if (!processing_template_decl
)
4633 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
4634 OMP_CLAUSE_DECL (c
) = first
;
4635 OMP_CLAUSE_SIZE (c
) = size
;
4636 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
4638 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
4640 OMP_CLAUSE_MAP_KIND (c2
) = OMP_CLAUSE_MAP_POINTER
;
4641 if (!cxx_mark_addressable (t
))
4643 OMP_CLAUSE_DECL (c2
) = t
;
4644 t
= build_fold_addr_expr (first
);
4645 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4646 ptrdiff_type_node
, t
);
4647 tree ptr
= OMP_CLAUSE_DECL (c2
);
4648 ptr
= convert_from_reference (ptr
);
4649 if (!POINTER_TYPE_P (TREE_TYPE (ptr
)))
4650 ptr
= build_fold_addr_expr (ptr
);
4651 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
4652 ptrdiff_type_node
, t
,
4653 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
4654 ptrdiff_type_node
, ptr
));
4655 OMP_CLAUSE_SIZE (c2
) = t
;
4656 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
4657 OMP_CLAUSE_CHAIN (c
) = c2
;
4658 ptr
= OMP_CLAUSE_DECL (c2
);
4659 if (TREE_CODE (TREE_TYPE (ptr
)) == REFERENCE_TYPE
4660 && POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
4662 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
4664 OMP_CLAUSE_MAP_KIND (c3
) = OMP_CLAUSE_MAP_POINTER
;
4665 OMP_CLAUSE_DECL (c3
) = ptr
;
4666 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
4667 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
4668 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
4669 OMP_CLAUSE_CHAIN (c2
) = c3
;
4676 /* Return identifier to look up for omp declare reduction. */
4679 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
4681 const char *p
= NULL
;
4682 const char *m
= NULL
;
4683 switch (reduction_code
)
4691 case TRUTH_ANDIF_EXPR
:
4692 case TRUTH_ORIF_EXPR
:
4693 reduction_id
= ansi_opname (reduction_code
);
4707 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
4708 return error_mark_node
;
4709 p
= IDENTIFIER_POINTER (reduction_id
);
4712 if (type
!= NULL_TREE
)
4713 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
4715 const char prefix
[] = "omp declare reduction ";
4716 size_t lenp
= sizeof (prefix
);
4717 if (strncmp (p
, prefix
, lenp
- 1) == 0)
4719 size_t len
= strlen (p
);
4720 size_t lenm
= m
? strlen (m
) + 1 : 0;
4721 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
4723 memcpy (name
, prefix
, lenp
- 1);
4724 memcpy (name
+ lenp
- 1, p
, len
+ 1);
4727 name
[lenp
+ len
- 1] = '~';
4728 memcpy (name
+ lenp
+ len
, m
, lenm
);
4730 return get_identifier (name
);
4733 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
4734 FUNCTION_DECL or NULL_TREE if not found. */
4737 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
4738 vec
<tree
> *ambiguousp
)
4741 tree baselink
= NULL_TREE
;
4742 if (identifier_p (id
))
4745 bool nonint_cst_expression_p
;
4746 const char *error_msg
;
4747 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
4748 tree decl
= lookup_name (id
);
4749 if (decl
== NULL_TREE
)
4750 decl
= error_mark_node
;
4751 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
4752 &nonint_cst_expression_p
, false, true, false,
4753 false, &error_msg
, loc
);
4754 if (idk
== CP_ID_KIND_UNQUALIFIED
4755 && identifier_p (id
))
4757 vec
<tree
, va_gc
> *args
= NULL
;
4758 vec_safe_push (args
, build_reference_type (type
));
4759 id
= perform_koenig_lookup (id
, args
, tf_none
);
4762 else if (TREE_CODE (id
) == SCOPE_REF
)
4763 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
4764 omp_reduction_id (ERROR_MARK
,
4765 TREE_OPERAND (id
, 1),
4769 if (id
&& is_overloaded_fn (id
))
4771 for (; id
; id
= OVL_NEXT (id
))
4773 tree fndecl
= OVL_CURRENT (id
);
4774 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
4776 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
4777 if (same_type_p (TREE_TYPE (argtype
), type
))
4781 if (id
&& BASELINK_P (fns
))
4788 if (id
== NULL_TREE
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
4790 vec
<tree
> ambiguous
= vNULL
;
4791 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
4793 if (ambiguousp
== NULL
)
4794 ambiguousp
= &ambiguous
;
4795 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
4797 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
4798 baselinkp
? baselinkp
: &baselink
,
4800 if (id
== NULL_TREE
)
4802 if (!ambiguousp
->is_empty ())
4803 ambiguousp
->safe_push (id
);
4804 else if (ret
!= NULL_TREE
)
4806 ambiguousp
->safe_push (ret
);
4807 ambiguousp
->safe_push (id
);
4813 if (ambiguousp
!= &ambiguous
)
4815 if (!ambiguous
.is_empty ())
4817 const char *str
= _("candidates are:");
4820 error_at (loc
, "user defined reduction lookup is ambiguous");
4821 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
4823 inform (DECL_SOURCE_LOCATION (udr
), "%s %#D", str
, udr
);
4825 str
= get_spaces (str
);
4827 ambiguous
.release ();
4828 ret
= error_mark_node
;
4829 baselink
= NULL_TREE
;
4834 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
4835 id
, id
, tf_warning_or_error
);
4839 /* Helper function for cp_parser_omp_declare_reduction_exprs
4841 Remove CLEANUP_STMT for data (omp_priv variable).
4842 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
4846 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
4850 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
4851 *tp
= CLEANUP_BODY (*tp
);
4852 else if (TREE_CODE (*tp
) == DECL_EXPR
)
4854 tree decl
= DECL_EXPR_DECL (*tp
);
4855 if (!processing_template_decl
4856 && decl
== (tree
) data
4857 && DECL_INITIAL (decl
)
4858 && DECL_INITIAL (decl
) != error_mark_node
)
4860 tree list
= NULL_TREE
;
4861 append_to_statement_list_force (*tp
, &list
);
4862 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
4863 decl
, DECL_INITIAL (decl
));
4864 DECL_INITIAL (decl
) = NULL_TREE
;
4865 append_to_statement_list_force (init_expr
, &list
);
4872 /* Data passed from cp_check_omp_declare_reduction to
4873 cp_check_omp_declare_reduction_r. */
4875 struct cp_check_omp_declare_reduction_data
4882 /* Helper function for cp_check_omp_declare_reduction, called via
4886 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
4888 struct cp_check_omp_declare_reduction_data
*udr_data
4889 = (struct cp_check_omp_declare_reduction_data
*) data
;
4891 && !DECL_ARTIFICIAL (*tp
)
4892 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
4893 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
4895 location_t loc
= udr_data
->loc
;
4896 if (udr_data
->combiner_p
)
4897 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
4898 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
4901 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
4902 "to variable %qD which is not %<omp_priv%> nor "
4910 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
4913 cp_check_omp_declare_reduction (tree udr
)
4915 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
4916 gcc_assert (TREE_CODE (type
) == REFERENCE_TYPE
);
4917 type
= TREE_TYPE (type
);
4919 location_t loc
= DECL_SOURCE_LOCATION (udr
);
4921 if (type
== error_mark_node
)
4923 if (ARITHMETIC_TYPE_P (type
))
4925 static enum tree_code predef_codes
[]
4926 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
4927 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
4928 for (i
= 0; i
< 8; i
++)
4930 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
4931 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
4932 const char *n2
= IDENTIFIER_POINTER (id
);
4933 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
4934 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
4935 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
4940 && TREE_CODE (type
) != COMPLEX_EXPR
)
4942 const char prefix_minmax
[] = "omp declare reduction m";
4943 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
4944 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
4945 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
4946 prefix_minmax
, prefix_size
) == 0
4947 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
4948 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
4949 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
4954 error_at (loc
, "predeclared arithmetic type %qT in "
4955 "%<#pragma omp declare reduction%>", type
);
4959 else if (TREE_CODE (type
) == FUNCTION_TYPE
4960 || TREE_CODE (type
) == METHOD_TYPE
4961 || TREE_CODE (type
) == ARRAY_TYPE
)
4963 error_at (loc
, "function or array type %qT in "
4964 "%<#pragma omp declare reduction%>", type
);
4967 else if (TREE_CODE (type
) == REFERENCE_TYPE
)
4969 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
4973 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
4975 error_at (loc
, "const, volatile or __restrict qualified type %qT in "
4976 "%<#pragma omp declare reduction%>", type
);
4980 tree body
= DECL_SAVED_TREE (udr
);
4981 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
4984 tree_stmt_iterator tsi
;
4985 struct cp_check_omp_declare_reduction_data data
;
4986 memset (data
.stmts
, 0, sizeof data
.stmts
);
4987 for (i
= 0, tsi
= tsi_start (body
);
4988 i
< 7 && !tsi_end_p (tsi
);
4989 i
++, tsi_next (&tsi
))
4990 data
.stmts
[i
] = tsi_stmt (tsi
);
4992 gcc_assert (tsi_end_p (tsi
));
4995 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
4996 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
4997 if (TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])))
4999 data
.combiner_p
= true;
5000 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5002 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5006 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5007 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5008 data
.combiner_p
= false;
5009 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5011 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5012 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5013 TREE_NO_WARNING (DECL_EXPR_DECL (data
.stmts
[0])) = 1;
5015 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
5019 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
5020 an inline call. But, remap
5021 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
5022 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
5025 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
5026 tree decl
, tree placeholder
)
5029 hash_map
<tree
, tree
> decl_map
;
5031 decl_map
.put (omp_decl1
, placeholder
);
5032 decl_map
.put (omp_decl2
, decl
);
5033 memset (&id
, 0, sizeof (id
));
5034 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
5035 id
.dst_fn
= current_function_decl
;
5036 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
5037 id
.decl_map
= &decl_map
;
5039 id
.copy_decl
= copy_decl_no_change
;
5040 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
5041 id
.transform_new_cfg
= true;
5042 id
.transform_return_to_modify
= false;
5043 id
.transform_lang_insert_block
= NULL
;
5045 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
5049 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
5050 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
5053 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
5055 if (*tp
== (tree
) data
)
5060 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
5061 Return true if there is some error and the clause should be removed. */
5064 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
5066 tree t
= OMP_CLAUSE_DECL (c
);
5067 bool predefined
= false;
5068 tree type
= TREE_TYPE (t
);
5069 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5070 type
= TREE_TYPE (type
);
5071 if (type
== error_mark_node
)
5073 else if (ARITHMETIC_TYPE_P (type
))
5074 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
5083 if (TREE_CODE (type
) == COMPLEX_TYPE
)
5090 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
5094 case TRUTH_ANDIF_EXPR
:
5095 case TRUTH_ORIF_EXPR
:
5096 if (FLOAT_TYPE_P (type
))
5103 else if (TREE_CODE (type
) == ARRAY_TYPE
|| TYPE_READONLY (type
))
5105 error ("%qE has invalid type for %<reduction%>", t
);
5108 else if (!processing_template_decl
)
5110 t
= require_complete_type (t
);
5111 if (t
== error_mark_node
)
5113 OMP_CLAUSE_DECL (c
) = t
;
5118 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5121 else if (processing_template_decl
)
5124 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
5126 type
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
5127 if (TREE_CODE (type
) == REFERENCE_TYPE
)
5128 type
= TREE_TYPE (type
);
5129 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
5130 if (id
== NULL_TREE
)
5131 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
5132 NULL_TREE
, NULL_TREE
);
5133 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
5136 if (id
== error_mark_node
)
5138 id
= OVL_CURRENT (id
);
5140 tree body
= DECL_SAVED_TREE (id
);
5141 if (TREE_CODE (body
) == STATEMENT_LIST
)
5143 tree_stmt_iterator tsi
;
5144 tree placeholder
= NULL_TREE
;
5147 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
5148 atype
= TREE_TYPE (atype
);
5149 bool need_static_cast
= !same_type_p (type
, atype
);
5150 memset (stmts
, 0, sizeof stmts
);
5151 for (i
= 0, tsi
= tsi_start (body
);
5152 i
< 7 && !tsi_end_p (tsi
);
5153 i
++, tsi_next (&tsi
))
5154 stmts
[i
] = tsi_stmt (tsi
);
5155 gcc_assert (tsi_end_p (tsi
));
5159 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
5160 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
5161 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
5162 DECL_ARTIFICIAL (placeholder
) = 1;
5163 DECL_IGNORED_P (placeholder
) = 1;
5164 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
5165 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
5166 cxx_mark_addressable (placeholder
);
5167 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
5168 && TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
5170 cxx_mark_addressable (OMP_CLAUSE_DECL (c
));
5171 tree omp_out
= placeholder
;
5172 tree omp_in
= convert_from_reference (OMP_CLAUSE_DECL (c
));
5173 if (need_static_cast
)
5175 tree rtype
= build_reference_type (atype
);
5176 omp_out
= build_static_cast (rtype
, omp_out
,
5177 tf_warning_or_error
);
5178 omp_in
= build_static_cast (rtype
, omp_in
,
5179 tf_warning_or_error
);
5180 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
5182 omp_out
= convert_from_reference (omp_out
);
5183 omp_in
= convert_from_reference (omp_in
);
5185 OMP_CLAUSE_REDUCTION_MERGE (c
)
5186 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
5187 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
5191 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
5192 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
5193 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3])))
5194 cxx_mark_addressable (OMP_CLAUSE_DECL (c
));
5195 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
5196 cxx_mark_addressable (placeholder
);
5197 tree omp_priv
= convert_from_reference (OMP_CLAUSE_DECL (c
));
5198 tree omp_orig
= placeholder
;
5199 if (need_static_cast
)
5203 error_at (OMP_CLAUSE_LOCATION (c
),
5204 "user defined reduction with constructor "
5205 "initializer for base class %qT", atype
);
5208 tree rtype
= build_reference_type (atype
);
5209 omp_priv
= build_static_cast (rtype
, omp_priv
,
5210 tf_warning_or_error
);
5211 omp_orig
= build_static_cast (rtype
, omp_orig
,
5212 tf_warning_or_error
);
5213 if (omp_priv
== error_mark_node
5214 || omp_orig
== error_mark_node
)
5216 omp_priv
= convert_from_reference (omp_priv
);
5217 omp_orig
= convert_from_reference (omp_orig
);
5220 *need_default_ctor
= true;
5221 OMP_CLAUSE_REDUCTION_INIT (c
)
5222 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
5223 DECL_EXPR_DECL (stmts
[3]),
5224 omp_priv
, omp_orig
);
5225 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
5226 find_omp_placeholder_r
, placeholder
, NULL
))
5227 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
5231 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
5232 *need_default_ctor
= true;
5236 tree v
= convert_from_reference (t
);
5237 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
5238 init
= build_constructor (TREE_TYPE (v
), NULL
);
5240 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
5241 OMP_CLAUSE_REDUCTION_INIT (c
)
5242 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
5247 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
5251 error ("user defined reduction not found for %qD", t
);
5257 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
5258 Remove any elements from the list that are invalid. */
5261 finish_omp_clauses (tree clauses
)
5263 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
5264 bitmap_head aligned_head
;
5266 bool branch_seen
= false;
5267 bool copyprivate_seen
= false;
5269 bitmap_obstack_initialize (NULL
);
5270 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
5271 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
5272 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
5273 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
5275 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
5277 bool remove
= false;
5279 switch (OMP_CLAUSE_CODE (c
))
5281 case OMP_CLAUSE_SHARED
:
5282 goto check_dup_generic
;
5283 case OMP_CLAUSE_PRIVATE
:
5284 goto check_dup_generic
;
5285 case OMP_CLAUSE_REDUCTION
:
5286 goto check_dup_generic
;
5287 case OMP_CLAUSE_COPYPRIVATE
:
5288 copyprivate_seen
= true;
5289 goto check_dup_generic
;
5290 case OMP_CLAUSE_COPYIN
:
5291 goto check_dup_generic
;
5292 case OMP_CLAUSE_LINEAR
:
5293 t
= OMP_CLAUSE_DECL (c
);
5294 if (!type_dependent_expression_p (t
)
5295 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
5296 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
)
5298 error ("linear clause applied to non-integral non-pointer "
5299 "variable with %qT type", TREE_TYPE (t
));
5303 t
= OMP_CLAUSE_LINEAR_STEP (c
);
5305 t
= integer_one_node
;
5306 if (t
== error_mark_node
)
5311 else if (!type_dependent_expression_p (t
)
5312 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5314 error ("linear step expression must be integral");
5320 t
= mark_rvalue_use (t
);
5321 if (!processing_template_decl
)
5323 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
)
5324 t
= maybe_constant_value (t
);
5325 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5326 if (TREE_CODE (TREE_TYPE (OMP_CLAUSE_DECL (c
)))
5329 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
5330 OMP_CLAUSE_DECL (c
), t
);
5331 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
5332 MINUS_EXPR
, sizetype
, t
,
5333 OMP_CLAUSE_DECL (c
));
5334 if (t
== error_mark_node
)
5341 t
= fold_convert (TREE_TYPE (OMP_CLAUSE_DECL (c
)), t
);
5343 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
5345 goto check_dup_generic
;
5347 t
= OMP_CLAUSE_DECL (c
);
5348 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5350 if (processing_template_decl
)
5353 error ("%qD is not a variable in clause %qs", t
,
5354 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5356 error ("%qE is not a variable in clause %qs", t
,
5357 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5360 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
5361 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
5362 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
5364 error ("%qD appears more than once in data clauses", t
);
5368 bitmap_set_bit (&generic_head
, DECL_UID (t
));
5371 case OMP_CLAUSE_FIRSTPRIVATE
:
5372 t
= OMP_CLAUSE_DECL (c
);
5373 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5375 if (processing_template_decl
)
5378 error ("%qD is not a variable in clause %<firstprivate%>", t
);
5380 error ("%qE is not a variable in clause %<firstprivate%>", t
);
5383 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
5384 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
5386 error ("%qD appears more than once in data clauses", t
);
5390 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
5393 case OMP_CLAUSE_LASTPRIVATE
:
5394 t
= OMP_CLAUSE_DECL (c
);
5395 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5397 if (processing_template_decl
)
5400 error ("%qD is not a variable in clause %<lastprivate%>", t
);
5402 error ("%qE is not a variable in clause %<lastprivate%>", t
);
5405 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
5406 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
5408 error ("%qD appears more than once in data clauses", t
);
5412 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
5416 t
= OMP_CLAUSE_IF_EXPR (c
);
5417 t
= maybe_convert_cond (t
);
5418 if (t
== error_mark_node
)
5420 else if (!processing_template_decl
)
5421 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5422 OMP_CLAUSE_IF_EXPR (c
) = t
;
5425 case OMP_CLAUSE_FINAL
:
5426 t
= OMP_CLAUSE_FINAL_EXPR (c
);
5427 t
= maybe_convert_cond (t
);
5428 if (t
== error_mark_node
)
5430 else if (!processing_template_decl
)
5431 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5432 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
5435 case OMP_CLAUSE_NUM_THREADS
:
5436 t
= OMP_CLAUSE_NUM_THREADS_EXPR (c
);
5437 if (t
== error_mark_node
)
5439 else if (!type_dependent_expression_p (t
)
5440 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5442 error ("num_threads expression must be integral");
5447 t
= mark_rvalue_use (t
);
5448 if (!processing_template_decl
)
5449 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5450 OMP_CLAUSE_NUM_THREADS_EXPR (c
) = t
;
5454 case OMP_CLAUSE_SCHEDULE
:
5455 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
5458 else if (t
== error_mark_node
)
5460 else if (!type_dependent_expression_p (t
)
5461 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
5462 != OMP_CLAUSE_SCHEDULE_CILKFOR
)
5463 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5465 error ("schedule chunk size expression must be integral");
5470 t
= mark_rvalue_use (t
);
5471 if (!processing_template_decl
)
5473 if (OMP_CLAUSE_SCHEDULE_KIND (c
)
5474 == OMP_CLAUSE_SCHEDULE_CILKFOR
)
5476 t
= convert_to_integer (long_integer_type_node
, t
);
5477 if (t
== error_mark_node
)
5483 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5485 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
5489 case OMP_CLAUSE_SIMDLEN
:
5490 case OMP_CLAUSE_SAFELEN
:
5491 t
= OMP_CLAUSE_OPERAND (c
, 0);
5492 if (t
== error_mark_node
)
5494 else if (!type_dependent_expression_p (t
)
5495 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5497 error ("%qs length expression must be integral",
5498 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5503 t
= mark_rvalue_use (t
);
5504 t
= maybe_constant_value (t
);
5505 if (!processing_template_decl
)
5507 if (TREE_CODE (t
) != INTEGER_CST
5508 || tree_int_cst_sgn (t
) != 1)
5510 error ("%qs length expression must be positive constant"
5511 " integer expression",
5512 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5516 OMP_CLAUSE_OPERAND (c
, 0) = t
;
5520 case OMP_CLAUSE_NUM_TEAMS
:
5521 t
= OMP_CLAUSE_NUM_TEAMS_EXPR (c
);
5522 if (t
== error_mark_node
)
5524 else if (!type_dependent_expression_p (t
)
5525 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5527 error ("%<num_teams%> expression must be integral");
5532 t
= mark_rvalue_use (t
);
5533 if (!processing_template_decl
)
5534 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5535 OMP_CLAUSE_NUM_TEAMS_EXPR (c
) = t
;
5539 case OMP_CLAUSE_THREAD_LIMIT
:
5540 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
5541 if (t
== error_mark_node
)
5543 else if (!type_dependent_expression_p (t
)
5544 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5546 error ("%<thread_limit%> expression must be integral");
5551 t
= mark_rvalue_use (t
);
5552 if (!processing_template_decl
)
5553 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5554 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
5558 case OMP_CLAUSE_DEVICE
:
5559 t
= OMP_CLAUSE_DEVICE_ID (c
);
5560 if (t
== error_mark_node
)
5562 else if (!type_dependent_expression_p (t
)
5563 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5565 error ("%<device%> id must be integral");
5570 t
= mark_rvalue_use (t
);
5571 if (!processing_template_decl
)
5572 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5573 OMP_CLAUSE_DEVICE_ID (c
) = t
;
5577 case OMP_CLAUSE_DIST_SCHEDULE
:
5578 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
5581 else if (t
== error_mark_node
)
5583 else if (!type_dependent_expression_p (t
)
5584 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5586 error ("%<dist_schedule%> chunk size expression must be "
5592 t
= mark_rvalue_use (t
);
5593 if (!processing_template_decl
)
5594 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
5595 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
5599 case OMP_CLAUSE_ALIGNED
:
5600 t
= OMP_CLAUSE_DECL (c
);
5601 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
5603 if (processing_template_decl
)
5606 error ("%qD is not a variable in %<aligned%> clause", t
);
5608 error ("%qE is not a variable in %<aligned%> clause", t
);
5611 else if (!type_dependent_expression_p (t
)
5612 && TREE_CODE (TREE_TYPE (t
)) != POINTER_TYPE
5613 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
5614 && (TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
5615 || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
5616 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
5619 error_at (OMP_CLAUSE_LOCATION (c
),
5620 "%qE in %<aligned%> clause is neither a pointer nor "
5621 "an array nor a reference to pointer or array", t
);
5624 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
5626 error ("%qD appears more than once in %<aligned%> clauses", t
);
5630 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
5631 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
5632 if (t
== error_mark_node
)
5634 else if (t
== NULL_TREE
)
5636 else if (!type_dependent_expression_p (t
)
5637 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
5639 error ("%<aligned%> clause alignment expression must "
5645 t
= mark_rvalue_use (t
);
5646 t
= maybe_constant_value (t
);
5647 if (!processing_template_decl
)
5649 if (TREE_CODE (t
) != INTEGER_CST
5650 || tree_int_cst_sgn (t
) != 1)
5652 error ("%<aligned%> clause alignment expression must be "
5653 "positive constant integer expression");
5657 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
5661 case OMP_CLAUSE_DEPEND
:
5662 t
= OMP_CLAUSE_DECL (c
);
5663 if (TREE_CODE (t
) == TREE_LIST
)
5665 if (handle_omp_array_sections (c
))
5669 if (t
== error_mark_node
)
5671 else if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
5673 if (processing_template_decl
)
5676 error ("%qD is not a variable in %<depend%> clause", t
);
5678 error ("%qE is not a variable in %<depend%> clause", t
);
5681 else if (!processing_template_decl
5682 && !cxx_mark_addressable (t
))
5686 case OMP_CLAUSE_MAP
:
5688 case OMP_CLAUSE_FROM
:
5689 t
= OMP_CLAUSE_DECL (c
);
5690 if (TREE_CODE (t
) == TREE_LIST
)
5692 if (handle_omp_array_sections (c
))
5696 t
= OMP_CLAUSE_DECL (c
);
5697 if (TREE_CODE (t
) != TREE_LIST
5698 && !type_dependent_expression_p (t
)
5699 && !cp_omp_mappable_type (TREE_TYPE (t
)))
5701 error_at (OMP_CLAUSE_LOCATION (c
),
5702 "array section does not have mappable type "
5704 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5710 if (t
== error_mark_node
)
5712 else if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
5714 if (processing_template_decl
)
5716 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5717 && OMP_CLAUSE_MAP_KIND (c
) == OMP_CLAUSE_MAP_POINTER
)
5720 error ("%qD is not a variable in %qs clause", t
,
5721 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5723 error ("%qE is not a variable in %qs clause", t
,
5724 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5727 else if (TREE_CODE (t
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (t
))
5729 error ("%qD is threadprivate variable in %qs clause", t
,
5730 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5733 else if (!processing_template_decl
5734 && TREE_CODE (TREE_TYPE (t
)) != REFERENCE_TYPE
5735 && !cxx_mark_addressable (t
))
5737 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5738 && OMP_CLAUSE_MAP_KIND (c
) == OMP_CLAUSE_MAP_POINTER
)
5739 && !type_dependent_expression_p (t
)
5740 && !cp_omp_mappable_type ((TREE_CODE (TREE_TYPE (t
))
5742 ? TREE_TYPE (TREE_TYPE (t
))
5745 error_at (OMP_CLAUSE_LOCATION (c
),
5746 "%qD does not have a mappable type in %qs clause", t
,
5747 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5750 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
5752 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
5753 error ("%qD appears more than once in motion clauses", t
);
5755 error ("%qD appears more than once in map clauses", t
);
5759 bitmap_set_bit (&generic_head
, DECL_UID (t
));
5762 case OMP_CLAUSE_UNIFORM
:
5763 t
= OMP_CLAUSE_DECL (c
);
5764 if (TREE_CODE (t
) != PARM_DECL
)
5766 if (processing_template_decl
)
5769 error ("%qD is not an argument in %<uniform%> clause", t
);
5771 error ("%qE is not an argument in %<uniform%> clause", t
);
5775 goto check_dup_generic
;
5777 case OMP_CLAUSE_NOWAIT
:
5778 case OMP_CLAUSE_ORDERED
:
5779 case OMP_CLAUSE_DEFAULT
:
5780 case OMP_CLAUSE_UNTIED
:
5781 case OMP_CLAUSE_COLLAPSE
:
5782 case OMP_CLAUSE_MERGEABLE
:
5783 case OMP_CLAUSE_PARALLEL
:
5784 case OMP_CLAUSE_FOR
:
5785 case OMP_CLAUSE_SECTIONS
:
5786 case OMP_CLAUSE_TASKGROUP
:
5787 case OMP_CLAUSE_PROC_BIND
:
5788 case OMP_CLAUSE__CILK_FOR_COUNT_
:
5791 case OMP_CLAUSE_INBRANCH
:
5792 case OMP_CLAUSE_NOTINBRANCH
:
5795 error ("%<inbranch%> clause is incompatible with "
5807 *pc
= OMP_CLAUSE_CHAIN (c
);
5809 pc
= &OMP_CLAUSE_CHAIN (c
);
5812 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
5814 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
5815 bool remove
= false;
5816 bool need_complete_non_reference
= false;
5817 bool need_default_ctor
= false;
5818 bool need_copy_ctor
= false;
5819 bool need_copy_assignment
= false;
5820 bool need_implicitly_determined
= false;
5821 bool need_dtor
= false;
5822 tree type
, inner_type
;
5826 case OMP_CLAUSE_SHARED
:
5827 need_implicitly_determined
= true;
5829 case OMP_CLAUSE_PRIVATE
:
5830 need_complete_non_reference
= true;
5831 need_default_ctor
= true;
5833 need_implicitly_determined
= true;
5835 case OMP_CLAUSE_FIRSTPRIVATE
:
5836 need_complete_non_reference
= true;
5837 need_copy_ctor
= true;
5839 need_implicitly_determined
= true;
5841 case OMP_CLAUSE_LASTPRIVATE
:
5842 need_complete_non_reference
= true;
5843 need_copy_assignment
= true;
5844 need_implicitly_determined
= true;
5846 case OMP_CLAUSE_REDUCTION
:
5847 need_implicitly_determined
= true;
5849 case OMP_CLAUSE_COPYPRIVATE
:
5850 need_copy_assignment
= true;
5852 case OMP_CLAUSE_COPYIN
:
5853 need_copy_assignment
= true;
5855 case OMP_CLAUSE_NOWAIT
:
5856 if (copyprivate_seen
)
5858 error_at (OMP_CLAUSE_LOCATION (c
),
5859 "%<nowait%> clause must not be used together "
5860 "with %<copyprivate%>");
5861 *pc
= OMP_CLAUSE_CHAIN (c
);
5866 pc
= &OMP_CLAUSE_CHAIN (c
);
5870 t
= OMP_CLAUSE_DECL (c
);
5871 if (processing_template_decl
5872 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5874 pc
= &OMP_CLAUSE_CHAIN (c
);
5880 case OMP_CLAUSE_LASTPRIVATE
:
5881 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
5883 need_default_ctor
= true;
5888 case OMP_CLAUSE_REDUCTION
:
5889 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
5893 t
= OMP_CLAUSE_DECL (c
);
5896 case OMP_CLAUSE_COPYIN
:
5897 if (!VAR_P (t
) || !DECL_THREAD_LOCAL_P (t
))
5899 error ("%qE must be %<threadprivate%> for %<copyin%>", t
);
5908 if (need_complete_non_reference
|| need_copy_assignment
)
5910 t
= require_complete_type (t
);
5911 if (t
== error_mark_node
)
5913 else if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
5914 && need_complete_non_reference
)
5916 error ("%qE has reference type for %qs", t
,
5917 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5921 if (need_implicitly_determined
)
5923 const char *share_name
= NULL
;
5925 if (VAR_P (t
) && DECL_THREAD_LOCAL_P (t
))
5926 share_name
= "threadprivate";
5927 else switch (cxx_omp_predetermined_sharing (t
))
5929 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
5931 case OMP_CLAUSE_DEFAULT_SHARED
:
5932 /* const vars may be specified in firstprivate clause. */
5933 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
5934 && cxx_omp_const_qual_no_mutable (t
))
5936 share_name
= "shared";
5938 case OMP_CLAUSE_DEFAULT_PRIVATE
:
5939 share_name
= "private";
5946 error ("%qE is predetermined %qs for %qs",
5947 t
, share_name
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5952 /* We're interested in the base element, not arrays. */
5953 inner_type
= type
= TREE_TYPE (t
);
5954 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
5955 inner_type
= TREE_TYPE (inner_type
);
5957 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5958 && TREE_CODE (inner_type
) == REFERENCE_TYPE
)
5959 inner_type
= TREE_TYPE (inner_type
);
5961 /* Check for special function availability by building a call to one.
5962 Save the results, because later we won't be in the right context
5963 for making these queries. */
5964 if (CLASS_TYPE_P (inner_type
)
5965 && COMPLETE_TYPE_P (inner_type
)
5966 && (need_default_ctor
|| need_copy_ctor
5967 || need_copy_assignment
|| need_dtor
)
5968 && !type_dependent_expression_p (t
)
5969 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
5970 need_copy_ctor
, need_copy_assignment
,
5975 *pc
= OMP_CLAUSE_CHAIN (c
);
5977 pc
= &OMP_CLAUSE_CHAIN (c
);
5980 bitmap_obstack_release (NULL
);
5984 /* For all variables in the tree_list VARS, mark them as thread local. */
5987 finish_omp_threadprivate (tree vars
)
5991 /* Mark every variable in VARS to be assigned thread local storage. */
5992 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
5994 tree v
= TREE_PURPOSE (t
);
5996 if (error_operand_p (v
))
5998 else if (!VAR_P (v
))
5999 error ("%<threadprivate%> %qD is not file, namespace "
6000 "or block scope variable", v
);
6001 /* If V had already been marked threadprivate, it doesn't matter
6002 whether it had been used prior to this point. */
6003 else if (TREE_USED (v
)
6004 && (DECL_LANG_SPECIFIC (v
) == NULL
6005 || !CP_DECL_THREADPRIVATE_P (v
)))
6006 error ("%qE declared %<threadprivate%> after first use", v
);
6007 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
6008 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
6009 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
6010 error ("%<threadprivate%> %qE has incomplete type", v
);
6011 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
6012 && CP_DECL_CONTEXT (v
) != current_class_type
)
6013 error ("%<threadprivate%> %qE directive not "
6014 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
6017 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
6018 if (DECL_LANG_SPECIFIC (v
) == NULL
)
6020 retrofit_lang_decl (v
);
6022 /* Make sure that DECL_DISCRIMINATOR_P continues to be true
6023 after the allocation of the lang_decl structure. */
6024 if (DECL_DISCRIMINATOR_P (v
))
6025 DECL_LANG_SPECIFIC (v
)->u
.base
.u2sel
= 1;
6028 if (! DECL_THREAD_LOCAL_P (v
))
6030 set_decl_tls_model (v
, decl_default_tls_model (v
));
6031 /* If rtl has been already set for this var, call
6032 make_decl_rtl once again, so that encode_section_info
6033 has a chance to look at the new decl flags. */
6034 if (DECL_RTL_SET_P (v
))
6037 CP_DECL_THREADPRIVATE_P (v
) = 1;
6042 /* Build an OpenMP structured block. */
6045 begin_omp_structured_block (void)
6047 return do_pushlevel (sk_omp
);
6051 finish_omp_structured_block (tree block
)
6053 return do_poplevel (block
);
6056 /* Similarly, except force the retention of the BLOCK. */
6059 begin_omp_parallel (void)
6061 keep_next_level (true);
6062 return begin_omp_structured_block ();
6066 finish_omp_parallel (tree clauses
, tree body
)
6070 body
= finish_omp_structured_block (body
);
6072 stmt
= make_node (OMP_PARALLEL
);
6073 TREE_TYPE (stmt
) = void_type_node
;
6074 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
6075 OMP_PARALLEL_BODY (stmt
) = body
;
6077 return add_stmt (stmt
);
6081 begin_omp_task (void)
6083 keep_next_level (true);
6084 return begin_omp_structured_block ();
6088 finish_omp_task (tree clauses
, tree body
)
6092 body
= finish_omp_structured_block (body
);
6094 stmt
= make_node (OMP_TASK
);
6095 TREE_TYPE (stmt
) = void_type_node
;
6096 OMP_TASK_CLAUSES (stmt
) = clauses
;
6097 OMP_TASK_BODY (stmt
) = body
;
6099 return add_stmt (stmt
);
6102 /* Helper function for finish_omp_for. Convert Ith random access iterator
6103 into integral iterator. Return FALSE if successful. */
6106 handle_omp_for_class_iterator (int i
, location_t locus
, tree declv
, tree initv
,
6107 tree condv
, tree incrv
, tree
*body
,
6108 tree
*pre_body
, tree clauses
, tree
*lastp
)
6110 tree diff
, iter_init
, iter_incr
= NULL
, last
;
6111 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
6112 tree decl
= TREE_VEC_ELT (declv
, i
);
6113 tree init
= TREE_VEC_ELT (initv
, i
);
6114 tree cond
= TREE_VEC_ELT (condv
, i
);
6115 tree incr
= TREE_VEC_ELT (incrv
, i
);
6117 location_t elocus
= locus
;
6119 if (init
&& EXPR_HAS_LOCATION (init
))
6120 elocus
= EXPR_LOCATION (init
);
6122 switch (TREE_CODE (cond
))
6129 if (TREE_OPERAND (cond
, 1) == iter
)
6130 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
6131 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
6132 if (TREE_OPERAND (cond
, 0) != iter
)
6133 cond
= error_mark_node
;
6136 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
6139 TREE_OPERAND (cond
, 1), ERROR_MARK
,
6140 NULL
, tf_warning_or_error
);
6141 if (error_operand_p (tem
))
6146 cond
= error_mark_node
;
6149 if (cond
== error_mark_node
)
6151 error_at (elocus
, "invalid controlling predicate");
6154 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
6155 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
6156 tf_warning_or_error
);
6157 if (error_operand_p (diff
))
6159 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
6161 error_at (elocus
, "difference between %qE and %qD does not have integer type",
6162 TREE_OPERAND (cond
, 1), iter
);
6166 switch (TREE_CODE (incr
))
6168 case PREINCREMENT_EXPR
:
6169 case PREDECREMENT_EXPR
:
6170 case POSTINCREMENT_EXPR
:
6171 case POSTDECREMENT_EXPR
:
6172 if (TREE_OPERAND (incr
, 0) != iter
)
6174 incr
= error_mark_node
;
6177 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
6178 TREE_CODE (incr
), iter
,
6179 tf_warning_or_error
);
6180 if (error_operand_p (iter_incr
))
6182 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
6183 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
6184 incr
= integer_one_node
;
6186 incr
= integer_minus_one_node
;
6189 if (TREE_OPERAND (incr
, 0) != iter
)
6190 incr
= error_mark_node
;
6191 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
6192 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
6194 tree rhs
= TREE_OPERAND (incr
, 1);
6195 if (TREE_OPERAND (rhs
, 0) == iter
)
6197 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
6199 incr
= error_mark_node
;
6202 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
6203 iter
, TREE_CODE (rhs
),
6204 TREE_OPERAND (rhs
, 1),
6205 tf_warning_or_error
);
6206 if (error_operand_p (iter_incr
))
6208 incr
= TREE_OPERAND (rhs
, 1);
6209 incr
= cp_convert (TREE_TYPE (diff
), incr
,
6210 tf_warning_or_error
);
6211 if (TREE_CODE (rhs
) == MINUS_EXPR
)
6213 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
6214 incr
= fold_if_not_in_template (incr
);
6216 if (TREE_CODE (incr
) != INTEGER_CST
6217 && (TREE_CODE (incr
) != NOP_EXPR
6218 || (TREE_CODE (TREE_OPERAND (incr
, 0))
6223 else if (TREE_OPERAND (rhs
, 1) == iter
)
6225 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
6226 || TREE_CODE (rhs
) != PLUS_EXPR
)
6227 incr
= error_mark_node
;
6230 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
6232 TREE_OPERAND (rhs
, 0),
6235 tf_warning_or_error
);
6236 if (error_operand_p (iter_incr
))
6238 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
6241 tf_warning_or_error
);
6242 if (error_operand_p (iter_incr
))
6244 incr
= TREE_OPERAND (rhs
, 0);
6249 incr
= error_mark_node
;
6252 incr
= error_mark_node
;
6255 incr
= error_mark_node
;
6259 if (incr
== error_mark_node
)
6261 error_at (elocus
, "invalid increment expression");
6265 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
6266 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6267 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
6268 && OMP_CLAUSE_DECL (c
) == iter
)
6271 decl
= create_temporary_var (TREE_TYPE (diff
));
6273 add_decl_expr (decl
);
6274 last
= create_temporary_var (TREE_TYPE (diff
));
6276 add_decl_expr (last
);
6277 if (c
&& iter_incr
== NULL
)
6279 incr_var
= create_temporary_var (TREE_TYPE (diff
));
6280 pushdecl (incr_var
);
6281 add_decl_expr (incr_var
);
6283 gcc_assert (stmts_are_full_exprs_p ());
6285 orig_pre_body
= *pre_body
;
6286 *pre_body
= push_stmt_list ();
6288 add_stmt (orig_pre_body
);
6290 finish_expr_stmt (build_x_modify_expr (elocus
,
6291 iter
, NOP_EXPR
, init
,
6292 tf_warning_or_error
));
6293 init
= build_int_cst (TREE_TYPE (diff
), 0);
6294 if (c
&& iter_incr
== NULL
)
6296 finish_expr_stmt (build_x_modify_expr (elocus
,
6298 incr
, tf_warning_or_error
));
6300 iter_incr
= build_x_modify_expr (elocus
,
6301 iter
, PLUS_EXPR
, incr
,
6302 tf_warning_or_error
);
6304 finish_expr_stmt (build_x_modify_expr (elocus
,
6305 last
, NOP_EXPR
, init
,
6306 tf_warning_or_error
));
6307 *pre_body
= pop_stmt_list (*pre_body
);
6309 cond
= cp_build_binary_op (elocus
,
6310 TREE_CODE (cond
), decl
, diff
,
6311 tf_warning_or_error
);
6312 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
6313 elocus
, incr
, NULL_TREE
);
6316 *body
= push_stmt_list ();
6317 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
6318 iter_init
= build_x_modify_expr (elocus
,
6319 iter
, PLUS_EXPR
, iter_init
,
6320 tf_warning_or_error
);
6321 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
6322 finish_expr_stmt (iter_init
);
6323 finish_expr_stmt (build_x_modify_expr (elocus
,
6324 last
, NOP_EXPR
, decl
,
6325 tf_warning_or_error
));
6326 add_stmt (orig_body
);
6327 *body
= pop_stmt_list (*body
);
6331 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
6332 finish_expr_stmt (iter_incr
);
6333 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
6334 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
6337 TREE_VEC_ELT (declv
, i
) = decl
;
6338 TREE_VEC_ELT (initv
, i
) = init
;
6339 TREE_VEC_ELT (condv
, i
) = cond
;
6340 TREE_VEC_ELT (incrv
, i
) = incr
;
6346 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
6347 are directly for their associated operands in the statement. DECL
6348 and INIT are a combo; if DECL is NULL then INIT ought to be a
6349 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
6350 optional statements that need to go before the loop into its
6354 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
, tree initv
,
6355 tree condv
, tree incrv
, tree body
, tree pre_body
, tree clauses
)
6357 tree omp_for
= NULL
, orig_incr
= NULL
;
6358 tree decl
= NULL
, init
, cond
, incr
, orig_decl
= NULL_TREE
, block
= NULL_TREE
;
6359 tree last
= NULL_TREE
;
6363 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
6364 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
6365 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
6366 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
6368 decl
= TREE_VEC_ELT (declv
, i
);
6369 init
= TREE_VEC_ELT (initv
, i
);
6370 cond
= TREE_VEC_ELT (condv
, i
);
6371 incr
= TREE_VEC_ELT (incrv
, i
);
6377 switch (TREE_CODE (init
))
6380 decl
= TREE_OPERAND (init
, 0);
6381 init
= TREE_OPERAND (init
, 1);
6384 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
6386 decl
= TREE_OPERAND (init
, 0);
6387 init
= TREE_OPERAND (init
, 2);
6397 "expected iteration declaration or initialization");
6402 if (init
&& EXPR_HAS_LOCATION (init
))
6403 elocus
= EXPR_LOCATION (init
);
6407 error_at (elocus
, "missing controlling predicate");
6413 error_at (elocus
, "missing increment expression");
6417 TREE_VEC_ELT (declv
, i
) = decl
;
6418 TREE_VEC_ELT (initv
, i
) = init
;
6421 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
6425 stmt
= make_node (code
);
6427 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
6429 /* This is really just a place-holder. We'll be decomposing this
6430 again and going through the cp_build_modify_expr path below when
6431 we instantiate the thing. */
6432 TREE_VEC_ELT (initv
, i
)
6433 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
6434 TREE_VEC_ELT (initv
, i
));
6437 TREE_TYPE (stmt
) = void_type_node
;
6438 OMP_FOR_INIT (stmt
) = initv
;
6439 OMP_FOR_COND (stmt
) = condv
;
6440 OMP_FOR_INCR (stmt
) = incrv
;
6441 OMP_FOR_BODY (stmt
) = body
;
6442 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
6443 OMP_FOR_CLAUSES (stmt
) = clauses
;
6445 SET_EXPR_LOCATION (stmt
, locus
);
6446 return add_stmt (stmt
);
6449 if (processing_template_decl
)
6450 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
6452 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
6454 decl
= TREE_VEC_ELT (declv
, i
);
6455 init
= TREE_VEC_ELT (initv
, i
);
6456 cond
= TREE_VEC_ELT (condv
, i
);
6457 incr
= TREE_VEC_ELT (incrv
, i
);
6459 TREE_VEC_ELT (orig_incr
, i
) = incr
;
6462 if (init
&& EXPR_HAS_LOCATION (init
))
6463 elocus
= EXPR_LOCATION (init
);
6467 error_at (elocus
, "expected iteration declaration or initialization");
6471 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
6474 TREE_VEC_ELT (orig_incr
, i
) = incr
;
6475 incr
= cp_build_modify_expr (TREE_OPERAND (incr
, 0),
6476 TREE_CODE (TREE_OPERAND (incr
, 1)),
6477 TREE_OPERAND (incr
, 2),
6478 tf_warning_or_error
);
6481 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
6483 if (code
== OMP_SIMD
)
6485 error_at (elocus
, "%<#pragma omp simd%> used with class "
6486 "iteration variable %qE", decl
);
6489 if (code
== CILK_FOR
&& i
== 0)
6491 if (handle_omp_for_class_iterator (i
, locus
, declv
, initv
, condv
,
6492 incrv
, &body
, &pre_body
,
6498 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
6499 && !TYPE_PTR_P (TREE_TYPE (decl
)))
6501 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
6505 if (!processing_template_decl
)
6507 init
= fold_build_cleanup_point_expr (TREE_TYPE (init
), init
);
6508 init
= cp_build_modify_expr (decl
, NOP_EXPR
, init
, tf_warning_or_error
);
6511 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
6513 && TREE_SIDE_EFFECTS (cond
)
6514 && COMPARISON_CLASS_P (cond
)
6515 && !processing_template_decl
)
6517 tree t
= TREE_OPERAND (cond
, 0);
6518 if (TREE_SIDE_EFFECTS (t
)
6520 && (TREE_CODE (t
) != NOP_EXPR
6521 || TREE_OPERAND (t
, 0) != decl
))
6522 TREE_OPERAND (cond
, 0)
6523 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6525 t
= TREE_OPERAND (cond
, 1);
6526 if (TREE_SIDE_EFFECTS (t
)
6528 && (TREE_CODE (t
) != NOP_EXPR
6529 || TREE_OPERAND (t
, 0) != decl
))
6530 TREE_OPERAND (cond
, 1)
6531 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6533 if (decl
== error_mark_node
|| init
== error_mark_node
)
6536 TREE_VEC_ELT (declv
, i
) = decl
;
6537 TREE_VEC_ELT (initv
, i
) = init
;
6538 TREE_VEC_ELT (condv
, i
) = cond
;
6539 TREE_VEC_ELT (incrv
, i
) = incr
;
6543 if (IS_EMPTY_STMT (pre_body
))
6546 if (code
== CILK_FOR
&& !processing_template_decl
)
6547 block
= push_stmt_list ();
6549 omp_for
= c_finish_omp_for (locus
, code
, declv
, initv
, condv
, incrv
,
6552 if (omp_for
== NULL
)
6555 pop_stmt_list (block
);
6559 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
6561 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
), 0);
6562 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
6564 if (TREE_CODE (incr
) != MODIFY_EXPR
)
6567 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
6568 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
6569 && !processing_template_decl
)
6571 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
6572 if (TREE_SIDE_EFFECTS (t
)
6574 && (TREE_CODE (t
) != NOP_EXPR
6575 || TREE_OPERAND (t
, 0) != decl
))
6576 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
6577 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6579 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
6580 if (TREE_SIDE_EFFECTS (t
)
6582 && (TREE_CODE (t
) != NOP_EXPR
6583 || TREE_OPERAND (t
, 0) != decl
))
6584 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
6585 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6589 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
6591 OMP_FOR_CLAUSES (omp_for
) = clauses
;
6595 tree omp_par
= make_node (OMP_PARALLEL
);
6596 TREE_TYPE (omp_par
) = void_type_node
;
6597 OMP_PARALLEL_CLAUSES (omp_par
) = NULL_TREE
;
6598 tree bind
= build3 (BIND_EXPR
, void_type_node
, NULL
, NULL
, NULL
);
6599 TREE_SIDE_EFFECTS (bind
) = 1;
6600 BIND_EXPR_BODY (bind
) = pop_stmt_list (block
);
6601 OMP_PARALLEL_BODY (omp_par
) = bind
;
6602 if (OMP_FOR_PRE_BODY (omp_for
))
6604 add_stmt (OMP_FOR_PRE_BODY (omp_for
));
6605 OMP_FOR_PRE_BODY (omp_for
) = NULL_TREE
;
6607 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0);
6608 decl
= TREE_OPERAND (init
, 0);
6609 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), 0);
6610 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
6611 tree t
= TREE_OPERAND (cond
, 1), c
, clauses
, *pc
;
6612 clauses
= OMP_FOR_CLAUSES (omp_for
);
6613 OMP_FOR_CLAUSES (omp_for
) = NULL_TREE
;
6614 for (pc
= &clauses
; *pc
; )
6615 if (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_SCHEDULE
)
6617 gcc_assert (OMP_FOR_CLAUSES (omp_for
) == NULL_TREE
);
6618 OMP_FOR_CLAUSES (omp_for
) = *pc
;
6619 *pc
= OMP_CLAUSE_CHAIN (*pc
);
6620 OMP_CLAUSE_CHAIN (OMP_FOR_CLAUSES (omp_for
)) = NULL_TREE
;
6624 gcc_assert (OMP_CLAUSE_CODE (*pc
) == OMP_CLAUSE_FIRSTPRIVATE
);
6625 pc
= &OMP_CLAUSE_CHAIN (*pc
);
6627 if (TREE_CODE (t
) != INTEGER_CST
)
6629 TREE_OPERAND (cond
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
6630 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6631 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (cond
, 1);
6632 OMP_CLAUSE_CHAIN (c
) = clauses
;
6635 if (TREE_CODE (incr
) == MODIFY_EXPR
)
6637 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
6638 if (TREE_CODE (t
) != INTEGER_CST
)
6640 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
6641 = get_temp_regvar (TREE_TYPE (t
), t
);
6642 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6643 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
6644 OMP_CLAUSE_CHAIN (c
) = clauses
;
6648 t
= TREE_OPERAND (init
, 1);
6649 if (TREE_CODE (t
) != INTEGER_CST
)
6651 TREE_OPERAND (init
, 1) = get_temp_regvar (TREE_TYPE (t
), t
);
6652 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6653 OMP_CLAUSE_DECL (c
) = TREE_OPERAND (init
, 1);
6654 OMP_CLAUSE_CHAIN (c
) = clauses
;
6657 if (orig_decl
&& orig_decl
!= decl
)
6659 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6660 OMP_CLAUSE_DECL (c
) = orig_decl
;
6661 OMP_CLAUSE_CHAIN (c
) = clauses
;
6666 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6667 OMP_CLAUSE_DECL (c
) = last
;
6668 OMP_CLAUSE_CHAIN (c
) = clauses
;
6671 c
= build_omp_clause (input_location
, OMP_CLAUSE_PRIVATE
);
6672 OMP_CLAUSE_DECL (c
) = decl
;
6673 OMP_CLAUSE_CHAIN (c
) = clauses
;
6675 c
= build_omp_clause (input_location
, OMP_CLAUSE__CILK_FOR_COUNT_
);
6676 OMP_CLAUSE_OPERAND (c
, 0)
6677 = cilk_for_number_of_iterations (omp_for
);
6678 OMP_CLAUSE_CHAIN (c
) = clauses
;
6679 OMP_PARALLEL_CLAUSES (omp_par
) = finish_omp_clauses (c
);
6683 else if (code
== CILK_FOR
&& processing_template_decl
)
6685 tree c
, clauses
= OMP_FOR_CLAUSES (omp_for
);
6686 if (orig_decl
&& orig_decl
!= decl
)
6688 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6689 OMP_CLAUSE_DECL (c
) = orig_decl
;
6690 OMP_CLAUSE_CHAIN (c
) = clauses
;
6695 c
= build_omp_clause (input_location
, OMP_CLAUSE_FIRSTPRIVATE
);
6696 OMP_CLAUSE_DECL (c
) = last
;
6697 OMP_CLAUSE_CHAIN (c
) = clauses
;
6700 OMP_FOR_CLAUSES (omp_for
) = clauses
;
6706 finish_omp_atomic (enum tree_code code
, enum tree_code opcode
, tree lhs
,
6707 tree rhs
, tree v
, tree lhs1
, tree rhs1
, bool seq_cst
)
6722 dependent_p
= false;
6725 /* Even in a template, we can detect invalid uses of the atomic
6726 pragma if neither LHS nor RHS is type-dependent. */
6727 if (processing_template_decl
)
6729 dependent_p
= (type_dependent_expression_p (lhs
)
6730 || (rhs
&& type_dependent_expression_p (rhs
))
6731 || (v
&& type_dependent_expression_p (v
))
6732 || (lhs1
&& type_dependent_expression_p (lhs1
))
6733 || (rhs1
&& type_dependent_expression_p (rhs1
)));
6736 lhs
= build_non_dependent_expr (lhs
);
6738 rhs
= build_non_dependent_expr (rhs
);
6740 v
= build_non_dependent_expr (v
);
6742 lhs1
= build_non_dependent_expr (lhs1
);
6744 rhs1
= build_non_dependent_expr (rhs1
);
6749 bool swapped
= false;
6750 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
6755 swapped
= !commutative_tree_code (opcode
);
6757 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
6759 if (code
== OMP_ATOMIC
)
6760 error ("%<#pragma omp atomic update%> uses two different "
6761 "expressions for memory");
6763 error ("%<#pragma omp atomic capture%> uses two different "
6764 "expressions for memory");
6767 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
6769 if (code
== OMP_ATOMIC
)
6770 error ("%<#pragma omp atomic update%> uses two different "
6771 "expressions for memory");
6773 error ("%<#pragma omp atomic capture%> uses two different "
6774 "expressions for memory");
6777 stmt
= c_finish_omp_atomic (input_location
, code
, opcode
, lhs
, rhs
,
6778 v
, lhs1
, rhs1
, swapped
, seq_cst
);
6779 if (stmt
== error_mark_node
)
6782 if (processing_template_decl
)
6784 if (code
== OMP_ATOMIC_READ
)
6786 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs
),
6787 OMP_ATOMIC_READ
, orig_lhs
);
6788 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
6789 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
6793 if (opcode
== NOP_EXPR
)
6794 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
6796 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
6798 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
6799 COMPOUND_EXPR
, orig_rhs1
, stmt
);
6800 if (code
!= OMP_ATOMIC
)
6802 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_lhs1
),
6803 code
, orig_lhs1
, stmt
);
6804 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
6805 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
6808 stmt
= build2 (OMP_ATOMIC
, void_type_node
, integer_zero_node
, stmt
);
6809 OMP_ATOMIC_SEQ_CST (stmt
) = seq_cst
;
6811 finish_expr_stmt (stmt
);
6815 finish_omp_barrier (void)
6817 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
6818 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6819 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6820 release_tree_vector (vec
);
6821 finish_expr_stmt (stmt
);
6825 finish_omp_flush (void)
6827 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
6828 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6829 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6830 release_tree_vector (vec
);
6831 finish_expr_stmt (stmt
);
6835 finish_omp_taskwait (void)
6837 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
6838 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6839 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6840 release_tree_vector (vec
);
6841 finish_expr_stmt (stmt
);
6845 finish_omp_taskyield (void)
6847 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
6848 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6849 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6850 release_tree_vector (vec
);
6851 finish_expr_stmt (stmt
);
6855 finish_omp_cancel (tree clauses
)
6857 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
6859 if (find_omp_clause (clauses
, OMP_CLAUSE_PARALLEL
))
6861 else if (find_omp_clause (clauses
, OMP_CLAUSE_FOR
))
6863 else if (find_omp_clause (clauses
, OMP_CLAUSE_SECTIONS
))
6865 else if (find_omp_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
6869 error ("%<#pragma omp cancel must specify one of "
6870 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
6873 vec
<tree
, va_gc
> *vec
= make_tree_vector ();
6874 tree ifc
= find_omp_clause (clauses
, OMP_CLAUSE_IF
);
6875 if (ifc
!= NULL_TREE
)
6877 tree type
= TREE_TYPE (OMP_CLAUSE_IF_EXPR (ifc
));
6878 ifc
= fold_build2_loc (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
6879 boolean_type_node
, OMP_CLAUSE_IF_EXPR (ifc
),
6880 build_zero_cst (type
));
6883 ifc
= boolean_true_node
;
6884 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
6885 vec
->quick_push (ifc
);
6886 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6887 release_tree_vector (vec
);
6888 finish_expr_stmt (stmt
);
6892 finish_omp_cancellation_point (tree clauses
)
6894 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
6896 if (find_omp_clause (clauses
, OMP_CLAUSE_PARALLEL
))
6898 else if (find_omp_clause (clauses
, OMP_CLAUSE_FOR
))
6900 else if (find_omp_clause (clauses
, OMP_CLAUSE_SECTIONS
))
6902 else if (find_omp_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
6906 error ("%<#pragma omp cancellation point must specify one of "
6907 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
6910 vec
<tree
, va_gc
> *vec
6911 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
6912 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
6913 release_tree_vector (vec
);
6914 finish_expr_stmt (stmt
);
6917 /* Begin a __transaction_atomic or __transaction_relaxed statement.
6918 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
6919 should create an extra compound stmt. */
6922 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
6927 *pcompound
= begin_compound_stmt (0);
6929 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
6931 /* Only add the statement to the function if support enabled. */
6935 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
6936 ? G_("%<__transaction_relaxed%> without "
6937 "transactional memory support enabled")
6938 : G_("%<__transaction_atomic%> without "
6939 "transactional memory support enabled")));
6941 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
6942 TREE_SIDE_EFFECTS (r
) = 1;
6946 /* End a __transaction_atomic or __transaction_relaxed statement.
6947 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
6948 and we should end the compound. If NOEX is non-NULL, we wrap the body in
6949 a MUST_NOT_THROW_EXPR with NOEX as condition. */
6952 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
6954 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
6955 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
6956 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
6957 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
6959 /* noexcept specifications are not allowed for function transactions. */
6960 gcc_assert (!(noex
&& compound_stmt
));
6963 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
6965 /* This may not be true when the STATEMENT_LIST is empty. */
6967 SET_EXPR_LOCATION (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
6968 TREE_SIDE_EFFECTS (body
) = 1;
6969 TRANSACTION_EXPR_BODY (stmt
) = body
;
6973 finish_compound_stmt (compound_stmt
);
6976 /* Build a __transaction_atomic or __transaction_relaxed expression. If
6977 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
6981 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
6986 expr
= build_must_not_throw_expr (expr
, noex
);
6988 SET_EXPR_LOCATION (expr
, loc
);
6989 TREE_SIDE_EFFECTS (expr
) = 1;
6991 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
6992 if (flags
& TM_STMT_ATTR_RELAXED
)
6993 TRANSACTION_EXPR_RELAXED (ret
) = 1;
6994 TREE_SIDE_EFFECTS (ret
) = 1;
6995 SET_EXPR_LOCATION (ret
, loc
);
7000 init_cp_semantics (void)
7004 /* Build a STATIC_ASSERT for a static assertion with the condition
7005 CONDITION and the message text MESSAGE. LOCATION is the location
7006 of the static assertion in the source code. When MEMBER_P, this
7007 static assertion is a member of a class. */
7009 finish_static_assert (tree condition
, tree message
, location_t location
,
7012 if (message
== NULL_TREE
7013 || message
== error_mark_node
7014 || condition
== NULL_TREE
7015 || condition
== error_mark_node
)
7018 if (check_for_bare_parameter_packs (condition
))
7019 condition
= error_mark_node
;
7021 if (type_dependent_expression_p (condition
)
7022 || value_dependent_expression_p (condition
))
7024 /* We're in a template; build a STATIC_ASSERT and put it in
7028 assertion
= make_node (STATIC_ASSERT
);
7029 STATIC_ASSERT_CONDITION (assertion
) = condition
;
7030 STATIC_ASSERT_MESSAGE (assertion
) = message
;
7031 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
7034 maybe_add_class_template_decl_list (current_class_type
,
7038 add_stmt (assertion
);
7043 /* Fold the expression and convert it to a boolean value. */
7044 condition
= instantiate_non_dependent_expr (condition
);
7045 condition
= cp_convert (boolean_type_node
, condition
, tf_warning_or_error
);
7046 condition
= maybe_constant_value (condition
);
7048 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
7049 /* Do nothing; the condition is satisfied. */
7053 location_t saved_loc
= input_location
;
7055 input_location
= location
;
7056 if (TREE_CODE (condition
) == INTEGER_CST
7057 && integer_zerop (condition
))
7058 /* Report the error. */
7059 error ("static assertion failed: %s", TREE_STRING_POINTER (message
));
7060 else if (condition
&& condition
!= error_mark_node
)
7062 error ("non-constant condition for static assertion");
7063 if (require_potential_rvalue_constant_expression (condition
))
7064 cxx_constant_value (condition
);
7066 input_location
= saved_loc
;
7070 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
7071 suitable for use as a type-specifier.
7073 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
7074 id-expression or a class member access, FALSE when it was parsed as
7075 a full expression. */
7078 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
7079 tsubst_flags_t complain
)
7081 tree type
= NULL_TREE
;
7083 if (!expr
|| error_operand_p (expr
))
7084 return error_mark_node
;
7087 || TREE_CODE (expr
) == TYPE_DECL
7088 || (TREE_CODE (expr
) == BIT_NOT_EXPR
7089 && TYPE_P (TREE_OPERAND (expr
, 0))))
7091 if (complain
& tf_error
)
7092 error ("argument to decltype must be an expression");
7093 return error_mark_node
;
7096 /* Depending on the resolution of DR 1172, we may later need to distinguish
7097 instantiation-dependent but not type-dependent expressions so that, say,
7098 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
7099 if (instantiation_dependent_expression_p (expr
))
7101 type
= cxx_make_type (DECLTYPE_TYPE
);
7102 DECLTYPE_TYPE_EXPR (type
) = expr
;
7103 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
7104 = id_expression_or_member_access_p
;
7105 SET_TYPE_STRUCTURAL_EQUALITY (type
);
7110 /* The type denoted by decltype(e) is defined as follows: */
7112 expr
= resolve_nondeduced_context (expr
);
7114 if (invalid_nonstatic_memfn_p (expr
, complain
))
7115 return error_mark_node
;
7117 if (type_unknown_p (expr
))
7119 if (complain
& tf_error
)
7120 error ("decltype cannot resolve address of overloaded function");
7121 return error_mark_node
;
7124 /* To get the size of a static data member declared as an array of
7125 unknown bound, we need to instantiate it. */
7127 && VAR_HAD_UNKNOWN_BOUND (expr
)
7128 && DECL_TEMPLATE_INSTANTIATION (expr
))
7129 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
7131 if (id_expression_or_member_access_p
)
7133 /* If e is an id-expression or a class member access (5.2.5
7134 [expr.ref]), decltype(e) is defined as the type of the entity
7135 named by e. If there is no such entity, or e names a set of
7136 overloaded functions, the program is ill-formed. */
7137 if (identifier_p (expr
))
7138 expr
= lookup_name (expr
);
7140 if (INDIRECT_REF_P (expr
))
7141 /* This can happen when the expression is, e.g., "a.b". Just
7142 look at the underlying operand. */
7143 expr
= TREE_OPERAND (expr
, 0);
7145 if (TREE_CODE (expr
) == OFFSET_REF
7146 || TREE_CODE (expr
) == MEMBER_REF
7147 || TREE_CODE (expr
) == SCOPE_REF
)
7148 /* We're only interested in the field itself. If it is a
7149 BASELINK, we will need to see through it in the next
7151 expr
= TREE_OPERAND (expr
, 1);
7153 if (BASELINK_P (expr
))
7154 /* See through BASELINK nodes to the underlying function. */
7155 expr
= BASELINK_FUNCTIONS (expr
);
7157 switch (TREE_CODE (expr
))
7160 if (DECL_BIT_FIELD_TYPE (expr
))
7162 type
= DECL_BIT_FIELD_TYPE (expr
);
7165 /* Fall through for fields that aren't bitfields. */
7172 case TEMPLATE_PARM_INDEX
:
7173 expr
= mark_type_use (expr
);
7174 type
= TREE_TYPE (expr
);
7178 type
= error_mark_node
;
7183 mark_type_use (expr
);
7184 type
= is_bitfield_expr_with_lowered_type (expr
);
7186 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
7194 /* We can get here when the id-expression refers to an
7195 enumerator or non-type template parameter. */
7196 type
= TREE_TYPE (expr
);
7200 /* Handle instantiated template non-type arguments. */
7201 type
= TREE_TYPE (expr
);
7207 /* Within a lambda-expression:
7209 Every occurrence of decltype((x)) where x is a possibly
7210 parenthesized id-expression that names an entity of
7211 automatic storage duration is treated as if x were
7212 transformed into an access to a corresponding data member
7213 of the closure type that would have been declared if x
7214 were a use of the denoted entity. */
7215 if (outer_automatic_var_p (expr
)
7216 && current_function_decl
7217 && LAMBDA_FUNCTION_P (current_function_decl
))
7218 type
= capture_decltype (expr
);
7219 else if (error_operand_p (expr
))
7220 type
= error_mark_node
;
7221 else if (expr
== current_class_ptr
)
7222 /* If the expression is just "this", we want the
7223 cv-unqualified pointer for the "this" type. */
7224 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
7227 /* Otherwise, where T is the type of e, if e is an lvalue,
7228 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
7229 cp_lvalue_kind clk
= lvalue_kind (expr
);
7230 type
= unlowered_expr_type (expr
);
7231 gcc_assert (TREE_CODE (type
) != REFERENCE_TYPE
);
7233 /* For vector types, pick a non-opaque variant. */
7234 if (TREE_CODE (type
) == VECTOR_TYPE
)
7235 type
= strip_typedefs (type
);
7237 if (clk
!= clk_none
&& !(clk
& clk_class
))
7238 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
7242 if (cxx_dialect
>= cxx14
&& array_of_runtime_bound_p (type
)
7243 && (flag_iso
|| warn_vla
> 0))
7245 if (complain
& tf_warning_or_error
)
7246 pedwarn (input_location
, OPT_Wvla
,
7247 "taking decltype of array of runtime bound");
7249 return error_mark_node
;
7255 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
7256 __has_nothrow_copy, depending on assign_p. */
7259 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
7266 ix
= lookup_fnfields_1 (type
, ansi_assopname (NOP_EXPR
));
7269 fns
= (*CLASSTYPE_METHOD_VEC (type
))[ix
];
7271 else if (TYPE_HAS_COPY_CTOR (type
))
7273 /* If construction of the copy constructor was postponed, create
7275 if (CLASSTYPE_LAZY_COPY_CTOR (type
))
7276 lazily_declare_fn (sfk_copy_constructor
, type
);
7277 if (CLASSTYPE_LAZY_MOVE_CTOR (type
))
7278 lazily_declare_fn (sfk_move_constructor
, type
);
7279 fns
= CLASSTYPE_CONSTRUCTORS (type
);
7284 for (; fns
; fns
= OVL_NEXT (fns
))
7286 tree fn
= OVL_CURRENT (fns
);
7290 if (copy_fn_p (fn
) == 0)
7293 else if (copy_fn_p (fn
) <= 0)
7296 maybe_instantiate_noexcept (fn
);
7297 if (!TYPE_NOTHROW_P (TREE_TYPE (fn
)))
7304 /* Actually evaluates the trait. */
7307 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
7309 enum tree_code type_code1
;
7312 type_code1
= TREE_CODE (type1
);
7316 case CPTK_HAS_NOTHROW_ASSIGN
:
7317 type1
= strip_array_types (type1
);
7318 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
7319 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
7320 || (CLASS_TYPE_P (type1
)
7321 && classtype_has_nothrow_assign_or_copy_p (type1
,
7324 case CPTK_HAS_TRIVIAL_ASSIGN
:
7325 /* ??? The standard seems to be missing the "or array of such a class
7326 type" wording for this trait. */
7327 type1
= strip_array_types (type1
);
7328 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
7329 && (trivial_type_p (type1
)
7330 || (CLASS_TYPE_P (type1
)
7331 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
7333 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
7334 type1
= strip_array_types (type1
);
7335 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
7336 || (CLASS_TYPE_P (type1
)
7337 && (t
= locate_ctor (type1
))
7338 && (maybe_instantiate_noexcept (t
),
7339 TYPE_NOTHROW_P (TREE_TYPE (t
)))));
7341 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
7342 type1
= strip_array_types (type1
);
7343 return (trivial_type_p (type1
)
7344 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
7346 case CPTK_HAS_NOTHROW_COPY
:
7347 type1
= strip_array_types (type1
);
7348 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
7349 || (CLASS_TYPE_P (type1
)
7350 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
7352 case CPTK_HAS_TRIVIAL_COPY
:
7353 /* ??? The standard seems to be missing the "or array of such a class
7354 type" wording for this trait. */
7355 type1
= strip_array_types (type1
);
7356 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
7357 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
7359 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
7360 type1
= strip_array_types (type1
);
7361 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
7362 || (CLASS_TYPE_P (type1
)
7363 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
7365 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
7366 return type_has_virtual_destructor (type1
);
7368 case CPTK_IS_ABSTRACT
:
7369 return (ABSTRACT_CLASS_TYPE_P (type1
));
7371 case CPTK_IS_BASE_OF
:
7372 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
7373 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
7374 || DERIVED_FROM_P (type1
, type2
)));
7377 return (NON_UNION_CLASS_TYPE_P (type1
));
7380 return (NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
));
7383 return (type_code1
== ENUMERAL_TYPE
);
7386 return (CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
));
7388 case CPTK_IS_LITERAL_TYPE
:
7389 return (literal_type_p (type1
));
7392 return (pod_type_p (type1
));
7394 case CPTK_IS_POLYMORPHIC
:
7395 return (CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
));
7397 case CPTK_IS_STD_LAYOUT
:
7398 return (std_layout_type_p (type1
));
7400 case CPTK_IS_TRIVIAL
:
7401 return (trivial_type_p (type1
));
7403 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
7404 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
7406 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
7407 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
7409 case CPTK_IS_TRIVIALLY_COPYABLE
:
7410 return (trivially_copyable_p (type1
));
7413 return (type_code1
== UNION_TYPE
);
7421 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
7422 void, or a complete type, returns true, otherwise false. */
7425 check_trait_type (tree type
)
7427 if (type
== NULL_TREE
)
7430 if (TREE_CODE (type
) == TREE_LIST
)
7431 return (check_trait_type (TREE_VALUE (type
))
7432 && check_trait_type (TREE_CHAIN (type
)));
7434 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
7435 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
7438 if (VOID_TYPE_P (type
))
7441 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
7444 /* Process a trait expression. */
7447 finish_trait_expr (cp_trait_kind kind
, tree type1
, tree type2
)
7449 if (type1
== error_mark_node
7450 || type2
== error_mark_node
)
7451 return error_mark_node
;
7453 if (processing_template_decl
)
7455 tree trait_expr
= make_node (TRAIT_EXPR
);
7456 TREE_TYPE (trait_expr
) = boolean_type_node
;
7457 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
7458 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
7459 TRAIT_EXPR_KIND (trait_expr
) = kind
;
7465 case CPTK_HAS_NOTHROW_ASSIGN
:
7466 case CPTK_HAS_TRIVIAL_ASSIGN
:
7467 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
7468 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
7469 case CPTK_HAS_NOTHROW_COPY
:
7470 case CPTK_HAS_TRIVIAL_COPY
:
7471 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
7472 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
7473 case CPTK_IS_ABSTRACT
:
7476 case CPTK_IS_LITERAL_TYPE
:
7478 case CPTK_IS_POLYMORPHIC
:
7479 case CPTK_IS_STD_LAYOUT
:
7480 case CPTK_IS_TRIVIAL
:
7481 case CPTK_IS_TRIVIALLY_COPYABLE
:
7482 if (!check_trait_type (type1
))
7483 return error_mark_node
;
7486 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
7487 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
7488 if (!check_trait_type (type1
)
7489 || !check_trait_type (type2
))
7490 return error_mark_node
;
7493 case CPTK_IS_BASE_OF
:
7494 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
7495 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
7496 && !complete_type_or_else (type2
, NULL_TREE
))
7497 /* We already issued an error. */
7498 return error_mark_node
;
7510 return (trait_expr_value (kind
, type1
, type2
)
7511 ? boolean_true_node
: boolean_false_node
);
7514 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
7515 which is ignored for C++. */
7518 set_float_const_decimal64 (void)
7523 clear_float_const_decimal64 (void)
7528 float_const_decimal64_p (void)
7534 /* Return true if T designates the implied `this' parameter. */
7537 is_this_parameter (tree t
)
7539 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
7541 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
));
7545 /* Insert the deduced return type for an auto function. */
7548 apply_deduced_return_type (tree fco
, tree return_type
)
7552 if (return_type
== error_mark_node
)
7555 if (LAMBDA_FUNCTION_P (fco
))
7557 tree lambda
= CLASSTYPE_LAMBDA_EXPR (current_class_type
);
7558 LAMBDA_EXPR_RETURN_TYPE (lambda
) = return_type
;
7561 if (DECL_CONV_FN_P (fco
))
7562 DECL_NAME (fco
) = mangle_conv_op_name_for_type (return_type
);
7564 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
7566 result
= DECL_RESULT (fco
);
7567 if (result
== NULL_TREE
)
7569 if (TREE_TYPE (result
) == return_type
)
7572 /* We already have a DECL_RESULT from start_preparsed_function.
7573 Now we need to redo the work it and allocate_struct_function
7574 did to reflect the new type. */
7575 gcc_assert (current_function_decl
== fco
);
7576 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
7577 TYPE_MAIN_VARIANT (return_type
));
7578 DECL_ARTIFICIAL (result
) = 1;
7579 DECL_IGNORED_P (result
) = 1;
7580 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
7583 DECL_RESULT (fco
) = result
;
7585 if (!processing_template_decl
)
7587 if (!VOID_TYPE_P (TREE_TYPE (result
)))
7588 complete_type_or_else (TREE_TYPE (result
), NULL_TREE
);
7589 bool aggr
= aggregate_value_p (result
, fco
);
7590 #ifdef PCC_STATIC_STRUCT_RETURN
7591 cfun
->returns_pcc_struct
= aggr
;
7593 cfun
->returns_struct
= aggr
;
7598 /* DECL is a local variable or parameter from the surrounding scope of a
7599 lambda-expression. Returns the decltype for a use of the capture field
7600 for DECL even if it hasn't been captured yet. */
7603 capture_decltype (tree decl
)
7605 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
7606 /* FIXME do lookup instead of list walk? */
7607 tree cap
= value_member (decl
, LAMBDA_EXPR_CAPTURE_LIST (lam
));
7611 type
= TREE_TYPE (TREE_PURPOSE (cap
));
7613 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
7616 error ("%qD is not captured", decl
);
7617 return error_mark_node
;
7620 type
= TREE_TYPE (decl
);
7621 if (TREE_CODE (type
) == REFERENCE_TYPE
7622 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
7623 type
= TREE_TYPE (type
);
7626 case CPLD_REFERENCE
:
7627 type
= TREE_TYPE (decl
);
7628 if (TREE_CODE (type
) != REFERENCE_TYPE
)
7629 type
= build_reference_type (TREE_TYPE (decl
));
7636 if (TREE_CODE (type
) != REFERENCE_TYPE
)
7638 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
7639 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
7641 type
= build_reference_type (type
);
7646 #include "gt-cp-semantics.h"