extra: handle returned struct members
[smatch.git] / smatch_flow.c
blobb3697ebd8474a65a11439902d640a34834c5d690
1 /*
2 * Copyright (C) 2006,2008 Dan Carpenter.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see http://www.gnu.org/copyleft/gpl.txt
18 #define _GNU_SOURCE 1
19 #include <unistd.h>
20 #include <stdio.h>
21 #include "token.h"
22 #include "scope.h"
23 #include "smatch.h"
24 #include "smatch_expression_stacks.h"
25 #include "smatch_extra.h"
26 #include "smatch_slist.h"
28 int __in_fake_assign;
29 int final_pass;
30 int __inline_call;
31 struct expression *__inline_fn;
33 static int __smatch_lineno = 0;
35 static char *base_file;
36 static const char *filename;
37 static char *pathname;
38 static char *full_filename;
39 static char *cur_func;
40 static unsigned int loop_count;
41 static int last_goto_statement_handled;
42 int __expr_stmt_count;
43 int __in_function_def;
44 static struct expression_list *switch_expr_stack = NULL;
45 static struct expression_list *post_op_stack = NULL;
47 struct expression_list *big_expression_stack;
48 struct statement_list *big_statement_stack;
49 struct statement *__prev_stmt;
50 struct statement *__cur_stmt;
51 struct statement *__next_stmt;
52 int __in_pre_condition = 0;
53 int __bail_on_rest_of_function = 0;
54 static struct timeval fn_start_time;
55 char *get_function(void) { return cur_func; }
56 int get_lineno(void) { return __smatch_lineno; }
57 int inside_loop(void) { return !!loop_count; }
58 int definitely_inside_loop(void) { return !!(loop_count & ~0x80000000); }
59 struct expression *get_switch_expr(void) { return top_expression(switch_expr_stack); }
60 int in_expression_statement(void) { return !!__expr_stmt_count; }
62 static void split_symlist(struct symbol_list *sym_list);
63 static void split_declaration(struct symbol_list *sym_list);
64 static void split_expr_list(struct expression_list *expr_list, struct expression *parent);
65 static void add_inline_function(struct symbol *sym);
66 static void parse_inline(struct expression *expr);
68 int option_assume_loops = 0;
69 int option_two_passes = 0;
70 struct symbol *cur_func_sym = NULL;
71 struct stree *global_states;
73 long long valid_ptr_min = 4096;
74 long long valid_ptr_max = 2117777777;
75 sval_t valid_ptr_min_sval = {
76 .type = &ptr_ctype,
77 {.value = 4096},
79 sval_t valid_ptr_max_sval = {
80 .type = &ptr_ctype,
81 {.value = LONG_MAX - 100000},
84 static void set_valid_ptr_max(void)
86 if (type_bits(&ptr_ctype) == 32)
87 valid_ptr_max = 2117777777;
88 else if (type_bits(&ptr_ctype) == 64)
89 valid_ptr_max = 2117777777777777777LL;
91 valid_ptr_max_sval.value = valid_ptr_max;
94 int outside_of_function(void)
96 return cur_func_sym == NULL;
99 const char *get_filename(void)
101 if (option_info)
102 return base_file;
103 if (option_full_path)
104 return full_filename;
105 return filename;
108 const char *get_base_file(void)
110 return base_file;
113 static void set_position(struct position pos)
115 int len;
116 static int prev_stream = -1;
118 if (pos.stream == 0 && pos.line == 0)
119 return;
121 __smatch_lineno = pos.line;
123 if (pos.stream == prev_stream)
124 return;
126 filename = stream_name(pos.stream);
128 free(full_filename);
129 pathname = getcwd(NULL, 0);
130 if (pathname) {
131 len = strlen(pathname) + 1 + strlen(filename) + 1;
132 full_filename = malloc(len);
133 snprintf(full_filename, len, "%s/%s", pathname, filename);
134 } else {
135 full_filename = alloc_string(filename);
137 free(pathname);
140 static void set_parent(struct expression *expr, struct expression *parent)
142 if (!expr)
143 return;
144 expr->parent = parent;
147 static void set_parent_stmt(struct statement *stmt, struct statement *parent)
149 if (!stmt)
150 return;
151 stmt->parent = parent;
154 int is_assigned_call(struct expression *expr)
156 struct expression *tmp;
158 FOR_EACH_PTR_REVERSE(big_expression_stack, tmp) {
159 if (tmp->type == EXPR_ASSIGNMENT && tmp->op == '=' &&
160 strip_expr(tmp->right) == expr)
161 return 1;
162 if (tmp->pos.line < expr->pos.line)
163 return 0;
164 } END_FOR_EACH_PTR_REVERSE(tmp);
165 return 0;
168 static int is_inline_func(struct expression *expr)
170 if (expr->type != EXPR_SYMBOL || !expr->symbol)
171 return 0;
172 if (expr->symbol->ctype.modifiers & MOD_INLINE)
173 return 1;
174 return 0;
177 static int is_noreturn_func(struct expression *expr)
179 if (expr->type != EXPR_SYMBOL || !expr->symbol)
180 return 0;
181 if (expr->symbol->ctype.modifiers & MOD_NORETURN)
182 return 1;
183 return 0;
186 int inlinable(struct expression *expr)
188 struct symbol *sym;
189 struct statement *last_stmt = NULL;
191 if (__inline_fn) /* don't nest */
192 return 0;
194 if (expr->type != EXPR_SYMBOL || !expr->symbol)
195 return 0;
196 if (is_no_inline_function(expr->symbol->ident->name))
197 return 0;
198 sym = get_base_type(expr->symbol);
199 if (sym->stmt && sym->stmt->type == STMT_COMPOUND) {
200 if (ptr_list_size((struct ptr_list *)sym->stmt->stmts) > 10)
201 return 0;
202 if (sym->stmt->type != STMT_COMPOUND)
203 return 0;
204 last_stmt = last_ptr_list((struct ptr_list *)sym->stmt->stmts);
206 if (sym->inline_stmt && sym->inline_stmt->type == STMT_COMPOUND) {
207 if (ptr_list_size((struct ptr_list *)sym->inline_stmt->stmts) > 10)
208 return 0;
209 if (sym->inline_stmt->type != STMT_COMPOUND)
210 return 0;
211 last_stmt = last_ptr_list((struct ptr_list *)sym->inline_stmt->stmts);
214 if (!last_stmt)
215 return 0;
217 /* the magic numbers in this function are pulled out of my bum. */
218 if (last_stmt->pos.line > sym->pos.line + 20)
219 return 0;
221 return 1;
224 void __process_post_op_stack(void)
226 struct expression *expr;
228 FOR_EACH_PTR(post_op_stack, expr) {
229 __pass_to_client(expr, OP_HOOK);
230 } END_FOR_EACH_PTR(expr);
232 __free_ptr_list((struct ptr_list **)&post_op_stack);
235 static int handle_comma_assigns(struct expression *expr)
237 struct expression *right;
238 struct expression *assign;
240 right = strip_expr(expr->right);
241 if (right->type != EXPR_COMMA)
242 return 0;
244 __split_expr(right->left);
245 __process_post_op_stack();
247 assign = assign_expression(expr->left, right->right);
248 __split_expr(assign);
250 return 1;
253 static int prev_expression_is_getting_address(struct expression *expr)
255 struct expression *parent;
257 do {
258 parent = expr->parent;
260 if (!parent)
261 return 0;
262 if (parent->type == EXPR_PREOP && parent->op == '&')
263 return 1;
264 if (parent->type == EXPR_PREOP && parent->op == '(')
265 goto next;
266 if (parent->type == EXPR_DEREF && parent->op == '.')
267 goto next;
269 return 0;
270 next:
271 expr = parent;
272 } while (1);
275 void __split_expr(struct expression *expr)
277 if (!expr)
278 return;
280 // sm_msg(" Debug expr_type %d %s", expr->type, show_special(expr->op));
282 if (__in_fake_assign && expr->type != EXPR_ASSIGNMENT)
283 return;
284 if (__in_fake_assign >= 4) /* don't allow too much nesting */
285 return;
287 push_expression(&big_expression_stack, expr);
288 set_position(expr->pos);
289 __pass_to_client(expr, EXPR_HOOK);
291 switch (expr->type) {
292 case EXPR_PREOP:
293 set_parent(expr->unop, expr);
295 if (expr->op == '*' &&
296 !prev_expression_is_getting_address(expr))
297 __pass_to_client(expr, DEREF_HOOK);
298 __split_expr(expr->unop);
299 __pass_to_client(expr, OP_HOOK);
300 break;
301 case EXPR_POSTOP:
302 set_parent(expr->unop, expr);
304 __split_expr(expr->unop);
305 push_expression(&post_op_stack, expr);
306 break;
307 case EXPR_STATEMENT:
308 __expr_stmt_count++;
309 __split_stmt(expr->statement);
310 __expr_stmt_count--;
311 break;
312 case EXPR_LOGICAL:
313 case EXPR_COMPARE:
314 set_parent(expr->left, expr);
315 set_parent(expr->right, expr);
317 __pass_to_client(expr, LOGIC_HOOK);
318 __handle_logic(expr);
319 break;
320 case EXPR_BINOP:
321 set_parent(expr->left, expr);
322 set_parent(expr->right, expr);
324 __pass_to_client(expr, BINOP_HOOK);
325 case EXPR_COMMA:
326 set_parent(expr->left, expr);
327 set_parent(expr->right, expr);
329 __split_expr(expr->left);
330 __process_post_op_stack();
331 __split_expr(expr->right);
332 break;
333 case EXPR_ASSIGNMENT: {
334 struct expression *tmp;
336 set_parent(expr->left, expr);
337 set_parent(expr->right, expr);
339 if (!expr->right)
340 break;
342 __pass_to_client(expr, RAW_ASSIGNMENT_HOOK);
344 /* foo = !bar() */
345 if (__handle_condition_assigns(expr))
346 break;
347 /* foo = (x < 5 ? foo : 5); */
348 if (__handle_select_assigns(expr))
349 break;
350 /* foo = ({frob(); frob(); frob(); 1;}) */
351 if (__handle_expr_statement_assigns(expr))
352 break;
353 /* foo = (3, 4); */
354 if (handle_comma_assigns(expr))
355 break;
357 __split_expr(expr->right);
358 if (outside_of_function())
359 __pass_to_client(expr, GLOBAL_ASSIGNMENT_HOOK);
360 else
361 __pass_to_client(expr, ASSIGNMENT_HOOK);
363 __fake_struct_member_assignments(expr);
365 tmp = strip_expr(expr->right);
366 if (expr->op == '=' && tmp->type == EXPR_CALL) {
367 __pass_to_client(expr, CALL_ASSIGNMENT_HOOK);
368 if (!is_fake_call(tmp))
369 __pass_to_client(tmp, FUNCTION_CALL_HOOK_AFTER);
371 if (get_macro_name(tmp->pos) &&
372 get_macro_name(expr->pos) != get_macro_name(tmp->pos))
373 __pass_to_client(expr, MACRO_ASSIGNMENT_HOOK);
374 __split_expr(expr->left);
375 break;
377 case EXPR_DEREF:
378 set_parent(expr->deref, expr);
380 __pass_to_client(expr, DEREF_HOOK);
381 __split_expr(expr->deref);
382 break;
383 case EXPR_SLICE:
384 set_parent(expr->base, expr);
386 __split_expr(expr->base);
387 break;
388 case EXPR_CAST:
389 case EXPR_FORCE_CAST:
390 set_parent(expr->cast_expression, expr);
392 __pass_to_client(expr, CAST_HOOK);
393 __split_expr(expr->cast_expression);
394 break;
395 case EXPR_SIZEOF:
396 if (expr->cast_expression)
397 __pass_to_client(strip_parens(expr->cast_expression),
398 SIZEOF_HOOK);
399 break;
400 case EXPR_OFFSETOF:
401 case EXPR_ALIGNOF:
402 evaluate_expression(expr);
403 break;
404 case EXPR_CONDITIONAL:
405 case EXPR_SELECT:
406 set_parent(expr->conditional, expr);
407 set_parent(expr->cond_true, expr);
408 set_parent(expr->cond_false, expr);
410 if (known_condition_true(expr->conditional)) {
411 __split_expr(expr->cond_true);
412 break;
414 if (known_condition_false(expr->conditional)) {
415 __split_expr(expr->cond_false);
416 break;
418 __pass_to_client(expr, SELECT_HOOK);
419 __split_whole_condition(expr->conditional);
420 __split_expr(expr->cond_true);
421 __push_true_states();
422 __use_false_states();
423 __split_expr(expr->cond_false);
424 __merge_true_states();
425 break;
426 case EXPR_CALL:
427 set_parent(expr->fn, expr);
429 if (sym_name_is("__builtin_constant_p", expr->fn))
430 break;
431 split_expr_list(expr->args, expr);
432 __split_expr(expr->fn);
433 if (is_inline_func(expr->fn))
434 add_inline_function(expr->fn->symbol);
435 if (inlinable(expr->fn))
436 __inline_call = 1;
437 __process_post_op_stack();
438 __pass_to_client(expr, FUNCTION_CALL_HOOK);
439 __inline_call = 0;
440 if (inlinable(expr->fn)) {
441 parse_inline(expr);
443 __pass_to_client(expr, CALL_HOOK_AFTER_INLINE);
444 if (!is_assigned_call(expr))
445 __pass_to_client(expr, FUNCTION_CALL_HOOK_AFTER);
446 if (is_noreturn_func(expr->fn))
447 nullify_path();
448 break;
449 case EXPR_INITIALIZER:
450 split_expr_list(expr->expr_list, expr);
451 break;
452 case EXPR_IDENTIFIER:
453 set_parent(expr->ident_expression, expr);
454 __split_expr(expr->ident_expression);
455 break;
456 case EXPR_INDEX:
457 set_parent(expr->idx_expression, expr);
458 __split_expr(expr->idx_expression);
459 break;
460 case EXPR_POS:
461 set_parent(expr->init_expr, expr);
462 __split_expr(expr->init_expr);
463 break;
464 case EXPR_SYMBOL:
465 __pass_to_client(expr, SYM_HOOK);
466 break;
467 case EXPR_STRING:
468 __pass_to_client(expr, STRING_HOOK);
469 break;
470 default:
471 break;
473 pop_expression(&big_expression_stack);
476 static int is_forever_loop(struct statement *stmt)
478 struct expression *expr;
480 expr = strip_expr(stmt->iterator_pre_condition);
481 if (!expr)
482 expr = stmt->iterator_post_condition;
483 if (!expr) {
484 /* this is a for(;;) loop... */
485 return 1;
488 if (expr->type == EXPR_VALUE && expr->value == 1)
489 return 1;
491 return 0;
494 static int loop_num;
495 static char *get_loop_name(int num)
497 char buf[256];
499 snprintf(buf, 255, "-loop%d", num);
500 buf[255] = '\0';
501 return alloc_sname(buf);
505 * Pre Loops are while and for loops.
507 static void handle_pre_loop(struct statement *stmt)
509 int once_through; /* we go through the loop at least once */
510 struct sm_state *extra_sm = NULL;
511 int unchanged = 0;
512 char *loop_name;
513 struct stree *stree = NULL;
514 struct sm_state *sm = NULL;
516 loop_name = get_loop_name(loop_num);
517 loop_num++;
519 __split_stmt(stmt->iterator_pre_statement);
520 __prev_stmt = stmt->iterator_pre_statement;
522 once_through = implied_condition_true(stmt->iterator_pre_condition);
524 loop_count++;
525 __push_continues();
526 __push_breaks();
528 __merge_gotos(loop_name);
530 extra_sm = __extra_handle_canonical_loops(stmt, &stree);
531 __in_pre_condition++;
532 __pass_to_client(stmt, PRELOOP_HOOK);
533 __split_whole_condition(stmt->iterator_pre_condition);
534 __in_pre_condition--;
535 FOR_EACH_SM(stree, sm) {
536 set_state(sm->owner, sm->name, sm->sym, sm->state);
537 } END_FOR_EACH_SM(sm);
538 free_stree(&stree);
539 if (extra_sm)
540 extra_sm = get_sm_state(extra_sm->owner, extra_sm->name, extra_sm->sym);
542 if (option_assume_loops)
543 once_through = 1;
545 __split_stmt(stmt->iterator_statement);
546 if (is_forever_loop(stmt)) {
547 __merge_continues();
548 __save_gotos(loop_name);
550 __push_fake_cur_stree();
551 __split_stmt(stmt->iterator_post_statement);
552 stree = __pop_fake_cur_stree();
554 __discard_false_states();
555 __use_breaks();
557 if (!__path_is_null())
558 __merge_stree_into_cur(stree);
559 free_stree(&stree);
560 } else {
561 __merge_continues();
562 unchanged = __iterator_unchanged(extra_sm);
563 __split_stmt(stmt->iterator_post_statement);
564 __prev_stmt = stmt->iterator_post_statement;
565 __cur_stmt = stmt;
567 __save_gotos(loop_name);
568 __in_pre_condition++;
569 __split_whole_condition(stmt->iterator_pre_condition);
570 __in_pre_condition--;
571 nullify_path();
572 __merge_false_states();
573 if (once_through)
574 __discard_false_states();
575 else
576 __merge_false_states();
578 if (extra_sm && unchanged)
579 __extra_pre_loop_hook_after(extra_sm,
580 stmt->iterator_post_statement,
581 stmt->iterator_pre_condition);
582 __merge_breaks();
584 loop_count--;
588 * Post loops are do {} while();
590 static void handle_post_loop(struct statement *stmt)
592 char *loop_name;
594 loop_name = get_loop_name(loop_num);
595 loop_num++;
596 loop_count++;
598 __push_continues();
599 __push_breaks();
600 __merge_gotos(loop_name);
601 __split_stmt(stmt->iterator_statement);
602 __merge_continues();
603 if (!is_zero(stmt->iterator_post_condition))
604 __save_gotos(loop_name);
606 if (is_forever_loop(stmt)) {
607 __use_breaks();
608 } else {
609 __split_whole_condition(stmt->iterator_post_condition);
610 __use_false_states();
611 __merge_breaks();
613 loop_count--;
616 static int empty_statement(struct statement *stmt)
618 if (!stmt)
619 return 0;
620 if (stmt->type == STMT_EXPRESSION && !stmt->expression)
621 return 1;
622 return 0;
625 static int last_stmt_on_same_line(void)
627 struct statement *stmt;
628 int i = 0;
630 FOR_EACH_PTR_REVERSE(big_statement_stack, stmt) {
631 if (!i++)
632 continue;
633 if (stmt->pos.line == get_lineno())
634 return 1;
635 return 0;
636 } END_FOR_EACH_PTR_REVERSE(stmt);
637 return 0;
640 static void split_asm_constraints(struct expression_list *expr_list)
642 struct expression *expr;
643 int state = 0;
645 FOR_EACH_PTR(expr_list, expr) {
646 switch (state) {
647 case 0: /* identifier */
648 case 1: /* constraint */
649 state++;
650 continue;
651 case 2: /* expression */
652 state = 0;
653 __split_expr(expr);
654 continue;
656 } END_FOR_EACH_PTR(expr);
659 static int is_case_val(struct statement *stmt, sval_t sval)
661 sval_t case_sval;
663 if (stmt->type != STMT_CASE)
664 return 0;
665 if (!stmt->case_expression) {
666 __set_default();
667 return 1;
669 if (!get_value(stmt->case_expression, &case_sval))
670 return 0;
671 if (case_sval.value == sval.value)
672 return 1;
673 return 0;
676 static void split_known_switch(struct statement *stmt, sval_t sval)
678 struct statement *tmp;
680 __split_expr(stmt->switch_expression);
682 push_expression(&switch_expr_stack, stmt->switch_expression);
683 __save_switch_states(top_expression(switch_expr_stack));
684 nullify_path();
685 __push_default();
686 __push_breaks();
688 stmt = stmt->switch_statement;
690 __push_scope_hooks();
691 FOR_EACH_PTR(stmt->stmts, tmp) {
692 __smatch_lineno = tmp->pos.line;
693 if (is_case_val(tmp, sval)) {
694 __merge_switches(top_expression(switch_expr_stack),
695 stmt->case_expression, stmt->case_to);
696 __pass_case_to_client(top_expression(switch_expr_stack),
697 stmt->case_expression);
699 if (__path_is_null())
700 continue;
701 __split_stmt(tmp);
702 if (__path_is_null()) {
703 __set_default();
704 goto out;
706 } END_FOR_EACH_PTR(tmp);
707 out:
708 __call_scope_hooks();
709 if (!__pop_default())
710 __merge_switches(top_expression(switch_expr_stack),
711 NULL, NULL);
712 __discard_switches();
713 __merge_breaks();
714 pop_expression(&switch_expr_stack);
717 static int taking_too_long(void)
719 int ms;
721 ms = ms_since(&fn_start_time);
722 if (ms > 1000 * 60 * 5) /* five minutes */
723 return 1;
724 return 0;
727 static int is_last_stmt(struct statement *cur_stmt)
729 struct symbol *fn = get_base_type(cur_func_sym);
730 struct statement *stmt;
732 if (!fn)
733 return 0;
734 stmt = fn->stmt;
735 if (!stmt)
736 stmt = fn->inline_stmt;
737 if (!stmt || stmt->type != STMT_COMPOUND)
738 return 0;
739 stmt = last_ptr_list((struct ptr_list *)stmt->stmts);
740 if (stmt && stmt->type == STMT_LABEL)
741 stmt = stmt->label_statement;
742 if (stmt == cur_stmt)
743 return 1;
744 return 0;
747 static void handle_backward_goto(struct statement *goto_stmt)
749 const char *goto_name, *label_name;
750 struct statement *func_stmt;
751 struct symbol *base_type = get_base_type(cur_func_sym);
752 struct statement *tmp;
753 int found = 0;
755 if (!option_info)
756 return;
757 if (last_goto_statement_handled)
758 return;
759 last_goto_statement_handled = 1;
761 if (!goto_stmt->goto_label ||
762 goto_stmt->goto_label->type != SYM_LABEL ||
763 !goto_stmt->goto_label->ident)
764 return;
765 goto_name = goto_stmt->goto_label->ident->name;
767 func_stmt = base_type->stmt;
768 if (!func_stmt)
769 func_stmt = base_type->inline_stmt;
770 if (!func_stmt)
771 return;
772 if (func_stmt->type != STMT_COMPOUND)
773 return;
775 FOR_EACH_PTR(func_stmt->stmts, tmp) {
776 if (!found) {
777 if (tmp->type != STMT_LABEL)
778 continue;
779 if (!tmp->label_identifier ||
780 tmp->label_identifier->type != SYM_LABEL ||
781 !tmp->label_identifier->ident)
782 continue;
783 label_name = tmp->label_identifier->ident->name;
784 if (strcmp(goto_name, label_name) != 0)
785 continue;
786 found = 1;
788 __split_stmt(tmp);
789 } END_FOR_EACH_PTR(tmp);
792 static void fake_a_return(void)
794 struct symbol *return_type;
796 nullify_path();
797 __unnullify_path();
799 return_type = get_real_base_type(cur_func_sym);
800 return_type = get_real_base_type(return_type);
801 if (return_type != &void_ctype) {
802 __pass_to_client(unknown_value_expression(NULL), RETURN_HOOK);
803 nullify_path();
807 static void split_compound(struct statement *stmt)
809 struct statement *prev = NULL;
810 struct statement *cur = NULL;
811 struct statement *next;
813 __push_scope_hooks();
815 FOR_EACH_PTR(stmt->stmts, next) {
816 /* just set them all ahead of time */
817 set_parent_stmt(next, stmt);
819 if (cur) {
820 __prev_stmt = prev;
821 __next_stmt = next;
822 __cur_stmt = cur;
823 __split_stmt(cur);
825 prev = cur;
826 cur = next;
827 } END_FOR_EACH_PTR(next);
828 if (cur) {
829 __prev_stmt = prev;
830 __cur_stmt = cur;
831 __next_stmt = NULL;
832 __split_stmt(cur);
835 __call_scope_hooks();
838 void __split_stmt(struct statement *stmt)
840 sval_t sval;
842 if (!stmt)
843 goto out;
845 if (__bail_on_rest_of_function)
846 return;
848 if (out_of_memory() || taking_too_long()) {
850 __bail_on_rest_of_function = 1;
851 sm_msg("Function too hairy. Giving up.");
852 fake_a_return();
853 final_pass = 0; /* turn off sm_msg() from here */
854 return;
857 add_ptr_list(&big_statement_stack, stmt);
858 free_expression_stack(&big_expression_stack);
859 set_position(stmt->pos);
860 __pass_to_client(stmt, STMT_HOOK);
862 switch (stmt->type) {
863 case STMT_DECLARATION:
864 split_declaration(stmt->declaration);
865 break;
866 case STMT_RETURN:
867 __split_expr(stmt->ret_value);
868 __pass_to_client(stmt->ret_value, RETURN_HOOK);
869 __process_post_op_stack();
870 nullify_path();
871 break;
872 case STMT_EXPRESSION:
873 __split_expr(stmt->expression);
874 break;
875 case STMT_COMPOUND:
876 split_compound(stmt);
877 break;
878 case STMT_IF:
879 set_parent_stmt(stmt->if_true, stmt);
880 set_parent_stmt(stmt->if_false, stmt);
882 if (known_condition_true(stmt->if_conditional)) {
883 __split_stmt(stmt->if_true);
884 break;
886 if (known_condition_false(stmt->if_conditional)) {
887 __split_stmt(stmt->if_false);
888 break;
890 __split_whole_condition(stmt->if_conditional);
891 __split_stmt(stmt->if_true);
892 if (empty_statement(stmt->if_true) &&
893 last_stmt_on_same_line() &&
894 !get_macro_name(stmt->if_true->pos))
895 sm_msg("warn: if();");
896 __push_true_states();
897 __use_false_states();
898 __split_stmt(stmt->if_false);
899 __merge_true_states();
900 break;
901 case STMT_ITERATOR:
902 set_parent_stmt(stmt->iterator_pre_statement, stmt);
903 set_parent_stmt(stmt->iterator_statement, stmt);
904 set_parent_stmt(stmt->iterator_post_statement, stmt);
906 if (stmt->iterator_pre_condition)
907 handle_pre_loop(stmt);
908 else if (stmt->iterator_post_condition)
909 handle_post_loop(stmt);
910 else {
911 // these are for(;;) type loops.
912 handle_pre_loop(stmt);
914 break;
915 case STMT_SWITCH:
916 set_parent_stmt(stmt->switch_statement, stmt);
918 if (get_value(stmt->switch_expression, &sval)) {
919 split_known_switch(stmt, sval);
920 break;
922 __split_expr(stmt->switch_expression);
923 push_expression(&switch_expr_stack, stmt->switch_expression);
924 __save_switch_states(top_expression(switch_expr_stack));
925 nullify_path();
926 __push_default();
927 __push_breaks();
928 __split_stmt(stmt->switch_statement);
929 if (!__pop_default())
930 __merge_switches(top_expression(switch_expr_stack),
931 NULL, NULL);
932 __discard_switches();
933 __merge_breaks();
934 pop_expression(&switch_expr_stack);
935 break;
936 case STMT_CASE:
937 __merge_switches(top_expression(switch_expr_stack),
938 stmt->case_expression, stmt->case_to);
939 __pass_case_to_client(top_expression(switch_expr_stack),
940 stmt->case_expression);
941 if (!stmt->case_expression)
942 __set_default();
943 __split_expr(stmt->case_expression);
944 __split_expr(stmt->case_to);
945 __split_stmt(stmt->case_statement);
946 break;
947 case STMT_LABEL:
948 if (stmt->label_identifier &&
949 stmt->label_identifier->type == SYM_LABEL &&
950 stmt->label_identifier->ident) {
951 loop_count |= 0x80000000;
952 __merge_gotos(stmt->label_identifier->ident->name);
954 __split_stmt(stmt->label_statement);
955 break;
956 case STMT_GOTO:
957 __split_expr(stmt->goto_expression);
958 if (stmt->goto_label && stmt->goto_label->type == SYM_NODE) {
959 if (!strcmp(stmt->goto_label->ident->name, "break")) {
960 __process_breaks();
961 } else if (!strcmp(stmt->goto_label->ident->name,
962 "continue")) {
963 __process_continues();
965 } else if (stmt->goto_label &&
966 stmt->goto_label->type == SYM_LABEL &&
967 stmt->goto_label->ident) {
968 __save_gotos(stmt->goto_label->ident->name);
970 nullify_path();
971 if (is_last_stmt(stmt))
972 handle_backward_goto(stmt);
973 break;
974 case STMT_NONE:
975 break;
976 case STMT_ASM:
977 __pass_to_client(stmt, ASM_HOOK);
978 __split_expr(stmt->asm_string);
979 split_asm_constraints(stmt->asm_outputs);
980 split_asm_constraints(stmt->asm_inputs);
981 split_asm_constraints(stmt->asm_clobbers);
982 break;
983 case STMT_CONTEXT:
984 break;
985 case STMT_RANGE:
986 __split_expr(stmt->range_expression);
987 __split_expr(stmt->range_low);
988 __split_expr(stmt->range_high);
989 break;
991 __pass_to_client(stmt, STMT_HOOK_AFTER);
992 out:
993 __process_post_op_stack();
996 static void split_expr_list(struct expression_list *expr_list, struct expression *parent)
998 struct expression *expr;
1000 FOR_EACH_PTR(expr_list, expr) {
1001 set_parent(expr, parent);
1002 __split_expr(expr);
1003 __process_post_op_stack();
1004 } END_FOR_EACH_PTR(expr);
1007 static void split_sym(struct symbol *sym)
1009 if (!sym)
1010 return;
1011 if (!(sym->namespace & NS_SYMBOL))
1012 return;
1014 __split_stmt(sym->stmt);
1015 __split_expr(sym->array_size);
1016 split_symlist(sym->arguments);
1017 split_symlist(sym->symbol_list);
1018 __split_stmt(sym->inline_stmt);
1019 split_symlist(sym->inline_symbol_list);
1022 static void split_symlist(struct symbol_list *sym_list)
1024 struct symbol *sym;
1026 FOR_EACH_PTR(sym_list, sym) {
1027 split_sym(sym);
1028 } END_FOR_EACH_PTR(sym);
1031 typedef void (fake_cb)(struct expression *expr);
1033 static int member_to_number(struct expression *expr, struct ident *member)
1035 struct symbol *type, *tmp;
1036 char *name;
1037 int i;
1039 if (!member)
1040 return -1;
1041 name = member->name;
1043 type = get_type(expr);
1044 if (!type || type->type != SYM_STRUCT)
1045 return -1;
1047 i = -1;
1048 FOR_EACH_PTR(type->symbol_list, tmp) {
1049 i++;
1050 if (!tmp->ident)
1051 continue;
1052 if (strcmp(name, tmp->ident->name) == 0)
1053 return i;
1054 } END_FOR_EACH_PTR(tmp);
1055 return -1;
1058 static struct ident *number_to_member(struct expression *expr, int num)
1060 struct symbol *type, *member;
1061 int i = 0;
1063 type = get_type(expr);
1064 if (!type || type->type != SYM_STRUCT)
1065 return NULL;
1067 FOR_EACH_PTR(type->symbol_list, member) {
1068 if (i == num)
1069 return member->ident;
1070 i++;
1071 } END_FOR_EACH_PTR(member);
1072 return NULL;
1075 static void fake_element_assigns_helper(struct expression *array, struct expression_list *expr_list, fake_cb *fake_cb);
1077 struct member_set {
1078 struct ident *ident;
1079 int set;
1082 static struct member_set *alloc_member_set(struct symbol *type)
1084 struct member_set *member_set;
1085 struct symbol *member;
1086 int member_count;
1087 int member_idx;
1089 member_count = ptr_list_size((struct ptr_list *)type->symbol_list);
1090 member_set = malloc(member_count * sizeof(*member_set));
1091 member_idx = 0;
1092 FOR_EACH_PTR(type->symbol_list, member) {
1093 member_set[member_idx].ident = member->ident;
1094 member_set[member_idx].set = 0;
1095 member_idx++;
1096 } END_FOR_EACH_PTR(member);
1098 return member_set;
1101 static void mark_member_as_set(struct symbol *type, struct member_set *member_set, struct ident *ident)
1103 int member_count = ptr_list_size((struct ptr_list *)type->symbol_list);
1104 int i;
1106 for (i = 0; i < member_count; i++) {
1107 if (member_set[i].ident == ident) {
1108 member_set[i].set = 1;
1109 return;
1112 // crap. this is buggy.
1113 // sm_msg("internal smatch error in initializer %s.%s", type->ident->name, ident->name);
1116 static void set_inner_struct_members(struct expression *expr, struct symbol *member)
1118 struct expression *edge_member, *assign;
1119 struct symbol *base = get_real_base_type(member);
1120 struct symbol *tmp;
1122 if (member->ident)
1123 expr = member_expression(expr, '.', member->ident);
1125 FOR_EACH_PTR(base->symbol_list, tmp) {
1126 struct symbol *type;
1128 type = get_real_base_type(tmp);
1129 if (!type)
1130 continue;
1132 if (tmp->ident) {
1133 edge_member = member_expression(expr, '.', tmp->ident);
1134 if (get_state_expr(SMATCH_EXTRA, edge_member))
1135 continue;
1138 if (type->type == SYM_UNION || type->type == SYM_STRUCT) {
1139 set_inner_struct_members(expr, tmp);
1140 continue;
1143 if (!tmp->ident)
1144 continue;
1146 assign = assign_expression(edge_member, zero_expr());
1147 __split_expr(assign);
1148 } END_FOR_EACH_PTR(tmp);
1153 static void set_unset_to_zero(struct symbol *type, struct expression *expr)
1155 struct symbol *tmp;
1156 struct expression *member, *assign;
1157 int op = '*';
1159 if (expr->type == EXPR_PREOP && expr->op == '&') {
1160 expr = strip_expr(expr->unop);
1161 op = '.';
1164 FOR_EACH_PTR(type->symbol_list, tmp) {
1165 type = get_real_base_type(tmp);
1166 if (!type)
1167 continue;
1169 if (tmp->ident) {
1170 member = member_expression(expr, op, tmp->ident);
1171 if (get_state_expr(SMATCH_EXTRA, member))
1172 continue;
1175 if (type->type == SYM_UNION || type->type == SYM_STRUCT) {
1176 set_inner_struct_members(expr, tmp);
1177 continue;
1179 if (type->type == SYM_ARRAY)
1180 continue;
1181 if (!tmp->ident)
1182 continue;
1184 assign = assign_expression(member, zero_expr());
1185 __split_expr(assign);
1186 } END_FOR_EACH_PTR(tmp);
1189 static void fake_member_assigns_helper(struct expression *symbol, struct expression_list *members, fake_cb *fake_cb)
1191 struct expression *deref, *assign, *tmp;
1192 struct symbol *struct_type, *type;
1193 struct ident *member;
1194 int member_idx;
1195 struct member_set *member_set;
1197 struct_type = get_type(symbol);
1198 if (!struct_type ||
1199 (struct_type->type != SYM_STRUCT && struct_type->type != SYM_UNION))
1200 return;
1202 member_set = alloc_member_set(struct_type);
1204 member_idx = 0;
1205 FOR_EACH_PTR(members, tmp) {
1206 member = number_to_member(symbol, member_idx);
1207 while (tmp->type == EXPR_IDENTIFIER) {
1208 member = tmp->expr_ident;
1209 member_idx = member_to_number(symbol, member);
1210 tmp = tmp->ident_expression;
1212 mark_member_as_set(struct_type, member_set, member);
1213 member_idx++;
1214 deref = member_expression(symbol, '.', member);
1215 if (tmp->type == EXPR_INITIALIZER) {
1216 type = get_type(deref);
1217 if (type && type->type == SYM_ARRAY)
1218 fake_element_assigns_helper(deref, tmp->expr_list, fake_cb);
1219 else
1220 fake_member_assigns_helper(deref, tmp->expr_list, fake_cb);
1221 } else {
1222 assign = assign_expression(deref, tmp);
1223 fake_cb(assign);
1225 } END_FOR_EACH_PTR(tmp);
1227 set_unset_to_zero(struct_type, symbol);
1230 static void fake_member_assigns(struct symbol *sym, fake_cb *fake_cb)
1232 fake_member_assigns_helper(symbol_expression(sym),
1233 sym->initializer->expr_list, fake_cb);
1236 static void fake_element_assigns_helper(struct expression *array, struct expression_list *expr_list, fake_cb *fake_cb)
1238 struct expression *offset, *binop, *assign, *tmp;
1239 struct symbol *type;
1240 int idx;
1242 if (ptr_list_size((struct ptr_list *)expr_list) > 1000)
1243 return;
1245 idx = 0;
1246 FOR_EACH_PTR(expr_list, tmp) {
1247 if (tmp->type == EXPR_INDEX) {
1248 if (tmp->idx_from != tmp->idx_to)
1249 return;
1250 idx = tmp->idx_from;
1251 if (!tmp->idx_expression)
1252 goto next;
1253 tmp = tmp->idx_expression;
1255 offset = value_expr(idx);
1256 binop = array_element_expression(array, offset);
1257 if (tmp->type == EXPR_INITIALIZER) {
1258 type = get_type(binop);
1259 if (type && type->type == SYM_ARRAY)
1260 fake_element_assigns_helper(binop, tmp->expr_list, fake_cb);
1261 else
1262 fake_member_assigns_helper(binop, tmp->expr_list, fake_cb);
1263 } else {
1264 assign = assign_expression(binop, tmp);
1265 fake_cb(assign);
1267 next:
1268 idx++;
1269 } END_FOR_EACH_PTR(tmp);
1272 static void fake_element_assigns(struct symbol *sym, fake_cb *fake_cb)
1274 fake_element_assigns_helper(symbol_expression(sym), sym->initializer->expr_list, fake_cb);
1277 static void fake_assign_expr(struct symbol *sym)
1279 struct expression *assign, *symbol;
1281 symbol = symbol_expression(sym);
1282 assign = assign_expression(symbol, sym->initializer);
1283 __split_expr(assign);
1286 static void call_split_expr(struct expression *expr)
1288 __split_expr(expr);
1291 static void do_initializer_stuff(struct symbol *sym)
1293 if (!sym->initializer)
1294 return;
1296 if (sym->initializer->type == EXPR_INITIALIZER) {
1297 if (get_real_base_type(sym)->type == SYM_ARRAY)
1298 fake_element_assigns(sym, call_split_expr);
1299 else
1300 fake_member_assigns(sym, call_split_expr);
1301 } else {
1302 fake_assign_expr(sym);
1306 static void split_declaration(struct symbol_list *sym_list)
1308 struct symbol *sym;
1310 FOR_EACH_PTR(sym_list, sym) {
1311 __pass_to_client(sym, DECLARATION_HOOK);
1312 do_initializer_stuff(sym);
1313 split_sym(sym);
1314 } END_FOR_EACH_PTR(sym);
1317 static void call_global_assign_hooks(struct expression *assign)
1319 __pass_to_client(assign, GLOBAL_ASSIGNMENT_HOOK);
1322 static void fake_global_assign(struct symbol *sym)
1324 struct expression *assign, *symbol;
1326 if (get_real_base_type(sym)->type == SYM_ARRAY) {
1327 if (sym->initializer && sym->initializer->type == EXPR_INITIALIZER) {
1328 fake_element_assigns(sym, call_global_assign_hooks);
1329 } else if (sym->initializer) {
1330 symbol = symbol_expression(sym);
1331 assign = assign_expression(symbol, sym->initializer);
1332 __pass_to_client(assign, GLOBAL_ASSIGNMENT_HOOK);
1333 } else {
1334 fake_element_assigns_helper(symbol_expression(sym), NULL, call_global_assign_hooks);
1336 } else if (get_real_base_type(sym)->type == SYM_STRUCT) {
1337 if (sym->initializer && sym->initializer->type == EXPR_INITIALIZER) {
1338 fake_member_assigns(sym, call_global_assign_hooks);
1339 } else if (sym->initializer) {
1340 symbol = symbol_expression(sym);
1341 assign = assign_expression(symbol, sym->initializer);
1342 __pass_to_client(assign, GLOBAL_ASSIGNMENT_HOOK);
1343 } else {
1344 fake_member_assigns_helper(symbol_expression(sym), NULL, call_global_assign_hooks);
1346 } else {
1347 symbol = symbol_expression(sym);
1348 if (sym->initializer)
1349 assign = assign_expression(symbol, sym->initializer);
1350 else
1351 assign = assign_expression(symbol, zero_expr());
1352 __pass_to_client(assign, GLOBAL_ASSIGNMENT_HOOK);
1356 static void start_function_definition(struct symbol *sym)
1358 __in_function_def = 1;
1359 __pass_to_client(sym, FUNC_DEF_HOOK);
1360 __in_function_def = 0;
1361 __pass_to_client(sym, AFTER_DEF_HOOK);
1365 static void split_function(struct symbol *sym)
1367 struct symbol *base_type = get_base_type(sym);
1369 if (!base_type->stmt && !base_type->inline_stmt)
1370 return;
1372 gettimeofday(&fn_start_time, NULL);
1373 cur_func_sym = sym;
1374 if (sym->ident)
1375 cur_func = sym->ident->name;
1376 __smatch_lineno = sym->pos.line;
1377 loop_count = 0;
1378 last_goto_statement_handled = 0;
1379 sm_debug("new function: %s\n", cur_func);
1380 __stree_id = 0;
1381 if (option_two_passes) {
1382 __unnullify_path();
1383 loop_num = 0;
1384 final_pass = 0;
1385 start_function_definition(sym);
1386 __split_stmt(base_type->stmt);
1387 __split_stmt(base_type->inline_stmt);
1388 nullify_path();
1390 __unnullify_path();
1391 loop_num = 0;
1392 final_pass = 1;
1393 start_function_definition(sym);
1394 __split_stmt(base_type->stmt);
1395 __split_stmt(base_type->inline_stmt);
1396 __pass_to_client(sym, END_FUNC_HOOK);
1397 __pass_to_client(sym, AFTER_FUNC_HOOK);
1399 clear_all_states();
1400 cur_func_sym = NULL;
1401 cur_func = NULL;
1402 free_data_info_allocs();
1403 free_expression_stack(&switch_expr_stack);
1404 __free_ptr_list((struct ptr_list **)&big_statement_stack);
1405 __bail_on_rest_of_function = 0;
1408 static void parse_inline(struct expression *call)
1410 struct symbol *base_type;
1411 int loop_num_bak = loop_num;
1412 int final_pass_bak = final_pass;
1413 char *cur_func_bak = cur_func;
1414 struct statement_list *big_statement_stack_bak = big_statement_stack;
1415 struct expression_list *big_expression_stack_bak = big_expression_stack;
1416 struct expression_list *switch_expr_stack_bak = switch_expr_stack;
1417 struct symbol *cur_func_sym_bak = cur_func_sym;
1419 __pass_to_client(call, INLINE_FN_START);
1420 final_pass = 0; /* don't print anything */
1421 __inline_fn = call;
1423 base_type = get_base_type(call->fn->symbol);
1424 cur_func_sym = call->fn->symbol;
1425 if (call->fn->symbol->ident)
1426 cur_func = call->fn->symbol->ident->name;
1427 else
1428 cur_func = NULL;
1429 set_position(call->fn->symbol->pos);
1431 save_all_states();
1432 big_statement_stack = NULL;
1433 big_expression_stack = NULL;
1434 switch_expr_stack = NULL;
1436 sm_debug("inline function: %s\n", cur_func);
1437 __unnullify_path();
1438 loop_num = 0;
1439 start_function_definition(call->fn->symbol);
1440 __split_stmt(base_type->stmt);
1441 __split_stmt(base_type->inline_stmt);
1442 __pass_to_client(call->fn->symbol, END_FUNC_HOOK);
1443 __pass_to_client(call->fn->symbol, AFTER_FUNC_HOOK);
1445 free_expression_stack(&switch_expr_stack);
1446 __free_ptr_list((struct ptr_list **)&big_statement_stack);
1447 nullify_path();
1448 free_goto_stack();
1450 loop_num = loop_num_bak;
1451 final_pass = final_pass_bak;
1452 cur_func_sym = cur_func_sym_bak;
1453 cur_func = cur_func_bak;
1454 big_statement_stack = big_statement_stack_bak;
1455 big_expression_stack = big_expression_stack_bak;
1456 switch_expr_stack = switch_expr_stack_bak;
1458 restore_all_states();
1459 set_position(call->pos);
1460 __inline_fn = NULL;
1461 __pass_to_client(call, INLINE_FN_END);
1464 static struct symbol_list *inlines_called;
1465 static void add_inline_function(struct symbol *sym)
1467 static struct symbol_list *already_added;
1468 struct symbol *tmp;
1470 FOR_EACH_PTR(already_added, tmp) {
1471 if (tmp == sym)
1472 return;
1473 } END_FOR_EACH_PTR(tmp);
1475 add_ptr_list(&already_added, sym);
1476 add_ptr_list(&inlines_called, sym);
1479 static void process_inlines(void)
1481 struct symbol *tmp;
1483 FOR_EACH_PTR(inlines_called, tmp) {
1484 split_function(tmp);
1485 } END_FOR_EACH_PTR(tmp);
1486 free_ptr_list(&inlines_called);
1489 static struct symbol *get_last_scoped_symbol(struct symbol_list *big_list, int use_static)
1491 struct symbol *sym;
1493 FOR_EACH_PTR_REVERSE(big_list, sym) {
1494 if (!sym->scope)
1495 continue;
1496 if (use_static && sym->ctype.modifiers & MOD_STATIC)
1497 return sym;
1498 if (!use_static && !(sym->ctype.modifiers & MOD_STATIC))
1499 return sym;
1500 } END_FOR_EACH_PTR_REVERSE(sym);
1502 return NULL;
1505 static void split_inlines_in_scope(struct symbol *sym)
1507 struct symbol *base;
1508 struct symbol_list *scope_list;
1509 int stream;
1511 scope_list = sym->scope->symbols;
1512 stream = sym->pos.stream;
1514 /* find the last static symbol in the file */
1515 FOR_EACH_PTR_REVERSE(scope_list, sym) {
1516 if (sym->pos.stream != stream)
1517 continue;
1518 if (sym->type != SYM_NODE)
1519 continue;
1520 base = get_base_type(sym);
1521 if (!base)
1522 continue;
1523 if (base->type != SYM_FN)
1524 continue;
1525 if (!base->inline_stmt)
1526 continue;
1527 add_inline_function(sym);
1528 } END_FOR_EACH_PTR_REVERSE(sym);
1530 process_inlines();
1533 static void split_inlines(struct symbol_list *sym_list)
1535 struct symbol *sym;
1537 sym = get_last_scoped_symbol(sym_list, 0);
1538 if (sym)
1539 split_inlines_in_scope(sym);
1540 sym = get_last_scoped_symbol(sym_list, 1);
1541 if (sym)
1542 split_inlines_in_scope(sym);
1545 static struct stree *clone_estates_perm(struct stree *orig)
1547 struct stree *ret = NULL;
1548 struct sm_state *tmp;
1550 FOR_EACH_SM(orig, tmp) {
1551 set_state_stree_perm(&ret, tmp->owner, tmp->name, tmp->sym, clone_estate_perm(tmp->state));
1552 } END_FOR_EACH_SM(tmp);
1554 return ret;
1557 static void split_functions(struct symbol_list *sym_list)
1559 struct symbol *sym;
1561 __unnullify_path();
1562 FOR_EACH_PTR(sym_list, sym) {
1563 set_position(sym->pos);
1564 if (sym->type != SYM_NODE || get_base_type(sym)->type != SYM_FN) {
1565 __pass_to_client(sym, BASE_HOOK);
1566 fake_global_assign(sym);
1568 } END_FOR_EACH_PTR(sym);
1569 global_states = clone_estates_perm(get_all_states_stree(SMATCH_EXTRA));
1570 nullify_path();
1572 FOR_EACH_PTR(sym_list, sym) {
1573 set_position(sym->pos);
1574 if (sym->type == SYM_NODE && get_base_type(sym)->type == SYM_FN) {
1575 split_function(sym);
1576 process_inlines();
1578 } END_FOR_EACH_PTR(sym);
1579 split_inlines(sym_list);
1580 __pass_to_client(sym_list, END_FILE_HOOK);
1583 void smatch(int argc, char **argv)
1586 struct string_list *filelist = NULL;
1587 struct symbol_list *sym_list;
1589 if (argc < 2) {
1590 printf("Usage: smatch [--debug] <filename.c>\n");
1591 exit(1);
1593 sparse_initialize(argc, argv, &filelist);
1594 set_valid_ptr_max();
1595 FOR_EACH_PTR_NOTAG(filelist, base_file) {
1596 if (option_file_output) {
1597 char buf[256];
1599 snprintf(buf, sizeof(buf), "%s.smatch", base_file);
1600 sm_outfd = fopen(buf, "w");
1601 if (!sm_outfd) {
1602 printf("Error: Cannot open %s\n", base_file);
1603 exit(1);
1606 sym_list = sparse_keep_tokens(base_file);
1607 split_functions(sym_list);
1608 } END_FOR_EACH_PTR_NOTAG(base_file);