From 348baf1738b873131fbe2f78b383b4e4aea9245e Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 26 Jul 2018 13:51:05 +0300 Subject: [PATCH] mtag: make get_mtag_offset() give both an mtag and an offset From the name, you'd sort of expect it to return an mtag and an offset. Also there is a kind of complicated thing with pointers where it hard to talk about the pointer vs what the pointer is holding. What's the value of a pointer? Is it the address or the thing stored in the address. This function is used when you want to get the thing stored in the address. But really it gives you the address... I don't know if this explanation is helping... Signed-off-by: Dan Carpenter --- smatch.h | 2 +- smatch_mtag.c | 18 ++++++++++++++---- smatch_mtag_data.c | 6 +----- 3 files changed, 16 insertions(+), 10 deletions(-) diff --git a/smatch.h b/smatch.h index 04d5dca5..45da5b47 100644 --- a/smatch.h +++ b/smatch.h @@ -1120,7 +1120,7 @@ int get_offset_from_container_of(struct expression *expr); /* smatch_mtag.c */ int get_toplevel_mtag(struct symbol *sym, mtag_t *tag); int get_mtag(struct expression *expr, mtag_t *tag); -int get_mtag_offset(struct expression *expr); +int get_mtag_offset(struct expression *expr, mtag_t *tag, int *offset); int create_mtag_alias(mtag_t tag, struct expression *expr, mtag_t *new); int expr_to_mtag_name_offset(struct expression *expr, mtag_t *tag, char **name, int *offset); void update_mtag_data(struct expression *expr); diff --git a/smatch_mtag.c b/smatch_mtag.c index 168db9d0..c564c2f9 100644 --- a/smatch_mtag.c +++ b/smatch_mtag.c @@ -330,14 +330,24 @@ dec_cnt: return ret; } -int get_mtag_offset(struct expression *expr) +int get_mtag_offset(struct expression *expr, mtag_t *tag, int *offset) { + int val; + if (!expr) - return -1; + return 0; + if (!get_mtag(expr, tag)) + return 0; expr = strip_expr(expr); - if (expr->type == EXPR_SYMBOL) + if (expr->type == EXPR_SYMBOL) { + *offset = 0; + return 1; + } + val = get_member_offset_from_deref(expr); + if (val < 0) return 0; - return get_member_offset_from_deref(expr); + *offset = val; + return 1; } int create_mtag_alias(mtag_t tag, struct expression *expr, mtag_t *new) diff --git a/smatch_mtag_data.c b/smatch_mtag_data.c index 63b28afe..1ce2dcbd 100644 --- a/smatch_mtag_data.c +++ b/smatch_mtag_data.c @@ -182,11 +182,7 @@ int get_db_data_rl(struct expression *expr, struct range_list **rl) int ret; int i; - if (!get_mtag(expr, &tag)) - return 0; - - offset = get_mtag_offset(expr); - if (offset < 0) + if (!get_mtag_offset(expr, &tag, &offset)) return 0; db_info.type = get_type(expr); -- 2.11.4.GIT