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-2024 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.cc.
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 *);
57 /* Used for OpenMP non-static data member privatization. */
59 static hash_map
<tree
, tree
> *omp_private_member_map
;
60 static vec
<tree
> omp_private_member_vec
;
61 static bool omp_private_member_ignore_next
;
64 /* Deferred Access Checking Overview
65 ---------------------------------
67 Most C++ expressions and declarations require access checking
68 to be performed during parsing. However, in several cases,
69 this has to be treated differently.
71 For member declarations, access checking has to be deferred
72 until more information about the declaration is known. For
84 When we are parsing the function return type `A::X', we don't
85 really know if this is allowed until we parse the function name.
87 Furthermore, some contexts require that access checking is
88 never performed at all. These include class heads, and template
91 Typical use of access checking functions is described here:
93 1. When we enter a context that requires certain access checking
94 mode, the function `push_deferring_access_checks' is called with
95 DEFERRING argument specifying the desired mode. Access checking
96 may be performed immediately (dk_no_deferred), deferred
97 (dk_deferred), or not performed (dk_no_check).
99 2. When a declaration such as a type, or a variable, is encountered,
100 the function `perform_or_defer_access_check' is called. It
101 maintains a vector of all deferred checks.
103 3. The global `current_class_type' or `current_function_decl' is then
104 setup by the parser. `enforce_access' relies on these information
107 4. Upon exiting the context mentioned in step 1,
108 `perform_deferred_access_checks' is called to check all declaration
109 stored in the vector. `pop_deferring_access_checks' is then
110 called to restore the previous access checking mode.
112 In case of parsing error, we simply call `pop_deferring_access_checks'
113 without `perform_deferred_access_checks'. */
115 struct GTY(()) deferred_access
{
116 /* A vector representing name-lookups for which we have deferred
117 checking access controls. We cannot check the accessibility of
118 names used in a decl-specifier-seq until we know what is being
119 declared because code like:
126 A::B* A::f() { return 0; }
128 is valid, even though `A::B' is not generally accessible. */
129 vec
<deferred_access_check
, va_gc
> *deferred_access_checks
;
131 /* The current mode of access checks. */
132 enum deferring_kind deferring_access_checks_kind
;
135 /* Data for deferred access checking. */
136 static GTY(()) vec
<deferred_access
, va_gc
> *deferred_access_stack
;
137 static GTY(()) unsigned deferred_access_no_check
;
139 /* Save the current deferred access states and start deferred
140 access checking iff DEFER_P is true. */
143 push_deferring_access_checks (deferring_kind deferring
)
145 /* For context like template instantiation, access checking
146 disabling applies to all nested context. */
147 if (deferred_access_no_check
|| deferring
== dk_no_check
)
148 deferred_access_no_check
++;
151 deferred_access e
= {NULL
, deferring
};
152 vec_safe_push (deferred_access_stack
, e
);
156 /* Save the current deferred access states and start deferred access
157 checking, continuing the set of deferred checks in CHECKS. */
160 reopen_deferring_access_checks (vec
<deferred_access_check
, va_gc
> * checks
)
162 push_deferring_access_checks (dk_deferred
);
163 if (!deferred_access_no_check
)
164 deferred_access_stack
->last().deferred_access_checks
= checks
;
167 /* Resume deferring access checks again after we stopped doing
171 resume_deferring_access_checks (void)
173 if (!deferred_access_no_check
)
174 deferred_access_stack
->last().deferring_access_checks_kind
= dk_deferred
;
177 /* Stop deferring access checks. */
180 stop_deferring_access_checks (void)
182 if (!deferred_access_no_check
)
183 deferred_access_stack
->last().deferring_access_checks_kind
= dk_no_deferred
;
186 /* Discard the current deferred access checks and restore the
190 pop_deferring_access_checks (void)
192 if (deferred_access_no_check
)
193 deferred_access_no_check
--;
195 deferred_access_stack
->pop ();
198 /* Returns a TREE_LIST representing the deferred checks.
199 The TREE_PURPOSE of each node is the type through which the
200 access occurred; the TREE_VALUE is the declaration named.
203 vec
<deferred_access_check
, va_gc
> *
204 get_deferred_access_checks (void)
206 if (deferred_access_no_check
)
209 return (deferred_access_stack
->last().deferred_access_checks
);
212 /* Take current deferred checks and combine with the
213 previous states if we also defer checks previously.
214 Otherwise perform checks now. */
217 pop_to_parent_deferring_access_checks (void)
219 if (deferred_access_no_check
)
220 deferred_access_no_check
--;
223 vec
<deferred_access_check
, va_gc
> *checks
;
224 deferred_access
*ptr
;
226 checks
= (deferred_access_stack
->last ().deferred_access_checks
);
228 deferred_access_stack
->pop ();
229 ptr
= &deferred_access_stack
->last ();
230 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
233 perform_access_checks (checks
, tf_warning_or_error
);
237 /* Merge with parent. */
239 deferred_access_check
*chk
, *probe
;
241 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
243 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, j
, probe
)
245 if (probe
->binfo
== chk
->binfo
&&
246 probe
->decl
== chk
->decl
&&
247 probe
->diag_decl
== chk
->diag_decl
)
250 /* Insert into parent's checks. */
251 vec_safe_push (ptr
->deferred_access_checks
, *chk
);
258 /* Called from enforce_access. A class has attempted (but failed) to access
259 DECL. It is already established that a baseclass of that class,
260 PARENT_BINFO, has private access to DECL. Examine certain special cases
261 to find a decl that accurately describes the source of the problem. If
262 none of the special cases apply, simply return DECL as the source of the
266 get_class_access_diagnostic_decl (tree parent_binfo
, tree decl
)
268 /* When a class is denied access to a decl in a baseclass, most of the
269 time it is because the decl itself was declared as private at the point
272 However, in C++, there are (at least) two situations in which a decl
273 can be private even though it was not originally defined as such.
274 These two situations only apply if a baseclass had private access to
275 DECL (this function is only called if that is the case). */
277 /* We should first check whether the reason the parent had private access
278 to DECL was simply because DECL was created and declared as private in
279 the parent. If it was, then DECL is definitively the source of the
281 if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl
),
282 BINFO_TYPE (parent_binfo
)))
285 /* 1. If the "using" keyword is used to inherit DECL within the parent,
286 this may cause DECL to be private, so we should return the using
287 statement as the source of the problem.
289 Scan the fields of PARENT_BINFO and see if there are any using decls. If
290 there are, see if they inherit DECL. If they do, that's where DECL must
291 have been declared private. */
293 for (tree parent_field
= TYPE_FIELDS (BINFO_TYPE (parent_binfo
));
295 parent_field
= DECL_CHAIN (parent_field
))
296 /* Not necessary, but also check TREE_PRIVATE for the sake of
297 eliminating obviously non-relevant using decls. */
298 if (TREE_CODE (parent_field
) == USING_DECL
299 && TREE_PRIVATE (parent_field
))
301 tree decl_stripped
= strip_using_decl (parent_field
);
303 /* The using statement might be overloaded. If so, we need to
304 check all of the overloads. */
305 for (ovl_iterator
iter (decl_stripped
); iter
; ++iter
)
306 /* If equal, the using statement inherits DECL, and so is the
307 source of the access failure, so return it. */
312 /* 2. If DECL was privately inherited by the parent class, then DECL will
313 be inaccessible, even though it may originally have been accessible to
314 deriving classes. In that case, the fault lies with the parent, since it
315 used a private inheritance, so we return the parent as the source of the
318 Since this is the last check, we just assume it's true. At worst, it
319 will simply point to the class that failed to give access, which is
321 return TYPE_NAME (BINFO_TYPE (parent_binfo
));
324 /* If the current scope isn't allowed to access DECL along
325 BASETYPE_PATH, give an error, or if we're parsing a function or class
326 template, defer the access check to be performed at instantiation time.
327 The most derived class in BASETYPE_PATH is the one used to qualify DECL.
328 DIAG_DECL is the declaration to use in the error diagnostic. */
331 enforce_access (tree basetype_path
, tree decl
, tree diag_decl
,
332 tsubst_flags_t complain
, access_failure_info
*afi
= NULL
)
334 gcc_assert (TREE_CODE (basetype_path
) == TREE_BINFO
);
336 if (flag_new_inheriting_ctors
337 && DECL_INHERITED_CTOR (decl
))
339 /* 7.3.3/18: The additional constructors are accessible if they would be
340 accessible when used to construct an object of the corresponding base
342 decl
= strip_inheriting_ctors (decl
);
343 basetype_path
= lookup_base (basetype_path
, DECL_CONTEXT (decl
),
344 ba_any
, NULL
, complain
);
347 tree cs
= current_scope ();
348 if (in_template_context
349 && (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
))
350 if (tree template_info
= get_template_info (cs
))
352 /* When parsing a function or class template, we in general need to
353 defer access checks until template instantiation time, since a friend
354 declaration may grant access only to a particular specialization of
357 if (accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
358 /* But if the member is deemed accessible at parse time, then we can
359 assume it'll be accessible at instantiation time. */
362 /* Access of a dependent decl should be rechecked after tsubst'ing
363 into the user of the decl, rather than explicitly deferring the
365 gcc_assert (!uses_template_parms (decl
));
366 if (TREE_CODE (decl
) == FIELD_DECL
)
367 gcc_assert (!uses_template_parms (DECL_CONTEXT (decl
)));
369 /* Defer this access check until instantiation time. */
370 deferred_access_check access_check
;
371 access_check
.binfo
= basetype_path
;
372 access_check
.decl
= decl
;
373 access_check
.diag_decl
= diag_decl
;
374 access_check
.loc
= input_location
;
375 vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info
), access_check
);
379 if (!accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
381 if (flag_new_inheriting_ctors
)
382 diag_decl
= strip_inheriting_ctors (diag_decl
);
383 if (complain
& tf_error
)
385 access_kind access_failure_reason
= ak_none
;
387 /* By default, using the decl as the source of the problem will
388 usually give correct results. */
389 tree diag_location
= diag_decl
;
391 /* However, if a parent of BASETYPE_PATH had private access to decl,
392 then it actually might be the case that the source of the problem
394 tree parent_binfo
= get_parent_with_private_access (decl
,
397 /* So if a parent did have private access, then we need to do
398 special checks to obtain the best diagnostic location decl. */
399 if (parent_binfo
!= NULL_TREE
)
401 diag_location
= get_class_access_diagnostic_decl (parent_binfo
,
404 /* We also at this point know that the reason access failed was
405 because decl was private. */
406 access_failure_reason
= ak_private
;
409 /* Finally, generate an error message. */
410 complain_about_access (decl
, diag_decl
, diag_location
, true,
411 access_failure_reason
);
414 afi
->record_access_failure (basetype_path
, decl
, diag_decl
);
421 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
422 is the BINFO indicating the qualifying scope used to access the
423 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
424 or we aren't in SFINAE context or all the checks succeed return TRUE,
428 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
429 tsubst_flags_t complain
)
432 deferred_access_check
*chk
;
433 location_t loc
= input_location
;
439 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
441 input_location
= chk
->loc
;
442 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
445 input_location
= loc
;
446 return (complain
& tf_error
) ? true : ok
;
449 /* Perform the deferred access checks.
451 After performing the checks, we still have to keep the list
452 `deferred_access_stack->deferred_access_checks' since we may want
453 to check access for them again later in a different context.
460 A::X A::a, x; // No error for `A::a', error for `x'
462 We have to perform deferred access of `A::X', first with `A::a',
463 next with `x'. Return value like perform_access_checks above. */
466 perform_deferred_access_checks (tsubst_flags_t complain
)
468 return perform_access_checks (get_deferred_access_checks (), complain
);
471 /* Defer checking the accessibility of DECL, when looked up in
472 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
473 Return value like perform_access_checks above.
474 If non-NULL, report failures to AFI. */
477 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
478 tsubst_flags_t complain
,
479 access_failure_info
*afi
)
482 deferred_access
*ptr
;
483 deferred_access_check
*chk
;
485 /* Exit if we are in a context that no access checking is performed. */
486 if (deferred_access_no_check
)
489 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
491 ptr
= &deferred_access_stack
->last ();
493 /* If we are not supposed to defer access checks, just check now. */
494 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
496 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
, afi
);
497 return (complain
& tf_error
) ? true : ok
;
500 /* See if we are already going to perform this check. */
501 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
503 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
504 chk
->diag_decl
== diag_decl
)
509 /* If not, record the check. */
510 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
511 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
516 /* Returns nonzero if the current statement is a full expression,
517 i.e. temporaries created during that statement should be destroyed
518 at the end of the statement. */
521 stmts_are_full_exprs_p (void)
523 return current_stmt_tree ()->stmts_are_full_exprs_p
;
526 /* T is a statement. Add it to the statement-tree. This is the C++
527 version. The C/ObjC frontends have a slightly different version of
533 enum tree_code code
= TREE_CODE (t
);
535 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
537 if (!EXPR_HAS_LOCATION (t
))
538 SET_EXPR_LOCATION (t
, input_location
);
540 /* When we expand a statement-tree, we must know whether or not the
541 statements are full-expressions. We record that fact here. */
542 if (STATEMENT_CODE_P (TREE_CODE (t
)))
543 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
546 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
547 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
549 /* Add T to the statement-tree. Non-side-effect statements need to be
550 recorded during statement expressions. */
551 gcc_checking_assert (!stmt_list_stack
->is_empty ());
552 append_to_statement_list_force (t
, &cur_stmt_list
);
557 /* Returns the stmt_tree to which statements are currently being added. */
560 current_stmt_tree (void)
563 ? &cfun
->language
->base
.x_stmt_tree
564 : &scope_chain
->x_stmt_tree
);
567 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
570 maybe_cleanup_point_expr (tree expr
)
572 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
573 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
577 /* Like maybe_cleanup_point_expr except have the type of the new expression be
578 void so we don't need to create a temporary variable to hold the inner
579 expression. The reason why we do this is because the original type might be
580 an aggregate and we cannot create a temporary variable for that type. */
583 maybe_cleanup_point_expr_void (tree expr
)
585 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
586 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
592 /* Create a declaration statement for the declaration given by the DECL. */
595 add_decl_expr (tree decl
)
597 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
598 if (DECL_INITIAL (decl
)
599 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
600 r
= maybe_cleanup_point_expr_void (r
);
604 /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC. */
607 set_cleanup_locs (tree stmts
, location_t loc
)
609 if (TREE_CODE (stmts
) == CLEANUP_STMT
)
611 tree t
= CLEANUP_EXPR (stmts
);
612 if (t
&& TREE_CODE (t
) != POSTCONDITION_STMT
)
613 protected_set_expr_location (t
, loc
);
614 /* Avoid locus differences for C++ cdtor calls depending on whether
615 cdtor_returns_this: a conversion to void is added to discard the return
616 value, and this conversion ends up carrying the location, and when it
617 gets discarded, the location is lost. So hold it in the call as
619 if (TREE_CODE (t
) == NOP_EXPR
620 && TREE_TYPE (t
) == void_type_node
621 && TREE_CODE (TREE_OPERAND (t
, 0)) == CALL_EXPR
)
622 protected_set_expr_location (TREE_OPERAND (t
, 0), loc
);
623 set_cleanup_locs (CLEANUP_BODY (stmts
), loc
);
625 else if (TREE_CODE (stmts
) == STATEMENT_LIST
)
626 for (tree stmt
: tsi_range (stmts
))
627 set_cleanup_locs (stmt
, loc
);
630 /* True iff the innermost block scope is a try block. */
635 cp_binding_level
*b
= current_binding_level
;
636 while (b
&& b
->kind
== sk_cleanup
)
638 return b
&& b
->kind
== sk_try
;
641 /* Finish a scope. */
644 do_poplevel (tree stmt_list
)
648 bool was_try
= at_try_scope ();
650 if (stmts_are_full_exprs_p ())
651 block
= poplevel (kept_level_p (), 1, 0);
653 /* This needs to come after poplevel merges sk_cleanup statement_lists. */
654 maybe_splice_retval_cleanup (stmt_list
, was_try
);
656 stmt_list
= pop_stmt_list (stmt_list
);
658 /* input_location is the last token of the scope, usually a }. */
659 set_cleanup_locs (stmt_list
, input_location
);
661 if (!processing_template_decl
)
663 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
664 /* ??? See c_end_compound_stmt re statement expressions. */
670 /* Begin a new scope. */
673 do_pushlevel (scope_kind sk
)
675 tree ret
= push_stmt_list ();
676 if (stmts_are_full_exprs_p ())
677 begin_scope (sk
, NULL
);
681 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
682 when the current scope is exited. EH_ONLY is true when this is not
683 meant to apply to normal control flow transfer. DECL is the VAR_DECL
684 being cleaned up, if any, or null for temporaries or subobjects. */
687 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
689 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
690 CLEANUP_EH_ONLY (stmt
) = eh_only
;
692 CLEANUP_BODY (stmt
) = push_stmt_list ();
695 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
696 the current loops, represented by 'NULL_TREE' if we've seen a possible
697 exit, and 'error_mark_node' if not. This is currently used only to
698 suppress the warning about a function with no return statements, and
699 therefore we don't bother noting returns as possible exits. We also
700 don't bother with gotos. */
703 begin_maybe_infinite_loop (tree cond
)
705 /* Only track this while parsing a function, not during instantiation. */
706 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
707 && !processing_template_decl
))
709 bool maybe_infinite
= true;
712 cond
= fold_non_dependent_expr (cond
);
713 maybe_infinite
= integer_nonzerop (cond
);
715 vec_safe_push (cp_function_chain
->infinite_loops
,
716 maybe_infinite
? error_mark_node
: NULL_TREE
);
720 /* A break is a possible exit for the current loop. */
723 break_maybe_infinite_loop (void)
727 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
730 /* If we reach the end of the loop without seeing a possible exit, we have
734 end_maybe_infinite_loop (tree cond
)
736 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
737 && !processing_template_decl
))
739 tree current
= cp_function_chain
->infinite_loops
->pop();
740 if (current
!= NULL_TREE
)
742 cond
= fold_non_dependent_expr (cond
);
743 if (integer_nonzerop (cond
))
744 current_function_infinite_loop
= 1;
748 /* Begin a conditional that might contain a declaration. When generating
749 normal code, we want the declaration to appear before the statement
750 containing the conditional. When generating template code, we want the
751 conditional to be rendered as the raw DECL_EXPR. */
754 begin_cond (tree
*cond_p
)
756 if (processing_template_decl
)
757 *cond_p
= push_stmt_list ();
760 /* Finish such a conditional. */
763 finish_cond (tree
*cond_p
, tree expr
)
765 if (processing_template_decl
)
767 tree cond
= pop_stmt_list (*cond_p
);
769 if (expr
== NULL_TREE
)
770 /* Empty condition in 'for'. */
771 gcc_assert (empty_expr_stmt_p (cond
));
772 else if (check_for_bare_parameter_packs (expr
))
773 expr
= error_mark_node
;
774 else if (!empty_expr_stmt_p (cond
))
775 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
780 /* If *COND_P specifies a conditional with a declaration, transform the
783 for (; A x = 42;) { }
785 while (true) { A x = 42; if (!x) break; }
786 for (;;) { A x = 42; if (!x) break; }
787 The statement list for BODY will be empty if the conditional did
788 not declare anything. */
791 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
795 if (!TREE_SIDE_EFFECTS (body
))
799 *cond_p
= boolean_true_node
;
801 if_stmt
= begin_if_stmt ();
803 while (TREE_CODE (*cond_p
) == ANNOTATE_EXPR
)
804 cond_p
= &TREE_OPERAND (*cond_p
, 0);
805 *cond_p
= cp_build_unary_op (TRUTH_NOT_EXPR
, *cond_p
, false,
806 tf_warning_or_error
);
807 finish_if_stmt_cond (cond
, if_stmt
);
808 finish_break_stmt ();
809 finish_then_clause (if_stmt
);
810 finish_if_stmt (if_stmt
);
813 /* Finish a goto-statement. */
816 finish_goto_stmt (tree destination
)
818 if (identifier_p (destination
))
819 destination
= lookup_label (destination
);
821 /* We warn about unused labels with -Wunused. That means we have to
822 mark the used labels as used. */
823 if (TREE_CODE (destination
) == LABEL_DECL
)
824 TREE_USED (destination
) = 1;
827 destination
= mark_rvalue_use (destination
);
828 if (!processing_template_decl
)
830 destination
= cp_convert (ptr_type_node
, destination
,
831 tf_warning_or_error
);
832 if (error_operand_p (destination
))
835 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
840 check_goto (destination
);
842 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
843 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
846 /* Returns true if T corresponds to an assignment operator expression. */
849 is_assignment_op_expr_p (tree t
)
854 if (TREE_CODE (t
) == MODIFY_EXPR
855 || (TREE_CODE (t
) == MODOP_EXPR
856 && TREE_CODE (TREE_OPERAND (t
, 1)) == NOP_EXPR
))
859 tree call
= extract_call_expr (t
);
860 if (call
== NULL_TREE
861 || call
== error_mark_node
862 || !CALL_EXPR_OPERATOR_SYNTAX (call
))
865 tree fndecl
= cp_get_callee_fndecl_nofold (call
);
866 return fndecl
!= NULL_TREE
867 && DECL_ASSIGNMENT_OPERATOR_P (fndecl
)
868 && DECL_OVERLOADED_OPERATOR_IS (fndecl
, NOP_EXPR
);
871 /* Return true if TYPE is a class type that is convertible to
872 and assignable from bool. */
874 static GTY((deletable
)) hash_map
<tree
, bool> *boolish_class_type_p_cache
;
877 boolish_class_type_p (tree type
)
879 type
= TYPE_MAIN_VARIANT (type
);
880 if (!CLASS_TYPE_P (type
) || !COMPLETE_TYPE_P (type
))
883 if (bool *r
= hash_map_safe_get (boolish_class_type_p_cache
, type
))
887 bool has_bool_assignment
= false;
888 bool has_bool_conversion
= false;
890 ops
= lookup_fnfields (type
, assign_op_identifier
, /*protect=*/0, tf_none
);
891 for (tree op
: ovl_range (BASELINK_FUNCTIONS (ops
)))
893 op
= STRIP_TEMPLATE (op
);
894 if (TREE_CODE (op
) != FUNCTION_DECL
)
896 tree parm
= DECL_CHAIN (DECL_ARGUMENTS (op
));
897 tree parm_type
= non_reference (TREE_TYPE (parm
));
898 if (TREE_CODE (parm_type
) == BOOLEAN_TYPE
)
900 has_bool_assignment
= true;
905 if (has_bool_assignment
)
907 ops
= lookup_conversions (type
);
908 for (; ops
; ops
= TREE_CHAIN (ops
))
910 tree op
= TREE_VALUE (ops
);
911 if (!DECL_NONCONVERTING_P (op
)
912 && TREE_CODE (DECL_CONV_FN_TYPE (op
)) == BOOLEAN_TYPE
)
914 has_bool_conversion
= true;
920 bool boolish
= has_bool_assignment
&& has_bool_conversion
;
921 hash_map_safe_put
<true> (boolish_class_type_p_cache
, type
, boolish
);
926 /* Maybe warn about an unparenthesized 'a = b' (appearing in a
927 boolean context where 'a == b' might have been intended).
928 NESTED_P is true if T is the RHS of another assignment. */
931 maybe_warn_unparenthesized_assignment (tree t
, bool nested_p
,
932 tsubst_flags_t complain
)
934 tree type
= TREE_TYPE (t
);
935 t
= STRIP_REFERENCE_REF (t
);
937 if ((complain
& tf_warning
)
939 && is_assignment_op_expr_p (t
)
940 /* A parenthesized expression would've had this warning
941 suppressed by finish_parenthesized_expr. */
942 && !warning_suppressed_p (t
, OPT_Wparentheses
)
943 /* In c = a = b, don't warn if a has type bool or bool-like class. */
945 || (TREE_CODE (type
) != BOOLEAN_TYPE
946 && !boolish_class_type_p (type
))))
948 warning_at (cp_expr_loc_or_input_loc (t
), OPT_Wparentheses
,
949 "suggest parentheses around assignment used as truth value");
950 suppress_warning (t
, OPT_Wparentheses
);
954 /* COND is the condition-expression for an if, while, etc.,
955 statement. Convert it to a boolean value, if appropriate.
956 In addition, verify sequence points if -Wsequence-point is enabled. */
959 maybe_convert_cond (tree cond
)
961 /* Empty conditions remain empty. */
965 /* Wait until we instantiate templates before doing conversion. */
966 if (type_dependent_expression_p (cond
))
969 if (warn_sequence_point
&& !processing_template_decl
)
970 verify_sequence_points (cond
);
972 maybe_warn_unparenthesized_assignment (cond
, /*nested_p=*/false,
973 tf_warning_or_error
);
975 /* Do the conversion. */
976 cond
= convert_from_reference (cond
);
977 return condition_conversion (cond
);
980 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
983 finish_expr_stmt (tree expr
)
986 location_t loc
= EXPR_LOCATION (expr
);
988 if (expr
!= NULL_TREE
)
990 /* If we ran into a problem, make sure we complained. */
991 gcc_assert (expr
!= error_mark_node
|| seen_error ());
993 if (!processing_template_decl
)
995 if (warn_sequence_point
)
996 verify_sequence_points (expr
);
997 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
999 else if (!type_dependent_expression_p (expr
))
1000 convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
1002 if (check_for_bare_parameter_packs (expr
))
1003 expr
= error_mark_node
;
1005 /* Simplification of inner statement expressions, compound exprs,
1006 etc can result in us already having an EXPR_STMT. */
1007 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
1009 if (TREE_CODE (expr
) != EXPR_STMT
)
1010 expr
= build_stmt (loc
, EXPR_STMT
, expr
);
1011 expr
= maybe_cleanup_point_expr_void (expr
);
1014 r
= add_stmt (expr
);
1021 /* Begin an if-statement. Returns a newly created IF_STMT if
1025 begin_if_stmt (void)
1028 scope
= do_pushlevel (sk_cond
);
1029 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
1030 NULL_TREE
, NULL_TREE
, scope
);
1031 current_binding_level
->this_entity
= r
;
1032 begin_cond (&IF_COND (r
));
1036 /* Returns true if FN, a CALL_EXPR, is a call to
1037 std::is_constant_evaluated or __builtin_is_constant_evaluated. */
1040 is_std_constant_evaluated_p (tree fn
)
1042 /* std::is_constant_evaluated takes no arguments. */
1043 if (call_expr_nargs (fn
) != 0)
1046 tree fndecl
= cp_get_callee_fndecl_nofold (fn
);
1047 if (fndecl
== NULL_TREE
)
1050 if (fndecl_built_in_p (fndecl
, CP_BUILT_IN_IS_CONSTANT_EVALUATED
,
1054 if (!decl_in_std_namespace_p (fndecl
))
1057 tree name
= DECL_NAME (fndecl
);
1058 return name
&& id_equal (name
, "is_constant_evaluated");
1061 /* Callback function for maybe_warn_for_constant_evaluated that looks
1062 for calls to std::is_constant_evaluated in TP. */
1065 find_std_constant_evaluated_r (tree
*tp
, int *walk_subtrees
, void *)
1069 if (TYPE_P (t
) || TREE_CONSTANT (t
))
1071 *walk_subtrees
= false;
1075 switch (TREE_CODE (t
))
1078 if (is_std_constant_evaluated_p (t
))
1082 /* Don't warn in statement expressions. */
1083 *walk_subtrees
= false;
1092 /* In certain contexts, std::is_constant_evaluated() is always true (for
1093 instance, in a consteval function or in a constexpr if), or always false
1094 (e.g., in a non-constexpr non-consteval function) so give the user a clue. */
1097 maybe_warn_for_constant_evaluated (tree cond
, bool constexpr_if
,
1098 bool trivial_infinite
)
1100 if (!warn_tautological_compare
)
1103 /* Suppress warning for std::is_constant_evaluated if the conditional
1104 comes from a macro. */
1105 if (from_macro_expansion_at (EXPR_LOCATION (cond
)))
1108 cond
= cp_walk_tree_without_duplicates (&cond
, find_std_constant_evaluated_r
,
1113 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
1114 "%<std::is_constant_evaluated%> always evaluates to "
1115 "true in %<if constexpr%>");
1116 else if (trivial_infinite
)
1118 auto_diagnostic_group d
;
1119 if (warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
1120 "%<std::is_constant_evaluated%> evaluates to "
1121 "true when checking if trivially empty iteration "
1122 "statement is trivial infinite loop")
1123 && !maybe_constexpr_fn (current_function_decl
))
1124 inform (EXPR_LOCATION (cond
),
1125 "and evaluates to false when actually evaluating "
1126 "the condition in non-%<constexpr%> function");
1128 else if (!maybe_constexpr_fn (current_function_decl
))
1129 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
1130 "%<std::is_constant_evaluated%> always evaluates to "
1131 "false in a non-%<constexpr%> function");
1132 else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl
))
1133 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
1134 "%<std::is_constant_evaluated%> always evaluates to "
1135 "true in a %<consteval%> function");
1139 /* Process the COND of an if-statement, which may be given by
1143 finish_if_stmt_cond (tree orig_cond
, tree if_stmt
)
1145 tree cond
= maybe_convert_cond (orig_cond
);
1146 maybe_warn_for_constant_evaluated (cond
, IF_STMT_CONSTEXPR_P (if_stmt
),
1147 /*trivial_infinite=*/false);
1148 if (IF_STMT_CONSTEXPR_P (if_stmt
)
1149 && !type_dependent_expression_p (cond
)
1150 && require_constant_expression (cond
)
1151 && !instantiation_dependent_expression_p (cond
)
1152 /* Wait until instantiation time, since only then COND has been
1153 converted to bool. */
1154 && TYPE_MAIN_VARIANT (TREE_TYPE (cond
)) == boolean_type_node
)
1156 cond
= instantiate_non_dependent_expr (cond
);
1157 cond
= cxx_constant_value (cond
);
1159 else if (processing_template_decl
)
1161 finish_cond (&IF_COND (if_stmt
), cond
);
1163 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
1167 /* Finish the then-clause of an if-statement, which may be given by
1171 finish_then_clause (tree if_stmt
)
1173 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
1177 /* Begin the else-clause of an if-statement. */
1180 begin_else_clause (tree if_stmt
)
1182 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
1185 /* Finish the else-clause of an if-statement, which may be given by
1189 finish_else_clause (tree if_stmt
)
1191 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
1194 /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1198 maybe_mark_exp_read_r (tree
*tp
, int *, void *)
1201 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
1206 /* Finish an if-statement. */
1209 finish_if_stmt (tree if_stmt
)
1211 tree scope
= IF_SCOPE (if_stmt
);
1212 IF_SCOPE (if_stmt
) = NULL
;
1213 if (IF_STMT_CONSTEXPR_P (if_stmt
))
1215 /* Prevent various -Wunused warnings. We might not instantiate
1216 either of these branches, so we would not mark the variables
1217 used in that branch as read. */
1218 cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt
),
1219 maybe_mark_exp_read_r
, NULL
);
1220 cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt
),
1221 maybe_mark_exp_read_r
, NULL
);
1223 add_stmt (do_poplevel (scope
));
1226 /* Determine if iteration statement with *CONDP condition and
1227 loop BODY is trivially empty iteration statement or even
1228 trivial infinite loop. In the latter case for -ffinite-loops
1229 add ANNOTATE_EXPR to mark the loop as maybe validly infinite.
1230 Also, emit -Wtautological-compare warning for std::is_constant_evaluated ()
1231 calls in the condition when needed. */
1234 finish_loop_cond (tree
*condp
, tree body
)
1236 if (TREE_CODE (*condp
) == INTEGER_CST
)
1238 bool trivially_empty
= expr_first (body
) == NULL_TREE
;
1239 bool trivial_infinite
= false;
1240 if (trivially_empty
)
1242 tree c
= fold_non_dependent_expr (*condp
, tf_none
,
1243 /*manifestly_const_eval=*/true);
1244 trivial_infinite
= c
&& integer_nonzerop (c
);
1246 if (warn_tautological_compare
)
1249 while (TREE_CODE (cond
) == ANNOTATE_EXPR
)
1250 cond
= TREE_OPERAND (cond
, 0);
1251 if (trivial_infinite
1252 && !DECL_IMMEDIATE_FUNCTION_P (current_function_decl
))
1253 maybe_warn_for_constant_evaluated (cond
, /*constexpr_if=*/false,
1254 /*trivial_infinite=*/true);
1255 else if (!trivially_empty
1256 || !processing_template_decl
1257 || DECL_IMMEDIATE_FUNCTION_P (current_function_decl
))
1258 maybe_warn_for_constant_evaluated (cond
, /*constexpr_if=*/false,
1259 /*trivial_infinite=*/false);
1261 if (trivial_infinite
&& flag_finite_loops
&& !processing_template_decl
)
1262 *condp
= build3 (ANNOTATE_EXPR
, TREE_TYPE (*condp
), *condp
,
1263 build_int_cst (integer_type_node
,
1264 annot_expr_maybe_infinite_kind
),
1268 /* Begin a while-statement. Returns a newly created WHILE_STMT if
1272 begin_while_stmt (void)
1275 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
1277 WHILE_BODY (r
) = do_pushlevel (sk_block
);
1278 begin_cond (&WHILE_COND (r
));
1282 /* Process the COND of a while-statement, which may be given by
1286 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
,
1287 tree unroll
, bool novector
)
1289 cond
= maybe_convert_cond (cond
);
1290 finish_cond (&WHILE_COND (while_stmt
), cond
);
1291 begin_maybe_infinite_loop (cond
);
1292 if (ivdep
&& cond
!= error_mark_node
)
1293 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
1294 TREE_TYPE (WHILE_COND (while_stmt
)),
1295 WHILE_COND (while_stmt
),
1296 build_int_cst (integer_type_node
,
1297 annot_expr_ivdep_kind
),
1299 if (unroll
&& cond
!= error_mark_node
)
1300 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
1301 TREE_TYPE (WHILE_COND (while_stmt
)),
1302 WHILE_COND (while_stmt
),
1303 build_int_cst (integer_type_node
,
1304 annot_expr_unroll_kind
),
1306 if (novector
&& cond
!= error_mark_node
)
1307 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
1308 TREE_TYPE (WHILE_COND (while_stmt
)),
1309 WHILE_COND (while_stmt
),
1310 build_int_cst (integer_type_node
,
1311 annot_expr_no_vector_kind
),
1313 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
1316 /* Finish a while-statement, which may be given by WHILE_STMT. */
1319 finish_while_stmt (tree while_stmt
)
1321 end_maybe_infinite_loop (boolean_true_node
);
1322 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
1323 finish_loop_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
1326 /* Begin a do-statement. Returns a newly created DO_STMT if
1330 begin_do_stmt (void)
1332 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
1333 begin_maybe_infinite_loop (boolean_true_node
);
1335 DO_BODY (r
) = push_stmt_list ();
1339 /* Finish the body of a do-statement, which may be given by DO_STMT. */
1342 finish_do_body (tree do_stmt
)
1344 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
1346 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
1347 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
1349 if (IS_EMPTY_STMT (body
))
1350 warning (OPT_Wempty_body
,
1351 "suggest explicit braces around empty body in %<do%> statement");
1354 /* Finish a do-statement, which may be given by DO_STMT, and whose
1355 COND is as indicated. */
1358 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
, tree unroll
,
1361 cond
= maybe_convert_cond (cond
);
1362 end_maybe_infinite_loop (cond
);
1363 /* Unlike other iteration statements, the condition may not contain
1364 a declaration, so we don't call finish_cond which checks for
1365 unexpanded parameter packs. */
1366 if (check_for_bare_parameter_packs (cond
))
1367 cond
= error_mark_node
;
1368 if (ivdep
&& cond
!= error_mark_node
)
1369 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1370 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
),
1372 if (unroll
&& cond
!= error_mark_node
)
1373 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1374 build_int_cst (integer_type_node
, annot_expr_unroll_kind
),
1376 if (novector
&& cond
!= error_mark_node
)
1377 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1378 build_int_cst (integer_type_node
, annot_expr_no_vector_kind
),
1380 DO_COND (do_stmt
) = cond
;
1381 tree do_body
= DO_BODY (do_stmt
);
1382 if (CONVERT_EXPR_P (do_body
)
1383 && integer_zerop (TREE_OPERAND (do_body
, 0))
1384 && VOID_TYPE_P (TREE_TYPE (do_body
)))
1385 do_body
= NULL_TREE
;
1386 finish_loop_cond (&DO_COND (do_stmt
), do_body
);
1389 /* Finish a return-statement. The EXPRESSION returned, if any, is as
1393 finish_return_stmt (tree expr
)
1399 expr
= check_return_expr (expr
, &no_warning
, &dangling
);
1401 if (error_operand_p (expr
)
1402 || (flag_openmp
&& !check_omp_return ()))
1404 /* Suppress -Wreturn-type for this function. */
1405 if (warn_return_type
)
1406 suppress_warning (current_function_decl
, OPT_Wreturn_type
);
1407 return error_mark_node
;
1410 if (!processing_template_decl
)
1412 if (warn_sequence_point
)
1413 verify_sequence_points (expr
);
1416 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
1417 RETURN_EXPR_LOCAL_ADDR_P (r
) = dangling
;
1419 suppress_warning (r
, OPT_Wreturn_type
);
1420 r
= maybe_cleanup_point_expr_void (r
);
1426 /* Begin the scope of a for-statement or a range-for-statement.
1427 Both the returned trees are to be used in a call to
1428 begin_for_stmt or begin_range_for_stmt. */
1431 begin_for_scope (tree
*init
)
1433 tree scope
= do_pushlevel (sk_for
);
1435 if (processing_template_decl
)
1436 *init
= push_stmt_list ();
1443 /* Begin a for-statement. Returns a new FOR_STMT.
1444 SCOPE and INIT should be the return of begin_for_scope,
1445 or both NULL_TREE */
1448 begin_for_stmt (tree scope
, tree init
)
1452 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
1453 NULL_TREE
, NULL_TREE
, NULL_TREE
);
1455 if (scope
== NULL_TREE
)
1458 scope
= begin_for_scope (&init
);
1461 FOR_INIT_STMT (r
) = init
;
1462 FOR_SCOPE (r
) = scope
;
1467 /* Finish the init-statement of a for-statement, which may be
1468 given by FOR_STMT. */
1471 finish_init_stmt (tree for_stmt
)
1473 if (processing_template_decl
)
1474 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
1475 add_stmt (for_stmt
);
1476 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
1477 begin_cond (&FOR_COND (for_stmt
));
1480 /* Finish the COND of a for-statement, which may be given by
1484 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
, tree unroll
,
1487 cond
= maybe_convert_cond (cond
);
1488 finish_cond (&FOR_COND (for_stmt
), cond
);
1489 begin_maybe_infinite_loop (cond
);
1490 if (ivdep
&& cond
!= error_mark_node
)
1491 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1492 TREE_TYPE (FOR_COND (for_stmt
)),
1493 FOR_COND (for_stmt
),
1494 build_int_cst (integer_type_node
,
1495 annot_expr_ivdep_kind
),
1497 if (unroll
&& cond
!= error_mark_node
)
1498 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1499 TREE_TYPE (FOR_COND (for_stmt
)),
1500 FOR_COND (for_stmt
),
1501 build_int_cst (integer_type_node
,
1502 annot_expr_unroll_kind
),
1504 if (novector
&& cond
!= error_mark_node
)
1505 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1506 TREE_TYPE (FOR_COND (for_stmt
)),
1507 FOR_COND (for_stmt
),
1508 build_int_cst (integer_type_node
,
1509 annot_expr_no_vector_kind
),
1511 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
1514 /* Finish the increment-EXPRESSION in a for-statement, which may be
1515 given by FOR_STMT. */
1518 finish_for_expr (tree expr
, tree for_stmt
)
1522 /* If EXPR is an overloaded function, issue an error; there is no
1523 context available to use to perform overload resolution. */
1524 if (type_unknown_p (expr
))
1526 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1527 expr
= error_mark_node
;
1529 if (!processing_template_decl
)
1531 if (warn_sequence_point
)
1532 verify_sequence_points (expr
);
1533 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1534 tf_warning_or_error
);
1536 else if (!type_dependent_expression_p (expr
))
1537 convert_to_void (expr
, ICV_THIRD_IN_FOR
, tf_warning_or_error
);
1538 expr
= maybe_cleanup_point_expr_void (expr
);
1539 if (check_for_bare_parameter_packs (expr
))
1540 expr
= error_mark_node
;
1541 FOR_EXPR (for_stmt
) = expr
;
1544 /* Finish the body of a for-statement, which may be given by
1545 FOR_STMT. The increment-EXPR for the loop must be
1547 It can also finish RANGE_FOR_STMT. */
1550 finish_for_stmt (tree for_stmt
)
1552 end_maybe_infinite_loop (boolean_true_node
);
1554 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1555 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1558 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1559 if (FOR_COND (for_stmt
))
1560 finish_loop_cond (&FOR_COND (for_stmt
),
1561 FOR_EXPR (for_stmt
) ? integer_one_node
1562 : FOR_BODY (for_stmt
));
1565 /* Pop the scope for the body of the loop. */
1566 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1567 ? &RANGE_FOR_SCOPE (for_stmt
)
1568 : &FOR_SCOPE (for_stmt
));
1569 tree scope
= *scope_ptr
;
1572 /* During parsing of the body, range for uses "__for_{range,begin,end} "
1573 decl names to make those unaccessible by code in the body.
1574 Change it to ones with underscore instead of space, so that it can
1575 be inspected in the debugger. */
1576 tree range_for_decl
[3] = { NULL_TREE
, NULL_TREE
, NULL_TREE
};
1577 gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 1
1578 && CPTI_FOR_END__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 2
1579 && CPTI_FOR_RANGE_IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 3
1580 && CPTI_FOR_BEGIN_IDENTIFIER
== CPTI_FOR_BEGIN__IDENTIFIER
+ 3
1581 && CPTI_FOR_END_IDENTIFIER
== CPTI_FOR_END__IDENTIFIER
+ 3);
1582 for (int i
= 0; i
< 3; i
++)
1584 tree id
= cp_global_trees
[CPTI_FOR_RANGE__IDENTIFIER
+ i
];
1585 if (IDENTIFIER_BINDING (id
)
1586 && IDENTIFIER_BINDING (id
)->scope
== current_binding_level
)
1588 range_for_decl
[i
] = IDENTIFIER_BINDING (id
)->value
;
1589 gcc_assert (VAR_P (range_for_decl
[i
])
1590 && DECL_ARTIFICIAL (range_for_decl
[i
]));
1594 add_stmt (do_poplevel (scope
));
1596 /* If we're being called from build_vec_init, don't mess with the names of
1597 the variables for an enclosing range-for. */
1598 if (!stmts_are_full_exprs_p ())
1601 for (int i
= 0; i
< 3; i
++)
1602 if (range_for_decl
[i
])
1603 DECL_NAME (range_for_decl
[i
])
1604 = cp_global_trees
[CPTI_FOR_RANGE_IDENTIFIER
+ i
];
1607 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1608 SCOPE and INIT should be the return of begin_for_scope,
1610 To finish it call finish_for_stmt(). */
1613 begin_range_for_stmt (tree scope
, tree init
)
1615 begin_maybe_infinite_loop (boolean_false_node
);
1617 tree r
= build_stmt (input_location
, RANGE_FOR_STMT
, NULL_TREE
, NULL_TREE
,
1618 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1620 if (scope
== NULL_TREE
)
1623 scope
= begin_for_scope (&init
);
1626 /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1627 RANGE_FOR_INIT_STMT (r
) = init
;
1628 RANGE_FOR_SCOPE (r
) = scope
;
1633 /* Finish the head of a range-based for statement, which may
1634 be given by RANGE_FOR_STMT. DECL must be the declaration
1635 and EXPR must be the loop expression. */
1638 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1640 if (processing_template_decl
)
1641 RANGE_FOR_INIT_STMT (range_for_stmt
)
1642 = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt
));
1643 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1644 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1645 add_stmt (range_for_stmt
);
1646 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1649 /* Finish a break-statement. */
1652 finish_break_stmt (void)
1654 /* In switch statements break is sometimes stylistically used after
1655 a return statement. This can lead to spurious warnings about
1656 control reaching the end of a non-void function when it is
1657 inlined. Note that we are calling block_may_fallthru with
1658 language specific tree nodes; this works because
1659 block_may_fallthru returns true when given something it does not
1661 if (!block_may_fallthru (cur_stmt_list
))
1664 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1667 /* Finish a continue-statement. */
1670 finish_continue_stmt (void)
1672 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1675 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1679 begin_switch_stmt (void)
1683 scope
= do_pushlevel (sk_cond
);
1684 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1686 begin_cond (&SWITCH_STMT_COND (r
));
1691 /* Finish the cond of a switch-statement. */
1694 finish_switch_cond (tree cond
, tree switch_stmt
)
1696 tree orig_type
= NULL
;
1698 if (!processing_template_decl
)
1700 /* Convert the condition to an integer or enumeration type. */
1701 tree orig_cond
= cond
;
1702 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1703 if (cond
== NULL_TREE
)
1705 error_at (cp_expr_loc_or_input_loc (orig_cond
),
1706 "switch quantity not an integer");
1707 cond
= error_mark_node
;
1709 /* We want unlowered type here to handle enum bit-fields. */
1710 orig_type
= unlowered_expr_type (cond
);
1711 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1712 orig_type
= TREE_TYPE (cond
);
1713 if (cond
!= error_mark_node
)
1717 Integral promotions are performed. */
1718 cond
= perform_integral_promotions (cond
);
1719 cond
= maybe_cleanup_point_expr (cond
);
1722 if (check_for_bare_parameter_packs (cond
))
1723 cond
= error_mark_node
;
1724 else if (!processing_template_decl
&& warn_sequence_point
)
1725 verify_sequence_points (cond
);
1727 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1728 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1729 add_stmt (switch_stmt
);
1730 push_switch (switch_stmt
);
1731 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1734 /* Finish the body of a switch-statement, which may be given by
1735 SWITCH_STMT. The COND to switch on is indicated. */
1738 finish_switch_stmt (tree switch_stmt
)
1742 SWITCH_STMT_BODY (switch_stmt
) =
1743 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1746 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1747 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1748 add_stmt (do_poplevel (scope
));
1751 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1755 begin_try_block (void)
1757 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1759 TRY_STMTS (r
) = push_stmt_list ();
1763 /* Likewise, for a function-try-block. The block returned in
1764 *COMPOUND_STMT is an artificial outer scope, containing the
1765 function-try-block. */
1768 begin_function_try_block (tree
*compound_stmt
)
1771 /* This outer scope does not exist in the C++ standard, but we need
1772 a place to put __FUNCTION__ and similar variables. */
1773 *compound_stmt
= begin_compound_stmt (0);
1774 current_binding_level
->artificial
= 1;
1775 r
= begin_try_block ();
1776 FN_TRY_BLOCK_P (r
) = 1;
1780 /* Finish a try-block, which may be given by TRY_BLOCK. */
1783 finish_try_block (tree try_block
)
1785 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1786 TRY_HANDLERS (try_block
) = push_stmt_list ();
1789 /* Finish the body of a cleanup try-block, which may be given by
1793 finish_cleanup_try_block (tree try_block
)
1795 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1798 /* Finish an implicitly generated try-block, with a cleanup is given
1802 finish_cleanup (tree cleanup
, tree try_block
)
1804 TRY_HANDLERS (try_block
) = cleanup
;
1805 CLEANUP_P (try_block
) = 1;
1808 /* Likewise, for a function-try-block. */
1811 finish_function_try_block (tree try_block
)
1813 finish_try_block (try_block
);
1814 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1815 the try block, but moving it inside. */
1816 in_function_try_handler
= 1;
1819 /* Finish a handler-sequence for a try-block, which may be given by
1823 finish_handler_sequence (tree try_block
)
1825 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1826 check_handlers (TRY_HANDLERS (try_block
));
1829 /* Finish the handler-seq for a function-try-block, given by
1830 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1831 begin_function_try_block. */
1834 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1836 in_function_try_handler
= 0;
1837 finish_handler_sequence (try_block
);
1838 finish_compound_stmt (compound_stmt
);
1841 /* Begin a handler. Returns a HANDLER if appropriate. */
1844 begin_handler (void)
1848 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1851 /* Create a binding level for the eh_info and the exception object
1853 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1858 /* Finish the handler-parameters for a handler, which may be given by
1859 HANDLER. DECL is the declaration for the catch parameter, or NULL
1860 if this is a `catch (...)' clause. */
1863 finish_handler_parms (tree decl
, tree handler
)
1865 tree type
= NULL_TREE
;
1866 if (processing_template_decl
)
1870 decl
= pushdecl (decl
);
1871 decl
= push_template_decl (decl
);
1872 HANDLER_PARMS (handler
) = decl
;
1873 type
= TREE_TYPE (decl
);
1878 type
= expand_start_catch_block (decl
);
1879 if (warn_catch_value
1880 && type
!= NULL_TREE
1881 && type
!= error_mark_node
1882 && !TYPE_REF_P (TREE_TYPE (decl
)))
1884 tree orig_type
= TREE_TYPE (decl
);
1885 if (CLASS_TYPE_P (orig_type
))
1887 if (TYPE_POLYMORPHIC_P (orig_type
))
1888 warning_at (DECL_SOURCE_LOCATION (decl
),
1890 "catching polymorphic type %q#T by value",
1892 else if (warn_catch_value
> 1)
1893 warning_at (DECL_SOURCE_LOCATION (decl
),
1895 "catching type %q#T by value", orig_type
);
1897 else if (warn_catch_value
> 2)
1898 warning_at (DECL_SOURCE_LOCATION (decl
),
1900 "catching non-reference type %q#T", orig_type
);
1903 HANDLER_TYPE (handler
) = type
;
1906 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1907 the return value from the matching call to finish_handler_parms. */
1910 finish_handler (tree handler
)
1912 if (!processing_template_decl
)
1913 expand_end_catch_block ();
1914 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1917 /* Begin a compound statement. FLAGS contains some bits that control the
1918 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1919 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1920 block of a function. If BCS_TRY_BLOCK is set, this is the block
1921 created on behalf of a TRY statement. Returns a token to be passed to
1922 finish_compound_stmt. */
1925 begin_compound_stmt (unsigned int flags
)
1929 if (flags
& BCS_NO_SCOPE
)
1931 r
= push_stmt_list ();
1932 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1934 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1935 But, if it's a statement-expression with a scopeless block, there's
1936 nothing to keep, and we don't want to accidentally keep a block
1937 *inside* the scopeless block. */
1938 keep_next_level (false);
1942 scope_kind sk
= sk_block
;
1943 if (flags
& BCS_TRY_BLOCK
)
1945 else if (flags
& BCS_TRANSACTION
)
1946 sk
= sk_transaction
;
1947 else if (flags
& BCS_STMT_EXPR
)
1949 r
= do_pushlevel (sk
);
1952 /* When processing a template, we need to remember where the braces were,
1953 so that we can set up identical scopes when instantiating the template
1954 later. BIND_EXPR is a handy candidate for this.
1955 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1956 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1957 processing templates. */
1958 if (processing_template_decl
)
1960 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1961 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1962 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1963 TREE_SIDE_EFFECTS (r
) = 1;
1969 /* Finish a compound-statement, which is given by STMT. */
1972 finish_compound_stmt (tree stmt
)
1974 if (TREE_CODE (stmt
) == BIND_EXPR
)
1976 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1977 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1978 discard the BIND_EXPR so it can be merged with the containing
1980 if (TREE_CODE (body
) == STATEMENT_LIST
1981 && STATEMENT_LIST_HEAD (body
) == NULL
1982 && !BIND_EXPR_BODY_BLOCK (stmt
)
1983 && !BIND_EXPR_TRY_BLOCK (stmt
))
1986 BIND_EXPR_BODY (stmt
) = body
;
1988 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1989 stmt
= pop_stmt_list (stmt
);
1992 /* Destroy any ObjC "super" receivers that may have been
1994 objc_clear_super_receiver ();
1996 stmt
= do_poplevel (stmt
);
1999 /* ??? See c_end_compound_stmt wrt statement expressions. */
2003 /* Finish an asm-statement, whose components are a STRING, some
2004 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
2005 LABELS. Also note whether the asm-statement should be
2006 considered volatile, and whether it is asm inline. */
2009 finish_asm_stmt (location_t loc
, int volatile_p
, tree string
,
2010 tree output_operands
, tree input_operands
, tree clobbers
,
2011 tree labels
, bool inline_p
)
2015 int ninputs
= list_length (input_operands
);
2016 int noutputs
= list_length (output_operands
);
2018 if (!processing_template_decl
)
2020 const char *constraint
;
2021 const char **oconstraints
;
2022 bool allows_mem
, allows_reg
, is_inout
;
2026 oconstraints
= XALLOCAVEC (const char *, noutputs
);
2028 string
= resolve_asm_operand_names (string
, output_operands
,
2029 input_operands
, labels
);
2031 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
2033 operand
= TREE_VALUE (t
);
2035 /* ??? Really, this should not be here. Users should be using a
2036 proper lvalue, dammit. But there's a long history of using
2037 casts in the output operands. In cases like longlong.h, this
2038 becomes a primitive form of typechecking -- if the cast can be
2039 removed, then the output operand had a type of the proper width;
2040 otherwise we'll get an error. Gross, but ... */
2041 STRIP_NOPS (operand
);
2043 operand
= mark_lvalue_use (operand
);
2045 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
2046 operand
= error_mark_node
;
2048 if (operand
!= error_mark_node
2049 && (TREE_READONLY (operand
)
2050 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
2051 /* Functions are not modifiable, even though they are
2053 || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand
))
2054 /* If it's an aggregate and any field is const, then it is
2055 effectively const. */
2056 || (CLASS_TYPE_P (TREE_TYPE (operand
))
2057 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
2058 cxx_readonly_error (loc
, operand
, lv_asm
);
2060 tree
*op
= &operand
;
2061 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
2062 op
= &TREE_OPERAND (*op
, 1);
2063 switch (TREE_CODE (*op
))
2065 case PREINCREMENT_EXPR
:
2066 case PREDECREMENT_EXPR
:
2068 *op
= genericize_compound_lvalue (*op
);
2069 op
= &TREE_OPERAND (*op
, 1);
2075 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
2076 oconstraints
[i
] = constraint
;
2078 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
2079 &allows_mem
, &allows_reg
, &is_inout
))
2081 /* If the operand is going to end up in memory,
2082 mark it addressable. */
2083 if (!allows_reg
&& !cxx_mark_addressable (*op
))
2084 operand
= error_mark_node
;
2087 operand
= error_mark_node
;
2089 TREE_VALUE (t
) = operand
;
2092 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
2094 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
2095 bool constraint_parsed
2096 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
2097 oconstraints
, &allows_mem
, &allows_reg
);
2098 /* If the operand is going to end up in memory, don't call
2099 decay_conversion. */
2100 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
2101 operand
= mark_lvalue_use (TREE_VALUE (t
));
2103 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
2105 /* If the type of the operand hasn't been determined (e.g.,
2106 because it involves an overloaded function), then issue
2107 an error message. There's no context available to
2108 resolve the overloading. */
2109 if (TREE_TYPE (operand
) == unknown_type_node
)
2112 "type of %<asm%> operand %qE could not be determined",
2114 operand
= error_mark_node
;
2117 if (constraint_parsed
)
2119 /* If the operand is going to end up in memory,
2120 mark it addressable. */
2121 if (!allows_reg
&& allows_mem
)
2123 /* Strip the nops as we allow this case. FIXME, this really
2124 should be rejected or made deprecated. */
2125 STRIP_NOPS (operand
);
2127 tree
*op
= &operand
;
2128 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
2129 op
= &TREE_OPERAND (*op
, 1);
2130 switch (TREE_CODE (*op
))
2132 case PREINCREMENT_EXPR
:
2133 case PREDECREMENT_EXPR
:
2135 *op
= genericize_compound_lvalue (*op
);
2136 op
= &TREE_OPERAND (*op
, 1);
2142 if (!cxx_mark_addressable (*op
))
2143 operand
= error_mark_node
;
2145 else if (!allows_reg
&& !allows_mem
)
2147 /* If constraint allows neither register nor memory,
2148 try harder to get a constant. */
2149 tree constop
= maybe_constant_value (operand
);
2150 if (TREE_CONSTANT (constop
))
2155 operand
= error_mark_node
;
2157 TREE_VALUE (t
) = operand
;
2161 r
= build_stmt (loc
, ASM_EXPR
, string
,
2162 output_operands
, input_operands
,
2164 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
2165 ASM_INLINE_P (r
) = inline_p
;
2166 r
= maybe_cleanup_point_expr_void (r
);
2167 return add_stmt (r
);
2170 /* Finish a label with the indicated NAME. Returns the new label. */
2173 finish_label_stmt (tree name
)
2175 tree decl
= define_label (input_location
, name
);
2177 if (decl
== error_mark_node
)
2178 return error_mark_node
;
2180 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
2185 /* Finish a series of declarations for local labels. G++ allows users
2186 to declare "local" labels, i.e., labels with scope. This extension
2187 is useful when writing code involving statement-expressions. */
2190 finish_label_decl (tree name
)
2192 if (!at_function_scope_p ())
2194 error ("%<__label__%> declarations are only allowed in function scopes");
2198 add_decl_expr (declare_local_label (name
));
2201 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
2204 finish_decl_cleanup (tree decl
, tree cleanup
)
2206 push_cleanup (decl
, cleanup
, false);
2209 /* If the current scope exits with an exception, run CLEANUP. */
2212 finish_eh_cleanup (tree cleanup
)
2214 push_cleanup (NULL
, cleanup
, true);
2217 /* The MEM_INITS is a list of mem-initializers, in reverse of the
2218 order they were written by the user. Each node is as for
2219 emit_mem_initializers. */
2222 finish_mem_initializers (tree mem_inits
)
2224 /* Reorder the MEM_INITS so that they are in the order they appeared
2225 in the source program. */
2226 mem_inits
= nreverse (mem_inits
);
2228 if (processing_template_decl
)
2232 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
2234 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
2235 check for bare parameter packs in the TREE_VALUE, because
2236 any parameter packs in the TREE_VALUE have already been
2237 bound as part of the TREE_PURPOSE. See
2238 make_pack_expansion for more information. */
2239 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
2240 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
2241 TREE_VALUE (mem
) = error_mark_node
;
2244 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
2245 CTOR_INITIALIZER
, mem_inits
));
2248 emit_mem_initializers (mem_inits
);
2251 /* Obfuscate EXPR if it looks like an id-expression or member access so
2252 that the call to finish_decltype in do_auto_deduction will give the
2253 right result. If EVEN_UNEVAL, do this even in unevaluated context. */
2256 force_paren_expr (tree expr
, bool even_uneval
/* = false */)
2258 /* This is only needed for decltype(auto) in C++14. */
2259 if (cxx_dialect
< cxx14
)
2262 /* If we're in unevaluated context, we can't be deducing a
2263 return/initializer type, so we don't need to mess with this. */
2264 if (cp_unevaluated_operand
&& !even_uneval
)
2267 if (TREE_CODE (expr
) == COMPONENT_REF
2268 || TREE_CODE (expr
) == SCOPE_REF
2269 || REFERENCE_REF_P (expr
))
2270 REF_PARENTHESIZED_P (expr
) = true;
2271 else if (DECL_P (tree_strip_any_location_wrapper (expr
)))
2273 location_t loc
= cp_expr_location (expr
);
2274 const tree_code code
= processing_template_decl
? PAREN_EXPR
2275 : VIEW_CONVERT_EXPR
;
2276 expr
= build1_loc (loc
, code
, TREE_TYPE (expr
), expr
);
2277 REF_PARENTHESIZED_P (expr
) = true;
2282 /* If T is an id-expression obfuscated by force_paren_expr, undo the
2283 obfuscation and return the underlying id-expression. Otherwise
2287 maybe_undo_parenthesized_ref (tree t
)
2289 if (cxx_dialect
< cxx14
)
2292 if ((TREE_CODE (t
) == PAREN_EXPR
|| TREE_CODE (t
) == VIEW_CONVERT_EXPR
)
2293 && REF_PARENTHESIZED_P (t
))
2294 t
= TREE_OPERAND (t
, 0);
2299 /* Finish a parenthesized expression EXPR. */
2302 finish_parenthesized_expr (cp_expr expr
)
2306 /* This inhibits warnings in maybe_warn_unparenthesized_assignment
2307 and c_common_truthvalue_conversion. */
2308 suppress_warning (STRIP_REFERENCE_REF (*expr
), OPT_Wparentheses
);
2311 if (TREE_CODE (expr
) == OFFSET_REF
2312 || TREE_CODE (expr
) == SCOPE_REF
)
2313 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
2314 enclosed in parentheses. */
2315 PTRMEM_OK_P (expr
) = 0;
2317 tree stripped_expr
= tree_strip_any_location_wrapper (expr
);
2318 if (TREE_CODE (stripped_expr
) == STRING_CST
)
2319 PAREN_STRING_LITERAL_P (stripped_expr
) = 1;
2321 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
2326 /* Finish a reference to a non-static data member (DECL) that is not
2327 preceded by `.' or `->'. */
2330 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
,
2331 tsubst_flags_t complain
/* = tf_warning_or_error */)
2333 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
2334 bool try_omp_private
= !object
&& omp_private_member_map
;
2339 tree scope
= qualifying_scope
;
2340 if (scope
== NULL_TREE
)
2342 scope
= context_for_name_lookup (decl
);
2343 if (!TYPE_P (scope
))
2345 /* Can happen during error recovery (c++/85014). */
2346 gcc_assert (seen_error ());
2347 return error_mark_node
;
2350 object
= maybe_dummy_object (scope
, NULL
);
2353 object
= maybe_resolve_dummy (object
, true);
2354 if (object
== error_mark_node
)
2355 return error_mark_node
;
2357 /* DR 613/850: Can use non-static data members without an associated
2358 object in sizeof/decltype/alignof. */
2359 if (is_dummy_object (object
)
2360 && !cp_unevaluated_operand
2361 && (!processing_template_decl
|| !current_class_ref
))
2363 if (complain
& tf_error
)
2365 if (current_function_decl
2366 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2367 error ("invalid use of member %qD in static member function", decl
);
2368 else if (current_function_decl
2369 && processing_contract_condition
2370 && DECL_CONSTRUCTOR_P (current_function_decl
))
2371 error ("invalid use of member %qD in constructor %<pre%> contract", decl
);
2372 else if (current_function_decl
2373 && processing_contract_condition
2374 && DECL_DESTRUCTOR_P (current_function_decl
))
2375 error ("invalid use of member %qD in destructor %<post%> contract", decl
);
2377 error ("invalid use of non-static data member %qD", decl
);
2378 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
2381 return error_mark_node
;
2384 if (current_class_ptr
)
2385 TREE_USED (current_class_ptr
) = 1;
2386 if (processing_template_decl
)
2388 tree type
= TREE_TYPE (decl
);
2390 if (TYPE_REF_P (type
))
2391 /* Quals on the object don't matter. */;
2392 else if (PACK_EXPANSION_P (type
))
2393 /* Don't bother trying to represent this. */
2395 else if (WILDCARD_TYPE_P (TREE_TYPE (object
)))
2396 /* We don't know what the eventual quals will be, so punt until
2399 This can happen when called from build_capture_proxy for an explicit
2400 object lambda. It's a bit marginal to call this function in that
2401 case, since this function is for references to members of 'this',
2402 but the deduced type is required to be derived from the closure
2403 type, so it works. */
2407 /* Set the cv qualifiers. */
2408 int quals
= cp_type_quals (TREE_TYPE (object
));
2410 if (DECL_MUTABLE_P (decl
))
2411 quals
&= ~TYPE_QUAL_CONST
;
2413 quals
|= cp_type_quals (TREE_TYPE (decl
));
2414 type
= cp_build_qualified_type (type
, quals
);
2417 if (qualifying_scope
)
2418 /* Wrap this in a SCOPE_REF for now. */
2419 ret
= build_qualified_name (type
, qualifying_scope
, decl
,
2420 /*template_p=*/false);
2422 ret
= (convert_from_reference
2423 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
2425 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2426 QUALIFYING_SCOPE is also non-null. */
2429 tree access_type
= TREE_TYPE (object
);
2431 if (!perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
2433 return error_mark_node
;
2435 /* If the data member was named `C::M', convert `*this' to `C'
2437 if (qualifying_scope
)
2439 tree binfo
= NULL_TREE
;
2440 object
= build_scoped_ref (object
, qualifying_scope
,
2444 ret
= build_class_member_access_expr (object
, decl
,
2445 /*access_path=*/NULL_TREE
,
2446 /*preserve_reference=*/false,
2449 if (try_omp_private
)
2451 tree
*v
= omp_private_member_map
->get (decl
);
2453 ret
= convert_from_reference (*v
);
2458 /* DECL was the declaration to which a qualified-id resolved. Issue
2459 an error message if it is not accessible. If OBJECT_TYPE is
2460 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2461 type of `*x', or `x', respectively. If the DECL was named as
2462 `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2463 perform_access_checks above. */
2466 check_accessibility_of_qualified_id (tree decl
,
2468 tree nested_name_specifier
,
2469 tsubst_flags_t complain
)
2471 /* If we're not checking, return immediately. */
2472 if (deferred_access_no_check
)
2475 /* Determine the SCOPE of DECL. */
2476 tree scope
= context_for_name_lookup (decl
);
2477 /* If the SCOPE is not a type, then DECL is not a member. */
2479 /* If SCOPE is dependent then we can't perform this access check now,
2480 and since we'll perform this access check again after substitution
2481 there's no need to explicitly defer it. */
2482 || dependent_type_p (scope
))
2485 tree qualifying_type
= NULL_TREE
;
2486 /* Compute the scope through which DECL is being accessed. */
2488 /* OBJECT_TYPE might not be a class type; consider:
2490 class A { typedef int I; };
2494 In this case, we will have "A::I" as the DECL, but "I" as the
2496 && CLASS_TYPE_P (object_type
)
2497 && DERIVED_FROM_P (scope
, object_type
))
2498 /* If we are processing a `->' or `.' expression, use the type of the
2500 qualifying_type
= object_type
;
2501 else if (nested_name_specifier
)
2503 /* If the reference is to a non-static member of the
2504 current class, treat it as if it were referenced through
2506 if (DECL_NONSTATIC_MEMBER_P (decl
)
2507 && current_class_ptr
)
2508 if (tree current
= current_nonlambda_class_type ())
2510 if (dependent_type_p (current
))
2511 /* In general we can't know whether this access goes through
2512 `this' until instantiation time. Punt now, or else we might
2513 create a deferred access check that's not relative to `this'
2514 when it ought to be. We'll check this access again after
2515 substitution, e.g. from tsubst_qualified_id. */
2518 if (DERIVED_FROM_P (scope
, current
))
2519 qualifying_type
= current
;
2521 /* Otherwise, use the type indicated by the
2522 nested-name-specifier. */
2523 if (!qualifying_type
)
2524 qualifying_type
= nested_name_specifier
;
2527 /* Otherwise, the name must be from the current class or one of
2529 qualifying_type
= currently_open_derived_class (scope
);
2532 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2533 or similar in a default argument value. */
2534 && CLASS_TYPE_P (qualifying_type
))
2535 return perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
2541 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2542 class named to the left of the "::" operator. DONE is true if this
2543 expression is a complete postfix-expression; it is false if this
2544 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2545 iff this expression is the operand of '&'. TEMPLATE_P is true iff
2546 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2547 is true iff this qualified name appears as a template argument. */
2550 finish_qualified_id_expr (tree qualifying_class
,
2555 bool template_arg_p
,
2556 tsubst_flags_t complain
)
2558 gcc_assert (TYPE_P (qualifying_class
));
2560 if (error_operand_p (expr
))
2561 return error_mark_node
;
2564 /* Functions are marked after overload resolution; avoid redundant
2566 && TREE_CODE (expr
) != FUNCTION_DECL
2567 && !mark_used (expr
, complain
))
2568 return error_mark_node
;
2572 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
2574 /* cp_parser_lookup_name thought we were looking for a type,
2575 but we're actually looking for a declaration. */
2576 qualifying_class
= TYPE_CONTEXT (expr
);
2577 expr
= TYPE_IDENTIFIER (expr
);
2580 check_template_keyword (expr
);
2583 /* If EXPR occurs as the operand of '&', use special handling that
2584 permits a pointer-to-member. */
2585 if (address_p
&& done
2586 && TREE_CODE (qualifying_class
) != ENUMERAL_TYPE
)
2588 if (TREE_CODE (expr
) == SCOPE_REF
)
2589 expr
= TREE_OPERAND (expr
, 1);
2590 expr
= build_offset_ref (qualifying_class
, expr
,
2591 /*address_p=*/true, complain
);
2595 /* No need to check access within an enum. */
2596 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
2597 && TREE_CODE (expr
) != IDENTIFIER_NODE
)
2600 /* Within the scope of a class, turn references to non-static
2601 members into expression of the form "this->...". */
2603 /* But, within a template argument, we do not want make the
2604 transformation, as there is no "this" pointer. */
2606 else if (TREE_CODE (expr
) == FIELD_DECL
)
2608 push_deferring_access_checks (dk_no_check
);
2609 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2610 qualifying_class
, complain
);
2611 pop_deferring_access_checks ();
2613 else if (BASELINK_P (expr
))
2615 /* See if any of the functions are non-static members. */
2616 /* If so, the expression may be relative to 'this'. */
2617 if (!shared_member_p (expr
)
2618 && current_class_ptr
2619 && DERIVED_FROM_P (qualifying_class
,
2620 current_nonlambda_class_type ()))
2621 expr
= (build_class_member_access_expr
2622 (maybe_dummy_object (qualifying_class
, NULL
),
2624 BASELINK_ACCESS_BINFO (expr
),
2625 /*preserve_reference=*/false,
2628 /* The expression is a qualified name whose address is not
2630 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2633 else if (!template_p
2634 && TREE_CODE (expr
) == TEMPLATE_DECL
2635 && !DECL_FUNCTION_TEMPLATE_P (expr
))
2637 if (complain
& tf_error
)
2638 error ("%qE missing template arguments", expr
);
2639 return error_mark_node
;
2643 /* In a template, return a SCOPE_REF for most qualified-ids
2644 so that we can check access at instantiation time. But if
2645 we're looking at a member of the current instantiation, we
2646 know we have access and building up the SCOPE_REF confuses
2647 non-type template argument handling. */
2648 if (processing_template_decl
2649 && (!currently_open_class (qualifying_class
)
2650 || TREE_CODE (expr
) == IDENTIFIER_NODE
2651 || TREE_CODE (expr
) == TEMPLATE_ID_EXPR
2652 || TREE_CODE (expr
) == BIT_NOT_EXPR
))
2653 expr
= build_qualified_name (TREE_TYPE (expr
),
2654 qualifying_class
, expr
,
2656 else if (tree wrap
= maybe_get_tls_wrapper_call (expr
))
2659 expr
= convert_from_reference (expr
);
2665 /* Begin a statement-expression. The value returned must be passed to
2666 finish_stmt_expr. */
2669 begin_stmt_expr (void)
2671 return push_stmt_list ();
2674 /* Process the final expression of a statement expression. EXPR can be
2675 NULL, if the final expression is empty. Return a STATEMENT_LIST
2676 containing all the statements in the statement-expression, or
2677 ERROR_MARK_NODE if there was an error. */
2680 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2682 if (error_operand_p (expr
))
2684 /* The type of the statement-expression is the type of the last
2686 TREE_TYPE (stmt_expr
) = error_mark_node
;
2687 return error_mark_node
;
2690 /* If the last statement does not have "void" type, then the value
2691 of the last statement is the value of the entire expression. */
2694 tree type
= TREE_TYPE (expr
);
2696 if (type
&& type_unknown_p (type
))
2698 error ("a statement expression is an insufficient context"
2699 " for overload resolution");
2700 TREE_TYPE (stmt_expr
) = error_mark_node
;
2701 return error_mark_node
;
2703 else if (processing_template_decl
)
2705 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2706 expr
= add_stmt (expr
);
2707 /* Mark the last statement so that we can recognize it as such at
2708 template-instantiation time. */
2709 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2711 else if (VOID_TYPE_P (type
))
2713 /* Just treat this like an ordinary statement. */
2714 expr
= finish_expr_stmt (expr
);
2718 /* It actually has a value we need to deal with. First, force it
2719 to be an rvalue so that we won't need to build up a copy
2720 constructor call later when we try to assign it to something. */
2721 expr
= force_rvalue (expr
, tf_warning_or_error
);
2722 if (error_operand_p (expr
))
2723 return error_mark_node
;
2725 /* Update for array-to-pointer decay. */
2726 type
= TREE_TYPE (expr
);
2728 /* This TARGET_EXPR will initialize the outer one added by
2729 finish_stmt_expr. */
2730 set_target_expr_eliding (expr
);
2732 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2733 normal statement, but don't convert to void or actually add
2735 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2736 expr
= maybe_cleanup_point_expr (expr
);
2740 /* The type of the statement-expression is the type of the last
2742 TREE_TYPE (stmt_expr
) = type
;
2748 /* Finish a statement-expression. EXPR should be the value returned
2749 by the previous begin_stmt_expr. Returns an expression
2750 representing the statement-expression. */
2753 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2758 if (error_operand_p (stmt_expr
))
2760 pop_stmt_list (stmt_expr
);
2761 return error_mark_node
;
2764 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2766 type
= TREE_TYPE (stmt_expr
);
2767 result
= pop_stmt_list (stmt_expr
);
2768 TREE_TYPE (result
) = type
;
2770 if (processing_template_decl
)
2772 result
= build_min (STMT_EXPR
, type
, result
);
2773 TREE_SIDE_EFFECTS (result
) = 1;
2774 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2776 else if (CLASS_TYPE_P (type
))
2778 /* Wrap the statement-expression in a TARGET_EXPR so that the
2779 temporary object created by the final expression is destroyed at
2780 the end of the full-expression containing the
2781 statement-expression. */
2782 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2788 /* Returns the expression which provides the value of STMT_EXPR. */
2791 stmt_expr_value_expr (tree stmt_expr
)
2793 tree t
= STMT_EXPR_STMT (stmt_expr
);
2795 if (TREE_CODE (t
) == BIND_EXPR
)
2796 t
= BIND_EXPR_BODY (t
);
2798 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2799 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2801 if (TREE_CODE (t
) == EXPR_STMT
)
2802 t
= EXPR_STMT_EXPR (t
);
2807 /* Return TRUE iff EXPR_STMT is an empty list of
2808 expression statements. */
2811 empty_expr_stmt_p (tree expr_stmt
)
2813 tree body
= NULL_TREE
;
2815 if (expr_stmt
== void_node
)
2820 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2821 body
= EXPR_STMT_EXPR (expr_stmt
);
2822 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2828 if (TREE_CODE (body
) == STATEMENT_LIST
)
2829 return tsi_end_p (tsi_start (body
));
2831 return empty_expr_stmt_p (body
);
2836 /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
2837 the function (or functions) to call; ARGS are the arguments to the
2838 call. Returns the functions to be considered by overload resolution. */
2841 perform_koenig_lookup (cp_expr fn_expr
, vec
<tree
, va_gc
> *args
,
2842 tsubst_flags_t complain
)
2844 tree identifier
= NULL_TREE
;
2845 tree functions
= NULL_TREE
;
2846 tree tmpl_args
= NULL_TREE
;
2847 bool template_id
= false;
2848 location_t loc
= fn_expr
.get_location ();
2849 tree fn
= fn_expr
.get_value ();
2851 STRIP_ANY_LOCATION_WRAPPER (fn
);
2853 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2855 /* Use a separate flag to handle null args. */
2857 tmpl_args
= TREE_OPERAND (fn
, 1);
2858 fn
= TREE_OPERAND (fn
, 0);
2861 /* Find the name of the overloaded function. */
2862 if (identifier_p (fn
))
2867 identifier
= OVL_NAME (functions
);
2870 /* A call to a namespace-scope function using an unqualified name.
2872 Do Koenig lookup -- unless any of the arguments are
2874 if (!any_type_dependent_arguments_p (args
)
2875 && !any_dependent_template_arguments_p (tmpl_args
))
2877 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2880 /* The unqualified name could not be resolved. */
2881 if (complain
& tf_error
)
2882 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2888 if (fn
&& template_id
&& fn
!= error_mark_node
)
2889 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2891 return cp_expr (fn
, loc
);
2894 /* Generate an expression for `FN (ARGS)'. This may change the
2897 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2898 as a virtual call, even if FN is virtual. (This flag is set when
2899 encountering an expression where the function name is explicitly
2900 qualified. For example a call to `X::f' never generates a virtual
2903 Returns code for the call. */
2906 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2907 bool koenig_p
, tsubst_flags_t complain
)
2911 vec
<tree
, va_gc
> *orig_args
= *args
;
2913 if (fn
== error_mark_node
)
2914 return error_mark_node
;
2916 gcc_assert (!TYPE_P (fn
));
2918 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2919 it so that we can tell this is a call to a known function. */
2920 fn
= maybe_undo_parenthesized_ref (fn
);
2922 STRIP_ANY_LOCATION_WRAPPER (fn
);
2926 if (processing_template_decl
)
2928 /* If FN is a local extern declaration (or set thereof) in a template,
2929 look it up again at instantiation time. */
2930 if (is_overloaded_fn (fn
))
2932 tree ifn
= get_first_fn (fn
);
2933 if (TREE_CODE (ifn
) == FUNCTION_DECL
2934 && dependent_local_decl_p (ifn
))
2935 orig_fn
= DECL_NAME (ifn
);
2938 /* If the call expression is dependent, build a CALL_EXPR node
2939 with no type; type_dependent_expression_p recognizes
2940 expressions with no type as being dependent. */
2941 if (type_dependent_expression_p (fn
)
2942 || any_type_dependent_arguments_p (*args
))
2944 result
= build_min_nt_call_vec (orig_fn
, *args
);
2945 SET_EXPR_LOCATION (result
, cp_expr_loc_or_input_loc (fn
));
2946 KOENIG_LOOKUP_P (result
) = koenig_p
;
2947 /* Disable the std::move warnings since this call was dependent
2948 (c++/89780, c++/107363). This also suppresses the
2949 -Wredundant-move warning. */
2950 suppress_warning (result
, OPT_Wpessimizing_move
);
2954 bool abnormal
= true;
2955 for (lkp_iterator
iter (maybe_get_fns (fn
)); iter
; ++iter
)
2957 tree fndecl
= STRIP_TEMPLATE (*iter
);
2958 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2959 || !TREE_THIS_VOLATILE (fndecl
))
2965 /* FIXME: Stop warning about falling off end of non-void
2966 function. But this is wrong. Even if we only see
2967 no-return fns at this point, we could select a
2968 future-defined return fn during instantiation. Or
2971 current_function_returns_abnormally
= 1;
2973 if (TREE_CODE (fn
) == COMPONENT_REF
)
2974 maybe_generic_this_capture (TREE_OPERAND (fn
, 0),
2975 TREE_OPERAND (fn
, 1));
2978 orig_args
= make_tree_vector_copy (*args
);
2981 if (TREE_CODE (fn
) == COMPONENT_REF
)
2983 tree member
= TREE_OPERAND (fn
, 1);
2984 if (BASELINK_P (member
))
2986 tree object
= TREE_OPERAND (fn
, 0);
2987 return build_new_method_call (object
, member
,
2990 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2997 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2998 if (TREE_CODE (fn
) == ADDR_EXPR
2999 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
3000 fn
= TREE_OPERAND (fn
, 0);
3002 if (is_overloaded_fn (fn
))
3003 fn
= baselink_for_fns (fn
);
3006 if (BASELINK_P (fn
))
3010 /* A call to a member function. From [over.call.func]:
3012 If the keyword this is in scope and refers to the class of
3013 that member function, or a derived class thereof, then the
3014 function call is transformed into a qualified function call
3015 using (*this) as the postfix-expression to the left of the
3016 . operator.... [Otherwise] a contrived object of type T
3017 becomes the implied object argument.
3021 struct A { void f(); };
3022 struct B : public A {};
3023 struct C : public A { void g() { B::f(); }};
3025 "the class of that member function" refers to `A'. But 11.2
3026 [class.access.base] says that we need to convert 'this' to B* as
3027 part of the access, so we pass 'B' to maybe_dummy_object. */
3029 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
3031 /* A constructor call always uses a dummy object. (This constructor
3032 call which has the form A::A () is actually invalid and we are
3033 going to reject it later in build_new_method_call.) */
3034 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
3037 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
3040 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
3042 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
3047 else if (concept_check_p (fn
))
3049 /* FN is actually a template-id referring to a concept definition. */
3050 tree id
= unpack_concept_check (fn
);
3051 tree tmpl
= TREE_OPERAND (id
, 0);
3052 tree args
= TREE_OPERAND (id
, 1);
3054 if (!function_concept_p (tmpl
))
3056 error_at (EXPR_LOC_OR_LOC (fn
, input_location
),
3057 "cannot call a concept as a function");
3058 return error_mark_node
;
3061 /* Ensure the result is wrapped as a call expression. */
3062 result
= build_concept_check (tmpl
, args
, tf_warning_or_error
);
3064 else if (is_overloaded_fn (fn
))
3066 /* If the function is an overloaded builtin, resolve it. */
3067 if (TREE_CODE (fn
) == FUNCTION_DECL
3068 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
3069 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
3070 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
3074 tree alloc_size_attr
= NULL_TREE
;
3075 if (warn_calloc_transposed_args
3076 && TREE_CODE (fn
) == FUNCTION_DECL
3078 = lookup_attribute ("alloc_size",
3079 TYPE_ATTRIBUTES (TREE_TYPE (fn
)))))
3080 if (TREE_VALUE (alloc_size_attr
) == NULL_TREE
3081 || TREE_CHAIN (TREE_VALUE (alloc_size_attr
)) == NULL_TREE
)
3082 alloc_size_attr
= NULL_TREE
;
3083 if ((warn_sizeof_pointer_memaccess
|| alloc_size_attr
)
3084 && (complain
& tf_warning
)
3085 && !vec_safe_is_empty (*args
)
3086 && !processing_template_decl
)
3088 location_t sizeof_arg_loc
[6];
3091 for (i
= 0; i
< (alloc_size_attr
? 6 : 3); i
++)
3095 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
3096 sizeof_arg
[i
] = NULL_TREE
;
3097 if (i
>= (*args
)->length ())
3100 if (TREE_CODE (t
) != SIZEOF_EXPR
)
3102 if (SIZEOF_EXPR_TYPE_P (t
))
3103 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
3105 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
3106 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
3108 if (warn_sizeof_pointer_memaccess
)
3110 auto same_p
= same_type_ignoring_top_level_qualifiers_p
;
3111 sizeof_pointer_memaccess_warning (sizeof_arg_loc
, fn
, *args
,
3112 sizeof_arg
, same_p
);
3114 if (alloc_size_attr
)
3115 warn_for_calloc (sizeof_arg_loc
, fn
, *args
, sizeof_arg
,
3119 if ((complain
& tf_warning
)
3120 && TREE_CODE (fn
) == FUNCTION_DECL
3121 && fndecl_built_in_p (fn
, BUILT_IN_MEMSET
)
3122 && vec_safe_length (*args
) == 3
3123 && !any_type_dependent_arguments_p (*args
))
3125 tree arg0
= (*orig_args
)[0];
3126 tree arg1
= (*orig_args
)[1];
3127 tree arg2
= (*orig_args
)[2];
3128 int literal_mask
= ((literal_integer_zerop (arg1
) << 1)
3129 | (literal_integer_zerop (arg2
) << 2));
3130 warn_for_memset (input_location
, arg0
, arg2
, literal_mask
);
3133 /* A call to a namespace-scope function. */
3134 result
= build_new_function_call (fn
, args
, complain
);
3137 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
3139 if (!vec_safe_is_empty (*args
))
3140 error ("arguments to destructor are not allowed");
3141 /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
3142 which case the postfix-expression is a possibly-parenthesized class
3143 member access), the function call destroys the object of scalar type
3144 denoted by the object expression of the class member access. */
3145 tree ob
= TREE_OPERAND (fn
, 0);
3147 result
= build_trivial_dtor_call (ob
, true);
3149 /* No location to clobber. */
3150 result
= convert_to_void (ob
, ICV_STATEMENT
, complain
);
3152 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
3153 /* If the "function" is really an object of class type, it might
3154 have an overloaded `operator ()'. */
3155 result
= build_op_call (fn
, args
, complain
);
3158 /* A call where the function is unknown. */
3159 result
= cp_build_function_call_vec (fn
, args
, complain
);
3161 if (processing_template_decl
&& result
!= error_mark_node
)
3163 if (INDIRECT_REF_P (result
))
3164 result
= TREE_OPERAND (result
, 0);
3166 /* Prune all but the selected function from the original overload
3167 set so that we can avoid some duplicate work at instantiation time. */
3168 if (TREE_CODE (result
) == CALL_EXPR
3169 && really_overloaded_fn (orig_fn
))
3171 tree sel_fn
= CALL_EXPR_FN (result
);
3172 if (TREE_CODE (sel_fn
) == COMPONENT_REF
)
3174 /* The non-dependent result of build_new_method_call. */
3175 sel_fn
= TREE_OPERAND (sel_fn
, 1);
3176 gcc_assert (BASELINK_P (sel_fn
));
3178 else if (TREE_CODE (sel_fn
) == ADDR_EXPR
)
3179 /* Our original callee wasn't wrapped in an ADDR_EXPR,
3180 so strip this ADDR_EXPR added by build_over_call. */
3181 sel_fn
= TREE_OPERAND (sel_fn
, 0);
3185 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
3186 SET_EXPR_LOCATION (result
, input_location
);
3187 KOENIG_LOOKUP_P (result
) = koenig_p
;
3188 release_tree_vector (orig_args
);
3189 result
= convert_from_reference (result
);
3195 /* Finish a call to a postfix increment or decrement or EXPR. (Which
3196 is indicated by CODE, which should be POSTINCREMENT_EXPR or
3197 POSTDECREMENT_EXPR.) */
3200 finish_increment_expr (cp_expr expr
, enum tree_code code
)
3202 /* input_location holds the location of the trailing operator token.
3203 Build a location of the form:
3206 with the caret at the operator token, ranging from the start
3207 of EXPR to the end of the operator token. */
3208 location_t combined_loc
= make_location (input_location
,
3210 get_finish (input_location
));
3211 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
3212 NULL_TREE
, tf_warning_or_error
);
3213 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
3214 result
.set_location (combined_loc
);
3218 /* Finish a use of `this'. Returns an expression for `this'. */
3221 finish_this_expr (void)
3223 tree result
= NULL_TREE
;
3225 if (current_class_ptr
)
3227 tree type
= TREE_TYPE (current_class_ref
);
3229 /* In a lambda expression, 'this' refers to the captured 'this'. */
3230 if (LAMBDA_TYPE_P (type
))
3231 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
3233 result
= current_class_ptr
;
3237 /* The keyword 'this' is a prvalue expression. */
3238 return rvalue (result
);
3240 tree fn
= current_nonlambda_function ();
3241 if (fn
&& DECL_XOBJ_MEMBER_FUNCTION_P (fn
))
3243 auto_diagnostic_group d
;
3244 error ("%<this%> is unavailable for explicit object member "
3246 tree xobj_parm
= DECL_ARGUMENTS (fn
);
3247 gcc_assert (xobj_parm
);
3248 tree parm_name
= DECL_NAME (xobj_parm
);
3250 static tree remembered_fn
= NULL_TREE
;
3251 /* Only output this diagnostic once per function. */
3252 if (remembered_fn
== fn
)
3253 /* Early escape. */;
3255 inform (DECL_SOURCE_LOCATION (xobj_parm
),
3256 "use explicit object parameter %qs instead",
3257 IDENTIFIER_POINTER (parm_name
));
3259 inform (DECL_SOURCE_LOCATION (xobj_parm
),
3260 "name the explicit object parameter");
3264 else if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
3265 error ("%<this%> is unavailable for static member functions");
3266 else if (fn
&& processing_contract_condition
&& DECL_CONSTRUCTOR_P (fn
))
3267 error ("invalid use of %<this%> before it is valid");
3268 else if (fn
&& processing_contract_condition
&& DECL_DESTRUCTOR_P (fn
))
3269 error ("invalid use of %<this%> after it is valid");
3271 error ("invalid use of %<this%> in non-member function");
3273 error ("invalid use of %<this%> at top level");
3274 return error_mark_node
;
3277 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
3278 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
3279 the TYPE for the type given. If SCOPE is non-NULL, the expression
3280 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
3283 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
3286 if (object
== error_mark_node
|| destructor
== error_mark_node
)
3287 return error_mark_node
;
3289 gcc_assert (TYPE_P (destructor
));
3291 if (!processing_template_decl
)
3293 if (scope
== error_mark_node
)
3295 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
3296 return error_mark_node
;
3298 if (is_auto (destructor
))
3299 destructor
= TREE_TYPE (object
);
3300 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
3303 "qualified type %qT does not match destructor name ~%qT",
3305 return error_mark_node
;
3309 /* [expr.pseudo] says both:
3311 The type designated by the pseudo-destructor-name shall be
3312 the same as the object type.
3316 The cv-unqualified versions of the object type and of the
3317 type designated by the pseudo-destructor-name shall be the
3320 We implement the more generous second sentence, since that is
3321 what most other compilers do. */
3322 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
3325 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
3326 return error_mark_node
;
3330 tree type
= (type_dependent_expression_p (object
)
3331 ? NULL_TREE
: void_type_node
);
3333 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, type
, object
,
3337 /* Finish an expression of the form CODE EXPR. */
3340 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
3341 tsubst_flags_t complain
)
3343 /* Build a location of the form:
3346 with the caret at the operator token, ranging from the start
3347 of the operator token to the end of EXPR. */
3348 location_t combined_loc
= make_location (op_loc
,
3349 op_loc
, expr
.get_finish ());
3350 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
3351 NULL_TREE
, complain
);
3352 /* TODO: build_x_unary_op doesn't always honor the location. */
3353 result
.set_location (combined_loc
);
3355 if (result
== error_mark_node
)
3358 if (!(complain
& tf_warning
))
3361 tree result_ovl
= result
;
3362 tree expr_ovl
= expr
;
3364 if (!processing_template_decl
)
3365 expr_ovl
= cp_fully_fold (expr_ovl
);
3367 if (!CONSTANT_CLASS_P (expr_ovl
)
3368 || TREE_OVERFLOW_P (expr_ovl
))
3371 if (!processing_template_decl
)
3372 result_ovl
= cp_fully_fold (result_ovl
);
3374 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
3375 overflow_warning (combined_loc
, result_ovl
);
3380 /* Return true if CONSTRUCTOR EXPR after pack expansion could have no
3384 maybe_zero_constructor_nelts (tree expr
)
3386 if (CONSTRUCTOR_NELTS (expr
) == 0)
3388 if (!processing_template_decl
)
3390 for (constructor_elt
&elt
: CONSTRUCTOR_ELTS (expr
))
3391 if (!PACK_EXPANSION_P (elt
.value
))
3396 /* Finish a compound-literal expression or C++11 functional cast with aggregate
3397 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3401 finish_compound_literal (tree type
, tree compound_literal
,
3402 tsubst_flags_t complain
,
3405 if (type
== error_mark_node
)
3406 return error_mark_node
;
3408 if (TYPE_REF_P (type
))
3411 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
3412 complain
, fcl_context
);
3413 /* The prvalue is then used to direct-initialize the reference. */
3414 tree r
= (perform_implicit_conversion_flags
3415 (type
, compound_literal
, complain
, LOOKUP_NORMAL
));
3416 return convert_from_reference (r
);
3419 if (!TYPE_OBJ_P (type
))
3422 if (VOID_TYPE_P (type
) && CONSTRUCTOR_NELTS (compound_literal
) == 0)
3424 if (!processing_template_decl
)
3426 TREE_TYPE (compound_literal
) = type
;
3427 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
3428 CONSTRUCTOR_IS_DEPENDENT (compound_literal
) = 0;
3429 return compound_literal
;
3431 else if (VOID_TYPE_P (type
)
3432 && processing_template_decl
3433 && maybe_zero_constructor_nelts (compound_literal
))
3434 /* If there are only packs in compound_literal, it could
3435 be void{} after pack expansion. */;
3438 if (complain
& tf_error
)
3439 error ("compound literal of non-object type %qT", type
);
3440 return error_mark_node
;
3444 if (template_placeholder_p (type
))
3446 type
= do_auto_deduction (type
, compound_literal
, type
, complain
,
3448 if (type
== error_mark_node
)
3449 return error_mark_node
;
3451 /* C++23 auto{x}. */
3452 else if (is_auto (type
)
3453 && !AUTO_IS_DECLTYPE (type
)
3454 && CONSTRUCTOR_NELTS (compound_literal
) == 1)
3456 if (is_constrained_auto (type
))
3458 if (complain
& tf_error
)
3459 error ("%<auto{x}%> cannot be constrained");
3460 return error_mark_node
;
3462 else if (cxx_dialect
< cxx23
)
3463 pedwarn (input_location
, OPT_Wc__23_extensions
,
3464 "%<auto{x}%> only available with "
3465 "%<-std=c++2b%> or %<-std=gnu++2b%>");
3466 type
= do_auto_deduction (type
, compound_literal
, type
, complain
,
3468 if (type
== error_mark_node
)
3469 return error_mark_node
;
3472 /* Used to hold a copy of the compound literal in a template. */
3473 tree orig_cl
= NULL_TREE
;
3475 if (processing_template_decl
)
3477 const bool dependent_p
3478 = (instantiation_dependent_expression_p (compound_literal
)
3479 || dependent_type_p (type
));
3481 /* We're about to return, no need to copy. */
3482 orig_cl
= compound_literal
;
3484 /* We're going to need a copy. */
3485 orig_cl
= unshare_constructor (compound_literal
);
3486 TREE_TYPE (orig_cl
) = type
;
3487 /* Mark the expression as a compound literal. */
3488 TREE_HAS_CONSTRUCTOR (orig_cl
) = 1;
3489 /* And as instantiation-dependent. */
3490 CONSTRUCTOR_IS_DEPENDENT (orig_cl
) = dependent_p
;
3491 if (fcl_context
== fcl_c99
)
3492 CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl
) = 1;
3493 /* If the compound literal is dependent, we're done for now. */
3496 /* Otherwise, do go on to e.g. check narrowing. */
3499 type
= complete_type (type
);
3501 if (TYPE_NON_AGGREGATE_CLASS (type
))
3503 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3504 everywhere that deals with function arguments would be a pain, so
3505 just wrap it in a TREE_LIST. The parser set a flag so we know
3506 that it came from T{} rather than T({}). */
3507 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
3508 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
3509 return build_functional_cast (input_location
, type
,
3510 compound_literal
, complain
);
3513 if (TREE_CODE (type
) == ARRAY_TYPE
3514 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
3515 return error_mark_node
;
3516 compound_literal
= reshape_init (type
, compound_literal
, complain
);
3517 if (SCALAR_TYPE_P (type
)
3518 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
)
3519 && !check_narrowing (type
, compound_literal
, complain
))
3520 return error_mark_node
;
3521 if (TREE_CODE (type
) == ARRAY_TYPE
3522 && TYPE_DOMAIN (type
) == NULL_TREE
)
3524 cp_complete_array_type_or_error (&type
, compound_literal
,
3526 if (type
== error_mark_node
)
3527 return error_mark_node
;
3529 compound_literal
= digest_init_flags (type
, compound_literal
,
3530 LOOKUP_NORMAL
| LOOKUP_NO_NARROWING
,
3532 if (compound_literal
== error_mark_node
)
3533 return error_mark_node
;
3535 /* If we're in a template, return the original compound literal. */
3539 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
3541 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
3542 if (fcl_context
== fcl_c99
)
3543 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
3546 /* Put static/constant array temporaries in static variables. */
3547 /* FIXME all C99 compound literals should be variables rather than C++
3548 temporaries, unless they are used as an aggregate initializer. */
3549 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
3550 && fcl_context
== fcl_c99
3551 && TREE_CODE (type
) == ARRAY_TYPE
3552 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
3553 && initializer_constant_valid_p (compound_literal
, type
))
3555 tree decl
= create_temporary_var (type
);
3556 DECL_CONTEXT (decl
) = NULL_TREE
;
3557 DECL_INITIAL (decl
) = compound_literal
;
3558 TREE_STATIC (decl
) = 1;
3559 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
3561 /* 5.19 says that a constant expression can include an
3562 lvalue-rvalue conversion applied to "a glvalue of literal type
3563 that refers to a non-volatile temporary object initialized
3564 with a constant expression". Rather than try to communicate
3565 that this VAR_DECL is a temporary, just mark it constexpr. */
3566 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
3567 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
3568 TREE_CONSTANT (decl
) = true;
3570 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
3571 decl
= pushdecl_top_level (decl
);
3572 DECL_NAME (decl
) = make_anon_name ();
3573 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
3574 /* Make sure the destructor is callable. */
3575 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
3576 if (clean
== error_mark_node
)
3577 return error_mark_node
;
3581 /* Represent other compound literals with TARGET_EXPR so we produce
3582 a prvalue, and can elide copies. */
3583 if (!VECTOR_TYPE_P (type
)
3584 && (TREE_CODE (compound_literal
) == CONSTRUCTOR
3585 || TREE_CODE (compound_literal
) == VEC_INIT_EXPR
))
3587 /* The CONSTRUCTOR is now an initializer, not a compound literal. */
3588 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
3589 TREE_HAS_CONSTRUCTOR (compound_literal
) = false;
3590 compound_literal
= get_target_expr (compound_literal
, complain
);
3593 /* For e.g. int{42} just make sure it's a prvalue. */
3594 compound_literal
= rvalue (compound_literal
);
3596 return compound_literal
;
3599 /* Return the declaration for the function-name variable indicated by
3603 finish_fname (tree id
)
3607 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
3608 if (processing_template_decl
&& current_function_decl
3609 && decl
!= error_mark_node
)
3610 decl
= DECL_NAME (decl
);
3614 /* Finish a translation unit. */
3617 finish_translation_unit (void)
3619 /* In case there were missing closebraces,
3620 get us back to the global binding level. */
3622 while (current_namespace
!= global_namespace
)
3625 /* Do file scope __FUNCTION__ et al. */
3626 finish_fname_decls ();
3628 if (vec_safe_length (scope_chain
->omp_declare_target_attribute
))
3630 cp_omp_declare_target_attr
3631 a
= scope_chain
->omp_declare_target_attribute
->pop ();
3633 error ("%qs without corresponding %qs",
3634 a
.device_type
>= 0 ? "#pragma omp begin declare target"
3635 : "#pragma omp declare target",
3636 "#pragma omp end declare target");
3637 vec_safe_truncate (scope_chain
->omp_declare_target_attribute
, 0);
3639 if (vec_safe_length (scope_chain
->omp_begin_assumes
))
3642 error ("%qs without corresponding %qs",
3643 "#pragma omp begin assumes", "#pragma omp end assumes");
3644 vec_safe_truncate (scope_chain
->omp_begin_assumes
, 0);
3648 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
3649 Returns the parameter. */
3652 finish_template_type_parm (tree aggr
, tree identifier
)
3654 if (aggr
!= class_type_node
)
3656 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
3657 aggr
= class_type_node
;
3660 return build_tree_list (aggr
, identifier
);
3663 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
3664 Returns the parameter. */
3667 finish_template_template_parm (tree aggr
, tree identifier
)
3669 tree decl
= build_decl (input_location
,
3670 TYPE_DECL
, identifier
, NULL_TREE
);
3672 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
3673 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
3674 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
3675 DECL_ARTIFICIAL (decl
) = 1;
3677 /* Associate the constraints with the underlying declaration,
3678 not the template. */
3679 tree constr
= current_template_constraints ();
3680 set_constraints (decl
, constr
);
3682 end_template_decl ();
3684 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
3686 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
3687 /*is_primary=*/true, /*is_partial=*/false,
3690 return finish_template_type_parm (aggr
, tmpl
);
3693 /* ARGUMENT is the default-argument value for a template template
3694 parameter. If ARGUMENT is invalid, issue error messages and return
3695 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
3698 check_template_template_default_arg (tree argument
)
3700 if (TREE_CODE (argument
) != TEMPLATE_DECL
3701 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
3702 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
3704 if (TREE_CODE (argument
) == TYPE_DECL
)
3706 if (tree t
= maybe_get_template_decl_from_type_decl (argument
))
3707 if (TREE_CODE (t
) == TEMPLATE_DECL
)
3709 error ("invalid use of type %qT as a default value for a template "
3710 "template-parameter", TREE_TYPE (argument
));
3713 error ("invalid default argument for a template template parameter");
3714 return error_mark_node
;
3720 /* Begin a class definition, as indicated by T. */
3723 begin_class_definition (tree t
)
3725 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
3726 return error_mark_node
;
3728 if (processing_template_parmlist
&& !LAMBDA_TYPE_P (t
))
3730 error ("definition of %q#T inside template parameter list", t
);
3731 return error_mark_node
;
3734 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
3735 are passed the same as decimal scalar types. */
3736 if (TREE_CODE (t
) == RECORD_TYPE
3737 && !processing_template_decl
)
3739 tree ns
= TYPE_CONTEXT (t
);
3740 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
3741 && DECL_CONTEXT (ns
) == std_node
3743 && id_equal (DECL_NAME (ns
), "decimal"))
3745 const char *n
= TYPE_NAME_STRING (t
);
3746 if ((strcmp (n
, "decimal32") == 0)
3747 || (strcmp (n
, "decimal64") == 0)
3748 || (strcmp (n
, "decimal128") == 0))
3749 TYPE_TRANSPARENT_AGGR (t
) = 1;
3753 /* A non-implicit typename comes from code like:
3755 template <typename T> struct A {
3756 template <typename U> struct A<T>::B ...
3758 This is erroneous. */
3759 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
3761 error ("invalid definition of qualified type %qT", t
);
3762 t
= error_mark_node
;
3765 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
3767 t
= make_class_type (RECORD_TYPE
);
3768 pushtag (make_anon_name (), t
);
3771 if (TYPE_BEING_DEFINED (t
))
3773 t
= make_class_type (TREE_CODE (t
));
3774 pushtag (TYPE_IDENTIFIER (t
), t
);
3779 if (!module_may_redeclare (TYPE_NAME (t
)))
3781 error ("cannot declare %qD in a different module", TYPE_NAME (t
));
3782 inform (DECL_SOURCE_LOCATION (TYPE_NAME (t
)), "declared here");
3783 return error_mark_node
;
3785 set_instantiating_module (TYPE_NAME (t
));
3786 set_defining_module (TYPE_NAME (t
));
3789 maybe_process_partial_specialization (t
);
3791 TYPE_BEING_DEFINED (t
) = 1;
3792 class_binding_level
->defining_class_p
= 1;
3794 if (flag_pack_struct
)
3797 TYPE_PACKED (t
) = 1;
3798 /* Even though the type is being defined for the first time
3799 here, there might have been a forward declaration, so there
3800 might be cv-qualified variants of T. */
3801 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
3802 TYPE_PACKED (v
) = 1;
3804 /* Reset the interface data, at the earliest possible
3805 moment, as it might have been set via a class foo;
3807 if (! TYPE_UNNAMED_P (t
))
3809 struct c_fileinfo
*finfo
= \
3810 get_fileinfo (LOCATION_FILE (input_location
));
3811 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
3812 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
3813 (t
, finfo
->interface_unknown
);
3815 reset_specialization ();
3817 /* Make a declaration for this class in its own scope. */
3818 build_self_reference ();
3823 /* Finish the member declaration given by DECL. */
3826 finish_member_declaration (tree decl
)
3828 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
3831 if (decl
== void_type_node
)
3832 /* The COMPONENT was a friend, not a member, and so there's
3833 nothing for us to do. */
3836 /* We should see only one DECL at a time. */
3837 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
3839 /* Don't add decls after definition. */
3840 gcc_assert (TYPE_BEING_DEFINED (current_class_type
)
3841 /* We can add lambda types when late parsing default
3843 || LAMBDA_TYPE_P (TREE_TYPE (decl
)));
3845 /* Set up access control for DECL. */
3847 = (current_access_specifier
== access_private_node
);
3848 TREE_PROTECTED (decl
)
3849 = (current_access_specifier
== access_protected_node
);
3850 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3852 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
3853 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
3856 /* Mark the DECL as a member of the current class, unless it's
3857 a member of an enumeration. */
3858 if (TREE_CODE (decl
) != CONST_DECL
)
3859 DECL_CONTEXT (decl
) = current_class_type
;
3861 /* Remember the single FIELD_DECL an anonymous aggregate type is used for. */
3862 if (TREE_CODE (decl
) == FIELD_DECL
3863 && ANON_AGGR_TYPE_P (TREE_TYPE (decl
)))
3865 gcc_assert (!ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl
))));
3866 ANON_AGGR_TYPE_FIELD (TYPE_MAIN_VARIANT (TREE_TYPE (decl
))) = decl
;
3869 if (TREE_CODE (decl
) == USING_DECL
)
3870 /* Avoid debug info for class-scope USING_DECLS for now, we'll
3871 call cp_emit_debug_info_for_using later. */
3872 DECL_IGNORED_P (decl
) = 1;
3874 /* Check for bare parameter packs in the non-static data member
3876 if (TREE_CODE (decl
) == FIELD_DECL
)
3878 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
3879 TREE_TYPE (decl
) = error_mark_node
;
3880 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3881 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3886 A C language linkage is ignored for the names of class members
3887 and the member function type of class member functions. */
3888 if (DECL_LANG_SPECIFIC (decl
))
3889 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3893 /* Functions and non-functions are added differently. */
3894 if (DECL_DECLARES_FUNCTION_P (decl
))
3895 add
= add_method (current_class_type
, decl
, false);
3896 /* Enter the DECL into the scope of the class, if the class
3897 isn't a closure (whose fields are supposed to be unnamed). */
3898 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3899 || maybe_push_used_methods (decl
)
3900 || pushdecl_class_level (decl
))
3905 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3906 go at the beginning. The reason is that
3907 legacy_nonfn_member_lookup searches the list in order, and we
3908 want a field name to override a type name so that the "struct
3909 stat hack" will work. In particular:
3911 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3915 if (TREE_CODE (decl
) == TYPE_DECL
)
3916 TYPE_FIELDS (current_class_type
)
3917 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3920 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3921 TYPE_FIELDS (current_class_type
) = decl
;
3924 maybe_add_class_template_decl_list (current_class_type
, decl
,
3929 /* Finish processing a complete template declaration. The PARMS are
3930 the template parameters. */
3933 finish_template_decl (tree parms
)
3936 end_template_decl ();
3938 end_specialization ();
3941 // Returns the template type of the class scope being entered. If we're
3942 // entering a constrained class scope. TYPE is the class template
3943 // scope being entered and we may need to match the intended type with
3944 // a constrained specialization. For example:
3946 // template<Object T>
3947 // struct S { void f(); }; #1
3949 // template<Object T>
3950 // void S<T>::f() { } #2
3952 // We check, in #2, that S<T> refers precisely to the type declared by
3953 // #1 (i.e., that the constraints match). Note that the following should
3954 // be an error since there is no specialization of S<T> that is
3955 // unconstrained, but this is not diagnosed here.
3957 // template<typename T>
3958 // void S<T>::f() { }
3960 // We cannot diagnose this problem here since this function also matches
3961 // qualified template names that are not part of a definition. For example:
3963 // template<Integral T, Floating_point U>
3964 // typename pair<T, U>::first_type void f(T, U);
3966 // Here, it is unlikely that there is a partial specialization of
3967 // pair constrained for Integral and Floating_point arguments.
3969 // The general rule is: if a constrained specialization with matching
3970 // constraints is found return that type. Also note that if TYPE is not a
3971 // class-type (e.g. a typename type), then no fixup is needed.
3974 fixup_template_type (tree type
)
3976 // Find the template parameter list at the a depth appropriate to
3977 // the scope we're trying to enter.
3978 tree parms
= current_template_parms
;
3979 int depth
= template_class_depth (type
);
3980 for (int n
= current_template_depth
; n
> depth
&& parms
; --n
)
3981 parms
= TREE_CHAIN (parms
);
3984 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3985 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3987 // Search for a specialization whose type and constraints match.
3988 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3989 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3992 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3994 // If the type and constraints match a specialization, then we
3995 // are entering that type.
3996 if (same_type_p (type
, TREE_TYPE (specs
))
3997 && equivalent_constraints (cur_constr
, spec_constr
))
3998 return TREE_TYPE (specs
);
3999 specs
= TREE_CHAIN (specs
);
4002 // If no specialization matches, then must return the type
4003 // previously found.
4007 /* Finish processing a template-id (which names a type) of the form
4008 NAME < ARGS >. Return the TYPE_DECL for the type named by the
4009 template-id. If ENTERING_SCOPE is nonzero we are about to enter
4010 the scope of template-id indicated. */
4013 finish_template_type (tree name
, tree args
, int entering_scope
)
4017 type
= lookup_template_class (name
, args
,
4018 NULL_TREE
, NULL_TREE
, entering_scope
,
4019 tf_warning_or_error
| tf_user
);
4021 /* If we might be entering the scope of a partial specialization,
4022 find the one with the right constraints. */
4025 && CLASS_TYPE_P (type
)
4026 && CLASSTYPE_TEMPLATE_INFO (type
)
4027 && dependent_type_p (type
)
4028 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
4029 type
= fixup_template_type (type
);
4031 if (type
== error_mark_node
)
4033 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
4034 return TYPE_STUB_DECL (type
);
4036 return TYPE_NAME (type
);
4039 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
4040 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
4041 BASE_CLASS, or NULL_TREE if an error occurred. The
4042 ACCESS_SPECIFIER is one of
4043 access_{default,public,protected_private}_node. For a virtual base
4044 we set TREE_TYPE. */
4047 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
4051 if (base
== error_mark_node
)
4053 error ("invalid base-class specification");
4056 else if (! MAYBE_CLASS_TYPE_P (base
))
4058 error ("%qT is not a class type", base
);
4063 if (cp_type_quals (base
) != 0)
4065 /* DR 484: Can a base-specifier name a cv-qualified
4067 base
= TYPE_MAIN_VARIANT (base
);
4069 result
= build_tree_list (access
, base
);
4071 TREE_TYPE (result
) = integer_type_node
;
4077 /* If FNS is a member function, a set of member functions, or a
4078 template-id referring to one or more member functions, return a
4079 BASELINK for FNS, incorporating the current access context.
4080 Otherwise, return FNS unchanged. */
4083 baselink_for_fns (tree fns
)
4088 if (BASELINK_P (fns
)
4089 || error_operand_p (fns
))
4092 scope
= ovl_scope (fns
);
4093 if (!CLASS_TYPE_P (scope
))
4096 cl
= currently_open_derived_class (scope
);
4099 tree access_path
= TYPE_BINFO (cl
);
4100 tree conv_path
= (cl
== scope
? access_path
4101 : lookup_base (cl
, scope
, ba_any
, NULL
, tf_none
));
4102 return build_baselink (conv_path
, access_path
, fns
, /*optype=*/NULL_TREE
);
4105 /* Returns true iff DECL is a variable from a function outside
4109 outer_var_p (tree decl
)
4111 /* These should have been stripped or otherwise handled by the caller. */
4112 gcc_checking_assert (!REFERENCE_REF_P (decl
));
4114 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
4115 && DECL_FUNCTION_SCOPE_P (decl
)
4116 /* Don't get confused by temporaries. */
4118 && (DECL_CONTEXT (decl
) != current_function_decl
4119 || parsing_nsdmi ()));
4122 /* As above, but also checks that DECL is automatic. */
4125 outer_automatic_var_p (tree decl
)
4127 return (outer_var_p (decl
)
4128 && !TREE_STATIC (decl
));
4131 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
4132 rewrite it for lambda capture.
4134 If ODR_USE is true, we're being called from mark_use, and we complain about
4135 use of constant variables. If ODR_USE is false, we're being called for the
4136 id-expression, and we do lambda capture. */
4139 process_outer_var_ref (tree decl
, tsubst_flags_t complain
, bool odr_use
)
4141 if (cp_unevaluated_operand
)
4143 tree type
= TREE_TYPE (decl
);
4144 if (!dependent_type_p (type
)
4145 && variably_modified_type_p (type
, NULL_TREE
))
4146 /* VLAs are used even in unevaluated context. */;
4148 /* It's not a use (3.2) if we're in an unevaluated context. */
4151 if (decl
== error_mark_node
)
4154 tree context
= DECL_CONTEXT (decl
);
4155 tree containing_function
= current_function_decl
;
4156 tree lambda_stack
= NULL_TREE
;
4157 tree lambda_expr
= NULL_TREE
;
4158 tree initializer
= convert_from_reference (decl
);
4160 /* Mark it as used now even if the use is ill-formed. */
4161 if (!mark_used (decl
, complain
))
4162 return error_mark_node
;
4164 if (parsing_nsdmi ())
4165 containing_function
= NULL_TREE
;
4167 if (containing_function
&& LAMBDA_FUNCTION_P (containing_function
))
4169 /* Check whether we've already built a proxy. */
4171 while (is_normal_capture_proxy (var
))
4172 var
= DECL_CAPTURED_VARIABLE (var
);
4173 tree d
= retrieve_local_specialization (var
);
4175 if (d
&& d
!= decl
&& is_capture_proxy (d
))
4177 if (DECL_CONTEXT (d
) == containing_function
)
4178 /* We already have an inner proxy. */
4181 /* We need to capture an outer proxy. */
4182 return process_outer_var_ref (d
, complain
, odr_use
);
4186 /* If we are in a lambda function, we can move out until we hit
4188 2. a non-lambda function, or
4189 3. a non-default capturing lambda function. */
4190 while (context
!= containing_function
4191 /* containing_function can be null with invalid generic lambdas. */
4192 && containing_function
4193 && LAMBDA_FUNCTION_P (containing_function
))
4195 tree closure
= DECL_CONTEXT (containing_function
);
4196 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
4198 if (TYPE_CLASS_SCOPE_P (closure
))
4199 /* A lambda in an NSDMI (c++/64496). */
4202 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
4205 lambda_stack
= tree_cons (NULL_TREE
, lambda_expr
, lambda_stack
);
4207 containing_function
= decl_function_context (containing_function
);
4210 /* In a lambda within a template, wait until instantiation time to implicitly
4211 capture a parameter pack. We want to wait because we don't know if we're
4212 capturing the whole pack or a single element, and it's OK to wait because
4213 find_parameter_packs_r walks into the lambda body. */
4214 if (context
== containing_function
4215 && DECL_PACK_P (decl
))
4218 if (lambda_expr
&& VAR_P (decl
) && DECL_ANON_UNION_VAR_P (decl
))
4220 if (complain
& tf_error
)
4221 error ("cannot capture member %qD of anonymous union", decl
);
4222 return error_mark_node
;
4224 /* Do lambda capture when processing the id-expression, not when
4225 odr-using a variable. */
4226 if (!odr_use
&& context
== containing_function
)
4227 decl
= add_default_capture (lambda_stack
,
4228 /*id=*/DECL_NAME (decl
), initializer
);
4229 /* Only an odr-use of an outer automatic variable causes an
4230 error, and a constant variable can decay to a prvalue
4231 constant without odr-use. So don't complain yet. */
4232 else if (!odr_use
&& decl_constant_var_p (decl
))
4234 else if (lambda_expr
)
4236 if (complain
& tf_error
)
4238 error ("%qD is not captured", decl
);
4239 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
4240 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
4241 inform (location_of (closure
),
4242 "the lambda has no capture-default");
4243 else if (TYPE_CLASS_SCOPE_P (closure
))
4244 inform (UNKNOWN_LOCATION
, "lambda in local class %q+T cannot "
4245 "capture variables from the enclosing context",
4246 TYPE_CONTEXT (closure
));
4247 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
4249 return error_mark_node
;
4251 else if (processing_contract_condition
&& (TREE_CODE (decl
) == PARM_DECL
))
4252 /* Use of a parameter in a contract condition is fine. */
4256 if (complain
& tf_error
)
4259 ? G_("use of local variable with automatic storage from "
4260 "containing function")
4261 : G_("use of parameter from containing function"));
4262 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
4264 return error_mark_node
;
4269 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
4270 id-expression. (See cp_parser_id_expression for details.) SCOPE,
4271 if non-NULL, is the type or namespace used to explicitly qualify
4272 ID_EXPRESSION. DECL is the entity to which that name has been
4275 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
4276 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
4277 be set to true if this expression isn't permitted in a
4278 constant-expression, but it is otherwise not set by this function.
4279 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
4280 constant-expression, but a non-constant expression is also
4283 DONE is true if this expression is a complete postfix-expression;
4284 it is false if this expression is followed by '->', '[', '(', etc.
4285 ADDRESS_P is true iff this expression is the operand of '&'.
4286 TEMPLATE_P is true iff the qualified-id was of the form
4287 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
4288 appears as a template argument.
4290 If an error occurs, and it is the kind of error that might cause
4291 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
4292 is the caller's responsibility to issue the message. *ERROR_MSG
4293 will be a string with static storage duration, so the caller need
4296 Return an expression for the entity, after issuing appropriate
4297 diagnostics. This function is also responsible for transforming a
4298 reference to a non-static member into a COMPONENT_REF that makes
4299 the use of "this" explicit.
4301 Upon return, *IDK will be filled in appropriately. */
4303 finish_id_expression_1 (tree id_expression
,
4307 bool integral_constant_expression_p
,
4308 bool allow_non_integral_constant_expression_p
,
4309 bool *non_integral_constant_expression_p
,
4313 bool template_arg_p
,
4314 const char **error_msg
,
4315 location_t location
)
4317 decl
= strip_using_decl (decl
);
4319 /* Initialize the output parameters. */
4320 *idk
= CP_ID_KIND_NONE
;
4323 if (id_expression
== error_mark_node
)
4324 return error_mark_node
;
4325 /* If we have a template-id, then no further lookup is
4326 required. If the template-id was for a template-class, we
4327 will sometimes have a TYPE_DECL at this point. */
4328 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
4329 || TREE_CODE (decl
) == TYPE_DECL
)
4331 /* Look up the name. */
4334 if (decl
== error_mark_node
)
4336 /* Name lookup failed. */
4339 || (!dependent_type_p (scope
)
4340 && !(identifier_p (id_expression
)
4341 && IDENTIFIER_CONV_OP_P (id_expression
)
4342 && dependent_type_p (TREE_TYPE (id_expression
))))))
4344 /* If the qualifying type is non-dependent (and the name
4345 does not name a conversion operator to a dependent
4346 type), issue an error. */
4347 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
4348 return error_mark_node
;
4352 /* It may be resolved via Koenig lookup. */
4353 *idk
= CP_ID_KIND_UNQUALIFIED
;
4354 return id_expression
;
4357 decl
= id_expression
;
4360 /* Remember that the name was used in the definition of
4361 the current class so that we can check later to see if
4362 the meaning would have been different after the class
4363 was entirely defined. */
4364 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
4365 maybe_note_name_used_in_class (id_expression
, decl
);
4367 /* A use in unevaluated operand might not be instantiated appropriately
4368 if tsubst_copy builds a dummy parm, or if we never instantiate a
4369 generic lambda, so mark it now. */
4370 if (processing_template_decl
&& cp_unevaluated_operand
)
4371 mark_type_use (decl
);
4373 /* Disallow uses of local variables from containing functions, except
4374 within lambda-expressions. */
4375 if (outer_automatic_var_p (decl
))
4377 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
4378 if (decl
== error_mark_node
)
4379 return error_mark_node
;
4382 /* Also disallow uses of function parameters outside the function
4383 body, except inside an unevaluated context (i.e. decltype). */
4384 if (TREE_CODE (decl
) == PARM_DECL
4385 && DECL_CONTEXT (decl
) == NULL_TREE
4386 && !cp_unevaluated_operand
4387 && !processing_contract_condition
)
4389 *error_msg
= G_("use of parameter outside function body");
4390 return error_mark_node
;
4394 /* If we didn't find anything, or what we found was a type,
4395 then this wasn't really an id-expression. */
4396 if (TREE_CODE (decl
) == TEMPLATE_DECL
4397 && !DECL_FUNCTION_TEMPLATE_P (decl
))
4399 *error_msg
= G_("missing template arguments");
4400 return error_mark_node
;
4402 else if (TREE_CODE (decl
) == TYPE_DECL
4403 || TREE_CODE (decl
) == NAMESPACE_DECL
)
4405 *error_msg
= G_("expected primary-expression");
4406 return error_mark_node
;
4409 /* If the name resolved to a template parameter, there is no
4410 need to look it up again later. */
4411 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
4412 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
4416 *idk
= CP_ID_KIND_NONE
;
4417 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
4418 decl
= TEMPLATE_PARM_DECL (decl
);
4419 r
= DECL_INITIAL (decl
);
4420 if (CLASS_TYPE_P (TREE_TYPE (r
)) && !CP_TYPE_CONST_P (TREE_TYPE (r
)))
4422 /* If the entity is a template parameter object for a template
4423 parameter of type T, the type of the expression is const T. */
4424 tree ctype
= TREE_TYPE (r
);
4425 ctype
= cp_build_qualified_type (ctype
, (cp_type_quals (ctype
)
4426 | TYPE_QUAL_CONST
));
4427 r
= build1 (VIEW_CONVERT_EXPR
, ctype
, r
);
4429 r
= convert_from_reference (r
);
4430 if (integral_constant_expression_p
4431 && !dependent_type_p (TREE_TYPE (decl
))
4432 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
4434 if (!allow_non_integral_constant_expression_p
)
4435 error ("template parameter %qD of type %qT is not allowed in "
4436 "an integral constant expression because it is not of "
4437 "integral or enumeration type", decl
, TREE_TYPE (decl
));
4438 *non_integral_constant_expression_p
= true;
4442 else if (TREE_CODE (decl
) == UNBOUND_CLASS_TEMPLATE
)
4444 gcc_checking_assert (scope
);
4445 *idk
= CP_ID_KIND_QUALIFIED
;
4446 cp_warn_deprecated_use_scopes (scope
);
4447 decl
= finish_qualified_id_expr (scope
, decl
, done
, address_p
,
4448 template_p
, template_arg_p
,
4449 tf_warning_or_error
);
4453 if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
4454 && variable_template_p (TREE_OPERAND (decl
, 0))
4455 && !concept_check_p (decl
))
4456 /* Try resolving this variable TEMPLATE_ID_EXPR (which is always
4457 considered type-dependent) now, so that the dependence test that
4458 follows gives us the right answer: if it represents a non-dependent
4459 variable template-id then finish_template_variable will yield the
4460 corresponding non-dependent VAR_DECL. */
4461 decl
= finish_template_variable (decl
);
4463 bool dependent_p
= type_dependent_expression_p (decl
);
4465 /* If the declaration was explicitly qualified indicate
4466 that. The semantics of `A::f(3)' are different than
4467 `f(3)' if `f' is virtual. */
4469 ? CP_ID_KIND_QUALIFIED
4470 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
4471 ? CP_ID_KIND_TEMPLATE_ID
4473 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4474 : CP_ID_KIND_UNQUALIFIED
)));
4479 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
4480 /* Dependent type attributes on the decl mean that the TREE_TYPE is
4481 wrong, so just return the identifier. */
4482 return id_expression
;
4484 if (DECL_CLASS_TEMPLATE_P (decl
))
4486 error ("use of class template %qT as expression", decl
);
4487 return error_mark_node
;
4490 if (TREE_CODE (decl
) == TREE_LIST
)
4492 /* Ambiguous reference to base members. */
4493 error ("request for member %qD is ambiguous in "
4494 "multiple inheritance lattice", id_expression
);
4495 print_candidates (decl
);
4496 return error_mark_node
;
4499 /* Mark variable-like entities as used. Functions are similarly
4500 marked either below or after overload resolution. */
4502 || TREE_CODE (decl
) == PARM_DECL
4503 || TREE_CODE (decl
) == CONST_DECL
4504 || TREE_CODE (decl
) == RESULT_DECL
)
4505 && !mark_used (decl
))
4506 return error_mark_node
;
4508 /* Only certain kinds of names are allowed in constant
4509 expression. Template parameters have already
4510 been handled above. */
4511 if (! error_operand_p (decl
)
4513 && integral_constant_expression_p
4514 && !decl_constant_var_p (decl
)
4515 && TREE_CODE (decl
) != CONST_DECL
4516 && !builtin_valid_in_constant_expr_p (decl
)
4517 && !concept_check_p (decl
))
4519 if (!allow_non_integral_constant_expression_p
)
4521 error ("%qD cannot appear in a constant-expression", decl
);
4522 return error_mark_node
;
4524 *non_integral_constant_expression_p
= true;
4527 if (tree wrap
= maybe_get_tls_wrapper_call (decl
))
4528 /* Replace an evaluated use of the thread_local variable with
4529 a call to its wrapper. */
4531 else if (concept_check_p (decl
))
4533 /* Nothing more to do. All of the analysis for concept checks
4534 is done by build_conept_id, called from the parser. */
4538 if (TREE_CODE (decl
) == SCOPE_REF
)
4540 gcc_assert (same_type_p (scope
, TREE_OPERAND (decl
, 0)));
4541 decl
= TREE_OPERAND (decl
, 1);
4544 decl
= (adjust_result_of_qualified_name_lookup
4545 (decl
, scope
, current_nonlambda_class_type()));
4547 cp_warn_deprecated_use_scopes (scope
);
4550 decl
= finish_qualified_id_expr (scope
,
4556 tf_warning_or_error
);
4558 decl
= convert_from_reference (decl
);
4560 else if (TREE_CODE (decl
) == FIELD_DECL
)
4562 /* Since SCOPE is NULL here, this is an unqualified name.
4563 Access checking has been performed during name lookup
4564 already. Turn off checking to avoid duplicate errors. */
4565 push_deferring_access_checks (dk_no_check
);
4566 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
4567 /*qualifying_scope=*/NULL_TREE
);
4568 pop_deferring_access_checks ();
4570 else if (is_overloaded_fn (decl
))
4572 /* We only need to look at the first function,
4573 because all the fns share the attribute we're
4574 concerned with (all member fns or all non-members). */
4575 tree first_fn
= get_first_fn (decl
);
4576 first_fn
= STRIP_TEMPLATE (first_fn
);
4579 && (TREE_CODE (first_fn
) == USING_DECL
4580 || (TREE_CODE (first_fn
) == FUNCTION_DECL
4581 && DECL_FUNCTION_MEMBER_P (first_fn
)
4582 && !shared_member_p (decl
))))
4584 /* A set of member functions. */
4585 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
4586 return finish_class_member_access_expr (decl
, id_expression
,
4587 /*template_p=*/false,
4588 tf_warning_or_error
);
4591 decl
= baselink_for_fns (decl
);
4595 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
4596 && DECL_CLASS_SCOPE_P (decl
))
4598 tree context
= context_for_name_lookup (decl
);
4599 if (context
!= current_class_type
)
4601 tree path
= currently_open_derived_class (context
);
4603 /* PATH can be null for using an enum of an unrelated
4604 class; we checked its access in lookup_using_decl.
4606 ??? Should this case make a clone instead, like
4607 handle_using_decl? */
4608 gcc_assert (TREE_CODE (decl
) == CONST_DECL
);
4610 perform_or_defer_access_check (TYPE_BINFO (path
),
4612 tf_warning_or_error
);
4616 decl
= convert_from_reference (decl
);
4620 return cp_expr (decl
, location
);
4623 /* As per finish_id_expression_1, but adding a wrapper node
4624 around the result if needed to express LOCATION. */
4627 finish_id_expression (tree id_expression
,
4631 bool integral_constant_expression_p
,
4632 bool allow_non_integral_constant_expression_p
,
4633 bool *non_integral_constant_expression_p
,
4637 bool template_arg_p
,
4638 const char **error_msg
,
4639 location_t location
)
4642 = finish_id_expression_1 (id_expression
, decl
, scope
, idk
,
4643 integral_constant_expression_p
,
4644 allow_non_integral_constant_expression_p
,
4645 non_integral_constant_expression_p
,
4646 template_p
, done
, address_p
, template_arg_p
,
4647 error_msg
, location
);
4648 return result
.maybe_add_location_wrapper ();
4651 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
4652 use as a type-specifier. */
4655 finish_typeof (tree expr
)
4659 if (type_dependent_expression_p (expr
))
4661 type
= cxx_make_type (TYPEOF_TYPE
);
4662 TYPEOF_TYPE_EXPR (type
) = expr
;
4663 SET_TYPE_STRUCTURAL_EQUALITY (type
);
4668 expr
= mark_type_use (expr
);
4670 type
= unlowered_expr_type (expr
);
4672 if (!type
|| type
== unknown_type_node
)
4674 error ("type of %qE is unknown", expr
);
4675 return error_mark_node
;
4681 /* Implement the __underlying_type keyword: Return the underlying
4682 type of TYPE, suitable for use as a type-specifier. */
4685 finish_underlying_type (tree type
)
4687 if (!complete_type_or_else (type
, NULL_TREE
))
4688 return error_mark_node
;
4690 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
4692 error ("%qT is not an enumeration type", type
);
4693 return error_mark_node
;
4696 tree underlying_type
= ENUM_UNDERLYING_TYPE (type
);
4698 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
4699 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
4700 See finish_enum_value_list for details. */
4701 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
4703 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
4704 TYPE_UNSIGNED (underlying_type
));
4706 return underlying_type
;
4709 /* Implement the __type_pack_element keyword: Return the type
4710 at index IDX within TYPES. */
4713 finish_type_pack_element (tree idx
, tree types
, tsubst_flags_t complain
)
4715 idx
= maybe_constant_value (idx
);
4716 if (TREE_CODE (idx
) != INTEGER_CST
|| !INTEGRAL_TYPE_P (TREE_TYPE (idx
)))
4718 if (complain
& tf_error
)
4719 error ("%<__type_pack_element%> index is not an integral constant");
4720 return error_mark_node
;
4722 if (tree_int_cst_sgn (idx
) < 0)
4724 if (complain
& tf_error
)
4725 error ("%<__type_pack_element%> index is negative");
4726 return error_mark_node
;
4728 if (wi::to_widest (idx
) >= TREE_VEC_LENGTH (types
))
4730 if (complain
& tf_error
)
4731 error ("%<__type_pack_element%> index is out of range");
4732 return error_mark_node
;
4734 return TREE_VEC_ELT (types
, tree_to_shwi (idx
));
4737 /* Implement the __direct_bases keyword: Return the direct base classes
4741 calculate_direct_bases (tree type
, tsubst_flags_t complain
)
4743 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4744 || !NON_UNION_CLASS_TYPE_P (type
))
4745 return make_tree_vec (0);
4747 releasing_vec vector
;
4748 vec
<tree
, va_gc
> *base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
4752 /* Virtual bases are initialized first */
4753 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4754 if (BINFO_VIRTUAL_P (binfo
))
4755 vec_safe_push (vector
, binfo
);
4757 /* Now non-virtuals */
4758 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4759 if (!BINFO_VIRTUAL_P (binfo
))
4760 vec_safe_push (vector
, binfo
);
4762 tree bases_vec
= make_tree_vec (vector
->length ());
4764 for (i
= 0; i
< vector
->length (); ++i
)
4765 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
4770 /* Implement the __bases keyword: Return the base classes
4773 /* Find morally non-virtual base classes by walking binfo hierarchy */
4774 /* Virtual base classes are handled separately in finish_bases */
4777 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
4779 /* Don't walk bases of virtual bases */
4780 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
4784 dfs_calculate_bases_post (tree binfo
, void *data_
)
4786 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
4787 if (!BINFO_VIRTUAL_P (binfo
))
4788 vec_safe_push (*data
, BINFO_TYPE (binfo
));
4792 /* Calculates the morally non-virtual base classes of a class */
4793 static vec
<tree
, va_gc
> *
4794 calculate_bases_helper (tree type
)
4796 vec
<tree
, va_gc
> *vector
= make_tree_vector ();
4798 /* Now add non-virtual base classes in order of construction */
4799 if (TYPE_BINFO (type
))
4800 dfs_walk_all (TYPE_BINFO (type
),
4801 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
4806 calculate_bases (tree type
, tsubst_flags_t complain
)
4808 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4809 || !NON_UNION_CLASS_TYPE_P (type
))
4810 return make_tree_vec (0);
4812 releasing_vec vector
;
4813 tree bases_vec
= NULL_TREE
;
4815 vec
<tree
, va_gc
> *vbases
;
4818 /* First go through virtual base classes */
4819 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
4820 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
4822 releasing_vec vbase_bases
4823 = calculate_bases_helper (BINFO_TYPE (binfo
));
4824 vec_safe_splice (vector
, vbase_bases
);
4827 /* Now for the non-virtual bases */
4828 releasing_vec nonvbases
= calculate_bases_helper (type
);
4829 vec_safe_splice (vector
, nonvbases
);
4831 /* Note that during error recovery vector->length can even be zero. */
4832 if (vector
->length () > 1)
4834 /* Last element is entire class, so don't copy */
4835 bases_vec
= make_tree_vec (vector
->length () - 1);
4837 for (i
= 0; i
< vector
->length () - 1; ++i
)
4838 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
4841 bases_vec
= make_tree_vec (0);
4847 finish_bases (tree type
, bool direct
)
4849 tree bases
= NULL_TREE
;
4851 if (!processing_template_decl
)
4853 /* Parameter packs can only be used in templates */
4854 error ("parameter pack %<__bases%> only valid in template declaration");
4855 return error_mark_node
;
4858 bases
= cxx_make_type (BASES
);
4859 BASES_TYPE (bases
) = type
;
4860 BASES_DIRECT (bases
) = direct
;
4861 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
4866 /* Perform C++-specific checks for __builtin_offsetof before calling
4870 finish_offsetof (tree object_ptr
, tree expr
, location_t loc
)
4872 /* If we're processing a template, we can't finish the semantics yet.
4873 Otherwise we can fold the entire expression now. */
4874 if (processing_template_decl
)
4876 expr
= build2 (OFFSETOF_EXPR
, size_type_node
, expr
, object_ptr
);
4877 SET_EXPR_LOCATION (expr
, loc
);
4881 if (expr
== error_mark_node
)
4882 return error_mark_node
;
4884 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4886 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4887 TREE_OPERAND (expr
, 2));
4888 return error_mark_node
;
4890 if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr
))
4891 || TREE_TYPE (expr
) == unknown_type_node
)
4893 while (TREE_CODE (expr
) == COMPONENT_REF
4894 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4895 expr
= TREE_OPERAND (expr
, 1);
4899 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4900 inform (DECL_SOURCE_LOCATION (expr
), "declared here");
4903 error ("cannot apply %<offsetof%> to member function");
4904 return error_mark_node
;
4906 if (TREE_CODE (expr
) == CONST_DECL
)
4908 error ("cannot apply %<offsetof%> to an enumerator %qD", expr
);
4909 return error_mark_node
;
4911 if (REFERENCE_REF_P (expr
))
4912 expr
= TREE_OPERAND (expr
, 0);
4913 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr
)), object_ptr
))
4914 return error_mark_node
;
4915 if (warn_invalid_offsetof
4916 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr
)))
4917 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr
)))
4918 && cp_unevaluated_operand
== 0)
4919 warning_at (loc
, OPT_Winvalid_offsetof
, "%<offsetof%> within "
4920 "non-standard-layout type %qT is conditionally-supported",
4921 TREE_TYPE (TREE_TYPE (object_ptr
)));
4922 return fold_offsetof (expr
);
4925 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4926 function is broken out from the above for the benefit of the tree-ssa
4930 simplify_aggr_init_expr (tree
*tp
)
4932 tree aggr_init_expr
= *tp
;
4934 /* Form an appropriate CALL_EXPR. */
4935 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4936 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4937 tree type
= TREE_TYPE (slot
);
4940 enum style_t
{ ctor
, arg
, pcc
} style
;
4942 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4944 #ifdef PCC_STATIC_STRUCT_RETURN
4950 gcc_assert (TREE_ADDRESSABLE (type
));
4954 call_expr
= build_call_array_loc (input_location
,
4955 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4957 aggr_init_expr_nargs (aggr_init_expr
),
4958 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4959 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4960 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4961 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4962 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4963 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4964 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4968 /* Replace the first argument to the ctor with the address of the
4970 cxx_mark_addressable (slot
);
4971 CALL_EXPR_ARG (call_expr
, 0) =
4972 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4974 else if (style
== arg
)
4976 /* Just mark it addressable here, and leave the rest to
4977 expand_call{,_inline}. */
4978 cxx_mark_addressable (slot
);
4979 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4980 call_expr
= cp_build_init_expr (slot
, call_expr
);
4982 else if (style
== pcc
)
4984 /* If we're using the non-reentrant PCC calling convention, then we
4985 need to copy the returned value out of the static buffer into the
4987 push_deferring_access_checks (dk_no_check
);
4988 call_expr
= build_aggr_init (slot
, call_expr
,
4989 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4990 tf_warning_or_error
);
4991 pop_deferring_access_checks ();
4992 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4995 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4997 tree init
= build_zero_init (type
, NULL_TREE
,
4998 /*static_storage_p=*/false);
4999 init
= cp_build_init_expr (slot
, init
);
5000 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
5007 /* Emit all thunks to FN that should be emitted when FN is emitted. */
5010 emit_associated_thunks (tree fn
)
5012 /* When we use vcall offsets, we emit thunks with the virtual
5013 functions to which they thunk. The whole point of vcall offsets
5014 is so that you can know statically the entire set of thunks that
5015 will ever be needed for a given virtual function, thereby
5016 enabling you to output all the thunks with the function itself. */
5017 if (DECL_VIRTUAL_P (fn
)
5018 /* Do not emit thunks for extern template instantiations. */
5019 && ! DECL_REALLY_EXTERN (fn
))
5023 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
5025 if (!THUNK_ALIAS (thunk
))
5027 use_thunk (thunk
, /*emit_p=*/1);
5028 if (DECL_RESULT_THUNK_P (thunk
))
5032 for (probe
= DECL_THUNKS (thunk
);
5033 probe
; probe
= DECL_CHAIN (probe
))
5034 use_thunk (probe
, /*emit_p=*/1);
5038 gcc_assert (!DECL_THUNKS (thunk
));
5043 /* Generate RTL for FN. */
5046 expand_or_defer_fn_1 (tree fn
)
5048 /* When the parser calls us after finishing the body of a template
5049 function, we don't really want to expand the body. */
5050 if (processing_template_decl
)
5052 /* Normally, collection only occurs in rest_of_compilation. So,
5053 if we don't collect here, we never collect junk generated
5054 during the processing of templates until we hit a
5055 non-template function. It's not safe to do this inside a
5056 nested class, though, as the parser may have local state that
5057 is not a GC root. */
5058 if (!function_depth
)
5063 gcc_assert (DECL_SAVED_TREE (fn
));
5065 /* We make a decision about linkage for these functions at the end
5066 of the compilation. Until that point, we do not want the back
5067 end to output them -- but we do want it to see the bodies of
5068 these functions so that it can inline them as appropriate. */
5069 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
5071 if (DECL_INTERFACE_KNOWN (fn
))
5072 /* We've already made a decision as to how this function will
5075 || DECL_IMMEDIATE_FUNCTION_P (fn
)
5076 || DECL_OMP_DECLARE_REDUCTION_P (fn
))
5077 tentative_decl_linkage (fn
);
5079 import_export_decl (fn
);
5081 /* If the user wants us to keep all inline functions, then mark
5082 this function as needed so that finish_file will make sure to
5083 output it later. Similarly, all dllexport'd functions must
5084 be emitted; there may be callers in other DLLs. */
5085 if (DECL_DECLARED_INLINE_P (fn
)
5086 && !DECL_REALLY_EXTERN (fn
)
5087 && !DECL_IMMEDIATE_FUNCTION_P (fn
)
5088 && !DECL_OMP_DECLARE_REDUCTION_P (fn
)
5089 && (flag_keep_inline_functions
5090 || (flag_keep_inline_dllexport
5091 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
5094 DECL_EXTERNAL (fn
) = 0;
5098 /* If this is a constructor or destructor body, we have to clone
5100 if (maybe_clone_body (fn
))
5102 /* We don't want to process FN again, so pretend we've written
5103 it out, even though we haven't. */
5104 TREE_ASM_WRITTEN (fn
) = 1;
5105 /* If this is a constexpr function we still need the body to be
5106 able to evaluate it. Similarly, with modules we only stream
5107 the maybe-in-charge cdtor and regenerate the clones from it on
5108 demand, so we also need to keep the body. Otherwise we don't
5110 if (!DECL_DECLARED_CONSTEXPR_P (fn
)
5111 && !(modules_p () && vague_linkage_p (fn
)))
5112 DECL_SAVED_TREE (fn
) = NULL_TREE
;
5116 /* There's no reason to do any of the work here if we're only doing
5117 semantic analysis; this code just generates RTL. */
5118 if (flag_syntax_only
)
5120 /* Pretend that this function has been written out so that we don't try
5121 to expand it again. */
5122 TREE_ASM_WRITTEN (fn
) = 1;
5126 if (DECL_OMP_DECLARE_REDUCTION_P (fn
))
5133 expand_or_defer_fn (tree fn
)
5135 if (expand_or_defer_fn_1 (fn
))
5139 /* Expand or defer, at the whim of the compilation unit manager. */
5140 cgraph_node::finalize_function (fn
, function_depth
> 1);
5141 emit_associated_thunks (fn
);
5145 if (DECL_IMMEDIATE_FUNCTION_P (fn
))
5147 if (cgraph_node
*node
= cgraph_node::get (fn
))
5149 node
->body_removed
= true;
5150 node
->analyzed
= false;
5151 node
->definition
= false;
5152 node
->force_output
= false;
5161 nrv_data () : visited (37) {}
5165 hash_set
<tree
> visited
;
5167 bool in_nrv_cleanup
;
5170 /* Helper function for walk_tree, used by finalize_nrv below. */
5173 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
5175 class nrv_data
*dp
= (class nrv_data
*)data
;
5177 /* No need to walk into types. There wouldn't be any need to walk into
5178 non-statements, except that we have to consider STMT_EXPRs. */
5182 /* Replace all uses of the NRV with the RESULT_DECL. */
5183 else if (*tp
== dp
->var
)
5186 /* Avoid walking into the same tree more than once. Unfortunately, we
5187 can't just use walk_tree_without duplicates because it would only call
5188 us for the first occurrence of dp->var in the function body. */
5189 else if (dp
->visited
.add (*tp
))
5192 /* If there's a label, we might need to destroy the NRV on goto (92407). */
5193 else if (TREE_CODE (*tp
) == LABEL_EXPR
&& !dp
->in_nrv_cleanup
)
5195 /* Change NRV returns to just refer to the RESULT_DECL; this is a nop,
5196 but differs from using NULL_TREE in that it indicates that we care
5197 about the value of the RESULT_DECL. But preserve anything appended
5198 by check_return_expr. */
5199 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
5201 tree
*p
= &TREE_OPERAND (*tp
, 0);
5202 while (TREE_CODE (*p
) == COMPOUND_EXPR
)
5203 p
= &TREE_OPERAND (*p
, 0);
5204 if (TREE_CODE (*p
) == INIT_EXPR
5205 && INIT_EXPR_NRV_P (*p
))
5208 /* Change all cleanups for the NRV to only run when not returning. */
5209 else if (TREE_CODE (*tp
) == CLEANUP_STMT
5210 && CLEANUP_DECL (*tp
) == dp
->var
)
5212 dp
->in_nrv_cleanup
= true;
5213 cp_walk_tree (&CLEANUP_BODY (*tp
), finalize_nrv_r
, data
, 0);
5214 dp
->in_nrv_cleanup
= false;
5215 cp_walk_tree (&CLEANUP_EXPR (*tp
), finalize_nrv_r
, data
, 0);
5219 /* For a simple NRV, just run it on the EH path. */
5220 CLEANUP_EH_ONLY (*tp
) = true;
5223 /* Not simple, we need to check current_retval_sentinel to decide
5224 whether to run it. If it's set, we're returning normally and
5225 don't want to destroy the NRV. If the sentinel is not set, we're
5226 leaving scope some other way, either by flowing off the end of its
5227 scope or throwing an exception. */
5228 tree cond
= build3 (COND_EXPR
, void_type_node
,
5229 current_retval_sentinel
,
5230 void_node
, CLEANUP_EXPR (*tp
));
5231 CLEANUP_EXPR (*tp
) = cond
;
5234 /* If a cleanup might throw, we need to clear current_retval_sentinel on
5235 the exception path, both so the check above succeeds and so an outer
5236 cleanup added by maybe_splice_retval_cleanup doesn't run. */
5237 if (cp_function_chain
->throwing_cleanup
)
5239 tree clear
= build2 (MODIFY_EXPR
, boolean_type_node
,
5240 current_retval_sentinel
,
5241 boolean_false_node
);
5244 /* We're already only on the EH path, just prepend it. */
5245 tree
&exp
= CLEANUP_EXPR (*tp
);
5246 exp
= build2 (COMPOUND_EXPR
, void_type_node
, clear
, exp
);
5250 /* The cleanup runs on both normal and EH paths, we need another
5251 CLEANUP_STMT to clear the flag only on the EH path. */
5252 tree
&bod
= CLEANUP_BODY (*tp
);
5253 bod
= build_stmt (EXPR_LOCATION (*tp
), CLEANUP_STMT
,
5254 bod
, clear
, current_retval_sentinel
);
5255 CLEANUP_EH_ONLY (bod
) = true;
5259 /* Disable maybe_splice_retval_cleanup within the NRV cleanup scope, we don't
5260 want to destroy the retval before the variable goes out of scope. */
5261 else if (TREE_CODE (*tp
) == CLEANUP_STMT
5262 && dp
->in_nrv_cleanup
5263 && CLEANUP_DECL (*tp
) == dp
->result
)
5264 CLEANUP_EXPR (*tp
) = void_node
;
5265 /* Replace the DECL_EXPR for the NRV with an initialization of the
5266 RESULT_DECL, if needed. */
5267 else if (TREE_CODE (*tp
) == DECL_EXPR
5268 && DECL_EXPR_DECL (*tp
) == dp
->var
)
5271 if (DECL_INITIAL (dp
->var
)
5272 && DECL_INITIAL (dp
->var
) != error_mark_node
)
5273 init
= cp_build_init_expr (dp
->result
,
5274 DECL_INITIAL (dp
->var
));
5276 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
5277 DECL_INITIAL (dp
->var
) = NULL_TREE
;
5278 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
5282 /* Keep iterating. */
5286 /* Called from finish_function to implement the named return value
5287 optimization by overriding all the RETURN_EXPRs and pertinent
5288 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
5289 RESULT_DECL for the function. */
5292 finalize_nrv (tree fndecl
, tree var
)
5294 class nrv_data data
;
5295 tree result
= DECL_RESULT (fndecl
);
5297 /* Copy name from VAR to RESULT. */
5298 DECL_NAME (result
) = DECL_NAME (var
);
5299 /* Don't forget that we take its address. */
5300 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
5301 /* Finally set DECL_VALUE_EXPR to avoid assigning
5302 a stack slot at -O0 for the original var and debug info
5303 uses RESULT location for VAR. */
5304 SET_DECL_VALUE_EXPR (var
, result
);
5305 DECL_HAS_VALUE_EXPR_P (var
) = 1;
5308 data
.result
= result
;
5309 data
.in_nrv_cleanup
= false;
5311 /* This is simpler for variables declared in the outer scope of
5312 the function so we know that their lifetime always ends with a
5313 return; see g++.dg/opt/nrv6.C. */
5314 tree outer
= outer_curly_brace_block (fndecl
);
5315 data
.simple
= chain_member (var
, BLOCK_VARS (outer
));
5317 cp_walk_tree (&DECL_SAVED_TREE (fndecl
), finalize_nrv_r
, &data
, 0);
5320 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
5323 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
5324 bool need_copy_ctor
, bool need_copy_assignment
,
5327 int save_errorcount
= errorcount
;
5330 /* Always allocate 3 elements for simplicity. These are the
5331 function decls for the ctor, dtor, and assignment op.
5332 This layout is known to the three lang hooks,
5333 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
5334 and cxx_omp_clause_assign_op. */
5335 info
= make_tree_vec (3);
5336 CP_OMP_CLAUSE_INFO (c
) = info
;
5338 if (need_default_ctor
|| need_copy_ctor
)
5340 if (need_default_ctor
)
5341 t
= get_default_ctor (type
);
5343 t
= get_copy_ctor (type
, tf_warning_or_error
);
5345 if (t
&& !trivial_fn_p (t
))
5346 TREE_VEC_ELT (info
, 0) = t
;
5349 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
5350 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
5352 if (need_copy_assignment
)
5354 t
= get_copy_assign (type
);
5356 if (t
&& !trivial_fn_p (t
))
5357 TREE_VEC_ELT (info
, 2) = t
;
5360 return errorcount
!= save_errorcount
;
5363 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
5364 FIELD_DECL, otherwise return DECL itself. */
5367 omp_clause_decl_field (tree decl
)
5370 && DECL_HAS_VALUE_EXPR_P (decl
)
5371 && DECL_ARTIFICIAL (decl
)
5372 && DECL_LANG_SPECIFIC (decl
)
5373 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
5375 tree f
= DECL_VALUE_EXPR (decl
);
5376 if (INDIRECT_REF_P (f
))
5377 f
= TREE_OPERAND (f
, 0);
5378 if (TREE_CODE (f
) == COMPONENT_REF
)
5380 f
= TREE_OPERAND (f
, 1);
5381 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
5388 /* Adjust DECL if needed for printing using %qE. */
5391 omp_clause_printable_decl (tree decl
)
5393 tree t
= omp_clause_decl_field (decl
);
5399 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
5400 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
5404 omp_note_field_privatization (tree f
, tree t
)
5406 if (!omp_private_member_map
)
5407 omp_private_member_map
= new hash_map
<tree
, tree
>;
5408 tree
&v
= omp_private_member_map
->get_or_insert (f
);
5412 omp_private_member_vec
.safe_push (f
);
5413 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
5414 omp_private_member_vec
.safe_push (integer_zero_node
);
5418 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
5422 omp_privatize_field (tree t
, bool shared
)
5424 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
5425 if (m
== error_mark_node
)
5426 return error_mark_node
;
5427 if (!omp_private_member_map
&& !shared
)
5428 omp_private_member_map
= new hash_map
<tree
, tree
>;
5429 if (TYPE_REF_P (TREE_TYPE (t
)))
5431 gcc_assert (INDIRECT_REF_P (m
));
5432 m
= TREE_OPERAND (m
, 0);
5434 tree vb
= NULL_TREE
;
5435 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
5438 v
= create_temporary_var (TREE_TYPE (m
));
5439 retrofit_lang_decl (v
);
5440 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
5441 SET_DECL_VALUE_EXPR (v
, m
);
5442 DECL_HAS_VALUE_EXPR_P (v
) = 1;
5444 omp_private_member_vec
.safe_push (t
);
5449 /* C++ specialisation of the c_omp_address_inspector class. */
5451 class cp_omp_address_inspector
: public c_omp_address_inspector
5454 cp_omp_address_inspector (location_t loc
, tree t
)
5455 : c_omp_address_inspector (loc
, t
)
5459 ~cp_omp_address_inspector ()
5463 bool processing_template_decl_p ()
5465 return processing_template_decl
;
5468 void emit_unmappable_type_notes (tree t
)
5470 if (TREE_TYPE (t
) != error_mark_node
5471 && !COMPLETE_TYPE_P (TREE_TYPE (t
)))
5472 cxx_incomplete_type_inform (TREE_TYPE (t
));
5475 tree
convert_from_reference (tree x
)
5477 return ::convert_from_reference (x
);
5480 tree
build_array_ref (location_t loc
, tree arr
, tree idx
)
5482 return ::build_array_ref (loc
, arr
, idx
);
5485 bool check_clause (tree clause
)
5487 if (TREE_CODE (orig
) == COMPONENT_REF
5488 && invalid_nonstatic_memfn_p (EXPR_LOCATION (orig
), orig
,
5489 tf_warning_or_error
))
5491 if (!c_omp_address_inspector::check_clause (clause
))
5497 /* Helper function for handle_omp_array_sections. Called recursively
5498 to handle multiple array-section-subscripts. C is the clause,
5499 T current expression (initially OMP_CLAUSE_DECL), which is either
5500 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
5501 expression if specified, TREE_VALUE length expression if specified,
5502 TREE_CHAIN is what it has been specified after, or some decl.
5503 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
5504 set to true if any of the array-section-subscript could have length
5505 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
5506 first array-section-subscript which is known not to have length
5508 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
5509 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
5510 all are or may have length of 1, array-section-subscript [:2] is the
5511 first one known not to have length 1. For array-section-subscript
5512 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
5513 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
5514 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
5515 case though, as some lengths could be zero. */
5518 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
5519 bool &maybe_zero_len
, unsigned int &first_non_one
,
5520 enum c_omp_region_type ort
)
5522 tree ret
, low_bound
, length
, type
;
5523 bool openacc
= (ort
& C_ORT_ACC
) != 0;
5524 if (TREE_CODE (t
) != OMP_ARRAY_SECTION
)
5526 if (error_operand_p (t
))
5527 return error_mark_node
;
5529 cp_omp_address_inspector
ai (OMP_CLAUSE_LOCATION (c
), t
);
5530 tree t_refto
= ai
.maybe_unconvert_ref (t
);
5532 if (!ai
.check_clause (c
))
5533 return error_mark_node
;
5534 else if (ai
.component_access_p ()
5535 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5536 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
5537 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
))
5538 t
= ai
.get_root_term (true);
5540 t
= ai
.unconverted_ref_origin ();
5541 if (t
== error_mark_node
)
5542 return error_mark_node
;
5544 if (TREE_CODE (t
) == FIELD_DECL
)
5545 ret
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
5547 && (openacc
|| !EXPR_P (t
))
5548 && TREE_CODE (t
) != PARM_DECL
)
5550 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
5553 error_at (OMP_CLAUSE_LOCATION (c
),
5554 "%qD is not a variable in %qs clause", t
,
5555 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5557 error_at (OMP_CLAUSE_LOCATION (c
),
5558 "%qE is not a variable in %qs clause", t
,
5559 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5560 return error_mark_node
;
5562 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5563 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5564 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
5566 error_at (OMP_CLAUSE_LOCATION (c
),
5567 "%qD is threadprivate variable in %qs clause", t
,
5568 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5569 return error_mark_node
;
5571 if (type_dependent_expression_p (ret
))
5573 ret
= convert_from_reference (ret
);
5577 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
5578 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5579 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5580 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5581 && TREE_CODE (TREE_OPERAND (t
, 0)) == FIELD_DECL
)
5582 TREE_OPERAND (t
, 0) = omp_privatize_field (TREE_OPERAND (t
, 0), false);
5583 ret
= handle_omp_array_sections_1 (c
, TREE_OPERAND (t
, 0), types
,
5584 maybe_zero_len
, first_non_one
, ort
);
5585 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
5588 type
= TREE_TYPE (ret
);
5589 low_bound
= TREE_OPERAND (t
, 1);
5590 length
= TREE_OPERAND (t
, 2);
5591 if ((low_bound
&& type_dependent_expression_p (low_bound
))
5592 || (length
&& type_dependent_expression_p (length
)))
5595 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
5596 return error_mark_node
;
5598 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
5600 error_at (OMP_CLAUSE_LOCATION (c
),
5601 "low bound %qE of array section does not have integral type",
5603 return error_mark_node
;
5605 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
5607 error_at (OMP_CLAUSE_LOCATION (c
),
5608 "length %qE of array section does not have integral type",
5610 return error_mark_node
;
5613 low_bound
= mark_rvalue_use (low_bound
);
5615 length
= mark_rvalue_use (length
);
5616 /* We need to reduce to real constant-values for checks below. */
5618 length
= fold_simple (length
);
5620 low_bound
= fold_simple (low_bound
);
5622 && TREE_CODE (low_bound
) == INTEGER_CST
5623 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5624 > TYPE_PRECISION (sizetype
))
5625 low_bound
= fold_convert (sizetype
, low_bound
);
5627 && TREE_CODE (length
) == INTEGER_CST
5628 && TYPE_PRECISION (TREE_TYPE (length
))
5629 > TYPE_PRECISION (sizetype
))
5630 length
= fold_convert (sizetype
, length
);
5631 if (low_bound
== NULL_TREE
)
5632 low_bound
= integer_zero_node
;
5634 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5635 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
5636 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
5638 if (length
!= integer_one_node
)
5640 error_at (OMP_CLAUSE_LOCATION (c
),
5641 "expected single pointer in %qs clause",
5642 user_omp_clause_code_name (c
, openacc
));
5643 return error_mark_node
;
5646 if (length
!= NULL_TREE
)
5648 if (!integer_nonzerop (length
))
5650 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
5651 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5652 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5653 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5654 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5656 if (integer_zerop (length
))
5658 error_at (OMP_CLAUSE_LOCATION (c
),
5659 "zero length array section in %qs clause",
5660 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5661 return error_mark_node
;
5665 maybe_zero_len
= true;
5667 if (first_non_one
== types
.length ()
5668 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
5671 if (TREE_CODE (type
) == ARRAY_TYPE
)
5673 if (length
== NULL_TREE
5674 && (TYPE_DOMAIN (type
) == NULL_TREE
5675 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
5677 error_at (OMP_CLAUSE_LOCATION (c
),
5678 "for unknown bound array type length expression must "
5680 return error_mark_node
;
5682 if (TREE_CODE (low_bound
) == INTEGER_CST
5683 && tree_int_cst_sgn (low_bound
) == -1)
5685 error_at (OMP_CLAUSE_LOCATION (c
),
5686 "negative low bound in array section in %qs clause",
5687 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5688 return error_mark_node
;
5690 if (length
!= NULL_TREE
5691 && TREE_CODE (length
) == INTEGER_CST
5692 && tree_int_cst_sgn (length
) == -1)
5694 error_at (OMP_CLAUSE_LOCATION (c
),
5695 "negative length in array section in %qs clause",
5696 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5697 return error_mark_node
;
5699 if (TYPE_DOMAIN (type
)
5700 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
5701 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
5705 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
5706 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
5707 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5709 if (tree_int_cst_lt (size
, low_bound
))
5711 error_at (OMP_CLAUSE_LOCATION (c
),
5712 "low bound %qE above array section size "
5713 "in %qs clause", low_bound
,
5714 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5715 return error_mark_node
;
5717 if (tree_int_cst_equal (size
, low_bound
))
5719 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
5720 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5721 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5722 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5723 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5725 error_at (OMP_CLAUSE_LOCATION (c
),
5726 "zero length array section in %qs clause",
5727 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5728 return error_mark_node
;
5730 maybe_zero_len
= true;
5732 else if (length
== NULL_TREE
5733 && first_non_one
== types
.length ()
5734 && tree_int_cst_equal
5735 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
5739 else if (length
== NULL_TREE
)
5741 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5742 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5743 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5744 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5745 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5746 maybe_zero_len
= true;
5747 if (first_non_one
== types
.length ())
5750 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
5752 if (tree_int_cst_lt (size
, length
))
5754 error_at (OMP_CLAUSE_LOCATION (c
),
5755 "length %qE above array section size "
5756 "in %qs clause", length
,
5757 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5758 return error_mark_node
;
5760 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5763 = size_binop (PLUS_EXPR
,
5764 fold_convert (sizetype
, low_bound
),
5765 fold_convert (sizetype
, length
));
5766 if (TREE_CODE (lbpluslen
) == INTEGER_CST
5767 && tree_int_cst_lt (size
, lbpluslen
))
5769 error_at (OMP_CLAUSE_LOCATION (c
),
5770 "high bound %qE above array section size "
5771 "in %qs clause", lbpluslen
,
5772 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5773 return error_mark_node
;
5778 else if (length
== NULL_TREE
)
5780 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5781 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5782 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5783 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5784 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5785 maybe_zero_len
= true;
5786 if (first_non_one
== types
.length ())
5790 /* For [lb:] we will need to evaluate lb more than once. */
5791 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5793 tree lb
= cp_save_expr (low_bound
);
5794 if (lb
!= low_bound
)
5796 TREE_OPERAND (t
, 1) = lb
;
5801 else if (TYPE_PTR_P (type
))
5803 if (length
== NULL_TREE
)
5805 if (TREE_CODE (ret
) == PARM_DECL
&& DECL_ARRAY_PARAMETER_P (ret
))
5806 error_at (OMP_CLAUSE_LOCATION (c
),
5807 "for array function parameter length expression "
5808 "must be specified");
5810 error_at (OMP_CLAUSE_LOCATION (c
),
5811 "for pointer type length expression must be specified");
5812 return error_mark_node
;
5814 if (length
!= NULL_TREE
5815 && TREE_CODE (length
) == INTEGER_CST
5816 && tree_int_cst_sgn (length
) == -1)
5818 error_at (OMP_CLAUSE_LOCATION (c
),
5819 "negative length in array section in %qs clause",
5820 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5821 return error_mark_node
;
5823 /* If there is a pointer type anywhere but in the very first
5824 array-section-subscript, the array section could be non-contiguous. */
5825 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5826 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5827 && TREE_CODE (TREE_OPERAND (t
, 0)) == OMP_ARRAY_SECTION
)
5829 /* If any prior dimension has a non-one length, then deem this
5830 array section as non-contiguous. */
5831 for (tree d
= TREE_OPERAND (t
, 0); TREE_CODE (d
) == OMP_ARRAY_SECTION
;
5832 d
= TREE_OPERAND (d
, 0))
5834 tree d_length
= TREE_OPERAND (d
, 2);
5835 if (d_length
== NULL_TREE
|| !integer_onep (d_length
))
5837 error_at (OMP_CLAUSE_LOCATION (c
),
5838 "array section is not contiguous in %qs clause",
5839 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5840 return error_mark_node
;
5847 error_at (OMP_CLAUSE_LOCATION (c
),
5848 "%qE does not have pointer or array type", ret
);
5849 return error_mark_node
;
5851 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5852 types
.safe_push (TREE_TYPE (ret
));
5853 /* We will need to evaluate lb more than once. */
5854 tree lb
= cp_save_expr (low_bound
);
5855 if (lb
!= low_bound
)
5857 TREE_OPERAND (t
, 1) = lb
;
5860 /* Temporarily disable -fstrong-eval-order for array reductions.
5861 The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
5862 is something the middle-end can't cope with and more importantly,
5863 it needs to be the actual base variable that is privatized, not some
5864 temporary assigned previous value of it. That, together with OpenMP
5865 saying how many times the side-effects are evaluated is unspecified,
5866 makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
5867 warning_sentinel
s (flag_strong_eval_order
,
5868 OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5869 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5870 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
);
5871 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, NULL
,
5872 tf_warning_or_error
);
5876 /* Handle array sections for clause C. */
5879 handle_omp_array_sections (tree
&c
, enum c_omp_region_type ort
)
5881 bool maybe_zero_len
= false;
5882 unsigned int first_non_one
= 0;
5883 auto_vec
<tree
, 10> types
;
5884 tree
*tp
= &OMP_CLAUSE_DECL (c
);
5885 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5886 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
)
5887 && TREE_CODE (*tp
) == TREE_LIST
5888 && TREE_PURPOSE (*tp
)
5889 && TREE_CODE (TREE_PURPOSE (*tp
)) == TREE_VEC
)
5890 tp
= &TREE_VALUE (*tp
);
5891 tree first
= handle_omp_array_sections_1 (c
, *tp
, types
,
5892 maybe_zero_len
, first_non_one
,
5894 if (first
== error_mark_node
)
5896 if (first
== NULL_TREE
)
5898 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5899 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
)
5902 tree tem
= NULL_TREE
;
5903 if (processing_template_decl
)
5905 /* Need to evaluate side effects in the length expressions
5907 while (TREE_CODE (t
) == TREE_LIST
)
5909 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
5911 if (tem
== NULL_TREE
)
5912 tem
= TREE_VALUE (t
);
5914 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
5915 TREE_VALUE (t
), tem
);
5920 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
5925 unsigned int num
= types
.length (), i
;
5926 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
5927 tree condition
= NULL_TREE
;
5929 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
5930 maybe_zero_len
= true;
5931 if (processing_template_decl
&& maybe_zero_len
)
5934 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
5935 t
= TREE_OPERAND (t
, 0))
5937 gcc_assert (TREE_CODE (t
) == OMP_ARRAY_SECTION
);
5939 tree low_bound
= TREE_OPERAND (t
, 1);
5940 tree length
= TREE_OPERAND (t
, 2);
5944 && TREE_CODE (low_bound
) == INTEGER_CST
5945 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5946 > TYPE_PRECISION (sizetype
))
5947 low_bound
= fold_convert (sizetype
, low_bound
);
5949 && TREE_CODE (length
) == INTEGER_CST
5950 && TYPE_PRECISION (TREE_TYPE (length
))
5951 > TYPE_PRECISION (sizetype
))
5952 length
= fold_convert (sizetype
, length
);
5953 if (low_bound
== NULL_TREE
)
5954 low_bound
= integer_zero_node
;
5955 if (!maybe_zero_len
&& i
> first_non_one
)
5957 if (integer_nonzerop (low_bound
))
5958 goto do_warn_noncontiguous
;
5959 if (length
!= NULL_TREE
5960 && TREE_CODE (length
) == INTEGER_CST
5961 && TYPE_DOMAIN (types
[i
])
5962 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
5963 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
5967 size
= size_binop (PLUS_EXPR
,
5968 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5970 if (!tree_int_cst_equal (length
, size
))
5972 do_warn_noncontiguous
:
5973 error_at (OMP_CLAUSE_LOCATION (c
),
5974 "array section is not contiguous in %qs "
5976 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5980 if (!processing_template_decl
5981 && length
!= NULL_TREE
5982 && TREE_SIDE_EFFECTS (length
))
5984 if (side_effects
== NULL_TREE
)
5985 side_effects
= length
;
5987 side_effects
= build2 (COMPOUND_EXPR
,
5988 TREE_TYPE (side_effects
),
5989 length
, side_effects
);
5992 else if (processing_template_decl
)
5998 if (i
> first_non_one
5999 && ((length
&& integer_nonzerop (length
))
6000 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6001 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
6002 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
))
6005 l
= fold_convert (sizetype
, length
);
6008 l
= size_binop (PLUS_EXPR
,
6009 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
6011 l
= size_binop (MINUS_EXPR
, l
,
6012 fold_convert (sizetype
, low_bound
));
6014 if (i
> first_non_one
)
6016 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
6018 if (condition
== NULL_TREE
)
6021 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
6024 else if (size
== NULL_TREE
)
6026 size
= size_in_bytes (TREE_TYPE (types
[i
]));
6027 tree eltype
= TREE_TYPE (types
[num
- 1]);
6028 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
6029 eltype
= TREE_TYPE (eltype
);
6030 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6031 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
6032 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
6033 size
= size_binop (EXACT_DIV_EXPR
, size
,
6034 size_in_bytes (eltype
));
6035 size
= size_binop (MULT_EXPR
, size
, l
);
6037 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
6038 size
, size_zero_node
);
6041 size
= size_binop (MULT_EXPR
, size
, l
);
6044 if (!processing_template_decl
)
6047 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
6048 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6049 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
6050 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
6052 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
6053 size
= save_expr (size
);
6054 tree index_type
= build_index_type (size
);
6055 tree eltype
= TREE_TYPE (first
);
6056 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
6057 eltype
= TREE_TYPE (eltype
);
6058 tree type
= build_array_type (eltype
, index_type
);
6059 tree ptype
= build_pointer_type (eltype
);
6060 if (TYPE_REF_P (TREE_TYPE (t
))
6061 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
6062 t
= convert_from_reference (t
);
6063 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6064 t
= build_fold_addr_expr (t
);
6065 tree t2
= build_fold_addr_expr (first
);
6066 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
6067 ptrdiff_type_node
, t2
);
6068 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
6069 ptrdiff_type_node
, t2
,
6070 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
6071 ptrdiff_type_node
, t
));
6072 if (tree_fits_shwi_p (t2
))
6073 t
= build2 (MEM_REF
, type
, t
,
6074 build_int_cst (ptype
, tree_to_shwi (t2
)));
6077 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
6079 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
6080 TREE_TYPE (t
), t
, t2
);
6081 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
6083 OMP_CLAUSE_DECL (c
) = t
;
6086 OMP_CLAUSE_DECL (c
) = first
;
6087 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_HAS_DEVICE_ADDR
)
6089 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
6090 || (OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_ATTACH
6091 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_DETACH
6092 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_FORCE_DETACH
))
6093 OMP_CLAUSE_SIZE (c
) = size
;
6094 if (TREE_CODE (t
) == FIELD_DECL
)
6095 t
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
6097 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6100 if (TREE_CODE (first
) == INDIRECT_REF
)
6102 /* Detect and skip adding extra nodes for pointer-to-member
6103 mappings. These are unsupported for now. */
6104 tree tmp
= TREE_OPERAND (first
, 0);
6106 if (TREE_CODE (tmp
) == NON_LVALUE_EXPR
)
6107 tmp
= TREE_OPERAND (tmp
, 0);
6109 if (TREE_CODE (tmp
) == INDIRECT_REF
)
6110 tmp
= TREE_OPERAND (tmp
, 0);
6112 if (TREE_CODE (tmp
) == POINTER_PLUS_EXPR
)
6114 tree offset
= TREE_OPERAND (tmp
, 1);
6115 STRIP_NOPS (offset
);
6116 if (TYPE_PTRMEM_P (TREE_TYPE (offset
)))
6118 sorry_at (OMP_CLAUSE_LOCATION (c
),
6119 "pointer-to-member mapping %qE not supported",
6120 OMP_CLAUSE_DECL (c
));
6126 /* FIRST represents the first item of data that we are mapping.
6127 E.g. if we're mapping an array, FIRST might resemble
6128 "foo.bar.myarray[0]". */
6130 auto_vec
<omp_addr_token
*, 10> addr_tokens
;
6132 if (!omp_parse_expr (addr_tokens
, first
))
6135 cp_omp_address_inspector
ai (OMP_CLAUSE_LOCATION (c
), t
);
6137 tree nc
= ai
.expand_map_clause (c
, first
, addr_tokens
, ort
);
6138 if (nc
!= error_mark_node
)
6140 using namespace omp_addr_tokenizer
;
6142 if (ai
.maybe_zero_length_array_section (c
))
6143 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
6145 /* !!! If we're accessing a base decl via chained access
6146 methods (e.g. multiple indirections), duplicate clause
6147 detection won't work properly. Skip it in that case. */
6148 if ((addr_tokens
[0]->type
== STRUCTURE_BASE
6149 || addr_tokens
[0]->type
== ARRAY_BASE
)
6150 && addr_tokens
[0]->u
.structure_base_kind
== BASE_DECL
6151 && addr_tokens
[1]->type
== ACCESS_METHOD
6152 && omp_access_chain_p (addr_tokens
, 1))
6162 /* Return identifier to look up for omp declare reduction. */
6165 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
6167 const char *p
= NULL
;
6168 const char *m
= NULL
;
6169 switch (reduction_code
)
6177 case TRUTH_ANDIF_EXPR
:
6178 case TRUTH_ORIF_EXPR
:
6179 reduction_id
= ovl_op_identifier (false, reduction_code
);
6193 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
6194 return error_mark_node
;
6195 p
= IDENTIFIER_POINTER (reduction_id
);
6198 if (type
!= NULL_TREE
)
6199 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
6201 const char prefix
[] = "omp declare reduction ";
6202 size_t lenp
= sizeof (prefix
);
6203 if (strncmp (p
, prefix
, lenp
- 1) == 0)
6205 size_t len
= strlen (p
);
6206 size_t lenm
= m
? strlen (m
) + 1 : 0;
6207 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
6209 memcpy (name
, prefix
, lenp
- 1);
6210 memcpy (name
+ lenp
- 1, p
, len
+ 1);
6213 name
[lenp
+ len
- 1] = '~';
6214 memcpy (name
+ lenp
+ len
, m
, lenm
);
6216 return get_identifier (name
);
6219 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
6220 FUNCTION_DECL or NULL_TREE if not found. */
6223 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
6224 vec
<tree
> *ambiguousp
)
6227 tree baselink
= NULL_TREE
;
6228 if (identifier_p (id
))
6231 bool nonint_cst_expression_p
;
6232 const char *error_msg
;
6233 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
6234 tree decl
= lookup_name (id
);
6235 if (decl
== NULL_TREE
)
6236 decl
= error_mark_node
;
6237 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
6238 &nonint_cst_expression_p
, false, true, false,
6239 false, &error_msg
, loc
);
6240 if (idk
== CP_ID_KIND_UNQUALIFIED
6241 && identifier_p (id
))
6243 vec
<tree
, va_gc
> *args
= NULL
;
6244 vec_safe_push (args
, build_reference_type (type
));
6245 id
= perform_koenig_lookup (id
, args
, tf_none
);
6248 else if (TREE_CODE (id
) == SCOPE_REF
)
6249 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
6250 omp_reduction_id (ERROR_MARK
,
6251 TREE_OPERAND (id
, 1),
6253 LOOK_want::NORMAL
, false);
6256 if (fns
&& is_overloaded_fn (fns
))
6258 for (lkp_iterator
iter (get_fns (fns
)); iter
; ++iter
)
6260 tree fndecl
= *iter
;
6261 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
6263 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
6264 if (same_type_p (TREE_TYPE (argtype
), type
))
6272 if (id
&& BASELINK_P (fns
))
6281 if (!id
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
6283 auto_vec
<tree
> ambiguous
;
6284 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
6286 if (ambiguousp
== NULL
)
6287 ambiguousp
= &ambiguous
;
6288 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
6290 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
6291 baselinkp
? baselinkp
: &baselink
,
6293 if (id
== NULL_TREE
)
6295 if (!ambiguousp
->is_empty ())
6296 ambiguousp
->safe_push (id
);
6297 else if (ret
!= NULL_TREE
)
6299 ambiguousp
->safe_push (ret
);
6300 ambiguousp
->safe_push (id
);
6306 if (ambiguousp
!= &ambiguous
)
6308 if (!ambiguous
.is_empty ())
6310 const char *str
= _("candidates are:");
6313 error_at (loc
, "user defined reduction lookup is ambiguous");
6314 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
6316 inform (DECL_SOURCE_LOCATION (udr
), "%s %#qD", str
, udr
);
6318 str
= get_spaces (str
);
6320 ret
= error_mark_node
;
6321 baselink
= NULL_TREE
;
6326 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
6327 id
, id
, tf_warning_or_error
);
6331 /* Helper function for cp_parser_omp_declare_reduction_exprs
6333 Remove CLEANUP_STMT for data (omp_priv variable).
6334 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
6338 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
6342 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
6343 *tp
= CLEANUP_BODY (*tp
);
6344 else if (TREE_CODE (*tp
) == DECL_EXPR
)
6346 tree decl
= DECL_EXPR_DECL (*tp
);
6347 if (!processing_template_decl
6348 && decl
== (tree
) data
6349 && DECL_INITIAL (decl
)
6350 && DECL_INITIAL (decl
) != error_mark_node
)
6352 tree list
= NULL_TREE
;
6353 append_to_statement_list_force (*tp
, &list
);
6354 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
6355 decl
, DECL_INITIAL (decl
));
6356 DECL_INITIAL (decl
) = NULL_TREE
;
6357 append_to_statement_list_force (init_expr
, &list
);
6364 /* Data passed from cp_check_omp_declare_reduction to
6365 cp_check_omp_declare_reduction_r. */
6367 struct cp_check_omp_declare_reduction_data
6374 /* Helper function for cp_check_omp_declare_reduction, called via
6378 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
6380 struct cp_check_omp_declare_reduction_data
*udr_data
6381 = (struct cp_check_omp_declare_reduction_data
*) data
;
6383 && !DECL_ARTIFICIAL (*tp
)
6384 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
6385 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
6387 location_t loc
= udr_data
->loc
;
6388 if (udr_data
->combiner_p
)
6389 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
6390 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
6393 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
6394 "to variable %qD which is not %<omp_priv%> nor "
6402 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
6405 cp_check_omp_declare_reduction (tree udr
)
6407 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
6408 gcc_assert (TYPE_REF_P (type
));
6409 type
= TREE_TYPE (type
);
6411 location_t loc
= DECL_SOURCE_LOCATION (udr
);
6413 if (type
== error_mark_node
)
6415 if (ARITHMETIC_TYPE_P (type
))
6417 static enum tree_code predef_codes
[]
6418 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
6419 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
6420 for (i
= 0; i
< 8; i
++)
6422 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
6423 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
6424 const char *n2
= IDENTIFIER_POINTER (id
);
6425 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
6426 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
6427 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
6432 && TREE_CODE (type
) != COMPLEX_EXPR
)
6434 const char prefix_minmax
[] = "omp declare reduction m";
6435 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
6436 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
6437 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
6438 prefix_minmax
, prefix_size
) == 0
6439 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
6440 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
6441 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
6446 error_at (loc
, "predeclared arithmetic type %qT in "
6447 "%<#pragma omp declare reduction%>", type
);
6451 else if (FUNC_OR_METHOD_TYPE_P (type
)
6452 || TREE_CODE (type
) == ARRAY_TYPE
)
6454 error_at (loc
, "function or array type %qT in "
6455 "%<#pragma omp declare reduction%>", type
);
6458 else if (TYPE_REF_P (type
))
6460 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
6464 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
6466 error_at (loc
, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
6467 "type %qT in %<#pragma omp declare reduction%>", type
);
6471 tree body
= DECL_SAVED_TREE (udr
);
6472 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
6475 tree_stmt_iterator tsi
;
6476 struct cp_check_omp_declare_reduction_data data
;
6477 memset (data
.stmts
, 0, sizeof data
.stmts
);
6478 for (i
= 0, tsi
= tsi_start (body
);
6479 i
< 7 && !tsi_end_p (tsi
);
6480 i
++, tsi_next (&tsi
))
6481 data
.stmts
[i
] = tsi_stmt (tsi
);
6483 gcc_assert (tsi_end_p (tsi
));
6486 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
6487 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
6488 if (warning_suppressed_p (DECL_EXPR_DECL (data
.stmts
[0]) /* What warning? */))
6490 data
.combiner_p
= true;
6491 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
6493 suppress_warning (DECL_EXPR_DECL (data
.stmts
[0]) /* What warning? */);
6497 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
6498 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
6499 data
.combiner_p
= false;
6500 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
6502 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
6503 cp_check_omp_declare_reduction_r
, &data
, NULL
))
6504 suppress_warning (DECL_EXPR_DECL (data
.stmts
[0]) /* Wat warning? */);
6506 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
6511 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
6512 an inline call. But, remap
6513 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
6514 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
6517 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
6518 tree decl
, tree placeholder
)
6521 hash_map
<tree
, tree
> decl_map
;
6523 decl_map
.put (omp_decl1
, placeholder
);
6524 decl_map
.put (omp_decl2
, decl
);
6525 memset (&id
, 0, sizeof (id
));
6526 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
6527 id
.dst_fn
= current_function_decl
;
6528 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
6529 id
.decl_map
= &decl_map
;
6531 id
.copy_decl
= copy_decl_no_change
;
6532 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
6533 id
.transform_new_cfg
= true;
6534 id
.transform_return_to_modify
= false;
6536 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
6540 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
6541 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
6544 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
6546 if (*tp
== (tree
) data
)
6551 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
6552 Return true if there is some error and the clause should be removed. */
6555 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
6557 tree t
= OMP_CLAUSE_DECL (c
);
6558 bool predefined
= false;
6559 if (TREE_CODE (t
) == TREE_LIST
)
6561 gcc_assert (processing_template_decl
);
6564 tree type
= TREE_TYPE (t
);
6565 if (TREE_CODE (t
) == MEM_REF
)
6566 type
= TREE_TYPE (type
);
6567 if (TYPE_REF_P (type
))
6568 type
= TREE_TYPE (type
);
6569 if (TREE_CODE (type
) == ARRAY_TYPE
)
6572 gcc_assert (TREE_CODE (t
) != MEM_REF
);
6573 while (TREE_CODE (type
) == ARRAY_TYPE
)
6574 type
= TREE_TYPE (type
);
6575 if (!processing_template_decl
)
6577 t
= require_complete_type (t
);
6578 if (t
== error_mark_node
6579 || !complete_type_or_else (oatype
, NULL_TREE
))
6581 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
6582 TYPE_SIZE_UNIT (type
));
6583 if (integer_zerop (size
))
6585 error_at (OMP_CLAUSE_LOCATION (c
),
6586 "%qE in %<reduction%> clause is a zero size array",
6587 omp_clause_printable_decl (t
));
6590 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
6591 size
= save_expr (size
);
6592 tree index_type
= build_index_type (size
);
6593 tree atype
= build_array_type (type
, index_type
);
6594 tree ptype
= build_pointer_type (type
);
6595 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6596 t
= build_fold_addr_expr (t
);
6597 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
6598 OMP_CLAUSE_DECL (c
) = t
;
6601 if (type
== error_mark_node
)
6603 else if (ARITHMETIC_TYPE_P (type
))
6604 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
6609 case TRUTH_ANDIF_EXPR
:
6610 case TRUTH_ORIF_EXPR
:
6615 if (TREE_CODE (type
) == COMPLEX_TYPE
)
6622 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
6629 else if (TYPE_READONLY (type
))
6631 error_at (OMP_CLAUSE_LOCATION (c
),
6632 "%qE has const type for %<reduction%>",
6633 omp_clause_printable_decl (t
));
6636 else if (!processing_template_decl
)
6638 t
= require_complete_type (t
);
6639 if (t
== error_mark_node
)
6641 OMP_CLAUSE_DECL (c
) = t
;
6646 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
6649 else if (processing_template_decl
)
6651 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) == error_mark_node
)
6656 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
6658 type
= TYPE_MAIN_VARIANT (type
);
6659 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
6660 if (id
== NULL_TREE
)
6661 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
6662 NULL_TREE
, NULL_TREE
);
6663 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
6666 if (id
== error_mark_node
)
6669 tree body
= DECL_SAVED_TREE (id
);
6672 if (TREE_CODE (body
) == STATEMENT_LIST
)
6674 tree_stmt_iterator tsi
;
6675 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
6678 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
6679 atype
= TREE_TYPE (atype
);
6680 bool need_static_cast
= !same_type_p (type
, atype
);
6681 memset (stmts
, 0, sizeof stmts
);
6682 for (i
= 0, tsi
= tsi_start (body
);
6683 i
< 7 && !tsi_end_p (tsi
);
6684 i
++, tsi_next (&tsi
))
6685 stmts
[i
] = tsi_stmt (tsi
);
6686 gcc_assert (tsi_end_p (tsi
));
6690 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
6691 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
6692 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
6693 DECL_ARTIFICIAL (placeholder
) = 1;
6694 DECL_IGNORED_P (placeholder
) = 1;
6695 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
6696 if (TREE_CODE (t
) == MEM_REF
)
6698 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
6700 DECL_ARTIFICIAL (decl_placeholder
) = 1;
6701 DECL_IGNORED_P (decl_placeholder
) = 1;
6702 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
6704 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
6705 cxx_mark_addressable (placeholder
);
6706 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
6707 && (decl_placeholder
6708 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6709 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6710 : OMP_CLAUSE_DECL (c
));
6711 tree omp_out
= placeholder
;
6712 tree omp_in
= decl_placeholder
? decl_placeholder
6713 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6714 if (need_static_cast
)
6716 tree rtype
= build_reference_type (atype
);
6717 omp_out
= build_static_cast (input_location
,
6719 tf_warning_or_error
);
6720 omp_in
= build_static_cast (input_location
,
6722 tf_warning_or_error
);
6723 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
6725 omp_out
= convert_from_reference (omp_out
);
6726 omp_in
= convert_from_reference (omp_in
);
6728 OMP_CLAUSE_REDUCTION_MERGE (c
)
6729 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
6730 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
6734 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
6735 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
6736 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3]))
6737 && (decl_placeholder
6738 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6739 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6740 : OMP_CLAUSE_DECL (c
));
6741 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
6742 cxx_mark_addressable (placeholder
);
6743 tree omp_priv
= decl_placeholder
? decl_placeholder
6744 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6745 tree omp_orig
= placeholder
;
6746 if (need_static_cast
)
6750 error_at (OMP_CLAUSE_LOCATION (c
),
6751 "user defined reduction with constructor "
6752 "initializer for base class %qT", atype
);
6755 tree rtype
= build_reference_type (atype
);
6756 omp_priv
= build_static_cast (input_location
,
6758 tf_warning_or_error
);
6759 omp_orig
= build_static_cast (input_location
,
6761 tf_warning_or_error
);
6762 if (omp_priv
== error_mark_node
6763 || omp_orig
== error_mark_node
)
6765 omp_priv
= convert_from_reference (omp_priv
);
6766 omp_orig
= convert_from_reference (omp_orig
);
6769 *need_default_ctor
= true;
6770 OMP_CLAUSE_REDUCTION_INIT (c
)
6771 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
6772 DECL_EXPR_DECL (stmts
[3]),
6773 omp_priv
, omp_orig
);
6774 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
6775 find_omp_placeholder_r
, placeholder
, NULL
))
6776 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
6780 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
6781 *need_default_ctor
= true;
6785 tree v
= decl_placeholder
? decl_placeholder
6786 : convert_from_reference (t
);
6787 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
6788 init
= build_constructor (TREE_TYPE (v
), NULL
);
6790 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
6791 OMP_CLAUSE_REDUCTION_INIT (c
)
6792 = cp_build_init_expr (v
, init
);
6797 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
6801 error_at (OMP_CLAUSE_LOCATION (c
),
6802 "user defined reduction not found for %qE",
6803 omp_clause_printable_decl (t
));
6806 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
6807 gcc_assert (TYPE_SIZE_UNIT (type
)
6808 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
6812 /* Called from finish_struct_1. linear(this) or linear(this:step)
6813 clauses might not be finalized yet because the class has been incomplete
6814 when parsing #pragma omp declare simd methods. Fix those up now. */
6817 finish_omp_declare_simd_methods (tree t
)
6819 if (processing_template_decl
)
6822 for (tree x
= TYPE_FIELDS (t
); x
; x
= DECL_CHAIN (x
))
6824 if (TREE_CODE (x
) == USING_DECL
6825 || !DECL_IOBJ_MEMBER_FUNCTION_P (x
))
6827 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
6828 if (!ods
|| !TREE_VALUE (ods
))
6830 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
6831 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
6832 && integer_zerop (OMP_CLAUSE_DECL (c
))
6833 && OMP_CLAUSE_LINEAR_STEP (c
)
6834 && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
))))
6836 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
6837 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
6838 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
6839 sizetype
, s
, TYPE_SIZE_UNIT (t
));
6840 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
6845 /* Adjust sink depend/doacross clause to take into account pointer offsets.
6847 Return TRUE if there was a problem processing the offset, and the
6848 whole clause should be removed. */
6851 cp_finish_omp_clause_doacross_sink (tree sink_clause
)
6853 tree t
= OMP_CLAUSE_DECL (sink_clause
);
6854 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
6856 /* Make sure we don't adjust things twice for templates. */
6857 if (processing_template_decl
)
6860 for (; t
; t
= TREE_CHAIN (t
))
6862 tree decl
= TREE_VALUE (t
);
6863 if (TYPE_PTR_P (TREE_TYPE (decl
)))
6865 tree offset
= TREE_PURPOSE (t
);
6866 bool neg
= wi::neg_p (wi::to_wide (offset
));
6867 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
6868 decl
= mark_rvalue_use (decl
);
6869 decl
= convert_from_reference (decl
);
6870 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
6871 neg
? MINUS_EXPR
: PLUS_EXPR
,
6873 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
6874 MINUS_EXPR
, sizetype
,
6875 fold_convert (sizetype
, t2
),
6876 fold_convert (sizetype
, decl
));
6877 if (t2
== error_mark_node
)
6879 TREE_PURPOSE (t
) = t2
;
6885 /* Finish OpenMP iterators ITER. Return true if they are errorneous
6886 and clauses containing them should be removed. */
6889 cp_omp_finish_iterators (tree iter
)
6892 for (tree it
= iter
; it
; it
= TREE_CHAIN (it
))
6894 tree var
= TREE_VEC_ELT (it
, 0);
6895 tree begin
= TREE_VEC_ELT (it
, 1);
6896 tree end
= TREE_VEC_ELT (it
, 2);
6897 tree step
= TREE_VEC_ELT (it
, 3);
6899 tree type
= TREE_TYPE (var
);
6900 location_t loc
= DECL_SOURCE_LOCATION (var
);
6901 if (type
== error_mark_node
)
6906 if (type_dependent_expression_p (var
))
6908 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
6910 error_at (loc
, "iterator %qD has neither integral nor pointer type",
6915 else if (TYPE_READONLY (type
))
6917 error_at (loc
, "iterator %qD has const qualified type", var
);
6921 if (type_dependent_expression_p (begin
)
6922 || type_dependent_expression_p (end
)
6923 || type_dependent_expression_p (step
))
6925 else if (error_operand_p (step
))
6930 else if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
6932 error_at (EXPR_LOC_OR_LOC (step
, loc
),
6933 "iterator step with non-integral type");
6938 begin
= mark_rvalue_use (begin
);
6939 end
= mark_rvalue_use (end
);
6940 step
= mark_rvalue_use (step
);
6941 begin
= cp_build_c_cast (input_location
, type
, begin
,
6942 tf_warning_or_error
);
6943 end
= cp_build_c_cast (input_location
, type
, end
,
6944 tf_warning_or_error
);
6946 if (!processing_template_decl
)
6947 step
= orig_step
= save_expr (step
);
6948 tree stype
= POINTER_TYPE_P (type
) ? sizetype
: type
;
6949 step
= cp_build_c_cast (input_location
, stype
, step
,
6950 tf_warning_or_error
);
6951 if (POINTER_TYPE_P (type
) && !processing_template_decl
)
6953 begin
= save_expr (begin
);
6954 step
= pointer_int_sum (loc
, PLUS_EXPR
, begin
, step
);
6955 step
= fold_build2_loc (loc
, MINUS_EXPR
, sizetype
,
6956 fold_convert (sizetype
, step
),
6957 fold_convert (sizetype
, begin
));
6958 step
= fold_convert (ssizetype
, step
);
6960 if (!processing_template_decl
)
6962 begin
= maybe_constant_value (begin
);
6963 end
= maybe_constant_value (end
);
6964 step
= maybe_constant_value (step
);
6965 orig_step
= maybe_constant_value (orig_step
);
6967 if (integer_zerop (step
))
6969 error_at (loc
, "iterator %qD has zero step", var
);
6974 if (begin
== error_mark_node
6975 || end
== error_mark_node
6976 || step
== error_mark_node
6977 || orig_step
== error_mark_node
)
6983 if (!processing_template_decl
)
6985 begin
= fold_build_cleanup_point_expr (TREE_TYPE (begin
), begin
);
6986 end
= fold_build_cleanup_point_expr (TREE_TYPE (end
), end
);
6987 step
= fold_build_cleanup_point_expr (TREE_TYPE (step
), step
);
6988 orig_step
= fold_build_cleanup_point_expr (TREE_TYPE (orig_step
),
6991 hash_set
<tree
> pset
;
6993 for (it2
= TREE_CHAIN (it
); it2
; it2
= TREE_CHAIN (it2
))
6995 tree var2
= TREE_VEC_ELT (it2
, 0);
6996 tree begin2
= TREE_VEC_ELT (it2
, 1);
6997 tree end2
= TREE_VEC_ELT (it2
, 2);
6998 tree step2
= TREE_VEC_ELT (it2
, 3);
6999 location_t loc2
= DECL_SOURCE_LOCATION (var2
);
7000 if (cp_walk_tree (&begin2
, find_omp_placeholder_r
, var
, &pset
))
7002 error_at (EXPR_LOC_OR_LOC (begin2
, loc2
),
7003 "begin expression refers to outer iterator %qD", var
);
7006 else if (cp_walk_tree (&end2
, find_omp_placeholder_r
, var
, &pset
))
7008 error_at (EXPR_LOC_OR_LOC (end2
, loc2
),
7009 "end expression refers to outer iterator %qD", var
);
7012 else if (cp_walk_tree (&step2
, find_omp_placeholder_r
, var
, &pset
))
7014 error_at (EXPR_LOC_OR_LOC (step2
, loc2
),
7015 "step expression refers to outer iterator %qD", var
);
7024 TREE_VEC_ELT (it
, 1) = begin
;
7025 TREE_VEC_ELT (it
, 2) = end
;
7026 if (processing_template_decl
)
7027 TREE_VEC_ELT (it
, 3) = orig_step
;
7030 TREE_VEC_ELT (it
, 3) = step
;
7031 TREE_VEC_ELT (it
, 4) = orig_step
;
7037 /* Ensure that pointers are used in OpenACC attach and detach clauses.
7038 Return true if an error has been detected. */
7041 cp_oacc_check_attachments (tree c
)
7043 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7046 /* OpenACC attach / detach clauses must be pointers. */
7047 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7048 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
)
7050 tree t
= OMP_CLAUSE_DECL (c
);
7053 while (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
7054 t
= TREE_OPERAND (t
, 0);
7056 type
= TREE_TYPE (t
);
7058 if (TREE_CODE (type
) == REFERENCE_TYPE
)
7059 type
= TREE_TYPE (type
);
7061 if (TREE_CODE (type
) != POINTER_TYPE
)
7063 error_at (OMP_CLAUSE_LOCATION (c
), "expected pointer in %qs clause",
7064 user_omp_clause_code_name (c
, true));
7072 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
7073 Remove any elements from the list that are invalid. */
7076 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
7078 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
7079 bitmap_head aligned_head
, map_head
, map_field_head
, map_firstprivate_head
;
7080 bitmap_head oacc_reduction_head
, is_on_device_head
;
7082 tree safelen
= NULL_TREE
;
7083 bool openacc
= (ort
& C_ORT_ACC
) != 0;
7084 bool branch_seen
= false;
7085 bool copyprivate_seen
= false;
7086 bool ordered_seen
= false;
7087 bool order_seen
= false;
7088 bool schedule_seen
= false;
7089 bool oacc_async
= false;
7090 bool indir_component_ref_p
= false;
7091 tree last_iterators
= NULL_TREE
;
7092 bool last_iterators_remove
= false;
7093 /* 1 if normal/task reduction has been seen, -1 if inscan reduction
7094 has been seen, -2 if mixed inscan/normal reduction diagnosed. */
7095 int reduction_seen
= 0;
7096 bool allocate_seen
= false;
7097 tree detach_seen
= NULL_TREE
;
7098 bool mergeable_seen
= false;
7099 bool implicit_moved
= false;
7100 bool target_in_reduction_seen
= false;
7102 bitmap_obstack_initialize (NULL
);
7103 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
7104 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
7105 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
7106 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
7107 /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
7108 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
7109 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
7110 bitmap_initialize (&map_firstprivate_head
, &bitmap_default_obstack
);
7111 /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
7112 instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
7113 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
7114 bitmap_initialize (&is_on_device_head
, &bitmap_default_obstack
);
7117 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
7118 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
7124 tree
*grp_start_p
= NULL
, grp_sentinel
= NULL_TREE
;
7126 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
7128 bool remove
= false;
7129 bool field_ok
= false;
7131 /* We've reached the end of a list of expanded nodes. Reset the group
7133 if (c
== grp_sentinel
)
7136 switch (OMP_CLAUSE_CODE (c
))
7138 case OMP_CLAUSE_SHARED
:
7139 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
7140 goto check_dup_generic
;
7141 case OMP_CLAUSE_PRIVATE
:
7142 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
7143 goto check_dup_generic
;
7144 case OMP_CLAUSE_REDUCTION
:
7145 if (reduction_seen
== 0)
7146 reduction_seen
= OMP_CLAUSE_REDUCTION_INSCAN (c
) ? -1 : 1;
7147 else if (reduction_seen
!= -2
7148 && reduction_seen
!= (OMP_CLAUSE_REDUCTION_INSCAN (c
)
7151 error_at (OMP_CLAUSE_LOCATION (c
),
7152 "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
7153 "on the same construct");
7154 reduction_seen
= -2;
7157 case OMP_CLAUSE_IN_REDUCTION
:
7158 case OMP_CLAUSE_TASK_REDUCTION
:
7159 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
7160 t
= OMP_CLAUSE_DECL (c
);
7161 if (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
7163 if (handle_omp_array_sections (c
, ort
))
7168 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
7169 && OMP_CLAUSE_REDUCTION_INSCAN (c
))
7171 error_at (OMP_CLAUSE_LOCATION (c
),
7172 "%<inscan%> %<reduction%> clause with array "
7177 if (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
7179 while (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
7180 t
= TREE_OPERAND (t
, 0);
7184 gcc_assert (TREE_CODE (t
) == MEM_REF
);
7185 t
= TREE_OPERAND (t
, 0);
7186 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
7187 t
= TREE_OPERAND (t
, 0);
7188 if (TREE_CODE (t
) == ADDR_EXPR
7189 || INDIRECT_REF_P (t
))
7190 t
= TREE_OPERAND (t
, 0);
7192 tree n
= omp_clause_decl_field (t
);
7195 goto check_dup_generic_t
;
7198 cxx_mark_addressable (t
);
7199 goto check_dup_generic
;
7200 case OMP_CLAUSE_COPYPRIVATE
:
7201 copyprivate_seen
= true;
7202 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
7203 goto check_dup_generic
;
7204 case OMP_CLAUSE_COPYIN
:
7205 goto check_dup_generic
;
7206 case OMP_CLAUSE_LINEAR
:
7207 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
7208 t
= OMP_CLAUSE_DECL (c
);
7209 if (ort
!= C_ORT_OMP_DECLARE_SIMD
7210 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
7212 if (OMP_CLAUSE_LINEAR_OLD_LINEAR_MODIFIER (c
))
7214 error_at (OMP_CLAUSE_LOCATION (c
),
7215 "modifier should not be specified in %<linear%> "
7216 "clause on %<simd%> or %<for%> constructs when "
7217 "not using OpenMP 5.2 modifiers");
7218 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
7220 else if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_VAL
)
7222 error_at (OMP_CLAUSE_LOCATION (c
),
7223 "modifier other than %<val%> specified in "
7224 "%<linear%> clause on %<simd%> or %<for%> "
7225 "constructs when using OpenMP 5.2 modifiers");
7226 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
7229 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7230 && !type_dependent_expression_p (t
))
7232 tree type
= TREE_TYPE (t
);
7233 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
7234 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
7235 && !TYPE_REF_P (type
))
7237 error_at (OMP_CLAUSE_LOCATION (c
),
7238 "linear clause with %qs modifier applied to "
7239 "non-reference variable with %qT type",
7240 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
7241 ? "ref" : "uval", TREE_TYPE (t
));
7245 if (TYPE_REF_P (type
))
7246 type
= TREE_TYPE (type
);
7247 if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
7249 if (!INTEGRAL_TYPE_P (type
)
7250 && !TYPE_PTR_P (type
))
7252 error_at (OMP_CLAUSE_LOCATION (c
),
7253 "linear clause applied to non-integral "
7254 "non-pointer variable with %qT type",
7261 t
= OMP_CLAUSE_LINEAR_STEP (c
);
7263 t
= integer_one_node
;
7264 if (t
== error_mark_node
)
7269 else if (!type_dependent_expression_p (t
)
7270 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
7271 && (ort
!= C_ORT_OMP_DECLARE_SIMD
7272 || TREE_CODE (t
) != PARM_DECL
7273 || !TYPE_REF_P (TREE_TYPE (t
))
7274 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
7276 error_at (OMP_CLAUSE_LOCATION (c
),
7277 "linear step expression must be integral");
7283 t
= mark_rvalue_use (t
);
7284 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
7286 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
7287 goto check_dup_generic
;
7289 if (!processing_template_decl
7290 && (VAR_P (OMP_CLAUSE_DECL (c
))
7291 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
7293 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
7295 t
= maybe_constant_value (t
);
7296 if (TREE_CODE (t
) != INTEGER_CST
)
7298 error_at (OMP_CLAUSE_LOCATION (c
),
7299 "%<linear%> clause step %qE is neither "
7300 "constant nor a parameter", t
);
7305 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7306 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
7307 if (TYPE_REF_P (type
))
7308 type
= TREE_TYPE (type
);
7309 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
7311 type
= build_pointer_type (type
);
7312 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
7313 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
7315 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
7316 MINUS_EXPR
, sizetype
,
7317 fold_convert (sizetype
, t
),
7318 fold_convert (sizetype
, d
));
7319 if (t
== error_mark_node
)
7325 else if (TYPE_PTR_P (type
)
7326 /* Can't multiply the step yet if *this
7327 is still incomplete type. */
7328 && (ort
!= C_ORT_OMP_DECLARE_SIMD
7329 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
7330 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
7331 || DECL_NAME (OMP_CLAUSE_DECL (c
))
7333 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
7335 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
7336 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
7338 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
7339 MINUS_EXPR
, sizetype
,
7340 fold_convert (sizetype
, t
),
7341 fold_convert (sizetype
, d
));
7342 if (t
== error_mark_node
)
7349 t
= fold_convert (type
, t
);
7351 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
7353 goto check_dup_generic
;
7355 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7358 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
7359 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7362 t
= OMP_CLAUSE_DECL (c
);
7363 check_dup_generic_t
:
7364 if (t
== current_class_ptr
7365 && ((ort
!= C_ORT_OMP_DECLARE_SIMD
&& !openacc
)
7366 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
7367 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
7369 error_at (OMP_CLAUSE_LOCATION (c
),
7370 "%<this%> allowed in OpenMP only in %<declare simd%>"
7375 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
7376 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
7378 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7381 error_at (OMP_CLAUSE_LOCATION (c
),
7382 "%qD is not a variable in clause %qs", t
,
7383 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7385 error_at (OMP_CLAUSE_LOCATION (c
),
7386 "%qE is not a variable in clause %qs", t
,
7387 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7391 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
7392 || (ort
== C_ORT_OMP
7393 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
7394 || (OMP_CLAUSE_CODE (c
)
7395 == OMP_CLAUSE_USE_DEVICE_ADDR
)))
7396 || (ort
== C_ORT_OMP_TARGET
7397 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
))
7399 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
7400 && (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7401 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))))
7403 error_at (OMP_CLAUSE_LOCATION (c
),
7404 "%qD appears more than once in data-sharing "
7409 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
)
7410 target_in_reduction_seen
= true;
7411 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
7413 error_at (OMP_CLAUSE_LOCATION (c
),
7415 ? "%qD appears more than once in reduction clauses"
7416 : "%qD appears more than once in data clauses",
7421 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
7423 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7424 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
7425 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
))
7426 || bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
7428 error_at (OMP_CLAUSE_LOCATION (c
),
7429 "%qD appears more than once in data clauses", t
);
7432 else if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
7433 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_HAS_DEVICE_ADDR
7434 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IS_DEVICE_PTR
)
7435 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
7438 error_at (OMP_CLAUSE_LOCATION (c
),
7439 "%qD appears more than once in data clauses", t
);
7441 error_at (OMP_CLAUSE_LOCATION (c
),
7442 "%qD appears both in data and map clauses", t
);
7446 bitmap_set_bit (&generic_head
, DECL_UID (t
));
7451 && TREE_CODE (t
) == FIELD_DECL
7452 && t
== OMP_CLAUSE_DECL (c
))
7455 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
7456 == OMP_CLAUSE_SHARED
));
7457 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
7462 case OMP_CLAUSE_FIRSTPRIVATE
:
7463 if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
) && !implicit_moved
)
7466 implicit_moved
= true;
7467 /* Move firstprivate and map clauses with
7468 OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
7470 tree cl1
= NULL_TREE
, cl2
= NULL_TREE
;
7471 tree
*pc1
= pc
, *pc2
= &cl1
, *pc3
= &cl2
;
7473 if (OMP_CLAUSE_CODE (*pc1
) == OMP_CLAUSE_FIRSTPRIVATE
7474 && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1
))
7477 pc3
= &OMP_CLAUSE_CHAIN (*pc3
);
7478 *pc1
= OMP_CLAUSE_CHAIN (*pc1
);
7480 else if (OMP_CLAUSE_CODE (*pc1
) == OMP_CLAUSE_MAP
7481 && OMP_CLAUSE_MAP_IMPLICIT (*pc1
))
7484 pc2
= &OMP_CLAUSE_CHAIN (*pc2
);
7485 *pc1
= OMP_CLAUSE_CHAIN (*pc1
);
7488 pc1
= &OMP_CLAUSE_CHAIN (*pc1
);
7494 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7496 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7498 t
= OMP_CLAUSE_DECL (c
);
7499 if (!openacc
&& t
== current_class_ptr
)
7501 error_at (OMP_CLAUSE_LOCATION (c
),
7502 "%<this%> allowed in OpenMP only in %<declare simd%>"
7507 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
7508 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
7509 || TREE_CODE (t
) != FIELD_DECL
))
7511 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7514 error_at (OMP_CLAUSE_LOCATION (c
),
7515 "%qD is not a variable in clause %<firstprivate%>",
7518 error_at (OMP_CLAUSE_LOCATION (c
),
7519 "%qE is not a variable in clause %<firstprivate%>",
7523 else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
)
7524 && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c
)
7525 && bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
7527 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7528 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
7529 || bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
7531 error_at (OMP_CLAUSE_LOCATION (c
),
7532 "%qD appears more than once in data clauses", t
);
7535 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
7536 || bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7539 error_at (OMP_CLAUSE_LOCATION (c
),
7540 "%qD appears more than once in data clauses", t
);
7541 else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
)
7542 && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c
))
7543 /* Silently drop the clause. */;
7545 error_at (OMP_CLAUSE_LOCATION (c
),
7546 "%qD appears both in data and map clauses", t
);
7550 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
7551 goto handle_field_decl
;
7553 case OMP_CLAUSE_LASTPRIVATE
:
7554 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7556 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7558 t
= OMP_CLAUSE_DECL (c
);
7559 if (!openacc
&& t
== current_class_ptr
)
7561 error_at (OMP_CLAUSE_LOCATION (c
),
7562 "%<this%> allowed in OpenMP only in %<declare simd%>"
7567 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
7568 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
7569 || TREE_CODE (t
) != FIELD_DECL
))
7571 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7574 error_at (OMP_CLAUSE_LOCATION (c
),
7575 "%qD is not a variable in clause %<lastprivate%>",
7578 error_at (OMP_CLAUSE_LOCATION (c
),
7579 "%qE is not a variable in clause %<lastprivate%>",
7583 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7584 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
7586 error_at (OMP_CLAUSE_LOCATION (c
),
7587 "%qD appears more than once in data clauses", t
);
7591 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
7592 goto handle_field_decl
;
7595 case OMP_CLAUSE_SELF
:
7596 t
= OMP_CLAUSE_OPERAND (c
, 0);
7597 t
= maybe_convert_cond (t
);
7598 if (t
== error_mark_node
)
7600 else if (!processing_template_decl
)
7601 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7602 OMP_CLAUSE_OPERAND (c
, 0) = t
;
7605 case OMP_CLAUSE_FINAL
:
7606 t
= OMP_CLAUSE_FINAL_EXPR (c
);
7607 t
= maybe_convert_cond (t
);
7608 if (t
== error_mark_node
)
7610 else if (!processing_template_decl
)
7611 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7612 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
7615 case OMP_CLAUSE_GANG
:
7616 /* Operand 1 is the gang static: argument. */
7617 t
= OMP_CLAUSE_OPERAND (c
, 1);
7620 if (t
== error_mark_node
)
7622 else if (!type_dependent_expression_p (t
)
7623 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7625 error_at (OMP_CLAUSE_LOCATION (c
),
7626 "%<gang%> static expression must be integral");
7631 t
= mark_rvalue_use (t
);
7632 if (!processing_template_decl
)
7634 t
= maybe_constant_value (t
);
7635 if (TREE_CODE (t
) == INTEGER_CST
7636 && tree_int_cst_sgn (t
) != 1
7637 && t
!= integer_minus_one_node
)
7639 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7640 "%<gang%> static value must be "
7642 t
= integer_one_node
;
7644 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7647 OMP_CLAUSE_OPERAND (c
, 1) = t
;
7649 /* Check operand 0, the num argument. */
7652 case OMP_CLAUSE_WORKER
:
7653 case OMP_CLAUSE_VECTOR
:
7654 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
7658 case OMP_CLAUSE_NUM_TASKS
:
7659 case OMP_CLAUSE_NUM_TEAMS
:
7660 case OMP_CLAUSE_NUM_THREADS
:
7661 case OMP_CLAUSE_NUM_GANGS
:
7662 case OMP_CLAUSE_NUM_WORKERS
:
7663 case OMP_CLAUSE_VECTOR_LENGTH
:
7664 t
= OMP_CLAUSE_OPERAND (c
, 0);
7665 if (t
== error_mark_node
)
7667 else if (!type_dependent_expression_p (t
)
7668 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7670 switch (OMP_CLAUSE_CODE (c
))
7672 case OMP_CLAUSE_GANG
:
7673 error_at (OMP_CLAUSE_LOCATION (c
),
7674 "%<gang%> num expression must be integral"); break;
7675 case OMP_CLAUSE_VECTOR
:
7676 error_at (OMP_CLAUSE_LOCATION (c
),
7677 "%<vector%> length expression must be integral");
7679 case OMP_CLAUSE_WORKER
:
7680 error_at (OMP_CLAUSE_LOCATION (c
),
7681 "%<worker%> num expression must be integral");
7684 error_at (OMP_CLAUSE_LOCATION (c
),
7685 "%qs expression must be integral",
7686 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7692 t
= mark_rvalue_use (t
);
7693 if (!processing_template_decl
)
7695 t
= maybe_constant_value (t
);
7696 if (TREE_CODE (t
) == INTEGER_CST
7697 && tree_int_cst_sgn (t
) != 1)
7699 switch (OMP_CLAUSE_CODE (c
))
7701 case OMP_CLAUSE_GANG
:
7702 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7703 "%<gang%> num value must be positive");
7705 case OMP_CLAUSE_VECTOR
:
7706 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7707 "%<vector%> length value must be "
7710 case OMP_CLAUSE_WORKER
:
7711 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7712 "%<worker%> num value must be "
7716 warning_at (OMP_CLAUSE_LOCATION (c
),
7717 (flag_openmp
|| flag_openmp_simd
)
7719 "%qs value must be positive",
7720 omp_clause_code_name
7721 [OMP_CLAUSE_CODE (c
)]);
7723 t
= integer_one_node
;
7725 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7727 OMP_CLAUSE_OPERAND (c
, 0) = t
;
7729 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_NUM_TEAMS
7730 && OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c
)
7733 t
= OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c
);
7734 if (t
== error_mark_node
)
7736 else if (!type_dependent_expression_p (t
)
7737 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7739 error_at (OMP_CLAUSE_LOCATION (c
),
7740 "%qs expression must be integral",
7741 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7746 t
= mark_rvalue_use (t
);
7747 if (!processing_template_decl
)
7749 t
= maybe_constant_value (t
);
7750 if (TREE_CODE (t
) == INTEGER_CST
7751 && tree_int_cst_sgn (t
) != 1)
7753 warning_at (OMP_CLAUSE_LOCATION (c
), OPT_Wopenmp
,
7754 "%qs value must be positive",
7755 omp_clause_code_name
7756 [OMP_CLAUSE_CODE (c
)]);
7760 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7761 tree upper
= OMP_CLAUSE_NUM_TEAMS_UPPER_EXPR (c
);
7763 && TREE_CODE (t
) == INTEGER_CST
7764 && TREE_CODE (upper
) == INTEGER_CST
7765 && tree_int_cst_lt (upper
, t
))
7767 warning_at (OMP_CLAUSE_LOCATION (c
), OPT_Wopenmp
,
7768 "%<num_teams%> lower bound %qE bigger "
7769 "than upper bound %qE", t
, upper
);
7773 OMP_CLAUSE_NUM_TEAMS_LOWER_EXPR (c
) = t
;
7778 case OMP_CLAUSE_SCHEDULE
:
7779 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
7782 else if (t
== error_mark_node
)
7784 else if (!type_dependent_expression_p (t
)
7785 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7787 error_at (OMP_CLAUSE_LOCATION (c
),
7788 "schedule chunk size expression must be integral");
7793 t
= mark_rvalue_use (t
);
7794 if (!processing_template_decl
)
7796 t
= maybe_constant_value (t
);
7797 if (TREE_CODE (t
) == INTEGER_CST
7798 && tree_int_cst_sgn (t
) != 1)
7800 warning_at (OMP_CLAUSE_LOCATION (c
), OPT_Wopenmp
,
7801 "chunk size value must be positive");
7802 t
= integer_one_node
;
7804 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7806 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7809 schedule_seen
= true;
7812 case OMP_CLAUSE_SIMDLEN
:
7813 case OMP_CLAUSE_SAFELEN
:
7814 t
= OMP_CLAUSE_OPERAND (c
, 0);
7815 if (t
== error_mark_node
)
7817 else if (!type_dependent_expression_p (t
)
7818 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7820 error_at (OMP_CLAUSE_LOCATION (c
),
7821 "%qs length expression must be integral",
7822 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7827 t
= mark_rvalue_use (t
);
7828 if (!processing_template_decl
)
7830 t
= maybe_constant_value (t
);
7831 if (TREE_CODE (t
) != INTEGER_CST
7832 || tree_int_cst_sgn (t
) != 1)
7834 error_at (OMP_CLAUSE_LOCATION (c
),
7835 "%qs length expression must be positive "
7836 "constant integer expression",
7837 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7841 OMP_CLAUSE_OPERAND (c
, 0) = t
;
7842 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
7847 case OMP_CLAUSE_ASYNC
:
7848 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
7849 if (t
== error_mark_node
)
7851 else if (!type_dependent_expression_p (t
)
7852 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7854 error_at (OMP_CLAUSE_LOCATION (c
),
7855 "%<async%> expression must be integral");
7860 t
= mark_rvalue_use (t
);
7861 if (!processing_template_decl
)
7862 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7863 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
7867 case OMP_CLAUSE_WAIT
:
7868 t
= OMP_CLAUSE_WAIT_EXPR (c
);
7869 if (t
== error_mark_node
)
7871 else if (!processing_template_decl
)
7872 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7873 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
7876 case OMP_CLAUSE_THREAD_LIMIT
:
7877 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
7878 if (t
== error_mark_node
)
7880 else if (!type_dependent_expression_p (t
)
7881 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7883 error_at (OMP_CLAUSE_LOCATION (c
),
7884 "%<thread_limit%> expression must be integral");
7889 t
= mark_rvalue_use (t
);
7890 if (!processing_template_decl
)
7892 t
= maybe_constant_value (t
);
7893 if (TREE_CODE (t
) == INTEGER_CST
7894 && tree_int_cst_sgn (t
) != 1)
7896 warning_at (OMP_CLAUSE_LOCATION (c
), OPT_Wopenmp
,
7897 "%<thread_limit%> value must be positive");
7898 t
= integer_one_node
;
7900 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7902 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
7906 case OMP_CLAUSE_DEVICE
:
7907 t
= OMP_CLAUSE_DEVICE_ID (c
);
7908 if (t
== error_mark_node
)
7910 else if (!type_dependent_expression_p (t
)
7911 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7913 error_at (OMP_CLAUSE_LOCATION (c
),
7914 "%<device%> id must be integral");
7917 else if (OMP_CLAUSE_DEVICE_ANCESTOR (c
)
7918 && TREE_CODE (t
) == INTEGER_CST
7919 && !integer_onep (t
))
7921 error_at (OMP_CLAUSE_LOCATION (c
),
7922 "the %<device%> clause expression must evaluate to "
7928 t
= mark_rvalue_use (t
);
7929 if (!processing_template_decl
)
7930 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7931 OMP_CLAUSE_DEVICE_ID (c
) = t
;
7935 case OMP_CLAUSE_DIST_SCHEDULE
:
7936 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
7939 else if (t
== error_mark_node
)
7941 else if (!type_dependent_expression_p (t
)
7942 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7944 error_at (OMP_CLAUSE_LOCATION (c
),
7945 "%<dist_schedule%> chunk size expression must be "
7951 t
= mark_rvalue_use (t
);
7952 if (!processing_template_decl
)
7953 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7954 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
7958 case OMP_CLAUSE_ALIGNED
:
7959 t
= OMP_CLAUSE_DECL (c
);
7960 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
7962 error_at (OMP_CLAUSE_LOCATION (c
),
7963 "%<this%> allowed in OpenMP only in %<declare simd%>"
7968 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7970 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7973 error_at (OMP_CLAUSE_LOCATION (c
),
7974 "%qD is not a variable in %<aligned%> clause", t
);
7976 error_at (OMP_CLAUSE_LOCATION (c
),
7977 "%qE is not a variable in %<aligned%> clause", t
);
7980 else if (!type_dependent_expression_p (t
)
7981 && !TYPE_PTR_P (TREE_TYPE (t
))
7982 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
7983 && (!TYPE_REF_P (TREE_TYPE (t
))
7984 || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
7985 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
7988 error_at (OMP_CLAUSE_LOCATION (c
),
7989 "%qE in %<aligned%> clause is neither a pointer nor "
7990 "an array nor a reference to pointer or array", t
);
7993 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7995 error_at (OMP_CLAUSE_LOCATION (c
),
7996 "%qD appears more than once in %<aligned%> clauses",
8001 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
8002 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
8003 if (t
== error_mark_node
)
8005 else if (t
== NULL_TREE
)
8007 else if (!type_dependent_expression_p (t
)
8008 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8010 error_at (OMP_CLAUSE_LOCATION (c
),
8011 "%<aligned%> clause alignment expression must "
8017 t
= mark_rvalue_use (t
);
8018 if (!processing_template_decl
)
8020 t
= maybe_constant_value (t
);
8021 if (TREE_CODE (t
) != INTEGER_CST
8022 || tree_int_cst_sgn (t
) != 1)
8024 error_at (OMP_CLAUSE_LOCATION (c
),
8025 "%<aligned%> clause alignment expression must "
8026 "be positive constant integer expression");
8030 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8032 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
8036 case OMP_CLAUSE_NONTEMPORAL
:
8037 t
= OMP_CLAUSE_DECL (c
);
8038 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8040 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8043 error_at (OMP_CLAUSE_LOCATION (c
),
8044 "%qD is not a variable in %<nontemporal%> clause",
8047 error_at (OMP_CLAUSE_LOCATION (c
),
8048 "%qE is not a variable in %<nontemporal%> clause",
8052 else if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
8054 error_at (OMP_CLAUSE_LOCATION (c
),
8055 "%qD appears more than once in %<nontemporal%> "
8060 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
8063 case OMP_CLAUSE_ALLOCATE
:
8064 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8066 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
8068 t
= OMP_CLAUSE_DECL (c
);
8069 if (t
== current_class_ptr
)
8071 error_at (OMP_CLAUSE_LOCATION (c
),
8072 "%<this%> not allowed in %<allocate%> clause");
8077 && TREE_CODE (t
) != PARM_DECL
8078 && TREE_CODE (t
) != FIELD_DECL
)
8080 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8083 error_at (OMP_CLAUSE_LOCATION (c
),
8084 "%qD is not a variable in %<allocate%> clause", t
);
8086 error_at (OMP_CLAUSE_LOCATION (c
),
8087 "%qE is not a variable in %<allocate%> clause", t
);
8090 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
8092 warning_at (OMP_CLAUSE_LOCATION (c
), OPT_Wopenmp
,
8093 "%qD appears more than once in %<allocate%> clauses",
8099 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
8100 allocate_seen
= true;
8102 tree allocator
, align
;
8103 align
= OMP_CLAUSE_ALLOCATE_ALIGN (c
);
8104 if (error_operand_p (align
))
8111 if (!type_dependent_expression_p (align
)
8112 && !INTEGRAL_TYPE_P (TREE_TYPE (align
)))
8114 error_at (OMP_CLAUSE_LOCATION (c
),
8115 "%<allocate%> clause %<align%> modifier "
8116 "argument needs to be positive constant "
8117 "power of two integer expression");
8122 align
= mark_rvalue_use (align
);
8123 if (!processing_template_decl
)
8125 align
= maybe_constant_value (align
);
8126 if (TREE_CODE (align
) != INTEGER_CST
8127 || !tree_fits_uhwi_p (align
)
8128 || !integer_pow2p (align
))
8130 error_at (OMP_CLAUSE_LOCATION (c
),
8131 "%<allocate%> clause %<align%> modifier "
8132 "argument needs to be positive constant "
8133 "power of two integer expression");
8138 OMP_CLAUSE_ALLOCATE_ALIGN (c
) = align
;
8140 allocator
= OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
);
8141 if (error_operand_p (allocator
))
8146 if (allocator
== NULL_TREE
)
8147 goto handle_field_decl
;
8149 allocatort
= TYPE_MAIN_VARIANT (TREE_TYPE (allocator
));
8150 if (!type_dependent_expression_p (allocator
)
8151 && (TREE_CODE (allocatort
) != ENUMERAL_TYPE
8152 || TYPE_NAME (allocatort
) == NULL_TREE
8153 || TREE_CODE (TYPE_NAME (allocatort
)) != TYPE_DECL
8154 || (DECL_NAME (TYPE_NAME (allocatort
))
8155 != get_identifier ("omp_allocator_handle_t"))
8156 || (TYPE_CONTEXT (allocatort
)
8157 != DECL_CONTEXT (global_namespace
))))
8159 error_at (OMP_CLAUSE_LOCATION (c
),
8160 "%<allocate%> clause allocator expression has "
8161 "type %qT rather than %<omp_allocator_handle_t%>",
8162 TREE_TYPE (allocator
));
8168 allocator
= mark_rvalue_use (allocator
);
8169 if (!processing_template_decl
)
8170 allocator
= maybe_constant_value (allocator
);
8171 OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
) = allocator
;
8173 goto handle_field_decl
;
8175 case OMP_CLAUSE_DOACROSS
:
8176 t
= OMP_CLAUSE_DECL (c
);
8179 if (OMP_CLAUSE_DOACROSS_KIND (c
) == OMP_CLAUSE_DOACROSS_SINK
)
8181 if (cp_finish_omp_clause_doacross_sink (c
))
8186 case OMP_CLAUSE_DEPEND
:
8187 case OMP_CLAUSE_AFFINITY
:
8188 t
= OMP_CLAUSE_DECL (c
);
8189 if (TREE_CODE (t
) == TREE_LIST
8191 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
8193 if (TREE_PURPOSE (t
) != last_iterators
)
8194 last_iterators_remove
8195 = cp_omp_finish_iterators (TREE_PURPOSE (t
));
8196 last_iterators
= TREE_PURPOSE (t
);
8198 if (last_iterators_remove
)
8199 t
= error_mark_node
;
8202 last_iterators
= NULL_TREE
;
8204 if (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
8206 if (handle_omp_array_sections (c
, ort
))
8208 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
8209 && (OMP_CLAUSE_DEPEND_KIND (c
)
8210 == OMP_CLAUSE_DEPEND_DEPOBJ
))
8212 error_at (OMP_CLAUSE_LOCATION (c
),
8213 "%<depend%> clause with %<depobj%> dependence "
8214 "type on array section");
8219 if (t
== error_mark_node
)
8221 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
8222 && t
== ridpointers
[RID_OMP_ALL_MEMORY
])
8224 if (OMP_CLAUSE_DEPEND_KIND (c
) != OMP_CLAUSE_DEPEND_OUT
8225 && OMP_CLAUSE_DEPEND_KIND (c
) != OMP_CLAUSE_DEPEND_INOUT
)
8227 error_at (OMP_CLAUSE_LOCATION (c
),
8228 "%<omp_all_memory%> used with %<depend%> kind "
8229 "other than %<out%> or %<inout%>");
8232 if (processing_template_decl
)
8235 else if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8237 else if (!lvalue_p (t
))
8240 error_at (OMP_CLAUSE_LOCATION (c
),
8241 "%qD is not lvalue expression nor array section "
8243 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8245 error_at (OMP_CLAUSE_LOCATION (c
),
8246 "%qE is not lvalue expression nor array section "
8248 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8251 else if (TREE_CODE (t
) == COMPONENT_REF
8252 && TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
8253 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
8255 error_at (OMP_CLAUSE_LOCATION (c
),
8256 "bit-field %qE in %qs clause", t
,
8257 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8260 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
8261 && OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
8263 if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
8264 ? TREE_TYPE (TREE_TYPE (t
))
8267 error_at (OMP_CLAUSE_LOCATION (c
),
8268 "%qE does not have %<omp_depend_t%> type in "
8269 "%<depend%> clause with %<depobj%> dependence "
8274 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
8275 && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
8276 ? TREE_TYPE (TREE_TYPE (t
))
8279 error_at (OMP_CLAUSE_LOCATION (c
),
8280 "%qE should not have %<omp_depend_t%> type in "
8281 "%<depend%> clause with dependence type other than "
8287 if (t
== ridpointers
[RID_OMP_ALL_MEMORY
])
8288 t
= null_pointer_node
;
8291 tree addr
= cp_build_addr_expr (t
, tf_warning_or_error
);
8292 if (addr
== error_mark_node
)
8297 t
= cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c
),
8298 addr
, RO_UNARY_STAR
,
8299 tf_warning_or_error
);
8300 if (t
== error_mark_node
)
8306 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == TREE_LIST
8307 && TREE_PURPOSE (OMP_CLAUSE_DECL (c
))
8308 && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c
)))
8310 TREE_VALUE (OMP_CLAUSE_DECL (c
)) = t
;
8312 OMP_CLAUSE_DECL (c
) = t
;
8315 case OMP_CLAUSE_DETACH
:
8316 t
= OMP_CLAUSE_DECL (c
);
8319 error_at (OMP_CLAUSE_LOCATION (c
),
8320 "too many %qs clauses on a task construct",
8325 else if (error_operand_p (t
))
8332 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
8333 if (!type_dependent_expression_p (t
)
8334 && (!INTEGRAL_TYPE_P (type
)
8335 || TREE_CODE (type
) != ENUMERAL_TYPE
8336 || TYPE_NAME (type
) == NULL_TREE
8337 || (DECL_NAME (TYPE_NAME (type
))
8338 != get_identifier ("omp_event_handle_t"))))
8340 error_at (OMP_CLAUSE_LOCATION (c
),
8341 "%<detach%> clause event handle "
8342 "has type %qT rather than "
8343 "%<omp_event_handle_t%>",
8348 cxx_mark_addressable (t
);
8352 case OMP_CLAUSE_MAP
:
8353 if (OMP_CLAUSE_MAP_IMPLICIT (c
) && !implicit_moved
)
8357 case OMP_CLAUSE_FROM
:
8358 case OMP_CLAUSE__CACHE_
:
8360 using namespace omp_addr_tokenizer
;
8361 auto_vec
<omp_addr_token
*, 10> addr_tokens
;
8363 t
= OMP_CLAUSE_DECL (c
);
8364 if (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
8367 grp_sentinel
= OMP_CLAUSE_CHAIN (c
);
8369 if (handle_omp_array_sections (c
, ort
))
8373 t
= OMP_CLAUSE_DECL (c
);
8374 if (TREE_CODE (t
) != OMP_ARRAY_SECTION
8375 && !type_dependent_expression_p (t
)
8376 && !omp_mappable_type (TREE_TYPE (t
)))
8378 error_at (OMP_CLAUSE_LOCATION (c
),
8379 "array section does not have mappable type "
8381 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8382 if (TREE_TYPE (t
) != error_mark_node
8383 && !COMPLETE_TYPE_P (TREE_TYPE (t
)))
8384 cxx_incomplete_type_inform (TREE_TYPE (t
));
8387 while (TREE_CODE (t
) == ARRAY_REF
)
8388 t
= TREE_OPERAND (t
, 0);
8390 if (type_dependent_expression_p (t
))
8393 cp_omp_address_inspector
ai (OMP_CLAUSE_LOCATION (c
), t
);
8395 if (!ai
.map_supported_p ()
8396 || !omp_parse_expr (addr_tokens
, t
))
8398 sorry_at (OMP_CLAUSE_LOCATION (c
),
8399 "unsupported map expression %qE",
8400 OMP_CLAUSE_DECL (c
));
8405 /* This check is to determine if this will be the only map
8406 node created for this clause. Otherwise, we'll check
8407 the following FIRSTPRIVATE_POINTER,
8408 FIRSTPRIVATE_REFERENCE or ATTACH_DETACH node on the next
8409 iteration(s) of the loop. */
8410 if (addr_tokens
.length () >= 4
8411 && addr_tokens
[0]->type
== STRUCTURE_BASE
8412 && addr_tokens
[0]->u
.structure_base_kind
== BASE_DECL
8413 && addr_tokens
[1]->type
== ACCESS_METHOD
8414 && addr_tokens
[2]->type
== COMPONENT_SELECTOR
8415 && addr_tokens
[3]->type
== ACCESS_METHOD
8416 && (addr_tokens
[3]->u
.access_kind
== ACCESS_DIRECT
8417 || (addr_tokens
[3]->u
.access_kind
8418 == ACCESS_INDEXED_ARRAY
)))
8420 tree rt
= addr_tokens
[1]->expr
;
8422 gcc_assert (DECL_P (rt
));
8424 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8425 && OMP_CLAUSE_MAP_IMPLICIT (c
)
8426 && (bitmap_bit_p (&map_head
, DECL_UID (rt
))
8427 || bitmap_bit_p (&map_field_head
, DECL_UID (rt
))
8428 || bitmap_bit_p (&map_firstprivate_head
,
8434 if (bitmap_bit_p (&map_field_head
, DECL_UID (rt
)))
8436 if (bitmap_bit_p (&map_head
, DECL_UID (rt
)))
8438 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
8439 error_at (OMP_CLAUSE_LOCATION (c
),
8440 "%qD appears more than once in motion"
8443 error_at (OMP_CLAUSE_LOCATION (c
),
8444 "%qD appears more than once in data"
8447 error_at (OMP_CLAUSE_LOCATION (c
),
8448 "%qD appears more than once in map"
8454 bitmap_set_bit (&map_head
, DECL_UID (rt
));
8455 bitmap_set_bit (&map_field_head
, DECL_UID (rt
));
8459 if (cp_oacc_check_attachments (c
))
8461 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8462 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
8463 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
)
8464 && !OMP_CLAUSE_SIZE (c
))
8465 /* In this case, we have a single array element which is a
8466 pointer, and we already set OMP_CLAUSE_SIZE in
8467 handle_omp_array_sections above. For attach/detach
8468 clauses, reset the OMP_CLAUSE_SIZE (representing a bias)
8470 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
8473 else if (type_dependent_expression_p (t
))
8475 else if (!omp_parse_expr (addr_tokens
, t
))
8477 sorry_at (OMP_CLAUSE_LOCATION (c
),
8478 "unsupported map expression %qE",
8479 OMP_CLAUSE_DECL (c
));
8483 if (t
== error_mark_node
)
8488 /* OpenACC attach / detach clauses must be pointers. */
8489 if (cp_oacc_check_attachments (c
))
8494 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8495 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
8496 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
)
8497 && !OMP_CLAUSE_SIZE (c
))
8498 /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
8499 bias) to zero here, so it is not set erroneously to the
8500 pointer size later on in gimplify.cc. */
8501 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
8503 cp_omp_address_inspector
ai (OMP_CLAUSE_LOCATION (c
), t
);
8505 if (!ai
.check_clause (c
))
8511 if (!ai
.map_supported_p ())
8513 sorry_at (OMP_CLAUSE_LOCATION (c
),
8514 "unsupported map expression %qE",
8515 OMP_CLAUSE_DECL (c
));
8520 gcc_assert ((addr_tokens
[0]->type
== ARRAY_BASE
8521 || addr_tokens
[0]->type
== STRUCTURE_BASE
)
8522 && addr_tokens
[1]->type
== ACCESS_METHOD
);
8524 t
= addr_tokens
[1]->expr
;
8526 /* This is used to prevent cxx_mark_addressable from being called
8527 on 'this' for expressions like 'this->a', i.e. typical member
8529 indir_component_ref_p
8530 = (addr_tokens
[0]->type
== STRUCTURE_BASE
8531 && addr_tokens
[1]->u
.access_kind
!= ACCESS_DIRECT
);
8533 if (addr_tokens
[0]->u
.structure_base_kind
!= BASE_DECL
)
8534 goto skip_decl_checks
;
8536 /* For OpenMP, we can access a struct "t" and "t.d" on the same
8537 mapping. OpenACC allows multiple fields of the same structure
8539 if (addr_tokens
[0]->type
== STRUCTURE_BASE
8540 && (bitmap_bit_p (&map_field_head
, DECL_UID (t
))
8541 || (!openacc
&& bitmap_bit_p (&map_head
, DECL_UID (t
)))))
8542 goto skip_decl_checks
;
8544 if (!processing_template_decl
&& TREE_CODE (t
) == FIELD_DECL
)
8547 = finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
8550 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8552 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8554 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8555 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
8556 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
8557 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH_DETACH
8558 || (!openacc
&& EXPR_P (t
))))
8561 error_at (OMP_CLAUSE_LOCATION (c
),
8562 "%qD is not a variable in %qs clause", t
,
8563 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8565 error_at (OMP_CLAUSE_LOCATION (c
),
8566 "%qE is not a variable in %qs clause", t
,
8567 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8570 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
8572 error_at (OMP_CLAUSE_LOCATION (c
),
8573 "%qD is threadprivate variable in %qs clause", t
,
8574 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8577 else if (!processing_template_decl
8578 && !TYPE_REF_P (TREE_TYPE (t
))
8579 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
8580 || (OMP_CLAUSE_MAP_KIND (c
)
8581 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
8582 && !indir_component_ref_p
8583 && (t
!= current_class_ptr
8584 || OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
8585 || OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_ATTACH_DETACH
)
8586 && !cxx_mark_addressable (t
))
8588 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8589 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
8590 || (OMP_CLAUSE_MAP_KIND (c
)
8591 == GOMP_MAP_FIRSTPRIVATE_POINTER
)
8592 || (OMP_CLAUSE_MAP_KIND (c
)
8593 == GOMP_MAP_ATTACH_DETACH
)))
8594 && t
== OMP_CLAUSE_DECL (c
)
8595 && !type_dependent_expression_p (t
)
8596 && !omp_mappable_type (TYPE_REF_P (TREE_TYPE (t
))
8597 ? TREE_TYPE (TREE_TYPE (t
))
8600 error_at (OMP_CLAUSE_LOCATION (c
),
8601 "%qD does not have a mappable type in %qs clause", t
,
8602 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8603 if (TREE_TYPE (t
) != error_mark_node
8604 && !COMPLETE_TYPE_P (TREE_TYPE (t
)))
8605 cxx_incomplete_type_inform (TREE_TYPE (t
));
8608 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8609 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
8610 && !type_dependent_expression_p (t
)
8611 && !INDIRECT_TYPE_P (TREE_TYPE (t
)))
8613 error_at (OMP_CLAUSE_LOCATION (c
),
8614 "%qD is not a pointer variable", t
);
8617 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8618 && OMP_CLAUSE_MAP_IMPLICIT (c
)
8619 && (bitmap_bit_p (&map_head
, DECL_UID (t
))
8620 || bitmap_bit_p (&map_field_head
, DECL_UID (t
))
8621 || bitmap_bit_p (&map_firstprivate_head
,
8624 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8625 && (OMP_CLAUSE_MAP_KIND (c
)
8626 == GOMP_MAP_FIRSTPRIVATE_POINTER
))
8628 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
8629 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
8630 || bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
8632 error_at (OMP_CLAUSE_LOCATION (c
),
8633 "%qD appears more than once in data clauses", t
);
8636 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
8637 && !bitmap_bit_p (&map_field_head
, DECL_UID (t
))
8640 error_at (OMP_CLAUSE_LOCATION (c
),
8641 "%qD appears more than once in data clauses", t
);
8645 bitmap_set_bit (&map_firstprivate_head
, DECL_UID (t
));
8647 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
8648 && (OMP_CLAUSE_MAP_KIND (c
)
8649 == GOMP_MAP_FIRSTPRIVATE_REFERENCE
))
8650 bitmap_set_bit (&map_firstprivate_head
, DECL_UID (t
));
8651 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
8652 && !bitmap_bit_p (&map_field_head
, DECL_UID (t
))
8654 && ort
!= C_ORT_OMP_EXIT_DATA
)
8656 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
8657 error_at (OMP_CLAUSE_LOCATION (c
),
8658 "%qD appears more than once in motion clauses", t
);
8660 error_at (OMP_CLAUSE_LOCATION (c
),
8661 "%qD appears more than once in data clauses", t
);
8663 error_at (OMP_CLAUSE_LOCATION (c
),
8664 "%qD appears more than once in map clauses", t
);
8667 else if (openacc
&& bitmap_bit_p (&generic_head
, DECL_UID (t
)))
8669 error_at (OMP_CLAUSE_LOCATION (c
),
8670 "%qD appears more than once in data clauses", t
);
8673 else if (bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
8674 || bitmap_bit_p (&is_on_device_head
, DECL_UID (t
)))
8677 error_at (OMP_CLAUSE_LOCATION (c
),
8678 "%qD appears more than once in data clauses", t
);
8680 error_at (OMP_CLAUSE_LOCATION (c
),
8681 "%qD appears both in data and map clauses", t
);
8684 else if (!omp_access_chain_p (addr_tokens
, 1))
8686 bitmap_set_bit (&map_head
, DECL_UID (t
));
8688 tree decl
= OMP_CLAUSE_DECL (c
);
8690 && (TREE_CODE (decl
) == COMPONENT_REF
8691 || (INDIRECT_REF_P (decl
)
8692 && (TREE_CODE (TREE_OPERAND (decl
, 0))
8694 && TYPE_REF_P (TREE_TYPE (TREE_OPERAND (decl
,
8696 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
8700 /* If we call ai.expand_map_clause in handle_omp_array_sections,
8701 the containing loop (here) iterates through the new nodes
8702 created by that expansion. Avoid expanding those again (just
8703 by checking the node type). */
8705 && !processing_template_decl
8706 && ort
!= C_ORT_DECLARE_SIMD
8707 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
8708 || (OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_FIRSTPRIVATE_POINTER
8709 && (OMP_CLAUSE_MAP_KIND (c
)
8710 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
8711 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_ALWAYS_POINTER
8712 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_ATTACH_DETACH
8713 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_ATTACH
8714 && OMP_CLAUSE_MAP_KIND (c
) != GOMP_MAP_DETACH
)))
8717 grp_sentinel
= OMP_CLAUSE_CHAIN (c
);
8718 tree nc
= ai
.expand_map_clause (c
, OMP_CLAUSE_DECL (c
),
8720 if (nc
!= error_mark_node
)
8726 case OMP_CLAUSE_ENTER
:
8727 case OMP_CLAUSE_LINK
:
8728 t
= OMP_CLAUSE_DECL (c
);
8730 cname
= omp_clause_code_name
[OMP_CLAUSE_CODE (c
)];
8731 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ENTER
8732 && OMP_CLAUSE_ENTER_TO (c
))
8734 if (TREE_CODE (t
) == FUNCTION_DECL
8735 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ENTER
)
8737 else if (!VAR_P (t
))
8739 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ENTER
)
8741 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
8742 error_at (OMP_CLAUSE_LOCATION (c
),
8743 "template %qE in clause %qs", t
, cname
);
8744 else if (really_overloaded_fn (t
))
8745 error_at (OMP_CLAUSE_LOCATION (c
),
8746 "overloaded function name %qE in clause %qs", t
,
8749 error_at (OMP_CLAUSE_LOCATION (c
),
8750 "%qE is neither a variable nor a function name "
8751 "in clause %qs", t
, cname
);
8754 error_at (OMP_CLAUSE_LOCATION (c
),
8755 "%qE is not a variable in clause %qs", t
, cname
);
8758 else if (DECL_THREAD_LOCAL_P (t
))
8760 error_at (OMP_CLAUSE_LOCATION (c
),
8761 "%qD is threadprivate variable in %qs clause", t
,
8765 else if (!omp_mappable_type (TREE_TYPE (t
)))
8767 error_at (OMP_CLAUSE_LOCATION (c
),
8768 "%qD does not have a mappable type in %qs clause", t
,
8770 if (TREE_TYPE (t
) != error_mark_node
8771 && !COMPLETE_TYPE_P (TREE_TYPE (t
)))
8772 cxx_incomplete_type_inform (TREE_TYPE (t
));
8777 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
8779 error_at (OMP_CLAUSE_LOCATION (c
),
8780 "%qE appears more than once on the same "
8781 "%<declare target%> directive", t
);
8785 bitmap_set_bit (&generic_head
, DECL_UID (t
));
8788 case OMP_CLAUSE_UNIFORM
:
8789 t
= OMP_CLAUSE_DECL (c
);
8790 if (TREE_CODE (t
) != PARM_DECL
)
8792 if (processing_template_decl
)
8795 error_at (OMP_CLAUSE_LOCATION (c
),
8796 "%qD is not an argument in %<uniform%> clause", t
);
8798 error_at (OMP_CLAUSE_LOCATION (c
),
8799 "%qE is not an argument in %<uniform%> clause", t
);
8803 /* map_head bitmap is used as uniform_head if declare_simd. */
8804 bitmap_set_bit (&map_head
, DECL_UID (t
));
8805 goto check_dup_generic
;
8807 case OMP_CLAUSE_GRAINSIZE
:
8808 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
8809 if (t
== error_mark_node
)
8811 else if (!type_dependent_expression_p (t
)
8812 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8814 error_at (OMP_CLAUSE_LOCATION (c
),
8815 "%<grainsize%> expression must be integral");
8820 t
= mark_rvalue_use (t
);
8821 if (!processing_template_decl
)
8823 t
= maybe_constant_value (t
);
8824 if (TREE_CODE (t
) == INTEGER_CST
8825 && tree_int_cst_sgn (t
) != 1)
8827 warning_at (OMP_CLAUSE_LOCATION (c
), OPT_Wopenmp
,
8828 "%<grainsize%> value must be positive");
8829 t
= integer_one_node
;
8831 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8833 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
8837 case OMP_CLAUSE_PRIORITY
:
8838 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
8839 if (t
== error_mark_node
)
8841 else if (!type_dependent_expression_p (t
)
8842 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8844 error_at (OMP_CLAUSE_LOCATION (c
),
8845 "%<priority%> expression must be integral");
8850 t
= mark_rvalue_use (t
);
8851 if (!processing_template_decl
)
8853 t
= maybe_constant_value (t
);
8854 if (TREE_CODE (t
) == INTEGER_CST
8855 && tree_int_cst_sgn (t
) == -1)
8857 warning_at (OMP_CLAUSE_LOCATION (c
), OPT_Wopenmp
,
8858 "%<priority%> value must be non-negative");
8859 t
= integer_one_node
;
8861 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8863 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
8867 case OMP_CLAUSE_HINT
:
8868 t
= OMP_CLAUSE_HINT_EXPR (c
);
8869 if (t
== error_mark_node
)
8871 else if (!type_dependent_expression_p (t
)
8872 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8874 error_at (OMP_CLAUSE_LOCATION (c
),
8875 "%<hint%> expression must be integral");
8880 t
= mark_rvalue_use (t
);
8881 if (!processing_template_decl
)
8883 t
= maybe_constant_value (t
);
8884 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8885 if (TREE_CODE (t
) != INTEGER_CST
)
8887 error_at (OMP_CLAUSE_LOCATION (c
),
8888 "%<hint%> expression must be constant integer "
8893 OMP_CLAUSE_HINT_EXPR (c
) = t
;
8897 case OMP_CLAUSE_FILTER
:
8898 t
= OMP_CLAUSE_FILTER_EXPR (c
);
8899 if (t
== error_mark_node
)
8901 else if (!type_dependent_expression_p (t
)
8902 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8904 error_at (OMP_CLAUSE_LOCATION (c
),
8905 "%<filter%> expression must be integral");
8910 t
= mark_rvalue_use (t
);
8911 if (!processing_template_decl
)
8913 t
= maybe_constant_value (t
);
8914 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8916 OMP_CLAUSE_FILTER_EXPR (c
) = t
;
8920 case OMP_CLAUSE_IS_DEVICE_PTR
:
8921 case OMP_CLAUSE_USE_DEVICE_PTR
:
8922 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
8923 t
= OMP_CLAUSE_DECL (c
);
8924 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IS_DEVICE_PTR
)
8925 bitmap_set_bit (&is_on_device_head
, DECL_UID (t
));
8926 if (!type_dependent_expression_p (t
))
8928 tree type
= TREE_TYPE (t
);
8929 if (!TYPE_PTR_P (type
)
8930 && (!TYPE_REF_P (type
) || !TYPE_PTR_P (TREE_TYPE (type
))))
8932 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
8933 && ort
== C_ORT_OMP
)
8935 error_at (OMP_CLAUSE_LOCATION (c
),
8936 "%qs variable is neither a pointer "
8937 "nor reference to pointer",
8938 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8941 else if (TREE_CODE (type
) != ARRAY_TYPE
8942 && (!TYPE_REF_P (type
)
8943 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
8945 error_at (OMP_CLAUSE_LOCATION (c
),
8946 "%qs variable is neither a pointer, nor an "
8947 "array nor reference to pointer or array",
8948 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8953 goto check_dup_generic
;
8955 case OMP_CLAUSE_HAS_DEVICE_ADDR
:
8956 t
= OMP_CLAUSE_DECL (c
);
8957 if (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
8959 if (handle_omp_array_sections (c
, ort
))
8963 t
= OMP_CLAUSE_DECL (c
);
8964 while (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
8965 t
= TREE_OPERAND (t
, 0);
8966 while (INDIRECT_REF_P (t
)
8967 || TREE_CODE (t
) == ARRAY_REF
)
8968 t
= TREE_OPERAND (t
, 0);
8971 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
8973 bitmap_set_bit (&is_on_device_head
, DECL_UID (t
));
8974 if (!processing_template_decl
8975 && !cxx_mark_addressable (t
))
8978 goto check_dup_generic_t
;
8980 case OMP_CLAUSE_USE_DEVICE_ADDR
:
8982 t
= OMP_CLAUSE_DECL (c
);
8983 if (!processing_template_decl
8984 && (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
8985 && !TYPE_REF_P (TREE_TYPE (t
))
8986 && !cxx_mark_addressable (t
))
8988 goto check_dup_generic
;
8990 case OMP_CLAUSE_NOWAIT
:
8991 case OMP_CLAUSE_DEFAULT
:
8992 case OMP_CLAUSE_UNTIED
:
8993 case OMP_CLAUSE_COLLAPSE
:
8994 case OMP_CLAUSE_PARALLEL
:
8995 case OMP_CLAUSE_FOR
:
8996 case OMP_CLAUSE_SECTIONS
:
8997 case OMP_CLAUSE_TASKGROUP
:
8998 case OMP_CLAUSE_PROC_BIND
:
8999 case OMP_CLAUSE_DEVICE_TYPE
:
9000 case OMP_CLAUSE_NOGROUP
:
9001 case OMP_CLAUSE_THREADS
:
9002 case OMP_CLAUSE_SIMD
:
9003 case OMP_CLAUSE_DEFAULTMAP
:
9004 case OMP_CLAUSE_BIND
:
9005 case OMP_CLAUSE_AUTO
:
9006 case OMP_CLAUSE_INDEPENDENT
:
9007 case OMP_CLAUSE_SEQ
:
9008 case OMP_CLAUSE_IF_PRESENT
:
9009 case OMP_CLAUSE_FINALIZE
:
9010 case OMP_CLAUSE_NOHOST
:
9011 case OMP_CLAUSE_INDIRECT
:
9014 case OMP_CLAUSE_MERGEABLE
:
9015 mergeable_seen
= true;
9018 case OMP_CLAUSE_TILE
:
9019 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
9020 list
= TREE_CHAIN (list
))
9022 t
= TREE_VALUE (list
);
9024 if (t
== error_mark_node
)
9026 else if (!type_dependent_expression_p (t
)
9027 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
9029 error_at (OMP_CLAUSE_LOCATION (c
),
9030 "%<tile%> argument needs integral type");
9035 t
= mark_rvalue_use (t
);
9036 if (!processing_template_decl
)
9038 /* Zero is used to indicate '*', we permit you
9039 to get there via an ICE of value zero. */
9040 t
= maybe_constant_value (t
);
9041 if (!tree_fits_shwi_p (t
)
9042 || tree_to_shwi (t
) < 0)
9044 error_at (OMP_CLAUSE_LOCATION (c
),
9045 "%<tile%> argument needs positive "
9046 "integral constant");
9049 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9053 /* Update list item. */
9054 TREE_VALUE (list
) = t
;
9058 case OMP_CLAUSE_ORDERED
:
9059 ordered_seen
= true;
9062 case OMP_CLAUSE_ORDER
:
9069 case OMP_CLAUSE_INBRANCH
:
9070 case OMP_CLAUSE_NOTINBRANCH
:
9073 error_at (OMP_CLAUSE_LOCATION (c
),
9074 "%<inbranch%> clause is incompatible with "
9081 case OMP_CLAUSE_INCLUSIVE
:
9082 case OMP_CLAUSE_EXCLUSIVE
:
9083 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
9085 t
= OMP_CLAUSE_DECL (c
);
9086 if (t
== current_class_ptr
)
9088 error_at (OMP_CLAUSE_LOCATION (c
),
9089 "%<this%> allowed in OpenMP only in %<declare simd%>"
9095 && TREE_CODE (t
) != PARM_DECL
9096 && TREE_CODE (t
) != FIELD_DECL
)
9098 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
9101 error_at (OMP_CLAUSE_LOCATION (c
),
9102 "%qD is not a variable in clause %qs", t
,
9103 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
9105 error_at (OMP_CLAUSE_LOCATION (c
),
9106 "%qE is not a variable in clause %qs", t
,
9107 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
9120 /* If we found a clause to remove, we want to remove the whole
9121 expanded group, otherwise gimplify
9122 (omp_resolve_clause_dependencies) can get confused. */
9123 *grp_start_p
= grp_sentinel
;
9128 *pc
= OMP_CLAUSE_CHAIN (c
);
9131 pc
= &OMP_CLAUSE_CHAIN (c
);
9134 if (reduction_seen
< 0 && (ordered_seen
|| schedule_seen
))
9135 reduction_seen
= -2;
9137 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
9139 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
9140 bool remove
= false;
9141 bool need_complete_type
= false;
9142 bool need_default_ctor
= false;
9143 bool need_copy_ctor
= false;
9144 bool need_copy_assignment
= false;
9145 bool need_implicitly_determined
= false;
9146 bool need_dtor
= false;
9147 tree type
, inner_type
;
9151 case OMP_CLAUSE_SHARED
:
9152 need_implicitly_determined
= true;
9154 case OMP_CLAUSE_PRIVATE
:
9155 need_complete_type
= true;
9156 need_default_ctor
= true;
9158 need_implicitly_determined
= true;
9160 case OMP_CLAUSE_FIRSTPRIVATE
:
9161 need_complete_type
= true;
9162 need_copy_ctor
= true;
9164 need_implicitly_determined
= true;
9166 case OMP_CLAUSE_LASTPRIVATE
:
9167 need_complete_type
= true;
9168 need_copy_assignment
= true;
9169 need_implicitly_determined
= true;
9171 case OMP_CLAUSE_REDUCTION
:
9172 if (reduction_seen
== -2)
9173 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
9174 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
9175 need_copy_assignment
= true;
9176 need_implicitly_determined
= true;
9178 case OMP_CLAUSE_IN_REDUCTION
:
9179 case OMP_CLAUSE_TASK_REDUCTION
:
9180 case OMP_CLAUSE_INCLUSIVE
:
9181 case OMP_CLAUSE_EXCLUSIVE
:
9182 need_implicitly_determined
= true;
9184 case OMP_CLAUSE_LINEAR
:
9185 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
9186 need_implicitly_determined
= true;
9187 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
9188 && !bitmap_bit_p (&map_head
,
9189 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
9191 error_at (OMP_CLAUSE_LOCATION (c
),
9192 "%<linear%> clause step is a parameter %qD not "
9193 "specified in %<uniform%> clause",
9194 OMP_CLAUSE_LINEAR_STEP (c
));
9195 *pc
= OMP_CLAUSE_CHAIN (c
);
9199 case OMP_CLAUSE_COPYPRIVATE
:
9200 need_copy_assignment
= true;
9202 case OMP_CLAUSE_COPYIN
:
9203 need_copy_assignment
= true;
9205 case OMP_CLAUSE_SIMDLEN
:
9207 && !processing_template_decl
9208 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
9209 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
9211 error_at (OMP_CLAUSE_LOCATION (c
),
9212 "%<simdlen%> clause value is bigger than "
9213 "%<safelen%> clause value");
9214 OMP_CLAUSE_SIMDLEN_EXPR (c
)
9215 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
9217 pc
= &OMP_CLAUSE_CHAIN (c
);
9219 case OMP_CLAUSE_SCHEDULE
:
9221 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
9222 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
9224 error_at (OMP_CLAUSE_LOCATION (c
),
9225 "%<nonmonotonic%> schedule modifier specified "
9226 "together with %<ordered%> clause");
9227 OMP_CLAUSE_SCHEDULE_KIND (c
)
9228 = (enum omp_clause_schedule_kind
)
9229 (OMP_CLAUSE_SCHEDULE_KIND (c
)
9230 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
9232 if (reduction_seen
== -2)
9233 error_at (OMP_CLAUSE_LOCATION (c
),
9234 "%qs clause specified together with %<inscan%> "
9235 "%<reduction%> clause", "schedule");
9236 pc
= &OMP_CLAUSE_CHAIN (c
);
9238 case OMP_CLAUSE_NOGROUP
:
9241 error_at (OMP_CLAUSE_LOCATION (c
),
9242 "%<nogroup%> clause must not be used together with "
9243 "%<reduction%> clause");
9244 *pc
= OMP_CLAUSE_CHAIN (c
);
9247 pc
= &OMP_CLAUSE_CHAIN (c
);
9249 case OMP_CLAUSE_ORDERED
:
9250 if (reduction_seen
== -2)
9251 error_at (OMP_CLAUSE_LOCATION (c
),
9252 "%qs clause specified together with %<inscan%> "
9253 "%<reduction%> clause", "ordered");
9254 pc
= &OMP_CLAUSE_CHAIN (c
);
9256 case OMP_CLAUSE_ORDER
:
9259 error_at (OMP_CLAUSE_LOCATION (c
),
9260 "%<order%> clause must not be used together "
9261 "with %<ordered%>");
9262 *pc
= OMP_CLAUSE_CHAIN (c
);
9265 pc
= &OMP_CLAUSE_CHAIN (c
);
9267 case OMP_CLAUSE_DETACH
:
9270 error_at (OMP_CLAUSE_LOCATION (c
),
9271 "%<detach%> clause must not be used together with "
9272 "%<mergeable%> clause");
9273 *pc
= OMP_CLAUSE_CHAIN (c
);
9276 pc
= &OMP_CLAUSE_CHAIN (c
);
9278 case OMP_CLAUSE_MAP
:
9279 if (target_in_reduction_seen
&& !processing_template_decl
)
9281 t
= OMP_CLAUSE_DECL (c
);
9282 while (handled_component_p (t
)
9283 || INDIRECT_REF_P (t
)
9284 || TREE_CODE (t
) == ADDR_EXPR
9285 || TREE_CODE (t
) == MEM_REF
9286 || TREE_CODE (t
) == NON_LVALUE_EXPR
)
9287 t
= TREE_OPERAND (t
, 0);
9289 && bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
9290 OMP_CLAUSE_MAP_IN_REDUCTION (c
) = 1;
9292 pc
= &OMP_CLAUSE_CHAIN (c
);
9294 case OMP_CLAUSE_NOWAIT
:
9295 if (copyprivate_seen
)
9297 error_at (OMP_CLAUSE_LOCATION (c
),
9298 "%<nowait%> clause must not be used together "
9299 "with %<copyprivate%>");
9300 *pc
= OMP_CLAUSE_CHAIN (c
);
9305 pc
= &OMP_CLAUSE_CHAIN (c
);
9309 t
= OMP_CLAUSE_DECL (c
);
9312 case OMP_CLAUSE_LASTPRIVATE
:
9314 && !bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
9316 need_default_ctor
= true;
9321 case OMP_CLAUSE_REDUCTION
:
9322 case OMP_CLAUSE_IN_REDUCTION
:
9323 case OMP_CLAUSE_TASK_REDUCTION
:
9326 if (TREE_CODE (t
) == MEM_REF
)
9328 t
= TREE_OPERAND (t
, 0);
9329 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
9330 t
= TREE_OPERAND (t
, 0);
9331 if (TREE_CODE (t
) == ADDR_EXPR
9332 || INDIRECT_REF_P (t
))
9333 t
= TREE_OPERAND (t
, 0);
9335 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
9337 else if (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
9339 while (TREE_CODE (t
) == OMP_ARRAY_SECTION
)
9340 t
= TREE_OPERAND (t
, 0);
9342 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
9343 t
= OMP_CLAUSE_DECL (c
);
9345 else if (DECL_P (t
))
9346 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
9347 t
= OMP_CLAUSE_DECL (c
);
9349 if (processing_template_decl
9350 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
9352 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
9356 t
= OMP_CLAUSE_DECL (c
);
9359 case OMP_CLAUSE_COPYIN
:
9360 if (processing_template_decl
9361 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
9363 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
9365 error_at (OMP_CLAUSE_LOCATION (c
),
9366 "%qE must be %<threadprivate%> for %<copyin%>", t
);
9375 if (processing_template_decl
9376 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
9378 pc
= &OMP_CLAUSE_CHAIN (c
);
9382 if (need_complete_type
|| need_copy_assignment
)
9384 t
= require_complete_type (t
);
9385 if (t
== error_mark_node
)
9387 else if (!processing_template_decl
9388 && TYPE_REF_P (TREE_TYPE (t
))
9389 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
9392 if (need_implicitly_determined
)
9394 const char *share_name
= NULL
;
9397 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
9399 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
9401 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
9402 share_name
= "threadprivate";
9403 else switch (cxx_omp_predetermined_sharing_1 (t
))
9405 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
9407 case OMP_CLAUSE_DEFAULT_SHARED
:
9408 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
9409 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
9410 && c_omp_predefined_variable (t
))
9411 /* The __func__ variable and similar function-local predefined
9412 variables may be listed in a shared or firstprivate
9416 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
9418 && cxx_omp_const_qual_no_mutable (t
))
9420 tree ctx
= CP_DECL_CONTEXT (t
);
9421 /* const qualified static data members without mutable
9422 member may be specified in firstprivate clause. */
9423 if (TYPE_P (ctx
) && MAYBE_CLASS_TYPE_P (ctx
))
9426 share_name
= "shared";
9428 case OMP_CLAUSE_DEFAULT_PRIVATE
:
9429 share_name
= "private";
9436 error_at (OMP_CLAUSE_LOCATION (c
),
9437 "%qE is predetermined %qs for %qs",
9438 omp_clause_printable_decl (t
), share_name
,
9439 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
9442 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
9443 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_FIRSTPRIVATE
9444 && cxx_omp_const_qual_no_mutable (t
))
9446 error_at (OMP_CLAUSE_LOCATION (c
),
9447 "%<const%> qualified %qE without %<mutable%> member "
9448 "may appear only in %<shared%> or %<firstprivate%> "
9449 "clauses", omp_clause_printable_decl (t
));
9455 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
9456 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
9457 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
9458 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
9459 && OMP_CLAUSE_DECL (c
) == OMP_CLAUSE_DECL (detach_seen
))
9461 error_at (OMP_CLAUSE_LOCATION (c
),
9462 "the event handle of a %<detach%> clause "
9463 "should not be in a data-sharing clause");
9467 /* We're interested in the base element, not arrays. */
9468 inner_type
= type
= TREE_TYPE (t
);
9469 if ((need_complete_type
9470 || need_copy_assignment
9471 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
9472 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
9473 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
9474 && TYPE_REF_P (inner_type
))
9475 inner_type
= TREE_TYPE (inner_type
);
9476 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
9477 inner_type
= TREE_TYPE (inner_type
);
9479 /* Check for special function availability by building a call to one.
9480 Save the results, because later we won't be in the right context
9481 for making these queries. */
9482 if (CLASS_TYPE_P (inner_type
)
9483 && COMPLETE_TYPE_P (inner_type
)
9484 && (need_default_ctor
|| need_copy_ctor
9485 || need_copy_assignment
|| need_dtor
)
9486 && !type_dependent_expression_p (t
)
9487 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
9488 need_copy_ctor
, need_copy_assignment
,
9493 && c_kind
== OMP_CLAUSE_SHARED
9494 && processing_template_decl
)
9496 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
9498 OMP_CLAUSE_DECL (c
) = t
;
9502 *pc
= OMP_CLAUSE_CHAIN (c
);
9504 pc
= &OMP_CLAUSE_CHAIN (c
);
9508 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
9510 bool remove
= false;
9511 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ALLOCATE
9512 && !OMP_CLAUSE_ALLOCATE_COMBINED (c
)
9513 && DECL_P (OMP_CLAUSE_DECL (c
))
9514 && bitmap_bit_p (&aligned_head
, DECL_UID (OMP_CLAUSE_DECL (c
))))
9516 error_at (OMP_CLAUSE_LOCATION (c
),
9517 "%qD specified in %<allocate%> clause but not in "
9518 "an explicit privatization clause", OMP_CLAUSE_DECL (c
));
9522 *pc
= OMP_CLAUSE_CHAIN (c
);
9524 pc
= &OMP_CLAUSE_CHAIN (c
);
9527 bitmap_obstack_release (NULL
);
9531 /* Start processing OpenMP clauses that can include any
9532 privatization clauses for non-static data members. */
9535 push_omp_privatization_clauses (bool ignore_next
)
9537 if (omp_private_member_ignore_next
)
9539 omp_private_member_ignore_next
= ignore_next
;
9542 omp_private_member_ignore_next
= ignore_next
;
9543 if (omp_private_member_map
)
9544 omp_private_member_vec
.safe_push (error_mark_node
);
9545 return push_stmt_list ();
9548 /* Revert remapping of any non-static data members since
9549 the last push_omp_privatization_clauses () call. */
9552 pop_omp_privatization_clauses (tree stmt
)
9554 if (stmt
== NULL_TREE
)
9556 stmt
= pop_stmt_list (stmt
);
9557 if (omp_private_member_map
)
9559 while (!omp_private_member_vec
.is_empty ())
9561 tree t
= omp_private_member_vec
.pop ();
9562 if (t
== error_mark_node
)
9567 bool no_decl_expr
= t
== integer_zero_node
;
9569 t
= omp_private_member_vec
.pop ();
9570 tree
*v
= omp_private_member_map
->get (t
);
9574 omp_private_member_map
->remove (t
);
9576 delete omp_private_member_map
;
9577 omp_private_member_map
= NULL
;
9582 /* Remember OpenMP privatization clauses mapping and clear it.
9583 Used for lambdas. */
9586 save_omp_privatization_clauses (vec
<tree
> &save
)
9589 if (omp_private_member_ignore_next
)
9590 save
.safe_push (integer_one_node
);
9591 omp_private_member_ignore_next
= false;
9592 if (!omp_private_member_map
)
9595 while (!omp_private_member_vec
.is_empty ())
9597 tree t
= omp_private_member_vec
.pop ();
9598 if (t
== error_mark_node
)
9604 if (t
== integer_zero_node
)
9605 t
= omp_private_member_vec
.pop ();
9606 tree
*v
= omp_private_member_map
->get (t
);
9608 save
.safe_push (*v
);
9613 delete omp_private_member_map
;
9614 omp_private_member_map
= NULL
;
9617 /* Restore OpenMP privatization clauses mapping saved by the
9621 restore_omp_privatization_clauses (vec
<tree
> &save
)
9623 gcc_assert (omp_private_member_vec
.is_empty ());
9624 omp_private_member_ignore_next
= false;
9625 if (save
.is_empty ())
9627 if (save
.length () == 1 && save
[0] == integer_one_node
)
9629 omp_private_member_ignore_next
= true;
9634 omp_private_member_map
= new hash_map
<tree
, tree
>;
9635 while (!save
.is_empty ())
9637 tree t
= save
.pop ();
9639 if (t
!= error_mark_node
)
9641 if (t
== integer_one_node
)
9643 omp_private_member_ignore_next
= true;
9644 gcc_assert (save
.is_empty ());
9647 if (t
== integer_zero_node
)
9649 tree
&v
= omp_private_member_map
->get_or_insert (t
);
9652 omp_private_member_vec
.safe_push (t
);
9654 omp_private_member_vec
.safe_push (n
);
9659 /* For all variables in the tree_list VARS, mark them as thread local. */
9662 finish_omp_threadprivate (tree vars
)
9666 /* Mark every variable in VARS to be assigned thread local storage. */
9667 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
9669 tree v
= TREE_PURPOSE (t
);
9671 if (error_operand_p (v
))
9673 else if (!VAR_P (v
))
9674 error ("%<threadprivate%> %qD is not file, namespace "
9675 "or block scope variable", v
);
9676 /* If V had already been marked threadprivate, it doesn't matter
9677 whether it had been used prior to this point. */
9678 else if (TREE_USED (v
)
9679 && (DECL_LANG_SPECIFIC (v
) == NULL
9680 || !CP_DECL_THREADPRIVATE_P (v
)))
9681 error ("%qE declared %<threadprivate%> after first use", v
);
9682 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
9683 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
9684 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
9685 error ("%<threadprivate%> %qE has incomplete type", v
);
9686 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
9687 && CP_DECL_CONTEXT (v
) != current_class_type
)
9688 error ("%<threadprivate%> %qE directive not "
9689 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
9692 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
9693 if (DECL_LANG_SPECIFIC (v
) == NULL
)
9694 retrofit_lang_decl (v
);
9696 if (! CP_DECL_THREAD_LOCAL_P (v
))
9698 CP_DECL_THREAD_LOCAL_P (v
) = true;
9699 set_decl_tls_model (v
, decl_default_tls_model (v
));
9700 /* If rtl has been already set for this var, call
9701 make_decl_rtl once again, so that encode_section_info
9702 has a chance to look at the new decl flags. */
9703 if (DECL_RTL_SET_P (v
))
9706 CP_DECL_THREADPRIVATE_P (v
) = 1;
9711 /* Build an OpenMP structured block. */
9714 begin_omp_structured_block (void)
9716 return do_pushlevel (sk_omp
);
9720 finish_omp_structured_block (tree block
)
9722 return do_poplevel (block
);
9725 /* Similarly, except force the retention of the BLOCK. */
9728 begin_omp_parallel (void)
9730 keep_next_level (true);
9731 return begin_omp_structured_block ();
9734 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
9738 finish_oacc_data (tree clauses
, tree block
)
9742 block
= finish_omp_structured_block (block
);
9744 stmt
= make_node (OACC_DATA
);
9745 TREE_TYPE (stmt
) = void_type_node
;
9746 OACC_DATA_CLAUSES (stmt
) = clauses
;
9747 OACC_DATA_BODY (stmt
) = block
;
9749 return add_stmt (stmt
);
9752 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
9756 finish_oacc_host_data (tree clauses
, tree block
)
9760 block
= finish_omp_structured_block (block
);
9762 stmt
= make_node (OACC_HOST_DATA
);
9763 TREE_TYPE (stmt
) = void_type_node
;
9764 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
9765 OACC_HOST_DATA_BODY (stmt
) = block
;
9767 return add_stmt (stmt
);
9770 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
9774 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
9776 body
= finish_omp_structured_block (body
);
9778 tree stmt
= make_node (code
);
9779 TREE_TYPE (stmt
) = void_type_node
;
9780 OMP_BODY (stmt
) = body
;
9781 OMP_CLAUSES (stmt
) = clauses
;
9783 return add_stmt (stmt
);
9786 /* Used to walk OpenMP target directive body. */
9788 struct omp_target_walk_data
9790 /* Holds the 'this' expression found in current function. */
9791 tree current_object
;
9793 /* True if the 'this' expression was accessed in the target body. */
9794 bool this_expr_accessed
;
9796 /* For non-static functions, record which pointer-typed members were
9797 accessed, and the whole expression. */
9798 hash_map
<tree
, tree
> ptr_members_accessed
;
9800 /* Record which lambda objects were accessed in target body. */
9801 hash_set
<tree
> lambda_objects_accessed
;
9803 /* For lambda functions, the __closure object expression of the current
9804 function, and the set of captured variables accessed in target body. */
9805 tree current_closure
;
9806 hash_set
<tree
> closure_vars_accessed
;
9808 /* Local variables declared inside a BIND_EXPR, used to filter out such
9809 variables when recording lambda_objects_accessed. */
9810 hash_set
<tree
> local_decls
;
9813 /* Helper function of finish_omp_target_clauses, called via
9814 cp_walk_tree_without_duplicates. Traverse body of OpenMP target
9815 directive *TP, and fill out omp_target_walk_data passed in *PTR. */
9818 finish_omp_target_clauses_r (tree
*tp
, int *walk_subtrees
, void *ptr
)
9821 struct omp_target_walk_data
*data
= (struct omp_target_walk_data
*) ptr
;
9822 tree current_object
= data
->current_object
;
9823 tree current_closure
= data
->current_closure
;
9825 /* References inside of these expression codes shouldn't incur any
9826 form of mapping, so return early. */
9827 if (TREE_CODE (t
) == SIZEOF_EXPR
9828 || TREE_CODE (t
) == ALIGNOF_EXPR
)
9834 if (TREE_CODE (t
) == OMP_CLAUSE
)
9839 tree this_expr
= TREE_OPERAND (current_object
, 0);
9841 if (operand_equal_p (t
, this_expr
))
9843 data
->this_expr_accessed
= true;
9848 if (TREE_CODE (t
) == COMPONENT_REF
9849 && POINTER_TYPE_P (TREE_TYPE (t
))
9850 && operand_equal_p (TREE_OPERAND (t
, 0), current_object
)
9851 && TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
)
9853 data
->this_expr_accessed
= true;
9854 tree fld
= TREE_OPERAND (t
, 1);
9855 if (data
->ptr_members_accessed
.get (fld
) == NULL
)
9857 if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
)
9858 t
= convert_from_reference (t
);
9859 data
->ptr_members_accessed
.put (fld
, t
);
9866 /* When the current_function_decl is a lambda function, the closure object
9867 argument's type seems to not yet have fields layed out, so a recording
9868 of DECL_VALUE_EXPRs during the target body walk seems the only way to
9872 || TREE_CODE (t
) == PARM_DECL
9873 || TREE_CODE (t
) == RESULT_DECL
)
9874 && DECL_HAS_VALUE_EXPR_P (t
)
9875 && TREE_CODE (DECL_VALUE_EXPR (t
)) == COMPONENT_REF
9876 && operand_equal_p (current_closure
,
9877 TREE_OPERAND (DECL_VALUE_EXPR (t
), 0)))
9879 if (!data
->closure_vars_accessed
.contains (t
))
9880 data
->closure_vars_accessed
.add (t
);
9885 if (TREE_CODE (t
) == BIND_EXPR
)
9887 tree block
= BIND_EXPR_BLOCK (t
);
9888 for (tree var
= BLOCK_VARS (block
); var
; var
= DECL_CHAIN (var
))
9889 if (!data
->local_decls
.contains (var
))
9890 data
->local_decls
.add (var
);
9894 if (TREE_TYPE (t
) && LAMBDA_TYPE_P (TREE_TYPE (t
)))
9896 tree lt
= TREE_TYPE (t
);
9897 gcc_assert (CLASS_TYPE_P (lt
));
9899 if (!data
->lambda_objects_accessed
.contains (t
)
9900 /* Do not prepare to create target maps for locally declared
9901 lambdas or anonymous ones. */
9902 && !data
->local_decls
.contains (t
)
9903 && TREE_CODE (t
) != TARGET_EXPR
)
9904 data
->lambda_objects_accessed
.add (t
);
9912 /* Helper function for finish_omp_target, and also from tsubst_expr.
9913 Create additional clauses for mapping of non-static members, lambda objects,
9917 finish_omp_target_clauses (location_t loc
, tree body
, tree
*clauses_ptr
)
9919 omp_target_walk_data data
;
9920 data
.this_expr_accessed
= false;
9921 data
.current_object
= NULL_TREE
;
9923 if (DECL_NONSTATIC_MEMBER_P (current_function_decl
) && current_class_ptr
)
9924 if (tree ct
= current_nonlambda_class_type ())
9926 tree object
= maybe_dummy_object (ct
, NULL
);
9927 object
= maybe_resolve_dummy (object
, true);
9928 data
.current_object
= object
;
9931 if (DECL_LAMBDA_FUNCTION_P (current_function_decl
))
9933 tree closure
= DECL_ARGUMENTS (current_function_decl
);
9934 data
.current_closure
= build_indirect_ref (loc
, closure
, RO_UNARY_STAR
);
9937 data
.current_closure
= NULL_TREE
;
9939 cp_walk_tree_without_duplicates (&body
, finish_omp_target_clauses_r
, &data
);
9941 auto_vec
<tree
, 16> new_clauses
;
9943 tree omp_target_this_expr
= NULL_TREE
;
9944 tree
*explicit_this_deref_map
= NULL
;
9945 if (data
.this_expr_accessed
)
9947 omp_target_this_expr
= TREE_OPERAND (data
.current_object
, 0);
9949 /* See if explicit user-specified map(this[:]) clause already exists.
9950 If not, we create an implicit map(tofrom:this[:1]) clause. */
9951 for (tree
*cp
= clauses_ptr
; *cp
; cp
= &OMP_CLAUSE_CHAIN (*cp
))
9952 if (OMP_CLAUSE_CODE (*cp
) == OMP_CLAUSE_MAP
9953 && (TREE_CODE (OMP_CLAUSE_DECL (*cp
)) == INDIRECT_REF
9954 || TREE_CODE (OMP_CLAUSE_DECL (*cp
)) == MEM_REF
)
9955 && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*cp
), 0),
9956 omp_target_this_expr
))
9958 explicit_this_deref_map
= cp
;
9963 if (DECL_LAMBDA_FUNCTION_P (current_function_decl
)
9964 && (data
.this_expr_accessed
9965 || !data
.closure_vars_accessed
.is_empty ()))
9967 /* For lambda functions, we need to first create a copy of the
9968 __closure object. */
9969 tree closure
= DECL_ARGUMENTS (current_function_decl
);
9970 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9971 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_TO
);
9973 = build_indirect_ref (loc
, closure
, RO_UNARY_STAR
);
9975 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure
)));
9976 new_clauses
.safe_push (c
);
9978 tree closure_obj
= OMP_CLAUSE_DECL (c
);
9979 tree closure_type
= TREE_TYPE (closure_obj
);
9981 gcc_assert (LAMBDA_TYPE_P (closure_type
)
9982 && CLASS_TYPE_P (closure_type
));
9984 tree c2
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
9985 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
9986 OMP_CLAUSE_DECL (c2
) = closure
;
9987 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
9988 new_clauses
.safe_push (c2
);
9991 if (data
.this_expr_accessed
)
9993 /* If the this-expr was accessed, create a map(*this) clause. */
9994 enum gomp_map_kind kind
= GOMP_MAP_TOFROM
;
9995 if (explicit_this_deref_map
)
9997 tree this_map
= *explicit_this_deref_map
;
9998 tree nc
= OMP_CLAUSE_CHAIN (this_map
);
9999 gcc_assert (nc
!= NULL_TREE
10000 && OMP_CLAUSE_CODE (nc
) == OMP_CLAUSE_MAP
10001 && (OMP_CLAUSE_MAP_KIND (nc
)
10002 == GOMP_MAP_FIRSTPRIVATE_POINTER
));
10003 kind
= OMP_CLAUSE_MAP_KIND (this_map
);
10004 /* Remove the original 'map(*this) map(firstprivate_ptr:this)'
10005 two-map sequence away from the chain. */
10006 *explicit_this_deref_map
= OMP_CLAUSE_CHAIN (nc
);
10008 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10009 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10010 OMP_CLAUSE_DECL (c
)
10011 = build_indirect_ref (loc
, omp_target_this_expr
, RO_UNARY_STAR
);
10012 OMP_CLAUSE_SIZE (c
)
10013 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (omp_target_this_expr
)));
10014 new_clauses
.safe_push (c
);
10016 /* If we're in a lambda function, the this-pointer will actually be
10017 '__closure->this', a mapped member of __closure, hence always_pointer.
10018 Otherwise it's a firstprivate pointer. */
10019 enum gomp_map_kind ptr_kind
10020 = (DECL_LAMBDA_FUNCTION_P (current_function_decl
)
10021 ? GOMP_MAP_ALWAYS_POINTER
10022 : GOMP_MAP_FIRSTPRIVATE_POINTER
);
10023 c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10024 OMP_CLAUSE_SET_MAP_KIND (c
, ptr_kind
);
10025 OMP_CLAUSE_DECL (c
) = omp_target_this_expr
;
10026 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
10027 new_clauses
.safe_push (c
);
10030 if (DECL_LAMBDA_FUNCTION_P (current_function_decl
))
10032 if (omp_target_this_expr
)
10034 STRIP_NOPS (omp_target_this_expr
);
10035 gcc_assert (DECL_HAS_VALUE_EXPR_P (omp_target_this_expr
));
10036 omp_target_this_expr
= DECL_VALUE_EXPR (omp_target_this_expr
);
10039 for (hash_set
<tree
>::iterator i
= data
.closure_vars_accessed
.begin ();
10040 i
!= data
.closure_vars_accessed
.end (); ++i
)
10042 tree orig_decl
= *i
;
10043 tree closure_expr
= DECL_VALUE_EXPR (orig_decl
);
10045 if (TREE_CODE (TREE_TYPE (orig_decl
)) == POINTER_TYPE
10046 || TREE_CODE (TREE_TYPE (orig_decl
)) == REFERENCE_TYPE
)
10048 /* this-pointer is processed above, outside this loop. */
10049 if (omp_target_this_expr
10050 && operand_equal_p (closure_expr
, omp_target_this_expr
))
10053 bool ptr_p
= TREE_CODE (TREE_TYPE (orig_decl
)) == POINTER_TYPE
;
10054 enum gomp_map_kind kind
, ptr_kind
, nc_kind
;
10059 /* For pointers, default mapped as zero-length array
10061 kind
= GOMP_MAP_ALLOC
;
10062 nc_kind
= GOMP_MAP_FIRSTPRIVATE_POINTER
;
10063 ptr_kind
= GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
;
10064 size
= size_zero_node
;
10068 /* For references, default mapped as appearing on map
10070 kind
= GOMP_MAP_TOFROM
;
10071 nc_kind
= GOMP_MAP_FIRSTPRIVATE_REFERENCE
;
10072 ptr_kind
= GOMP_MAP_ALWAYS_POINTER
;
10073 size
= TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (closure_expr
)));
10076 for (tree
*p
= clauses_ptr
; *p
; p
= &OMP_CLAUSE_CHAIN (*p
))
10077 if (OMP_CLAUSE_CODE (*p
) == OMP_CLAUSE_MAP
10078 && (TREE_CODE (OMP_CLAUSE_DECL (*p
)) == INDIRECT_REF
10079 || TREE_CODE (OMP_CLAUSE_DECL (*p
)) == MEM_REF
)
10080 && operand_equal_p (TREE_OPERAND (OMP_CLAUSE_DECL (*p
), 0),
10083 /* If this was already specified by user as a map,
10084 save the user specified map kind, delete the
10085 "map(*ptr/ref), map(firstprivate ptr/ref)" sequence,
10086 and insert our own sequence:
10087 "map(*__closure->ptr/ref), map(<ptr_kind>:__closure->ref"
10089 tree nc
= OMP_CLAUSE_CHAIN (*p
);
10090 gcc_assert (nc
!= NULL_TREE
10091 && OMP_CLAUSE_CODE (nc
) == OMP_CLAUSE_MAP
10092 && OMP_CLAUSE_MAP_KIND (nc
) == nc_kind
);
10093 /* Update with user specified kind and size. */
10094 kind
= OMP_CLAUSE_MAP_KIND (*p
);
10095 size
= OMP_CLAUSE_SIZE (*p
);
10096 *p
= OMP_CLAUSE_CHAIN (nc
);
10100 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10101 OMP_CLAUSE_SET_MAP_KIND (c
, kind
);
10102 OMP_CLAUSE_DECL (c
)
10103 = build_indirect_ref (loc
, closure_expr
, RO_UNARY_STAR
);
10104 OMP_CLAUSE_SIZE (c
) = size
;
10106 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
10107 new_clauses
.safe_push (c
);
10109 c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10110 OMP_CLAUSE_SET_MAP_KIND (c
, ptr_kind
);
10111 OMP_CLAUSE_DECL (c
) = closure_expr
;
10112 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
10113 new_clauses
.safe_push (c
);
10118 if (!data
.ptr_members_accessed
.is_empty ())
10119 for (hash_map
<tree
, tree
>::iterator i
= data
.ptr_members_accessed
.begin ();
10120 i
!= data
.ptr_members_accessed
.end (); ++i
)
10122 /* For each referenced member that is of pointer or reference-to-pointer
10123 type, create the equivalent of map(alloc:this->ptr[:0]). */
10124 tree field_decl
= (*i
).first
;
10125 tree ptr_member
= (*i
).second
;
10127 for (tree c
= *clauses_ptr
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10129 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
10131 /* If map(this->ptr[:N]) already exists, avoid creating another
10133 tree decl
= OMP_CLAUSE_DECL (c
);
10134 if ((TREE_CODE (decl
) == INDIRECT_REF
10135 || TREE_CODE (decl
) == MEM_REF
)
10136 && operand_equal_p (TREE_OPERAND (decl
, 0), ptr_member
))
10137 goto next_ptr_member
;
10140 if (!cxx_mark_addressable (ptr_member
))
10141 gcc_unreachable ();
10143 if (TREE_CODE (TREE_TYPE (field_decl
)) == REFERENCE_TYPE
)
10145 /* For reference to pointers, we need to map the referenced
10146 pointer first for things to be correct. */
10147 tree ptr_member_type
= TREE_TYPE (ptr_member
);
10149 /* Map pointer target as zero-length array section. */
10150 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10151 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_ALLOC
);
10152 OMP_CLAUSE_DECL (c
)
10153 = build1 (INDIRECT_REF
, TREE_TYPE (ptr_member_type
), ptr_member
);
10154 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
10155 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
10157 /* Map pointer to zero-length array section. */
10158 tree c2
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10159 OMP_CLAUSE_SET_MAP_KIND
10160 (c2
, GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION
);
10161 OMP_CLAUSE_DECL (c2
) = ptr_member
;
10162 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
10164 /* Attach reference-to-pointer field to pointer. */
10165 tree c3
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10166 OMP_CLAUSE_SET_MAP_KIND (c3
, GOMP_MAP_ATTACH
);
10167 OMP_CLAUSE_DECL (c3
) = TREE_OPERAND (ptr_member
, 0);
10168 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
10170 new_clauses
.safe_push (c
);
10171 new_clauses
.safe_push (c2
);
10172 new_clauses
.safe_push (c3
);
10174 else if (TREE_CODE (TREE_TYPE (field_decl
)) == POINTER_TYPE
)
10176 /* Map pointer target as zero-length array section. */
10177 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10178 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_ALLOC
);
10179 OMP_CLAUSE_DECL (c
) = build_indirect_ref (loc
, ptr_member
,
10181 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
10182 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
10184 /* Attach zero-length array section to pointer. */
10185 tree c2
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10186 OMP_CLAUSE_SET_MAP_KIND
10187 (c2
, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
);
10188 OMP_CLAUSE_DECL (c2
) = ptr_member
;
10189 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
10191 new_clauses
.safe_push (c
);
10192 new_clauses
.safe_push (c2
);
10195 gcc_unreachable ();
10201 for (hash_set
<tree
>::iterator i
= data
.lambda_objects_accessed
.begin ();
10202 i
!= data
.lambda_objects_accessed
.end (); ++i
)
10205 if (TREE_CODE (lobj
) == TARGET_EXPR
)
10206 lobj
= TREE_OPERAND (lobj
, 0);
10208 tree lt
= TREE_TYPE (lobj
);
10209 gcc_assert (LAMBDA_TYPE_P (lt
) && CLASS_TYPE_P (lt
));
10211 tree lc
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10212 OMP_CLAUSE_SET_MAP_KIND (lc
, GOMP_MAP_TO
);
10213 OMP_CLAUSE_DECL (lc
) = lobj
;
10214 OMP_CLAUSE_SIZE (lc
) = TYPE_SIZE_UNIT (lt
);
10215 new_clauses
.safe_push (lc
);
10217 for (tree fld
= TYPE_FIELDS (lt
); fld
; fld
= DECL_CHAIN (fld
))
10219 if (TREE_CODE (TREE_TYPE (fld
)) == POINTER_TYPE
)
10221 tree exp
= build3 (COMPONENT_REF
, TREE_TYPE (fld
),
10222 lobj
, fld
, NULL_TREE
);
10223 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10224 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_ALLOC
);
10225 OMP_CLAUSE_DECL (c
)
10226 = build_indirect_ref (loc
, exp
, RO_UNARY_STAR
);
10227 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
10228 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
10229 new_clauses
.safe_push (c
);
10231 c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10232 OMP_CLAUSE_SET_MAP_KIND
10233 (c
, GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
);
10234 OMP_CLAUSE_DECL (c
) = exp
;
10235 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
10236 new_clauses
.safe_push (c
);
10238 else if (TREE_CODE (TREE_TYPE (fld
)) == REFERENCE_TYPE
)
10240 tree exp
= build3 (COMPONENT_REF
, TREE_TYPE (fld
),
10241 lobj
, fld
, NULL_TREE
);
10242 tree c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10243 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_TOFROM
);
10244 OMP_CLAUSE_DECL (c
)
10245 = build1 (INDIRECT_REF
, TREE_TYPE (TREE_TYPE (exp
)), exp
);
10246 OMP_CLAUSE_SIZE (c
)
10247 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (exp
)));
10248 new_clauses
.safe_push (c
);
10250 c
= build_omp_clause (loc
, OMP_CLAUSE_MAP
);
10251 OMP_CLAUSE_SET_MAP_KIND (c
, GOMP_MAP_ALWAYS_POINTER
);
10252 OMP_CLAUSE_DECL (c
) = exp
;
10253 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
10254 new_clauses
.safe_push (c
);
10259 tree c
= *clauses_ptr
;
10260 for (int i
= new_clauses
.length () - 1; i
>= 0; i
--)
10262 OMP_CLAUSE_CHAIN (new_clauses
[i
]) = c
;
10263 c
= new_clauses
[i
];
10268 /* Called from cp_parser_omp_target. Create additional implicit clauses for
10269 OpenMP target directives, and do sanity checks. */
10272 finish_omp_target (location_t loc
, tree clauses
, tree body
, bool combined_p
)
10274 if (!processing_template_decl
)
10275 finish_omp_target_clauses (loc
, body
, &clauses
);
10277 tree stmt
= make_node (OMP_TARGET
);
10278 TREE_TYPE (stmt
) = void_type_node
;
10279 OMP_TARGET_CLAUSES (stmt
) = clauses
;
10280 OMP_TARGET_BODY (stmt
) = body
;
10281 OMP_TARGET_COMBINED (stmt
) = combined_p
;
10282 SET_EXPR_LOCATION (stmt
, loc
);
10287 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
)
10288 switch (OMP_CLAUSE_MAP_KIND (c
))
10291 case GOMP_MAP_ALWAYS_TO
:
10292 case GOMP_MAP_PRESENT_TO
:
10293 case GOMP_MAP_ALWAYS_PRESENT_TO
:
10294 case GOMP_MAP_FROM
:
10295 case GOMP_MAP_ALWAYS_FROM
:
10296 case GOMP_MAP_PRESENT_FROM
:
10297 case GOMP_MAP_ALWAYS_PRESENT_FROM
:
10298 case GOMP_MAP_TOFROM
:
10299 case GOMP_MAP_ALWAYS_TOFROM
:
10300 case GOMP_MAP_PRESENT_TOFROM
:
10301 case GOMP_MAP_ALWAYS_PRESENT_TOFROM
:
10302 case GOMP_MAP_ALLOC
:
10303 case GOMP_MAP_PRESENT_ALLOC
:
10304 case GOMP_MAP_FIRSTPRIVATE_POINTER
:
10305 case GOMP_MAP_FIRSTPRIVATE_REFERENCE
:
10306 case GOMP_MAP_ALWAYS_POINTER
:
10307 case GOMP_MAP_ATTACH_DETACH
:
10308 case GOMP_MAP_ATTACH
:
10309 case GOMP_MAP_ATTACH_ZERO_LENGTH_ARRAY_SECTION
:
10310 case GOMP_MAP_POINTER
:
10311 case GOMP_MAP_POINTER_TO_ZERO_LENGTH_ARRAY_SECTION
:
10314 error_at (OMP_CLAUSE_LOCATION (c
),
10315 "%<#pragma omp target%> with map-type other "
10316 "than %<to%>, %<from%>, %<tofrom%> or %<alloc%> "
10317 "on %<map%> clause");
10320 c
= OMP_CLAUSE_CHAIN (c
);
10322 return add_stmt (stmt
);
10326 finish_omp_parallel (tree clauses
, tree body
)
10330 body
= finish_omp_structured_block (body
);
10332 stmt
= make_node (OMP_PARALLEL
);
10333 TREE_TYPE (stmt
) = void_type_node
;
10334 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
10335 OMP_PARALLEL_BODY (stmt
) = body
;
10337 return add_stmt (stmt
);
10341 begin_omp_task (void)
10343 keep_next_level (true);
10344 return begin_omp_structured_block ();
10348 finish_omp_task (tree clauses
, tree body
)
10352 body
= finish_omp_structured_block (body
);
10354 stmt
= make_node (OMP_TASK
);
10355 TREE_TYPE (stmt
) = void_type_node
;
10356 OMP_TASK_CLAUSES (stmt
) = clauses
;
10357 OMP_TASK_BODY (stmt
) = body
;
10359 return add_stmt (stmt
);
10362 /* Helper function for finish_omp_for. Convert Ith random access iterator
10363 into integral iterator. Return FALSE if successful. */
10366 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
10367 tree declv
, tree orig_declv
, tree initv
,
10368 tree condv
, tree incrv
, tree
*body
,
10369 tree
*pre_body
, tree
&clauses
,
10370 int collapse
, int ordered
)
10372 tree diff
, iter_init
, iter_incr
= NULL
, last
;
10373 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
10374 tree decl
= TREE_VEC_ELT (declv
, i
);
10375 tree init
= TREE_VEC_ELT (initv
, i
);
10376 tree cond
= TREE_VEC_ELT (condv
, i
);
10377 tree incr
= TREE_VEC_ELT (incrv
, i
);
10379 location_t elocus
= locus
;
10381 if (init
&& EXPR_HAS_LOCATION (init
))
10382 elocus
= EXPR_LOCATION (init
);
10384 switch (TREE_CODE (cond
))
10391 if (TREE_OPERAND (cond
, 1) == iter
)
10392 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
10393 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
10394 if (TREE_OPERAND (cond
, 0) != iter
)
10395 cond
= error_mark_node
;
10398 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
10401 TREE_OPERAND (cond
, 1), ERROR_MARK
,
10402 NULL_TREE
, NULL
, tf_warning_or_error
);
10403 if (error_operand_p (tem
))
10408 cond
= error_mark_node
;
10411 if (cond
== error_mark_node
)
10413 error_at (elocus
, "invalid controlling predicate");
10416 diff
= build_x_binary_op (elocus
, MINUS_EXPR
,
10417 TREE_OPERAND (cond
, 1), ERROR_MARK
,
10419 NULL_TREE
, NULL
, tf_warning_or_error
);
10420 diff
= cp_fully_fold (diff
);
10421 if (error_operand_p (diff
))
10423 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
10425 error_at (elocus
, "difference between %qE and %qD does not have integer type",
10426 TREE_OPERAND (cond
, 1), iter
);
10429 if (!c_omp_check_loop_iv_exprs (locus
, code
, orig_declv
, i
,
10430 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
10431 cond
, cp_walk_subtrees
))
10434 switch (TREE_CODE (incr
))
10436 case PREINCREMENT_EXPR
:
10437 case PREDECREMENT_EXPR
:
10438 case POSTINCREMENT_EXPR
:
10439 case POSTDECREMENT_EXPR
:
10440 if (TREE_OPERAND (incr
, 0) != iter
)
10442 incr
= error_mark_node
;
10445 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
10446 TREE_CODE (incr
), iter
,
10447 NULL_TREE
, tf_warning_or_error
);
10448 if (error_operand_p (iter_incr
))
10450 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
10451 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
10452 incr
= integer_one_node
;
10454 incr
= integer_minus_one_node
;
10457 if (TREE_OPERAND (incr
, 0) != iter
)
10458 incr
= error_mark_node
;
10459 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
10460 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
10462 tree rhs
= TREE_OPERAND (incr
, 1);
10463 if (TREE_OPERAND (rhs
, 0) == iter
)
10465 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
10467 incr
= error_mark_node
;
10470 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
10471 iter
, TREE_CODE (rhs
),
10472 TREE_OPERAND (rhs
, 1),
10474 tf_warning_or_error
);
10475 if (error_operand_p (iter_incr
))
10477 incr
= TREE_OPERAND (rhs
, 1);
10478 incr
= cp_convert (TREE_TYPE (diff
), incr
,
10479 tf_warning_or_error
);
10480 if (TREE_CODE (rhs
) == MINUS_EXPR
)
10482 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
10483 incr
= fold_simple (incr
);
10485 if (TREE_CODE (incr
) != INTEGER_CST
10486 && (TREE_CODE (incr
) != NOP_EXPR
10487 || (TREE_CODE (TREE_OPERAND (incr
, 0))
10492 else if (TREE_OPERAND (rhs
, 1) == iter
)
10494 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
10495 || TREE_CODE (rhs
) != PLUS_EXPR
)
10496 incr
= error_mark_node
;
10499 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
10501 TREE_OPERAND (rhs
, 0),
10503 ERROR_MARK
, NULL_TREE
, NULL
,
10504 tf_warning_or_error
);
10505 if (error_operand_p (iter_incr
))
10507 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
10509 iter_incr
, NULL_TREE
,
10510 tf_warning_or_error
);
10511 if (error_operand_p (iter_incr
))
10513 incr
= TREE_OPERAND (rhs
, 0);
10518 incr
= error_mark_node
;
10521 incr
= error_mark_node
;
10524 incr
= error_mark_node
;
10528 if (incr
== error_mark_node
)
10530 error_at (elocus
, "invalid increment expression");
10534 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
10535 incr
= cp_fully_fold (incr
);
10536 tree loop_iv_seen
= NULL_TREE
;
10537 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
10538 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
10539 && OMP_CLAUSE_DECL (c
) == iter
)
10541 if (code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
10544 OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
) = 1;
10548 else if ((code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
10549 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
10550 && OMP_CLAUSE_DECL (c
) == iter
)
10553 if (code
== OMP_TASKLOOP
)
10554 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
10557 decl
= create_temporary_var (TREE_TYPE (diff
));
10559 add_decl_expr (decl
);
10560 last
= create_temporary_var (TREE_TYPE (diff
));
10562 add_decl_expr (last
);
10563 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
10564 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
10566 incr_var
= create_temporary_var (TREE_TYPE (diff
));
10567 pushdecl (incr_var
);
10568 add_decl_expr (incr_var
);
10570 gcc_assert (stmts_are_full_exprs_p ());
10571 tree diffvar
= NULL_TREE
;
10572 if (code
== OMP_TASKLOOP
)
10576 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
10577 OMP_CLAUSE_DECL (ivc
) = iter
;
10578 cxx_omp_finish_clause (ivc
, NULL
, false);
10579 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
10582 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
10583 OMP_CLAUSE_DECL (lvc
) = last
;
10584 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
10586 diffvar
= create_temporary_var (TREE_TYPE (diff
));
10587 pushdecl (diffvar
);
10588 add_decl_expr (diffvar
);
10590 else if (code
== OMP_LOOP
)
10594 /* While iterators on the loop construct are predetermined
10595 lastprivate, if the decl is not declared inside of the
10596 loop, OMP_CLAUSE_LASTPRIVATE should have been added
10598 loop_iv_seen
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
10599 OMP_CLAUSE_DECL (loop_iv_seen
) = iter
;
10600 OMP_CLAUSE_CHAIN (loop_iv_seen
) = clauses
;
10601 clauses
= loop_iv_seen
;
10603 else if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_PRIVATE
)
10605 OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen
) = 0;
10606 OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen
) = 0;
10607 OMP_CLAUSE_CODE (loop_iv_seen
) = OMP_CLAUSE_FIRSTPRIVATE
;
10609 if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_FIRSTPRIVATE
)
10610 cxx_omp_finish_clause (loop_iv_seen
, NULL
, false);
10613 orig_pre_body
= *pre_body
;
10614 *pre_body
= push_stmt_list ();
10616 add_stmt (orig_pre_body
);
10618 finish_expr_stmt (build_x_modify_expr (elocus
,
10619 iter
, NOP_EXPR
, init
,
10620 NULL_TREE
, tf_warning_or_error
));
10621 init
= build_int_cst (TREE_TYPE (diff
), 0);
10622 if (c
&& iter_incr
== NULL
10623 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
10627 finish_expr_stmt (build_x_modify_expr (elocus
,
10628 incr_var
, NOP_EXPR
,
10630 tf_warning_or_error
));
10633 iter_incr
= build_x_modify_expr (elocus
,
10634 iter
, PLUS_EXPR
, incr
,
10635 NULL_TREE
, tf_warning_or_error
);
10637 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
10639 finish_expr_stmt (build_x_modify_expr (elocus
,
10640 last
, NOP_EXPR
, init
,
10641 NULL_TREE
, tf_warning_or_error
));
10644 finish_expr_stmt (build_x_modify_expr (elocus
,
10646 diff
, NULL_TREE
, tf_warning_or_error
));
10649 *pre_body
= pop_stmt_list (*pre_body
);
10651 cond
= cp_build_binary_op (elocus
,
10652 TREE_CODE (cond
), decl
, diff
,
10653 tf_warning_or_error
);
10654 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
10655 elocus
, incr
, NULL_TREE
);
10658 *body
= push_stmt_list ();
10659 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
10660 iter_init
= build_x_modify_expr (elocus
,
10661 iter
, PLUS_EXPR
, iter_init
,
10662 NULL_TREE
, tf_warning_or_error
);
10663 if (iter_init
!= error_mark_node
)
10664 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
10665 finish_expr_stmt (iter_init
);
10666 finish_expr_stmt (build_x_modify_expr (elocus
,
10667 last
, NOP_EXPR
, decl
,
10668 NULL_TREE
, tf_warning_or_error
));
10669 add_stmt (orig_body
);
10670 *body
= pop_stmt_list (*body
);
10674 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
10676 finish_expr_stmt (iter_incr
);
10680 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
10681 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
10682 iter_init
, iter_incr
);
10683 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
10684 iter_init
= build_x_modify_expr (elocus
,
10685 iter
, PLUS_EXPR
, iter_init
,
10686 NULL_TREE
, tf_warning_or_error
);
10687 if (iter_init
!= error_mark_node
)
10688 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
10689 finish_expr_stmt (iter_init
);
10691 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
10692 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
10695 if (TREE_CODE (TREE_VEC_ELT (orig_declv
, i
)) == TREE_LIST
)
10697 tree t
= TREE_VEC_ELT (orig_declv
, i
);
10698 gcc_assert (TREE_PURPOSE (t
) == NULL_TREE
10699 && TREE_VALUE (t
) == NULL_TREE
10700 && TREE_CODE (TREE_CHAIN (t
)) == TREE_VEC
);
10701 TREE_PURPOSE (t
) = TREE_VEC_ELT (declv
, i
);
10702 TREE_VALUE (t
) = last
;
10705 TREE_VEC_ELT (orig_declv
, i
)
10706 = tree_cons (TREE_VEC_ELT (declv
, i
), last
, NULL_TREE
);
10707 TREE_VEC_ELT (declv
, i
) = decl
;
10708 TREE_VEC_ELT (initv
, i
) = init
;
10709 TREE_VEC_ELT (condv
, i
) = cond
;
10710 TREE_VEC_ELT (incrv
, i
) = incr
;
10715 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
10716 are directly for their associated operands in the statement. DECL
10717 and INIT are a combo; if DECL is NULL then INIT ought to be a
10718 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
10719 optional statements that need to go before the loop into its
10723 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
10724 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
10725 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
10727 tree omp_for
= NULL
, orig_incr
= NULL
;
10728 tree decl
= NULL
, init
, cond
, incr
;
10733 auto_vec
<location_t
> init_locv
;
10735 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
10736 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
10737 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
10738 if (TREE_VEC_LENGTH (declv
) > 1)
10742 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
10744 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
10747 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
10749 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
10750 if (collapse
!= TREE_VEC_LENGTH (declv
))
10751 ordered
= TREE_VEC_LENGTH (declv
);
10754 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
10756 decl
= TREE_VEC_ELT (declv
, i
);
10757 init
= TREE_VEC_ELT (initv
, i
);
10758 cond
= TREE_VEC_ELT (condv
, i
);
10759 incr
= TREE_VEC_ELT (incrv
, i
);
10762 /* We are going to throw out the init's original MODIFY_EXPR or
10763 MODOP_EXPR below. Save its location so we can use it when
10764 reconstructing the expression farther down. Alternatively, if the
10765 initializer is a binding of the iteration variable, save
10766 that location. Any of these locations in the initialization clause
10767 for the current nested loop are better than using the argument locus,
10768 that points to the "for" of the outermost loop in the nest. */
10769 if (init
&& EXPR_HAS_LOCATION (init
))
10770 elocus
= EXPR_LOCATION (init
);
10771 else if (decl
&& INDIRECT_REF_P (decl
) && EXPR_HAS_LOCATION (decl
))
10772 /* This can happen for class iterators. */
10773 elocus
= EXPR_LOCATION (decl
);
10774 else if (decl
&& DECL_P (decl
))
10776 if (DECL_SOURCE_LOCATION (decl
) != UNKNOWN_LOCATION
)
10777 elocus
= DECL_SOURCE_LOCATION (decl
);
10778 else if (DECL_INITIAL (decl
)
10779 && EXPR_HAS_LOCATION (DECL_INITIAL (decl
)))
10780 elocus
= EXPR_LOCATION (DECL_INITIAL (decl
));
10782 init_locv
.safe_push (elocus
);
10787 switch (TREE_CODE (init
))
10790 decl
= TREE_OPERAND (init
, 0);
10791 init
= TREE_OPERAND (init
, 1);
10794 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
10796 decl
= TREE_OPERAND (init
, 0);
10797 init
= TREE_OPERAND (init
, 2);
10807 "expected iteration declaration or initialization");
10812 if (cond
== global_namespace
)
10817 error_at (elocus
, "missing controlling predicate");
10823 error_at (elocus
, "missing increment expression");
10827 TREE_VEC_ELT (declv
, i
) = decl
;
10828 TREE_VEC_ELT (initv
, i
) = init
;
10835 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
10837 && !c_omp_check_loop_iv_exprs (locus
, code
,
10838 orig_declv
? orig_declv
: declv
, i
,
10839 TREE_VEC_ELT (declv
, i
), orig_init
,
10840 NULL_TREE
, cp_walk_subtrees
))
10846 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
10850 stmt
= make_node (code
);
10852 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
10854 /* This is really just a place-holder. We'll be decomposing this
10855 again and going through the cp_build_modify_expr path below when
10856 we instantiate the thing. */
10857 TREE_VEC_ELT (initv
, i
)
10858 = build2_loc (init_locv
[i
], MODIFY_EXPR
, void_type_node
,
10859 TREE_VEC_ELT (declv
, i
), TREE_VEC_ELT (initv
, i
));
10862 TREE_TYPE (stmt
) = void_type_node
;
10863 OMP_FOR_INIT (stmt
) = initv
;
10864 OMP_FOR_COND (stmt
) = condv
;
10865 OMP_FOR_INCR (stmt
) = incrv
;
10866 OMP_FOR_BODY (stmt
) = body
;
10867 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
10868 OMP_FOR_CLAUSES (stmt
) = clauses
;
10870 SET_EXPR_LOCATION (stmt
, locus
);
10871 return add_stmt (stmt
);
10875 orig_declv
= copy_node (declv
);
10877 if (processing_template_decl
)
10878 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
10880 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
10882 decl
= TREE_VEC_ELT (declv
, i
);
10883 init
= TREE_VEC_ELT (initv
, i
);
10884 cond
= TREE_VEC_ELT (condv
, i
);
10885 incr
= TREE_VEC_ELT (incrv
, i
);
10887 TREE_VEC_ELT (orig_incr
, i
) = incr
;
10888 elocus
= init_locv
[i
];
10890 if (!DECL_P (decl
))
10892 error_at (elocus
, "expected iteration declaration or initialization");
10896 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
10899 TREE_VEC_ELT (orig_incr
, i
) = incr
;
10900 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
10901 TREE_CODE (TREE_OPERAND (incr
, 1)),
10902 TREE_OPERAND (incr
, 2),
10903 tf_warning_or_error
);
10906 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
10908 if (code
== OMP_SIMD
)
10910 error_at (elocus
, "%<#pragma omp simd%> used with class "
10911 "iteration variable %qE", decl
);
10914 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
10915 initv
, condv
, incrv
, &body
,
10916 &pre_body
, clauses
,
10917 collapse
, ordered
))
10922 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
10923 && !TYPE_PTR_P (TREE_TYPE (decl
)))
10925 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
10929 if (!processing_template_decl
&& TREE_CODE (init
) != TREE_VEC
)
10930 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
10931 tf_warning_or_error
);
10933 init
= build2_loc (elocus
, MODIFY_EXPR
, void_type_node
, decl
, init
);
10934 if (decl
== error_mark_node
|| init
== error_mark_node
)
10937 TREE_VEC_ELT (declv
, i
) = decl
;
10938 TREE_VEC_ELT (initv
, i
) = init
;
10939 TREE_VEC_ELT (condv
, i
) = cond
;
10940 TREE_VEC_ELT (incrv
, i
) = incr
;
10944 if (pre_body
&& IS_EMPTY_STMT (pre_body
))
10947 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
10948 incrv
, body
, pre_body
,
10949 !processing_template_decl
);
10951 /* Check for iterators appearing in lb, b or incr expressions. */
10952 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
10953 omp_for
= NULL_TREE
;
10955 if (omp_for
== NULL
)
10958 add_stmt (omp_for
);
10960 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
10962 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
);
10963 decl
= TREE_OPERAND (init
, 0);
10964 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), i
);
10965 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
10967 if (!processing_template_decl
)
10969 if (TREE_CODE (TREE_OPERAND (init
, 1)) == TREE_VEC
)
10971 tree t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1);
10972 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1)
10973 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10974 t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2);
10975 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2)
10976 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10980 tree t
= TREE_OPERAND (init
, 1);
10981 TREE_OPERAND (init
, 1)
10982 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10984 if (TREE_CODE (TREE_OPERAND (cond
, 1)) == TREE_VEC
)
10986 tree t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1);
10987 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1)
10988 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10989 t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2);
10990 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2)
10991 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
10995 tree t
= TREE_OPERAND (cond
, 1);
10996 TREE_OPERAND (cond
, 1)
10997 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
11001 if (TREE_CODE (incr
) != MODIFY_EXPR
)
11004 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
11005 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
11006 && !processing_template_decl
)
11008 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
11009 if (TREE_SIDE_EFFECTS (t
)
11011 && (TREE_CODE (t
) != NOP_EXPR
11012 || TREE_OPERAND (t
, 0) != decl
))
11013 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
11014 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
11016 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
11017 if (TREE_SIDE_EFFECTS (t
)
11019 && (TREE_CODE (t
) != NOP_EXPR
11020 || TREE_OPERAND (t
, 0) != decl
))
11021 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
11022 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
11026 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
11028 OMP_FOR_CLAUSES (omp_for
) = clauses
;
11030 /* For simd loops with non-static data member iterators, we could have added
11031 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
11032 step at this point, fill it in. */
11033 if (code
== OMP_SIMD
&& !processing_template_decl
11034 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
11035 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
11036 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
11037 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
11039 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
11040 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
11041 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
11043 switch (TREE_CODE (incr
))
11045 case PREINCREMENT_EXPR
:
11046 case POSTINCREMENT_EXPR
:
11047 /* c_omp_for_incr_canonicalize_ptr() should have been
11048 called to massage things appropriately. */
11049 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
11050 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
11052 case PREDECREMENT_EXPR
:
11053 case POSTDECREMENT_EXPR
:
11054 /* c_omp_for_incr_canonicalize_ptr() should have been
11055 called to massage things appropriately. */
11056 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
11057 OMP_CLAUSE_LINEAR_STEP (c
)
11058 = build_int_cst (TREE_TYPE (decl
), -1);
11061 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
11062 incr
= TREE_OPERAND (incr
, 1);
11063 switch (TREE_CODE (incr
))
11066 if (TREE_OPERAND (incr
, 1) == decl
)
11067 step
= TREE_OPERAND (incr
, 0);
11069 step
= TREE_OPERAND (incr
, 1);
11072 case POINTER_PLUS_EXPR
:
11073 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
11074 step
= TREE_OPERAND (incr
, 1);
11077 gcc_unreachable ();
11079 stept
= TREE_TYPE (decl
);
11080 if (INDIRECT_TYPE_P (stept
))
11082 step
= fold_convert (stept
, step
);
11083 if (TREE_CODE (incr
) == MINUS_EXPR
)
11084 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
11085 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
11088 gcc_unreachable ();
11091 /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
11092 clauses, we need copy ctor for those rather than default ctor,
11093 plus as for other lastprivates assignment op and dtor. */
11094 if (code
== OMP_LOOP
&& !processing_template_decl
)
11095 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
11096 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
11097 && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
)
11098 && cxx_omp_create_clause_info (c
, TREE_TYPE (OMP_CLAUSE_DECL (c
)),
11099 false, true, true, true))
11100 CP_OMP_CLAUSE_INFO (c
) = NULL_TREE
;
11105 /* Code walker for finish_omp_for_block: extract binding of DP->var
11106 from its current block and move it to a new BIND_EXPR DP->b
11107 surrounding the body of DP->omp_for. */
11116 finish_omp_for_block_walker (tree
*tp
, int *walk_subtrees
, void *dp
)
11118 struct fofb_data
*fofb
= (struct fofb_data
*)dp
;
11119 if (TREE_CODE (*tp
) == BIND_EXPR
)
11120 for (tree
*p
= &BIND_EXPR_VARS (*tp
); *p
; p
= &DECL_CHAIN (*p
))
11122 if (*p
== fofb
->var
)
11124 *p
= DECL_CHAIN (*p
);
11125 if (fofb
->b
== NULL_TREE
)
11127 fofb
->b
= make_node (BLOCK
);
11128 fofb
->b
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
11129 OMP_FOR_BODY (fofb
->omp_for
), fofb
->b
);
11130 TREE_SIDE_EFFECTS (fofb
->b
) = 1;
11131 OMP_FOR_BODY (fofb
->omp_for
) = fofb
->b
;
11133 DECL_CHAIN (fofb
->var
) = BIND_EXPR_VARS (fofb
->b
);
11134 BIND_EXPR_VARS (fofb
->b
) = fofb
->var
;
11135 BLOCK_VARS (BIND_EXPR_BLOCK (fofb
->b
)) = fofb
->var
;
11136 BLOCK_VARS (BIND_EXPR_BLOCK (*tp
)) = BIND_EXPR_VARS (*tp
);
11140 if (TREE_CODE (*tp
) != BIND_EXPR
&& TREE_CODE (*tp
) != STATEMENT_LIST
)
11141 *walk_subtrees
= false;
11145 /* Fix up range for decls. Those decls were pushed into BIND's
11146 BIND_EXPR_VARS, or that of a nested BIND_EXPR inside its body,
11147 and need to be moved into a new BIND_EXPR surrounding OMP_FOR's body
11148 so that processing of combined loop directives can find them. */
11150 finish_omp_for_block (tree bind
, tree omp_for
)
11152 if (omp_for
== NULL_TREE
11153 || !OMP_FOR_ORIG_DECLS (omp_for
)
11154 || bind
== NULL_TREE
)
11156 struct fofb_data fofb
;
11157 fofb
.b
= NULL_TREE
;
11158 fofb
.omp_for
= omp_for
;
11159 for (int i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for
)); i
++)
11160 if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)) == TREE_LIST
11161 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)))
11163 tree v
= TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
));
11164 for (int j
= 2; j
< TREE_VEC_LENGTH (v
); j
++)
11166 fofb
.var
= TREE_VEC_ELT (v
, j
);
11167 cp_walk_tree (&bind
, finish_omp_for_block_walker
,
11168 (void *)&fofb
, NULL
);
11175 finish_omp_atomic (location_t loc
, enum tree_code code
, enum tree_code opcode
,
11176 tree lhs
, tree rhs
, tree v
, tree lhs1
, tree rhs1
, tree r
,
11177 tree clauses
, enum omp_memory_order mo
, bool weak
)
11194 dependent_p
= false;
11197 /* Even in a template, we can detect invalid uses of the atomic
11198 pragma if neither LHS nor RHS is type-dependent. */
11199 if (processing_template_decl
)
11201 dependent_p
= (type_dependent_expression_p (lhs
)
11202 || (rhs
&& type_dependent_expression_p (rhs
))
11203 || (v
&& type_dependent_expression_p (v
))
11204 || (lhs1
&& type_dependent_expression_p (lhs1
))
11205 || (rhs1
&& type_dependent_expression_p (rhs1
))
11207 && r
!= void_list_node
11208 && type_dependent_expression_p (r
)));
11211 gcc_assert (TREE_CODE (clauses
) == OMP_CLAUSE
11212 && OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_HINT
11213 && OMP_CLAUSE_CHAIN (clauses
) == NULL_TREE
);
11214 if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses
))
11215 || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses
)) != INTEGER_CST
)
11216 dependent_p
= true;
11221 bool swapped
= false;
11222 if (rhs1
&& opcode
!= COND_EXPR
&& cp_tree_equal (lhs
, rhs
))
11224 std::swap (rhs
, rhs1
);
11225 swapped
= !commutative_tree_code (opcode
);
11227 if (rhs1
&& opcode
!= COND_EXPR
&& !cp_tree_equal (lhs
, rhs1
))
11229 if (code
== OMP_ATOMIC
)
11230 error ("%<#pragma omp atomic update%> uses two different "
11231 "expressions for memory");
11233 error ("%<#pragma omp atomic capture%> uses two different "
11234 "expressions for memory");
11237 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
11239 if (code
== OMP_ATOMIC
)
11240 error ("%<#pragma omp atomic update%> uses two different "
11241 "expressions for memory");
11243 error ("%<#pragma omp atomic capture%> uses two different "
11244 "expressions for memory");
11247 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
,
11248 v
, lhs1
, rhs1
, r
, swapped
, mo
, weak
,
11249 processing_template_decl
!= 0);
11250 if (stmt
== error_mark_node
)
11253 if (processing_template_decl
)
11255 if (code
== OMP_ATOMIC_READ
)
11257 stmt
= build_min_nt_loc (loc
, OMP_ATOMIC_READ
, orig_lhs
);
11258 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
11259 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
11263 if (opcode
== NOP_EXPR
)
11264 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
11265 else if (opcode
== COND_EXPR
)
11267 stmt
= build2 (EQ_EXPR
, boolean_type_node
, orig_lhs
, orig_rhs
);
11269 stmt
= build2 (MODIFY_EXPR
, boolean_type_node
, orig_r
,
11271 stmt
= build3 (COND_EXPR
, void_type_node
, stmt
, orig_rhs1
,
11273 orig_rhs1
= NULL_TREE
;
11276 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
11278 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
11279 COMPOUND_EXPR
, orig_rhs1
, stmt
);
11280 if (code
!= OMP_ATOMIC
)
11282 stmt
= build_min_nt_loc (loc
, code
, orig_lhs1
, stmt
);
11283 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
11284 OMP_ATOMIC_WEAK (stmt
) = weak
;
11285 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
11288 stmt
= build2 (OMP_ATOMIC
, void_type_node
,
11289 clauses
? clauses
: integer_zero_node
, stmt
);
11290 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
11291 OMP_ATOMIC_WEAK (stmt
) = weak
;
11292 SET_EXPR_LOCATION (stmt
, loc
);
11295 /* Avoid -Wunused-value warnings here, the whole construct has side-effects
11296 and even if it might be wrapped from fold-const.cc or c-omp.cc wrapped
11297 in some tree that appears to be unused, the value is not unused. */
11298 warning_sentinel
w (warn_unused_value
);
11299 finish_expr_stmt (stmt
);
11303 finish_omp_barrier (void)
11305 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
11307 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
11308 finish_expr_stmt (stmt
);
11312 finish_omp_depobj (location_t loc
, tree depobj
,
11313 enum omp_clause_depend_kind kind
, tree clause
)
11315 if (!error_operand_p (depobj
) && !type_dependent_expression_p (depobj
))
11317 if (!lvalue_p (depobj
))
11319 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
11320 "%<depobj%> expression is not lvalue expression");
11321 depobj
= error_mark_node
;
11325 if (processing_template_decl
)
11327 if (clause
== NULL_TREE
)
11328 clause
= build_int_cst (integer_type_node
, kind
);
11329 add_stmt (build_min_nt_loc (loc
, OMP_DEPOBJ
, depobj
, clause
));
11333 if (!error_operand_p (depobj
))
11335 tree addr
= cp_build_addr_expr (depobj
, tf_warning_or_error
);
11336 if (addr
== error_mark_node
)
11337 depobj
= error_mark_node
;
11339 depobj
= cp_build_indirect_ref (loc
, addr
, RO_UNARY_STAR
,
11340 tf_warning_or_error
);
11343 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
11347 finish_omp_flush (int mo
)
11349 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
11351 if (mo
!= MEMMODEL_LAST
&& mo
!= MEMMODEL_SEQ_CST
)
11353 fn
= builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE
);
11354 vec
->quick_push (build_int_cst (integer_type_node
, mo
));
11356 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
11357 finish_expr_stmt (stmt
);
11361 finish_omp_taskwait (void)
11363 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
11365 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
11366 finish_expr_stmt (stmt
);
11370 finish_omp_taskyield (void)
11372 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
11374 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
11375 finish_expr_stmt (stmt
);
11379 finish_omp_cancel (tree clauses
)
11381 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
11383 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
11385 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
11387 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
11389 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
11393 error ("%<#pragma omp cancel%> must specify one of "
11394 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
11398 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
11399 if (ifc
!= NULL_TREE
)
11401 if (OMP_CLAUSE_IF_MODIFIER (ifc
) != ERROR_MARK
11402 && OMP_CLAUSE_IF_MODIFIER (ifc
) != VOID_CST
)
11403 error_at (OMP_CLAUSE_LOCATION (ifc
),
11404 "expected %<cancel%> %<if%> clause modifier");
11407 tree ifc2
= omp_find_clause (OMP_CLAUSE_CHAIN (ifc
), OMP_CLAUSE_IF
);
11408 if (ifc2
!= NULL_TREE
)
11410 gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc
) == VOID_CST
11411 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != ERROR_MARK
11412 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != VOID_CST
);
11413 error_at (OMP_CLAUSE_LOCATION (ifc2
),
11414 "expected %<cancel%> %<if%> clause modifier");
11418 if (!processing_template_decl
)
11419 ifc
= maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc
));
11421 ifc
= build_x_binary_op (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
11422 OMP_CLAUSE_IF_EXPR (ifc
), ERROR_MARK
,
11423 integer_zero_node
, ERROR_MARK
,
11424 NULL_TREE
, NULL
, tf_warning_or_error
);
11427 ifc
= boolean_true_node
;
11428 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
11429 vec
->quick_push (ifc
);
11430 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
11431 finish_expr_stmt (stmt
);
11435 finish_omp_cancellation_point (tree clauses
)
11437 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
11439 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
11441 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
11443 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
11445 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
11449 error ("%<#pragma omp cancellation point%> must specify one of "
11450 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
11454 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
11455 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
11456 finish_expr_stmt (stmt
);
11459 /* Begin a __transaction_atomic or __transaction_relaxed statement.
11460 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
11461 should create an extra compound stmt. */
11464 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
11469 *pcompound
= begin_compound_stmt (0);
11471 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
11473 /* Only add the statement to the function if support enabled. */
11477 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
11478 ? G_("%<__transaction_relaxed%> without "
11479 "transactional memory support enabled")
11480 : G_("%<__transaction_atomic%> without "
11481 "transactional memory support enabled")));
11483 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
11484 TREE_SIDE_EFFECTS (r
) = 1;
11488 /* End a __transaction_atomic or __transaction_relaxed statement.
11489 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
11490 and we should end the compound. If NOEX is non-NULL, we wrap the body in
11491 a MUST_NOT_THROW_EXPR with NOEX as condition. */
11494 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
11496 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
11497 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
11498 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
11499 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
11501 /* noexcept specifications are not allowed for function transactions. */
11502 gcc_assert (!(noex
&& compound_stmt
));
11505 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
11507 protected_set_expr_location
11508 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
11509 TREE_SIDE_EFFECTS (body
) = 1;
11510 TRANSACTION_EXPR_BODY (stmt
) = body
;
11514 finish_compound_stmt (compound_stmt
);
11517 /* Build a __transaction_atomic or __transaction_relaxed expression. If
11518 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
11522 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
11527 expr
= build_must_not_throw_expr (expr
, noex
);
11528 protected_set_expr_location (expr
, loc
);
11529 TREE_SIDE_EFFECTS (expr
) = 1;
11531 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
11532 if (flags
& TM_STMT_ATTR_RELAXED
)
11533 TRANSACTION_EXPR_RELAXED (ret
) = 1;
11534 TREE_SIDE_EFFECTS (ret
) = 1;
11535 SET_EXPR_LOCATION (ret
, loc
);
11540 init_cp_semantics (void)
11545 /* Build a STATIC_ASSERT for a static assertion with the condition
11546 CONDITION and the message text MESSAGE. LOCATION is the location
11547 of the static assertion in the source code. When MEMBER_P, this
11548 static assertion is a member of a class. If SHOW_EXPR_P is true,
11549 print the condition (because it was instantiation-dependent). */
11552 finish_static_assert (tree condition
, tree message
, location_t location
,
11553 bool member_p
, bool show_expr_p
)
11555 tsubst_flags_t complain
= tf_warning_or_error
;
11556 tree message_sz
= NULL_TREE
, message_data
= NULL_TREE
;
11558 if (message
== NULL_TREE
11559 || message
== error_mark_node
11560 || condition
== NULL_TREE
11561 || condition
== error_mark_node
)
11564 if (check_for_bare_parameter_packs (condition
)
11565 || check_for_bare_parameter_packs (message
))
11568 if (TREE_CODE (message
) != STRING_CST
11569 && !type_dependent_expression_p (message
))
11572 = finish_class_member_access_expr (message
,
11573 get_identifier ("size"),
11575 if (message_sz
!= error_mark_node
)
11577 = finish_class_member_access_expr (message
,
11578 get_identifier ("data"),
11580 if (message_sz
== error_mark_node
|| message_data
== error_mark_node
)
11582 error_at (location
, "%<static_assert%> message must be a string "
11583 "literal or object with %<size%> and "
11584 "%<data%> members");
11587 releasing_vec size_args
, data_args
;
11588 message_sz
= finish_call_expr (message_sz
, &size_args
, false, false,
11590 message_data
= finish_call_expr (message_data
, &data_args
, false, false,
11592 if (message_sz
== error_mark_node
|| message_data
== error_mark_node
)
11594 message_sz
= build_converted_constant_expr (size_type_node
, message_sz
,
11596 if (message_sz
== error_mark_node
)
11598 error_at (location
, "%<static_assert%> message %<size()%> "
11599 "must be implicitly convertible to "
11600 "%<std::size_t%>");
11603 message_data
= build_converted_constant_expr (const_string_type_node
,
11604 message_data
, complain
);
11605 if (message_data
== error_mark_node
)
11607 error_at (location
, "%<static_assert%> message %<data()%> "
11608 "must be implicitly convertible to "
11609 "%<const char*%>");
11614 /* Save the condition in case it was a concept check. */
11615 tree orig_condition
= condition
;
11617 if (instantiation_dependent_expression_p (condition
)
11618 || instantiation_dependent_expression_p (message
))
11620 /* We're in a template; build a STATIC_ASSERT and put it in
11621 the right place. */
11623 tree assertion
= make_node (STATIC_ASSERT
);
11624 STATIC_ASSERT_CONDITION (assertion
) = orig_condition
;
11625 STATIC_ASSERT_MESSAGE (assertion
) = message
;
11626 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
11629 maybe_add_class_template_decl_list (current_class_type
,
11633 add_stmt (assertion
);
11638 /* Fold the expression and convert it to a boolean value. */
11639 condition
= contextual_conv_bool (condition
, complain
);
11640 condition
= fold_non_dependent_expr (condition
, complain
,
11641 /*manifestly_const_eval=*/true);
11643 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
11644 /* Do nothing; the condition is satisfied. */
11648 iloc_sentinel
ils (location
);
11650 if (integer_zerop (condition
))
11652 /* CWG2518: static_assert failure in a template is not IFNDR. */
11653 if (processing_template_decl
)
11657 const char *msg
= NULL
;
11659 if (message_sz
&& message_data
)
11661 tree msz
= cxx_constant_value (message_sz
, NULL_TREE
, complain
);
11662 if (!tree_fits_uhwi_p (msz
))
11664 error_at (location
,
11665 "%<static_assert%> message %<size()%> "
11666 "must be a constant expression");
11669 else if ((unsigned HOST_WIDE_INT
) (int) tree_to_uhwi (msz
)
11670 != tree_to_uhwi (msz
))
11672 error_at (location
,
11673 "%<static_assert%> message %<size()%> "
11674 "%qE too large", msz
);
11677 len
= tree_to_uhwi (msz
);
11678 tree data
= maybe_constant_value (message_data
, NULL_TREE
,
11680 if (!reduced_constant_expression_p (data
))
11685 msg
= c_getstr (data
);
11687 buf
= XNEWVEC (char, len
);
11688 for (int i
= 0; i
< len
; ++i
)
11690 tree t
= message_data
;
11692 t
= build2 (POINTER_PLUS_EXPR
,
11693 TREE_TYPE (message_data
), message_data
,
11695 t
= build1 (INDIRECT_REF
, TREE_TYPE (TREE_TYPE (t
)), t
);
11696 tree t2
= cxx_constant_value (t
, NULL_TREE
, complain
);
11697 if (!tree_fits_shwi_p (t2
))
11699 error_at (location
,
11700 "%<static_assert%> message %<data()[%d]%> "
11701 "must be a constant expression", i
);
11706 buf
[i
] = tree_to_shwi (t2
);
11707 /* If c_getstr worked, just verify the first and
11708 last characters using constant evaluation. */
11709 else if (len
> 2 && i
== 0)
11717 /* We don't have any function to test whether some
11718 expression is a core constant expression. So, instead
11719 test whether (message.data (), 0) is a constant
11721 data
= build2 (COMPOUND_EXPR
, integer_type_node
,
11722 message_data
, integer_zero_node
);
11723 tree t
= cxx_constant_value (data
, NULL_TREE
, complain
);
11724 if (!integer_zerop (t
))
11726 error_at (location
,
11727 "%<static_assert%> message %<data()%> "
11728 "must be a core constant expression");
11735 tree eltype
= TREE_TYPE (TREE_TYPE (message
));
11736 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT (eltype
));
11737 msg
= TREE_STRING_POINTER (message
);
11738 len
= TREE_STRING_LENGTH (message
) / sz
- 1;
11741 /* See if we can find which clause was failing (for logical AND). */
11742 tree bad
= find_failing_clause (NULL
, orig_condition
);
11743 /* If not, or its location is unusable, fall back to the previous
11745 location_t cloc
= cp_expr_loc_or_loc (bad
, location
);
11747 auto_diagnostic_group d
;
11749 /* Report the error. */
11751 error_at (cloc
, "static assertion failed");
11753 error_at (cloc
, "static assertion failed: %.*s", len
, msg
);
11757 diagnose_failing_condition (bad
, cloc
, show_expr_p
);
11759 else if (condition
&& condition
!= error_mark_node
)
11761 error ("non-constant condition for static assertion");
11762 if (require_rvalue_constant_expression (condition
))
11763 cxx_constant_value (condition
);
11768 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
11769 suitable for use as a type-specifier.
11771 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
11772 id-expression or a class member access, FALSE when it was parsed as
11773 a full expression. */
11776 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
11777 tsubst_flags_t complain
)
11779 tree type
= NULL_TREE
;
11781 if (!expr
|| error_operand_p (expr
))
11782 return error_mark_node
;
11785 || TREE_CODE (expr
) == TYPE_DECL
11786 || (TREE_CODE (expr
) == BIT_NOT_EXPR
11787 && TYPE_P (TREE_OPERAND (expr
, 0))))
11789 if (complain
& tf_error
)
11790 error ("argument to %<decltype%> must be an expression");
11791 return error_mark_node
;
11794 /* decltype is an unevaluated context. */
11797 processing_template_decl_sentinel
ptds (/*reset=*/false);
11799 /* Depending on the resolution of DR 1172, we may later need to distinguish
11800 instantiation-dependent but not type-dependent expressions so that, say,
11801 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
11802 if (instantiation_dependent_uneval_expression_p (expr
))
11805 type
= cxx_make_type (DECLTYPE_TYPE
);
11806 DECLTYPE_TYPE_EXPR (type
) = expr
;
11807 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
11808 = id_expression_or_member_access_p
;
11809 SET_TYPE_STRUCTURAL_EQUALITY (type
);
11813 else if (processing_template_decl
)
11815 expr
= instantiate_non_dependent_expr (expr
, complain
|tf_decltype
);
11816 if (expr
== error_mark_node
)
11817 return error_mark_node
;
11818 /* Keep processing_template_decl cleared for the rest of the function
11819 (for sake of the call to lvalue_kind below, which handles templated
11820 and non-templated COND_EXPR differently). */
11821 processing_template_decl
= 0;
11824 /* The type denoted by decltype(e) is defined as follows: */
11826 expr
= resolve_nondeduced_context (expr
, complain
);
11827 if (!mark_single_function (expr
, complain
))
11828 return error_mark_node
;
11830 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
11831 return error_mark_node
;
11833 if (type_unknown_p (expr
))
11835 if (complain
& tf_error
)
11836 error ("%<decltype%> cannot resolve address of overloaded function");
11837 return error_mark_node
;
11840 /* To get the size of a static data member declared as an array of
11841 unknown bound, we need to instantiate it. */
11843 && VAR_HAD_UNKNOWN_BOUND (expr
)
11844 && DECL_TEMPLATE_INSTANTIATION (expr
))
11845 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
11847 if (id_expression_or_member_access_p
)
11849 /* If e is an id-expression or a class member access (5.2.5
11850 [expr.ref]), decltype(e) is defined as the type of the entity
11851 named by e. If there is no such entity, or e names a set of
11852 overloaded functions, the program is ill-formed. */
11853 if (identifier_p (expr
))
11854 expr
= lookup_name (expr
);
11856 if (INDIRECT_REF_P (expr
)
11857 || TREE_CODE (expr
) == VIEW_CONVERT_EXPR
)
11858 /* This can happen when the expression is, e.g., "a.b". Just
11859 look at the underlying operand. */
11860 expr
= TREE_OPERAND (expr
, 0);
11862 if (TREE_CODE (expr
) == OFFSET_REF
11863 || TREE_CODE (expr
) == MEMBER_REF
11864 || TREE_CODE (expr
) == SCOPE_REF
)
11865 /* We're only interested in the field itself. If it is a
11866 BASELINK, we will need to see through it in the next
11868 expr
= TREE_OPERAND (expr
, 1);
11870 if (BASELINK_P (expr
))
11871 /* See through BASELINK nodes to the underlying function. */
11872 expr
= BASELINK_FUNCTIONS (expr
);
11874 /* decltype of a decomposition name drops references in the tuple case
11875 (unlike decltype of a normal variable) and keeps cv-qualifiers from
11876 the containing object in the other cases (unlike decltype of a member
11877 access expression). */
11878 if (DECL_DECOMPOSITION_P (expr
))
11882 gcc_checking_assert (DECL_HAS_VALUE_EXPR_P (expr
));
11883 /* DECL_HAS_VALUE_EXPR_P is always set if
11884 processing_template_decl. If lookup_decomp_type
11885 returns non-NULL, it is the tuple case. */
11886 if (tree ret
= lookup_decomp_type (expr
))
11889 if (DECL_HAS_VALUE_EXPR_P (expr
))
11890 /* Expr is an array or struct subobject proxy, handle
11891 bit-fields properly. */
11892 return unlowered_expr_type (expr
);
11894 /* Expr is a reference variable for the tuple case. */
11895 return lookup_decomp_type (expr
);
11898 switch (TREE_CODE (expr
))
11901 if (DECL_BIT_FIELD_TYPE (expr
))
11903 type
= DECL_BIT_FIELD_TYPE (expr
);
11906 /* Fall through for fields that aren't bitfields. */
11907 gcc_fallthrough ();
11910 if (is_capture_proxy (expr
))
11912 if (is_normal_capture_proxy (expr
))
11914 expr
= DECL_CAPTURED_VARIABLE (expr
);
11915 type
= TREE_TYPE (expr
);
11916 type
= non_reference (type
);
11920 expr
= DECL_VALUE_EXPR (expr
);
11921 gcc_assert (TREE_CODE (expr
) == COMPONENT_REF
);
11922 expr
= TREE_OPERAND (expr
, 1);
11923 type
= TREE_TYPE (expr
);
11927 /* Fall through for variables that aren't capture proxies. */
11928 gcc_fallthrough ();
11930 case FUNCTION_DECL
:
11934 case TEMPLATE_PARM_INDEX
:
11935 expr
= mark_type_use (expr
);
11936 type
= TREE_TYPE (expr
);
11937 if (VAR_P (expr
) && DECL_NTTP_OBJECT_P (expr
))
11939 /* decltype of an NTTP object is the type of the template
11940 parameter, which is the object type modulo cv-quals. */
11941 int quals
= cp_type_quals (type
);
11942 gcc_checking_assert (quals
& TYPE_QUAL_CONST
);
11943 type
= cv_unqualified (type
);
11948 type
= error_mark_node
;
11951 case COMPONENT_REF
:
11952 case COMPOUND_EXPR
:
11953 mark_type_use (expr
);
11954 type
= is_bitfield_expr_with_lowered_type (expr
);
11956 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
11959 case BIT_FIELD_REF
:
11960 gcc_unreachable ();
11964 /* We can get here when the id-expression refers to an
11965 enumerator or non-type template parameter. */
11966 type
= TREE_TYPE (expr
);
11970 /* Handle instantiated template non-type arguments. */
11971 type
= TREE_TYPE (expr
);
11977 if (outer_automatic_var_p (STRIP_REFERENCE_REF (expr
))
11978 && current_function_decl
11979 && LAMBDA_FUNCTION_P (current_function_decl
))
11981 /* [expr.prim.id.unqual]/3: If naming the entity from outside of an
11982 unevaluated operand within S would refer to an entity captured by
11983 copy in some intervening lambda-expression, then let E be the
11984 innermost such lambda-expression.
11986 If there is such a lambda-expression and if P is in E's function
11987 parameter scope but not its parameter-declaration-clause, then the
11988 type of the expression is the type of a class member access
11989 expression naming the non-static data member that would be declared
11990 for such a capture in the object parameter of the function call
11992 /* FIXME: This transformation needs to happen for all uses of an outer
11993 local variable inside decltype, not just decltype((x)) (PR83167).
11994 And we don't handle nested lambdas properly, where we need to
11995 consider the outer lambdas as well (PR112926). */
11996 tree decl
= STRIP_REFERENCE_REF (expr
);
11997 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
11998 tree cap
= lookup_name (DECL_NAME (decl
), LOOK_where::BLOCK
,
11999 LOOK_want::HIDDEN_LAMBDA
);
12001 if (cap
&& is_capture_proxy (cap
))
12002 type
= TREE_TYPE (cap
);
12003 else if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
) == CPLD_COPY
)
12005 type
= TREE_TYPE (decl
);
12006 if (TYPE_REF_P (type
)
12007 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
12008 type
= TREE_TYPE (type
);
12011 if (type
&& !TYPE_REF_P (type
))
12013 tree obtype
= TREE_TYPE (DECL_ARGUMENTS (current_function_decl
));
12014 if (WILDCARD_TYPE_P (non_reference (obtype
)))
12015 /* We don't know what the eventual obtype quals will be. */
12017 auto direct_type
= [](tree t
){
12018 if (INDIRECT_TYPE_P (t
))
12019 return TREE_TYPE (t
);
12022 int const quals
= cp_type_quals (type
)
12023 | cp_type_quals (direct_type (obtype
));
12024 type
= cp_build_qualified_type (type
, quals
);
12025 type
= build_reference_type (type
);
12028 else if (error_operand_p (expr
))
12029 type
= error_mark_node
;
12030 else if (expr
== current_class_ptr
)
12031 /* If the expression is just "this", we want the
12032 cv-unqualified pointer for the "this" type. */
12033 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
12037 /* Otherwise, where T is the type of e, if e is an lvalue,
12038 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
12039 cp_lvalue_kind clk
= lvalue_kind (expr
);
12040 type
= unlowered_expr_type (expr
);
12041 gcc_assert (!TYPE_REF_P (type
));
12043 /* For vector types, pick a non-opaque variant. */
12044 if (VECTOR_TYPE_P (type
))
12045 type
= strip_typedefs (type
);
12047 if (clk
!= clk_none
&& !(clk
& clk_class
))
12048 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
12055 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
12056 __has_nothrow_copy, depending on assign_p. Returns true iff all
12057 the copy {ctor,assign} fns are nothrow. */
12060 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
12062 tree fns
= NULL_TREE
;
12064 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
12065 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
12066 : ctor_identifier
);
12068 bool saw_copy
= false;
12069 for (ovl_iterator
iter (fns
); iter
; ++iter
)
12073 if (copy_fn_p (fn
) > 0)
12076 if (!maybe_instantiate_noexcept (fn
)
12077 || !TYPE_NOTHROW_P (TREE_TYPE (fn
)))
12085 /* Return true if DERIVED is pointer interconvertible base of BASE. */
12088 pointer_interconvertible_base_of_p (tree base
, tree derived
)
12090 if (base
== error_mark_node
|| derived
== error_mark_node
)
12092 base
= TYPE_MAIN_VARIANT (base
);
12093 derived
= TYPE_MAIN_VARIANT (derived
);
12094 if (!NON_UNION_CLASS_TYPE_P (base
)
12095 || !NON_UNION_CLASS_TYPE_P (derived
))
12098 if (same_type_p (base
, derived
))
12101 if (!std_layout_type_p (derived
))
12104 return uniquely_derived_from_p (base
, derived
);
12107 /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
12108 return true if MEMBERTYPE is the type of the first non-static data member
12109 of TYPE or for unions of any members. */
12111 first_nonstatic_data_member_p (tree type
, tree membertype
)
12113 for (tree field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
12115 if (TREE_CODE (field
) != FIELD_DECL
)
12117 if (DECL_FIELD_IS_BASE (field
) && is_empty_field (field
))
12119 if (DECL_FIELD_IS_BASE (field
))
12120 return first_nonstatic_data_member_p (TREE_TYPE (field
), membertype
);
12121 if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
12123 if ((TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
12124 || std_layout_type_p (TREE_TYPE (field
)))
12125 && first_nonstatic_data_member_p (TREE_TYPE (field
), membertype
))
12128 else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field
),
12131 if (TREE_CODE (type
) != UNION_TYPE
)
12137 /* Fold __builtin_is_pointer_interconvertible_with_class call. */
12140 fold_builtin_is_pointer_inverconvertible_with_class (location_t loc
, int nargs
,
12143 /* Unless users call the builtin directly, the following 3 checks should be
12144 ensured from std::is_pointer_interconvertible_with_class function
12148 error_at (loc
, "%<__builtin_is_pointer_interconvertible_with_class%> "
12149 "needs a single argument");
12150 return boolean_false_node
;
12152 tree arg
= args
[0];
12153 if (error_operand_p (arg
))
12154 return boolean_false_node
;
12155 if (!TYPE_PTRMEM_P (TREE_TYPE (arg
)))
12157 error_at (loc
, "%<__builtin_is_pointer_interconvertible_with_class%> "
12158 "argument is not pointer to member");
12159 return boolean_false_node
;
12162 if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg
)))
12163 return boolean_false_node
;
12165 tree membertype
= TREE_TYPE (TREE_TYPE (arg
));
12166 tree basetype
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg
));
12167 if (!complete_type_or_else (basetype
, NULL_TREE
))
12168 return boolean_false_node
;
12170 if (TREE_CODE (basetype
) != UNION_TYPE
12171 && !std_layout_type_p (basetype
))
12172 return boolean_false_node
;
12174 if (!first_nonstatic_data_member_p (basetype
, membertype
))
12175 return boolean_false_node
;
12177 if (TREE_CODE (arg
) == PTRMEM_CST
)
12178 arg
= cplus_expand_constant (arg
);
12180 if (integer_nonzerop (arg
))
12181 return boolean_false_node
;
12182 if (integer_zerop (arg
))
12183 return boolean_true_node
;
12185 return fold_build2 (EQ_EXPR
, boolean_type_node
, arg
,
12186 build_zero_cst (TREE_TYPE (arg
)));
12189 /* Helper function for is_corresponding_member_aggr. Return true if
12190 MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
12191 union or structure BASETYPE. */
12194 is_corresponding_member_union (tree basetype
, tree membertype
, tree arg
)
12196 for (tree field
= TYPE_FIELDS (basetype
); field
; field
= DECL_CHAIN (field
))
12197 if (TREE_CODE (field
) != FIELD_DECL
|| DECL_BIT_FIELD_TYPE (field
))
12199 else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field
),
12202 if (TREE_CODE (arg
) != INTEGER_CST
12203 || tree_int_cst_equal (arg
, byte_position (field
)))
12206 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
12209 if (TREE_CODE (basetype
) != UNION_TYPE
12210 && TREE_CODE (narg
) == INTEGER_CST
)
12211 narg
= size_binop (MINUS_EXPR
, arg
, byte_position (field
));
12212 if (is_corresponding_member_union (TREE_TYPE (field
),
12219 /* Helper function for fold_builtin_is_corresponding_member call.
12220 Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
12221 MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
12222 boolean_true_node if they are corresponding members, or for
12223 non-constant ARG2 the highest member offset for corresponding
12227 is_corresponding_member_aggr (location_t loc
, tree basetype1
, tree membertype1
,
12228 tree arg1
, tree basetype2
, tree membertype2
,
12231 tree field1
= TYPE_FIELDS (basetype1
);
12232 tree field2
= TYPE_FIELDS (basetype2
);
12233 tree ret
= boolean_false_node
;
12236 bool r
= next_common_initial_sequence (field1
, field2
);
12237 if (field1
== NULL_TREE
|| field2
== NULL_TREE
)
12240 && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1
),
12242 && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2
),
12245 tree pos
= byte_position (field1
);
12246 if (TREE_CODE (arg1
) == INTEGER_CST
12247 && tree_int_cst_equal (arg1
, pos
))
12249 if (TREE_CODE (arg2
) == INTEGER_CST
)
12250 return boolean_true_node
;
12253 else if (TREE_CODE (arg1
) != INTEGER_CST
)
12256 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1
))
12257 && ANON_AGGR_TYPE_P (TREE_TYPE (field2
)))
12259 if ((!lookup_attribute ("no_unique_address",
12260 DECL_ATTRIBUTES (field1
)))
12261 != !lookup_attribute ("no_unique_address",
12262 DECL_ATTRIBUTES (field2
)))
12264 if (!tree_int_cst_equal (bit_position (field1
),
12265 bit_position (field2
)))
12267 bool overlap
= true;
12268 tree pos
= byte_position (field1
);
12269 if (TREE_CODE (arg1
) == INTEGER_CST
)
12271 tree off1
= fold_convert (sizetype
, arg1
);
12272 tree sz1
= TYPE_SIZE_UNIT (TREE_TYPE (field1
));
12273 if (tree_int_cst_lt (off1
, pos
)
12274 || tree_int_cst_le (size_binop (PLUS_EXPR
, pos
, sz1
), off1
))
12277 if (TREE_CODE (arg2
) == INTEGER_CST
)
12279 tree off2
= fold_convert (sizetype
, arg2
);
12280 tree sz2
= TYPE_SIZE_UNIT (TREE_TYPE (field2
));
12281 if (tree_int_cst_lt (off2
, pos
)
12282 || tree_int_cst_le (size_binop (PLUS_EXPR
, pos
, sz2
), off2
))
12286 && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1
))
12287 && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2
)))
12290 if (TREE_CODE (arg1
) == INTEGER_CST
)
12291 narg1
= size_binop (MINUS_EXPR
,
12292 fold_convert (sizetype
, arg1
), pos
);
12294 if (TREE_CODE (arg2
) == INTEGER_CST
)
12295 narg2
= size_binop (MINUS_EXPR
,
12296 fold_convert (sizetype
, arg2
), pos
);
12297 tree t1
= TREE_TYPE (field1
);
12298 tree t2
= TREE_TYPE (field2
);
12299 tree nret
= is_corresponding_member_aggr (loc
, t1
, membertype1
,
12300 narg1
, t2
, membertype2
,
12302 if (nret
!= boolean_false_node
)
12304 if (nret
== boolean_true_node
)
12306 if (TREE_CODE (arg1
) == INTEGER_CST
)
12307 return size_binop (PLUS_EXPR
, nret
, pos
);
12308 ret
= size_binop (PLUS_EXPR
, nret
, pos
);
12312 && TREE_CODE (TREE_TYPE (field1
)) == UNION_TYPE
12313 && TREE_CODE (TREE_TYPE (field2
)) == UNION_TYPE
)
12316 if (TREE_CODE (arg1
) == INTEGER_CST
)
12317 narg1
= size_binop (MINUS_EXPR
,
12318 fold_convert (sizetype
, arg1
), pos
);
12320 if (TREE_CODE (arg2
) == INTEGER_CST
)
12321 narg2
= size_binop (MINUS_EXPR
,
12322 fold_convert (sizetype
, arg2
), pos
);
12323 if (is_corresponding_member_union (TREE_TYPE (field1
),
12324 membertype1
, narg1
)
12325 && is_corresponding_member_union (TREE_TYPE (field2
),
12326 membertype2
, narg2
))
12328 sorry_at (loc
, "%<__builtin_is_corresponding_member%> "
12329 "not well defined for anonymous unions");
12330 return boolean_false_node
;
12336 field1
= DECL_CHAIN (field1
);
12337 field2
= DECL_CHAIN (field2
);
12342 /* Fold __builtin_is_corresponding_member call. */
12345 fold_builtin_is_corresponding_member (location_t loc
, int nargs
,
12348 /* Unless users call the builtin directly, the following 3 checks should be
12349 ensured from std::is_corresponding_member function template. */
12352 error_at (loc
, "%<__builtin_is_corresponding_member%> "
12353 "needs two arguments");
12354 return boolean_false_node
;
12356 tree arg1
= args
[0];
12357 tree arg2
= args
[1];
12358 if (error_operand_p (arg1
) || error_operand_p (arg2
))
12359 return boolean_false_node
;
12360 if (!TYPE_PTRMEM_P (TREE_TYPE (arg1
))
12361 || !TYPE_PTRMEM_P (TREE_TYPE (arg2
)))
12363 error_at (loc
, "%<__builtin_is_corresponding_member%> "
12364 "argument is not pointer to member");
12365 return boolean_false_node
;
12368 if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1
))
12369 || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2
)))
12370 return boolean_false_node
;
12372 tree membertype1
= TREE_TYPE (TREE_TYPE (arg1
));
12373 tree basetype1
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1
));
12374 if (!complete_type_or_else (basetype1
, NULL_TREE
))
12375 return boolean_false_node
;
12377 tree membertype2
= TREE_TYPE (TREE_TYPE (arg2
));
12378 tree basetype2
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2
));
12379 if (!complete_type_or_else (basetype2
, NULL_TREE
))
12380 return boolean_false_node
;
12382 if (!NON_UNION_CLASS_TYPE_P (basetype1
)
12383 || !NON_UNION_CLASS_TYPE_P (basetype2
)
12384 || !std_layout_type_p (basetype1
)
12385 || !std_layout_type_p (basetype2
))
12386 return boolean_false_node
;
12388 /* If the member types aren't layout compatible, then they
12389 can't be corresponding members. */
12390 if (!layout_compatible_type_p (membertype1
, membertype2
))
12391 return boolean_false_node
;
12393 if (TREE_CODE (arg1
) == PTRMEM_CST
)
12394 arg1
= cplus_expand_constant (arg1
);
12395 if (TREE_CODE (arg2
) == PTRMEM_CST
)
12396 arg2
= cplus_expand_constant (arg2
);
12398 if (null_member_pointer_value_p (arg1
)
12399 || null_member_pointer_value_p (arg2
))
12400 return boolean_false_node
;
12402 if (TREE_CODE (arg1
) == INTEGER_CST
12403 && TREE_CODE (arg2
) == INTEGER_CST
12404 && !tree_int_cst_equal (arg1
, arg2
))
12405 return boolean_false_node
;
12407 if (TREE_CODE (arg2
) == INTEGER_CST
12408 && TREE_CODE (arg1
) != INTEGER_CST
)
12410 std::swap (arg1
, arg2
);
12411 std::swap (membertype1
, membertype2
);
12412 std::swap (basetype1
, basetype2
);
12415 tree ret
= is_corresponding_member_aggr (loc
, basetype1
, membertype1
, arg1
,
12416 basetype2
, membertype2
, arg2
);
12417 if (TREE_TYPE (ret
) == boolean_type_node
)
12419 /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
12420 already returns boolean_{true,false}_node whether those particular
12421 members are corresponding members or not. Otherwise, if only
12422 one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
12423 above), it returns boolean_false_node if it is certainly not a
12424 corresponding member and otherwise we need to do a runtime check that
12425 those two OFFSET_TYPE offsets are equal.
12426 If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
12427 returns the largest offset at which the members would be corresponding
12428 members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
12429 gcc_assert (TREE_CODE (arg2
) != INTEGER_CST
);
12430 if (TREE_CODE (arg1
) == INTEGER_CST
)
12431 return fold_build2 (EQ_EXPR
, boolean_type_node
, arg1
,
12432 fold_convert (TREE_TYPE (arg1
), arg2
));
12433 ret
= fold_build2 (LE_EXPR
, boolean_type_node
,
12434 fold_convert (pointer_sized_int_node
, arg1
),
12435 fold_convert (pointer_sized_int_node
, ret
));
12436 return fold_build2 (TRUTH_AND_EXPR
, boolean_type_node
, ret
,
12437 fold_build2 (EQ_EXPR
, boolean_type_node
, arg1
,
12438 fold_convert (TREE_TYPE (arg1
), arg2
)));
12441 /* Actually evaluates the trait. */
12444 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
12446 enum tree_code type_code1
;
12449 type_code1
= TREE_CODE (type1
);
12453 case CPTK_HAS_NOTHROW_ASSIGN
:
12454 type1
= strip_array_types (type1
);
12455 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
12456 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
12457 || (CLASS_TYPE_P (type1
)
12458 && classtype_has_nothrow_assign_or_copy_p (type1
,
12461 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
12462 type1
= strip_array_types (type1
);
12463 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
12464 || (CLASS_TYPE_P (type1
)
12465 && (t
= locate_ctor (type1
))
12466 && maybe_instantiate_noexcept (t
)
12467 && TYPE_NOTHROW_P (TREE_TYPE (t
))));
12469 case CPTK_HAS_NOTHROW_COPY
:
12470 type1
= strip_array_types (type1
);
12471 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
12472 || (CLASS_TYPE_P (type1
)
12473 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
12475 case CPTK_HAS_TRIVIAL_ASSIGN
:
12476 /* ??? The standard seems to be missing the "or array of such a class
12477 type" wording for this trait. */
12478 type1
= strip_array_types (type1
);
12479 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
12480 && (trivial_type_p (type1
)
12481 || (CLASS_TYPE_P (type1
)
12482 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
12484 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
12485 type1
= strip_array_types (type1
);
12486 return (trivial_type_p (type1
)
12487 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
12489 case CPTK_HAS_TRIVIAL_COPY
:
12490 /* ??? The standard seems to be missing the "or array of such a class
12491 type" wording for this trait. */
12492 type1
= strip_array_types (type1
);
12493 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
12494 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
12496 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
12497 type1
= strip_array_types (type1
);
12498 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
12499 || (CLASS_TYPE_P (type1
)
12500 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
12502 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
12503 return type_has_unique_obj_representations (type1
);
12505 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
12506 return type_has_virtual_destructor (type1
);
12508 case CPTK_IS_ABSTRACT
:
12509 return ABSTRACT_CLASS_TYPE_P (type1
);
12511 case CPTK_IS_AGGREGATE
:
12512 return CP_AGGREGATE_TYPE_P (type1
);
12514 case CPTK_IS_ARRAY
:
12515 return (type_code1
== ARRAY_TYPE
12516 /* We don't want to report T[0] as being an array type.
12517 This is for compatibility with an implementation of
12518 std::is_array by template argument deduction, because
12519 compute_array_index_type_loc rejects a zero-size array
12520 in SFINAE context. */
12521 && !(TYPE_SIZE (type1
) && integer_zerop (TYPE_SIZE (type1
))));
12523 case CPTK_IS_ASSIGNABLE
:
12524 return is_xible (MODIFY_EXPR
, type1
, type2
);
12526 case CPTK_IS_BASE_OF
:
12527 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
12528 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
12529 || DERIVED_FROM_P (type1
, type2
)));
12531 case CPTK_IS_BOUNDED_ARRAY
:
12532 return type_code1
== ARRAY_TYPE
&& TYPE_DOMAIN (type1
);
12534 case CPTK_IS_CLASS
:
12535 return NON_UNION_CLASS_TYPE_P (type1
);
12537 case CPTK_IS_CONSTRUCTIBLE
:
12538 return is_xible (INIT_EXPR
, type1
, type2
);
12540 case CPTK_IS_CONVERTIBLE
:
12541 return is_convertible (type1
, type2
);
12543 case CPTK_IS_EMPTY
:
12544 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
12547 return type_code1
== ENUMERAL_TYPE
;
12549 case CPTK_IS_FINAL
:
12550 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
12552 case CPTK_IS_FUNCTION
:
12553 return type_code1
== FUNCTION_TYPE
;
12555 case CPTK_IS_LAYOUT_COMPATIBLE
:
12556 return layout_compatible_type_p (type1
, type2
);
12558 case CPTK_IS_LITERAL_TYPE
:
12559 return literal_type_p (type1
);
12561 case CPTK_IS_MEMBER_FUNCTION_POINTER
:
12562 return TYPE_PTRMEMFUNC_P (type1
);
12564 case CPTK_IS_MEMBER_OBJECT_POINTER
:
12565 return TYPE_PTRDATAMEM_P (type1
);
12567 case CPTK_IS_MEMBER_POINTER
:
12568 return TYPE_PTRMEM_P (type1
);
12570 case CPTK_IS_NOTHROW_ASSIGNABLE
:
12571 return is_nothrow_xible (MODIFY_EXPR
, type1
, type2
);
12573 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
12574 return is_nothrow_xible (INIT_EXPR
, type1
, type2
);
12576 case CPTK_IS_NOTHROW_CONVERTIBLE
:
12577 return is_nothrow_convertible (type1
, type2
);
12579 case CPTK_IS_OBJECT
:
12580 return (type_code1
!= FUNCTION_TYPE
12581 && type_code1
!= REFERENCE_TYPE
12582 && type_code1
!= VOID_TYPE
);
12584 case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF
:
12585 return pointer_interconvertible_base_of_p (type1
, type2
);
12588 return pod_type_p (type1
);
12590 case CPTK_IS_POLYMORPHIC
:
12591 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
12593 case CPTK_IS_REFERENCE
:
12594 return type_code1
== REFERENCE_TYPE
;
12597 return same_type_p (type1
, type2
);
12599 case CPTK_IS_SCOPED_ENUM
:
12600 return SCOPED_ENUM_P (type1
);
12602 case CPTK_IS_STD_LAYOUT
:
12603 return std_layout_type_p (type1
);
12605 case CPTK_IS_TRIVIAL
:
12606 return trivial_type_p (type1
);
12608 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
12609 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
12611 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
12612 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
12614 case CPTK_IS_TRIVIALLY_COPYABLE
:
12615 return trivially_copyable_p (type1
);
12617 case CPTK_IS_UNION
:
12618 return type_code1
== UNION_TYPE
;
12620 case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY
:
12621 return ref_xes_from_temporary (type1
, type2
, /*direct_init=*/true);
12623 case CPTK_REF_CONVERTS_FROM_TEMPORARY
:
12624 return ref_xes_from_temporary (type1
, type2
, /*direct_init=*/false);
12626 case CPTK_IS_DEDUCIBLE
:
12627 return type_targs_deducible_from (type1
, type2
);
12629 #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
12631 #include "cp-trait.def"
12632 #undef DEFTRAIT_TYPE
12633 /* Type-yielding traits are handled in finish_trait_type. */
12637 gcc_unreachable ();
12640 /* Returns true if TYPE meets the requirements for the specified KIND,
12643 When KIND == 1, TYPE must be an array of unknown bound,
12644 or (possibly cv-qualified) void, or a complete type.
12646 When KIND == 2, TYPE must be a complete type, or array of complete type,
12647 or (possibly cv-qualified) void.
12650 If TYPE is a non-union class type, it must be complete.
12653 If TYPE is a class type, it must be complete. */
12656 check_trait_type (tree type
, int kind
= 1)
12658 if (type
== NULL_TREE
)
12661 if (TREE_CODE (type
) == TREE_VEC
)
12663 for (tree arg
: tree_vec_range (type
))
12664 if (!check_trait_type (arg
, kind
))
12669 if (kind
== 1 && TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
))
12670 return true; // Array of unknown bound. Don't care about completeness.
12672 if (kind
== 3 && !NON_UNION_CLASS_TYPE_P (type
))
12673 return true; // Not a non-union class type. Don't care about completeness.
12675 if (kind
== 4 && TREE_CODE (type
) == ARRAY_TYPE
)
12676 return true; // Not a class type. Don't care about completeness.
12678 if (VOID_TYPE_P (type
))
12681 type
= complete_type (strip_array_types (type
));
12682 if (!COMPLETE_TYPE_P (type
)
12683 && cxx_incomplete_type_diagnostic (NULL_TREE
, type
, DK_PERMERROR
)
12684 && !flag_permissive
)
12689 /* True iff the conversion (if any) would be a direct reference
12690 binding, not requiring complete types. This is LWG2939. */
12693 same_type_ref_bind_p (cp_trait_kind kind
, tree type1
, tree type2
)
12698 /* These put the target type first. */
12699 case CPTK_IS_CONSTRUCTIBLE
:
12700 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
12701 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
12702 case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY
:
12703 case CPTK_REF_CONVERTS_FROM_TEMPORARY
:
12708 /* These put it second. */
12709 case CPTK_IS_CONVERTIBLE
:
12710 case CPTK_IS_NOTHROW_CONVERTIBLE
:
12716 gcc_unreachable ();
12719 if (TREE_CODE (to
) != REFERENCE_TYPE
|| !from
)
12721 if (TREE_CODE (from
) == TREE_VEC
&& TREE_VEC_LENGTH (from
) == 1)
12722 from
= TREE_VEC_ELT (from
, 0);
12723 return (TYPE_P (from
)
12724 && (same_type_ignoring_top_level_qualifiers_p
12725 (non_reference (to
), non_reference (from
))));
12728 /* Process a trait expression. */
12731 finish_trait_expr (location_t loc
, cp_trait_kind kind
, tree type1
, tree type2
)
12733 if (type1
== error_mark_node
12734 || type2
== error_mark_node
)
12735 return error_mark_node
;
12737 if (processing_template_decl
)
12739 tree trait_expr
= make_node (TRAIT_EXPR
);
12740 TREE_TYPE (trait_expr
) = boolean_type_node
;
12741 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
12742 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
12743 TRAIT_EXPR_KIND (trait_expr
) = kind
;
12744 TRAIT_EXPR_LOCATION (trait_expr
) = loc
;
12750 case CPTK_HAS_NOTHROW_ASSIGN
:
12751 case CPTK_HAS_TRIVIAL_ASSIGN
:
12752 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
12753 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
12754 case CPTK_HAS_NOTHROW_COPY
:
12755 case CPTK_HAS_TRIVIAL_COPY
:
12756 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
12757 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
12758 if (!check_trait_type (type1
))
12759 return error_mark_node
;
12762 case CPTK_IS_LITERAL_TYPE
:
12764 case CPTK_IS_STD_LAYOUT
:
12765 case CPTK_IS_TRIVIAL
:
12766 case CPTK_IS_TRIVIALLY_COPYABLE
:
12767 if (!check_trait_type (type1
, /* kind = */ 2))
12768 return error_mark_node
;
12771 case CPTK_IS_ABSTRACT
:
12772 case CPTK_IS_EMPTY
:
12773 case CPTK_IS_POLYMORPHIC
:
12774 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
12775 if (!check_trait_type (type1
, /* kind = */ 3))
12776 return error_mark_node
;
12779 /* N.B. std::is_aggregate is kind=2 but we don't need a complete element
12780 type to know whether an array is an aggregate, so use kind=4 here. */
12781 case CPTK_IS_AGGREGATE
:
12782 case CPTK_IS_FINAL
:
12783 if (!check_trait_type (type1
, /* kind = */ 4))
12784 return error_mark_node
;
12787 case CPTK_IS_CONSTRUCTIBLE
:
12788 case CPTK_IS_CONVERTIBLE
:
12789 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
12790 case CPTK_IS_NOTHROW_CONVERTIBLE
:
12791 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
12792 case CPTK_REF_CONSTRUCTS_FROM_TEMPORARY
:
12793 case CPTK_REF_CONVERTS_FROM_TEMPORARY
:
12794 /* Don't check completeness for direct reference binding. */;
12795 if (same_type_ref_bind_p (kind
, type1
, type2
))
12797 gcc_fallthrough ();
12799 case CPTK_IS_ASSIGNABLE
:
12800 case CPTK_IS_NOTHROW_ASSIGNABLE
:
12801 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
12802 if (!check_trait_type (type1
)
12803 || !check_trait_type (type2
))
12804 return error_mark_node
;
12807 case CPTK_IS_BASE_OF
:
12808 case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF
:
12809 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
12810 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
12811 && !complete_type_or_else (type2
, NULL_TREE
))
12812 /* We already issued an error. */
12813 return error_mark_node
;
12816 case CPTK_IS_ARRAY
:
12817 case CPTK_IS_BOUNDED_ARRAY
:
12818 case CPTK_IS_CLASS
:
12820 case CPTK_IS_FUNCTION
:
12821 case CPTK_IS_MEMBER_FUNCTION_POINTER
:
12822 case CPTK_IS_MEMBER_OBJECT_POINTER
:
12823 case CPTK_IS_MEMBER_POINTER
:
12824 case CPTK_IS_OBJECT
:
12825 case CPTK_IS_REFERENCE
:
12827 case CPTK_IS_SCOPED_ENUM
:
12828 case CPTK_IS_UNION
:
12831 case CPTK_IS_LAYOUT_COMPATIBLE
:
12832 if (!array_of_unknown_bound_p (type1
)
12833 && TREE_CODE (type1
) != VOID_TYPE
12834 && !complete_type_or_else (type1
, NULL_TREE
))
12835 /* We already issued an error. */
12836 return error_mark_node
;
12837 if (!array_of_unknown_bound_p (type2
)
12838 && TREE_CODE (type2
) != VOID_TYPE
12839 && !complete_type_or_else (type2
, NULL_TREE
))
12840 /* We already issued an error. */
12841 return error_mark_node
;
12844 case CPTK_IS_DEDUCIBLE
:
12845 if (!DECL_TYPE_TEMPLATE_P (type1
))
12847 error ("%qD is not a class or alias template", type1
);
12848 return error_mark_node
;
12852 #define DEFTRAIT_TYPE(CODE, NAME, ARITY) \
12854 #include "cp-trait.def"
12855 #undef DEFTRAIT_TYPE
12856 /* Type-yielding traits are handled in finish_trait_type. */
12857 gcc_unreachable ();
12860 tree val
= (trait_expr_value (kind
, type1
, type2
)
12861 ? boolean_true_node
: boolean_false_node
);
12862 return maybe_wrap_with_location (val
, loc
);
12865 /* Process a trait type. */
12868 finish_trait_type (cp_trait_kind kind
, tree type1
, tree type2
,
12869 tsubst_flags_t complain
)
12871 if (type1
== error_mark_node
12872 || type2
== error_mark_node
)
12873 return error_mark_node
;
12875 if (processing_template_decl
)
12877 tree type
= cxx_make_type (TRAIT_TYPE
);
12878 TRAIT_TYPE_TYPE1 (type
) = type1
;
12879 TRAIT_TYPE_TYPE2 (type
) = type2
;
12880 TRAIT_TYPE_KIND_RAW (type
) = build_int_cstu (integer_type_node
, kind
);
12881 /* These traits are intended to be used in the definition of the ::type
12882 member of the corresponding standard library type trait and aren't
12883 mangleable (and thus won't appear directly in template signatures),
12884 so structural equality should suffice. */
12885 SET_TYPE_STRUCTURAL_EQUALITY (type
);
12891 case CPTK_REMOVE_CV
:
12892 return cv_unqualified (type1
);
12894 case CPTK_REMOVE_CVREF
:
12895 if (TYPE_REF_P (type1
))
12896 type1
= TREE_TYPE (type1
);
12897 return cv_unqualified (type1
);
12899 case CPTK_REMOVE_POINTER
:
12900 if (TYPE_PTR_P (type1
))
12901 type1
= TREE_TYPE (type1
);
12904 case CPTK_REMOVE_REFERENCE
:
12905 if (TYPE_REF_P (type1
))
12906 type1
= TREE_TYPE (type1
);
12909 case CPTK_TYPE_PACK_ELEMENT
:
12910 return finish_type_pack_element (type1
, type2
, complain
);
12912 case CPTK_UNDERLYING_TYPE
:
12913 return finish_underlying_type (type1
);
12915 #define DEFTRAIT_EXPR(CODE, NAME, ARITY) \
12917 #include "cp-trait.def"
12918 #undef DEFTRAIT_EXPR
12919 /* Expression-yielding traits are handled in finish_trait_expr. */
12921 case CPTK_DIRECT_BASES
:
12922 /* BASES and DIRECT_BASES are handled in finish_bases. */
12926 gcc_unreachable ();
12929 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
12930 which is ignored for C++. */
12933 set_float_const_decimal64 (void)
12938 clear_float_const_decimal64 (void)
12943 float_const_decimal64_p (void)
12949 /* Return true if T designates the implied `this' parameter. */
12952 is_this_parameter (tree t
)
12954 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
12956 gcc_assert (TREE_CODE (t
) == PARM_DECL
12957 || (VAR_P (t
) && DECL_HAS_VALUE_EXPR_P (t
))
12958 || (cp_binding_oracle
&& VAR_P (t
)));
12962 /* As above, or a C++23 explicit object parameter. */
12965 is_object_parameter (tree t
)
12967 if (is_this_parameter (t
))
12969 if (TREE_CODE (t
) != PARM_DECL
)
12971 tree ctx
= DECL_CONTEXT (t
);
12972 return (ctx
&& DECL_XOBJ_MEMBER_FUNCTION_P (ctx
)
12973 && t
== DECL_ARGUMENTS (ctx
));
12976 /* Insert the deduced return type for an auto function. */
12979 apply_deduced_return_type (tree fco
, tree return_type
)
12983 if (return_type
== error_mark_node
)
12986 if (DECL_CONV_FN_P (fco
))
12987 DECL_NAME (fco
) = make_conv_op_name (return_type
);
12989 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
12991 maybe_update_postconditions (fco
);
12993 /* Apply the type to the result object. */
12995 result
= DECL_RESULT (fco
);
12996 if (result
== NULL_TREE
)
12998 if (TREE_TYPE (result
) == return_type
)
13001 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
13002 && !complete_type_or_else (return_type
, NULL_TREE
))
13005 /* We already have a DECL_RESULT from start_preparsed_function.
13006 Now we need to redo the work it and allocate_struct_function
13007 did to reflect the new type. */
13008 result
= build_decl (DECL_SOURCE_LOCATION (result
), RESULT_DECL
, NULL_TREE
,
13009 TYPE_MAIN_VARIANT (return_type
));
13010 DECL_ARTIFICIAL (result
) = 1;
13011 DECL_IGNORED_P (result
) = 1;
13012 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
13014 DECL_RESULT (fco
) = result
;
13016 if (!processing_template_decl
)
13017 if (function
*fun
= DECL_STRUCT_FUNCTION (fco
))
13019 bool aggr
= aggregate_value_p (result
, fco
);
13020 #ifdef PCC_STATIC_STRUCT_RETURN
13021 fun
->returns_pcc_struct
= aggr
;
13023 fun
->returns_struct
= aggr
;
13027 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
13028 this is a right unary fold. Otherwise it is a left unary fold. */
13031 finish_unary_fold_expr (location_t loc
, tree expr
, int op
, tree_code dir
)
13033 /* Build a pack expansion (assuming expr has pack type). */
13034 if (!uses_parameter_packs (expr
))
13036 error_at (location_of (expr
), "operand of fold expression has no "
13037 "unexpanded parameter packs");
13038 return error_mark_node
;
13040 tree pack
= make_pack_expansion (expr
);
13042 /* Build the fold expression. */
13043 tree code
= build_int_cstu (integer_type_node
, abs (op
));
13044 tree fold
= build_min_nt_loc (loc
, dir
, code
, pack
);
13045 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
13046 TREE_TYPE (fold
) = build_dependent_operator_type (NULL_TREE
,
13047 FOLD_EXPR_OP (fold
),
13048 FOLD_EXPR_MODIFY_P (fold
));
13053 finish_left_unary_fold_expr (location_t loc
, tree expr
, int op
)
13055 return finish_unary_fold_expr (loc
, expr
, op
, UNARY_LEFT_FOLD_EXPR
);
13059 finish_right_unary_fold_expr (location_t loc
, tree expr
, int op
)
13061 return finish_unary_fold_expr (loc
, expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
13064 /* Build a binary fold expression over EXPR1 and EXPR2. The
13065 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
13066 has an unexpanded parameter pack). */
13069 finish_binary_fold_expr (location_t loc
, tree pack
, tree init
,
13070 int op
, tree_code dir
)
13072 pack
= make_pack_expansion (pack
);
13073 tree code
= build_int_cstu (integer_type_node
, abs (op
));
13074 tree fold
= build_min_nt_loc (loc
, dir
, code
, pack
, init
);
13075 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
13076 TREE_TYPE (fold
) = build_dependent_operator_type (NULL_TREE
,
13077 FOLD_EXPR_OP (fold
),
13078 FOLD_EXPR_MODIFY_P (fold
));
13083 finish_binary_fold_expr (location_t loc
, tree expr1
, tree expr2
, int op
)
13085 // Determine which expr has an unexpanded parameter pack and
13086 // set the pack and initial term.
13087 bool pack1
= uses_parameter_packs (expr1
);
13088 bool pack2
= uses_parameter_packs (expr2
);
13089 if (pack1
&& !pack2
)
13090 return finish_binary_fold_expr (loc
, expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
13091 else if (pack2
&& !pack1
)
13092 return finish_binary_fold_expr (loc
, expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
13096 error ("both arguments in binary fold have unexpanded parameter packs");
13098 error ("no unexpanded parameter packs in binary fold");
13100 return error_mark_node
;
13103 /* Finish __builtin_launder (arg). */
13106 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
13108 tree orig_arg
= arg
;
13109 if (!type_dependent_expression_p (arg
))
13110 arg
= decay_conversion (arg
, complain
);
13111 if (error_operand_p (arg
))
13112 return error_mark_node
;
13113 if (!type_dependent_expression_p (arg
)
13114 && !TYPE_PTR_P (TREE_TYPE (arg
)))
13116 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
13117 return error_mark_node
;
13119 if (processing_template_decl
)
13121 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
13122 TREE_TYPE (arg
), 1, arg
);
13125 /* Finish __builtin_convertvector (arg, type). */
13128 cp_build_vec_convert (tree arg
, location_t loc
, tree type
,
13129 tsubst_flags_t complain
)
13131 if (error_operand_p (type
))
13132 return error_mark_node
;
13133 if (error_operand_p (arg
))
13134 return error_mark_node
;
13136 tree ret
= NULL_TREE
;
13137 if (!type_dependent_expression_p (arg
) && !dependent_type_p (type
))
13138 ret
= c_build_vec_convert (cp_expr_loc_or_input_loc (arg
),
13139 decay_conversion (arg
, complain
),
13140 loc
, type
, (complain
& tf_error
) != 0);
13142 if (!processing_template_decl
)
13145 return build_call_expr_internal_loc (loc
, IFN_VEC_CONVERT
, type
, 1, arg
);
13148 /* Finish __builtin_bit_cast (type, arg). */
13151 cp_build_bit_cast (location_t loc
, tree type
, tree arg
,
13152 tsubst_flags_t complain
)
13154 if (error_operand_p (type
))
13155 return error_mark_node
;
13156 if (!dependent_type_p (type
))
13158 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
))
13159 return error_mark_node
;
13160 if (TREE_CODE (type
) == ARRAY_TYPE
)
13162 /* std::bit_cast for destination ARRAY_TYPE is not possible,
13163 as functions may not return an array, so don't bother trying
13164 to support this (and then deal with VLAs etc.). */
13165 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
13166 "is an array type", type
);
13167 return error_mark_node
;
13169 if (!trivially_copyable_p (type
))
13171 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
13172 "is not trivially copyable", type
);
13173 return error_mark_node
;
13177 if (error_operand_p (arg
))
13178 return error_mark_node
;
13180 if (!type_dependent_expression_p (arg
))
13182 if (TREE_CODE (TREE_TYPE (arg
)) == ARRAY_TYPE
)
13184 /* Don't perform array-to-pointer conversion. */
13185 arg
= mark_rvalue_use (arg
, loc
, true);
13186 if (!complete_type_or_maybe_complain (TREE_TYPE (arg
), arg
, complain
))
13187 return error_mark_node
;
13190 arg
= decay_conversion (arg
, complain
);
13192 if (error_operand_p (arg
))
13193 return error_mark_node
;
13195 if (!trivially_copyable_p (TREE_TYPE (arg
)))
13197 error_at (cp_expr_loc_or_loc (arg
, loc
),
13198 "%<__builtin_bit_cast%> source type %qT "
13199 "is not trivially copyable", TREE_TYPE (arg
));
13200 return error_mark_node
;
13202 if (!dependent_type_p (type
)
13203 && !cp_tree_equal (TYPE_SIZE_UNIT (type
),
13204 TYPE_SIZE_UNIT (TREE_TYPE (arg
))))
13206 error_at (loc
, "%<__builtin_bit_cast%> source size %qE "
13207 "not equal to destination type size %qE",
13208 TYPE_SIZE_UNIT (TREE_TYPE (arg
)),
13209 TYPE_SIZE_UNIT (type
));
13210 return error_mark_node
;
13214 tree ret
= build_min (BIT_CAST_EXPR
, type
, arg
);
13215 SET_EXPR_LOCATION (ret
, loc
);
13217 if (!processing_template_decl
&& CLASS_TYPE_P (type
))
13218 ret
= get_target_expr (ret
, complain
);
13223 /* Diagnose invalid #pragma GCC unroll argument and adjust
13227 cp_check_pragma_unroll (location_t loc
, tree unroll
)
13229 HOST_WIDE_INT lunroll
= 0;
13230 if (type_dependent_expression_p (unroll
))
13232 else if (!INTEGRAL_TYPE_P (TREE_TYPE (unroll
))
13233 || (!value_dependent_expression_p (unroll
)
13234 && (!tree_fits_shwi_p (unroll
)
13235 || (lunroll
= tree_to_shwi (unroll
)) < 0
13236 || lunroll
>= USHRT_MAX
)))
13238 error_at (loc
, "%<#pragma GCC unroll%> requires an"
13239 " assignment-expression that evaluates to a non-negative"
13240 " integral constant less than %u", USHRT_MAX
);
13241 unroll
= integer_one_node
;
13243 else if (TREE_CODE (unroll
) == INTEGER_CST
)
13245 unroll
= fold_convert (integer_type_node
, unroll
);
13246 if (integer_zerop (unroll
))
13247 unroll
= integer_one_node
;
13252 #include "gt-cp-semantics.h"