Added flag to switch off entity verification in Load/Store nodes.
[libfirm] / ir / ir / irvrfy.c
1 /*
2  * Project:     libFIRM
3  * File name:   ir/ir/irvrfy.c
4  * Purpose:     Check irnodes for correctness.
5  * Author:      Christian Schaefer
6  * Modified by: Goetz Lindenmaier. Till Riedel
7  * Created:
8  * CVS-ID:      $Id$
9  * Copyright:   (c) 1998-2003 Universität Karlsruhe
10  * Licence:     This file protected by GPL -  GNU GENERAL PUBLIC LICENSE.
11  */
12
13 #ifdef HAVE_CONFIG_H
14 # include <config.h>
15 #endif
16
17 # include "irprog.h"
18 # include "irgraph_t.h"
19 # include "irvrfy.h"
20 # include "irgwalk.h"
21 # include "irdump.h"
22
23 #ifdef NDEBUG
24 /*
25  * in RELEASE mode, returns ret if the expression expr evaluates to zero
26  * in ASSERT mode, asserts the expression expr (and the string string).
27  */
28 #define ASSERT_AND_RET(expr, string, ret)       if (!(expr)) return (ret)
29
30 /*
31  * in RELEASE mode, returns ret if the expression expr evaluates to zero
32  * in ASSERT mode, executes blk if the expression expr evaluates to zero and asserts expr
33  */
34 #define ASSERT_AND_RET_DBG(expr, string, ret, blk)      if (!(expr)) return (ret)
35 #else
36 #define ASSERT_AND_RET(expr, string, ret) \
37 do { \
38   if (opt_do_node_verification == NODE_VERIFICATION_ON) {\
39     if (!(expr)) dump_ir_block_graph(current_ir_graph, "-assert"); \
40     assert((expr) && string); } \
41   if (!(expr)) { \
42     if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
43       fprintf(stderr, #expr " : " string "\n"); \
44     bad_msg = #expr " && " string; \
45     return (ret); \
46   } \
47 } while(0)
48
49 #define ASSERT_AND_RET_DBG(expr, string, ret, blk) \
50 do { \
51   if (!(expr)) { \
52     bad_msg = #expr " && " string; \
53     if (opt_do_node_verification != NODE_VERIFICATION_ERROR_ONLY) { blk; } \
54     if (opt_do_node_verification == NODE_VERIFICATION_REPORT) \
55       fprintf(stderr, #expr " : " string "\n"); \
56     else if (opt_do_node_verification == NODE_VERIFICATION_ON) \
57       assert((expr) && string); \
58     return (ret); \
59   } \
60 } while(0)
61
62 #endif
63
64 /** if this flag is set, verify entity types in Load & Store nodes */
65 static int vrfy_entities = 0;
66
67 /* @@@ replace use of array "in" by access functions. */
68 ir_node **get_irn_in(ir_node *node);
69
70 static node_verification_t opt_do_node_verification = NODE_VERIFICATION_ON;
71 static const char *bad_msg;
72
73 /* enable verification of Load/Store entities */
74 void vrfy_enable_entity_tests(int enable)
75 {
76   vrfy_entities = enable;
77 }
78
79 /**
80  * little helper for NULL modes
81  */
82 static const char *get_mode_name_ex(ir_mode *mode)
83 {
84   if (! mode)
85     return "<no mode>";
86   return get_mode_name(mode);
87 }
88
89 void do_node_verification(node_verification_t mode)
90 {
91   opt_do_node_verification = mode;
92 }
93
94 /**
95  * Prints a failure for a Node
96  */
97 static void show_node_failure(ir_node *n)
98 {
99   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s\n" ,
100     get_irn_node_nr(n),
101     get_irn_opname(n), get_irn_modename(n)
102   );
103 }
104
105 /**
106  * Prints a failure message for a binop
107  */
108 static void show_binop_failure(ir_node *n, const char *text)
109 {
110   ir_node *left  = get_binop_left(n);
111   ir_node *right = get_binop_right(n);
112
113   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s, %s%s) did not match (%s)\n",
114       get_irn_node_nr(n),
115       get_irn_opname(n), get_irn_modename(n),
116       get_irn_opname(left), get_irn_modename(left),
117       get_irn_opname(right), get_irn_modename(right),
118       text);
119 }
120
121 /**
122  * Prints a failure message for an unop
123  */
124 static void show_unop_failure(ir_node *n, const char *text)
125 {
126   ir_node *op  = get_unop_op(n);
127
128   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s(%s%s) did not match (%s)\n",
129       get_irn_node_nr(n),
130       get_irn_opname(n), get_irn_modename(n),
131       get_irn_opname(op), get_irn_modename(op),
132       text);
133 }
134
135 /**
136  * Prints a failure message for a proj
137  */
138 static void show_proj_failure(ir_node *n)
139 {
140   ir_node *op  = get_Proj_pred(n);
141   int proj     = get_Proj_proj(n);
142
143   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) failed\n" ,
144       get_irn_node_nr(n),
145       get_irn_opname(n), get_irn_modename(n), proj,
146       get_irn_opname(op), get_irn_modename(op));
147 }
148
149 /**
150  * Prints a failure message for a proj
151  */
152 static void show_proj_failure_ent(ir_node *n, entity *ent)
153 {
154   ir_node *op  = get_Proj_pred(n);
155   int proj     = get_Proj_proj(n);
156   ir_mode *m   = get_type_mode(get_entity_type(ent));
157
158   fprintf(stderr, "\nFIRM: irn_vrfy_irg() of node %ld %s%s %d(%s%s) entity %s(type %s mode %s)failed\n" ,
159       get_irn_node_nr(n),
160       get_irn_opname(n), get_irn_modename(n), proj,
161       get_irn_opname(op), get_irn_modename(op),
162       get_entity_name(ent), get_type_name(get_entity_type(ent)),
163       get_mode_name_ex(m));
164 }
165
166 /**
167  * Show a node and a graph
168  */
169 static void show_node_on_graph(ir_graph *irg, ir_node *n)
170 {
171   entity *ent = get_irg_entity(irg);
172
173   if (ent)
174     fprintf(stderr, "\nFIRM: irn_vrfy_irg() of entity %s, node %ld %s%s\n",
175       get_entity_name(ent),
176       get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
177   else
178     fprintf(stderr, "\nFIRM: irn_vrfy_irg() of graph %p, node %ld %s%s\n",
179       (void *)irg,
180       get_irn_node_nr(n), get_irn_opname(n), get_irn_modename(n));
181 }
182
183 /**
184  * Show call params
185  */
186 static void show_call_param(ir_node *n, type *mt)
187 {
188   int i;
189
190   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Call type-check failed: %s(", get_type_name(mt));
191   for (i = 0; i < get_method_n_params(mt); ++i) {
192     fprintf(stderr, "%s ", get_mode_name_ex(get_type_mode(get_method_param_type(mt, i))));
193   }
194   fprintf(stderr, ") != CALL(");
195
196   for (i = 0; i < get_Call_n_params(n); ++i) {
197     fprintf(stderr, "%s ", get_mode_name_ex(get_irn_mode(get_Call_param(n, i))));
198   }
199   fprintf(stderr, ")\n");
200
201 }
202
203 /**
204  * Show return modes
205  */
206 static void show_return_modes(ir_graph *irg, ir_node *n, type *mt, int i)
207 {
208   entity *ent = get_irg_entity(irg);
209
210   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" mode %s different from type mode %s\n",
211     get_irn_node_nr(n), get_entity_name(ent),
212     get_mode_name_ex(get_irn_mode(get_Return_res(n, i))),
213     get_mode_name_ex(get_type_mode(get_method_res_type(mt, i)))
214   );
215 }
216
217 /**
218  * Show return number of results
219  */
220 static void show_return_nres(ir_graph *irg, ir_node *n, type *mt)
221 {
222   entity *ent = get_irg_entity(irg);
223
224   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Return node %ld in entity \"%s\" has %d results different from type %d\n",
225     get_irn_node_nr(n), get_entity_name(ent),
226     get_Return_n_ress(n), get_method_n_ress(mt));
227 }
228
229 /**
230  * Show Phi input
231  */
232 static void show_phi_failure(ir_node *phi, ir_node *pred, int pos)
233 {
234   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Phi node %ld has mode %s different from predeccessor node %ld mode %s\n",
235     get_irn_node_nr(phi), get_mode_name_ex(get_irn_mode(phi)),
236     get_irn_node_nr(pred), get_mode_name_ex(get_irn_mode(pred)));
237 }
238
239 /**
240  * Show Phi inputs
241  */
242 static void show_phi_inputs(ir_node *phi, ir_node *block)
243 {
244   fprintf(stderr, "\nFIRM: irn_vrfy_irg() Phi node %ld has %d inputs, its Block %ld has %d\n",
245     get_irn_node_nr(phi),   get_irn_arity(phi),
246     get_irn_node_nr(block), get_irn_arity(block));
247 }
248
249 /* If the address is Sel or SymConst, return the entity. */
250 static entity *get_ptr_entity(ir_node *ptr) {
251   if (get_irn_op(ptr) == op_Sel) {
252     return get_Sel_entity(ptr);
253   } else if ((get_irn_op(ptr) == op_SymConst) && (get_SymConst_kind(ptr) == symconst_addr_ent)) {
254     return get_SymConst_entity(ptr);
255   }
256   return NULL;
257 }
258
259 /**
260  * verify the Proj number
261  */
262 static int
263 vrfy_Proj_proj(ir_node *p, ir_graph *irg) {
264   ir_node *pred;
265   ir_mode *mode;
266   int proj;
267
268   pred = skip_Id(get_Proj_pred(p));
269   ASSERT_AND_RET(get_irn_mode(pred) == mode_T, "mode of a 'projed' node is not Tuple", 0);
270   mode = get_irn_mode(p);
271   proj = get_Proj_proj(p);
272
273   switch (get_irn_opcode(pred)) {
274     case iro_Start:
275       ASSERT_AND_RET_DBG(
276           (
277            (proj == pn_Start_X_initial_exec && mode == mode_X) ||
278            (proj == pn_Start_M         && mode == mode_M) ||
279            (proj == pn_Start_P_frame_base && mode_is_reference(mode)) ||
280            (proj == pn_Start_P_globals && mode_is_reference(mode)) ||
281            (proj == pn_Start_T_args    && mode == mode_T) ||
282            (proj == pn_Start_P_value_arg_base && mode_is_reference(mode)) ||
283            (proj == pn_Start_P_value_arg_base && mode == mode_T)    /* FIXME: only one of those */
284           ),
285           "wrong Proj from Start", 0,
286       show_proj_failure(p);
287       );
288       break;
289
290     case iro_Cond:
291       ASSERT_AND_RET_DBG(
292         (
293           (proj >= 0 && mode == mode_X && get_irn_mode(get_Cond_selector(pred)) == mode_b) ||   /* compare */
294           (mode == mode_X && mode_is_int(get_irn_mode(get_Cond_selector(pred))))                /* switch */
295         ),
296         "wrong Proj from Cond", 0,
297         show_proj_failure(p);
298       );
299       break;
300
301     case iro_Raise:
302       ASSERT_AND_RET_DBG(
303         ((proj == pn_Raise_X && mode == mode_X) || (proj == pn_Raise_M && mode == mode_M)),
304         "wrong Proj from Raise", 0,
305     show_proj_failure(p);
306       );
307       break;
308
309     case iro_InstOf:
310       ASSERT_AND_RET_DBG(
311     (proj >= 0 && mode == mode_X),
312     "wrong Proj from InstOf", 0,
313     show_proj_failure(p);
314       );
315       break;
316
317     case iro_Call:
318       ASSERT_AND_RET_DBG(
319         ((proj == pn_Call_M_regular        && mode == mode_M) ||
320          (proj == pn_Call_X_except         && mode == mode_X) ||
321          (proj == pn_Call_T_result         && mode == mode_T) ||
322          (proj == pn_Call_M_except         && mode == mode_M) ||
323      (proj == pn_Call_P_value_res_base && mode == mode_P)),
324         "wrong Proj from Call", 0,
325         show_proj_failure(p);
326       );
327       break;
328
329     case iro_FuncCall:
330       ASSERT_AND_RET_DBG(
331         ((proj == pn_Call_M_regular        && mode == mode_M) ||
332          (proj == pn_Call_X_except         && mode == mode_X) ||
333          (proj == pn_Call_T_result         && mode == mode_T) ||
334          (proj == pn_Call_M_except         && mode == mode_M) ||
335      (proj == pn_Call_P_value_res_base && mode == mode_P)),
336         "wrong Proj from FuncCall", 0,
337         show_proj_failure(p);
338       );
339       break;
340
341     case iro_Quot:
342       ASSERT_AND_RET_DBG(
343         ((proj == pn_Quot_M        && mode == mode_M) ||
344          (proj == pn_Quot_X_except && mode == mode_X) ||
345          (proj == pn_Quot_res      && mode_is_float(mode))),
346         "wrong Proj from Quot", 0,
347     show_proj_failure(p);
348       );
349       break;
350
351     case iro_DivMod:
352       ASSERT_AND_RET_DBG(
353         ((proj == pn_DivMod_M        && mode == mode_M) ||
354          (proj == pn_DivMod_X_except && mode == mode_X) ||
355          (proj == pn_DivMod_res_div  && mode_is_int(mode)) ||
356          (proj == pn_DivMod_res_mod  && mode_is_int(mode))),
357         "wrong Proj from DivMod", 0,
358     show_proj_failure(p);
359       );
360       break;
361
362     case iro_Div:
363       ASSERT_AND_RET_DBG(
364         ((proj == pn_Div_M        && mode == mode_M) ||
365          (proj == pn_Div_X_except && mode == mode_X) ||
366          (proj == pn_Div_res      && mode_is_int(mode))),
367         "wrong Proj from Div or Mod", 0,
368     show_proj_failure(p);
369       );
370       break;
371
372     case iro_Mod:
373       ASSERT_AND_RET_DBG(
374         ((proj == pn_Mod_M        && mode == mode_M) ||
375          (proj == pn_Mod_X_except && mode == mode_X) ||
376          (proj == pn_Mod_res      && mode_is_int(mode))),
377         "wrong Proj from Div or Mod", 0,
378     show_proj_failure(p);
379       );
380       break;
381
382     case iro_Cmp:
383       ASSERT_AND_RET_DBG(
384         (proj >= 0 && proj <= 15 && mode == mode_b),
385         "wrong Proj from Cmp", 0,
386     show_proj_failure(p);
387       );
388       break;
389
390     case iro_Load:
391       if (proj == pn_Load_res) {
392         ir_node *ptr = get_Load_ptr(pred);
393         entity *ent = get_ptr_entity(ptr);
394         if (vrfy_entities && ent && get_irg_phase_state(current_ir_graph) == phase_high) {
395           /* do NOT check this for lowered phases, see comment on Store */
396           ASSERT_AND_RET_DBG(
397                              (mode == get_type_mode(get_entity_type(ent))),
398                              "wrong data Proj from Load, entity type_mode failed", 0,
399                              show_proj_failure_ent(p, ent);
400                              );
401         }
402         else {
403           ASSERT_AND_RET_DBG(
404                              mode_is_data(mode),
405                              "wrong data Proj from Load", 0,
406                              show_proj_failure(p);
407                              );
408         }
409       } else {
410         ASSERT_AND_RET_DBG(
411                            ((proj == pn_Load_M        && mode == mode_M) ||
412                             (proj == pn_Load_X_except && mode == mode_X)),
413                            "wrong Proj from Load", 0,
414                            show_proj_failure(p);
415                            );
416       }
417       break;
418
419     case iro_Store:
420       ASSERT_AND_RET_DBG(
421         ((proj == pn_Store_M        && mode == mode_M) ||
422          (proj == pn_Store_X_except && mode == mode_X)),
423         "wrong Proj from Store", 0,
424         show_proj_failure(p);
425       );
426       break;
427
428     case iro_Alloc:
429       ASSERT_AND_RET_DBG(
430         (
431          (proj == pn_Alloc_M        && mode == mode_M) ||
432          (proj == pn_Alloc_X_except /* && mode == mode_X*/) ||
433          (proj == pn_Alloc_res      && mode_is_reference(mode))
434         ),
435         "wrong Proj from Alloc", 0,
436         show_proj_failure(p);
437       );
438       break;
439
440     case iro_Proj:
441       {
442         type *mt; /* A method type */
443         long nr = get_Proj_proj(pred);
444
445         pred = skip_Id(get_Proj_pred(pred));
446         ASSERT_AND_RET((get_irn_mode(pred) == mode_T), "Proj from something not a tuple", 0);
447         switch (get_irn_opcode(pred))
448         {
449           case iro_Start:
450             mt = get_entity_type(get_irg_entity(irg));
451
452         if (nr == pn_Start_T_args) {
453               ASSERT_AND_RET(
454                   (proj >= 0 && mode_is_data(mode)),
455                   "wrong Proj from Proj from Start", 0);
456               ASSERT_AND_RET(
457                 (proj < get_method_n_params(mt)),
458                 "More Projs for args than args in type", 0
459               );
460               if ((mode_is_reference(mode)) && is_compound_type(get_method_param_type(mt, proj)))
461                 /* value argument */ break;
462
463               ASSERT_AND_RET(
464                   (mode == get_type_mode(get_method_param_type(mt, proj))),
465                   "Mode of Proj from Start doesn't match mode of param type.", 0);
466             }
467         else if (nr == pn_Start_P_value_arg_base) {
468           ASSERT_AND_RET(
469                   (proj >= 0 && mode_is_reference(mode)),
470                   "wrong Proj from Proj from Start", 0
471               );
472               ASSERT_AND_RET(
473                 (proj < get_method_n_params(mt)),
474                 "More Projs for args than args in type", 0
475               );
476         }
477             break;
478
479           case iro_Call:
480             {
481               ASSERT_AND_RET(
482                   (proj >= 0 && mode_is_data(mode)),
483                   "wrong Proj from Proj from Call", 0);
484               mt = get_Call_type(pred);
485               ASSERT_AND_RET(
486                   (proj < get_method_n_ress(mt)),
487                   "More Projs for results than results in type.", 0);
488               if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
489                 /* value result */ break;
490
491               ASSERT_AND_RET(
492                   (mode == get_type_mode(get_method_res_type(mt, proj))),
493                   "Mode of Proj from Call doesn't match mode of result type.", 0);
494             }
495             break;
496
497           case iro_FuncCall:
498             {
499               ASSERT_AND_RET(
500                   (proj >= 0 && mode_is_data(mode)),
501                   "wrong Proj from Proj from FuncCall", 0);
502               mt = get_FuncCall_type(pred);
503               ASSERT_AND_RET(
504                   (proj < get_method_n_ress(mt)),
505                   "More Projs for results than results in type.", 0);
506               if ((mode_is_reference(mode)) && is_compound_type(get_method_res_type(mt, proj)))
507                 /* value result */ break;
508
509               ASSERT_AND_RET(
510                   (mode == get_type_mode(get_method_res_type(mt, proj))),
511                   "Mode of Proj from FuncCall doesn't match mode of result type.", 0);
512             }
513             break;
514
515           case iro_Tuple:
516             /* We don't test */
517             break;
518
519           default:
520             ASSERT_AND_RET(0, "Unknown opcode", 0);
521         }
522         break;
523
524       }
525     case iro_Tuple:
526       /* We don't test */
527       break;
528
529     case iro_CallBegin:
530       break;
531
532     case iro_EndReg:
533       break;
534
535     case iro_EndExcept:
536       break;
537
538     default:
539       ASSERT_AND_RET(0, "Unknown opcode", 0);
540   }
541
542   /* all went ok */
543   return 1;
544 }
545
546 int irn_vrfy_irg(ir_node *n, ir_graph *irg)
547 {
548   int i;
549   int opcode, opcode1;
550   ir_mode *mymode, *op1mode = NULL, *op2mode, *op3mode;
551   int op_is_symmetric = 1;  /*  0: asymmetric
552                                 1: operands have identical modes
553                                 2: modes of operands == mode of this node */
554   type *mt;                 /* A method type */
555   entity *ent;
556
557   ir_node **in;
558
559   if (!opt_do_node_verification) return 1;
560
561   if (! interprocedural_view) {
562     /*
563      * do NOT check placement in interprocedural view, as we don't always know
564      * the "right" graph ...
565      */
566     ASSERT_AND_RET_DBG(
567                        node_is_in_irgs_storage(irg, n),
568                        "Node is not stored on proper IR graph!", 0,
569                        show_node_on_graph(irg, n);
570                        );
571   }
572
573   opcode = get_irn_opcode(n);
574
575   /* We don't want to test nodes whose predecessors are Bad,
576      as we would have to special case that for each operation. */
577   if (opcode != iro_Phi && opcode != iro_Block)
578     for (i = 0; i < get_irn_arity(n); i++) {
579       opcode1 = get_irn_opcode(get_irn_n(n, i));
580       if (opcode1 == iro_Bad)
581         return 1;
582     }
583
584   mymode = get_irn_mode(n);
585   in = get_irn_in(n);
586
587   switch (opcode) {
588
589     case iro_Block:
590       for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
591         ir_node *pred =  get_Block_cfgpred(n, i);
592         ASSERT_AND_RET(
593                        (is_Bad(pred)     ||
594                         is_Unknown(pred) ||
595                         (get_irn_mode(pred) == mode_X)
596                         ), "Block node", 0);
597       }
598       /*  End block may only have Return, Raise or fragile ops as preds. */
599       if (n == get_irg_end_block(irg))
600         for (i = 0; i < get_Block_n_cfgpreds(n); ++i) {
601           ir_node *pred =  skip_Proj(get_Block_cfgpred(n, i));
602           if (is_Proj(pred) || get_irn_op(pred) == op_Tuple)
603             break;   /*  We can not test properly.  How many tuples are there? */
604           ASSERT_AND_RET(((get_irn_op(pred) == op_Return) ||
605                           is_Bad(pred)                    ||
606                           (get_irn_op(pred) == op_Raise)  ||
607                           is_fragile_op(pred)               ),
608                          "End Block node", 0);
609         }
610       /*  irg attr must == graph we are in. */
611       if (! interprocedural_view) {
612         ASSERT_AND_RET(((get_irn_irg(n) && get_irn_irg(n) == irg)), "Block node has wrong irg attribute", 0);
613       }
614
615       break;
616
617     case iro_Start:
618       ASSERT_AND_RET(
619                      /* Start: BB --> X x M x ref x data1 x ... x datan x ref */
620                      mymode == mode_T, "Start node", 0
621                      );
622       break;
623
624     case iro_Jmp:
625       ASSERT_AND_RET(
626                      /* Jmp: BB --> X */
627                      mymode == mode_X, "Jmp node", 0
628                      );
629       break;
630
631     case iro_Break:
632       ASSERT_AND_RET(
633                      /* Jmp: BB --> X */
634                      mymode == mode_X, "Jmp node", 0
635                      );
636       break;
637
638     case iro_Cond:
639       op1mode = get_irn_mode(in[1]);
640       ASSERT_AND_RET(
641                      /* Cond: BB x b --> X x X */
642                      (op1mode == mode_b ||
643                       /* Cond: BB x int --> X^n */
644                       mode_is_int(op1mode) ),  "Cond node", 0
645                      );
646       ASSERT_AND_RET(mymode == mode_T, "Cond mode is not a tuple", 0);
647       break;
648
649     case iro_Return:
650       op1mode = get_irn_mode(in[1]);
651       /* Return: BB x M x data1 x ... x datan --> X */
652       /* printf("mode: %s, code %s\n", ID_TO_STR(n->mode->name), ID_TO_STR(n->op->name));*/
653       ASSERT_AND_RET( op1mode == mode_M, "Return node", 0 );  /* operand M */
654       for (i = 2; i < get_irn_arity(n); i++) {
655         ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Return node", 0 );  /* operand datai */
656       };
657       ASSERT_AND_RET( mymode == mode_X, "Result X", 0 );   /* result X */
658       /* Compare returned results with result types of method type */
659       mt = get_entity_type(get_irg_entity(irg));
660       ASSERT_AND_RET_DBG( get_Return_n_ress(n) == get_method_n_ress(mt),
661         "Number of results for Return doesn't match number of results in type.", 0,
662       show_return_nres(irg, n, mt););
663       for (i = 0; i < get_Return_n_ress(n); i++) {
664     type *res_type = get_method_res_type(mt, i);
665
666         if (is_atomic_type(res_type)) {
667       ASSERT_AND_RET_DBG(
668         get_irn_mode(get_Return_res(n, i)) == get_type_mode(res_type),
669         "Mode of result for Return doesn't match mode of result type.", 0,
670         show_return_modes(irg, n, mt, i);
671       );
672     }
673     else {
674       ASSERT_AND_RET_DBG(
675         mode_is_reference(get_irn_mode(get_Return_res(n, i))),
676         "Mode of result for Return doesn't match mode of result type.", 0,
677         show_return_modes(irg, n, mt, i);
678       );
679     }
680       }
681       break;
682
683     case iro_Raise:
684       op1mode = get_irn_mode(in[1]);
685       op2mode = get_irn_mode(in[2]);
686       ASSERT_AND_RET(
687                      /* Sel: BB x M x ref --> X x M */
688                      op1mode == mode_M && mode_is_reference(op2mode) &&
689                      mymode == mode_T, "Raise node", 0
690                      );
691       break;
692
693     case iro_Const: {
694       ASSERT_AND_RET(
695                      /* Const: BB --> data */
696                      (mode_is_data (mymode) ||
697                       mymode == mode_b)      /* we want boolean constants for static evaluation */
698                      ,"Const node", 0        /* of Cmp. */
699                      );
700       } break;
701     case iro_SymConst:
702       if (get_SymConst_kind(n) == symconst_addr_ent) {
703         entity *ent = get_SymConst_entity(n);
704         if (is_method_type(get_entity_type(ent)) &&
705             get_irn_irg(n) != get_const_code_irg()) {
706 #if 1
707           ASSERT_AND_RET((get_entity_peculiarity(ent) != peculiarity_description),
708                          "A constant must address an existing method.", 0);
709 #endif
710         }
711       }
712       ASSERT_AND_RET(
713                      /* SymConst: BB --> int*/
714                      (mode_is_int(mymode) ||
715                       /* SymConst: BB --> ref */
716                       mode_is_reference(mymode))
717                      ,"SymConst node", 0);
718       break;
719
720     case iro_Sel:
721       op1mode = get_irn_mode(in[1]);
722       op2mode = get_irn_mode(in[2]);
723       ASSERT_AND_RET_DBG(
724                          /* Sel: BB x M x ref x int^n --> ref */
725                          (op1mode == mode_M && op2mode == mymode && mode_is_reference(mymode)),
726                          "Sel node", 0, show_node_failure(n)
727                          );
728       for (i=3; i < get_irn_arity(n); i++)
729         {
730           ASSERT_AND_RET_DBG(mode_is_int(get_irn_mode(in[i])), "Sel node", 0, show_node_failure(n));
731         }
732       ent = get_Sel_entity(n);
733       ASSERT_AND_RET_DBG(ent, "Sel node with empty entity", 0, show_node_failure(n));
734       break;
735
736     case iro_InstOf:
737       ASSERT_AND_RET(mode_T == mymode, "mode of Instof is not a tuple", 0);
738       ASSERT_AND_RET(mode_is_data(op1mode), "Instof not on data", 0);
739       break;
740
741     case iro_Call:
742       op1mode = get_irn_mode(in[1]);
743       op2mode = get_irn_mode(in[2]);
744       /* Call: BB x M x ref x data1 x ... x datan
745          --> M x datan+1 x ... x data n+m */
746       ASSERT_AND_RET( op1mode == mode_M && mode_is_reference(op2mode), "Call node", 0 );  /* operand M x ref */
747       for (i=3; i < get_irn_arity(n); i++) {
748         ASSERT_AND_RET( mode_is_data(get_irn_mode(in[i])), "Call node", 0 );  /* operand datai */
749       };
750       ASSERT_AND_RET( mymode == mode_T, "Call result not a tuple", 0 );   /* result T */
751       /* Compare arguments of node with those of type */
752       mt = get_Call_type(n);
753
754       if (get_method_variadicity(mt) == variadicity_variadic) {
755         ASSERT_AND_RET_DBG(
756                            get_Call_n_params(n) >= get_method_n_params(mt),
757                            "Number of args for Call doesn't match number of args in variadic type.",
758                            0,
759                            fprintf(stderr, "Call has %d params, method %s type %d\n",
760                                    get_Call_n_params(n), get_type_name(mt), get_method_n_params(mt));
761                            );
762       }
763       else {
764         ASSERT_AND_RET(
765                        get_Call_n_params(n) == get_method_n_params(mt),
766                        "Number of args for Call doesn't match number of args in non variadic type.",
767                        0);
768       }
769
770       for (i = 0; i < get_method_n_params(mt); i++) {
771     type *t = get_method_param_type(mt, i);
772
773     if (is_atomic_type(t)) {
774       ASSERT_AND_RET_DBG(
775           get_irn_mode(get_Call_param(n, i)) == get_type_mode(t),
776           "Mode of arg for Call doesn't match mode of arg type.", 0,
777       show_call_param(n, mt);
778       );
779     }
780     else {
781       /* call with a compound type, mode must be reference */
782       ASSERT_AND_RET_DBG(
783           mode_is_reference(get_irn_mode(get_Call_param(n, i))),
784           "Mode of arg for Call doesn't match mode of arg type.", 0,
785       show_call_param(n, mt);
786       );
787     }
788       }
789       break;
790
791     case iro_Add:
792       op1mode = get_irn_mode(in[1]);
793       op2mode = get_irn_mode(in[2]);
794       ASSERT_AND_RET_DBG(
795                          (
796                           /* common Add: BB x numP x numP --> numP */
797                           (op1mode == mymode && op2mode == op1mode && mode_is_numP(mymode)) ||
798                           /* Pointer Add: BB x ref x int --> ref */
799                           (mode_is_reference(op1mode) && mode_is_int(op2mode) && op1mode == mymode) ||
800                           /* Pointer Add: BB x int x ref --> ref */
801                           (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode))
802                           ),
803                          "Add node", 0,
804                          show_binop_failure(n, "/* common Add: BB x numP x numP --> numP */ |\n"
805                                             "/* Pointer Add: BB x ref x int --> ref */   |\n"
806                                             "/* Pointer Add: BB x int x ref --> ref */");
807                          );
808       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
809         /* BB x ref x int --> ref or BB x int x ref --> ref */
810         op_is_symmetric = 0;
811       } else {
812         /* BB x num x num --> num or BB x ref x ref */
813         op_is_symmetric = 2;
814       }
815       break;
816
817     case iro_Sub:
818       op1mode = get_irn_mode(in[1]);
819       op2mode = get_irn_mode(in[2]);
820       ASSERT_AND_RET_DBG(
821                          /* common Sub: BB x numP x numP --> numP */
822                          ((mymode ==op1mode && mymode == op2mode && mode_is_numP(op1mode)) ||
823                           /* Pointer Sub: BB x ref x int --> ref */
824                           (op1mode == mymode && mode_is_int(op2mode) && mode_is_reference(mymode)) ||
825                           /* Pointer Sub: BB x int x ref --> ref */
826                           (mode_is_int(op1mode) && op2mode == mymode && mode_is_reference(mymode)) ||
827                           /* Pointer Sub: BB x ref x ref --> int */
828                           (op1mode == op2mode && mode_is_reference(op2mode) && mode_is_int(mymode))),
829                          "Sub node", 0,
830                          show_binop_failure(n, "/* common Sub: BB x numP x numP --> numP */ |\n"
831                                             "/* Pointer Sub: BB x ref x int --> ref */   |\n"
832                                             "/* Pointer Sub: BB x int x ref --> ref */   |\n"
833                                             "/* Pointer Sub: BB x ref x ref --> int */" );
834                          );
835       if (mode_is_reference(op1mode) != mode_is_reference(op2mode)) {
836         op_is_symmetric = 0;
837       } else {
838         op_is_symmetric = 2;
839       }
840       break;
841
842     case iro_Minus:
843       op1mode = get_irn_mode(in[1]);
844       ASSERT_AND_RET_DBG(
845                          /* Minus: BB x float --> float */
846                          op1mode == mymode && mode_is_float(op1mode), "Minus node", 0,
847                          show_unop_failure(n , "/* Minus: BB x float --> float */");
848                          );
849       op_is_symmetric = 2;
850       break;
851
852     case iro_Mul:
853       op1mode = get_irn_mode(in[1]);
854       op2mode = get_irn_mode(in[2]);
855       ASSERT_AND_RET_DBG(
856                          /* Mul: BB x int1 x int1 --> int2 */
857                          ((mode_is_int(op1mode)   && op2mode == op1mode && mode_is_int(mymode)) ||
858                          /* Mul: BB x float x float --> float */
859                           (mode_is_float(op1mode) && op2mode == op1mode && mymode == op1mode)),
860                          "Mul node",0,
861                          show_binop_failure(n, "/* Mul: BB x int1 x int1 --> int2 */ |\n"
862                                                "/* Mul: BB x float x float --> float */");
863                          );
864       op_is_symmetric = 2;
865       break;
866
867     case iro_Quot:
868       op1mode = get_irn_mode(in[1]);
869       op2mode = get_irn_mode(in[2]);
870       op3mode = get_irn_mode(in[3]);
871       ASSERT_AND_RET_DBG(
872                          /* Quot: BB x M x float x float --> M x X x float */
873                          op1mode == mode_M && op2mode == op3mode &&
874                          get_mode_sort(op2mode) == irms_float_number &&
875                          mymode == mode_T,
876                          "Quot node",0,
877                          show_binop_failure(n, "/* Quot: BB x M x float x float --> M x X x float */");
878                          );
879       op_is_symmetric = 2;
880       break;
881
882     case iro_DivMod:
883       op1mode = get_irn_mode(in[1]);
884       op2mode = get_irn_mode(in[2]);
885       op3mode = get_irn_mode(in[3]);
886       ASSERT_AND_RET(
887                      /* DivMod: BB x M x int x int --> M x X x int x int */
888                      op1mode == mode_M &&
889                      mode_is_int(op2mode) &&
890                      op3mode == op2mode &&
891                      mymode == mode_T,
892                      "DivMod node", 0
893                      );
894       op_is_symmetric = 1;
895       break;
896
897     case iro_Div:
898     case iro_Mod:
899       op1mode = get_irn_mode(in[1]);
900       op2mode = get_irn_mode(in[2]);
901       op3mode = get_irn_mode(in[3]);
902       ASSERT_AND_RET(
903                      /* Div or Mod: BB x M x int x int --> M x X x int */
904                      op1mode == mode_M &&
905                      op2mode == op3mode &&
906                      mode_is_int(op2mode) &&
907                      mymode == mode_T,
908                      "Div or Mod node", 0
909                      );
910       op_is_symmetric = 1;
911       break;
912
913     case iro_Abs:
914       op1mode = get_irn_mode(in[1]);
915       ASSERT_AND_RET_DBG(
916                          /* Abs: BB x num --> num */
917                          op1mode == mymode &&
918                          mode_is_num (op1mode),
919                          "Abs node", 0,
920                          show_unop_failure(n, "/* Abs: BB x num --> num */");
921                          );
922       op_is_symmetric = 2;
923       break;
924
925     case iro_And:
926     case iro_Or:
927     case iro_Eor:
928       op1mode = get_irn_mode(in[1]);
929       op2mode = get_irn_mode(in[2]);
930       ASSERT_AND_RET_DBG(
931                          /* And or Or or Eor: BB x int x int --> int */
932                          mode_is_int(mymode) &&
933                          op2mode == op1mode &&
934                          mymode == op2mode,
935                          "And, Or or Eor node", 0,
936                          show_binop_failure(n, "/* And or Or or Eor: BB x int x int --> int */");
937                          );
938       op_is_symmetric = 2;
939       break;
940
941     case iro_Not:
942       op1mode = get_irn_mode(in[1]);
943       ASSERT_AND_RET_DBG(
944                          /* Not: BB x int --> int */
945                          mode_is_int(mymode) &&
946                          mymode == op1mode,
947                          "Not node", 0,
948                          show_unop_failure(n, "/* Not: BB x int --> int */");
949                          );
950       op_is_symmetric = 2;
951       break;
952
953
954     case iro_Cmp:
955       op1mode = get_irn_mode(in[1]);
956       op2mode = get_irn_mode(in[2]);
957       ASSERT_AND_RET_DBG(
958                          /* Cmp: BB x datab x datab --> b16 */
959                          mode_is_data (op1mode) &&
960                          op2mode == op1mode &&
961                          mymode == mode_T,
962                          "Cmp node", 0,
963                          show_binop_failure(n, "/* Cmp: BB x datab x datab --> b16 */");
964                          );
965       break;
966
967     case iro_Shl:
968     case iro_Shr:
969     case iro_Shrs:
970       op1mode = get_irn_mode(in[1]);
971       op2mode = get_irn_mode(in[2]);
972       ASSERT_AND_RET_DBG(
973                          /* Shl, Shr or Shrs: BB x int x int_u --> int */
974                          mode_is_int(op1mode) &&
975                          mode_is_int(op2mode) &&
976                          !mode_is_signed(op2mode) &&
977                          mymode == op1mode,
978                          "Shl, Shr, Shr or Rot node", 0,
979                          show_binop_failure(n, "/* Shl, Shr or Shrs: BB x int x int_u --> int */");
980                          );
981       break;
982
983     case iro_Rot:
984       op1mode = get_irn_mode(in[1]);
985       op2mode = get_irn_mode(in[2]);
986       ASSERT_AND_RET_DBG(
987                          /* Rot: BB x int x int --> int */
988                          mode_is_int(op1mode) &&
989                          mode_is_int(op2mode) &&
990                          mymode == op1mode,
991                          "Rot node", 0,
992                          show_binop_failure(n, "/* Rot: BB x int x int --> int */");
993                          );
994       break;
995
996     case iro_Conv:
997       op1mode = get_irn_mode(in[1]);
998       ASSERT_AND_RET_DBG(
999                          /* Conv: BB x datab1 --> datab2 */
1000                          mode_is_datab(op1mode) && mode_is_data(mymode),
1001                          "Conv node", 0,
1002                          show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1003                          );
1004       break;
1005
1006     case iro_Cast:
1007       op1mode = get_irn_mode(in[1]);
1008       ASSERT_AND_RET_DBG(
1009                          /* Conv: BB x datab1 --> datab2 */
1010                          mode_is_data(op1mode) && op1mode == mymode,
1011                          "Cast node", 0,
1012                          show_unop_failure(n, "/* Conv: BB x datab1 --> datab2 */");
1013                          );
1014       break;
1015
1016     case iro_Phi:
1017     {
1018       ir_node *block = get_nodes_block(n);
1019
1020       if (! is_Bad(block) && get_irg_phase_state(get_irn_irg(n)) != phase_building) {
1021         /* a Phi node MUST have the same number of inputs as its block */
1022         ASSERT_AND_RET_DBG(
1023           get_irn_arity(n) == get_irn_arity(block),
1024           "wrong number of inputs in Phi node", 0,
1025           show_phi_inputs(n, block);
1026         );
1027       }
1028
1029       /* Phi: BB x dataM^n --> dataM */
1030       for (i = 1; i < get_irn_arity(n); i++) {
1031         if (!is_Bad(in[i]) && (get_irn_op(in[i]) != op_Unknown))
1032           ASSERT_AND_RET_DBG(
1033                              get_irn_mode(in[i]) == mymode,
1034                              "Phi node", 0,
1035                              show_phi_failure(n, in[i], i);
1036                              );
1037       };
1038       ASSERT_AND_RET( mode_is_dataM(mymode), "Phi node", 0 );
1039       break;
1040     }
1041     case iro_Load:
1042       op1mode = get_irn_mode(in[1]);
1043       op2mode = get_irn_mode(in[2]);
1044       ASSERT_AND_RET(
1045                      /* Load: BB x M x ref --> M x X x data */
1046                      op1mode == mode_M && mode_is_reference(op2mode),
1047                      "Load node", 0
1048                      );
1049       ASSERT_AND_RET( mymode == mode_T, "Load node", 0 );
1050
1051       /*
1052        * jack's gen_add_firm_code:simpleSel seems to build Load (Load
1053        * (Proj (Proj))) sometimes ...
1054
1055        * interprete.c:ai_eval seems to assume that this happens, too
1056
1057        * obset.c:get_abstval_any can't deal with this if the load has
1058        * mode_T
1059        *
1060       {
1061         entity *ent = hunt_for_entity (get_Load_ptr (n), n);
1062         assert ((NULL != ent) || (mymode != mode_T));
1063       }
1064       */
1065
1066       break;
1067
1068     case iro_Store:
1069       op1mode = get_irn_mode(in[1]);
1070       op2mode = get_irn_mode(in[2]);
1071       op3mode = get_irn_mode(in[3]);
1072       ASSERT_AND_RET(
1073                      /* Load: BB x M x ref data --> M x X */
1074                      op1mode == mode_M && mode_is_reference(op2mode) && mode_is_data(op3mode),
1075                      "Store node", 0
1076                      );
1077       ASSERT_AND_RET(mymode == mode_T, "Store node", 0);
1078
1079       entity *target = get_ptr_entity(in[2]);
1080       if (vrfy_entities && target && get_irg_phase_state(current_ir_graph) == phase_high) {
1081         /*
1082          * If lowered code, any Sels that add 0 may be removed, causing
1083          * an direct access to entities of array or compound type.
1084          * Prevent this by checking the phase.
1085          */
1086         ASSERT_AND_RET( op3mode == get_type_mode(get_entity_type(target)),
1087                         "Store node", 0);
1088       }
1089
1090       break;
1091
1092     case iro_Alloc:
1093       op1mode = get_irn_mode(in[1]);
1094       op2mode = get_irn_mode(in[2]);
1095       ASSERT_AND_RET_DBG(
1096                          /* Alloc: BB x M x int_u --> M x X x ref */
1097                          op1mode == mode_M &&
1098                          mode_is_int(op2mode) &&
1099                          !mode_is_signed(op2mode) &&
1100                          mymode == mode_T,
1101                          "Alloc node", 0,
1102                          show_binop_failure(n, "/* Alloc: BB x M x int_u --> M x X x ref */");
1103                          );
1104       break;
1105
1106     case iro_Free:
1107       op1mode = get_irn_mode(in[1]);
1108       op2mode = get_irn_mode(in[2]);
1109       ASSERT_AND_RET_DBG(
1110                          /* Free: BB x M x ref --> M */
1111                          op1mode == mode_M && mode_is_reference(op2mode) &&
1112                          mymode == mode_M,
1113                          "Free node", 0,
1114                          show_binop_failure(n, "/* Free: BB x M x ref --> M */");
1115                          );
1116       break;
1117
1118     case iro_Sync:
1119       /* Sync: BB x M^n --> M */
1120       for (i=1; i < get_irn_arity(n); i++) {
1121         ASSERT_AND_RET( get_irn_mode(in[i]) == mode_M, "Sync node", 0 );
1122       };
1123       ASSERT_AND_RET( mymode == mode_M, "Sync node", 0 );
1124       break;
1125
1126     case iro_Proj:
1127       return vrfy_Proj_proj(n, irg);
1128       break;
1129
1130     case iro_Confirm:
1131       op1mode = get_irn_mode(in[1]);
1132       op2mode = get_irn_mode(in[2]);
1133       ASSERT_AND_RET_DBG(
1134                          /* Confirm: BB x T x T --> T */
1135                          op1mode == mymode &&
1136                          op2mode == mymode,
1137                          "Confirm node", 0,
1138                          show_binop_failure(n, "/* Confirm: BB x T x T --> T */");
1139                          );
1140       break;
1141
1142     default:
1143       break;
1144     }
1145
1146   /* All went ok */
1147   return 1;
1148 }
1149
1150 int irn_vrfy(ir_node *n)
1151 {
1152   int res = 1;
1153 #ifdef DEBUG_libfirm
1154   res = irn_vrfy_irg(n, current_ir_graph);
1155 #endif
1156   return res;
1157 }
1158
1159 /*-----------------------------------------------------------------*/
1160 /* Verify the whole graph.                                         */
1161 /*-----------------------------------------------------------------*/
1162
1163 /* This *is* used, except gcc doesn't notice that */
1164 static void vrfy_wrap(ir_node *node, void *env)
1165 {
1166   int *res = env;
1167
1168   *res = irn_vrfy(node);
1169 }
1170
1171 int irg_vrfy(ir_graph *irg)
1172 {
1173   int res = 1;
1174 #ifdef DEBUG_libfirm
1175   ir_graph *rem;
1176
1177   rem = current_ir_graph;
1178   current_ir_graph = irg;
1179
1180   assert(get_irg_pinned(irg) == op_pin_state_pinned);
1181
1182   irg_walk_graph(irg, vrfy_wrap, NULL, &res);
1183
1184   current_ir_graph = rem;
1185
1186   if (opt_do_node_verification == NODE_VERIFICATION_REPORT && ! res) {
1187     entity *ent = get_irg_entity(current_ir_graph);
1188
1189     if (ent)
1190       fprintf(stderr, "irg_verify: Verifying graph %s failed\n", get_entity_name(ent));
1191     else
1192       fprintf(stderr, "irg_verify: Verifying graph %p failed\n", (void *)current_ir_graph);
1193   }
1194
1195 #endif
1196   return res;
1197 }
1198
1199 int irn_vrfy_irg_dump(ir_node *n, ir_graph *irg, const char **bad_string)
1200 {
1201   int res;
1202   node_verification_t old = opt_do_node_verification;
1203
1204   bad_msg = NULL;
1205   opt_do_node_verification = NODE_VERIFICATION_ERROR_ONLY;
1206   res = irn_vrfy_irg(n, irg);
1207   opt_do_node_verification = old;
1208   *bad_string = bad_msg;
1209
1210   return res;
1211 }
1212
1213
1214 typedef struct _vrfy_bad_env_t {
1215   int flags;
1216   int res;
1217 } vrfy_bad_env_t;
1218
1219 static void check_bads(ir_node *node, void *env)
1220 {
1221   vrfy_bad_env_t *venv = env;
1222   int i, arity = get_irn_arity(node);
1223
1224   if (is_Block(node)) {
1225     if ((venv->flags & BAD_CF) == 0) {
1226
1227       /* check for Bad Block predecessor */
1228       for (i = 0; i < arity; ++i) {
1229         ir_node *pred = get_irn_n(node, i);
1230
1231         if (is_Bad(pred)) {
1232           venv->res |= BAD_CF;
1233
1234           if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1235             fprintf(stderr, "irg_vrfy_bads: Block %ld has Bad predecessor\n", get_irn_node_nr(node));
1236           }
1237           if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1238             assert(0 && "Bad CF detected");
1239           }
1240         }
1241       }
1242     }
1243   }
1244   else {
1245     if ((venv->flags & BAD_BLOCK) == 0) {
1246
1247       /* check for Bad Block */
1248       if (is_Bad(get_nodes_block(node))) {
1249         venv->res |= BAD_BLOCK;
1250
1251         if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1252           fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Block\n", get_irn_node_nr(node));
1253         }
1254         if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1255           assert(0 && "Bad CF detected");
1256         }
1257       }
1258     }
1259
1260     if ((venv->flags & TUPLE) == 0) {
1261       if (get_irn_op(node) == op_Tuple) {
1262         venv->res |= TUPLE;
1263
1264         if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1265           fprintf(stderr, "irg_vrfy_bads: node %ld is a Tuple\n", get_irn_node_nr(node));
1266         }
1267         if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1268           assert(0 && "Tuple detected");
1269         }
1270       }
1271     }
1272
1273     for (i = 0; i < arity; ++i) {
1274       ir_node *pred = get_irn_n(node, i);
1275
1276       if (is_Bad(pred)) {
1277         /* check for Phi with Bad inputs */
1278         if (is_Phi(node) && !is_Bad(get_nodes_block(node)) && is_Bad(get_irn_n(get_nodes_block(node), i))) {
1279           if (venv->flags & BAD_CF)
1280             continue;
1281           else {
1282             venv->res |= BAD_CF;
1283
1284             if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1285               fprintf(stderr, "irg_vrfy_bads: Phi %ld has Bad Input\n", get_irn_node_nr(node));
1286             }
1287             if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1288               assert(0 && "Bad CF detected");
1289             }
1290           }
1291         }
1292
1293         /* Bad node input */
1294         if ((venv->flags & BAD_DF) == 0) {
1295           venv->res |= BAD_DF;
1296
1297           if (opt_do_node_verification == NODE_VERIFICATION_REPORT) {
1298             fprintf(stderr, "irg_vrfy_bads: node %ld has Bad Input\n", get_irn_node_nr(node));
1299           }
1300           if (opt_do_node_verification == NODE_VERIFICATION_ON) {
1301             assert(0 && "Bad NON-CF detected");
1302           }
1303         }
1304       }
1305     }
1306   }
1307 }
1308
1309 /*
1310  * verify occurance of bad nodes
1311  */
1312 int irg_vrfy_bads(ir_graph *irg, int flags)
1313 {
1314   vrfy_bad_env_t env;
1315
1316   env.flags = flags;
1317   env.res   = 0;
1318
1319   irg_walk_graph(irg, check_bads, NULL, &env);
1320
1321   return env.res;
1322 }