From 32a672087e68a564dcc0c359fcaf02acac61cc33 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 6 Mar 2014 13:21:25 +0300 Subject: [PATCH] comparison: don't record that actual structs are equivalent Say you have: struct foo a, b; a = b; We should record that the struct members are equivalent but it isn't useful to record that the structs themselves are equivalent. Signed-off-by: Dan Carpenter --- smatch.h | 1 + smatch_comparison.c | 3 +++ smatch_type.c | 10 ++++++++++ 3 files changed, 14 insertions(+) diff --git a/smatch.h b/smatch.h index 5b438d26..6979c2a4 100644 --- a/smatch.h +++ b/smatch.h @@ -330,6 +330,7 @@ const char *global_static(); struct symbol *cur_func_return_type(void); struct symbol *get_arg_type(struct expression *fn, int arg); struct symbol *get_member_type_from_key(struct expression *expr, char *key); +int is_struct(struct expression *expr); /* smatch_ignore.c */ void add_ignore(int owner, const char *name, struct symbol *sym); diff --git a/smatch_comparison.c b/smatch_comparison.c index de16674b..76a863d7 100644 --- a/smatch_comparison.c +++ b/smatch_comparison.c @@ -988,6 +988,9 @@ static void match_assign(struct expression *expr) if (expr->op != '=') return; + if (is_struct(expr->left)) + return; + copy_comparisons(expr->left, expr->right); add_comparison(expr->left, SPECIAL_EQUAL, expr->right); diff --git a/smatch_type.c b/smatch_type.c index d800913e..c23f01c3 100644 --- a/smatch_type.c +++ b/smatch_type.c @@ -522,3 +522,13 @@ struct symbol *get_member_type_from_key(struct expression *expr, char *key) return NULL; return get_real_base_type(sym); } + +int is_struct(struct expression *expr) +{ + struct symbol *type; + + type = get_type(expr); + if (type && type->type == SYM_STRUCT) + return 1; + return 0; +} -- 2.11.4.GIT