PR target/11183
[official-gcc.git] / gcc / c-semantics.c
blob374e9f13dec15f597277e2a023dd9db5c6151729
1 /* This file contains the definitions and documentation for the common
2 tree codes used in the GNU C and C++ compilers (see c-common.def
3 for the standard codes).
4 Copyright (C) 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 Written by Benjamin Chelf (chelf@codesourcery.com).
7 This file is part of GCC.
9 GCC is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 2, or (at your option) any later
12 version.
14 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
19 You should have received a copy of the GNU General Public License
20 along with GCC; see the file COPYING. If not, write to the Free
21 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 02111-1307, USA. */
24 #include "config.h"
25 #include "system.h"
26 #include "coretypes.h"
27 #include "tm.h"
28 #include "tree.h"
29 #include "function.h"
30 #include "splay-tree.h"
31 #include "varray.h"
32 #include "c-common.h"
33 #include "except.h"
34 #include "toplev.h"
35 #include "flags.h"
36 #include "ggc.h"
37 #include "rtl.h"
38 #include "expr.h"
39 #include "output.h"
40 #include "timevar.h"
41 #include "predict.h"
42 #include "tree-inline.h"
44 /* If non-NULL, the address of a language-specific function for
45 expanding statements. */
46 void (*lang_expand_stmt) PARAMS ((tree));
48 /* If non-NULL, the address of a language-specific function for
49 expanding a DECL_STMT. After the language-independent cases are
50 handled, this function will be called. If this function is not
51 defined, it is assumed that declarations other than those for
52 variables and labels do not require any RTL generation. */
53 void (*lang_expand_decl_stmt) PARAMS ((tree));
55 static tree find_reachable_label_1 PARAMS ((tree *, int *, void *));
56 static tree find_reachable_label PARAMS ((tree));
57 static bool expand_unreachable_if_stmt PARAMS ((tree));
58 static tree expand_unreachable_stmt PARAMS ((tree, int));
59 static void genrtl_do_stmt_1 PARAMS ((tree, tree));
61 /* Create an empty statement tree rooted at T. */
63 void
64 begin_stmt_tree (t)
65 tree *t;
67 /* We create a trivial EXPR_STMT so that last_tree is never NULL in
68 what follows. We remove the extraneous statement in
69 finish_stmt_tree. */
70 *t = build_nt (EXPR_STMT, void_zero_node);
71 last_tree = *t;
72 last_expr_type = NULL_TREE;
73 last_expr_filename = input_filename;
76 /* T is a statement. Add it to the statement-tree. */
78 tree
79 add_stmt (t)
80 tree t;
82 if (input_filename != last_expr_filename)
84 /* If the filename has changed, also add in a FILE_STMT. Do a string
85 compare first, though, as it might be an equivalent string. */
86 int add = (strcmp (input_filename, last_expr_filename) != 0);
87 last_expr_filename = input_filename;
88 if (add)
90 tree pos = build_nt (FILE_STMT, get_identifier (input_filename));
91 add_stmt (pos);
95 /* Add T to the statement-tree. */
96 TREE_CHAIN (last_tree) = t;
97 last_tree = t;
99 /* When we expand a statement-tree, we must know whether or not the
100 statements are full-expressions. We record that fact here. */
101 STMT_IS_FULL_EXPR_P (last_tree) = stmts_are_full_exprs_p ();
103 /* Keep track of the number of statements in this function. */
104 if (current_function_decl)
105 ++DECL_NUM_STMTS (current_function_decl);
107 return t;
110 /* Create a declaration statement for the declaration given by the
111 DECL. */
113 void
114 add_decl_stmt (decl)
115 tree decl;
117 tree decl_stmt;
119 /* We need the type to last until instantiation time. */
120 decl_stmt = build_stmt (DECL_STMT, decl);
121 add_stmt (decl_stmt);
124 /* Add a scope-statement to the statement-tree. BEGIN_P indicates
125 whether this statements opens or closes a scope. PARTIAL_P is true
126 for a partial scope, i.e, the scope that begins after a label when
127 an object that needs a cleanup is created. If BEGIN_P is nonzero,
128 returns a new TREE_LIST representing the top of the SCOPE_STMT
129 stack. The TREE_PURPOSE is the new SCOPE_STMT. If BEGIN_P is
130 zero, returns a TREE_LIST whose TREE_VALUE is the new SCOPE_STMT,
131 and whose TREE_PURPOSE is the matching SCOPE_STMT with
132 SCOPE_BEGIN_P set. */
134 tree
135 add_scope_stmt (begin_p, partial_p)
136 int begin_p;
137 int partial_p;
139 tree *stack_ptr = current_scope_stmt_stack ();
140 tree ss;
141 tree top = *stack_ptr;
143 /* Build the statement. */
144 ss = build_stmt (SCOPE_STMT, NULL_TREE);
145 SCOPE_BEGIN_P (ss) = begin_p;
146 SCOPE_PARTIAL_P (ss) = partial_p;
148 /* Keep the scope stack up to date. */
149 if (begin_p)
151 top = tree_cons (ss, NULL_TREE, top);
152 *stack_ptr = top;
154 else
156 if (partial_p != SCOPE_PARTIAL_P (TREE_PURPOSE (top)))
157 abort ();
158 TREE_VALUE (top) = ss;
159 *stack_ptr = TREE_CHAIN (top);
162 /* Add the new statement to the statement-tree. */
163 add_stmt (ss);
165 return top;
168 /* Finish the statement tree rooted at T. */
170 void
171 finish_stmt_tree (t)
172 tree *t;
174 tree stmt;
176 /* Remove the fake extra statement added in begin_stmt_tree. */
177 stmt = TREE_CHAIN (*t);
178 *t = stmt;
179 last_tree = NULL_TREE;
181 if (cfun && stmt)
183 /* The line-number recorded in the outermost statement in a function
184 is the line number of the end of the function. */
185 STMT_LINENO (stmt) = input_line;
186 STMT_LINENO_FOR_FN_P (stmt) = 1;
190 /* Build a generic statement based on the given type of node and
191 arguments. Similar to `build_nt', except that we set
192 STMT_LINENO to be the current line number. */
193 /* ??? This should be obsolete with the lineno_stmt productions
194 in the grammar. */
196 tree
197 build_stmt (enum tree_code code, ...)
199 tree t;
200 int length;
201 int i;
202 va_list p;
204 va_start (p, code);
206 t = make_node (code);
207 length = TREE_CODE_LENGTH (code);
208 STMT_LINENO (t) = input_line;
210 for (i = 0; i < length; i++)
211 TREE_OPERAND (t, i) = va_arg (p, tree);
213 va_end (p);
214 return t;
217 /* Some statements, like for-statements or if-statements, require a
218 condition. This condition can be a declaration. If T is such a
219 declaration it is processed, and an expression appropriate to use
220 as the condition is returned. Otherwise, T itself is returned. */
222 tree
223 expand_cond (t)
224 tree t;
226 if (t && TREE_CODE (t) == TREE_LIST)
228 expand_stmt (TREE_PURPOSE (t));
229 return TREE_VALUE (t);
231 else
232 return t;
235 /* Create RTL for the local static variable DECL. */
237 void
238 make_rtl_for_local_static (decl)
239 tree decl;
241 const char *asmspec = NULL;
243 /* If we inlined this variable, we could see it's declaration
244 again. */
245 if (TREE_ASM_WRITTEN (decl))
246 return;
248 /* If the DECL_ASSEMBLER_NAME is not the same as the DECL_NAME, then
249 either we already created RTL for this DECL (and since it was a
250 local variable, its DECL_ASSEMBLER_NAME got hacked up to prevent
251 clashes with other local statics with the same name by a previous
252 call to make_decl_rtl), or the user explicitly requested a
253 particular assembly name for this variable, using the GNU
254 extension for this purpose:
256 int i asm ("j");
258 There's no way to know which case we're in, here. But, it turns
259 out we're safe. If there's already RTL, then
260 rest_of_decl_compilation ignores the ASMSPEC parameter, so we
261 may as well not pass it in. If there isn't RTL, then we didn't
262 already create RTL, which means that the modification to
263 DECL_ASSEMBLER_NAME came only via the explicit extension. */
264 if (DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl)
265 && !DECL_RTL_SET_P (decl))
266 asmspec = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
268 rest_of_decl_compilation (decl, asmspec, /*top_level=*/0, /*at_end=*/0);
271 /* Let the back-end know about DECL. */
273 void
274 emit_local_var (decl)
275 tree decl;
277 /* Create RTL for this variable. */
278 if (!DECL_RTL_SET_P (decl))
280 if (DECL_C_HARD_REGISTER (decl))
281 /* The user specified an assembler name for this variable.
282 Set that up now. */
283 rest_of_decl_compilation
284 (decl, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
285 /*top_level=*/0, /*at_end=*/0);
286 else
287 expand_decl (decl);
290 if (DECL_INITIAL (decl))
292 /* Actually do the initialization. */
293 if (stmts_are_full_exprs_p ())
294 expand_start_target_temps ();
296 expand_decl_init (decl);
298 if (stmts_are_full_exprs_p ())
299 expand_end_target_temps ();
303 /* Helper for generating the RTL at the beginning of a scope. */
305 void
306 genrtl_do_pushlevel ()
308 emit_line_note (input_filename, input_line);
309 clear_last_expr ();
312 /* Generate the RTL for DESTINATION, which is a GOTO_STMT. */
314 void
315 genrtl_goto_stmt (destination)
316 tree destination;
318 if (TREE_CODE (destination) == IDENTIFIER_NODE)
319 abort ();
321 /* We warn about unused labels with -Wunused. That means we have to
322 mark the used labels as used. */
323 if (TREE_CODE (destination) == LABEL_DECL)
324 TREE_USED (destination) = 1;
326 emit_line_note (input_filename, input_line);
328 if (TREE_CODE (destination) == LABEL_DECL)
330 label_rtx (destination);
331 expand_goto (destination);
333 else
334 expand_computed_goto (destination);
337 /* Generate the RTL for EXPR, which is an EXPR_STMT. Provided just
338 for backward compatibility. genrtl_expr_stmt_value() should be
339 used for new code. */
341 void
342 genrtl_expr_stmt (expr)
343 tree expr;
345 genrtl_expr_stmt_value (expr, -1, 1);
348 /* Generate the RTL for EXPR, which is an EXPR_STMT. WANT_VALUE tells
349 whether to (1) save the value of the expression, (0) discard it or
350 (-1) use expr_stmts_for_value to tell. The use of -1 is
351 deprecated, and retained only for backward compatibility.
352 MAYBE_LAST is nonzero if this EXPR_STMT might be the last statement
353 in expression statement. */
355 void
356 genrtl_expr_stmt_value (expr, want_value, maybe_last)
357 tree expr;
358 int want_value, maybe_last;
360 if (expr != NULL_TREE)
362 emit_line_note (input_filename, input_line);
364 if (stmts_are_full_exprs_p ())
365 expand_start_target_temps ();
367 if (expr != error_mark_node)
368 expand_expr_stmt_value (expr, want_value, maybe_last);
370 if (stmts_are_full_exprs_p ())
371 expand_end_target_temps ();
375 /* Generate the RTL for T, which is a DECL_STMT. */
377 void
378 genrtl_decl_stmt (t)
379 tree t;
381 tree decl;
382 emit_line_note (input_filename, input_line);
383 decl = DECL_STMT_DECL (t);
384 /* If this is a declaration for an automatic local
385 variable, initialize it. Note that we might also see a
386 declaration for a namespace-scope object (declared with
387 `extern'). We don't have to handle the initialization
388 of those objects here; they can only be declarations,
389 rather than definitions. */
390 if (TREE_CODE (decl) == VAR_DECL
391 && !TREE_STATIC (decl)
392 && !DECL_EXTERNAL (decl))
394 /* Let the back-end know about this variable. */
395 if (!anon_aggr_type_p (TREE_TYPE (decl)))
396 emit_local_var (decl);
397 else
398 expand_anon_union_decl (decl, NULL_TREE,
399 DECL_ANON_UNION_ELEMS (decl));
401 else if (TREE_CODE (decl) == VAR_DECL && TREE_STATIC (decl))
402 make_rtl_for_local_static (decl);
403 else if (TREE_CODE (decl) == LABEL_DECL
404 && C_DECLARED_LABEL_FLAG (decl))
405 declare_nonlocal_label (decl);
406 else if (lang_expand_decl_stmt)
407 (*lang_expand_decl_stmt) (t);
410 /* Generate the RTL for T, which is an IF_STMT. */
412 void
413 genrtl_if_stmt (t)
414 tree t;
416 tree cond;
417 genrtl_do_pushlevel ();
418 cond = expand_cond (IF_COND (t));
419 emit_line_note (input_filename, input_line);
420 expand_start_cond (cond, 0);
421 if (THEN_CLAUSE (t))
423 tree nextt = THEN_CLAUSE (t);
425 if (cond && integer_zerop (cond))
426 nextt = expand_unreachable_stmt (nextt, warn_notreached);
427 expand_stmt (nextt);
430 if (ELSE_CLAUSE (t))
432 tree nextt = ELSE_CLAUSE (t);
433 expand_start_else ();
434 if (cond && integer_nonzerop (cond))
435 nextt = expand_unreachable_stmt (nextt, warn_notreached);
436 expand_stmt (nextt);
438 expand_end_cond ();
441 /* Generate the RTL for T, which is a WHILE_STMT. */
443 void
444 genrtl_while_stmt (t)
445 tree t;
447 tree cond = WHILE_COND (t);
449 emit_nop ();
450 emit_line_note (input_filename, input_line);
451 expand_start_loop (1);
452 genrtl_do_pushlevel ();
454 if (cond && !integer_nonzerop (cond))
456 cond = expand_cond (cond);
457 emit_line_note (input_filename, input_line);
458 expand_exit_loop_top_cond (0, cond);
459 genrtl_do_pushlevel ();
462 expand_stmt (WHILE_BODY (t));
464 expand_end_loop ();
467 /* Generate the RTL for a DO_STMT with condition COND and loop BODY
468 body. This is reused for expanding unreachable WHILE_STMTS. */
470 static void
471 genrtl_do_stmt_1 (cond, body)
472 tree cond, body;
474 /* Recognize the common special-case of do { ... } while (0) and do
475 not emit the loop widgetry in this case. In particular this
476 avoids cluttering the rtl with dummy loop notes, which can affect
477 alignment of adjacent labels. COND can be NULL due to parse
478 errors. */
479 if (!cond || integer_zerop (cond))
481 expand_start_null_loop ();
482 expand_stmt (body);
483 expand_end_null_loop ();
485 else if (integer_nonzerop (cond))
487 emit_nop ();
488 emit_line_note (input_filename, input_line);
489 expand_start_loop (1);
491 expand_stmt (body);
493 emit_line_note (input_filename, input_line);
494 expand_end_loop ();
496 else
498 emit_nop ();
499 emit_line_note (input_filename, input_line);
500 expand_start_loop_continue_elsewhere (1);
502 expand_stmt (body);
504 expand_loop_continue_here ();
505 cond = expand_cond (cond);
506 emit_line_note (input_filename, input_line);
507 expand_exit_loop_if_false (0, cond);
508 expand_end_loop ();
512 /* Generate the RTL for T, which is a DO_STMT. */
514 void
515 genrtl_do_stmt (t)
516 tree t;
518 genrtl_do_stmt_1 (DO_COND (t), DO_BODY (t));
521 /* Build the node for a return statement and return it. */
523 tree
524 build_return_stmt (expr)
525 tree expr;
527 return (build_stmt (RETURN_STMT, expr));
530 /* Generate the RTL for STMT, which is a RETURN_STMT. */
532 void
533 genrtl_return_stmt (stmt)
534 tree stmt;
536 tree expr;
538 expr = RETURN_STMT_EXPR (stmt);
540 emit_line_note (input_filename, input_line);
541 if (!expr)
542 expand_null_return ();
543 else
545 expand_start_target_temps ();
546 expand_return (expr);
547 expand_end_target_temps ();
551 /* Generate the RTL for T, which is a FOR_STMT. */
553 void
554 genrtl_for_stmt (t)
555 tree t;
557 tree cond = FOR_COND (t);
558 location_t saved_loc;
560 if (NEW_FOR_SCOPE_P (t))
561 genrtl_do_pushlevel ();
563 expand_stmt (FOR_INIT_STMT (t));
565 /* Expand the initialization. */
566 emit_nop ();
567 emit_line_note (input_filename, input_line);
568 if (FOR_EXPR (t))
569 expand_start_loop_continue_elsewhere (1);
570 else
571 expand_start_loop (1);
572 genrtl_do_pushlevel ();
574 /* Save the filename and line number so that we expand the FOR_EXPR
575 we can reset them back to the saved values. */
576 saved_loc = input_location;
578 /* Expand the condition. */
579 if (cond && !integer_nonzerop (cond))
581 cond = expand_cond (cond);
582 emit_line_note (input_filename, input_line);
583 expand_exit_loop_top_cond (0, cond);
584 genrtl_do_pushlevel ();
587 /* Expand the body. */
588 expand_stmt (FOR_BODY (t));
590 /* Expand the increment expression. */
591 input_location = saved_loc;
592 emit_line_note (input_filename, input_line);
593 if (FOR_EXPR (t))
595 expand_loop_continue_here ();
596 genrtl_expr_stmt (FOR_EXPR (t));
598 expand_end_loop ();
601 /* Build a break statement node and return it. */
603 tree
604 build_break_stmt ()
606 return (build_stmt (BREAK_STMT));
609 /* Generate the RTL for a BREAK_STMT. */
611 void
612 genrtl_break_stmt ()
614 emit_line_note (input_filename, input_line);
615 if ( ! expand_exit_something ())
616 error ("break statement not within loop or switch");
619 /* Build a continue statement node and return it. */
621 tree
622 build_continue_stmt ()
624 return (build_stmt (CONTINUE_STMT));
627 /* Generate the RTL for a CONTINUE_STMT. */
629 void
630 genrtl_continue_stmt ()
632 emit_line_note (input_filename, input_line);
633 if (! expand_continue_loop (0))
634 error ("continue statement not within a loop");
637 /* Generate the RTL for T, which is a SCOPE_STMT. */
639 void
640 genrtl_scope_stmt (t)
641 tree t;
643 tree block = SCOPE_STMT_BLOCK (t);
645 if (!SCOPE_NO_CLEANUPS_P (t))
647 if (SCOPE_BEGIN_P (t))
648 expand_start_bindings_and_block (2 * SCOPE_NULLIFIED_P (t), block);
649 else if (SCOPE_END_P (t))
650 expand_end_bindings (NULL_TREE, !SCOPE_NULLIFIED_P (t), 0);
652 else if (!SCOPE_NULLIFIED_P (t))
654 rtx note = emit_note (NULL,
655 (SCOPE_BEGIN_P (t)
656 ? NOTE_INSN_BLOCK_BEG
657 : NOTE_INSN_BLOCK_END));
658 NOTE_BLOCK (note) = block;
661 /* If we're at the end of a scope that contains inlined nested
662 functions, we have to decide whether or not to write them out. */
663 if (block && SCOPE_END_P (t))
665 tree fn;
667 for (fn = BLOCK_VARS (block); fn; fn = TREE_CHAIN (fn))
669 if (TREE_CODE (fn) == FUNCTION_DECL
670 && DECL_CONTEXT (fn) == current_function_decl
671 && DECL_SAVED_INSNS (fn)
672 && !TREE_ASM_WRITTEN (fn)
673 && TREE_ADDRESSABLE (fn))
675 push_function_context ();
676 output_inline_function (fn);
677 pop_function_context ();
683 /* Generate the RTL for T, which is a SWITCH_STMT. */
685 void
686 genrtl_switch_stmt (t)
687 tree t;
689 tree cond;
690 genrtl_do_pushlevel ();
692 cond = expand_cond (SWITCH_COND (t));
693 if (cond == error_mark_node)
694 /* The code is in error, but we don't want expand_end_case to
695 crash. */
696 cond = boolean_false_node;
698 emit_line_note (input_filename, input_line);
699 expand_start_case (1, cond, TREE_TYPE (cond), "switch statement");
700 expand_stmt (expand_unreachable_stmt (SWITCH_BODY (t), warn_notreached));
701 expand_end_case_type (cond, SWITCH_TYPE (t));
704 /* Create a CASE_LABEL tree node and return it. */
706 tree
707 build_case_label (low_value, high_value, label_decl)
708 tree low_value;
709 tree high_value;
710 tree label_decl;
712 return build_stmt (CASE_LABEL, low_value, high_value, label_decl);
716 /* Generate the RTL for a CASE_LABEL. */
718 void
719 genrtl_case_label (case_label)
720 tree case_label;
722 tree duplicate;
723 tree cleanup;
725 cleanup = last_cleanup_this_contour ();
726 if (cleanup)
728 static int explained = 0;
729 warning ("destructor needed for `%#D'", (TREE_PURPOSE (cleanup)));
730 warning ("where case label appears here");
731 if (!explained)
733 warning ("(enclose actions of previous case statements requiring destructors in their own scope.)");
734 explained = 1;
738 add_case_node (CASE_LOW (case_label), CASE_HIGH (case_label),
739 CASE_LABEL_DECL (case_label), &duplicate);
742 /* Generate the RTL for T, which is a COMPOUND_STMT. */
744 void
745 genrtl_compound_stmt (t)
746 tree t;
748 #ifdef ENABLE_CHECKING
749 struct nesting *n = current_nesting_level ();
750 #endif
752 expand_stmt (COMPOUND_BODY (t));
754 #ifdef ENABLE_CHECKING
755 /* Make sure that we've pushed and popped the same number of levels. */
756 if (!COMPOUND_STMT_NO_SCOPE (t) && n != current_nesting_level ())
757 abort ();
758 #endif
761 /* Generate the RTL for an ASM_STMT. */
763 void
764 genrtl_asm_stmt (cv_qualifier, string, output_operands,
765 input_operands, clobbers, asm_input_p)
766 tree cv_qualifier;
767 tree string;
768 tree output_operands;
769 tree input_operands;
770 tree clobbers;
771 int asm_input_p;
773 if (cv_qualifier != NULL_TREE
774 && cv_qualifier != ridpointers[(int) RID_VOLATILE])
776 warning ("%s qualifier ignored on asm",
777 IDENTIFIER_POINTER (cv_qualifier));
778 cv_qualifier = NULL_TREE;
781 emit_line_note (input_filename, input_line);
782 if (asm_input_p)
783 expand_asm (string, cv_qualifier != NULL_TREE);
784 else
785 c_expand_asm_operands (string, output_operands, input_operands,
786 clobbers, cv_qualifier != NULL_TREE,
787 input_filename, input_line);
790 /* Generate the RTL for a CLEANUP_STMT. */
792 void
793 genrtl_cleanup_stmt (t)
794 tree t;
796 tree decl = CLEANUP_DECL (t);
797 if (!decl || (DECL_SIZE (decl) && TREE_TYPE (decl) != error_mark_node))
798 expand_decl_cleanup_eh (decl, CLEANUP_EXPR (t), CLEANUP_EH_ONLY (t));
801 /* We're about to expand T, a statement. Set up appropriate context
802 for the substitution. */
804 void
805 prep_stmt (t)
806 tree t;
808 if (!STMT_LINENO_FOR_FN_P (t))
809 input_line = STMT_LINENO (t);
810 current_stmt_tree ()->stmts_are_full_exprs_p = STMT_IS_FULL_EXPR_P (t);
813 /* Generate the RTL for the statement T, its substatements, and any
814 other statements at its nesting level. */
816 void
817 expand_stmt (t)
818 tree t;
820 while (t && t != error_mark_node)
822 int saved_stmts_are_full_exprs_p;
824 /* Set up context appropriately for handling this statement. */
825 saved_stmts_are_full_exprs_p = stmts_are_full_exprs_p ();
826 prep_stmt (t);
828 switch (TREE_CODE (t))
830 case FILE_STMT:
831 input_filename = FILE_STMT_FILENAME (t);
832 break;
834 case RETURN_STMT:
835 genrtl_return_stmt (t);
836 t = expand_unreachable_stmt (TREE_CHAIN (t), warn_notreached);
837 goto process_t;
839 case EXPR_STMT:
840 genrtl_expr_stmt_value (EXPR_STMT_EXPR (t), TREE_ADDRESSABLE (t),
841 TREE_CHAIN (t) == NULL
842 || (TREE_CODE (TREE_CHAIN (t)) == SCOPE_STMT
843 && TREE_CHAIN (TREE_CHAIN (t)) == NULL));
844 break;
846 case DECL_STMT:
847 genrtl_decl_stmt (t);
848 break;
850 case FOR_STMT:
851 genrtl_for_stmt (t);
852 break;
854 case WHILE_STMT:
855 genrtl_while_stmt (t);
856 break;
858 case DO_STMT:
859 genrtl_do_stmt (t);
860 break;
862 case IF_STMT:
863 genrtl_if_stmt (t);
864 break;
866 case COMPOUND_STMT:
867 genrtl_compound_stmt (t);
868 break;
870 case BREAK_STMT:
871 genrtl_break_stmt ();
872 t = expand_unreachable_stmt (TREE_CHAIN (t), warn_notreached);
873 goto process_t;
875 case CONTINUE_STMT:
876 genrtl_continue_stmt ();
877 t = expand_unreachable_stmt (TREE_CHAIN (t), warn_notreached);
878 goto process_t;
880 case SWITCH_STMT:
881 genrtl_switch_stmt (t);
882 break;
884 case CASE_LABEL:
885 genrtl_case_label (t);
886 break;
888 case LABEL_STMT:
889 expand_label (LABEL_STMT_LABEL (t));
890 break;
892 case GOTO_STMT:
893 /* Emit information for branch prediction. */
894 if (!GOTO_FAKE_P (t)
895 && TREE_CODE (GOTO_DESTINATION (t)) == LABEL_DECL
896 && flag_guess_branch_prob)
898 rtx note = emit_note (NULL, NOTE_INSN_PREDICTION);
900 NOTE_PREDICTION (note) = NOTE_PREDICT (PRED_GOTO, NOT_TAKEN);
902 genrtl_goto_stmt (GOTO_DESTINATION (t));
903 t = expand_unreachable_stmt (TREE_CHAIN (t), warn_notreached);
904 goto process_t;
906 case ASM_STMT:
907 genrtl_asm_stmt (ASM_CV_QUAL (t), ASM_STRING (t),
908 ASM_OUTPUTS (t), ASM_INPUTS (t),
909 ASM_CLOBBERS (t), ASM_INPUT_P (t));
910 break;
912 case SCOPE_STMT:
913 genrtl_scope_stmt (t);
914 break;
916 case CLEANUP_STMT:
917 genrtl_cleanup_stmt (t);
918 break;
920 default:
921 if (lang_expand_stmt)
922 (*lang_expand_stmt) (t);
923 else
924 abort ();
925 break;
928 /* Go on to the next statement in this scope. */
929 t = TREE_CHAIN (t);
931 process_t:
932 /* Restore saved state. */
933 current_stmt_tree ()->stmts_are_full_exprs_p
934 = saved_stmts_are_full_exprs_p;
938 /* If *TP is a potentially reachable label, return nonzero. */
940 static tree
941 find_reachable_label_1 (tp, walk_subtrees, data)
942 tree *tp;
943 int *walk_subtrees ATTRIBUTE_UNUSED;
944 void *data ATTRIBUTE_UNUSED;
946 switch (TREE_CODE (*tp))
948 case LABEL_STMT:
949 case CASE_LABEL:
950 return *tp;
952 default:
953 break;
955 return NULL_TREE;
958 /* Determine whether expression EXP contains a potentially
959 reachable label. */
960 static tree
961 find_reachable_label (exp)
962 tree exp;
964 location_t saved_loc = input_location;
965 tree ret = walk_tree (&exp, find_reachable_label_1, NULL, NULL);
966 input_location = saved_loc;
967 return ret;
970 /* Expand an unreachable if statement, T. This function returns
971 true if the IF_STMT contains a potentially reachable code_label. */
972 static bool
973 expand_unreachable_if_stmt (t)
974 tree t;
976 tree n;
978 if (find_reachable_label (IF_COND (t)) != NULL_TREE)
980 genrtl_if_stmt (t);
981 return true;
984 if (THEN_CLAUSE (t) && ELSE_CLAUSE (t))
986 n = expand_unreachable_stmt (THEN_CLAUSE (t), 0);
988 if (n != NULL_TREE)
990 rtx label;
991 expand_stmt (n);
992 label = gen_label_rtx ();
993 emit_jump (label);
994 expand_stmt (expand_unreachable_stmt (ELSE_CLAUSE (t), 0));
995 emit_label (label);
996 return true;
998 else
999 n = expand_unreachable_stmt (ELSE_CLAUSE (t), 0);
1001 else if (THEN_CLAUSE (t))
1002 n = expand_unreachable_stmt (THEN_CLAUSE (t), 0);
1003 else if (ELSE_CLAUSE (t))
1004 n = expand_unreachable_stmt (ELSE_CLAUSE (t), 0);
1005 else
1006 n = NULL_TREE;
1008 expand_stmt (n);
1010 return n != NULL_TREE;
1013 /* Expand an unreachable statement list. This function skips all
1014 statements preceding the first potentially reachable label and
1015 then returns the label (or, in same cases, the statement after
1016 one containing the label). */
1017 static tree
1018 expand_unreachable_stmt (t, warn)
1019 tree t;
1020 int warn;
1022 int saved;
1024 while (t && t != error_mark_node)
1026 if (warn)
1027 switch (TREE_CODE (t))
1029 case BREAK_STMT:
1030 case CONTINUE_STMT:
1031 case EXPR_STMT:
1032 case GOTO_STMT:
1033 case IF_STMT:
1034 case RETURN_STMT:
1035 if (!STMT_LINENO_FOR_FN_P (t))
1036 input_line = STMT_LINENO (t);
1037 warning("will never be executed");
1038 warn = false;
1039 break;
1041 default:
1042 break;
1045 switch (TREE_CODE (t))
1047 case GOTO_STMT:
1048 case CONTINUE_STMT:
1049 case BREAK_STMT:
1050 break;
1052 case FILE_STMT:
1053 input_filename = FILE_STMT_FILENAME (t);
1054 break;
1056 case RETURN_STMT:
1057 if (find_reachable_label (RETURN_STMT_EXPR (t)) != NULL_TREE)
1058 return t;
1059 break;
1061 case EXPR_STMT:
1062 if (find_reachable_label (EXPR_STMT_EXPR (t)) != NULL_TREE)
1063 return t;
1064 break;
1066 case IF_STMT:
1067 if (expand_unreachable_if_stmt (t))
1068 return TREE_CHAIN (t);
1069 break;
1071 case WHILE_STMT:
1072 /* If the start of a while statement is unreachable, there is
1073 no need to rotate the loop, instead the WHILE_STMT can be
1074 expanded like a DO_STMT. */
1075 genrtl_do_stmt_1 (WHILE_COND (t), WHILE_BODY (t));
1076 return TREE_CHAIN (t);
1078 case COMPOUND_STMT:
1080 tree n;
1081 n = expand_unreachable_stmt (COMPOUND_BODY (t), warn);
1082 if (n != NULL_TREE)
1084 expand_stmt (n);
1085 return TREE_CHAIN (t);
1087 warn = false;
1088 break;
1091 case SCOPE_STMT:
1092 saved = stmts_are_full_exprs_p ();
1093 prep_stmt (t);
1094 genrtl_scope_stmt (t);
1095 current_stmt_tree ()->stmts_are_full_exprs_p = saved;
1096 break;
1098 default:
1099 return t;
1101 t = TREE_CHAIN (t);
1103 return NULL_TREE;