Print this page
12724 update smatch to 0.6.1-rc1-il-5

*** 145,155 **** i++; } END_FOR_EACH_PTR(expr); return NULL; } ! static struct expression *get_array_expr(struct expression *expr) { struct expression *parent; struct symbol *type; if (expr->type != EXPR_BINOP || expr->op != '+') --- 145,155 ---- i++; } END_FOR_EACH_PTR(expr); return NULL; } ! struct expression *get_array_expr(struct expression *expr) { struct expression *parent; struct symbol *type; if (expr->type != EXPR_BINOP || expr->op != '+')
*** 172,185 **** return NULL; } static void __get_variable_from_expr(struct symbol **sym_ptr, char *buf, struct expression *expr, int len, ! int *complicated, int no_parens) { - - if (!expr) { /* can't happen on valid code */ *complicated = 1; return; } --- 172,183 ---- return NULL; } static void __get_variable_from_expr(struct symbol **sym_ptr, char *buf, struct expression *expr, int len, ! int *complicated) { if (!expr) { /* can't happen on valid code */ *complicated = 1; return; }
*** 202,212 **** op = '.'; deref = deref->unop; } } ! __get_variable_from_expr(sym_ptr, buf, deref, len, complicated, no_parens); if (op == '*') append(buf, "->", len); else append(buf, ".", len); --- 200,210 ---- op = '.'; deref = deref->unop; } } ! __get_variable_from_expr(sym_ptr, buf, deref, len, complicated); if (op == '*') append(buf, "->", len); else append(buf, ".", len);
*** 234,253 **** *complicated = 2; return; } if (expr->op == '(') { ! if (!no_parens && expr->unop->type != EXPR_SYMBOL) append(buf, "(", len); } else if (expr->op != '*' || !get_array_expr(expr->unop)) { tmp = show_special(expr->op); append(buf, tmp, len); } __get_variable_from_expr(sym_ptr, buf, expr->unop, ! len, complicated, no_parens); ! if (expr->op == '(' && !no_parens && expr->unop->type != EXPR_SYMBOL) append(buf, ")", len); if (expr->op == SPECIAL_DECREMENT || expr->op == SPECIAL_INCREMENT) *complicated = 1; --- 232,251 ---- *complicated = 2; return; } if (expr->op == '(') { ! if (expr->unop->type != EXPR_SYMBOL) append(buf, "(", len); } else if (expr->op != '*' || !get_array_expr(expr->unop)) { tmp = show_special(expr->op); append(buf, tmp, len); } __get_variable_from_expr(sym_ptr, buf, expr->unop, ! len, complicated); ! if (expr->op == '(' && expr->unop->type != EXPR_SYMBOL) append(buf, ")", len); if (expr->op == SPECIAL_DECREMENT || expr->op == SPECIAL_INCREMENT) *complicated = 1;
*** 256,266 **** } case EXPR_POSTOP: { const char *tmp; __get_variable_from_expr(sym_ptr, buf, expr->unop, ! len, complicated, no_parens); tmp = show_special(expr->op); append(buf, tmp, len); if (expr->op == SPECIAL_DECREMENT || expr->op == SPECIAL_INCREMENT) *complicated = 1; --- 254,264 ---- } case EXPR_POSTOP: { const char *tmp; __get_variable_from_expr(sym_ptr, buf, expr->unop, ! len, complicated); tmp = show_special(expr->op); append(buf, tmp, len); if (expr->op == SPECIAL_DECREMENT || expr->op == SPECIAL_INCREMENT) *complicated = 1;
*** 274,291 **** struct expression *array_expr; *complicated = 1; array_expr = get_array_expr(expr); if (array_expr) { ! __get_variable_from_expr(sym_ptr, buf, array_expr, len, complicated, no_parens); append(buf, "[", len); } else { ! __get_variable_from_expr(sym_ptr, buf, expr->left, len, complicated, no_parens); snprintf(tmp, sizeof(tmp), " %s ", show_special(expr->op)); append(buf, tmp, len); } ! __get_variable_from_expr(NULL, buf, expr->right, len, complicated, no_parens); if (array_expr) append(buf, "]", len); return; } case EXPR_VALUE: { --- 272,289 ---- struct expression *array_expr; *complicated = 1; array_expr = get_array_expr(expr); if (array_expr) { ! __get_variable_from_expr(sym_ptr, buf, array_expr, len, complicated); append(buf, "[", len); } else { ! __get_variable_from_expr(sym_ptr, buf, expr->left, len, complicated); snprintf(tmp, sizeof(tmp), " %s ", show_special(expr->op)); append(buf, tmp, len); } ! __get_variable_from_expr(NULL, buf, expr->right, len, complicated); if (array_expr) append(buf, "]", len); return; } case EXPR_VALUE: {
*** 319,344 **** case EXPR_CALL: { struct expression *tmp; int i; *complicated = 1; ! __get_variable_from_expr(NULL, buf, expr->fn, len, complicated, no_parens); append(buf, "(", len); i = 0; FOR_EACH_PTR(expr->args, tmp) { if (i++) append(buf, ", ", len); ! __get_variable_from_expr(NULL, buf, tmp, len, complicated, no_parens); } END_FOR_EACH_PTR(tmp); append(buf, ")", len); return; } case EXPR_CAST: case EXPR_FORCE_CAST: __get_variable_from_expr(sym_ptr, buf, expr->cast_expression, len, ! complicated, no_parens); return; case EXPR_SIZEOF: { sval_t sval; int size; char tmp[25]; --- 317,342 ---- case EXPR_CALL: { struct expression *tmp; int i; *complicated = 1; ! __get_variable_from_expr(NULL, buf, expr->fn, len, complicated); append(buf, "(", len); i = 0; FOR_EACH_PTR(expr->args, tmp) { if (i++) append(buf, ", ", len); ! __get_variable_from_expr(NULL, buf, tmp, len, complicated); } END_FOR_EACH_PTR(tmp); append(buf, ")", len); return; } case EXPR_CAST: case EXPR_FORCE_CAST: __get_variable_from_expr(sym_ptr, buf, expr->cast_expression, len, ! complicated); return; case EXPR_SIZEOF: { sval_t sval; int size; char tmp[25];
*** 356,406 **** case EXPR_IDENTIFIER: *complicated = 1; if (expr->expr_ident) append(buf, expr->expr_ident->name, len); return; ! default: *complicated = 1; ! //printf("unknown type = %d\n", expr->type); return; } } struct expr_str_cache_results { struct expression *expr; - int no_parens; char str[VAR_LEN]; struct symbol *sym; int complicated; }; static void get_variable_from_expr(struct symbol **sym_ptr, char *buf, struct expression *expr, int len, ! int *complicated, int no_parens) { static struct expr_str_cache_results cached[8]; struct symbol *tmp_sym = NULL; static int idx; int i; for (i = 0; i < ARRAY_SIZE(cached); i++) { ! if (expr == cached[i].expr && ! no_parens == cached[i].no_parens) { strncpy(buf, cached[i].str, len); if (sym_ptr) *sym_ptr = cached[i].sym; *complicated = cached[i].complicated; return; } } ! __get_variable_from_expr(&tmp_sym, buf, expr, len, complicated, no_parens); if (sym_ptr) *sym_ptr = tmp_sym; cached[idx].expr = expr; - cached[idx].no_parens = no_parens; strncpy(cached[idx].str, buf, VAR_LEN); cached[idx].sym = tmp_sym; cached[idx].complicated = *complicated; idx = (idx + 1) % ARRAY_SIZE(cached); --- 354,419 ---- case EXPR_IDENTIFIER: *complicated = 1; if (expr->expr_ident) append(buf, expr->expr_ident->name, len); return; ! case EXPR_SELECT: ! case EXPR_CONDITIONAL: *complicated = 1; ! append(buf, "(", len); ! __get_variable_from_expr(NULL, buf, expr->conditional, len, complicated); ! append(buf, ") ?", len); ! if (expr->cond_true) ! __get_variable_from_expr(NULL, buf, expr->cond_true, len, complicated); ! append(buf, ":", len); ! __get_variable_from_expr(NULL, buf, expr->cond_false, len, complicated); return; + default: { + char tmp[64]; + + snprintf(tmp, sizeof(tmp), "$expr_%p(%d)", expr, expr->type); + append(buf, tmp, len); + *complicated = 1; } + return; + } } struct expr_str_cache_results { struct expression *expr; char str[VAR_LEN]; struct symbol *sym; int complicated; }; static void get_variable_from_expr(struct symbol **sym_ptr, char *buf, struct expression *expr, int len, ! int *complicated) { static struct expr_str_cache_results cached[8]; struct symbol *tmp_sym = NULL; static int idx; int i; for (i = 0; i < ARRAY_SIZE(cached); i++) { ! if (expr == cached[i].expr) { strncpy(buf, cached[i].str, len); if (sym_ptr) *sym_ptr = cached[i].sym; *complicated = cached[i].complicated; return; } } ! __get_variable_from_expr(&tmp_sym, buf, expr, len, complicated); if (sym_ptr) *sym_ptr = tmp_sym; + if (expr->smatch_flags & Tmp) + return; + cached[idx].expr = expr; strncpy(cached[idx].str, buf, VAR_LEN); cached[idx].sym = tmp_sym; cached[idx].complicated = *complicated; idx = (idx + 1) % ARRAY_SIZE(cached);
*** 425,435 **** var_name[0] = '\0'; if (!expr) return NULL; get_variable_from_expr(sym_ptr, var_name, expr, sizeof(var_name), ! &complicated, 0); if (complicated < 2) return alloc_string(var_name); else return NULL; } --- 438,448 ---- var_name[0] = '\0'; if (!expr) return NULL; get_variable_from_expr(sym_ptr, var_name, expr, sizeof(var_name), ! &complicated); if (complicated < 2) return alloc_string(var_name); else return NULL; }
*** 456,466 **** if (!expr) return NULL; expr = strip_expr(expr); get_variable_from_expr(sym_ptr, var_name, expr, sizeof(var_name), ! &complicated, 1); if (complicated) { if (sym_ptr) *sym_ptr = NULL; return NULL; --- 469,479 ---- if (!expr) return NULL; expr = strip_expr(expr); get_variable_from_expr(sym_ptr, var_name, expr, sizeof(var_name), ! &complicated); if (complicated) { if (sym_ptr) *sym_ptr = NULL; return NULL;
*** 1049,1081 **** int get_param_num_from_sym(struct symbol *sym) { struct symbol *tmp; int i; ! if (!cur_func_sym) ! return -1; i = 0; FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, tmp) { if (tmp == sym) return i; i++; } END_FOR_EACH_PTR(tmp); ! return -1; } int get_param_num(struct expression *expr) { struct symbol *sym; char *name; if (!cur_func_sym) ! return -1; name = expr_to_var_sym(expr, &sym); free_string(name); if (!sym) ! return -1; return get_param_num_from_sym(sym); } struct symbol *get_param_sym_from_num(int num) { --- 1062,1109 ---- int get_param_num_from_sym(struct symbol *sym) { struct symbol *tmp; int i; ! if (!sym) ! return UNKNOWN_SCOPE; + if (sym->ctype.modifiers & MOD_TOPLEVEL) { + if (sym->ctype.modifiers & MOD_STATIC) + return FILE_SCOPE; + return GLOBAL_SCOPE; + } + + if (!cur_func_sym) { + if (!parse_error) { + sm_msg("warn: internal. problem with scope: %s", + sym->ident ? sym->ident->name : "<anon var>"); + } + return GLOBAL_SCOPE; + } + + i = 0; FOR_EACH_PTR(cur_func_sym->ctype.base_type->arguments, tmp) { if (tmp == sym) return i; i++; } END_FOR_EACH_PTR(tmp); ! return LOCAL_SCOPE; } int get_param_num(struct expression *expr) { struct symbol *sym; char *name; if (!cur_func_sym) ! return UNKNOWN_SCOPE; name = expr_to_var_sym(expr, &sym); free_string(name); if (!sym) ! return UNKNOWN_SCOPE; return get_param_num_from_sym(sym); } struct symbol *get_param_sym_from_num(int num) {