whitespace: add a newline
[smatch.git] / smatch_flow.c
blobc99361ed6f5f070b448f011cc7e28b0bd3f41d8b
1 /*
2 * sparse/smatch_flow.c
4 * Copyright (C) 2006,2008 Dan Carpenter.
6 * Licensed under the Open Software License version 1.1
8 */
10 #define _GNU_SOURCE 1
11 #include <unistd.h>
12 #include <stdio.h>
13 #include "token.h"
14 #include "smatch.h"
15 #include "smatch_expression_stacks.h"
16 #include "smatch_extra.h"
17 #include "smatch_slist.h"
19 int final_pass;
21 static int __smatch_lineno = 0;
23 static char *base_file;
24 static const char *filename;
25 static char *pathname;
26 static char *full_filename;
27 static char *cur_func;
28 static int line_func_start;
29 static int loop_count;
30 int __expr_stmt_count;
31 static struct expression_list *switch_expr_stack = NULL;
33 struct expression_list *big_expression_stack;
34 struct statement_list *big_statement_stack;
35 int __in_pre_condition = 0;
36 int __bail_on_rest_of_function = 0;
37 char *get_function(void) { return cur_func; }
38 int get_lineno(void) { return __smatch_lineno; }
39 int inside_loop(void) { return !!loop_count; }
40 int in_expression_statement(void) { return !!__expr_stmt_count; }
42 static void split_symlist(struct symbol_list *sym_list);
43 static void split_declaration(struct symbol_list *sym_list);
44 static void split_expr_list(struct expression_list *expr_list);
45 static void add_inline_function(struct symbol *sym);
47 int option_assume_loops = 0;
48 int option_known_conditions = 0;
49 int option_two_passes = 0;
50 struct symbol *cur_func_sym = NULL;
52 const char *get_filename(void)
54 if (option_info)
55 return base_file;
56 if (option_full_path)
57 return full_filename;
58 return filename;
61 static void set_position(struct position pos)
63 int len;
64 static int prev_stream = -1;
66 __smatch_lineno = pos.line;
68 if (pos.stream == prev_stream)
69 return;
71 filename = stream_name(pos.stream);
73 free(full_filename);
74 pathname = getcwd(NULL, 0);
75 if (pathname) {
76 len = strlen(pathname) + 1 + strlen(filename) + 1;
77 full_filename = malloc(len);
78 snprintf(full_filename, len, "%s/%s", pathname, filename);
79 } else {
80 full_filename = alloc_string(filename);
82 free(pathname);
85 static int is_inline_func(struct expression *expr)
87 if (expr->type != EXPR_SYMBOL || !expr->symbol)
88 return 0;
89 if (expr->symbol->ctype.modifiers & MOD_INLINE)
90 return 1;
91 return 0;
94 static int is_noreturn_func(struct expression *expr)
96 if (expr->type != EXPR_SYMBOL || !expr->symbol)
97 return 0;
98 if (expr->symbol->ctype.modifiers & MOD_NORETURN)
99 return 1;
100 return 0;
103 void __split_expr(struct expression *expr)
105 if (!expr)
106 return;
108 // sm_msg(" Debug expr_type %d %s", expr->type, show_special(expr->op));
110 push_expression(&big_expression_stack, expr);
111 set_position(expr->pos);
112 __pass_to_client(expr, EXPR_HOOK);
114 switch (expr->type) {
115 case EXPR_PREOP:
116 if (expr->op == '*')
117 __pass_to_client(expr, DEREF_HOOK);
118 case EXPR_POSTOP:
119 __pass_to_client(expr, OP_HOOK);
120 __split_expr(expr->unop);
121 break;
122 case EXPR_STATEMENT:
123 __expr_stmt_count++;
124 __split_stmt(expr->statement);
125 __expr_stmt_count--;
126 break;
127 case EXPR_LOGICAL:
128 case EXPR_COMPARE:
129 __pass_to_client(expr, LOGIC_HOOK);
130 __handle_logic(expr);
131 break;
132 case EXPR_BINOP:
133 __pass_to_client(expr, BINOP_HOOK);
134 case EXPR_COMMA:
135 __split_expr(expr->left);
136 __split_expr(expr->right);
137 break;
138 case EXPR_ASSIGNMENT: {
139 struct expression *tmp;
141 if (!expr->right)
142 break;
144 __pass_to_client(expr, RAW_ASSIGNMENT_HOOK);
146 /* foo = !bar() */
147 if (__handle_condition_assigns(expr))
148 break;
149 /* foo = (x < 5 ? foo : 5); */
150 if (__handle_select_assigns(expr))
151 break;
152 /* foo = ({frob(); frob(); frob(); 1;}) */
153 if (__handle_expr_statement_assigns(expr))
154 break;
156 __split_expr(expr->right);
157 __pass_to_client(expr, ASSIGNMENT_HOOK);
158 tmp = strip_expr(expr->right);
159 if (tmp->type == EXPR_CALL)
160 __pass_to_client(expr, CALL_ASSIGNMENT_HOOK);
161 if (get_macro_name(tmp->pos))
162 __pass_to_client(expr, MACRO_ASSIGNMENT_HOOK);
163 __split_expr(expr->left);
164 break;
166 case EXPR_DEREF:
167 __pass_to_client(expr, DEREF_HOOK);
168 __split_expr(expr->deref);
169 break;
170 case EXPR_SLICE:
171 __split_expr(expr->base);
172 break;
173 case EXPR_CAST:
174 case EXPR_FORCE_CAST:
175 __pass_to_client(expr, CAST_HOOK);
176 __split_expr(expr->cast_expression);
177 break;
178 case EXPR_SIZEOF:
179 /* there isn't anything to pass a client from inside a sizeof() */
180 break;
181 case EXPR_OFFSETOF:
182 case EXPR_ALIGNOF:
183 evaluate_expression(expr);
184 break;
185 case EXPR_CONDITIONAL:
186 case EXPR_SELECT:
187 if (known_condition_true(expr->conditional)) {
188 __split_expr(expr->cond_true);
189 break;
191 if (known_condition_false(expr->conditional)) {
192 __split_expr(expr->cond_false);
193 break;
195 __pass_to_client(expr, SELECT_HOOK);
196 __split_whole_condition(expr->conditional);
197 __split_expr(expr->cond_true);
198 __push_true_states();
199 __use_false_states();
200 __split_expr(expr->cond_false);
201 __merge_true_states();
202 break;
203 case EXPR_CALL:
204 if (sym_name_is("__builtin_constant_p", expr->fn))
205 break;
206 split_expr_list(expr->args);
207 __split_expr(expr->fn);
208 if (is_inline_func(expr->fn))
209 add_inline_function(expr->fn->symbol);
210 __pass_to_client(expr, FUNCTION_CALL_HOOK);
211 if (is_noreturn_func(expr->fn))
212 nullify_path();
213 break;
214 case EXPR_INITIALIZER:
215 split_expr_list(expr->expr_list);
216 break;
217 case EXPR_IDENTIFIER:
218 __split_expr(expr->ident_expression);
219 break;
220 case EXPR_INDEX:
221 __split_expr(expr->idx_expression);
222 break;
223 case EXPR_POS:
224 __split_expr(expr->init_expr);
225 break;
226 case EXPR_SYMBOL:
227 __pass_to_client(expr, SYM_HOOK);
228 break;
229 case EXPR_STRING:
230 __pass_to_client(expr, STRING_HOOK);
231 break;
232 default:
233 break;
235 pop_expression(&big_expression_stack);
238 static int is_forever_loop(struct statement *stmt)
240 struct expression *expr;
242 expr = strip_expr(stmt->iterator_pre_condition);
243 if (!expr)
244 expr = stmt->iterator_post_condition;
245 if (!expr) {
246 /* this is a for(;;) loop... */
247 return 1;
250 if (expr->type == EXPR_VALUE && expr->value == 1)
251 return 1;
253 return 0;
256 static int loop_num;
257 static char *get_loop_name(int num)
259 char buf[256];
261 snprintf(buf, 255, "-loop%d", num);
262 buf[255] = '\0';
263 return alloc_sname(buf);
267 * Pre Loops are while and for loops.
269 static void handle_pre_loop(struct statement *stmt)
271 int once_through; /* we go through the loop at least once */
272 struct sm_state *extra_sm = NULL;
273 int unchanged = 0;
274 char *loop_name;
275 struct state_list *slist = NULL;
276 struct sm_state *sm = NULL;
278 loop_name = get_loop_name(loop_num);
279 loop_num++;
281 __split_stmt(stmt->iterator_pre_statement);
283 once_through = implied_condition_true(stmt->iterator_pre_condition);
285 loop_count++;
286 __push_continues();
287 __push_breaks();
289 __merge_gotos(loop_name);
291 extra_sm = __extra_handle_canonical_loops(stmt, &slist);
292 __in_pre_condition++;
293 __pass_to_client(stmt, PRELOOP_HOOK);
294 __split_whole_condition(stmt->iterator_pre_condition);
295 __in_pre_condition--;
296 FOR_EACH_PTR(slist, sm) {
297 set_state(sm->owner, sm->name, sm->sym, sm->state);
298 } END_FOR_EACH_PTR(sm);
299 free_slist(&slist);
300 if (extra_sm)
301 extra_sm = get_sm_state(extra_sm->owner, extra_sm->name, extra_sm->sym);
303 if (option_assume_loops)
304 once_through = 1;
306 __split_stmt(stmt->iterator_statement);
307 __warn_on_silly_pre_loops();
308 if (is_forever_loop(stmt)) {
309 struct state_list *slist;
311 __save_gotos(loop_name);
313 __push_fake_cur_slist();
314 __split_stmt(stmt->iterator_post_statement);
315 slist = __pop_fake_cur_slist();
317 __discard_continues();
318 __discard_false_states();
319 __use_breaks();
321 if (!__path_is_null())
322 __merge_slist_into_cur(slist);
323 free_slist(&slist);
324 } else {
325 __merge_continues();
326 unchanged = __iterator_unchanged(extra_sm);
327 __split_stmt(stmt->iterator_post_statement);
328 __save_gotos(loop_name);
329 __split_whole_condition(stmt->iterator_pre_condition);
330 nullify_path();
331 __merge_false_states();
332 if (once_through)
333 __discard_false_states();
334 else
335 __merge_false_states();
337 if (extra_sm && unchanged)
338 __extra_pre_loop_hook_after(extra_sm,
339 stmt->iterator_post_statement,
340 stmt->iterator_pre_condition);
341 __merge_breaks();
343 loop_count--;
347 * Post loops are do {} while();
349 static void handle_post_loop(struct statement *stmt)
351 char *loop_name;
353 loop_name = get_loop_name(loop_num);
354 loop_num++;
355 loop_count++;
357 __push_continues();
358 __push_breaks();
359 __merge_gotos(loop_name);
360 __split_stmt(stmt->iterator_statement);
361 __merge_continues();
362 if (!is_zero(stmt->iterator_post_condition))
363 __save_gotos(loop_name);
365 if (is_forever_loop(stmt)) {
366 __use_breaks();
367 } else {
368 __split_whole_condition(stmt->iterator_post_condition);
369 __use_false_states();
370 __merge_breaks();
372 loop_count--;
375 static int empty_statement(struct statement *stmt)
377 if (!stmt)
378 return 0;
379 if (stmt->type == STMT_EXPRESSION && !stmt->expression)
380 return 1;
381 return 0;
384 static int last_stmt_on_same_line()
386 struct statement *stmt;
387 int i = 0;
389 FOR_EACH_PTR_REVERSE(big_statement_stack, stmt) {
390 if (!i++)
391 continue;
392 if (stmt->pos.line == get_lineno())
393 return 1;
394 return 0;
395 } END_FOR_EACH_PTR_REVERSE(stmt);
396 return 0;
399 static struct statement *last_stmt;
400 static int is_last_stmt(struct statement *stmt)
402 if (stmt == last_stmt)
403 return 1;
404 return 0;
407 static void print_unreached_initializers(struct symbol_list *sym_list)
409 struct symbol *sym;
411 FOR_EACH_PTR(sym_list, sym) {
412 if (sym->initializer)
413 sm_msg("info: '%s' is not actually initialized (unreached code).",
414 (sym->ident ? sym->ident->name : "this variable"));
415 } END_FOR_EACH_PTR(sym);
418 static void print_unreached(struct statement *stmt)
420 static int print = 1;
422 if (!__path_is_null()) {
423 print = 1;
424 return;
426 if (!print)
427 return;
429 switch (stmt->type) {
430 case STMT_COMPOUND: /* after a switch before a case stmt */
431 case STMT_RANGE:
432 case STMT_CASE:
433 case STMT_LABEL:
434 return;
435 case STMT_DECLARATION: /* switch (x) { int a; case foo: ... */
436 print_unreached_initializers(stmt->declaration);
437 return;
438 case STMT_RETURN: /* gcc complains if you don't have a return statement */
439 if (is_last_stmt(stmt))
440 return;
441 break;
442 case STMT_GOTO:
443 if (!option_spammy)
444 return;
445 break;
446 default:
447 break;
449 if (!option_spammy && empty_statement(stmt))
450 return;
451 sm_msg("info: ignoring unreachable code.");
452 print = 0;
455 static void split_asm_constraints(struct expression_list *expr_list)
457 struct expression *expr;
458 int state = 0;
460 FOR_EACH_PTR(expr_list, expr) {
461 switch (state) {
462 case 0: /* identifier */
463 case 1: /* constraint */
464 state++;
465 continue;
466 case 2: /* expression */
467 state = 0;
468 __split_expr(expr);
469 continue;
471 } END_FOR_EACH_PTR(expr);
474 static int is_case_val(struct statement *stmt, long long val)
476 long long case_val;
478 if (stmt->type != STMT_CASE)
479 return 0;
480 if (!stmt->case_expression) {
481 __set_default();
482 return 1;
484 if (!get_value(stmt->case_expression, &case_val))
485 return 0;
486 if (case_val == val)
487 return 1;
488 return 0;
491 static void split_known_switch(struct statement *stmt, long long val)
493 struct statement *tmp;
495 __split_expr(stmt->switch_expression);
497 push_expression(&switch_expr_stack, stmt->switch_expression);
498 __save_switch_states(top_expression(switch_expr_stack));
499 nullify_path();
500 __push_default();
501 __push_breaks();
503 stmt = stmt->switch_statement;
505 if (!last_stmt)
506 last_stmt = last_ptr_list((struct ptr_list *)stmt->stmts);
508 __push_scope_hooks();
509 FOR_EACH_PTR(stmt->stmts, tmp) {
510 __smatch_lineno = tmp->pos.line;
511 if (is_case_val(tmp, val)) {
512 __merge_switches(top_expression(switch_expr_stack),
513 stmt->case_expression);
514 __pass_case_to_client(top_expression(switch_expr_stack),
515 stmt->case_expression);
517 if (__path_is_null())
518 continue;
519 __split_stmt(tmp);
520 if (__path_is_null()) {
521 __set_default();
522 goto out;
524 } END_FOR_EACH_PTR(tmp);
525 out:
526 __call_scope_hooks();
527 if (!__pop_default())
528 __merge_switches(top_expression(switch_expr_stack),
529 NULL);
530 __discard_switches();
531 __merge_breaks();
532 pop_expression(&switch_expr_stack);
535 void __split_stmt(struct statement *stmt)
537 long long val;
539 if (!stmt)
540 return;
542 if (out_of_memory() || __bail_on_rest_of_function) {
543 static char *printed = NULL;
545 if (printed != cur_func)
546 sm_msg("Function too hairy. Giving up.");
547 final_pass = 0; /* turn off sm_msg() from here */
548 printed = cur_func;
549 return;
552 add_ptr_list(&big_statement_stack, stmt);
553 free_expression_stack(&big_expression_stack);
554 set_position(stmt->pos);
555 print_unreached(stmt);
556 __pass_to_client(stmt, STMT_HOOK);
558 switch (stmt->type) {
559 case STMT_DECLARATION:
560 split_declaration(stmt->declaration);
561 return;
562 case STMT_RETURN:
563 __split_expr(stmt->ret_value);
564 __pass_to_client(stmt->ret_value, RETURN_HOOK);
565 nullify_path();
566 return;
567 case STMT_EXPRESSION:
568 __split_expr(stmt->expression);
569 return;
570 case STMT_COMPOUND: {
571 struct statement *tmp;
573 if (!last_stmt)
574 last_stmt = last_ptr_list((struct ptr_list *)stmt->stmts);
575 __push_scope_hooks();
576 FOR_EACH_PTR(stmt->stmts, tmp) {
577 __split_stmt(tmp);
578 } END_FOR_EACH_PTR(tmp);
579 __call_scope_hooks();
580 return;
582 case STMT_IF:
583 if (known_condition_true(stmt->if_conditional)) {
584 __split_stmt(stmt->if_true);
585 return;
587 if (known_condition_false(stmt->if_conditional)) {
588 __split_stmt(stmt->if_false);
589 return;
591 if (option_known_conditions &&
592 implied_condition_true(stmt->if_conditional)) {
593 sm_info("this condition is true.");
594 __split_stmt(stmt->if_true);
595 return;
597 if (option_known_conditions &&
598 implied_condition_false(stmt->if_conditional)) {
599 sm_info("this condition is false.");
600 __split_stmt(stmt->if_false);
601 return;
603 __split_whole_condition(stmt->if_conditional);
604 __split_stmt(stmt->if_true);
605 if (empty_statement(stmt->if_true) &&
606 last_stmt_on_same_line() &&
607 !get_macro_name(stmt->if_true->pos))
608 sm_msg("warn: if();");
609 __push_true_states();
610 __use_false_states();
611 __split_stmt(stmt->if_false);
612 __merge_true_states();
613 return;
614 case STMT_ITERATOR:
615 if (stmt->iterator_pre_condition)
616 handle_pre_loop(stmt);
617 else if (stmt->iterator_post_condition)
618 handle_post_loop(stmt);
619 else {
620 // these are for(;;) type loops.
621 handle_pre_loop(stmt);
623 return;
624 case STMT_SWITCH:
625 if (get_value(stmt->switch_expression, &val)) {
626 split_known_switch(stmt, val);
627 return;
629 __split_expr(stmt->switch_expression);
630 push_expression(&switch_expr_stack, stmt->switch_expression);
631 __save_switch_states(top_expression(switch_expr_stack));
632 nullify_path();
633 __push_default();
634 __push_breaks();
635 __split_stmt(stmt->switch_statement);
636 if (!__pop_default())
637 __merge_switches(top_expression(switch_expr_stack),
638 NULL);
639 __discard_switches();
640 __merge_breaks();
641 pop_expression(&switch_expr_stack);
642 return;
643 case STMT_CASE:
644 __merge_switches(top_expression(switch_expr_stack),
645 stmt->case_expression);
646 __pass_case_to_client(top_expression(switch_expr_stack),
647 stmt->case_expression);
648 if (!stmt->case_expression)
649 __set_default();
650 __split_expr(stmt->case_expression);
651 __split_expr(stmt->case_to);
652 __split_stmt(stmt->case_statement);
653 return;
654 case STMT_LABEL:
655 if (stmt->label_identifier &&
656 stmt->label_identifier->type == SYM_LABEL &&
657 stmt->label_identifier->ident) {
658 loop_count = 1000000;
659 __merge_gotos(stmt->label_identifier->ident->name);
661 __split_stmt(stmt->label_statement);
662 return;
663 case STMT_GOTO:
664 __split_expr(stmt->goto_expression);
665 if (stmt->goto_label && stmt->goto_label->type == SYM_NODE) {
666 if (!strcmp(stmt->goto_label->ident->name, "break")) {
667 __process_breaks();
668 } else if (!strcmp(stmt->goto_label->ident->name,
669 "continue")) {
670 __process_continues();
672 } else if (stmt->goto_label &&
673 stmt->goto_label->type == SYM_LABEL &&
674 stmt->goto_label->ident) {
675 __save_gotos(stmt->goto_label->ident->name);
677 nullify_path();
678 return;
679 case STMT_NONE:
680 return;
681 case STMT_ASM:
682 __pass_to_client(stmt, ASM_HOOK);
683 __split_expr(stmt->asm_string);
684 split_asm_constraints(stmt->asm_outputs);
685 split_asm_constraints(stmt->asm_inputs);
686 split_asm_constraints(stmt->asm_clobbers);
687 return;
688 case STMT_CONTEXT:
689 return;
690 case STMT_RANGE:
691 __split_expr(stmt->range_expression);
692 __split_expr(stmt->range_low);
693 __split_expr(stmt->range_high);
694 return;
698 static void split_expr_list(struct expression_list *expr_list)
700 struct expression *expr;
702 FOR_EACH_PTR(expr_list, expr) {
703 __split_expr(expr);
704 } END_FOR_EACH_PTR(expr);
707 static void split_sym(struct symbol *sym)
709 if (!sym)
710 return;
711 if (!(sym->namespace & NS_SYMBOL))
712 return;
714 __split_stmt(sym->stmt);
715 __split_expr(sym->array_size);
716 split_symlist(sym->arguments);
717 split_symlist(sym->symbol_list);
718 __split_stmt(sym->inline_stmt);
719 split_symlist(sym->inline_symbol_list);
722 static void split_symlist(struct symbol_list *sym_list)
724 struct symbol *sym;
726 FOR_EACH_PTR(sym_list, sym) {
727 split_sym(sym);
728 } END_FOR_EACH_PTR(sym);
731 static void fake_member_assigns(struct symbol *sym)
733 struct expression *symbol, *deref, *assign, *tmp;
735 symbol = symbol_expression(sym);
736 FOR_EACH_PTR(sym->initializer->expr_list, tmp) {
737 if (tmp->type != EXPR_IDENTIFIER) /* how to handle arrays?? */
738 continue;
739 deref = deref_expression(symbol, '.', tmp->expr_ident);
740 assign = assign_expression(deref, tmp->ident_expression);
741 __split_expr(assign);
742 } END_FOR_EACH_PTR(tmp);
745 static void fake_assign_expr(struct symbol *sym)
747 struct expression *assign, *symbol;
749 symbol = symbol_expression(sym);
750 assign = assign_expression(symbol, sym->initializer);
751 __split_expr(assign);
754 static void do_initializer_stuff(struct symbol *sym)
756 if (!sym->initializer)
757 return;
758 if (sym->initializer->type == EXPR_INITIALIZER)
759 fake_member_assigns(sym);
760 else
761 fake_assign_expr(sym);
764 static void split_declaration(struct symbol_list *sym_list)
766 struct symbol *sym;
768 FOR_EACH_PTR(sym_list, sym) {
769 __pass_to_client(sym, DECLARATION_HOOK);
770 do_initializer_stuff(sym);
771 split_sym(sym);
772 } END_FOR_EACH_PTR(sym);
775 static void split_function(struct symbol *sym)
777 struct symbol *base_type = get_base_type(sym);
779 cur_func_sym = sym;
780 if (base_type->stmt)
781 line_func_start = base_type->stmt->pos.line;
782 if (sym->ident)
783 cur_func = sym->ident->name;
784 __smatch_lineno = sym->pos.line;
785 last_stmt = NULL;
786 loop_count = 0;
787 sm_debug("new function: %s\n", cur_func);
788 __slist_id = 0;
789 if (option_two_passes) {
790 __unnullify_path();
791 loop_num = 0;
792 final_pass = 0;
793 __pass_to_client(sym, FUNC_DEF_HOOK);
794 __split_stmt(base_type->stmt);
795 __split_stmt(base_type->inline_stmt);
796 nullify_path();
798 __unnullify_path();
799 loop_num = 0;
800 final_pass = 1;
801 __pass_to_client(sym, FUNC_DEF_HOOK);
802 __split_stmt(base_type->stmt);
803 __split_stmt(base_type->inline_stmt);
804 __pass_to_client(sym, END_FUNC_HOOK);
805 cur_func = NULL;
806 line_func_start = 0;
807 clear_all_states();
808 free_data_info_allocs();
809 free_expression_stack(&switch_expr_stack);
810 __free_ptr_list((struct ptr_list **)&big_statement_stack);
811 __bail_on_rest_of_function = 0;
814 static struct symbol_list *inlines_called;
815 static void add_inline_function(struct symbol *sym)
817 static struct symbol_list *already_added;
818 struct symbol *tmp;
820 FOR_EACH_PTR(already_added, tmp) {
821 if (tmp == sym)
822 return;
823 } END_FOR_EACH_PTR(tmp);
825 add_ptr_list(&already_added, sym);
826 add_ptr_list(&inlines_called, sym);
829 static void process_inlines()
831 struct symbol *tmp;
833 FOR_EACH_PTR(inlines_called, tmp) {
834 split_function(tmp);
835 } END_FOR_EACH_PTR(tmp);
836 free_ptr_list(&inlines_called);
839 static void split_functions(struct symbol_list *sym_list)
841 struct symbol *sym;
843 FOR_EACH_PTR(sym_list, sym) {
844 set_position(sym->pos);
845 if (sym->type == SYM_NODE && get_base_type(sym)->type == SYM_FN) {
846 split_function(sym);
847 process_inlines();
848 } else {
849 __pass_to_client(sym, BASE_HOOK);
851 } END_FOR_EACH_PTR(sym);
852 __pass_to_client_no_data(END_FILE_HOOK);
855 void smatch(int argc, char **argv)
858 struct string_list *filelist = NULL;
859 struct symbol_list *sym_list;
861 if (argc < 2) {
862 printf("Usage: smatch [--debug] <filename.c>\n");
863 exit(1);
865 sparse_initialize(argc, argv, &filelist);
866 FOR_EACH_PTR_NOTAG(filelist, base_file) {
867 if (option_file_output) {
868 char buf[256];
870 snprintf(buf, sizeof(buf), "%s.smatch", base_file);
871 sm_outfd = fopen(buf, "w");
872 if (!sm_outfd) {
873 printf("Error: Cannot open %s\n", base_file);
874 exit(1);
877 sym_list = sparse_keep_tokens(base_file);
878 split_functions(sym_list);
879 } END_FOR_EACH_PTR_NOTAG(base_file);