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-2022 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GCC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GCC; see the file COPYING3. If not see
24 <http://www.gnu.org/licenses/>. */
28 #include "coretypes.h"
32 #include "stringpool.h"
36 #include "stor-layout.h"
37 #include "c-family/c-objc.h"
38 #include "tree-inline.h"
40 #include "tree-iterator.h"
41 #include "omp-general.h"
43 #include "stringpool.h"
45 #include "gomp-constants.h"
49 /* There routines provide a modular interface to perform many parsing
50 operations. They may therefore be used during actual parsing, or
51 during template instantiation, which may be regarded as a
52 degenerate form of parsing. */
54 static tree
maybe_convert_cond (tree
);
55 static tree
finalize_nrv_r (tree
*, int *, void *);
56 static tree
capture_decltype (tree
);
58 /* Used for OpenMP non-static data member privatization. */
60 static hash_map
<tree
, tree
> *omp_private_member_map
;
61 static vec
<tree
> omp_private_member_vec
;
62 static bool omp_private_member_ignore_next
;
65 /* Deferred Access Checking Overview
66 ---------------------------------
68 Most C++ expressions and declarations require access checking
69 to be performed during parsing. However, in several cases,
70 this has to be treated differently.
72 For member declarations, access checking has to be deferred
73 until more information about the declaration is known. For
85 When we are parsing the function return type `A::X', we don't
86 really know if this is allowed until we parse the function name.
88 Furthermore, some contexts require that access checking is
89 never performed at all. These include class heads, and template
92 Typical use of access checking functions is described here:
94 1. When we enter a context that requires certain access checking
95 mode, the function `push_deferring_access_checks' is called with
96 DEFERRING argument specifying the desired mode. Access checking
97 may be performed immediately (dk_no_deferred), deferred
98 (dk_deferred), or not performed (dk_no_check).
100 2. When a declaration such as a type, or a variable, is encountered,
101 the function `perform_or_defer_access_check' is called. It
102 maintains a vector of all deferred checks.
104 3. The global `current_class_type' or `current_function_decl' is then
105 setup by the parser. `enforce_access' relies on these information
108 4. Upon exiting the context mentioned in step 1,
109 `perform_deferred_access_checks' is called to check all declaration
110 stored in the vector. `pop_deferring_access_checks' is then
111 called to restore the previous access checking mode.
113 In case of parsing error, we simply call `pop_deferring_access_checks'
114 without `perform_deferred_access_checks'. */
116 struct GTY(()) deferred_access
{
117 /* A vector representing name-lookups for which we have deferred
118 checking access controls. We cannot check the accessibility of
119 names used in a decl-specifier-seq until we know what is being
120 declared because code like:
127 A::B* A::f() { return 0; }
129 is valid, even though `A::B' is not generally accessible. */
130 vec
<deferred_access_check
, va_gc
> *deferred_access_checks
;
132 /* The current mode of access checks. */
133 enum deferring_kind deferring_access_checks_kind
;
136 /* Data for deferred access checking. */
137 static GTY(()) vec
<deferred_access
, va_gc
> *deferred_access_stack
;
138 static GTY(()) unsigned deferred_access_no_check
;
140 /* Save the current deferred access states and start deferred
141 access checking iff DEFER_P is true. */
144 push_deferring_access_checks (deferring_kind deferring
)
146 /* For context like template instantiation, access checking
147 disabling applies to all nested context. */
148 if (deferred_access_no_check
|| deferring
== dk_no_check
)
149 deferred_access_no_check
++;
152 deferred_access e
= {NULL
, deferring
};
153 vec_safe_push (deferred_access_stack
, e
);
157 /* Save the current deferred access states and start deferred access
158 checking, continuing the set of deferred checks in CHECKS. */
161 reopen_deferring_access_checks (vec
<deferred_access_check
, va_gc
> * checks
)
163 push_deferring_access_checks (dk_deferred
);
164 if (!deferred_access_no_check
)
165 deferred_access_stack
->last().deferred_access_checks
= checks
;
168 /* Resume deferring access checks again after we stopped doing
172 resume_deferring_access_checks (void)
174 if (!deferred_access_no_check
)
175 deferred_access_stack
->last().deferring_access_checks_kind
= dk_deferred
;
178 /* Stop deferring access checks. */
181 stop_deferring_access_checks (void)
183 if (!deferred_access_no_check
)
184 deferred_access_stack
->last().deferring_access_checks_kind
= dk_no_deferred
;
187 /* Discard the current deferred access checks and restore the
191 pop_deferring_access_checks (void)
193 if (deferred_access_no_check
)
194 deferred_access_no_check
--;
196 deferred_access_stack
->pop ();
199 /* Returns a TREE_LIST representing the deferred checks.
200 The TREE_PURPOSE of each node is the type through which the
201 access occurred; the TREE_VALUE is the declaration named.
204 vec
<deferred_access_check
, va_gc
> *
205 get_deferred_access_checks (void)
207 if (deferred_access_no_check
)
210 return (deferred_access_stack
->last().deferred_access_checks
);
213 /* Take current deferred checks and combine with the
214 previous states if we also defer checks previously.
215 Otherwise perform checks now. */
218 pop_to_parent_deferring_access_checks (void)
220 if (deferred_access_no_check
)
221 deferred_access_no_check
--;
224 vec
<deferred_access_check
, va_gc
> *checks
;
225 deferred_access
*ptr
;
227 checks
= (deferred_access_stack
->last ().deferred_access_checks
);
229 deferred_access_stack
->pop ();
230 ptr
= &deferred_access_stack
->last ();
231 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
234 perform_access_checks (checks
, tf_warning_or_error
);
238 /* Merge with parent. */
240 deferred_access_check
*chk
, *probe
;
242 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
244 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, j
, probe
)
246 if (probe
->binfo
== chk
->binfo
&&
247 probe
->decl
== chk
->decl
&&
248 probe
->diag_decl
== chk
->diag_decl
)
251 /* Insert into parent's checks. */
252 vec_safe_push (ptr
->deferred_access_checks
, *chk
);
259 /* Called from enforce_access. A class has attempted (but failed) to access
260 DECL. It is already established that a baseclass of that class,
261 PARENT_BINFO, has private access to DECL. Examine certain special cases
262 to find a decl that accurately describes the source of the problem. If
263 none of the special cases apply, simply return DECL as the source of the
267 get_class_access_diagnostic_decl (tree parent_binfo
, tree decl
)
269 /* When a class is denied access to a decl in a baseclass, most of the
270 time it is because the decl itself was declared as private at the point
273 However, in C++, there are (at least) two situations in which a decl
274 can be private even though it was not originally defined as such.
275 These two situations only apply if a baseclass had private access to
276 DECL (this function is only called if that is the case). */
278 /* We should first check whether the reason the parent had private access
279 to DECL was simply because DECL was created and declared as private in
280 the parent. If it was, then DECL is definitively the source of the
282 if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl
),
283 BINFO_TYPE (parent_binfo
)))
286 /* 1. If the "using" keyword is used to inherit DECL within the parent,
287 this may cause DECL to be private, so we should return the using
288 statement as the source of the problem.
290 Scan the fields of PARENT_BINFO and see if there are any using decls. If
291 there are, see if they inherit DECL. If they do, that's where DECL must
292 have been declared private. */
294 for (tree parent_field
= TYPE_FIELDS (BINFO_TYPE (parent_binfo
));
296 parent_field
= DECL_CHAIN (parent_field
))
297 /* Not necessary, but also check TREE_PRIVATE for the sake of
298 eliminating obviously non-relevant using decls. */
299 if (TREE_CODE (parent_field
) == USING_DECL
300 && TREE_PRIVATE (parent_field
))
302 tree decl_stripped
= strip_using_decl (parent_field
);
304 /* The using statement might be overloaded. If so, we need to
305 check all of the overloads. */
306 for (ovl_iterator
iter (decl_stripped
); iter
; ++iter
)
307 /* If equal, the using statement inherits DECL, and so is the
308 source of the access failure, so return it. */
313 /* 2. If DECL was privately inherited by the parent class, then DECL will
314 be inaccessible, even though it may originally have been accessible to
315 deriving classes. In that case, the fault lies with the parent, since it
316 used a private inheritance, so we return the parent as the source of the
319 Since this is the last check, we just assume it's true. At worst, it
320 will simply point to the class that failed to give access, which is
322 return TYPE_NAME (BINFO_TYPE (parent_binfo
));
325 /* If the current scope isn't allowed to access DECL along
326 BASETYPE_PATH, give an error, or if we're parsing a function or class
327 template, defer the access check to be performed at instantiation time.
328 The most derived class in BASETYPE_PATH is the one used to qualify DECL.
329 DIAG_DECL is the declaration to use in the error diagnostic. */
332 enforce_access (tree basetype_path
, tree decl
, tree diag_decl
,
333 tsubst_flags_t complain
, access_failure_info
*afi
= NULL
)
335 gcc_assert (TREE_CODE (basetype_path
) == TREE_BINFO
);
337 if (flag_new_inheriting_ctors
338 && DECL_INHERITED_CTOR (decl
))
340 /* 7.3.3/18: The additional constructors are accessible if they would be
341 accessible when used to construct an object of the corresponding base
343 decl
= strip_inheriting_ctors (decl
);
344 basetype_path
= lookup_base (basetype_path
, DECL_CONTEXT (decl
),
345 ba_any
, NULL
, complain
);
348 tree cs
= current_scope ();
349 if (processing_template_decl
350 && (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
))
351 if (tree template_info
= get_template_info (cs
))
353 /* When parsing a function or class template, we in general need to
354 defer access checks until template instantiation time, since a friend
355 declaration may grant access only to a particular specialization of
358 if (accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
359 /* But if the member is deemed accessible at parse time, then we can
360 assume it'll be accessible at instantiation time. */
363 /* Access of a dependent decl should be rechecked after tsubst'ing
364 into the user of the decl, rather than explicitly deferring the
366 gcc_assert (!uses_template_parms (decl
));
367 if (TREE_CODE (decl
) == FIELD_DECL
)
368 gcc_assert (!uses_template_parms (DECL_CONTEXT (decl
)));
370 /* Defer this access check until instantiation time. */
371 deferred_access_check access_check
;
372 access_check
.binfo
= basetype_path
;
373 access_check
.decl
= decl
;
374 access_check
.diag_decl
= diag_decl
;
375 access_check
.loc
= input_location
;
376 vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info
), access_check
);
380 if (!accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
382 if (flag_new_inheriting_ctors
)
383 diag_decl
= strip_inheriting_ctors (diag_decl
);
384 if (complain
& tf_error
)
386 access_kind access_failure_reason
= ak_none
;
388 /* By default, using the decl as the source of the problem will
389 usually give correct results. */
390 tree diag_location
= diag_decl
;
392 /* However, if a parent of BASETYPE_PATH had private access to decl,
393 then it actually might be the case that the source of the problem
395 tree parent_binfo
= get_parent_with_private_access (decl
,
398 /* So if a parent did have private access, then we need to do
399 special checks to obtain the best diagnostic location decl. */
400 if (parent_binfo
!= NULL_TREE
)
402 diag_location
= get_class_access_diagnostic_decl (parent_binfo
,
405 /* We also at this point know that the reason access failed was
406 because decl was private. */
407 access_failure_reason
= ak_private
;
410 /* Finally, generate an error message. */
411 complain_about_access (decl
, diag_decl
, diag_location
, true,
412 access_failure_reason
);
415 afi
->record_access_failure (basetype_path
, decl
, diag_decl
);
422 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
423 is the BINFO indicating the qualifying scope used to access the
424 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
425 or we aren't in SFINAE context or all the checks succeed return TRUE,
429 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
430 tsubst_flags_t complain
)
433 deferred_access_check
*chk
;
434 location_t loc
= input_location
;
440 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
442 input_location
= chk
->loc
;
443 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
446 input_location
= loc
;
447 return (complain
& tf_error
) ? true : ok
;
450 /* Perform the deferred access checks.
452 After performing the checks, we still have to keep the list
453 `deferred_access_stack->deferred_access_checks' since we may want
454 to check access for them again later in a different context.
461 A::X A::a, x; // No error for `A::a', error for `x'
463 We have to perform deferred access of `A::X', first with `A::a',
464 next with `x'. Return value like perform_access_checks above. */
467 perform_deferred_access_checks (tsubst_flags_t complain
)
469 return perform_access_checks (get_deferred_access_checks (), complain
);
472 /* Defer checking the accessibility of DECL, when looked up in
473 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
474 Return value like perform_access_checks above.
475 If non-NULL, report failures to AFI. */
478 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
479 tsubst_flags_t complain
,
480 access_failure_info
*afi
)
483 deferred_access
*ptr
;
484 deferred_access_check
*chk
;
486 /* Exit if we are in a context that no access checking is performed. */
487 if (deferred_access_no_check
)
490 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
492 ptr
= &deferred_access_stack
->last ();
494 /* If we are not supposed to defer access checks, just check now. */
495 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
497 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
, afi
);
498 return (complain
& tf_error
) ? true : ok
;
501 /* See if we are already going to perform this check. */
502 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
504 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
505 chk
->diag_decl
== diag_decl
)
510 /* If not, record the check. */
511 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
512 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
517 /* Returns nonzero if the current statement is a full expression,
518 i.e. temporaries created during that statement should be destroyed
519 at the end of the statement. */
522 stmts_are_full_exprs_p (void)
524 return current_stmt_tree ()->stmts_are_full_exprs_p
;
527 /* T is a statement. Add it to the statement-tree. This is the C++
528 version. The C/ObjC frontends have a slightly different version of
534 enum tree_code code
= TREE_CODE (t
);
536 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
538 if (!EXPR_HAS_LOCATION (t
))
539 SET_EXPR_LOCATION (t
, input_location
);
541 /* When we expand a statement-tree, we must know whether or not the
542 statements are full-expressions. We record that fact here. */
543 if (STATEMENT_CODE_P (TREE_CODE (t
)))
544 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
547 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
548 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
550 /* Add T to the statement-tree. Non-side-effect statements need to be
551 recorded during statement expressions. */
552 gcc_checking_assert (!stmt_list_stack
->is_empty ());
553 append_to_statement_list_force (t
, &cur_stmt_list
);
558 /* Returns the stmt_tree to which statements are currently being added. */
561 current_stmt_tree (void)
564 ? &cfun
->language
->base
.x_stmt_tree
565 : &scope_chain
->x_stmt_tree
);
568 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
571 maybe_cleanup_point_expr (tree expr
)
573 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
574 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
578 /* Like maybe_cleanup_point_expr except have the type of the new expression be
579 void so we don't need to create a temporary variable to hold the inner
580 expression. The reason why we do this is because the original type might be
581 an aggregate and we cannot create a temporary variable for that type. */
584 maybe_cleanup_point_expr_void (tree expr
)
586 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
587 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
593 /* Create a declaration statement for the declaration given by the DECL. */
596 add_decl_expr (tree decl
)
598 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
599 if (DECL_INITIAL (decl
)
600 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
601 r
= maybe_cleanup_point_expr_void (r
);
605 /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC. */
608 set_cleanup_locs (tree stmts
, location_t loc
)
610 if (TREE_CODE (stmts
) == CLEANUP_STMT
)
612 protected_set_expr_location (CLEANUP_EXPR (stmts
), loc
);
613 set_cleanup_locs (CLEANUP_BODY (stmts
), loc
);
615 else if (TREE_CODE (stmts
) == STATEMENT_LIST
)
616 for (tree stmt
: tsi_range (stmts
))
617 set_cleanup_locs (stmt
, loc
);
620 /* Finish a scope. */
623 do_poplevel (tree stmt_list
)
627 if (stmts_are_full_exprs_p ())
628 block
= poplevel (kept_level_p (), 1, 0);
630 stmt_list
= pop_stmt_list (stmt_list
);
632 /* input_location is the last token of the scope, usually a }. */
633 set_cleanup_locs (stmt_list
, input_location
);
635 if (!processing_template_decl
)
637 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
638 /* ??? See c_end_compound_stmt re statement expressions. */
644 /* Begin a new scope. */
647 do_pushlevel (scope_kind sk
)
649 tree ret
= push_stmt_list ();
650 if (stmts_are_full_exprs_p ())
651 begin_scope (sk
, NULL
);
655 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
656 when the current scope is exited. EH_ONLY is true when this is not
657 meant to apply to normal control flow transfer. */
660 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
662 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
663 CLEANUP_EH_ONLY (stmt
) = eh_only
;
665 CLEANUP_BODY (stmt
) = push_stmt_list ();
668 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
669 the current loops, represented by 'NULL_TREE' if we've seen a possible
670 exit, and 'error_mark_node' if not. This is currently used only to
671 suppress the warning about a function with no return statements, and
672 therefore we don't bother noting returns as possible exits. We also
673 don't bother with gotos. */
676 begin_maybe_infinite_loop (tree cond
)
678 /* Only track this while parsing a function, not during instantiation. */
679 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
680 && !processing_template_decl
))
682 bool maybe_infinite
= true;
685 cond
= fold_non_dependent_expr (cond
);
686 maybe_infinite
= integer_nonzerop (cond
);
688 vec_safe_push (cp_function_chain
->infinite_loops
,
689 maybe_infinite
? error_mark_node
: NULL_TREE
);
693 /* A break is a possible exit for the current loop. */
696 break_maybe_infinite_loop (void)
700 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
703 /* If we reach the end of the loop without seeing a possible exit, we have
707 end_maybe_infinite_loop (tree cond
)
709 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
710 && !processing_template_decl
))
712 tree current
= cp_function_chain
->infinite_loops
->pop();
713 if (current
!= NULL_TREE
)
715 cond
= fold_non_dependent_expr (cond
);
716 if (integer_nonzerop (cond
))
717 current_function_infinite_loop
= 1;
722 /* Begin a conditional that might contain a declaration. When generating
723 normal code, we want the declaration to appear before the statement
724 containing the conditional. When generating template code, we want the
725 conditional to be rendered as the raw DECL_EXPR. */
728 begin_cond (tree
*cond_p
)
730 if (processing_template_decl
)
731 *cond_p
= push_stmt_list ();
734 /* Finish such a conditional. */
737 finish_cond (tree
*cond_p
, tree expr
)
739 if (processing_template_decl
)
741 tree cond
= pop_stmt_list (*cond_p
);
743 if (expr
== NULL_TREE
)
744 /* Empty condition in 'for'. */
745 gcc_assert (empty_expr_stmt_p (cond
));
746 else if (check_for_bare_parameter_packs (expr
))
747 expr
= error_mark_node
;
748 else if (!empty_expr_stmt_p (cond
))
749 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
754 /* If *COND_P specifies a conditional with a declaration, transform the
757 for (; A x = 42;) { }
759 while (true) { A x = 42; if (!x) break; }
760 for (;;) { A x = 42; if (!x) break; }
761 The statement list for BODY will be empty if the conditional did
762 not declare anything. */
765 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
769 if (!TREE_SIDE_EFFECTS (body
))
773 *cond_p
= boolean_true_node
;
775 if_stmt
= begin_if_stmt ();
776 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, false, tf_warning_or_error
);
777 finish_if_stmt_cond (cond
, if_stmt
);
778 finish_break_stmt ();
779 finish_then_clause (if_stmt
);
780 finish_if_stmt (if_stmt
);
783 /* Finish a goto-statement. */
786 finish_goto_stmt (tree destination
)
788 if (identifier_p (destination
))
789 destination
= lookup_label (destination
);
791 /* We warn about unused labels with -Wunused. That means we have to
792 mark the used labels as used. */
793 if (TREE_CODE (destination
) == LABEL_DECL
)
794 TREE_USED (destination
) = 1;
797 destination
= mark_rvalue_use (destination
);
798 if (!processing_template_decl
)
800 destination
= cp_convert (ptr_type_node
, destination
,
801 tf_warning_or_error
);
802 if (error_operand_p (destination
))
805 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
810 check_goto (destination
);
812 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
813 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
816 /* COND is the condition-expression for an if, while, etc.,
817 statement. Convert it to a boolean value, if appropriate.
818 In addition, verify sequence points if -Wsequence-point is enabled. */
821 maybe_convert_cond (tree cond
)
823 /* Empty conditions remain empty. */
827 /* Wait until we instantiate templates before doing conversion. */
828 if (type_dependent_expression_p (cond
))
831 if (warn_sequence_point
&& !processing_template_decl
)
832 verify_sequence_points (cond
);
834 /* Do the conversion. */
835 cond
= convert_from_reference (cond
);
837 if (TREE_CODE (cond
) == MODIFY_EXPR
839 && !warning_suppressed_p (cond
, OPT_Wparentheses
)
840 && warning_at (cp_expr_loc_or_input_loc (cond
),
841 OPT_Wparentheses
, "suggest parentheses around "
842 "assignment used as truth value"))
843 suppress_warning (cond
, OPT_Wparentheses
);
845 return condition_conversion (cond
);
848 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
851 finish_expr_stmt (tree expr
)
854 location_t loc
= EXPR_LOCATION (expr
);
856 if (expr
!= NULL_TREE
)
858 /* If we ran into a problem, make sure we complained. */
859 gcc_assert (expr
!= error_mark_node
|| seen_error ());
861 if (!processing_template_decl
)
863 if (warn_sequence_point
)
864 verify_sequence_points (expr
);
865 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
867 else if (!type_dependent_expression_p (expr
))
868 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
869 tf_warning_or_error
);
871 if (check_for_bare_parameter_packs (expr
))
872 expr
= error_mark_node
;
874 /* Simplification of inner statement expressions, compound exprs,
875 etc can result in us already having an EXPR_STMT. */
876 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
878 if (TREE_CODE (expr
) != EXPR_STMT
)
879 expr
= build_stmt (loc
, EXPR_STMT
, expr
);
880 expr
= maybe_cleanup_point_expr_void (expr
);
890 /* Begin an if-statement. Returns a newly created IF_STMT if
897 scope
= do_pushlevel (sk_cond
);
898 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
899 NULL_TREE
, NULL_TREE
, scope
);
900 current_binding_level
->this_entity
= r
;
901 begin_cond (&IF_COND (r
));
905 /* Returns true if FN, a CALL_EXPR, is a call to
906 std::is_constant_evaluated or __builtin_is_constant_evaluated. */
909 is_std_constant_evaluated_p (tree fn
)
911 /* std::is_constant_evaluated takes no arguments. */
912 if (call_expr_nargs (fn
) != 0)
915 tree fndecl
= cp_get_callee_fndecl_nofold (fn
);
916 if (fndecl
== NULL_TREE
)
919 if (fndecl_built_in_p (fndecl
, CP_BUILT_IN_IS_CONSTANT_EVALUATED
,
923 if (!decl_in_std_namespace_p (fndecl
))
926 tree name
= DECL_NAME (fndecl
);
927 return name
&& id_equal (name
, "is_constant_evaluated");
930 /* Callback function for maybe_warn_for_constant_evaluated that looks
931 for calls to std::is_constant_evaluated in TP. */
934 find_std_constant_evaluated_r (tree
*tp
, int *walk_subtrees
, void *)
938 if (TYPE_P (t
) || TREE_CONSTANT (t
))
940 *walk_subtrees
= false;
944 switch (TREE_CODE (t
))
947 if (is_std_constant_evaluated_p (t
))
951 /* Don't warn in statement expressions. */
952 *walk_subtrees
= false;
961 /* In certain contexts, std::is_constant_evaluated() is always true (for
962 instance, in a consteval function or in a constexpr if), or always false
963 (e.g., in a non-constexpr non-consteval function) so give the user a clue. */
966 maybe_warn_for_constant_evaluated (tree cond
, bool constexpr_if
)
968 if (!warn_tautological_compare
)
971 /* Suppress warning for std::is_constant_evaluated if the conditional
972 comes from a macro. */
973 if (from_macro_expansion_at (EXPR_LOCATION (cond
)))
976 cond
= cp_walk_tree_without_duplicates (&cond
, find_std_constant_evaluated_r
,
981 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
982 "%<std::is_constant_evaluated%> always evaluates to "
983 "true in %<if constexpr%>");
984 else if (!maybe_constexpr_fn (current_function_decl
))
985 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
986 "%<std::is_constant_evaluated%> always evaluates to "
987 "false in a non-%<constexpr%> function");
988 else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl
))
989 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
990 "%<std::is_constant_evaluated%> always evaluates to "
991 "true in a %<consteval%> function");
995 /* Process the COND of an if-statement, which may be given by
999 finish_if_stmt_cond (tree cond
, tree if_stmt
)
1001 cond
= maybe_convert_cond (cond
);
1002 if (IF_STMT_CONSTEXPR_P (if_stmt
)
1003 && !type_dependent_expression_p (cond
)
1004 && require_constant_expression (cond
)
1005 && !instantiation_dependent_expression_p (cond
)
1006 /* Wait until instantiation time, since only then COND has been
1007 converted to bool. */
1008 && TYPE_MAIN_VARIANT (TREE_TYPE (cond
)) == boolean_type_node
)
1010 maybe_warn_for_constant_evaluated (cond
, /*constexpr_if=*/true);
1011 cond
= instantiate_non_dependent_expr (cond
);
1012 cond
= cxx_constant_value (cond
, NULL_TREE
);
1015 maybe_warn_for_constant_evaluated (cond
, /*constexpr_if=*/false);
1016 finish_cond (&IF_COND (if_stmt
), cond
);
1018 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
1022 /* Finish the then-clause of an if-statement, which may be given by
1026 finish_then_clause (tree if_stmt
)
1028 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
1032 /* Begin the else-clause of an if-statement. */
1035 begin_else_clause (tree if_stmt
)
1037 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
1040 /* Finish the else-clause of an if-statement, which may be given by
1044 finish_else_clause (tree if_stmt
)
1046 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
1049 /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1053 maybe_mark_exp_read_r (tree
*tp
, int *, void *)
1056 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
1061 /* Finish an if-statement. */
1064 finish_if_stmt (tree if_stmt
)
1066 tree scope
= IF_SCOPE (if_stmt
);
1067 IF_SCOPE (if_stmt
) = NULL
;
1068 if (IF_STMT_CONSTEXPR_P (if_stmt
))
1070 /* Prevent various -Wunused warnings. We might not instantiate
1071 either of these branches, so we would not mark the variables
1072 used in that branch as read. */
1073 cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt
),
1074 maybe_mark_exp_read_r
, NULL
);
1075 cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt
),
1076 maybe_mark_exp_read_r
, NULL
);
1078 add_stmt (do_poplevel (scope
));
1081 /* Begin a while-statement. Returns a newly created WHILE_STMT if
1085 begin_while_stmt (void)
1088 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
1090 WHILE_BODY (r
) = do_pushlevel (sk_block
);
1091 begin_cond (&WHILE_COND (r
));
1095 /* Process the COND of a while-statement, which may be given by
1099 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
,
1100 unsigned short unroll
)
1102 cond
= maybe_convert_cond (cond
);
1103 finish_cond (&WHILE_COND (while_stmt
), cond
);
1104 begin_maybe_infinite_loop (cond
);
1105 if (ivdep
&& cond
!= error_mark_node
)
1106 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
1107 TREE_TYPE (WHILE_COND (while_stmt
)),
1108 WHILE_COND (while_stmt
),
1109 build_int_cst (integer_type_node
,
1110 annot_expr_ivdep_kind
),
1112 if (unroll
&& cond
!= error_mark_node
)
1113 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
1114 TREE_TYPE (WHILE_COND (while_stmt
)),
1115 WHILE_COND (while_stmt
),
1116 build_int_cst (integer_type_node
,
1117 annot_expr_unroll_kind
),
1118 build_int_cst (integer_type_node
,
1120 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
1123 /* Finish a while-statement, which may be given by WHILE_STMT. */
1126 finish_while_stmt (tree while_stmt
)
1128 end_maybe_infinite_loop (boolean_true_node
);
1129 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
1132 /* Begin a do-statement. Returns a newly created DO_STMT if
1136 begin_do_stmt (void)
1138 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
1139 begin_maybe_infinite_loop (boolean_true_node
);
1141 DO_BODY (r
) = push_stmt_list ();
1145 /* Finish the body of a do-statement, which may be given by DO_STMT. */
1148 finish_do_body (tree do_stmt
)
1150 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
1152 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
1153 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
1155 if (IS_EMPTY_STMT (body
))
1156 warning (OPT_Wempty_body
,
1157 "suggest explicit braces around empty body in %<do%> statement");
1160 /* Finish a do-statement, which may be given by DO_STMT, and whose
1161 COND is as indicated. */
1164 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
, unsigned short unroll
)
1166 cond
= maybe_convert_cond (cond
);
1167 end_maybe_infinite_loop (cond
);
1168 /* Unlike other iteration statements, the condition may not contain
1169 a declaration, so we don't call finish_cond which checks for
1170 unexpanded parameter packs. */
1171 if (check_for_bare_parameter_packs (cond
))
1172 cond
= error_mark_node
;
1173 if (ivdep
&& cond
!= error_mark_node
)
1174 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1175 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
),
1177 if (unroll
&& cond
!= error_mark_node
)
1178 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1179 build_int_cst (integer_type_node
, annot_expr_unroll_kind
),
1180 build_int_cst (integer_type_node
, unroll
));
1181 DO_COND (do_stmt
) = cond
;
1184 /* Finish a return-statement. The EXPRESSION returned, if any, is as
1188 finish_return_stmt (tree expr
)
1193 expr
= check_return_expr (expr
, &no_warning
);
1195 if (error_operand_p (expr
)
1196 || (flag_openmp
&& !check_omp_return ()))
1198 /* Suppress -Wreturn-type for this function. */
1199 if (warn_return_type
)
1200 suppress_warning (current_function_decl
, OPT_Wreturn_type
);
1201 return error_mark_node
;
1204 if (!processing_template_decl
)
1206 if (warn_sequence_point
)
1207 verify_sequence_points (expr
);
1209 if (DECL_DESTRUCTOR_P (current_function_decl
)
1210 || (DECL_CONSTRUCTOR_P (current_function_decl
)
1211 && targetm
.cxx
.cdtor_returns_this ()))
1213 /* Similarly, all destructors must run destructors for
1214 base-classes before returning. So, all returns in a
1215 destructor get sent to the DTOR_LABEL; finish_function emits
1216 code to return a value there. */
1217 return finish_goto_stmt (cdtor_label
);
1221 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
1223 suppress_warning (r
, OPT_Wreturn_type
);
1224 r
= maybe_cleanup_point_expr_void (r
);
1230 /* Begin the scope of a for-statement or a range-for-statement.
1231 Both the returned trees are to be used in a call to
1232 begin_for_stmt or begin_range_for_stmt. */
1235 begin_for_scope (tree
*init
)
1237 tree scope
= do_pushlevel (sk_for
);
1239 if (processing_template_decl
)
1240 *init
= push_stmt_list ();
1247 /* Begin a for-statement. Returns a new FOR_STMT.
1248 SCOPE and INIT should be the return of begin_for_scope,
1249 or both NULL_TREE */
1252 begin_for_stmt (tree scope
, tree init
)
1256 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
1257 NULL_TREE
, NULL_TREE
, NULL_TREE
);
1259 if (scope
== NULL_TREE
)
1262 scope
= begin_for_scope (&init
);
1265 FOR_INIT_STMT (r
) = init
;
1266 FOR_SCOPE (r
) = scope
;
1271 /* Finish the init-statement of a for-statement, which may be
1272 given by FOR_STMT. */
1275 finish_init_stmt (tree for_stmt
)
1277 if (processing_template_decl
)
1278 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
1279 add_stmt (for_stmt
);
1280 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
1281 begin_cond (&FOR_COND (for_stmt
));
1284 /* Finish the COND of a for-statement, which may be given by
1288 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
, unsigned short unroll
)
1290 cond
= maybe_convert_cond (cond
);
1291 finish_cond (&FOR_COND (for_stmt
), cond
);
1292 begin_maybe_infinite_loop (cond
);
1293 if (ivdep
&& cond
!= error_mark_node
)
1294 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1295 TREE_TYPE (FOR_COND (for_stmt
)),
1296 FOR_COND (for_stmt
),
1297 build_int_cst (integer_type_node
,
1298 annot_expr_ivdep_kind
),
1300 if (unroll
&& cond
!= error_mark_node
)
1301 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1302 TREE_TYPE (FOR_COND (for_stmt
)),
1303 FOR_COND (for_stmt
),
1304 build_int_cst (integer_type_node
,
1305 annot_expr_unroll_kind
),
1306 build_int_cst (integer_type_node
,
1308 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
1311 /* Finish the increment-EXPRESSION in a for-statement, which may be
1312 given by FOR_STMT. */
1315 finish_for_expr (tree expr
, tree for_stmt
)
1319 /* If EXPR is an overloaded function, issue an error; there is no
1320 context available to use to perform overload resolution. */
1321 if (type_unknown_p (expr
))
1323 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1324 expr
= error_mark_node
;
1326 if (!processing_template_decl
)
1328 if (warn_sequence_point
)
1329 verify_sequence_points (expr
);
1330 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1331 tf_warning_or_error
);
1333 else if (!type_dependent_expression_p (expr
))
1334 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1335 tf_warning_or_error
);
1336 expr
= maybe_cleanup_point_expr_void (expr
);
1337 if (check_for_bare_parameter_packs (expr
))
1338 expr
= error_mark_node
;
1339 FOR_EXPR (for_stmt
) = expr
;
1342 /* Finish the body of a for-statement, which may be given by
1343 FOR_STMT. The increment-EXPR for the loop must be
1345 It can also finish RANGE_FOR_STMT. */
1348 finish_for_stmt (tree for_stmt
)
1350 end_maybe_infinite_loop (boolean_true_node
);
1352 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1353 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1355 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1357 /* Pop the scope for the body of the loop. */
1358 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1359 ? &RANGE_FOR_SCOPE (for_stmt
)
1360 : &FOR_SCOPE (for_stmt
));
1361 tree scope
= *scope_ptr
;
1364 /* During parsing of the body, range for uses "__for_{range,begin,end} "
1365 decl names to make those unaccessible by code in the body.
1366 Change it to ones with underscore instead of space, so that it can
1367 be inspected in the debugger. */
1368 tree range_for_decl
[3] = { NULL_TREE
, NULL_TREE
, NULL_TREE
};
1369 gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 1
1370 && CPTI_FOR_END__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 2
1371 && CPTI_FOR_RANGE_IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 3
1372 && CPTI_FOR_BEGIN_IDENTIFIER
== CPTI_FOR_BEGIN__IDENTIFIER
+ 3
1373 && CPTI_FOR_END_IDENTIFIER
== CPTI_FOR_END__IDENTIFIER
+ 3);
1374 for (int i
= 0; i
< 3; i
++)
1376 tree id
= cp_global_trees
[CPTI_FOR_RANGE__IDENTIFIER
+ i
];
1377 if (IDENTIFIER_BINDING (id
)
1378 && IDENTIFIER_BINDING (id
)->scope
== current_binding_level
)
1380 range_for_decl
[i
] = IDENTIFIER_BINDING (id
)->value
;
1381 gcc_assert (VAR_P (range_for_decl
[i
])
1382 && DECL_ARTIFICIAL (range_for_decl
[i
]));
1386 add_stmt (do_poplevel (scope
));
1388 for (int i
= 0; i
< 3; i
++)
1389 if (range_for_decl
[i
])
1390 DECL_NAME (range_for_decl
[i
])
1391 = cp_global_trees
[CPTI_FOR_RANGE_IDENTIFIER
+ i
];
1394 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1395 SCOPE and INIT should be the return of begin_for_scope,
1397 To finish it call finish_for_stmt(). */
1400 begin_range_for_stmt (tree scope
, tree init
)
1402 begin_maybe_infinite_loop (boolean_false_node
);
1404 tree r
= build_stmt (input_location
, RANGE_FOR_STMT
, NULL_TREE
, NULL_TREE
,
1405 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1407 if (scope
== NULL_TREE
)
1410 scope
= begin_for_scope (&init
);
1413 /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1414 RANGE_FOR_INIT_STMT (r
) = init
;
1415 RANGE_FOR_SCOPE (r
) = scope
;
1420 /* Finish the head of a range-based for statement, which may
1421 be given by RANGE_FOR_STMT. DECL must be the declaration
1422 and EXPR must be the loop expression. */
1425 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1427 if (processing_template_decl
)
1428 RANGE_FOR_INIT_STMT (range_for_stmt
)
1429 = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt
));
1430 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1431 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1432 add_stmt (range_for_stmt
);
1433 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1436 /* Finish a break-statement. */
1439 finish_break_stmt (void)
1441 /* In switch statements break is sometimes stylistically used after
1442 a return statement. This can lead to spurious warnings about
1443 control reaching the end of a non-void function when it is
1444 inlined. Note that we are calling block_may_fallthru with
1445 language specific tree nodes; this works because
1446 block_may_fallthru returns true when given something it does not
1448 if (!block_may_fallthru (cur_stmt_list
))
1451 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1454 /* Finish a continue-statement. */
1457 finish_continue_stmt (void)
1459 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1462 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1466 begin_switch_stmt (void)
1470 scope
= do_pushlevel (sk_cond
);
1471 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1473 begin_cond (&SWITCH_STMT_COND (r
));
1478 /* Finish the cond of a switch-statement. */
1481 finish_switch_cond (tree cond
, tree switch_stmt
)
1483 tree orig_type
= NULL
;
1485 if (!processing_template_decl
)
1487 /* Convert the condition to an integer or enumeration type. */
1488 tree orig_cond
= cond
;
1489 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1490 if (cond
== NULL_TREE
)
1492 error_at (cp_expr_loc_or_input_loc (orig_cond
),
1493 "switch quantity not an integer");
1494 cond
= error_mark_node
;
1496 /* We want unlowered type here to handle enum bit-fields. */
1497 orig_type
= unlowered_expr_type (cond
);
1498 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1499 orig_type
= TREE_TYPE (cond
);
1500 if (cond
!= error_mark_node
)
1504 Integral promotions are performed. */
1505 cond
= perform_integral_promotions (cond
);
1506 cond
= maybe_cleanup_point_expr (cond
);
1509 if (check_for_bare_parameter_packs (cond
))
1510 cond
= error_mark_node
;
1511 else if (!processing_template_decl
&& warn_sequence_point
)
1512 verify_sequence_points (cond
);
1514 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1515 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1516 add_stmt (switch_stmt
);
1517 push_switch (switch_stmt
);
1518 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1521 /* Finish the body of a switch-statement, which may be given by
1522 SWITCH_STMT. The COND to switch on is indicated. */
1525 finish_switch_stmt (tree switch_stmt
)
1529 SWITCH_STMT_BODY (switch_stmt
) =
1530 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1533 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1534 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1535 add_stmt (do_poplevel (scope
));
1538 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1542 begin_try_block (void)
1544 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1546 TRY_STMTS (r
) = push_stmt_list ();
1550 /* Likewise, for a function-try-block. The block returned in
1551 *COMPOUND_STMT is an artificial outer scope, containing the
1552 function-try-block. */
1555 begin_function_try_block (tree
*compound_stmt
)
1558 /* This outer scope does not exist in the C++ standard, but we need
1559 a place to put __FUNCTION__ and similar variables. */
1560 *compound_stmt
= begin_compound_stmt (0);
1561 r
= begin_try_block ();
1562 FN_TRY_BLOCK_P (r
) = 1;
1566 /* Finish a try-block, which may be given by TRY_BLOCK. */
1569 finish_try_block (tree try_block
)
1571 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1572 TRY_HANDLERS (try_block
) = push_stmt_list ();
1575 /* Finish the body of a cleanup try-block, which may be given by
1579 finish_cleanup_try_block (tree try_block
)
1581 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1584 /* Finish an implicitly generated try-block, with a cleanup is given
1588 finish_cleanup (tree cleanup
, tree try_block
)
1590 TRY_HANDLERS (try_block
) = cleanup
;
1591 CLEANUP_P (try_block
) = 1;
1594 /* Likewise, for a function-try-block. */
1597 finish_function_try_block (tree try_block
)
1599 finish_try_block (try_block
);
1600 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1601 the try block, but moving it inside. */
1602 in_function_try_handler
= 1;
1605 /* Finish a handler-sequence for a try-block, which may be given by
1609 finish_handler_sequence (tree try_block
)
1611 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1612 check_handlers (TRY_HANDLERS (try_block
));
1615 /* Finish the handler-seq for a function-try-block, given by
1616 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1617 begin_function_try_block. */
1620 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1622 in_function_try_handler
= 0;
1623 finish_handler_sequence (try_block
);
1624 finish_compound_stmt (compound_stmt
);
1627 /* Begin a handler. Returns a HANDLER if appropriate. */
1630 begin_handler (void)
1634 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1637 /* Create a binding level for the eh_info and the exception object
1639 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1644 /* Finish the handler-parameters for a handler, which may be given by
1645 HANDLER. DECL is the declaration for the catch parameter, or NULL
1646 if this is a `catch (...)' clause. */
1649 finish_handler_parms (tree decl
, tree handler
)
1651 tree type
= NULL_TREE
;
1652 if (processing_template_decl
)
1656 decl
= pushdecl (decl
);
1657 decl
= push_template_decl (decl
);
1658 HANDLER_PARMS (handler
) = decl
;
1659 type
= TREE_TYPE (decl
);
1664 type
= expand_start_catch_block (decl
);
1665 if (warn_catch_value
1666 && type
!= NULL_TREE
1667 && type
!= error_mark_node
1668 && !TYPE_REF_P (TREE_TYPE (decl
)))
1670 tree orig_type
= TREE_TYPE (decl
);
1671 if (CLASS_TYPE_P (orig_type
))
1673 if (TYPE_POLYMORPHIC_P (orig_type
))
1674 warning_at (DECL_SOURCE_LOCATION (decl
),
1676 "catching polymorphic type %q#T by value",
1678 else if (warn_catch_value
> 1)
1679 warning_at (DECL_SOURCE_LOCATION (decl
),
1681 "catching type %q#T by value", orig_type
);
1683 else if (warn_catch_value
> 2)
1684 warning_at (DECL_SOURCE_LOCATION (decl
),
1686 "catching non-reference type %q#T", orig_type
);
1689 HANDLER_TYPE (handler
) = type
;
1692 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1693 the return value from the matching call to finish_handler_parms. */
1696 finish_handler (tree handler
)
1698 if (!processing_template_decl
)
1699 expand_end_catch_block ();
1700 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1703 /* Begin a compound statement. FLAGS contains some bits that control the
1704 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1705 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1706 block of a function. If BCS_TRY_BLOCK is set, this is the block
1707 created on behalf of a TRY statement. Returns a token to be passed to
1708 finish_compound_stmt. */
1711 begin_compound_stmt (unsigned int flags
)
1715 if (flags
& BCS_NO_SCOPE
)
1717 r
= push_stmt_list ();
1718 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1720 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1721 But, if it's a statement-expression with a scopeless block, there's
1722 nothing to keep, and we don't want to accidentally keep a block
1723 *inside* the scopeless block. */
1724 keep_next_level (false);
1728 scope_kind sk
= sk_block
;
1729 if (flags
& BCS_TRY_BLOCK
)
1731 else if (flags
& BCS_TRANSACTION
)
1732 sk
= sk_transaction
;
1733 r
= do_pushlevel (sk
);
1736 /* When processing a template, we need to remember where the braces were,
1737 so that we can set up identical scopes when instantiating the template
1738 later. BIND_EXPR is a handy candidate for this.
1739 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1740 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1741 processing templates. */
1742 if (processing_template_decl
)
1744 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1745 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1746 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1747 TREE_SIDE_EFFECTS (r
) = 1;
1753 /* Finish a compound-statement, which is given by STMT. */
1756 finish_compound_stmt (tree stmt
)
1758 if (TREE_CODE (stmt
) == BIND_EXPR
)
1760 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1761 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1762 discard the BIND_EXPR so it can be merged with the containing
1764 if (TREE_CODE (body
) == STATEMENT_LIST
1765 && STATEMENT_LIST_HEAD (body
) == NULL
1766 && !BIND_EXPR_BODY_BLOCK (stmt
)
1767 && !BIND_EXPR_TRY_BLOCK (stmt
))
1770 BIND_EXPR_BODY (stmt
) = body
;
1772 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1773 stmt
= pop_stmt_list (stmt
);
1776 /* Destroy any ObjC "super" receivers that may have been
1778 objc_clear_super_receiver ();
1780 stmt
= do_poplevel (stmt
);
1783 /* ??? See c_end_compound_stmt wrt statement expressions. */
1787 /* Finish an asm-statement, whose components are a STRING, some
1788 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1789 LABELS. Also note whether the asm-statement should be
1790 considered volatile, and whether it is asm inline. */
1793 finish_asm_stmt (location_t loc
, int volatile_p
, tree string
,
1794 tree output_operands
, tree input_operands
, tree clobbers
,
1795 tree labels
, bool inline_p
)
1799 int ninputs
= list_length (input_operands
);
1800 int noutputs
= list_length (output_operands
);
1802 if (!processing_template_decl
)
1804 const char *constraint
;
1805 const char **oconstraints
;
1806 bool allows_mem
, allows_reg
, is_inout
;
1810 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1812 string
= resolve_asm_operand_names (string
, output_operands
,
1813 input_operands
, labels
);
1815 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1817 operand
= TREE_VALUE (t
);
1819 /* ??? Really, this should not be here. Users should be using a
1820 proper lvalue, dammit. But there's a long history of using
1821 casts in the output operands. In cases like longlong.h, this
1822 becomes a primitive form of typechecking -- if the cast can be
1823 removed, then the output operand had a type of the proper width;
1824 otherwise we'll get an error. Gross, but ... */
1825 STRIP_NOPS (operand
);
1827 operand
= mark_lvalue_use (operand
);
1829 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1830 operand
= error_mark_node
;
1832 if (operand
!= error_mark_node
1833 && (TREE_READONLY (operand
)
1834 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1835 /* Functions are not modifiable, even though they are
1837 || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand
))
1838 /* If it's an aggregate and any field is const, then it is
1839 effectively const. */
1840 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1841 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1842 cxx_readonly_error (loc
, operand
, lv_asm
);
1844 tree
*op
= &operand
;
1845 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1846 op
= &TREE_OPERAND (*op
, 1);
1847 switch (TREE_CODE (*op
))
1849 case PREINCREMENT_EXPR
:
1850 case PREDECREMENT_EXPR
:
1852 *op
= genericize_compound_lvalue (*op
);
1853 op
= &TREE_OPERAND (*op
, 1);
1859 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1860 oconstraints
[i
] = constraint
;
1862 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1863 &allows_mem
, &allows_reg
, &is_inout
))
1865 /* If the operand is going to end up in memory,
1866 mark it addressable. */
1867 if (!allows_reg
&& !cxx_mark_addressable (*op
))
1868 operand
= error_mark_node
;
1871 operand
= error_mark_node
;
1873 TREE_VALUE (t
) = operand
;
1876 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1878 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1879 bool constraint_parsed
1880 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1881 oconstraints
, &allows_mem
, &allows_reg
);
1882 /* If the operand is going to end up in memory, don't call
1883 decay_conversion. */
1884 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1885 operand
= mark_lvalue_use (TREE_VALUE (t
));
1887 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1889 /* If the type of the operand hasn't been determined (e.g.,
1890 because it involves an overloaded function), then issue
1891 an error message. There's no context available to
1892 resolve the overloading. */
1893 if (TREE_TYPE (operand
) == unknown_type_node
)
1896 "type of %<asm%> operand %qE could not be determined",
1898 operand
= error_mark_node
;
1901 if (constraint_parsed
)
1903 /* If the operand is going to end up in memory,
1904 mark it addressable. */
1905 if (!allows_reg
&& allows_mem
)
1907 /* Strip the nops as we allow this case. FIXME, this really
1908 should be rejected or made deprecated. */
1909 STRIP_NOPS (operand
);
1911 tree
*op
= &operand
;
1912 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1913 op
= &TREE_OPERAND (*op
, 1);
1914 switch (TREE_CODE (*op
))
1916 case PREINCREMENT_EXPR
:
1917 case PREDECREMENT_EXPR
:
1919 *op
= genericize_compound_lvalue (*op
);
1920 op
= &TREE_OPERAND (*op
, 1);
1926 if (!cxx_mark_addressable (*op
))
1927 operand
= error_mark_node
;
1929 else if (!allows_reg
&& !allows_mem
)
1931 /* If constraint allows neither register nor memory,
1932 try harder to get a constant. */
1933 tree constop
= maybe_constant_value (operand
);
1934 if (TREE_CONSTANT (constop
))
1939 operand
= error_mark_node
;
1941 TREE_VALUE (t
) = operand
;
1945 r
= build_stmt (loc
, ASM_EXPR
, string
,
1946 output_operands
, input_operands
,
1948 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1949 ASM_INLINE_P (r
) = inline_p
;
1950 r
= maybe_cleanup_point_expr_void (r
);
1951 return add_stmt (r
);
1954 /* Finish a label with the indicated NAME. Returns the new label. */
1957 finish_label_stmt (tree name
)
1959 tree decl
= define_label (input_location
, name
);
1961 if (decl
== error_mark_node
)
1962 return error_mark_node
;
1964 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1969 /* Finish a series of declarations for local labels. G++ allows users
1970 to declare "local" labels, i.e., labels with scope. This extension
1971 is useful when writing code involving statement-expressions. */
1974 finish_label_decl (tree name
)
1976 if (!at_function_scope_p ())
1978 error ("%<__label__%> declarations are only allowed in function scopes");
1982 add_decl_expr (declare_local_label (name
));
1985 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1988 finish_decl_cleanup (tree decl
, tree cleanup
)
1990 push_cleanup (decl
, cleanup
, false);
1993 /* If the current scope exits with an exception, run CLEANUP. */
1996 finish_eh_cleanup (tree cleanup
)
1998 push_cleanup (NULL
, cleanup
, true);
2001 /* The MEM_INITS is a list of mem-initializers, in reverse of the
2002 order they were written by the user. Each node is as for
2003 emit_mem_initializers. */
2006 finish_mem_initializers (tree mem_inits
)
2008 /* Reorder the MEM_INITS so that they are in the order they appeared
2009 in the source program. */
2010 mem_inits
= nreverse (mem_inits
);
2012 if (processing_template_decl
)
2016 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
2018 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
2019 check for bare parameter packs in the TREE_VALUE, because
2020 any parameter packs in the TREE_VALUE have already been
2021 bound as part of the TREE_PURPOSE. See
2022 make_pack_expansion for more information. */
2023 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
2024 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
2025 TREE_VALUE (mem
) = error_mark_node
;
2028 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
2029 CTOR_INITIALIZER
, mem_inits
));
2032 emit_mem_initializers (mem_inits
);
2035 /* Obfuscate EXPR if it looks like an id-expression or member access so
2036 that the call to finish_decltype in do_auto_deduction will give the
2037 right result. If EVEN_UNEVAL, do this even in unevaluated context. */
2040 force_paren_expr (tree expr
, bool even_uneval
)
2042 /* This is only needed for decltype(auto) in C++14. */
2043 if (cxx_dialect
< cxx14
)
2046 /* If we're in unevaluated context, we can't be deducing a
2047 return/initializer type, so we don't need to mess with this. */
2048 if (cp_unevaluated_operand
&& !even_uneval
)
2051 if (TREE_CODE (expr
) == COMPONENT_REF
2052 || TREE_CODE (expr
) == SCOPE_REF
2053 || REFERENCE_REF_P (expr
))
2054 REF_PARENTHESIZED_P (expr
) = true;
2055 else if (DECL_P (tree_strip_any_location_wrapper (expr
)))
2057 location_t loc
= cp_expr_location (expr
);
2058 const tree_code code
= processing_template_decl
? PAREN_EXPR
2059 : VIEW_CONVERT_EXPR
;
2060 expr
= build1_loc (loc
, code
, TREE_TYPE (expr
), expr
);
2061 REF_PARENTHESIZED_P (expr
) = true;
2066 /* If T is an id-expression obfuscated by force_paren_expr, undo the
2067 obfuscation and return the underlying id-expression. Otherwise
2071 maybe_undo_parenthesized_ref (tree t
)
2073 if (cxx_dialect
< cxx14
)
2076 if ((TREE_CODE (t
) == PAREN_EXPR
|| TREE_CODE (t
) == VIEW_CONVERT_EXPR
)
2077 && REF_PARENTHESIZED_P (t
))
2078 t
= TREE_OPERAND (t
, 0);
2083 /* Finish a parenthesized expression EXPR. */
2086 finish_parenthesized_expr (cp_expr expr
)
2089 /* This inhibits warnings in c_common_truthvalue_conversion. */
2090 suppress_warning (expr
, OPT_Wparentheses
);
2092 if (TREE_CODE (expr
) == OFFSET_REF
2093 || TREE_CODE (expr
) == SCOPE_REF
)
2094 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
2095 enclosed in parentheses. */
2096 PTRMEM_OK_P (expr
) = 0;
2098 tree stripped_expr
= tree_strip_any_location_wrapper (expr
);
2099 if (TREE_CODE (stripped_expr
) == STRING_CST
)
2100 PAREN_STRING_LITERAL_P (stripped_expr
) = 1;
2102 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
2107 /* Finish a reference to a non-static data member (DECL) that is not
2108 preceded by `.' or `->'. */
2111 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
2113 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
2114 bool try_omp_private
= !object
&& omp_private_member_map
;
2119 tree scope
= qualifying_scope
;
2120 if (scope
== NULL_TREE
)
2122 scope
= context_for_name_lookup (decl
);
2123 if (!TYPE_P (scope
))
2125 /* Can happen during error recovery (c++/85014). */
2126 gcc_assert (seen_error ());
2127 return error_mark_node
;
2130 object
= maybe_dummy_object (scope
, NULL
);
2133 object
= maybe_resolve_dummy (object
, true);
2134 if (object
== error_mark_node
)
2135 return error_mark_node
;
2137 /* DR 613/850: Can use non-static data members without an associated
2138 object in sizeof/decltype/alignof. */
2139 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
2140 && (!processing_template_decl
|| !current_class_ref
))
2142 if (current_function_decl
2143 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2144 error ("invalid use of member %qD in static member function", decl
);
2146 error ("invalid use of non-static data member %qD", decl
);
2147 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
2149 return error_mark_node
;
2152 if (current_class_ptr
)
2153 TREE_USED (current_class_ptr
) = 1;
2154 if (processing_template_decl
)
2156 tree type
= TREE_TYPE (decl
);
2158 if (TYPE_REF_P (type
))
2159 /* Quals on the object don't matter. */;
2160 else if (PACK_EXPANSION_P (type
))
2161 /* Don't bother trying to represent this. */
2165 /* Set the cv qualifiers. */
2166 int quals
= cp_type_quals (TREE_TYPE (object
));
2168 if (DECL_MUTABLE_P (decl
))
2169 quals
&= ~TYPE_QUAL_CONST
;
2171 quals
|= cp_type_quals (TREE_TYPE (decl
));
2172 type
= cp_build_qualified_type (type
, quals
);
2175 if (qualifying_scope
)
2176 /* Wrap this in a SCOPE_REF for now. */
2177 ret
= build_qualified_name (type
, qualifying_scope
, decl
,
2178 /*template_p=*/false);
2180 ret
= (convert_from_reference
2181 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
2183 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2184 QUALIFYING_SCOPE is also non-null. */
2187 tree access_type
= TREE_TYPE (object
);
2189 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
2190 decl
, tf_warning_or_error
);
2192 /* If the data member was named `C::M', convert `*this' to `C'
2194 if (qualifying_scope
)
2196 tree binfo
= NULL_TREE
;
2197 object
= build_scoped_ref (object
, qualifying_scope
,
2201 ret
= build_class_member_access_expr (object
, decl
,
2202 /*access_path=*/NULL_TREE
,
2203 /*preserve_reference=*/false,
2204 tf_warning_or_error
);
2206 if (try_omp_private
)
2208 tree
*v
= omp_private_member_map
->get (decl
);
2210 ret
= convert_from_reference (*v
);
2215 /* DECL was the declaration to which a qualified-id resolved. Issue
2216 an error message if it is not accessible. If OBJECT_TYPE is
2217 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2218 type of `*x', or `x', respectively. If the DECL was named as
2219 `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2220 perform_access_checks above. */
2223 check_accessibility_of_qualified_id (tree decl
,
2225 tree nested_name_specifier
,
2226 tsubst_flags_t complain
)
2228 /* If we're not checking, return immediately. */
2229 if (deferred_access_no_check
)
2232 /* Determine the SCOPE of DECL. */
2233 tree scope
= context_for_name_lookup (decl
);
2234 /* If the SCOPE is not a type, then DECL is not a member. */
2236 /* If SCOPE is dependent then we can't perform this access check now,
2237 and since we'll perform this access check again after substitution
2238 there's no need to explicitly defer it. */
2239 || dependent_type_p (scope
))
2242 tree qualifying_type
= NULL_TREE
;
2243 /* Compute the scope through which DECL is being accessed. */
2245 /* OBJECT_TYPE might not be a class type; consider:
2247 class A { typedef int I; };
2251 In this case, we will have "A::I" as the DECL, but "I" as the
2253 && CLASS_TYPE_P (object_type
)
2254 && DERIVED_FROM_P (scope
, object_type
))
2255 /* If we are processing a `->' or `.' expression, use the type of the
2257 qualifying_type
= object_type
;
2258 else if (nested_name_specifier
)
2260 /* If the reference is to a non-static member of the
2261 current class, treat it as if it were referenced through
2263 if (DECL_NONSTATIC_MEMBER_P (decl
)
2264 && current_class_ptr
)
2265 if (tree current
= current_nonlambda_class_type ())
2267 if (dependent_type_p (current
))
2268 /* In general we can't know whether this access goes through
2269 `this' until instantiation time. Punt now, or else we might
2270 create a deferred access check that's not relative to `this'
2271 when it ought to be. We'll check this access again after
2272 substitution, e.g. from tsubst_qualified_id. */
2275 if (DERIVED_FROM_P (scope
, current
))
2276 qualifying_type
= current
;
2278 /* Otherwise, use the type indicated by the
2279 nested-name-specifier. */
2280 if (!qualifying_type
)
2281 qualifying_type
= nested_name_specifier
;
2284 /* Otherwise, the name must be from the current class or one of
2286 qualifying_type
= currently_open_derived_class (scope
);
2289 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2290 or similar in a default argument value. */
2291 && CLASS_TYPE_P (qualifying_type
))
2292 return perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
2298 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2299 class named to the left of the "::" operator. DONE is true if this
2300 expression is a complete postfix-expression; it is false if this
2301 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2302 iff this expression is the operand of '&'. TEMPLATE_P is true iff
2303 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2304 is true iff this qualified name appears as a template argument. */
2307 finish_qualified_id_expr (tree qualifying_class
,
2312 bool template_arg_p
,
2313 tsubst_flags_t complain
)
2315 gcc_assert (TYPE_P (qualifying_class
));
2317 if (error_operand_p (expr
))
2318 return error_mark_node
;
2320 if ((DECL_P (expr
) || BASELINK_P (expr
))
2321 && !mark_used (expr
, complain
))
2322 return error_mark_node
;
2326 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
2328 /* cp_parser_lookup_name thought we were looking for a type,
2329 but we're actually looking for a declaration. */
2330 qualifying_class
= TYPE_CONTEXT (expr
);
2331 expr
= TYPE_IDENTIFIER (expr
);
2334 check_template_keyword (expr
);
2337 /* If EXPR occurs as the operand of '&', use special handling that
2338 permits a pointer-to-member. */
2339 if (address_p
&& done
)
2341 if (TREE_CODE (expr
) == SCOPE_REF
)
2342 expr
= TREE_OPERAND (expr
, 1);
2343 expr
= build_offset_ref (qualifying_class
, expr
,
2344 /*address_p=*/true, complain
);
2348 /* No need to check access within an enum. */
2349 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
2350 && TREE_CODE (expr
) != IDENTIFIER_NODE
)
2353 /* Within the scope of a class, turn references to non-static
2354 members into expression of the form "this->...". */
2356 /* But, within a template argument, we do not want make the
2357 transformation, as there is no "this" pointer. */
2359 else if (TREE_CODE (expr
) == FIELD_DECL
)
2361 push_deferring_access_checks (dk_no_check
);
2362 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2364 pop_deferring_access_checks ();
2366 else if (BASELINK_P (expr
))
2368 /* See if any of the functions are non-static members. */
2369 /* If so, the expression may be relative to 'this'. */
2370 if (!shared_member_p (expr
)
2371 && current_class_ptr
2372 && DERIVED_FROM_P (qualifying_class
,
2373 current_nonlambda_class_type ()))
2374 expr
= (build_class_member_access_expr
2375 (maybe_dummy_object (qualifying_class
, NULL
),
2377 BASELINK_ACCESS_BINFO (expr
),
2378 /*preserve_reference=*/false,
2381 /* The expression is a qualified name whose address is not
2383 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2386 else if (!template_p
2387 && TREE_CODE (expr
) == TEMPLATE_DECL
2388 && !DECL_FUNCTION_TEMPLATE_P (expr
))
2390 if (complain
& tf_error
)
2391 error ("%qE missing template arguments", expr
);
2392 return error_mark_node
;
2396 /* In a template, return a SCOPE_REF for most qualified-ids
2397 so that we can check access at instantiation time. But if
2398 we're looking at a member of the current instantiation, we
2399 know we have access and building up the SCOPE_REF confuses
2400 non-type template argument handling. */
2401 if (processing_template_decl
2402 && (!currently_open_class (qualifying_class
)
2403 || TREE_CODE (expr
) == IDENTIFIER_NODE
2404 || TREE_CODE (expr
) == TEMPLATE_ID_EXPR
2405 || TREE_CODE (expr
) == BIT_NOT_EXPR
))
2406 expr
= build_qualified_name (TREE_TYPE (expr
),
2407 qualifying_class
, expr
,
2409 else if (tree wrap
= maybe_get_tls_wrapper_call (expr
))
2412 expr
= convert_from_reference (expr
);
2418 /* Begin a statement-expression. The value returned must be passed to
2419 finish_stmt_expr. */
2422 begin_stmt_expr (void)
2424 return push_stmt_list ();
2427 /* Process the final expression of a statement expression. EXPR can be
2428 NULL, if the final expression is empty. Return a STATEMENT_LIST
2429 containing all the statements in the statement-expression, or
2430 ERROR_MARK_NODE if there was an error. */
2433 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2435 if (error_operand_p (expr
))
2437 /* The type of the statement-expression is the type of the last
2439 TREE_TYPE (stmt_expr
) = error_mark_node
;
2440 return error_mark_node
;
2443 /* If the last statement does not have "void" type, then the value
2444 of the last statement is the value of the entire expression. */
2447 tree type
= TREE_TYPE (expr
);
2449 if (type
&& type_unknown_p (type
))
2451 error ("a statement expression is an insufficient context"
2452 " for overload resolution");
2453 TREE_TYPE (stmt_expr
) = error_mark_node
;
2454 return error_mark_node
;
2456 else if (processing_template_decl
)
2458 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2459 expr
= add_stmt (expr
);
2460 /* Mark the last statement so that we can recognize it as such at
2461 template-instantiation time. */
2462 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2464 else if (VOID_TYPE_P (type
))
2466 /* Just treat this like an ordinary statement. */
2467 expr
= finish_expr_stmt (expr
);
2471 /* It actually has a value we need to deal with. First, force it
2472 to be an rvalue so that we won't need to build up a copy
2473 constructor call later when we try to assign it to something. */
2474 expr
= force_rvalue (expr
, tf_warning_or_error
);
2475 if (error_operand_p (expr
))
2476 return error_mark_node
;
2478 /* Update for array-to-pointer decay. */
2479 type
= TREE_TYPE (expr
);
2481 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2482 normal statement, but don't convert to void or actually add
2484 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2485 expr
= maybe_cleanup_point_expr (expr
);
2489 /* The type of the statement-expression is the type of the last
2491 TREE_TYPE (stmt_expr
) = type
;
2497 /* Finish a statement-expression. EXPR should be the value returned
2498 by the previous begin_stmt_expr. Returns an expression
2499 representing the statement-expression. */
2502 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2507 if (error_operand_p (stmt_expr
))
2509 pop_stmt_list (stmt_expr
);
2510 return error_mark_node
;
2513 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2515 type
= TREE_TYPE (stmt_expr
);
2516 result
= pop_stmt_list (stmt_expr
);
2517 TREE_TYPE (result
) = type
;
2519 if (processing_template_decl
)
2521 result
= build_min (STMT_EXPR
, type
, result
);
2522 TREE_SIDE_EFFECTS (result
) = 1;
2523 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2525 else if (CLASS_TYPE_P (type
))
2527 /* Wrap the statement-expression in a TARGET_EXPR so that the
2528 temporary object created by the final expression is destroyed at
2529 the end of the full-expression containing the
2530 statement-expression. */
2531 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2537 /* Returns the expression which provides the value of STMT_EXPR. */
2540 stmt_expr_value_expr (tree stmt_expr
)
2542 tree t
= STMT_EXPR_STMT (stmt_expr
);
2544 if (TREE_CODE (t
) == BIND_EXPR
)
2545 t
= BIND_EXPR_BODY (t
);
2547 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2548 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2550 if (TREE_CODE (t
) == EXPR_STMT
)
2551 t
= EXPR_STMT_EXPR (t
);
2556 /* Return TRUE iff EXPR_STMT is an empty list of
2557 expression statements. */
2560 empty_expr_stmt_p (tree expr_stmt
)
2562 tree body
= NULL_TREE
;
2564 if (expr_stmt
== void_node
)
2569 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2570 body
= EXPR_STMT_EXPR (expr_stmt
);
2571 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2577 if (TREE_CODE (body
) == STATEMENT_LIST
)
2578 return tsi_end_p (tsi_start (body
));
2580 return empty_expr_stmt_p (body
);
2585 /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
2586 the function (or functions) to call; ARGS are the arguments to the
2587 call. Returns the functions to be considered by overload resolution. */
2590 perform_koenig_lookup (cp_expr fn_expr
, vec
<tree
, va_gc
> *args
,
2591 tsubst_flags_t complain
)
2593 tree identifier
= NULL_TREE
;
2594 tree functions
= NULL_TREE
;
2595 tree tmpl_args
= NULL_TREE
;
2596 bool template_id
= false;
2597 location_t loc
= fn_expr
.get_location ();
2598 tree fn
= fn_expr
.get_value ();
2600 STRIP_ANY_LOCATION_WRAPPER (fn
);
2602 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2604 /* Use a separate flag to handle null args. */
2606 tmpl_args
= TREE_OPERAND (fn
, 1);
2607 fn
= TREE_OPERAND (fn
, 0);
2610 /* Find the name of the overloaded function. */
2611 if (identifier_p (fn
))
2616 identifier
= OVL_NAME (functions
);
2619 /* A call to a namespace-scope function using an unqualified name.
2621 Do Koenig lookup -- unless any of the arguments are
2623 if (!any_type_dependent_arguments_p (args
)
2624 && !any_dependent_template_arguments_p (tmpl_args
))
2626 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2629 /* The unqualified name could not be resolved. */
2630 if (complain
& tf_error
)
2631 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2637 if (fn
&& template_id
&& fn
!= error_mark_node
)
2638 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2640 return cp_expr (fn
, loc
);
2643 /* Generate an expression for `FN (ARGS)'. This may change the
2646 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2647 as a virtual call, even if FN is virtual. (This flag is set when
2648 encountering an expression where the function name is explicitly
2649 qualified. For example a call to `X::f' never generates a virtual
2652 Returns code for the call. */
2655 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2656 bool koenig_p
, tsubst_flags_t complain
)
2660 vec
<tree
, va_gc
> *orig_args
= *args
;
2662 if (fn
== error_mark_node
)
2663 return error_mark_node
;
2665 gcc_assert (!TYPE_P (fn
));
2667 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2668 it so that we can tell this is a call to a known function. */
2669 fn
= maybe_undo_parenthesized_ref (fn
);
2671 STRIP_ANY_LOCATION_WRAPPER (fn
);
2675 if (processing_template_decl
)
2677 /* If FN is a local extern declaration or set thereof, look them up
2678 again at instantiation time. */
2679 if (is_overloaded_fn (fn
))
2681 tree ifn
= get_first_fn (fn
);
2682 if (TREE_CODE (ifn
) == FUNCTION_DECL
2683 && DECL_LOCAL_DECL_P (ifn
))
2684 orig_fn
= DECL_NAME (ifn
);
2687 /* If the call expression is dependent, build a CALL_EXPR node
2688 with no type; type_dependent_expression_p recognizes
2689 expressions with no type as being dependent. */
2690 if (type_dependent_expression_p (fn
)
2691 || any_type_dependent_arguments_p (*args
))
2693 result
= build_min_nt_call_vec (orig_fn
, *args
);
2694 SET_EXPR_LOCATION (result
, cp_expr_loc_or_input_loc (fn
));
2695 KOENIG_LOOKUP_P (result
) = koenig_p
;
2696 if (is_overloaded_fn (fn
))
2701 bool abnormal
= true;
2702 for (lkp_iterator
iter (fn
); abnormal
&& iter
; ++iter
)
2704 tree fndecl
= STRIP_TEMPLATE (*iter
);
2705 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2706 || !TREE_THIS_VOLATILE (fndecl
))
2709 /* FIXME: Stop warning about falling off end of non-void
2710 function. But this is wrong. Even if we only see
2711 no-return fns at this point, we could select a
2712 future-defined return fn during instantiation. Or
2715 current_function_returns_abnormally
= 1;
2719 orig_args
= make_tree_vector_copy (*args
);
2720 if (!BASELINK_P (fn
)
2721 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2722 && TREE_TYPE (fn
) != unknown_type_node
)
2723 fn
= build_non_dependent_expr (fn
);
2724 make_args_non_dependent (*args
);
2727 if (TREE_CODE (fn
) == COMPONENT_REF
)
2729 tree member
= TREE_OPERAND (fn
, 1);
2730 if (BASELINK_P (member
))
2732 tree object
= TREE_OPERAND (fn
, 0);
2733 return build_new_method_call (object
, member
,
2736 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2743 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2744 if (TREE_CODE (fn
) == ADDR_EXPR
2745 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2746 fn
= TREE_OPERAND (fn
, 0);
2748 if (is_overloaded_fn (fn
))
2749 fn
= baselink_for_fns (fn
);
2752 if (BASELINK_P (fn
))
2756 /* A call to a member function. From [over.call.func]:
2758 If the keyword this is in scope and refers to the class of
2759 that member function, or a derived class thereof, then the
2760 function call is transformed into a qualified function call
2761 using (*this) as the postfix-expression to the left of the
2762 . operator.... [Otherwise] a contrived object of type T
2763 becomes the implied object argument.
2767 struct A { void f(); };
2768 struct B : public A {};
2769 struct C : public A { void g() { B::f(); }};
2771 "the class of that member function" refers to `A'. But 11.2
2772 [class.access.base] says that we need to convert 'this' to B* as
2773 part of the access, so we pass 'B' to maybe_dummy_object. */
2775 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2777 /* A constructor call always uses a dummy object. (This constructor
2778 call which has the form A::A () is actually invalid and we are
2779 going to reject it later in build_new_method_call.) */
2780 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2783 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2786 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2788 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2793 else if (concept_check_p (fn
))
2795 /* FN is actually a template-id referring to a concept definition. */
2796 tree id
= unpack_concept_check (fn
);
2797 tree tmpl
= TREE_OPERAND (id
, 0);
2798 tree args
= TREE_OPERAND (id
, 1);
2800 if (!function_concept_p (tmpl
))
2802 error_at (EXPR_LOC_OR_LOC (fn
, input_location
),
2803 "cannot call a concept as a function");
2804 return error_mark_node
;
2807 /* Ensure the result is wrapped as a call expression. */
2808 result
= build_concept_check (tmpl
, args
, tf_warning_or_error
);
2810 else if (is_overloaded_fn (fn
))
2812 /* If the function is an overloaded builtin, resolve it. */
2813 if (TREE_CODE (fn
) == FUNCTION_DECL
2814 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2815 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2816 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2820 if (warn_sizeof_pointer_memaccess
2821 && (complain
& tf_warning
)
2822 && !vec_safe_is_empty (*args
)
2823 && !processing_template_decl
)
2825 location_t sizeof_arg_loc
[3];
2828 for (i
= 0; i
< 3; i
++)
2832 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2833 sizeof_arg
[i
] = NULL_TREE
;
2834 if (i
>= (*args
)->length ())
2837 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2839 if (SIZEOF_EXPR_TYPE_P (t
))
2840 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2842 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2843 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2845 sizeof_pointer_memaccess_warning
2846 (sizeof_arg_loc
, fn
, *args
,
2847 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2850 if ((complain
& tf_warning
)
2851 && TREE_CODE (fn
) == FUNCTION_DECL
2852 && fndecl_built_in_p (fn
, BUILT_IN_MEMSET
)
2853 && vec_safe_length (*args
) == 3
2854 && !any_type_dependent_arguments_p (*args
))
2856 tree arg0
= (*orig_args
)[0];
2857 tree arg1
= (*orig_args
)[1];
2858 tree arg2
= (*orig_args
)[2];
2859 int literal_mask
= ((literal_integer_zerop (arg1
) << 1)
2860 | (literal_integer_zerop (arg2
) << 2));
2861 warn_for_memset (input_location
, arg0
, arg2
, literal_mask
);
2864 /* A call to a namespace-scope function. */
2865 result
= build_new_function_call (fn
, args
, complain
);
2868 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2870 if (!vec_safe_is_empty (*args
))
2871 error ("arguments to destructor are not allowed");
2872 /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
2873 which case the postfix-expression is a possibly-parenthesized class
2874 member access), the function call destroys the object of scalar type
2875 denoted by the object expression of the class member access. */
2876 tree ob
= TREE_OPERAND (fn
, 0);
2878 result
= build_trivial_dtor_call (ob
, true);
2880 /* No location to clobber. */
2881 result
= convert_to_void (ob
, ICV_STATEMENT
, complain
);
2883 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2884 /* If the "function" is really an object of class type, it might
2885 have an overloaded `operator ()'. */
2886 result
= build_op_call (fn
, args
, complain
);
2889 /* A call where the function is unknown. */
2890 result
= cp_build_function_call_vec (fn
, args
, complain
);
2892 if (processing_template_decl
&& result
!= error_mark_node
)
2894 if (INDIRECT_REF_P (result
))
2895 result
= TREE_OPERAND (result
, 0);
2897 /* Prune all but the selected function from the original overload
2898 set so that we can avoid some duplicate work at instantiation time. */
2899 if (TREE_CODE (result
) == CALL_EXPR
2900 && really_overloaded_fn (orig_fn
))
2902 orig_fn
= CALL_EXPR_FN (result
);
2903 if (TREE_CODE (orig_fn
) == COMPONENT_REF
)
2905 /* The non-dependent result of build_new_method_call. */
2906 orig_fn
= TREE_OPERAND (orig_fn
, 1);
2907 gcc_assert (BASELINK_P (orig_fn
));
2911 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2912 SET_EXPR_LOCATION (result
, input_location
);
2913 KOENIG_LOOKUP_P (result
) = koenig_p
;
2914 release_tree_vector (orig_args
);
2915 result
= convert_from_reference (result
);
2921 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2922 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2923 POSTDECREMENT_EXPR.) */
2926 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2928 /* input_location holds the location of the trailing operator token.
2929 Build a location of the form:
2932 with the caret at the operator token, ranging from the start
2933 of EXPR to the end of the operator token. */
2934 location_t combined_loc
= make_location (input_location
,
2936 get_finish (input_location
));
2937 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2938 NULL_TREE
, tf_warning_or_error
);
2939 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2940 result
.set_location (combined_loc
);
2944 /* Finish a use of `this'. Returns an expression for `this'. */
2947 finish_this_expr (void)
2949 tree result
= NULL_TREE
;
2951 if (current_class_ptr
)
2953 tree type
= TREE_TYPE (current_class_ref
);
2955 /* In a lambda expression, 'this' refers to the captured 'this'. */
2956 if (LAMBDA_TYPE_P (type
))
2957 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2959 result
= current_class_ptr
;
2963 /* The keyword 'this' is a prvalue expression. */
2964 return rvalue (result
);
2966 tree fn
= current_nonlambda_function ();
2967 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2968 error ("%<this%> is unavailable for static member functions");
2970 error ("invalid use of %<this%> in non-member function");
2972 error ("invalid use of %<this%> at top level");
2973 return error_mark_node
;
2976 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2977 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2978 the TYPE for the type given. If SCOPE is non-NULL, the expression
2979 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2982 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2985 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2986 return error_mark_node
;
2988 gcc_assert (TYPE_P (destructor
));
2990 if (!processing_template_decl
)
2992 if (scope
== error_mark_node
)
2994 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2995 return error_mark_node
;
2997 if (is_auto (destructor
))
2998 destructor
= TREE_TYPE (object
);
2999 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
3002 "qualified type %qT does not match destructor name ~%qT",
3004 return error_mark_node
;
3008 /* [expr.pseudo] says both:
3010 The type designated by the pseudo-destructor-name shall be
3011 the same as the object type.
3015 The cv-unqualified versions of the object type and of the
3016 type designated by the pseudo-destructor-name shall be the
3019 We implement the more generous second sentence, since that is
3020 what most other compilers do. */
3021 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
3024 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
3025 return error_mark_node
;
3029 tree type
= (type_dependent_expression_p (object
)
3030 ? NULL_TREE
: void_type_node
);
3032 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, type
, object
,
3036 /* Finish an expression of the form CODE EXPR. */
3039 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
3040 tsubst_flags_t complain
)
3042 /* Build a location of the form:
3045 with the caret at the operator token, ranging from the start
3046 of the operator token to the end of EXPR. */
3047 location_t combined_loc
= make_location (op_loc
,
3048 op_loc
, expr
.get_finish ());
3049 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
3050 NULL_TREE
, complain
);
3051 /* TODO: build_x_unary_op doesn't always honor the location. */
3052 result
.set_location (combined_loc
);
3054 if (result
== error_mark_node
)
3057 if (!(complain
& tf_warning
))
3060 tree result_ovl
= result
;
3061 tree expr_ovl
= expr
;
3063 if (!processing_template_decl
)
3064 expr_ovl
= cp_fully_fold (expr_ovl
);
3066 if (!CONSTANT_CLASS_P (expr_ovl
)
3067 || TREE_OVERFLOW_P (expr_ovl
))
3070 if (!processing_template_decl
)
3071 result_ovl
= cp_fully_fold (result_ovl
);
3073 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
3074 overflow_warning (combined_loc
, result_ovl
);
3079 /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3083 maybe_zero_constructor_nelts (tree expr
)
3085 if (CONSTRUCTOR_NELTS (expr
) == 0)
3087 if (!processing_template_decl
)
3089 for (constructor_elt
&elt
: CONSTRUCTOR_ELTS (expr
))
3090 if (!PACK_EXPANSION_P (elt
.value
))
3095 /* Finish a compound-literal expression or C++11 functional cast with aggregate
3096 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3100 finish_compound_literal (tree type
, tree compound_literal
,
3101 tsubst_flags_t complain
,
3104 if (type
== error_mark_node
)
3105 return error_mark_node
;
3107 if (TYPE_REF_P (type
))
3110 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
3111 complain
, fcl_context
);
3112 /* The prvalue is then used to direct-initialize the reference. */
3113 tree r
= (perform_implicit_conversion_flags
3114 (type
, compound_literal
, complain
, LOOKUP_NORMAL
));
3115 return convert_from_reference (r
);
3118 if (!TYPE_OBJ_P (type
))
3121 if (VOID_TYPE_P (type
) && CONSTRUCTOR_NELTS (compound_literal
) == 0)
3123 else if (VOID_TYPE_P (type
)
3124 && processing_template_decl
3125 && maybe_zero_constructor_nelts (compound_literal
))
3126 /* If there are only packs in compound_literal, it could
3127 be void{} after pack expansion. */;
3130 if (complain
& tf_error
)
3131 error ("compound literal of non-object type %qT", type
);
3132 return error_mark_node
;
3136 if (template_placeholder_p (type
))
3138 type
= do_auto_deduction (type
, compound_literal
, type
, complain
,
3140 if (type
== error_mark_node
)
3141 return error_mark_node
;
3143 /* C++23 auto{x}. */
3144 else if (is_auto (type
)
3145 && !AUTO_IS_DECLTYPE (type
)
3146 && CONSTRUCTOR_NELTS (compound_literal
) == 1)
3148 if (cxx_dialect
< cxx23
)
3149 pedwarn (input_location
, OPT_Wc__23_extensions
,
3150 "%<auto{x}%> only available with "
3151 "%<-std=c++2b%> or %<-std=gnu++2b%>");
3152 type
= do_auto_deduction (type
, compound_literal
, type
, complain
,
3154 if (type
== error_mark_node
)
3155 return error_mark_node
;
3158 /* Used to hold a copy of the compound literal in a template. */
3159 tree orig_cl
= NULL_TREE
;
3161 if (processing_template_decl
)
3163 const bool dependent_p
3164 = (instantiation_dependent_expression_p (compound_literal
)
3165 || dependent_type_p (type
));
3167 /* We're about to return, no need to copy. */
3168 orig_cl
= compound_literal
;
3170 /* We're going to need a copy. */
3171 orig_cl
= unshare_constructor (compound_literal
);
3172 TREE_TYPE (orig_cl
) = type
;
3173 /* Mark the expression as a compound literal. */
3174 TREE_HAS_CONSTRUCTOR (orig_cl
) = 1;
3175 /* And as instantiation-dependent. */
3176 CONSTRUCTOR_IS_DEPENDENT (orig_cl
) = dependent_p
;
3177 if (fcl_context
== fcl_c99
)
3178 CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl
) = 1;
3179 /* If the compound literal is dependent, we're done for now. */
3182 /* Otherwise, do go on to e.g. check narrowing. */
3185 type
= complete_type (type
);
3187 if (TYPE_NON_AGGREGATE_CLASS (type
))
3189 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3190 everywhere that deals with function arguments would be a pain, so
3191 just wrap it in a TREE_LIST. The parser set a flag so we know
3192 that it came from T{} rather than T({}). */
3193 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
3194 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
3195 return build_functional_cast (input_location
, type
,
3196 compound_literal
, complain
);
3199 if (TREE_CODE (type
) == ARRAY_TYPE
3200 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
3201 return error_mark_node
;
3202 compound_literal
= reshape_init (type
, compound_literal
, complain
);
3203 if (SCALAR_TYPE_P (type
)
3204 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
))
3206 tree t
= instantiate_non_dependent_expr_sfinae (compound_literal
,
3208 if (!check_narrowing (type
, t
, complain
))
3209 return error_mark_node
;
3211 if (TREE_CODE (type
) == ARRAY_TYPE
3212 && TYPE_DOMAIN (type
) == NULL_TREE
)
3214 cp_complete_array_type_or_error (&type
, compound_literal
,
3216 if (type
== error_mark_node
)
3217 return error_mark_node
;
3219 compound_literal
= digest_init_flags (type
, compound_literal
,
3220 LOOKUP_NORMAL
| LOOKUP_NO_NARROWING
,
3222 if (compound_literal
== error_mark_node
)
3223 return error_mark_node
;
3225 /* If we're in a template, return the original compound literal. */
3229 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
3231 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
3232 if (fcl_context
== fcl_c99
)
3233 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
3236 /* Put static/constant array temporaries in static variables. */
3237 /* FIXME all C99 compound literals should be variables rather than C++
3238 temporaries, unless they are used as an aggregate initializer. */
3239 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
3240 && fcl_context
== fcl_c99
3241 && TREE_CODE (type
) == ARRAY_TYPE
3242 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
3243 && initializer_constant_valid_p (compound_literal
, type
))
3245 tree decl
= create_temporary_var (type
);
3246 DECL_CONTEXT (decl
) = NULL_TREE
;
3247 DECL_INITIAL (decl
) = compound_literal
;
3248 TREE_STATIC (decl
) = 1;
3249 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
3251 /* 5.19 says that a constant expression can include an
3252 lvalue-rvalue conversion applied to "a glvalue of literal type
3253 that refers to a non-volatile temporary object initialized
3254 with a constant expression". Rather than try to communicate
3255 that this VAR_DECL is a temporary, just mark it constexpr. */
3256 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
3257 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
3258 TREE_CONSTANT (decl
) = true;
3260 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
3261 decl
= pushdecl_top_level (decl
);
3262 DECL_NAME (decl
) = make_anon_name ();
3263 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
3264 /* Make sure the destructor is callable. */
3265 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
3266 if (clean
== error_mark_node
)
3267 return error_mark_node
;
3271 /* Represent other compound literals with TARGET_EXPR so we produce
3272 a prvalue, and can elide copies. */
3273 if (!VECTOR_TYPE_P (type
))
3275 /* The CONSTRUCTOR is now an initializer, not a compound literal. */
3276 TREE_HAS_CONSTRUCTOR (compound_literal
) = false;
3277 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
3280 return compound_literal
;
3283 /* Return the declaration for the function-name variable indicated by
3287 finish_fname (tree id
)
3291 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
3292 if (processing_template_decl
&& current_function_decl
3293 && decl
!= error_mark_node
)
3294 decl
= DECL_NAME (decl
);
3298 /* Finish a translation unit. */
3301 finish_translation_unit (void)
3303 /* In case there were missing closebraces,
3304 get us back to the global binding level. */
3306 while (current_namespace
!= global_namespace
)
3309 /* Do file scope __FUNCTION__ et al. */
3310 finish_fname_decls ();
3312 if (vec_safe_length (scope_chain
->omp_declare_target_attribute
))
3315 error ("%<#pragma omp declare target%> without corresponding "
3316 "%<#pragma omp end declare target%>");
3317 vec_safe_truncate (scope_chain
->omp_declare_target_attribute
, 0);
3321 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
3322 Returns the parameter. */
3325 finish_template_type_parm (tree aggr
, tree identifier
)
3327 if (aggr
!= class_type_node
)
3329 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
3330 aggr
= class_type_node
;
3333 return build_tree_list (aggr
, identifier
);
3336 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
3337 Returns the parameter. */
3340 finish_template_template_parm (tree aggr
, tree identifier
)
3342 tree decl
= build_decl (input_location
,
3343 TYPE_DECL
, identifier
, NULL_TREE
);
3345 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
3346 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
3347 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
3348 DECL_ARTIFICIAL (decl
) = 1;
3350 /* Associate the constraints with the underlying declaration,
3351 not the template. */
3352 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
3353 tree constr
= build_constraints (reqs
, NULL_TREE
);
3354 set_constraints (decl
, constr
);
3356 end_template_decl ();
3358 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
3360 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
3361 /*is_primary=*/true, /*is_partial=*/false,
3364 return finish_template_type_parm (aggr
, tmpl
);
3367 /* ARGUMENT is the default-argument value for a template template
3368 parameter. If ARGUMENT is invalid, issue error messages and return
3369 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
3372 check_template_template_default_arg (tree argument
)
3374 if (TREE_CODE (argument
) != TEMPLATE_DECL
3375 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
3376 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
3378 if (TREE_CODE (argument
) == TYPE_DECL
)
3379 error ("invalid use of type %qT as a default value for a template "
3380 "template-parameter", TREE_TYPE (argument
));
3382 error ("invalid default argument for a template template parameter");
3383 return error_mark_node
;
3389 /* Begin a class definition, as indicated by T. */
3392 begin_class_definition (tree t
)
3394 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
3395 return error_mark_node
;
3397 if (processing_template_parmlist
&& !LAMBDA_TYPE_P (t
))
3399 error ("definition of %q#T inside template parameter list", t
);
3400 return error_mark_node
;
3403 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
3404 are passed the same as decimal scalar types. */
3405 if (TREE_CODE (t
) == RECORD_TYPE
3406 && !processing_template_decl
)
3408 tree ns
= TYPE_CONTEXT (t
);
3409 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
3410 && DECL_CONTEXT (ns
) == std_node
3412 && id_equal (DECL_NAME (ns
), "decimal"))
3414 const char *n
= TYPE_NAME_STRING (t
);
3415 if ((strcmp (n
, "decimal32") == 0)
3416 || (strcmp (n
, "decimal64") == 0)
3417 || (strcmp (n
, "decimal128") == 0))
3418 TYPE_TRANSPARENT_AGGR (t
) = 1;
3422 /* A non-implicit typename comes from code like:
3424 template <typename T> struct A {
3425 template <typename U> struct A<T>::B ...
3427 This is erroneous. */
3428 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
3430 error ("invalid definition of qualified type %qT", t
);
3431 t
= error_mark_node
;
3434 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
3436 t
= make_class_type (RECORD_TYPE
);
3437 pushtag (make_anon_name (), t
);
3440 if (TYPE_BEING_DEFINED (t
))
3442 t
= make_class_type (TREE_CODE (t
));
3443 pushtag (TYPE_IDENTIFIER (t
), t
);
3448 if (!module_may_redeclare (TYPE_NAME (t
)))
3450 error ("cannot declare %qD in a different module", TYPE_NAME (t
));
3451 inform (DECL_SOURCE_LOCATION (TYPE_NAME (t
)), "declared here");
3452 return error_mark_node
;
3454 set_instantiating_module (TYPE_NAME (t
));
3455 set_defining_module (TYPE_NAME (t
));
3458 maybe_process_partial_specialization (t
);
3460 TYPE_BEING_DEFINED (t
) = 1;
3461 class_binding_level
->defining_class_p
= 1;
3463 if (flag_pack_struct
)
3466 TYPE_PACKED (t
) = 1;
3467 /* Even though the type is being defined for the first time
3468 here, there might have been a forward declaration, so there
3469 might be cv-qualified variants of T. */
3470 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
3471 TYPE_PACKED (v
) = 1;
3473 /* Reset the interface data, at the earliest possible
3474 moment, as it might have been set via a class foo;
3476 if (! TYPE_UNNAMED_P (t
))
3478 struct c_fileinfo
*finfo
= \
3479 get_fileinfo (LOCATION_FILE (input_location
));
3480 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
3481 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
3482 (t
, finfo
->interface_unknown
);
3484 reset_specialization ();
3486 /* Make a declaration for this class in its own scope. */
3487 build_self_reference ();
3492 /* Finish the member declaration given by DECL. */
3495 finish_member_declaration (tree decl
)
3497 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
3500 if (decl
== void_type_node
)
3501 /* The COMPONENT was a friend, not a member, and so there's
3502 nothing for us to do. */
3505 /* We should see only one DECL at a time. */
3506 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
3508 /* Don't add decls after definition. */
3509 gcc_assert (TYPE_BEING_DEFINED (current_class_type
)
3510 /* We can add lambda types when late parsing default
3512 || LAMBDA_TYPE_P (TREE_TYPE (decl
)));
3514 /* Set up access control for DECL. */
3516 = (current_access_specifier
== access_private_node
);
3517 TREE_PROTECTED (decl
)
3518 = (current_access_specifier
== access_protected_node
);
3519 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3521 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
3522 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
3525 /* Mark the DECL as a member of the current class, unless it's
3526 a member of an enumeration. */
3527 if (TREE_CODE (decl
) != CONST_DECL
)
3528 DECL_CONTEXT (decl
) = current_class_type
;
3530 /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */
3531 if (TREE_CODE (decl
) == FIELD_DECL
3532 && ANON_AGGR_TYPE_P (TREE_TYPE (decl
)))
3534 gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl
))));
3535 ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl
))) = decl
;
3538 if (TREE_CODE (decl
) == USING_DECL
)
3539 /* For now, ignore class-scope USING_DECLS, so that debugging
3540 backends do not see them. */
3541 DECL_IGNORED_P (decl
) = 1;
3543 /* Check for bare parameter packs in the non-static data member
3545 if (TREE_CODE (decl
) == FIELD_DECL
)
3547 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
3548 TREE_TYPE (decl
) = error_mark_node
;
3549 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3550 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3555 A C language linkage is ignored for the names of class members
3556 and the member function type of class member functions. */
3557 if (DECL_LANG_SPECIFIC (decl
))
3558 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3562 /* Functions and non-functions are added differently. */
3563 if (DECL_DECLARES_FUNCTION_P (decl
))
3564 add
= add_method (current_class_type
, decl
, false);
3565 /* Enter the DECL into the scope of the class, if the class
3566 isn't a closure (whose fields are supposed to be unnamed). */
3567 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3568 || pushdecl_class_level (decl
))
3573 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3574 go at the beginning. The reason is that
3575 legacy_nonfn_member_lookup searches the list in order, and we
3576 want a field name to override a type name so that the "struct
3577 stat hack" will work. In particular:
3579 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3583 if (TREE_CODE (decl
) == TYPE_DECL
)
3584 TYPE_FIELDS (current_class_type
)
3585 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3588 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3589 TYPE_FIELDS (current_class_type
) = decl
;
3592 maybe_add_class_template_decl_list (current_class_type
, decl
,
3597 /* Finish processing a complete template declaration. The PARMS are
3598 the template parameters. */
3601 finish_template_decl (tree parms
)
3604 end_template_decl ();
3606 end_specialization ();
3609 // Returns the template type of the class scope being entered. If we're
3610 // entering a constrained class scope. TYPE is the class template
3611 // scope being entered and we may need to match the intended type with
3612 // a constrained specialization. For example:
3614 // template<Object T>
3615 // struct S { void f(); }; #1
3617 // template<Object T>
3618 // void S<T>::f() { } #2
3620 // We check, in #2, that S<T> refers precisely to the type declared by
3621 // #1 (i.e., that the constraints match). Note that the following should
3622 // be an error since there is no specialization of S<T> that is
3623 // unconstrained, but this is not diagnosed here.
3625 // template<typename T>
3626 // void S<T>::f() { }
3628 // We cannot diagnose this problem here since this function also matches
3629 // qualified template names that are not part of a definition. For example:
3631 // template<Integral T, Floating_point U>
3632 // typename pair<T, U>::first_type void f(T, U);
3634 // Here, it is unlikely that there is a partial specialization of
3635 // pair constrained for for Integral and Floating_point arguments.
3637 // The general rule is: if a constrained specialization with matching
3638 // constraints is found return that type. Also note that if TYPE is not a
3639 // class-type (e.g. a typename type), then no fixup is needed.
3642 fixup_template_type (tree type
)
3644 // Find the template parameter list at the a depth appropriate to
3645 // the scope we're trying to enter.
3646 tree parms
= current_template_parms
;
3647 int depth
= template_class_depth (type
);
3648 for (int n
= current_template_depth
; n
> depth
&& parms
; --n
)
3649 parms
= TREE_CHAIN (parms
);
3652 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3653 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3655 // Search for a specialization whose type and constraints match.
3656 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3657 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3660 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3662 // If the type and constraints match a specialization, then we
3663 // are entering that type.
3664 if (same_type_p (type
, TREE_TYPE (specs
))
3665 && equivalent_constraints (cur_constr
, spec_constr
))
3666 return TREE_TYPE (specs
);
3667 specs
= TREE_CHAIN (specs
);
3670 // If no specialization matches, then must return the type
3671 // previously found.
3675 /* Finish processing a template-id (which names a type) of the form
3676 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3677 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3678 the scope of template-id indicated. */
3681 finish_template_type (tree name
, tree args
, int entering_scope
)
3685 type
= lookup_template_class (name
, args
,
3686 NULL_TREE
, NULL_TREE
, entering_scope
,
3687 tf_warning_or_error
| tf_user
);
3689 /* If we might be entering the scope of a partial specialization,
3690 find the one with the right constraints. */
3693 && CLASS_TYPE_P (type
)
3694 && CLASSTYPE_TEMPLATE_INFO (type
)
3695 && dependent_type_p (type
)
3696 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3697 type
= fixup_template_type (type
);
3699 if (type
== error_mark_node
)
3701 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3702 return TYPE_STUB_DECL (type
);
3704 return TYPE_NAME (type
);
3707 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3708 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3709 BASE_CLASS, or NULL_TREE if an error occurred. The
3710 ACCESS_SPECIFIER is one of
3711 access_{default,public,protected_private}_node. For a virtual base
3712 we set TREE_TYPE. */
3715 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3719 if (base
== error_mark_node
)
3721 error ("invalid base-class specification");
3724 else if (! MAYBE_CLASS_TYPE_P (base
))
3726 error ("%qT is not a class type", base
);
3731 if (cp_type_quals (base
) != 0)
3733 /* DR 484: Can a base-specifier name a cv-qualified
3735 base
= TYPE_MAIN_VARIANT (base
);
3737 result
= build_tree_list (access
, base
);
3739 TREE_TYPE (result
) = integer_type_node
;
3745 /* If FNS is a member function, a set of member functions, or a
3746 template-id referring to one or more member functions, return a
3747 BASELINK for FNS, incorporating the current access context.
3748 Otherwise, return FNS unchanged. */
3751 baselink_for_fns (tree fns
)
3756 if (BASELINK_P (fns
)
3757 || error_operand_p (fns
))
3760 scope
= ovl_scope (fns
);
3761 if (!CLASS_TYPE_P (scope
))
3764 cl
= currently_open_derived_class (scope
);
3767 tree access_path
= TYPE_BINFO (cl
);
3768 tree conv_path
= (cl
== scope
? access_path
3769 : lookup_base (cl
, scope
, ba_any
, NULL
, tf_none
));
3770 return build_baselink (conv_path
, access_path
, fns
, /*optype=*/NULL_TREE
);
3773 /* Returns true iff DECL is a variable from a function outside
3777 outer_var_p (tree decl
)
3779 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3780 && DECL_FUNCTION_SCOPE_P (decl
)
3781 /* Don't get confused by temporaries. */
3783 && (DECL_CONTEXT (decl
) != current_function_decl
3784 || parsing_nsdmi ()));
3787 /* As above, but also checks that DECL is automatic. */
3790 outer_automatic_var_p (tree decl
)
3792 return (outer_var_p (decl
)
3793 && !TREE_STATIC (decl
));
3796 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3797 rewrite it for lambda capture.
3799 If ODR_USE is true, we're being called from mark_use, and we complain about
3800 use of constant variables. If ODR_USE is false, we're being called for the
3801 id-expression, and we do lambda capture. */
3804 process_outer_var_ref (tree decl
, tsubst_flags_t complain
, bool odr_use
)
3806 if (cp_unevaluated_operand
)
3808 tree type
= TREE_TYPE (decl
);
3809 if (!dependent_type_p (type
)
3810 && variably_modified_type_p (type
, NULL_TREE
))
3811 /* VLAs are used even in unevaluated context. */;
3813 /* It's not a use (3.2) if we're in an unevaluated context. */
3816 if (decl
== error_mark_node
)
3819 tree context
= DECL_CONTEXT (decl
);
3820 tree containing_function
= current_function_decl
;
3821 tree lambda_stack
= NULL_TREE
;
3822 tree lambda_expr
= NULL_TREE
;
3823 tree initializer
= convert_from_reference (decl
);
3825 /* Mark it as used now even if the use is ill-formed. */
3826 if (!mark_used (decl
, complain
))
3827 return error_mark_node
;
3829 if (parsing_nsdmi ())
3830 containing_function
= NULL_TREE
;
3832 if (containing_function
&& LAMBDA_FUNCTION_P (containing_function
))
3834 /* Check whether we've already built a proxy. */
3836 while (is_normal_capture_proxy (var
))
3837 var
= DECL_CAPTURED_VARIABLE (var
);
3838 tree d
= retrieve_local_specialization (var
);
3840 if (d
&& d
!= decl
&& is_capture_proxy (d
))
3842 if (DECL_CONTEXT (d
) == containing_function
)
3843 /* We already have an inner proxy. */
3846 /* We need to capture an outer proxy. */
3847 return process_outer_var_ref (d
, complain
, odr_use
);
3851 /* If we are in a lambda function, we can move out until we hit
3853 2. a non-lambda function, or
3854 3. a non-default capturing lambda function. */
3855 while (context
!= containing_function
3856 /* containing_function can be null with invalid generic lambdas. */
3857 && containing_function
3858 && LAMBDA_FUNCTION_P (containing_function
))
3860 tree closure
= DECL_CONTEXT (containing_function
);
3861 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3863 if (TYPE_CLASS_SCOPE_P (closure
))
3864 /* A lambda in an NSDMI (c++/64496). */
3867 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3870 lambda_stack
= tree_cons (NULL_TREE
, lambda_expr
, lambda_stack
);
3872 containing_function
= decl_function_context (containing_function
);
3875 /* In a lambda within a template, wait until instantiation time to implicitly
3876 capture a parameter pack. We want to wait because we don't know if we're
3877 capturing the whole pack or a single element, and it's OK to wait because
3878 find_parameter_packs_r walks into the lambda body. */
3879 if (context
== containing_function
3880 && DECL_PACK_P (decl
))
3883 if (lambda_expr
&& VAR_P (decl
) && DECL_ANON_UNION_VAR_P (decl
))
3885 if (complain
& tf_error
)
3886 error ("cannot capture member %qD of anonymous union", decl
);
3887 return error_mark_node
;
3889 /* Do lambda capture when processing the id-expression, not when
3890 odr-using a variable. */
3891 if (!odr_use
&& context
== containing_function
)
3892 decl
= add_default_capture (lambda_stack
,
3893 /*id=*/DECL_NAME (decl
), initializer
);
3894 /* Only an odr-use of an outer automatic variable causes an
3895 error, and a constant variable can decay to a prvalue
3896 constant without odr-use. So don't complain yet. */
3897 else if (!odr_use
&& decl_constant_var_p (decl
))
3899 else if (lambda_expr
)
3901 if (complain
& tf_error
)
3903 error ("%qD is not captured", decl
);
3904 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3905 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3906 inform (location_of (closure
),
3907 "the lambda has no capture-default");
3908 else if (TYPE_CLASS_SCOPE_P (closure
))
3909 inform (UNKNOWN_LOCATION
, "lambda in local class %q+T cannot "
3910 "capture variables from the enclosing context",
3911 TYPE_CONTEXT (closure
));
3912 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3914 return error_mark_node
;
3918 if (complain
& tf_error
)
3921 ? G_("use of local variable with automatic storage from "
3922 "containing function")
3923 : G_("use of parameter from containing function"));
3924 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3926 return error_mark_node
;
3931 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3932 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3933 if non-NULL, is the type or namespace used to explicitly qualify
3934 ID_EXPRESSION. DECL is the entity to which that name has been
3937 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3938 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3939 be set to true if this expression isn't permitted in a
3940 constant-expression, but it is otherwise not set by this function.
3941 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3942 constant-expression, but a non-constant expression is also
3945 DONE is true if this expression is a complete postfix-expression;
3946 it is false if this expression is followed by '->', '[', '(', etc.
3947 ADDRESS_P is true iff this expression is the operand of '&'.
3948 TEMPLATE_P is true iff the qualified-id was of the form
3949 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3950 appears as a template argument.
3952 If an error occurs, and it is the kind of error that might cause
3953 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3954 is the caller's responsibility to issue the message. *ERROR_MSG
3955 will be a string with static storage duration, so the caller need
3958 Return an expression for the entity, after issuing appropriate
3959 diagnostics. This function is also responsible for transforming a
3960 reference to a non-static member into a COMPONENT_REF that makes
3961 the use of "this" explicit.
3963 Upon return, *IDK will be filled in appropriately. */
3965 finish_id_expression_1 (tree id_expression
,
3969 bool integral_constant_expression_p
,
3970 bool allow_non_integral_constant_expression_p
,
3971 bool *non_integral_constant_expression_p
,
3975 bool template_arg_p
,
3976 const char **error_msg
,
3977 location_t location
)
3979 decl
= strip_using_decl (decl
);
3981 /* Initialize the output parameters. */
3982 *idk
= CP_ID_KIND_NONE
;
3985 if (id_expression
== error_mark_node
)
3986 return error_mark_node
;
3987 /* If we have a template-id, then no further lookup is
3988 required. If the template-id was for a template-class, we
3989 will sometimes have a TYPE_DECL at this point. */
3990 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3991 || TREE_CODE (decl
) == TYPE_DECL
)
3993 /* Look up the name. */
3996 if (decl
== error_mark_node
)
3998 /* Name lookup failed. */
4001 || (!dependent_type_p (scope
)
4002 && !(identifier_p (id_expression
)
4003 && IDENTIFIER_CONV_OP_P (id_expression
)
4004 && dependent_type_p (TREE_TYPE (id_expression
))))))
4006 /* If the qualifying type is non-dependent (and the name
4007 does not name a conversion operator to a dependent
4008 type), issue an error. */
4009 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
4010 return error_mark_node
;
4014 /* It may be resolved via Koenig lookup. */
4015 *idk
= CP_ID_KIND_UNQUALIFIED
;
4016 return id_expression
;
4019 decl
= id_expression
;
4022 /* Remember that the name was used in the definition of
4023 the current class so that we can check later to see if
4024 the meaning would have been different after the class
4025 was entirely defined. */
4026 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
4027 maybe_note_name_used_in_class (id_expression
, decl
);
4029 /* A use in unevaluated operand might not be instantiated appropriately
4030 if tsubst_copy builds a dummy parm, or if we never instantiate a
4031 generic lambda, so mark it now. */
4032 if (processing_template_decl
&& cp_unevaluated_operand
)
4033 mark_type_use (decl
);
4035 /* Disallow uses of local variables from containing functions, except
4036 within lambda-expressions. */
4037 if (outer_automatic_var_p (decl
))
4039 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
4040 if (decl
== error_mark_node
)
4041 return error_mark_node
;
4044 /* Also disallow uses of function parameters outside the function
4045 body, except inside an unevaluated context (i.e. decltype). */
4046 if (TREE_CODE (decl
) == PARM_DECL
4047 && DECL_CONTEXT (decl
) == NULL_TREE
4048 && !cp_unevaluated_operand
)
4050 *error_msg
= G_("use of parameter outside function body");
4051 return error_mark_node
;
4055 /* If we didn't find anything, or what we found was a type,
4056 then this wasn't really an id-expression. */
4057 if (TREE_CODE (decl
) == TEMPLATE_DECL
4058 && !DECL_FUNCTION_TEMPLATE_P (decl
))
4060 *error_msg
= G_("missing template arguments");
4061 return error_mark_node
;
4063 else if (TREE_CODE (decl
) == TYPE_DECL
4064 || TREE_CODE (decl
) == NAMESPACE_DECL
)
4066 *error_msg
= G_("expected primary-expression");
4067 return error_mark_node
;
4070 /* If the name resolved to a template parameter, there is no
4071 need to look it up again later. */
4072 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
4073 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
4077 *idk
= CP_ID_KIND_NONE
;
4078 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
4079 decl
= TEMPLATE_PARM_DECL (decl
);
4080 r
= DECL_INITIAL (decl
);
4081 if (CLASS_TYPE_P (TREE_TYPE (r
)) && !CP_TYPE_CONST_P (TREE_TYPE (r
)))
4083 /* If the entity is a template parameter object for a template
4084 parameter of type T, the type of the expression is const T. */
4085 tree ctype
= TREE_TYPE (r
);
4086 ctype
= cp_build_qualified_type (ctype
, (cp_type_quals (ctype
)
4087 | TYPE_QUAL_CONST
));
4088 r
= build1 (VIEW_CONVERT_EXPR
, ctype
, r
);
4090 r
= convert_from_reference (r
);
4091 if (integral_constant_expression_p
4092 && !dependent_type_p (TREE_TYPE (decl
))
4093 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
4095 if (!allow_non_integral_constant_expression_p
)
4096 error ("template parameter %qD of type %qT is not allowed in "
4097 "an integral constant expression because it is not of "
4098 "integral or enumeration type", decl
, TREE_TYPE (decl
));
4099 *non_integral_constant_expression_p
= true;
4105 bool dependent_p
= type_dependent_expression_p (decl
);
4107 /* If the declaration was explicitly qualified indicate
4108 that. The semantics of `A::f(3)' are different than
4109 `f(3)' if `f' is virtual. */
4111 ? CP_ID_KIND_QUALIFIED
4112 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
4113 ? CP_ID_KIND_TEMPLATE_ID
4115 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4116 : CP_ID_KIND_UNQUALIFIED
)));
4120 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
4121 /* Dependent type attributes on the decl mean that the TREE_TYPE is
4122 wrong, so just return the identifier. */
4123 return id_expression
;
4125 if (DECL_CLASS_TEMPLATE_P (decl
))
4127 error ("use of class template %qT as expression", decl
);
4128 return error_mark_node
;
4131 if (TREE_CODE (decl
) == TREE_LIST
)
4133 /* Ambiguous reference to base members. */
4134 error ("request for member %qD is ambiguous in "
4135 "multiple inheritance lattice", id_expression
);
4136 print_candidates (decl
);
4137 return error_mark_node
;
4140 /* Mark variable-like entities as used. Functions are similarly
4141 marked either below or after overload resolution. */
4143 || TREE_CODE (decl
) == PARM_DECL
4144 || TREE_CODE (decl
) == CONST_DECL
4145 || TREE_CODE (decl
) == RESULT_DECL
)
4146 && !mark_used (decl
))
4147 return error_mark_node
;
4149 /* Only certain kinds of names are allowed in constant
4150 expression. Template parameters have already
4151 been handled above. */
4152 if (! error_operand_p (decl
)
4154 && integral_constant_expression_p
4155 && !decl_constant_var_p (decl
)
4156 && TREE_CODE (decl
) != CONST_DECL
4157 && !builtin_valid_in_constant_expr_p (decl
)
4158 && !concept_check_p (decl
))
4160 if (!allow_non_integral_constant_expression_p
)
4162 error ("%qD cannot appear in a constant-expression", decl
);
4163 return error_mark_node
;
4165 *non_integral_constant_expression_p
= true;
4168 if (tree wrap
= maybe_get_tls_wrapper_call (decl
))
4169 /* Replace an evaluated use of the thread_local variable with
4170 a call to its wrapper. */
4172 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
4174 && variable_template_p (TREE_OPERAND (decl
, 0))
4175 && !concept_check_p (decl
))
4177 decl
= finish_template_variable (decl
);
4179 decl
= convert_from_reference (decl
);
4181 else if (concept_check_p (decl
))
4183 /* Nothing more to do. All of the analysis for concept checks
4184 is done by build_conept_id, called from the parser. */
4188 if (TREE_CODE (decl
) == SCOPE_REF
)
4190 gcc_assert (same_type_p (scope
, TREE_OPERAND (decl
, 0)));
4191 decl
= TREE_OPERAND (decl
, 1);
4194 decl
= (adjust_result_of_qualified_name_lookup
4195 (decl
, scope
, current_nonlambda_class_type()));
4197 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4200 cp_warn_deprecated_use_scopes (scope
);
4203 decl
= finish_qualified_id_expr (scope
,
4209 tf_warning_or_error
);
4211 decl
= convert_from_reference (decl
);
4213 else if (TREE_CODE (decl
) == FIELD_DECL
)
4215 /* Since SCOPE is NULL here, this is an unqualified name.
4216 Access checking has been performed during name lookup
4217 already. Turn off checking to avoid duplicate errors. */
4218 push_deferring_access_checks (dk_no_check
);
4219 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
4220 /*qualifying_scope=*/NULL_TREE
);
4221 pop_deferring_access_checks ();
4223 else if (is_overloaded_fn (decl
))
4225 /* We only need to look at the first function,
4226 because all the fns share the attribute we're
4227 concerned with (all member fns or all non-members). */
4228 tree first_fn
= get_first_fn (decl
);
4229 first_fn
= STRIP_TEMPLATE (first_fn
);
4231 /* [basic.def.odr]: "A function whose name appears as a
4232 potentially-evaluated expression is odr-used if it is the unique
4235 But only mark it if it's a complete postfix-expression; in a call,
4236 ADL might select a different function, and we'll call mark_used in
4239 && !really_overloaded_fn (decl
)
4240 && !mark_used (first_fn
))
4241 return error_mark_node
;
4244 && (TREE_CODE (first_fn
) == USING_DECL
4245 || (TREE_CODE (first_fn
) == FUNCTION_DECL
4246 && DECL_FUNCTION_MEMBER_P (first_fn
)
4247 && !shared_member_p (decl
))))
4249 /* A set of member functions. */
4250 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
4251 return finish_class_member_access_expr (decl
, id_expression
,
4252 /*template_p=*/false,
4253 tf_warning_or_error
);
4256 decl
= baselink_for_fns (decl
);
4260 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
4261 && DECL_CLASS_SCOPE_P (decl
))
4263 tree context
= context_for_name_lookup (decl
);
4264 if (context
!= current_class_type
)
4266 tree path
= currently_open_derived_class (context
);
4268 /* PATH can be null for using an enum of an unrelated
4269 class; we checked its access in lookup_using_decl.
4271 ??? Should this case make a clone instead, like
4272 handle_using_decl? */
4273 gcc_assert (TREE_CODE (decl
) == CONST_DECL
);
4275 perform_or_defer_access_check (TYPE_BINFO (path
),
4277 tf_warning_or_error
);
4281 decl
= convert_from_reference (decl
);
4285 return cp_expr (decl
, location
);
4288 /* As per finish_id_expression_1, but adding a wrapper node
4289 around the result if needed to express LOCATION. */
4292 finish_id_expression (tree id_expression
,
4296 bool integral_constant_expression_p
,
4297 bool allow_non_integral_constant_expression_p
,
4298 bool *non_integral_constant_expression_p
,
4302 bool template_arg_p
,
4303 const char **error_msg
,
4304 location_t location
)
4307 = finish_id_expression_1 (id_expression
, decl
, scope
, idk
,
4308 integral_constant_expression_p
,
4309 allow_non_integral_constant_expression_p
,
4310 non_integral_constant_expression_p
,
4311 template_p
, done
, address_p
, template_arg_p
,
4312 error_msg
, location
);
4313 return result
.maybe_add_location_wrapper ();
4316 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
4317 use as a type-specifier. */
4320 finish_typeof (tree expr
)
4324 if (type_dependent_expression_p (expr
))
4326 type
= cxx_make_type (TYPEOF_TYPE
);
4327 TYPEOF_TYPE_EXPR (type
) = expr
;
4328 SET_TYPE_STRUCTURAL_EQUALITY (type
);
4333 expr
= mark_type_use (expr
);
4335 type
= unlowered_expr_type (expr
);
4337 if (!type
|| type
== unknown_type_node
)
4339 error ("type of %qE is unknown", expr
);
4340 return error_mark_node
;
4346 /* Implement the __underlying_type keyword: Return the underlying
4347 type of TYPE, suitable for use as a type-specifier. */
4350 finish_underlying_type (tree type
)
4352 tree underlying_type
;
4354 if (processing_template_decl
)
4356 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
4357 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
4358 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
4360 return underlying_type
;
4363 if (!complete_type_or_else (type
, NULL_TREE
))
4364 return error_mark_node
;
4366 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
4368 error ("%qT is not an enumeration type", type
);
4369 return error_mark_node
;
4372 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
4374 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
4375 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
4376 See finish_enum_value_list for details. */
4377 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
4379 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
4380 TYPE_UNSIGNED (underlying_type
));
4382 return underlying_type
;
4385 /* Implement the __direct_bases keyword: Return the direct base classes
4389 calculate_direct_bases (tree type
, tsubst_flags_t complain
)
4391 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4392 || !NON_UNION_CLASS_TYPE_P (type
))
4393 return make_tree_vec (0);
4395 releasing_vec vector
;
4396 vec
<tree
, va_gc
> *base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
4400 /* Virtual bases are initialized first */
4401 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4402 if (BINFO_VIRTUAL_P (binfo
))
4403 vec_safe_push (vector
, binfo
);
4405 /* Now non-virtuals */
4406 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4407 if (!BINFO_VIRTUAL_P (binfo
))
4408 vec_safe_push (vector
, binfo
);
4410 tree bases_vec
= make_tree_vec (vector
->length ());
4412 for (i
= 0; i
< vector
->length (); ++i
)
4413 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
4418 /* Implement the __bases keyword: Return the base classes
4421 /* Find morally non-virtual base classes by walking binfo hierarchy */
4422 /* Virtual base classes are handled separately in finish_bases */
4425 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
4427 /* Don't walk bases of virtual bases */
4428 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
4432 dfs_calculate_bases_post (tree binfo
, void *data_
)
4434 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
4435 if (!BINFO_VIRTUAL_P (binfo
))
4436 vec_safe_push (*data
, BINFO_TYPE (binfo
));
4440 /* Calculates the morally non-virtual base classes of a class */
4441 static vec
<tree
, va_gc
> *
4442 calculate_bases_helper (tree type
)
4444 vec
<tree
, va_gc
> *vector
= make_tree_vector ();
4446 /* Now add non-virtual base classes in order of construction */
4447 if (TYPE_BINFO (type
))
4448 dfs_walk_all (TYPE_BINFO (type
),
4449 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
4454 calculate_bases (tree type
, tsubst_flags_t complain
)
4456 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4457 || !NON_UNION_CLASS_TYPE_P (type
))
4458 return make_tree_vec (0);
4460 releasing_vec vector
;
4461 tree bases_vec
= NULL_TREE
;
4463 vec
<tree
, va_gc
> *vbases
;
4466 /* First go through virtual base classes */
4467 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
4468 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
4470 releasing_vec vbase_bases
4471 = calculate_bases_helper (BINFO_TYPE (binfo
));
4472 vec_safe_splice (vector
, vbase_bases
);
4475 /* Now for the non-virtual bases */
4476 releasing_vec nonvbases
= calculate_bases_helper (type
);
4477 vec_safe_splice (vector
, nonvbases
);
4479 /* Note that during error recovery vector->length can even be zero. */
4480 if (vector
->length () > 1)
4482 /* Last element is entire class, so don't copy */
4483 bases_vec
= make_tree_vec (vector
->length () - 1);
4485 for (i
= 0; i
< vector
->length () - 1; ++i
)
4486 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
4489 bases_vec
= make_tree_vec (0);
4495 finish_bases (tree type
, bool direct
)
4497 tree bases
= NULL_TREE
;
4499 if (!processing_template_decl
)
4501 /* Parameter packs can only be used in templates */
4502 error ("parameter pack %<__bases%> only valid in template declaration");
4503 return error_mark_node
;
4506 bases
= cxx_make_type (BASES
);
4507 BASES_TYPE (bases
) = type
;
4508 BASES_DIRECT (bases
) = direct
;
4509 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
4514 /* Perform C++-specific checks for __builtin_offsetof before calling
4518 finish_offsetof (tree object_ptr
, tree expr
, location_t loc
)
4520 /* If we're processing a template, we can't finish the semantics yet.
4521 Otherwise we can fold the entire expression now. */
4522 if (processing_template_decl
)
4524 expr
= build2 (OFFSETOF_EXPR
, size_type_node
, expr
, object_ptr
);
4525 SET_EXPR_LOCATION (expr
, loc
);
4529 if (expr
== error_mark_node
)
4530 return error_mark_node
;
4532 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4534 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4535 TREE_OPERAND (expr
, 2));
4536 return error_mark_node
;
4538 if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr
))
4539 || TREE_TYPE (expr
) == unknown_type_node
)
4541 while (TREE_CODE (expr
) == COMPONENT_REF
4542 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4543 expr
= TREE_OPERAND (expr
, 1);
4547 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4548 inform (DECL_SOURCE_LOCATION (expr
), "declared here");
4551 error ("cannot apply %<offsetof%> to member function");
4552 return error_mark_node
;
4554 if (TREE_CODE (expr
) == CONST_DECL
)
4556 error ("cannot apply %<offsetof%> to an enumerator %qD", expr
);
4557 return error_mark_node
;
4559 if (REFERENCE_REF_P (expr
))
4560 expr
= TREE_OPERAND (expr
, 0);
4561 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr
)), object_ptr
))
4562 return error_mark_node
;
4563 if (warn_invalid_offsetof
4564 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr
)))
4565 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr
)))
4566 && cp_unevaluated_operand
== 0)
4567 warning_at (loc
, OPT_Winvalid_offsetof
, "%<offsetof%> within "
4568 "non-standard-layout type %qT is conditionally-supported",
4569 TREE_TYPE (TREE_TYPE (object_ptr
)));
4570 return fold_offsetof (expr
);
4573 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4574 function is broken out from the above for the benefit of the tree-ssa
4578 simplify_aggr_init_expr (tree
*tp
)
4580 tree aggr_init_expr
= *tp
;
4582 /* Form an appropriate CALL_EXPR. */
4583 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4584 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4585 tree type
= TREE_TYPE (slot
);
4588 enum style_t
{ ctor
, arg
, pcc
} style
;
4590 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4592 #ifdef PCC_STATIC_STRUCT_RETURN
4598 gcc_assert (TREE_ADDRESSABLE (type
));
4602 call_expr
= build_call_array_loc (input_location
,
4603 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4605 aggr_init_expr_nargs (aggr_init_expr
),
4606 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4607 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4608 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4609 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4610 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4611 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4612 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4616 /* Replace the first argument to the ctor with the address of the
4618 cxx_mark_addressable (slot
);
4619 CALL_EXPR_ARG (call_expr
, 0) =
4620 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4622 else if (style
== arg
)
4624 /* Just mark it addressable here, and leave the rest to
4625 expand_call{,_inline}. */
4626 cxx_mark_addressable (slot
);
4627 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4628 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4630 else if (style
== pcc
)
4632 /* If we're using the non-reentrant PCC calling convention, then we
4633 need to copy the returned value out of the static buffer into the
4635 push_deferring_access_checks (dk_no_check
);
4636 call_expr
= build_aggr_init (slot
, call_expr
,
4637 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4638 tf_warning_or_error
);
4639 pop_deferring_access_checks ();
4640 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4643 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4645 tree init
= build_zero_init (type
, NULL_TREE
,
4646 /*static_storage_p=*/false);
4647 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4648 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4655 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4658 emit_associated_thunks (tree fn
)
4660 /* When we use vcall offsets, we emit thunks with the virtual
4661 functions to which they thunk. The whole point of vcall offsets
4662 is so that you can know statically the entire set of thunks that
4663 will ever be needed for a given virtual function, thereby
4664 enabling you to output all the thunks with the function itself. */
4665 if (DECL_VIRTUAL_P (fn
)
4666 /* Do not emit thunks for extern template instantiations. */
4667 && ! DECL_REALLY_EXTERN (fn
))
4671 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4673 if (!THUNK_ALIAS (thunk
))
4675 use_thunk (thunk
, /*emit_p=*/1);
4676 if (DECL_RESULT_THUNK_P (thunk
))
4680 for (probe
= DECL_THUNKS (thunk
);
4681 probe
; probe
= DECL_CHAIN (probe
))
4682 use_thunk (probe
, /*emit_p=*/1);
4686 gcc_assert (!DECL_THUNKS (thunk
));
4691 /* Generate RTL for FN. */
4694 expand_or_defer_fn_1 (tree fn
)
4696 /* When the parser calls us after finishing the body of a template
4697 function, we don't really want to expand the body. */
4698 if (processing_template_decl
)
4700 /* Normally, collection only occurs in rest_of_compilation. So,
4701 if we don't collect here, we never collect junk generated
4702 during the processing of templates until we hit a
4703 non-template function. It's not safe to do this inside a
4704 nested class, though, as the parser may have local state that
4705 is not a GC root. */
4706 if (!function_depth
)
4711 gcc_assert (DECL_SAVED_TREE (fn
));
4713 /* We make a decision about linkage for these functions at the end
4714 of the compilation. Until that point, we do not want the back
4715 end to output them -- but we do want it to see the bodies of
4716 these functions so that it can inline them as appropriate. */
4717 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4719 if (DECL_INTERFACE_KNOWN (fn
))
4720 /* We've already made a decision as to how this function will
4723 || DECL_IMMEDIATE_FUNCTION_P (fn
)
4724 || DECL_OMP_DECLARE_REDUCTION_P (fn
))
4725 tentative_decl_linkage (fn
);
4727 import_export_decl (fn
);
4729 /* If the user wants us to keep all inline functions, then mark
4730 this function as needed so that finish_file will make sure to
4731 output it later. Similarly, all dllexport'd functions must
4732 be emitted; there may be callers in other DLLs. */
4733 if (DECL_DECLARED_INLINE_P (fn
)
4734 && !DECL_REALLY_EXTERN (fn
)
4735 && !DECL_IMMEDIATE_FUNCTION_P (fn
)
4736 && !DECL_OMP_DECLARE_REDUCTION_P (fn
)
4737 && (flag_keep_inline_functions
4738 || (flag_keep_inline_dllexport
4739 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4742 DECL_EXTERNAL (fn
) = 0;
4746 /* If this is a constructor or destructor body, we have to clone
4748 if (maybe_clone_body (fn
))
4750 /* We don't want to process FN again, so pretend we've written
4751 it out, even though we haven't. */
4752 TREE_ASM_WRITTEN (fn
) = 1;
4753 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4754 if (!DECL_DECLARED_CONSTEXPR_P (fn
)
4755 && !(modules_p () && DECL_DECLARED_INLINE_P (fn
)))
4756 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4760 /* There's no reason to do any of the work here if we're only doing
4761 semantic analysis; this code just generates RTL. */
4762 if (flag_syntax_only
)
4764 /* Pretend that this function has been written out so that we don't try
4765 to expand it again. */
4766 TREE_ASM_WRITTEN (fn
) = 1;
4770 if (DECL_OMP_DECLARE_REDUCTION_P (fn
))
4777 expand_or_defer_fn (tree fn
)
4779 if (expand_or_defer_fn_1 (fn
))
4783 /* Expand or defer, at the whim of the compilation unit manager. */
4784 cgraph_node::finalize_function (fn
, function_depth
> 1);
4785 emit_associated_thunks (fn
);
4794 nrv_data () : visited (37) {}
4798 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4801 /* Helper function for walk_tree, used by finalize_nrv below. */
4804 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4806 class nrv_data
*dp
= (class nrv_data
*)data
;
4809 /* No need to walk into types. There wouldn't be any need to walk into
4810 non-statements, except that we have to consider STMT_EXPRs. */
4813 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4814 but differs from using NULL_TREE in that it indicates that we care
4815 about the value of the RESULT_DECL. */
4816 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4817 TREE_OPERAND (*tp
, 0) = dp
->result
;
4818 /* Change all cleanups for the NRV to only run when an exception is
4820 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4821 && CLEANUP_DECL (*tp
) == dp
->var
)
4822 CLEANUP_EH_ONLY (*tp
) = 1;
4823 /* Replace the DECL_EXPR for the NRV with an initialization of the
4824 RESULT_DECL, if needed. */
4825 else if (TREE_CODE (*tp
) == DECL_EXPR
4826 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4829 if (DECL_INITIAL (dp
->var
)
4830 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4831 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4832 DECL_INITIAL (dp
->var
));
4834 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4835 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4836 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4839 /* And replace all uses of the NRV with the RESULT_DECL. */
4840 else if (*tp
== dp
->var
)
4843 /* Avoid walking into the same tree more than once. Unfortunately, we
4844 can't just use walk_tree_without duplicates because it would only call
4845 us for the first occurrence of dp->var in the function body. */
4846 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4852 /* Keep iterating. */
4856 /* Called from finish_function to implement the named return value
4857 optimization by overriding all the RETURN_EXPRs and pertinent
4858 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4859 RESULT_DECL for the function. */
4862 finalize_nrv (tree
*tp
, tree var
, tree result
)
4864 class nrv_data data
;
4866 /* Copy name from VAR to RESULT. */
4867 DECL_NAME (result
) = DECL_NAME (var
);
4868 /* Don't forget that we take its address. */
4869 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4870 /* Finally set DECL_VALUE_EXPR to avoid assigning
4871 a stack slot at -O0 for the original var and debug info
4872 uses RESULT location for VAR. */
4873 SET_DECL_VALUE_EXPR (var
, result
);
4874 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4877 data
.result
= result
;
4878 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4881 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4884 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4885 bool need_copy_ctor
, bool need_copy_assignment
,
4888 int save_errorcount
= errorcount
;
4891 /* Always allocate 3 elements for simplicity. These are the
4892 function decls for the ctor, dtor, and assignment op.
4893 This layout is known to the three lang hooks,
4894 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4895 and cxx_omp_clause_assign_op. */
4896 info
= make_tree_vec (3);
4897 CP_OMP_CLAUSE_INFO (c
) = info
;
4899 if (need_default_ctor
|| need_copy_ctor
)
4901 if (need_default_ctor
)
4902 t
= get_default_ctor (type
);
4904 t
= get_copy_ctor (type
, tf_warning_or_error
);
4906 if (t
&& !trivial_fn_p (t
))
4907 TREE_VEC_ELT (info
, 0) = t
;
4910 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4911 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4913 if (need_copy_assignment
)
4915 t
= get_copy_assign (type
);
4917 if (t
&& !trivial_fn_p (t
))
4918 TREE_VEC_ELT (info
, 2) = t
;
4921 return errorcount
!= save_errorcount
;
4924 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4925 FIELD_DECL, otherwise return DECL itself. */
4928 omp_clause_decl_field (tree decl
)
4931 && DECL_HAS_VALUE_EXPR_P (decl
)
4932 && DECL_ARTIFICIAL (decl
)
4933 && DECL_LANG_SPECIFIC (decl
)
4934 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4936 tree f
= DECL_VALUE_EXPR (decl
);
4937 if (INDIRECT_REF_P (f
))
4938 f
= TREE_OPERAND (f
, 0);
4939 if (TREE_CODE (f
) == COMPONENT_REF
)
4941 f
= TREE_OPERAND (f
, 1);
4942 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4949 /* Adjust DECL if needed for printing using %qE. */
4952 omp_clause_printable_decl (tree decl
)
4954 tree t
= omp_clause_decl_field (decl
);
4960 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4961 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4965 omp_note_field_privatization (tree f
, tree t
)
4967 if (!omp_private_member_map
)
4968 omp_private_member_map
= new hash_map
<tree
, tree
>;
4969 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4973 omp_private_member_vec
.safe_push (f
);
4974 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4975 omp_private_member_vec
.safe_push (integer_zero_node
);
4979 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4983 omp_privatize_field (tree t
, bool shared
)
4985 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4986 if (m
== error_mark_node
)
4987 return error_mark_node
;
4988 if (!omp_private_member_map
&& !shared
)
4989 omp_private_member_map
= new hash_map
<tree
, tree
>;
4990 if (TYPE_REF_P (TREE_TYPE (t
)))
4992 gcc_assert (INDIRECT_REF_P (m
));
4993 m
= TREE_OPERAND (m
, 0);
4995 tree vb
= NULL_TREE
;
4996 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4999 v
= create_temporary_var (TREE_TYPE (m
));
5000 retrofit_lang_decl (v
);
5001 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
5002 SET_DECL_VALUE_EXPR (v
, m
);
5003 DECL_HAS_VALUE_EXPR_P (v
) = 1;
5005 omp_private_member_vec
.safe_push (t
);
5010 /* Helper function for handle_omp_array_sections. Called recursively
5011 to handle multiple array-section-subscripts. C is the clause,
5012 T current expression (initially OMP_CLAUSE_DECL), which is either
5013 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
5014 expression if specified, TREE_VALUE length expression if specified,
5015 TREE_CHAIN is what it has been specified after, or some decl.
5016 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
5017 set to true if any of the array-section-subscript could have length
5018 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
5019 first array-section-subscript which is known not to have length
5021 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
5022 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
5023 all are or may have length of 1, array-section-subscript [:2] is the
5024 first one known not to have length 1. For array-section-subscript
5025 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
5026 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
5027 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
5028 case though, as some lengths could be zero. */
5031 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
5032 bool &maybe_zero_len
, unsigned int &first_non_one
,
5033 enum c_omp_region_type ort
)
5035 tree ret
, low_bound
, length
, type
;
5036 if (TREE_CODE (t
) != TREE_LIST
)
5038 if (error_operand_p (t
))
5039 return error_mark_node
;
5040 if (REFERENCE_REF_P (t
)
5041 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5042 t
= TREE_OPERAND (t
, 0);
5044 while (TREE_CODE (t
) == INDIRECT_REF
)
5046 t
= TREE_OPERAND (t
, 0);
5048 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
5049 t
= TREE_OPERAND (t
, 0);
5051 while (TREE_CODE (t
) == COMPOUND_EXPR
)
5053 t
= TREE_OPERAND (t
, 1);
5056 if (TREE_CODE (t
) == COMPONENT_REF
5057 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5058 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
5059 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
5060 && !type_dependent_expression_p (t
))
5062 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
5063 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
5065 error_at (OMP_CLAUSE_LOCATION (c
),
5066 "bit-field %qE in %qs clause",
5067 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5068 return error_mark_node
;
5070 while (TREE_CODE (t
) == COMPONENT_REF
)
5072 if (TREE_TYPE (TREE_OPERAND (t
, 0))
5073 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
5075 error_at (OMP_CLAUSE_LOCATION (c
),
5076 "%qE is a member of a union", t
);
5077 return error_mark_node
;
5079 t
= TREE_OPERAND (t
, 0);
5080 while (TREE_CODE (t
) == MEM_REF
5081 || TREE_CODE (t
) == INDIRECT_REF
5082 || TREE_CODE (t
) == ARRAY_REF
)
5084 t
= TREE_OPERAND (t
, 0);
5086 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
5087 t
= TREE_OPERAND (t
, 0);
5090 if (REFERENCE_REF_P (t
))
5091 t
= TREE_OPERAND (t
, 0);
5093 if (TREE_CODE (t
) == FIELD_DECL
)
5094 ret
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
5095 else if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5097 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
5100 error_at (OMP_CLAUSE_LOCATION (c
),
5101 "%qD is not a variable in %qs clause", t
,
5102 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5104 error_at (OMP_CLAUSE_LOCATION (c
),
5105 "%qE is not a variable in %qs clause", t
,
5106 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5107 return error_mark_node
;
5109 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5110 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5111 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
5113 error_at (OMP_CLAUSE_LOCATION (c
),
5114 "%qD is threadprivate variable in %qs clause", t
,
5115 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5116 return error_mark_node
;
5118 if (type_dependent_expression_p (ret
))
5120 ret
= convert_from_reference (ret
);
5124 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
5125 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5126 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5127 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5128 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
5129 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
5130 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
5131 maybe_zero_len
, first_non_one
, ort
);
5132 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
5135 type
= TREE_TYPE (ret
);
5136 low_bound
= TREE_PURPOSE (t
);
5137 length
= TREE_VALUE (t
);
5138 if ((low_bound
&& type_dependent_expression_p (low_bound
))
5139 || (length
&& type_dependent_expression_p (length
)))
5142 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
5143 return error_mark_node
;
5145 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
5147 error_at (OMP_CLAUSE_LOCATION (c
),
5148 "low bound %qE of array section does not have integral type",
5150 return error_mark_node
;
5152 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
5154 error_at (OMP_CLAUSE_LOCATION (c
),
5155 "length %qE of array section does not have integral type",
5157 return error_mark_node
;
5160 low_bound
= mark_rvalue_use (low_bound
);
5162 length
= mark_rvalue_use (length
);
5163 /* We need to reduce to real constant-values for checks below. */
5165 length
= fold_simple (length
);
5167 low_bound
= fold_simple (low_bound
);
5169 && TREE_CODE (low_bound
) == INTEGER_CST
5170 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5171 > TYPE_PRECISION (sizetype
))
5172 low_bound
= fold_convert (sizetype
, low_bound
);
5174 && TREE_CODE (length
) == INTEGER_CST
5175 && TYPE_PRECISION (TREE_TYPE (length
))
5176 > TYPE_PRECISION (sizetype
))
5177 length
= fold_convert (sizetype
, length
);
5178 if (low_bound
== NULL_TREE
)
5179 low_bound
= integer_zero_node
;
5181 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5182 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
5183 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
5185 if (length
!= integer_one_node
)
5187 error_at (OMP_CLAUSE_LOCATION (c
),
5188 "expected single pointer in %qs clause",
5189 c_omp_map_clause_name (c
, ort
== C_ORT_ACC
));
5190 return error_mark_node
;
5193 if (length
!= NULL_TREE
)
5195 if (!integer_nonzerop (length
))
5197 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
5198 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5199 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5200 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5201 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5203 if (integer_zerop (length
))
5205 error_at (OMP_CLAUSE_LOCATION (c
),
5206 "zero length array section in %qs clause",
5207 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5208 return error_mark_node
;
5212 maybe_zero_len
= true;
5214 if (first_non_one
== types
.length ()
5215 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
5218 if (TREE_CODE (type
) == ARRAY_TYPE
)
5220 if (length
== NULL_TREE
5221 && (TYPE_DOMAIN (type
) == NULL_TREE
5222 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
5224 error_at (OMP_CLAUSE_LOCATION (c
),
5225 "for unknown bound array type length expression must "
5227 return error_mark_node
;
5229 if (TREE_CODE (low_bound
) == INTEGER_CST
5230 && tree_int_cst_sgn (low_bound
) == -1)
5232 error_at (OMP_CLAUSE_LOCATION (c
),
5233 "negative low bound in array section in %qs clause",
5234 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5235 return error_mark_node
;
5237 if (length
!= NULL_TREE
5238 && TREE_CODE (length
) == INTEGER_CST
5239 && tree_int_cst_sgn (length
) == -1)
5241 error_at (OMP_CLAUSE_LOCATION (c
),
5242 "negative length in array section in %qs clause",
5243 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5244 return error_mark_node
;
5246 if (TYPE_DOMAIN (type
)
5247 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
5248 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
5252 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
5253 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
5254 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5256 if (tree_int_cst_lt (size
, low_bound
))
5258 error_at (OMP_CLAUSE_LOCATION (c
),
5259 "low bound %qE above array section size "
5260 "in %qs clause", low_bound
,
5261 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5262 return error_mark_node
;
5264 if (tree_int_cst_equal (size
, low_bound
))
5266 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
5267 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5268 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5269 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5270 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5272 error_at (OMP_CLAUSE_LOCATION (c
),
5273 "zero length array section in %qs clause",
5274 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5275 return error_mark_node
;
5277 maybe_zero_len
= true;
5279 else if (length
== NULL_TREE
5280 && first_non_one
== types
.length ()
5281 && tree_int_cst_equal
5282 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
5286 else if (length
== NULL_TREE
)
5288 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5289 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5290 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5291 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5292 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5293 maybe_zero_len
= true;
5294 if (first_non_one
== types
.length ())
5297 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
5299 if (tree_int_cst_lt (size
, length
))
5301 error_at (OMP_CLAUSE_LOCATION (c
),
5302 "length %qE above array section size "
5303 "in %qs clause", length
,
5304 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5305 return error_mark_node
;
5307 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5310 = size_binop (PLUS_EXPR
,
5311 fold_convert (sizetype
, low_bound
),
5312 fold_convert (sizetype
, length
));
5313 if (TREE_CODE (lbpluslen
) == INTEGER_CST
5314 && tree_int_cst_lt (size
, lbpluslen
))
5316 error_at (OMP_CLAUSE_LOCATION (c
),
5317 "high bound %qE above array section size "
5318 "in %qs clause", lbpluslen
,
5319 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5320 return error_mark_node
;
5325 else if (length
== NULL_TREE
)
5327 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5328 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5329 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5330 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5331 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5332 maybe_zero_len
= true;
5333 if (first_non_one
== types
.length ())
5337 /* For [lb:] we will need to evaluate lb more than once. */
5338 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5340 tree lb
= cp_save_expr (low_bound
);
5341 if (lb
!= low_bound
)
5343 TREE_PURPOSE (t
) = lb
;
5348 else if (TYPE_PTR_P (type
))
5350 if (length
== NULL_TREE
)
5352 if (TREE_CODE (ret
) == PARM_DECL
&& DECL_ARRAY_PARAMETER_P (ret
))
5353 error_at (OMP_CLAUSE_LOCATION (c
),
5354 "for array function parameter length expression "
5355 "must be specified");
5357 error_at (OMP_CLAUSE_LOCATION (c
),
5358 "for pointer type length expression must be specified");
5359 return error_mark_node
;
5361 if (length
!= NULL_TREE
5362 && TREE_CODE (length
) == INTEGER_CST
5363 && tree_int_cst_sgn (length
) == -1)
5365 error_at (OMP_CLAUSE_LOCATION (c
),
5366 "negative length in array section in %qs clause",
5367 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5368 return error_mark_node
;
5370 /* If there is a pointer type anywhere but in the very first
5371 array-section-subscript, the array section could be non-contiguous. */
5372 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5373 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5374 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
5376 /* If any prior dimension has a non-one length, then deem this
5377 array section as non-contiguous. */
5378 for (tree d
= TREE_CHAIN (t
); TREE_CODE (d
) == TREE_LIST
;
5381 tree d_length
= TREE_VALUE (d
);
5382 if (d_length
== NULL_TREE
|| !integer_onep (d_length
))
5384 error_at (OMP_CLAUSE_LOCATION (c
),
5385 "array section is not contiguous in %qs clause",
5386 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5387 return error_mark_node
;
5394 error_at (OMP_CLAUSE_LOCATION (c
),
5395 "%qE does not have pointer or array type", ret
);
5396 return error_mark_node
;
5398 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5399 types
.safe_push (TREE_TYPE (ret
));
5400 /* We will need to evaluate lb more than once. */
5401 tree lb
= cp_save_expr (low_bound
);
5402 if (lb
!= low_bound
)
5404 TREE_PURPOSE (t
) = lb
;
5407 /* Temporarily disable -fstrong-eval-order for array reductions.
5408 The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
5409 is something the middle-end can't cope with and more importantly,
5410 it needs to be the actual base variable that is privatized, not some
5411 temporary assigned previous value of it. That, together with OpenMP
5412 saying how many times the side-effects are evaluated is unspecified,
5413 makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
5414 warning_sentinel
s (flag_strong_eval_order
,
5415 OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5416 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5417 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
);
5418 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, NULL
,
5419 tf_warning_or_error
);
5423 /* Handle array sections for clause C. */
5426 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
5428 bool maybe_zero_len
= false;
5429 unsigned int first_non_one
= 0;
5430 auto_vec
<tree
, 10> types
;
5431 tree
*tp
= &OMP_CLAUSE_DECL (c
);
5432 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5433 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
)
5434 && TREE_CODE (*tp
) == TREE_LIST
5435 && TREE_PURPOSE (*tp
)
5436 && TREE_CODE (TREE_PURPOSE (*tp
)) == TREE_VEC
)
5437 tp
= &TREE_VALUE (*tp
);
5438 tree first
= handle_omp_array_sections_1 (c
, *tp
, types
,
5439 maybe_zero_len
, first_non_one
,
5441 if (first
== error_mark_node
)
5443 if (first
== NULL_TREE
)
5445 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5446 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
)
5449 tree tem
= NULL_TREE
;
5450 if (processing_template_decl
)
5452 /* Need to evaluate side effects in the length expressions
5454 while (TREE_CODE (t
) == TREE_LIST
)
5456 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
5458 if (tem
== NULL_TREE
)
5459 tem
= TREE_VALUE (t
);
5461 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
5462 TREE_VALUE (t
), tem
);
5467 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
5472 unsigned int num
= types
.length (), i
;
5473 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
5474 tree condition
= NULL_TREE
;
5476 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
5477 maybe_zero_len
= true;
5478 if (processing_template_decl
&& maybe_zero_len
)
5481 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
5484 tree low_bound
= TREE_PURPOSE (t
);
5485 tree length
= TREE_VALUE (t
);
5489 && TREE_CODE (low_bound
) == INTEGER_CST
5490 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5491 > TYPE_PRECISION (sizetype
))
5492 low_bound
= fold_convert (sizetype
, low_bound
);
5494 && TREE_CODE (length
) == INTEGER_CST
5495 && TYPE_PRECISION (TREE_TYPE (length
))
5496 > TYPE_PRECISION (sizetype
))
5497 length
= fold_convert (sizetype
, length
);
5498 if (low_bound
== NULL_TREE
)
5499 low_bound
= integer_zero_node
;
5500 if (!maybe_zero_len
&& i
> first_non_one
)
5502 if (integer_nonzerop (low_bound
))
5503 goto do_warn_noncontiguous
;
5504 if (length
!= NULL_TREE
5505 && TREE_CODE (length
) == INTEGER_CST
5506 && TYPE_DOMAIN (types
[i
])
5507 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
5508 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
5512 size
= size_binop (PLUS_EXPR
,
5513 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5515 if (!tree_int_cst_equal (length
, size
))
5517 do_warn_noncontiguous
:
5518 error_at (OMP_CLAUSE_LOCATION (c
),
5519 "array section is not contiguous in %qs "
5521 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5525 if (!processing_template_decl
5526 && length
!= NULL_TREE
5527 && TREE_SIDE_EFFECTS (length
))
5529 if (side_effects
== NULL_TREE
)
5530 side_effects
= length
;
5532 side_effects
= build2 (COMPOUND_EXPR
,
5533 TREE_TYPE (side_effects
),
5534 length
, side_effects
);
5537 else if (processing_template_decl
)
5543 if (i
> first_non_one
5544 && ((length
&& integer_nonzerop (length
))
5545 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5546 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5547 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
))
5550 l
= fold_convert (sizetype
, length
);
5553 l
= size_binop (PLUS_EXPR
,
5554 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5556 l
= size_binop (MINUS_EXPR
, l
,
5557 fold_convert (sizetype
, low_bound
));
5559 if (i
> first_non_one
)
5561 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
5563 if (condition
== NULL_TREE
)
5566 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
5569 else if (size
== NULL_TREE
)
5571 size
= size_in_bytes (TREE_TYPE (types
[i
]));
5572 tree eltype
= TREE_TYPE (types
[num
- 1]);
5573 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5574 eltype
= TREE_TYPE (eltype
);
5575 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5576 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5577 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5578 size
= size_binop (EXACT_DIV_EXPR
, size
,
5579 size_in_bytes (eltype
));
5580 size
= size_binop (MULT_EXPR
, size
, l
);
5582 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
5583 size
, size_zero_node
);
5586 size
= size_binop (MULT_EXPR
, size
, l
);
5589 if (!processing_template_decl
)
5592 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
5593 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5594 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5595 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5597 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5598 size
= save_expr (size
);
5599 tree index_type
= build_index_type (size
);
5600 tree eltype
= TREE_TYPE (first
);
5601 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5602 eltype
= TREE_TYPE (eltype
);
5603 tree type
= build_array_type (eltype
, index_type
);
5604 tree ptype
= build_pointer_type (eltype
);
5605 if (TYPE_REF_P (TREE_TYPE (t
))
5606 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
5607 t
= convert_from_reference (t
);
5608 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5609 t
= build_fold_addr_expr (t
);
5610 tree t2
= build_fold_addr_expr (first
);
5611 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5612 ptrdiff_type_node
, t2
);
5613 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5614 ptrdiff_type_node
, t2
,
5615 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5616 ptrdiff_type_node
, t
));
5617 if (tree_fits_shwi_p (t2
))
5618 t
= build2 (MEM_REF
, type
, t
,
5619 build_int_cst (ptype
, tree_to_shwi (t2
)));
5622 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5624 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
5625 TREE_TYPE (t
), t
, t2
);
5626 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5628 OMP_CLAUSE_DECL (c
) = t
;
5631 OMP_CLAUSE_DECL (c
) = first
;
5632 OMP_CLAUSE_SIZE (c
) = size
;
5633 if (TREE_CODE (t
) == FIELD_DECL
)
5634 t
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
5635 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5636 || (TREE_CODE (t
) == COMPONENT_REF
5637 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5639 switch (OMP_CLAUSE_MAP_KIND (c
))
5641 case GOMP_MAP_ALLOC
:
5642 case GOMP_MAP_IF_PRESENT
:
5645 case GOMP_MAP_TOFROM
:
5646 case GOMP_MAP_ALWAYS_TO
:
5647 case GOMP_MAP_ALWAYS_FROM
:
5648 case GOMP_MAP_ALWAYS_TOFROM
:
5649 case GOMP_MAP_RELEASE
:
5650 case GOMP_MAP_DELETE
:
5651 case GOMP_MAP_FORCE_TO
:
5652 case GOMP_MAP_FORCE_FROM
:
5653 case GOMP_MAP_FORCE_TOFROM
:
5654 case GOMP_MAP_FORCE_PRESENT
:
5655 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5660 bool reference_always_pointer
= true;
5661 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5663 if (TREE_CODE (t
) == COMPONENT_REF
)
5665 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ATTACH_DETACH
);
5667 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
5668 && TYPE_REF_P (TREE_TYPE (t
)))
5670 if (TREE_CODE (TREE_TYPE (TREE_TYPE (t
))) == ARRAY_TYPE
)
5671 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5673 t
= convert_from_reference (t
);
5675 reference_always_pointer
= false;
5678 else if (REFERENCE_REF_P (t
)
5679 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5682 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
5683 && TREE_CODE (TREE_TYPE (t
)) == POINTER_TYPE
)
5684 k
= GOMP_MAP_ATTACH_DETACH
;
5687 t
= TREE_OPERAND (t
, 0);
5688 k
= (ort
== C_ORT_ACC
5689 ? GOMP_MAP_ATTACH_DETACH
: GOMP_MAP_ALWAYS_POINTER
);
5691 OMP_CLAUSE_SET_MAP_KIND (c2
, k
);
5694 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5695 OMP_CLAUSE_MAP_IMPLICIT (c2
) = OMP_CLAUSE_MAP_IMPLICIT (c
);
5696 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5697 && !cxx_mark_addressable (t
))
5699 OMP_CLAUSE_DECL (c2
) = t
;
5700 t
= build_fold_addr_expr (first
);
5701 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5702 ptrdiff_type_node
, t
);
5703 tree ptr
= OMP_CLAUSE_DECL (c2
);
5704 ptr
= convert_from_reference (ptr
);
5705 if (!INDIRECT_TYPE_P (TREE_TYPE (ptr
)))
5706 ptr
= build_fold_addr_expr (ptr
);
5707 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5708 ptrdiff_type_node
, t
,
5709 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5710 ptrdiff_type_node
, ptr
));
5711 OMP_CLAUSE_SIZE (c2
) = t
;
5712 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5713 OMP_CLAUSE_CHAIN (c
) = c2
;
5715 ptr
= OMP_CLAUSE_DECL (c2
);
5716 if (reference_always_pointer
5717 && OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5718 && TYPE_REF_P (TREE_TYPE (ptr
))
5719 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5721 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5723 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5724 OMP_CLAUSE_MAP_IMPLICIT (c2
) = OMP_CLAUSE_MAP_IMPLICIT (c
);
5725 OMP_CLAUSE_DECL (c3
) = ptr
;
5726 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
5727 || OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ATTACH_DETACH
)
5729 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5730 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5733 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5734 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5735 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5736 OMP_CLAUSE_CHAIN (c2
) = c3
;
5743 /* Return identifier to look up for omp declare reduction. */
5746 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5748 const char *p
= NULL
;
5749 const char *m
= NULL
;
5750 switch (reduction_code
)
5758 case TRUTH_ANDIF_EXPR
:
5759 case TRUTH_ORIF_EXPR
:
5760 reduction_id
= ovl_op_identifier (false, reduction_code
);
5774 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5775 return error_mark_node
;
5776 p
= IDENTIFIER_POINTER (reduction_id
);
5779 if (type
!= NULL_TREE
)
5780 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5782 const char prefix
[] = "omp declare reduction ";
5783 size_t lenp
= sizeof (prefix
);
5784 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5786 size_t len
= strlen (p
);
5787 size_t lenm
= m
? strlen (m
) + 1 : 0;
5788 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5790 memcpy (name
, prefix
, lenp
- 1);
5791 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5794 name
[lenp
+ len
- 1] = '~';
5795 memcpy (name
+ lenp
+ len
, m
, lenm
);
5797 return get_identifier (name
);
5800 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5801 FUNCTION_DECL or NULL_TREE if not found. */
5804 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5805 vec
<tree
> *ambiguousp
)
5808 tree baselink
= NULL_TREE
;
5809 if (identifier_p (id
))
5812 bool nonint_cst_expression_p
;
5813 const char *error_msg
;
5814 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5815 tree decl
= lookup_name (id
);
5816 if (decl
== NULL_TREE
)
5817 decl
= error_mark_node
;
5818 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5819 &nonint_cst_expression_p
, false, true, false,
5820 false, &error_msg
, loc
);
5821 if (idk
== CP_ID_KIND_UNQUALIFIED
5822 && identifier_p (id
))
5824 vec
<tree
, va_gc
> *args
= NULL
;
5825 vec_safe_push (args
, build_reference_type (type
));
5826 id
= perform_koenig_lookup (id
, args
, tf_none
);
5829 else if (TREE_CODE (id
) == SCOPE_REF
)
5830 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5831 omp_reduction_id (ERROR_MARK
,
5832 TREE_OPERAND (id
, 1),
5834 LOOK_want::NORMAL
, false);
5837 if (fns
&& is_overloaded_fn (fns
))
5839 for (lkp_iterator
iter (get_fns (fns
)); iter
; ++iter
)
5841 tree fndecl
= *iter
;
5842 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5844 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5845 if (same_type_p (TREE_TYPE (argtype
), type
))
5853 if (id
&& BASELINK_P (fns
))
5862 if (!id
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5864 auto_vec
<tree
> ambiguous
;
5865 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5867 if (ambiguousp
== NULL
)
5868 ambiguousp
= &ambiguous
;
5869 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5871 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5872 baselinkp
? baselinkp
: &baselink
,
5874 if (id
== NULL_TREE
)
5876 if (!ambiguousp
->is_empty ())
5877 ambiguousp
->safe_push (id
);
5878 else if (ret
!= NULL_TREE
)
5880 ambiguousp
->safe_push (ret
);
5881 ambiguousp
->safe_push (id
);
5887 if (ambiguousp
!= &ambiguous
)
5889 if (!ambiguous
.is_empty ())
5891 const char *str
= _("candidates are:");
5894 error_at (loc
, "user defined reduction lookup is ambiguous");
5895 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5897 inform (DECL_SOURCE_LOCATION (udr
), "%s %#qD", str
, udr
);
5899 str
= get_spaces (str
);
5901 ret
= error_mark_node
;
5902 baselink
= NULL_TREE
;
5907 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5908 id
, id
, tf_warning_or_error
);
5912 /* Helper function for cp_parser_omp_declare_reduction_exprs
5914 Remove CLEANUP_STMT for data (omp_priv variable).
5915 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5919 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5923 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5924 *tp
= CLEANUP_BODY (*tp
);
5925 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5927 tree decl
= DECL_EXPR_DECL (*tp
);
5928 if (!processing_template_decl
5929 && decl
== (tree
) data
5930 && DECL_INITIAL (decl
)
5931 && DECL_INITIAL (decl
) != error_mark_node
)
5933 tree list
= NULL_TREE
;
5934 append_to_statement_list_force (*tp
, &list
);
5935 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5936 decl
, DECL_INITIAL (decl
));
5937 DECL_INITIAL (decl
) = NULL_TREE
;
5938 append_to_statement_list_force (init_expr
, &list
);
5945 /* Data passed from cp_check_omp_declare_reduction to
5946 cp_check_omp_declare_reduction_r. */
5948 struct cp_check_omp_declare_reduction_data
5955 /* Helper function for cp_check_omp_declare_reduction, called via
5959 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5961 struct cp_check_omp_declare_reduction_data
*udr_data
5962 = (struct cp_check_omp_declare_reduction_data
*) data
;
5964 && !DECL_ARTIFICIAL (*tp
)
5965 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5966 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5968 location_t loc
= udr_data
->loc
;
5969 if (udr_data
->combiner_p
)
5970 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5971 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5974 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5975 "to variable %qD which is not %<omp_priv%> nor "
5983 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5986 cp_check_omp_declare_reduction (tree udr
)
5988 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5989 gcc_assert (TYPE_REF_P (type
));
5990 type
= TREE_TYPE (type
);
5992 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5994 if (type
== error_mark_node
)
5996 if (ARITHMETIC_TYPE_P (type
))
5998 static enum tree_code predef_codes
[]
5999 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
6000 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
6001 for (i
= 0; i
< 8; i
++)
6003 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
6004 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
6005 const char *n2
= IDENTIFIER_POINTER (id
);
6006 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
6007 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
6008 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
6013 && TREE_CODE (type
) != COMPLEX_EXPR
)
6015 const char prefix_minmax
[] = "omp declare reduction m";
6016 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
6017 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
6018 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
6019 prefix_minmax
, prefix_size
) == 0
6020 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
6021 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
6022 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
6027 error_at (loc
, "predeclared arithmetic type %qT in "
6028 "%<#pragma omp declare reduction%>", type
);
6032 else if (FUNC_OR_METHOD_TYPE_P (type
)
6033 || TREE_CODE (type
) == ARRAY_TYPE
)
6035 error_at (loc
, "function or array type %qT in "
6036 "%<#pragma omp declare reduction%>", type
);
6039 else if (TYPE_REF_P (type
))
6041 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
6045 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
6047 error_at (loc
, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
6048 "type %qT in %<#pragma omp declare reduction%>", type
);
6052 tree body
= DECL_SAVED_TREE (udr
);
6053 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
6056 tree_stmt_iterator tsi
;
6057 struct cp_check_omp_declare_reduction_data data
;
6058 memset (data
.stmts
, 0, sizeof data
.stmts
);
6059 for (i
= 0, tsi
= tsi_start (body
);
6060 i
< 7 && !tsi_end_p (tsi
);
6061 i
++, tsi_next (&tsi
))
6062 data
.stmts
[i
] = tsi_stmt (tsi
);
6064 gcc_assert (tsi_end_p (tsi
));
6067 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
6068 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
6069 if (warning_suppressed_p (DECL_EXPR_DECL (data
.stmts
[0]) /* What warning? */))
6071 data
.combiner_p
= true;
6072 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
6074 suppress_warning (DECL_EXPR_DECL (data
.stmts
[0]) /* What warning? */);
6078 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
6079 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
6080 data
.combiner_p
= false;
6081 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
6083 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
6084 cp_check_omp_declare_reduction_r
, &data
, NULL
))
6085 suppress_warning (DECL_EXPR_DECL (data
.stmts
[0]) /* Wat warning? */);
6087 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
6092 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
6093 an inline call. But, remap
6094 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
6095 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
6098 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
6099 tree decl
, tree placeholder
)
6102 hash_map
<tree
, tree
> decl_map
;
6104 decl_map
.put (omp_decl1
, placeholder
);
6105 decl_map
.put (omp_decl2
, decl
);
6106 memset (&id
, 0, sizeof (id
));
6107 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
6108 id
.dst_fn
= current_function_decl
;
6109 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
6110 id
.decl_map
= &decl_map
;
6112 id
.copy_decl
= copy_decl_no_change
;
6113 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
6114 id
.transform_new_cfg
= true;
6115 id
.transform_return_to_modify
= false;
6117 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
6121 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
6122 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
6125 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
6127 if (*tp
== (tree
) data
)
6132 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
6133 Return true if there is some error and the clause should be removed. */
6136 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
6138 tree t
= OMP_CLAUSE_DECL (c
);
6139 bool predefined
= false;
6140 if (TREE_CODE (t
) == TREE_LIST
)
6142 gcc_assert (processing_template_decl
);
6145 tree type
= TREE_TYPE (t
);
6146 if (TREE_CODE (t
) == MEM_REF
)
6147 type
= TREE_TYPE (type
);
6148 if (TYPE_REF_P (type
))
6149 type
= TREE_TYPE (type
);
6150 if (TREE_CODE (type
) == ARRAY_TYPE
)
6153 gcc_assert (TREE_CODE (t
) != MEM_REF
);
6154 while (TREE_CODE (type
) == ARRAY_TYPE
)
6155 type
= TREE_TYPE (type
);
6156 if (!processing_template_decl
)
6158 t
= require_complete_type (t
);
6159 if (t
== error_mark_node
6160 || !complete_type_or_else (oatype
, NULL_TREE
))
6162 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
6163 TYPE_SIZE_UNIT (type
));
6164 if (integer_zerop (size
))
6166 error_at (OMP_CLAUSE_LOCATION (c
),
6167 "%qE in %<reduction%> clause is a zero size array",
6168 omp_clause_printable_decl (t
));
6171 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
6172 size
= save_expr (size
);
6173 tree index_type
= build_index_type (size
);
6174 tree atype
= build_array_type (type
, index_type
);
6175 tree ptype
= build_pointer_type (type
);
6176 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6177 t
= build_fold_addr_expr (t
);
6178 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
6179 OMP_CLAUSE_DECL (c
) = t
;
6182 if (type
== error_mark_node
)
6184 else if (ARITHMETIC_TYPE_P (type
))
6185 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
6190 case TRUTH_ANDIF_EXPR
:
6191 case TRUTH_ORIF_EXPR
:
6196 if (TREE_CODE (type
) == COMPLEX_TYPE
)
6203 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
6210 else if (TYPE_READONLY (type
))
6212 error_at (OMP_CLAUSE_LOCATION (c
),
6213 "%qE has const type for %<reduction%>",
6214 omp_clause_printable_decl (t
));
6217 else if (!processing_template_decl
)
6219 t
= require_complete_type (t
);
6220 if (t
== error_mark_node
)
6222 OMP_CLAUSE_DECL (c
) = t
;
6227 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
6230 else if (processing_template_decl
)
6232 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) == error_mark_node
)
6237 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
6239 type
= TYPE_MAIN_VARIANT (type
);
6240 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
6241 if (id
== NULL_TREE
)
6242 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
6243 NULL_TREE
, NULL_TREE
);
6244 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
6247 if (id
== error_mark_node
)
6250 tree body
= DECL_SAVED_TREE (id
);
6253 if (TREE_CODE (body
) == STATEMENT_LIST
)
6255 tree_stmt_iterator tsi
;
6256 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
6259 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
6260 atype
= TREE_TYPE (atype
);
6261 bool need_static_cast
= !same_type_p (type
, atype
);
6262 memset (stmts
, 0, sizeof stmts
);
6263 for (i
= 0, tsi
= tsi_start (body
);
6264 i
< 7 && !tsi_end_p (tsi
);
6265 i
++, tsi_next (&tsi
))
6266 stmts
[i
] = tsi_stmt (tsi
);
6267 gcc_assert (tsi_end_p (tsi
));
6271 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
6272 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
6273 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
6274 DECL_ARTIFICIAL (placeholder
) = 1;
6275 DECL_IGNORED_P (placeholder
) = 1;
6276 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
6277 if (TREE_CODE (t
) == MEM_REF
)
6279 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
6281 DECL_ARTIFICIAL (decl_placeholder
) = 1;
6282 DECL_IGNORED_P (decl_placeholder
) = 1;
6283 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
6285 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
6286 cxx_mark_addressable (placeholder
);
6287 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
6288 && (decl_placeholder
6289 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6290 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6291 : OMP_CLAUSE_DECL (c
));
6292 tree omp_out
= placeholder
;
6293 tree omp_in
= decl_placeholder
? decl_placeholder
6294 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6295 if (need_static_cast
)
6297 tree rtype
= build_reference_type (atype
);
6298 omp_out
= build_static_cast (input_location
,
6300 tf_warning_or_error
);
6301 omp_in
= build_static_cast (input_location
,
6303 tf_warning_or_error
);
6304 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
6306 omp_out
= convert_from_reference (omp_out
);
6307 omp_in
= convert_from_reference (omp_in
);
6309 OMP_CLAUSE_REDUCTION_MERGE (c
)
6310 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
6311 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
6315 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
6316 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
6317 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3]))
6318 && (decl_placeholder
6319 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6320 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6321 : OMP_CLAUSE_DECL (c
));
6322 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
6323 cxx_mark_addressable (placeholder
);
6324 tree omp_priv
= decl_placeholder
? decl_placeholder
6325 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6326 tree omp_orig
= placeholder
;
6327 if (need_static_cast
)
6331 error_at (OMP_CLAUSE_LOCATION (c
),
6332 "user defined reduction with constructor "
6333 "initializer for base class %qT", atype
);
6336 tree rtype
= build_reference_type (atype
);
6337 omp_priv
= build_static_cast (input_location
,
6339 tf_warning_or_error
);
6340 omp_orig
= build_static_cast (input_location
,
6342 tf_warning_or_error
);
6343 if (omp_priv
== error_mark_node
6344 || omp_orig
== error_mark_node
)
6346 omp_priv
= convert_from_reference (omp_priv
);
6347 omp_orig
= convert_from_reference (omp_orig
);
6350 *need_default_ctor
= true;
6351 OMP_CLAUSE_REDUCTION_INIT (c
)
6352 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
6353 DECL_EXPR_DECL (stmts
[3]),
6354 omp_priv
, omp_orig
);
6355 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
6356 find_omp_placeholder_r
, placeholder
, NULL
))
6357 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
6361 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
6362 *need_default_ctor
= true;
6366 tree v
= decl_placeholder
? decl_placeholder
6367 : convert_from_reference (t
);
6368 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
6369 init
= build_constructor (TREE_TYPE (v
), NULL
);
6371 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
6372 OMP_CLAUSE_REDUCTION_INIT (c
)
6373 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
6378 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
6382 error_at (OMP_CLAUSE_LOCATION (c
),
6383 "user defined reduction not found for %qE",
6384 omp_clause_printable_decl (t
));
6387 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
6388 gcc_assert (TYPE_SIZE_UNIT (type
)
6389 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
6393 /* Called from finish_struct_1. linear(this) or linear(this:step)
6394 clauses might not be finalized yet because the class has been incomplete
6395 when parsing #pragma omp declare simd methods. Fix those up now. */
6398 finish_omp_declare_simd_methods (tree t
)
6400 if (processing_template_decl
)
6403 for (tree x
= TYPE_FIELDS (t
); x
; x
= DECL_CHAIN (x
))
6405 if (TREE_CODE (x
) == USING_DECL
6406 || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x
))
6408 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
6409 if (!ods
|| !TREE_VALUE (ods
))
6411 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
6412 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
6413 && integer_zerop (OMP_CLAUSE_DECL (c
))
6414 && OMP_CLAUSE_LINEAR_STEP (c
)
6415 && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
))))
6417 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
6418 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
6419 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
6420 sizetype
, s
, TYPE_SIZE_UNIT (t
));
6421 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
6426 /* Adjust sink depend clause to take into account pointer offsets.
6428 Return TRUE if there was a problem processing the offset, and the
6429 whole clause should be removed. */
6432 cp_finish_omp_clause_depend_sink (tree sink_clause
)
6434 tree t
= OMP_CLAUSE_DECL (sink_clause
);
6435 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
6437 /* Make sure we don't adjust things twice for templates. */
6438 if (processing_template_decl
)
6441 for (; t
; t
= TREE_CHAIN (t
))
6443 tree decl
= TREE_VALUE (t
);
6444 if (TYPE_PTR_P (TREE_TYPE (decl
)))
6446 tree offset
= TREE_PURPOSE (t
);
6447 bool neg
= wi::neg_p (wi::to_wide (offset
));
6448 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
6449 decl
= mark_rvalue_use (decl
);
6450 decl
= convert_from_reference (decl
);
6451 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
6452 neg
? MINUS_EXPR
: PLUS_EXPR
,
6454 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
6455 MINUS_EXPR
, sizetype
,
6456 fold_convert (sizetype
, t2
),
6457 fold_convert (sizetype
, decl
));
6458 if (t2
== error_mark_node
)
6460 TREE_PURPOSE (t
) = t2
;
6466 /* Finish OpenMP iterators ITER. Return true if they are errorneous
6467 and clauses containing them should be removed. */
6470 cp_omp_finish_iterators (tree iter
)
6473 for (tree it
= iter
; it
; it
= TREE_CHAIN (it
))
6475 tree var
= TREE_VEC_ELT (it
, 0);
6476 tree begin
= TREE_VEC_ELT (it
, 1);
6477 tree end
= TREE_VEC_ELT (it
, 2);
6478 tree step
= TREE_VEC_ELT (it
, 3);
6480 tree type
= TREE_TYPE (var
);
6481 location_t loc
= DECL_SOURCE_LOCATION (var
);
6482 if (type
== error_mark_node
)
6487 if (type_dependent_expression_p (var
))
6489 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
6491 error_at (loc
, "iterator %qD has neither integral nor pointer type",
6496 else if (TYPE_READONLY (type
))
6498 error_at (loc
, "iterator %qD has const qualified type", var
);
6502 if (type_dependent_expression_p (begin
)
6503 || type_dependent_expression_p (end
)
6504 || type_dependent_expression_p (step
))
6506 else if (error_operand_p (step
))
6511 else if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
6513 error_at (EXPR_LOC_OR_LOC (step
, loc
),
6514 "iterator step with non-integral type");
6519 begin
= mark_rvalue_use (begin
);
6520 end
= mark_rvalue_use (end
);
6521 step
= mark_rvalue_use (step
);
6522 begin
= cp_build_c_cast (input_location
, type
, begin
,
6523 tf_warning_or_error
);
6524 end
= cp_build_c_cast (input_location
, type
, end
,
6525 tf_warning_or_error
);
6527 if (!processing_template_decl
)
6528 step
= orig_step
= save_expr (step
);
6529 tree stype
= POINTER_TYPE_P (type
) ? sizetype
: type
;
6530 step
= cp_build_c_cast (input_location
, stype
, step
,
6531 tf_warning_or_error
);
6532 if (POINTER_TYPE_P (type
) && !processing_template_decl
)
6534 begin
= save_expr (begin
);
6535 step
= pointer_int_sum (loc
, PLUS_EXPR
, begin
, step
);
6536 step
= fold_build2_loc (loc
, MINUS_EXPR
, sizetype
,
6537 fold_convert (sizetype
, step
),
6538 fold_convert (sizetype
, begin
));
6539 step
= fold_convert (ssizetype
, step
);
6541 if (!processing_template_decl
)
6543 begin
= maybe_constant_value (begin
);
6544 end
= maybe_constant_value (end
);
6545 step
= maybe_constant_value (step
);
6546 orig_step
= maybe_constant_value (orig_step
);
6548 if (integer_zerop (step
))
6550 error_at (loc
, "iterator %qD has zero step", var
);
6555 if (begin
== error_mark_node
6556 || end
== error_mark_node
6557 || step
== error_mark_node
6558 || orig_step
== error_mark_node
)
6564 if (!processing_template_decl
)
6566 begin
= fold_build_cleanup_point_expr (TREE_TYPE (begin
), begin
);
6567 end
= fold_build_cleanup_point_expr (TREE_TYPE (end
), end
);
6568 step
= fold_build_cleanup_point_expr (TREE_TYPE (step
), step
);
6569 orig_step
= fold_build_cleanup_point_expr (TREE_TYPE (orig_step
),
6572 hash_set
<tree
> pset
;
6574 for (it2
= TREE_CHAIN (it
); it2
; it2
= TREE_CHAIN (it2
))
6576 tree var2
= TREE_VEC_ELT (it2
, 0);
6577 tree begin2
= TREE_VEC_ELT (it2
, 1);
6578 tree end2
= TREE_VEC_ELT (it2
, 2);
6579 tree step2
= TREE_VEC_ELT (it2
, 3);
6580 location_t loc2
= DECL_SOURCE_LOCATION (var2
);
6581 if (cp_walk_tree (&begin2
, find_omp_placeholder_r
, var
, &pset
))
6583 error_at (EXPR_LOC_OR_LOC (begin2
, loc2
),
6584 "begin expression refers to outer iterator %qD", var
);
6587 else if (cp_walk_tree (&end2
, find_omp_placeholder_r
, var
, &pset
))
6589 error_at (EXPR_LOC_OR_LOC (end2
, loc2
),
6590 "end expression refers to outer iterator %qD", var
);
6593 else if (cp_walk_tree (&step2
, find_omp_placeholder_r
, var
, &pset
))
6595 error_at (EXPR_LOC_OR_LOC (step2
, loc2
),
6596 "step expression refers to outer iterator %qD", var
);
6605 TREE_VEC_ELT (it
, 1) = begin
;
6606 TREE_VEC_ELT (it
, 2) = end
;
6607 if (processing_template_decl
)
6608 TREE_VEC_ELT (it
, 3) = orig_step
;
6611 TREE_VEC_ELT (it
, 3) = step
;
6612 TREE_VEC_ELT (it
, 4) = orig_step
;
6618 /* Ensure that pointers are used in OpenACC attach and detach clauses.
6619 Return true if an error has been detected. */
6622 cp_oacc_check_attachments (tree c
)
6624 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6627 /* OpenACC attach / detach clauses must be pointers. */
6628 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
6629 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
)
6631 tree t
= OMP_CLAUSE_DECL (c
);
6634 while (TREE_CODE (t
) == TREE_LIST
)
6637 type
= TREE_TYPE (t
);
6639 if (TREE_CODE (type
) == REFERENCE_TYPE
)
6640 type
= TREE_TYPE (type
);
6642 if (TREE_CODE (type
) != POINTER_TYPE
)
6644 error_at (OMP_CLAUSE_LOCATION (c
), "expected pointer in %qs clause",
6645 c_omp_map_clause_name (c
, true));
6653 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
6654 Remove any elements from the list that are invalid. */
6657 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
6659 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
6660 bitmap_head aligned_head
, map_head
, map_field_head
, map_firstprivate_head
;
6661 bitmap_head oacc_reduction_head
;
6663 tree safelen
= NULL_TREE
;
6664 bool branch_seen
= false;
6665 bool copyprivate_seen
= false;
6666 bool ordered_seen
= false;
6667 bool order_seen
= false;
6668 bool schedule_seen
= false;
6669 bool oacc_async
= false;
6670 bool indir_component_ref_p
= false;
6671 tree last_iterators
= NULL_TREE
;
6672 bool last_iterators_remove
= false;
6673 /* 1 if normal/task reduction has been seen, -1 if inscan reduction
6674 has been seen, -2 if mixed inscan/normal reduction diagnosed. */
6675 int reduction_seen
= 0;
6676 bool allocate_seen
= false;
6677 tree detach_seen
= NULL_TREE
;
6678 bool mergeable_seen
= false;
6679 bool implicit_moved
= false;
6680 bool target_in_reduction_seen
= false;
6682 bitmap_obstack_initialize (NULL
);
6683 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
6684 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
6685 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
6686 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
6687 /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
6688 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
6689 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
6690 bitmap_initialize (&map_firstprivate_head
, &bitmap_default_obstack
);
6691 /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
6692 instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
6693 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
6695 if (ort
& C_ORT_ACC
)
6696 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6697 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
6703 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
6705 bool remove
= false;
6706 bool field_ok
= false;
6708 switch (OMP_CLAUSE_CODE (c
))
6710 case OMP_CLAUSE_SHARED
:
6711 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6712 goto check_dup_generic
;
6713 case OMP_CLAUSE_PRIVATE
:
6714 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6715 goto check_dup_generic
;
6716 case OMP_CLAUSE_REDUCTION
:
6717 if (reduction_seen
== 0)
6718 reduction_seen
= OMP_CLAUSE_REDUCTION_INSCAN (c
) ? -1 : 1;
6719 else if (reduction_seen
!= -2
6720 && reduction_seen
!= (OMP_CLAUSE_REDUCTION_INSCAN (c
)
6723 error_at (OMP_CLAUSE_LOCATION (c
),
6724 "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
6725 "on the same construct");
6726 reduction_seen
= -2;
6729 case OMP_CLAUSE_IN_REDUCTION
:
6730 case OMP_CLAUSE_TASK_REDUCTION
:
6731 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6732 t
= OMP_CLAUSE_DECL (c
);
6733 if (TREE_CODE (t
) == TREE_LIST
)
6735 if (handle_omp_array_sections (c
, ort
))
6740 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6741 && OMP_CLAUSE_REDUCTION_INSCAN (c
))
6743 error_at (OMP_CLAUSE_LOCATION (c
),
6744 "%<inscan%> %<reduction%> clause with array "
6749 if (TREE_CODE (t
) == TREE_LIST
)
6751 while (TREE_CODE (t
) == TREE_LIST
)
6756 gcc_assert (TREE_CODE (t
) == MEM_REF
);
6757 t
= TREE_OPERAND (t
, 0);
6758 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
6759 t
= TREE_OPERAND (t
, 0);
6760 if (TREE_CODE (t
) == ADDR_EXPR
6761 || INDIRECT_REF_P (t
))
6762 t
= TREE_OPERAND (t
, 0);
6764 tree n
= omp_clause_decl_field (t
);
6767 goto check_dup_generic_t
;
6770 cxx_mark_addressable (t
);
6771 goto check_dup_generic
;
6772 case OMP_CLAUSE_COPYPRIVATE
:
6773 copyprivate_seen
= true;
6774 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6775 goto check_dup_generic
;
6776 case OMP_CLAUSE_COPYIN
:
6777 goto check_dup_generic
;
6778 case OMP_CLAUSE_LINEAR
:
6779 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6780 t
= OMP_CLAUSE_DECL (c
);
6781 if (ort
!= C_ORT_OMP_DECLARE_SIMD
6782 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
6784 error_at (OMP_CLAUSE_LOCATION (c
),
6785 "modifier should not be specified in %<linear%> "
6786 "clause on %<simd%> or %<for%> constructs");
6787 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
6789 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6790 && !type_dependent_expression_p (t
))
6792 tree type
= TREE_TYPE (t
);
6793 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6794 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
6795 && !TYPE_REF_P (type
))
6797 error_at (OMP_CLAUSE_LOCATION (c
),
6798 "linear clause with %qs modifier applied to "
6799 "non-reference variable with %qT type",
6800 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6801 ? "ref" : "uval", TREE_TYPE (t
));
6805 if (TYPE_REF_P (type
))
6806 type
= TREE_TYPE (type
);
6807 if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
6809 if (!INTEGRAL_TYPE_P (type
)
6810 && !TYPE_PTR_P (type
))
6812 error_at (OMP_CLAUSE_LOCATION (c
),
6813 "linear clause applied to non-integral "
6814 "non-pointer variable with %qT type",
6821 t
= OMP_CLAUSE_LINEAR_STEP (c
);
6823 t
= integer_one_node
;
6824 if (t
== error_mark_node
)
6829 else if (!type_dependent_expression_p (t
)
6830 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
6831 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6832 || TREE_CODE (t
) != PARM_DECL
6833 || !TYPE_REF_P (TREE_TYPE (t
))
6834 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
6836 error_at (OMP_CLAUSE_LOCATION (c
),
6837 "linear step expression must be integral");
6843 t
= mark_rvalue_use (t
);
6844 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
6846 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
6847 goto check_dup_generic
;
6849 if (!processing_template_decl
6850 && (VAR_P (OMP_CLAUSE_DECL (c
))
6851 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
6853 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
6855 t
= maybe_constant_value (t
);
6856 if (TREE_CODE (t
) != INTEGER_CST
)
6858 error_at (OMP_CLAUSE_LOCATION (c
),
6859 "%<linear%> clause step %qE is neither "
6860 "constant nor a parameter", t
);
6865 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6866 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
6867 if (TYPE_REF_P (type
))
6868 type
= TREE_TYPE (type
);
6869 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
6871 type
= build_pointer_type (type
);
6872 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
6873 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6875 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6876 MINUS_EXPR
, sizetype
,
6877 fold_convert (sizetype
, t
),
6878 fold_convert (sizetype
, d
));
6879 if (t
== error_mark_node
)
6885 else if (TYPE_PTR_P (type
)
6886 /* Can't multiply the step yet if *this
6887 is still incomplete type. */
6888 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6889 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
6890 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
6891 || DECL_NAME (OMP_CLAUSE_DECL (c
))
6893 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
6895 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
6896 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6898 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6899 MINUS_EXPR
, sizetype
,
6900 fold_convert (sizetype
, t
),
6901 fold_convert (sizetype
, d
));
6902 if (t
== error_mark_node
)
6909 t
= fold_convert (type
, t
);
6911 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6913 goto check_dup_generic
;
6915 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6918 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6919 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6922 t
= OMP_CLAUSE_DECL (c
);
6923 check_dup_generic_t
:
6924 if (t
== current_class_ptr
6925 && ((ort
!= C_ORT_OMP_DECLARE_SIMD
&& ort
!= C_ORT_ACC
)
6926 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6927 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6929 error_at (OMP_CLAUSE_LOCATION (c
),
6930 "%<this%> allowed in OpenMP only in %<declare simd%>"
6935 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6936 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6938 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6941 error_at (OMP_CLAUSE_LOCATION (c
),
6942 "%qD is not a variable in clause %qs", t
,
6943 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6945 error_at (OMP_CLAUSE_LOCATION (c
),
6946 "%qE is not a variable in clause %qs", t
,
6947 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6950 else if ((ort
== C_ORT_ACC
6951 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
6952 || (ort
== C_ORT_OMP
6953 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
6954 || (OMP_CLAUSE_CODE (c
)
6955 == OMP_CLAUSE_USE_DEVICE_ADDR
)))
6956 || (ort
== C_ORT_OMP_TARGET
6957 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
))
6959 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
6960 && (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6961 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))))
6963 error_at (OMP_CLAUSE_LOCATION (c
),
6964 "%qD appears more than once in data-sharing "
6969 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
)
6970 target_in_reduction_seen
= true;
6971 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
6973 error_at (OMP_CLAUSE_LOCATION (c
),
6975 ? "%qD appears more than once in reduction clauses"
6976 : "%qD appears more than once in data clauses",
6981 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
6983 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6984 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6985 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
))
6986 || bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
6988 error_at (OMP_CLAUSE_LOCATION (c
),
6989 "%qD appears more than once in data clauses", t
);
6992 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6993 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6995 if (ort
== C_ORT_ACC
)
6996 error_at (OMP_CLAUSE_LOCATION (c
),
6997 "%qD appears more than once in data clauses", t
);
6999 error_at (OMP_CLAUSE_LOCATION (c
),
7000 "%qD appears both in data and map clauses", t
);
7004 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7009 && TREE_CODE (t
) == FIELD_DECL
7010 && t
== OMP_CLAUSE_DECL (c
))
7013 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
7014 == OMP_CLAUSE_SHARED
));
7015 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
7020 case OMP_CLAUSE_FIRSTPRIVATE
:
7021 if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
) && !implicit_moved
)
7024 implicit_moved
= true;
7025 /* Move firstprivate and map clauses with
7026 OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
7028 tree cl1
= NULL_TREE
, cl2
= NULL_TREE
;
7029 tree
*pc1
= pc
, *pc2
= &cl1
, *pc3
= &cl2
;
7031 if (OMP_CLAUSE_CODE (*pc1
) == OMP_CLAUSE_FIRSTPRIVATE
7032 && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1
))
7035 pc3
= &OMP_CLAUSE_CHAIN (*pc3
);
7036 *pc1
= OMP_CLAUSE_CHAIN (*pc1
);
7038 else if (OMP_CLAUSE_CODE (*pc1
) == OMP_CLAUSE_MAP
7039 && OMP_CLAUSE_MAP_IMPLICIT (*pc1
))
7042 pc2
= &OMP_CLAUSE_CHAIN (*pc2
);
7043 *pc1
= OMP_CLAUSE_CHAIN (*pc1
);
7046 pc1
= &OMP_CLAUSE_CHAIN (*pc1
);
7052 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7054 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7056 t
= OMP_CLAUSE_DECL (c
);
7057 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7059 error_at (OMP_CLAUSE_LOCATION (c
),
7060 "%<this%> allowed in OpenMP only in %<declare simd%>"
7065 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
7066 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
7067 || TREE_CODE (t
) != FIELD_DECL
))
7069 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7072 error_at (OMP_CLAUSE_LOCATION (c
),
7073 "%qD is not a variable in clause %<firstprivate%>",
7076 error_at (OMP_CLAUSE_LOCATION (c
),
7077 "%qE is not a variable in clause %<firstprivate%>",
7081 else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
)
7082 && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c
)
7083 && bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
7085 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7086 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
7087 || bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
7089 error_at (OMP_CLAUSE_LOCATION (c
),
7090 "%qD appears more than once in data clauses", t
);
7093 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7095 if (ort
== C_ORT_ACC
)
7096 error_at (OMP_CLAUSE_LOCATION (c
),
7097 "%qD appears more than once in data clauses", t
);
7098 else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
)
7099 && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c
))
7100 /* Silently drop the clause. */;
7102 error_at (OMP_CLAUSE_LOCATION (c
),
7103 "%qD appears both in data and map clauses", t
);
7107 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
7108 goto handle_field_decl
;
7110 case OMP_CLAUSE_LASTPRIVATE
:
7111 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7113 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7115 t
= OMP_CLAUSE_DECL (c
);
7116 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7118 error_at (OMP_CLAUSE_LOCATION (c
),
7119 "%<this%> allowed in OpenMP only in %<declare simd%>"
7124 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
7125 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
7126 || TREE_CODE (t
) != FIELD_DECL
))
7128 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7131 error_at (OMP_CLAUSE_LOCATION (c
),
7132 "%qD is not a variable in clause %<lastprivate%>",
7135 error_at (OMP_CLAUSE_LOCATION (c
),
7136 "%qE is not a variable in clause %<lastprivate%>",
7140 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7141 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
7143 error_at (OMP_CLAUSE_LOCATION (c
),
7144 "%qD appears more than once in data clauses", t
);
7148 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
7149 goto handle_field_decl
;
7152 t
= OMP_CLAUSE_IF_EXPR (c
);
7153 t
= maybe_convert_cond (t
);
7154 if (t
== error_mark_node
)
7156 else if (!processing_template_decl
)
7157 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7158 OMP_CLAUSE_IF_EXPR (c
) = t
;
7161 case OMP_CLAUSE_FINAL
:
7162 t
= OMP_CLAUSE_FINAL_EXPR (c
);
7163 t
= maybe_convert_cond (t
);
7164 if (t
== error_mark_node
)
7166 else if (!processing_template_decl
)
7167 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7168 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
7171 case OMP_CLAUSE_GANG
:
7172 /* Operand 1 is the gang static: argument. */
7173 t
= OMP_CLAUSE_OPERAND (c
, 1);
7176 if (t
== error_mark_node
)
7178 else if (!type_dependent_expression_p (t
)
7179 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7181 error_at (OMP_CLAUSE_LOCATION (c
),
7182 "%<gang%> static expression must be integral");
7187 t
= mark_rvalue_use (t
);
7188 if (!processing_template_decl
)
7190 t
= maybe_constant_value (t
);
7191 if (TREE_CODE (t
) == INTEGER_CST
7192 && tree_int_cst_sgn (t
) != 1
7193 && t
!= integer_minus_one_node
)
7195 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7196 "%<gang%> static value must be "
7198 t
= integer_one_node
;
7200 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7203 OMP_CLAUSE_OPERAND (c
, 1) = t
;
7205 /* Check operand 0, the num argument. */
7208 case OMP_CLAUSE_WORKER
:
7209 case OMP_CLAUSE_VECTOR
:
7210 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
7214 case OMP_CLAUSE_NUM_TASKS
:
7215 case OMP_CLAUSE_NUM_TEAMS
:
7216 case OMP_CLAUSE_NUM_THREADS
:
7217 case OMP_CLAUSE_NUM_GANGS
:
7218 case OMP_CLAUSE_NUM_WORKERS
:
7219 case OMP_CLAUSE_VECTOR_LENGTH
:
7220 t
= OMP_CLAUSE_OPERAND (c
, 0);
7221 if (t
== error_mark_node
)
7223 else if (!type_dependent_expression_p (t
)
7224 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7226 switch (OMP_CLAUSE_CODE (c
))
7228 case OMP_CLAUSE_GANG
:
7229 error_at (OMP_CLAUSE_LOCATION (c
),
7230 "%<gang%> num expression must be integral"); break;
7231 case OMP_CLAUSE_VECTOR
:
7232 error_at (OMP_CLAUSE_LOCATION (c
),
7233 "%<vector%> length expression must be integral");
7235 case OMP_CLAUSE_WORKER
:
7236 error_at (OMP_CLAUSE_LOCATION (c
),
7237 "%<worker%> num expression must be integral");
7240 error_at (OMP_CLAUSE_LOCATION (c
),
7241 "%qs expression must be integral",
7242 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7248 t
= mark_rvalue_use (t
);
7249 if (!processing_template_decl
)
7251 t
= maybe_constant_value (t
);
7252 if (TREE_CODE (t
) == INTEGER_CST
7253 && tree_int_cst_sgn (t
) != 1)
7255 switch (OMP_CLAUSE_CODE (c
))
7257 case OMP_CLAUSE_GANG
:
7258 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7259 "%<gang%> num value must be positive");
7261 case OMP_CLAUSE_VECTOR
:
7262 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7263 "%<vector%> length value must be "
7266 case OMP_CLAUSE_WORKER
:
7267 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7268 "%<worker%> num value must be "
7272 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7273 "%qs value must be positive",
7274 omp_clause_code_name
7275 [OMP_CLAUSE_CODE (c
)]);
7277 t
= integer_one_node
;
7279 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7281 OMP_CLAUSE_OPERAND (c
, 0) = t
;
7283 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
7284 && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c
)
7287 t
= OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c
);
7288 if (t
== error_mark_node
)
7290 else if (!type_dependent_expression_p (t
)
7291 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7293 error_at (OMP_CLAUSE_LOCATION (c
),
7294 "%qs expression must be integral",
7295 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7300 t
= mark_rvalue_use (t
);
7301 if (!processing_template_decl
)
7303 t
= maybe_constant_value (t
);
7304 if (TREE_CODE (t
) == INTEGER_CST
7305 && tree_int_cst_sgn (t
) != 1)
7307 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7308 "%qs value must be positive",
7309 omp_clause_code_name
7310 [OMP_CLAUSE_CODE (c
)]);
7314 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7315 tree upper
= OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c
);
7317 && TREE_CODE (t
) == INTEGER_CST
7318 && TREE_CODE (upper
) == INTEGER_CST
7319 && tree_int_cst_lt (upper
, t
))
7321 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7322 "%<num_teams%> lower bound %qE bigger "
7323 "than upper bound %qE", t
, upper
);
7327 OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c
) = t
;
7332 case OMP_CLAUSE_SCHEDULE
:
7333 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
7336 else if (t
== error_mark_node
)
7338 else if (!type_dependent_expression_p (t
)
7339 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7341 error_at (OMP_CLAUSE_LOCATION (c
),
7342 "schedule chunk size expression must be integral");
7347 t
= mark_rvalue_use (t
);
7348 if (!processing_template_decl
)
7350 t
= maybe_constant_value (t
);
7351 if (TREE_CODE (t
) == INTEGER_CST
7352 && tree_int_cst_sgn (t
) != 1)
7354 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7355 "chunk size value must be positive");
7356 t
= integer_one_node
;
7358 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7360 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7363 schedule_seen
= true;
7366 case OMP_CLAUSE_SIMDLEN
:
7367 case OMP_CLAUSE_SAFELEN
:
7368 t
= OMP_CLAUSE_OPERAND (c
, 0);
7369 if (t
== error_mark_node
)
7371 else if (!type_dependent_expression_p (t
)
7372 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7374 error_at (OMP_CLAUSE_LOCATION (c
),
7375 "%qs length expression must be integral",
7376 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7381 t
= mark_rvalue_use (t
);
7382 if (!processing_template_decl
)
7384 t
= maybe_constant_value (t
);
7385 if (TREE_CODE (t
) != INTEGER_CST
7386 || tree_int_cst_sgn (t
) != 1)
7388 error_at (OMP_CLAUSE_LOCATION (c
),
7389 "%qs length expression must be positive "
7390 "constant integer expression",
7391 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7395 OMP_CLAUSE_OPERAND (c
, 0) = t
;
7396 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
7401 case OMP_CLAUSE_ASYNC
:
7402 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
7403 if (t
== error_mark_node
)
7405 else if (!type_dependent_expression_p (t
)
7406 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7408 error_at (OMP_CLAUSE_LOCATION (c
),
7409 "%<async%> expression must be integral");
7414 t
= mark_rvalue_use (t
);
7415 if (!processing_template_decl
)
7416 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7417 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
7421 case OMP_CLAUSE_WAIT
:
7422 t
= OMP_CLAUSE_WAIT_EXPR (c
);
7423 if (t
== error_mark_node
)
7425 else if (!processing_template_decl
)
7426 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7427 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
7430 case OMP_CLAUSE_THREAD_LIMIT
:
7431 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
7432 if (t
== error_mark_node
)
7434 else if (!type_dependent_expression_p (t
)
7435 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7437 error_at (OMP_CLAUSE_LOCATION (c
),
7438 "%<thread_limit%> expression must be integral");
7443 t
= mark_rvalue_use (t
);
7444 if (!processing_template_decl
)
7446 t
= maybe_constant_value (t
);
7447 if (TREE_CODE (t
) == INTEGER_CST
7448 && tree_int_cst_sgn (t
) != 1)
7450 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7451 "%<thread_limit%> value must be positive");
7452 t
= integer_one_node
;
7454 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7456 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
7460 case OMP_CLAUSE_DEVICE
:
7461 t
= OMP_CLAUSE_DEVICE_ID (c
);
7462 if (t
== error_mark_node
)
7464 else if (!type_dependent_expression_p (t
)
7465 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7467 error_at (OMP_CLAUSE_LOCATION (c
),
7468 "%<device%> id must be integral");
7471 else if (OMP_CLAUSE_DEVICE_ANCESTOR (c
)
7472 && TREE_CODE (t
) == INTEGER_CST
7473 && !integer_onep (t
))
7475 error_at (OMP_CLAUSE_LOCATION (c
),
7476 "the %<device%> clause expression must evaluate to "
7482 t
= mark_rvalue_use (t
);
7483 if (!processing_template_decl
)
7484 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7485 OMP_CLAUSE_DEVICE_ID (c
) = t
;
7489 case OMP_CLAUSE_DIST_SCHEDULE
:
7490 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
7493 else if (t
== error_mark_node
)
7495 else if (!type_dependent_expression_p (t
)
7496 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7498 error_at (OMP_CLAUSE_LOCATION (c
),
7499 "%<dist_schedule%> chunk size expression must be "
7505 t
= mark_rvalue_use (t
);
7506 if (!processing_template_decl
)
7507 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7508 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
7512 case OMP_CLAUSE_ALIGNED
:
7513 t
= OMP_CLAUSE_DECL (c
);
7514 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
7516 error_at (OMP_CLAUSE_LOCATION (c
),
7517 "%<this%> allowed in OpenMP only in %<declare simd%>"
7522 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7524 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7527 error_at (OMP_CLAUSE_LOCATION (c
),
7528 "%qD is not a variable in %<aligned%> clause", t
);
7530 error_at (OMP_CLAUSE_LOCATION (c
),
7531 "%qE is not a variable in %<aligned%> clause", t
);
7534 else if (!type_dependent_expression_p (t
)
7535 && !TYPE_PTR_P (TREE_TYPE (t
))
7536 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
7537 && (!TYPE_REF_P (TREE_TYPE (t
))
7538 || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
7539 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
7542 error_at (OMP_CLAUSE_LOCATION (c
),
7543 "%qE in %<aligned%> clause is neither a pointer nor "
7544 "an array nor a reference to pointer or array", t
);
7547 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7549 error_at (OMP_CLAUSE_LOCATION (c
),
7550 "%qD appears more than once in %<aligned%> clauses",
7555 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
7556 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
7557 if (t
== error_mark_node
)
7559 else if (t
== NULL_TREE
)
7561 else if (!type_dependent_expression_p (t
)
7562 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7564 error_at (OMP_CLAUSE_LOCATION (c
),
7565 "%<aligned%> clause alignment expression must "
7571 t
= mark_rvalue_use (t
);
7572 if (!processing_template_decl
)
7574 t
= maybe_constant_value (t
);
7575 if (TREE_CODE (t
) != INTEGER_CST
7576 || tree_int_cst_sgn (t
) != 1)
7578 error_at (OMP_CLAUSE_LOCATION (c
),
7579 "%<aligned%> clause alignment expression must "
7580 "be positive constant integer expression");
7584 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7586 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
7590 case OMP_CLAUSE_NONTEMPORAL
:
7591 t
= OMP_CLAUSE_DECL (c
);
7592 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7594 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7597 error_at (OMP_CLAUSE_LOCATION (c
),
7598 "%qD is not a variable in %<nontemporal%> clause",
7601 error_at (OMP_CLAUSE_LOCATION (c
),
7602 "%qE is not a variable in %<nontemporal%> clause",
7606 else if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
7608 error_at (OMP_CLAUSE_LOCATION (c
),
7609 "%qD appears more than once in %<nontemporal%> "
7614 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
7617 case OMP_CLAUSE_ALLOCATE
:
7618 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7620 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7622 t
= OMP_CLAUSE_DECL (c
);
7623 if (t
== current_class_ptr
)
7625 error_at (OMP_CLAUSE_LOCATION (c
),
7626 "%<this%> not allowed in %<allocate%> clause");
7631 && TREE_CODE (t
) != PARM_DECL
7632 && TREE_CODE (t
) != FIELD_DECL
)
7634 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7637 error_at (OMP_CLAUSE_LOCATION (c
),
7638 "%qD is not a variable in %<allocate%> clause", t
);
7640 error_at (OMP_CLAUSE_LOCATION (c
),
7641 "%qE is not a variable in %<allocate%> clause", t
);
7644 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7646 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7647 "%qD appears more than once in %<allocate%> clauses",
7653 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
7654 allocate_seen
= true;
7656 tree allocator
, align
;
7657 align
= OMP_CLAUSE_ALLOCATE_ALIGN (c
);
7658 if (error_operand_p (align
))
7665 if (!type_dependent_expression_p (align
)
7666 && !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
7668 error_at (OMP_CLAUSE_LOCATION (c
),
7669 "%<allocate%> clause %<align%> modifier "
7670 "argument needs to be positive constant "
7671 "power of two integer expression");
7676 align
= mark_rvalue_use (align
);
7677 if (!processing_template_decl
)
7679 align
= maybe_constant_value (align
);
7680 if (TREE_CODE (align
) != INTEGER_CST
7681 || !tree_fits_uhwi_p (align
)
7682 || !integer_pow2p (align
))
7684 error_at (OMP_CLAUSE_LOCATION (c
),
7685 "%<allocate%> clause %<align%> modifier "
7686 "argument needs to be positive constant "
7687 "power of two integer expression");
7692 OMP_CLAUSE_ALLOCATE_ALIGN (c
) = align
;
7694 allocator
= OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
);
7695 if (error_operand_p (allocator
))
7700 if (allocator
== NULL_TREE
)
7701 goto handle_field_decl
;
7703 allocatort
= TYPE_MAIN_VARIANT (TREE_TYPE (allocator
));
7704 if (!type_dependent_expression_p (allocator
)
7705 && (TREE_CODE (allocatort
) != ENUMERAL_TYPE
7706 || TYPE_NAME (allocatort
) == NULL_TREE
7707 || TREE_CODE (TYPE_NAME (allocatort
)) != TYPE_DECL
7708 || (DECL_NAME (TYPE_NAME (allocatort
))
7709 != get_identifier ("omp_allocator_handle_t"))
7710 || (TYPE_CONTEXT (allocatort
)
7711 != DECL_CONTEXT (global_namespace
))))
7713 error_at (OMP_CLAUSE_LOCATION (c
),
7714 "%<allocate%> clause allocator expression has "
7715 "type %qT rather than %<omp_allocator_handle_t%>",
7716 TREE_TYPE (allocator
));
7722 allocator
= mark_rvalue_use (allocator
);
7723 if (!processing_template_decl
)
7724 allocator
= maybe_constant_value (allocator
);
7725 OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
) = allocator
;
7727 goto handle_field_decl
;
7729 case OMP_CLAUSE_DEPEND
:
7730 t
= OMP_CLAUSE_DECL (c
);
7733 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
7734 == OMP_CLAUSE_DEPEND_SOURCE
);
7737 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
7739 if (cp_finish_omp_clause_depend_sink (c
))
7744 case OMP_CLAUSE_AFFINITY
:
7745 t
= OMP_CLAUSE_DECL (c
);
7746 if (TREE_CODE (t
) == TREE_LIST
7748 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
7750 if (TREE_PURPOSE (t
) != last_iterators
)
7751 last_iterators_remove
7752 = cp_omp_finish_iterators (TREE_PURPOSE (t
));
7753 last_iterators
= TREE_PURPOSE (t
);
7755 if (last_iterators_remove
)
7756 t
= error_mark_node
;
7759 last_iterators
= NULL_TREE
;
7761 if (TREE_CODE (t
) == TREE_LIST
)
7763 if (handle_omp_array_sections (c
, ort
))
7765 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
7766 && (OMP_CLAUSE_DEPEND_KIND (c
)
7767 == OMP_CLAUSE_DEPEND_DEPOBJ
))
7769 error_at (OMP_CLAUSE_LOCATION (c
),
7770 "%<depend%> clause with %<depobj%> dependence "
7771 "type on array section");
7776 if (t
== error_mark_node
)
7778 else if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7780 else if (!lvalue_p (t
))
7783 error_at (OMP_CLAUSE_LOCATION (c
),
7784 "%qD is not lvalue expression nor array section "
7786 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7788 error_at (OMP_CLAUSE_LOCATION (c
),
7789 "%qE is not lvalue expression nor array section "
7791 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7794 else if (TREE_CODE (t
) == COMPONENT_REF
7795 && TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7796 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7798 error_at (OMP_CLAUSE_LOCATION (c
),
7799 "bit-field %qE in %qs clause", t
,
7800 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7803 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
7804 && OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7806 if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7807 ? TREE_TYPE (TREE_TYPE (t
))
7810 error_at (OMP_CLAUSE_LOCATION (c
),
7811 "%qE does not have %<omp_depend_t%> type in "
7812 "%<depend%> clause with %<depobj%> dependence "
7817 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
7818 && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7819 ? TREE_TYPE (TREE_TYPE (t
))
7822 error_at (OMP_CLAUSE_LOCATION (c
),
7823 "%qE should not have %<omp_depend_t%> type in "
7824 "%<depend%> clause with dependence type other than "
7830 tree addr
= cp_build_addr_expr (t
, tf_warning_or_error
);
7831 if (addr
== error_mark_node
)
7835 t
= cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c
),
7836 addr
, RO_UNARY_STAR
,
7837 tf_warning_or_error
);
7838 if (t
== error_mark_node
)
7840 else if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == TREE_LIST
7841 && TREE_PURPOSE (OMP_CLAUSE_DECL (c
))
7842 && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c
)))
7844 TREE_VALUE (OMP_CLAUSE_DECL (c
)) = t
;
7846 OMP_CLAUSE_DECL (c
) = t
;
7850 case OMP_CLAUSE_DETACH
:
7851 t
= OMP_CLAUSE_DECL (c
);
7854 error_at (OMP_CLAUSE_LOCATION (c
),
7855 "too many %qs clauses on a task construct",
7860 else if (error_operand_p (t
))
7867 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
7868 if (!type_dependent_expression_p (t
)
7869 && (!INTEGRAL_TYPE_P (type
)
7870 || TREE_CODE (type
) != ENUMERAL_TYPE
7871 || TYPE_NAME (type
) == NULL_TREE
7872 || (DECL_NAME (TYPE_NAME (type
))
7873 != get_identifier ("omp_event_handle_t"))))
7875 error_at (OMP_CLAUSE_LOCATION (c
),
7876 "%<detach%> clause event handle "
7877 "has type %qT rather than "
7878 "%<omp_event_handle_t%>",
7883 cxx_mark_addressable (t
);
7887 case OMP_CLAUSE_MAP
:
7888 if (OMP_CLAUSE_MAP_IMPLICIT (c
) && !implicit_moved
)
7892 case OMP_CLAUSE_FROM
:
7893 case OMP_CLAUSE__CACHE_
:
7894 t
= OMP_CLAUSE_DECL (c
);
7895 if (TREE_CODE (t
) == TREE_LIST
)
7897 if (handle_omp_array_sections (c
, ort
))
7901 t
= OMP_CLAUSE_DECL (c
);
7902 if (TREE_CODE (t
) != TREE_LIST
7903 && !type_dependent_expression_p (t
)
7904 && !cp_omp_mappable_type (TREE_TYPE (t
)))
7906 error_at (OMP_CLAUSE_LOCATION (c
),
7907 "array section does not have mappable type "
7909 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7910 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7913 while (TREE_CODE (t
) == ARRAY_REF
)
7914 t
= TREE_OPERAND (t
, 0);
7915 if (TREE_CODE (t
) == COMPONENT_REF
7916 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
7920 t
= TREE_OPERAND (t
, 0);
7921 if (REFERENCE_REF_P (t
))
7922 t
= TREE_OPERAND (t
, 0);
7923 if (TREE_CODE (t
) == MEM_REF
7924 || TREE_CODE (t
) == INDIRECT_REF
)
7926 t
= TREE_OPERAND (t
, 0);
7928 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
7929 t
= TREE_OPERAND (t
, 0);
7932 while (TREE_CODE (t
) == COMPONENT_REF
);
7934 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7935 && OMP_CLAUSE_MAP_IMPLICIT (c
)
7936 && (bitmap_bit_p (&map_head
, DECL_UID (t
))
7937 || bitmap_bit_p (&map_field_head
, DECL_UID (t
))
7938 || bitmap_bit_p (&map_firstprivate_head
,
7944 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7946 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7948 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7949 error_at (OMP_CLAUSE_LOCATION (c
),
7950 "%qD appears more than once in motion"
7952 else if (ort
== C_ORT_ACC
)
7953 error_at (OMP_CLAUSE_LOCATION (c
),
7954 "%qD appears more than once in data"
7957 error_at (OMP_CLAUSE_LOCATION (c
),
7958 "%qD appears more than once in map"
7964 bitmap_set_bit (&map_head
, DECL_UID (t
));
7965 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7969 if (cp_oacc_check_attachments (c
))
7971 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7972 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7973 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7974 /* In this case, we have a single array element which is a
7975 pointer, and we already set OMP_CLAUSE_SIZE in
7976 handle_omp_array_sections above. For attach/detach clauses,
7977 reset the OMP_CLAUSE_SIZE (representing a bias) to zero
7979 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
7982 if (t
== error_mark_node
)
7987 /* OpenACC attach / detach clauses must be pointers. */
7988 if (cp_oacc_check_attachments (c
))
7993 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7994 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7995 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7996 /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
7997 bias) to zero here, so it is not set erroneously to the pointer
7998 size later on in gimplify.c. */
7999 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
8000 if (REFERENCE_REF_P (t
)
8001 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
8003 t
= TREE_OPERAND (t
, 0);
8004 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8005 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_ATTACH_DETACH
)
8006 OMP_CLAUSE_DECL (c
) = t
;
8008 while (TREE_CODE (t
) == INDIRECT_REF
8009 || TREE_CODE (t
) == ARRAY_REF
)
8011 t
= TREE_OPERAND (t
, 0);
8013 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
8014 t
= TREE_OPERAND (t
, 0);
8016 while (TREE_CODE (t
) == COMPOUND_EXPR
)
8018 t
= TREE_OPERAND (t
, 1);
8021 indir_component_ref_p
= false;
8022 if (TREE_CODE (t
) == COMPONENT_REF
8023 && (TREE_CODE (TREE_OPERAND (t
, 0)) == INDIRECT_REF
8024 || TREE_CODE (TREE_OPERAND (t
, 0)) == ARRAY_REF
))
8026 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
8027 indir_component_ref_p
= true;
8029 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
8030 t
= TREE_OPERAND (t
, 0);
8032 if (TREE_CODE (t
) == COMPONENT_REF
8033 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
8035 if (type_dependent_expression_p (t
))
8037 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
8038 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
8040 error_at (OMP_CLAUSE_LOCATION (c
),
8041 "bit-field %qE in %qs clause",
8042 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8045 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
8047 error_at (OMP_CLAUSE_LOCATION (c
),
8048 "%qE does not have a mappable type in %qs clause",
8049 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8050 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
8053 while (TREE_CODE (t
) == COMPONENT_REF
)
8055 if (TREE_TYPE (TREE_OPERAND (t
, 0))
8056 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
8059 error_at (OMP_CLAUSE_LOCATION (c
),
8060 "%qE is a member of a union", t
);
8064 t
= TREE_OPERAND (t
, 0);
8065 if (TREE_CODE (t
) == MEM_REF
)
8067 if (maybe_ne (mem_ref_offset (t
), 0))
8068 error_at (OMP_CLAUSE_LOCATION (c
),
8069 "cannot dereference %qE in %qs clause", t
,
8070 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8072 t
= TREE_OPERAND (t
, 0);
8074 while (TREE_CODE (t
) == MEM_REF
8075 || TREE_CODE (t
) == INDIRECT_REF
8076 || TREE_CODE (t
) == ARRAY_REF
)
8078 t
= TREE_OPERAND (t
, 0);
8080 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
8081 t
= TREE_OPERAND (t
, 0);
8086 if (REFERENCE_REF_P (t
))
8087 t
= TREE_OPERAND (t
, 0);
8088 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
8090 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
))
8091 || (ort
!= C_ORT_ACC
8092 && bitmap_bit_p (&map_head
, DECL_UID (t
))))
8093 goto handle_map_references
;
8096 if (!processing_template_decl
8097 && TREE_CODE (t
) == FIELD_DECL
)
8099 OMP_CLAUSE_DECL (c
) = finish_non_static_data_member (t
, NULL_TREE
,
8103 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8105 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8107 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8108 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
8109 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
8110 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH_DETACH
))
8113 error_at (OMP_CLAUSE_LOCATION (c
),
8114 "%qD is not a variable in %qs clause", t
,
8115 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8117 error_at (OMP_CLAUSE_LOCATION (c
),
8118 "%qE is not a variable in %qs clause", t
,
8119 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8122 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
8124 error_at (OMP_CLAUSE_LOCATION (c
),
8125 "%qD is threadprivate variable in %qs clause", t
,
8126 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8129 else if (!processing_template_decl
8130 && !TYPE_REF_P (TREE_TYPE (t
))
8131 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
8132 || (OMP_CLAUSE_MAP_KIND (c
)
8133 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
8134 && !indir_component_ref_p
8135 && !cxx_mark_addressable (t
))
8137 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8138 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
8139 || (OMP_CLAUSE_MAP_KIND (c
)
8140 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
8141 && t
== OMP_CLAUSE_DECL (c
)
8142 && !type_dependent_expression_p (t
)
8143 && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t
))
8144 ? TREE_TYPE (TREE_TYPE (t
))
8147 error_at (OMP_CLAUSE_LOCATION (c
),
8148 "%qD does not have a mappable type in %qs clause", t
,
8149 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8150 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
8153 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8154 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
8155 && !type_dependent_expression_p (t
)
8156 && !INDIRECT_TYPE_P (TREE_TYPE (t
)))
8158 error_at (OMP_CLAUSE_LOCATION (c
),
8159 "%qD is not a pointer variable", t
);
8162 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8163 && OMP_CLAUSE_MAP_IMPLICIT (c
)
8164 && (bitmap_bit_p (&map_head
, DECL_UID (t
))
8165 || bitmap_bit_p (&map_field_head
, DECL_UID (t
))
8166 || bitmap_bit_p (&map_firstprivate_head
,
8169 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8170 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
8172 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
8173 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
8174 || bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
8176 error_at (OMP_CLAUSE_LOCATION (c
),
8177 "%qD appears more than once in data clauses", t
);
8180 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
8181 && !bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
8183 if (ort
== C_ORT_ACC
)
8184 error_at (OMP_CLAUSE_LOCATION (c
),
8185 "%qD appears more than once in data clauses", t
);
8187 error_at (OMP_CLAUSE_LOCATION (c
),
8188 "%qD appears both in data and map clauses", t
);
8192 bitmap_set_bit (&map_firstprivate_head
, DECL_UID (t
));
8194 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
8195 && !bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
8197 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
8198 error_at (OMP_CLAUSE_LOCATION (c
),
8199 "%qD appears more than once in motion clauses", t
);
8200 else if (ort
== C_ORT_ACC
)
8201 error_at (OMP_CLAUSE_LOCATION (c
),
8202 "%qD appears more than once in data clauses", t
);
8204 error_at (OMP_CLAUSE_LOCATION (c
),
8205 "%qD appears more than once in map clauses", t
);
8208 else if (ort
== C_ORT_ACC
8209 && bitmap_bit_p (&generic_head
, DECL_UID (t
)))
8211 error_at (OMP_CLAUSE_LOCATION (c
),
8212 "%qD appears more than once in data clauses", t
);
8215 else if (bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
8217 if (ort
== C_ORT_ACC
)
8218 error_at (OMP_CLAUSE_LOCATION (c
),
8219 "%qD appears more than once in data clauses", t
);
8221 error_at (OMP_CLAUSE_LOCATION (c
),
8222 "%qD appears both in data and map clauses", t
);
8227 bitmap_set_bit (&map_head
, DECL_UID (t
));
8229 tree decl
= OMP_CLAUSE_DECL (c
);
8231 && (TREE_CODE (decl
) == COMPONENT_REF
8232 || (INDIRECT_REF_P (decl
)
8233 && TREE_CODE (TREE_OPERAND (decl
, 0)) == COMPONENT_REF
8234 && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl
, 0))))))
8235 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
8237 handle_map_references
:
8239 && !processing_template_decl
8240 && ort
!= C_ORT_DECLARE_SIMD
8241 && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
))))
8243 t
= OMP_CLAUSE_DECL (c
);
8244 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
8246 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
8247 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
8249 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
8251 else if (OMP_CLAUSE_MAP_KIND (c
)
8252 != GOMP_MAP_FIRSTPRIVATE_POINTER
8253 && (OMP_CLAUSE_MAP_KIND (c
)
8254 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
8255 && (OMP_CLAUSE_MAP_KIND (c
)
8256 != GOMP_MAP_ALWAYS_POINTER
)
8257 && (OMP_CLAUSE_MAP_KIND (c
)
8258 != GOMP_MAP_ATTACH_DETACH
))
8260 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8262 if (TREE_CODE (t
) == COMPONENT_REF
)
8263 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
8265 OMP_CLAUSE_SET_MAP_KIND (c2
,
8266 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
8267 OMP_CLAUSE_DECL (c2
) = t
;
8268 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
8269 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
8270 OMP_CLAUSE_CHAIN (c
) = c2
;
8271 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
8272 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
8274 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
8280 case OMP_CLAUSE_TO_DECLARE
:
8281 case OMP_CLAUSE_LINK
:
8282 t
= OMP_CLAUSE_DECL (c
);
8283 if (TREE_CODE (t
) == FUNCTION_DECL
8284 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
8286 else if (!VAR_P (t
))
8288 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
8290 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
8291 error_at (OMP_CLAUSE_LOCATION (c
),
8292 "template %qE in clause %qs", t
,
8293 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8294 else if (really_overloaded_fn (t
))
8295 error_at (OMP_CLAUSE_LOCATION (c
),
8296 "overloaded function name %qE in clause %qs", t
,
8297 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8299 error_at (OMP_CLAUSE_LOCATION (c
),
8300 "%qE is neither a variable nor a function name "
8302 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8305 error_at (OMP_CLAUSE_LOCATION (c
),
8306 "%qE is not a variable in clause %qs", t
,
8307 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8310 else if (DECL_THREAD_LOCAL_P (t
))
8312 error_at (OMP_CLAUSE_LOCATION (c
),
8313 "%qD is threadprivate variable in %qs clause", t
,
8314 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8317 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
8319 error_at (OMP_CLAUSE_LOCATION (c
),
8320 "%qD does not have a mappable type in %qs clause", t
,
8321 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8322 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
8327 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
8329 error_at (OMP_CLAUSE_LOCATION (c
),
8330 "%qE appears more than once on the same "
8331 "%<declare target%> directive", t
);
8335 bitmap_set_bit (&generic_head
, DECL_UID (t
));
8338 case OMP_CLAUSE_UNIFORM
:
8339 t
= OMP_CLAUSE_DECL (c
);
8340 if (TREE_CODE (t
) != PARM_DECL
)
8342 if (processing_template_decl
)
8345 error_at (OMP_CLAUSE_LOCATION (c
),
8346 "%qD is not an argument in %<uniform%> clause", t
);
8348 error_at (OMP_CLAUSE_LOCATION (c
),
8349 "%qE is not an argument in %<uniform%> clause", t
);
8353 /* map_head bitmap is used as uniform_head if declare_simd. */
8354 bitmap_set_bit (&map_head
, DECL_UID (t
));
8355 goto check_dup_generic
;
8357 case OMP_CLAUSE_GRAINSIZE
:
8358 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
8359 if (t
== error_mark_node
)
8361 else if (!type_dependent_expression_p (t
)
8362 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8364 error_at (OMP_CLAUSE_LOCATION (c
),
8365 "%<grainsize%> expression must be integral");
8370 t
= mark_rvalue_use (t
);
8371 if (!processing_template_decl
)
8373 t
= maybe_constant_value (t
);
8374 if (TREE_CODE (t
) == INTEGER_CST
8375 && tree_int_cst_sgn (t
) != 1)
8377 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
8378 "%<grainsize%> value must be positive");
8379 t
= integer_one_node
;
8381 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8383 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
8387 case OMP_CLAUSE_PRIORITY
:
8388 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
8389 if (t
== error_mark_node
)
8391 else if (!type_dependent_expression_p (t
)
8392 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8394 error_at (OMP_CLAUSE_LOCATION (c
),
8395 "%<priority%> expression must be integral");
8400 t
= mark_rvalue_use (t
);
8401 if (!processing_template_decl
)
8403 t
= maybe_constant_value (t
);
8404 if (TREE_CODE (t
) == INTEGER_CST
8405 && tree_int_cst_sgn (t
) == -1)
8407 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
8408 "%<priority%> value must be non-negative");
8409 t
= integer_one_node
;
8411 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8413 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
8417 case OMP_CLAUSE_HINT
:
8418 t
= OMP_CLAUSE_HINT_EXPR (c
);
8419 if (t
== error_mark_node
)
8421 else if (!type_dependent_expression_p (t
)
8422 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8424 error_at (OMP_CLAUSE_LOCATION (c
),
8425 "%<hint%> expression must be integral");
8430 t
= mark_rvalue_use (t
);
8431 if (!processing_template_decl
)
8433 t
= maybe_constant_value (t
);
8434 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8435 if (TREE_CODE (t
) != INTEGER_CST
)
8437 error_at (OMP_CLAUSE_LOCATION (c
),
8438 "%<hint%> expression must be constant integer "
8443 OMP_CLAUSE_HINT_EXPR (c
) = t
;
8447 case OMP_CLAUSE_FILTER
:
8448 t
= OMP_CLAUSE_FILTER_EXPR (c
);
8449 if (t
== error_mark_node
)
8451 else if (!type_dependent_expression_p (t
)
8452 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8454 error_at (OMP_CLAUSE_LOCATION (c
),
8455 "%<filter%> expression must be integral");
8460 t
= mark_rvalue_use (t
);
8461 if (!processing_template_decl
)
8463 t
= maybe_constant_value (t
);
8464 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8466 OMP_CLAUSE_FILTER_EXPR (c
) = t
;
8470 case OMP_CLAUSE_IS_DEVICE_PTR
:
8471 case OMP_CLAUSE_USE_DEVICE_PTR
:
8472 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
8473 t
= OMP_CLAUSE_DECL (c
);
8474 if (!type_dependent_expression_p (t
))
8476 tree type
= TREE_TYPE (t
);
8477 if (!TYPE_PTR_P (type
)
8478 && (!TYPE_REF_P (type
) || !TYPE_PTR_P (TREE_TYPE (type
))))
8480 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
8481 && ort
== C_ORT_OMP
)
8483 error_at (OMP_CLAUSE_LOCATION (c
),
8484 "%qs variable is neither a pointer "
8485 "nor reference to pointer",
8486 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8489 else if (TREE_CODE (type
) != ARRAY_TYPE
8490 && (!TYPE_REF_P (type
)
8491 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
8493 error_at (OMP_CLAUSE_LOCATION (c
),
8494 "%qs variable is neither a pointer, nor an "
8495 "array nor reference to pointer or array",
8496 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8501 goto check_dup_generic
;
8503 case OMP_CLAUSE_USE_DEVICE_ADDR
:
8505 t
= OMP_CLAUSE_DECL (c
);
8506 if (!processing_template_decl
8507 && (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
8508 && !TYPE_REF_P (TREE_TYPE (t
))
8509 && !cxx_mark_addressable (t
))
8511 goto check_dup_generic
;
8513 case OMP_CLAUSE_NOWAIT
:
8514 case OMP_CLAUSE_DEFAULT
:
8515 case OMP_CLAUSE_UNTIED
:
8516 case OMP_CLAUSE_COLLAPSE
:
8517 case OMP_CLAUSE_PARALLEL
:
8518 case OMP_CLAUSE_FOR
:
8519 case OMP_CLAUSE_SECTIONS
:
8520 case OMP_CLAUSE_TASKGROUP
:
8521 case OMP_CLAUSE_PROC_BIND
:
8522 case OMP_CLAUSE_DEVICE_TYPE
:
8523 case OMP_CLAUSE_NOGROUP
:
8524 case OMP_CLAUSE_THREADS
:
8525 case OMP_CLAUSE_SIMD
:
8526 case OMP_CLAUSE_DEFAULTMAP
:
8527 case OMP_CLAUSE_BIND
:
8528 case OMP_CLAUSE_AUTO
:
8529 case OMP_CLAUSE_INDEPENDENT
:
8530 case OMP_CLAUSE_SEQ
:
8531 case OMP_CLAUSE_IF_PRESENT
:
8532 case OMP_CLAUSE_FINALIZE
:
8533 case OMP_CLAUSE_NOHOST
:
8536 case OMP_CLAUSE_MERGEABLE
:
8537 mergeable_seen
= true;
8540 case OMP_CLAUSE_TILE
:
8541 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
8542 list
= TREE_CHAIN (list
))
8544 t
= TREE_VALUE (list
);
8546 if (t
== error_mark_node
)
8548 else if (!type_dependent_expression_p (t
)
8549 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8551 error_at (OMP_CLAUSE_LOCATION (c
),
8552 "%<tile%> argument needs integral type");
8557 t
= mark_rvalue_use (t
);
8558 if (!processing_template_decl
)
8560 /* Zero is used to indicate '*', we permit you
8561 to get there via an ICE of value zero. */
8562 t
= maybe_constant_value (t
);
8563 if (!tree_fits_shwi_p (t
)
8564 || tree_to_shwi (t
) < 0)
8566 error_at (OMP_CLAUSE_LOCATION (c
),
8567 "%<tile%> argument needs positive "
8568 "integral constant");
8571 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8575 /* Update list item. */
8576 TREE_VALUE (list
) = t
;
8580 case OMP_CLAUSE_ORDERED
:
8581 ordered_seen
= true;
8584 case OMP_CLAUSE_ORDER
:
8591 case OMP_CLAUSE_INBRANCH
:
8592 case OMP_CLAUSE_NOTINBRANCH
:
8595 error_at (OMP_CLAUSE_LOCATION (c
),
8596 "%<inbranch%> clause is incompatible with "
8603 case OMP_CLAUSE_INCLUSIVE
:
8604 case OMP_CLAUSE_EXCLUSIVE
:
8605 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8607 t
= OMP_CLAUSE_DECL (c
);
8608 if (t
== current_class_ptr
)
8610 error_at (OMP_CLAUSE_LOCATION (c
),
8611 "%<this%> allowed in OpenMP only in %<declare simd%>"
8617 && TREE_CODE (t
) != PARM_DECL
8618 && TREE_CODE (t
) != FIELD_DECL
)
8620 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8623 error_at (OMP_CLAUSE_LOCATION (c
),
8624 "%qD is not a variable in clause %qs", t
,
8625 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8627 error_at (OMP_CLAUSE_LOCATION (c
),
8628 "%qE is not a variable in clause %qs", t
,
8629 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8639 *pc
= OMP_CLAUSE_CHAIN (c
);
8641 pc
= &OMP_CLAUSE_CHAIN (c
);
8644 if (reduction_seen
< 0 && (ordered_seen
|| schedule_seen
))
8645 reduction_seen
= -2;
8647 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
8649 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
8650 bool remove
= false;
8651 bool need_complete_type
= false;
8652 bool need_default_ctor
= false;
8653 bool need_copy_ctor
= false;
8654 bool need_copy_assignment
= false;
8655 bool need_implicitly_determined
= false;
8656 bool need_dtor
= false;
8657 tree type
, inner_type
;
8661 case OMP_CLAUSE_SHARED
:
8662 need_implicitly_determined
= true;
8664 case OMP_CLAUSE_PRIVATE
:
8665 need_complete_type
= true;
8666 need_default_ctor
= true;
8668 need_implicitly_determined
= true;
8670 case OMP_CLAUSE_FIRSTPRIVATE
:
8671 need_complete_type
= true;
8672 need_copy_ctor
= true;
8674 need_implicitly_determined
= true;
8676 case OMP_CLAUSE_LASTPRIVATE
:
8677 need_complete_type
= true;
8678 need_copy_assignment
= true;
8679 need_implicitly_determined
= true;
8681 case OMP_CLAUSE_REDUCTION
:
8682 if (reduction_seen
== -2)
8683 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
8684 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
8685 need_copy_assignment
= true;
8686 need_implicitly_determined
= true;
8688 case OMP_CLAUSE_IN_REDUCTION
:
8689 case OMP_CLAUSE_TASK_REDUCTION
:
8690 case OMP_CLAUSE_INCLUSIVE
:
8691 case OMP_CLAUSE_EXCLUSIVE
:
8692 need_implicitly_determined
= true;
8694 case OMP_CLAUSE_LINEAR
:
8695 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
8696 need_implicitly_determined
= true;
8697 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
8698 && !bitmap_bit_p (&map_head
,
8699 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
8701 error_at (OMP_CLAUSE_LOCATION (c
),
8702 "%<linear%> clause step is a parameter %qD not "
8703 "specified in %<uniform%> clause",
8704 OMP_CLAUSE_LINEAR_STEP (c
));
8705 *pc
= OMP_CLAUSE_CHAIN (c
);
8709 case OMP_CLAUSE_COPYPRIVATE
:
8710 need_copy_assignment
= true;
8712 case OMP_CLAUSE_COPYIN
:
8713 need_copy_assignment
= true;
8715 case OMP_CLAUSE_SIMDLEN
:
8717 && !processing_template_decl
8718 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
8719 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
8721 error_at (OMP_CLAUSE_LOCATION (c
),
8722 "%<simdlen%> clause value is bigger than "
8723 "%<safelen%> clause value");
8724 OMP_CLAUSE_SIMDLEN_EXPR (c
)
8725 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
8727 pc
= &OMP_CLAUSE_CHAIN (c
);
8729 case OMP_CLAUSE_SCHEDULE
:
8731 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
8732 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
8734 error_at (OMP_CLAUSE_LOCATION (c
),
8735 "%<nonmonotonic%> schedule modifier specified "
8736 "together with %<ordered%> clause");
8737 OMP_CLAUSE_SCHEDULE_KIND (c
)
8738 = (enum omp_clause_schedule_kind
)
8739 (OMP_CLAUSE_SCHEDULE_KIND (c
)
8740 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
8742 if (reduction_seen
== -2)
8743 error_at (OMP_CLAUSE_LOCATION (c
),
8744 "%qs clause specified together with %<inscan%> "
8745 "%<reduction%> clause", "schedule");
8746 pc
= &OMP_CLAUSE_CHAIN (c
);
8748 case OMP_CLAUSE_NOGROUP
:
8751 error_at (OMP_CLAUSE_LOCATION (c
),
8752 "%<nogroup%> clause must not be used together with "
8753 "%<reduction%> clause");
8754 *pc
= OMP_CLAUSE_CHAIN (c
);
8757 pc
= &OMP_CLAUSE_CHAIN (c
);
8759 case OMP_CLAUSE_ORDERED
:
8760 if (reduction_seen
== -2)
8761 error_at (OMP_CLAUSE_LOCATION (c
),
8762 "%qs clause specified together with %<inscan%> "
8763 "%<reduction%> clause", "ordered");
8764 pc
= &OMP_CLAUSE_CHAIN (c
);
8766 case OMP_CLAUSE_ORDER
:
8769 error_at (OMP_CLAUSE_LOCATION (c
),
8770 "%<order%> clause must not be used together "
8771 "with %<ordered%>");
8772 *pc
= OMP_CLAUSE_CHAIN (c
);
8775 pc
= &OMP_CLAUSE_CHAIN (c
);
8777 case OMP_CLAUSE_DETACH
:
8780 error_at (OMP_CLAUSE_LOCATION (c
),
8781 "%<detach%> clause must not be used together with "
8782 "%<mergeable%> clause");
8783 *pc
= OMP_CLAUSE_CHAIN (c
);
8786 pc
= &OMP_CLAUSE_CHAIN (c
);
8788 case OMP_CLAUSE_MAP
:
8789 if (target_in_reduction_seen
&& !processing_template_decl
)
8791 t
= OMP_CLAUSE_DECL (c
);
8792 while (handled_component_p (t
)
8793 || TREE_CODE (t
) == INDIRECT_REF
8794 || TREE_CODE (t
) == ADDR_EXPR
8795 || TREE_CODE (t
) == MEM_REF
8796 || TREE_CODE (t
) == NON_LVALUE_EXPR
)
8797 t
= TREE_OPERAND (t
, 0);
8799 && bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
8800 OMP_CLAUSE_MAP_IN_REDUCTION (c
) = 1;
8802 pc
= &OMP_CLAUSE_CHAIN (c
);
8804 case OMP_CLAUSE_NOWAIT
:
8805 if (copyprivate_seen
)
8807 error_at (OMP_CLAUSE_LOCATION (c
),
8808 "%<nowait%> clause must not be used together "
8809 "with %<copyprivate%>");
8810 *pc
= OMP_CLAUSE_CHAIN (c
);
8815 pc
= &OMP_CLAUSE_CHAIN (c
);
8819 t
= OMP_CLAUSE_DECL (c
);
8822 case OMP_CLAUSE_LASTPRIVATE
:
8824 && !bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
8826 need_default_ctor
= true;
8831 case OMP_CLAUSE_REDUCTION
:
8832 case OMP_CLAUSE_IN_REDUCTION
:
8833 case OMP_CLAUSE_TASK_REDUCTION
:
8836 if (TREE_CODE (t
) == MEM_REF
)
8838 t
= TREE_OPERAND (t
, 0);
8839 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
8840 t
= TREE_OPERAND (t
, 0);
8841 if (TREE_CODE (t
) == ADDR_EXPR
8842 || TREE_CODE (t
) == INDIRECT_REF
)
8843 t
= TREE_OPERAND (t
, 0);
8845 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8847 else if (TREE_CODE (t
) == TREE_LIST
)
8849 while (TREE_CODE (t
) == TREE_LIST
)
8852 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8853 t
= OMP_CLAUSE_DECL (c
);
8855 else if (DECL_P (t
))
8856 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8857 t
= OMP_CLAUSE_DECL (c
);
8859 if (processing_template_decl
8860 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8862 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
8866 t
= OMP_CLAUSE_DECL (c
);
8869 case OMP_CLAUSE_COPYIN
:
8870 if (processing_template_decl
8871 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8873 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
8875 error_at (OMP_CLAUSE_LOCATION (c
),
8876 "%qE must be %<threadprivate%> for %<copyin%>", t
);
8885 if (processing_template_decl
8886 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8888 pc
= &OMP_CLAUSE_CHAIN (c
);
8892 if (need_complete_type
|| need_copy_assignment
)
8894 t
= require_complete_type (t
);
8895 if (t
== error_mark_node
)
8897 else if (!processing_template_decl
8898 && TYPE_REF_P (TREE_TYPE (t
))
8899 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
8902 if (need_implicitly_determined
)
8904 const char *share_name
= NULL
;
8907 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8909 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8911 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
8912 share_name
= "threadprivate";
8913 else switch (cxx_omp_predetermined_sharing_1 (t
))
8915 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
8917 case OMP_CLAUSE_DEFAULT_SHARED
:
8918 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8919 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8920 && c_omp_predefined_variable (t
))
8921 /* The __func__ variable and similar function-local predefined
8922 variables may be listed in a shared or firstprivate
8926 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8928 && cxx_omp_const_qual_no_mutable (t
))
8930 tree ctx
= CP_DECL_CONTEXT (t
);
8931 /* const qualified static data members without mutable
8932 member may be specified in firstprivate clause. */
8933 if (TYPE_P (ctx
) && MAYBE_CLASS_TYPE_P (ctx
))
8936 share_name
= "shared";
8938 case OMP_CLAUSE_DEFAULT_PRIVATE
:
8939 share_name
= "private";
8946 error_at (OMP_CLAUSE_LOCATION (c
),
8947 "%qE is predetermined %qs for %qs",
8948 omp_clause_printable_decl (t
), share_name
,
8949 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8952 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8953 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_FIRSTPRIVATE
8954 && cxx_omp_const_qual_no_mutable (t
))
8956 error_at (OMP_CLAUSE_LOCATION (c
),
8957 "%<const%> qualified %qE without %<mutable%> member "
8958 "may appear only in %<shared%> or %<firstprivate%> "
8959 "clauses", omp_clause_printable_decl (t
));
8965 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8966 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
8967 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8968 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
8969 && OMP_CLAUSE_DECL (c
) == OMP_CLAUSE_DECL (detach_seen
))
8971 error_at (OMP_CLAUSE_LOCATION (c
),
8972 "the event handle of a %<detach%> clause "
8973 "should not be in a data-sharing clause");
8977 /* We're interested in the base element, not arrays. */
8978 inner_type
= type
= TREE_TYPE (t
);
8979 if ((need_complete_type
8980 || need_copy_assignment
8981 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
8982 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
8983 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
8984 && TYPE_REF_P (inner_type
))
8985 inner_type
= TREE_TYPE (inner_type
);
8986 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
8987 inner_type
= TREE_TYPE (inner_type
);
8989 /* Check for special function availability by building a call to one.
8990 Save the results, because later we won't be in the right context
8991 for making these queries. */
8992 if (CLASS_TYPE_P (inner_type
)
8993 && COMPLETE_TYPE_P (inner_type
)
8994 && (need_default_ctor
|| need_copy_ctor
8995 || need_copy_assignment
|| need_dtor
)
8996 && !type_dependent_expression_p (t
)
8997 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
8998 need_copy_ctor
, need_copy_assignment
,
9003 && c_kind
== OMP_CLAUSE_SHARED
9004 && processing_template_decl
)
9006 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
9008 OMP_CLAUSE_DECL (c
) = t
;
9012 *pc
= OMP_CLAUSE_CHAIN (c
);
9014 pc
= &OMP_CLAUSE_CHAIN (c
);
9018 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
9020 bool remove
= false;
9021 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ALLOCATE
9022 && !OMP_CLAUSE_ALLOCATE_COMBINED (c
)
9023 && DECL_P (OMP_CLAUSE_DECL (c
))
9024 && bitmap_bit_p (&aligned_head
, DECL_UID (OMP_CLAUSE_DECL (c
))))
9026 error_at (OMP_CLAUSE_LOCATION (c
),
9027 "%qD specified in %<allocate%> clause but not in "
9028 "an explicit privatization clause", OMP_CLAUSE_DECL (c
));
9032 *pc
= OMP_CLAUSE_CHAIN (c
);
9034 pc
= &OMP_CLAUSE_CHAIN (c
);
9037 bitmap_obstack_release (NULL
);
9041 /* Start processing OpenMP clauses that can include any
9042 privatization clauses for non-static data members. */
9045 push_omp_privatization_clauses (bool ignore_next
)
9047 if (omp_private_member_ignore_next
)
9049 omp_private_member_ignore_next
= ignore_next
;
9052 omp_private_member_ignore_next
= ignore_next
;
9053 if (omp_private_member_map
)
9054 omp_private_member_vec
.safe_push (error_mark_node
);
9055 return push_stmt_list ();
9058 /* Revert remapping of any non-static data members since
9059 the last push_omp_privatization_clauses () call. */
9062 pop_omp_privatization_clauses (tree stmt
)
9064 if (stmt
== NULL_TREE
)
9066 stmt
= pop_stmt_list (stmt
);
9067 if (omp_private_member_map
)
9069 while (!omp_private_member_vec
.is_empty ())
9071 tree t
= omp_private_member_vec
.pop ();
9072 if (t
== error_mark_node
)
9077 bool no_decl_expr
= t
== integer_zero_node
;
9079 t
= omp_private_member_vec
.pop ();
9080 tree
*v
= omp_private_member_map
->get (t
);
9084 omp_private_member_map
->remove (t
);
9086 delete omp_private_member_map
;
9087 omp_private_member_map
= NULL
;
9092 /* Remember OpenMP privatization clauses mapping and clear it.
9093 Used for lambdas. */
9096 save_omp_privatization_clauses (vec
<tree
> &save
)
9099 if (omp_private_member_ignore_next
)
9100 save
.safe_push (integer_one_node
);
9101 omp_private_member_ignore_next
= false;
9102 if (!omp_private_member_map
)
9105 while (!omp_private_member_vec
.is_empty ())
9107 tree t
= omp_private_member_vec
.pop ();
9108 if (t
== error_mark_node
)
9114 if (t
== integer_zero_node
)
9115 t
= omp_private_member_vec
.pop ();
9116 tree
*v
= omp_private_member_map
->get (t
);
9118 save
.safe_push (*v
);
9123 delete omp_private_member_map
;
9124 omp_private_member_map
= NULL
;
9127 /* Restore OpenMP privatization clauses mapping saved by the
9131 restore_omp_privatization_clauses (vec
<tree
> &save
)
9133 gcc_assert (omp_private_member_vec
.is_empty ());
9134 omp_private_member_ignore_next
= false;
9135 if (save
.is_empty ())
9137 if (save
.length () == 1 && save
[0] == integer_one_node
)
9139 omp_private_member_ignore_next
= true;
9144 omp_private_member_map
= new hash_map
<tree
, tree
>;
9145 while (!save
.is_empty ())
9147 tree t
= save
.pop ();
9149 if (t
!= error_mark_node
)
9151 if (t
== integer_one_node
)
9153 omp_private_member_ignore_next
= true;
9154 gcc_assert (save
.is_empty ());
9157 if (t
== integer_zero_node
)
9159 tree
&v
= omp_private_member_map
->get_or_insert (t
);
9162 omp_private_member_vec
.safe_push (t
);
9164 omp_private_member_vec
.safe_push (n
);
9169 /* For all variables in the tree_list VARS, mark them as thread local. */
9172 finish_omp_threadprivate (tree vars
)
9176 /* Mark every variable in VARS to be assigned thread local storage. */
9177 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
9179 tree v
= TREE_PURPOSE (t
);
9181 if (error_operand_p (v
))
9183 else if (!VAR_P (v
))
9184 error ("%<threadprivate%> %qD is not file, namespace "
9185 "or block scope variable", v
);
9186 /* If V had already been marked threadprivate, it doesn't matter
9187 whether it had been used prior to this point. */
9188 else if (TREE_USED (v
)
9189 && (DECL_LANG_SPECIFIC (v
) == NULL
9190 || !CP_DECL_THREADPRIVATE_P (v
)))
9191 error ("%qE declared %<threadprivate%> after first use", v
);
9192 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
9193 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
9194 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
9195 error ("%<threadprivate%> %qE has incomplete type", v
);
9196 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
9197 && CP_DECL_CONTEXT (v
) != current_class_type
)
9198 error ("%<threadprivate%> %qE directive not "
9199 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
9202 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
9203 if (DECL_LANG_SPECIFIC (v
) == NULL
)
9204 retrofit_lang_decl (v
);
9206 if (! CP_DECL_THREAD_LOCAL_P (v
))
9208 CP_DECL_THREAD_LOCAL_P (v
) = true;
9209 set_decl_tls_model (v
, decl_default_tls_model (v
));
9210 /* If rtl has been already set for this var, call
9211 make_decl_rtl once again, so that encode_section_info
9212 has a chance to look at the new decl flags. */
9213 if (DECL_RTL_SET_P (v
))
9216 CP_DECL_THREADPRIVATE_P (v
) = 1;
9221 /* Build an OpenMP structured block. */
9224 begin_omp_structured_block (void)
9226 return do_pushlevel (sk_omp
);
9230 finish_omp_structured_block (tree block
)
9232 return do_poplevel (block
);
9235 /* Similarly, except force the retention of the BLOCK. */
9238 begin_omp_parallel (void)
9240 keep_next_level (true);
9241 return begin_omp_structured_block ();
9244 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
9248 finish_oacc_data (tree clauses
, tree block
)
9252 block
= finish_omp_structured_block (block
);
9254 stmt
= make_node (OACC_DATA
);
9255 TREE_TYPE (stmt
) = void_type_node
;
9256 OACC_DATA_CLAUSES (stmt
) = clauses
;
9257 OACC_DATA_BODY (stmt
) = block
;
9259 return add_stmt (stmt
);
9262 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
9266 finish_oacc_host_data (tree clauses
, tree block
)
9270 block
= finish_omp_structured_block (block
);
9272 stmt
= make_node (OACC_HOST_DATA
);
9273 TREE_TYPE (stmt
) = void_type_node
;
9274 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
9275 OACC_HOST_DATA_BODY (stmt
) = block
;
9277 return add_stmt (stmt
);
9280 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
9284 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
9286 body
= finish_omp_structured_block (body
);
9288 tree stmt
= make_node (code
);
9289 TREE_TYPE (stmt
) = void_type_node
;
9290 OMP_BODY (stmt
) = body
;
9291 OMP_CLAUSES (stmt
) = clauses
;
9293 return add_stmt (stmt
);
9296 /* Used to walk OpenMP target directive body. */
9298 struct omp_target_walk_data
9300 /* Holds the 'this' expression found in current function. */
9301 tree current_object
;
9303 /* True if the 'this' expression was accessed in the target body. */
9304 bool this_expr_accessed
;
9306 /* For non-static functions, record which pointer-typed members were
9307 accessed, and the whole expression. */
9308 hash_map
<tree
, tree
> ptr_members_accessed
;
9310 /* Record which lambda objects were accessed in target body. */
9311 hash_set
<tree
> lambda_objects_accessed
;
9313 /* For lambda functions, the __closure object expression of the current
9314 function, and the set of captured variables accessed in target body. */
9315 tree current_closure
;
9316 hash_set
<tree
> closure_vars_accessed
;
9318 /* Local variables declared inside a BIND_EXPR, used to filter out such
9319 variables when recording lambda_objects_accessed. */
9320 hash_set
<tree
> local_decls
;
9323 /* Helper function of finish_omp_target_clauses, called via
9324 cp_walk_tree_without_duplicates. Traverse body of OpenMP target
9325 directive *TP, and fill out omp_target_walk_data passed in *PTR. */
9328 finish_omp_target_clauses_r (tree
*tp
, int *walk_subtrees
, void *ptr
)
9331 struct omp_target_walk_data
*data
= (struct omp_target_walk_data
*) ptr
;
9332 tree current_object
= data
->current_object
;
9333 tree current_closure
= data
->current_closure
;
9335 /* References inside of these expression codes shouldn't incur any
9336 form of mapping, so return early. */
9337 if (TREE_CODE (t
) == SIZEOF_EXPR
9338 || TREE_CODE (t
) == ALIGNOF_EXPR
)
9344 if (TREE_CODE (t
) == OMP_CLAUSE
)
9349 tree this_expr
= TREE_OPERAND (current_object
, 0);
9351 if (operand_equal_p (t
, this_expr
))
9353 data
->this_expr_accessed
= true;
9358 if (TREE_CODE (t
) == COMPONENT_REF
9359 && POINTER_TYPE_P (TREE_TYPE (t
))
9360 && operand_equal_p (TREE_OPERAND (t
, 0), current_object
)
9361 && TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
)
9363 data
->this_expr_accessed
= true;
9364 tree fld
= TREE_OPERAND (t
, 1);
9365 if (data
->ptr_members_accessed
.get (fld
) == NULL
)
9367 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
)
9368 t
= convert_from_reference (t
);
9369 data
->ptr_members_accessed
.put (fld
, t
);
9376 /* When the current_function_decl is a lambda function, the closure object
9377 argument's type seems to not yet have fields layed out, so a recording
9378 of DECL_VALUE_EXPRs during the target body walk seems the only way to
9381 && (TREE_CODE (t
) == VAR_DECL
9382 || TREE_CODE (t
) == PARM_DECL
9383 || TREE_CODE (t
) == RESULT_DECL
)
9384 && DECL_HAS_VALUE_EXPR_P (t
)
9385 && TREE_CODE (DECL_VALUE_EXPR (t
)) == COMPONENT_REF
9386 && operand_equal_p (current_closure
,
9387 TREE_OPERAND (DECL_VALUE_EXPR (t
), 0)))
9389 if (!data
->closure_vars_accessed
.contains (t
))
9390 data
->closure_vars_accessed
.add (t
);
9395 if (TREE_CODE (t
) == BIND_EXPR
)
9397 tree block
= BIND_EXPR_BLOCK (t
);
9398 for (tree var
= BLOCK_VARS (block
); var
; var
= DECL_CHAIN (var
))
9399 if (!data
->local_decls
.contains (var
))
9400 data
->local_decls
.add (var
);
9404 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
9406 tree lt
= TREE_TYPE (t
);
9407 gcc_assert (CLASS_TYPE_P (lt
));
9409 if (!data
->lambda_objects_accessed
.contains (t
)
9410 /* Do not prepare to create target maps for locally declared
9411 lambdas or anonymous ones. */
9412 && !data
->local_decls
.contains (t
)
9413 && TREE_CODE (t
) != TARGET_EXPR
)
9414 data
->lambda_objects_accessed
.add (t
);
9422 /* Helper function for finish_omp_target, and also from tsubst_expr.
9423 Create additional clauses for mapping of non-static members, lambda objects,
9427 finish_omp_target_clauses (location_t loc
, tree body
, tree
*clauses_ptr
)
9429 omp_target_walk_data data
;
9430 data
.this_expr_accessed
= false;
9432 tree ct
= current_nonlambda_class_type ();
9435 tree object
= maybe_dummy_object (ct
, NULL
);
9436 object
= maybe_resolve_dummy (object
, true);
9437 data
.current_object
= object
;
9440 data
.current_object
= NULL_TREE
;
9442 if (DECL_LAMBDA_FUNCTION_P (current_function_decl
))
9444 tree closure
= DECL_ARGUMENTS (current_function_decl
);
9445 data
.current_closure
= build_indirect_ref (loc
, closure
, RO_UNARY_STAR
);
9448 data
.current_closure
= NULL_TREE
;
9450 cp_walk_tree_without_duplicates (&body
, finish_omp_target_clauses_r
, &data
);
9452 auto_vec
<tree
, 16> new_clauses
;
9454 tree omp_target_this_expr
= NULL_TREE
;
9455 tree
*explicit_this_deref_map
= NULL
;
9456 if (data
.this_expr_accessed
)
9458 omp_target_this_expr
= TREE_OPERAND (data
.current_object
, 0);
9460 /* See if explicit user-specified map(this[:]) clause already exists.
9461 If not, we create an implicit map(tofrom:this[:1]) clause. */
9462 for (tree
*cp
= clauses_ptr
; *cp
; cp
= &OMP_CLAUSE_CHAIN (*cp
))
9463 if (OMP_CLAUSE_CODE (*cp
) == OMP_CLAUSE_MAP
9464 && (TREE_CODE (OMP_CLAUSE_DECL (*cp
)) == INDIRECT_REF
9465 || TREE_CODE (OMP_CLAUSE_DECL (*cp
)) == MEM_REF
)
9466 && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp
), 0),
9467 omp_target_this_expr
))
9469 explicit_this_deref_map
= cp
;
9474 if (DECL_LAMBDA_FUNCTION_P (current_function_decl
)
9475 && (data
.this_expr_accessed
9476 || !data
.closure_vars_accessed
.is_empty ()))
9478 /* For lambda functions, we need to first create a copy of the
9479 __closure object. */
9480 tree closure
= DECL_ARGUMENTS (current_function_decl
);
9481 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9482 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_TO
);
9484 = build_indirect_ref (loc
, closure
, RO_UNARY_STAR
);
9486 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure
)));
9487 new_clauses
.safe_push (c
);
9489 tree closure_obj
= OMP_CLAUSE_DECL (c
);
9490 tree closure_type
= TREE_TYPE (closure_obj
);
9492 gcc_assert (LAMBDA_TYPE_P (closure_type
)
9493 && CLASS_TYPE_P (closure_type
));
9495 tree c2
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9496 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
9497 OMP_CLAUSE_DECL (c2
) = closure
;
9498 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
9499 new_clauses
.safe_push (c2
);
9502 if (data
.this_expr_accessed
)
9504 /* If the this-expr was accessed, create a map(*this) clause. */
9505 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
9506 if (explicit_this_deref_map
)
9508 tree this_map
= *explicit_this_deref_map
;
9509 tree nc
= OMP_CLAUSE_CHAIN (this_map
);
9510 gcc_assert (nc
!= NULL_TREE
9511 && OMP_CLAUSE_CODE (nc
) == OMP_CLAUSE_MAP
9512 && (OMP_CLAUSE_MAP_KIND (nc
)
9513 == GOMP_MAP_FIRSTPRIVATE_POINTER
));
9514 kind
= OMP_CLAUSE_MAP_KIND (this_map
);
9515 /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
9516 two-map sequence away from the chain. */
9517 *explicit_this_deref_map
= OMP_CLAUSE_CHAIN (nc
);
9519 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9520 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
9522 = build_indirect_ref (loc
, omp_target_this_expr
, RO_UNARY_STAR
);
9524 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr
)));
9525 new_clauses
.safe_push (c
);
9527 /* If we're in a lambda function, the this-pointer will actually be
9528 '__closure->this', a mapped member of __closure, hence always_pointer.
9529 Otherwise it's a firstprivate pointer. */
9530 enum gomp_map_kind ptr_kind
9531 = (DECL_LAMBDA_FUNCTION_P (current_function_decl
)
9532 ? GOMP_MAP_ALWAYS_POINTER
9533 : GOMP_MAP_FIRSTPRIVATE_POINTER
);
9534 c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9535 OMP_CLAUSE_SET_MAP_KIND (c
, ptr_kind
);
9536 OMP_CLAUSE_DECL (c
) = omp_target_this_expr
;
9537 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
9538 new_clauses
.safe_push (c
);
9541 if (DECL_LAMBDA_FUNCTION_P (current_function_decl
))
9543 if (omp_target_this_expr
)
9545 STRIP_NOPS (omp_target_this_expr
);
9546 gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr
));
9547 omp_target_this_expr
= DECL_VALUE_EXPR (omp_target_this_expr
);
9550 for (hash_set
<tree
>::iterator i
= data
.closure_vars_accessed
.begin ();
9551 i
!= data
.closure_vars_accessed
.end (); ++i
)
9553 tree orig_decl
= *i
;
9554 tree closure_expr
= DECL_VALUE_EXPR (orig_decl
);
9556 if (TREE_CODE (TREE_TYPE (orig_decl
)) == POINTER_TYPE
9557 || TREE_CODE (TREE_TYPE (orig_decl
)) == REFERENCE_TYPE
)
9559 /* this-pointer is processed above, outside this loop. */
9560 if (omp_target_this_expr
9561 && operand_equal_p (closure_expr
, omp_target_this_expr
))
9564 bool ptr_p
= TREE_CODE (TREE_TYPE (orig_decl
)) == POINTER_TYPE
;
9565 enum gomp_map_kind kind
, ptr_kind
, nc_kind
;
9570 /* For pointers, default mapped as zero-length array
9572 kind
= GOMP_MAP_ALLOC
;
9573 nc_kind
= GOMP_MAP_FIRSTPRIVATE_POINTER
;
9574 ptr_kind
= GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
;
9575 size
= size_zero_node
;
9579 /* For references, default mapped as appearing on map
9581 kind
= GOMP_MAP_TOFROM
;
9582 nc_kind
= GOMP_MAP_FIRSTPRIVATE_REFERENCE
;
9583 ptr_kind
= GOMP_MAP_ALWAYS_POINTER
;
9584 size
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr
)));
9587 for (tree
*p
= clauses_ptr
; *p
; p
= &OMP_CLAUSE_CHAIN (*p
))
9588 if (OMP_CLAUSE_CODE (*p
) == OMP_CLAUSE_MAP
9589 && (TREE_CODE (OMP_CLAUSE_DECL (*p
)) == INDIRECT_REF
9590 || TREE_CODE (OMP_CLAUSE_DECL (*p
)) == MEM_REF
)
9591 && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p
), 0),
9594 /* If this was already specified by user as a map,
9595 save the user specified map kind, delete the
9596 "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
9597 and insert our own sequence:
9598 "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
9600 tree nc
= OMP_CLAUSE_CHAIN (*p
);
9601 gcc_assert (nc
!= NULL_TREE
9602 && OMP_CLAUSE_CODE (nc
) == OMP_CLAUSE_MAP
9603 && OMP_CLAUSE_MAP_KIND (nc
) == nc_kind
);
9604 /* Update with user specified kind and size. */
9605 kind
= OMP_CLAUSE_MAP_KIND (*p
);
9606 size
= OMP_CLAUSE_SIZE (*p
);
9607 *p
= OMP_CLAUSE_CHAIN (nc
);
9611 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9612 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
9614 = build_indirect_ref (loc
, closure_expr
, RO_UNARY_STAR
);
9615 OMP_CLAUSE_SIZE (c
) = size
;
9617 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
9618 new_clauses
.safe_push (c
);
9620 c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9621 OMP_CLAUSE_SET_MAP_KIND (c
, ptr_kind
);
9622 OMP_CLAUSE_DECL (c
) = closure_expr
;
9623 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
9624 new_clauses
.safe_push (c
);
9629 if (!data
.ptr_members_accessed
.is_empty ())
9630 for (hash_map
<tree
, tree
>::iterator i
= data
.ptr_members_accessed
.begin ();
9631 i
!= data
.ptr_members_accessed
.end (); ++i
)
9633 /* For each referenced member that is of pointer or reference-to-pointer
9634 type, create the equivalent of map(alloc:this->ptr[:0]). */
9635 tree field_decl
= (*i
).first
;
9636 tree ptr_member
= (*i
).second
;
9638 for (tree c
= *clauses_ptr
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9640 /* If map(this->ptr[:N] already exists, avoid creating another
9642 tree decl
= OMP_CLAUSE_DECL (c
);
9643 if ((TREE_CODE (decl
) == INDIRECT_REF
9644 || TREE_CODE (decl
) == MEM_REF
)
9645 && operand_equal_p (TREE_OPERAND (decl
, 0), ptr_member
))
9646 goto next_ptr_member
;
9649 if (!cxx_mark_addressable (ptr_member
))
9652 if (TREE_CODE (TREE_TYPE (field_decl
)) == REFERENCE_TYPE
)
9654 /* For reference to pointers, we need to map the referenced
9655 pointer first for things to be correct. */
9656 tree ptr_member_type
= TREE_TYPE (ptr_member
);
9658 /* Map pointer target as zero-length array section. */
9659 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9660 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_ALLOC
);
9662 = build1 (INDIRECT_REF
, TREE_TYPE (ptr_member_type
), ptr_member
);
9663 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
9664 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
9666 /* Map pointer to zero-length array section. */
9667 tree c2
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9668 OMP_CLAUSE_SET_MAP_KIND
9669 (c2
, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION
);
9670 OMP_CLAUSE_DECL (c2
) = ptr_member
;
9671 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
9673 /* Attach reference-to-pointer field to pointer. */
9674 tree c3
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9675 OMP_CLAUSE_SET_MAP_KIND (c3
, GOMP_MAP_ATTACH
);
9676 OMP_CLAUSE_DECL (c3
) = TREE_OPERAND (ptr_member
, 0);
9677 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
9679 new_clauses
.safe_push (c
);
9680 new_clauses
.safe_push (c2
);
9681 new_clauses
.safe_push (c3
);
9683 else if (TREE_CODE (TREE_TYPE (field_decl
)) == POINTER_TYPE
)
9685 /* Map pointer target as zero-length array section. */
9686 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9687 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_ALLOC
);
9688 OMP_CLAUSE_DECL (c
) = build_indirect_ref (loc
, ptr_member
,
9690 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
9691 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
9693 /* Attach zero-length array section to pointer. */
9694 tree c2
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9695 OMP_CLAUSE_SET_MAP_KIND
9696 (c2
, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
);
9697 OMP_CLAUSE_DECL (c2
) = ptr_member
;
9698 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
9700 new_clauses
.safe_push (c
);
9701 new_clauses
.safe_push (c2
);
9710 for (hash_set
<tree
>::iterator i
= data
.lambda_objects_accessed
.begin ();
9711 i
!= data
.lambda_objects_accessed
.end (); ++i
)
9714 if (TREE_CODE (lobj
) == TARGET_EXPR
)
9715 lobj
= TREE_OPERAND (lobj
, 0);
9717 tree lt
= TREE_TYPE (lobj
);
9718 gcc_assert (LAMBDA_TYPE_P (lt
) && CLASS_TYPE_P (lt
));
9720 tree lc
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9721 OMP_CLAUSE_SET_MAP_KIND (lc
, GOMP_MAP_TO
);
9722 OMP_CLAUSE_DECL (lc
) = lobj
;
9723 OMP_CLAUSE_SIZE (lc
) = TYPE_SIZE_UNIT (lt
);
9724 new_clauses
.safe_push (lc
);
9726 for (tree fld
= TYPE_FIELDS (lt
); fld
; fld
= DECL_CHAIN (fld
))
9728 if (TREE_CODE (TREE_TYPE (fld
)) == POINTER_TYPE
)
9730 tree exp
= build3 (COMPONENT_REF
, TREE_TYPE (fld
),
9731 lobj
, fld
, NULL_TREE
);
9732 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9733 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_ALLOC
);
9735 = build_indirect_ref (loc
, exp
, RO_UNARY_STAR
);
9736 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
9737 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
9738 new_clauses
.safe_push (c
);
9740 c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9741 OMP_CLAUSE_SET_MAP_KIND
9742 (c
, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
);
9743 OMP_CLAUSE_DECL (c
) = exp
;
9744 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
9745 new_clauses
.safe_push (c
);
9747 else if (TREE_CODE (TREE_TYPE (fld
)) == REFERENCE_TYPE
)
9749 tree exp
= build3 (COMPONENT_REF
, TREE_TYPE (fld
),
9750 lobj
, fld
, NULL_TREE
);
9751 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9752 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_TOFROM
);
9754 = build1 (INDIRECT_REF
, TREE_TYPE (TREE_TYPE (exp
)), exp
);
9756 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp
)));
9757 new_clauses
.safe_push (c
);
9759 c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9760 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_ALWAYS_POINTER
);
9761 OMP_CLAUSE_DECL (c
) = exp
;
9762 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
9763 new_clauses
.safe_push (c
);
9768 tree c
= *clauses_ptr
;
9769 for (int i
= new_clauses
.length () - 1; i
>= 0; i
--)
9771 OMP_CLAUSE_CHAIN (new_clauses
[i
]) = c
;
9777 /* Called from cp_parser_omp_target. Create additional implicit clauses for
9778 OpenMP target directives, and do sanity checks. */
9781 finish_omp_target (location_t loc
, tree clauses
, tree body
, bool combined_p
)
9783 if (!processing_template_decl
)
9784 finish_omp_target_clauses (loc
, body
, &clauses
);
9786 tree stmt
= make_node (OMP_TARGET
);
9787 TREE_TYPE (stmt
) = void_type_node
;
9788 OMP_TARGET_CLAUSES (stmt
) = clauses
;
9789 OMP_TARGET_BODY (stmt
) = body
;
9790 OMP_TARGET_COMBINED (stmt
) = combined_p
;
9791 SET_EXPR_LOCATION (stmt
, loc
);
9796 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
)
9797 switch (OMP_CLAUSE_MAP_KIND (c
))
9800 case GOMP_MAP_ALWAYS_TO
:
9802 case GOMP_MAP_ALWAYS_FROM
:
9803 case GOMP_MAP_TOFROM
:
9804 case GOMP_MAP_ALWAYS_TOFROM
:
9805 case GOMP_MAP_ALLOC
:
9806 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
9807 case GOMP_MAP_FIRSTPRIVATE_REFERENCE
:
9808 case GOMP_MAP_ALWAYS_POINTER
:
9809 case GOMP_MAP_ATTACH_DETACH
:
9810 case GOMP_MAP_ATTACH
:
9811 case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
:
9812 case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION
:
9815 error_at (OMP_CLAUSE_LOCATION (c
),
9816 "%<#pragma omp target%> with map-type other "
9817 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
9818 "on %<map%> clause");
9821 c
= OMP_CLAUSE_CHAIN (c
);
9823 return add_stmt (stmt
);
9827 finish_omp_parallel (tree clauses
, tree body
)
9831 body
= finish_omp_structured_block (body
);
9833 stmt
= make_node (OMP_PARALLEL
);
9834 TREE_TYPE (stmt
) = void_type_node
;
9835 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
9836 OMP_PARALLEL_BODY (stmt
) = body
;
9838 return add_stmt (stmt
);
9842 begin_omp_task (void)
9844 keep_next_level (true);
9845 return begin_omp_structured_block ();
9849 finish_omp_task (tree clauses
, tree body
)
9853 body
= finish_omp_structured_block (body
);
9855 stmt
= make_node (OMP_TASK
);
9856 TREE_TYPE (stmt
) = void_type_node
;
9857 OMP_TASK_CLAUSES (stmt
) = clauses
;
9858 OMP_TASK_BODY (stmt
) = body
;
9860 return add_stmt (stmt
);
9863 /* Helper function for finish_omp_for. Convert Ith random access iterator
9864 into integral iterator. Return FALSE if successful. */
9867 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
9868 tree declv
, tree orig_declv
, tree initv
,
9869 tree condv
, tree incrv
, tree
*body
,
9870 tree
*pre_body
, tree
&clauses
,
9871 int collapse
, int ordered
)
9873 tree diff
, iter_init
, iter_incr
= NULL
, last
;
9874 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
9875 tree decl
= TREE_VEC_ELT (declv
, i
);
9876 tree init
= TREE_VEC_ELT (initv
, i
);
9877 tree cond
= TREE_VEC_ELT (condv
, i
);
9878 tree incr
= TREE_VEC_ELT (incrv
, i
);
9880 location_t elocus
= locus
;
9882 if (init
&& EXPR_HAS_LOCATION (init
))
9883 elocus
= EXPR_LOCATION (init
);
9885 switch (TREE_CODE (cond
))
9892 if (TREE_OPERAND (cond
, 1) == iter
)
9893 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
9894 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
9895 if (TREE_OPERAND (cond
, 0) != iter
)
9896 cond
= error_mark_node
;
9899 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
9902 TREE_OPERAND (cond
, 1), ERROR_MARK
,
9903 NULL_TREE
, NULL
, tf_warning_or_error
);
9904 if (error_operand_p (tem
))
9909 cond
= error_mark_node
;
9912 if (cond
== error_mark_node
)
9914 error_at (elocus
, "invalid controlling predicate");
9917 diff
= build_x_binary_op (elocus
, MINUS_EXPR
,
9918 TREE_OPERAND (cond
, 1), ERROR_MARK
,
9920 NULL_TREE
, NULL
, tf_warning_or_error
);
9921 diff
= cp_fully_fold (diff
);
9922 if (error_operand_p (diff
))
9924 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
9926 error_at (elocus
, "difference between %qE and %qD does not have integer type",
9927 TREE_OPERAND (cond
, 1), iter
);
9930 if (!c_omp_check_loop_iv_exprs (locus
, code
, orig_declv
, i
,
9931 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
9932 cond
, cp_walk_subtrees
))
9935 switch (TREE_CODE (incr
))
9937 case PREINCREMENT_EXPR
:
9938 case PREDECREMENT_EXPR
:
9939 case POSTINCREMENT_EXPR
:
9940 case POSTDECREMENT_EXPR
:
9941 if (TREE_OPERAND (incr
, 0) != iter
)
9943 incr
= error_mark_node
;
9946 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
9947 TREE_CODE (incr
), iter
,
9948 NULL_TREE
, tf_warning_or_error
);
9949 if (error_operand_p (iter_incr
))
9951 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
9952 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
9953 incr
= integer_one_node
;
9955 incr
= integer_minus_one_node
;
9958 if (TREE_OPERAND (incr
, 0) != iter
)
9959 incr
= error_mark_node
;
9960 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
9961 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
9963 tree rhs
= TREE_OPERAND (incr
, 1);
9964 if (TREE_OPERAND (rhs
, 0) == iter
)
9966 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
9968 incr
= error_mark_node
;
9971 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
9972 iter
, TREE_CODE (rhs
),
9973 TREE_OPERAND (rhs
, 1),
9975 tf_warning_or_error
);
9976 if (error_operand_p (iter_incr
))
9978 incr
= TREE_OPERAND (rhs
, 1);
9979 incr
= cp_convert (TREE_TYPE (diff
), incr
,
9980 tf_warning_or_error
);
9981 if (TREE_CODE (rhs
) == MINUS_EXPR
)
9983 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
9984 incr
= fold_simple (incr
);
9986 if (TREE_CODE (incr
) != INTEGER_CST
9987 && (TREE_CODE (incr
) != NOP_EXPR
9988 || (TREE_CODE (TREE_OPERAND (incr
, 0))
9993 else if (TREE_OPERAND (rhs
, 1) == iter
)
9995 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
9996 || TREE_CODE (rhs
) != PLUS_EXPR
)
9997 incr
= error_mark_node
;
10000 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
10002 TREE_OPERAND (rhs
, 0),
10004 ERROR_MARK
, NULL_TREE
, NULL
,
10005 tf_warning_or_error
);
10006 if (error_operand_p (iter_incr
))
10008 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
10010 iter_incr
, NULL_TREE
,
10011 tf_warning_or_error
);
10012 if (error_operand_p (iter_incr
))
10014 incr
= TREE_OPERAND (rhs
, 0);
10019 incr
= error_mark_node
;
10022 incr
= error_mark_node
;
10025 incr
= error_mark_node
;
10029 if (incr
== error_mark_node
)
10031 error_at (elocus
, "invalid increment expression");
10035 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
10036 incr
= cp_fully_fold (incr
);
10037 tree loop_iv_seen
= NULL_TREE
;
10038 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10039 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
10040 && OMP_CLAUSE_DECL (c
) == iter
)
10042 if (code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
10045 OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
) = 1;
10049 else if ((code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
10050 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
10051 && OMP_CLAUSE_DECL (c
) == iter
)
10054 if (code
== OMP_TASKLOOP
)
10055 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
10058 decl
= create_temporary_var (TREE_TYPE (diff
));
10060 add_decl_expr (decl
);
10061 last
= create_temporary_var (TREE_TYPE (diff
));
10063 add_decl_expr (last
);
10064 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
10065 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
10067 incr_var
= create_temporary_var (TREE_TYPE (diff
));
10068 pushdecl (incr_var
);
10069 add_decl_expr (incr_var
);
10071 gcc_assert (stmts_are_full_exprs_p ());
10072 tree diffvar
= NULL_TREE
;
10073 if (code
== OMP_TASKLOOP
)
10077 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
10078 OMP_CLAUSE_DECL (ivc
) = iter
;
10079 cxx_omp_finish_clause (ivc
, NULL
, false);
10080 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
10083 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
10084 OMP_CLAUSE_DECL (lvc
) = last
;
10085 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
10087 diffvar
= create_temporary_var (TREE_TYPE (diff
));
10088 pushdecl (diffvar
);
10089 add_decl_expr (diffvar
);
10091 else if (code
== OMP_LOOP
)
10095 /* While iterators on the loop construct are predetermined
10096 lastprivate, if the decl is not declared inside of the
10097 loop, OMP_CLAUSE_LASTPRIVATE should have been added
10099 loop_iv_seen
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
10100 OMP_CLAUSE_DECL (loop_iv_seen
) = iter
;
10101 OMP_CLAUSE_CHAIN (loop_iv_seen
) = clauses
;
10102 clauses
= loop_iv_seen
;
10104 else if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_PRIVATE
)
10106 OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen
) = 0;
10107 OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen
) = 0;
10108 OMP_CLAUSE_CODE (loop_iv_seen
) = OMP_CLAUSE_FIRSTPRIVATE
;
10110 if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_FIRSTPRIVATE
)
10111 cxx_omp_finish_clause (loop_iv_seen
, NULL
, false);
10114 orig_pre_body
= *pre_body
;
10115 *pre_body
= push_stmt_list ();
10117 add_stmt (orig_pre_body
);
10119 finish_expr_stmt (build_x_modify_expr (elocus
,
10120 iter
, NOP_EXPR
, init
,
10121 NULL_TREE
, tf_warning_or_error
));
10122 init
= build_int_cst (TREE_TYPE (diff
), 0);
10123 if (c
&& iter_incr
== NULL
10124 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
10128 finish_expr_stmt (build_x_modify_expr (elocus
,
10129 incr_var
, NOP_EXPR
,
10131 tf_warning_or_error
));
10134 iter_incr
= build_x_modify_expr (elocus
,
10135 iter
, PLUS_EXPR
, incr
,
10136 NULL_TREE
, tf_warning_or_error
);
10138 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
10140 finish_expr_stmt (build_x_modify_expr (elocus
,
10141 last
, NOP_EXPR
, init
,
10142 NULL_TREE
, tf_warning_or_error
));
10145 finish_expr_stmt (build_x_modify_expr (elocus
,
10147 diff
, NULL_TREE
, tf_warning_or_error
));
10150 *pre_body
= pop_stmt_list (*pre_body
);
10152 cond
= cp_build_binary_op (elocus
,
10153 TREE_CODE (cond
), decl
, diff
,
10154 tf_warning_or_error
);
10155 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
10156 elocus
, incr
, NULL_TREE
);
10159 *body
= push_stmt_list ();
10160 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
10161 iter_init
= build_x_modify_expr (elocus
,
10162 iter
, PLUS_EXPR
, iter_init
,
10163 NULL_TREE
, tf_warning_or_error
);
10164 if (iter_init
!= error_mark_node
)
10165 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
10166 finish_expr_stmt (iter_init
);
10167 finish_expr_stmt (build_x_modify_expr (elocus
,
10168 last
, NOP_EXPR
, decl
,
10169 NULL_TREE
, tf_warning_or_error
));
10170 add_stmt (orig_body
);
10171 *body
= pop_stmt_list (*body
);
10175 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
10177 finish_expr_stmt (iter_incr
);
10181 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
10182 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
10183 iter_init
, iter_incr
);
10184 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
10185 iter_init
= build_x_modify_expr (elocus
,
10186 iter
, PLUS_EXPR
, iter_init
,
10187 NULL_TREE
, tf_warning_or_error
);
10188 if (iter_init
!= error_mark_node
)
10189 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
10190 finish_expr_stmt (iter_init
);
10192 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
10193 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
10196 if (TREE_CODE (TREE_VEC_ELT (orig_declv
, i
)) == TREE_LIST
)
10198 tree t
= TREE_VEC_ELT (orig_declv
, i
);
10199 gcc_assert (TREE_PURPOSE (t
) == NULL_TREE
10200 && TREE_VALUE (t
) == NULL_TREE
10201 && TREE_CODE (TREE_CHAIN (t
)) == TREE_VEC
);
10202 TREE_PURPOSE (t
) = TREE_VEC_ELT (declv
, i
);
10203 TREE_VALUE (t
) = last
;
10206 TREE_VEC_ELT (orig_declv
, i
)
10207 = tree_cons (TREE_VEC_ELT (declv
, i
), last
, NULL_TREE
);
10208 TREE_VEC_ELT (declv
, i
) = decl
;
10209 TREE_VEC_ELT (initv
, i
) = init
;
10210 TREE_VEC_ELT (condv
, i
) = cond
;
10211 TREE_VEC_ELT (incrv
, i
) = incr
;
10216 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
10217 are directly for their associated operands in the statement. DECL
10218 and INIT are a combo; if DECL is NULL then INIT ought to be a
10219 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
10220 optional statements that need to go before the loop into its
10224 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
10225 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
10226 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
10228 tree omp_for
= NULL
, orig_incr
= NULL
;
10229 tree decl
= NULL
, init
, cond
, incr
;
10235 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
10236 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
10237 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
10238 if (TREE_VEC_LENGTH (declv
) > 1)
10242 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
10244 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
10247 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
10249 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
10250 if (collapse
!= TREE_VEC_LENGTH (declv
))
10251 ordered
= TREE_VEC_LENGTH (declv
);
10254 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
10256 decl
= TREE_VEC_ELT (declv
, i
);
10257 init
= TREE_VEC_ELT (initv
, i
);
10258 cond
= TREE_VEC_ELT (condv
, i
);
10259 incr
= TREE_VEC_ELT (incrv
, i
);
10265 switch (TREE_CODE (init
))
10268 decl
= TREE_OPERAND (init
, 0);
10269 init
= TREE_OPERAND (init
, 1);
10272 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
10274 decl
= TREE_OPERAND (init
, 0);
10275 init
= TREE_OPERAND (init
, 2);
10285 "expected iteration declaration or initialization");
10290 if (init
&& EXPR_HAS_LOCATION (init
))
10291 elocus
= EXPR_LOCATION (init
);
10293 if (cond
== global_namespace
)
10298 error_at (elocus
, "missing controlling predicate");
10304 error_at (elocus
, "missing increment expression");
10308 TREE_VEC_ELT (declv
, i
) = decl
;
10309 TREE_VEC_ELT (initv
, i
) = init
;
10316 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
10318 && !c_omp_check_loop_iv_exprs (locus
, code
,
10319 orig_declv
? orig_declv
: declv
, i
,
10320 TREE_VEC_ELT (declv
, i
), orig_init
,
10321 NULL_TREE
, cp_walk_subtrees
))
10327 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
10331 stmt
= make_node (code
);
10333 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
10335 /* This is really just a place-holder. We'll be decomposing this
10336 again and going through the cp_build_modify_expr path below when
10337 we instantiate the thing. */
10338 TREE_VEC_ELT (initv
, i
)
10339 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
10340 TREE_VEC_ELT (initv
, i
));
10343 TREE_TYPE (stmt
) = void_type_node
;
10344 OMP_FOR_INIT (stmt
) = initv
;
10345 OMP_FOR_COND (stmt
) = condv
;
10346 OMP_FOR_INCR (stmt
) = incrv
;
10347 OMP_FOR_BODY (stmt
) = body
;
10348 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
10349 OMP_FOR_CLAUSES (stmt
) = clauses
;
10351 SET_EXPR_LOCATION (stmt
, locus
);
10352 return add_stmt (stmt
);
10356 orig_declv
= copy_node (declv
);
10358 if (processing_template_decl
)
10359 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
10361 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
10363 decl
= TREE_VEC_ELT (declv
, i
);
10364 init
= TREE_VEC_ELT (initv
, i
);
10365 cond
= TREE_VEC_ELT (condv
, i
);
10366 incr
= TREE_VEC_ELT (incrv
, i
);
10368 TREE_VEC_ELT (orig_incr
, i
) = incr
;
10371 if (init
&& EXPR_HAS_LOCATION (init
))
10372 elocus
= EXPR_LOCATION (init
);
10374 if (!DECL_P (decl
))
10376 error_at (elocus
, "expected iteration declaration or initialization");
10380 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
10383 TREE_VEC_ELT (orig_incr
, i
) = incr
;
10384 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
10385 TREE_CODE (TREE_OPERAND (incr
, 1)),
10386 TREE_OPERAND (incr
, 2),
10387 tf_warning_or_error
);
10390 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
10392 if (code
== OMP_SIMD
)
10394 error_at (elocus
, "%<#pragma omp simd%> used with class "
10395 "iteration variable %qE", decl
);
10398 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
10399 initv
, condv
, incrv
, &body
,
10400 &pre_body
, clauses
,
10401 collapse
, ordered
))
10406 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
10407 && !TYPE_PTR_P (TREE_TYPE (decl
)))
10409 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
10413 if (!processing_template_decl
&& TREE_CODE (init
) != TREE_VEC
)
10414 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
10415 tf_warning_or_error
);
10417 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
10418 if (decl
== error_mark_node
|| init
== error_mark_node
)
10421 TREE_VEC_ELT (declv
, i
) = decl
;
10422 TREE_VEC_ELT (initv
, i
) = init
;
10423 TREE_VEC_ELT (condv
, i
) = cond
;
10424 TREE_VEC_ELT (incrv
, i
) = incr
;
10428 if (pre_body
&& IS_EMPTY_STMT (pre_body
))
10431 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
10432 incrv
, body
, pre_body
,
10433 !processing_template_decl
);
10435 /* Check for iterators appearing in lb, b or incr expressions. */
10436 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
10437 omp_for
= NULL_TREE
;
10439 if (omp_for
== NULL
)
10442 add_stmt (omp_for
);
10444 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
10446 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
);
10447 decl
= TREE_OPERAND (init
, 0);
10448 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), i
);
10449 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
10451 if (!processing_template_decl
)
10453 if (TREE_CODE (TREE_OPERAND (init
, 1)) == TREE_VEC
)
10455 tree t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1);
10456 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1)
10457 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10458 t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2);
10459 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2)
10460 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10464 tree t
= TREE_OPERAND (init
, 1);
10465 TREE_OPERAND (init
, 1)
10466 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10468 if (TREE_CODE (TREE_OPERAND (cond
, 1)) == TREE_VEC
)
10470 tree t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1);
10471 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1)
10472 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10473 t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2);
10474 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2)
10475 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10479 tree t
= TREE_OPERAND (cond
, 1);
10480 TREE_OPERAND (cond
, 1)
10481 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10485 if (TREE_CODE (incr
) != MODIFY_EXPR
)
10488 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
10489 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
10490 && !processing_template_decl
)
10492 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
10493 if (TREE_SIDE_EFFECTS (t
)
10495 && (TREE_CODE (t
) != NOP_EXPR
10496 || TREE_OPERAND (t
, 0) != decl
))
10497 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
10498 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10500 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
10501 if (TREE_SIDE_EFFECTS (t
)
10503 && (TREE_CODE (t
) != NOP_EXPR
10504 || TREE_OPERAND (t
, 0) != decl
))
10505 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
10506 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10510 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
10512 OMP_FOR_CLAUSES (omp_for
) = clauses
;
10514 /* For simd loops with non-static data member iterators, we could have added
10515 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
10516 step at this point, fill it in. */
10517 if (code
== OMP_SIMD
&& !processing_template_decl
10518 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
10519 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
10520 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
10521 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
10523 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
10524 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
10525 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
10527 switch (TREE_CODE (incr
))
10529 case PREINCREMENT_EXPR
:
10530 case POSTINCREMENT_EXPR
:
10531 /* c_omp_for_incr_canonicalize_ptr() should have been
10532 called to massage things appropriately. */
10533 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
10534 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
10536 case PREDECREMENT_EXPR
:
10537 case POSTDECREMENT_EXPR
:
10538 /* c_omp_for_incr_canonicalize_ptr() should have been
10539 called to massage things appropriately. */
10540 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
10541 OMP_CLAUSE_LINEAR_STEP (c
)
10542 = build_int_cst (TREE_TYPE (decl
), -1);
10545 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
10546 incr
= TREE_OPERAND (incr
, 1);
10547 switch (TREE_CODE (incr
))
10550 if (TREE_OPERAND (incr
, 1) == decl
)
10551 step
= TREE_OPERAND (incr
, 0);
10553 step
= TREE_OPERAND (incr
, 1);
10556 case POINTER_PLUS_EXPR
:
10557 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
10558 step
= TREE_OPERAND (incr
, 1);
10561 gcc_unreachable ();
10563 stept
= TREE_TYPE (decl
);
10564 if (INDIRECT_TYPE_P (stept
))
10566 step
= fold_convert (stept
, step
);
10567 if (TREE_CODE (incr
) == MINUS_EXPR
)
10568 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
10569 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
10572 gcc_unreachable ();
10575 /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
10576 clauses, we need copy ctor for those rather than default ctor,
10577 plus as for other lastprivates assignment op and dtor. */
10578 if (code
== OMP_LOOP
&& !processing_template_decl
)
10579 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10580 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
10581 && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
)
10582 && cxx_omp_create_clause_info (c
, TREE_TYPE (OMP_CLAUSE_DECL (c
)),
10583 false, true, true, true))
10584 CP_OMP_CLAUSE_INFO (c
) = NULL_TREE
;
10589 /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS
10590 and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */
10593 finish_omp_for_block (tree bind
, tree omp_for
)
10595 if (omp_for
== NULL_TREE
10596 || !OMP_FOR_ORIG_DECLS (omp_for
)
10597 || bind
== NULL_TREE
10598 || TREE_CODE (bind
) != BIND_EXPR
)
10600 tree b
= NULL_TREE
;
10601 for (int i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for
)); i
++)
10602 if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)) == TREE_LIST
10603 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)))
10605 tree v
= TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
));
10606 gcc_assert (BIND_EXPR_BLOCK (bind
)
10607 && (BIND_EXPR_VARS (bind
)
10608 == BLOCK_VARS (BIND_EXPR_BLOCK (bind
))));
10609 for (int j
= 2; j
< TREE_VEC_LENGTH (v
); j
++)
10610 for (tree
*p
= &BIND_EXPR_VARS (bind
); *p
; p
= &DECL_CHAIN (*p
))
10612 if (*p
== TREE_VEC_ELT (v
, j
))
10615 *p
= DECL_CHAIN (*p
);
10616 if (b
== NULL_TREE
)
10618 b
= make_node (BLOCK
);
10619 b
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
10620 OMP_FOR_BODY (omp_for
), b
);
10621 TREE_SIDE_EFFECTS (b
) = 1;
10622 OMP_FOR_BODY (omp_for
) = b
;
10624 DECL_CHAIN (var
) = BIND_EXPR_VARS (b
);
10625 BIND_EXPR_VARS (b
) = var
;
10626 BLOCK_VARS (BIND_EXPR_BLOCK (b
)) = var
;
10629 BLOCK_VARS (BIND_EXPR_BLOCK (bind
)) = BIND_EXPR_VARS (bind
);
10635 finish_omp_atomic (location_t loc
, enum tree_code code
, enum tree_code opcode
,
10636 tree lhs
, tree rhs
, tree v
, tree lhs1
, tree rhs1
, tree r
,
10637 tree clauses
, enum omp_memory_order mo
, bool weak
)
10654 dependent_p
= false;
10657 /* Even in a template, we can detect invalid uses of the atomic
10658 pragma if neither LHS nor RHS is type-dependent. */
10659 if (processing_template_decl
)
10661 dependent_p
= (type_dependent_expression_p (lhs
)
10662 || (rhs
&& type_dependent_expression_p (rhs
))
10663 || (v
&& type_dependent_expression_p (v
))
10664 || (lhs1
&& type_dependent_expression_p (lhs1
))
10665 || (rhs1
&& type_dependent_expression_p (rhs1
))
10667 && r
!= void_list_node
10668 && type_dependent_expression_p (r
)));
10671 gcc_assert (TREE_CODE (clauses
) == OMP_CLAUSE
10672 && OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_HINT
10673 && OMP_CLAUSE_CHAIN (clauses
) == NULL_TREE
);
10674 if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses
))
10675 || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses
)) != INTEGER_CST
)
10676 dependent_p
= true;
10680 lhs
= build_non_dependent_expr (lhs
);
10682 rhs
= build_non_dependent_expr (rhs
);
10684 v
= build_non_dependent_expr (v
);
10686 lhs1
= build_non_dependent_expr (lhs1
);
10688 rhs1
= build_non_dependent_expr (rhs1
);
10689 if (r
&& r
!= void_list_node
)
10690 r
= build_non_dependent_expr (r
);
10695 bool swapped
= false;
10696 if (rhs1
&& opcode
!= COND_EXPR
&& cp_tree_equal (lhs
, rhs
))
10698 std::swap (rhs
, rhs1
);
10699 swapped
= !commutative_tree_code (opcode
);
10701 if (rhs1
&& opcode
!= COND_EXPR
&& !cp_tree_equal (lhs
, rhs1
))
10703 if (code
== OMP_ATOMIC
)
10704 error ("%<#pragma omp atomic update%> uses two different "
10705 "expressions for memory");
10707 error ("%<#pragma omp atomic capture%> uses two different "
10708 "expressions for memory");
10711 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
10713 if (code
== OMP_ATOMIC
)
10714 error ("%<#pragma omp atomic update%> uses two different "
10715 "expressions for memory");
10717 error ("%<#pragma omp atomic capture%> uses two different "
10718 "expressions for memory");
10721 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
,
10722 v
, lhs1
, rhs1
, r
, swapped
, mo
, weak
,
10723 processing_template_decl
!= 0);
10724 if (stmt
== error_mark_node
)
10727 if (processing_template_decl
)
10729 if (code
== OMP_ATOMIC_READ
)
10731 stmt
= build_min_nt_loc (loc
, OMP_ATOMIC_READ
, orig_lhs
);
10732 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
10733 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
10737 if (opcode
== NOP_EXPR
)
10738 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
10739 else if (opcode
== COND_EXPR
)
10741 stmt
= build2 (EQ_EXPR
, boolean_type_node
, orig_lhs
, orig_rhs
);
10743 stmt
= build2 (MODIFY_EXPR
, boolean_type_node
, orig_r
,
10745 stmt
= build3 (COND_EXPR
, void_type_node
, stmt
, orig_rhs1
,
10747 orig_rhs1
= NULL_TREE
;
10750 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
10752 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
10753 COMPOUND_EXPR
, orig_rhs1
, stmt
);
10754 if (code
!= OMP_ATOMIC
)
10756 stmt
= build_min_nt_loc (loc
, code
, orig_lhs1
, stmt
);
10757 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
10758 OMP_ATOMIC_WEAK (stmt
) = weak
;
10759 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
10762 stmt
= build2 (OMP_ATOMIC
, void_type_node
,
10763 clauses
? clauses
: integer_zero_node
, stmt
);
10764 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
10765 OMP_ATOMIC_WEAK (stmt
) = weak
;
10766 SET_EXPR_LOCATION (stmt
, loc
);
10769 /* Avoid -Wunused-value warnings here, the whole construct has side-effects
10770 and even if it might be wrapped from fold-const.c or c-omp.c wrapped
10771 in some tree that appears to be unused, the value is not unused. */
10772 warning_sentinel
w (warn_unused_value
);
10773 finish_expr_stmt (stmt
);
10777 finish_omp_barrier (void)
10779 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
10781 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10782 finish_expr_stmt (stmt
);
10786 finish_omp_depobj (location_t loc
, tree depobj
,
10787 enum omp_clause_depend_kind kind
, tree clause
)
10789 if (!error_operand_p (depobj
) && !type_dependent_expression_p (depobj
))
10791 if (!lvalue_p (depobj
))
10793 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
10794 "%<depobj%> expression is not lvalue expression");
10795 depobj
= error_mark_node
;
10799 if (processing_template_decl
)
10801 if (clause
== NULL_TREE
)
10802 clause
= build_int_cst (integer_type_node
, kind
);
10803 add_stmt (build_min_nt_loc (loc
, OMP_DEPOBJ
, depobj
, clause
));
10807 if (!error_operand_p (depobj
))
10809 tree addr
= cp_build_addr_expr (depobj
, tf_warning_or_error
);
10810 if (addr
== error_mark_node
)
10811 depobj
= error_mark_node
;
10813 depobj
= cp_build_indirect_ref (loc
, addr
, RO_UNARY_STAR
,
10814 tf_warning_or_error
);
10817 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
10821 finish_omp_flush (int mo
)
10823 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
10825 if (mo
!= MEMMODEL_LAST
&& mo
!= MEMMODEL_SEQ_CST
)
10827 fn
= builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE
);
10828 vec
->quick_push (build_int_cst (integer_type_node
, mo
));
10830 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10831 finish_expr_stmt (stmt
);
10835 finish_omp_taskwait (void)
10837 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
10839 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10840 finish_expr_stmt (stmt
);
10844 finish_omp_taskyield (void)
10846 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
10848 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10849 finish_expr_stmt (stmt
);
10853 finish_omp_cancel (tree clauses
)
10855 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
10857 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
10859 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
10861 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
10863 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
10867 error ("%<#pragma omp cancel%> must specify one of "
10868 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
10872 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
10873 if (ifc
!= NULL_TREE
)
10875 if (OMP_CLAUSE_IF_MODIFIER (ifc
) != ERROR_MARK
10876 && OMP_CLAUSE_IF_MODIFIER (ifc
) != VOID_CST
)
10877 error_at (OMP_CLAUSE_LOCATION (ifc
),
10878 "expected %<cancel%> %<if%> clause modifier");
10881 tree ifc2
= omp_find_clause (OMP_CLAUSE_CHAIN (ifc
), OMP_CLAUSE_IF
);
10882 if (ifc2
!= NULL_TREE
)
10884 gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc
) == VOID_CST
10885 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != ERROR_MARK
10886 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != VOID_CST
);
10887 error_at (OMP_CLAUSE_LOCATION (ifc2
),
10888 "expected %<cancel%> %<if%> clause modifier");
10892 if (!processing_template_decl
)
10893 ifc
= maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc
));
10895 ifc
= build_x_binary_op (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
10896 OMP_CLAUSE_IF_EXPR (ifc
), ERROR_MARK
,
10897 integer_zero_node
, ERROR_MARK
,
10898 NULL_TREE
, NULL
, tf_warning_or_error
);
10901 ifc
= boolean_true_node
;
10902 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
10903 vec
->quick_push (ifc
);
10904 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10905 finish_expr_stmt (stmt
);
10909 finish_omp_cancellation_point (tree clauses
)
10911 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
10913 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
10915 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
10917 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
10919 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
10923 error ("%<#pragma omp cancellation point%> must specify one of "
10924 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
10928 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
10929 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10930 finish_expr_stmt (stmt
);
10933 /* Begin a __transaction_atomic or __transaction_relaxed statement.
10934 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
10935 should create an extra compound stmt. */
10938 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
10943 *pcompound
= begin_compound_stmt (0);
10945 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
10947 /* Only add the statement to the function if support enabled. */
10951 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
10952 ? G_("%<__transaction_relaxed%> without "
10953 "transactional memory support enabled")
10954 : G_("%<__transaction_atomic%> without "
10955 "transactional memory support enabled")));
10957 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
10958 TREE_SIDE_EFFECTS (r
) = 1;
10962 /* End a __transaction_atomic or __transaction_relaxed statement.
10963 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
10964 and we should end the compound. If NOEX is non-NULL, we wrap the body in
10965 a MUST_NOT_THROW_EXPR with NOEX as condition. */
10968 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
10970 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
10971 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
10972 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
10973 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
10975 /* noexcept specifications are not allowed for function transactions. */
10976 gcc_assert (!(noex
&& compound_stmt
));
10979 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
10981 protected_set_expr_location
10982 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
10983 TREE_SIDE_EFFECTS (body
) = 1;
10984 TRANSACTION_EXPR_BODY (stmt
) = body
;
10988 finish_compound_stmt (compound_stmt
);
10991 /* Build a __transaction_atomic or __transaction_relaxed expression. If
10992 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
10996 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
11001 expr
= build_must_not_throw_expr (expr
, noex
);
11002 protected_set_expr_location (expr
, loc
);
11003 TREE_SIDE_EFFECTS (expr
) = 1;
11005 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
11006 if (flags
& TM_STMT_ATTR_RELAXED
)
11007 TRANSACTION_EXPR_RELAXED (ret
) = 1;
11008 TREE_SIDE_EFFECTS (ret
) = 1;
11009 SET_EXPR_LOCATION (ret
, loc
);
11014 init_cp_semantics (void)
11019 /* If we have a condition in conjunctive normal form (CNF), find the first
11020 failing clause. In other words, given an expression like
11022 true && true && false && true && false
11024 return the first 'false'. EXPR is the expression. */
11027 find_failing_clause_r (tree expr
)
11029 if (TREE_CODE (expr
) == TRUTH_ANDIF_EXPR
)
11031 /* First check the left side... */
11032 tree e
= find_failing_clause_r (TREE_OPERAND (expr
, 0));
11033 if (e
== NULL_TREE
)
11034 /* ...if we didn't find a false clause, check the right side. */
11035 e
= find_failing_clause_r (TREE_OPERAND (expr
, 1));
11038 tree e
= contextual_conv_bool (expr
, tf_none
);
11039 e
= fold_non_dependent_expr (e
, tf_none
, /*manifestly_const_eval=*/true);
11040 if (integer_zerop (e
))
11041 /* This is the failing clause. */
11046 /* Wrapper for find_failing_clause_r. */
11049 find_failing_clause (tree expr
)
11051 if (TREE_CODE (expr
) != TRUTH_ANDIF_EXPR
)
11053 return find_failing_clause_r (expr
);
11056 /* Build a STATIC_ASSERT for a static assertion with the condition
11057 CONDITION and the message text MESSAGE. LOCATION is the location
11058 of the static assertion in the source code. When MEMBER_P, this
11059 static assertion is a member of a class. If SHOW_EXPR_P is true,
11060 print the condition (because it was instantiation-dependent). */
11063 finish_static_assert (tree condition
, tree message
, location_t location
,
11064 bool member_p
, bool show_expr_p
)
11066 tsubst_flags_t complain
= tf_warning_or_error
;
11068 if (message
== NULL_TREE
11069 || message
== error_mark_node
11070 || condition
== NULL_TREE
11071 || condition
== error_mark_node
)
11074 if (check_for_bare_parameter_packs (condition
))
11075 condition
= error_mark_node
;
11077 if (instantiation_dependent_expression_p (condition
))
11079 /* We're in a template; build a STATIC_ASSERT and put it in
11080 the right place. */
11083 assertion
= make_node (STATIC_ASSERT
);
11084 STATIC_ASSERT_CONDITION (assertion
) = condition
;
11085 STATIC_ASSERT_MESSAGE (assertion
) = message
;
11086 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
11089 maybe_add_class_template_decl_list (current_class_type
,
11093 add_stmt (assertion
);
11098 /* Save the condition in case it was a concept check. */
11099 tree orig_condition
= condition
;
11101 /* Fold the expression and convert it to a boolean value. */
11102 condition
= contextual_conv_bool (condition
, complain
);
11103 condition
= fold_non_dependent_expr (condition
, complain
,
11104 /*manifestly_const_eval=*/true);
11106 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
11107 /* Do nothing; the condition is satisfied. */
11111 iloc_sentinel
ils (location
);
11113 if (integer_zerop (condition
))
11115 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
11116 (TREE_TYPE (TREE_TYPE (message
))));
11117 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
11119 /* See if we can find which clause was failing (for logical AND). */
11120 tree bad
= find_failing_clause (orig_condition
);
11121 /* If not, or its location is unusable, fall back to the previous
11123 location_t cloc
= location
;
11124 if (cp_expr_location (bad
) != UNKNOWN_LOCATION
)
11125 cloc
= cp_expr_location (bad
);
11127 /* Report the error. */
11129 error_at (cloc
, "static assertion failed");
11131 error_at (cloc
, "static assertion failed: %s",
11132 TREE_STRING_POINTER (message
));
11134 inform (cloc
, "%qE evaluates to false",
11135 /* Nobody wants to see the artificial (bool) cast. */
11136 (bad
? tree_strip_nop_conversions (bad
) : orig_condition
));
11138 /* Actually explain the failure if this is a concept check or a
11139 requires-expression. */
11140 if (concept_check_p (orig_condition
)
11141 || TREE_CODE (orig_condition
) == REQUIRES_EXPR
)
11142 diagnose_constraints (location
, orig_condition
, NULL_TREE
);
11144 else if (condition
&& condition
!= error_mark_node
)
11146 error ("non-constant condition for static assertion");
11147 if (require_rvalue_constant_expression (condition
))
11148 cxx_constant_value (condition
);
11153 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
11154 suitable for use as a type-specifier.
11156 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
11157 id-expression or a class member access, FALSE when it was parsed as
11158 a full expression. */
11161 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
11162 tsubst_flags_t complain
)
11164 tree type
= NULL_TREE
;
11166 if (!expr
|| error_operand_p (expr
))
11167 return error_mark_node
;
11170 || TREE_CODE (expr
) == TYPE_DECL
11171 || (TREE_CODE (expr
) == BIT_NOT_EXPR
11172 && TYPE_P (TREE_OPERAND (expr
, 0))))
11174 if (complain
& tf_error
)
11175 error ("argument to %<decltype%> must be an expression");
11176 return error_mark_node
;
11179 /* decltype is an unevaluated context. */
11182 /* Depending on the resolution of DR 1172, we may later need to distinguish
11183 instantiation-dependent but not type-dependent expressions so that, say,
11184 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
11185 if (instantiation_dependent_uneval_expression_p (expr
))
11187 type
= cxx_make_type (DECLTYPE_TYPE
);
11188 DECLTYPE_TYPE_EXPR (type
) = expr
;
11189 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
11190 = id_expression_or_member_access_p
;
11191 SET_TYPE_STRUCTURAL_EQUALITY (type
);
11195 else if (processing_template_decl
)
11197 expr
= instantiate_non_dependent_expr_sfinae (expr
, complain
);
11198 if (expr
== error_mark_node
)
11199 return error_mark_node
;
11202 /* The type denoted by decltype(e) is defined as follows: */
11204 expr
= resolve_nondeduced_context (expr
, complain
);
11206 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
11207 return error_mark_node
;
11209 if (type_unknown_p (expr
))
11211 if (complain
& tf_error
)
11212 error ("%<decltype%> cannot resolve address of overloaded function");
11213 return error_mark_node
;
11216 /* To get the size of a static data member declared as an array of
11217 unknown bound, we need to instantiate it. */
11219 && VAR_HAD_UNKNOWN_BOUND (expr
)
11220 && DECL_TEMPLATE_INSTANTIATION (expr
))
11221 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
11223 if (id_expression_or_member_access_p
)
11225 /* If e is an id-expression or a class member access (5.2.5
11226 [expr.ref]), decltype(e) is defined as the type of the entity
11227 named by e. If there is no such entity, or e names a set of
11228 overloaded functions, the program is ill-formed. */
11229 if (identifier_p (expr
))
11230 expr
= lookup_name (expr
);
11232 if (INDIRECT_REF_P (expr
)
11233 || TREE_CODE (expr
) == VIEW_CONVERT_EXPR
)
11234 /* This can happen when the expression is, e.g., "a.b". Just
11235 look at the underlying operand. */
11236 expr
= TREE_OPERAND (expr
, 0);
11238 if (TREE_CODE (expr
) == OFFSET_REF
11239 || TREE_CODE (expr
) == MEMBER_REF
11240 || TREE_CODE (expr
) == SCOPE_REF
)
11241 /* We're only interested in the field itself. If it is a
11242 BASELINK, we will need to see through it in the next
11244 expr
= TREE_OPERAND (expr
, 1);
11246 if (BASELINK_P (expr
))
11247 /* See through BASELINK nodes to the underlying function. */
11248 expr
= BASELINK_FUNCTIONS (expr
);
11250 /* decltype of a decomposition name drops references in the tuple case
11251 (unlike decltype of a normal variable) and keeps cv-qualifiers from
11252 the containing object in the other cases (unlike decltype of a member
11253 access expression). */
11254 if (DECL_DECOMPOSITION_P (expr
))
11256 if (DECL_HAS_VALUE_EXPR_P (expr
))
11257 /* Expr is an array or struct subobject proxy, handle
11258 bit-fields properly. */
11259 return unlowered_expr_type (expr
);
11261 /* Expr is a reference variable for the tuple case. */
11262 return lookup_decomp_type (expr
);
11265 switch (TREE_CODE (expr
))
11268 if (DECL_BIT_FIELD_TYPE (expr
))
11270 type
= DECL_BIT_FIELD_TYPE (expr
);
11273 /* Fall through for fields that aren't bitfields. */
11274 gcc_fallthrough ();
11276 case FUNCTION_DECL
:
11281 case TEMPLATE_PARM_INDEX
:
11282 expr
= mark_type_use (expr
);
11283 type
= TREE_TYPE (expr
);
11287 type
= error_mark_node
;
11290 case COMPONENT_REF
:
11291 case COMPOUND_EXPR
:
11292 mark_type_use (expr
);
11293 type
= is_bitfield_expr_with_lowered_type (expr
);
11295 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
11298 case BIT_FIELD_REF
:
11299 gcc_unreachable ();
11303 /* We can get here when the id-expression refers to an
11304 enumerator or non-type template parameter. */
11305 type
= TREE_TYPE (expr
);
11309 /* Handle instantiated template non-type arguments. */
11310 type
= TREE_TYPE (expr
);
11316 /* Within a lambda-expression:
11318 Every occurrence of decltype((x)) where x is a possibly
11319 parenthesized id-expression that names an entity of
11320 automatic storage duration is treated as if x were
11321 transformed into an access to a corresponding data member
11322 of the closure type that would have been declared if x
11323 were a use of the denoted entity. */
11324 if (outer_automatic_var_p (expr
)
11325 && current_function_decl
11326 && LAMBDA_FUNCTION_P (current_function_decl
))
11327 type
= capture_decltype (expr
);
11328 else if (error_operand_p (expr
))
11329 type
= error_mark_node
;
11330 else if (expr
== current_class_ptr
)
11331 /* If the expression is just "this", we want the
11332 cv-unqualified pointer for the "this" type. */
11333 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
11336 /* Otherwise, where T is the type of e, if e is an lvalue,
11337 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
11338 cp_lvalue_kind clk
= lvalue_kind (expr
);
11339 type
= unlowered_expr_type (expr
);
11340 gcc_assert (!TYPE_REF_P (type
));
11342 /* For vector types, pick a non-opaque variant. */
11343 if (VECTOR_TYPE_P (type
))
11344 type
= strip_typedefs (type
);
11346 if (clk
!= clk_none
&& !(clk
& clk_class
))
11347 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
11354 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
11355 __has_nothrow_copy, depending on assign_p. Returns true iff all
11356 the copy {ctor,assign} fns are nothrow. */
11359 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
11361 tree fns
= NULL_TREE
;
11363 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
11364 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
11365 : ctor_identifier
);
11367 bool saw_copy
= false;
11368 for (ovl_iterator
iter (fns
); iter
; ++iter
)
11372 if (copy_fn_p (fn
) > 0)
11375 if (!maybe_instantiate_noexcept (fn
)
11376 || !TYPE_NOTHROW_P (TREE_TYPE (fn
)))
11384 /* Return true if DERIVED is pointer interconvertible base of BASE. */
11387 pointer_interconvertible_base_of_p (tree base
, tree derived
)
11389 if (base
== error_mark_node
|| derived
== error_mark_node
)
11391 base
= TYPE_MAIN_VARIANT (base
);
11392 derived
= TYPE_MAIN_VARIANT (derived
);
11393 if (!NON_UNION_CLASS_TYPE_P (base
)
11394 || !NON_UNION_CLASS_TYPE_P (derived
))
11397 if (same_type_p (base
, derived
))
11400 if (!std_layout_type_p (derived
))
11403 return uniquely_derived_from_p (base
, derived
);
11406 /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
11407 return true if MEMBERTYPE is the type of the first non-static data member
11408 of TYPE or for unions of any members. */
11410 first_nonstatic_data_member_p (tree type
, tree membertype
)
11412 for (tree field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
11414 if (TREE_CODE (field
) != FIELD_DECL
)
11416 if (DECL_FIELD_IS_BASE (field
) && is_empty_field (field
))
11418 if (DECL_FIELD_IS_BASE (field
))
11419 return first_nonstatic_data_member_p (TREE_TYPE (field
), membertype
);
11420 if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
11422 if ((TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
11423 || std_layout_type_p (TREE_TYPE (field
)))
11424 && first_nonstatic_data_member_p (TREE_TYPE (field
), membertype
))
11427 else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field
),
11430 if (TREE_CODE (type
) != UNION_TYPE
)
11436 /* Fold __builtin_is_pointer_interconvertible_with_class call. */
11439 fold_builtin_is_pointer_inverconvertible_with_class (location_t loc
, int nargs
,
11442 /* Unless users call the builtin directly, the following 3 checks should be
11443 ensured from std::is_pointer_interconvertible_with_class function
11447 error_at (loc
, "%<__builtin_is_pointer_interconvertible_with_class%> "
11448 "needs a single argument");
11449 return boolean_false_node
;
11451 tree arg
= args
[0];
11452 if (error_operand_p (arg
))
11453 return boolean_false_node
;
11454 if (!TYPE_PTRMEM_P (TREE_TYPE (arg
)))
11456 error_at (loc
, "%<__builtin_is_pointer_interconvertible_with_class%> "
11457 "argument is not pointer to member");
11458 return boolean_false_node
;
11461 if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg
)))
11462 return boolean_false_node
;
11464 tree membertype
= TREE_TYPE (TREE_TYPE (arg
));
11465 tree basetype
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg
));
11466 if (!complete_type_or_else (basetype
, NULL_TREE
))
11467 return boolean_false_node
;
11469 if (TREE_CODE (basetype
) != UNION_TYPE
11470 && !std_layout_type_p (basetype
))
11471 return boolean_false_node
;
11473 if (!first_nonstatic_data_member_p (basetype
, membertype
))
11474 return boolean_false_node
;
11476 if (TREE_CODE (arg
) == PTRMEM_CST
)
11477 arg
= cplus_expand_constant (arg
);
11479 if (integer_nonzerop (arg
))
11480 return boolean_false_node
;
11481 if (integer_zerop (arg
))
11482 return boolean_true_node
;
11484 return fold_build2 (EQ_EXPR
, boolean_type_node
, arg
,
11485 build_zero_cst (TREE_TYPE (arg
)));
11488 /* Helper function for is_corresponding_member_aggr. Return true if
11489 MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
11490 union or structure BASETYPE. */
11493 is_corresponding_member_union (tree basetype
, tree membertype
, tree arg
)
11495 for (tree field
= TYPE_FIELDS (basetype
); field
; field
= DECL_CHAIN (field
))
11496 if (TREE_CODE (field
) != FIELD_DECL
|| DECL_BIT_FIELD_TYPE (field
))
11498 else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field
),
11501 if (TREE_CODE (arg
) != INTEGER_CST
11502 || tree_int_cst_equal (arg
, byte_position (field
)))
11505 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
11508 if (TREE_CODE (basetype
) != UNION_TYPE
11509 && TREE_CODE (narg
) == INTEGER_CST
)
11510 narg
= size_binop (MINUS_EXPR
, arg
, byte_position (field
));
11511 if (is_corresponding_member_union (TREE_TYPE (field
),
11518 /* Helper function for fold_builtin_is_corresponding_member call.
11519 Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
11520 MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
11521 boolean_true_node if they are corresponding members, or for
11522 non-constant ARG2 the highest member offset for corresponding
11526 is_corresponding_member_aggr (location_t loc
, tree basetype1
, tree membertype1
,
11527 tree arg1
, tree basetype2
, tree membertype2
,
11530 tree field1
= TYPE_FIELDS (basetype1
);
11531 tree field2
= TYPE_FIELDS (basetype2
);
11532 tree ret
= boolean_false_node
;
11535 bool r
= next_common_initial_seqence (field1
, field2
);
11536 if (field1
== NULL_TREE
|| field2
== NULL_TREE
)
11539 && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1
),
11541 && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2
),
11544 tree pos
= byte_position (field1
);
11545 if (TREE_CODE (arg1
) == INTEGER_CST
11546 && tree_int_cst_equal (arg1
, pos
))
11548 if (TREE_CODE (arg2
) == INTEGER_CST
)
11549 return boolean_true_node
;
11552 else if (TREE_CODE (arg1
) != INTEGER_CST
)
11555 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1
))
11556 && ANON_AGGR_TYPE_P (TREE_TYPE (field2
)))
11558 if ((!lookup_attribute ("no_unique_address",
11559 DECL_ATTRIBUTES (field1
)))
11560 != !lookup_attribute ("no_unique_address",
11561 DECL_ATTRIBUTES (field2
)))
11563 if (!tree_int_cst_equal (bit_position (field1
),
11564 bit_position (field2
)))
11566 bool overlap
= true;
11567 tree pos
= byte_position (field1
);
11568 if (TREE_CODE (arg1
) == INTEGER_CST
)
11570 tree off1
= fold_convert (sizetype
, arg1
);
11571 tree sz1
= TYPE_SIZE_UNIT (TREE_TYPE (field1
));
11572 if (tree_int_cst_lt (off1
, pos
)
11573 || tree_int_cst_le (size_binop (PLUS_EXPR
, pos
, sz1
), off1
))
11576 if (TREE_CODE (arg2
) == INTEGER_CST
)
11578 tree off2
= fold_convert (sizetype
, arg2
);
11579 tree sz2
= TYPE_SIZE_UNIT (TREE_TYPE (field2
));
11580 if (tree_int_cst_lt (off2
, pos
)
11581 || tree_int_cst_le (size_binop (PLUS_EXPR
, pos
, sz2
), off2
))
11585 && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1
))
11586 && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2
)))
11589 if (TREE_CODE (arg1
) == INTEGER_CST
)
11590 narg1
= size_binop (MINUS_EXPR
,
11591 fold_convert (sizetype
, arg1
), pos
);
11593 if (TREE_CODE (arg2
) == INTEGER_CST
)
11594 narg2
= size_binop (MINUS_EXPR
,
11595 fold_convert (sizetype
, arg2
), pos
);
11596 tree t1
= TREE_TYPE (field1
);
11597 tree t2
= TREE_TYPE (field2
);
11598 tree nret
= is_corresponding_member_aggr (loc
, t1
, membertype1
,
11599 narg1
, t2
, membertype2
,
11601 if (nret
!= boolean_false_node
)
11603 if (nret
== boolean_true_node
)
11605 if (TREE_CODE (arg1
) == INTEGER_CST
)
11606 return size_binop (PLUS_EXPR
, nret
, pos
);
11607 ret
= size_binop (PLUS_EXPR
, nret
, pos
);
11611 && TREE_CODE (TREE_TYPE (field1
)) == UNION_TYPE
11612 && TREE_CODE (TREE_TYPE (field2
)) == UNION_TYPE
)
11615 if (TREE_CODE (arg1
) == INTEGER_CST
)
11616 narg1
= size_binop (MINUS_EXPR
,
11617 fold_convert (sizetype
, arg1
), pos
);
11619 if (TREE_CODE (arg2
) == INTEGER_CST
)
11620 narg2
= size_binop (MINUS_EXPR
,
11621 fold_convert (sizetype
, arg2
), pos
);
11622 if (is_corresponding_member_union (TREE_TYPE (field1
),
11623 membertype1
, narg1
)
11624 && is_corresponding_member_union (TREE_TYPE (field2
),
11625 membertype2
, narg2
))
11627 sorry_at (loc
, "%<__builtin_is_corresponding_member%> "
11628 "not well defined for anonymous unions");
11629 return boolean_false_node
;
11635 field1
= DECL_CHAIN (field1
);
11636 field2
= DECL_CHAIN (field2
);
11641 /* Fold __builtin_is_corresponding_member call. */
11644 fold_builtin_is_corresponding_member (location_t loc
, int nargs
,
11647 /* Unless users call the builtin directly, the following 3 checks should be
11648 ensured from std::is_corresponding_member function template. */
11651 error_at (loc
, "%<__builtin_is_corresponding_member%> "
11652 "needs two arguments");
11653 return boolean_false_node
;
11655 tree arg1
= args
[0];
11656 tree arg2
= args
[1];
11657 if (error_operand_p (arg1
) || error_operand_p (arg2
))
11658 return boolean_false_node
;
11659 if (!TYPE_PTRMEM_P (TREE_TYPE (arg1
))
11660 || !TYPE_PTRMEM_P (TREE_TYPE (arg2
)))
11662 error_at (loc
, "%<__builtin_is_corresponding_member%> "
11663 "argument is not pointer to member");
11664 return boolean_false_node
;
11667 if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1
))
11668 || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2
)))
11669 return boolean_false_node
;
11671 tree membertype1
= TREE_TYPE (TREE_TYPE (arg1
));
11672 tree basetype1
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1
));
11673 if (!complete_type_or_else (basetype1
, NULL_TREE
))
11674 return boolean_false_node
;
11676 tree membertype2
= TREE_TYPE (TREE_TYPE (arg2
));
11677 tree basetype2
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2
));
11678 if (!complete_type_or_else (basetype2
, NULL_TREE
))
11679 return boolean_false_node
;
11681 if (!NON_UNION_CLASS_TYPE_P (basetype1
)
11682 || !NON_UNION_CLASS_TYPE_P (basetype2
)
11683 || !std_layout_type_p (basetype1
)
11684 || !std_layout_type_p (basetype2
))
11685 return boolean_false_node
;
11687 /* If the member types aren't layout compatible, then they
11688 can't be corresponding members. */
11689 if (!layout_compatible_type_p (membertype1
, membertype2
))
11690 return boolean_false_node
;
11692 if (TREE_CODE (arg1
) == PTRMEM_CST
)
11693 arg1
= cplus_expand_constant (arg1
);
11694 if (TREE_CODE (arg2
) == PTRMEM_CST
)
11695 arg2
= cplus_expand_constant (arg2
);
11697 if (null_member_pointer_value_p (arg1
)
11698 || null_member_pointer_value_p (arg2
))
11699 return boolean_false_node
;
11701 if (TREE_CODE (arg1
) == INTEGER_CST
11702 && TREE_CODE (arg2
) == INTEGER_CST
11703 && !tree_int_cst_equal (arg1
, arg2
))
11704 return boolean_false_node
;
11706 if (TREE_CODE (arg2
) == INTEGER_CST
11707 && TREE_CODE (arg1
) != INTEGER_CST
)
11709 std::swap (arg1
, arg2
);
11710 std::swap (membertype1
, membertype2
);
11711 std::swap (basetype1
, basetype2
);
11714 tree ret
= is_corresponding_member_aggr (loc
, basetype1
, membertype1
, arg1
,
11715 basetype2
, membertype2
, arg2
);
11716 if (TREE_TYPE (ret
) == boolean_type_node
)
11718 /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
11719 already returns boolean_{true,false}_node whether those particular
11720 members are corresponding members or not. Otherwise, if only
11721 one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
11722 above), it returns boolean_false_node if it is certainly not a
11723 corresponding member and otherwise we need to do a runtime check that
11724 those two OFFSET_TYPE offsets are equal.
11725 If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
11726 returns the largest offset at which the members would be corresponding
11727 members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
11728 gcc_assert (TREE_CODE (arg2
) != INTEGER_CST
);
11729 if (TREE_CODE (arg1
) == INTEGER_CST
)
11730 return fold_build2 (EQ_EXPR
, boolean_type_node
, arg1
,
11731 fold_convert (TREE_TYPE (arg1
), arg2
));
11732 ret
= fold_build2 (LE_EXPR
, boolean_type_node
,
11733 fold_convert (pointer_sized_int_node
, arg1
),
11734 fold_convert (pointer_sized_int_node
, ret
));
11735 return fold_build2 (TRUTH_AND_EXPR
, boolean_type_node
, ret
,
11736 fold_build2 (EQ_EXPR
, boolean_type_node
, arg1
,
11737 fold_convert (TREE_TYPE (arg1
), arg2
)));
11740 /* Actually evaluates the trait. */
11743 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
11745 enum tree_code type_code1
;
11748 type_code1
= TREE_CODE (type1
);
11752 case CPTK_HAS_NOTHROW_ASSIGN
:
11753 type1
= strip_array_types (type1
);
11754 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
11755 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
11756 || (CLASS_TYPE_P (type1
)
11757 && classtype_has_nothrow_assign_or_copy_p (type1
,
11760 case CPTK_HAS_TRIVIAL_ASSIGN
:
11761 /* ??? The standard seems to be missing the "or array of such a class
11762 type" wording for this trait. */
11763 type1
= strip_array_types (type1
);
11764 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
11765 && (trivial_type_p (type1
)
11766 || (CLASS_TYPE_P (type1
)
11767 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
11769 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
11770 type1
= strip_array_types (type1
);
11771 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
11772 || (CLASS_TYPE_P (type1
)
11773 && (t
= locate_ctor (type1
))
11774 && maybe_instantiate_noexcept (t
)
11775 && TYPE_NOTHROW_P (TREE_TYPE (t
))));
11777 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
11778 type1
= strip_array_types (type1
);
11779 return (trivial_type_p (type1
)
11780 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
11782 case CPTK_HAS_NOTHROW_COPY
:
11783 type1
= strip_array_types (type1
);
11784 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
11785 || (CLASS_TYPE_P (type1
)
11786 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
11788 case CPTK_HAS_TRIVIAL_COPY
:
11789 /* ??? The standard seems to be missing the "or array of such a class
11790 type" wording for this trait. */
11791 type1
= strip_array_types (type1
);
11792 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
11793 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
11795 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
11796 type1
= strip_array_types (type1
);
11797 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
11798 || (CLASS_TYPE_P (type1
)
11799 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
11801 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
11802 return type_has_virtual_destructor (type1
);
11804 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
11805 return type_has_unique_obj_representations (type1
);
11807 case CPTK_IS_ABSTRACT
:
11808 return ABSTRACT_CLASS_TYPE_P (type1
);
11810 case CPTK_IS_AGGREGATE
:
11811 return CP_AGGREGATE_TYPE_P (type1
);
11813 case CPTK_IS_BASE_OF
:
11814 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
11815 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
11816 || DERIVED_FROM_P (type1
, type2
)));
11818 case CPTK_IS_CLASS
:
11819 return NON_UNION_CLASS_TYPE_P (type1
);
11821 case CPTK_IS_EMPTY
:
11822 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
11825 return type_code1
== ENUMERAL_TYPE
;
11827 case CPTK_IS_FINAL
:
11828 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
11830 case CPTK_IS_LAYOUT_COMPATIBLE
:
11831 return layout_compatible_type_p (type1
, type2
);
11833 case CPTK_IS_LITERAL_TYPE
:
11834 return literal_type_p (type1
);
11836 case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF
:
11837 return pointer_interconvertible_base_of_p (type1
, type2
);
11840 return pod_type_p (type1
);
11842 case CPTK_IS_POLYMORPHIC
:
11843 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
11845 case CPTK_IS_SAME_AS
:
11846 return same_type_p (type1
, type2
);
11848 case CPTK_IS_STD_LAYOUT
:
11849 return std_layout_type_p (type1
);
11851 case CPTK_IS_TRIVIAL
:
11852 return trivial_type_p (type1
);
11854 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
11855 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
11857 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
11858 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
11860 case CPTK_IS_TRIVIALLY_COPYABLE
:
11861 return trivially_copyable_p (type1
);
11863 case CPTK_IS_UNION
:
11864 return type_code1
== UNION_TYPE
;
11866 case CPTK_IS_ASSIGNABLE
:
11867 return is_xible (MODIFY_EXPR
, type1
, type2
);
11869 case CPTK_IS_CONSTRUCTIBLE
:
11870 return is_xible (INIT_EXPR
, type1
, type2
);
11872 case CPTK_IS_NOTHROW_ASSIGNABLE
:
11873 return is_nothrow_xible (MODIFY_EXPR
, type1
, type2
);
11875 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
11876 return is_nothrow_xible (INIT_EXPR
, type1
, type2
);
11879 gcc_unreachable ();
11884 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
11885 void, or a complete type, returns true, otherwise false. */
11888 check_trait_type (tree type
)
11890 if (type
== NULL_TREE
)
11893 if (TREE_CODE (type
) == TREE_LIST
)
11894 return (check_trait_type (TREE_VALUE (type
))
11895 && check_trait_type (TREE_CHAIN (type
)));
11897 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
11898 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
11901 if (VOID_TYPE_P (type
))
11904 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
11907 /* Process a trait expression. */
11910 finish_trait_expr (location_t loc
, cp_trait_kind kind
, tree type1
, tree type2
)
11912 if (type1
== error_mark_node
11913 || type2
== error_mark_node
)
11914 return error_mark_node
;
11916 if (processing_template_decl
)
11918 tree trait_expr
= make_node (TRAIT_EXPR
);
11919 TREE_TYPE (trait_expr
) = boolean_type_node
;
11920 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
11921 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
11922 TRAIT_EXPR_KIND (trait_expr
) = kind
;
11923 TRAIT_EXPR_LOCATION (trait_expr
) = loc
;
11929 case CPTK_HAS_NOTHROW_ASSIGN
:
11930 case CPTK_HAS_TRIVIAL_ASSIGN
:
11931 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
11932 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
11933 case CPTK_HAS_NOTHROW_COPY
:
11934 case CPTK_HAS_TRIVIAL_COPY
:
11935 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
11936 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
11937 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
11938 case CPTK_IS_ABSTRACT
:
11939 case CPTK_IS_AGGREGATE
:
11940 case CPTK_IS_EMPTY
:
11941 case CPTK_IS_FINAL
:
11942 case CPTK_IS_LITERAL_TYPE
:
11944 case CPTK_IS_POLYMORPHIC
:
11945 case CPTK_IS_STD_LAYOUT
:
11946 case CPTK_IS_TRIVIAL
:
11947 case CPTK_IS_TRIVIALLY_COPYABLE
:
11948 if (!check_trait_type (type1
))
11949 return error_mark_node
;
11952 case CPTK_IS_ASSIGNABLE
:
11953 case CPTK_IS_CONSTRUCTIBLE
:
11956 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
11957 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
11958 case CPTK_IS_NOTHROW_ASSIGNABLE
:
11959 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
11960 if (!check_trait_type (type1
)
11961 || !check_trait_type (type2
))
11962 return error_mark_node
;
11965 case CPTK_IS_BASE_OF
:
11966 case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF
:
11967 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
11968 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
11969 && !complete_type_or_else (type2
, NULL_TREE
))
11970 /* We already issued an error. */
11971 return error_mark_node
;
11974 case CPTK_IS_CLASS
:
11976 case CPTK_IS_UNION
:
11977 case CPTK_IS_SAME_AS
:
11980 case CPTK_IS_LAYOUT_COMPATIBLE
:
11981 if (!array_of_unknown_bound_p (type1
)
11982 && TREE_CODE (type1
) != VOID_TYPE
11983 && !complete_type_or_else (type1
, NULL_TREE
))
11984 /* We already issued an error. */
11985 return error_mark_node
;
11986 if (!array_of_unknown_bound_p (type2
)
11987 && TREE_CODE (type2
) != VOID_TYPE
11988 && !complete_type_or_else (type2
, NULL_TREE
))
11989 /* We already issued an error. */
11990 return error_mark_node
;
11994 gcc_unreachable ();
11997 tree val
= (trait_expr_value (kind
, type1
, type2
)
11998 ? boolean_true_node
: boolean_false_node
);
11999 return maybe_wrap_with_location (val
, loc
);
12002 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
12003 which is ignored for C++. */
12006 set_float_const_decimal64 (void)
12011 clear_float_const_decimal64 (void)
12016 float_const_decimal64_p (void)
12022 /* Return true if T designates the implied `this' parameter. */
12025 is_this_parameter (tree t
)
12027 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
12029 gcc_assert (TREE_CODE (t
) == PARM_DECL
12030 || (TREE_CODE (t
) == VAR_DECL
&& DECL_HAS_VALUE_EXPR_P (t
))
12031 || (cp_binding_oracle
&& TREE_CODE (t
) == VAR_DECL
));
12035 /* Insert the deduced return type for an auto function. */
12038 apply_deduced_return_type (tree fco
, tree return_type
)
12042 if (return_type
== error_mark_node
)
12045 if (DECL_CONV_FN_P (fco
))
12046 DECL_NAME (fco
) = make_conv_op_name (return_type
);
12048 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
12050 result
= DECL_RESULT (fco
);
12051 if (result
== NULL_TREE
)
12053 if (TREE_TYPE (result
) == return_type
)
12056 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
12057 && !complete_type_or_else (return_type
, NULL_TREE
))
12060 /* We already have a DECL_RESULT from start_preparsed_function.
12061 Now we need to redo the work it and allocate_struct_function
12062 did to reflect the new type. */
12063 gcc_assert (current_function_decl
== fco
);
12064 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
12065 TYPE_MAIN_VARIANT (return_type
));
12066 DECL_ARTIFICIAL (result
) = 1;
12067 DECL_IGNORED_P (result
) = 1;
12068 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
12071 DECL_RESULT (fco
) = result
;
12073 if (!processing_template_decl
)
12075 bool aggr
= aggregate_value_p (result
, fco
);
12076 #ifdef PCC_STATIC_STRUCT_RETURN
12077 cfun
->returns_pcc_struct
= aggr
;
12079 cfun
->returns_struct
= aggr
;
12083 /* DECL is a local variable or parameter from the surrounding scope of a
12084 lambda-expression. Returns the decltype for a use of the capture field
12085 for DECL even if it hasn't been captured yet. */
12088 capture_decltype (tree decl
)
12090 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
12091 tree cap
= lookup_name (DECL_NAME (decl
), LOOK_where::BLOCK
,
12092 LOOK_want::HIDDEN_LAMBDA
);
12095 if (cap
&& is_capture_proxy (cap
))
12096 type
= TREE_TYPE (cap
);
12098 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
12101 error ("%qD is not captured", decl
);
12102 return error_mark_node
;
12105 type
= TREE_TYPE (decl
);
12106 if (TYPE_REF_P (type
)
12107 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
12108 type
= TREE_TYPE (type
);
12111 case CPLD_REFERENCE
:
12112 type
= TREE_TYPE (decl
);
12113 if (!TYPE_REF_P (type
))
12114 type
= build_reference_type (TREE_TYPE (decl
));
12118 gcc_unreachable ();
12121 if (!TYPE_REF_P (type
))
12123 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
12124 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
12125 |TYPE_QUAL_CONST
));
12126 type
= build_reference_type (type
);
12131 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
12132 this is a right unary fold. Otherwise it is a left unary fold. */
12135 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
12137 /* Build a pack expansion (assuming expr has pack type). */
12138 if (!uses_parameter_packs (expr
))
12140 error_at (location_of (expr
), "operand of fold expression has no "
12141 "unexpanded parameter packs");
12142 return error_mark_node
;
12144 tree pack
= make_pack_expansion (expr
);
12146 /* Build the fold expression. */
12147 tree code
= build_int_cstu (integer_type_node
, abs (op
));
12148 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
);
12149 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
12150 TREE_TYPE (fold
) = build_dependent_operator_type (NULL_TREE
,
12151 FOLD_EXPR_OP (fold
),
12152 FOLD_EXPR_MODIFY_P (fold
));
12157 finish_left_unary_fold_expr (tree expr
, int op
)
12159 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
12163 finish_right_unary_fold_expr (tree expr
, int op
)
12165 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
12168 /* Build a binary fold expression over EXPR1 and EXPR2. The
12169 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
12170 has an unexpanded parameter pack). */
12173 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
12175 pack
= make_pack_expansion (pack
);
12176 tree code
= build_int_cstu (integer_type_node
, abs (op
));
12177 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
, init
);
12178 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
12179 TREE_TYPE (fold
) = build_dependent_operator_type (NULL_TREE
,
12180 FOLD_EXPR_OP (fold
),
12181 FOLD_EXPR_MODIFY_P (fold
));
12186 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
12188 // Determine which expr has an unexpanded parameter pack and
12189 // set the pack and initial term.
12190 bool pack1
= uses_parameter_packs (expr1
);
12191 bool pack2
= uses_parameter_packs (expr2
);
12192 if (pack1
&& !pack2
)
12193 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
12194 else if (pack2
&& !pack1
)
12195 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
12199 error ("both arguments in binary fold have unexpanded parameter packs");
12201 error ("no unexpanded parameter packs in binary fold");
12203 return error_mark_node
;
12206 /* Finish __builtin_launder (arg). */
12209 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
12211 tree orig_arg
= arg
;
12212 if (!type_dependent_expression_p (arg
))
12213 arg
= decay_conversion (arg
, complain
);
12214 if (error_operand_p (arg
))
12215 return error_mark_node
;
12216 if (!type_dependent_expression_p (arg
)
12217 && !TYPE_PTR_P (TREE_TYPE (arg
)))
12219 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
12220 return error_mark_node
;
12222 if (processing_template_decl
)
12224 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
12225 TREE_TYPE (arg
), 1, arg
);
12228 /* Finish __builtin_convertvector (arg, type). */
12231 cp_build_vec_convert (tree arg
, location_t loc
, tree type
,
12232 tsubst_flags_t complain
)
12234 if (error_operand_p (type
))
12235 return error_mark_node
;
12236 if (error_operand_p (arg
))
12237 return error_mark_node
;
12239 tree ret
= NULL_TREE
;
12240 if (!type_dependent_expression_p (arg
) && !dependent_type_p (type
))
12241 ret
= c_build_vec_convert (cp_expr_loc_or_input_loc (arg
),
12242 decay_conversion (arg
, complain
),
12243 loc
, type
, (complain
& tf_error
) != 0);
12245 if (!processing_template_decl
)
12248 return build_call_expr_internal_loc (loc
, IFN_VEC_CONVERT
, type
, 1, arg
);
12251 /* Finish __builtin_bit_cast (type, arg). */
12254 cp_build_bit_cast (location_t loc
, tree type
, tree arg
,
12255 tsubst_flags_t complain
)
12257 if (error_operand_p (type
))
12258 return error_mark_node
;
12259 if (!dependent_type_p (type
))
12261 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
))
12262 return error_mark_node
;
12263 if (TREE_CODE (type
) == ARRAY_TYPE
)
12265 /* std::bit_cast for destination ARRAY_TYPE is not possible,
12266 as functions may not return an array, so don't bother trying
12267 to support this (and then deal with VLAs etc.). */
12268 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
12269 "is an array type", type
);
12270 return error_mark_node
;
12272 if (!trivially_copyable_p (type
))
12274 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
12275 "is not trivially copyable", type
);
12276 return error_mark_node
;
12280 if (error_operand_p (arg
))
12281 return error_mark_node
;
12283 if (!type_dependent_expression_p (arg
))
12285 if (TREE_CODE (TREE_TYPE (arg
)) == ARRAY_TYPE
)
12287 /* Don't perform array-to-pointer conversion. */
12288 arg
= mark_rvalue_use (arg
, loc
, true);
12289 if (!complete_type_or_maybe_complain (TREE_TYPE (arg
), arg
, complain
))
12290 return error_mark_node
;
12293 arg
= decay_conversion (arg
, complain
);
12295 if (error_operand_p (arg
))
12296 return error_mark_node
;
12298 if (!trivially_copyable_p (TREE_TYPE (arg
)))
12300 error_at (cp_expr_loc_or_loc (arg
, loc
),
12301 "%<__builtin_bit_cast%> source type %qT "
12302 "is not trivially copyable", TREE_TYPE (arg
));
12303 return error_mark_node
;
12305 if (!dependent_type_p (type
)
12306 && !cp_tree_equal (TYPE_SIZE_UNIT (type
),
12307 TYPE_SIZE_UNIT (TREE_TYPE (arg
))))
12309 error_at (loc
, "%<__builtin_bit_cast%> source size %qE "
12310 "not equal to destination type size %qE",
12311 TYPE_SIZE_UNIT (TREE_TYPE (arg
)),
12312 TYPE_SIZE_UNIT (type
));
12313 return error_mark_node
;
12317 tree ret
= build_min (BIT_CAST_EXPR
, type
, arg
);
12318 SET_EXPR_LOCATION (ret
, loc
);
12320 if (!processing_template_decl
&& CLASS_TYPE_P (type
))
12321 ret
= get_target_expr_sfinae (ret
, complain
);
12326 #include "gt-cp-semantics.h"