OSDN Git Service

374e9f13dec15f597277e2a023dd9db5c6151729
[pf3gnuchains/gcc-fork.git] / gcc / c-semantics.c
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).
6
7 This file is part of GCC.
8
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.
13
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.
18
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.  */
23
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"
43
44 /* If non-NULL, the address of a language-specific function for
45    expanding statements.  */
46 void (*lang_expand_stmt) PARAMS ((tree));
47
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));
54
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));
60
61 /* Create an empty statement tree rooted at T.  */
62
63 void
64 begin_stmt_tree (t)
65      tree *t;
66 {
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;
74 }
75
76 /* T is a statement.  Add it to the statement-tree.  */
77
78 tree
79 add_stmt (t)
80      tree t;
81 {
82   if (input_filename != last_expr_filename)
83     {
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)
89         {
90           tree pos = build_nt (FILE_STMT, get_identifier (input_filename));
91           add_stmt (pos);
92         }
93     }
94
95   /* Add T to the statement-tree.  */
96   TREE_CHAIN (last_tree) = t;
97   last_tree = t;
98   
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 ();
102
103   /* Keep track of the number of statements in this function.  */
104   if (current_function_decl)
105     ++DECL_NUM_STMTS (current_function_decl);
106
107   return t;
108 }
109
110 /* Create a declaration statement for the declaration given by the
111    DECL.  */
112
113 void
114 add_decl_stmt (decl)
115      tree decl;
116 {
117   tree decl_stmt;
118
119   /* We need the type to last until instantiation time.  */
120   decl_stmt = build_stmt (DECL_STMT, decl);
121   add_stmt (decl_stmt); 
122 }
123
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.  */
133
134 tree
135 add_scope_stmt (begin_p, partial_p)
136      int begin_p;
137      int partial_p;
138 {
139   tree *stack_ptr = current_scope_stmt_stack ();
140   tree ss;
141   tree top = *stack_ptr;
142
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;
147
148   /* Keep the scope stack up to date.  */
149   if (begin_p)
150     {
151       top = tree_cons (ss, NULL_TREE, top);
152       *stack_ptr = top;
153     }
154   else
155     {
156       if (partial_p != SCOPE_PARTIAL_P (TREE_PURPOSE (top)))
157         abort ();
158       TREE_VALUE (top) = ss;
159       *stack_ptr = TREE_CHAIN (top);
160     }
161
162   /* Add the new statement to the statement-tree.  */
163   add_stmt (ss);
164
165   return top;
166 }
167
168 /* Finish the statement tree rooted at T.  */
169
170 void
171 finish_stmt_tree (t)
172      tree *t;
173 {
174   tree stmt;
175   
176   /* Remove the fake extra statement added in begin_stmt_tree.  */
177   stmt = TREE_CHAIN (*t);
178   *t = stmt;
179   last_tree = NULL_TREE;
180
181   if (cfun && stmt)
182     {
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;
187     }
188 }
189
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.  */
195
196 tree
197 build_stmt (enum tree_code code, ...)
198 {
199   tree t;
200   int length;
201   int i;
202   va_list p;
203   
204   va_start (p, code);
205
206   t = make_node (code);
207   length = TREE_CODE_LENGTH (code);
208   STMT_LINENO (t) = input_line;
209
210   for (i = 0; i < length; i++)
211     TREE_OPERAND (t, i) = va_arg (p, tree);
212
213   va_end (p);
214   return t;
215 }
216
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.  */
221
222 tree
223 expand_cond (t)
224      tree t;
225 {
226   if (t && TREE_CODE (t) == TREE_LIST)
227     {
228       expand_stmt (TREE_PURPOSE (t));
229       return TREE_VALUE (t);
230     }
231   else 
232     return t;
233 }
234
235 /* Create RTL for the local static variable DECL.  */
236
237 void
238 make_rtl_for_local_static (decl)
239      tree decl;
240 {
241   const char *asmspec = NULL;
242
243   /* If we inlined this variable, we could see it's declaration
244      again.  */
245   if (TREE_ASM_WRITTEN (decl))
246     return;
247
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:
255
256        int i asm ("j");
257
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));
267
268   rest_of_decl_compilation (decl, asmspec, /*top_level=*/0, /*at_end=*/0);
269 }
270
271 /* Let the back-end know about DECL.  */
272
273 void
274 emit_local_var (decl)
275      tree decl;
276 {
277   /* Create RTL for this variable.  */
278   if (!DECL_RTL_SET_P (decl))
279     {
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);
288     }
289
290   if (DECL_INITIAL (decl))
291     {
292       /* Actually do the initialization.  */
293       if (stmts_are_full_exprs_p ())
294         expand_start_target_temps ();
295
296       expand_decl_init (decl);
297
298       if (stmts_are_full_exprs_p ())
299         expand_end_target_temps ();
300     }
301 }
302
303 /* Helper for generating the RTL at the beginning of a scope.  */
304
305 void
306 genrtl_do_pushlevel ()
307 {
308   emit_line_note (input_filename, input_line);
309   clear_last_expr ();
310 }
311
312 /* Generate the RTL for DESTINATION, which is a GOTO_STMT.  */
313
314 void
315 genrtl_goto_stmt (destination)
316      tree destination;
317 {
318   if (TREE_CODE (destination) == IDENTIFIER_NODE)
319     abort ();
320   
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;
325   
326   emit_line_note (input_filename, input_line);
327   
328   if (TREE_CODE (destination) == LABEL_DECL)
329     {
330       label_rtx (destination);
331       expand_goto (destination); 
332     }
333   else
334     expand_computed_goto (destination);
335 }
336
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.  */
340
341 void
342 genrtl_expr_stmt (expr)
343      tree expr;
344 {
345   genrtl_expr_stmt_value (expr, -1, 1);
346 }
347
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.  */
354
355 void 
356 genrtl_expr_stmt_value (expr, want_value, maybe_last)
357      tree expr;
358      int want_value, maybe_last;
359 {
360   if (expr != NULL_TREE)
361     {
362       emit_line_note (input_filename, input_line);
363       
364       if (stmts_are_full_exprs_p ())
365         expand_start_target_temps ();
366       
367       if (expr != error_mark_node)
368         expand_expr_stmt_value (expr, want_value, maybe_last);
369       
370       if (stmts_are_full_exprs_p ())
371         expand_end_target_temps ();
372     }
373 }
374
375 /* Generate the RTL for T, which is a DECL_STMT.  */
376
377 void
378 genrtl_decl_stmt (t)
379      tree t;
380 {
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))
393     {
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));
400     }
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);
408 }
409
410 /* Generate the RTL for T, which is an IF_STMT.  */
411
412 void
413 genrtl_if_stmt (t)
414      tree t;
415 {
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))
422     {
423       tree nextt = THEN_CLAUSE (t);
424       
425       if (cond && integer_zerop (cond))
426         nextt = expand_unreachable_stmt (nextt, warn_notreached);
427       expand_stmt (nextt);
428     }
429
430   if (ELSE_CLAUSE (t))
431     {
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);
437     }
438   expand_end_cond ();
439 }
440
441 /* Generate the RTL for T, which is a WHILE_STMT.  */
442
443 void
444 genrtl_while_stmt (t)
445      tree t;
446 {
447   tree cond = WHILE_COND (t);
448
449   emit_nop ();
450   emit_line_note (input_filename, input_line);
451   expand_start_loop (1); 
452   genrtl_do_pushlevel ();
453
454   if (cond && !integer_nonzerop (cond))
455     {
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 ();
460     }
461   
462   expand_stmt (WHILE_BODY (t));
463
464   expand_end_loop ();
465 }
466
467 /* Generate the RTL for a DO_STMT with condition COND and loop BODY
468    body.  This is reused for expanding unreachable WHILE_STMTS.  */
469
470 static void
471 genrtl_do_stmt_1 (cond, body)
472      tree cond, body;
473 {
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))
480     {
481       expand_start_null_loop ();
482       expand_stmt (body);
483       expand_end_null_loop ();
484     }
485   else if (integer_nonzerop (cond))
486     {
487       emit_nop ();
488       emit_line_note (input_filename, input_line);
489       expand_start_loop (1);
490
491       expand_stmt (body);
492
493       emit_line_note (input_filename, input_line);
494       expand_end_loop ();
495     }
496   else
497     {
498       emit_nop ();
499       emit_line_note (input_filename, input_line);
500       expand_start_loop_continue_elsewhere (1);
501
502       expand_stmt (body);
503
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 ();
509     }
510 }
511
512 /* Generate the RTL for T, which is a DO_STMT.  */
513
514 void
515 genrtl_do_stmt (t)
516      tree t;
517 {
518   genrtl_do_stmt_1 (DO_COND (t), DO_BODY (t));
519 }
520
521 /* Build the node for a return statement and return it.  */
522
523 tree
524 build_return_stmt (expr)
525      tree expr;
526 {
527   return (build_stmt (RETURN_STMT, expr));
528 }
529
530 /* Generate the RTL for STMT, which is a RETURN_STMT.  */
531
532 void
533 genrtl_return_stmt (stmt)
534      tree stmt;
535 {
536   tree expr;
537
538   expr = RETURN_STMT_EXPR (stmt);
539
540   emit_line_note (input_filename, input_line);
541   if (!expr)
542     expand_null_return ();
543   else
544     {
545       expand_start_target_temps ();
546       expand_return (expr);
547       expand_end_target_temps ();
548     }
549 }
550
551 /* Generate the RTL for T, which is a FOR_STMT.  */
552
553 void
554 genrtl_for_stmt (t)
555      tree t;
556 {
557   tree cond = FOR_COND (t);
558   location_t saved_loc;
559
560   if (NEW_FOR_SCOPE_P (t))
561     genrtl_do_pushlevel ();
562
563   expand_stmt (FOR_INIT_STMT (t));
564
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 ();
573
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;
577
578   /* Expand the condition.  */
579   if (cond && !integer_nonzerop (cond))
580     {
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 ();
585     }
586
587   /* Expand the body.  */
588   expand_stmt (FOR_BODY (t));
589
590   /* Expand the increment expression.  */
591   input_location = saved_loc;
592   emit_line_note (input_filename, input_line);
593   if (FOR_EXPR (t))
594     {
595       expand_loop_continue_here ();
596       genrtl_expr_stmt (FOR_EXPR (t));
597     }
598   expand_end_loop ();
599 }
600
601 /* Build a break statement node and return it.  */
602
603 tree
604 build_break_stmt ()
605 {
606   return (build_stmt (BREAK_STMT));
607 }
608
609 /* Generate the RTL for a BREAK_STMT.  */
610
611 void
612 genrtl_break_stmt ()
613 {
614   emit_line_note (input_filename, input_line);
615   if ( ! expand_exit_something ())
616     error ("break statement not within loop or switch");
617 }
618
619 /* Build a continue statement node and return it.  */
620
621 tree
622 build_continue_stmt ()
623 {
624   return (build_stmt (CONTINUE_STMT));
625 }
626
627 /* Generate the RTL for a CONTINUE_STMT.  */
628
629 void
630 genrtl_continue_stmt ()
631 {
632   emit_line_note (input_filename, input_line);
633   if (! expand_continue_loop (0))
634     error ("continue statement not within a loop");   
635 }
636
637 /* Generate the RTL for T, which is a SCOPE_STMT.  */
638
639 void
640 genrtl_scope_stmt (t)
641      tree t;
642 {
643   tree block = SCOPE_STMT_BLOCK (t);
644
645   if (!SCOPE_NO_CLEANUPS_P (t))
646     {
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);
651     }
652   else if (!SCOPE_NULLIFIED_P (t))
653     {
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;
659     }
660
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))
664     {
665       tree fn;
666
667       for (fn = BLOCK_VARS (block); fn; fn = TREE_CHAIN (fn))
668         {
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))
674             {
675               push_function_context ();
676               output_inline_function (fn);
677               pop_function_context ();
678             }
679         }
680     }
681 }
682
683 /* Generate the RTL for T, which is a SWITCH_STMT.  */
684
685 void
686 genrtl_switch_stmt (t)
687      tree t;
688 {
689   tree cond;
690   genrtl_do_pushlevel ();
691  
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;
697
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));
702 }
703
704 /* Create a CASE_LABEL tree node and return it.  */
705
706 tree
707 build_case_label (low_value, high_value, label_decl)
708      tree low_value;
709      tree high_value;
710      tree label_decl;
711 {
712   return build_stmt (CASE_LABEL, low_value, high_value, label_decl);
713 }
714
715
716 /* Generate the RTL for a CASE_LABEL.  */
717
718 void 
719 genrtl_case_label (case_label)
720      tree case_label;
721 {
722   tree duplicate;
723   tree cleanup;
724
725   cleanup = last_cleanup_this_contour ();
726   if (cleanup)
727     {
728       static int explained = 0;
729       warning ("destructor needed for `%#D'", (TREE_PURPOSE (cleanup)));
730       warning ("where case label appears here");
731       if (!explained)
732         {
733           warning ("(enclose actions of previous case statements requiring destructors in their own scope.)");
734           explained = 1;
735         }
736     }
737
738   add_case_node (CASE_LOW (case_label), CASE_HIGH (case_label), 
739                  CASE_LABEL_DECL (case_label), &duplicate);
740 }
741
742 /* Generate the RTL for T, which is a COMPOUND_STMT.  */
743
744 void
745 genrtl_compound_stmt (t)
746     tree t;
747 {
748 #ifdef ENABLE_CHECKING
749   struct nesting *n = current_nesting_level ();
750 #endif
751
752   expand_stmt (COMPOUND_BODY (t));
753
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
759 }
760
761 /* Generate the RTL for an ASM_STMT.  */
762
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;
772 {
773   if (cv_qualifier != NULL_TREE
774       && cv_qualifier != ridpointers[(int) RID_VOLATILE])
775     {
776       warning ("%s qualifier ignored on asm",
777                IDENTIFIER_POINTER (cv_qualifier));
778       cv_qualifier = NULL_TREE;
779     }
780
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);
788 }
789
790 /* Generate the RTL for a CLEANUP_STMT.  */
791
792 void 
793 genrtl_cleanup_stmt (t)
794      tree t;
795 {
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));
799 }
800
801 /* We're about to expand T, a statement.  Set up appropriate context
802    for the substitution.  */
803
804 void
805 prep_stmt (t)
806      tree t;
807 {
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);
811 }
812
813 /* Generate the RTL for the statement T, its substatements, and any
814    other statements at its nesting level.  */
815
816 void
817 expand_stmt (t)
818      tree t;
819 {
820   while (t && t != error_mark_node)
821     {
822       int saved_stmts_are_full_exprs_p;
823
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);
827
828       switch (TREE_CODE (t))
829         {
830         case FILE_STMT:
831           input_filename = FILE_STMT_FILENAME (t);
832           break;
833
834         case RETURN_STMT:
835           genrtl_return_stmt (t);
836           t = expand_unreachable_stmt (TREE_CHAIN (t), warn_notreached);
837           goto process_t;
838
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;
845
846         case DECL_STMT:
847           genrtl_decl_stmt (t);
848           break;
849
850         case FOR_STMT:
851           genrtl_for_stmt (t);
852           break;
853
854         case WHILE_STMT:
855           genrtl_while_stmt (t);
856           break;
857
858         case DO_STMT:
859           genrtl_do_stmt (t);
860           break;
861
862         case IF_STMT:
863           genrtl_if_stmt (t);
864           break;
865
866         case COMPOUND_STMT:
867           genrtl_compound_stmt (t);
868           break;
869
870         case BREAK_STMT:
871           genrtl_break_stmt ();
872           t = expand_unreachable_stmt (TREE_CHAIN (t), warn_notreached);
873           goto process_t;
874
875         case CONTINUE_STMT:
876           genrtl_continue_stmt ();
877           t = expand_unreachable_stmt (TREE_CHAIN (t), warn_notreached);
878           goto process_t;
879
880         case SWITCH_STMT:
881           genrtl_switch_stmt (t);
882           break;
883
884         case CASE_LABEL:
885           genrtl_case_label (t);
886           break;
887
888         case LABEL_STMT:
889           expand_label (LABEL_STMT_LABEL (t));
890           break;
891
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)
897             {
898               rtx note = emit_note (NULL, NOTE_INSN_PREDICTION);
899
900               NOTE_PREDICTION (note) = NOTE_PREDICT (PRED_GOTO, NOT_TAKEN);
901             }
902           genrtl_goto_stmt (GOTO_DESTINATION (t));
903           t = expand_unreachable_stmt (TREE_CHAIN (t), warn_notreached);
904           goto process_t;
905
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;
911
912         case SCOPE_STMT:
913           genrtl_scope_stmt (t);
914           break;
915
916         case CLEANUP_STMT:
917           genrtl_cleanup_stmt (t);
918           break;
919
920         default:
921           if (lang_expand_stmt)
922             (*lang_expand_stmt) (t);
923           else 
924             abort ();
925           break;
926         }
927
928       /* Go on to the next statement in this scope.  */
929       t = TREE_CHAIN (t);
930
931     process_t:
932       /* Restore saved state.  */
933       current_stmt_tree ()->stmts_are_full_exprs_p
934         = saved_stmts_are_full_exprs_p;
935     }
936 }
937 \f
938 /* If *TP is a potentially reachable label, return nonzero.  */
939
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;
945 {
946   switch (TREE_CODE (*tp))
947     {
948     case LABEL_STMT:
949     case CASE_LABEL:
950       return *tp;
951
952     default:
953       break;
954     }
955   return NULL_TREE;
956 }
957
958 /* Determine whether expression EXP contains a potentially
959    reachable label.  */
960 static tree
961 find_reachable_label (exp)
962      tree exp;
963 {
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;
968 }
969
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;
975 {
976   tree n;
977   
978   if (find_reachable_label (IF_COND (t)) != NULL_TREE)
979     {
980       genrtl_if_stmt (t);
981       return true;
982     }
983
984   if (THEN_CLAUSE (t) && ELSE_CLAUSE (t))
985     {
986       n = expand_unreachable_stmt (THEN_CLAUSE (t), 0);
987       
988       if (n != NULL_TREE)
989         {
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;
997         }
998       else
999         n = expand_unreachable_stmt (ELSE_CLAUSE (t), 0);
1000     }
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;
1007   
1008   expand_stmt (n);
1009   
1010   return n != NULL_TREE;
1011 }
1012
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;
1021 {
1022   int saved;
1023
1024   while (t && t != error_mark_node)
1025     {
1026       if (warn)
1027         switch (TREE_CODE (t))
1028           {
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;
1040
1041           default:
1042             break;
1043           }
1044
1045       switch (TREE_CODE (t))
1046         {
1047         case GOTO_STMT:
1048         case CONTINUE_STMT:
1049         case BREAK_STMT:
1050           break;
1051
1052         case FILE_STMT:
1053           input_filename = FILE_STMT_FILENAME (t);
1054           break;
1055
1056         case RETURN_STMT:
1057           if (find_reachable_label (RETURN_STMT_EXPR (t)) != NULL_TREE)
1058             return t;
1059           break;
1060
1061         case EXPR_STMT:
1062           if (find_reachable_label (EXPR_STMT_EXPR (t)) != NULL_TREE)
1063             return t;
1064           break;
1065
1066         case IF_STMT:
1067           if (expand_unreachable_if_stmt (t))
1068             return TREE_CHAIN (t);
1069           break;
1070
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);
1077
1078         case COMPOUND_STMT:
1079           {
1080             tree n;
1081             n = expand_unreachable_stmt (COMPOUND_BODY (t), warn);
1082             if (n != NULL_TREE)
1083               {
1084                 expand_stmt (n);
1085                 return TREE_CHAIN (t);
1086               }
1087             warn = false;
1088             break;
1089           }
1090
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;
1097
1098         default:
1099           return t;
1100         }
1101       t = TREE_CHAIN (t);
1102     }
1103   return NULL_TREE;
1104 }
1105