From f23e60821b94dd7bda01e31310107c46232792a0 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Mon, 15 Dec 2014 15:15:11 +0300 Subject: [PATCH] helper: change "&*foo" to "foo" at the lowest levels I changed expr_to_str() to automatically simplify "&*foo" to "foo". I considered doing this in strip_expr() but for some reason when I looked at that then it seemed like I would have to allocate a fake expression and I didn't want to do that... Doing the simplification here is sort of a new approach for Smatch. Signed-off-by: Dan Carpenter --- smatch_helper.c | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/smatch_helper.c b/smatch_helper.c index 2ebe0718..5a4fa3dd 100644 --- a/smatch_helper.c +++ b/smatch_helper.c @@ -23,6 +23,7 @@ #include #include "allocate.h" #include "smatch.h" +#include "smatch_extra.h" #define VAR_LEN 512 @@ -114,18 +115,27 @@ static void __get_variable_from_expr(struct symbol **sym_ptr, char *buf, struct expression *expr, int len, int *complicated, int no_parens) { - struct expression *tmp; - switch (expr->type) { - case EXPR_DEREF: - tmp = expr->deref; - if (tmp->op == '*') - tmp = tmp->unop; + case EXPR_DEREF: { + struct expression *deref; + int op; + + deref = expr->deref; + op = deref->op; + if (op == '*') { + struct expression *unop = strip_expr(deref->unop); + + if (unop->type == EXPR_PREOP && unop->op == '&') { + deref = unop->unop; + op = '.'; + } else { + deref = deref->unop; + } + } - __get_variable_from_expr(sym_ptr, buf, tmp, len, complicated, no_parens); + __get_variable_from_expr(sym_ptr, buf, deref, len, complicated, no_parens); - tmp = expr->deref; - if (tmp->op == '*') + if (op == '*') append(buf, "->", len); else append(buf, ".", len); @@ -136,6 +146,7 @@ static void __get_variable_from_expr(struct symbol **sym_ptr, char *buf, append(buf, "unknown_member", len); return; + } case EXPR_SYMBOL: if (expr->symbol_name) append(buf, expr->symbol_name->name, len); -- 2.11.4.GIT