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-2021 Free Software Foundation, Inc.
7 Written by Mark Mitchell (mmitchell@usa.net) based on code found
8 formerly in parse.y and pt.c.
10 This file is part of GCC.
12 GCC is free software; you can redistribute it and/or modify it
13 under the terms of the GNU General Public License as published by
14 the Free Software Foundation; either version 3, or (at your option)
17 GCC is distributed in the hope that it will be useful, but
18 WITHOUT ANY WARRANTY; without even the implied warranty of
19 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 General Public License for more details.
22 You should have received a copy of the GNU General Public License
23 along with GCC; see the file COPYING3. If not see
24 <http://www.gnu.org/licenses/>. */
28 #include "coretypes.h"
32 #include "stringpool.h"
36 #include "stor-layout.h"
37 #include "c-family/c-objc.h"
38 #include "tree-inline.h"
40 #include "tree-iterator.h"
41 #include "omp-general.h"
43 #include "stringpool.h"
45 #include "gomp-constants.h"
49 /* There routines provide a modular interface to perform many parsing
50 operations. They may therefore be used during actual parsing, or
51 during template instantiation, which may be regarded as a
52 degenerate form of parsing. */
54 static tree
maybe_convert_cond (tree
);
55 static tree
finalize_nrv_r (tree
*, int *, void *);
56 static tree
capture_decltype (tree
);
58 /* Used for OpenMP non-static data member privatization. */
60 static hash_map
<tree
, tree
> *omp_private_member_map
;
61 static vec
<tree
> omp_private_member_vec
;
62 static bool omp_private_member_ignore_next
;
65 /* Deferred Access Checking Overview
66 ---------------------------------
68 Most C++ expressions and declarations require access checking
69 to be performed during parsing. However, in several cases,
70 this has to be treated differently.
72 For member declarations, access checking has to be deferred
73 until more information about the declaration is known. For
85 When we are parsing the function return type `A::X', we don't
86 really know if this is allowed until we parse the function name.
88 Furthermore, some contexts require that access checking is
89 never performed at all. These include class heads, and template
92 Typical use of access checking functions is described here:
94 1. When we enter a context that requires certain access checking
95 mode, the function `push_deferring_access_checks' is called with
96 DEFERRING argument specifying the desired mode. Access checking
97 may be performed immediately (dk_no_deferred), deferred
98 (dk_deferred), or not performed (dk_no_check).
100 2. When a declaration such as a type, or a variable, is encountered,
101 the function `perform_or_defer_access_check' is called. It
102 maintains a vector of all deferred checks.
104 3. The global `current_class_type' or `current_function_decl' is then
105 setup by the parser. `enforce_access' relies on these information
108 4. Upon exiting the context mentioned in step 1,
109 `perform_deferred_access_checks' is called to check all declaration
110 stored in the vector. `pop_deferring_access_checks' is then
111 called to restore the previous access checking mode.
113 In case of parsing error, we simply call `pop_deferring_access_checks'
114 without `perform_deferred_access_checks'. */
116 struct GTY(()) deferred_access
{
117 /* A vector representing name-lookups for which we have deferred
118 checking access controls. We cannot check the accessibility of
119 names used in a decl-specifier-seq until we know what is being
120 declared because code like:
127 A::B* A::f() { return 0; }
129 is valid, even though `A::B' is not generally accessible. */
130 vec
<deferred_access_check
, va_gc
> *deferred_access_checks
;
132 /* The current mode of access checks. */
133 enum deferring_kind deferring_access_checks_kind
;
136 /* Data for deferred access checking. */
137 static GTY(()) vec
<deferred_access
, va_gc
> *deferred_access_stack
;
138 static GTY(()) unsigned deferred_access_no_check
;
140 /* Save the current deferred access states and start deferred
141 access checking iff DEFER_P is true. */
144 push_deferring_access_checks (deferring_kind deferring
)
146 /* For context like template instantiation, access checking
147 disabling applies to all nested context. */
148 if (deferred_access_no_check
|| deferring
== dk_no_check
)
149 deferred_access_no_check
++;
152 deferred_access e
= {NULL
, deferring
};
153 vec_safe_push (deferred_access_stack
, e
);
157 /* Save the current deferred access states and start deferred access
158 checking, continuing the set of deferred checks in CHECKS. */
161 reopen_deferring_access_checks (vec
<deferred_access_check
, va_gc
> * checks
)
163 push_deferring_access_checks (dk_deferred
);
164 if (!deferred_access_no_check
)
165 deferred_access_stack
->last().deferred_access_checks
= checks
;
168 /* Resume deferring access checks again after we stopped doing
172 resume_deferring_access_checks (void)
174 if (!deferred_access_no_check
)
175 deferred_access_stack
->last().deferring_access_checks_kind
= dk_deferred
;
178 /* Stop deferring access checks. */
181 stop_deferring_access_checks (void)
183 if (!deferred_access_no_check
)
184 deferred_access_stack
->last().deferring_access_checks_kind
= dk_no_deferred
;
187 /* Discard the current deferred access checks and restore the
191 pop_deferring_access_checks (void)
193 if (deferred_access_no_check
)
194 deferred_access_no_check
--;
196 deferred_access_stack
->pop ();
199 /* Returns a TREE_LIST representing the deferred checks.
200 The TREE_PURPOSE of each node is the type through which the
201 access occurred; the TREE_VALUE is the declaration named.
204 vec
<deferred_access_check
, va_gc
> *
205 get_deferred_access_checks (void)
207 if (deferred_access_no_check
)
210 return (deferred_access_stack
->last().deferred_access_checks
);
213 /* Take current deferred checks and combine with the
214 previous states if we also defer checks previously.
215 Otherwise perform checks now. */
218 pop_to_parent_deferring_access_checks (void)
220 if (deferred_access_no_check
)
221 deferred_access_no_check
--;
224 vec
<deferred_access_check
, va_gc
> *checks
;
225 deferred_access
*ptr
;
227 checks
= (deferred_access_stack
->last ().deferred_access_checks
);
229 deferred_access_stack
->pop ();
230 ptr
= &deferred_access_stack
->last ();
231 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
234 perform_access_checks (checks
, tf_warning_or_error
);
238 /* Merge with parent. */
240 deferred_access_check
*chk
, *probe
;
242 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
244 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, j
, probe
)
246 if (probe
->binfo
== chk
->binfo
&&
247 probe
->decl
== chk
->decl
&&
248 probe
->diag_decl
== chk
->diag_decl
)
251 /* Insert into parent's checks. */
252 vec_safe_push (ptr
->deferred_access_checks
, *chk
);
259 /* Called from enforce_access. A class has attempted (but failed) to access
260 DECL. It is already established that a baseclass of that class,
261 PARENT_BINFO, has private access to DECL. Examine certain special cases
262 to find a decl that accurately describes the source of the problem. If
263 none of the special cases apply, simply return DECL as the source of the
267 get_class_access_diagnostic_decl (tree parent_binfo
, tree decl
)
269 /* When a class is denied access to a decl in a baseclass, most of the
270 time it is because the decl itself was declared as private at the point
273 However, in C++, there are (at least) two situations in which a decl
274 can be private even though it was not originally defined as such.
275 These two situations only apply if a baseclass had private access to
276 DECL (this function is only called if that is the case). */
278 /* We should first check whether the reason the parent had private access
279 to DECL was simply because DECL was created and declared as private in
280 the parent. If it was, then DECL is definitively the source of the
282 if (SAME_BINFO_TYPE_P (context_for_name_lookup (decl
),
283 BINFO_TYPE (parent_binfo
)))
286 /* 1. If the "using" keyword is used to inherit DECL within the parent,
287 this may cause DECL to be private, so we should return the using
288 statement as the source of the problem.
290 Scan the fields of PARENT_BINFO and see if there are any using decls. If
291 there are, see if they inherit DECL. If they do, that's where DECL must
292 have been declared private. */
294 for (tree parent_field
= TYPE_FIELDS (BINFO_TYPE (parent_binfo
));
296 parent_field
= DECL_CHAIN (parent_field
))
297 /* Not necessary, but also check TREE_PRIVATE for the sake of
298 eliminating obviously non-relevant using decls. */
299 if (TREE_CODE (parent_field
) == USING_DECL
300 && TREE_PRIVATE (parent_field
))
302 tree decl_stripped
= strip_using_decl (parent_field
);
304 /* The using statement might be overloaded. If so, we need to
305 check all of the overloads. */
306 for (ovl_iterator
iter (decl_stripped
); iter
; ++iter
)
307 /* If equal, the using statement inherits DECL, and so is the
308 source of the access failure, so return it. */
313 /* 2. If DECL was privately inherited by the parent class, then DECL will
314 be inaccessible, even though it may originally have been accessible to
315 deriving classes. In that case, the fault lies with the parent, since it
316 used a private inheritance, so we return the parent as the source of the
319 Since this is the last check, we just assume it's true. At worst, it
320 will simply point to the class that failed to give access, which is
322 return TYPE_NAME (BINFO_TYPE (parent_binfo
));
325 /* If the current scope isn't allowed to access DECL along
326 BASETYPE_PATH, give an error, or if we're parsing a function or class
327 template, defer the access check to be performed at instantiation time.
328 The most derived class in BASETYPE_PATH is the one used to qualify DECL.
329 DIAG_DECL is the declaration to use in the error diagnostic. */
332 enforce_access (tree basetype_path
, tree decl
, tree diag_decl
,
333 tsubst_flags_t complain
, access_failure_info
*afi
= NULL
)
335 gcc_assert (TREE_CODE (basetype_path
) == TREE_BINFO
);
337 if (flag_new_inheriting_ctors
338 && DECL_INHERITED_CTOR (decl
))
340 /* 7.3.3/18: The additional constructors are accessible if they would be
341 accessible when used to construct an object of the corresponding base
343 decl
= strip_inheriting_ctors (decl
);
344 basetype_path
= lookup_base (basetype_path
, DECL_CONTEXT (decl
),
345 ba_any
, NULL
, complain
);
348 tree cs
= current_scope ();
349 if (processing_template_decl
350 && (CLASS_TYPE_P (cs
) || TREE_CODE (cs
) == FUNCTION_DECL
))
351 if (tree template_info
= get_template_info (cs
))
353 /* When parsing a function or class template, we in general need to
354 defer access checks until template instantiation time, since a friend
355 declaration may grant access only to a particular specialization of
358 if (accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
359 /* But if the member is deemed accessible at parse time, then we can
360 assume it'll be accessible at instantiation time. */
363 /* Access of a dependent decl should be rechecked after tsubst'ing
364 into the user of the decl, rather than explicitly deferring the
366 gcc_assert (!uses_template_parms (decl
));
367 if (TREE_CODE (decl
) == FIELD_DECL
)
368 gcc_assert (!uses_template_parms (DECL_CONTEXT (decl
)));
370 /* Defer this access check until instantiation time. */
371 deferred_access_check access_check
;
372 access_check
.binfo
= basetype_path
;
373 access_check
.decl
= decl
;
374 access_check
.diag_decl
= diag_decl
;
375 access_check
.loc
= input_location
;
376 vec_safe_push (TI_DEFERRED_ACCESS_CHECKS (template_info
), access_check
);
380 if (!accessible_p (basetype_path
, decl
, /*consider_local_p=*/true))
382 if (flag_new_inheriting_ctors
)
383 diag_decl
= strip_inheriting_ctors (diag_decl
);
384 if (complain
& tf_error
)
386 access_kind access_failure_reason
= ak_none
;
388 /* By default, using the decl as the source of the problem will
389 usually give correct results. */
390 tree diag_location
= diag_decl
;
392 /* However, if a parent of BASETYPE_PATH had private access to decl,
393 then it actually might be the case that the source of the problem
395 tree parent_binfo
= get_parent_with_private_access (decl
,
398 /* So if a parent did have private access, then we need to do
399 special checks to obtain the best diagnostic location decl. */
400 if (parent_binfo
!= NULL_TREE
)
402 diag_location
= get_class_access_diagnostic_decl (parent_binfo
,
405 /* We also at this point know that the reason access failed was
406 because decl was private. */
407 access_failure_reason
= ak_private
;
410 /* Finally, generate an error message. */
411 complain_about_access (decl
, diag_decl
, diag_location
, true,
412 access_failure_reason
);
415 afi
->record_access_failure (basetype_path
, decl
, diag_decl
);
422 /* Perform the access checks in CHECKS. The TREE_PURPOSE of each node
423 is the BINFO indicating the qualifying scope used to access the
424 DECL node stored in the TREE_VALUE of the node. If CHECKS is empty
425 or we aren't in SFINAE context or all the checks succeed return TRUE,
429 perform_access_checks (vec
<deferred_access_check
, va_gc
> *checks
,
430 tsubst_flags_t complain
)
433 deferred_access_check
*chk
;
434 location_t loc
= input_location
;
440 FOR_EACH_VEC_SAFE_ELT (checks
, i
, chk
)
442 input_location
= chk
->loc
;
443 ok
&= enforce_access (chk
->binfo
, chk
->decl
, chk
->diag_decl
, complain
);
446 input_location
= loc
;
447 return (complain
& tf_error
) ? true : ok
;
450 /* Perform the deferred access checks.
452 After performing the checks, we still have to keep the list
453 `deferred_access_stack->deferred_access_checks' since we may want
454 to check access for them again later in a different context.
461 A::X A::a, x; // No error for `A::a', error for `x'
463 We have to perform deferred access of `A::X', first with `A::a',
464 next with `x'. Return value like perform_access_checks above. */
467 perform_deferred_access_checks (tsubst_flags_t complain
)
469 return perform_access_checks (get_deferred_access_checks (), complain
);
472 /* Defer checking the accessibility of DECL, when looked up in
473 BINFO. DIAG_DECL is the declaration to use to print diagnostics.
474 Return value like perform_access_checks above.
475 If non-NULL, report failures to AFI. */
478 perform_or_defer_access_check (tree binfo
, tree decl
, tree diag_decl
,
479 tsubst_flags_t complain
,
480 access_failure_info
*afi
)
483 deferred_access
*ptr
;
484 deferred_access_check
*chk
;
486 /* Exit if we are in a context that no access checking is performed. */
487 if (deferred_access_no_check
)
490 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
492 ptr
= &deferred_access_stack
->last ();
494 /* If we are not supposed to defer access checks, just check now. */
495 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
497 bool ok
= enforce_access (binfo
, decl
, diag_decl
, complain
, afi
);
498 return (complain
& tf_error
) ? true : ok
;
501 /* See if we are already going to perform this check. */
502 FOR_EACH_VEC_SAFE_ELT (ptr
->deferred_access_checks
, i
, chk
)
504 if (chk
->decl
== decl
&& chk
->binfo
== binfo
&&
505 chk
->diag_decl
== diag_decl
)
510 /* If not, record the check. */
511 deferred_access_check new_access
= {binfo
, decl
, diag_decl
, input_location
};
512 vec_safe_push (ptr
->deferred_access_checks
, new_access
);
517 /* Returns nonzero if the current statement is a full expression,
518 i.e. temporaries created during that statement should be destroyed
519 at the end of the statement. */
522 stmts_are_full_exprs_p (void)
524 return current_stmt_tree ()->stmts_are_full_exprs_p
;
527 /* T is a statement. Add it to the statement-tree. This is the C++
528 version. The C/ObjC frontends have a slightly different version of
534 enum tree_code code
= TREE_CODE (t
);
536 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
538 if (!EXPR_HAS_LOCATION (t
))
539 SET_EXPR_LOCATION (t
, input_location
);
541 /* When we expand a statement-tree, we must know whether or not the
542 statements are full-expressions. We record that fact here. */
543 if (STATEMENT_CODE_P (TREE_CODE (t
)))
544 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
547 if (code
== LABEL_EXPR
|| code
== CASE_LABEL_EXPR
)
548 STATEMENT_LIST_HAS_LABEL (cur_stmt_list
) = 1;
550 /* Add T to the statement-tree. Non-side-effect statements need to be
551 recorded during statement expressions. */
552 gcc_checking_assert (!stmt_list_stack
->is_empty ());
553 append_to_statement_list_force (t
, &cur_stmt_list
);
558 /* Returns the stmt_tree to which statements are currently being added. */
561 current_stmt_tree (void)
564 ? &cfun
->language
->base
.x_stmt_tree
565 : &scope_chain
->x_stmt_tree
);
568 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
571 maybe_cleanup_point_expr (tree expr
)
573 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
574 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
578 /* Like maybe_cleanup_point_expr except have the type of the new expression be
579 void so we don't need to create a temporary variable to hold the inner
580 expression. The reason why we do this is because the original type might be
581 an aggregate and we cannot create a temporary variable for that type. */
584 maybe_cleanup_point_expr_void (tree expr
)
586 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
587 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
593 /* Create a declaration statement for the declaration given by the DECL. */
596 add_decl_expr (tree decl
)
598 tree r
= build_stmt (DECL_SOURCE_LOCATION (decl
), DECL_EXPR
, decl
);
599 if (DECL_INITIAL (decl
)
600 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
601 r
= maybe_cleanup_point_expr_void (r
);
605 /* Set EXPR_LOCATION of the cleanups of any CLEANUP_STMT in STMTS to LOC. */
608 set_cleanup_locs (tree stmts
, location_t loc
)
610 if (TREE_CODE (stmts
) == CLEANUP_STMT
)
612 protected_set_expr_location (CLEANUP_EXPR (stmts
), loc
);
613 set_cleanup_locs (CLEANUP_BODY (stmts
), loc
);
615 else if (TREE_CODE (stmts
) == STATEMENT_LIST
)
616 for (tree stmt
: tsi_range (stmts
))
617 set_cleanup_locs (stmt
, loc
);
620 /* Finish a scope. */
623 do_poplevel (tree stmt_list
)
627 if (stmts_are_full_exprs_p ())
628 block
= poplevel (kept_level_p (), 1, 0);
630 stmt_list
= pop_stmt_list (stmt_list
);
632 /* input_location is the last token of the scope, usually a }. */
633 set_cleanup_locs (stmt_list
, input_location
);
635 if (!processing_template_decl
)
637 stmt_list
= c_build_bind_expr (input_location
, block
, stmt_list
);
638 /* ??? See c_end_compound_stmt re statement expressions. */
644 /* Begin a new scope. */
647 do_pushlevel (scope_kind sk
)
649 tree ret
= push_stmt_list ();
650 if (stmts_are_full_exprs_p ())
651 begin_scope (sk
, NULL
);
655 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
656 when the current scope is exited. EH_ONLY is true when this is not
657 meant to apply to normal control flow transfer. */
660 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
662 tree stmt
= build_stmt (input_location
, CLEANUP_STMT
, NULL
, cleanup
, decl
);
663 CLEANUP_EH_ONLY (stmt
) = eh_only
;
665 CLEANUP_BODY (stmt
) = push_stmt_list ();
668 /* Simple infinite loop tracking for -Wreturn-type. We keep a stack of all
669 the current loops, represented by 'NULL_TREE' if we've seen a possible
670 exit, and 'error_mark_node' if not. This is currently used only to
671 suppress the warning about a function with no return statements, and
672 therefore we don't bother noting returns as possible exits. We also
673 don't bother with gotos. */
676 begin_maybe_infinite_loop (tree cond
)
678 /* Only track this while parsing a function, not during instantiation. */
679 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
680 && !processing_template_decl
))
682 bool maybe_infinite
= true;
685 cond
= fold_non_dependent_expr (cond
);
686 maybe_infinite
= integer_nonzerop (cond
);
688 vec_safe_push (cp_function_chain
->infinite_loops
,
689 maybe_infinite
? error_mark_node
: NULL_TREE
);
693 /* A break is a possible exit for the current loop. */
696 break_maybe_infinite_loop (void)
700 cp_function_chain
->infinite_loops
->last() = NULL_TREE
;
703 /* If we reach the end of the loop without seeing a possible exit, we have
707 end_maybe_infinite_loop (tree cond
)
709 if (!cfun
|| (DECL_TEMPLATE_INSTANTIATION (current_function_decl
)
710 && !processing_template_decl
))
712 tree current
= cp_function_chain
->infinite_loops
->pop();
713 if (current
!= NULL_TREE
)
715 cond
= fold_non_dependent_expr (cond
);
716 if (integer_nonzerop (cond
))
717 current_function_infinite_loop
= 1;
722 /* Begin a conditional that might contain a declaration. When generating
723 normal code, we want the declaration to appear before the statement
724 containing the conditional. When generating template code, we want the
725 conditional to be rendered as the raw DECL_EXPR. */
728 begin_cond (tree
*cond_p
)
730 if (processing_template_decl
)
731 *cond_p
= push_stmt_list ();
734 /* Finish such a conditional. */
737 finish_cond (tree
*cond_p
, tree expr
)
739 if (processing_template_decl
)
741 tree cond
= pop_stmt_list (*cond_p
);
743 if (expr
== NULL_TREE
)
744 /* Empty condition in 'for'. */
745 gcc_assert (empty_expr_stmt_p (cond
));
746 else if (check_for_bare_parameter_packs (expr
))
747 expr
= error_mark_node
;
748 else if (!empty_expr_stmt_p (cond
))
749 expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (expr
), cond
, expr
);
754 /* If *COND_P specifies a conditional with a declaration, transform the
757 for (; A x = 42;) { }
759 while (true) { A x = 42; if (!x) break; }
760 for (;;) { A x = 42; if (!x) break; }
761 The statement list for BODY will be empty if the conditional did
762 not declare anything. */
765 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
769 if (!TREE_SIDE_EFFECTS (body
))
773 *cond_p
= boolean_true_node
;
775 if_stmt
= begin_if_stmt ();
776 cond
= cp_build_unary_op (TRUTH_NOT_EXPR
, cond
, false, tf_warning_or_error
);
777 finish_if_stmt_cond (cond
, if_stmt
);
778 finish_break_stmt ();
779 finish_then_clause (if_stmt
);
780 finish_if_stmt (if_stmt
);
783 /* Finish a goto-statement. */
786 finish_goto_stmt (tree destination
)
788 if (identifier_p (destination
))
789 destination
= lookup_label (destination
);
791 /* We warn about unused labels with -Wunused. That means we have to
792 mark the used labels as used. */
793 if (TREE_CODE (destination
) == LABEL_DECL
)
794 TREE_USED (destination
) = 1;
797 destination
= mark_rvalue_use (destination
);
798 if (!processing_template_decl
)
800 destination
= cp_convert (ptr_type_node
, destination
,
801 tf_warning_or_error
);
802 if (error_operand_p (destination
))
805 = fold_build_cleanup_point_expr (TREE_TYPE (destination
),
810 check_goto (destination
);
812 add_stmt (build_predict_expr (PRED_GOTO
, NOT_TAKEN
));
813 return add_stmt (build_stmt (input_location
, GOTO_EXPR
, destination
));
816 /* COND is the condition-expression for an if, while, etc.,
817 statement. Convert it to a boolean value, if appropriate.
818 In addition, verify sequence points if -Wsequence-point is enabled. */
821 maybe_convert_cond (tree cond
)
823 /* Empty conditions remain empty. */
827 /* Wait until we instantiate templates before doing conversion. */
828 if (type_dependent_expression_p (cond
))
831 if (warn_sequence_point
&& !processing_template_decl
)
832 verify_sequence_points (cond
);
834 /* Do the conversion. */
835 cond
= convert_from_reference (cond
);
837 if (TREE_CODE (cond
) == MODIFY_EXPR
839 && !warning_suppressed_p (cond
, OPT_Wparentheses
)
840 && warning_at (cp_expr_loc_or_input_loc (cond
),
841 OPT_Wparentheses
, "suggest parentheses around "
842 "assignment used as truth value"))
843 suppress_warning (cond
, OPT_Wparentheses
);
845 return condition_conversion (cond
);
848 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
851 finish_expr_stmt (tree expr
)
854 location_t loc
= EXPR_LOCATION (expr
);
856 if (expr
!= NULL_TREE
)
858 /* If we ran into a problem, make sure we complained. */
859 gcc_assert (expr
!= error_mark_node
|| seen_error ());
861 if (!processing_template_decl
)
863 if (warn_sequence_point
)
864 verify_sequence_points (expr
);
865 expr
= convert_to_void (expr
, ICV_STATEMENT
, tf_warning_or_error
);
867 else if (!type_dependent_expression_p (expr
))
868 convert_to_void (build_non_dependent_expr (expr
), ICV_STATEMENT
,
869 tf_warning_or_error
);
871 if (check_for_bare_parameter_packs (expr
))
872 expr
= error_mark_node
;
874 /* Simplification of inner statement expressions, compound exprs,
875 etc can result in us already having an EXPR_STMT. */
876 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
878 if (TREE_CODE (expr
) != EXPR_STMT
)
879 expr
= build_stmt (loc
, EXPR_STMT
, expr
);
880 expr
= maybe_cleanup_point_expr_void (expr
);
890 /* Begin an if-statement. Returns a newly created IF_STMT if
897 scope
= do_pushlevel (sk_cond
);
898 r
= build_stmt (input_location
, IF_STMT
, NULL_TREE
,
899 NULL_TREE
, NULL_TREE
, scope
);
900 current_binding_level
->this_entity
= r
;
901 begin_cond (&IF_COND (r
));
905 /* Returns true if FN, a CALL_EXPR, is a call to
906 std::is_constant_evaluated or __builtin_is_constant_evaluated. */
909 is_std_constant_evaluated_p (tree fn
)
911 /* std::is_constant_evaluated takes no arguments. */
912 if (call_expr_nargs (fn
) != 0)
915 tree fndecl
= cp_get_callee_fndecl_nofold (fn
);
916 if (fndecl
== NULL_TREE
)
919 if (fndecl_built_in_p (fndecl
, CP_BUILT_IN_IS_CONSTANT_EVALUATED
,
923 if (!decl_in_std_namespace_p (fndecl
))
926 tree name
= DECL_NAME (fndecl
);
927 return name
&& id_equal (name
, "is_constant_evaluated");
930 /* Callback function for maybe_warn_for_constant_evaluated that looks
931 for calls to std::is_constant_evaluated in TP. */
934 find_std_constant_evaluated_r (tree
*tp
, int *walk_subtrees
, void *)
938 if (TYPE_P (t
) || TREE_CONSTANT (t
))
940 *walk_subtrees
= false;
944 switch (TREE_CODE (t
))
947 if (is_std_constant_evaluated_p (t
))
951 /* Don't warn in statement expressions. */
952 *walk_subtrees
= false;
961 /* In certain contexts, std::is_constant_evaluated() is always true (for
962 instance, in a consteval function or in a constexpr if), or always false
963 (e.g., in a non-constexpr non-consteval function) so give the user a clue. */
966 maybe_warn_for_constant_evaluated (tree cond
, bool constexpr_if
)
968 if (!warn_tautological_compare
)
971 /* Suppress warning for std::is_constant_evaluated if the conditional
972 comes from a macro. */
973 if (from_macro_expansion_at (EXPR_LOCATION (cond
)))
976 cond
= cp_walk_tree_without_duplicates (&cond
, find_std_constant_evaluated_r
,
981 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
982 "%<std::is_constant_evaluated%> always evaluates to "
983 "true in %<if constexpr%>");
984 else if (!maybe_constexpr_fn (current_function_decl
))
985 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
986 "%<std::is_constant_evaluated%> always evaluates to "
987 "false in a non-%<constexpr%> function");
988 else if (DECL_IMMEDIATE_FUNCTION_P (current_function_decl
))
989 warning_at (EXPR_LOCATION (cond
), OPT_Wtautological_compare
,
990 "%<std::is_constant_evaluated%> always evaluates to "
991 "true in a %<consteval%> function");
995 /* Process the COND of an if-statement, which may be given by
999 finish_if_stmt_cond (tree cond
, tree if_stmt
)
1001 cond
= maybe_convert_cond (cond
);
1002 if (IF_STMT_CONSTEXPR_P (if_stmt
)
1003 && !type_dependent_expression_p (cond
)
1004 && require_constant_expression (cond
)
1005 && !instantiation_dependent_expression_p (cond
)
1006 /* Wait until instantiation time, since only then COND has been
1007 converted to bool. */
1008 && TYPE_MAIN_VARIANT (TREE_TYPE (cond
)) == boolean_type_node
)
1010 maybe_warn_for_constant_evaluated (cond
, /*constexpr_if=*/true);
1011 cond
= instantiate_non_dependent_expr (cond
);
1012 cond
= cxx_constant_value (cond
, NULL_TREE
);
1015 maybe_warn_for_constant_evaluated (cond
, /*constexpr_if=*/false);
1016 finish_cond (&IF_COND (if_stmt
), cond
);
1018 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
1022 /* Finish the then-clause of an if-statement, which may be given by
1026 finish_then_clause (tree if_stmt
)
1028 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
1032 /* Begin the else-clause of an if-statement. */
1035 begin_else_clause (tree if_stmt
)
1037 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
1040 /* Finish the else-clause of an if-statement, which may be given by
1044 finish_else_clause (tree if_stmt
)
1046 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
1049 /* Callback for cp_walk_tree to mark all {VAR,PARM}_DECLs in a tree as
1053 maybe_mark_exp_read_r (tree
*tp
, int *, void *)
1056 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
1061 /* Finish an if-statement. */
1064 finish_if_stmt (tree if_stmt
)
1066 tree scope
= IF_SCOPE (if_stmt
);
1067 IF_SCOPE (if_stmt
) = NULL
;
1068 if (IF_STMT_CONSTEXPR_P (if_stmt
))
1070 /* Prevent various -Wunused warnings. We might not instantiate
1071 either of these branches, so we would not mark the variables
1072 used in that branch as read. */
1073 cp_walk_tree_without_duplicates (&THEN_CLAUSE (if_stmt
),
1074 maybe_mark_exp_read_r
, NULL
);
1075 cp_walk_tree_without_duplicates (&ELSE_CLAUSE (if_stmt
),
1076 maybe_mark_exp_read_r
, NULL
);
1078 add_stmt (do_poplevel (scope
));
1081 /* Begin a while-statement. Returns a newly created WHILE_STMT if
1085 begin_while_stmt (void)
1088 r
= build_stmt (input_location
, WHILE_STMT
, NULL_TREE
, NULL_TREE
);
1090 WHILE_BODY (r
) = do_pushlevel (sk_block
);
1091 begin_cond (&WHILE_COND (r
));
1095 /* Process the COND of a while-statement, which may be given by
1099 finish_while_stmt_cond (tree cond
, tree while_stmt
, bool ivdep
,
1100 unsigned short unroll
)
1102 cond
= maybe_convert_cond (cond
);
1103 finish_cond (&WHILE_COND (while_stmt
), cond
);
1104 begin_maybe_infinite_loop (cond
);
1105 if (ivdep
&& cond
!= error_mark_node
)
1106 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
1107 TREE_TYPE (WHILE_COND (while_stmt
)),
1108 WHILE_COND (while_stmt
),
1109 build_int_cst (integer_type_node
,
1110 annot_expr_ivdep_kind
),
1112 if (unroll
&& cond
!= error_mark_node
)
1113 WHILE_COND (while_stmt
) = build3 (ANNOTATE_EXPR
,
1114 TREE_TYPE (WHILE_COND (while_stmt
)),
1115 WHILE_COND (while_stmt
),
1116 build_int_cst (integer_type_node
,
1117 annot_expr_unroll_kind
),
1118 build_int_cst (integer_type_node
,
1120 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
1123 /* Finish a while-statement, which may be given by WHILE_STMT. */
1126 finish_while_stmt (tree while_stmt
)
1128 end_maybe_infinite_loop (boolean_true_node
);
1129 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
1132 /* Begin a do-statement. Returns a newly created DO_STMT if
1136 begin_do_stmt (void)
1138 tree r
= build_stmt (input_location
, DO_STMT
, NULL_TREE
, NULL_TREE
);
1139 begin_maybe_infinite_loop (boolean_true_node
);
1141 DO_BODY (r
) = push_stmt_list ();
1145 /* Finish the body of a do-statement, which may be given by DO_STMT. */
1148 finish_do_body (tree do_stmt
)
1150 tree body
= DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
1152 if (TREE_CODE (body
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (body
))
1153 body
= STATEMENT_LIST_TAIL (body
)->stmt
;
1155 if (IS_EMPTY_STMT (body
))
1156 warning (OPT_Wempty_body
,
1157 "suggest explicit braces around empty body in %<do%> statement");
1160 /* Finish a do-statement, which may be given by DO_STMT, and whose
1161 COND is as indicated. */
1164 finish_do_stmt (tree cond
, tree do_stmt
, bool ivdep
, unsigned short unroll
)
1166 cond
= maybe_convert_cond (cond
);
1167 end_maybe_infinite_loop (cond
);
1168 /* Unlike other iteration statements, the condition may not contain
1169 a declaration, so we don't call finish_cond which checks for
1170 unexpanded parameter packs. */
1171 if (check_for_bare_parameter_packs (cond
))
1172 cond
= error_mark_node
;
1173 if (ivdep
&& cond
!= error_mark_node
)
1174 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1175 build_int_cst (integer_type_node
, annot_expr_ivdep_kind
),
1177 if (unroll
&& cond
!= error_mark_node
)
1178 cond
= build3 (ANNOTATE_EXPR
, TREE_TYPE (cond
), cond
,
1179 build_int_cst (integer_type_node
, annot_expr_unroll_kind
),
1180 build_int_cst (integer_type_node
, unroll
));
1181 DO_COND (do_stmt
) = cond
;
1184 /* Finish a return-statement. The EXPRESSION returned, if any, is as
1188 finish_return_stmt (tree expr
)
1193 expr
= check_return_expr (expr
, &no_warning
);
1195 if (error_operand_p (expr
)
1196 || (flag_openmp
&& !check_omp_return ()))
1198 /* Suppress -Wreturn-type for this function. */
1199 if (warn_return_type
)
1200 suppress_warning (current_function_decl
, OPT_Wreturn_type
);
1201 return error_mark_node
;
1204 if (!processing_template_decl
)
1206 if (warn_sequence_point
)
1207 verify_sequence_points (expr
);
1209 if (DECL_DESTRUCTOR_P (current_function_decl
)
1210 || (DECL_CONSTRUCTOR_P (current_function_decl
)
1211 && targetm
.cxx
.cdtor_returns_this ()))
1213 /* Similarly, all destructors must run destructors for
1214 base-classes before returning. So, all returns in a
1215 destructor get sent to the DTOR_LABEL; finish_function emits
1216 code to return a value there. */
1217 return finish_goto_stmt (cdtor_label
);
1221 r
= build_stmt (input_location
, RETURN_EXPR
, expr
);
1223 suppress_warning (r
, OPT_Wreturn_type
);
1224 r
= maybe_cleanup_point_expr_void (r
);
1230 /* Begin the scope of a for-statement or a range-for-statement.
1231 Both the returned trees are to be used in a call to
1232 begin_for_stmt or begin_range_for_stmt. */
1235 begin_for_scope (tree
*init
)
1237 tree scope
= do_pushlevel (sk_for
);
1239 if (processing_template_decl
)
1240 *init
= push_stmt_list ();
1247 /* Begin a for-statement. Returns a new FOR_STMT.
1248 SCOPE and INIT should be the return of begin_for_scope,
1249 or both NULL_TREE */
1252 begin_for_stmt (tree scope
, tree init
)
1256 r
= build_stmt (input_location
, FOR_STMT
, NULL_TREE
, NULL_TREE
,
1257 NULL_TREE
, NULL_TREE
, NULL_TREE
);
1259 if (scope
== NULL_TREE
)
1262 scope
= begin_for_scope (&init
);
1265 FOR_INIT_STMT (r
) = init
;
1266 FOR_SCOPE (r
) = scope
;
1271 /* Finish the init-statement of a for-statement, which may be
1272 given by FOR_STMT. */
1275 finish_init_stmt (tree for_stmt
)
1277 if (processing_template_decl
)
1278 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
1279 add_stmt (for_stmt
);
1280 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
1281 begin_cond (&FOR_COND (for_stmt
));
1284 /* Finish the COND of a for-statement, which may be given by
1288 finish_for_cond (tree cond
, tree for_stmt
, bool ivdep
, unsigned short unroll
)
1290 cond
= maybe_convert_cond (cond
);
1291 finish_cond (&FOR_COND (for_stmt
), cond
);
1292 begin_maybe_infinite_loop (cond
);
1293 if (ivdep
&& cond
!= error_mark_node
)
1294 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1295 TREE_TYPE (FOR_COND (for_stmt
)),
1296 FOR_COND (for_stmt
),
1297 build_int_cst (integer_type_node
,
1298 annot_expr_ivdep_kind
),
1300 if (unroll
&& cond
!= error_mark_node
)
1301 FOR_COND (for_stmt
) = build3 (ANNOTATE_EXPR
,
1302 TREE_TYPE (FOR_COND (for_stmt
)),
1303 FOR_COND (for_stmt
),
1304 build_int_cst (integer_type_node
,
1305 annot_expr_unroll_kind
),
1306 build_int_cst (integer_type_node
,
1308 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
1311 /* Finish the increment-EXPRESSION in a for-statement, which may be
1312 given by FOR_STMT. */
1315 finish_for_expr (tree expr
, tree for_stmt
)
1319 /* If EXPR is an overloaded function, issue an error; there is no
1320 context available to use to perform overload resolution. */
1321 if (type_unknown_p (expr
))
1323 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
1324 expr
= error_mark_node
;
1326 if (!processing_template_decl
)
1328 if (warn_sequence_point
)
1329 verify_sequence_points (expr
);
1330 expr
= convert_to_void (expr
, ICV_THIRD_IN_FOR
,
1331 tf_warning_or_error
);
1333 else if (!type_dependent_expression_p (expr
))
1334 convert_to_void (build_non_dependent_expr (expr
), ICV_THIRD_IN_FOR
,
1335 tf_warning_or_error
);
1336 expr
= maybe_cleanup_point_expr_void (expr
);
1337 if (check_for_bare_parameter_packs (expr
))
1338 expr
= error_mark_node
;
1339 FOR_EXPR (for_stmt
) = expr
;
1342 /* Finish the body of a for-statement, which may be given by
1343 FOR_STMT. The increment-EXPR for the loop must be
1345 It can also finish RANGE_FOR_STMT. */
1348 finish_for_stmt (tree for_stmt
)
1350 end_maybe_infinite_loop (boolean_true_node
);
1352 if (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
)
1353 RANGE_FOR_BODY (for_stmt
) = do_poplevel (RANGE_FOR_BODY (for_stmt
));
1355 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
1357 /* Pop the scope for the body of the loop. */
1358 tree
*scope_ptr
= (TREE_CODE (for_stmt
) == RANGE_FOR_STMT
1359 ? &RANGE_FOR_SCOPE (for_stmt
)
1360 : &FOR_SCOPE (for_stmt
));
1361 tree scope
= *scope_ptr
;
1364 /* During parsing of the body, range for uses "__for_{range,begin,end} "
1365 decl names to make those unaccessible by code in the body.
1366 Change it to ones with underscore instead of space, so that it can
1367 be inspected in the debugger. */
1368 tree range_for_decl
[3] = { NULL_TREE
, NULL_TREE
, NULL_TREE
};
1369 gcc_assert (CPTI_FOR_BEGIN__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 1
1370 && CPTI_FOR_END__IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 2
1371 && CPTI_FOR_RANGE_IDENTIFIER
== CPTI_FOR_RANGE__IDENTIFIER
+ 3
1372 && CPTI_FOR_BEGIN_IDENTIFIER
== CPTI_FOR_BEGIN__IDENTIFIER
+ 3
1373 && CPTI_FOR_END_IDENTIFIER
== CPTI_FOR_END__IDENTIFIER
+ 3);
1374 for (int i
= 0; i
< 3; i
++)
1376 tree id
= cp_global_trees
[CPTI_FOR_RANGE__IDENTIFIER
+ i
];
1377 if (IDENTIFIER_BINDING (id
)
1378 && IDENTIFIER_BINDING (id
)->scope
== current_binding_level
)
1380 range_for_decl
[i
] = IDENTIFIER_BINDING (id
)->value
;
1381 gcc_assert (VAR_P (range_for_decl
[i
])
1382 && DECL_ARTIFICIAL (range_for_decl
[i
]));
1386 add_stmt (do_poplevel (scope
));
1388 for (int i
= 0; i
< 3; i
++)
1389 if (range_for_decl
[i
])
1390 DECL_NAME (range_for_decl
[i
])
1391 = cp_global_trees
[CPTI_FOR_RANGE_IDENTIFIER
+ i
];
1394 /* Begin a range-for-statement. Returns a new RANGE_FOR_STMT.
1395 SCOPE and INIT should be the return of begin_for_scope,
1397 To finish it call finish_for_stmt(). */
1400 begin_range_for_stmt (tree scope
, tree init
)
1402 begin_maybe_infinite_loop (boolean_false_node
);
1404 tree r
= build_stmt (input_location
, RANGE_FOR_STMT
, NULL_TREE
, NULL_TREE
,
1405 NULL_TREE
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
1407 if (scope
== NULL_TREE
)
1410 scope
= begin_for_scope (&init
);
1413 /* Since C++20, RANGE_FOR_STMTs can use the init tree, so save it. */
1414 RANGE_FOR_INIT_STMT (r
) = init
;
1415 RANGE_FOR_SCOPE (r
) = scope
;
1420 /* Finish the head of a range-based for statement, which may
1421 be given by RANGE_FOR_STMT. DECL must be the declaration
1422 and EXPR must be the loop expression. */
1425 finish_range_for_decl (tree range_for_stmt
, tree decl
, tree expr
)
1427 if (processing_template_decl
)
1428 RANGE_FOR_INIT_STMT (range_for_stmt
)
1429 = pop_stmt_list (RANGE_FOR_INIT_STMT (range_for_stmt
));
1430 RANGE_FOR_DECL (range_for_stmt
) = decl
;
1431 RANGE_FOR_EXPR (range_for_stmt
) = expr
;
1432 add_stmt (range_for_stmt
);
1433 RANGE_FOR_BODY (range_for_stmt
) = do_pushlevel (sk_block
);
1436 /* Finish a break-statement. */
1439 finish_break_stmt (void)
1441 /* In switch statements break is sometimes stylistically used after
1442 a return statement. This can lead to spurious warnings about
1443 control reaching the end of a non-void function when it is
1444 inlined. Note that we are calling block_may_fallthru with
1445 language specific tree nodes; this works because
1446 block_may_fallthru returns true when given something it does not
1448 if (!block_may_fallthru (cur_stmt_list
))
1451 return add_stmt (build_stmt (input_location
, BREAK_STMT
));
1454 /* Finish a continue-statement. */
1457 finish_continue_stmt (void)
1459 return add_stmt (build_stmt (input_location
, CONTINUE_STMT
));
1462 /* Begin a switch-statement. Returns a new SWITCH_STMT if
1466 begin_switch_stmt (void)
1470 scope
= do_pushlevel (sk_cond
);
1471 r
= build_stmt (input_location
, SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
, scope
);
1473 begin_cond (&SWITCH_STMT_COND (r
));
1478 /* Finish the cond of a switch-statement. */
1481 finish_switch_cond (tree cond
, tree switch_stmt
)
1483 tree orig_type
= NULL
;
1485 if (!processing_template_decl
)
1487 /* Convert the condition to an integer or enumeration type. */
1488 tree orig_cond
= cond
;
1489 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
1490 if (cond
== NULL_TREE
)
1492 error_at (cp_expr_loc_or_input_loc (orig_cond
),
1493 "switch quantity not an integer");
1494 cond
= error_mark_node
;
1496 /* We want unlowered type here to handle enum bit-fields. */
1497 orig_type
= unlowered_expr_type (cond
);
1498 if (TREE_CODE (orig_type
) != ENUMERAL_TYPE
)
1499 orig_type
= TREE_TYPE (cond
);
1500 if (cond
!= error_mark_node
)
1504 Integral promotions are performed. */
1505 cond
= perform_integral_promotions (cond
);
1506 cond
= maybe_cleanup_point_expr (cond
);
1509 if (check_for_bare_parameter_packs (cond
))
1510 cond
= error_mark_node
;
1511 else if (!processing_template_decl
&& warn_sequence_point
)
1512 verify_sequence_points (cond
);
1514 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
1515 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
1516 add_stmt (switch_stmt
);
1517 push_switch (switch_stmt
);
1518 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
1521 /* Finish the body of a switch-statement, which may be given by
1522 SWITCH_STMT. The COND to switch on is indicated. */
1525 finish_switch_stmt (tree switch_stmt
)
1529 SWITCH_STMT_BODY (switch_stmt
) =
1530 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
1533 scope
= SWITCH_STMT_SCOPE (switch_stmt
);
1534 SWITCH_STMT_SCOPE (switch_stmt
) = NULL
;
1535 add_stmt (do_poplevel (scope
));
1538 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
1542 begin_try_block (void)
1544 tree r
= build_stmt (input_location
, TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
1546 TRY_STMTS (r
) = push_stmt_list ();
1550 /* Likewise, for a function-try-block. The block returned in
1551 *COMPOUND_STMT is an artificial outer scope, containing the
1552 function-try-block. */
1555 begin_function_try_block (tree
*compound_stmt
)
1558 /* This outer scope does not exist in the C++ standard, but we need
1559 a place to put __FUNCTION__ and similar variables. */
1560 *compound_stmt
= begin_compound_stmt (0);
1561 r
= begin_try_block ();
1562 FN_TRY_BLOCK_P (r
) = 1;
1566 /* Finish a try-block, which may be given by TRY_BLOCK. */
1569 finish_try_block (tree try_block
)
1571 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1572 TRY_HANDLERS (try_block
) = push_stmt_list ();
1575 /* Finish the body of a cleanup try-block, which may be given by
1579 finish_cleanup_try_block (tree try_block
)
1581 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1584 /* Finish an implicitly generated try-block, with a cleanup is given
1588 finish_cleanup (tree cleanup
, tree try_block
)
1590 TRY_HANDLERS (try_block
) = cleanup
;
1591 CLEANUP_P (try_block
) = 1;
1594 /* Likewise, for a function-try-block. */
1597 finish_function_try_block (tree try_block
)
1599 finish_try_block (try_block
);
1600 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1601 the try block, but moving it inside. */
1602 in_function_try_handler
= 1;
1605 /* Finish a handler-sequence for a try-block, which may be given by
1609 finish_handler_sequence (tree try_block
)
1611 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1612 check_handlers (TRY_HANDLERS (try_block
));
1615 /* Finish the handler-seq for a function-try-block, given by
1616 TRY_BLOCK. COMPOUND_STMT is the outer block created by
1617 begin_function_try_block. */
1620 finish_function_handler_sequence (tree try_block
, tree compound_stmt
)
1622 in_function_try_handler
= 0;
1623 finish_handler_sequence (try_block
);
1624 finish_compound_stmt (compound_stmt
);
1627 /* Begin a handler. Returns a HANDLER if appropriate. */
1630 begin_handler (void)
1634 r
= build_stmt (input_location
, HANDLER
, NULL_TREE
, NULL_TREE
);
1637 /* Create a binding level for the eh_info and the exception object
1639 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1644 /* Finish the handler-parameters for a handler, which may be given by
1645 HANDLER. DECL is the declaration for the catch parameter, or NULL
1646 if this is a `catch (...)' clause. */
1649 finish_handler_parms (tree decl
, tree handler
)
1651 tree type
= NULL_TREE
;
1652 if (processing_template_decl
)
1656 decl
= pushdecl (decl
);
1657 decl
= push_template_decl (decl
);
1658 HANDLER_PARMS (handler
) = decl
;
1659 type
= TREE_TYPE (decl
);
1664 type
= expand_start_catch_block (decl
);
1665 if (warn_catch_value
1666 && type
!= NULL_TREE
1667 && type
!= error_mark_node
1668 && !TYPE_REF_P (TREE_TYPE (decl
)))
1670 tree orig_type
= TREE_TYPE (decl
);
1671 if (CLASS_TYPE_P (orig_type
))
1673 if (TYPE_POLYMORPHIC_P (orig_type
))
1674 warning_at (DECL_SOURCE_LOCATION (decl
),
1676 "catching polymorphic type %q#T by value",
1678 else if (warn_catch_value
> 1)
1679 warning_at (DECL_SOURCE_LOCATION (decl
),
1681 "catching type %q#T by value", orig_type
);
1683 else if (warn_catch_value
> 2)
1684 warning_at (DECL_SOURCE_LOCATION (decl
),
1686 "catching non-reference type %q#T", orig_type
);
1689 HANDLER_TYPE (handler
) = type
;
1692 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1693 the return value from the matching call to finish_handler_parms. */
1696 finish_handler (tree handler
)
1698 if (!processing_template_decl
)
1699 expand_end_catch_block ();
1700 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1703 /* Begin a compound statement. FLAGS contains some bits that control the
1704 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1705 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1706 block of a function. If BCS_TRY_BLOCK is set, this is the block
1707 created on behalf of a TRY statement. Returns a token to be passed to
1708 finish_compound_stmt. */
1711 begin_compound_stmt (unsigned int flags
)
1715 if (flags
& BCS_NO_SCOPE
)
1717 r
= push_stmt_list ();
1718 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1720 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1721 But, if it's a statement-expression with a scopeless block, there's
1722 nothing to keep, and we don't want to accidentally keep a block
1723 *inside* the scopeless block. */
1724 keep_next_level (false);
1728 scope_kind sk
= sk_block
;
1729 if (flags
& BCS_TRY_BLOCK
)
1731 else if (flags
& BCS_TRANSACTION
)
1732 sk
= sk_transaction
;
1733 r
= do_pushlevel (sk
);
1736 /* When processing a template, we need to remember where the braces were,
1737 so that we can set up identical scopes when instantiating the template
1738 later. BIND_EXPR is a handy candidate for this.
1739 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1740 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1741 processing templates. */
1742 if (processing_template_decl
)
1744 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1745 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1746 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1747 TREE_SIDE_EFFECTS (r
) = 1;
1753 /* Finish a compound-statement, which is given by STMT. */
1756 finish_compound_stmt (tree stmt
)
1758 if (TREE_CODE (stmt
) == BIND_EXPR
)
1760 tree body
= do_poplevel (BIND_EXPR_BODY (stmt
));
1761 /* If the STATEMENT_LIST is empty and this BIND_EXPR isn't special,
1762 discard the BIND_EXPR so it can be merged with the containing
1764 if (TREE_CODE (body
) == STATEMENT_LIST
1765 && STATEMENT_LIST_HEAD (body
) == NULL
1766 && !BIND_EXPR_BODY_BLOCK (stmt
)
1767 && !BIND_EXPR_TRY_BLOCK (stmt
))
1770 BIND_EXPR_BODY (stmt
) = body
;
1772 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1773 stmt
= pop_stmt_list (stmt
);
1776 /* Destroy any ObjC "super" receivers that may have been
1778 objc_clear_super_receiver ();
1780 stmt
= do_poplevel (stmt
);
1783 /* ??? See c_end_compound_stmt wrt statement expressions. */
1787 /* Finish an asm-statement, whose components are a STRING, some
1788 OUTPUT_OPERANDS, some INPUT_OPERANDS, some CLOBBERS and some
1789 LABELS. Also note whether the asm-statement should be
1790 considered volatile, and whether it is asm inline. */
1793 finish_asm_stmt (location_t loc
, int volatile_p
, tree string
,
1794 tree output_operands
, tree input_operands
, tree clobbers
,
1795 tree labels
, bool inline_p
)
1799 int ninputs
= list_length (input_operands
);
1800 int noutputs
= list_length (output_operands
);
1802 if (!processing_template_decl
)
1804 const char *constraint
;
1805 const char **oconstraints
;
1806 bool allows_mem
, allows_reg
, is_inout
;
1810 oconstraints
= XALLOCAVEC (const char *, noutputs
);
1812 string
= resolve_asm_operand_names (string
, output_operands
,
1813 input_operands
, labels
);
1815 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1817 operand
= TREE_VALUE (t
);
1819 /* ??? Really, this should not be here. Users should be using a
1820 proper lvalue, dammit. But there's a long history of using
1821 casts in the output operands. In cases like longlong.h, this
1822 becomes a primitive form of typechecking -- if the cast can be
1823 removed, then the output operand had a type of the proper width;
1824 otherwise we'll get an error. Gross, but ... */
1825 STRIP_NOPS (operand
);
1827 operand
= mark_lvalue_use (operand
);
1829 if (!lvalue_or_else (operand
, lv_asm
, tf_warning_or_error
))
1830 operand
= error_mark_node
;
1832 if (operand
!= error_mark_node
1833 && (TREE_READONLY (operand
)
1834 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1835 /* Functions are not modifiable, even though they are
1837 || FUNC_OR_METHOD_TYPE_P (TREE_TYPE (operand
))
1838 /* If it's an aggregate and any field is const, then it is
1839 effectively const. */
1840 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1841 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1842 cxx_readonly_error (loc
, operand
, lv_asm
);
1844 tree
*op
= &operand
;
1845 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1846 op
= &TREE_OPERAND (*op
, 1);
1847 switch (TREE_CODE (*op
))
1849 case PREINCREMENT_EXPR
:
1850 case PREDECREMENT_EXPR
:
1852 *op
= genericize_compound_lvalue (*op
);
1853 op
= &TREE_OPERAND (*op
, 1);
1859 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1860 oconstraints
[i
] = constraint
;
1862 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1863 &allows_mem
, &allows_reg
, &is_inout
))
1865 /* If the operand is going to end up in memory,
1866 mark it addressable. */
1867 if (!allows_reg
&& !cxx_mark_addressable (*op
))
1868 operand
= error_mark_node
;
1871 operand
= error_mark_node
;
1873 TREE_VALUE (t
) = operand
;
1876 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1878 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1879 bool constraint_parsed
1880 = parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1881 oconstraints
, &allows_mem
, &allows_reg
);
1882 /* If the operand is going to end up in memory, don't call
1883 decay_conversion. */
1884 if (constraint_parsed
&& !allows_reg
&& allows_mem
)
1885 operand
= mark_lvalue_use (TREE_VALUE (t
));
1887 operand
= decay_conversion (TREE_VALUE (t
), tf_warning_or_error
);
1889 /* If the type of the operand hasn't been determined (e.g.,
1890 because it involves an overloaded function), then issue
1891 an error message. There's no context available to
1892 resolve the overloading. */
1893 if (TREE_TYPE (operand
) == unknown_type_node
)
1896 "type of %<asm%> operand %qE could not be determined",
1898 operand
= error_mark_node
;
1901 if (constraint_parsed
)
1903 /* If the operand is going to end up in memory,
1904 mark it addressable. */
1905 if (!allows_reg
&& allows_mem
)
1907 /* Strip the nops as we allow this case. FIXME, this really
1908 should be rejected or made deprecated. */
1909 STRIP_NOPS (operand
);
1911 tree
*op
= &operand
;
1912 while (TREE_CODE (*op
) == COMPOUND_EXPR
)
1913 op
= &TREE_OPERAND (*op
, 1);
1914 switch (TREE_CODE (*op
))
1916 case PREINCREMENT_EXPR
:
1917 case PREDECREMENT_EXPR
:
1919 *op
= genericize_compound_lvalue (*op
);
1920 op
= &TREE_OPERAND (*op
, 1);
1926 if (!cxx_mark_addressable (*op
))
1927 operand
= error_mark_node
;
1929 else if (!allows_reg
&& !allows_mem
)
1931 /* If constraint allows neither register nor memory,
1932 try harder to get a constant. */
1933 tree constop
= maybe_constant_value (operand
);
1934 if (TREE_CONSTANT (constop
))
1939 operand
= error_mark_node
;
1941 TREE_VALUE (t
) = operand
;
1945 r
= build_stmt (loc
, ASM_EXPR
, string
,
1946 output_operands
, input_operands
,
1948 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1949 ASM_INLINE_P (r
) = inline_p
;
1950 r
= maybe_cleanup_point_expr_void (r
);
1951 return add_stmt (r
);
1954 /* Finish a label with the indicated NAME. Returns the new label. */
1957 finish_label_stmt (tree name
)
1959 tree decl
= define_label (input_location
, name
);
1961 if (decl
== error_mark_node
)
1962 return error_mark_node
;
1964 add_stmt (build_stmt (input_location
, LABEL_EXPR
, decl
));
1969 /* Finish a series of declarations for local labels. G++ allows users
1970 to declare "local" labels, i.e., labels with scope. This extension
1971 is useful when writing code involving statement-expressions. */
1974 finish_label_decl (tree name
)
1976 if (!at_function_scope_p ())
1978 error ("%<__label__%> declarations are only allowed in function scopes");
1982 add_decl_expr (declare_local_label (name
));
1985 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1988 finish_decl_cleanup (tree decl
, tree cleanup
)
1990 push_cleanup (decl
, cleanup
, false);
1993 /* If the current scope exits with an exception, run CLEANUP. */
1996 finish_eh_cleanup (tree cleanup
)
1998 push_cleanup (NULL
, cleanup
, true);
2001 /* The MEM_INITS is a list of mem-initializers, in reverse of the
2002 order they were written by the user. Each node is as for
2003 emit_mem_initializers. */
2006 finish_mem_initializers (tree mem_inits
)
2008 /* Reorder the MEM_INITS so that they are in the order they appeared
2009 in the source program. */
2010 mem_inits
= nreverse (mem_inits
);
2012 if (processing_template_decl
)
2016 for (mem
= mem_inits
; mem
; mem
= TREE_CHAIN (mem
))
2018 /* If the TREE_PURPOSE is a TYPE_PACK_EXPANSION, skip the
2019 check for bare parameter packs in the TREE_VALUE, because
2020 any parameter packs in the TREE_VALUE have already been
2021 bound as part of the TREE_PURPOSE. See
2022 make_pack_expansion for more information. */
2023 if (TREE_CODE (TREE_PURPOSE (mem
)) != TYPE_PACK_EXPANSION
2024 && check_for_bare_parameter_packs (TREE_VALUE (mem
)))
2025 TREE_VALUE (mem
) = error_mark_node
;
2028 add_stmt (build_min_nt_loc (UNKNOWN_LOCATION
,
2029 CTOR_INITIALIZER
, mem_inits
));
2032 emit_mem_initializers (mem_inits
);
2035 /* Obfuscate EXPR if it looks like an id-expression or member access so
2036 that the call to finish_decltype in do_auto_deduction will give the
2037 right result. If EVEN_UNEVAL, do this even in unevaluated context. */
2040 force_paren_expr (tree expr
, bool even_uneval
)
2042 /* This is only needed for decltype(auto) in C++14. */
2043 if (cxx_dialect
< cxx14
)
2046 /* If we're in unevaluated context, we can't be deducing a
2047 return/initializer type, so we don't need to mess with this. */
2048 if (cp_unevaluated_operand
&& !even_uneval
)
2051 if (!DECL_P (tree_strip_any_location_wrapper (expr
))
2052 && TREE_CODE (expr
) != COMPONENT_REF
2053 && TREE_CODE (expr
) != SCOPE_REF
)
2056 location_t loc
= cp_expr_location (expr
);
2058 if (TREE_CODE (expr
) == COMPONENT_REF
2059 || TREE_CODE (expr
) == SCOPE_REF
)
2060 REF_PARENTHESIZED_P (expr
) = true;
2061 else if (processing_template_decl
)
2062 expr
= build1_loc (loc
, PAREN_EXPR
, TREE_TYPE (expr
), expr
);
2065 expr
= build1_loc (loc
, VIEW_CONVERT_EXPR
, TREE_TYPE (expr
), expr
);
2066 REF_PARENTHESIZED_P (expr
) = true;
2072 /* If T is an id-expression obfuscated by force_paren_expr, undo the
2073 obfuscation and return the underlying id-expression. Otherwise
2077 maybe_undo_parenthesized_ref (tree t
)
2079 if (cxx_dialect
< cxx14
)
2082 if (INDIRECT_REF_P (t
) && REF_PARENTHESIZED_P (t
))
2084 t
= TREE_OPERAND (t
, 0);
2085 while (TREE_CODE (t
) == NON_LVALUE_EXPR
2086 || TREE_CODE (t
) == NOP_EXPR
)
2087 t
= TREE_OPERAND (t
, 0);
2089 gcc_assert (TREE_CODE (t
) == ADDR_EXPR
2090 || TREE_CODE (t
) == STATIC_CAST_EXPR
);
2091 t
= TREE_OPERAND (t
, 0);
2093 else if (TREE_CODE (t
) == PAREN_EXPR
)
2094 t
= TREE_OPERAND (t
, 0);
2095 else if (TREE_CODE (t
) == VIEW_CONVERT_EXPR
2096 && REF_PARENTHESIZED_P (t
))
2097 t
= TREE_OPERAND (t
, 0);
2102 /* Finish a parenthesized expression EXPR. */
2105 finish_parenthesized_expr (cp_expr expr
)
2108 /* This inhibits warnings in c_common_truthvalue_conversion. */
2109 suppress_warning (expr
, OPT_Wparentheses
);
2111 if (TREE_CODE (expr
) == OFFSET_REF
2112 || TREE_CODE (expr
) == SCOPE_REF
)
2113 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
2114 enclosed in parentheses. */
2115 PTRMEM_OK_P (expr
) = 0;
2117 tree stripped_expr
= tree_strip_any_location_wrapper (expr
);
2118 if (TREE_CODE (stripped_expr
) == STRING_CST
)
2119 PAREN_STRING_LITERAL_P (stripped_expr
) = 1;
2121 expr
= cp_expr (force_paren_expr (expr
), expr
.get_location ());
2126 /* Finish a reference to a non-static data member (DECL) that is not
2127 preceded by `.' or `->'. */
2130 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
2132 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
2133 bool try_omp_private
= !object
&& omp_private_member_map
;
2138 tree scope
= qualifying_scope
;
2139 if (scope
== NULL_TREE
)
2141 scope
= context_for_name_lookup (decl
);
2142 if (!TYPE_P (scope
))
2144 /* Can happen during error recovery (c++/85014). */
2145 gcc_assert (seen_error ());
2146 return error_mark_node
;
2149 object
= maybe_dummy_object (scope
, NULL
);
2152 object
= maybe_resolve_dummy (object
, true);
2153 if (object
== error_mark_node
)
2154 return error_mark_node
;
2156 /* DR 613/850: Can use non-static data members without an associated
2157 object in sizeof/decltype/alignof. */
2158 if (is_dummy_object (object
) && cp_unevaluated_operand
== 0
2159 && (!processing_template_decl
|| !current_class_ref
))
2161 if (current_function_decl
2162 && DECL_STATIC_FUNCTION_P (current_function_decl
))
2163 error ("invalid use of member %qD in static member function", decl
);
2165 error ("invalid use of non-static data member %qD", decl
);
2166 inform (DECL_SOURCE_LOCATION (decl
), "declared here");
2168 return error_mark_node
;
2171 if (current_class_ptr
)
2172 TREE_USED (current_class_ptr
) = 1;
2173 if (processing_template_decl
)
2175 tree type
= TREE_TYPE (decl
);
2177 if (TYPE_REF_P (type
))
2178 /* Quals on the object don't matter. */;
2179 else if (PACK_EXPANSION_P (type
))
2180 /* Don't bother trying to represent this. */
2184 /* Set the cv qualifiers. */
2185 int quals
= cp_type_quals (TREE_TYPE (object
));
2187 if (DECL_MUTABLE_P (decl
))
2188 quals
&= ~TYPE_QUAL_CONST
;
2190 quals
|= cp_type_quals (TREE_TYPE (decl
));
2191 type
= cp_build_qualified_type (type
, quals
);
2194 if (qualifying_scope
)
2195 /* Wrap this in a SCOPE_REF for now. */
2196 ret
= build_qualified_name (type
, qualifying_scope
, decl
,
2197 /*template_p=*/false);
2199 ret
= (convert_from_reference
2200 (build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
)));
2202 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
2203 QUALIFYING_SCOPE is also non-null. */
2206 tree access_type
= TREE_TYPE (object
);
2208 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
,
2209 decl
, tf_warning_or_error
);
2211 /* If the data member was named `C::M', convert `*this' to `C'
2213 if (qualifying_scope
)
2215 tree binfo
= NULL_TREE
;
2216 object
= build_scoped_ref (object
, qualifying_scope
,
2220 ret
= build_class_member_access_expr (object
, decl
,
2221 /*access_path=*/NULL_TREE
,
2222 /*preserve_reference=*/false,
2223 tf_warning_or_error
);
2225 if (try_omp_private
)
2227 tree
*v
= omp_private_member_map
->get (decl
);
2229 ret
= convert_from_reference (*v
);
2234 /* DECL was the declaration to which a qualified-id resolved. Issue
2235 an error message if it is not accessible. If OBJECT_TYPE is
2236 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
2237 type of `*x', or `x', respectively. If the DECL was named as
2238 `A::B' then NESTED_NAME_SPECIFIER is `A'. Return value is like
2239 perform_access_checks above. */
2242 check_accessibility_of_qualified_id (tree decl
,
2244 tree nested_name_specifier
,
2245 tsubst_flags_t complain
)
2247 /* If we're not checking, return immediately. */
2248 if (deferred_access_no_check
)
2251 /* Determine the SCOPE of DECL. */
2252 tree scope
= context_for_name_lookup (decl
);
2253 /* If the SCOPE is not a type, then DECL is not a member. */
2255 /* If SCOPE is dependent then we can't perform this access check now,
2256 and since we'll perform this access check again after substitution
2257 there's no need to explicitly defer it. */
2258 || dependent_type_p (scope
))
2261 tree qualifying_type
= NULL_TREE
;
2262 /* Compute the scope through which DECL is being accessed. */
2264 /* OBJECT_TYPE might not be a class type; consider:
2266 class A { typedef int I; };
2270 In this case, we will have "A::I" as the DECL, but "I" as the
2272 && CLASS_TYPE_P (object_type
)
2273 && DERIVED_FROM_P (scope
, object_type
))
2274 /* If we are processing a `->' or `.' expression, use the type of the
2276 qualifying_type
= object_type
;
2277 else if (nested_name_specifier
)
2279 /* If the reference is to a non-static member of the
2280 current class, treat it as if it were referenced through
2282 if (DECL_NONSTATIC_MEMBER_P (decl
)
2283 && current_class_ptr
)
2284 if (tree current
= current_nonlambda_class_type ())
2286 if (dependent_type_p (current
))
2287 /* In general we can't know whether this access goes through
2288 `this' until instantiation time. Punt now, or else we might
2289 create a deferred access check that's not relative to `this'
2290 when it ought to be. We'll check this access again after
2291 substitution, e.g. from tsubst_qualified_id. */
2294 if (DERIVED_FROM_P (scope
, current
))
2295 qualifying_type
= current
;
2297 /* Otherwise, use the type indicated by the
2298 nested-name-specifier. */
2299 if (!qualifying_type
)
2300 qualifying_type
= nested_name_specifier
;
2303 /* Otherwise, the name must be from the current class or one of
2305 qualifying_type
= currently_open_derived_class (scope
);
2308 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
2309 or similar in a default argument value. */
2310 && CLASS_TYPE_P (qualifying_type
))
2311 return perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
,
2317 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
2318 class named to the left of the "::" operator. DONE is true if this
2319 expression is a complete postfix-expression; it is false if this
2320 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
2321 iff this expression is the operand of '&'. TEMPLATE_P is true iff
2322 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
2323 is true iff this qualified name appears as a template argument. */
2326 finish_qualified_id_expr (tree qualifying_class
,
2331 bool template_arg_p
,
2332 tsubst_flags_t complain
)
2334 gcc_assert (TYPE_P (qualifying_class
));
2336 if (error_operand_p (expr
))
2337 return error_mark_node
;
2339 if ((DECL_P (expr
) || BASELINK_P (expr
))
2340 && !mark_used (expr
, complain
))
2341 return error_mark_node
;
2345 if (TREE_CODE (expr
) == UNBOUND_CLASS_TEMPLATE
)
2347 /* cp_parser_lookup_name thought we were looking for a type,
2348 but we're actually looking for a declaration. */
2349 qualifying_class
= TYPE_CONTEXT (expr
);
2350 expr
= TYPE_IDENTIFIER (expr
);
2353 check_template_keyword (expr
);
2356 /* If EXPR occurs as the operand of '&', use special handling that
2357 permits a pointer-to-member. */
2358 if (address_p
&& done
)
2360 if (TREE_CODE (expr
) == SCOPE_REF
)
2361 expr
= TREE_OPERAND (expr
, 1);
2362 expr
= build_offset_ref (qualifying_class
, expr
,
2363 /*address_p=*/true, complain
);
2367 /* No need to check access within an enum. */
2368 if (TREE_CODE (qualifying_class
) == ENUMERAL_TYPE
2369 && TREE_CODE (expr
) != IDENTIFIER_NODE
)
2372 /* Within the scope of a class, turn references to non-static
2373 members into expression of the form "this->...". */
2375 /* But, within a template argument, we do not want make the
2376 transformation, as there is no "this" pointer. */
2378 else if (TREE_CODE (expr
) == FIELD_DECL
)
2380 push_deferring_access_checks (dk_no_check
);
2381 expr
= finish_non_static_data_member (expr
, NULL_TREE
,
2383 pop_deferring_access_checks ();
2385 else if (BASELINK_P (expr
))
2387 /* See if any of the functions are non-static members. */
2388 /* If so, the expression may be relative to 'this'. */
2389 if (!shared_member_p (expr
)
2390 && current_class_ptr
2391 && DERIVED_FROM_P (qualifying_class
,
2392 current_nonlambda_class_type ()))
2393 expr
= (build_class_member_access_expr
2394 (maybe_dummy_object (qualifying_class
, NULL
),
2396 BASELINK_ACCESS_BINFO (expr
),
2397 /*preserve_reference=*/false,
2400 /* The expression is a qualified name whose address is not
2402 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false,
2405 else if (!template_p
2406 && TREE_CODE (expr
) == TEMPLATE_DECL
2407 && !DECL_FUNCTION_TEMPLATE_P (expr
))
2409 if (complain
& tf_error
)
2410 error ("%qE missing template arguments", expr
);
2411 return error_mark_node
;
2415 /* In a template, return a SCOPE_REF for most qualified-ids
2416 so that we can check access at instantiation time. But if
2417 we're looking at a member of the current instantiation, we
2418 know we have access and building up the SCOPE_REF confuses
2419 non-type template argument handling. */
2420 if (processing_template_decl
2421 && (!currently_open_class (qualifying_class
)
2422 || TREE_CODE (expr
) == IDENTIFIER_NODE
2423 || TREE_CODE (expr
) == TEMPLATE_ID_EXPR
2424 || TREE_CODE (expr
) == BIT_NOT_EXPR
))
2425 expr
= build_qualified_name (TREE_TYPE (expr
),
2426 qualifying_class
, expr
,
2428 else if (tree wrap
= maybe_get_tls_wrapper_call (expr
))
2431 expr
= convert_from_reference (expr
);
2437 /* Begin a statement-expression. The value returned must be passed to
2438 finish_stmt_expr. */
2441 begin_stmt_expr (void)
2443 return push_stmt_list ();
2446 /* Process the final expression of a statement expression. EXPR can be
2447 NULL, if the final expression is empty. Return a STATEMENT_LIST
2448 containing all the statements in the statement-expression, or
2449 ERROR_MARK_NODE if there was an error. */
2452 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
2454 if (error_operand_p (expr
))
2456 /* The type of the statement-expression is the type of the last
2458 TREE_TYPE (stmt_expr
) = error_mark_node
;
2459 return error_mark_node
;
2462 /* If the last statement does not have "void" type, then the value
2463 of the last statement is the value of the entire expression. */
2466 tree type
= TREE_TYPE (expr
);
2468 if (type
&& type_unknown_p (type
))
2470 error ("a statement expression is an insufficient context"
2471 " for overload resolution");
2472 TREE_TYPE (stmt_expr
) = error_mark_node
;
2473 return error_mark_node
;
2475 else if (processing_template_decl
)
2477 expr
= build_stmt (input_location
, EXPR_STMT
, expr
);
2478 expr
= add_stmt (expr
);
2479 /* Mark the last statement so that we can recognize it as such at
2480 template-instantiation time. */
2481 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
2483 else if (VOID_TYPE_P (type
))
2485 /* Just treat this like an ordinary statement. */
2486 expr
= finish_expr_stmt (expr
);
2490 /* It actually has a value we need to deal with. First, force it
2491 to be an rvalue so that we won't need to build up a copy
2492 constructor call later when we try to assign it to something. */
2493 expr
= force_rvalue (expr
, tf_warning_or_error
);
2494 if (error_operand_p (expr
))
2495 return error_mark_node
;
2497 /* Update for array-to-pointer decay. */
2498 type
= TREE_TYPE (expr
);
2500 /* Wrap it in a CLEANUP_POINT_EXPR and add it to the list like a
2501 normal statement, but don't convert to void or actually add
2503 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
2504 expr
= maybe_cleanup_point_expr (expr
);
2508 /* The type of the statement-expression is the type of the last
2510 TREE_TYPE (stmt_expr
) = type
;
2516 /* Finish a statement-expression. EXPR should be the value returned
2517 by the previous begin_stmt_expr. Returns an expression
2518 representing the statement-expression. */
2521 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
2526 if (error_operand_p (stmt_expr
))
2528 pop_stmt_list (stmt_expr
);
2529 return error_mark_node
;
2532 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
2534 type
= TREE_TYPE (stmt_expr
);
2535 result
= pop_stmt_list (stmt_expr
);
2536 TREE_TYPE (result
) = type
;
2538 if (processing_template_decl
)
2540 result
= build_min (STMT_EXPR
, type
, result
);
2541 TREE_SIDE_EFFECTS (result
) = 1;
2542 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
2544 else if (CLASS_TYPE_P (type
))
2546 /* Wrap the statement-expression in a TARGET_EXPR so that the
2547 temporary object created by the final expression is destroyed at
2548 the end of the full-expression containing the
2549 statement-expression. */
2550 result
= force_target_expr (type
, result
, tf_warning_or_error
);
2556 /* Returns the expression which provides the value of STMT_EXPR. */
2559 stmt_expr_value_expr (tree stmt_expr
)
2561 tree t
= STMT_EXPR_STMT (stmt_expr
);
2563 if (TREE_CODE (t
) == BIND_EXPR
)
2564 t
= BIND_EXPR_BODY (t
);
2566 if (TREE_CODE (t
) == STATEMENT_LIST
&& STATEMENT_LIST_TAIL (t
))
2567 t
= STATEMENT_LIST_TAIL (t
)->stmt
;
2569 if (TREE_CODE (t
) == EXPR_STMT
)
2570 t
= EXPR_STMT_EXPR (t
);
2575 /* Return TRUE iff EXPR_STMT is an empty list of
2576 expression statements. */
2579 empty_expr_stmt_p (tree expr_stmt
)
2581 tree body
= NULL_TREE
;
2583 if (expr_stmt
== void_node
)
2588 if (TREE_CODE (expr_stmt
) == EXPR_STMT
)
2589 body
= EXPR_STMT_EXPR (expr_stmt
);
2590 else if (TREE_CODE (expr_stmt
) == STATEMENT_LIST
)
2596 if (TREE_CODE (body
) == STATEMENT_LIST
)
2597 return tsi_end_p (tsi_start (body
));
2599 return empty_expr_stmt_p (body
);
2604 /* Perform Koenig lookup. FN_EXPR is the postfix-expression representing
2605 the function (or functions) to call; ARGS are the arguments to the
2606 call. Returns the functions to be considered by overload resolution. */
2609 perform_koenig_lookup (cp_expr fn_expr
, vec
<tree
, va_gc
> *args
,
2610 tsubst_flags_t complain
)
2612 tree identifier
= NULL_TREE
;
2613 tree functions
= NULL_TREE
;
2614 tree tmpl_args
= NULL_TREE
;
2615 bool template_id
= false;
2616 location_t loc
= fn_expr
.get_location ();
2617 tree fn
= fn_expr
.get_value ();
2619 STRIP_ANY_LOCATION_WRAPPER (fn
);
2621 if (TREE_CODE (fn
) == TEMPLATE_ID_EXPR
)
2623 /* Use a separate flag to handle null args. */
2625 tmpl_args
= TREE_OPERAND (fn
, 1);
2626 fn
= TREE_OPERAND (fn
, 0);
2629 /* Find the name of the overloaded function. */
2630 if (identifier_p (fn
))
2635 identifier
= OVL_NAME (functions
);
2638 /* A call to a namespace-scope function using an unqualified name.
2640 Do Koenig lookup -- unless any of the arguments are
2642 if (!any_type_dependent_arguments_p (args
)
2643 && !any_dependent_template_arguments_p (tmpl_args
))
2645 fn
= lookup_arg_dependent (identifier
, functions
, args
);
2648 /* The unqualified name could not be resolved. */
2649 if (complain
& tf_error
)
2650 fn
= unqualified_fn_lookup_error (cp_expr (identifier
, loc
));
2656 if (fn
&& template_id
&& fn
!= error_mark_node
)
2657 fn
= build2 (TEMPLATE_ID_EXPR
, unknown_type_node
, fn
, tmpl_args
);
2659 return cp_expr (fn
, loc
);
2662 /* Generate an expression for `FN (ARGS)'. This may change the
2665 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
2666 as a virtual call, even if FN is virtual. (This flag is set when
2667 encountering an expression where the function name is explicitly
2668 qualified. For example a call to `X::f' never generates a virtual
2671 Returns code for the call. */
2674 finish_call_expr (tree fn
, vec
<tree
, va_gc
> **args
, bool disallow_virtual
,
2675 bool koenig_p
, tsubst_flags_t complain
)
2679 vec
<tree
, va_gc
> *orig_args
= *args
;
2681 if (fn
== error_mark_node
)
2682 return error_mark_node
;
2684 gcc_assert (!TYPE_P (fn
));
2686 /* If FN may be a FUNCTION_DECL obfuscated by force_paren_expr, undo
2687 it so that we can tell this is a call to a known function. */
2688 fn
= maybe_undo_parenthesized_ref (fn
);
2690 STRIP_ANY_LOCATION_WRAPPER (fn
);
2694 if (processing_template_decl
)
2696 /* If FN is a local extern declaration or set thereof, look them up
2697 again at instantiation time. */
2698 if (is_overloaded_fn (fn
))
2700 tree ifn
= get_first_fn (fn
);
2701 if (TREE_CODE (ifn
) == FUNCTION_DECL
2702 && DECL_LOCAL_DECL_P (ifn
))
2703 orig_fn
= DECL_NAME (ifn
);
2706 /* If the call expression is dependent, build a CALL_EXPR node
2707 with no type; type_dependent_expression_p recognizes
2708 expressions with no type as being dependent. */
2709 if (type_dependent_expression_p (fn
)
2710 || any_type_dependent_arguments_p (*args
))
2712 result
= build_min_nt_call_vec (orig_fn
, *args
);
2713 SET_EXPR_LOCATION (result
, cp_expr_loc_or_input_loc (fn
));
2714 KOENIG_LOOKUP_P (result
) = koenig_p
;
2715 if (is_overloaded_fn (fn
))
2720 bool abnormal
= true;
2721 for (lkp_iterator
iter (fn
); abnormal
&& iter
; ++iter
)
2723 tree fndecl
= STRIP_TEMPLATE (*iter
);
2724 if (TREE_CODE (fndecl
) != FUNCTION_DECL
2725 || !TREE_THIS_VOLATILE (fndecl
))
2728 /* FIXME: Stop warning about falling off end of non-void
2729 function. But this is wrong. Even if we only see
2730 no-return fns at this point, we could select a
2731 future-defined return fn during instantiation. Or
2734 current_function_returns_abnormally
= 1;
2738 orig_args
= make_tree_vector_copy (*args
);
2739 if (!BASELINK_P (fn
)
2740 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
2741 && TREE_TYPE (fn
) != unknown_type_node
)
2742 fn
= build_non_dependent_expr (fn
);
2743 make_args_non_dependent (*args
);
2746 if (TREE_CODE (fn
) == COMPONENT_REF
)
2748 tree member
= TREE_OPERAND (fn
, 1);
2749 if (BASELINK_P (member
))
2751 tree object
= TREE_OPERAND (fn
, 0);
2752 return build_new_method_call (object
, member
,
2755 ? LOOKUP_NORMAL
| LOOKUP_NONVIRTUAL
2762 /* Per 13.3.1.1, '(&f)(...)' is the same as '(f)(...)'. */
2763 if (TREE_CODE (fn
) == ADDR_EXPR
2764 && TREE_CODE (TREE_OPERAND (fn
, 0)) == OVERLOAD
)
2765 fn
= TREE_OPERAND (fn
, 0);
2767 if (is_overloaded_fn (fn
))
2768 fn
= baselink_for_fns (fn
);
2771 if (BASELINK_P (fn
))
2775 /* A call to a member function. From [over.call.func]:
2777 If the keyword this is in scope and refers to the class of
2778 that member function, or a derived class thereof, then the
2779 function call is transformed into a qualified function call
2780 using (*this) as the postfix-expression to the left of the
2781 . operator.... [Otherwise] a contrived object of type T
2782 becomes the implied object argument.
2786 struct A { void f(); };
2787 struct B : public A {};
2788 struct C : public A { void g() { B::f(); }};
2790 "the class of that member function" refers to `A'. But 11.2
2791 [class.access.base] says that we need to convert 'this' to B* as
2792 part of the access, so we pass 'B' to maybe_dummy_object. */
2794 if (DECL_MAYBE_IN_CHARGE_CONSTRUCTOR_P (get_first_fn (fn
)))
2796 /* A constructor call always uses a dummy object. (This constructor
2797 call which has the form A::A () is actually invalid and we are
2798 going to reject it later in build_new_method_call.) */
2799 object
= build_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)));
2802 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
2805 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
2807 ? LOOKUP_NORMAL
|LOOKUP_NONVIRTUAL
2812 else if (concept_check_p (fn
))
2814 /* FN is actually a template-id referring to a concept definition. */
2815 tree id
= unpack_concept_check (fn
);
2816 tree tmpl
= TREE_OPERAND (id
, 0);
2817 tree args
= TREE_OPERAND (id
, 1);
2819 if (!function_concept_p (tmpl
))
2821 error_at (EXPR_LOC_OR_LOC (fn
, input_location
),
2822 "cannot call a concept as a function");
2823 return error_mark_node
;
2826 /* Ensure the result is wrapped as a call expression. */
2827 result
= build_concept_check (tmpl
, args
, tf_warning_or_error
);
2829 else if (is_overloaded_fn (fn
))
2831 /* If the function is an overloaded builtin, resolve it. */
2832 if (TREE_CODE (fn
) == FUNCTION_DECL
2833 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
2834 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
2835 result
= resolve_overloaded_builtin (input_location
, fn
, *args
);
2839 if (warn_sizeof_pointer_memaccess
2840 && (complain
& tf_warning
)
2841 && !vec_safe_is_empty (*args
)
2842 && !processing_template_decl
)
2844 location_t sizeof_arg_loc
[3];
2847 for (i
= 0; i
< 3; i
++)
2851 sizeof_arg_loc
[i
] = UNKNOWN_LOCATION
;
2852 sizeof_arg
[i
] = NULL_TREE
;
2853 if (i
>= (*args
)->length ())
2856 if (TREE_CODE (t
) != SIZEOF_EXPR
)
2858 if (SIZEOF_EXPR_TYPE_P (t
))
2859 sizeof_arg
[i
] = TREE_TYPE (TREE_OPERAND (t
, 0));
2861 sizeof_arg
[i
] = TREE_OPERAND (t
, 0);
2862 sizeof_arg_loc
[i
] = EXPR_LOCATION (t
);
2864 sizeof_pointer_memaccess_warning
2865 (sizeof_arg_loc
, fn
, *args
,
2866 sizeof_arg
, same_type_ignoring_top_level_qualifiers_p
);
2869 if ((complain
& tf_warning
)
2870 && TREE_CODE (fn
) == FUNCTION_DECL
2871 && fndecl_built_in_p (fn
, BUILT_IN_MEMSET
)
2872 && vec_safe_length (*args
) == 3
2873 && !any_type_dependent_arguments_p (*args
))
2875 tree arg0
= (*orig_args
)[0];
2876 tree arg1
= (*orig_args
)[1];
2877 tree arg2
= (*orig_args
)[2];
2878 int literal_mask
= ((literal_integer_zerop (arg1
) << 1)
2879 | (literal_integer_zerop (arg2
) << 2));
2880 warn_for_memset (input_location
, arg0
, arg2
, literal_mask
);
2883 /* A call to a namespace-scope function. */
2884 result
= build_new_function_call (fn
, args
, complain
);
2887 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
2889 if (!vec_safe_is_empty (*args
))
2890 error ("arguments to destructor are not allowed");
2891 /* C++20/DR: If the postfix-expression names a pseudo-destructor (in
2892 which case the postfix-expression is a possibly-parenthesized class
2893 member access), the function call destroys the object of scalar type
2894 denoted by the object expression of the class member access. */
2895 tree ob
= TREE_OPERAND (fn
, 0);
2897 result
= build_trivial_dtor_call (ob
, true);
2899 /* No location to clobber. */
2900 result
= convert_to_void (ob
, ICV_STATEMENT
, complain
);
2902 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
2903 /* If the "function" is really an object of class type, it might
2904 have an overloaded `operator ()'. */
2905 result
= build_op_call (fn
, args
, complain
);
2908 /* A call where the function is unknown. */
2909 result
= cp_build_function_call_vec (fn
, args
, complain
);
2911 if (processing_template_decl
&& result
!= error_mark_node
)
2913 if (INDIRECT_REF_P (result
))
2914 result
= TREE_OPERAND (result
, 0);
2915 result
= build_call_vec (TREE_TYPE (result
), orig_fn
, orig_args
);
2916 SET_EXPR_LOCATION (result
, input_location
);
2917 KOENIG_LOOKUP_P (result
) = koenig_p
;
2918 release_tree_vector (orig_args
);
2919 result
= convert_from_reference (result
);
2925 /* Finish a call to a postfix increment or decrement or EXPR. (Which
2926 is indicated by CODE, which should be POSTINCREMENT_EXPR or
2927 POSTDECREMENT_EXPR.) */
2930 finish_increment_expr (cp_expr expr
, enum tree_code code
)
2932 /* input_location holds the location of the trailing operator token.
2933 Build a location of the form:
2936 with the caret at the operator token, ranging from the start
2937 of EXPR to the end of the operator token. */
2938 location_t combined_loc
= make_location (input_location
,
2940 get_finish (input_location
));
2941 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
,
2942 tf_warning_or_error
);
2943 /* TODO: build_x_unary_op doesn't honor the location, so set it here. */
2944 result
.set_location (combined_loc
);
2948 /* Finish a use of `this'. Returns an expression for `this'. */
2951 finish_this_expr (void)
2953 tree result
= NULL_TREE
;
2955 if (current_class_ptr
)
2957 tree type
= TREE_TYPE (current_class_ref
);
2959 /* In a lambda expression, 'this' refers to the captured 'this'. */
2960 if (LAMBDA_TYPE_P (type
))
2961 result
= lambda_expr_this_capture (CLASSTYPE_LAMBDA_EXPR (type
), true);
2963 result
= current_class_ptr
;
2967 /* The keyword 'this' is a prvalue expression. */
2968 return rvalue (result
);
2970 tree fn
= current_nonlambda_function ();
2971 if (fn
&& DECL_STATIC_FUNCTION_P (fn
))
2972 error ("%<this%> is unavailable for static member functions");
2974 error ("invalid use of %<this%> in non-member function");
2976 error ("invalid use of %<this%> at top level");
2977 return error_mark_node
;
2980 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
2981 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
2982 the TYPE for the type given. If SCOPE is non-NULL, the expression
2983 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
2986 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
,
2989 if (object
== error_mark_node
|| destructor
== error_mark_node
)
2990 return error_mark_node
;
2992 gcc_assert (TYPE_P (destructor
));
2994 if (!processing_template_decl
)
2996 if (scope
== error_mark_node
)
2998 error_at (loc
, "invalid qualifying scope in pseudo-destructor name");
2999 return error_mark_node
;
3001 if (is_auto (destructor
))
3002 destructor
= TREE_TYPE (object
);
3003 if (scope
&& TYPE_P (scope
) && !check_dtor_name (scope
, destructor
))
3006 "qualified type %qT does not match destructor name ~%qT",
3008 return error_mark_node
;
3012 /* [expr.pseudo] says both:
3014 The type designated by the pseudo-destructor-name shall be
3015 the same as the object type.
3019 The cv-unqualified versions of the object type and of the
3020 type designated by the pseudo-destructor-name shall be the
3023 We implement the more generous second sentence, since that is
3024 what most other compilers do. */
3025 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
3028 error_at (loc
, "%qE is not of type %qT", object
, destructor
);
3029 return error_mark_node
;
3033 tree type
= (type_dependent_expression_p (object
)
3034 ? NULL_TREE
: void_type_node
);
3036 return build3_loc (loc
, PSEUDO_DTOR_EXPR
, type
, object
,
3040 /* Finish an expression of the form CODE EXPR. */
3043 finish_unary_op_expr (location_t op_loc
, enum tree_code code
, cp_expr expr
,
3044 tsubst_flags_t complain
)
3046 /* Build a location of the form:
3049 with the caret at the operator token, ranging from the start
3050 of the operator token to the end of EXPR. */
3051 location_t combined_loc
= make_location (op_loc
,
3052 op_loc
, expr
.get_finish ());
3053 cp_expr result
= build_x_unary_op (combined_loc
, code
, expr
, complain
);
3054 /* TODO: build_x_unary_op doesn't always honor the location. */
3055 result
.set_location (combined_loc
);
3057 if (result
== error_mark_node
)
3060 if (!(complain
& tf_warning
))
3063 tree result_ovl
= result
;
3064 tree expr_ovl
= expr
;
3066 if (!processing_template_decl
)
3067 expr_ovl
= cp_fully_fold (expr_ovl
);
3069 if (!CONSTANT_CLASS_P (expr_ovl
)
3070 || TREE_OVERFLOW_P (expr_ovl
))
3073 if (!processing_template_decl
)
3074 result_ovl
= cp_fully_fold (result_ovl
);
3076 if (CONSTANT_CLASS_P (result_ovl
) && TREE_OVERFLOW_P (result_ovl
))
3077 overflow_warning (combined_loc
, result_ovl
);
3082 /* Finish a compound-literal expression or C++11 functional cast with aggregate
3083 initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL
3087 finish_compound_literal (tree type
, tree compound_literal
,
3088 tsubst_flags_t complain
,
3091 if (type
== error_mark_node
)
3092 return error_mark_node
;
3094 if (TYPE_REF_P (type
))
3097 = finish_compound_literal (TREE_TYPE (type
), compound_literal
,
3098 complain
, fcl_context
);
3099 /* The prvalue is then used to direct-initialize the reference. */
3100 tree r
= (perform_implicit_conversion_flags
3101 (type
, compound_literal
, complain
, LOOKUP_NORMAL
));
3102 return convert_from_reference (r
);
3105 if (!TYPE_OBJ_P (type
))
3107 if (complain
& tf_error
)
3108 error ("compound literal of non-object type %qT", type
);
3109 return error_mark_node
;
3112 if (template_placeholder_p (type
))
3114 type
= do_auto_deduction (type
, compound_literal
, type
, complain
,
3116 if (type
== error_mark_node
)
3117 return error_mark_node
;
3120 /* Used to hold a copy of the compound literal in a template. */
3121 tree orig_cl
= NULL_TREE
;
3123 if (processing_template_decl
)
3125 const bool dependent_p
3126 = (instantiation_dependent_expression_p (compound_literal
)
3127 || dependent_type_p (type
));
3129 /* We're about to return, no need to copy. */
3130 orig_cl
= compound_literal
;
3132 /* We're going to need a copy. */
3133 orig_cl
= unshare_constructor (compound_literal
);
3134 TREE_TYPE (orig_cl
) = type
;
3135 /* Mark the expression as a compound literal. */
3136 TREE_HAS_CONSTRUCTOR (orig_cl
) = 1;
3137 /* And as instantiation-dependent. */
3138 CONSTRUCTOR_IS_DEPENDENT (orig_cl
) = dependent_p
;
3139 if (fcl_context
== fcl_c99
)
3140 CONSTRUCTOR_C99_COMPOUND_LITERAL (orig_cl
) = 1;
3141 /* If the compound literal is dependent, we're done for now. */
3144 /* Otherwise, do go on to e.g. check narrowing. */
3147 type
= complete_type (type
);
3149 if (TYPE_NON_AGGREGATE_CLASS (type
))
3151 /* Trying to deal with a CONSTRUCTOR instead of a TREE_LIST
3152 everywhere that deals with function arguments would be a pain, so
3153 just wrap it in a TREE_LIST. The parser set a flag so we know
3154 that it came from T{} rather than T({}). */
3155 CONSTRUCTOR_IS_DIRECT_INIT (compound_literal
) = 1;
3156 compound_literal
= build_tree_list (NULL_TREE
, compound_literal
);
3157 return build_functional_cast (input_location
, type
,
3158 compound_literal
, complain
);
3161 if (TREE_CODE (type
) == ARRAY_TYPE
3162 && check_array_initializer (NULL_TREE
, type
, compound_literal
))
3163 return error_mark_node
;
3164 compound_literal
= reshape_init (type
, compound_literal
, complain
);
3165 if (SCALAR_TYPE_P (type
)
3166 && !BRACE_ENCLOSED_INITIALIZER_P (compound_literal
))
3168 tree t
= instantiate_non_dependent_expr_sfinae (compound_literal
,
3170 if (!check_narrowing (type
, t
, complain
))
3171 return error_mark_node
;
3173 if (TREE_CODE (type
) == ARRAY_TYPE
3174 && TYPE_DOMAIN (type
) == NULL_TREE
)
3176 cp_complete_array_type_or_error (&type
, compound_literal
,
3178 if (type
== error_mark_node
)
3179 return error_mark_node
;
3181 compound_literal
= digest_init_flags (type
, compound_literal
,
3182 LOOKUP_NORMAL
| LOOKUP_NO_NARROWING
,
3184 if (compound_literal
== error_mark_node
)
3185 return error_mark_node
;
3187 /* If we're in a template, return the original compound literal. */
3191 if (TREE_CODE (compound_literal
) == CONSTRUCTOR
)
3193 TREE_HAS_CONSTRUCTOR (compound_literal
) = true;
3194 if (fcl_context
== fcl_c99
)
3195 CONSTRUCTOR_C99_COMPOUND_LITERAL (compound_literal
) = 1;
3198 /* Put static/constant array temporaries in static variables. */
3199 /* FIXME all C99 compound literals should be variables rather than C++
3200 temporaries, unless they are used as an aggregate initializer. */
3201 if ((!at_function_scope_p () || CP_TYPE_CONST_P (type
))
3202 && fcl_context
== fcl_c99
3203 && TREE_CODE (type
) == ARRAY_TYPE
3204 && !TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
)
3205 && initializer_constant_valid_p (compound_literal
, type
))
3207 tree decl
= create_temporary_var (type
);
3208 DECL_CONTEXT (decl
) = NULL_TREE
;
3209 DECL_INITIAL (decl
) = compound_literal
;
3210 TREE_STATIC (decl
) = 1;
3211 if (literal_type_p (type
) && CP_TYPE_CONST_NON_VOLATILE_P (type
))
3213 /* 5.19 says that a constant expression can include an
3214 lvalue-rvalue conversion applied to "a glvalue of literal type
3215 that refers to a non-volatile temporary object initialized
3216 with a constant expression". Rather than try to communicate
3217 that this VAR_DECL is a temporary, just mark it constexpr. */
3218 DECL_DECLARED_CONSTEXPR_P (decl
) = true;
3219 DECL_INITIALIZED_BY_CONSTANT_EXPRESSION_P (decl
) = true;
3220 TREE_CONSTANT (decl
) = true;
3222 cp_apply_type_quals_to_decl (cp_type_quals (type
), decl
);
3223 decl
= pushdecl_top_level (decl
);
3224 DECL_NAME (decl
) = make_anon_name ();
3225 SET_DECL_ASSEMBLER_NAME (decl
, DECL_NAME (decl
));
3226 /* Make sure the destructor is callable. */
3227 tree clean
= cxx_maybe_build_cleanup (decl
, complain
);
3228 if (clean
== error_mark_node
)
3229 return error_mark_node
;
3233 /* Represent other compound literals with TARGET_EXPR so we produce
3234 a prvalue, and can elide copies. */
3235 if (!VECTOR_TYPE_P (type
))
3237 /* The CONSTRUCTOR is now an initializer, not a compound literal. */
3238 TREE_HAS_CONSTRUCTOR (compound_literal
) = false;
3239 compound_literal
= get_target_expr_sfinae (compound_literal
, complain
);
3242 return compound_literal
;
3245 /* Return the declaration for the function-name variable indicated by
3249 finish_fname (tree id
)
3253 decl
= fname_decl (input_location
, C_RID_CODE (id
), id
);
3254 if (processing_template_decl
&& current_function_decl
3255 && decl
!= error_mark_node
)
3256 decl
= DECL_NAME (decl
);
3260 /* Finish a translation unit. */
3263 finish_translation_unit (void)
3265 /* In case there were missing closebraces,
3266 get us back to the global binding level. */
3268 while (current_namespace
!= global_namespace
)
3271 /* Do file scope __FUNCTION__ et al. */
3272 finish_fname_decls ();
3274 if (vec_safe_length (scope_chain
->omp_declare_target_attribute
))
3277 error ("%<#pragma omp declare target%> without corresponding "
3278 "%<#pragma omp end declare target%>");
3279 vec_safe_truncate (scope_chain
->omp_declare_target_attribute
, 0);
3283 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
3284 Returns the parameter. */
3287 finish_template_type_parm (tree aggr
, tree identifier
)
3289 if (aggr
!= class_type_node
)
3291 permerror (input_location
, "template type parameters must use the keyword %<class%> or %<typename%>");
3292 aggr
= class_type_node
;
3295 return build_tree_list (aggr
, identifier
);
3298 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
3299 Returns the parameter. */
3302 finish_template_template_parm (tree aggr
, tree identifier
)
3304 tree decl
= build_decl (input_location
,
3305 TYPE_DECL
, identifier
, NULL_TREE
);
3307 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
3308 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
3309 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
3310 DECL_ARTIFICIAL (decl
) = 1;
3312 /* Associate the constraints with the underlying declaration,
3313 not the template. */
3314 tree reqs
= TEMPLATE_PARMS_CONSTRAINTS (current_template_parms
);
3315 tree constr
= build_constraints (reqs
, NULL_TREE
);
3316 set_constraints (decl
, constr
);
3318 end_template_decl ();
3320 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
3322 check_default_tmpl_args (decl
, DECL_TEMPLATE_PARMS (tmpl
),
3323 /*is_primary=*/true, /*is_partial=*/false,
3326 return finish_template_type_parm (aggr
, tmpl
);
3329 /* ARGUMENT is the default-argument value for a template template
3330 parameter. If ARGUMENT is invalid, issue error messages and return
3331 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
3334 check_template_template_default_arg (tree argument
)
3336 if (TREE_CODE (argument
) != TEMPLATE_DECL
3337 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
3338 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
3340 if (TREE_CODE (argument
) == TYPE_DECL
)
3341 error ("invalid use of type %qT as a default value for a template "
3342 "template-parameter", TREE_TYPE (argument
));
3344 error ("invalid default argument for a template template parameter");
3345 return error_mark_node
;
3351 /* Begin a class definition, as indicated by T. */
3354 begin_class_definition (tree t
)
3356 if (error_operand_p (t
) || error_operand_p (TYPE_MAIN_DECL (t
)))
3357 return error_mark_node
;
3359 if (processing_template_parmlist
&& !LAMBDA_TYPE_P (t
))
3361 error ("definition of %q#T inside template parameter list", t
);
3362 return error_mark_node
;
3365 /* According to the C++ ABI, decimal classes defined in ISO/IEC TR 24733
3366 are passed the same as decimal scalar types. */
3367 if (TREE_CODE (t
) == RECORD_TYPE
3368 && !processing_template_decl
)
3370 tree ns
= TYPE_CONTEXT (t
);
3371 if (ns
&& TREE_CODE (ns
) == NAMESPACE_DECL
3372 && DECL_CONTEXT (ns
) == std_node
3374 && id_equal (DECL_NAME (ns
), "decimal"))
3376 const char *n
= TYPE_NAME_STRING (t
);
3377 if ((strcmp (n
, "decimal32") == 0)
3378 || (strcmp (n
, "decimal64") == 0)
3379 || (strcmp (n
, "decimal128") == 0))
3380 TYPE_TRANSPARENT_AGGR (t
) = 1;
3384 /* A non-implicit typename comes from code like:
3386 template <typename T> struct A {
3387 template <typename U> struct A<T>::B ...
3389 This is erroneous. */
3390 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
3392 error ("invalid definition of qualified type %qT", t
);
3393 t
= error_mark_node
;
3396 if (t
== error_mark_node
|| ! MAYBE_CLASS_TYPE_P (t
))
3398 t
= make_class_type (RECORD_TYPE
);
3399 pushtag (make_anon_name (), t
);
3402 if (TYPE_BEING_DEFINED (t
))
3404 t
= make_class_type (TREE_CODE (t
));
3405 pushtag (TYPE_IDENTIFIER (t
), t
);
3410 if (!module_may_redeclare (TYPE_NAME (t
)))
3412 error ("cannot declare %qD in a different module", TYPE_NAME (t
));
3413 inform (DECL_SOURCE_LOCATION (TYPE_NAME (t
)), "declared here");
3414 return error_mark_node
;
3416 set_instantiating_module (TYPE_NAME (t
));
3417 set_defining_module (TYPE_NAME (t
));
3420 maybe_process_partial_specialization (t
);
3422 TYPE_BEING_DEFINED (t
) = 1;
3423 class_binding_level
->defining_class_p
= 1;
3425 if (flag_pack_struct
)
3428 TYPE_PACKED (t
) = 1;
3429 /* Even though the type is being defined for the first time
3430 here, there might have been a forward declaration, so there
3431 might be cv-qualified variants of T. */
3432 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
3433 TYPE_PACKED (v
) = 1;
3435 /* Reset the interface data, at the earliest possible
3436 moment, as it might have been set via a class foo;
3438 if (! TYPE_UNNAMED_P (t
))
3440 struct c_fileinfo
*finfo
= \
3441 get_fileinfo (LOCATION_FILE (input_location
));
3442 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
3443 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
3444 (t
, finfo
->interface_unknown
);
3446 reset_specialization ();
3448 /* Make a declaration for this class in its own scope. */
3449 build_self_reference ();
3454 /* Finish the member declaration given by DECL. */
3457 finish_member_declaration (tree decl
)
3459 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
3462 if (decl
== void_type_node
)
3463 /* The COMPONENT was a friend, not a member, and so there's
3464 nothing for us to do. */
3467 /* We should see only one DECL at a time. */
3468 gcc_assert (DECL_CHAIN (decl
) == NULL_TREE
);
3470 /* Don't add decls after definition. */
3471 gcc_assert (TYPE_BEING_DEFINED (current_class_type
)
3472 /* We can add lambda types when late parsing default
3474 || LAMBDA_TYPE_P (TREE_TYPE (decl
)));
3476 /* Set up access control for DECL. */
3478 = (current_access_specifier
== access_private_node
);
3479 TREE_PROTECTED (decl
)
3480 = (current_access_specifier
== access_protected_node
);
3481 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
3483 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
3484 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
3487 /* Mark the DECL as a member of the current class, unless it's
3488 a member of an enumeration. */
3489 if (TREE_CODE (decl
) != CONST_DECL
)
3490 DECL_CONTEXT (decl
) = current_class_type
;
3492 if (TREE_CODE (decl
) == USING_DECL
)
3493 /* For now, ignore class-scope USING_DECLS, so that debugging
3494 backends do not see them. */
3495 DECL_IGNORED_P (decl
) = 1;
3497 /* Check for bare parameter packs in the non-static data member
3499 if (TREE_CODE (decl
) == FIELD_DECL
)
3501 if (check_for_bare_parameter_packs (TREE_TYPE (decl
)))
3502 TREE_TYPE (decl
) = error_mark_node
;
3503 if (check_for_bare_parameter_packs (DECL_ATTRIBUTES (decl
)))
3504 DECL_ATTRIBUTES (decl
) = NULL_TREE
;
3509 A C language linkage is ignored for the names of class members
3510 and the member function type of class member functions. */
3511 if (DECL_LANG_SPECIFIC (decl
))
3512 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
3516 /* Functions and non-functions are added differently. */
3517 if (DECL_DECLARES_FUNCTION_P (decl
))
3518 add
= add_method (current_class_type
, decl
, false);
3519 /* Enter the DECL into the scope of the class, if the class
3520 isn't a closure (whose fields are supposed to be unnamed). */
3521 else if (CLASSTYPE_LAMBDA_EXPR (current_class_type
)
3522 || pushdecl_class_level (decl
))
3527 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
3528 go at the beginning. The reason is that
3529 legacy_nonfn_member_lookup searches the list in order, and we
3530 want a field name to override a type name so that the "struct
3531 stat hack" will work. In particular:
3533 struct S { enum E { }; static const int E = 5; int ary[S::E]; } s;
3537 if (TREE_CODE (decl
) == TYPE_DECL
)
3538 TYPE_FIELDS (current_class_type
)
3539 = chainon (TYPE_FIELDS (current_class_type
), decl
);
3542 DECL_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
3543 TYPE_FIELDS (current_class_type
) = decl
;
3546 maybe_add_class_template_decl_list (current_class_type
, decl
,
3551 /* Finish processing a complete template declaration. The PARMS are
3552 the template parameters. */
3555 finish_template_decl (tree parms
)
3558 end_template_decl ();
3560 end_specialization ();
3563 // Returns the template type of the class scope being entered. If we're
3564 // entering a constrained class scope. TYPE is the class template
3565 // scope being entered and we may need to match the intended type with
3566 // a constrained specialization. For example:
3568 // template<Object T>
3569 // struct S { void f(); }; #1
3571 // template<Object T>
3572 // void S<T>::f() { } #2
3574 // We check, in #2, that S<T> refers precisely to the type declared by
3575 // #1 (i.e., that the constraints match). Note that the following should
3576 // be an error since there is no specialization of S<T> that is
3577 // unconstrained, but this is not diagnosed here.
3579 // template<typename T>
3580 // void S<T>::f() { }
3582 // We cannot diagnose this problem here since this function also matches
3583 // qualified template names that are not part of a definition. For example:
3585 // template<Integral T, Floating_point U>
3586 // typename pair<T, U>::first_type void f(T, U);
3588 // Here, it is unlikely that there is a partial specialization of
3589 // pair constrained for for Integral and Floating_point arguments.
3591 // The general rule is: if a constrained specialization with matching
3592 // constraints is found return that type. Also note that if TYPE is not a
3593 // class-type (e.g. a typename type), then no fixup is needed.
3596 fixup_template_type (tree type
)
3598 // Find the template parameter list at the a depth appropriate to
3599 // the scope we're trying to enter.
3600 tree parms
= current_template_parms
;
3601 int depth
= template_class_depth (type
);
3602 for (int n
= processing_template_decl
; n
> depth
&& parms
; --n
)
3603 parms
= TREE_CHAIN (parms
);
3606 tree cur_reqs
= TEMPLATE_PARMS_CONSTRAINTS (parms
);
3607 tree cur_constr
= build_constraints (cur_reqs
, NULL_TREE
);
3609 // Search for a specialization whose type and constraints match.
3610 tree tmpl
= CLASSTYPE_TI_TEMPLATE (type
);
3611 tree specs
= DECL_TEMPLATE_SPECIALIZATIONS (tmpl
);
3614 tree spec_constr
= get_constraints (TREE_VALUE (specs
));
3616 // If the type and constraints match a specialization, then we
3617 // are entering that type.
3618 if (same_type_p (type
, TREE_TYPE (specs
))
3619 && equivalent_constraints (cur_constr
, spec_constr
))
3620 return TREE_TYPE (specs
);
3621 specs
= TREE_CHAIN (specs
);
3624 // If no specialization matches, then must return the type
3625 // previously found.
3629 /* Finish processing a template-id (which names a type) of the form
3630 NAME < ARGS >. Return the TYPE_DECL for the type named by the
3631 template-id. If ENTERING_SCOPE is nonzero we are about to enter
3632 the scope of template-id indicated. */
3635 finish_template_type (tree name
, tree args
, int entering_scope
)
3639 type
= lookup_template_class (name
, args
,
3640 NULL_TREE
, NULL_TREE
, entering_scope
,
3641 tf_warning_or_error
| tf_user
);
3643 /* If we might be entering the scope of a partial specialization,
3644 find the one with the right constraints. */
3647 && CLASS_TYPE_P (type
)
3648 && CLASSTYPE_TEMPLATE_INFO (type
)
3649 && dependent_type_p (type
)
3650 && PRIMARY_TEMPLATE_P (CLASSTYPE_TI_TEMPLATE (type
)))
3651 type
= fixup_template_type (type
);
3653 if (type
== error_mark_node
)
3655 else if (CLASS_TYPE_P (type
) && !alias_type_or_template_p (type
))
3656 return TYPE_STUB_DECL (type
);
3658 return TYPE_NAME (type
);
3661 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
3662 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
3663 BASE_CLASS, or NULL_TREE if an error occurred. The
3664 ACCESS_SPECIFIER is one of
3665 access_{default,public,protected_private}_node. For a virtual base
3666 we set TREE_TYPE. */
3669 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
3673 if (base
== error_mark_node
)
3675 error ("invalid base-class specification");
3678 else if (! MAYBE_CLASS_TYPE_P (base
))
3680 error ("%qT is not a class type", base
);
3685 if (cp_type_quals (base
) != 0)
3687 /* DR 484: Can a base-specifier name a cv-qualified
3689 base
= TYPE_MAIN_VARIANT (base
);
3691 result
= build_tree_list (access
, base
);
3693 TREE_TYPE (result
) = integer_type_node
;
3699 /* If FNS is a member function, a set of member functions, or a
3700 template-id referring to one or more member functions, return a
3701 BASELINK for FNS, incorporating the current access context.
3702 Otherwise, return FNS unchanged. */
3705 baselink_for_fns (tree fns
)
3710 if (BASELINK_P (fns
)
3711 || error_operand_p (fns
))
3714 scope
= ovl_scope (fns
);
3715 if (!CLASS_TYPE_P (scope
))
3718 cl
= currently_open_derived_class (scope
);
3721 tree access_path
= TYPE_BINFO (cl
);
3722 tree conv_path
= (cl
== scope
? access_path
3723 : lookup_base (cl
, scope
, ba_any
, NULL
, tf_none
));
3724 return build_baselink (conv_path
, access_path
, fns
, /*optype=*/NULL_TREE
);
3727 /* Returns true iff DECL is a variable from a function outside
3731 outer_var_p (tree decl
)
3733 return ((VAR_P (decl
) || TREE_CODE (decl
) == PARM_DECL
)
3734 && DECL_FUNCTION_SCOPE_P (decl
)
3735 /* Don't get confused by temporaries. */
3737 && (DECL_CONTEXT (decl
) != current_function_decl
3738 || parsing_nsdmi ()));
3741 /* As above, but also checks that DECL is automatic. */
3744 outer_automatic_var_p (tree decl
)
3746 return (outer_var_p (decl
)
3747 && !TREE_STATIC (decl
));
3750 /* DECL satisfies outer_automatic_var_p. Possibly complain about it or
3751 rewrite it for lambda capture.
3753 If ODR_USE is true, we're being called from mark_use, and we complain about
3754 use of constant variables. If ODR_USE is false, we're being called for the
3755 id-expression, and we do lambda capture. */
3758 process_outer_var_ref (tree decl
, tsubst_flags_t complain
, bool odr_use
)
3760 if (cp_unevaluated_operand
)
3762 tree type
= TREE_TYPE (decl
);
3763 if (!dependent_type_p (type
)
3764 && variably_modified_type_p (type
, NULL_TREE
))
3765 /* VLAs are used even in unevaluated context. */;
3767 /* It's not a use (3.2) if we're in an unevaluated context. */
3770 if (decl
== error_mark_node
)
3773 tree context
= DECL_CONTEXT (decl
);
3774 tree containing_function
= current_function_decl
;
3775 tree lambda_stack
= NULL_TREE
;
3776 tree lambda_expr
= NULL_TREE
;
3777 tree initializer
= convert_from_reference (decl
);
3779 /* Mark it as used now even if the use is ill-formed. */
3780 if (!mark_used (decl
, complain
))
3781 return error_mark_node
;
3783 if (parsing_nsdmi ())
3784 containing_function
= NULL_TREE
;
3786 if (containing_function
&& LAMBDA_FUNCTION_P (containing_function
))
3788 /* Check whether we've already built a proxy. */
3790 while (is_normal_capture_proxy (var
))
3791 var
= DECL_CAPTURED_VARIABLE (var
);
3792 tree d
= retrieve_local_specialization (var
);
3794 if (d
&& d
!= decl
&& is_capture_proxy (d
))
3796 if (DECL_CONTEXT (d
) == containing_function
)
3797 /* We already have an inner proxy. */
3800 /* We need to capture an outer proxy. */
3801 return process_outer_var_ref (d
, complain
, odr_use
);
3805 /* If we are in a lambda function, we can move out until we hit
3807 2. a non-lambda function, or
3808 3. a non-default capturing lambda function. */
3809 while (context
!= containing_function
3810 /* containing_function can be null with invalid generic lambdas. */
3811 && containing_function
3812 && LAMBDA_FUNCTION_P (containing_function
))
3814 tree closure
= DECL_CONTEXT (containing_function
);
3815 lambda_expr
= CLASSTYPE_LAMBDA_EXPR (closure
);
3817 if (TYPE_CLASS_SCOPE_P (closure
))
3818 /* A lambda in an NSDMI (c++/64496). */
3821 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3824 lambda_stack
= tree_cons (NULL_TREE
, lambda_expr
, lambda_stack
);
3826 containing_function
= decl_function_context (containing_function
);
3829 /* In a lambda within a template, wait until instantiation time to implicitly
3830 capture a parameter pack. We want to wait because we don't know if we're
3831 capturing the whole pack or a single element, and it's OK to wait because
3832 find_parameter_packs_r walks into the lambda body. */
3833 if (context
== containing_function
3834 && DECL_PACK_P (decl
))
3837 if (lambda_expr
&& VAR_P (decl
) && DECL_ANON_UNION_VAR_P (decl
))
3839 if (complain
& tf_error
)
3840 error ("cannot capture member %qD of anonymous union", decl
);
3841 return error_mark_node
;
3843 /* Do lambda capture when processing the id-expression, not when
3844 odr-using a variable. */
3845 if (!odr_use
&& context
== containing_function
)
3846 decl
= add_default_capture (lambda_stack
,
3847 /*id=*/DECL_NAME (decl
), initializer
);
3848 /* Only an odr-use of an outer automatic variable causes an
3849 error, and a constant variable can decay to a prvalue
3850 constant without odr-use. So don't complain yet. */
3851 else if (!odr_use
&& decl_constant_var_p (decl
))
3853 else if (lambda_expr
)
3855 if (complain
& tf_error
)
3857 error ("%qD is not captured", decl
);
3858 tree closure
= LAMBDA_EXPR_CLOSURE (lambda_expr
);
3859 if (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lambda_expr
) == CPLD_NONE
)
3860 inform (location_of (closure
),
3861 "the lambda has no capture-default");
3862 else if (TYPE_CLASS_SCOPE_P (closure
))
3863 inform (UNKNOWN_LOCATION
, "lambda in local class %q+T cannot "
3864 "capture variables from the enclosing context",
3865 TYPE_CONTEXT (closure
));
3866 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3868 return error_mark_node
;
3872 if (complain
& tf_error
)
3875 ? G_("use of local variable with automatic storage from "
3876 "containing function")
3877 : G_("use of parameter from containing function"));
3878 inform (DECL_SOURCE_LOCATION (decl
), "%q#D declared here", decl
);
3880 return error_mark_node
;
3885 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
3886 id-expression. (See cp_parser_id_expression for details.) SCOPE,
3887 if non-NULL, is the type or namespace used to explicitly qualify
3888 ID_EXPRESSION. DECL is the entity to which that name has been
3891 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
3892 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
3893 be set to true if this expression isn't permitted in a
3894 constant-expression, but it is otherwise not set by this function.
3895 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
3896 constant-expression, but a non-constant expression is also
3899 DONE is true if this expression is a complete postfix-expression;
3900 it is false if this expression is followed by '->', '[', '(', etc.
3901 ADDRESS_P is true iff this expression is the operand of '&'.
3902 TEMPLATE_P is true iff the qualified-id was of the form
3903 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
3904 appears as a template argument.
3906 If an error occurs, and it is the kind of error that might cause
3907 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
3908 is the caller's responsibility to issue the message. *ERROR_MSG
3909 will be a string with static storage duration, so the caller need
3912 Return an expression for the entity, after issuing appropriate
3913 diagnostics. This function is also responsible for transforming a
3914 reference to a non-static member into a COMPONENT_REF that makes
3915 the use of "this" explicit.
3917 Upon return, *IDK will be filled in appropriately. */
3919 finish_id_expression_1 (tree id_expression
,
3923 bool integral_constant_expression_p
,
3924 bool allow_non_integral_constant_expression_p
,
3925 bool *non_integral_constant_expression_p
,
3929 bool template_arg_p
,
3930 const char **error_msg
,
3931 location_t location
)
3933 decl
= strip_using_decl (decl
);
3935 /* Initialize the output parameters. */
3936 *idk
= CP_ID_KIND_NONE
;
3939 if (id_expression
== error_mark_node
)
3940 return error_mark_node
;
3941 /* If we have a template-id, then no further lookup is
3942 required. If the template-id was for a template-class, we
3943 will sometimes have a TYPE_DECL at this point. */
3944 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
3945 || TREE_CODE (decl
) == TYPE_DECL
)
3947 /* Look up the name. */
3950 if (decl
== error_mark_node
)
3952 /* Name lookup failed. */
3955 || (!dependent_type_p (scope
)
3956 && !(identifier_p (id_expression
)
3957 && IDENTIFIER_CONV_OP_P (id_expression
)
3958 && dependent_type_p (TREE_TYPE (id_expression
))))))
3960 /* If the qualifying type is non-dependent (and the name
3961 does not name a conversion operator to a dependent
3962 type), issue an error. */
3963 qualified_name_lookup_error (scope
, id_expression
, decl
, location
);
3964 return error_mark_node
;
3968 /* It may be resolved via Koenig lookup. */
3969 *idk
= CP_ID_KIND_UNQUALIFIED
;
3970 return id_expression
;
3973 decl
= id_expression
;
3976 /* Remember that the name was used in the definition of
3977 the current class so that we can check later to see if
3978 the meaning would have been different after the class
3979 was entirely defined. */
3980 if (!scope
&& decl
!= error_mark_node
&& identifier_p (id_expression
))
3981 maybe_note_name_used_in_class (id_expression
, decl
);
3983 /* A use in unevaluated operand might not be instantiated appropriately
3984 if tsubst_copy builds a dummy parm, or if we never instantiate a
3985 generic lambda, so mark it now. */
3986 if (processing_template_decl
&& cp_unevaluated_operand
)
3987 mark_type_use (decl
);
3989 /* Disallow uses of local variables from containing functions, except
3990 within lambda-expressions. */
3991 if (outer_automatic_var_p (decl
))
3993 decl
= process_outer_var_ref (decl
, tf_warning_or_error
);
3994 if (decl
== error_mark_node
)
3995 return error_mark_node
;
3998 /* Also disallow uses of function parameters outside the function
3999 body, except inside an unevaluated context (i.e. decltype). */
4000 if (TREE_CODE (decl
) == PARM_DECL
4001 && DECL_CONTEXT (decl
) == NULL_TREE
4002 && !cp_unevaluated_operand
)
4004 *error_msg
= G_("use of parameter outside function body");
4005 return error_mark_node
;
4009 /* If we didn't find anything, or what we found was a type,
4010 then this wasn't really an id-expression. */
4011 if (TREE_CODE (decl
) == TEMPLATE_DECL
4012 && !DECL_FUNCTION_TEMPLATE_P (decl
))
4014 *error_msg
= G_("missing template arguments");
4015 return error_mark_node
;
4017 else if (TREE_CODE (decl
) == TYPE_DECL
4018 || TREE_CODE (decl
) == NAMESPACE_DECL
)
4020 *error_msg
= G_("expected primary-expression");
4021 return error_mark_node
;
4024 /* If the name resolved to a template parameter, there is no
4025 need to look it up again later. */
4026 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
4027 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
4031 *idk
= CP_ID_KIND_NONE
;
4032 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
4033 decl
= TEMPLATE_PARM_DECL (decl
);
4034 r
= DECL_INITIAL (decl
);
4035 if (CLASS_TYPE_P (TREE_TYPE (r
)) && !CP_TYPE_CONST_P (TREE_TYPE (r
)))
4037 /* If the entity is a template parameter object for a template
4038 parameter of type T, the type of the expression is const T. */
4039 tree ctype
= TREE_TYPE (r
);
4040 ctype
= cp_build_qualified_type (ctype
, (cp_type_quals (ctype
)
4041 | TYPE_QUAL_CONST
));
4042 r
= build1 (VIEW_CONVERT_EXPR
, ctype
, r
);
4044 r
= convert_from_reference (r
);
4045 if (integral_constant_expression_p
4046 && !dependent_type_p (TREE_TYPE (decl
))
4047 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
4049 if (!allow_non_integral_constant_expression_p
)
4050 error ("template parameter %qD of type %qT is not allowed in "
4051 "an integral constant expression because it is not of "
4052 "integral or enumeration type", decl
, TREE_TYPE (decl
));
4053 *non_integral_constant_expression_p
= true;
4059 bool dependent_p
= type_dependent_expression_p (decl
);
4061 /* If the declaration was explicitly qualified indicate
4062 that. The semantics of `A::f(3)' are different than
4063 `f(3)' if `f' is virtual. */
4065 ? CP_ID_KIND_QUALIFIED
4066 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
4067 ? CP_ID_KIND_TEMPLATE_ID
4069 ? CP_ID_KIND_UNQUALIFIED_DEPENDENT
4070 : CP_ID_KIND_UNQUALIFIED
)));
4074 && any_dependent_type_attributes_p (DECL_ATTRIBUTES (decl
)))
4075 /* Dependent type attributes on the decl mean that the TREE_TYPE is
4076 wrong, so just return the identifier. */
4077 return id_expression
;
4079 if (DECL_CLASS_TEMPLATE_P (decl
))
4081 error ("use of class template %qT as expression", decl
);
4082 return error_mark_node
;
4085 if (TREE_CODE (decl
) == TREE_LIST
)
4087 /* Ambiguous reference to base members. */
4088 error ("request for member %qD is ambiguous in "
4089 "multiple inheritance lattice", id_expression
);
4090 print_candidates (decl
);
4091 return error_mark_node
;
4094 /* Mark variable-like entities as used. Functions are similarly
4095 marked either below or after overload resolution. */
4097 || TREE_CODE (decl
) == PARM_DECL
4098 || TREE_CODE (decl
) == CONST_DECL
4099 || TREE_CODE (decl
) == RESULT_DECL
)
4100 && !mark_used (decl
))
4101 return error_mark_node
;
4103 /* Only certain kinds of names are allowed in constant
4104 expression. Template parameters have already
4105 been handled above. */
4106 if (! error_operand_p (decl
)
4108 && integral_constant_expression_p
4109 && !decl_constant_var_p (decl
)
4110 && TREE_CODE (decl
) != CONST_DECL
4111 && !builtin_valid_in_constant_expr_p (decl
)
4112 && !concept_check_p (decl
))
4114 if (!allow_non_integral_constant_expression_p
)
4116 error ("%qD cannot appear in a constant-expression", decl
);
4117 return error_mark_node
;
4119 *non_integral_constant_expression_p
= true;
4122 if (tree wrap
= maybe_get_tls_wrapper_call (decl
))
4123 /* Replace an evaluated use of the thread_local variable with
4124 a call to its wrapper. */
4126 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
4128 && variable_template_p (TREE_OPERAND (decl
, 0))
4129 && !concept_check_p (decl
))
4131 decl
= finish_template_variable (decl
);
4133 decl
= convert_from_reference (decl
);
4135 else if (concept_check_p (decl
))
4137 /* Nothing more to do. All of the analysis for concept checks
4138 is done by build_conept_id, called from the parser. */
4142 if (TREE_CODE (decl
) == SCOPE_REF
)
4144 gcc_assert (same_type_p (scope
, TREE_OPERAND (decl
, 0)));
4145 decl
= TREE_OPERAND (decl
, 1);
4148 decl
= (adjust_result_of_qualified_name_lookup
4149 (decl
, scope
, current_nonlambda_class_type()));
4151 if (TREE_CODE (decl
) == FUNCTION_DECL
)
4154 cp_warn_deprecated_use_scopes (scope
);
4157 decl
= finish_qualified_id_expr (scope
,
4163 tf_warning_or_error
);
4165 decl
= convert_from_reference (decl
);
4167 else if (TREE_CODE (decl
) == FIELD_DECL
)
4169 /* Since SCOPE is NULL here, this is an unqualified name.
4170 Access checking has been performed during name lookup
4171 already. Turn off checking to avoid duplicate errors. */
4172 push_deferring_access_checks (dk_no_check
);
4173 decl
= finish_non_static_data_member (decl
, NULL_TREE
,
4174 /*qualifying_scope=*/NULL_TREE
);
4175 pop_deferring_access_checks ();
4177 else if (is_overloaded_fn (decl
))
4179 /* We only need to look at the first function,
4180 because all the fns share the attribute we're
4181 concerned with (all member fns or all non-members). */
4182 tree first_fn
= get_first_fn (decl
);
4183 first_fn
= STRIP_TEMPLATE (first_fn
);
4185 /* [basic.def.odr]: "A function whose name appears as a
4186 potentially-evaluated expression is odr-used if it is the unique
4189 But only mark it if it's a complete postfix-expression; in a call,
4190 ADL might select a different function, and we'll call mark_used in
4193 && !really_overloaded_fn (decl
)
4194 && !mark_used (first_fn
))
4195 return error_mark_node
;
4198 && (TREE_CODE (first_fn
) == USING_DECL
4199 || (TREE_CODE (first_fn
) == FUNCTION_DECL
4200 && DECL_FUNCTION_MEMBER_P (first_fn
)
4201 && !shared_member_p (decl
))))
4203 /* A set of member functions. */
4204 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
4205 return finish_class_member_access_expr (decl
, id_expression
,
4206 /*template_p=*/false,
4207 tf_warning_or_error
);
4210 decl
= baselink_for_fns (decl
);
4214 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
4215 && DECL_CLASS_SCOPE_P (decl
))
4217 tree context
= context_for_name_lookup (decl
);
4218 if (context
!= current_class_type
)
4220 tree path
= currently_open_derived_class (context
);
4222 /* PATH can be null for using an enum of an unrelated
4223 class; we checked its access in lookup_using_decl.
4225 ??? Should this case make a clone instead, like
4226 handle_using_decl? */
4227 gcc_assert (TREE_CODE (decl
) == CONST_DECL
);
4229 perform_or_defer_access_check (TYPE_BINFO (path
),
4231 tf_warning_or_error
);
4235 decl
= convert_from_reference (decl
);
4239 return cp_expr (decl
, location
);
4242 /* As per finish_id_expression_1, but adding a wrapper node
4243 around the result if needed to express LOCATION. */
4246 finish_id_expression (tree id_expression
,
4250 bool integral_constant_expression_p
,
4251 bool allow_non_integral_constant_expression_p
,
4252 bool *non_integral_constant_expression_p
,
4256 bool template_arg_p
,
4257 const char **error_msg
,
4258 location_t location
)
4261 = finish_id_expression_1 (id_expression
, decl
, scope
, idk
,
4262 integral_constant_expression_p
,
4263 allow_non_integral_constant_expression_p
,
4264 non_integral_constant_expression_p
,
4265 template_p
, done
, address_p
, template_arg_p
,
4266 error_msg
, location
);
4267 return result
.maybe_add_location_wrapper ();
4270 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
4271 use as a type-specifier. */
4274 finish_typeof (tree expr
)
4278 if (type_dependent_expression_p (expr
))
4280 type
= cxx_make_type (TYPEOF_TYPE
);
4281 TYPEOF_TYPE_EXPR (type
) = expr
;
4282 SET_TYPE_STRUCTURAL_EQUALITY (type
);
4287 expr
= mark_type_use (expr
);
4289 type
= unlowered_expr_type (expr
);
4291 if (!type
|| type
== unknown_type_node
)
4293 error ("type of %qE is unknown", expr
);
4294 return error_mark_node
;
4300 /* Implement the __underlying_type keyword: Return the underlying
4301 type of TYPE, suitable for use as a type-specifier. */
4304 finish_underlying_type (tree type
)
4306 tree underlying_type
;
4308 if (processing_template_decl
)
4310 underlying_type
= cxx_make_type (UNDERLYING_TYPE
);
4311 UNDERLYING_TYPE_TYPE (underlying_type
) = type
;
4312 SET_TYPE_STRUCTURAL_EQUALITY (underlying_type
);
4314 return underlying_type
;
4317 if (!complete_type_or_else (type
, NULL_TREE
))
4318 return error_mark_node
;
4320 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
4322 error ("%qT is not an enumeration type", type
);
4323 return error_mark_node
;
4326 underlying_type
= ENUM_UNDERLYING_TYPE (type
);
4328 /* Fixup necessary in this case because ENUM_UNDERLYING_TYPE
4329 includes TYPE_MIN_VALUE and TYPE_MAX_VALUE information.
4330 See finish_enum_value_list for details. */
4331 if (!ENUM_FIXED_UNDERLYING_TYPE_P (type
))
4333 = c_common_type_for_mode (TYPE_MODE (underlying_type
),
4334 TYPE_UNSIGNED (underlying_type
));
4336 return underlying_type
;
4339 /* Implement the __direct_bases keyword: Return the direct base classes
4343 calculate_direct_bases (tree type
, tsubst_flags_t complain
)
4345 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4346 || !NON_UNION_CLASS_TYPE_P (type
))
4347 return make_tree_vec (0);
4349 releasing_vec vector
;
4350 vec
<tree
, va_gc
> *base_binfos
= BINFO_BASE_BINFOS (TYPE_BINFO (type
));
4354 /* Virtual bases are initialized first */
4355 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4356 if (BINFO_VIRTUAL_P (binfo
))
4357 vec_safe_push (vector
, binfo
);
4359 /* Now non-virtuals */
4360 for (i
= 0; base_binfos
->iterate (i
, &binfo
); i
++)
4361 if (!BINFO_VIRTUAL_P (binfo
))
4362 vec_safe_push (vector
, binfo
);
4364 tree bases_vec
= make_tree_vec (vector
->length ());
4366 for (i
= 0; i
< vector
->length (); ++i
)
4367 TREE_VEC_ELT (bases_vec
, i
) = BINFO_TYPE ((*vector
)[i
]);
4372 /* Implement the __bases keyword: Return the base classes
4375 /* Find morally non-virtual base classes by walking binfo hierarchy */
4376 /* Virtual base classes are handled separately in finish_bases */
4379 dfs_calculate_bases_pre (tree binfo
, void * /*data_*/)
4381 /* Don't walk bases of virtual bases */
4382 return BINFO_VIRTUAL_P (binfo
) ? dfs_skip_bases
: NULL_TREE
;
4386 dfs_calculate_bases_post (tree binfo
, void *data_
)
4388 vec
<tree
, va_gc
> **data
= ((vec
<tree
, va_gc
> **) data_
);
4389 if (!BINFO_VIRTUAL_P (binfo
))
4390 vec_safe_push (*data
, BINFO_TYPE (binfo
));
4394 /* Calculates the morally non-virtual base classes of a class */
4395 static vec
<tree
, va_gc
> *
4396 calculate_bases_helper (tree type
)
4398 vec
<tree
, va_gc
> *vector
= make_tree_vector ();
4400 /* Now add non-virtual base classes in order of construction */
4401 if (TYPE_BINFO (type
))
4402 dfs_walk_all (TYPE_BINFO (type
),
4403 dfs_calculate_bases_pre
, dfs_calculate_bases_post
, &vector
);
4408 calculate_bases (tree type
, tsubst_flags_t complain
)
4410 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
)
4411 || !NON_UNION_CLASS_TYPE_P (type
))
4412 return make_tree_vec (0);
4414 releasing_vec vector
;
4415 tree bases_vec
= NULL_TREE
;
4417 vec
<tree
, va_gc
> *vbases
;
4420 /* First go through virtual base classes */
4421 for (vbases
= CLASSTYPE_VBASECLASSES (type
), i
= 0;
4422 vec_safe_iterate (vbases
, i
, &binfo
); i
++)
4424 releasing_vec vbase_bases
4425 = calculate_bases_helper (BINFO_TYPE (binfo
));
4426 vec_safe_splice (vector
, vbase_bases
);
4429 /* Now for the non-virtual bases */
4430 releasing_vec nonvbases
= calculate_bases_helper (type
);
4431 vec_safe_splice (vector
, nonvbases
);
4433 /* Note that during error recovery vector->length can even be zero. */
4434 if (vector
->length () > 1)
4436 /* Last element is entire class, so don't copy */
4437 bases_vec
= make_tree_vec (vector
->length () - 1);
4439 for (i
= 0; i
< vector
->length () - 1; ++i
)
4440 TREE_VEC_ELT (bases_vec
, i
) = (*vector
)[i
];
4443 bases_vec
= make_tree_vec (0);
4449 finish_bases (tree type
, bool direct
)
4451 tree bases
= NULL_TREE
;
4453 if (!processing_template_decl
)
4455 /* Parameter packs can only be used in templates */
4456 error ("parameter pack %<__bases%> only valid in template declaration");
4457 return error_mark_node
;
4460 bases
= cxx_make_type (BASES
);
4461 BASES_TYPE (bases
) = type
;
4462 BASES_DIRECT (bases
) = direct
;
4463 SET_TYPE_STRUCTURAL_EQUALITY (bases
);
4468 /* Perform C++-specific checks for __builtin_offsetof before calling
4472 finish_offsetof (tree object_ptr
, tree expr
, location_t loc
)
4474 /* If we're processing a template, we can't finish the semantics yet.
4475 Otherwise we can fold the entire expression now. */
4476 if (processing_template_decl
)
4478 expr
= build2 (OFFSETOF_EXPR
, size_type_node
, expr
, object_ptr
);
4479 SET_EXPR_LOCATION (expr
, loc
);
4483 if (expr
== error_mark_node
)
4484 return error_mark_node
;
4486 if (TREE_CODE (expr
) == PSEUDO_DTOR_EXPR
)
4488 error ("cannot apply %<offsetof%> to destructor %<~%T%>",
4489 TREE_OPERAND (expr
, 2));
4490 return error_mark_node
;
4492 if (FUNC_OR_METHOD_TYPE_P (TREE_TYPE (expr
))
4493 || TREE_TYPE (expr
) == unknown_type_node
)
4495 while (TREE_CODE (expr
) == COMPONENT_REF
4496 || TREE_CODE (expr
) == COMPOUND_EXPR
)
4497 expr
= TREE_OPERAND (expr
, 1);
4501 error ("cannot apply %<offsetof%> to member function %qD", expr
);
4502 inform (DECL_SOURCE_LOCATION (expr
), "declared here");
4505 error ("cannot apply %<offsetof%> to member function");
4506 return error_mark_node
;
4508 if (TREE_CODE (expr
) == CONST_DECL
)
4510 error ("cannot apply %<offsetof%> to an enumerator %qD", expr
);
4511 return error_mark_node
;
4513 if (REFERENCE_REF_P (expr
))
4514 expr
= TREE_OPERAND (expr
, 0);
4515 if (!complete_type_or_else (TREE_TYPE (TREE_TYPE (object_ptr
)), object_ptr
))
4516 return error_mark_node
;
4517 if (warn_invalid_offsetof
4518 && CLASS_TYPE_P (TREE_TYPE (TREE_TYPE (object_ptr
)))
4519 && CLASSTYPE_NON_STD_LAYOUT (TREE_TYPE (TREE_TYPE (object_ptr
)))
4520 && cp_unevaluated_operand
== 0)
4521 warning_at (loc
, OPT_Winvalid_offsetof
, "%<offsetof%> within "
4522 "non-standard-layout type %qT is conditionally-supported",
4523 TREE_TYPE (TREE_TYPE (object_ptr
)));
4524 return fold_offsetof (expr
);
4527 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
4528 function is broken out from the above for the benefit of the tree-ssa
4532 simplify_aggr_init_expr (tree
*tp
)
4534 tree aggr_init_expr
= *tp
;
4536 /* Form an appropriate CALL_EXPR. */
4537 tree fn
= AGGR_INIT_EXPR_FN (aggr_init_expr
);
4538 tree slot
= AGGR_INIT_EXPR_SLOT (aggr_init_expr
);
4539 tree type
= TREE_TYPE (slot
);
4542 enum style_t
{ ctor
, arg
, pcc
} style
;
4544 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
4546 #ifdef PCC_STATIC_STRUCT_RETURN
4552 gcc_assert (TREE_ADDRESSABLE (type
));
4556 call_expr
= build_call_array_loc (input_location
,
4557 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
4559 aggr_init_expr_nargs (aggr_init_expr
),
4560 AGGR_INIT_EXPR_ARGP (aggr_init_expr
));
4561 TREE_NOTHROW (call_expr
) = TREE_NOTHROW (aggr_init_expr
);
4562 CALL_FROM_THUNK_P (call_expr
) = AGGR_INIT_FROM_THUNK_P (aggr_init_expr
);
4563 CALL_EXPR_OPERATOR_SYNTAX (call_expr
)
4564 = CALL_EXPR_OPERATOR_SYNTAX (aggr_init_expr
);
4565 CALL_EXPR_ORDERED_ARGS (call_expr
) = CALL_EXPR_ORDERED_ARGS (aggr_init_expr
);
4566 CALL_EXPR_REVERSE_ARGS (call_expr
) = CALL_EXPR_REVERSE_ARGS (aggr_init_expr
);
4570 /* Replace the first argument to the ctor with the address of the
4572 cxx_mark_addressable (slot
);
4573 CALL_EXPR_ARG (call_expr
, 0) =
4574 build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
4576 else if (style
== arg
)
4578 /* Just mark it addressable here, and leave the rest to
4579 expand_call{,_inline}. */
4580 cxx_mark_addressable (slot
);
4581 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
4582 call_expr
= build2 (INIT_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
4584 else if (style
== pcc
)
4586 /* If we're using the non-reentrant PCC calling convention, then we
4587 need to copy the returned value out of the static buffer into the
4589 push_deferring_access_checks (dk_no_check
);
4590 call_expr
= build_aggr_init (slot
, call_expr
,
4591 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
,
4592 tf_warning_or_error
);
4593 pop_deferring_access_checks ();
4594 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
4597 if (AGGR_INIT_ZERO_FIRST (aggr_init_expr
))
4599 tree init
= build_zero_init (type
, NULL_TREE
,
4600 /*static_storage_p=*/false);
4601 init
= build2 (INIT_EXPR
, void_type_node
, slot
, init
);
4602 call_expr
= build2 (COMPOUND_EXPR
, TREE_TYPE (call_expr
),
4609 /* Emit all thunks to FN that should be emitted when FN is emitted. */
4612 emit_associated_thunks (tree fn
)
4614 /* When we use vcall offsets, we emit thunks with the virtual
4615 functions to which they thunk. The whole point of vcall offsets
4616 is so that you can know statically the entire set of thunks that
4617 will ever be needed for a given virtual function, thereby
4618 enabling you to output all the thunks with the function itself. */
4619 if (DECL_VIRTUAL_P (fn
)
4620 /* Do not emit thunks for extern template instantiations. */
4621 && ! DECL_REALLY_EXTERN (fn
))
4625 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= DECL_CHAIN (thunk
))
4627 if (!THUNK_ALIAS (thunk
))
4629 use_thunk (thunk
, /*emit_p=*/1);
4630 if (DECL_RESULT_THUNK_P (thunk
))
4634 for (probe
= DECL_THUNKS (thunk
);
4635 probe
; probe
= DECL_CHAIN (probe
))
4636 use_thunk (probe
, /*emit_p=*/1);
4640 gcc_assert (!DECL_THUNKS (thunk
));
4645 /* Generate RTL for FN. */
4648 expand_or_defer_fn_1 (tree fn
)
4650 /* When the parser calls us after finishing the body of a template
4651 function, we don't really want to expand the body. */
4652 if (processing_template_decl
)
4654 /* Normally, collection only occurs in rest_of_compilation. So,
4655 if we don't collect here, we never collect junk generated
4656 during the processing of templates until we hit a
4657 non-template function. It's not safe to do this inside a
4658 nested class, though, as the parser may have local state that
4659 is not a GC root. */
4660 if (!function_depth
)
4665 gcc_assert (DECL_SAVED_TREE (fn
));
4667 /* We make a decision about linkage for these functions at the end
4668 of the compilation. Until that point, we do not want the back
4669 end to output them -- but we do want it to see the bodies of
4670 these functions so that it can inline them as appropriate. */
4671 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
4673 if (DECL_INTERFACE_KNOWN (fn
))
4674 /* We've already made a decision as to how this function will
4677 || DECL_IMMEDIATE_FUNCTION_P (fn
)
4678 || DECL_OMP_DECLARE_REDUCTION_P (fn
))
4679 tentative_decl_linkage (fn
);
4681 import_export_decl (fn
);
4683 /* If the user wants us to keep all inline functions, then mark
4684 this function as needed so that finish_file will make sure to
4685 output it later. Similarly, all dllexport'd functions must
4686 be emitted; there may be callers in other DLLs. */
4687 if (DECL_DECLARED_INLINE_P (fn
)
4688 && !DECL_REALLY_EXTERN (fn
)
4689 && !DECL_IMMEDIATE_FUNCTION_P (fn
)
4690 && !DECL_OMP_DECLARE_REDUCTION_P (fn
)
4691 && (flag_keep_inline_functions
4692 || (flag_keep_inline_dllexport
4693 && lookup_attribute ("dllexport", DECL_ATTRIBUTES (fn
)))))
4696 DECL_EXTERNAL (fn
) = 0;
4700 /* If this is a constructor or destructor body, we have to clone
4702 if (maybe_clone_body (fn
))
4704 /* We don't want to process FN again, so pretend we've written
4705 it out, even though we haven't. */
4706 TREE_ASM_WRITTEN (fn
) = 1;
4707 /* If this is a constexpr function, keep DECL_SAVED_TREE. */
4708 if (!DECL_DECLARED_CONSTEXPR_P (fn
)
4709 && !(modules_p () && DECL_DECLARED_INLINE_P (fn
)))
4710 DECL_SAVED_TREE (fn
) = NULL_TREE
;
4714 /* There's no reason to do any of the work here if we're only doing
4715 semantic analysis; this code just generates RTL. */
4716 if (flag_syntax_only
)
4718 /* Pretend that this function has been written out so that we don't try
4719 to expand it again. */
4720 TREE_ASM_WRITTEN (fn
) = 1;
4724 if (DECL_OMP_DECLARE_REDUCTION_P (fn
))
4731 expand_or_defer_fn (tree fn
)
4733 if (expand_or_defer_fn_1 (fn
))
4737 /* Expand or defer, at the whim of the compilation unit manager. */
4738 cgraph_node::finalize_function (fn
, function_depth
> 1);
4739 emit_associated_thunks (fn
);
4748 nrv_data () : visited (37) {}
4752 hash_table
<nofree_ptr_hash
<tree_node
> > visited
;
4755 /* Helper function for walk_tree, used by finalize_nrv below. */
4758 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
4760 class nrv_data
*dp
= (class nrv_data
*)data
;
4763 /* No need to walk into types. There wouldn't be any need to walk into
4764 non-statements, except that we have to consider STMT_EXPRs. */
4767 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
4768 but differs from using NULL_TREE in that it indicates that we care
4769 about the value of the RESULT_DECL. */
4770 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
4771 TREE_OPERAND (*tp
, 0) = dp
->result
;
4772 /* Change all cleanups for the NRV to only run when an exception is
4774 else if (TREE_CODE (*tp
) == CLEANUP_STMT
4775 && CLEANUP_DECL (*tp
) == dp
->var
)
4776 CLEANUP_EH_ONLY (*tp
) = 1;
4777 /* Replace the DECL_EXPR for the NRV with an initialization of the
4778 RESULT_DECL, if needed. */
4779 else if (TREE_CODE (*tp
) == DECL_EXPR
4780 && DECL_EXPR_DECL (*tp
) == dp
->var
)
4783 if (DECL_INITIAL (dp
->var
)
4784 && DECL_INITIAL (dp
->var
) != error_mark_node
)
4785 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
4786 DECL_INITIAL (dp
->var
));
4788 init
= build_empty_stmt (EXPR_LOCATION (*tp
));
4789 DECL_INITIAL (dp
->var
) = NULL_TREE
;
4790 SET_EXPR_LOCATION (init
, EXPR_LOCATION (*tp
));
4793 /* And replace all uses of the NRV with the RESULT_DECL. */
4794 else if (*tp
== dp
->var
)
4797 /* Avoid walking into the same tree more than once. Unfortunately, we
4798 can't just use walk_tree_without duplicates because it would only call
4799 us for the first occurrence of dp->var in the function body. */
4800 slot
= dp
->visited
.find_slot (*tp
, INSERT
);
4806 /* Keep iterating. */
4810 /* Called from finish_function to implement the named return value
4811 optimization by overriding all the RETURN_EXPRs and pertinent
4812 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
4813 RESULT_DECL for the function. */
4816 finalize_nrv (tree
*tp
, tree var
, tree result
)
4818 class nrv_data data
;
4820 /* Copy name from VAR to RESULT. */
4821 DECL_NAME (result
) = DECL_NAME (var
);
4822 /* Don't forget that we take its address. */
4823 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
4824 /* Finally set DECL_VALUE_EXPR to avoid assigning
4825 a stack slot at -O0 for the original var and debug info
4826 uses RESULT location for VAR. */
4827 SET_DECL_VALUE_EXPR (var
, result
);
4828 DECL_HAS_VALUE_EXPR_P (var
) = 1;
4831 data
.result
= result
;
4832 cp_walk_tree (tp
, finalize_nrv_r
, &data
, 0);
4835 /* Create CP_OMP_CLAUSE_INFO for clause C. Returns true if it is invalid. */
4838 cxx_omp_create_clause_info (tree c
, tree type
, bool need_default_ctor
,
4839 bool need_copy_ctor
, bool need_copy_assignment
,
4842 int save_errorcount
= errorcount
;
4845 /* Always allocate 3 elements for simplicity. These are the
4846 function decls for the ctor, dtor, and assignment op.
4847 This layout is known to the three lang hooks,
4848 cxx_omp_clause_default_init, cxx_omp_clause_copy_init,
4849 and cxx_omp_clause_assign_op. */
4850 info
= make_tree_vec (3);
4851 CP_OMP_CLAUSE_INFO (c
) = info
;
4853 if (need_default_ctor
|| need_copy_ctor
)
4855 if (need_default_ctor
)
4856 t
= get_default_ctor (type
);
4858 t
= get_copy_ctor (type
, tf_warning_or_error
);
4860 if (t
&& !trivial_fn_p (t
))
4861 TREE_VEC_ELT (info
, 0) = t
;
4864 if (need_dtor
&& TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type
))
4865 TREE_VEC_ELT (info
, 1) = get_dtor (type
, tf_warning_or_error
);
4867 if (need_copy_assignment
)
4869 t
= get_copy_assign (type
);
4871 if (t
&& !trivial_fn_p (t
))
4872 TREE_VEC_ELT (info
, 2) = t
;
4875 return errorcount
!= save_errorcount
;
4878 /* If DECL is DECL_OMP_PRIVATIZED_MEMBER, return corresponding
4879 FIELD_DECL, otherwise return DECL itself. */
4882 omp_clause_decl_field (tree decl
)
4885 && DECL_HAS_VALUE_EXPR_P (decl
)
4886 && DECL_ARTIFICIAL (decl
)
4887 && DECL_LANG_SPECIFIC (decl
)
4888 && DECL_OMP_PRIVATIZED_MEMBER (decl
))
4890 tree f
= DECL_VALUE_EXPR (decl
);
4891 if (INDIRECT_REF_P (f
))
4892 f
= TREE_OPERAND (f
, 0);
4893 if (TREE_CODE (f
) == COMPONENT_REF
)
4895 f
= TREE_OPERAND (f
, 1);
4896 gcc_assert (TREE_CODE (f
) == FIELD_DECL
);
4903 /* Adjust DECL if needed for printing using %qE. */
4906 omp_clause_printable_decl (tree decl
)
4908 tree t
= omp_clause_decl_field (decl
);
4914 /* For a FIELD_DECL F and corresponding DECL_OMP_PRIVATIZED_MEMBER
4915 VAR_DECL T that doesn't need a DECL_EXPR added, record it for
4919 omp_note_field_privatization (tree f
, tree t
)
4921 if (!omp_private_member_map
)
4922 omp_private_member_map
= new hash_map
<tree
, tree
>;
4923 tree
&v
= omp_private_member_map
->get_or_insert (f
);
4927 omp_private_member_vec
.safe_push (f
);
4928 /* Signal that we don't want to create DECL_EXPR for this dummy var. */
4929 omp_private_member_vec
.safe_push (integer_zero_node
);
4933 /* Privatize FIELD_DECL T, return corresponding DECL_OMP_PRIVATIZED_MEMBER
4937 omp_privatize_field (tree t
, bool shared
)
4939 tree m
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
4940 if (m
== error_mark_node
)
4941 return error_mark_node
;
4942 if (!omp_private_member_map
&& !shared
)
4943 omp_private_member_map
= new hash_map
<tree
, tree
>;
4944 if (TYPE_REF_P (TREE_TYPE (t
)))
4946 gcc_assert (INDIRECT_REF_P (m
));
4947 m
= TREE_OPERAND (m
, 0);
4949 tree vb
= NULL_TREE
;
4950 tree
&v
= shared
? vb
: omp_private_member_map
->get_or_insert (t
);
4953 v
= create_temporary_var (TREE_TYPE (m
));
4954 retrofit_lang_decl (v
);
4955 DECL_OMP_PRIVATIZED_MEMBER (v
) = 1;
4956 SET_DECL_VALUE_EXPR (v
, m
);
4957 DECL_HAS_VALUE_EXPR_P (v
) = 1;
4959 omp_private_member_vec
.safe_push (t
);
4964 /* Helper function for handle_omp_array_sections. Called recursively
4965 to handle multiple array-section-subscripts. C is the clause,
4966 T current expression (initially OMP_CLAUSE_DECL), which is either
4967 a TREE_LIST for array-section-subscript (TREE_PURPOSE is low-bound
4968 expression if specified, TREE_VALUE length expression if specified,
4969 TREE_CHAIN is what it has been specified after, or some decl.
4970 TYPES vector is populated with array section types, MAYBE_ZERO_LEN
4971 set to true if any of the array-section-subscript could have length
4972 of zero (explicit or implicit), FIRST_NON_ONE is the index of the
4973 first array-section-subscript which is known not to have length
4975 map(a[:b][2:1][:c][:2][:d][e:f][2:5])
4976 FIRST_NON_ONE will be 3, array-section-subscript [:b], [2:1] and [:c]
4977 all are or may have length of 1, array-section-subscript [:2] is the
4978 first one known not to have length 1. For array-section-subscript
4979 <= FIRST_NON_ONE we diagnose non-contiguous arrays if low bound isn't
4980 0 or length isn't the array domain max + 1, for > FIRST_NON_ONE we
4981 can if MAYBE_ZERO_LEN is false. MAYBE_ZERO_LEN will be true in the above
4982 case though, as some lengths could be zero. */
4985 handle_omp_array_sections_1 (tree c
, tree t
, vec
<tree
> &types
,
4986 bool &maybe_zero_len
, unsigned int &first_non_one
,
4987 enum c_omp_region_type ort
)
4989 tree ret
, low_bound
, length
, type
;
4990 if (TREE_CODE (t
) != TREE_LIST
)
4992 if (error_operand_p (t
))
4993 return error_mark_node
;
4994 if (REFERENCE_REF_P (t
)
4995 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
4996 t
= TREE_OPERAND (t
, 0);
4998 if (TREE_CODE (t
) == COMPONENT_REF
4999 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5000 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO
5001 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FROM
)
5002 && !type_dependent_expression_p (t
))
5004 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
5005 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
5007 error_at (OMP_CLAUSE_LOCATION (c
),
5008 "bit-field %qE in %qs clause",
5009 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5010 return error_mark_node
;
5012 while (TREE_CODE (t
) == COMPONENT_REF
)
5014 if (TREE_TYPE (TREE_OPERAND (t
, 0))
5015 && TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0))) == UNION_TYPE
)
5017 error_at (OMP_CLAUSE_LOCATION (c
),
5018 "%qE is a member of a union", t
);
5019 return error_mark_node
;
5021 t
= TREE_OPERAND (t
, 0);
5022 if (ort
== C_ORT_ACC
&& TREE_CODE (t
) == INDIRECT_REF
)
5023 t
= TREE_OPERAND (t
, 0);
5025 if (REFERENCE_REF_P (t
))
5026 t
= TREE_OPERAND (t
, 0);
5028 if (TREE_CODE (t
) == FIELD_DECL
5029 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
5030 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
))
5031 ret
= finish_non_static_data_member (t
, NULL_TREE
, NULL_TREE
);
5032 else if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
5034 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
5037 error_at (OMP_CLAUSE_LOCATION (c
),
5038 "%qD is not a variable in %qs clause", t
,
5039 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5041 error_at (OMP_CLAUSE_LOCATION (c
),
5042 "%qE is not a variable in %qs clause", t
,
5043 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5044 return error_mark_node
;
5046 else if ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
5047 && TREE_CODE (t
) == PARM_DECL
5048 && DECL_ARTIFICIAL (t
)
5049 && DECL_NAME (t
) == this_identifier
5050 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5051 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5053 error_at (OMP_CLAUSE_LOCATION (c
),
5054 "%<this%> allowed in OpenMP only in %<declare simd%>"
5056 return error_mark_node
;
5058 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5059 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5060 && VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
5062 error_at (OMP_CLAUSE_LOCATION (c
),
5063 "%qD is threadprivate variable in %qs clause", t
,
5064 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5065 return error_mark_node
;
5067 if (type_dependent_expression_p (ret
))
5069 ret
= convert_from_reference (ret
);
5073 if ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
5074 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5075 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5076 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5077 && TREE_CODE (TREE_CHAIN (t
)) == FIELD_DECL
)
5078 TREE_CHAIN (t
) = omp_privatize_field (TREE_CHAIN (t
), false);
5079 ret
= handle_omp_array_sections_1 (c
, TREE_CHAIN (t
), types
,
5080 maybe_zero_len
, first_non_one
, ort
);
5081 if (ret
== error_mark_node
|| ret
== NULL_TREE
)
5084 type
= TREE_TYPE (ret
);
5085 low_bound
= TREE_PURPOSE (t
);
5086 length
= TREE_VALUE (t
);
5087 if ((low_bound
&& type_dependent_expression_p (low_bound
))
5088 || (length
&& type_dependent_expression_p (length
)))
5091 if (low_bound
== error_mark_node
|| length
== error_mark_node
)
5092 return error_mark_node
;
5094 if (low_bound
&& !INTEGRAL_TYPE_P (TREE_TYPE (low_bound
)))
5096 error_at (OMP_CLAUSE_LOCATION (c
),
5097 "low bound %qE of array section does not have integral type",
5099 return error_mark_node
;
5101 if (length
&& !INTEGRAL_TYPE_P (TREE_TYPE (length
)))
5103 error_at (OMP_CLAUSE_LOCATION (c
),
5104 "length %qE of array section does not have integral type",
5106 return error_mark_node
;
5109 low_bound
= mark_rvalue_use (low_bound
);
5111 length
= mark_rvalue_use (length
);
5112 /* We need to reduce to real constant-values for checks below. */
5114 length
= fold_simple (length
);
5116 low_bound
= fold_simple (low_bound
);
5118 && TREE_CODE (low_bound
) == INTEGER_CST
5119 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5120 > TYPE_PRECISION (sizetype
))
5121 low_bound
= fold_convert (sizetype
, low_bound
);
5123 && TREE_CODE (length
) == INTEGER_CST
5124 && TYPE_PRECISION (TREE_TYPE (length
))
5125 > TYPE_PRECISION (sizetype
))
5126 length
= fold_convert (sizetype
, length
);
5127 if (low_bound
== NULL_TREE
)
5128 low_bound
= integer_zero_node
;
5130 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
5131 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
5132 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
5134 if (length
!= integer_one_node
)
5136 error_at (OMP_CLAUSE_LOCATION (c
),
5137 "expected single pointer in %qs clause",
5138 c_omp_map_clause_name (c
, ort
== C_ORT_ACC
));
5139 return error_mark_node
;
5142 if (length
!= NULL_TREE
)
5144 if (!integer_nonzerop (length
))
5146 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
5147 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5148 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5149 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5150 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5152 if (integer_zerop (length
))
5154 error_at (OMP_CLAUSE_LOCATION (c
),
5155 "zero length array section in %qs clause",
5156 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5157 return error_mark_node
;
5161 maybe_zero_len
= true;
5163 if (first_non_one
== types
.length ()
5164 && (TREE_CODE (length
) != INTEGER_CST
|| integer_onep (length
)))
5167 if (TREE_CODE (type
) == ARRAY_TYPE
)
5169 if (length
== NULL_TREE
5170 && (TYPE_DOMAIN (type
) == NULL_TREE
5171 || TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) == NULL_TREE
))
5173 error_at (OMP_CLAUSE_LOCATION (c
),
5174 "for unknown bound array type length expression must "
5176 return error_mark_node
;
5178 if (TREE_CODE (low_bound
) == INTEGER_CST
5179 && tree_int_cst_sgn (low_bound
) == -1)
5181 error_at (OMP_CLAUSE_LOCATION (c
),
5182 "negative low bound in array section in %qs clause",
5183 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5184 return error_mark_node
;
5186 if (length
!= NULL_TREE
5187 && TREE_CODE (length
) == INTEGER_CST
5188 && tree_int_cst_sgn (length
) == -1)
5190 error_at (OMP_CLAUSE_LOCATION (c
),
5191 "negative length in array section in %qs clause",
5192 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5193 return error_mark_node
;
5195 if (TYPE_DOMAIN (type
)
5196 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
))
5197 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)))
5201 = fold_convert (sizetype
, TYPE_MAX_VALUE (TYPE_DOMAIN (type
)));
5202 size
= size_binop (PLUS_EXPR
, size
, size_one_node
);
5203 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5205 if (tree_int_cst_lt (size
, low_bound
))
5207 error_at (OMP_CLAUSE_LOCATION (c
),
5208 "low bound %qE above array section size "
5209 "in %qs clause", low_bound
,
5210 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5211 return error_mark_node
;
5213 if (tree_int_cst_equal (size
, low_bound
))
5215 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
5216 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5217 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5218 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5219 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5221 error_at (OMP_CLAUSE_LOCATION (c
),
5222 "zero length array section in %qs clause",
5223 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5224 return error_mark_node
;
5226 maybe_zero_len
= true;
5228 else if (length
== NULL_TREE
5229 && first_non_one
== types
.length ()
5230 && tree_int_cst_equal
5231 (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)),
5235 else if (length
== NULL_TREE
)
5237 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5238 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5239 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5240 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5241 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5242 maybe_zero_len
= true;
5243 if (first_non_one
== types
.length ())
5246 if (length
&& TREE_CODE (length
) == INTEGER_CST
)
5248 if (tree_int_cst_lt (size
, length
))
5250 error_at (OMP_CLAUSE_LOCATION (c
),
5251 "length %qE above array section size "
5252 "in %qs clause", length
,
5253 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5254 return error_mark_node
;
5256 if (TREE_CODE (low_bound
) == INTEGER_CST
)
5259 = size_binop (PLUS_EXPR
,
5260 fold_convert (sizetype
, low_bound
),
5261 fold_convert (sizetype
, length
));
5262 if (TREE_CODE (lbpluslen
) == INTEGER_CST
5263 && tree_int_cst_lt (size
, lbpluslen
))
5265 error_at (OMP_CLAUSE_LOCATION (c
),
5266 "high bound %qE above array section size "
5267 "in %qs clause", lbpluslen
,
5268 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5269 return error_mark_node
;
5274 else if (length
== NULL_TREE
)
5276 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5277 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5278 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_REDUCTION
5279 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_IN_REDUCTION
5280 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_TASK_REDUCTION
)
5281 maybe_zero_len
= true;
5282 if (first_non_one
== types
.length ())
5286 /* For [lb:] we will need to evaluate lb more than once. */
5287 if (length
== NULL_TREE
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5289 tree lb
= cp_save_expr (low_bound
);
5290 if (lb
!= low_bound
)
5292 TREE_PURPOSE (t
) = lb
;
5297 else if (TYPE_PTR_P (type
))
5299 if (length
== NULL_TREE
)
5301 if (TREE_CODE (ret
) == PARM_DECL
&& DECL_ARRAY_PARAMETER_P (ret
))
5302 error_at (OMP_CLAUSE_LOCATION (c
),
5303 "for array function parameter length expression "
5304 "must be specified");
5306 error_at (OMP_CLAUSE_LOCATION (c
),
5307 "for pointer type length expression must be specified");
5308 return error_mark_node
;
5310 if (length
!= NULL_TREE
5311 && TREE_CODE (length
) == INTEGER_CST
5312 && tree_int_cst_sgn (length
) == -1)
5314 error_at (OMP_CLAUSE_LOCATION (c
),
5315 "negative length in array section in %qs clause",
5316 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5317 return error_mark_node
;
5319 /* If there is a pointer type anywhere but in the very first
5320 array-section-subscript, the array section can't be contiguous. */
5321 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_AFFINITY
5322 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
5323 && TREE_CODE (TREE_CHAIN (t
)) == TREE_LIST
)
5325 error_at (OMP_CLAUSE_LOCATION (c
),
5326 "array section is not contiguous in %qs clause",
5327 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5328 return error_mark_node
;
5333 error_at (OMP_CLAUSE_LOCATION (c
),
5334 "%qE does not have pointer or array type", ret
);
5335 return error_mark_node
;
5337 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_DEPEND
)
5338 types
.safe_push (TREE_TYPE (ret
));
5339 /* We will need to evaluate lb more than once. */
5340 tree lb
= cp_save_expr (low_bound
);
5341 if (lb
!= low_bound
)
5343 TREE_PURPOSE (t
) = lb
;
5346 /* Temporarily disable -fstrong-eval-order for array reductions.
5347 The SAVE_EXPR and COMPOUND_EXPR added if low_bound has side-effects
5348 is something the middle-end can't cope with and more importantly,
5349 it needs to be the actual base variable that is privatized, not some
5350 temporary assigned previous value of it. That, together with OpenMP
5351 saying how many times the side-effects are evaluated is unspecified,
5352 makes int *a, *b; ... reduction(+:a[a = b, 3:10]) really unspecified. */
5353 warning_sentinel
s (flag_strong_eval_order
,
5354 OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5355 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5356 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
);
5357 ret
= grok_array_decl (OMP_CLAUSE_LOCATION (c
), ret
, low_bound
, false);
5361 /* Handle array sections for clause C. */
5364 handle_omp_array_sections (tree c
, enum c_omp_region_type ort
)
5366 bool maybe_zero_len
= false;
5367 unsigned int first_non_one
= 0;
5368 auto_vec
<tree
, 10> types
;
5369 tree
*tp
= &OMP_CLAUSE_DECL (c
);
5370 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5371 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
)
5372 && TREE_CODE (*tp
) == TREE_LIST
5373 && TREE_PURPOSE (*tp
)
5374 && TREE_CODE (TREE_PURPOSE (*tp
)) == TREE_VEC
)
5375 tp
= &TREE_VALUE (*tp
);
5376 tree first
= handle_omp_array_sections_1 (c
, *tp
, types
,
5377 maybe_zero_len
, first_non_one
,
5379 if (first
== error_mark_node
)
5381 if (first
== NULL_TREE
)
5383 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
5384 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_AFFINITY
)
5387 tree tem
= NULL_TREE
;
5388 if (processing_template_decl
)
5390 /* Need to evaluate side effects in the length expressions
5392 while (TREE_CODE (t
) == TREE_LIST
)
5394 if (TREE_VALUE (t
) && TREE_SIDE_EFFECTS (TREE_VALUE (t
)))
5396 if (tem
== NULL_TREE
)
5397 tem
= TREE_VALUE (t
);
5399 tem
= build2 (COMPOUND_EXPR
, TREE_TYPE (tem
),
5400 TREE_VALUE (t
), tem
);
5405 first
= build2 (COMPOUND_EXPR
, TREE_TYPE (first
), tem
, first
);
5410 unsigned int num
= types
.length (), i
;
5411 tree t
, side_effects
= NULL_TREE
, size
= NULL_TREE
;
5412 tree condition
= NULL_TREE
;
5414 if (int_size_in_bytes (TREE_TYPE (first
)) <= 0)
5415 maybe_zero_len
= true;
5416 if (processing_template_decl
&& maybe_zero_len
)
5419 for (i
= num
, t
= OMP_CLAUSE_DECL (c
); i
> 0;
5422 tree low_bound
= TREE_PURPOSE (t
);
5423 tree length
= TREE_VALUE (t
);
5427 && TREE_CODE (low_bound
) == INTEGER_CST
5428 && TYPE_PRECISION (TREE_TYPE (low_bound
))
5429 > TYPE_PRECISION (sizetype
))
5430 low_bound
= fold_convert (sizetype
, low_bound
);
5432 && TREE_CODE (length
) == INTEGER_CST
5433 && TYPE_PRECISION (TREE_TYPE (length
))
5434 > TYPE_PRECISION (sizetype
))
5435 length
= fold_convert (sizetype
, length
);
5436 if (low_bound
== NULL_TREE
)
5437 low_bound
= integer_zero_node
;
5438 if (!maybe_zero_len
&& i
> first_non_one
)
5440 if (integer_nonzerop (low_bound
))
5441 goto do_warn_noncontiguous
;
5442 if (length
!= NULL_TREE
5443 && TREE_CODE (length
) == INTEGER_CST
5444 && TYPE_DOMAIN (types
[i
])
5445 && TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
]))
5446 && TREE_CODE (TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])))
5450 size
= size_binop (PLUS_EXPR
,
5451 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5453 if (!tree_int_cst_equal (length
, size
))
5455 do_warn_noncontiguous
:
5456 error_at (OMP_CLAUSE_LOCATION (c
),
5457 "array section is not contiguous in %qs "
5459 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
5463 if (!processing_template_decl
5464 && length
!= NULL_TREE
5465 && TREE_SIDE_EFFECTS (length
))
5467 if (side_effects
== NULL_TREE
)
5468 side_effects
= length
;
5470 side_effects
= build2 (COMPOUND_EXPR
,
5471 TREE_TYPE (side_effects
),
5472 length
, side_effects
);
5475 else if (processing_template_decl
)
5481 if (i
> first_non_one
5482 && ((length
&& integer_nonzerop (length
))
5483 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5484 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5485 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
))
5488 l
= fold_convert (sizetype
, length
);
5491 l
= size_binop (PLUS_EXPR
,
5492 TYPE_MAX_VALUE (TYPE_DOMAIN (types
[i
])),
5494 l
= size_binop (MINUS_EXPR
, l
,
5495 fold_convert (sizetype
, low_bound
));
5497 if (i
> first_non_one
)
5499 l
= fold_build2 (NE_EXPR
, boolean_type_node
, l
,
5501 if (condition
== NULL_TREE
)
5504 condition
= fold_build2 (BIT_AND_EXPR
, boolean_type_node
,
5507 else if (size
== NULL_TREE
)
5509 size
= size_in_bytes (TREE_TYPE (types
[i
]));
5510 tree eltype
= TREE_TYPE (types
[num
- 1]);
5511 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5512 eltype
= TREE_TYPE (eltype
);
5513 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5514 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5515 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5516 size
= size_binop (EXACT_DIV_EXPR
, size
,
5517 size_in_bytes (eltype
));
5518 size
= size_binop (MULT_EXPR
, size
, l
);
5520 size
= fold_build3 (COND_EXPR
, sizetype
, condition
,
5521 size
, size_zero_node
);
5524 size
= size_binop (MULT_EXPR
, size
, l
);
5527 if (!processing_template_decl
)
5530 size
= build2 (COMPOUND_EXPR
, sizetype
, side_effects
, size
);
5531 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
5532 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
5533 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
5535 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
5536 size
= save_expr (size
);
5537 tree index_type
= build_index_type (size
);
5538 tree eltype
= TREE_TYPE (first
);
5539 while (TREE_CODE (eltype
) == ARRAY_TYPE
)
5540 eltype
= TREE_TYPE (eltype
);
5541 tree type
= build_array_type (eltype
, index_type
);
5542 tree ptype
= build_pointer_type (eltype
);
5543 if (TYPE_REF_P (TREE_TYPE (t
))
5544 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
))))
5545 t
= convert_from_reference (t
);
5546 else if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
5547 t
= build_fold_addr_expr (t
);
5548 tree t2
= build_fold_addr_expr (first
);
5549 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5550 ptrdiff_type_node
, t2
);
5551 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5552 ptrdiff_type_node
, t2
,
5553 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5554 ptrdiff_type_node
, t
));
5555 if (tree_fits_shwi_p (t2
))
5556 t
= build2 (MEM_REF
, type
, t
,
5557 build_int_cst (ptype
, tree_to_shwi (t2
)));
5560 t2
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5562 t
= build2_loc (OMP_CLAUSE_LOCATION (c
), POINTER_PLUS_EXPR
,
5563 TREE_TYPE (t
), t
, t2
);
5564 t
= build2 (MEM_REF
, type
, t
, build_int_cst (ptype
, 0));
5566 OMP_CLAUSE_DECL (c
) = t
;
5569 OMP_CLAUSE_DECL (c
) = first
;
5570 OMP_CLAUSE_SIZE (c
) = size
;
5571 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
5572 || (TREE_CODE (t
) == COMPONENT_REF
5573 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
))
5575 switch (OMP_CLAUSE_MAP_KIND (c
))
5577 case GOMP_MAP_ALLOC
:
5578 case GOMP_MAP_IF_PRESENT
:
5581 case GOMP_MAP_TOFROM
:
5582 case GOMP_MAP_ALWAYS_TO
:
5583 case GOMP_MAP_ALWAYS_FROM
:
5584 case GOMP_MAP_ALWAYS_TOFROM
:
5585 case GOMP_MAP_RELEASE
:
5586 case GOMP_MAP_DELETE
:
5587 case GOMP_MAP_FORCE_TO
:
5588 case GOMP_MAP_FORCE_FROM
:
5589 case GOMP_MAP_FORCE_TOFROM
:
5590 case GOMP_MAP_FORCE_PRESENT
:
5591 OMP_CLAUSE_MAP_MAYBE_ZERO_LENGTH_ARRAY_SECTION (c
) = 1;
5596 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5598 if (TREE_CODE (t
) == COMPONENT_REF
)
5599 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ATTACH_DETACH
);
5600 else if (REFERENCE_REF_P (t
)
5601 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
5603 t
= TREE_OPERAND (t
, 0);
5604 gomp_map_kind k
= (ort
== C_ORT_ACC
) ? GOMP_MAP_ATTACH_DETACH
5605 : GOMP_MAP_ALWAYS_POINTER
;
5606 OMP_CLAUSE_SET_MAP_KIND (c2
, k
);
5609 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_FIRSTPRIVATE_POINTER
);
5610 OMP_CLAUSE_MAP_IMPLICIT (c2
) = OMP_CLAUSE_MAP_IMPLICIT (c
);
5611 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5612 && !cxx_mark_addressable (t
))
5614 OMP_CLAUSE_DECL (c2
) = t
;
5615 t
= build_fold_addr_expr (first
);
5616 t
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5617 ptrdiff_type_node
, t
);
5618 tree ptr
= OMP_CLAUSE_DECL (c2
);
5619 ptr
= convert_from_reference (ptr
);
5620 if (!INDIRECT_TYPE_P (TREE_TYPE (ptr
)))
5621 ptr
= build_fold_addr_expr (ptr
);
5622 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MINUS_EXPR
,
5623 ptrdiff_type_node
, t
,
5624 fold_convert_loc (OMP_CLAUSE_LOCATION (c
),
5625 ptrdiff_type_node
, ptr
));
5626 OMP_CLAUSE_SIZE (c2
) = t
;
5627 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
5628 OMP_CLAUSE_CHAIN (c
) = c2
;
5629 ptr
= OMP_CLAUSE_DECL (c2
);
5630 if (OMP_CLAUSE_MAP_KIND (c2
) != GOMP_MAP_FIRSTPRIVATE_POINTER
5631 && TYPE_REF_P (TREE_TYPE (ptr
))
5632 && INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (ptr
))))
5634 tree c3
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
5636 OMP_CLAUSE_SET_MAP_KIND (c3
, OMP_CLAUSE_MAP_KIND (c2
));
5637 OMP_CLAUSE_MAP_IMPLICIT (c2
) = OMP_CLAUSE_MAP_IMPLICIT (c
);
5638 OMP_CLAUSE_DECL (c3
) = ptr
;
5639 if (OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ALWAYS_POINTER
5640 || OMP_CLAUSE_MAP_KIND (c2
) == GOMP_MAP_ATTACH_DETACH
)
5642 OMP_CLAUSE_DECL (c2
) = build_simple_mem_ref (ptr
);
5643 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ALWAYS_POINTER
);
5646 OMP_CLAUSE_DECL (c2
) = convert_from_reference (ptr
);
5647 OMP_CLAUSE_SIZE (c3
) = size_zero_node
;
5648 OMP_CLAUSE_CHAIN (c3
) = OMP_CLAUSE_CHAIN (c2
);
5649 OMP_CLAUSE_CHAIN (c2
) = c3
;
5656 /* Return identifier to look up for omp declare reduction. */
5659 omp_reduction_id (enum tree_code reduction_code
, tree reduction_id
, tree type
)
5661 const char *p
= NULL
;
5662 const char *m
= NULL
;
5663 switch (reduction_code
)
5671 case TRUTH_ANDIF_EXPR
:
5672 case TRUTH_ORIF_EXPR
:
5673 reduction_id
= ovl_op_identifier (false, reduction_code
);
5687 if (TREE_CODE (reduction_id
) != IDENTIFIER_NODE
)
5688 return error_mark_node
;
5689 p
= IDENTIFIER_POINTER (reduction_id
);
5692 if (type
!= NULL_TREE
)
5693 m
= mangle_type_string (TYPE_MAIN_VARIANT (type
));
5695 const char prefix
[] = "omp declare reduction ";
5696 size_t lenp
= sizeof (prefix
);
5697 if (strncmp (p
, prefix
, lenp
- 1) == 0)
5699 size_t len
= strlen (p
);
5700 size_t lenm
= m
? strlen (m
) + 1 : 0;
5701 char *name
= XALLOCAVEC (char, lenp
+ len
+ lenm
);
5703 memcpy (name
, prefix
, lenp
- 1);
5704 memcpy (name
+ lenp
- 1, p
, len
+ 1);
5707 name
[lenp
+ len
- 1] = '~';
5708 memcpy (name
+ lenp
+ len
, m
, lenm
);
5710 return get_identifier (name
);
5713 /* Lookup OpenMP UDR ID for TYPE, return the corresponding artificial
5714 FUNCTION_DECL or NULL_TREE if not found. */
5717 omp_reduction_lookup (location_t loc
, tree id
, tree type
, tree
*baselinkp
,
5718 vec
<tree
> *ambiguousp
)
5721 tree baselink
= NULL_TREE
;
5722 if (identifier_p (id
))
5725 bool nonint_cst_expression_p
;
5726 const char *error_msg
;
5727 id
= omp_reduction_id (ERROR_MARK
, id
, type
);
5728 tree decl
= lookup_name (id
);
5729 if (decl
== NULL_TREE
)
5730 decl
= error_mark_node
;
5731 id
= finish_id_expression (id
, decl
, NULL_TREE
, &idk
, false, true,
5732 &nonint_cst_expression_p
, false, true, false,
5733 false, &error_msg
, loc
);
5734 if (idk
== CP_ID_KIND_UNQUALIFIED
5735 && identifier_p (id
))
5737 vec
<tree
, va_gc
> *args
= NULL
;
5738 vec_safe_push (args
, build_reference_type (type
));
5739 id
= perform_koenig_lookup (id
, args
, tf_none
);
5742 else if (TREE_CODE (id
) == SCOPE_REF
)
5743 id
= lookup_qualified_name (TREE_OPERAND (id
, 0),
5744 omp_reduction_id (ERROR_MARK
,
5745 TREE_OPERAND (id
, 1),
5747 LOOK_want::NORMAL
, false);
5750 if (fns
&& is_overloaded_fn (fns
))
5752 for (lkp_iterator
iter (get_fns (fns
)); iter
; ++iter
)
5754 tree fndecl
= *iter
;
5755 if (TREE_CODE (fndecl
) == FUNCTION_DECL
)
5757 tree argtype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (fndecl
)));
5758 if (same_type_p (TREE_TYPE (argtype
), type
))
5766 if (id
&& BASELINK_P (fns
))
5775 if (!id
&& CLASS_TYPE_P (type
) && TYPE_BINFO (type
))
5777 auto_vec
<tree
> ambiguous
;
5778 tree binfo
= TYPE_BINFO (type
), base_binfo
, ret
= NULL_TREE
;
5780 if (ambiguousp
== NULL
)
5781 ambiguousp
= &ambiguous
;
5782 for (ix
= 0; BINFO_BASE_ITERATE (binfo
, ix
, base_binfo
); ix
++)
5784 id
= omp_reduction_lookup (loc
, orig_id
, BINFO_TYPE (base_binfo
),
5785 baselinkp
? baselinkp
: &baselink
,
5787 if (id
== NULL_TREE
)
5789 if (!ambiguousp
->is_empty ())
5790 ambiguousp
->safe_push (id
);
5791 else if (ret
!= NULL_TREE
)
5793 ambiguousp
->safe_push (ret
);
5794 ambiguousp
->safe_push (id
);
5800 if (ambiguousp
!= &ambiguous
)
5802 if (!ambiguous
.is_empty ())
5804 const char *str
= _("candidates are:");
5807 error_at (loc
, "user defined reduction lookup is ambiguous");
5808 FOR_EACH_VEC_ELT (ambiguous
, idx
, udr
)
5810 inform (DECL_SOURCE_LOCATION (udr
), "%s %#qD", str
, udr
);
5812 str
= get_spaces (str
);
5814 ret
= error_mark_node
;
5815 baselink
= NULL_TREE
;
5820 perform_or_defer_access_check (BASELINK_BINFO (baselink
),
5821 id
, id
, tf_warning_or_error
);
5825 /* Helper function for cp_parser_omp_declare_reduction_exprs
5827 Remove CLEANUP_STMT for data (omp_priv variable).
5828 Also append INIT_EXPR for DECL_INITIAL of omp_priv after its
5832 cp_remove_omp_priv_cleanup_stmt (tree
*tp
, int *walk_subtrees
, void *data
)
5836 else if (TREE_CODE (*tp
) == CLEANUP_STMT
&& CLEANUP_DECL (*tp
) == (tree
) data
)
5837 *tp
= CLEANUP_BODY (*tp
);
5838 else if (TREE_CODE (*tp
) == DECL_EXPR
)
5840 tree decl
= DECL_EXPR_DECL (*tp
);
5841 if (!processing_template_decl
5842 && decl
== (tree
) data
5843 && DECL_INITIAL (decl
)
5844 && DECL_INITIAL (decl
) != error_mark_node
)
5846 tree list
= NULL_TREE
;
5847 append_to_statement_list_force (*tp
, &list
);
5848 tree init_expr
= build2 (INIT_EXPR
, void_type_node
,
5849 decl
, DECL_INITIAL (decl
));
5850 DECL_INITIAL (decl
) = NULL_TREE
;
5851 append_to_statement_list_force (init_expr
, &list
);
5858 /* Data passed from cp_check_omp_declare_reduction to
5859 cp_check_omp_declare_reduction_r. */
5861 struct cp_check_omp_declare_reduction_data
5868 /* Helper function for cp_check_omp_declare_reduction, called via
5872 cp_check_omp_declare_reduction_r (tree
*tp
, int *, void *data
)
5874 struct cp_check_omp_declare_reduction_data
*udr_data
5875 = (struct cp_check_omp_declare_reduction_data
*) data
;
5877 && !DECL_ARTIFICIAL (*tp
)
5878 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 0 : 3])
5879 && *tp
!= DECL_EXPR_DECL (udr_data
->stmts
[udr_data
->combiner_p
? 1 : 4]))
5881 location_t loc
= udr_data
->loc
;
5882 if (udr_data
->combiner_p
)
5883 error_at (loc
, "%<#pragma omp declare reduction%> combiner refers to "
5884 "variable %qD which is not %<omp_out%> nor %<omp_in%>",
5887 error_at (loc
, "%<#pragma omp declare reduction%> initializer refers "
5888 "to variable %qD which is not %<omp_priv%> nor "
5896 /* Diagnose violation of OpenMP #pragma omp declare reduction restrictions. */
5899 cp_check_omp_declare_reduction (tree udr
)
5901 tree type
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (udr
)));
5902 gcc_assert (TYPE_REF_P (type
));
5903 type
= TREE_TYPE (type
);
5905 location_t loc
= DECL_SOURCE_LOCATION (udr
);
5907 if (type
== error_mark_node
)
5909 if (ARITHMETIC_TYPE_P (type
))
5911 static enum tree_code predef_codes
[]
5912 = { PLUS_EXPR
, MULT_EXPR
, MINUS_EXPR
, BIT_AND_EXPR
, BIT_XOR_EXPR
,
5913 BIT_IOR_EXPR
, TRUTH_ANDIF_EXPR
, TRUTH_ORIF_EXPR
};
5914 for (i
= 0; i
< 8; i
++)
5916 tree id
= omp_reduction_id (predef_codes
[i
], NULL_TREE
, NULL_TREE
);
5917 const char *n1
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5918 const char *n2
= IDENTIFIER_POINTER (id
);
5919 if (strncmp (n1
, n2
, IDENTIFIER_LENGTH (id
)) == 0
5920 && (n1
[IDENTIFIER_LENGTH (id
)] == '~'
5921 || n1
[IDENTIFIER_LENGTH (id
)] == '\0'))
5926 && TREE_CODE (type
) != COMPLEX_EXPR
)
5928 const char prefix_minmax
[] = "omp declare reduction m";
5929 size_t prefix_size
= sizeof (prefix_minmax
) - 1;
5930 const char *n
= IDENTIFIER_POINTER (DECL_NAME (udr
));
5931 if (strncmp (IDENTIFIER_POINTER (DECL_NAME (udr
)),
5932 prefix_minmax
, prefix_size
) == 0
5933 && ((n
[prefix_size
] == 'i' && n
[prefix_size
+ 1] == 'n')
5934 || (n
[prefix_size
] == 'a' && n
[prefix_size
+ 1] == 'x'))
5935 && (n
[prefix_size
+ 2] == '~' || n
[prefix_size
+ 2] == '\0'))
5940 error_at (loc
, "predeclared arithmetic type %qT in "
5941 "%<#pragma omp declare reduction%>", type
);
5945 else if (FUNC_OR_METHOD_TYPE_P (type
)
5946 || TREE_CODE (type
) == ARRAY_TYPE
)
5948 error_at (loc
, "function or array type %qT in "
5949 "%<#pragma omp declare reduction%>", type
);
5952 else if (TYPE_REF_P (type
))
5954 error_at (loc
, "reference type %qT in %<#pragma omp declare reduction%>",
5958 else if (TYPE_QUALS_NO_ADDR_SPACE (type
))
5960 error_at (loc
, "%<const%>, %<volatile%> or %<__restrict%>-qualified "
5961 "type %qT in %<#pragma omp declare reduction%>", type
);
5965 tree body
= DECL_SAVED_TREE (udr
);
5966 if (body
== NULL_TREE
|| TREE_CODE (body
) != STATEMENT_LIST
)
5969 tree_stmt_iterator tsi
;
5970 struct cp_check_omp_declare_reduction_data data
;
5971 memset (data
.stmts
, 0, sizeof data
.stmts
);
5972 for (i
= 0, tsi
= tsi_start (body
);
5973 i
< 7 && !tsi_end_p (tsi
);
5974 i
++, tsi_next (&tsi
))
5975 data
.stmts
[i
] = tsi_stmt (tsi
);
5977 gcc_assert (tsi_end_p (tsi
));
5980 gcc_assert (TREE_CODE (data
.stmts
[0]) == DECL_EXPR
5981 && TREE_CODE (data
.stmts
[1]) == DECL_EXPR
);
5982 if (warning_suppressed_p (DECL_EXPR_DECL (data
.stmts
[0]) /* What warning? */))
5984 data
.combiner_p
= true;
5985 if (cp_walk_tree (&data
.stmts
[2], cp_check_omp_declare_reduction_r
,
5987 suppress_warning (DECL_EXPR_DECL (data
.stmts
[0]) /* What warning? */);
5991 gcc_assert (TREE_CODE (data
.stmts
[3]) == DECL_EXPR
5992 && TREE_CODE (data
.stmts
[4]) == DECL_EXPR
);
5993 data
.combiner_p
= false;
5994 if (cp_walk_tree (&data
.stmts
[5], cp_check_omp_declare_reduction_r
,
5996 || cp_walk_tree (&DECL_INITIAL (DECL_EXPR_DECL (data
.stmts
[3])),
5997 cp_check_omp_declare_reduction_r
, &data
, NULL
))
5998 suppress_warning (DECL_EXPR_DECL (data
.stmts
[0]) /* Wat warning? */);
6000 gcc_assert (TREE_CODE (data
.stmts
[6]) == DECL_EXPR
);
6005 /* Helper function of finish_omp_clauses. Clone STMT as if we were making
6006 an inline call. But, remap
6007 the OMP_DECL1 VAR_DECL (omp_out resp. omp_orig) to PLACEHOLDER
6008 and OMP_DECL2 VAR_DECL (omp_in resp. omp_priv) to DECL. */
6011 clone_omp_udr (tree stmt
, tree omp_decl1
, tree omp_decl2
,
6012 tree decl
, tree placeholder
)
6015 hash_map
<tree
, tree
> decl_map
;
6017 decl_map
.put (omp_decl1
, placeholder
);
6018 decl_map
.put (omp_decl2
, decl
);
6019 memset (&id
, 0, sizeof (id
));
6020 id
.src_fn
= DECL_CONTEXT (omp_decl1
);
6021 id
.dst_fn
= current_function_decl
;
6022 id
.src_cfun
= DECL_STRUCT_FUNCTION (id
.src_fn
);
6023 id
.decl_map
= &decl_map
;
6025 id
.copy_decl
= copy_decl_no_change
;
6026 id
.transform_call_graph_edges
= CB_CGE_DUPLICATE
;
6027 id
.transform_new_cfg
= true;
6028 id
.transform_return_to_modify
= false;
6029 id
.transform_lang_insert_block
= NULL
;
6031 walk_tree (&stmt
, copy_tree_body_r
, &id
, NULL
);
6035 /* Helper function of finish_omp_clauses, called via cp_walk_tree.
6036 Find OMP_CLAUSE_PLACEHOLDER (passed in DATA) in *TP. */
6039 find_omp_placeholder_r (tree
*tp
, int *, void *data
)
6041 if (*tp
== (tree
) data
)
6046 /* Helper function of finish_omp_clauses. Handle OMP_CLAUSE_REDUCTION C.
6047 Return true if there is some error and the clause should be removed. */
6050 finish_omp_reduction_clause (tree c
, bool *need_default_ctor
, bool *need_dtor
)
6052 tree t
= OMP_CLAUSE_DECL (c
);
6053 bool predefined
= false;
6054 if (TREE_CODE (t
) == TREE_LIST
)
6056 gcc_assert (processing_template_decl
);
6059 tree type
= TREE_TYPE (t
);
6060 if (TREE_CODE (t
) == MEM_REF
)
6061 type
= TREE_TYPE (type
);
6062 if (TYPE_REF_P (type
))
6063 type
= TREE_TYPE (type
);
6064 if (TREE_CODE (type
) == ARRAY_TYPE
)
6067 gcc_assert (TREE_CODE (t
) != MEM_REF
);
6068 while (TREE_CODE (type
) == ARRAY_TYPE
)
6069 type
= TREE_TYPE (type
);
6070 if (!processing_template_decl
)
6072 t
= require_complete_type (t
);
6073 if (t
== error_mark_node
6074 || !complete_type_or_else (oatype
, NULL_TREE
))
6076 tree size
= size_binop (EXACT_DIV_EXPR
, TYPE_SIZE_UNIT (oatype
),
6077 TYPE_SIZE_UNIT (type
));
6078 if (integer_zerop (size
))
6080 error_at (OMP_CLAUSE_LOCATION (c
),
6081 "%qE in %<reduction%> clause is a zero size array",
6082 omp_clause_printable_decl (t
));
6085 size
= size_binop (MINUS_EXPR
, size
, size_one_node
);
6086 size
= save_expr (size
);
6087 tree index_type
= build_index_type (size
);
6088 tree atype
= build_array_type (type
, index_type
);
6089 tree ptype
= build_pointer_type (type
);
6090 if (TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
6091 t
= build_fold_addr_expr (t
);
6092 t
= build2 (MEM_REF
, atype
, t
, build_int_cst (ptype
, 0));
6093 OMP_CLAUSE_DECL (c
) = t
;
6096 if (type
== error_mark_node
)
6098 else if (ARITHMETIC_TYPE_P (type
))
6099 switch (OMP_CLAUSE_REDUCTION_CODE (c
))
6104 case TRUTH_ANDIF_EXPR
:
6105 case TRUTH_ORIF_EXPR
:
6110 if (TREE_CODE (type
) == COMPLEX_TYPE
)
6117 if (FLOAT_TYPE_P (type
) || TREE_CODE (type
) == COMPLEX_TYPE
)
6124 else if (TYPE_READONLY (type
))
6126 error_at (OMP_CLAUSE_LOCATION (c
),
6127 "%qE has const type for %<reduction%>",
6128 omp_clause_printable_decl (t
));
6131 else if (!processing_template_decl
)
6133 t
= require_complete_type (t
);
6134 if (t
== error_mark_node
)
6136 OMP_CLAUSE_DECL (c
) = t
;
6141 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
6144 else if (processing_template_decl
)
6146 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) == error_mark_node
)
6151 tree id
= OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
);
6153 type
= TYPE_MAIN_VARIANT (type
);
6154 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = NULL_TREE
;
6155 if (id
== NULL_TREE
)
6156 id
= omp_reduction_id (OMP_CLAUSE_REDUCTION_CODE (c
),
6157 NULL_TREE
, NULL_TREE
);
6158 id
= omp_reduction_lookup (OMP_CLAUSE_LOCATION (c
), id
, type
, NULL
, NULL
);
6161 if (id
== error_mark_node
)
6164 tree body
= DECL_SAVED_TREE (id
);
6167 if (TREE_CODE (body
) == STATEMENT_LIST
)
6169 tree_stmt_iterator tsi
;
6170 tree placeholder
= NULL_TREE
, decl_placeholder
= NULL_TREE
;
6173 tree atype
= TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (id
)));
6174 atype
= TREE_TYPE (atype
);
6175 bool need_static_cast
= !same_type_p (type
, atype
);
6176 memset (stmts
, 0, sizeof stmts
);
6177 for (i
= 0, tsi
= tsi_start (body
);
6178 i
< 7 && !tsi_end_p (tsi
);
6179 i
++, tsi_next (&tsi
))
6180 stmts
[i
] = tsi_stmt (tsi
);
6181 gcc_assert (tsi_end_p (tsi
));
6185 gcc_assert (TREE_CODE (stmts
[0]) == DECL_EXPR
6186 && TREE_CODE (stmts
[1]) == DECL_EXPR
);
6187 placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
, type
);
6188 DECL_ARTIFICIAL (placeholder
) = 1;
6189 DECL_IGNORED_P (placeholder
) = 1;
6190 OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
) = placeholder
;
6191 if (TREE_CODE (t
) == MEM_REF
)
6193 decl_placeholder
= build_lang_decl (VAR_DECL
, NULL_TREE
,
6195 DECL_ARTIFICIAL (decl_placeholder
) = 1;
6196 DECL_IGNORED_P (decl_placeholder
) = 1;
6197 OMP_CLAUSE_REDUCTION_DECL_PLACEHOLDER (c
) = decl_placeholder
;
6199 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[0])))
6200 cxx_mark_addressable (placeholder
);
6201 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[1]))
6202 && (decl_placeholder
6203 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6204 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6205 : OMP_CLAUSE_DECL (c
));
6206 tree omp_out
= placeholder
;
6207 tree omp_in
= decl_placeholder
? decl_placeholder
6208 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6209 if (need_static_cast
)
6211 tree rtype
= build_reference_type (atype
);
6212 omp_out
= build_static_cast (input_location
,
6214 tf_warning_or_error
);
6215 omp_in
= build_static_cast (input_location
,
6217 tf_warning_or_error
);
6218 if (omp_out
== error_mark_node
|| omp_in
== error_mark_node
)
6220 omp_out
= convert_from_reference (omp_out
);
6221 omp_in
= convert_from_reference (omp_in
);
6223 OMP_CLAUSE_REDUCTION_MERGE (c
)
6224 = clone_omp_udr (stmts
[2], DECL_EXPR_DECL (stmts
[0]),
6225 DECL_EXPR_DECL (stmts
[1]), omp_in
, omp_out
);
6229 gcc_assert (TREE_CODE (stmts
[3]) == DECL_EXPR
6230 && TREE_CODE (stmts
[4]) == DECL_EXPR
);
6231 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[3]))
6232 && (decl_placeholder
6233 || !TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
)))))
6234 cxx_mark_addressable (decl_placeholder
? decl_placeholder
6235 : OMP_CLAUSE_DECL (c
));
6236 if (TREE_ADDRESSABLE (DECL_EXPR_DECL (stmts
[4])))
6237 cxx_mark_addressable (placeholder
);
6238 tree omp_priv
= decl_placeholder
? decl_placeholder
6239 : convert_from_reference (OMP_CLAUSE_DECL (c
));
6240 tree omp_orig
= placeholder
;
6241 if (need_static_cast
)
6245 error_at (OMP_CLAUSE_LOCATION (c
),
6246 "user defined reduction with constructor "
6247 "initializer for base class %qT", atype
);
6250 tree rtype
= build_reference_type (atype
);
6251 omp_priv
= build_static_cast (input_location
,
6253 tf_warning_or_error
);
6254 omp_orig
= build_static_cast (input_location
,
6256 tf_warning_or_error
);
6257 if (omp_priv
== error_mark_node
6258 || omp_orig
== error_mark_node
)
6260 omp_priv
= convert_from_reference (omp_priv
);
6261 omp_orig
= convert_from_reference (omp_orig
);
6264 *need_default_ctor
= true;
6265 OMP_CLAUSE_REDUCTION_INIT (c
)
6266 = clone_omp_udr (stmts
[5], DECL_EXPR_DECL (stmts
[4]),
6267 DECL_EXPR_DECL (stmts
[3]),
6268 omp_priv
, omp_orig
);
6269 if (cp_walk_tree (&OMP_CLAUSE_REDUCTION_INIT (c
),
6270 find_omp_placeholder_r
, placeholder
, NULL
))
6271 OMP_CLAUSE_REDUCTION_OMP_ORIG_REF (c
) = 1;
6275 if (CLASS_TYPE_P (type
) && !pod_type_p (type
))
6276 *need_default_ctor
= true;
6280 tree v
= decl_placeholder
? decl_placeholder
6281 : convert_from_reference (t
);
6282 if (AGGREGATE_TYPE_P (TREE_TYPE (v
)))
6283 init
= build_constructor (TREE_TYPE (v
), NULL
);
6285 init
= fold_convert (TREE_TYPE (v
), integer_zero_node
);
6286 OMP_CLAUSE_REDUCTION_INIT (c
)
6287 = build2 (INIT_EXPR
, TREE_TYPE (v
), v
, init
);
6292 if (OMP_CLAUSE_REDUCTION_PLACEHOLDER (c
))
6296 error_at (OMP_CLAUSE_LOCATION (c
),
6297 "user defined reduction not found for %qE",
6298 omp_clause_printable_decl (t
));
6301 if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == MEM_REF
)
6302 gcc_assert (TYPE_SIZE_UNIT (type
)
6303 && TREE_CODE (TYPE_SIZE_UNIT (type
)) == INTEGER_CST
);
6307 /* Called from finish_struct_1. linear(this) or linear(this:step)
6308 clauses might not be finalized yet because the class has been incomplete
6309 when parsing #pragma omp declare simd methods. Fix those up now. */
6312 finish_omp_declare_simd_methods (tree t
)
6314 if (processing_template_decl
)
6317 for (tree x
= TYPE_FIELDS (t
); x
; x
= DECL_CHAIN (x
))
6319 if (TREE_CODE (x
) == USING_DECL
6320 || !DECL_NONSTATIC_MEMBER_FUNCTION_P (x
))
6322 tree ods
= lookup_attribute ("omp declare simd", DECL_ATTRIBUTES (x
));
6323 if (!ods
|| !TREE_VALUE (ods
))
6325 for (tree c
= TREE_VALUE (TREE_VALUE (ods
)); c
; c
= OMP_CLAUSE_CHAIN (c
))
6326 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LINEAR
6327 && integer_zerop (OMP_CLAUSE_DECL (c
))
6328 && OMP_CLAUSE_LINEAR_STEP (c
)
6329 && TYPE_PTR_P (TREE_TYPE (OMP_CLAUSE_LINEAR_STEP (c
))))
6331 tree s
= OMP_CLAUSE_LINEAR_STEP (c
);
6332 s
= fold_convert_loc (OMP_CLAUSE_LOCATION (c
), sizetype
, s
);
6333 s
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
), MULT_EXPR
,
6334 sizetype
, s
, TYPE_SIZE_UNIT (t
));
6335 OMP_CLAUSE_LINEAR_STEP (c
) = s
;
6340 /* Adjust sink depend clause to take into account pointer offsets.
6342 Return TRUE if there was a problem processing the offset, and the
6343 whole clause should be removed. */
6346 cp_finish_omp_clause_depend_sink (tree sink_clause
)
6348 tree t
= OMP_CLAUSE_DECL (sink_clause
);
6349 gcc_assert (TREE_CODE (t
) == TREE_LIST
);
6351 /* Make sure we don't adjust things twice for templates. */
6352 if (processing_template_decl
)
6355 for (; t
; t
= TREE_CHAIN (t
))
6357 tree decl
= TREE_VALUE (t
);
6358 if (TYPE_PTR_P (TREE_TYPE (decl
)))
6360 tree offset
= TREE_PURPOSE (t
);
6361 bool neg
= wi::neg_p (wi::to_wide (offset
));
6362 offset
= fold_unary (ABS_EXPR
, TREE_TYPE (offset
), offset
);
6363 decl
= mark_rvalue_use (decl
);
6364 decl
= convert_from_reference (decl
);
6365 tree t2
= pointer_int_sum (OMP_CLAUSE_LOCATION (sink_clause
),
6366 neg
? MINUS_EXPR
: PLUS_EXPR
,
6368 t2
= fold_build2_loc (OMP_CLAUSE_LOCATION (sink_clause
),
6369 MINUS_EXPR
, sizetype
,
6370 fold_convert (sizetype
, t2
),
6371 fold_convert (sizetype
, decl
));
6372 if (t2
== error_mark_node
)
6374 TREE_PURPOSE (t
) = t2
;
6380 /* Finish OpenMP iterators ITER. Return true if they are errorneous
6381 and clauses containing them should be removed. */
6384 cp_omp_finish_iterators (tree iter
)
6387 for (tree it
= iter
; it
; it
= TREE_CHAIN (it
))
6389 tree var
= TREE_VEC_ELT (it
, 0);
6390 tree begin
= TREE_VEC_ELT (it
, 1);
6391 tree end
= TREE_VEC_ELT (it
, 2);
6392 tree step
= TREE_VEC_ELT (it
, 3);
6394 tree type
= TREE_TYPE (var
);
6395 location_t loc
= DECL_SOURCE_LOCATION (var
);
6396 if (type
== error_mark_node
)
6401 if (type_dependent_expression_p (var
))
6403 if (!INTEGRAL_TYPE_P (type
) && !POINTER_TYPE_P (type
))
6405 error_at (loc
, "iterator %qD has neither integral nor pointer type",
6410 else if (TYPE_READONLY (type
))
6412 error_at (loc
, "iterator %qD has const qualified type", var
);
6416 if (type_dependent_expression_p (begin
)
6417 || type_dependent_expression_p (end
)
6418 || type_dependent_expression_p (step
))
6420 else if (error_operand_p (step
))
6425 else if (!INTEGRAL_TYPE_P (TREE_TYPE (step
)))
6427 error_at (EXPR_LOC_OR_LOC (step
, loc
),
6428 "iterator step with non-integral type");
6433 begin
= mark_rvalue_use (begin
);
6434 end
= mark_rvalue_use (end
);
6435 step
= mark_rvalue_use (step
);
6436 begin
= cp_build_c_cast (input_location
, type
, begin
,
6437 tf_warning_or_error
);
6438 end
= cp_build_c_cast (input_location
, type
, end
,
6439 tf_warning_or_error
);
6441 if (!processing_template_decl
)
6442 step
= orig_step
= save_expr (step
);
6443 tree stype
= POINTER_TYPE_P (type
) ? sizetype
: type
;
6444 step
= cp_build_c_cast (input_location
, stype
, step
,
6445 tf_warning_or_error
);
6446 if (POINTER_TYPE_P (type
) && !processing_template_decl
)
6448 begin
= save_expr (begin
);
6449 step
= pointer_int_sum (loc
, PLUS_EXPR
, begin
, step
);
6450 step
= fold_build2_loc (loc
, MINUS_EXPR
, sizetype
,
6451 fold_convert (sizetype
, step
),
6452 fold_convert (sizetype
, begin
));
6453 step
= fold_convert (ssizetype
, step
);
6455 if (!processing_template_decl
)
6457 begin
= maybe_constant_value (begin
);
6458 end
= maybe_constant_value (end
);
6459 step
= maybe_constant_value (step
);
6460 orig_step
= maybe_constant_value (orig_step
);
6462 if (integer_zerop (step
))
6464 error_at (loc
, "iterator %qD has zero step", var
);
6469 if (begin
== error_mark_node
6470 || end
== error_mark_node
6471 || step
== error_mark_node
6472 || orig_step
== error_mark_node
)
6478 if (!processing_template_decl
)
6480 begin
= fold_build_cleanup_point_expr (TREE_TYPE (begin
), begin
);
6481 end
= fold_build_cleanup_point_expr (TREE_TYPE (end
), end
);
6482 step
= fold_build_cleanup_point_expr (TREE_TYPE (step
), step
);
6483 orig_step
= fold_build_cleanup_point_expr (TREE_TYPE (orig_step
),
6486 hash_set
<tree
> pset
;
6488 for (it2
= TREE_CHAIN (it
); it2
; it2
= TREE_CHAIN (it2
))
6490 tree var2
= TREE_VEC_ELT (it2
, 0);
6491 tree begin2
= TREE_VEC_ELT (it2
, 1);
6492 tree end2
= TREE_VEC_ELT (it2
, 2);
6493 tree step2
= TREE_VEC_ELT (it2
, 3);
6494 location_t loc2
= DECL_SOURCE_LOCATION (var2
);
6495 if (cp_walk_tree (&begin2
, find_omp_placeholder_r
, var
, &pset
))
6497 error_at (EXPR_LOC_OR_LOC (begin2
, loc2
),
6498 "begin expression refers to outer iterator %qD", var
);
6501 else if (cp_walk_tree (&end2
, find_omp_placeholder_r
, var
, &pset
))
6503 error_at (EXPR_LOC_OR_LOC (end2
, loc2
),
6504 "end expression refers to outer iterator %qD", var
);
6507 else if (cp_walk_tree (&step2
, find_omp_placeholder_r
, var
, &pset
))
6509 error_at (EXPR_LOC_OR_LOC (step2
, loc2
),
6510 "step expression refers to outer iterator %qD", var
);
6519 TREE_VEC_ELT (it
, 1) = begin
;
6520 TREE_VEC_ELT (it
, 2) = end
;
6521 if (processing_template_decl
)
6522 TREE_VEC_ELT (it
, 3) = orig_step
;
6525 TREE_VEC_ELT (it
, 3) = step
;
6526 TREE_VEC_ELT (it
, 4) = orig_step
;
6532 /* Ensure that pointers are used in OpenACC attach and detach clauses.
6533 Return true if an error has been detected. */
6536 cp_oacc_check_attachments (tree c
)
6538 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
6541 /* OpenACC attach / detach clauses must be pointers. */
6542 if (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
6543 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
)
6545 tree t
= OMP_CLAUSE_DECL (c
);
6548 while (TREE_CODE (t
) == TREE_LIST
)
6551 type
= TREE_TYPE (t
);
6553 if (TREE_CODE (type
) == REFERENCE_TYPE
)
6554 type
= TREE_TYPE (type
);
6556 if (TREE_CODE (type
) != POINTER_TYPE
)
6558 error_at (OMP_CLAUSE_LOCATION (c
), "expected pointer in %qs clause",
6559 c_omp_map_clause_name (c
, true));
6567 /* For all elements of CLAUSES, validate them vs OpenMP constraints.
6568 Remove any elements from the list that are invalid. */
6571 finish_omp_clauses (tree clauses
, enum c_omp_region_type ort
)
6573 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
6574 bitmap_head aligned_head
, map_head
, map_field_head
, map_firstprivate_head
;
6575 bitmap_head oacc_reduction_head
;
6577 tree safelen
= NULL_TREE
;
6578 bool branch_seen
= false;
6579 bool copyprivate_seen
= false;
6580 bool ordered_seen
= false;
6581 bool order_seen
= false;
6582 bool schedule_seen
= false;
6583 bool oacc_async
= false;
6584 tree last_iterators
= NULL_TREE
;
6585 bool last_iterators_remove
= false;
6586 /* 1 if normal/task reduction has been seen, -1 if inscan reduction
6587 has been seen, -2 if mixed inscan/normal reduction diagnosed. */
6588 int reduction_seen
= 0;
6589 bool allocate_seen
= false;
6590 tree detach_seen
= NULL_TREE
;
6591 bool mergeable_seen
= false;
6592 bool implicit_moved
= false;
6593 bool target_in_reduction_seen
= false;
6595 bitmap_obstack_initialize (NULL
);
6596 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
6597 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
6598 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
6599 bitmap_initialize (&aligned_head
, &bitmap_default_obstack
);
6600 /* If ort == C_ORT_OMP_DECLARE_SIMD used as uniform_head instead. */
6601 bitmap_initialize (&map_head
, &bitmap_default_obstack
);
6602 bitmap_initialize (&map_field_head
, &bitmap_default_obstack
);
6603 bitmap_initialize (&map_firstprivate_head
, &bitmap_default_obstack
);
6604 /* If ort == C_ORT_OMP used as nontemporal_head or use_device_xxx_head
6605 instead and for ort == C_ORT_OMP_TARGET used as in_reduction_head. */
6606 bitmap_initialize (&oacc_reduction_head
, &bitmap_default_obstack
);
6608 if (ort
& C_ORT_ACC
)
6609 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
6610 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ASYNC
)
6616 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
6618 bool remove
= false;
6619 bool field_ok
= false;
6621 switch (OMP_CLAUSE_CODE (c
))
6623 case OMP_CLAUSE_SHARED
:
6624 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6625 goto check_dup_generic
;
6626 case OMP_CLAUSE_PRIVATE
:
6627 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6628 goto check_dup_generic
;
6629 case OMP_CLAUSE_REDUCTION
:
6630 if (reduction_seen
== 0)
6631 reduction_seen
= OMP_CLAUSE_REDUCTION_INSCAN (c
) ? -1 : 1;
6632 else if (reduction_seen
!= -2
6633 && reduction_seen
!= (OMP_CLAUSE_REDUCTION_INSCAN (c
)
6636 error_at (OMP_CLAUSE_LOCATION (c
),
6637 "%<inscan%> and non-%<inscan%> %<reduction%> clauses "
6638 "on the same construct");
6639 reduction_seen
= -2;
6642 case OMP_CLAUSE_IN_REDUCTION
:
6643 case OMP_CLAUSE_TASK_REDUCTION
:
6644 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6645 t
= OMP_CLAUSE_DECL (c
);
6646 if (TREE_CODE (t
) == TREE_LIST
)
6648 if (handle_omp_array_sections (c
, ort
))
6653 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
6654 && OMP_CLAUSE_REDUCTION_INSCAN (c
))
6656 error_at (OMP_CLAUSE_LOCATION (c
),
6657 "%<inscan%> %<reduction%> clause with array "
6662 if (TREE_CODE (t
) == TREE_LIST
)
6664 while (TREE_CODE (t
) == TREE_LIST
)
6669 gcc_assert (TREE_CODE (t
) == MEM_REF
);
6670 t
= TREE_OPERAND (t
, 0);
6671 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
6672 t
= TREE_OPERAND (t
, 0);
6673 if (TREE_CODE (t
) == ADDR_EXPR
6674 || INDIRECT_REF_P (t
))
6675 t
= TREE_OPERAND (t
, 0);
6677 tree n
= omp_clause_decl_field (t
);
6680 goto check_dup_generic_t
;
6683 cxx_mark_addressable (t
);
6684 goto check_dup_generic
;
6685 case OMP_CLAUSE_COPYPRIVATE
:
6686 copyprivate_seen
= true;
6687 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6688 goto check_dup_generic
;
6689 case OMP_CLAUSE_COPYIN
:
6690 goto check_dup_generic
;
6691 case OMP_CLAUSE_LINEAR
:
6692 field_ok
= ((ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
);
6693 t
= OMP_CLAUSE_DECL (c
);
6694 if (ort
!= C_ORT_OMP_DECLARE_SIMD
6695 && OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_DEFAULT
)
6697 error_at (OMP_CLAUSE_LOCATION (c
),
6698 "modifier should not be specified in %<linear%> "
6699 "clause on %<simd%> or %<for%> constructs");
6700 OMP_CLAUSE_LINEAR_KIND (c
) = OMP_CLAUSE_LINEAR_DEFAULT
;
6702 if ((VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
6703 && !type_dependent_expression_p (t
))
6705 tree type
= TREE_TYPE (t
);
6706 if ((OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6707 || OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_UVAL
)
6708 && !TYPE_REF_P (type
))
6710 error_at (OMP_CLAUSE_LOCATION (c
),
6711 "linear clause with %qs modifier applied to "
6712 "non-reference variable with %qT type",
6713 OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
6714 ? "ref" : "uval", TREE_TYPE (t
));
6718 if (TYPE_REF_P (type
))
6719 type
= TREE_TYPE (type
);
6720 if (OMP_CLAUSE_LINEAR_KIND (c
) != OMP_CLAUSE_LINEAR_REF
)
6722 if (!INTEGRAL_TYPE_P (type
)
6723 && !TYPE_PTR_P (type
))
6725 error_at (OMP_CLAUSE_LOCATION (c
),
6726 "linear clause applied to non-integral "
6727 "non-pointer variable with %qT type",
6734 t
= OMP_CLAUSE_LINEAR_STEP (c
);
6736 t
= integer_one_node
;
6737 if (t
== error_mark_node
)
6742 else if (!type_dependent_expression_p (t
)
6743 && !INTEGRAL_TYPE_P (TREE_TYPE (t
))
6744 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6745 || TREE_CODE (t
) != PARM_DECL
6746 || !TYPE_REF_P (TREE_TYPE (t
))
6747 || !INTEGRAL_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))))
6749 error_at (OMP_CLAUSE_LOCATION (c
),
6750 "linear step expression must be integral");
6756 t
= mark_rvalue_use (t
);
6757 if (ort
== C_ORT_OMP_DECLARE_SIMD
&& TREE_CODE (t
) == PARM_DECL
)
6759 OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
) = 1;
6760 goto check_dup_generic
;
6762 if (!processing_template_decl
6763 && (VAR_P (OMP_CLAUSE_DECL (c
))
6764 || TREE_CODE (OMP_CLAUSE_DECL (c
)) == PARM_DECL
))
6766 if (ort
== C_ORT_OMP_DECLARE_SIMD
)
6768 t
= maybe_constant_value (t
);
6769 if (TREE_CODE (t
) != INTEGER_CST
)
6771 error_at (OMP_CLAUSE_LOCATION (c
),
6772 "%<linear%> clause step %qE is neither "
6773 "constant nor a parameter", t
);
6778 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
6779 tree type
= TREE_TYPE (OMP_CLAUSE_DECL (c
));
6780 if (TYPE_REF_P (type
))
6781 type
= TREE_TYPE (type
);
6782 if (OMP_CLAUSE_LINEAR_KIND (c
) == OMP_CLAUSE_LINEAR_REF
)
6784 type
= build_pointer_type (type
);
6785 tree d
= fold_convert (type
, OMP_CLAUSE_DECL (c
));
6786 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6788 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6789 MINUS_EXPR
, sizetype
,
6790 fold_convert (sizetype
, t
),
6791 fold_convert (sizetype
, d
));
6792 if (t
== error_mark_node
)
6798 else if (TYPE_PTR_P (type
)
6799 /* Can't multiply the step yet if *this
6800 is still incomplete type. */
6801 && (ort
!= C_ORT_OMP_DECLARE_SIMD
6802 || TREE_CODE (OMP_CLAUSE_DECL (c
)) != PARM_DECL
6803 || !DECL_ARTIFICIAL (OMP_CLAUSE_DECL (c
))
6804 || DECL_NAME (OMP_CLAUSE_DECL (c
))
6806 || !TYPE_BEING_DEFINED (TREE_TYPE (type
))))
6808 tree d
= convert_from_reference (OMP_CLAUSE_DECL (c
));
6809 t
= pointer_int_sum (OMP_CLAUSE_LOCATION (c
), PLUS_EXPR
,
6811 t
= fold_build2_loc (OMP_CLAUSE_LOCATION (c
),
6812 MINUS_EXPR
, sizetype
,
6813 fold_convert (sizetype
, t
),
6814 fold_convert (sizetype
, d
));
6815 if (t
== error_mark_node
)
6822 t
= fold_convert (type
, t
);
6824 OMP_CLAUSE_LINEAR_STEP (c
) = t
;
6826 goto check_dup_generic
;
6828 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6831 if (!remove
&& OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
)
6832 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6835 t
= OMP_CLAUSE_DECL (c
);
6836 check_dup_generic_t
:
6837 if (t
== current_class_ptr
6838 && ((ort
!= C_ORT_OMP_DECLARE_SIMD
&& ort
!= C_ORT_ACC
)
6839 || (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_LINEAR
6840 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_UNIFORM
)))
6842 error_at (OMP_CLAUSE_LOCATION (c
),
6843 "%<this%> allowed in OpenMP only in %<declare simd%>"
6848 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6849 && (!field_ok
|| TREE_CODE (t
) != FIELD_DECL
))
6851 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6854 error_at (OMP_CLAUSE_LOCATION (c
),
6855 "%qD is not a variable in clause %qs", t
,
6856 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6858 error_at (OMP_CLAUSE_LOCATION (c
),
6859 "%qE is not a variable in clause %qs", t
,
6860 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
6863 else if ((ort
== C_ORT_ACC
6864 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
)
6865 || (ort
== C_ORT_OMP
6866 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
6867 || (OMP_CLAUSE_CODE (c
)
6868 == OMP_CLAUSE_USE_DEVICE_ADDR
)))
6869 || (ort
== C_ORT_OMP_TARGET
6870 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
))
6872 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
6873 && (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6874 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))))
6876 error_at (OMP_CLAUSE_LOCATION (c
),
6877 "%qD appears more than once in data-sharing "
6882 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
)
6883 target_in_reduction_seen
= true;
6884 if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
6886 error_at (OMP_CLAUSE_LOCATION (c
),
6888 ? "%qD appears more than once in reduction clauses"
6889 : "%qD appears more than once in data clauses",
6894 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
6896 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6897 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
6898 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
))
6899 || bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
6901 error_at (OMP_CLAUSE_LOCATION (c
),
6902 "%qD appears more than once in data clauses", t
);
6905 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
6906 && bitmap_bit_p (&map_head
, DECL_UID (t
)))
6908 if (ort
== C_ORT_ACC
)
6909 error_at (OMP_CLAUSE_LOCATION (c
),
6910 "%qD appears more than once in data clauses", t
);
6912 error_at (OMP_CLAUSE_LOCATION (c
),
6913 "%qD appears both in data and map clauses", t
);
6917 bitmap_set_bit (&generic_head
, DECL_UID (t
));
6922 && TREE_CODE (t
) == FIELD_DECL
6923 && t
== OMP_CLAUSE_DECL (c
))
6926 = omp_privatize_field (t
, (OMP_CLAUSE_CODE (c
)
6927 == OMP_CLAUSE_SHARED
));
6928 if (OMP_CLAUSE_DECL (c
) == error_mark_node
)
6933 case OMP_CLAUSE_FIRSTPRIVATE
:
6934 if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
) && !implicit_moved
)
6937 implicit_moved
= true;
6938 /* Move firstprivate and map clauses with
6939 OMP_CLAUSE_{FIRSTPRIVATE,MAP}_IMPLICIT set to the end of
6941 tree cl1
= NULL_TREE
, cl2
= NULL_TREE
;
6942 tree
*pc1
= pc
, *pc2
= &cl1
, *pc3
= &cl2
;
6944 if (OMP_CLAUSE_CODE (*pc1
) == OMP_CLAUSE_FIRSTPRIVATE
6945 && OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (*pc1
))
6948 pc3
= &OMP_CLAUSE_CHAIN (*pc3
);
6949 *pc1
= OMP_CLAUSE_CHAIN (*pc1
);
6951 else if (OMP_CLAUSE_CODE (*pc1
) == OMP_CLAUSE_MAP
6952 && OMP_CLAUSE_MAP_IMPLICIT (*pc1
))
6955 pc2
= &OMP_CLAUSE_CHAIN (*pc2
);
6956 *pc1
= OMP_CLAUSE_CHAIN (*pc1
);
6959 pc1
= &OMP_CLAUSE_CHAIN (*pc1
);
6965 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
6967 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
6969 t
= OMP_CLAUSE_DECL (c
);
6970 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
6972 error_at (OMP_CLAUSE_LOCATION (c
),
6973 "%<this%> allowed in OpenMP only in %<declare simd%>"
6978 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
6979 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
6980 || TREE_CODE (t
) != FIELD_DECL
))
6982 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
6985 error_at (OMP_CLAUSE_LOCATION (c
),
6986 "%qD is not a variable in clause %<firstprivate%>",
6989 error_at (OMP_CLAUSE_LOCATION (c
),
6990 "%qE is not a variable in clause %<firstprivate%>",
6994 else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
)
6995 && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c
)
6996 && bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
6998 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
6999 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
7000 || bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
7002 error_at (OMP_CLAUSE_LOCATION (c
),
7003 "%qD appears more than once in data clauses", t
);
7006 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7008 if (ort
== C_ORT_ACC
)
7009 error_at (OMP_CLAUSE_LOCATION (c
),
7010 "%qD appears more than once in data clauses", t
);
7011 else if (OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT (c
)
7012 && !OMP_CLAUSE_FIRSTPRIVATE_IMPLICIT_TARGET (c
))
7013 /* Silently drop the clause. */;
7015 error_at (OMP_CLAUSE_LOCATION (c
),
7016 "%qD appears both in data and map clauses", t
);
7020 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
7021 goto handle_field_decl
;
7023 case OMP_CLAUSE_LASTPRIVATE
:
7024 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7026 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7028 t
= OMP_CLAUSE_DECL (c
);
7029 if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7031 error_at (OMP_CLAUSE_LOCATION (c
),
7032 "%<this%> allowed in OpenMP only in %<declare simd%>"
7037 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
7038 && ((ort
& C_ORT_OMP_DECLARE_SIMD
) != C_ORT_OMP
7039 || TREE_CODE (t
) != FIELD_DECL
))
7041 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7044 error_at (OMP_CLAUSE_LOCATION (c
),
7045 "%qD is not a variable in clause %<lastprivate%>",
7048 error_at (OMP_CLAUSE_LOCATION (c
),
7049 "%qE is not a variable in clause %<lastprivate%>",
7053 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7054 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
7056 error_at (OMP_CLAUSE_LOCATION (c
),
7057 "%qD appears more than once in data clauses", t
);
7061 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
7062 goto handle_field_decl
;
7065 t
= OMP_CLAUSE_IF_EXPR (c
);
7066 t
= maybe_convert_cond (t
);
7067 if (t
== error_mark_node
)
7069 else if (!processing_template_decl
)
7070 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7071 OMP_CLAUSE_IF_EXPR (c
) = t
;
7074 case OMP_CLAUSE_FINAL
:
7075 t
= OMP_CLAUSE_FINAL_EXPR (c
);
7076 t
= maybe_convert_cond (t
);
7077 if (t
== error_mark_node
)
7079 else if (!processing_template_decl
)
7080 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7081 OMP_CLAUSE_FINAL_EXPR (c
) = t
;
7084 case OMP_CLAUSE_GANG
:
7085 /* Operand 1 is the gang static: argument. */
7086 t
= OMP_CLAUSE_OPERAND (c
, 1);
7089 if (t
== error_mark_node
)
7091 else if (!type_dependent_expression_p (t
)
7092 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7094 error_at (OMP_CLAUSE_LOCATION (c
),
7095 "%<gang%> static expression must be integral");
7100 t
= mark_rvalue_use (t
);
7101 if (!processing_template_decl
)
7103 t
= maybe_constant_value (t
);
7104 if (TREE_CODE (t
) == INTEGER_CST
7105 && tree_int_cst_sgn (t
) != 1
7106 && t
!= integer_minus_one_node
)
7108 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7109 "%<gang%> static value must be "
7111 t
= integer_one_node
;
7113 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7116 OMP_CLAUSE_OPERAND (c
, 1) = t
;
7118 /* Check operand 0, the num argument. */
7121 case OMP_CLAUSE_WORKER
:
7122 case OMP_CLAUSE_VECTOR
:
7123 if (OMP_CLAUSE_OPERAND (c
, 0) == NULL_TREE
)
7127 case OMP_CLAUSE_NUM_TASKS
:
7128 case OMP_CLAUSE_NUM_TEAMS
:
7129 case OMP_CLAUSE_NUM_THREADS
:
7130 case OMP_CLAUSE_NUM_GANGS
:
7131 case OMP_CLAUSE_NUM_WORKERS
:
7132 case OMP_CLAUSE_VECTOR_LENGTH
:
7133 t
= OMP_CLAUSE_OPERAND (c
, 0);
7134 if (t
== error_mark_node
)
7136 else if (!type_dependent_expression_p (t
)
7137 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7139 switch (OMP_CLAUSE_CODE (c
))
7141 case OMP_CLAUSE_GANG
:
7142 error_at (OMP_CLAUSE_LOCATION (c
),
7143 "%<gang%> num expression must be integral"); break;
7144 case OMP_CLAUSE_VECTOR
:
7145 error_at (OMP_CLAUSE_LOCATION (c
),
7146 "%<vector%> length expression must be integral");
7148 case OMP_CLAUSE_WORKER
:
7149 error_at (OMP_CLAUSE_LOCATION (c
),
7150 "%<worker%> num expression must be integral");
7153 error_at (OMP_CLAUSE_LOCATION (c
),
7154 "%qs expression must be integral",
7155 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7161 t
= mark_rvalue_use (t
);
7162 if (!processing_template_decl
)
7164 t
= maybe_constant_value (t
);
7165 if (TREE_CODE (t
) == INTEGER_CST
7166 && tree_int_cst_sgn (t
) != 1)
7168 switch (OMP_CLAUSE_CODE (c
))
7170 case OMP_CLAUSE_GANG
:
7171 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7172 "%<gang%> num value must be positive");
7174 case OMP_CLAUSE_VECTOR
:
7175 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7176 "%<vector%> length value must be "
7179 case OMP_CLAUSE_WORKER
:
7180 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7181 "%<worker%> num value must be "
7185 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7186 "%qs value must be positive",
7187 omp_clause_code_name
7188 [OMP_CLAUSE_CODE (c
)]);
7190 t
= integer_one_node
;
7192 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7194 OMP_CLAUSE_OPERAND (c
, 0) = t
;
7198 case OMP_CLAUSE_SCHEDULE
:
7199 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
7202 else if (t
== error_mark_node
)
7204 else if (!type_dependent_expression_p (t
)
7205 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7207 error_at (OMP_CLAUSE_LOCATION (c
),
7208 "schedule chunk size expression must be integral");
7213 t
= mark_rvalue_use (t
);
7214 if (!processing_template_decl
)
7216 t
= maybe_constant_value (t
);
7217 if (TREE_CODE (t
) == INTEGER_CST
7218 && tree_int_cst_sgn (t
) != 1)
7220 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7221 "chunk size value must be positive");
7222 t
= integer_one_node
;
7224 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7226 OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
) = t
;
7229 schedule_seen
= true;
7232 case OMP_CLAUSE_SIMDLEN
:
7233 case OMP_CLAUSE_SAFELEN
:
7234 t
= OMP_CLAUSE_OPERAND (c
, 0);
7235 if (t
== error_mark_node
)
7237 else if (!type_dependent_expression_p (t
)
7238 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7240 error_at (OMP_CLAUSE_LOCATION (c
),
7241 "%qs length expression must be integral",
7242 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7247 t
= mark_rvalue_use (t
);
7248 if (!processing_template_decl
)
7250 t
= maybe_constant_value (t
);
7251 if (TREE_CODE (t
) != INTEGER_CST
7252 || tree_int_cst_sgn (t
) != 1)
7254 error_at (OMP_CLAUSE_LOCATION (c
),
7255 "%qs length expression must be positive "
7256 "constant integer expression",
7257 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7261 OMP_CLAUSE_OPERAND (c
, 0) = t
;
7262 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SAFELEN
)
7267 case OMP_CLAUSE_ASYNC
:
7268 t
= OMP_CLAUSE_ASYNC_EXPR (c
);
7269 if (t
== error_mark_node
)
7271 else if (!type_dependent_expression_p (t
)
7272 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7274 error_at (OMP_CLAUSE_LOCATION (c
),
7275 "%<async%> expression must be integral");
7280 t
= mark_rvalue_use (t
);
7281 if (!processing_template_decl
)
7282 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7283 OMP_CLAUSE_ASYNC_EXPR (c
) = t
;
7287 case OMP_CLAUSE_WAIT
:
7288 t
= OMP_CLAUSE_WAIT_EXPR (c
);
7289 if (t
== error_mark_node
)
7291 else if (!processing_template_decl
)
7292 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7293 OMP_CLAUSE_WAIT_EXPR (c
) = t
;
7296 case OMP_CLAUSE_THREAD_LIMIT
:
7297 t
= OMP_CLAUSE_THREAD_LIMIT_EXPR (c
);
7298 if (t
== error_mark_node
)
7300 else if (!type_dependent_expression_p (t
)
7301 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7303 error_at (OMP_CLAUSE_LOCATION (c
),
7304 "%<thread_limit%> expression must be integral");
7309 t
= mark_rvalue_use (t
);
7310 if (!processing_template_decl
)
7312 t
= maybe_constant_value (t
);
7313 if (TREE_CODE (t
) == INTEGER_CST
7314 && tree_int_cst_sgn (t
) != 1)
7316 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7317 "%<thread_limit%> value must be positive");
7318 t
= integer_one_node
;
7320 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7322 OMP_CLAUSE_THREAD_LIMIT_EXPR (c
) = t
;
7326 case OMP_CLAUSE_DEVICE
:
7327 t
= OMP_CLAUSE_DEVICE_ID (c
);
7328 if (t
== error_mark_node
)
7330 else if (!type_dependent_expression_p (t
)
7331 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7333 error_at (OMP_CLAUSE_LOCATION (c
),
7334 "%<device%> id must be integral");
7339 t
= mark_rvalue_use (t
);
7340 if (!processing_template_decl
)
7341 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7342 OMP_CLAUSE_DEVICE_ID (c
) = t
;
7346 case OMP_CLAUSE_DIST_SCHEDULE
:
7347 t
= OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
);
7350 else if (t
== error_mark_node
)
7352 else if (!type_dependent_expression_p (t
)
7353 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7355 error_at (OMP_CLAUSE_LOCATION (c
),
7356 "%<dist_schedule%> chunk size expression must be "
7362 t
= mark_rvalue_use (t
);
7363 if (!processing_template_decl
)
7364 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7365 OMP_CLAUSE_DIST_SCHEDULE_CHUNK_EXPR (c
) = t
;
7369 case OMP_CLAUSE_ALIGNED
:
7370 t
= OMP_CLAUSE_DECL (c
);
7371 if (t
== current_class_ptr
&& ort
!= C_ORT_OMP_DECLARE_SIMD
)
7373 error_at (OMP_CLAUSE_LOCATION (c
),
7374 "%<this%> allowed in OpenMP only in %<declare simd%>"
7379 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7381 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7384 error_at (OMP_CLAUSE_LOCATION (c
),
7385 "%qD is not a variable in %<aligned%> clause", t
);
7387 error_at (OMP_CLAUSE_LOCATION (c
),
7388 "%qE is not a variable in %<aligned%> clause", t
);
7391 else if (!type_dependent_expression_p (t
)
7392 && !TYPE_PTR_P (TREE_TYPE (t
))
7393 && TREE_CODE (TREE_TYPE (t
)) != ARRAY_TYPE
7394 && (!TYPE_REF_P (TREE_TYPE (t
))
7395 || (!INDIRECT_TYPE_P (TREE_TYPE (TREE_TYPE (t
)))
7396 && (TREE_CODE (TREE_TYPE (TREE_TYPE (t
)))
7399 error_at (OMP_CLAUSE_LOCATION (c
),
7400 "%qE in %<aligned%> clause is neither a pointer nor "
7401 "an array nor a reference to pointer or array", t
);
7404 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7406 error_at (OMP_CLAUSE_LOCATION (c
),
7407 "%qD appears more than once in %<aligned%> clauses",
7412 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
7413 t
= OMP_CLAUSE_ALIGNED_ALIGNMENT (c
);
7414 if (t
== error_mark_node
)
7416 else if (t
== NULL_TREE
)
7418 else if (!type_dependent_expression_p (t
)
7419 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
7421 error_at (OMP_CLAUSE_LOCATION (c
),
7422 "%<aligned%> clause alignment expression must "
7428 t
= mark_rvalue_use (t
);
7429 if (!processing_template_decl
)
7431 t
= maybe_constant_value (t
);
7432 if (TREE_CODE (t
) != INTEGER_CST
7433 || tree_int_cst_sgn (t
) != 1)
7435 error_at (OMP_CLAUSE_LOCATION (c
),
7436 "%<aligned%> clause alignment expression must "
7437 "be positive constant integer expression");
7441 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
7443 OMP_CLAUSE_ALIGNED_ALIGNMENT (c
) = t
;
7447 case OMP_CLAUSE_NONTEMPORAL
:
7448 t
= OMP_CLAUSE_DECL (c
);
7449 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7451 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7454 error_at (OMP_CLAUSE_LOCATION (c
),
7455 "%qD is not a variable in %<nontemporal%> clause",
7458 error_at (OMP_CLAUSE_LOCATION (c
),
7459 "%qE is not a variable in %<nontemporal%> clause",
7463 else if (bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
7465 error_at (OMP_CLAUSE_LOCATION (c
),
7466 "%qD appears more than once in %<nontemporal%> "
7471 bitmap_set_bit (&oacc_reduction_head
, DECL_UID (t
));
7474 case OMP_CLAUSE_ALLOCATE
:
7475 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
7477 omp_note_field_privatization (t
, OMP_CLAUSE_DECL (c
));
7479 t
= OMP_CLAUSE_DECL (c
);
7480 if (t
== current_class_ptr
)
7482 error_at (OMP_CLAUSE_LOCATION (c
),
7483 "%<this%> not allowed in %<allocate%> clause");
7488 && TREE_CODE (t
) != PARM_DECL
7489 && TREE_CODE (t
) != FIELD_DECL
)
7491 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7494 error_at (OMP_CLAUSE_LOCATION (c
),
7495 "%qD is not a variable in %<allocate%> clause", t
);
7497 error_at (OMP_CLAUSE_LOCATION (c
),
7498 "%qE is not a variable in %<allocate%> clause", t
);
7501 else if (bitmap_bit_p (&aligned_head
, DECL_UID (t
)))
7503 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
7504 "%qD appears more than once in %<allocate%> clauses",
7510 bitmap_set_bit (&aligned_head
, DECL_UID (t
));
7511 allocate_seen
= true;
7514 allocator
= OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
);
7515 if (error_operand_p (allocator
))
7520 if (allocator
== NULL_TREE
)
7521 goto handle_field_decl
;
7523 allocatort
= TYPE_MAIN_VARIANT (TREE_TYPE (allocator
));
7524 if (!type_dependent_expression_p (allocator
)
7525 && (TREE_CODE (allocatort
) != ENUMERAL_TYPE
7526 || TYPE_NAME (allocatort
) == NULL_TREE
7527 || TREE_CODE (TYPE_NAME (allocatort
)) != TYPE_DECL
7528 || (DECL_NAME (TYPE_NAME (allocatort
))
7529 != get_identifier ("omp_allocator_handle_t"))
7530 || (TYPE_CONTEXT (allocatort
)
7531 != DECL_CONTEXT (global_namespace
))))
7533 error_at (OMP_CLAUSE_LOCATION (c
),
7534 "%<allocate%> clause allocator expression has "
7535 "type %qT rather than %<omp_allocator_handle_t%>",
7536 TREE_TYPE (allocator
));
7541 allocator
= mark_rvalue_use (allocator
);
7542 if (!processing_template_decl
)
7543 allocator
= maybe_constant_value (allocator
);
7544 OMP_CLAUSE_ALLOCATE_ALLOCATOR (c
) = allocator
;
7546 goto handle_field_decl
;
7548 case OMP_CLAUSE_DEPEND
:
7549 t
= OMP_CLAUSE_DECL (c
);
7552 gcc_assert (OMP_CLAUSE_DEPEND_KIND (c
)
7553 == OMP_CLAUSE_DEPEND_SOURCE
);
7556 if (OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_SINK
)
7558 if (cp_finish_omp_clause_depend_sink (c
))
7563 case OMP_CLAUSE_AFFINITY
:
7564 t
= OMP_CLAUSE_DECL (c
);
7565 if (TREE_CODE (t
) == TREE_LIST
7567 && TREE_CODE (TREE_PURPOSE (t
)) == TREE_VEC
)
7569 if (TREE_PURPOSE (t
) != last_iterators
)
7570 last_iterators_remove
7571 = cp_omp_finish_iterators (TREE_PURPOSE (t
));
7572 last_iterators
= TREE_PURPOSE (t
);
7574 if (last_iterators_remove
)
7575 t
= error_mark_node
;
7578 last_iterators
= NULL_TREE
;
7580 if (TREE_CODE (t
) == TREE_LIST
)
7582 if (handle_omp_array_sections (c
, ort
))
7584 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
7585 && (OMP_CLAUSE_DEPEND_KIND (c
)
7586 == OMP_CLAUSE_DEPEND_DEPOBJ
))
7588 error_at (OMP_CLAUSE_LOCATION (c
),
7589 "%<depend%> clause with %<depobj%> dependence "
7590 "type on array section");
7595 if (t
== error_mark_node
)
7597 else if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7599 else if (!lvalue_p (t
))
7602 error_at (OMP_CLAUSE_LOCATION (c
),
7603 "%qD is not lvalue expression nor array section "
7605 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7607 error_at (OMP_CLAUSE_LOCATION (c
),
7608 "%qE is not lvalue expression nor array section "
7610 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7613 else if (TREE_CODE (t
) == COMPONENT_REF
7614 && TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7615 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7617 error_at (OMP_CLAUSE_LOCATION (c
),
7618 "bit-field %qE in %qs clause", t
,
7619 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7622 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
7623 && OMP_CLAUSE_DEPEND_KIND (c
) == OMP_CLAUSE_DEPEND_DEPOBJ
)
7625 if (!c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7626 ? TREE_TYPE (TREE_TYPE (t
))
7629 error_at (OMP_CLAUSE_LOCATION (c
),
7630 "%qE does not have %<omp_depend_t%> type in "
7631 "%<depend%> clause with %<depobj%> dependence "
7636 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_DEPEND
7637 && c_omp_depend_t_p (TYPE_REF_P (TREE_TYPE (t
))
7638 ? TREE_TYPE (TREE_TYPE (t
))
7641 error_at (OMP_CLAUSE_LOCATION (c
),
7642 "%qE should not have %<omp_depend_t%> type in "
7643 "%<depend%> clause with dependence type other than "
7649 tree addr
= cp_build_addr_expr (t
, tf_warning_or_error
);
7650 if (addr
== error_mark_node
)
7654 t
= cp_build_indirect_ref (OMP_CLAUSE_LOCATION (c
),
7655 addr
, RO_UNARY_STAR
,
7656 tf_warning_or_error
);
7657 if (t
== error_mark_node
)
7659 else if (TREE_CODE (OMP_CLAUSE_DECL (c
)) == TREE_LIST
7660 && TREE_PURPOSE (OMP_CLAUSE_DECL (c
))
7661 && (TREE_CODE (TREE_PURPOSE (OMP_CLAUSE_DECL (c
)))
7663 TREE_VALUE (OMP_CLAUSE_DECL (c
)) = t
;
7665 OMP_CLAUSE_DECL (c
) = t
;
7669 case OMP_CLAUSE_DETACH
:
7670 t
= OMP_CLAUSE_DECL (c
);
7673 error_at (OMP_CLAUSE_LOCATION (c
),
7674 "too many %qs clauses on a task construct",
7679 else if (error_operand_p (t
))
7686 tree type
= TYPE_MAIN_VARIANT (TREE_TYPE (t
));
7687 if (!type_dependent_expression_p (t
)
7688 && (!INTEGRAL_TYPE_P (type
)
7689 || TREE_CODE (type
) != ENUMERAL_TYPE
7690 || TYPE_NAME (type
) == NULL_TREE
7691 || (DECL_NAME (TYPE_NAME (type
))
7692 != get_identifier ("omp_event_handle_t"))))
7694 error_at (OMP_CLAUSE_LOCATION (c
),
7695 "%<detach%> clause event handle "
7696 "has type %qT rather than "
7697 "%<omp_event_handle_t%>",
7702 cxx_mark_addressable (t
);
7706 case OMP_CLAUSE_MAP
:
7707 if (OMP_CLAUSE_MAP_IMPLICIT (c
) && !implicit_moved
)
7711 case OMP_CLAUSE_FROM
:
7712 case OMP_CLAUSE__CACHE_
:
7713 t
= OMP_CLAUSE_DECL (c
);
7714 if (TREE_CODE (t
) == TREE_LIST
)
7716 if (handle_omp_array_sections (c
, ort
))
7720 t
= OMP_CLAUSE_DECL (c
);
7721 if (TREE_CODE (t
) != TREE_LIST
7722 && !type_dependent_expression_p (t
)
7723 && !cp_omp_mappable_type (TREE_TYPE (t
)))
7725 error_at (OMP_CLAUSE_LOCATION (c
),
7726 "array section does not have mappable type "
7728 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7729 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7732 while (TREE_CODE (t
) == ARRAY_REF
)
7733 t
= TREE_OPERAND (t
, 0);
7734 if (TREE_CODE (t
) == COMPONENT_REF
7735 && TREE_CODE (TREE_TYPE (t
)) == ARRAY_TYPE
)
7737 while (TREE_CODE (t
) == COMPONENT_REF
)
7738 t
= TREE_OPERAND (t
, 0);
7739 if (REFERENCE_REF_P (t
))
7740 t
= TREE_OPERAND (t
, 0);
7741 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7742 && OMP_CLAUSE_MAP_IMPLICIT (c
)
7743 && (bitmap_bit_p (&map_head
, DECL_UID (t
))
7744 || bitmap_bit_p (&map_field_head
, DECL_UID (t
))
7745 || bitmap_bit_p (&map_firstprivate_head
,
7751 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7753 if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7755 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7756 error_at (OMP_CLAUSE_LOCATION (c
),
7757 "%qD appears more than once in motion"
7759 else if (ort
== C_ORT_ACC
)
7760 error_at (OMP_CLAUSE_LOCATION (c
),
7761 "%qD appears more than once in data"
7764 error_at (OMP_CLAUSE_LOCATION (c
),
7765 "%qD appears more than once in map"
7771 bitmap_set_bit (&map_head
, DECL_UID (t
));
7772 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7776 if (cp_oacc_check_attachments (c
))
7778 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7779 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7780 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7781 /* In this case, we have a single array element which is a
7782 pointer, and we already set OMP_CLAUSE_SIZE in
7783 handle_omp_array_sections above. For attach/detach clauses,
7784 reset the OMP_CLAUSE_SIZE (representing a bias) to zero
7786 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
7789 if (t
== error_mark_node
)
7794 /* OpenACC attach / detach clauses must be pointers. */
7795 if (cp_oacc_check_attachments (c
))
7800 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7801 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH
7802 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_DETACH
))
7803 /* For attach/detach clauses, set OMP_CLAUSE_SIZE (representing a
7804 bias) to zero here, so it is not set erroneously to the pointer
7805 size later on in gimplify.c. */
7806 OMP_CLAUSE_SIZE (c
) = size_zero_node
;
7807 if (REFERENCE_REF_P (t
)
7808 && TREE_CODE (TREE_OPERAND (t
, 0)) == COMPONENT_REF
)
7810 t
= TREE_OPERAND (t
, 0);
7811 OMP_CLAUSE_DECL (c
) = t
;
7813 if (TREE_CODE (t
) == COMPONENT_REF
7814 && TREE_CODE (TREE_OPERAND (t
, 0)) == INDIRECT_REF
)
7815 t
= TREE_OPERAND (TREE_OPERAND (t
, 0), 0);
7816 if (TREE_CODE (t
) == COMPONENT_REF
7817 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE__CACHE_
)
7819 if (type_dependent_expression_p (t
))
7821 if (TREE_CODE (TREE_OPERAND (t
, 1)) == FIELD_DECL
7822 && DECL_BIT_FIELD (TREE_OPERAND (t
, 1)))
7824 error_at (OMP_CLAUSE_LOCATION (c
),
7825 "bit-field %qE in %qs clause",
7826 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7829 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
7831 error_at (OMP_CLAUSE_LOCATION (c
),
7832 "%qE does not have a mappable type in %qs clause",
7833 t
, omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7834 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7837 while (TREE_CODE (t
) == COMPONENT_REF
)
7839 if (TREE_TYPE (TREE_OPERAND (t
, 0))
7840 && (TREE_CODE (TREE_TYPE (TREE_OPERAND (t
, 0)))
7843 error_at (OMP_CLAUSE_LOCATION (c
),
7844 "%qE is a member of a union", t
);
7848 t
= TREE_OPERAND (t
, 0);
7852 if (REFERENCE_REF_P (t
))
7853 t
= TREE_OPERAND (t
, 0);
7854 if (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
7856 if (bitmap_bit_p (&map_field_head
, DECL_UID (t
))
7857 || (ort
!= C_ORT_ACC
7858 && bitmap_bit_p (&map_head
, DECL_UID (t
))))
7859 goto handle_map_references
;
7862 if (!VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
7864 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
7866 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7867 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7868 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ALWAYS_POINTER
7869 || OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_ATTACH_DETACH
))
7872 error_at (OMP_CLAUSE_LOCATION (c
),
7873 "%qD is not a variable in %qs clause", t
,
7874 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7876 error_at (OMP_CLAUSE_LOCATION (c
),
7877 "%qE is not a variable in %qs clause", t
,
7878 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7881 else if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
7883 error_at (OMP_CLAUSE_LOCATION (c
),
7884 "%qD is threadprivate variable in %qs clause", t
,
7885 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7888 else if (ort
!= C_ORT_ACC
&& t
== current_class_ptr
)
7890 error_at (OMP_CLAUSE_LOCATION (c
),
7891 "%<this%> allowed in OpenMP only in %<declare simd%>"
7896 else if (!processing_template_decl
7897 && !TYPE_REF_P (TREE_TYPE (t
))
7898 && (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
7899 || (OMP_CLAUSE_MAP_KIND (c
)
7900 != GOMP_MAP_FIRSTPRIVATE_POINTER
))
7901 && !cxx_mark_addressable (t
))
7903 else if (!(OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7904 && (OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_POINTER
7905 || (OMP_CLAUSE_MAP_KIND (c
)
7906 == GOMP_MAP_FIRSTPRIVATE_POINTER
)))
7907 && t
== OMP_CLAUSE_DECL (c
)
7908 && !type_dependent_expression_p (t
)
7909 && !cp_omp_mappable_type (TYPE_REF_P (TREE_TYPE (t
))
7910 ? TREE_TYPE (TREE_TYPE (t
))
7913 error_at (OMP_CLAUSE_LOCATION (c
),
7914 "%qD does not have a mappable type in %qs clause", t
,
7915 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
7916 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
7919 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7920 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FORCE_DEVICEPTR
7921 && !type_dependent_expression_p (t
)
7922 && !INDIRECT_TYPE_P (TREE_TYPE (t
)))
7924 error_at (OMP_CLAUSE_LOCATION (c
),
7925 "%qD is not a pointer variable", t
);
7928 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7929 && OMP_CLAUSE_MAP_IMPLICIT (c
)
7930 && (bitmap_bit_p (&map_head
, DECL_UID (t
))
7931 || bitmap_bit_p (&map_field_head
, DECL_UID (t
))
7932 || bitmap_bit_p (&map_firstprivate_head
,
7935 else if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_MAP
7936 && OMP_CLAUSE_MAP_KIND (c
) == GOMP_MAP_FIRSTPRIVATE_POINTER
)
7938 if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
7939 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
7940 || bitmap_bit_p (&map_firstprivate_head
, DECL_UID (t
)))
7942 error_at (OMP_CLAUSE_LOCATION (c
),
7943 "%qD appears more than once in data clauses", t
);
7946 else if (bitmap_bit_p (&map_head
, DECL_UID (t
)))
7948 if (ort
== C_ORT_ACC
)
7949 error_at (OMP_CLAUSE_LOCATION (c
),
7950 "%qD appears more than once in data clauses", t
);
7952 error_at (OMP_CLAUSE_LOCATION (c
),
7953 "%qD appears both in data and map clauses", t
);
7957 bitmap_set_bit (&map_firstprivate_head
, DECL_UID (t
));
7959 else if (bitmap_bit_p (&map_head
, DECL_UID (t
))
7960 && !bitmap_bit_p (&map_field_head
, DECL_UID (t
)))
7962 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
7963 error_at (OMP_CLAUSE_LOCATION (c
),
7964 "%qD appears more than once in motion clauses", t
);
7965 else if (ort
== C_ORT_ACC
)
7966 error_at (OMP_CLAUSE_LOCATION (c
),
7967 "%qD appears more than once in data clauses", t
);
7969 error_at (OMP_CLAUSE_LOCATION (c
),
7970 "%qD appears more than once in map clauses", t
);
7973 else if (ort
== C_ORT_ACC
7974 && bitmap_bit_p (&generic_head
, DECL_UID (t
)))
7976 error_at (OMP_CLAUSE_LOCATION (c
),
7977 "%qD appears more than once in data clauses", t
);
7980 else if (bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
7982 if (ort
== C_ORT_ACC
)
7983 error_at (OMP_CLAUSE_LOCATION (c
),
7984 "%qD appears more than once in data clauses", t
);
7986 error_at (OMP_CLAUSE_LOCATION (c
),
7987 "%qD appears both in data and map clauses", t
);
7992 bitmap_set_bit (&map_head
, DECL_UID (t
));
7993 if (t
!= OMP_CLAUSE_DECL (c
)
7994 && TREE_CODE (OMP_CLAUSE_DECL (c
)) == COMPONENT_REF
)
7995 bitmap_set_bit (&map_field_head
, DECL_UID (t
));
7997 handle_map_references
:
7999 && !processing_template_decl
8000 && ort
!= C_ORT_DECLARE_SIMD
8001 && TYPE_REF_P (TREE_TYPE (OMP_CLAUSE_DECL (c
))))
8003 t
= OMP_CLAUSE_DECL (c
);
8004 if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_MAP
)
8006 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
8007 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
8009 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
8011 else if (OMP_CLAUSE_MAP_KIND (c
)
8012 != GOMP_MAP_FIRSTPRIVATE_POINTER
8013 && (OMP_CLAUSE_MAP_KIND (c
)
8014 != GOMP_MAP_FIRSTPRIVATE_REFERENCE
)
8015 && (OMP_CLAUSE_MAP_KIND (c
)
8016 != GOMP_MAP_ALWAYS_POINTER
)
8017 && (OMP_CLAUSE_MAP_KIND (c
)
8018 != GOMP_MAP_ATTACH_DETACH
))
8020 tree c2
= build_omp_clause (OMP_CLAUSE_LOCATION (c
),
8022 if (TREE_CODE (t
) == COMPONENT_REF
)
8023 OMP_CLAUSE_SET_MAP_KIND (c2
, GOMP_MAP_ATTACH_DETACH
);
8025 OMP_CLAUSE_SET_MAP_KIND (c2
,
8026 GOMP_MAP_FIRSTPRIVATE_REFERENCE
);
8027 OMP_CLAUSE_DECL (c2
) = t
;
8028 OMP_CLAUSE_SIZE (c2
) = size_zero_node
;
8029 OMP_CLAUSE_CHAIN (c2
) = OMP_CLAUSE_CHAIN (c
);
8030 OMP_CLAUSE_CHAIN (c
) = c2
;
8031 OMP_CLAUSE_DECL (c
) = build_simple_mem_ref (t
);
8032 if (OMP_CLAUSE_SIZE (c
) == NULL_TREE
)
8034 = TYPE_SIZE_UNIT (TREE_TYPE (TREE_TYPE (t
)));
8040 case OMP_CLAUSE_TO_DECLARE
:
8041 case OMP_CLAUSE_LINK
:
8042 t
= OMP_CLAUSE_DECL (c
);
8043 if (TREE_CODE (t
) == FUNCTION_DECL
8044 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
8046 else if (!VAR_P (t
))
8048 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TO_DECLARE
)
8050 if (TREE_CODE (t
) == TEMPLATE_ID_EXPR
)
8051 error_at (OMP_CLAUSE_LOCATION (c
),
8052 "template %qE in clause %qs", t
,
8053 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8054 else if (really_overloaded_fn (t
))
8055 error_at (OMP_CLAUSE_LOCATION (c
),
8056 "overloaded function name %qE in clause %qs", t
,
8057 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8059 error_at (OMP_CLAUSE_LOCATION (c
),
8060 "%qE is neither a variable nor a function name "
8062 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8065 error_at (OMP_CLAUSE_LOCATION (c
),
8066 "%qE is not a variable in clause %qs", t
,
8067 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8070 else if (DECL_THREAD_LOCAL_P (t
))
8072 error_at (OMP_CLAUSE_LOCATION (c
),
8073 "%qD is threadprivate variable in %qs clause", t
,
8074 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8077 else if (!cp_omp_mappable_type (TREE_TYPE (t
)))
8079 error_at (OMP_CLAUSE_LOCATION (c
),
8080 "%qD does not have a mappable type in %qs clause", t
,
8081 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8082 cp_omp_emit_unmappable_type_notes (TREE_TYPE (t
));
8087 if (bitmap_bit_p (&generic_head
, DECL_UID (t
)))
8089 error_at (OMP_CLAUSE_LOCATION (c
),
8090 "%qE appears more than once on the same "
8091 "%<declare target%> directive", t
);
8095 bitmap_set_bit (&generic_head
, DECL_UID (t
));
8098 case OMP_CLAUSE_UNIFORM
:
8099 t
= OMP_CLAUSE_DECL (c
);
8100 if (TREE_CODE (t
) != PARM_DECL
)
8102 if (processing_template_decl
)
8105 error_at (OMP_CLAUSE_LOCATION (c
),
8106 "%qD is not an argument in %<uniform%> clause", t
);
8108 error_at (OMP_CLAUSE_LOCATION (c
),
8109 "%qE is not an argument in %<uniform%> clause", t
);
8113 /* map_head bitmap is used as uniform_head if declare_simd. */
8114 bitmap_set_bit (&map_head
, DECL_UID (t
));
8115 goto check_dup_generic
;
8117 case OMP_CLAUSE_GRAINSIZE
:
8118 t
= OMP_CLAUSE_GRAINSIZE_EXPR (c
);
8119 if (t
== error_mark_node
)
8121 else if (!type_dependent_expression_p (t
)
8122 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8124 error_at (OMP_CLAUSE_LOCATION (c
),
8125 "%<grainsize%> expression must be integral");
8130 t
= mark_rvalue_use (t
);
8131 if (!processing_template_decl
)
8133 t
= maybe_constant_value (t
);
8134 if (TREE_CODE (t
) == INTEGER_CST
8135 && tree_int_cst_sgn (t
) != 1)
8137 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
8138 "%<grainsize%> value must be positive");
8139 t
= integer_one_node
;
8141 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8143 OMP_CLAUSE_GRAINSIZE_EXPR (c
) = t
;
8147 case OMP_CLAUSE_PRIORITY
:
8148 t
= OMP_CLAUSE_PRIORITY_EXPR (c
);
8149 if (t
== error_mark_node
)
8151 else if (!type_dependent_expression_p (t
)
8152 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8154 error_at (OMP_CLAUSE_LOCATION (c
),
8155 "%<priority%> expression must be integral");
8160 t
= mark_rvalue_use (t
);
8161 if (!processing_template_decl
)
8163 t
= maybe_constant_value (t
);
8164 if (TREE_CODE (t
) == INTEGER_CST
8165 && tree_int_cst_sgn (t
) == -1)
8167 warning_at (OMP_CLAUSE_LOCATION (c
), 0,
8168 "%<priority%> value must be non-negative");
8169 t
= integer_one_node
;
8171 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8173 OMP_CLAUSE_PRIORITY_EXPR (c
) = t
;
8177 case OMP_CLAUSE_HINT
:
8178 t
= OMP_CLAUSE_HINT_EXPR (c
);
8179 if (t
== error_mark_node
)
8181 else if (!type_dependent_expression_p (t
)
8182 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8184 error_at (OMP_CLAUSE_LOCATION (c
),
8185 "%<hint%> expression must be integral");
8190 t
= mark_rvalue_use (t
);
8191 if (!processing_template_decl
)
8193 t
= maybe_constant_value (t
);
8194 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8195 if (TREE_CODE (t
) != INTEGER_CST
)
8197 error_at (OMP_CLAUSE_LOCATION (c
),
8198 "%<hint%> expression must be constant integer "
8203 OMP_CLAUSE_HINT_EXPR (c
) = t
;
8207 case OMP_CLAUSE_FILTER
:
8208 t
= OMP_CLAUSE_FILTER_EXPR (c
);
8209 if (t
== error_mark_node
)
8211 else if (!type_dependent_expression_p (t
)
8212 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8214 error_at (OMP_CLAUSE_LOCATION (c
),
8215 "%<filter%> expression must be integral");
8220 t
= mark_rvalue_use (t
);
8221 if (!processing_template_decl
)
8223 t
= maybe_constant_value (t
);
8224 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8226 OMP_CLAUSE_FILTER_EXPR (c
) = t
;
8230 case OMP_CLAUSE_IS_DEVICE_PTR
:
8231 case OMP_CLAUSE_USE_DEVICE_PTR
:
8232 field_ok
= (ort
& C_ORT_OMP_DECLARE_SIMD
) == C_ORT_OMP
;
8233 t
= OMP_CLAUSE_DECL (c
);
8234 if (!type_dependent_expression_p (t
))
8236 tree type
= TREE_TYPE (t
);
8237 if (!TYPE_PTR_P (type
)
8238 && (!TYPE_REF_P (type
) || !TYPE_PTR_P (TREE_TYPE (type
))))
8240 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_USE_DEVICE_PTR
8241 && ort
== C_ORT_OMP
)
8243 error_at (OMP_CLAUSE_LOCATION (c
),
8244 "%qs variable is neither a pointer "
8245 "nor reference to pointer",
8246 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8249 else if (TREE_CODE (type
) != ARRAY_TYPE
8250 && (!TYPE_REF_P (type
)
8251 || TREE_CODE (TREE_TYPE (type
)) != ARRAY_TYPE
))
8253 error_at (OMP_CLAUSE_LOCATION (c
),
8254 "%qs variable is neither a pointer, nor an "
8255 "array nor reference to pointer or array",
8256 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8261 goto check_dup_generic
;
8263 case OMP_CLAUSE_USE_DEVICE_ADDR
:
8265 t
= OMP_CLAUSE_DECL (c
);
8266 if (!processing_template_decl
8267 && (VAR_P (t
) || TREE_CODE (t
) == PARM_DECL
)
8268 && !TYPE_REF_P (TREE_TYPE (t
))
8269 && !cxx_mark_addressable (t
))
8271 goto check_dup_generic
;
8273 case OMP_CLAUSE_NOWAIT
:
8274 case OMP_CLAUSE_DEFAULT
:
8275 case OMP_CLAUSE_UNTIED
:
8276 case OMP_CLAUSE_COLLAPSE
:
8277 case OMP_CLAUSE_PARALLEL
:
8278 case OMP_CLAUSE_FOR
:
8279 case OMP_CLAUSE_SECTIONS
:
8280 case OMP_CLAUSE_TASKGROUP
:
8281 case OMP_CLAUSE_PROC_BIND
:
8282 case OMP_CLAUSE_DEVICE_TYPE
:
8283 case OMP_CLAUSE_NOGROUP
:
8284 case OMP_CLAUSE_THREADS
:
8285 case OMP_CLAUSE_SIMD
:
8286 case OMP_CLAUSE_DEFAULTMAP
:
8287 case OMP_CLAUSE_BIND
:
8288 case OMP_CLAUSE_AUTO
:
8289 case OMP_CLAUSE_INDEPENDENT
:
8290 case OMP_CLAUSE_SEQ
:
8291 case OMP_CLAUSE_IF_PRESENT
:
8292 case OMP_CLAUSE_FINALIZE
:
8293 case OMP_CLAUSE_NOHOST
:
8296 case OMP_CLAUSE_MERGEABLE
:
8297 mergeable_seen
= true;
8300 case OMP_CLAUSE_TILE
:
8301 for (tree list
= OMP_CLAUSE_TILE_LIST (c
); !remove
&& list
;
8302 list
= TREE_CHAIN (list
))
8304 t
= TREE_VALUE (list
);
8306 if (t
== error_mark_node
)
8308 else if (!type_dependent_expression_p (t
)
8309 && !INTEGRAL_TYPE_P (TREE_TYPE (t
)))
8311 error_at (OMP_CLAUSE_LOCATION (c
),
8312 "%<tile%> argument needs integral type");
8317 t
= mark_rvalue_use (t
);
8318 if (!processing_template_decl
)
8320 /* Zero is used to indicate '*', we permit you
8321 to get there via an ICE of value zero. */
8322 t
= maybe_constant_value (t
);
8323 if (!tree_fits_shwi_p (t
)
8324 || tree_to_shwi (t
) < 0)
8326 error_at (OMP_CLAUSE_LOCATION (c
),
8327 "%<tile%> argument needs positive "
8328 "integral constant");
8331 t
= fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
8335 /* Update list item. */
8336 TREE_VALUE (list
) = t
;
8340 case OMP_CLAUSE_ORDERED
:
8341 ordered_seen
= true;
8344 case OMP_CLAUSE_ORDER
:
8351 case OMP_CLAUSE_INBRANCH
:
8352 case OMP_CLAUSE_NOTINBRANCH
:
8355 error_at (OMP_CLAUSE_LOCATION (c
),
8356 "%<inbranch%> clause is incompatible with "
8363 case OMP_CLAUSE_INCLUSIVE
:
8364 case OMP_CLAUSE_EXCLUSIVE
:
8365 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8367 t
= OMP_CLAUSE_DECL (c
);
8368 if (t
== current_class_ptr
)
8370 error_at (OMP_CLAUSE_LOCATION (c
),
8371 "%<this%> allowed in OpenMP only in %<declare simd%>"
8377 && TREE_CODE (t
) != PARM_DECL
8378 && TREE_CODE (t
) != FIELD_DECL
)
8380 if (processing_template_decl
&& TREE_CODE (t
) != OVERLOAD
)
8383 error_at (OMP_CLAUSE_LOCATION (c
),
8384 "%qD is not a variable in clause %qs", t
,
8385 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8387 error_at (OMP_CLAUSE_LOCATION (c
),
8388 "%qE is not a variable in clause %qs", t
,
8389 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8399 *pc
= OMP_CLAUSE_CHAIN (c
);
8401 pc
= &OMP_CLAUSE_CHAIN (c
);
8404 if (reduction_seen
< 0 && (ordered_seen
|| schedule_seen
))
8405 reduction_seen
= -2;
8407 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
8409 enum omp_clause_code c_kind
= OMP_CLAUSE_CODE (c
);
8410 bool remove
= false;
8411 bool need_complete_type
= false;
8412 bool need_default_ctor
= false;
8413 bool need_copy_ctor
= false;
8414 bool need_copy_assignment
= false;
8415 bool need_implicitly_determined
= false;
8416 bool need_dtor
= false;
8417 tree type
, inner_type
;
8421 case OMP_CLAUSE_SHARED
:
8422 need_implicitly_determined
= true;
8424 case OMP_CLAUSE_PRIVATE
:
8425 need_complete_type
= true;
8426 need_default_ctor
= true;
8428 need_implicitly_determined
= true;
8430 case OMP_CLAUSE_FIRSTPRIVATE
:
8431 need_complete_type
= true;
8432 need_copy_ctor
= true;
8434 need_implicitly_determined
= true;
8436 case OMP_CLAUSE_LASTPRIVATE
:
8437 need_complete_type
= true;
8438 need_copy_assignment
= true;
8439 need_implicitly_determined
= true;
8441 case OMP_CLAUSE_REDUCTION
:
8442 if (reduction_seen
== -2)
8443 OMP_CLAUSE_REDUCTION_INSCAN (c
) = 0;
8444 if (OMP_CLAUSE_REDUCTION_INSCAN (c
))
8445 need_copy_assignment
= true;
8446 need_implicitly_determined
= true;
8448 case OMP_CLAUSE_IN_REDUCTION
:
8449 case OMP_CLAUSE_TASK_REDUCTION
:
8450 case OMP_CLAUSE_INCLUSIVE
:
8451 case OMP_CLAUSE_EXCLUSIVE
:
8452 need_implicitly_determined
= true;
8454 case OMP_CLAUSE_LINEAR
:
8455 if (ort
!= C_ORT_OMP_DECLARE_SIMD
)
8456 need_implicitly_determined
= true;
8457 else if (OMP_CLAUSE_LINEAR_VARIABLE_STRIDE (c
)
8458 && !bitmap_bit_p (&map_head
,
8459 DECL_UID (OMP_CLAUSE_LINEAR_STEP (c
))))
8461 error_at (OMP_CLAUSE_LOCATION (c
),
8462 "%<linear%> clause step is a parameter %qD not "
8463 "specified in %<uniform%> clause",
8464 OMP_CLAUSE_LINEAR_STEP (c
));
8465 *pc
= OMP_CLAUSE_CHAIN (c
);
8469 case OMP_CLAUSE_COPYPRIVATE
:
8470 need_copy_assignment
= true;
8472 case OMP_CLAUSE_COPYIN
:
8473 need_copy_assignment
= true;
8475 case OMP_CLAUSE_SIMDLEN
:
8477 && !processing_template_decl
8478 && tree_int_cst_lt (OMP_CLAUSE_SAFELEN_EXPR (safelen
),
8479 OMP_CLAUSE_SIMDLEN_EXPR (c
)))
8481 error_at (OMP_CLAUSE_LOCATION (c
),
8482 "%<simdlen%> clause value is bigger than "
8483 "%<safelen%> clause value");
8484 OMP_CLAUSE_SIMDLEN_EXPR (c
)
8485 = OMP_CLAUSE_SAFELEN_EXPR (safelen
);
8487 pc
= &OMP_CLAUSE_CHAIN (c
);
8489 case OMP_CLAUSE_SCHEDULE
:
8491 && (OMP_CLAUSE_SCHEDULE_KIND (c
)
8492 & OMP_CLAUSE_SCHEDULE_NONMONOTONIC
))
8494 error_at (OMP_CLAUSE_LOCATION (c
),
8495 "%<nonmonotonic%> schedule modifier specified "
8496 "together with %<ordered%> clause");
8497 OMP_CLAUSE_SCHEDULE_KIND (c
)
8498 = (enum omp_clause_schedule_kind
)
8499 (OMP_CLAUSE_SCHEDULE_KIND (c
)
8500 & ~OMP_CLAUSE_SCHEDULE_NONMONOTONIC
);
8502 if (reduction_seen
== -2)
8503 error_at (OMP_CLAUSE_LOCATION (c
),
8504 "%qs clause specified together with %<inscan%> "
8505 "%<reduction%> clause", "schedule");
8506 pc
= &OMP_CLAUSE_CHAIN (c
);
8508 case OMP_CLAUSE_NOGROUP
:
8511 error_at (OMP_CLAUSE_LOCATION (c
),
8512 "%<nogroup%> clause must not be used together with "
8513 "%<reduction%> clause");
8514 *pc
= OMP_CLAUSE_CHAIN (c
);
8517 pc
= &OMP_CLAUSE_CHAIN (c
);
8519 case OMP_CLAUSE_ORDERED
:
8520 if (reduction_seen
== -2)
8521 error_at (OMP_CLAUSE_LOCATION (c
),
8522 "%qs clause specified together with %<inscan%> "
8523 "%<reduction%> clause", "ordered");
8524 pc
= &OMP_CLAUSE_CHAIN (c
);
8526 case OMP_CLAUSE_ORDER
:
8529 error_at (OMP_CLAUSE_LOCATION (c
),
8530 "%<order%> clause must not be used together "
8531 "with %<ordered%>");
8532 *pc
= OMP_CLAUSE_CHAIN (c
);
8535 pc
= &OMP_CLAUSE_CHAIN (c
);
8537 case OMP_CLAUSE_DETACH
:
8540 error_at (OMP_CLAUSE_LOCATION (c
),
8541 "%<detach%> clause must not be used together with "
8542 "%<mergeable%> clause");
8543 *pc
= OMP_CLAUSE_CHAIN (c
);
8546 pc
= &OMP_CLAUSE_CHAIN (c
);
8548 case OMP_CLAUSE_MAP
:
8549 if (target_in_reduction_seen
&& !processing_template_decl
)
8551 t
= OMP_CLAUSE_DECL (c
);
8552 while (handled_component_p (t
)
8553 || TREE_CODE (t
) == INDIRECT_REF
8554 || TREE_CODE (t
) == ADDR_EXPR
8555 || TREE_CODE (t
) == MEM_REF
8556 || TREE_CODE (t
) == NON_LVALUE_EXPR
)
8557 t
= TREE_OPERAND (t
, 0);
8559 && bitmap_bit_p (&oacc_reduction_head
, DECL_UID (t
)))
8560 OMP_CLAUSE_MAP_IN_REDUCTION (c
) = 1;
8562 pc
= &OMP_CLAUSE_CHAIN (c
);
8564 case OMP_CLAUSE_NOWAIT
:
8565 if (copyprivate_seen
)
8567 error_at (OMP_CLAUSE_LOCATION (c
),
8568 "%<nowait%> clause must not be used together "
8569 "with %<copyprivate%>");
8570 *pc
= OMP_CLAUSE_CHAIN (c
);
8575 pc
= &OMP_CLAUSE_CHAIN (c
);
8579 t
= OMP_CLAUSE_DECL (c
);
8582 case OMP_CLAUSE_LASTPRIVATE
:
8584 && !bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
8586 need_default_ctor
= true;
8591 case OMP_CLAUSE_REDUCTION
:
8592 case OMP_CLAUSE_IN_REDUCTION
:
8593 case OMP_CLAUSE_TASK_REDUCTION
:
8596 if (TREE_CODE (t
) == MEM_REF
)
8598 t
= TREE_OPERAND (t
, 0);
8599 if (TREE_CODE (t
) == POINTER_PLUS_EXPR
)
8600 t
= TREE_OPERAND (t
, 0);
8601 if (TREE_CODE (t
) == ADDR_EXPR
8602 || TREE_CODE (t
) == INDIRECT_REF
)
8603 t
= TREE_OPERAND (t
, 0);
8605 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8607 else if (TREE_CODE (t
) == TREE_LIST
)
8609 while (TREE_CODE (t
) == TREE_LIST
)
8612 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8613 t
= OMP_CLAUSE_DECL (c
);
8615 else if (DECL_P (t
))
8616 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8617 t
= OMP_CLAUSE_DECL (c
);
8619 if (processing_template_decl
8620 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8622 if (finish_omp_reduction_clause (c
, &need_default_ctor
,
8626 t
= OMP_CLAUSE_DECL (c
);
8629 case OMP_CLAUSE_COPYIN
:
8630 if (processing_template_decl
8631 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8633 if (!VAR_P (t
) || !CP_DECL_THREAD_LOCAL_P (t
))
8635 error_at (OMP_CLAUSE_LOCATION (c
),
8636 "%qE must be %<threadprivate%> for %<copyin%>", t
);
8645 if (processing_template_decl
8646 && !VAR_P (t
) && TREE_CODE (t
) != PARM_DECL
)
8648 pc
= &OMP_CLAUSE_CHAIN (c
);
8652 if (need_complete_type
|| need_copy_assignment
)
8654 t
= require_complete_type (t
);
8655 if (t
== error_mark_node
)
8657 else if (!processing_template_decl
8658 && TYPE_REF_P (TREE_TYPE (t
))
8659 && !complete_type_or_else (TREE_TYPE (TREE_TYPE (t
)), t
))
8662 if (need_implicitly_determined
)
8664 const char *share_name
= NULL
;
8667 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8669 bitmap_clear_bit (&aligned_head
, DECL_UID (t
));
8671 if (VAR_P (t
) && CP_DECL_THREAD_LOCAL_P (t
))
8672 share_name
= "threadprivate";
8673 else switch (cxx_omp_predetermined_sharing_1 (t
))
8675 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
8677 case OMP_CLAUSE_DEFAULT_SHARED
:
8678 if ((OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8679 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
)
8680 && c_omp_predefined_variable (t
))
8681 /* The __func__ variable and similar function-local predefined
8682 variables may be listed in a shared or firstprivate
8686 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8688 && cxx_omp_const_qual_no_mutable (t
))
8690 tree ctx
= CP_DECL_CONTEXT (t
);
8691 /* const qualified static data members without mutable
8692 member may be specified in firstprivate clause. */
8693 if (TYPE_P (ctx
) && MAYBE_CLASS_TYPE_P (ctx
))
8696 share_name
= "shared";
8698 case OMP_CLAUSE_DEFAULT_PRIVATE
:
8699 share_name
= "private";
8706 error_at (OMP_CLAUSE_LOCATION (c
),
8707 "%qE is predetermined %qs for %qs",
8708 omp_clause_printable_decl (t
), share_name
,
8709 omp_clause_code_name
[OMP_CLAUSE_CODE (c
)]);
8712 else if (OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_SHARED
8713 && OMP_CLAUSE_CODE (c
) != OMP_CLAUSE_FIRSTPRIVATE
8714 && cxx_omp_const_qual_no_mutable (t
))
8716 error_at (OMP_CLAUSE_LOCATION (c
),
8717 "%<const%> qualified %qE without %<mutable%> member "
8718 "may appear only in %<shared%> or %<firstprivate%> "
8719 "clauses", omp_clause_printable_decl (t
));
8725 && (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_SHARED
8726 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
8727 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_FIRSTPRIVATE
8728 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
)
8729 && OMP_CLAUSE_DECL (c
) == OMP_CLAUSE_DECL (detach_seen
))
8731 error_at (OMP_CLAUSE_LOCATION (c
),
8732 "the event handle of a %<detach%> clause "
8733 "should not be in a data-sharing clause");
8737 /* We're interested in the base element, not arrays. */
8738 inner_type
= type
= TREE_TYPE (t
);
8739 if ((need_complete_type
8740 || need_copy_assignment
8741 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_REDUCTION
8742 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_IN_REDUCTION
8743 || OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_TASK_REDUCTION
)
8744 && TYPE_REF_P (inner_type
))
8745 inner_type
= TREE_TYPE (inner_type
);
8746 while (TREE_CODE (inner_type
) == ARRAY_TYPE
)
8747 inner_type
= TREE_TYPE (inner_type
);
8749 /* Check for special function availability by building a call to one.
8750 Save the results, because later we won't be in the right context
8751 for making these queries. */
8752 if (CLASS_TYPE_P (inner_type
)
8753 && COMPLETE_TYPE_P (inner_type
)
8754 && (need_default_ctor
|| need_copy_ctor
8755 || need_copy_assignment
|| need_dtor
)
8756 && !type_dependent_expression_p (t
)
8757 && cxx_omp_create_clause_info (c
, inner_type
, need_default_ctor
,
8758 need_copy_ctor
, need_copy_assignment
,
8763 && c_kind
== OMP_CLAUSE_SHARED
8764 && processing_template_decl
)
8766 t
= omp_clause_decl_field (OMP_CLAUSE_DECL (c
));
8768 OMP_CLAUSE_DECL (c
) = t
;
8772 *pc
= OMP_CLAUSE_CHAIN (c
);
8774 pc
= &OMP_CLAUSE_CHAIN (c
);
8778 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
8780 bool remove
= false;
8781 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_ALLOCATE
8782 && !OMP_CLAUSE_ALLOCATE_COMBINED (c
)
8783 && DECL_P (OMP_CLAUSE_DECL (c
))
8784 && bitmap_bit_p (&aligned_head
, DECL_UID (OMP_CLAUSE_DECL (c
))))
8786 error_at (OMP_CLAUSE_LOCATION (c
),
8787 "%qD specified in %<allocate%> clause but not in "
8788 "an explicit privatization clause", OMP_CLAUSE_DECL (c
));
8792 *pc
= OMP_CLAUSE_CHAIN (c
);
8794 pc
= &OMP_CLAUSE_CHAIN (c
);
8797 bitmap_obstack_release (NULL
);
8801 /* Start processing OpenMP clauses that can include any
8802 privatization clauses for non-static data members. */
8805 push_omp_privatization_clauses (bool ignore_next
)
8807 if (omp_private_member_ignore_next
)
8809 omp_private_member_ignore_next
= ignore_next
;
8812 omp_private_member_ignore_next
= ignore_next
;
8813 if (omp_private_member_map
)
8814 omp_private_member_vec
.safe_push (error_mark_node
);
8815 return push_stmt_list ();
8818 /* Revert remapping of any non-static data members since
8819 the last push_omp_privatization_clauses () call. */
8822 pop_omp_privatization_clauses (tree stmt
)
8824 if (stmt
== NULL_TREE
)
8826 stmt
= pop_stmt_list (stmt
);
8827 if (omp_private_member_map
)
8829 while (!omp_private_member_vec
.is_empty ())
8831 tree t
= omp_private_member_vec
.pop ();
8832 if (t
== error_mark_node
)
8837 bool no_decl_expr
= t
== integer_zero_node
;
8839 t
= omp_private_member_vec
.pop ();
8840 tree
*v
= omp_private_member_map
->get (t
);
8844 omp_private_member_map
->remove (t
);
8846 delete omp_private_member_map
;
8847 omp_private_member_map
= NULL
;
8852 /* Remember OpenMP privatization clauses mapping and clear it.
8853 Used for lambdas. */
8856 save_omp_privatization_clauses (vec
<tree
> &save
)
8859 if (omp_private_member_ignore_next
)
8860 save
.safe_push (integer_one_node
);
8861 omp_private_member_ignore_next
= false;
8862 if (!omp_private_member_map
)
8865 while (!omp_private_member_vec
.is_empty ())
8867 tree t
= omp_private_member_vec
.pop ();
8868 if (t
== error_mark_node
)
8874 if (t
== integer_zero_node
)
8875 t
= omp_private_member_vec
.pop ();
8876 tree
*v
= omp_private_member_map
->get (t
);
8878 save
.safe_push (*v
);
8883 delete omp_private_member_map
;
8884 omp_private_member_map
= NULL
;
8887 /* Restore OpenMP privatization clauses mapping saved by the
8891 restore_omp_privatization_clauses (vec
<tree
> &save
)
8893 gcc_assert (omp_private_member_vec
.is_empty ());
8894 omp_private_member_ignore_next
= false;
8895 if (save
.is_empty ())
8897 if (save
.length () == 1 && save
[0] == integer_one_node
)
8899 omp_private_member_ignore_next
= true;
8904 omp_private_member_map
= new hash_map
<tree
, tree
>;
8905 while (!save
.is_empty ())
8907 tree t
= save
.pop ();
8909 if (t
!= error_mark_node
)
8911 if (t
== integer_one_node
)
8913 omp_private_member_ignore_next
= true;
8914 gcc_assert (save
.is_empty ());
8917 if (t
== integer_zero_node
)
8919 tree
&v
= omp_private_member_map
->get_or_insert (t
);
8922 omp_private_member_vec
.safe_push (t
);
8924 omp_private_member_vec
.safe_push (n
);
8929 /* For all variables in the tree_list VARS, mark them as thread local. */
8932 finish_omp_threadprivate (tree vars
)
8936 /* Mark every variable in VARS to be assigned thread local storage. */
8937 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
8939 tree v
= TREE_PURPOSE (t
);
8941 if (error_operand_p (v
))
8943 else if (!VAR_P (v
))
8944 error ("%<threadprivate%> %qD is not file, namespace "
8945 "or block scope variable", v
);
8946 /* If V had already been marked threadprivate, it doesn't matter
8947 whether it had been used prior to this point. */
8948 else if (TREE_USED (v
)
8949 && (DECL_LANG_SPECIFIC (v
) == NULL
8950 || !CP_DECL_THREADPRIVATE_P (v
)))
8951 error ("%qE declared %<threadprivate%> after first use", v
);
8952 else if (! TREE_STATIC (v
) && ! DECL_EXTERNAL (v
))
8953 error ("automatic variable %qE cannot be %<threadprivate%>", v
);
8954 else if (! COMPLETE_TYPE_P (complete_type (TREE_TYPE (v
))))
8955 error ("%<threadprivate%> %qE has incomplete type", v
);
8956 else if (TREE_STATIC (v
) && TYPE_P (CP_DECL_CONTEXT (v
))
8957 && CP_DECL_CONTEXT (v
) != current_class_type
)
8958 error ("%<threadprivate%> %qE directive not "
8959 "in %qT definition", v
, CP_DECL_CONTEXT (v
));
8962 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
8963 if (DECL_LANG_SPECIFIC (v
) == NULL
)
8964 retrofit_lang_decl (v
);
8966 if (! CP_DECL_THREAD_LOCAL_P (v
))
8968 CP_DECL_THREAD_LOCAL_P (v
) = true;
8969 set_decl_tls_model (v
, decl_default_tls_model (v
));
8970 /* If rtl has been already set for this var, call
8971 make_decl_rtl once again, so that encode_section_info
8972 has a chance to look at the new decl flags. */
8973 if (DECL_RTL_SET_P (v
))
8976 CP_DECL_THREADPRIVATE_P (v
) = 1;
8981 /* Build an OpenMP structured block. */
8984 begin_omp_structured_block (void)
8986 return do_pushlevel (sk_omp
);
8990 finish_omp_structured_block (tree block
)
8992 return do_poplevel (block
);
8995 /* Similarly, except force the retention of the BLOCK. */
8998 begin_omp_parallel (void)
9000 keep_next_level (true);
9001 return begin_omp_structured_block ();
9004 /* Generate OACC_DATA, with CLAUSES and BLOCK as its compound
9008 finish_oacc_data (tree clauses
, tree block
)
9012 block
= finish_omp_structured_block (block
);
9014 stmt
= make_node (OACC_DATA
);
9015 TREE_TYPE (stmt
) = void_type_node
;
9016 OACC_DATA_CLAUSES (stmt
) = clauses
;
9017 OACC_DATA_BODY (stmt
) = block
;
9019 return add_stmt (stmt
);
9022 /* Generate OACC_HOST_DATA, with CLAUSES and BLOCK as its compound
9026 finish_oacc_host_data (tree clauses
, tree block
)
9030 block
= finish_omp_structured_block (block
);
9032 stmt
= make_node (OACC_HOST_DATA
);
9033 TREE_TYPE (stmt
) = void_type_node
;
9034 OACC_HOST_DATA_CLAUSES (stmt
) = clauses
;
9035 OACC_HOST_DATA_BODY (stmt
) = block
;
9037 return add_stmt (stmt
);
9040 /* Generate OMP construct CODE, with BODY and CLAUSES as its compound
9044 finish_omp_construct (enum tree_code code
, tree body
, tree clauses
)
9046 body
= finish_omp_structured_block (body
);
9048 tree stmt
= make_node (code
);
9049 TREE_TYPE (stmt
) = void_type_node
;
9050 OMP_BODY (stmt
) = body
;
9051 OMP_CLAUSES (stmt
) = clauses
;
9053 return add_stmt (stmt
);
9057 finish_omp_parallel (tree clauses
, tree body
)
9061 body
= finish_omp_structured_block (body
);
9063 stmt
= make_node (OMP_PARALLEL
);
9064 TREE_TYPE (stmt
) = void_type_node
;
9065 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
9066 OMP_PARALLEL_BODY (stmt
) = body
;
9068 return add_stmt (stmt
);
9072 begin_omp_task (void)
9074 keep_next_level (true);
9075 return begin_omp_structured_block ();
9079 finish_omp_task (tree clauses
, tree body
)
9083 body
= finish_omp_structured_block (body
);
9085 stmt
= make_node (OMP_TASK
);
9086 TREE_TYPE (stmt
) = void_type_node
;
9087 OMP_TASK_CLAUSES (stmt
) = clauses
;
9088 OMP_TASK_BODY (stmt
) = body
;
9090 return add_stmt (stmt
);
9093 /* Helper function for finish_omp_for. Convert Ith random access iterator
9094 into integral iterator. Return FALSE if successful. */
9097 handle_omp_for_class_iterator (int i
, location_t locus
, enum tree_code code
,
9098 tree declv
, tree orig_declv
, tree initv
,
9099 tree condv
, tree incrv
, tree
*body
,
9100 tree
*pre_body
, tree
&clauses
,
9101 int collapse
, int ordered
)
9103 tree diff
, iter_init
, iter_incr
= NULL
, last
;
9104 tree incr_var
= NULL
, orig_pre_body
, orig_body
, c
;
9105 tree decl
= TREE_VEC_ELT (declv
, i
);
9106 tree init
= TREE_VEC_ELT (initv
, i
);
9107 tree cond
= TREE_VEC_ELT (condv
, i
);
9108 tree incr
= TREE_VEC_ELT (incrv
, i
);
9110 location_t elocus
= locus
;
9112 if (init
&& EXPR_HAS_LOCATION (init
))
9113 elocus
= EXPR_LOCATION (init
);
9115 switch (TREE_CODE (cond
))
9122 if (TREE_OPERAND (cond
, 1) == iter
)
9123 cond
= build2 (swap_tree_comparison (TREE_CODE (cond
)),
9124 TREE_TYPE (cond
), iter
, TREE_OPERAND (cond
, 0));
9125 if (TREE_OPERAND (cond
, 0) != iter
)
9126 cond
= error_mark_node
;
9129 tree tem
= build_x_binary_op (EXPR_LOCATION (cond
),
9132 TREE_OPERAND (cond
, 1), ERROR_MARK
,
9133 NULL
, tf_warning_or_error
);
9134 if (error_operand_p (tem
))
9139 cond
= error_mark_node
;
9142 if (cond
== error_mark_node
)
9144 error_at (elocus
, "invalid controlling predicate");
9147 diff
= build_x_binary_op (elocus
, MINUS_EXPR
, TREE_OPERAND (cond
, 1),
9148 ERROR_MARK
, iter
, ERROR_MARK
, NULL
,
9149 tf_warning_or_error
);
9150 diff
= cp_fully_fold (diff
);
9151 if (error_operand_p (diff
))
9153 if (TREE_CODE (TREE_TYPE (diff
)) != INTEGER_TYPE
)
9155 error_at (elocus
, "difference between %qE and %qD does not have integer type",
9156 TREE_OPERAND (cond
, 1), iter
);
9159 if (!c_omp_check_loop_iv_exprs (locus
, orig_declv
, i
,
9160 TREE_VEC_ELT (declv
, i
), NULL_TREE
,
9161 cond
, cp_walk_subtrees
))
9164 switch (TREE_CODE (incr
))
9166 case PREINCREMENT_EXPR
:
9167 case PREDECREMENT_EXPR
:
9168 case POSTINCREMENT_EXPR
:
9169 case POSTDECREMENT_EXPR
:
9170 if (TREE_OPERAND (incr
, 0) != iter
)
9172 incr
= error_mark_node
;
9175 iter_incr
= build_x_unary_op (EXPR_LOCATION (incr
),
9176 TREE_CODE (incr
), iter
,
9177 tf_warning_or_error
);
9178 if (error_operand_p (iter_incr
))
9180 else if (TREE_CODE (incr
) == PREINCREMENT_EXPR
9181 || TREE_CODE (incr
) == POSTINCREMENT_EXPR
)
9182 incr
= integer_one_node
;
9184 incr
= integer_minus_one_node
;
9187 if (TREE_OPERAND (incr
, 0) != iter
)
9188 incr
= error_mark_node
;
9189 else if (TREE_CODE (TREE_OPERAND (incr
, 1)) == PLUS_EXPR
9190 || TREE_CODE (TREE_OPERAND (incr
, 1)) == MINUS_EXPR
)
9192 tree rhs
= TREE_OPERAND (incr
, 1);
9193 if (TREE_OPERAND (rhs
, 0) == iter
)
9195 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 1)))
9197 incr
= error_mark_node
;
9200 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
9201 iter
, TREE_CODE (rhs
),
9202 TREE_OPERAND (rhs
, 1),
9203 tf_warning_or_error
);
9204 if (error_operand_p (iter_incr
))
9206 incr
= TREE_OPERAND (rhs
, 1);
9207 incr
= cp_convert (TREE_TYPE (diff
), incr
,
9208 tf_warning_or_error
);
9209 if (TREE_CODE (rhs
) == MINUS_EXPR
)
9211 incr
= build1 (NEGATE_EXPR
, TREE_TYPE (diff
), incr
);
9212 incr
= fold_simple (incr
);
9214 if (TREE_CODE (incr
) != INTEGER_CST
9215 && (TREE_CODE (incr
) != NOP_EXPR
9216 || (TREE_CODE (TREE_OPERAND (incr
, 0))
9221 else if (TREE_OPERAND (rhs
, 1) == iter
)
9223 if (TREE_CODE (TREE_TYPE (TREE_OPERAND (rhs
, 0))) != INTEGER_TYPE
9224 || TREE_CODE (rhs
) != PLUS_EXPR
)
9225 incr
= error_mark_node
;
9228 iter_incr
= build_x_binary_op (EXPR_LOCATION (rhs
),
9230 TREE_OPERAND (rhs
, 0),
9233 tf_warning_or_error
);
9234 if (error_operand_p (iter_incr
))
9236 iter_incr
= build_x_modify_expr (EXPR_LOCATION (rhs
),
9239 tf_warning_or_error
);
9240 if (error_operand_p (iter_incr
))
9242 incr
= TREE_OPERAND (rhs
, 0);
9247 incr
= error_mark_node
;
9250 incr
= error_mark_node
;
9253 incr
= error_mark_node
;
9257 if (incr
== error_mark_node
)
9259 error_at (elocus
, "invalid increment expression");
9263 incr
= cp_convert (TREE_TYPE (diff
), incr
, tf_warning_or_error
);
9264 incr
= cp_fully_fold (incr
);
9265 tree loop_iv_seen
= NULL_TREE
;
9266 for (c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9267 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9268 && OMP_CLAUSE_DECL (c
) == iter
)
9270 if (code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
9273 OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
) = 1;
9277 else if ((code
== OMP_TASKLOOP
|| code
== OMP_LOOP
)
9278 && OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_PRIVATE
9279 && OMP_CLAUSE_DECL (c
) == iter
)
9282 if (code
== OMP_TASKLOOP
)
9283 OMP_CLAUSE_PRIVATE_TASKLOOP_IV (c
) = 1;
9286 decl
= create_temporary_var (TREE_TYPE (diff
));
9288 add_decl_expr (decl
);
9289 last
= create_temporary_var (TREE_TYPE (diff
));
9291 add_decl_expr (last
);
9292 if (c
&& iter_incr
== NULL
&& TREE_CODE (incr
) != INTEGER_CST
9293 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
9295 incr_var
= create_temporary_var (TREE_TYPE (diff
));
9296 pushdecl (incr_var
);
9297 add_decl_expr (incr_var
);
9299 gcc_assert (stmts_are_full_exprs_p ());
9300 tree diffvar
= NULL_TREE
;
9301 if (code
== OMP_TASKLOOP
)
9305 tree ivc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9306 OMP_CLAUSE_DECL (ivc
) = iter
;
9307 cxx_omp_finish_clause (ivc
, NULL
, false);
9308 OMP_CLAUSE_CHAIN (ivc
) = clauses
;
9311 tree lvc
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9312 OMP_CLAUSE_DECL (lvc
) = last
;
9313 OMP_CLAUSE_CHAIN (lvc
) = clauses
;
9315 diffvar
= create_temporary_var (TREE_TYPE (diff
));
9317 add_decl_expr (diffvar
);
9319 else if (code
== OMP_LOOP
)
9323 /* While iterators on the loop construct are predetermined
9324 lastprivate, if the decl is not declared inside of the
9325 loop, OMP_CLAUSE_LASTPRIVATE should have been added
9327 loop_iv_seen
= build_omp_clause (locus
, OMP_CLAUSE_FIRSTPRIVATE
);
9328 OMP_CLAUSE_DECL (loop_iv_seen
) = iter
;
9329 OMP_CLAUSE_CHAIN (loop_iv_seen
) = clauses
;
9330 clauses
= loop_iv_seen
;
9332 else if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_PRIVATE
)
9334 OMP_CLAUSE_PRIVATE_DEBUG (loop_iv_seen
) = 0;
9335 OMP_CLAUSE_PRIVATE_OUTER_REF (loop_iv_seen
) = 0;
9336 OMP_CLAUSE_CODE (loop_iv_seen
) = OMP_CLAUSE_FIRSTPRIVATE
;
9338 if (OMP_CLAUSE_CODE (loop_iv_seen
) == OMP_CLAUSE_FIRSTPRIVATE
)
9339 cxx_omp_finish_clause (loop_iv_seen
, NULL
, false);
9342 orig_pre_body
= *pre_body
;
9343 *pre_body
= push_stmt_list ();
9345 add_stmt (orig_pre_body
);
9347 finish_expr_stmt (build_x_modify_expr (elocus
,
9348 iter
, NOP_EXPR
, init
,
9349 tf_warning_or_error
));
9350 init
= build_int_cst (TREE_TYPE (diff
), 0);
9351 if (c
&& iter_incr
== NULL
9352 && (!ordered
|| (i
< collapse
&& collapse
> 1)))
9356 finish_expr_stmt (build_x_modify_expr (elocus
,
9358 incr
, tf_warning_or_error
));
9361 iter_incr
= build_x_modify_expr (elocus
,
9362 iter
, PLUS_EXPR
, incr
,
9363 tf_warning_or_error
);
9365 if (c
&& ordered
&& i
< collapse
&& collapse
> 1)
9367 finish_expr_stmt (build_x_modify_expr (elocus
,
9368 last
, NOP_EXPR
, init
,
9369 tf_warning_or_error
));
9372 finish_expr_stmt (build_x_modify_expr (elocus
,
9374 diff
, tf_warning_or_error
));
9377 *pre_body
= pop_stmt_list (*pre_body
);
9379 cond
= cp_build_binary_op (elocus
,
9380 TREE_CODE (cond
), decl
, diff
,
9381 tf_warning_or_error
);
9382 incr
= build_modify_expr (elocus
, decl
, NULL_TREE
, PLUS_EXPR
,
9383 elocus
, incr
, NULL_TREE
);
9386 *body
= push_stmt_list ();
9387 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), decl
, last
);
9388 iter_init
= build_x_modify_expr (elocus
,
9389 iter
, PLUS_EXPR
, iter_init
,
9390 tf_warning_or_error
);
9391 if (iter_init
!= error_mark_node
)
9392 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
9393 finish_expr_stmt (iter_init
);
9394 finish_expr_stmt (build_x_modify_expr (elocus
,
9395 last
, NOP_EXPR
, decl
,
9396 tf_warning_or_error
));
9397 add_stmt (orig_body
);
9398 *body
= pop_stmt_list (*body
);
9402 OMP_CLAUSE_LASTPRIVATE_STMT (c
) = push_stmt_list ();
9404 finish_expr_stmt (iter_incr
);
9408 if (i
< collapse
&& collapse
> 1 && !error_operand_p (iter_incr
))
9409 iter_init
= build2 (PLUS_EXPR
, TREE_TYPE (diff
),
9410 iter_init
, iter_incr
);
9411 iter_init
= build2 (MINUS_EXPR
, TREE_TYPE (diff
), iter_init
, last
);
9412 iter_init
= build_x_modify_expr (elocus
,
9413 iter
, PLUS_EXPR
, iter_init
,
9414 tf_warning_or_error
);
9415 if (iter_init
!= error_mark_node
)
9416 iter_init
= build1 (NOP_EXPR
, void_type_node
, iter_init
);
9417 finish_expr_stmt (iter_init
);
9419 OMP_CLAUSE_LASTPRIVATE_STMT (c
)
9420 = pop_stmt_list (OMP_CLAUSE_LASTPRIVATE_STMT (c
));
9423 if (TREE_CODE (TREE_VEC_ELT (orig_declv
, i
)) == TREE_LIST
)
9425 tree t
= TREE_VEC_ELT (orig_declv
, i
);
9426 gcc_assert (TREE_PURPOSE (t
) == NULL_TREE
9427 && TREE_VALUE (t
) == NULL_TREE
9428 && TREE_CODE (TREE_CHAIN (t
)) == TREE_VEC
);
9429 TREE_PURPOSE (t
) = TREE_VEC_ELT (declv
, i
);
9430 TREE_VALUE (t
) = last
;
9433 TREE_VEC_ELT (orig_declv
, i
)
9434 = tree_cons (TREE_VEC_ELT (declv
, i
), last
, NULL_TREE
);
9435 TREE_VEC_ELT (declv
, i
) = decl
;
9436 TREE_VEC_ELT (initv
, i
) = init
;
9437 TREE_VEC_ELT (condv
, i
) = cond
;
9438 TREE_VEC_ELT (incrv
, i
) = incr
;
9443 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
9444 are directly for their associated operands in the statement. DECL
9445 and INIT are a combo; if DECL is NULL then INIT ought to be a
9446 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
9447 optional statements that need to go before the loop into its
9451 finish_omp_for (location_t locus
, enum tree_code code
, tree declv
,
9452 tree orig_declv
, tree initv
, tree condv
, tree incrv
,
9453 tree body
, tree pre_body
, vec
<tree
> *orig_inits
, tree clauses
)
9455 tree omp_for
= NULL
, orig_incr
= NULL
;
9456 tree decl
= NULL
, init
, cond
, incr
;
9462 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (initv
));
9463 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (condv
));
9464 gcc_assert (TREE_VEC_LENGTH (declv
) == TREE_VEC_LENGTH (incrv
));
9465 if (TREE_VEC_LENGTH (declv
) > 1)
9469 c
= omp_find_clause (clauses
, OMP_CLAUSE_TILE
);
9471 collapse
= list_length (OMP_CLAUSE_TILE_LIST (c
));
9474 c
= omp_find_clause (clauses
, OMP_CLAUSE_COLLAPSE
);
9476 collapse
= tree_to_shwi (OMP_CLAUSE_COLLAPSE_EXPR (c
));
9477 if (collapse
!= TREE_VEC_LENGTH (declv
))
9478 ordered
= TREE_VEC_LENGTH (declv
);
9481 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
9483 decl
= TREE_VEC_ELT (declv
, i
);
9484 init
= TREE_VEC_ELT (initv
, i
);
9485 cond
= TREE_VEC_ELT (condv
, i
);
9486 incr
= TREE_VEC_ELT (incrv
, i
);
9492 switch (TREE_CODE (init
))
9495 decl
= TREE_OPERAND (init
, 0);
9496 init
= TREE_OPERAND (init
, 1);
9499 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
9501 decl
= TREE_OPERAND (init
, 0);
9502 init
= TREE_OPERAND (init
, 2);
9512 "expected iteration declaration or initialization");
9517 if (init
&& EXPR_HAS_LOCATION (init
))
9518 elocus
= EXPR_LOCATION (init
);
9520 if (cond
== global_namespace
)
9525 error_at (elocus
, "missing controlling predicate");
9531 error_at (elocus
, "missing increment expression");
9535 TREE_VEC_ELT (declv
, i
) = decl
;
9536 TREE_VEC_ELT (initv
, i
) = init
;
9543 FOR_EACH_VEC_ELT (*orig_inits
, i
, orig_init
)
9545 && !c_omp_check_loop_iv_exprs (locus
,
9546 orig_declv
? orig_declv
: declv
, i
,
9547 TREE_VEC_ELT (declv
, i
), orig_init
,
9548 NULL_TREE
, cp_walk_subtrees
))
9554 if (dependent_omp_for_p (declv
, initv
, condv
, incrv
))
9558 stmt
= make_node (code
);
9560 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); i
++)
9562 /* This is really just a place-holder. We'll be decomposing this
9563 again and going through the cp_build_modify_expr path below when
9564 we instantiate the thing. */
9565 TREE_VEC_ELT (initv
, i
)
9566 = build2 (MODIFY_EXPR
, void_type_node
, TREE_VEC_ELT (declv
, i
),
9567 TREE_VEC_ELT (initv
, i
));
9570 TREE_TYPE (stmt
) = void_type_node
;
9571 OMP_FOR_INIT (stmt
) = initv
;
9572 OMP_FOR_COND (stmt
) = condv
;
9573 OMP_FOR_INCR (stmt
) = incrv
;
9574 OMP_FOR_BODY (stmt
) = body
;
9575 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
9576 OMP_FOR_CLAUSES (stmt
) = clauses
;
9578 SET_EXPR_LOCATION (stmt
, locus
);
9579 return add_stmt (stmt
);
9583 orig_declv
= copy_node (declv
);
9585 if (processing_template_decl
)
9586 orig_incr
= make_tree_vec (TREE_VEC_LENGTH (incrv
));
9588 for (i
= 0; i
< TREE_VEC_LENGTH (declv
); )
9590 decl
= TREE_VEC_ELT (declv
, i
);
9591 init
= TREE_VEC_ELT (initv
, i
);
9592 cond
= TREE_VEC_ELT (condv
, i
);
9593 incr
= TREE_VEC_ELT (incrv
, i
);
9595 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9598 if (init
&& EXPR_HAS_LOCATION (init
))
9599 elocus
= EXPR_LOCATION (init
);
9603 error_at (elocus
, "expected iteration declaration or initialization");
9607 if (incr
&& TREE_CODE (incr
) == MODOP_EXPR
)
9610 TREE_VEC_ELT (orig_incr
, i
) = incr
;
9611 incr
= cp_build_modify_expr (elocus
, TREE_OPERAND (incr
, 0),
9612 TREE_CODE (TREE_OPERAND (incr
, 1)),
9613 TREE_OPERAND (incr
, 2),
9614 tf_warning_or_error
);
9617 if (CLASS_TYPE_P (TREE_TYPE (decl
)))
9619 if (code
== OMP_SIMD
)
9621 error_at (elocus
, "%<#pragma omp simd%> used with class "
9622 "iteration variable %qE", decl
);
9625 if (handle_omp_for_class_iterator (i
, locus
, code
, declv
, orig_declv
,
9626 initv
, condv
, incrv
, &body
,
9633 if (!INTEGRAL_TYPE_P (TREE_TYPE (decl
))
9634 && !TYPE_PTR_P (TREE_TYPE (decl
)))
9636 error_at (elocus
, "invalid type for iteration variable %qE", decl
);
9640 if (!processing_template_decl
&& TREE_CODE (init
) != TREE_VEC
)
9641 init
= cp_build_modify_expr (elocus
, decl
, NOP_EXPR
, init
,
9642 tf_warning_or_error
);
9644 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
9645 if (decl
== error_mark_node
|| init
== error_mark_node
)
9648 TREE_VEC_ELT (declv
, i
) = decl
;
9649 TREE_VEC_ELT (initv
, i
) = init
;
9650 TREE_VEC_ELT (condv
, i
) = cond
;
9651 TREE_VEC_ELT (incrv
, i
) = incr
;
9655 if (pre_body
&& IS_EMPTY_STMT (pre_body
))
9658 omp_for
= c_finish_omp_for (locus
, code
, declv
, orig_declv
, initv
, condv
,
9659 incrv
, body
, pre_body
,
9660 !processing_template_decl
);
9662 /* Check for iterators appearing in lb, b or incr expressions. */
9663 if (omp_for
&& !c_omp_check_loop_iv (omp_for
, orig_declv
, cp_walk_subtrees
))
9664 omp_for
= NULL_TREE
;
9666 if (omp_for
== NULL
)
9671 for (i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)); i
++)
9673 init
= TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), i
);
9674 decl
= TREE_OPERAND (init
, 0);
9675 cond
= TREE_VEC_ELT (OMP_FOR_COND (omp_for
), i
);
9676 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
);
9678 if (!processing_template_decl
)
9680 if (TREE_CODE (TREE_OPERAND (init
, 1)) == TREE_VEC
)
9682 tree t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1);
9683 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 1)
9684 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9685 t
= TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2);
9686 TREE_VEC_ELT (TREE_OPERAND (init
, 1), 2)
9687 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9691 tree t
= TREE_OPERAND (init
, 1);
9692 TREE_OPERAND (init
, 1)
9693 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9695 if (TREE_CODE (TREE_OPERAND (cond
, 1)) == TREE_VEC
)
9697 tree t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1);
9698 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 1)
9699 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9700 t
= TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2);
9701 TREE_VEC_ELT (TREE_OPERAND (cond
, 1), 2)
9702 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9706 tree t
= TREE_OPERAND (cond
, 1);
9707 TREE_OPERAND (cond
, 1)
9708 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9712 if (TREE_CODE (incr
) != MODIFY_EXPR
)
9715 if (TREE_SIDE_EFFECTS (TREE_OPERAND (incr
, 1))
9716 && BINARY_CLASS_P (TREE_OPERAND (incr
, 1))
9717 && !processing_template_decl
)
9719 tree t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 0);
9720 if (TREE_SIDE_EFFECTS (t
)
9722 && (TREE_CODE (t
) != NOP_EXPR
9723 || TREE_OPERAND (t
, 0) != decl
))
9724 TREE_OPERAND (TREE_OPERAND (incr
, 1), 0)
9725 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9727 t
= TREE_OPERAND (TREE_OPERAND (incr
, 1), 1);
9728 if (TREE_SIDE_EFFECTS (t
)
9730 && (TREE_CODE (t
) != NOP_EXPR
9731 || TREE_OPERAND (t
, 0) != decl
))
9732 TREE_OPERAND (TREE_OPERAND (incr
, 1), 1)
9733 = fold_build_cleanup_point_expr (TREE_TYPE (t
), t
);
9737 TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), i
) = TREE_VEC_ELT (orig_incr
, i
);
9739 OMP_FOR_CLAUSES (omp_for
) = clauses
;
9741 /* For simd loops with non-static data member iterators, we could have added
9742 OMP_CLAUSE_LINEAR clauses without OMP_CLAUSE_LINEAR_STEP. As we know the
9743 step at this point, fill it in. */
9744 if (code
== OMP_SIMD
&& !processing_template_decl
9745 && TREE_VEC_LENGTH (OMP_FOR_INCR (omp_for
)) == 1)
9746 for (tree c
= omp_find_clause (clauses
, OMP_CLAUSE_LINEAR
); c
;
9747 c
= omp_find_clause (OMP_CLAUSE_CHAIN (c
), OMP_CLAUSE_LINEAR
))
9748 if (OMP_CLAUSE_LINEAR_STEP (c
) == NULL_TREE
)
9750 decl
= TREE_OPERAND (TREE_VEC_ELT (OMP_FOR_INIT (omp_for
), 0), 0);
9751 gcc_assert (decl
== OMP_CLAUSE_DECL (c
));
9752 incr
= TREE_VEC_ELT (OMP_FOR_INCR (omp_for
), 0);
9754 switch (TREE_CODE (incr
))
9756 case PREINCREMENT_EXPR
:
9757 case POSTINCREMENT_EXPR
:
9758 /* c_omp_for_incr_canonicalize_ptr() should have been
9759 called to massage things appropriately. */
9760 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9761 OMP_CLAUSE_LINEAR_STEP (c
) = build_int_cst (TREE_TYPE (decl
), 1);
9763 case PREDECREMENT_EXPR
:
9764 case POSTDECREMENT_EXPR
:
9765 /* c_omp_for_incr_canonicalize_ptr() should have been
9766 called to massage things appropriately. */
9767 gcc_assert (!INDIRECT_TYPE_P (TREE_TYPE (decl
)));
9768 OMP_CLAUSE_LINEAR_STEP (c
)
9769 = build_int_cst (TREE_TYPE (decl
), -1);
9772 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9773 incr
= TREE_OPERAND (incr
, 1);
9774 switch (TREE_CODE (incr
))
9777 if (TREE_OPERAND (incr
, 1) == decl
)
9778 step
= TREE_OPERAND (incr
, 0);
9780 step
= TREE_OPERAND (incr
, 1);
9783 case POINTER_PLUS_EXPR
:
9784 gcc_assert (TREE_OPERAND (incr
, 0) == decl
);
9785 step
= TREE_OPERAND (incr
, 1);
9790 stept
= TREE_TYPE (decl
);
9791 if (INDIRECT_TYPE_P (stept
))
9793 step
= fold_convert (stept
, step
);
9794 if (TREE_CODE (incr
) == MINUS_EXPR
)
9795 step
= fold_build1 (NEGATE_EXPR
, stept
, step
);
9796 OMP_CLAUSE_LINEAR_STEP (c
) = step
;
9802 /* Override saved methods on OMP_LOOP's OMP_CLAUSE_LASTPRIVATE_LOOP_IV
9803 clauses, we need copy ctor for those rather than default ctor,
9804 plus as for other lastprivates assignment op and dtor. */
9805 if (code
== OMP_LOOP
&& !processing_template_decl
)
9806 for (tree c
= clauses
; c
; c
= OMP_CLAUSE_CHAIN (c
))
9807 if (OMP_CLAUSE_CODE (c
) == OMP_CLAUSE_LASTPRIVATE
9808 && OMP_CLAUSE_LASTPRIVATE_LOOP_IV (c
)
9809 && cxx_omp_create_clause_info (c
, TREE_TYPE (OMP_CLAUSE_DECL (c
)),
9810 false, true, true, true))
9811 CP_OMP_CLAUSE_INFO (c
) = NULL_TREE
;
9816 /* Fix up range for decls. Those decls were pushed into BIND's BIND_EXPR_VARS
9817 and need to be moved into the BIND_EXPR inside of the OMP_FOR's body. */
9820 finish_omp_for_block (tree bind
, tree omp_for
)
9822 if (omp_for
== NULL_TREE
9823 || !OMP_FOR_ORIG_DECLS (omp_for
)
9824 || bind
== NULL_TREE
9825 || TREE_CODE (bind
) != BIND_EXPR
)
9828 for (int i
= 0; i
< TREE_VEC_LENGTH (OMP_FOR_INIT (omp_for
)); i
++)
9829 if (TREE_CODE (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)) == TREE_LIST
9830 && TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
)))
9832 tree v
= TREE_CHAIN (TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (omp_for
), i
));
9833 gcc_assert (BIND_EXPR_BLOCK (bind
)
9834 && (BIND_EXPR_VARS (bind
)
9835 == BLOCK_VARS (BIND_EXPR_BLOCK (bind
))));
9836 for (int j
= 2; j
< TREE_VEC_LENGTH (v
); j
++)
9837 for (tree
*p
= &BIND_EXPR_VARS (bind
); *p
; p
= &DECL_CHAIN (*p
))
9839 if (*p
== TREE_VEC_ELT (v
, j
))
9842 *p
= DECL_CHAIN (*p
);
9845 b
= make_node (BLOCK
);
9846 b
= build3 (BIND_EXPR
, void_type_node
, NULL_TREE
,
9847 OMP_FOR_BODY (omp_for
), b
);
9848 TREE_SIDE_EFFECTS (b
) = 1;
9849 OMP_FOR_BODY (omp_for
) = b
;
9851 DECL_CHAIN (var
) = BIND_EXPR_VARS (b
);
9852 BIND_EXPR_VARS (b
) = var
;
9853 BLOCK_VARS (BIND_EXPR_BLOCK (b
)) = var
;
9856 BLOCK_VARS (BIND_EXPR_BLOCK (bind
)) = BIND_EXPR_VARS (bind
);
9862 finish_omp_atomic (location_t loc
, enum tree_code code
, enum tree_code opcode
,
9863 tree lhs
, tree rhs
, tree v
, tree lhs1
, tree rhs1
,
9864 tree clauses
, enum omp_memory_order mo
)
9879 dependent_p
= false;
9882 /* Even in a template, we can detect invalid uses of the atomic
9883 pragma if neither LHS nor RHS is type-dependent. */
9884 if (processing_template_decl
)
9886 dependent_p
= (type_dependent_expression_p (lhs
)
9887 || (rhs
&& type_dependent_expression_p (rhs
))
9888 || (v
&& type_dependent_expression_p (v
))
9889 || (lhs1
&& type_dependent_expression_p (lhs1
))
9890 || (rhs1
&& type_dependent_expression_p (rhs1
)));
9893 gcc_assert (TREE_CODE (clauses
) == OMP_CLAUSE
9894 && OMP_CLAUSE_CODE (clauses
) == OMP_CLAUSE_HINT
9895 && OMP_CLAUSE_CHAIN (clauses
) == NULL_TREE
);
9896 if (type_dependent_expression_p (OMP_CLAUSE_HINT_EXPR (clauses
))
9897 || TREE_CODE (OMP_CLAUSE_HINT_EXPR (clauses
)) != INTEGER_CST
)
9902 lhs
= build_non_dependent_expr (lhs
);
9904 rhs
= build_non_dependent_expr (rhs
);
9906 v
= build_non_dependent_expr (v
);
9908 lhs1
= build_non_dependent_expr (lhs1
);
9910 rhs1
= build_non_dependent_expr (rhs1
);
9915 bool swapped
= false;
9916 if (rhs1
&& cp_tree_equal (lhs
, rhs
))
9918 std::swap (rhs
, rhs1
);
9919 swapped
= !commutative_tree_code (opcode
);
9921 if (rhs1
&& !cp_tree_equal (lhs
, rhs1
))
9923 if (code
== OMP_ATOMIC
)
9924 error ("%<#pragma omp atomic update%> uses two different "
9925 "expressions for memory");
9927 error ("%<#pragma omp atomic capture%> uses two different "
9928 "expressions for memory");
9931 if (lhs1
&& !cp_tree_equal (lhs
, lhs1
))
9933 if (code
== OMP_ATOMIC
)
9934 error ("%<#pragma omp atomic update%> uses two different "
9935 "expressions for memory");
9937 error ("%<#pragma omp atomic capture%> uses two different "
9938 "expressions for memory");
9941 stmt
= c_finish_omp_atomic (loc
, code
, opcode
, lhs
, rhs
,
9942 v
, lhs1
, rhs1
, swapped
, mo
,
9943 processing_template_decl
!= 0);
9944 if (stmt
== error_mark_node
)
9947 if (processing_template_decl
)
9949 if (code
== OMP_ATOMIC_READ
)
9951 stmt
= build_min_nt_loc (loc
, OMP_ATOMIC_READ
, orig_lhs
);
9952 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9953 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9957 if (opcode
== NOP_EXPR
)
9958 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_lhs
, orig_rhs
);
9960 stmt
= build2 (opcode
, void_type_node
, orig_lhs
, orig_rhs
);
9962 stmt
= build_min_nt_loc (EXPR_LOCATION (orig_rhs1
),
9963 COMPOUND_EXPR
, orig_rhs1
, stmt
);
9964 if (code
!= OMP_ATOMIC
)
9966 stmt
= build_min_nt_loc (loc
, code
, orig_lhs1
, stmt
);
9967 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9968 stmt
= build2 (MODIFY_EXPR
, void_type_node
, orig_v
, stmt
);
9971 stmt
= build2 (OMP_ATOMIC
, void_type_node
,
9972 clauses
? clauses
: integer_zero_node
, stmt
);
9973 OMP_ATOMIC_MEMORY_ORDER (stmt
) = mo
;
9974 SET_EXPR_LOCATION (stmt
, loc
);
9977 /* Avoid -Wunused-value warnings here, the whole construct has side-effects
9978 and even if it might be wrapped from fold-const.c or c-omp.c wrapped
9979 in some tree that appears to be unused, the value is not unused. */
9980 warning_sentinel
w (warn_unused_value
);
9981 finish_expr_stmt (stmt
);
9985 finish_omp_barrier (void)
9987 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_BARRIER
);
9989 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
9990 finish_expr_stmt (stmt
);
9994 finish_omp_depobj (location_t loc
, tree depobj
,
9995 enum omp_clause_depend_kind kind
, tree clause
)
9997 if (!error_operand_p (depobj
) && !type_dependent_expression_p (depobj
))
9999 if (!lvalue_p (depobj
))
10001 error_at (EXPR_LOC_OR_LOC (depobj
, loc
),
10002 "%<depobj%> expression is not lvalue expression");
10003 depobj
= error_mark_node
;
10007 if (processing_template_decl
)
10009 if (clause
== NULL_TREE
)
10010 clause
= build_int_cst (integer_type_node
, kind
);
10011 add_stmt (build_min_nt_loc (loc
, OMP_DEPOBJ
, depobj
, clause
));
10015 if (!error_operand_p (depobj
))
10017 tree addr
= cp_build_addr_expr (depobj
, tf_warning_or_error
);
10018 if (addr
== error_mark_node
)
10019 depobj
= error_mark_node
;
10021 depobj
= cp_build_indirect_ref (loc
, addr
, RO_UNARY_STAR
,
10022 tf_warning_or_error
);
10025 c_finish_omp_depobj (loc
, depobj
, kind
, clause
);
10029 finish_omp_flush (int mo
)
10031 tree fn
= builtin_decl_explicit (BUILT_IN_SYNC_SYNCHRONIZE
);
10033 if (mo
!= MEMMODEL_LAST
)
10035 fn
= builtin_decl_explicit (BUILT_IN_ATOMIC_THREAD_FENCE
);
10036 vec
->quick_push (build_int_cst (integer_type_node
, mo
));
10038 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10039 finish_expr_stmt (stmt
);
10043 finish_omp_taskwait (void)
10045 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKWAIT
);
10047 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10048 finish_expr_stmt (stmt
);
10052 finish_omp_taskyield (void)
10054 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_TASKYIELD
);
10056 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10057 finish_expr_stmt (stmt
);
10061 finish_omp_cancel (tree clauses
)
10063 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCEL
);
10065 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
10067 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
10069 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
10071 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
10075 error ("%<#pragma omp cancel%> must specify one of "
10076 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
10080 tree ifc
= omp_find_clause (clauses
, OMP_CLAUSE_IF
);
10081 if (ifc
!= NULL_TREE
)
10083 if (OMP_CLAUSE_IF_MODIFIER (ifc
) != ERROR_MARK
10084 && OMP_CLAUSE_IF_MODIFIER (ifc
) != VOID_CST
)
10085 error_at (OMP_CLAUSE_LOCATION (ifc
),
10086 "expected %<cancel%> %<if%> clause modifier");
10089 tree ifc2
= omp_find_clause (OMP_CLAUSE_CHAIN (ifc
), OMP_CLAUSE_IF
);
10090 if (ifc2
!= NULL_TREE
)
10092 gcc_assert (OMP_CLAUSE_IF_MODIFIER (ifc
) == VOID_CST
10093 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != ERROR_MARK
10094 && OMP_CLAUSE_IF_MODIFIER (ifc2
) != VOID_CST
);
10095 error_at (OMP_CLAUSE_LOCATION (ifc2
),
10096 "expected %<cancel%> %<if%> clause modifier");
10100 if (!processing_template_decl
)
10101 ifc
= maybe_convert_cond (OMP_CLAUSE_IF_EXPR (ifc
));
10103 ifc
= build_x_binary_op (OMP_CLAUSE_LOCATION (ifc
), NE_EXPR
,
10104 OMP_CLAUSE_IF_EXPR (ifc
), ERROR_MARK
,
10105 integer_zero_node
, ERROR_MARK
,
10106 NULL
, tf_warning_or_error
);
10109 ifc
= boolean_true_node
;
10110 vec
->quick_push (build_int_cst (integer_type_node
, mask
));
10111 vec
->quick_push (ifc
);
10112 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10113 finish_expr_stmt (stmt
);
10117 finish_omp_cancellation_point (tree clauses
)
10119 tree fn
= builtin_decl_explicit (BUILT_IN_GOMP_CANCELLATION_POINT
);
10121 if (omp_find_clause (clauses
, OMP_CLAUSE_PARALLEL
))
10123 else if (omp_find_clause (clauses
, OMP_CLAUSE_FOR
))
10125 else if (omp_find_clause (clauses
, OMP_CLAUSE_SECTIONS
))
10127 else if (omp_find_clause (clauses
, OMP_CLAUSE_TASKGROUP
))
10131 error ("%<#pragma omp cancellation point%> must specify one of "
10132 "%<parallel%>, %<for%>, %<sections%> or %<taskgroup%> clauses");
10136 = make_tree_vector_single (build_int_cst (integer_type_node
, mask
));
10137 tree stmt
= finish_call_expr (fn
, &vec
, false, false, tf_warning_or_error
);
10138 finish_expr_stmt (stmt
);
10141 /* Begin a __transaction_atomic or __transaction_relaxed statement.
10142 If PCOMPOUND is non-null, this is for a function-transaction-block, and we
10143 should create an extra compound stmt. */
10146 begin_transaction_stmt (location_t loc
, tree
*pcompound
, int flags
)
10151 *pcompound
= begin_compound_stmt (0);
10153 r
= build_stmt (loc
, TRANSACTION_EXPR
, NULL_TREE
);
10155 /* Only add the statement to the function if support enabled. */
10159 error_at (loc
, ((flags
& TM_STMT_ATTR_RELAXED
) != 0
10160 ? G_("%<__transaction_relaxed%> without "
10161 "transactional memory support enabled")
10162 : G_("%<__transaction_atomic%> without "
10163 "transactional memory support enabled")));
10165 TRANSACTION_EXPR_BODY (r
) = push_stmt_list ();
10166 TREE_SIDE_EFFECTS (r
) = 1;
10170 /* End a __transaction_atomic or __transaction_relaxed statement.
10171 If COMPOUND_STMT is non-null, this is for a function-transaction-block,
10172 and we should end the compound. If NOEX is non-NULL, we wrap the body in
10173 a MUST_NOT_THROW_EXPR with NOEX as condition. */
10176 finish_transaction_stmt (tree stmt
, tree compound_stmt
, int flags
, tree noex
)
10178 TRANSACTION_EXPR_BODY (stmt
) = pop_stmt_list (TRANSACTION_EXPR_BODY (stmt
));
10179 TRANSACTION_EXPR_OUTER (stmt
) = (flags
& TM_STMT_ATTR_OUTER
) != 0;
10180 TRANSACTION_EXPR_RELAXED (stmt
) = (flags
& TM_STMT_ATTR_RELAXED
) != 0;
10181 TRANSACTION_EXPR_IS_STMT (stmt
) = 1;
10183 /* noexcept specifications are not allowed for function transactions. */
10184 gcc_assert (!(noex
&& compound_stmt
));
10187 tree body
= build_must_not_throw_expr (TRANSACTION_EXPR_BODY (stmt
),
10189 protected_set_expr_location
10190 (body
, EXPR_LOCATION (TRANSACTION_EXPR_BODY (stmt
)));
10191 TREE_SIDE_EFFECTS (body
) = 1;
10192 TRANSACTION_EXPR_BODY (stmt
) = body
;
10196 finish_compound_stmt (compound_stmt
);
10199 /* Build a __transaction_atomic or __transaction_relaxed expression. If
10200 NOEX is non-NULL, we wrap the body in a MUST_NOT_THROW_EXPR with NOEX as
10204 build_transaction_expr (location_t loc
, tree expr
, int flags
, tree noex
)
10209 expr
= build_must_not_throw_expr (expr
, noex
);
10210 protected_set_expr_location (expr
, loc
);
10211 TREE_SIDE_EFFECTS (expr
) = 1;
10213 ret
= build1 (TRANSACTION_EXPR
, TREE_TYPE (expr
), expr
);
10214 if (flags
& TM_STMT_ATTR_RELAXED
)
10215 TRANSACTION_EXPR_RELAXED (ret
) = 1;
10216 TREE_SIDE_EFFECTS (ret
) = 1;
10217 SET_EXPR_LOCATION (ret
, loc
);
10222 init_cp_semantics (void)
10227 /* If we have a condition in conjunctive normal form (CNF), find the first
10228 failing clause. In other words, given an expression like
10230 true && true && false && true && false
10232 return the first 'false'. EXPR is the expression. */
10235 find_failing_clause_r (tree expr
)
10237 if (TREE_CODE (expr
) == TRUTH_ANDIF_EXPR
)
10239 /* First check the left side... */
10240 tree e
= find_failing_clause_r (TREE_OPERAND (expr
, 0));
10241 if (e
== NULL_TREE
)
10242 /* ...if we didn't find a false clause, check the right side. */
10243 e
= find_failing_clause_r (TREE_OPERAND (expr
, 1));
10246 tree e
= contextual_conv_bool (expr
, tf_none
);
10247 e
= fold_non_dependent_expr (e
, tf_none
, /*manifestly_const_eval=*/true);
10248 if (integer_zerop (e
))
10249 /* This is the failing clause. */
10254 /* Wrapper for find_failing_clause_r. */
10257 find_failing_clause (tree expr
)
10259 if (TREE_CODE (expr
) != TRUTH_ANDIF_EXPR
)
10261 return find_failing_clause_r (expr
);
10264 /* Build a STATIC_ASSERT for a static assertion with the condition
10265 CONDITION and the message text MESSAGE. LOCATION is the location
10266 of the static assertion in the source code. When MEMBER_P, this
10267 static assertion is a member of a class. If SHOW_EXPR_P is true,
10268 print the condition (because it was instantiation-dependent). */
10271 finish_static_assert (tree condition
, tree message
, location_t location
,
10272 bool member_p
, bool show_expr_p
)
10274 tsubst_flags_t complain
= tf_warning_or_error
;
10276 if (message
== NULL_TREE
10277 || message
== error_mark_node
10278 || condition
== NULL_TREE
10279 || condition
== error_mark_node
)
10282 if (check_for_bare_parameter_packs (condition
))
10283 condition
= error_mark_node
;
10285 if (instantiation_dependent_expression_p (condition
))
10287 /* We're in a template; build a STATIC_ASSERT and put it in
10288 the right place. */
10291 assertion
= make_node (STATIC_ASSERT
);
10292 STATIC_ASSERT_CONDITION (assertion
) = condition
;
10293 STATIC_ASSERT_MESSAGE (assertion
) = message
;
10294 STATIC_ASSERT_SOURCE_LOCATION (assertion
) = location
;
10297 maybe_add_class_template_decl_list (current_class_type
,
10301 add_stmt (assertion
);
10306 /* Save the condition in case it was a concept check. */
10307 tree orig_condition
= condition
;
10309 /* Fold the expression and convert it to a boolean value. */
10310 condition
= contextual_conv_bool (condition
, complain
);
10311 condition
= fold_non_dependent_expr (condition
, complain
,
10312 /*manifestly_const_eval=*/true);
10314 if (TREE_CODE (condition
) == INTEGER_CST
&& !integer_zerop (condition
))
10315 /* Do nothing; the condition is satisfied. */
10319 iloc_sentinel
ils (location
);
10321 if (integer_zerop (condition
))
10323 int sz
= TREE_INT_CST_LOW (TYPE_SIZE_UNIT
10324 (TREE_TYPE (TREE_TYPE (message
))));
10325 int len
= TREE_STRING_LENGTH (message
) / sz
- 1;
10327 /* See if we can find which clause was failing (for logical AND). */
10328 tree bad
= find_failing_clause (orig_condition
);
10329 /* If not, or its location is unusable, fall back to the previous
10331 location_t cloc
= location
;
10332 if (cp_expr_location (bad
) != UNKNOWN_LOCATION
)
10333 cloc
= cp_expr_location (bad
);
10335 /* Report the error. */
10337 error_at (cloc
, "static assertion failed");
10339 error_at (cloc
, "static assertion failed: %s",
10340 TREE_STRING_POINTER (message
));
10342 inform (cloc
, "%qE evaluates to false",
10343 /* Nobody wants to see the artificial (bool) cast. */
10344 (bad
? tree_strip_nop_conversions (bad
) : orig_condition
));
10346 /* Actually explain the failure if this is a concept check or a
10347 requires-expression. */
10348 if (concept_check_p (orig_condition
)
10349 || TREE_CODE (orig_condition
) == REQUIRES_EXPR
)
10350 diagnose_constraints (location
, orig_condition
, NULL_TREE
);
10352 else if (condition
&& condition
!= error_mark_node
)
10354 error ("non-constant condition for static assertion");
10355 if (require_rvalue_constant_expression (condition
))
10356 cxx_constant_value (condition
);
10361 /* Implements the C++0x decltype keyword. Returns the type of EXPR,
10362 suitable for use as a type-specifier.
10364 ID_EXPRESSION_OR_MEMBER_ACCESS_P is true when EXPR was parsed as an
10365 id-expression or a class member access, FALSE when it was parsed as
10366 a full expression. */
10369 finish_decltype_type (tree expr
, bool id_expression_or_member_access_p
,
10370 tsubst_flags_t complain
)
10372 tree type
= NULL_TREE
;
10374 if (!expr
|| error_operand_p (expr
))
10375 return error_mark_node
;
10378 || TREE_CODE (expr
) == TYPE_DECL
10379 || (TREE_CODE (expr
) == BIT_NOT_EXPR
10380 && TYPE_P (TREE_OPERAND (expr
, 0))))
10382 if (complain
& tf_error
)
10383 error ("argument to %<decltype%> must be an expression");
10384 return error_mark_node
;
10387 /* decltype is an unevaluated context. */
10390 /* Depending on the resolution of DR 1172, we may later need to distinguish
10391 instantiation-dependent but not type-dependent expressions so that, say,
10392 A<decltype(sizeof(T))>::U doesn't require 'typename'. */
10393 if (instantiation_dependent_uneval_expression_p (expr
))
10395 type
= cxx_make_type (DECLTYPE_TYPE
);
10396 DECLTYPE_TYPE_EXPR (type
) = expr
;
10397 DECLTYPE_TYPE_ID_EXPR_OR_MEMBER_ACCESS_P (type
)
10398 = id_expression_or_member_access_p
;
10399 SET_TYPE_STRUCTURAL_EQUALITY (type
);
10403 else if (processing_template_decl
)
10405 expr
= instantiate_non_dependent_expr_sfinae (expr
, complain
);
10406 if (expr
== error_mark_node
)
10407 return error_mark_node
;
10410 /* The type denoted by decltype(e) is defined as follows: */
10412 expr
= resolve_nondeduced_context (expr
, complain
);
10414 if (invalid_nonstatic_memfn_p (input_location
, expr
, complain
))
10415 return error_mark_node
;
10417 if (type_unknown_p (expr
))
10419 if (complain
& tf_error
)
10420 error ("%<decltype%> cannot resolve address of overloaded function");
10421 return error_mark_node
;
10424 /* To get the size of a static data member declared as an array of
10425 unknown bound, we need to instantiate it. */
10427 && VAR_HAD_UNKNOWN_BOUND (expr
)
10428 && DECL_TEMPLATE_INSTANTIATION (expr
))
10429 instantiate_decl (expr
, /*defer_ok*/true, /*expl_inst_mem*/false);
10431 if (id_expression_or_member_access_p
)
10433 /* If e is an id-expression or a class member access (5.2.5
10434 [expr.ref]), decltype(e) is defined as the type of the entity
10435 named by e. If there is no such entity, or e names a set of
10436 overloaded functions, the program is ill-formed. */
10437 if (identifier_p (expr
))
10438 expr
= lookup_name (expr
);
10440 if (INDIRECT_REF_P (expr
)
10441 || TREE_CODE (expr
) == VIEW_CONVERT_EXPR
)
10442 /* This can happen when the expression is, e.g., "a.b". Just
10443 look at the underlying operand. */
10444 expr
= TREE_OPERAND (expr
, 0);
10446 if (TREE_CODE (expr
) == OFFSET_REF
10447 || TREE_CODE (expr
) == MEMBER_REF
10448 || TREE_CODE (expr
) == SCOPE_REF
)
10449 /* We're only interested in the field itself. If it is a
10450 BASELINK, we will need to see through it in the next
10452 expr
= TREE_OPERAND (expr
, 1);
10454 if (BASELINK_P (expr
))
10455 /* See through BASELINK nodes to the underlying function. */
10456 expr
= BASELINK_FUNCTIONS (expr
);
10458 /* decltype of a decomposition name drops references in the tuple case
10459 (unlike decltype of a normal variable) and keeps cv-qualifiers from
10460 the containing object in the other cases (unlike decltype of a member
10461 access expression). */
10462 if (DECL_DECOMPOSITION_P (expr
))
10464 if (DECL_HAS_VALUE_EXPR_P (expr
))
10465 /* Expr is an array or struct subobject proxy, handle
10466 bit-fields properly. */
10467 return unlowered_expr_type (expr
);
10469 /* Expr is a reference variable for the tuple case. */
10470 return lookup_decomp_type (expr
);
10473 switch (TREE_CODE (expr
))
10476 if (DECL_BIT_FIELD_TYPE (expr
))
10478 type
= DECL_BIT_FIELD_TYPE (expr
);
10481 /* Fall through for fields that aren't bitfields. */
10482 gcc_fallthrough ();
10484 case FUNCTION_DECL
:
10489 case TEMPLATE_PARM_INDEX
:
10490 expr
= mark_type_use (expr
);
10491 type
= TREE_TYPE (expr
);
10495 type
= error_mark_node
;
10498 case COMPONENT_REF
:
10499 case COMPOUND_EXPR
:
10500 mark_type_use (expr
);
10501 type
= is_bitfield_expr_with_lowered_type (expr
);
10503 type
= TREE_TYPE (TREE_OPERAND (expr
, 1));
10506 case BIT_FIELD_REF
:
10507 gcc_unreachable ();
10511 /* We can get here when the id-expression refers to an
10512 enumerator or non-type template parameter. */
10513 type
= TREE_TYPE (expr
);
10517 /* Handle instantiated template non-type arguments. */
10518 type
= TREE_TYPE (expr
);
10524 /* Within a lambda-expression:
10526 Every occurrence of decltype((x)) where x is a possibly
10527 parenthesized id-expression that names an entity of
10528 automatic storage duration is treated as if x were
10529 transformed into an access to a corresponding data member
10530 of the closure type that would have been declared if x
10531 were a use of the denoted entity. */
10532 if (outer_automatic_var_p (expr
)
10533 && current_function_decl
10534 && LAMBDA_FUNCTION_P (current_function_decl
))
10535 type
= capture_decltype (expr
);
10536 else if (error_operand_p (expr
))
10537 type
= error_mark_node
;
10538 else if (expr
== current_class_ptr
)
10539 /* If the expression is just "this", we want the
10540 cv-unqualified pointer for the "this" type. */
10541 type
= TYPE_MAIN_VARIANT (TREE_TYPE (expr
));
10544 /* Otherwise, where T is the type of e, if e is an lvalue,
10545 decltype(e) is defined as T&; if an xvalue, T&&; otherwise, T. */
10546 cp_lvalue_kind clk
= lvalue_kind (expr
);
10547 type
= unlowered_expr_type (expr
);
10548 gcc_assert (!TYPE_REF_P (type
));
10550 /* For vector types, pick a non-opaque variant. */
10551 if (VECTOR_TYPE_P (type
))
10552 type
= strip_typedefs (type
);
10554 if (clk
!= clk_none
&& !(clk
& clk_class
))
10555 type
= cp_build_reference_type (type
, (clk
& clk_rvalueref
));
10562 /* Called from trait_expr_value to evaluate either __has_nothrow_assign or
10563 __has_nothrow_copy, depending on assign_p. Returns true iff all
10564 the copy {ctor,assign} fns are nothrow. */
10567 classtype_has_nothrow_assign_or_copy_p (tree type
, bool assign_p
)
10569 tree fns
= NULL_TREE
;
10571 if (assign_p
|| TYPE_HAS_COPY_CTOR (type
))
10572 fns
= get_class_binding (type
, assign_p
? assign_op_identifier
10573 : ctor_identifier
);
10575 bool saw_copy
= false;
10576 for (ovl_iterator
iter (fns
); iter
; ++iter
)
10580 if (copy_fn_p (fn
) > 0)
10583 if (!maybe_instantiate_noexcept (fn
)
10584 || !TYPE_NOTHROW_P (TREE_TYPE (fn
)))
10592 /* Return true if DERIVED is pointer interconvertible base of BASE. */
10595 pointer_interconvertible_base_of_p (tree base
, tree derived
)
10597 if (base
== error_mark_node
|| derived
== error_mark_node
)
10599 base
= TYPE_MAIN_VARIANT (base
);
10600 derived
= TYPE_MAIN_VARIANT (derived
);
10601 if (!NON_UNION_CLASS_TYPE_P (base
)
10602 || !NON_UNION_CLASS_TYPE_P (derived
))
10605 if (same_type_p (base
, derived
))
10608 if (!std_layout_type_p (derived
))
10611 return uniquely_derived_from_p (base
, derived
);
10614 /* Helper function for fold_builtin_is_pointer_inverconvertible_with_class,
10615 return true if MEMBERTYPE is the type of the first non-static data member
10616 of TYPE or for unions of any members. */
10618 first_nonstatic_data_member_p (tree type
, tree membertype
)
10620 for (tree field
= TYPE_FIELDS (type
); field
; field
= DECL_CHAIN (field
))
10622 if (TREE_CODE (field
) != FIELD_DECL
)
10624 if (DECL_FIELD_IS_BASE (field
) && is_empty_field (field
))
10626 if (DECL_FIELD_IS_BASE (field
))
10627 return first_nonstatic_data_member_p (TREE_TYPE (field
), membertype
);
10628 if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
10630 if ((TREE_CODE (TREE_TYPE (field
)) == UNION_TYPE
10631 || std_layout_type_p (TREE_TYPE (field
)))
10632 && first_nonstatic_data_member_p (TREE_TYPE (field
), membertype
))
10635 else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field
),
10638 if (TREE_CODE (type
) != UNION_TYPE
)
10644 /* Fold __builtin_is_pointer_interconvertible_with_class call. */
10647 fold_builtin_is_pointer_inverconvertible_with_class (location_t loc
, int nargs
,
10650 /* Unless users call the builtin directly, the following 3 checks should be
10651 ensured from std::is_pointer_interconvertible_with_class function
10655 error_at (loc
, "%<__builtin_is_pointer_interconvertible_with_class%> "
10656 "needs a single argument");
10657 return boolean_false_node
;
10659 tree arg
= args
[0];
10660 if (error_operand_p (arg
))
10661 return boolean_false_node
;
10662 if (!TYPE_PTRMEM_P (TREE_TYPE (arg
)))
10664 error_at (loc
, "%<__builtin_is_pointer_interconvertible_with_class%> "
10665 "argument is not pointer to member");
10666 return boolean_false_node
;
10669 if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg
)))
10670 return boolean_false_node
;
10672 tree membertype
= TREE_TYPE (TREE_TYPE (arg
));
10673 tree basetype
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg
));
10674 if (!complete_type_or_else (basetype
, NULL_TREE
))
10675 return boolean_false_node
;
10677 if (TREE_CODE (basetype
) != UNION_TYPE
10678 && !std_layout_type_p (basetype
))
10679 return boolean_false_node
;
10681 if (!first_nonstatic_data_member_p (basetype
, membertype
))
10682 return boolean_false_node
;
10684 if (TREE_CODE (arg
) == PTRMEM_CST
)
10685 arg
= cplus_expand_constant (arg
);
10687 if (integer_nonzerop (arg
))
10688 return boolean_false_node
;
10689 if (integer_zerop (arg
))
10690 return boolean_true_node
;
10692 return fold_build2 (EQ_EXPR
, boolean_type_node
, arg
,
10693 build_zero_cst (TREE_TYPE (arg
)));
10696 /* Helper function for is_corresponding_member_aggr. Return true if
10697 MEMBERTYPE pointer-to-data-member ARG can be found in anonymous
10698 union or structure BASETYPE. */
10701 is_corresponding_member_union (tree basetype
, tree membertype
, tree arg
)
10703 for (tree field
= TYPE_FIELDS (basetype
); field
; field
= DECL_CHAIN (field
))
10704 if (TREE_CODE (field
) != FIELD_DECL
|| DECL_BIT_FIELD_TYPE (field
))
10706 else if (same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field
),
10709 if (TREE_CODE (arg
) != INTEGER_CST
10710 || tree_int_cst_equal (arg
, byte_position (field
)))
10713 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field
)))
10716 if (TREE_CODE (basetype
) != UNION_TYPE
10717 && TREE_CODE (narg
) == INTEGER_CST
)
10718 narg
= size_binop (MINUS_EXPR
, arg
, byte_position (field
));
10719 if (is_corresponding_member_union (TREE_TYPE (field
),
10726 /* Helper function for fold_builtin_is_corresponding_member call.
10727 Return boolean_false_node if MEMBERTYPE1 BASETYPE1::*ARG1 and
10728 MEMBERTYPE2 BASETYPE2::*ARG2 aren't corresponding members,
10729 boolean_true_node if they are corresponding members, or for
10730 non-constant ARG2 the highest member offset for corresponding
10734 is_corresponding_member_aggr (location_t loc
, tree basetype1
, tree membertype1
,
10735 tree arg1
, tree basetype2
, tree membertype2
,
10738 tree field1
= TYPE_FIELDS (basetype1
);
10739 tree field2
= TYPE_FIELDS (basetype2
);
10740 tree ret
= boolean_false_node
;
10743 bool r
= next_common_initial_seqence (field1
, field2
);
10744 if (field1
== NULL_TREE
|| field2
== NULL_TREE
)
10747 && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field1
),
10749 && same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (field2
),
10752 tree pos
= byte_position (field1
);
10753 if (TREE_CODE (arg1
) == INTEGER_CST
10754 && tree_int_cst_equal (arg1
, pos
))
10756 if (TREE_CODE (arg2
) == INTEGER_CST
)
10757 return boolean_true_node
;
10760 else if (TREE_CODE (arg1
) != INTEGER_CST
)
10763 else if (ANON_AGGR_TYPE_P (TREE_TYPE (field1
))
10764 && ANON_AGGR_TYPE_P (TREE_TYPE (field2
)))
10766 if ((!lookup_attribute ("no_unique_address",
10767 DECL_ATTRIBUTES (field1
)))
10768 != !lookup_attribute ("no_unique_address",
10769 DECL_ATTRIBUTES (field2
)))
10771 if (!tree_int_cst_equal (bit_position (field1
),
10772 bit_position (field2
)))
10774 bool overlap
= true;
10775 tree pos
= byte_position (field1
);
10776 if (TREE_CODE (arg1
) == INTEGER_CST
)
10778 tree off1
= fold_convert (sizetype
, arg1
);
10779 tree sz1
= TYPE_SIZE_UNIT (TREE_TYPE (field1
));
10780 if (tree_int_cst_lt (off1
, pos
)
10781 || tree_int_cst_le (size_binop (PLUS_EXPR
, pos
, sz1
), off1
))
10784 if (TREE_CODE (arg2
) == INTEGER_CST
)
10786 tree off2
= fold_convert (sizetype
, arg2
);
10787 tree sz2
= TYPE_SIZE_UNIT (TREE_TYPE (field2
));
10788 if (tree_int_cst_lt (off2
, pos
)
10789 || tree_int_cst_le (size_binop (PLUS_EXPR
, pos
, sz2
), off2
))
10793 && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field1
))
10794 && NON_UNION_CLASS_TYPE_P (TREE_TYPE (field2
)))
10797 if (TREE_CODE (arg1
) == INTEGER_CST
)
10798 narg1
= size_binop (MINUS_EXPR
,
10799 fold_convert (sizetype
, arg1
), pos
);
10801 if (TREE_CODE (arg2
) == INTEGER_CST
)
10802 narg2
= size_binop (MINUS_EXPR
,
10803 fold_convert (sizetype
, arg2
), pos
);
10804 tree t1
= TREE_TYPE (field1
);
10805 tree t2
= TREE_TYPE (field2
);
10806 tree nret
= is_corresponding_member_aggr (loc
, t1
, membertype1
,
10807 narg1
, t2
, membertype2
,
10809 if (nret
!= boolean_false_node
)
10811 if (nret
== boolean_true_node
)
10813 if (TREE_CODE (arg1
) == INTEGER_CST
)
10814 return size_binop (PLUS_EXPR
, nret
, pos
);
10815 ret
= size_binop (PLUS_EXPR
, nret
, pos
);
10819 && TREE_CODE (TREE_TYPE (field1
)) == UNION_TYPE
10820 && TREE_CODE (TREE_TYPE (field2
)) == UNION_TYPE
)
10823 if (TREE_CODE (arg1
) == INTEGER_CST
)
10824 narg1
= size_binop (MINUS_EXPR
,
10825 fold_convert (sizetype
, arg1
), pos
);
10827 if (TREE_CODE (arg2
) == INTEGER_CST
)
10828 narg2
= size_binop (MINUS_EXPR
,
10829 fold_convert (sizetype
, arg2
), pos
);
10830 if (is_corresponding_member_union (TREE_TYPE (field1
),
10831 membertype1
, narg1
)
10832 && is_corresponding_member_union (TREE_TYPE (field2
),
10833 membertype2
, narg2
))
10835 sorry_at (loc
, "%<__builtin_is_corresponding_member%> "
10836 "not well defined for anonymous unions");
10837 return boolean_false_node
;
10843 field1
= DECL_CHAIN (field1
);
10844 field2
= DECL_CHAIN (field2
);
10849 /* Fold __builtin_is_corresponding_member call. */
10852 fold_builtin_is_corresponding_member (location_t loc
, int nargs
,
10855 /* Unless users call the builtin directly, the following 3 checks should be
10856 ensured from std::is_corresponding_member function template. */
10859 error_at (loc
, "%<__builtin_is_corresponding_member%> "
10860 "needs two arguments");
10861 return boolean_false_node
;
10863 tree arg1
= args
[0];
10864 tree arg2
= args
[1];
10865 if (error_operand_p (arg1
) || error_operand_p (arg2
))
10866 return boolean_false_node
;
10867 if (!TYPE_PTRMEM_P (TREE_TYPE (arg1
))
10868 || !TYPE_PTRMEM_P (TREE_TYPE (arg2
)))
10870 error_at (loc
, "%<__builtin_is_corresponding_member%> "
10871 "argument is not pointer to member");
10872 return boolean_false_node
;
10875 if (!TYPE_PTRDATAMEM_P (TREE_TYPE (arg1
))
10876 || !TYPE_PTRDATAMEM_P (TREE_TYPE (arg2
)))
10877 return boolean_false_node
;
10879 tree membertype1
= TREE_TYPE (TREE_TYPE (arg1
));
10880 tree basetype1
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg1
));
10881 if (!complete_type_or_else (basetype1
, NULL_TREE
))
10882 return boolean_false_node
;
10884 tree membertype2
= TREE_TYPE (TREE_TYPE (arg2
));
10885 tree basetype2
= TYPE_OFFSET_BASETYPE (TREE_TYPE (arg2
));
10886 if (!complete_type_or_else (basetype2
, NULL_TREE
))
10887 return boolean_false_node
;
10889 if (!NON_UNION_CLASS_TYPE_P (basetype1
)
10890 || !NON_UNION_CLASS_TYPE_P (basetype2
)
10891 || !std_layout_type_p (basetype1
)
10892 || !std_layout_type_p (basetype2
))
10893 return boolean_false_node
;
10895 /* If the member types aren't layout compatible, then they
10896 can't be corresponding members. */
10897 if (!layout_compatible_type_p (membertype1
, membertype2
))
10898 return boolean_false_node
;
10900 if (TREE_CODE (arg1
) == PTRMEM_CST
)
10901 arg1
= cplus_expand_constant (arg1
);
10902 if (TREE_CODE (arg2
) == PTRMEM_CST
)
10903 arg2
= cplus_expand_constant (arg2
);
10905 if (null_member_pointer_value_p (arg1
)
10906 || null_member_pointer_value_p (arg2
))
10907 return boolean_false_node
;
10909 if (TREE_CODE (arg1
) == INTEGER_CST
10910 && TREE_CODE (arg2
) == INTEGER_CST
10911 && !tree_int_cst_equal (arg1
, arg2
))
10912 return boolean_false_node
;
10914 if (TREE_CODE (arg2
) == INTEGER_CST
10915 && TREE_CODE (arg1
) != INTEGER_CST
)
10917 std::swap (arg1
, arg2
);
10918 std::swap (membertype1
, membertype2
);
10919 std::swap (basetype1
, basetype2
);
10922 tree ret
= is_corresponding_member_aggr (loc
, basetype1
, membertype1
, arg1
,
10923 basetype2
, membertype2
, arg2
);
10924 if (TREE_TYPE (ret
) == boolean_type_node
)
10926 /* If both arg1 and arg2 are INTEGER_CSTs, is_corresponding_member_aggr
10927 already returns boolean_{true,false}_node whether those particular
10928 members are corresponding members or not. Otherwise, if only
10929 one of them is INTEGER_CST (canonicalized to first being INTEGER_CST
10930 above), it returns boolean_false_node if it is certainly not a
10931 corresponding member and otherwise we need to do a runtime check that
10932 those two OFFSET_TYPE offsets are equal.
10933 If neither of the operands is INTEGER_CST, is_corresponding_member_aggr
10934 returns the largest offset at which the members would be corresponding
10935 members, so perform arg1 <= ret && arg1 == arg2 runtime check. */
10936 gcc_assert (TREE_CODE (arg2
) != INTEGER_CST
);
10937 if (TREE_CODE (arg1
) == INTEGER_CST
)
10938 return fold_build2 (EQ_EXPR
, boolean_type_node
, arg1
,
10939 fold_convert (TREE_TYPE (arg1
), arg2
));
10940 ret
= fold_build2 (LE_EXPR
, boolean_type_node
,
10941 fold_convert (pointer_sized_int_node
, arg1
),
10942 fold_convert (pointer_sized_int_node
, ret
));
10943 return fold_build2 (TRUTH_AND_EXPR
, boolean_type_node
, ret
,
10944 fold_build2 (EQ_EXPR
, boolean_type_node
, arg1
,
10945 fold_convert (TREE_TYPE (arg1
), arg2
)));
10948 /* Actually evaluates the trait. */
10951 trait_expr_value (cp_trait_kind kind
, tree type1
, tree type2
)
10953 enum tree_code type_code1
;
10956 type_code1
= TREE_CODE (type1
);
10960 case CPTK_HAS_NOTHROW_ASSIGN
:
10961 type1
= strip_array_types (type1
);
10962 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
10963 && (trait_expr_value (CPTK_HAS_TRIVIAL_ASSIGN
, type1
, type2
)
10964 || (CLASS_TYPE_P (type1
)
10965 && classtype_has_nothrow_assign_or_copy_p (type1
,
10968 case CPTK_HAS_TRIVIAL_ASSIGN
:
10969 /* ??? The standard seems to be missing the "or array of such a class
10970 type" wording for this trait. */
10971 type1
= strip_array_types (type1
);
10972 return (!CP_TYPE_CONST_P (type1
) && type_code1
!= REFERENCE_TYPE
10973 && (trivial_type_p (type1
)
10974 || (CLASS_TYPE_P (type1
)
10975 && TYPE_HAS_TRIVIAL_COPY_ASSIGN (type1
))));
10977 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
10978 type1
= strip_array_types (type1
);
10979 return (trait_expr_value (CPTK_HAS_TRIVIAL_CONSTRUCTOR
, type1
, type2
)
10980 || (CLASS_TYPE_P (type1
)
10981 && (t
= locate_ctor (type1
))
10982 && maybe_instantiate_noexcept (t
)
10983 && TYPE_NOTHROW_P (TREE_TYPE (t
))));
10985 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
10986 type1
= strip_array_types (type1
);
10987 return (trivial_type_p (type1
)
10988 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_DFLT (type1
)));
10990 case CPTK_HAS_NOTHROW_COPY
:
10991 type1
= strip_array_types (type1
);
10992 return (trait_expr_value (CPTK_HAS_TRIVIAL_COPY
, type1
, type2
)
10993 || (CLASS_TYPE_P (type1
)
10994 && classtype_has_nothrow_assign_or_copy_p (type1
, false)));
10996 case CPTK_HAS_TRIVIAL_COPY
:
10997 /* ??? The standard seems to be missing the "or array of such a class
10998 type" wording for this trait. */
10999 type1
= strip_array_types (type1
);
11000 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
11001 || (CLASS_TYPE_P (type1
) && TYPE_HAS_TRIVIAL_COPY_CTOR (type1
)));
11003 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
11004 type1
= strip_array_types (type1
);
11005 return (trivial_type_p (type1
) || type_code1
== REFERENCE_TYPE
11006 || (CLASS_TYPE_P (type1
)
11007 && TYPE_HAS_TRIVIAL_DESTRUCTOR (type1
)));
11009 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
11010 return type_has_virtual_destructor (type1
);
11012 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
11013 return type_has_unique_obj_representations (type1
);
11015 case CPTK_IS_ABSTRACT
:
11016 return ABSTRACT_CLASS_TYPE_P (type1
);
11018 case CPTK_IS_AGGREGATE
:
11019 return CP_AGGREGATE_TYPE_P (type1
);
11021 case CPTK_IS_BASE_OF
:
11022 return (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
11023 && (same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
11024 || DERIVED_FROM_P (type1
, type2
)));
11026 case CPTK_IS_CLASS
:
11027 return NON_UNION_CLASS_TYPE_P (type1
);
11029 case CPTK_IS_EMPTY
:
11030 return NON_UNION_CLASS_TYPE_P (type1
) && CLASSTYPE_EMPTY_P (type1
);
11033 return type_code1
== ENUMERAL_TYPE
;
11035 case CPTK_IS_FINAL
:
11036 return CLASS_TYPE_P (type1
) && CLASSTYPE_FINAL (type1
);
11038 case CPTK_IS_LAYOUT_COMPATIBLE
:
11039 return layout_compatible_type_p (type1
, type2
);
11041 case CPTK_IS_LITERAL_TYPE
:
11042 return literal_type_p (type1
);
11044 case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF
:
11045 return pointer_interconvertible_base_of_p (type1
, type2
);
11048 return pod_type_p (type1
);
11050 case CPTK_IS_POLYMORPHIC
:
11051 return CLASS_TYPE_P (type1
) && TYPE_POLYMORPHIC_P (type1
);
11053 case CPTK_IS_SAME_AS
:
11054 return same_type_p (type1
, type2
);
11056 case CPTK_IS_STD_LAYOUT
:
11057 return std_layout_type_p (type1
);
11059 case CPTK_IS_TRIVIAL
:
11060 return trivial_type_p (type1
);
11062 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
11063 return is_trivially_xible (MODIFY_EXPR
, type1
, type2
);
11065 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
11066 return is_trivially_xible (INIT_EXPR
, type1
, type2
);
11068 case CPTK_IS_TRIVIALLY_COPYABLE
:
11069 return trivially_copyable_p (type1
);
11071 case CPTK_IS_UNION
:
11072 return type_code1
== UNION_TYPE
;
11074 case CPTK_IS_ASSIGNABLE
:
11075 return is_xible (MODIFY_EXPR
, type1
, type2
);
11077 case CPTK_IS_CONSTRUCTIBLE
:
11078 return is_xible (INIT_EXPR
, type1
, type2
);
11080 case CPTK_IS_NOTHROW_ASSIGNABLE
:
11081 return is_nothrow_xible (MODIFY_EXPR
, type1
, type2
);
11083 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
11084 return is_nothrow_xible (INIT_EXPR
, type1
, type2
);
11087 gcc_unreachable ();
11092 /* If TYPE is an array of unknown bound, or (possibly cv-qualified)
11093 void, or a complete type, returns true, otherwise false. */
11096 check_trait_type (tree type
)
11098 if (type
== NULL_TREE
)
11101 if (TREE_CODE (type
) == TREE_LIST
)
11102 return (check_trait_type (TREE_VALUE (type
))
11103 && check_trait_type (TREE_CHAIN (type
)));
11105 if (TREE_CODE (type
) == ARRAY_TYPE
&& !TYPE_DOMAIN (type
)
11106 && COMPLETE_TYPE_P (TREE_TYPE (type
)))
11109 if (VOID_TYPE_P (type
))
11112 return !!complete_type_or_else (strip_array_types (type
), NULL_TREE
);
11115 /* Process a trait expression. */
11118 finish_trait_expr (location_t loc
, cp_trait_kind kind
, tree type1
, tree type2
)
11120 if (type1
== error_mark_node
11121 || type2
== error_mark_node
)
11122 return error_mark_node
;
11124 if (processing_template_decl
)
11126 tree trait_expr
= make_node (TRAIT_EXPR
);
11127 TREE_TYPE (trait_expr
) = boolean_type_node
;
11128 TRAIT_EXPR_TYPE1 (trait_expr
) = type1
;
11129 TRAIT_EXPR_TYPE2 (trait_expr
) = type2
;
11130 TRAIT_EXPR_KIND (trait_expr
) = kind
;
11131 TRAIT_EXPR_LOCATION (trait_expr
) = loc
;
11137 case CPTK_HAS_NOTHROW_ASSIGN
:
11138 case CPTK_HAS_TRIVIAL_ASSIGN
:
11139 case CPTK_HAS_NOTHROW_CONSTRUCTOR
:
11140 case CPTK_HAS_TRIVIAL_CONSTRUCTOR
:
11141 case CPTK_HAS_NOTHROW_COPY
:
11142 case CPTK_HAS_TRIVIAL_COPY
:
11143 case CPTK_HAS_TRIVIAL_DESTRUCTOR
:
11144 case CPTK_HAS_UNIQUE_OBJ_REPRESENTATIONS
:
11145 case CPTK_HAS_VIRTUAL_DESTRUCTOR
:
11146 case CPTK_IS_ABSTRACT
:
11147 case CPTK_IS_AGGREGATE
:
11148 case CPTK_IS_EMPTY
:
11149 case CPTK_IS_FINAL
:
11150 case CPTK_IS_LITERAL_TYPE
:
11152 case CPTK_IS_POLYMORPHIC
:
11153 case CPTK_IS_STD_LAYOUT
:
11154 case CPTK_IS_TRIVIAL
:
11155 case CPTK_IS_TRIVIALLY_COPYABLE
:
11156 if (!check_trait_type (type1
))
11157 return error_mark_node
;
11160 case CPTK_IS_ASSIGNABLE
:
11161 case CPTK_IS_CONSTRUCTIBLE
:
11164 case CPTK_IS_TRIVIALLY_ASSIGNABLE
:
11165 case CPTK_IS_TRIVIALLY_CONSTRUCTIBLE
:
11166 case CPTK_IS_NOTHROW_ASSIGNABLE
:
11167 case CPTK_IS_NOTHROW_CONSTRUCTIBLE
:
11168 if (!check_trait_type (type1
)
11169 || !check_trait_type (type2
))
11170 return error_mark_node
;
11173 case CPTK_IS_BASE_OF
:
11174 case CPTK_IS_POINTER_INTERCONVERTIBLE_BASE_OF
:
11175 if (NON_UNION_CLASS_TYPE_P (type1
) && NON_UNION_CLASS_TYPE_P (type2
)
11176 && !same_type_ignoring_top_level_qualifiers_p (type1
, type2
)
11177 && !complete_type_or_else (type2
, NULL_TREE
))
11178 /* We already issued an error. */
11179 return error_mark_node
;
11182 case CPTK_IS_CLASS
:
11184 case CPTK_IS_UNION
:
11185 case CPTK_IS_SAME_AS
:
11188 case CPTK_IS_LAYOUT_COMPATIBLE
:
11189 if (!array_of_unknown_bound_p (type1
)
11190 && TREE_CODE (type1
) != VOID_TYPE
11191 && !complete_type_or_else (type1
, NULL_TREE
))
11192 /* We already issued an error. */
11193 return error_mark_node
;
11194 if (!array_of_unknown_bound_p (type2
)
11195 && TREE_CODE (type2
) != VOID_TYPE
11196 && !complete_type_or_else (type2
, NULL_TREE
))
11197 /* We already issued an error. */
11198 return error_mark_node
;
11202 gcc_unreachable ();
11205 tree val
= (trait_expr_value (kind
, type1
, type2
)
11206 ? boolean_true_node
: boolean_false_node
);
11207 return maybe_wrap_with_location (val
, loc
);
11210 /* Do-nothing variants of functions to handle pragma FLOAT_CONST_DECIMAL64,
11211 which is ignored for C++. */
11214 set_float_const_decimal64 (void)
11219 clear_float_const_decimal64 (void)
11224 float_const_decimal64_p (void)
11230 /* Return true if T designates the implied `this' parameter. */
11233 is_this_parameter (tree t
)
11235 if (!DECL_P (t
) || DECL_NAME (t
) != this_identifier
)
11237 gcc_assert (TREE_CODE (t
) == PARM_DECL
|| is_capture_proxy (t
)
11238 || (cp_binding_oracle
&& TREE_CODE (t
) == VAR_DECL
));
11242 /* Insert the deduced return type for an auto function. */
11245 apply_deduced_return_type (tree fco
, tree return_type
)
11249 if (return_type
== error_mark_node
)
11252 if (DECL_CONV_FN_P (fco
))
11253 DECL_NAME (fco
) = make_conv_op_name (return_type
);
11255 TREE_TYPE (fco
) = change_return_type (return_type
, TREE_TYPE (fco
));
11257 result
= DECL_RESULT (fco
);
11258 if (result
== NULL_TREE
)
11260 if (TREE_TYPE (result
) == return_type
)
11263 if (!processing_template_decl
&& !VOID_TYPE_P (return_type
)
11264 && !complete_type_or_else (return_type
, NULL_TREE
))
11267 /* We already have a DECL_RESULT from start_preparsed_function.
11268 Now we need to redo the work it and allocate_struct_function
11269 did to reflect the new type. */
11270 gcc_assert (current_function_decl
== fco
);
11271 result
= build_decl (input_location
, RESULT_DECL
, NULL_TREE
,
11272 TYPE_MAIN_VARIANT (return_type
));
11273 DECL_ARTIFICIAL (result
) = 1;
11274 DECL_IGNORED_P (result
) = 1;
11275 cp_apply_type_quals_to_decl (cp_type_quals (return_type
),
11278 DECL_RESULT (fco
) = result
;
11280 if (!processing_template_decl
)
11282 bool aggr
= aggregate_value_p (result
, fco
);
11283 #ifdef PCC_STATIC_STRUCT_RETURN
11284 cfun
->returns_pcc_struct
= aggr
;
11286 cfun
->returns_struct
= aggr
;
11290 /* DECL is a local variable or parameter from the surrounding scope of a
11291 lambda-expression. Returns the decltype for a use of the capture field
11292 for DECL even if it hasn't been captured yet. */
11295 capture_decltype (tree decl
)
11297 tree lam
= CLASSTYPE_LAMBDA_EXPR (DECL_CONTEXT (current_function_decl
));
11298 tree cap
= lookup_name (DECL_NAME (decl
), LOOK_where::BLOCK
,
11299 LOOK_want::HIDDEN_LAMBDA
);
11302 if (cap
&& is_capture_proxy (cap
))
11303 type
= TREE_TYPE (cap
);
11305 switch (LAMBDA_EXPR_DEFAULT_CAPTURE_MODE (lam
))
11308 error ("%qD is not captured", decl
);
11309 return error_mark_node
;
11312 type
= TREE_TYPE (decl
);
11313 if (TYPE_REF_P (type
)
11314 && TREE_CODE (TREE_TYPE (type
)) != FUNCTION_TYPE
)
11315 type
= TREE_TYPE (type
);
11318 case CPLD_REFERENCE
:
11319 type
= TREE_TYPE (decl
);
11320 if (!TYPE_REF_P (type
))
11321 type
= build_reference_type (TREE_TYPE (decl
));
11325 gcc_unreachable ();
11328 if (!TYPE_REF_P (type
))
11330 if (!LAMBDA_EXPR_MUTABLE_P (lam
))
11331 type
= cp_build_qualified_type (type
, (cp_type_quals (type
)
11332 |TYPE_QUAL_CONST
));
11333 type
= build_reference_type (type
);
11338 /* Build a unary fold expression of EXPR over OP. If IS_RIGHT is true,
11339 this is a right unary fold. Otherwise it is a left unary fold. */
11342 finish_unary_fold_expr (tree expr
, int op
, tree_code dir
)
11344 /* Build a pack expansion (assuming expr has pack type). */
11345 if (!uses_parameter_packs (expr
))
11347 error_at (location_of (expr
), "operand of fold expression has no "
11348 "unexpanded parameter packs");
11349 return error_mark_node
;
11351 tree pack
= make_pack_expansion (expr
);
11353 /* Build the fold expression. */
11354 tree code
= build_int_cstu (integer_type_node
, abs (op
));
11355 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
);
11356 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
11361 finish_left_unary_fold_expr (tree expr
, int op
)
11363 return finish_unary_fold_expr (expr
, op
, UNARY_LEFT_FOLD_EXPR
);
11367 finish_right_unary_fold_expr (tree expr
, int op
)
11369 return finish_unary_fold_expr (expr
, op
, UNARY_RIGHT_FOLD_EXPR
);
11372 /* Build a binary fold expression over EXPR1 and EXPR2. The
11373 associativity of the fold is determined by EXPR1 and EXPR2 (whichever
11374 has an unexpanded parameter pack). */
11377 finish_binary_fold_expr (tree pack
, tree init
, int op
, tree_code dir
)
11379 pack
= make_pack_expansion (pack
);
11380 tree code
= build_int_cstu (integer_type_node
, abs (op
));
11381 tree fold
= build_min_nt_loc (UNKNOWN_LOCATION
, dir
, code
, pack
, init
);
11382 FOLD_EXPR_MODIFY_P (fold
) = (op
< 0);
11387 finish_binary_fold_expr (tree expr1
, tree expr2
, int op
)
11389 // Determine which expr has an unexpanded parameter pack and
11390 // set the pack and initial term.
11391 bool pack1
= uses_parameter_packs (expr1
);
11392 bool pack2
= uses_parameter_packs (expr2
);
11393 if (pack1
&& !pack2
)
11394 return finish_binary_fold_expr (expr1
, expr2
, op
, BINARY_RIGHT_FOLD_EXPR
);
11395 else if (pack2
&& !pack1
)
11396 return finish_binary_fold_expr (expr2
, expr1
, op
, BINARY_LEFT_FOLD_EXPR
);
11400 error ("both arguments in binary fold have unexpanded parameter packs");
11402 error ("no unexpanded parameter packs in binary fold");
11404 return error_mark_node
;
11407 /* Finish __builtin_launder (arg). */
11410 finish_builtin_launder (location_t loc
, tree arg
, tsubst_flags_t complain
)
11412 tree orig_arg
= arg
;
11413 if (!type_dependent_expression_p (arg
))
11414 arg
= decay_conversion (arg
, complain
);
11415 if (error_operand_p (arg
))
11416 return error_mark_node
;
11417 if (!type_dependent_expression_p (arg
)
11418 && !TYPE_PTR_P (TREE_TYPE (arg
)))
11420 error_at (loc
, "non-pointer argument to %<__builtin_launder%>");
11421 return error_mark_node
;
11423 if (processing_template_decl
)
11425 return build_call_expr_internal_loc (loc
, IFN_LAUNDER
,
11426 TREE_TYPE (arg
), 1, arg
);
11429 /* Finish __builtin_convertvector (arg, type). */
11432 cp_build_vec_convert (tree arg
, location_t loc
, tree type
,
11433 tsubst_flags_t complain
)
11435 if (error_operand_p (type
))
11436 return error_mark_node
;
11437 if (error_operand_p (arg
))
11438 return error_mark_node
;
11440 tree ret
= NULL_TREE
;
11441 if (!type_dependent_expression_p (arg
) && !dependent_type_p (type
))
11442 ret
= c_build_vec_convert (cp_expr_loc_or_input_loc (arg
),
11443 decay_conversion (arg
, complain
),
11444 loc
, type
, (complain
& tf_error
) != 0);
11446 if (!processing_template_decl
)
11449 return build_call_expr_internal_loc (loc
, IFN_VEC_CONVERT
, type
, 1, arg
);
11452 /* Finish __builtin_bit_cast (type, arg). */
11455 cp_build_bit_cast (location_t loc
, tree type
, tree arg
,
11456 tsubst_flags_t complain
)
11458 if (error_operand_p (type
))
11459 return error_mark_node
;
11460 if (!dependent_type_p (type
))
11462 if (!complete_type_or_maybe_complain (type
, NULL_TREE
, complain
))
11463 return error_mark_node
;
11464 if (TREE_CODE (type
) == ARRAY_TYPE
)
11466 /* std::bit_cast for destination ARRAY_TYPE is not possible,
11467 as functions may not return an array, so don't bother trying
11468 to support this (and then deal with VLAs etc.). */
11469 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
11470 "is an array type", type
);
11471 return error_mark_node
;
11473 if (!trivially_copyable_p (type
))
11475 error_at (loc
, "%<__builtin_bit_cast%> destination type %qT "
11476 "is not trivially copyable", type
);
11477 return error_mark_node
;
11481 if (error_operand_p (arg
))
11482 return error_mark_node
;
11484 if (!type_dependent_expression_p (arg
))
11486 if (TREE_CODE (TREE_TYPE (arg
)) == ARRAY_TYPE
)
11488 /* Don't perform array-to-pointer conversion. */
11489 arg
= mark_rvalue_use (arg
, loc
, true);
11490 if (!complete_type_or_maybe_complain (TREE_TYPE (arg
), arg
, complain
))
11491 return error_mark_node
;
11494 arg
= decay_conversion (arg
, complain
);
11496 if (error_operand_p (arg
))
11497 return error_mark_node
;
11499 if (!trivially_copyable_p (TREE_TYPE (arg
)))
11501 error_at (cp_expr_loc_or_loc (arg
, loc
),
11502 "%<__builtin_bit_cast%> source type %qT "
11503 "is not trivially copyable", TREE_TYPE (arg
));
11504 return error_mark_node
;
11506 if (!dependent_type_p (type
)
11507 && !cp_tree_equal (TYPE_SIZE_UNIT (type
),
11508 TYPE_SIZE_UNIT (TREE_TYPE (arg
))))
11510 error_at (loc
, "%<__builtin_bit_cast%> source size %qE "
11511 "not equal to destination type size %qE",
11512 TYPE_SIZE_UNIT (TREE_TYPE (arg
)),
11513 TYPE_SIZE_UNIT (type
));
11514 return error_mark_node
;
11518 tree ret
= build_min (BIT_CAST_EXPR
, type
, arg
);
11519 SET_EXPR_LOCATION (ret
, loc
);
11521 if (!processing_template_decl
&& CLASS_TYPE_P (type
))
11522 ret
= get_target_expr_sfinae (ret
, complain
);
11527 #include "gt-cp-semantics.h"