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, 1999, 2000, 2001, 2002, 2003, 2004, 2005
7 Free Software Foundation, Inc.
8 Written by Mark Mitchell (mmitchell@usa.net) based on code found
9 formerly in parse.y and pt.c.
11 This file is part of GCC.
13 GCC is free software; you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation; either version 2, or (at your option)
18 GCC is distributed in the hope that it will be useful, but
19 WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21 General Public License for more details.
23 You should have received a copy of the GNU General Public License
24 along with GCC; see the file COPYING. If not, write to the Free
25 Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
30 #include "coretypes.h"
35 #include "tree-inline.h"
36 #include "tree-mudflap.h"
45 #include "diagnostic.h"
47 #include "tree-iterator.h"
51 /* There routines provide a modular interface to perform many parsing
52 operations. They may therefore be used during actual parsing, or
53 during template instantiation, which may be regarded as a
54 degenerate form of parsing. Since the current g++ parser is
55 lacking in several respects, and will be reimplemented, we are
56 attempting to move most code that is not directly related to
57 parsing into this file; that will make implementing the new parser
58 much easier since it will be able to make use of these routines. */
60 static tree
maybe_convert_cond (tree
);
61 static tree
simplify_aggr_init_exprs_r (tree
*, int *, void *);
62 static void emit_associated_thunks (tree
);
63 static tree
finalize_nrv_r (tree
*, int *, void *);
66 /* Deferred Access Checking Overview
67 ---------------------------------
69 Most C++ expressions and declarations require access checking
70 to be performed during parsing. However, in several cases,
71 this has to be treated differently.
73 For member declarations, access checking has to be deferred
74 until more information about the declaration is known. For
86 When we are parsing the function return type `A::X', we don't
87 really know if this is allowed until we parse the function name.
89 Furthermore, some contexts require that access checking is
90 never performed at all. These include class heads, and template
93 Typical use of access checking functions is described here:
95 1. When we enter a context that requires certain access checking
96 mode, the function `push_deferring_access_checks' is called with
97 DEFERRING argument specifying the desired mode. Access checking
98 may be performed immediately (dk_no_deferred), deferred
99 (dk_deferred), or not performed (dk_no_check).
101 2. When a declaration such as a type, or a variable, is encountered,
102 the function `perform_or_defer_access_check' is called. It
103 maintains a TREE_LIST of all deferred checks.
105 3. The global `current_class_type' or `current_function_decl' is then
106 setup by the parser. `enforce_access' relies on these information
109 4. Upon exiting the context mentioned in step 1,
110 `perform_deferred_access_checks' is called to check all declaration
111 stored in the TREE_LIST. `pop_deferring_access_checks' is then
112 called to restore the previous access checking mode.
114 In case of parsing error, we simply call `pop_deferring_access_checks'
115 without `perform_deferred_access_checks'. */
117 typedef struct deferred_access
GTY(())
119 /* A TREE_LIST representing name-lookups for which we have deferred
120 checking access controls. We cannot check the accessibility of
121 names used in a decl-specifier-seq until we know what is being
122 declared because code like:
129 A::B* A::f() { return 0; }
131 is valid, even though `A::B' is not generally accessible.
133 The TREE_PURPOSE of each node is the scope used to qualify the
134 name being looked up; the TREE_VALUE is the DECL to which the
135 name was resolved. */
136 tree deferred_access_checks
;
138 /* The current mode of access checks. */
139 enum deferring_kind deferring_access_checks_kind
;
142 DEF_VEC_O (deferred_access
);
143 DEF_VEC_ALLOC_O (deferred_access
,gc
);
145 /* Data for deferred access checking. */
146 static GTY(()) VEC(deferred_access
,gc
) *deferred_access_stack
;
147 static GTY(()) unsigned deferred_access_no_check
;
149 /* Save the current deferred access states and start deferred
150 access checking iff DEFER_P is true. */
153 push_deferring_access_checks (deferring_kind deferring
)
155 /* For context like template instantiation, access checking
156 disabling applies to all nested context. */
157 if (deferred_access_no_check
|| deferring
== dk_no_check
)
158 deferred_access_no_check
++;
161 deferred_access
*ptr
;
163 ptr
= VEC_safe_push (deferred_access
, gc
, deferred_access_stack
, NULL
);
164 ptr
->deferred_access_checks
= NULL_TREE
;
165 ptr
->deferring_access_checks_kind
= deferring
;
169 /* Resume deferring access checks again after we stopped doing
173 resume_deferring_access_checks (void)
175 if (!deferred_access_no_check
)
176 VEC_last (deferred_access
, deferred_access_stack
)
177 ->deferring_access_checks_kind
= dk_deferred
;
180 /* Stop deferring access checks. */
183 stop_deferring_access_checks (void)
185 if (!deferred_access_no_check
)
186 VEC_last (deferred_access
, deferred_access_stack
)
187 ->deferring_access_checks_kind
= dk_no_deferred
;
190 /* Discard the current deferred access checks and restore the
194 pop_deferring_access_checks (void)
196 if (deferred_access_no_check
)
197 deferred_access_no_check
--;
199 VEC_pop (deferred_access
, deferred_access_stack
);
202 /* Returns a TREE_LIST representing the deferred checks.
203 The TREE_PURPOSE of each node is the type through which the
204 access occurred; the TREE_VALUE is the declaration named.
208 get_deferred_access_checks (void)
210 if (deferred_access_no_check
)
213 return (VEC_last (deferred_access
, deferred_access_stack
)
214 ->deferred_access_checks
);
217 /* Take current deferred checks and combine with the
218 previous states if we also defer checks previously.
219 Otherwise perform checks now. */
222 pop_to_parent_deferring_access_checks (void)
224 if (deferred_access_no_check
)
225 deferred_access_no_check
--;
229 deferred_access
*ptr
;
231 checks
= (VEC_last (deferred_access
, deferred_access_stack
)
232 ->deferred_access_checks
);
234 VEC_pop (deferred_access
, deferred_access_stack
);
235 ptr
= VEC_last (deferred_access
, deferred_access_stack
);
236 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
239 for (; checks
; checks
= TREE_CHAIN (checks
))
240 enforce_access (TREE_PURPOSE (checks
),
241 TREE_VALUE (checks
));
245 /* Merge with parent. */
247 tree original
= ptr
->deferred_access_checks
;
249 for (; checks
; checks
= next
)
253 next
= TREE_CHAIN (checks
);
255 for (probe
= original
; probe
; probe
= TREE_CHAIN (probe
))
256 if (TREE_VALUE (probe
) == TREE_VALUE (checks
)
257 && TREE_PURPOSE (probe
) == TREE_PURPOSE (checks
))
259 /* Insert into parent's checks. */
260 TREE_CHAIN (checks
) = ptr
->deferred_access_checks
;
261 ptr
->deferred_access_checks
= checks
;
268 /* Perform the deferred access checks.
270 After performing the checks, we still have to keep the list
271 `deferred_access_stack->deferred_access_checks' since we may want
272 to check access for them again later in a different context.
279 A::X A::a, x; // No error for `A::a', error for `x'
281 We have to perform deferred access of `A::X', first with `A::a',
285 perform_deferred_access_checks (void)
289 for (deferred_check
= get_deferred_access_checks ();
291 deferred_check
= TREE_CHAIN (deferred_check
))
293 enforce_access (TREE_PURPOSE (deferred_check
),
294 TREE_VALUE (deferred_check
));
297 /* Defer checking the accessibility of DECL, when looked up in
301 perform_or_defer_access_check (tree binfo
, tree decl
)
304 deferred_access
*ptr
;
306 /* Exit if we are in a context that no access checking is performed.
308 if (deferred_access_no_check
)
311 gcc_assert (TREE_CODE (binfo
) == TREE_BINFO
);
313 ptr
= VEC_last (deferred_access
, deferred_access_stack
);
315 /* If we are not supposed to defer access checks, just check now. */
316 if (ptr
->deferring_access_checks_kind
== dk_no_deferred
)
318 enforce_access (binfo
, decl
);
322 /* See if we are already going to perform this check. */
323 for (check
= ptr
->deferred_access_checks
;
325 check
= TREE_CHAIN (check
))
326 if (TREE_VALUE (check
) == decl
&& TREE_PURPOSE (check
) == binfo
)
328 /* If not, record the check. */
329 ptr
->deferred_access_checks
330 = tree_cons (binfo
, decl
, ptr
->deferred_access_checks
);
333 /* Returns nonzero if the current statement is a full expression,
334 i.e. temporaries created during that statement should be destroyed
335 at the end of the statement. */
338 stmts_are_full_exprs_p (void)
340 return current_stmt_tree ()->stmts_are_full_exprs_p
;
343 /* T is a statement. Add it to the statement-tree. This is the C++
344 version. The C/ObjC frontends have a slightly different version of
350 enum tree_code code
= TREE_CODE (t
);
352 if (EXPR_P (t
) && code
!= LABEL_EXPR
)
354 if (!EXPR_HAS_LOCATION (t
))
355 SET_EXPR_LOCATION (t
, input_location
);
357 /* When we expand a statement-tree, we must know whether or not the
358 statements are full-expressions. We record that fact here. */
359 STMT_IS_FULL_EXPR_P (t
) = stmts_are_full_exprs_p ();
362 /* Add T to the statement-tree. Non-side-effect statements need to be
363 recorded during statement expressions. */
364 append_to_statement_list_force (t
, &cur_stmt_list
);
369 /* Returns the stmt_tree (if any) to which statements are currently
370 being added. If there is no active statement-tree, NULL is
374 current_stmt_tree (void)
377 ? &cfun
->language
->base
.x_stmt_tree
378 : &scope_chain
->x_stmt_tree
);
381 /* If statements are full expressions, wrap STMT in a CLEANUP_POINT_EXPR. */
384 maybe_cleanup_point_expr (tree expr
)
386 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
387 expr
= fold_build_cleanup_point_expr (TREE_TYPE (expr
), expr
);
391 /* Like maybe_cleanup_point_expr except have the type of the new expression be
392 void so we don't need to create a temporary variable to hold the inner
393 expression. The reason why we do this is because the original type might be
394 an aggregate and we cannot create a temporary variable for that type. */
397 maybe_cleanup_point_expr_void (tree expr
)
399 if (!processing_template_decl
&& stmts_are_full_exprs_p ())
400 expr
= fold_build_cleanup_point_expr (void_type_node
, expr
);
406 /* Create a declaration statement for the declaration given by the DECL. */
409 add_decl_expr (tree decl
)
411 tree r
= build_stmt (DECL_EXPR
, decl
);
412 if (DECL_INITIAL (decl
)
413 || (DECL_SIZE (decl
) && TREE_SIDE_EFFECTS (DECL_SIZE (decl
))))
414 r
= maybe_cleanup_point_expr_void (r
);
418 /* Nonzero if TYPE is an anonymous union or struct type. We have to use a
419 flag for this because "A union for which objects or pointers are
420 declared is not an anonymous union" [class.union]. */
423 anon_aggr_type_p (tree node
)
425 return ANON_AGGR_TYPE_P (node
);
428 /* Finish a scope. */
431 do_poplevel (tree stmt_list
)
435 if (stmts_are_full_exprs_p ())
436 block
= poplevel (kept_level_p (), 1, 0);
438 stmt_list
= pop_stmt_list (stmt_list
);
440 if (!processing_template_decl
)
442 stmt_list
= c_build_bind_expr (block
, stmt_list
);
443 /* ??? See c_end_compound_stmt re statement expressions. */
449 /* Begin a new scope. */
452 do_pushlevel (scope_kind sk
)
454 tree ret
= push_stmt_list ();
455 if (stmts_are_full_exprs_p ())
456 begin_scope (sk
, NULL
);
460 /* Queue a cleanup. CLEANUP is an expression/statement to be executed
461 when the current scope is exited. EH_ONLY is true when this is not
462 meant to apply to normal control flow transfer. */
465 push_cleanup (tree decl
, tree cleanup
, bool eh_only
)
467 tree stmt
= build_stmt (CLEANUP_STMT
, NULL
, cleanup
, decl
);
468 CLEANUP_EH_ONLY (stmt
) = eh_only
;
470 CLEANUP_BODY (stmt
) = push_stmt_list ();
473 /* Begin a conditional that might contain a declaration. When generating
474 normal code, we want the declaration to appear before the statement
475 containing the conditional. When generating template code, we want the
476 conditional to be rendered as the raw DECL_EXPR. */
479 begin_cond (tree
*cond_p
)
481 if (processing_template_decl
)
482 *cond_p
= push_stmt_list ();
485 /* Finish such a conditional. */
488 finish_cond (tree
*cond_p
, tree expr
)
490 if (processing_template_decl
)
492 tree cond
= pop_stmt_list (*cond_p
);
493 if (TREE_CODE (cond
) == DECL_EXPR
)
499 /* If *COND_P specifies a conditional with a declaration, transform the
502 for (; A x = 42;) { }
504 while (true) { A x = 42; if (!x) break; }
505 for (;;) { A x = 42; if (!x) break; }
506 The statement list for BODY will be empty if the conditional did
507 not declare anything. */
510 simplify_loop_decl_cond (tree
*cond_p
, tree body
)
514 if (!TREE_SIDE_EFFECTS (body
))
518 *cond_p
= boolean_true_node
;
520 if_stmt
= begin_if_stmt ();
521 cond
= build_unary_op (TRUTH_NOT_EXPR
, cond
, 0);
522 finish_if_stmt_cond (cond
, if_stmt
);
523 finish_break_stmt ();
524 finish_then_clause (if_stmt
);
525 finish_if_stmt (if_stmt
);
528 /* Finish a goto-statement. */
531 finish_goto_stmt (tree destination
)
533 if (TREE_CODE (destination
) == IDENTIFIER_NODE
)
534 destination
= lookup_label (destination
);
536 /* We warn about unused labels with -Wunused. That means we have to
537 mark the used labels as used. */
538 if (TREE_CODE (destination
) == LABEL_DECL
)
539 TREE_USED (destination
) = 1;
542 /* The DESTINATION is being used as an rvalue. */
543 if (!processing_template_decl
)
544 destination
= decay_conversion (destination
);
545 /* We don't inline calls to functions with computed gotos.
546 Those functions are typically up to some funny business,
547 and may be depending on the labels being at particular
548 addresses, or some such. */
549 DECL_UNINLINABLE (current_function_decl
) = 1;
552 check_goto (destination
);
554 return add_stmt (build_stmt (GOTO_EXPR
, destination
));
557 /* COND is the condition-expression for an if, while, etc.,
558 statement. Convert it to a boolean value, if appropriate. */
561 maybe_convert_cond (tree cond
)
563 /* Empty conditions remain empty. */
567 /* Wait until we instantiate templates before doing conversion. */
568 if (processing_template_decl
)
571 /* Do the conversion. */
572 cond
= convert_from_reference (cond
);
573 return condition_conversion (cond
);
576 /* Finish an expression-statement, whose EXPRESSION is as indicated. */
579 finish_expr_stmt (tree expr
)
583 if (expr
!= NULL_TREE
)
585 if (!processing_template_decl
)
587 if (warn_sequence_point
)
588 verify_sequence_points (expr
);
589 expr
= convert_to_void (expr
, "statement");
591 else if (!type_dependent_expression_p (expr
))
592 convert_to_void (build_non_dependent_expr (expr
), "statement");
594 /* Simplification of inner statement expressions, compound exprs,
595 etc can result in us already having an EXPR_STMT. */
596 if (TREE_CODE (expr
) != CLEANUP_POINT_EXPR
)
598 if (TREE_CODE (expr
) != EXPR_STMT
)
599 expr
= build_stmt (EXPR_STMT
, expr
);
600 expr
= maybe_cleanup_point_expr_void (expr
);
612 /* Begin an if-statement. Returns a newly created IF_STMT if
619 scope
= do_pushlevel (sk_block
);
620 r
= build_stmt (IF_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
621 TREE_CHAIN (r
) = scope
;
622 begin_cond (&IF_COND (r
));
626 /* Process the COND of an if-statement, which may be given by
630 finish_if_stmt_cond (tree cond
, tree if_stmt
)
632 finish_cond (&IF_COND (if_stmt
), maybe_convert_cond (cond
));
634 THEN_CLAUSE (if_stmt
) = push_stmt_list ();
637 /* Finish the then-clause of an if-statement, which may be given by
641 finish_then_clause (tree if_stmt
)
643 THEN_CLAUSE (if_stmt
) = pop_stmt_list (THEN_CLAUSE (if_stmt
));
647 /* Begin the else-clause of an if-statement. */
650 begin_else_clause (tree if_stmt
)
652 ELSE_CLAUSE (if_stmt
) = push_stmt_list ();
655 /* Finish the else-clause of an if-statement, which may be given by
659 finish_else_clause (tree if_stmt
)
661 ELSE_CLAUSE (if_stmt
) = pop_stmt_list (ELSE_CLAUSE (if_stmt
));
664 /* Finish an if-statement. */
667 finish_if_stmt (tree if_stmt
)
669 tree scope
= TREE_CHAIN (if_stmt
);
670 TREE_CHAIN (if_stmt
) = NULL
;
671 add_stmt (do_poplevel (scope
));
675 /* Begin a while-statement. Returns a newly created WHILE_STMT if
679 begin_while_stmt (void)
682 r
= build_stmt (WHILE_STMT
, NULL_TREE
, NULL_TREE
);
684 WHILE_BODY (r
) = do_pushlevel (sk_block
);
685 begin_cond (&WHILE_COND (r
));
689 /* Process the COND of a while-statement, which may be given by
693 finish_while_stmt_cond (tree cond
, tree while_stmt
)
695 finish_cond (&WHILE_COND (while_stmt
), maybe_convert_cond (cond
));
696 simplify_loop_decl_cond (&WHILE_COND (while_stmt
), WHILE_BODY (while_stmt
));
699 /* Finish a while-statement, which may be given by WHILE_STMT. */
702 finish_while_stmt (tree while_stmt
)
704 WHILE_BODY (while_stmt
) = do_poplevel (WHILE_BODY (while_stmt
));
708 /* Begin a do-statement. Returns a newly created DO_STMT if
714 tree r
= build_stmt (DO_STMT
, NULL_TREE
, NULL_TREE
);
716 DO_BODY (r
) = push_stmt_list ();
720 /* Finish the body of a do-statement, which may be given by DO_STMT. */
723 finish_do_body (tree do_stmt
)
725 DO_BODY (do_stmt
) = pop_stmt_list (DO_BODY (do_stmt
));
728 /* Finish a do-statement, which may be given by DO_STMT, and whose
729 COND is as indicated. */
732 finish_do_stmt (tree cond
, tree do_stmt
)
734 cond
= maybe_convert_cond (cond
);
735 DO_COND (do_stmt
) = cond
;
739 /* Finish a return-statement. The EXPRESSION returned, if any, is as
743 finish_return_stmt (tree expr
)
748 expr
= check_return_expr (expr
, &no_warning
);
750 if (flag_openmp
&& !check_omp_return ())
751 return error_mark_node
;
752 if (!processing_template_decl
)
754 if (DECL_DESTRUCTOR_P (current_function_decl
)
755 || (DECL_CONSTRUCTOR_P (current_function_decl
)
756 && targetm
.cxx
.cdtor_returns_this ()))
758 /* Similarly, all destructors must run destructors for
759 base-classes before returning. So, all returns in a
760 destructor get sent to the DTOR_LABEL; finish_function emits
761 code to return a value there. */
762 return finish_goto_stmt (cdtor_label
);
766 r
= build_stmt (RETURN_EXPR
, expr
);
767 TREE_NO_WARNING (r
) |= no_warning
;
768 r
= maybe_cleanup_point_expr_void (r
);
775 /* Begin a for-statement. Returns a new FOR_STMT if appropriate. */
778 begin_for_stmt (void)
782 r
= build_stmt (FOR_STMT
, NULL_TREE
, NULL_TREE
,
783 NULL_TREE
, NULL_TREE
);
785 if (flag_new_for_scope
> 0)
786 TREE_CHAIN (r
) = do_pushlevel (sk_for
);
788 if (processing_template_decl
)
789 FOR_INIT_STMT (r
) = push_stmt_list ();
794 /* Finish the for-init-statement of a for-statement, which may be
795 given by FOR_STMT. */
798 finish_for_init_stmt (tree for_stmt
)
800 if (processing_template_decl
)
801 FOR_INIT_STMT (for_stmt
) = pop_stmt_list (FOR_INIT_STMT (for_stmt
));
803 FOR_BODY (for_stmt
) = do_pushlevel (sk_block
);
804 begin_cond (&FOR_COND (for_stmt
));
807 /* Finish the COND of a for-statement, which may be given by
811 finish_for_cond (tree cond
, tree for_stmt
)
813 finish_cond (&FOR_COND (for_stmt
), maybe_convert_cond (cond
));
814 simplify_loop_decl_cond (&FOR_COND (for_stmt
), FOR_BODY (for_stmt
));
817 /* Finish the increment-EXPRESSION in a for-statement, which may be
818 given by FOR_STMT. */
821 finish_for_expr (tree expr
, tree for_stmt
)
825 /* If EXPR is an overloaded function, issue an error; there is no
826 context available to use to perform overload resolution. */
827 if (type_unknown_p (expr
))
829 cxx_incomplete_type_error (expr
, TREE_TYPE (expr
));
830 expr
= error_mark_node
;
832 if (!processing_template_decl
)
834 if (warn_sequence_point
)
835 verify_sequence_points (expr
);
836 expr
= convert_to_void (expr
, "3rd expression in for");
838 else if (!type_dependent_expression_p (expr
))
839 convert_to_void (build_non_dependent_expr (expr
), "3rd expression in for");
840 expr
= maybe_cleanup_point_expr_void (expr
);
841 FOR_EXPR (for_stmt
) = expr
;
844 /* Finish the body of a for-statement, which may be given by
845 FOR_STMT. The increment-EXPR for the loop must be
849 finish_for_stmt (tree for_stmt
)
851 FOR_BODY (for_stmt
) = do_poplevel (FOR_BODY (for_stmt
));
853 /* Pop the scope for the body of the loop. */
854 if (flag_new_for_scope
> 0)
856 tree scope
= TREE_CHAIN (for_stmt
);
857 TREE_CHAIN (for_stmt
) = NULL
;
858 add_stmt (do_poplevel (scope
));
864 /* Finish a break-statement. */
867 finish_break_stmt (void)
869 return add_stmt (build_stmt (BREAK_STMT
));
872 /* Finish a continue-statement. */
875 finish_continue_stmt (void)
877 return add_stmt (build_stmt (CONTINUE_STMT
));
880 /* Begin a switch-statement. Returns a new SWITCH_STMT if
884 begin_switch_stmt (void)
888 r
= build_stmt (SWITCH_STMT
, NULL_TREE
, NULL_TREE
, NULL_TREE
);
890 scope
= do_pushlevel (sk_block
);
891 TREE_CHAIN (r
) = scope
;
892 begin_cond (&SWITCH_STMT_COND (r
));
897 /* Finish the cond of a switch-statement. */
900 finish_switch_cond (tree cond
, tree switch_stmt
)
902 tree orig_type
= NULL
;
903 if (!processing_template_decl
)
907 /* Convert the condition to an integer or enumeration type. */
908 cond
= build_expr_type_conversion (WANT_INT
| WANT_ENUM
, cond
, true);
909 if (cond
== NULL_TREE
)
911 error ("switch quantity not an integer");
912 cond
= error_mark_node
;
914 orig_type
= TREE_TYPE (cond
);
915 if (cond
!= error_mark_node
)
919 Integral promotions are performed. */
920 cond
= perform_integral_promotions (cond
);
921 cond
= maybe_cleanup_point_expr (cond
);
924 if (cond
!= error_mark_node
)
926 index
= get_unwidened (cond
, NULL_TREE
);
927 /* We can't strip a conversion from a signed type to an unsigned,
928 because if we did, int_fits_type_p would do the wrong thing
929 when checking case values for being in range,
930 and it's too hard to do the right thing. */
931 if (TYPE_UNSIGNED (TREE_TYPE (cond
))
932 == TYPE_UNSIGNED (TREE_TYPE (index
)))
936 finish_cond (&SWITCH_STMT_COND (switch_stmt
), cond
);
937 SWITCH_STMT_TYPE (switch_stmt
) = orig_type
;
938 add_stmt (switch_stmt
);
939 push_switch (switch_stmt
);
940 SWITCH_STMT_BODY (switch_stmt
) = push_stmt_list ();
943 /* Finish the body of a switch-statement, which may be given by
944 SWITCH_STMT. The COND to switch on is indicated. */
947 finish_switch_stmt (tree switch_stmt
)
951 SWITCH_STMT_BODY (switch_stmt
) =
952 pop_stmt_list (SWITCH_STMT_BODY (switch_stmt
));
956 scope
= TREE_CHAIN (switch_stmt
);
957 TREE_CHAIN (switch_stmt
) = NULL
;
958 add_stmt (do_poplevel (scope
));
961 /* Begin a try-block. Returns a newly-created TRY_BLOCK if
965 begin_try_block (void)
967 tree r
= build_stmt (TRY_BLOCK
, NULL_TREE
, NULL_TREE
);
969 TRY_STMTS (r
) = push_stmt_list ();
973 /* Likewise, for a function-try-block. */
976 begin_function_try_block (void)
978 tree r
= begin_try_block ();
979 FN_TRY_BLOCK_P (r
) = 1;
983 /* Finish a try-block, which may be given by TRY_BLOCK. */
986 finish_try_block (tree try_block
)
988 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
989 TRY_HANDLERS (try_block
) = push_stmt_list ();
992 /* Finish the body of a cleanup try-block, which may be given by
996 finish_cleanup_try_block (tree try_block
)
998 TRY_STMTS (try_block
) = pop_stmt_list (TRY_STMTS (try_block
));
1001 /* Finish an implicitly generated try-block, with a cleanup is given
1005 finish_cleanup (tree cleanup
, tree try_block
)
1007 TRY_HANDLERS (try_block
) = cleanup
;
1008 CLEANUP_P (try_block
) = 1;
1011 /* Likewise, for a function-try-block. */
1014 finish_function_try_block (tree try_block
)
1016 finish_try_block (try_block
);
1017 /* FIXME : something queer about CTOR_INITIALIZER somehow following
1018 the try block, but moving it inside. */
1019 in_function_try_handler
= 1;
1022 /* Finish a handler-sequence for a try-block, which may be given by
1026 finish_handler_sequence (tree try_block
)
1028 TRY_HANDLERS (try_block
) = pop_stmt_list (TRY_HANDLERS (try_block
));
1029 check_handlers (TRY_HANDLERS (try_block
));
1032 /* Likewise, for a function-try-block. */
1035 finish_function_handler_sequence (tree try_block
)
1037 in_function_try_handler
= 0;
1038 finish_handler_sequence (try_block
);
1041 /* Begin a handler. Returns a HANDLER if appropriate. */
1044 begin_handler (void)
1048 r
= build_stmt (HANDLER
, NULL_TREE
, NULL_TREE
);
1051 /* Create a binding level for the eh_info and the exception object
1053 HANDLER_BODY (r
) = do_pushlevel (sk_catch
);
1058 /* Finish the handler-parameters for a handler, which may be given by
1059 HANDLER. DECL is the declaration for the catch parameter, or NULL
1060 if this is a `catch (...)' clause. */
1063 finish_handler_parms (tree decl
, tree handler
)
1065 tree type
= NULL_TREE
;
1066 if (processing_template_decl
)
1070 decl
= pushdecl (decl
);
1071 decl
= push_template_decl (decl
);
1072 HANDLER_PARMS (handler
) = decl
;
1073 type
= TREE_TYPE (decl
);
1077 type
= expand_start_catch_block (decl
);
1079 HANDLER_TYPE (handler
) = type
;
1080 if (!processing_template_decl
&& type
)
1081 mark_used (eh_type_info (type
));
1084 /* Finish a handler, which may be given by HANDLER. The BLOCKs are
1085 the return value from the matching call to finish_handler_parms. */
1088 finish_handler (tree handler
)
1090 if (!processing_template_decl
)
1091 expand_end_catch_block ();
1092 HANDLER_BODY (handler
) = do_poplevel (HANDLER_BODY (handler
));
1095 /* Begin a compound statement. FLAGS contains some bits that control the
1096 behavior and context. If BCS_NO_SCOPE is set, the compound statement
1097 does not define a scope. If BCS_FN_BODY is set, this is the outermost
1098 block of a function. If BCS_TRY_BLOCK is set, this is the block
1099 created on behalf of a TRY statement. Returns a token to be passed to
1100 finish_compound_stmt. */
1103 begin_compound_stmt (unsigned int flags
)
1107 if (flags
& BCS_NO_SCOPE
)
1109 r
= push_stmt_list ();
1110 STATEMENT_LIST_NO_SCOPE (r
) = 1;
1112 /* Normally, we try hard to keep the BLOCK for a statement-expression.
1113 But, if it's a statement-expression with a scopeless block, there's
1114 nothing to keep, and we don't want to accidentally keep a block
1115 *inside* the scopeless block. */
1116 keep_next_level (false);
1119 r
= do_pushlevel (flags
& BCS_TRY_BLOCK
? sk_try
: sk_block
);
1121 /* When processing a template, we need to remember where the braces were,
1122 so that we can set up identical scopes when instantiating the template
1123 later. BIND_EXPR is a handy candidate for this.
1124 Note that do_poplevel won't create a BIND_EXPR itself here (and thus
1125 result in nested BIND_EXPRs), since we don't build BLOCK nodes when
1126 processing templates. */
1127 if (processing_template_decl
)
1129 r
= build3 (BIND_EXPR
, NULL
, NULL
, r
, NULL
);
1130 BIND_EXPR_TRY_BLOCK (r
) = (flags
& BCS_TRY_BLOCK
) != 0;
1131 BIND_EXPR_BODY_BLOCK (r
) = (flags
& BCS_FN_BODY
) != 0;
1132 TREE_SIDE_EFFECTS (r
) = 1;
1138 /* Finish a compound-statement, which is given by STMT. */
1141 finish_compound_stmt (tree stmt
)
1143 if (TREE_CODE (stmt
) == BIND_EXPR
)
1144 BIND_EXPR_BODY (stmt
) = do_poplevel (BIND_EXPR_BODY (stmt
));
1145 else if (STATEMENT_LIST_NO_SCOPE (stmt
))
1146 stmt
= pop_stmt_list (stmt
);
1149 /* Destroy any ObjC "super" receivers that may have been
1151 objc_clear_super_receiver ();
1153 stmt
= do_poplevel (stmt
);
1156 /* ??? See c_end_compound_stmt wrt statement expressions. */
1161 /* Finish an asm-statement, whose components are a STRING, some
1162 OUTPUT_OPERANDS, some INPUT_OPERANDS, and some CLOBBERS. Also note
1163 whether the asm-statement should be considered volatile. */
1166 finish_asm_stmt (int volatile_p
, tree string
, tree output_operands
,
1167 tree input_operands
, tree clobbers
)
1171 int ninputs
= list_length (input_operands
);
1172 int noutputs
= list_length (output_operands
);
1174 if (!processing_template_decl
)
1176 const char *constraint
;
1177 const char **oconstraints
;
1178 bool allows_mem
, allows_reg
, is_inout
;
1182 oconstraints
= (const char **) alloca (noutputs
* sizeof (char *));
1184 string
= resolve_asm_operand_names (string
, output_operands
,
1187 for (i
= 0, t
= output_operands
; t
; t
= TREE_CHAIN (t
), ++i
)
1189 operand
= TREE_VALUE (t
);
1191 /* ??? Really, this should not be here. Users should be using a
1192 proper lvalue, dammit. But there's a long history of using
1193 casts in the output operands. In cases like longlong.h, this
1194 becomes a primitive form of typechecking -- if the cast can be
1195 removed, then the output operand had a type of the proper width;
1196 otherwise we'll get an error. Gross, but ... */
1197 STRIP_NOPS (operand
);
1199 if (!lvalue_or_else (operand
, lv_asm
))
1200 operand
= error_mark_node
;
1202 if (operand
!= error_mark_node
1203 && (TREE_READONLY (operand
)
1204 || CP_TYPE_CONST_P (TREE_TYPE (operand
))
1205 /* Functions are not modifiable, even though they are
1207 || TREE_CODE (TREE_TYPE (operand
)) == FUNCTION_TYPE
1208 || TREE_CODE (TREE_TYPE (operand
)) == METHOD_TYPE
1209 /* If it's an aggregate and any field is const, then it is
1210 effectively const. */
1211 || (CLASS_TYPE_P (TREE_TYPE (operand
))
1212 && C_TYPE_FIELDS_READONLY (TREE_TYPE (operand
)))))
1213 readonly_error (operand
, "assignment (via 'asm' output)", 0);
1215 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1216 oconstraints
[i
] = constraint
;
1218 if (parse_output_constraint (&constraint
, i
, ninputs
, noutputs
,
1219 &allows_mem
, &allows_reg
, &is_inout
))
1221 /* If the operand is going to end up in memory,
1222 mark it addressable. */
1223 if (!allows_reg
&& !cxx_mark_addressable (operand
))
1224 operand
= error_mark_node
;
1227 operand
= error_mark_node
;
1229 TREE_VALUE (t
) = operand
;
1232 for (i
= 0, t
= input_operands
; t
; ++i
, t
= TREE_CHAIN (t
))
1234 constraint
= TREE_STRING_POINTER (TREE_VALUE (TREE_PURPOSE (t
)));
1235 operand
= decay_conversion (TREE_VALUE (t
));
1237 /* If the type of the operand hasn't been determined (e.g.,
1238 because it involves an overloaded function), then issue
1239 an error message. There's no context available to
1240 resolve the overloading. */
1241 if (TREE_TYPE (operand
) == unknown_type_node
)
1243 error ("type of asm operand %qE could not be determined",
1245 operand
= error_mark_node
;
1248 if (parse_input_constraint (&constraint
, i
, ninputs
, noutputs
, 0,
1249 oconstraints
, &allows_mem
, &allows_reg
))
1251 /* If the operand is going to end up in memory,
1252 mark it addressable. */
1253 if (!allows_reg
&& allows_mem
)
1255 /* Strip the nops as we allow this case. FIXME, this really
1256 should be rejected or made deprecated. */
1257 STRIP_NOPS (operand
);
1258 if (!cxx_mark_addressable (operand
))
1259 operand
= error_mark_node
;
1263 operand
= error_mark_node
;
1265 TREE_VALUE (t
) = operand
;
1269 r
= build_stmt (ASM_EXPR
, string
,
1270 output_operands
, input_operands
,
1272 ASM_VOLATILE_P (r
) = volatile_p
|| noutputs
== 0;
1273 r
= maybe_cleanup_point_expr_void (r
);
1274 return add_stmt (r
);
1277 /* Finish a label with the indicated NAME. */
1280 finish_label_stmt (tree name
)
1282 tree decl
= define_label (input_location
, name
);
1283 return add_stmt (build_stmt (LABEL_EXPR
, decl
));
1286 /* Finish a series of declarations for local labels. G++ allows users
1287 to declare "local" labels, i.e., labels with scope. This extension
1288 is useful when writing code involving statement-expressions. */
1291 finish_label_decl (tree name
)
1293 tree decl
= declare_local_label (name
);
1294 add_decl_expr (decl
);
1297 /* When DECL goes out of scope, make sure that CLEANUP is executed. */
1300 finish_decl_cleanup (tree decl
, tree cleanup
)
1302 push_cleanup (decl
, cleanup
, false);
1305 /* If the current scope exits with an exception, run CLEANUP. */
1308 finish_eh_cleanup (tree cleanup
)
1310 push_cleanup (NULL
, cleanup
, true);
1313 /* The MEM_INITS is a list of mem-initializers, in reverse of the
1314 order they were written by the user. Each node is as for
1315 emit_mem_initializers. */
1318 finish_mem_initializers (tree mem_inits
)
1320 /* Reorder the MEM_INITS so that they are in the order they appeared
1321 in the source program. */
1322 mem_inits
= nreverse (mem_inits
);
1324 if (processing_template_decl
)
1325 add_stmt (build_min_nt (CTOR_INITIALIZER
, mem_inits
));
1327 emit_mem_initializers (mem_inits
);
1330 /* Finish a parenthesized expression EXPR. */
1333 finish_parenthesized_expr (tree expr
)
1336 /* This inhibits warnings in c_common_truthvalue_conversion. */
1337 TREE_NO_WARNING (expr
) = 1;
1339 if (TREE_CODE (expr
) == OFFSET_REF
)
1340 /* [expr.unary.op]/3 The qualified id of a pointer-to-member must not be
1341 enclosed in parentheses. */
1342 PTRMEM_OK_P (expr
) = 0;
1344 if (TREE_CODE (expr
) == STRING_CST
)
1345 PAREN_STRING_LITERAL_P (expr
) = 1;
1350 /* Finish a reference to a non-static data member (DECL) that is not
1351 preceded by `.' or `->'. */
1354 finish_non_static_data_member (tree decl
, tree object
, tree qualifying_scope
)
1356 gcc_assert (TREE_CODE (decl
) == FIELD_DECL
);
1360 if (current_function_decl
1361 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1362 error ("invalid use of member %q+D in static member function", decl
);
1364 error ("invalid use of non-static data member %q+D", decl
);
1365 error ("from this location");
1367 return error_mark_node
;
1369 TREE_USED (current_class_ptr
) = 1;
1370 if (processing_template_decl
&& !qualifying_scope
)
1372 tree type
= TREE_TYPE (decl
);
1374 if (TREE_CODE (type
) == REFERENCE_TYPE
)
1375 type
= TREE_TYPE (type
);
1378 /* Set the cv qualifiers. */
1379 int quals
= cp_type_quals (TREE_TYPE (current_class_ref
));
1381 if (DECL_MUTABLE_P (decl
))
1382 quals
&= ~TYPE_QUAL_CONST
;
1384 quals
|= cp_type_quals (TREE_TYPE (decl
));
1385 type
= cp_build_qualified_type (type
, quals
);
1388 return build_min (COMPONENT_REF
, type
, object
, decl
, NULL_TREE
);
1392 tree access_type
= TREE_TYPE (object
);
1393 tree lookup_context
= context_for_name_lookup (decl
);
1395 while (!DERIVED_FROM_P (lookup_context
, access_type
))
1397 access_type
= TYPE_CONTEXT (access_type
);
1398 while (access_type
&& DECL_P (access_type
))
1399 access_type
= DECL_CONTEXT (access_type
);
1403 error ("object missing in reference to %q+D", decl
);
1404 error ("from this location");
1405 return error_mark_node
;
1409 /* If PROCESSING_TEMPLATE_DECL is nonzero here, then
1410 QUALIFYING_SCOPE is also non-null. Wrap this in a SCOPE_REF
1412 if (processing_template_decl
)
1413 return build_qualified_name (TREE_TYPE (decl
),
1416 /*template_p=*/false);
1418 perform_or_defer_access_check (TYPE_BINFO (access_type
), decl
);
1420 /* If the data member was named `C::M', convert `*this' to `C'
1422 if (qualifying_scope
)
1424 tree binfo
= NULL_TREE
;
1425 object
= build_scoped_ref (object
, qualifying_scope
,
1429 return build_class_member_access_expr (object
, decl
,
1430 /*access_path=*/NULL_TREE
,
1431 /*preserve_reference=*/false);
1435 /* DECL was the declaration to which a qualified-id resolved. Issue
1436 an error message if it is not accessible. If OBJECT_TYPE is
1437 non-NULL, we have just seen `x->' or `x.' and OBJECT_TYPE is the
1438 type of `*x', or `x', respectively. If the DECL was named as
1439 `A::B' then NESTED_NAME_SPECIFIER is `A'. */
1442 check_accessibility_of_qualified_id (tree decl
,
1444 tree nested_name_specifier
)
1447 tree qualifying_type
= NULL_TREE
;
1449 /* If we're not checking, return immediately. */
1450 if (deferred_access_no_check
)
1453 /* Determine the SCOPE of DECL. */
1454 scope
= context_for_name_lookup (decl
);
1455 /* If the SCOPE is not a type, then DECL is not a member. */
1456 if (!TYPE_P (scope
))
1458 /* Compute the scope through which DECL is being accessed. */
1460 /* OBJECT_TYPE might not be a class type; consider:
1462 class A { typedef int I; };
1466 In this case, we will have "A::I" as the DECL, but "I" as the
1468 && CLASS_TYPE_P (object_type
)
1469 && DERIVED_FROM_P (scope
, object_type
))
1470 /* If we are processing a `->' or `.' expression, use the type of the
1472 qualifying_type
= object_type
;
1473 else if (nested_name_specifier
)
1475 /* If the reference is to a non-static member of the
1476 current class, treat it as if it were referenced through
1478 if (DECL_NONSTATIC_MEMBER_P (decl
)
1479 && current_class_ptr
1480 && DERIVED_FROM_P (scope
, current_class_type
))
1481 qualifying_type
= current_class_type
;
1482 /* Otherwise, use the type indicated by the
1483 nested-name-specifier. */
1485 qualifying_type
= nested_name_specifier
;
1488 /* Otherwise, the name must be from the current class or one of
1490 qualifying_type
= currently_open_derived_class (scope
);
1492 if (qualifying_type
&& IS_AGGR_TYPE_CODE (TREE_CODE (qualifying_type
)))
1493 /* It is possible for qualifying type to be a TEMPLATE_TYPE_PARM
1494 or similar in a default argument value. */
1495 perform_or_defer_access_check (TYPE_BINFO (qualifying_type
), decl
);
1498 /* EXPR is the result of a qualified-id. The QUALIFYING_CLASS was the
1499 class named to the left of the "::" operator. DONE is true if this
1500 expression is a complete postfix-expression; it is false if this
1501 expression is followed by '->', '[', '(', etc. ADDRESS_P is true
1502 iff this expression is the operand of '&'. TEMPLATE_P is true iff
1503 the qualified-id was of the form "A::template B". TEMPLATE_ARG_P
1504 is true iff this qualified name appears as a template argument. */
1507 finish_qualified_id_expr (tree qualifying_class
,
1512 bool template_arg_p
)
1514 if (error_operand_p (expr
))
1515 return error_mark_node
;
1518 check_template_keyword (expr
);
1520 /* If EXPR occurs as the operand of '&', use special handling that
1521 permits a pointer-to-member. */
1522 if (address_p
&& done
)
1524 if (TREE_CODE (expr
) == SCOPE_REF
)
1525 expr
= TREE_OPERAND (expr
, 1);
1526 expr
= build_offset_ref (qualifying_class
, expr
,
1527 /*address_p=*/true);
1531 /* Within the scope of a class, turn references to non-static
1532 members into expression of the form "this->...". */
1534 /* But, within a template argument, we do not want make the
1535 transformation, as there is no "this" pointer. */
1537 else if (TREE_CODE (expr
) == FIELD_DECL
)
1538 expr
= finish_non_static_data_member (expr
, current_class_ref
,
1540 else if (BASELINK_P (expr
) && !processing_template_decl
)
1544 /* See if any of the functions are non-static members. */
1545 fns
= BASELINK_FUNCTIONS (expr
);
1546 if (TREE_CODE (fns
) == TEMPLATE_ID_EXPR
)
1547 fns
= TREE_OPERAND (fns
, 0);
1548 /* If so, the expression may be relative to the current
1550 if (!shared_member_p (fns
)
1551 && current_class_type
1552 && DERIVED_FROM_P (qualifying_class
, current_class_type
))
1553 expr
= (build_class_member_access_expr
1554 (maybe_dummy_object (qualifying_class
, NULL
),
1556 BASELINK_ACCESS_BINFO (expr
),
1557 /*preserve_reference=*/false));
1559 /* The expression is a qualified name whose address is not
1561 expr
= build_offset_ref (qualifying_class
, expr
, /*address_p=*/false);
1567 /* Begin a statement-expression. The value returned must be passed to
1568 finish_stmt_expr. */
1571 begin_stmt_expr (void)
1573 return push_stmt_list ();
1576 /* Process the final expression of a statement expression. EXPR can be
1577 NULL, if the final expression is empty. Return a STATEMENT_LIST
1578 containing all the statements in the statement-expression, or
1579 ERROR_MARK_NODE if there was an error. */
1582 finish_stmt_expr_expr (tree expr
, tree stmt_expr
)
1584 if (error_operand_p (expr
))
1585 return error_mark_node
;
1587 /* If the last statement does not have "void" type, then the value
1588 of the last statement is the value of the entire expression. */
1592 type
= TREE_TYPE (expr
);
1593 if (!dependent_type_p (type
) && !VOID_TYPE_P (type
))
1595 expr
= decay_conversion (expr
);
1596 if (error_operand_p (expr
))
1597 return error_mark_node
;
1598 type
= TREE_TYPE (expr
);
1600 /* The type of the statement-expression is the type of the last
1602 TREE_TYPE (stmt_expr
) = type
;
1603 /* We must take particular care if TYPE is a class type. In
1604 particular if EXPR creates a temporary of class type, then it
1605 must be destroyed at the semicolon terminating the last
1606 statement -- but we must make a copy before that happens.
1608 This problem is solved by using a TARGET_EXPR to initialize a
1609 new temporary variable. The TARGET_EXPR itself is placed
1610 outside the statement-expression. However, the last
1611 statement in the statement-expression is transformed from
1612 EXPR to (approximately) T = EXPR, where T is the new
1613 temporary variable. Thus, the lifetime of the new temporary
1614 extends to the full-expression surrounding the
1615 statement-expression. */
1616 if (!processing_template_decl
&& !VOID_TYPE_P (type
))
1619 if (CLASS_TYPE_P (type
)
1620 && !TYPE_HAS_TRIVIAL_INIT_REF (type
))
1622 target_expr
= build_target_expr_with_type (expr
, type
);
1623 expr
= TARGET_EXPR_INITIAL (target_expr
);
1627 /* Normally, build_target_expr will not create a
1628 TARGET_EXPR for scalars. However, we need the
1629 temporary here, in order to solve the scoping
1630 problem described above. */
1631 target_expr
= force_target_expr (type
, expr
);
1632 expr
= TARGET_EXPR_INITIAL (target_expr
);
1633 expr
= build2 (INIT_EXPR
,
1635 TARGET_EXPR_SLOT (target_expr
),
1638 TARGET_EXPR_INITIAL (target_expr
) = NULL_TREE
;
1639 /* Save away the TARGET_EXPR in the TREE_TYPE field of the
1640 STATEMENT_EXPR. We will retrieve it in
1641 finish_stmt_expr. */
1642 TREE_TYPE (stmt_expr
) = target_expr
;
1646 /* Having modified EXPR to reflect the extra initialization, we now
1647 treat it just like an ordinary statement. */
1648 expr
= finish_expr_stmt (expr
);
1650 /* Mark the last statement so that we can recognize it as such at
1651 template-instantiation time. */
1652 if (expr
&& processing_template_decl
)
1653 EXPR_STMT_STMT_EXPR_RESULT (expr
) = 1;
1658 /* Finish a statement-expression. EXPR should be the value returned
1659 by the previous begin_stmt_expr. Returns an expression
1660 representing the statement-expression. */
1663 finish_stmt_expr (tree stmt_expr
, bool has_no_scope
)
1668 if (error_operand_p (stmt_expr
))
1669 return error_mark_node
;
1671 gcc_assert (TREE_CODE (stmt_expr
) == STATEMENT_LIST
);
1673 type
= TREE_TYPE (stmt_expr
);
1674 result
= pop_stmt_list (stmt_expr
);
1676 if (processing_template_decl
)
1678 result
= build_min (STMT_EXPR
, type
, result
);
1679 TREE_SIDE_EFFECTS (result
) = 1;
1680 STMT_EXPR_NO_SCOPE (result
) = has_no_scope
;
1682 else if (!TYPE_P (type
))
1684 gcc_assert (TREE_CODE (type
) == TARGET_EXPR
);
1685 TARGET_EXPR_INITIAL (type
) = result
;
1686 TREE_TYPE (result
) = void_type_node
;
1693 /* Perform Koenig lookup. FN is the postfix-expression representing
1694 the function (or functions) to call; ARGS are the arguments to the
1695 call. Returns the functions to be considered by overload
1699 perform_koenig_lookup (tree fn
, tree args
)
1701 tree identifier
= NULL_TREE
;
1702 tree functions
= NULL_TREE
;
1704 /* Find the name of the overloaded function. */
1705 if (TREE_CODE (fn
) == IDENTIFIER_NODE
)
1707 else if (is_overloaded_fn (fn
))
1710 identifier
= DECL_NAME (get_first_fn (functions
));
1712 else if (DECL_P (fn
))
1715 identifier
= DECL_NAME (fn
);
1718 /* A call to a namespace-scope function using an unqualified name.
1720 Do Koenig lookup -- unless any of the arguments are
1722 if (!any_type_dependent_arguments_p (args
))
1724 fn
= lookup_arg_dependent (identifier
, functions
, args
);
1726 /* The unqualified name could not be resolved. */
1727 fn
= unqualified_fn_lookup_error (identifier
);
1733 /* Generate an expression for `FN (ARGS)'.
1735 If DISALLOW_VIRTUAL is true, the call to FN will be not generated
1736 as a virtual call, even if FN is virtual. (This flag is set when
1737 encountering an expression where the function name is explicitly
1738 qualified. For example a call to `X::f' never generates a virtual
1741 Returns code for the call. */
1744 finish_call_expr (tree fn
, tree args
, bool disallow_virtual
, bool koenig_p
)
1750 if (fn
== error_mark_node
|| args
== error_mark_node
)
1751 return error_mark_node
;
1753 /* ARGS should be a list of arguments. */
1754 gcc_assert (!args
|| TREE_CODE (args
) == TREE_LIST
);
1759 if (processing_template_decl
)
1761 if (type_dependent_expression_p (fn
)
1762 || any_type_dependent_arguments_p (args
))
1764 result
= build_nt (CALL_EXPR
, fn
, args
, NULL_TREE
);
1765 KOENIG_LOOKUP_P (result
) = koenig_p
;
1768 if (!BASELINK_P (fn
)
1769 && TREE_CODE (fn
) != PSEUDO_DTOR_EXPR
1770 && TREE_TYPE (fn
) != unknown_type_node
)
1771 fn
= build_non_dependent_expr (fn
);
1772 args
= build_non_dependent_args (orig_args
);
1775 /* A reference to a member function will appear as an overloaded
1776 function (rather than a BASELINK) if an unqualified name was used
1778 if (!BASELINK_P (fn
) && is_overloaded_fn (fn
))
1782 if (TREE_CODE (f
) == TEMPLATE_ID_EXPR
)
1783 f
= TREE_OPERAND (f
, 0);
1784 f
= get_first_fn (f
);
1785 if (DECL_FUNCTION_MEMBER_P (f
))
1787 tree type
= currently_open_derived_class (DECL_CONTEXT (f
));
1789 type
= DECL_CONTEXT (f
);
1790 fn
= build_baselink (TYPE_BINFO (type
),
1792 fn
, /*optype=*/NULL_TREE
);
1797 if (BASELINK_P (fn
))
1801 /* A call to a member function. From [over.call.func]:
1803 If the keyword this is in scope and refers to the class of
1804 that member function, or a derived class thereof, then the
1805 function call is transformed into a qualified function call
1806 using (*this) as the postfix-expression to the left of the
1807 . operator.... [Otherwise] a contrived object of type T
1808 becomes the implied object argument.
1810 This paragraph is unclear about this situation:
1812 struct A { void f(); };
1813 struct B : public A {};
1814 struct C : public A { void g() { B::f(); }};
1816 In particular, for `B::f', this paragraph does not make clear
1817 whether "the class of that member function" refers to `A' or
1818 to `B'. We believe it refers to `B'. */
1819 if (current_class_type
1820 && DERIVED_FROM_P (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
1822 && current_class_ref
)
1823 object
= maybe_dummy_object (BINFO_TYPE (BASELINK_ACCESS_BINFO (fn
)),
1827 tree representative_fn
;
1829 representative_fn
= BASELINK_FUNCTIONS (fn
);
1830 if (TREE_CODE (representative_fn
) == TEMPLATE_ID_EXPR
)
1831 representative_fn
= TREE_OPERAND (representative_fn
, 0);
1832 representative_fn
= get_first_fn (representative_fn
);
1833 object
= build_dummy_object (DECL_CONTEXT (representative_fn
));
1836 if (processing_template_decl
)
1838 if (type_dependent_expression_p (object
))
1839 return build_nt (CALL_EXPR
, orig_fn
, orig_args
, NULL_TREE
);
1840 object
= build_non_dependent_expr (object
);
1843 result
= build_new_method_call (object
, fn
, args
, NULL_TREE
,
1845 ? LOOKUP_NONVIRTUAL
: 0));
1847 else if (is_overloaded_fn (fn
))
1849 /* If the function is an overloaded builtin, resolve it. */
1850 if (TREE_CODE (fn
) == FUNCTION_DECL
1851 && (DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_NORMAL
1852 || DECL_BUILT_IN_CLASS (fn
) == BUILT_IN_MD
))
1853 result
= resolve_overloaded_builtin (fn
, args
);
1856 /* A call to a namespace-scope function. */
1857 result
= build_new_function_call (fn
, args
, koenig_p
);
1859 else if (TREE_CODE (fn
) == PSEUDO_DTOR_EXPR
)
1862 error ("arguments to destructor are not allowed");
1863 /* Mark the pseudo-destructor call as having side-effects so
1864 that we do not issue warnings about its use. */
1865 result
= build1 (NOP_EXPR
,
1867 TREE_OPERAND (fn
, 0));
1868 TREE_SIDE_EFFECTS (result
) = 1;
1870 else if (CLASS_TYPE_P (TREE_TYPE (fn
)))
1871 /* If the "function" is really an object of class type, it might
1872 have an overloaded `operator ()'. */
1873 result
= build_new_op (CALL_EXPR
, LOOKUP_NORMAL
, fn
, args
, NULL_TREE
,
1874 /*overloaded_p=*/NULL
);
1877 /* A call where the function is unknown. */
1878 result
= build_function_call (fn
, args
);
1880 if (processing_template_decl
)
1882 result
= build3 (CALL_EXPR
, TREE_TYPE (result
), orig_fn
,
1883 orig_args
, NULL_TREE
);
1884 KOENIG_LOOKUP_P (result
) = koenig_p
;
1889 /* Finish a call to a postfix increment or decrement or EXPR. (Which
1890 is indicated by CODE, which should be POSTINCREMENT_EXPR or
1891 POSTDECREMENT_EXPR.) */
1894 finish_increment_expr (tree expr
, enum tree_code code
)
1896 return build_x_unary_op (code
, expr
);
1899 /* Finish a use of `this'. Returns an expression for `this'. */
1902 finish_this_expr (void)
1906 if (current_class_ptr
)
1908 result
= current_class_ptr
;
1910 else if (current_function_decl
1911 && DECL_STATIC_FUNCTION_P (current_function_decl
))
1913 error ("%<this%> is unavailable for static member functions");
1914 result
= error_mark_node
;
1918 if (current_function_decl
)
1919 error ("invalid use of %<this%> in non-member function");
1921 error ("invalid use of %<this%> at top level");
1922 result
= error_mark_node
;
1928 /* Finish a pseudo-destructor expression. If SCOPE is NULL, the
1929 expression was of the form `OBJECT.~DESTRUCTOR' where DESTRUCTOR is
1930 the TYPE for the type given. If SCOPE is non-NULL, the expression
1931 was of the form `OBJECT.SCOPE::~DESTRUCTOR'. */
1934 finish_pseudo_destructor_expr (tree object
, tree scope
, tree destructor
)
1936 if (destructor
== error_mark_node
)
1937 return error_mark_node
;
1939 gcc_assert (TYPE_P (destructor
));
1941 if (!processing_template_decl
)
1943 if (scope
== error_mark_node
)
1945 error ("invalid qualifying scope in pseudo-destructor name");
1946 return error_mark_node
;
1949 /* [expr.pseudo] says both:
1951 The type designated by the pseudo-destructor-name shall be
1952 the same as the object type.
1956 The cv-unqualified versions of the object type and of the
1957 type designated by the pseudo-destructor-name shall be the
1960 We implement the more generous second sentence, since that is
1961 what most other compilers do. */
1962 if (!same_type_ignoring_top_level_qualifiers_p (TREE_TYPE (object
),
1965 error ("%qE is not of type %qT", object
, destructor
);
1966 return error_mark_node
;
1970 return build3 (PSEUDO_DTOR_EXPR
, void_type_node
, object
, scope
, destructor
);
1973 /* Finish an expression of the form CODE EXPR. */
1976 finish_unary_op_expr (enum tree_code code
, tree expr
)
1978 tree result
= build_x_unary_op (code
, expr
);
1979 /* Inside a template, build_x_unary_op does not fold the
1980 expression. So check whether the result is folded before
1981 setting TREE_NEGATED_INT. */
1982 if (code
== NEGATE_EXPR
&& TREE_CODE (expr
) == INTEGER_CST
1983 && TREE_CODE (result
) == INTEGER_CST
1984 && !TYPE_UNSIGNED (TREE_TYPE (result
))
1985 && INT_CST_LT (result
, integer_zero_node
))
1987 /* RESULT may be a cached INTEGER_CST, so we must copy it before
1988 setting TREE_NEGATED_INT. */
1989 result
= copy_node (result
);
1990 TREE_NEGATED_INT (result
) = 1;
1992 overflow_warning (result
);
1996 /* Finish a compound-literal expression. TYPE is the type to which
1997 the INITIALIZER_LIST is being cast. */
2000 finish_compound_literal (tree type
, VEC(constructor_elt
,gc
) *initializer_list
)
2002 tree compound_literal
;
2004 /* Build a CONSTRUCTOR for the INITIALIZER_LIST. */
2005 compound_literal
= build_constructor (NULL_TREE
, initializer_list
);
2006 /* Mark it as a compound-literal. */
2007 if (processing_template_decl
)
2008 TREE_TYPE (compound_literal
) = type
;
2011 /* Check the initialization. */
2012 compound_literal
= digest_init (type
, compound_literal
);
2013 /* If the TYPE was an array type with an unknown bound, then we can
2014 figure out the dimension now. For example, something like:
2018 implies that the array has two elements. */
2019 if (TREE_CODE (type
) == ARRAY_TYPE
&& !COMPLETE_TYPE_P (type
))
2020 cp_complete_array_type (&TREE_TYPE (compound_literal
),
2021 compound_literal
, 1);
2024 TREE_HAS_CONSTRUCTOR (compound_literal
) = 1;
2025 return compound_literal
;
2028 /* Return the declaration for the function-name variable indicated by
2032 finish_fname (tree id
)
2036 decl
= fname_decl (C_RID_CODE (id
), id
);
2037 if (processing_template_decl
)
2038 decl
= DECL_NAME (decl
);
2042 /* Finish a translation unit. */
2045 finish_translation_unit (void)
2047 /* In case there were missing closebraces,
2048 get us back to the global binding level. */
2050 while (current_namespace
!= global_namespace
)
2053 /* Do file scope __FUNCTION__ et al. */
2054 finish_fname_decls ();
2057 /* Finish a template type parameter, specified as AGGR IDENTIFIER.
2058 Returns the parameter. */
2061 finish_template_type_parm (tree aggr
, tree identifier
)
2063 if (aggr
!= class_type_node
)
2065 pedwarn ("template type parameters must use the keyword %<class%> or %<typename%>");
2066 aggr
= class_type_node
;
2069 return build_tree_list (aggr
, identifier
);
2072 /* Finish a template template parameter, specified as AGGR IDENTIFIER.
2073 Returns the parameter. */
2076 finish_template_template_parm (tree aggr
, tree identifier
)
2078 tree decl
= build_decl (TYPE_DECL
, identifier
, NULL_TREE
);
2079 tree tmpl
= build_lang_decl (TEMPLATE_DECL
, identifier
, NULL_TREE
);
2080 DECL_TEMPLATE_PARMS (tmpl
) = current_template_parms
;
2081 DECL_TEMPLATE_RESULT (tmpl
) = decl
;
2082 DECL_ARTIFICIAL (decl
) = 1;
2083 end_template_decl ();
2085 gcc_assert (DECL_TEMPLATE_PARMS (tmpl
));
2087 return finish_template_type_parm (aggr
, tmpl
);
2090 /* ARGUMENT is the default-argument value for a template template
2091 parameter. If ARGUMENT is invalid, issue error messages and return
2092 the ERROR_MARK_NODE. Otherwise, ARGUMENT itself is returned. */
2095 check_template_template_default_arg (tree argument
)
2097 if (TREE_CODE (argument
) != TEMPLATE_DECL
2098 && TREE_CODE (argument
) != TEMPLATE_TEMPLATE_PARM
2099 && TREE_CODE (argument
) != UNBOUND_CLASS_TEMPLATE
)
2101 if (TREE_CODE (argument
) == TYPE_DECL
)
2103 tree t
= TREE_TYPE (argument
);
2105 /* Try to emit a slightly smarter error message if we detect
2106 that the user is using a template instantiation. */
2107 if (CLASSTYPE_TEMPLATE_INFO (t
)
2108 && CLASSTYPE_TEMPLATE_INSTANTIATION (t
))
2109 error ("invalid use of type %qT as a default value for a "
2110 "template template-parameter", t
);
2112 error ("invalid use of %qD as a default value for a template "
2113 "template-parameter", argument
);
2116 error ("invalid default argument for a template template parameter");
2117 return error_mark_node
;
2123 /* Begin a class definition, as indicated by T. */
2126 begin_class_definition (tree t
)
2128 if (t
== error_mark_node
)
2129 return error_mark_node
;
2131 if (processing_template_parmlist
)
2133 error ("definition of %q#T inside template parameter list", t
);
2134 return error_mark_node
;
2136 /* A non-implicit typename comes from code like:
2138 template <typename T> struct A {
2139 template <typename U> struct A<T>::B ...
2141 This is erroneous. */
2142 else if (TREE_CODE (t
) == TYPENAME_TYPE
)
2144 error ("invalid definition of qualified type %qT", t
);
2145 t
= error_mark_node
;
2148 if (t
== error_mark_node
|| ! IS_AGGR_TYPE (t
))
2150 t
= make_aggr_type (RECORD_TYPE
);
2151 pushtag (make_anon_name (), t
, /*tag_scope=*/ts_current
);
2154 /* Update the location of the decl. */
2155 DECL_SOURCE_LOCATION (TYPE_NAME (t
)) = input_location
;
2157 if (TYPE_BEING_DEFINED (t
))
2159 t
= make_aggr_type (TREE_CODE (t
));
2160 pushtag (TYPE_IDENTIFIER (t
), t
, /*tag_scope=*/ts_current
);
2162 maybe_process_partial_specialization (t
);
2164 TYPE_BEING_DEFINED (t
) = 1;
2165 if (flag_pack_struct
)
2168 TYPE_PACKED (t
) = 1;
2169 /* Even though the type is being defined for the first time
2170 here, there might have been a forward declaration, so there
2171 might be cv-qualified variants of T. */
2172 for (v
= TYPE_NEXT_VARIANT (t
); v
; v
= TYPE_NEXT_VARIANT (v
))
2173 TYPE_PACKED (v
) = 1;
2175 /* Reset the interface data, at the earliest possible
2176 moment, as it might have been set via a class foo;
2178 if (! TYPE_ANONYMOUS_P (t
))
2180 struct c_fileinfo
*finfo
= get_fileinfo (lbasename (input_filename
));
2181 CLASSTYPE_INTERFACE_ONLY (t
) = finfo
->interface_only
;
2182 SET_CLASSTYPE_INTERFACE_UNKNOWN_X
2183 (t
, finfo
->interface_unknown
);
2185 reset_specialization();
2187 /* Make a declaration for this class in its own scope. */
2188 build_self_reference ();
2193 /* Finish the member declaration given by DECL. */
2196 finish_member_declaration (tree decl
)
2198 if (decl
== error_mark_node
|| decl
== NULL_TREE
)
2201 if (decl
== void_type_node
)
2202 /* The COMPONENT was a friend, not a member, and so there's
2203 nothing for us to do. */
2206 /* We should see only one DECL at a time. */
2207 gcc_assert (TREE_CHAIN (decl
) == NULL_TREE
);
2209 /* Set up access control for DECL. */
2211 = (current_access_specifier
== access_private_node
);
2212 TREE_PROTECTED (decl
)
2213 = (current_access_specifier
== access_protected_node
);
2214 if (TREE_CODE (decl
) == TEMPLATE_DECL
)
2216 TREE_PRIVATE (DECL_TEMPLATE_RESULT (decl
)) = TREE_PRIVATE (decl
);
2217 TREE_PROTECTED (DECL_TEMPLATE_RESULT (decl
)) = TREE_PROTECTED (decl
);
2220 /* Mark the DECL as a member of the current class. */
2221 DECL_CONTEXT (decl
) = current_class_type
;
2225 A C language linkage is ignored for the names of class members
2226 and the member function type of class member functions. */
2227 if (DECL_LANG_SPECIFIC (decl
) && DECL_LANGUAGE (decl
) == lang_c
)
2228 SET_DECL_LANGUAGE (decl
, lang_cplusplus
);
2230 /* Put functions on the TYPE_METHODS list and everything else on the
2231 TYPE_FIELDS list. Note that these are built up in reverse order.
2232 We reverse them (to obtain declaration order) in finish_struct. */
2233 if (TREE_CODE (decl
) == FUNCTION_DECL
2234 || DECL_FUNCTION_TEMPLATE_P (decl
))
2236 /* We also need to add this function to the
2237 CLASSTYPE_METHOD_VEC. */
2238 if (add_method (current_class_type
, decl
, NULL_TREE
))
2240 TREE_CHAIN (decl
) = TYPE_METHODS (current_class_type
);
2241 TYPE_METHODS (current_class_type
) = decl
;
2243 maybe_add_class_template_decl_list (current_class_type
, decl
,
2247 /* Enter the DECL into the scope of the class. */
2248 else if ((TREE_CODE (decl
) == USING_DECL
&& !DECL_DEPENDENT_P (decl
))
2249 || pushdecl_class_level (decl
))
2251 /* All TYPE_DECLs go at the end of TYPE_FIELDS. Ordinary fields
2252 go at the beginning. The reason is that lookup_field_1
2253 searches the list in order, and we want a field name to
2254 override a type name so that the "struct stat hack" will
2255 work. In particular:
2257 struct S { enum E { }; int E } s;
2260 is valid. In addition, the FIELD_DECLs must be maintained in
2261 declaration order so that class layout works as expected.
2262 However, we don't need that order until class layout, so we
2263 save a little time by putting FIELD_DECLs on in reverse order
2264 here, and then reversing them in finish_struct_1. (We could
2265 also keep a pointer to the correct insertion points in the
2268 if (TREE_CODE (decl
) == TYPE_DECL
)
2269 TYPE_FIELDS (current_class_type
)
2270 = chainon (TYPE_FIELDS (current_class_type
), decl
);
2273 TREE_CHAIN (decl
) = TYPE_FIELDS (current_class_type
);
2274 TYPE_FIELDS (current_class_type
) = decl
;
2277 maybe_add_class_template_decl_list (current_class_type
, decl
,
2282 note_decl_for_pch (decl
);
2285 /* DECL has been declared while we are building a PCH file. Perform
2286 actions that we might normally undertake lazily, but which can be
2287 performed now so that they do not have to be performed in
2288 translation units which include the PCH file. */
2291 note_decl_for_pch (tree decl
)
2293 gcc_assert (pch_file
);
2295 /* There's a good chance that we'll have to mangle names at some
2296 point, even if only for emission in debugging information. */
2297 if (TREE_CODE (decl
) == VAR_DECL
2298 || TREE_CODE (decl
) == FUNCTION_DECL
)
2302 /* Finish processing a complete template declaration. The PARMS are
2303 the template parameters. */
2306 finish_template_decl (tree parms
)
2309 end_template_decl ();
2311 end_specialization ();
2314 /* Finish processing a template-id (which names a type) of the form
2315 NAME < ARGS >. Return the TYPE_DECL for the type named by the
2316 template-id. If ENTERING_SCOPE is nonzero we are about to enter
2317 the scope of template-id indicated. */
2320 finish_template_type (tree name
, tree args
, int entering_scope
)
2324 decl
= lookup_template_class (name
, args
,
2325 NULL_TREE
, NULL_TREE
, entering_scope
,
2326 tf_error
| tf_warning
| tf_user
);
2327 if (decl
!= error_mark_node
)
2328 decl
= TYPE_STUB_DECL (decl
);
2333 /* Finish processing a BASE_CLASS with the indicated ACCESS_SPECIFIER.
2334 Return a TREE_LIST containing the ACCESS_SPECIFIER and the
2335 BASE_CLASS, or NULL_TREE if an error occurred. The
2336 ACCESS_SPECIFIER is one of
2337 access_{default,public,protected_private}_node. For a virtual base
2338 we set TREE_TYPE. */
2341 finish_base_specifier (tree base
, tree access
, bool virtual_p
)
2345 if (base
== error_mark_node
)
2347 error ("invalid base-class specification");
2350 else if (! is_aggr_type (base
, 1))
2354 if (cp_type_quals (base
) != 0)
2356 error ("base class %qT has cv qualifiers", base
);
2357 base
= TYPE_MAIN_VARIANT (base
);
2359 result
= build_tree_list (access
, base
);
2361 TREE_TYPE (result
) = integer_type_node
;
2367 /* Issue a diagnostic that NAME cannot be found in SCOPE. DECL is
2368 what we found when we tried to do the lookup. */
2371 qualified_name_lookup_error (tree scope
, tree name
, tree decl
)
2373 if (scope
== error_mark_node
)
2374 ; /* We already complained. */
2375 else if (TYPE_P (scope
))
2377 if (!COMPLETE_TYPE_P (scope
))
2378 error ("incomplete type %qT used in nested name specifier", scope
);
2379 else if (TREE_CODE (decl
) == TREE_LIST
)
2381 error ("reference to %<%T::%D%> is ambiguous", scope
, name
);
2382 print_candidates (decl
);
2385 error ("%qD is not a member of %qT", name
, scope
);
2387 else if (scope
!= global_namespace
)
2388 error ("%qD is not a member of %qD", name
, scope
);
2390 error ("%<::%D%> has not been declared", name
);
2393 /* ID_EXPRESSION is a representation of parsed, but unprocessed,
2394 id-expression. (See cp_parser_id_expression for details.) SCOPE,
2395 if non-NULL, is the type or namespace used to explicitly qualify
2396 ID_EXPRESSION. DECL is the entity to which that name has been
2399 *CONSTANT_EXPRESSION_P is true if we are presently parsing a
2400 constant-expression. In that case, *NON_CONSTANT_EXPRESSION_P will
2401 be set to true if this expression isn't permitted in a
2402 constant-expression, but it is otherwise not set by this function.
2403 *ALLOW_NON_CONSTANT_EXPRESSION_P is true if we are parsing a
2404 constant-expression, but a non-constant expression is also
2407 DONE is true if this expression is a complete postfix-expression;
2408 it is false if this expression is followed by '->', '[', '(', etc.
2409 ADDRESS_P is true iff this expression is the operand of '&'.
2410 TEMPLATE_P is true iff the qualified-id was of the form
2411 "A::template B". TEMPLATE_ARG_P is true iff this qualified name
2412 appears as a template argument.
2414 If an error occurs, and it is the kind of error that might cause
2415 the parser to abort a tentative parse, *ERROR_MSG is filled in. It
2416 is the caller's responsibility to issue the message. *ERROR_MSG
2417 will be a string with static storage duration, so the caller need
2420 Return an expression for the entity, after issuing appropriate
2421 diagnostics. This function is also responsible for transforming a
2422 reference to a non-static member into a COMPONENT_REF that makes
2423 the use of "this" explicit.
2425 Upon return, *IDK will be filled in appropriately. */
2428 finish_id_expression (tree id_expression
,
2432 bool integral_constant_expression_p
,
2433 bool allow_non_integral_constant_expression_p
,
2434 bool *non_integral_constant_expression_p
,
2438 bool template_arg_p
,
2439 const char **error_msg
)
2441 /* Initialize the output parameters. */
2442 *idk
= CP_ID_KIND_NONE
;
2445 if (id_expression
== error_mark_node
)
2446 return error_mark_node
;
2447 /* If we have a template-id, then no further lookup is
2448 required. If the template-id was for a template-class, we
2449 will sometimes have a TYPE_DECL at this point. */
2450 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
2451 || TREE_CODE (decl
) == TYPE_DECL
)
2453 /* Look up the name. */
2456 if (decl
== error_mark_node
)
2458 /* Name lookup failed. */
2461 || (!dependent_type_p (scope
)
2462 && !(TREE_CODE (id_expression
) == IDENTIFIER_NODE
2463 && IDENTIFIER_TYPENAME_P (id_expression
)
2464 && dependent_type_p (TREE_TYPE (id_expression
))))))
2466 /* If the qualifying type is non-dependent (and the name
2467 does not name a conversion operator to a dependent
2468 type), issue an error. */
2469 qualified_name_lookup_error (scope
, id_expression
, decl
);
2470 return error_mark_node
;
2474 /* It may be resolved via Koenig lookup. */
2475 *idk
= CP_ID_KIND_UNQUALIFIED
;
2476 return id_expression
;
2479 decl
= id_expression
;
2481 /* If DECL is a variable that would be out of scope under
2482 ANSI/ISO rules, but in scope in the ARM, name lookup
2483 will succeed. Issue a diagnostic here. */
2485 decl
= check_for_out_of_scope_variable (decl
);
2487 /* Remember that the name was used in the definition of
2488 the current class so that we can check later to see if
2489 the meaning would have been different after the class
2490 was entirely defined. */
2491 if (!scope
&& decl
!= error_mark_node
)
2492 maybe_note_name_used_in_class (id_expression
, decl
);
2494 /* Disallow uses of local variables from containing functions. */
2495 if (TREE_CODE (decl
) == VAR_DECL
|| TREE_CODE (decl
) == PARM_DECL
)
2497 tree context
= decl_function_context (decl
);
2498 if (context
!= NULL_TREE
&& context
!= current_function_decl
2499 && ! TREE_STATIC (decl
))
2501 error (TREE_CODE (decl
) == VAR_DECL
2502 ? "use of %<auto%> variable from containing function"
2503 : "use of parameter from containing function");
2504 error (" %q+#D declared here", decl
);
2505 return error_mark_node
;
2510 /* If we didn't find anything, or what we found was a type,
2511 then this wasn't really an id-expression. */
2512 if (TREE_CODE (decl
) == TEMPLATE_DECL
2513 && !DECL_FUNCTION_TEMPLATE_P (decl
))
2515 *error_msg
= "missing template arguments";
2516 return error_mark_node
;
2518 else if (TREE_CODE (decl
) == TYPE_DECL
2519 || TREE_CODE (decl
) == NAMESPACE_DECL
)
2521 *error_msg
= "expected primary-expression";
2522 return error_mark_node
;
2525 /* If the name resolved to a template parameter, there is no
2526 need to look it up again later. */
2527 if ((TREE_CODE (decl
) == CONST_DECL
&& DECL_TEMPLATE_PARM_P (decl
))
2528 || TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
2532 *idk
= CP_ID_KIND_NONE
;
2533 if (TREE_CODE (decl
) == TEMPLATE_PARM_INDEX
)
2534 decl
= TEMPLATE_PARM_DECL (decl
);
2535 r
= convert_from_reference (DECL_INITIAL (decl
));
2537 if (integral_constant_expression_p
2538 && !dependent_type_p (TREE_TYPE (decl
))
2539 && !(INTEGRAL_OR_ENUMERATION_TYPE_P (TREE_TYPE (r
))))
2541 if (!allow_non_integral_constant_expression_p
)
2542 error ("template parameter %qD of type %qT is not allowed in "
2543 "an integral constant expression because it is not of "
2544 "integral or enumeration type", decl
, TREE_TYPE (decl
));
2545 *non_integral_constant_expression_p
= true;
2549 /* Similarly, we resolve enumeration constants to their
2550 underlying values. */
2551 else if (TREE_CODE (decl
) == CONST_DECL
)
2553 *idk
= CP_ID_KIND_NONE
;
2554 if (!processing_template_decl
)
2555 return DECL_INITIAL (decl
);
2562 /* If the declaration was explicitly qualified indicate
2563 that. The semantics of `A::f(3)' are different than
2564 `f(3)' if `f' is virtual. */
2566 ? CP_ID_KIND_QUALIFIED
2567 : (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
2568 ? CP_ID_KIND_TEMPLATE_ID
2569 : CP_ID_KIND_UNQUALIFIED
));
2574 An id-expression is type-dependent if it contains an
2575 identifier that was declared with a dependent type.
2577 The standard is not very specific about an id-expression that
2578 names a set of overloaded functions. What if some of them
2579 have dependent types and some of them do not? Presumably,
2580 such a name should be treated as a dependent name. */
2581 /* Assume the name is not dependent. */
2582 dependent_p
= false;
2583 if (!processing_template_decl
)
2584 /* No names are dependent outside a template. */
2586 /* A template-id where the name of the template was not resolved
2587 is definitely dependent. */
2588 else if (TREE_CODE (decl
) == TEMPLATE_ID_EXPR
2589 && (TREE_CODE (TREE_OPERAND (decl
, 0))
2590 == IDENTIFIER_NODE
))
2592 /* For anything except an overloaded function, just check its
2594 else if (!is_overloaded_fn (decl
))
2596 = dependent_type_p (TREE_TYPE (decl
));
2597 /* For a set of overloaded functions, check each of the
2603 if (BASELINK_P (fns
))
2604 fns
= BASELINK_FUNCTIONS (fns
);
2606 /* For a template-id, check to see if the template
2607 arguments are dependent. */
2608 if (TREE_CODE (fns
) == TEMPLATE_ID_EXPR
)
2610 tree args
= TREE_OPERAND (fns
, 1);
2611 dependent_p
= any_dependent_template_arguments_p (args
);
2612 /* The functions are those referred to by the
2614 fns
= TREE_OPERAND (fns
, 0);
2617 /* If there are no dependent template arguments, go through
2618 the overloaded functions. */
2619 while (fns
&& !dependent_p
)
2621 tree fn
= OVL_CURRENT (fns
);
2623 /* Member functions of dependent classes are
2625 if (TREE_CODE (fn
) == FUNCTION_DECL
2626 && type_dependent_expression_p (fn
))
2628 else if (TREE_CODE (fn
) == TEMPLATE_DECL
2629 && dependent_template_p (fn
))
2632 fns
= OVL_NEXT (fns
);
2636 /* If the name was dependent on a template parameter, we will
2637 resolve the name at instantiation time. */
2640 /* Create a SCOPE_REF for qualified names, if the scope is
2644 /* Since this name was dependent, the expression isn't
2645 constant -- yet. No error is issued because it might
2646 be constant when things are instantiated. */
2647 if (integral_constant_expression_p
)
2648 *non_integral_constant_expression_p
= true;
2651 if (address_p
&& done
)
2652 decl
= finish_qualified_id_expr (scope
, decl
,
2656 else if (dependent_type_p (scope
))
2657 decl
= build_qualified_name (/*type=*/NULL_TREE
,
2661 else if (DECL_P (decl
))
2662 decl
= build_qualified_name (TREE_TYPE (decl
),
2667 if (TREE_TYPE (decl
))
2668 decl
= convert_from_reference (decl
);
2671 /* A TEMPLATE_ID already contains all the information we
2673 if (TREE_CODE (id_expression
) == TEMPLATE_ID_EXPR
)
2674 return id_expression
;
2675 *idk
= CP_ID_KIND_UNQUALIFIED_DEPENDENT
;
2676 /* If we found a variable, then name lookup during the
2677 instantiation will always resolve to the same VAR_DECL
2678 (or an instantiation thereof). */
2679 if (TREE_CODE (decl
) == VAR_DECL
2680 || TREE_CODE (decl
) == PARM_DECL
)
2681 return convert_from_reference (decl
);
2682 /* The same is true for FIELD_DECL, but we also need to
2683 make sure that the syntax is correct. */
2684 else if (TREE_CODE (decl
) == FIELD_DECL
)
2686 /* Since SCOPE is NULL here, this is an unqualified name.
2687 Access checking has been performed during name lookup
2688 already. Turn off checking to avoid duplicate errors. */
2689 push_deferring_access_checks (dk_no_check
);
2690 decl
= finish_non_static_data_member
2691 (decl
, current_class_ref
,
2692 /*qualifying_scope=*/NULL_TREE
);
2693 pop_deferring_access_checks ();
2696 return id_expression
;
2699 /* Only certain kinds of names are allowed in constant
2700 expression. Enumerators and template parameters have already
2701 been handled above. */
2702 if (integral_constant_expression_p
2703 && ! DECL_INTEGRAL_CONSTANT_VAR_P (decl
)
2704 && ! builtin_valid_in_constant_expr_p (decl
))
2706 if (!allow_non_integral_constant_expression_p
)
2708 error ("%qD cannot appear in a constant-expression", decl
);
2709 return error_mark_node
;
2711 *non_integral_constant_expression_p
= true;
2714 if (TREE_CODE (decl
) == NAMESPACE_DECL
)
2716 error ("use of namespace %qD as expression", decl
);
2717 return error_mark_node
;
2719 else if (DECL_CLASS_TEMPLATE_P (decl
))
2721 error ("use of class template %qT as expression", decl
);
2722 return error_mark_node
;
2724 else if (TREE_CODE (decl
) == TREE_LIST
)
2726 /* Ambiguous reference to base members. */
2727 error ("request for member %qD is ambiguous in "
2728 "multiple inheritance lattice", id_expression
);
2729 print_candidates (decl
);
2730 return error_mark_node
;
2733 /* Mark variable-like entities as used. Functions are similarly
2734 marked either below or after overload resolution. */
2735 if (TREE_CODE (decl
) == VAR_DECL
2736 || TREE_CODE (decl
) == PARM_DECL
2737 || TREE_CODE (decl
) == RESULT_DECL
)
2742 decl
= (adjust_result_of_qualified_name_lookup
2743 (decl
, scope
, current_class_type
));
2745 if (TREE_CODE (decl
) == FUNCTION_DECL
)
2748 if (TREE_CODE (decl
) == FIELD_DECL
|| BASELINK_P (decl
))
2749 decl
= finish_qualified_id_expr (scope
,
2757 tree r
= convert_from_reference (decl
);
2759 if (processing_template_decl
&& TYPE_P (scope
))
2760 r
= build_qualified_name (TREE_TYPE (r
),
2766 else if (TREE_CODE (decl
) == FIELD_DECL
)
2768 /* Since SCOPE is NULL here, this is an unqualified name.
2769 Access checking has been performed during name lookup
2770 already. Turn off checking to avoid duplicate errors. */
2771 push_deferring_access_checks (dk_no_check
);
2772 decl
= finish_non_static_data_member (decl
, current_class_ref
,
2773 /*qualifying_scope=*/NULL_TREE
);
2774 pop_deferring_access_checks ();
2776 else if (is_overloaded_fn (decl
))
2778 tree first_fn
= OVL_CURRENT (decl
);
2780 if (TREE_CODE (first_fn
) == TEMPLATE_DECL
)
2781 first_fn
= DECL_TEMPLATE_RESULT (first_fn
);
2783 if (!really_overloaded_fn (decl
))
2784 mark_used (first_fn
);
2787 && TREE_CODE (first_fn
) == FUNCTION_DECL
2788 && DECL_FUNCTION_MEMBER_P (first_fn
)
2789 && !shared_member_p (decl
))
2791 /* A set of member functions. */
2792 decl
= maybe_dummy_object (DECL_CONTEXT (first_fn
), 0);
2793 return finish_class_member_access_expr (decl
, id_expression
,
2794 /*template_p=*/false);
2799 if (DECL_P (decl
) && DECL_NONLOCAL (decl
)
2800 && DECL_CLASS_SCOPE_P (decl
)
2801 && DECL_CONTEXT (decl
) != current_class_type
)
2805 path
= currently_open_derived_class (DECL_CONTEXT (decl
));
2806 perform_or_defer_access_check (TYPE_BINFO (path
), decl
);
2809 decl
= convert_from_reference (decl
);
2813 if (TREE_DEPRECATED (decl
))
2814 warn_deprecated_use (decl
);
2819 /* Implement the __typeof keyword: Return the type of EXPR, suitable for
2820 use as a type-specifier. */
2823 finish_typeof (tree expr
)
2827 if (type_dependent_expression_p (expr
))
2829 type
= make_aggr_type (TYPEOF_TYPE
);
2830 TYPEOF_TYPE_EXPR (type
) = expr
;
2835 type
= TREE_TYPE (expr
);
2837 if (!type
|| type
== unknown_type_node
)
2839 error ("type of %qE is unknown", expr
);
2840 return error_mark_node
;
2846 /* Called from expand_body via walk_tree. Replace all AGGR_INIT_EXPRs
2847 with equivalent CALL_EXPRs. */
2850 simplify_aggr_init_exprs_r (tree
* tp
,
2852 void* data ATTRIBUTE_UNUSED
)
2854 /* We don't need to walk into types; there's nothing in a type that
2855 needs simplification. (And, furthermore, there are places we
2856 actively don't want to go. For example, we don't want to wander
2857 into the default arguments for a FUNCTION_DECL that appears in a
2864 /* Only AGGR_INIT_EXPRs are interesting. */
2865 else if (TREE_CODE (*tp
) != AGGR_INIT_EXPR
)
2868 simplify_aggr_init_expr (tp
);
2870 /* Keep iterating. */
2874 /* Replace the AGGR_INIT_EXPR at *TP with an equivalent CALL_EXPR. This
2875 function is broken out from the above for the benefit of the tree-ssa
2879 simplify_aggr_init_expr (tree
*tp
)
2881 tree aggr_init_expr
= *tp
;
2883 /* Form an appropriate CALL_EXPR. */
2884 tree fn
= TREE_OPERAND (aggr_init_expr
, 0);
2885 tree args
= TREE_OPERAND (aggr_init_expr
, 1);
2886 tree slot
= TREE_OPERAND (aggr_init_expr
, 2);
2887 tree type
= TREE_TYPE (slot
);
2890 enum style_t
{ ctor
, arg
, pcc
} style
;
2892 if (AGGR_INIT_VIA_CTOR_P (aggr_init_expr
))
2894 #ifdef PCC_STATIC_STRUCT_RETURN
2900 gcc_assert (TREE_ADDRESSABLE (type
));
2906 /* Replace the first argument to the ctor with the address of the
2910 args
= TREE_CHAIN (args
);
2911 cxx_mark_addressable (slot
);
2912 addr
= build1 (ADDR_EXPR
, build_pointer_type (type
), slot
);
2913 args
= tree_cons (NULL_TREE
, addr
, args
);
2916 call_expr
= build3 (CALL_EXPR
,
2917 TREE_TYPE (TREE_TYPE (TREE_TYPE (fn
))),
2918 fn
, args
, NULL_TREE
);
2922 /* Just mark it addressable here, and leave the rest to
2923 expand_call{,_inline}. */
2924 cxx_mark_addressable (slot
);
2925 CALL_EXPR_RETURN_SLOT_OPT (call_expr
) = true;
2926 call_expr
= build2 (MODIFY_EXPR
, TREE_TYPE (call_expr
), slot
, call_expr
);
2928 else if (style
== pcc
)
2930 /* If we're using the non-reentrant PCC calling convention, then we
2931 need to copy the returned value out of the static buffer into the
2933 push_deferring_access_checks (dk_no_check
);
2934 call_expr
= build_aggr_init (slot
, call_expr
,
2935 DIRECT_BIND
| LOOKUP_ONLYCONVERTING
);
2936 pop_deferring_access_checks ();
2937 call_expr
= build (COMPOUND_EXPR
, TREE_TYPE (slot
), call_expr
, slot
);
2943 /* Emit all thunks to FN that should be emitted when FN is emitted. */
2946 emit_associated_thunks (tree fn
)
2948 /* When we use vcall offsets, we emit thunks with the virtual
2949 functions to which they thunk. The whole point of vcall offsets
2950 is so that you can know statically the entire set of thunks that
2951 will ever be needed for a given virtual function, thereby
2952 enabling you to output all the thunks with the function itself. */
2953 if (DECL_VIRTUAL_P (fn
))
2957 for (thunk
= DECL_THUNKS (fn
); thunk
; thunk
= TREE_CHAIN (thunk
))
2959 if (!THUNK_ALIAS (thunk
))
2961 use_thunk (thunk
, /*emit_p=*/1);
2962 if (DECL_RESULT_THUNK_P (thunk
))
2966 for (probe
= DECL_THUNKS (thunk
);
2967 probe
; probe
= TREE_CHAIN (probe
))
2968 use_thunk (probe
, /*emit_p=*/1);
2972 gcc_assert (!DECL_THUNKS (thunk
));
2977 /* Generate RTL for FN. */
2980 expand_body (tree fn
)
2982 tree saved_function
;
2984 /* Compute the appropriate object-file linkage for inline
2986 if (DECL_DECLARED_INLINE_P (fn
))
2987 import_export_decl (fn
);
2989 /* If FN is external, then there's no point in generating RTL for
2990 it. This situation can arise with an inline function under
2991 `-fexternal-templates'; we instantiate the function, even though
2992 we're not planning on emitting it, in case we get a chance to
2994 if (DECL_EXTERNAL (fn
))
2997 /* ??? When is this needed? */
2998 saved_function
= current_function_decl
;
3000 /* Emit any thunks that should be emitted at the same time as FN. */
3001 emit_associated_thunks (fn
);
3003 /* This function is only called from cgraph, or recursively from
3004 emit_associated_thunks. In neither case should we be currently
3005 generating trees for a function. */
3006 gcc_assert (function_depth
== 0);
3008 tree_rest_of_compilation (fn
);
3010 current_function_decl
= saved_function
;
3012 if (DECL_CLONED_FUNCTION_P (fn
))
3014 /* If this is a clone, go through the other clones now and mark
3015 their parameters used. We have to do that here, as we don't
3016 know whether any particular clone will be expanded, and
3017 therefore cannot pick one arbitrarily. */
3020 for (probe
= TREE_CHAIN (DECL_CLONED_FUNCTION (fn
));
3021 probe
&& DECL_CLONED_FUNCTION_P (probe
);
3022 probe
= TREE_CHAIN (probe
))
3026 for (parms
= DECL_ARGUMENTS (probe
);
3027 parms
; parms
= TREE_CHAIN (parms
))
3028 TREE_USED (parms
) = 1;
3033 /* Generate RTL for FN. */
3036 expand_or_defer_fn (tree fn
)
3038 /* When the parser calls us after finishing the body of a template
3039 function, we don't really want to expand the body. */
3040 if (processing_template_decl
)
3042 /* Normally, collection only occurs in rest_of_compilation. So,
3043 if we don't collect here, we never collect junk generated
3044 during the processing of templates until we hit a
3045 non-template function. It's not safe to do this inside a
3046 nested class, though, as the parser may have local state that
3047 is not a GC root. */
3048 if (!function_depth
)
3053 /* Replace AGGR_INIT_EXPRs with appropriate CALL_EXPRs. */
3054 walk_tree_without_duplicates (&DECL_SAVED_TREE (fn
),
3055 simplify_aggr_init_exprs_r
,
3058 /* If this is a constructor or destructor body, we have to clone
3060 if (maybe_clone_body (fn
))
3062 /* We don't want to process FN again, so pretend we've written
3063 it out, even though we haven't. */
3064 TREE_ASM_WRITTEN (fn
) = 1;
3068 /* If this function is marked with the constructor attribute, add it
3069 to the list of functions to be called along with constructors
3070 from static duration objects. */
3071 if (DECL_STATIC_CONSTRUCTOR (fn
))
3072 static_ctors
= tree_cons (NULL_TREE
, fn
, static_ctors
);
3074 /* If this function is marked with the destructor attribute, add it
3075 to the list of functions to be called along with destructors from
3076 static duration objects. */
3077 if (DECL_STATIC_DESTRUCTOR (fn
))
3078 static_dtors
= tree_cons (NULL_TREE
, fn
, static_dtors
);
3080 /* We make a decision about linkage for these functions at the end
3081 of the compilation. Until that point, we do not want the back
3082 end to output them -- but we do want it to see the bodies of
3083 these functions so that it can inline them as appropriate. */
3084 if (DECL_DECLARED_INLINE_P (fn
) || DECL_IMPLICIT_INSTANTIATION (fn
))
3086 if (DECL_INTERFACE_KNOWN (fn
))
3087 /* We've already made a decision as to how this function will
3091 DECL_EXTERNAL (fn
) = 1;
3092 DECL_NOT_REALLY_EXTERN (fn
) = 1;
3093 note_vague_linkage_fn (fn
);
3094 /* A non-template inline function with external linkage will
3095 always be COMDAT. As we must eventually determine the
3096 linkage of all functions, and as that causes writes to
3097 the data mapped in from the PCH file, it's advantageous
3098 to mark the functions at this point. */
3099 if (!DECL_IMPLICIT_INSTANTIATION (fn
))
3101 /* This function must have external linkage, as
3102 otherwise DECL_INTERFACE_KNOWN would have been
3104 gcc_assert (TREE_PUBLIC (fn
));
3105 comdat_linkage (fn
);
3106 DECL_INTERFACE_KNOWN (fn
) = 1;
3110 import_export_decl (fn
);
3112 /* If the user wants us to keep all inline functions, then mark
3113 this function as needed so that finish_file will make sure to
3115 if (flag_keep_inline_functions
&& DECL_DECLARED_INLINE_P (fn
))
3119 /* There's no reason to do any of the work here if we're only doing
3120 semantic analysis; this code just generates RTL. */
3121 if (flag_syntax_only
)
3126 /* Expand or defer, at the whim of the compilation unit manager. */
3127 cgraph_finalize_function (fn
, function_depth
> 1);
3139 /* Helper function for walk_tree, used by finalize_nrv below. */
3142 finalize_nrv_r (tree
* tp
, int* walk_subtrees
, void* data
)
3144 struct nrv_data
*dp
= (struct nrv_data
*)data
;
3147 /* No need to walk into types. There wouldn't be any need to walk into
3148 non-statements, except that we have to consider STMT_EXPRs. */
3151 /* Change all returns to just refer to the RESULT_DECL; this is a nop,
3152 but differs from using NULL_TREE in that it indicates that we care
3153 about the value of the RESULT_DECL. */
3154 else if (TREE_CODE (*tp
) == RETURN_EXPR
)
3155 TREE_OPERAND (*tp
, 0) = dp
->result
;
3156 /* Change all cleanups for the NRV to only run when an exception is
3158 else if (TREE_CODE (*tp
) == CLEANUP_STMT
3159 && CLEANUP_DECL (*tp
) == dp
->var
)
3160 CLEANUP_EH_ONLY (*tp
) = 1;
3161 /* Replace the DECL_EXPR for the NRV with an initialization of the
3162 RESULT_DECL, if needed. */
3163 else if (TREE_CODE (*tp
) == DECL_EXPR
3164 && DECL_EXPR_DECL (*tp
) == dp
->var
)
3167 if (DECL_INITIAL (dp
->var
)
3168 && DECL_INITIAL (dp
->var
) != error_mark_node
)
3170 init
= build2 (INIT_EXPR
, void_type_node
, dp
->result
,
3171 DECL_INITIAL (dp
->var
));
3172 DECL_INITIAL (dp
->var
) = error_mark_node
;
3175 init
= build_empty_stmt ();
3176 SET_EXPR_LOCUS (init
, EXPR_LOCUS (*tp
));
3179 /* And replace all uses of the NRV with the RESULT_DECL. */
3180 else if (*tp
== dp
->var
)
3183 /* Avoid walking into the same tree more than once. Unfortunately, we
3184 can't just use walk_tree_without duplicates because it would only call
3185 us for the first occurrence of dp->var in the function body. */
3186 slot
= htab_find_slot (dp
->visited
, *tp
, INSERT
);
3192 /* Keep iterating. */
3196 /* Called from finish_function to implement the named return value
3197 optimization by overriding all the RETURN_EXPRs and pertinent
3198 CLEANUP_STMTs and replacing all occurrences of VAR with RESULT, the
3199 RESULT_DECL for the function. */
3202 finalize_nrv (tree
*tp
, tree var
, tree result
)
3204 struct nrv_data data
;
3206 /* Copy debugging information from VAR to RESULT. */
3207 DECL_NAME (result
) = DECL_NAME (var
);
3208 DECL_ARTIFICIAL (result
) = DECL_ARTIFICIAL (var
);
3209 DECL_IGNORED_P (result
) = DECL_IGNORED_P (var
);
3210 DECL_SOURCE_LOCATION (result
) = DECL_SOURCE_LOCATION (var
);
3211 DECL_ABSTRACT_ORIGIN (result
) = DECL_ABSTRACT_ORIGIN (var
);
3212 /* Don't forget that we take its address. */
3213 TREE_ADDRESSABLE (result
) = TREE_ADDRESSABLE (var
);
3216 data
.result
= result
;
3217 data
.visited
= htab_create (37, htab_hash_pointer
, htab_eq_pointer
, NULL
);
3218 walk_tree (tp
, finalize_nrv_r
, &data
, 0);
3219 htab_delete (data
.visited
);
3222 /* For all elements of *PCLAUSES, validate them vs OpenMP constraints.
3223 Remove any elements from the list that are invalid. */
3226 finish_omp_clauses (tree clauses
)
3228 bitmap_head generic_head
, firstprivate_head
, lastprivate_head
;
3229 tree c
, t
, *pc
= &clauses
;
3232 bitmap_obstack_initialize (NULL
);
3233 bitmap_initialize (&generic_head
, &bitmap_default_obstack
);
3234 bitmap_initialize (&firstprivate_head
, &bitmap_default_obstack
);
3235 bitmap_initialize (&lastprivate_head
, &bitmap_default_obstack
);
3237 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
3239 bool remove
= false;
3241 switch (TREE_CODE (c
))
3243 case OMP_CLAUSE_SHARED
:
3245 goto check_dup_generic
;
3246 case OMP_CLAUSE_PRIVATE
:
3248 goto check_dup_generic
;
3249 case OMP_CLAUSE_REDUCTION
:
3251 goto check_dup_generic
;
3252 case OMP_CLAUSE_COPYPRIVATE
:
3253 name
= "copyprivate";
3254 goto check_dup_generic
;
3255 case OMP_CLAUSE_COPYIN
:
3257 goto check_dup_generic
;
3259 t
= OMP_CLAUSE_DECL (c
);
3260 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
3262 if (processing_template_decl
)
3264 error ("%qE is not a variable in clause %qs", t
, name
);
3267 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
3268 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
))
3269 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
3271 error ("%qE appears more than once in data clauses", t
);
3275 bitmap_set_bit (&generic_head
, DECL_UID (t
));
3278 case OMP_CLAUSE_FIRSTPRIVATE
:
3279 t
= OMP_CLAUSE_DECL (c
);
3280 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
3282 if (processing_template_decl
)
3284 error ("%qE is not a variable in clause %<firstprivate%>", t
);
3287 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
3288 || bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
3290 error ("%qE appears more than once in data clauses", t
);
3294 bitmap_set_bit (&firstprivate_head
, DECL_UID (t
));
3297 case OMP_CLAUSE_LASTPRIVATE
:
3298 t
= OMP_CLAUSE_DECL (c
);
3299 if (TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
3301 if (processing_template_decl
)
3303 error ("%qE is not a variable in clause %<lastprivate%>", t
);
3306 else if (bitmap_bit_p (&generic_head
, DECL_UID (t
))
3307 || bitmap_bit_p (&lastprivate_head
, DECL_UID (t
)))
3309 error ("%qE appears more than once in data clauses", t
);
3313 bitmap_set_bit (&lastprivate_head
, DECL_UID (t
));
3317 t
= OMP_CLAUSE_IF_EXPR (c
);
3318 t
= maybe_convert_cond (t
);
3319 if (t
== error_mark_node
)
3321 OMP_CLAUSE_IF_EXPR (c
) = t
;
3324 case OMP_CLAUSE_NUM_THREADS
:
3325 t
= OMP_CLAUSE_NUM_THREADS_EXPR (c
);
3326 if (t
== error_mark_node
)
3328 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
3329 && !type_dependent_expression_p (t
))
3331 error ("num_threads expression must be integral");
3336 case OMP_CLAUSE_SCHEDULE
:
3337 t
= OMP_CLAUSE_SCHEDULE_CHUNK_EXPR (c
);
3340 else if (t
== error_mark_node
)
3342 else if (!INTEGRAL_TYPE_P (TREE_TYPE (t
))
3343 && !type_dependent_expression_p (t
))
3345 error ("schedule chunk size expression must be integral");
3350 case OMP_CLAUSE_NOWAIT
:
3351 case OMP_CLAUSE_ORDERED
:
3352 case OMP_CLAUSE_DEFAULT
:
3360 *pc
= OMP_CLAUSE_CHAIN (c
);
3362 pc
= &OMP_CLAUSE_CHAIN (c
);
3365 for (pc
= &clauses
, c
= clauses
; c
; c
= *pc
)
3367 enum tree_code c_kind
= TREE_CODE (c
);
3368 bool remove
= false;
3369 bool need_non_const_or_mutable
= false;
3370 bool need_complete_non_reference
= false;
3371 bool need_default_ctor
= false;
3372 bool need_copy_ctor
= false;
3373 bool need_copy_assignment
= false;
3374 bool need_implicitly_determined
= false;
3379 case OMP_CLAUSE_SHARED
:
3381 need_implicitly_determined
= true;
3383 case OMP_CLAUSE_PRIVATE
:
3385 need_non_const_or_mutable
= true;
3386 need_complete_non_reference
= true;
3387 need_default_ctor
= true;
3388 need_implicitly_determined
= true;
3390 case OMP_CLAUSE_FIRSTPRIVATE
:
3391 name
= "firstprivate";
3392 need_non_const_or_mutable
= true;
3393 need_complete_non_reference
= true;
3394 need_copy_ctor
= true;
3395 need_implicitly_determined
= true;
3397 case OMP_CLAUSE_LASTPRIVATE
:
3398 name
= "lastprivate";
3399 need_non_const_or_mutable
= true;
3400 need_complete_non_reference
= true;
3401 need_copy_assignment
= true;
3402 need_implicitly_determined
= true;
3404 case OMP_CLAUSE_REDUCTION
:
3406 need_non_const_or_mutable
= true;
3407 need_implicitly_determined
= true;
3409 case OMP_CLAUSE_COPYPRIVATE
:
3410 name
= "copyprivate";
3411 need_copy_assignment
= true;
3413 case OMP_CLAUSE_COPYIN
:
3415 need_copy_assignment
= true;
3418 pc
= &OMP_CLAUSE_CHAIN (c
);
3422 t
= OMP_CLAUSE_DECL (c
);
3423 if (processing_template_decl
3424 && TREE_CODE (t
) != VAR_DECL
&& TREE_CODE (t
) != PARM_DECL
)
3426 pc
= &OMP_CLAUSE_CHAIN (c
);
3432 case OMP_CLAUSE_LASTPRIVATE
:
3433 if (!bitmap_bit_p (&firstprivate_head
, DECL_UID (t
)))
3434 need_default_ctor
= true;
3437 case OMP_CLAUSE_REDUCTION
:
3438 if (AGGREGATE_TYPE_P (TREE_TYPE (t
))
3439 || POINTER_TYPE_P (TREE_TYPE (t
)))
3441 error ("%qE has invalid type for %<reduction%>", t
);
3444 else if (FLOAT_TYPE_P (TREE_TYPE (t
)))
3446 enum tree_code r_code
= OMP_CLAUSE_REDUCTION_CODE (c
);
3454 error ("%qE has invalid type for %<reduction(%s)%>",
3455 t
, operator_name_info
[r_code
].name
);
3461 case OMP_CLAUSE_COPYIN
:
3462 if (!DECL_THREAD_LOCAL_P (t
))
3464 error ("%qE must be %<threadprivate%> for %<copyin%>", t
);
3473 if (need_non_const_or_mutable
&& TREE_READONLY (t
))
3475 error ("%qE is read-only for %qs", t
, name
);
3478 if (need_complete_non_reference
)
3480 t
= require_complete_type (t
);
3481 if (t
== error_mark_node
)
3483 else if (TREE_CODE (TREE_TYPE (t
)) == REFERENCE_TYPE
)
3485 error ("%qE has reference type for %qs", t
, name
);
3489 if (need_implicitly_determined
)
3491 const char *share_name
= NULL
;
3493 if (TREE_CODE (t
) == VAR_DECL
&& DECL_THREAD_LOCAL_P (t
))
3494 share_name
= "threadprivate";
3495 else switch (cxx_omp_predetermined_sharing (t
))
3497 case OMP_CLAUSE_DEFAULT_UNSPECIFIED
:
3499 case OMP_CLAUSE_DEFAULT_SHARED
:
3500 share_name
= "shared";
3502 case OMP_CLAUSE_DEFAULT_PRIVATE
:
3503 share_name
= "private";
3510 error ("%qE is predetermined %qs for %qs",
3511 t
, share_name
, name
);
3516 /* We're interested in the base element, not arrays. */
3517 type
= TREE_TYPE (t
);
3518 while (TREE_CODE (type
) == ARRAY_TYPE
)
3519 type
= TREE_TYPE (type
);
3521 /* Check for special function availablity by building a call to one
3522 and discarding the results. C.f. check_constructor_callable. */
3523 if (CLASS_TYPE_P (type
))
3525 int save_errorcount
= errorcount
;
3527 /* For the copy constructor and assignment op, we need
3528 an object of the appropriate type. Pretend with an
3529 otherwise bogus INDIRECT_REF. */
3530 if (type
!= TREE_TYPE (t
))
3532 t
= build_int_cst (build_pointer_type (type
), 0);
3533 t
= build1 (INDIRECT_REF
, type
, t
);
3536 if (need_default_ctor
&& TYPE_NEEDS_CONSTRUCTING (type
))
3538 build_special_member_call (NULL_TREE
, complete_ctor_identifier
,
3539 NULL_TREE
, type
, LOOKUP_NORMAL
);
3541 if (need_copy_ctor
&& TYPE_NEEDS_CONSTRUCTING (type
))
3543 build_special_member_call (NULL_TREE
, complete_ctor_identifier
,
3544 build_tree_list (NULL
, t
),
3545 type
, LOOKUP_NORMAL
);
3547 if (need_copy_assignment
)
3549 build_special_member_call (t
, ansi_assopname (NOP_EXPR
),
3550 build_tree_list (NULL
, t
),
3551 type
, LOOKUP_NORMAL
);
3554 if (errorcount
!= save_errorcount
)
3560 *pc
= OMP_CLAUSE_CHAIN (c
);
3562 /* If we don't remove the corresponding firstprivate clause, we
3563 can wind up with spurrious errors later, since this changes
3564 the set of constructors we request. */
3565 if (c_kind
== OMP_CLAUSE_LASTPRIVATE
3566 && bitmap_bit_p (&firstprivate_head
,
3567 DECL_UID (OMP_CLAUSE_DECL (c
))))
3570 for (p
= &clauses
; *p
; p
= &OMP_CLAUSE_CHAIN (*p
))
3571 if (TREE_CODE (*p
) == OMP_CLAUSE_FIRSTPRIVATE
3572 && OMP_CLAUSE_DECL (*p
) == OMP_CLAUSE_DECL (c
))
3574 *p
= OMP_CLAUSE_CHAIN (*p
);
3580 pc
= &OMP_CLAUSE_CHAIN (c
);
3583 bitmap_obstack_release (NULL
);
3587 /* For all variables in the tree_list VARS, mark them as thread local. */
3590 finish_omp_threadprivate (tree vars
)
3594 /* Mark every variable in VARS to be assigned thread local storage. */
3595 for (t
= vars
; t
; t
= TREE_CHAIN (t
))
3597 tree v
= TREE_PURPOSE (t
);
3599 /* If V had already been marked threadprivate, it doesn't matter
3600 whether it had been used prior to this point. */
3602 && (DECL_LANG_SPECIFIC (v
) == NULL
3603 || !CP_DECL_THREADPRIVATE_P (v
)))
3604 error ("%qE declared %<threadprivate%> after first use", v
);
3607 /* Allocate a LANG_SPECIFIC structure for V, if needed. */
3608 if (DECL_LANG_SPECIFIC (v
) == NULL
)
3610 retrofit_lang_decl (v
);
3612 /* Make sure that DECL_DISCRIMINATOR_P continues to be true
3613 after the allocation of the lang_decl structure. */
3614 if (DECL_DISCRIMINATOR_P (v
))
3615 DECL_LANG_SPECIFIC (v
)->decl_flags
.u2sel
= 1;
3618 if (! DECL_THREAD_LOCAL_P (v
))
3620 DECL_TLS_MODEL (v
) = decl_default_tls_model (v
);
3621 /* If rtl has been already set for this var, call
3622 make_decl_rtl once again, so that encode_section_info
3623 has a chance to look at the new decl flags. */
3624 if (DECL_RTL_SET_P (v
))
3627 CP_DECL_THREADPRIVATE_P (v
) = 1;
3632 /* Build an OpenMP structured block. */
3635 begin_omp_structured_block (void)
3637 return do_pushlevel (sk_omp
);
3641 finish_omp_structured_block (tree block
)
3643 return do_poplevel (block
);
3646 /* Similarly, except force the retension of the BLOCK. */
3649 begin_omp_parallel (void)
3651 keep_next_level (true);
3652 return begin_omp_structured_block ();
3656 finish_omp_parallel (tree clauses
, tree body
)
3660 body
= finish_omp_structured_block (body
);
3662 stmt
= make_node (OMP_PARALLEL
);
3663 TREE_TYPE (stmt
) = void_type_node
;
3664 OMP_PARALLEL_CLAUSES (stmt
) = clauses
;
3665 OMP_PARALLEL_BODY (stmt
) = body
;
3667 return add_stmt (stmt
);
3670 /* Build and validate an OMP_FOR statement. CLAUSES, BODY, COND, INCR
3671 are directly for their associated operands in the statement. DECL
3672 and INIT are a combo; if DECL is NULL then INIT ought to be a
3673 MODIFY_EXPR, and the DECL should be extracted. PRE_BODY are
3674 optional statements that need to go before the loop into its
3678 finish_omp_for (location_t locus
, tree decl
, tree init
, tree cond
,
3679 tree incr
, tree body
, tree pre_body
)
3684 switch (TREE_CODE (init
))
3687 decl
= TREE_OPERAND (init
, 0);
3688 init
= TREE_OPERAND (init
, 1);
3691 if (TREE_CODE (TREE_OPERAND (init
, 1)) == NOP_EXPR
)
3693 decl
= TREE_OPERAND (init
, 0);
3694 init
= TREE_OPERAND (init
, 2);
3703 error ("expected iteration declaration or initialization");
3708 if (type_dependent_expression_p (decl
)
3709 || type_dependent_expression_p (init
)
3710 || (cond
&& type_dependent_expression_p (cond
))
3711 || (incr
&& type_dependent_expression_p (incr
)))
3717 error ("%Hmissing controlling predicate", &locus
);
3723 error ("%Hmissing increment expression", &locus
);
3727 stmt
= make_node (OMP_FOR
);
3729 /* This is really just a place-holder. We'll be decomposing this
3730 again and going through the build_modify_expr path below when
3731 we instantiate the thing. */
3732 init
= build2 (MODIFY_EXPR
, void_type_node
, decl
, init
);
3734 TREE_TYPE (stmt
) = void_type_node
;
3735 OMP_FOR_INIT (stmt
) = init
;
3736 OMP_FOR_COND (stmt
) = cond
;
3737 OMP_FOR_INCR (stmt
) = incr
;
3738 OMP_FOR_BODY (stmt
) = body
;
3739 OMP_FOR_PRE_BODY (stmt
) = pre_body
;
3741 SET_EXPR_LOCATION (stmt
, locus
);
3742 return add_stmt (stmt
);
3747 error ("expected iteration declaration or initialization");
3751 if (pre_body
== NULL
|| IS_EMPTY_STMT (pre_body
))
3753 else if (! processing_template_decl
)
3755 add_stmt (pre_body
);
3758 init
= build_modify_expr (decl
, NOP_EXPR
, init
);
3759 return c_finish_omp_for (locus
, decl
, init
, cond
, incr
, body
, pre_body
);
3763 finish_omp_atomic (enum tree_code code
, tree lhs
, tree rhs
)
3765 /* If either of the operands are dependent, we can't do semantic
3766 processing yet. Stuff the values away for now. We cheat a bit
3767 and use the same tree code for this, even though the operands
3768 are of totally different form, thus we need to remember which
3769 statements are which, thus the lang_flag bit. */
3770 /* ??? We ought to be using type_dependent_expression_p, but the
3771 invocation of build_modify_expr in c_finish_omp_atomic can result
3772 in the creation of CONVERT_EXPRs, which are not handled by
3773 tsubst_copy_and_build. */
3774 if (uses_template_parms (lhs
) || uses_template_parms (rhs
))
3776 tree stmt
= build2 (OMP_ATOMIC
, void_type_node
, lhs
, rhs
);
3777 OMP_ATOMIC_DEPENDENT_P (stmt
) = 1;
3778 OMP_ATOMIC_CODE (stmt
) = code
;
3782 c_finish_omp_atomic (code
, lhs
, rhs
);
3785 /* True if OpenMP sharing attribute of DECL is predetermined. */
3787 enum omp_clause_default_kind
3788 cxx_omp_predetermined_sharing (tree decl
)
3790 enum omp_clause_default_kind kind
;
3792 kind
= c_omp_predetermined_sharing (decl
);
3793 if (kind
!= OMP_CLAUSE_DEFAULT_UNSPECIFIED
)
3796 /* Static data members are predetermined as shared. */
3797 if (TREE_STATIC (decl
))
3799 tree ctx
= CP_DECL_CONTEXT (decl
);
3800 if (TYPE_P (ctx
) && IS_AGGR_TYPE (ctx
))
3801 return OMP_CLAUSE_DEFAULT_SHARED
;
3804 return OMP_CLAUSE_DEFAULT_UNSPECIFIED
;
3807 /* Build and return code to initialize DECL with its default constructor.
3808 Return NULL if there's nothing to do. */
3811 cxx_omp_clause_default_ctor (tree decl
)
3813 tree type
= TREE_TYPE (decl
);
3815 if (TREE_CODE (type
) == ARRAY_TYPE
)
3818 while (TREE_CODE (etype
) == ARRAY_TYPE
)
3819 etype
= TREE_TYPE (etype
);
3821 if (TYPE_NEEDS_CONSTRUCTING (etype
))
3822 return build_vec_init (decl
, NULL
, NULL
, true, 0);
3826 else if (TYPE_NEEDS_CONSTRUCTING (type
))
3827 return build_aggr_init (decl
, NULL
, 0);
3832 /* Build and return code for a copy constructor from SRC to DST. */
3835 cxx_omp_clause_copy_ctor (tree dst
, tree src
)
3837 if (TREE_CODE (TREE_TYPE (dst
)) == ARRAY_TYPE
)
3838 return build_vec_init (dst
, NULL
, src
, false, 1);
3840 return build_modify_expr (dst
, INIT_EXPR
, src
);
3843 /* Similarly, except use an assignment operator instead. */
3846 cxx_omp_clause_assign_op (tree dst
, tree src
)
3848 if (TREE_CODE (TREE_TYPE (dst
)) == ARRAY_TYPE
)
3849 return build_vec_init (dst
, NULL
, src
, false, 2);
3851 return build_modify_expr (dst
, NOP_EXPR
, src
);
3856 init_cp_semantics (void)
3860 #include "gt-cp-semantics.h"