From e465a8870d683247bb6b23f3bcfb8391f29b6c79 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Wed, 16 Dec 2020 15:55:39 +0300 Subject: [PATCH] states: use the state from the fake assignment There was no reason for this, it just seemed like an good idea so I did it. The problem was that inline functions get parsed more than once so it led to double frees. So I added a check for that. Otherwise, I didn't notice any difference in the output. But I'm only looking at bad output so maybe it made it better and I didn't notice. Signed-off-by: Dan Carpenter --- smatch_flow.c | 2 ++ smatch_states.c | 7 +++++++ symbol.h | 2 +- 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/smatch_flow.c b/smatch_flow.c index 4b120792..a61dfbd6 100644 --- a/smatch_flow.c +++ b/smatch_flow.c @@ -1792,6 +1792,7 @@ static void split_function(struct symbol *sym) if (need_delayed_scope_hooks()) __call_scope_hooks(); __pass_to_client(sym, AFTER_FUNC_HOOK); + sym->parsed = true; clear_all_states(); @@ -1903,6 +1904,7 @@ static void parse_inline(struct expression *call) __split_stmt(base_type->inline_stmt); __pass_to_client(call->fn->symbol, END_FUNC_HOOK); __pass_to_client(call->fn->symbol, AFTER_FUNC_HOOK); + call->fn->symbol->parsed = true; free_expression_stack(&switch_expr_stack); __free_ptr_list((struct ptr_list **)&big_statement_stack); diff --git a/smatch_states.c b/smatch_states.c index 06d07696..77564b68 100644 --- a/smatch_states.c +++ b/smatch_states.c @@ -390,10 +390,17 @@ struct smatch_state *get_state(int owner, const char *name, struct symbol *sym) struct smatch_state *get_state_expr(int owner, struct expression *expr) { + struct expression *fake_parent; char *name; struct symbol *sym; struct smatch_state *ret = NULL; + if (cur_func_sym && !cur_func_sym->parsed) { + fake_parent = expr_get_fake_parent_expr(expr); + if (fake_parent) + expr = fake_parent->left; + } + expr = strip_expr(expr); name = expr_to_var_sym(expr, &sym); if (!name || !sym) diff --git a/symbol.h b/symbol.h index 83fc00ca..06995c9f 100644 --- a/symbol.h +++ b/symbol.h @@ -144,7 +144,7 @@ struct symbol_op { struct symbol { enum type type:8; enum namespace namespace:9; - unsigned char used:1, attr:2, enum_member:1, bound:1; + unsigned char used:1, attr:2, enum_member:1, bound:1, parsed:1; struct position pos; /* Where this symbol was declared */ struct position endpos; /* Where this symbol ends*/ struct ident *ident; /* What identifier this symbol is associated with */ -- 2.11.4.GIT