Print this page
11506 smatch resync

@@ -34,15 +34,13 @@
 
         *rl = strtoul(argv[0], NULL, 10);
         return 0;
 }
 
-static struct range_list *select_orig_rl(sval_t sval)
+static struct range_list *select_orig(mtag_t tag, int offset)
 {
         struct range_list *rl = NULL;
-        mtag_t tag = sval.uvalue & ~MTAG_OFFSET_MASK;
-        int offset = sval.uvalue & MTAG_OFFSET_MASK;
 
         mem_sql(&save_rl, &rl, "select value from mtag_data where tag = %lld and offset = %d;",
                 tag, offset);
         return rl;
 }

@@ -69,15 +67,12 @@
         } END_FOR_EACH_SM(tmp);
 
         return 0;
 }
 
-void insert_mtag_data(sval_t sval, struct range_list *rl)
+static void insert_mtag_data(mtag_t tag, int offset, struct range_list *rl)
 {
-        mtag_t tag = sval.uvalue & ~MTAG_OFFSET_MASK;
-        int offset = sval.uvalue & MTAG_OFFSET_MASK;
-
         rl = clone_rl_permanent(rl);
 
         mem_sql(NULL, NULL, "delete from mtag_data where tag = %lld and offset = %d and type = %d",
                 tag, offset, DATA_VALUE);
         mem_sql(NULL, NULL, "insert into mtag_data values (%lld, %d, %d, '%lu');",

@@ -85,48 +80,57 @@
 }
 
 void update_mtag_data(struct expression *expr)
 {
         struct range_list *orig, *new, *rl;
+        struct symbol *type;
         char *name;
-        sval_t sval;
+        mtag_t tag;
+        int offset;
 
         name = expr_to_var(expr);
         if (is_kernel_param(name)) {
                 free_string(name);
                 return;
         }
         free_string(name);
 
-        if (!get_mtag_addr_sval(expr, &sval))
+        if (!expr_to_mtag_offset(expr, &tag, &offset))
                 return;
 
+        type = get_type(expr);
+        if ((offset == 0) &&
+            (!type || type == &void_ctype ||
+             type->type == SYM_STRUCT || type->type == SYM_UNION || type->type == SYM_ARRAY))
+                return;
+
         get_absolute_rl(expr, &rl);
 
-        orig = select_orig_rl(sval);
+        orig = select_orig(tag, offset);
         new = rl_union(orig, rl);
-        insert_mtag_data(sval, new);
+        insert_mtag_data(tag, offset, new);
 }
 
 static void match_global_assign(struct expression *expr)
 {
         struct range_list *rl;
-        sval_t sval;
+        mtag_t tag;
+        int offset;
         char *name;
 
         name = expr_to_var(expr->left);
         if (is_kernel_param(name)) {
                 free_string(name);
                 return;
         }
         free_string(name);
 
-        if (!get_mtag_addr_sval(expr->left, &sval))
+        if (!expr_to_mtag_offset(expr->left, &tag, &offset))
                 return;
 
         get_absolute_rl(expr->right, &rl);
-        insert_mtag_data(sval, rl);
+        insert_mtag_data(tag, offset, rl);
 }
 
 static int save_mtag_data(void *_unused, int argc, char **argv, char **azColName)
 {
         struct range_list *rl;

@@ -169,40 +173,37 @@
 
         return 0;
 }
 
 struct db_cache_results {
-        sval_t sval;
+        mtag_t tag;
         struct range_list *rl;
 };
 static struct db_cache_results cached_results[8];
 
-static int get_rl_from_mtag_sval(sval_t sval, struct symbol *type, struct range_list **rl)
+static int get_rl_from_mtag_offset(mtag_t tag, int offset, struct symbol *type, struct range_list **rl)
 {
         struct db_info db_info = {};
-        mtag_t tag;
-        int offset;
+        mtag_t merged = tag | offset;
         static int idx;
         int ret;
         int i;
 
+        if (!type || type == &void_ctype ||
+            (type->type == SYM_STRUCT || type->type == SYM_ARRAY || type->type == SYM_UNION))
+                return 0;
+
         for (i = 0; i < ARRAY_SIZE(cached_results); i++) {
-                if (sval.uvalue == cached_results[i].sval.uvalue) {
+                if (merged == cached_results[i].tag) {
                         if (cached_results[i].rl) {
                                 *rl = cached_results[i].rl;
                                 return 1;
                         }
                         return 0;
                 }
         }
 
-        tag = sval.uvalue & ~MTAG_OFFSET_MASK;
-        offset = sval.uvalue & MTAG_OFFSET_MASK;
-        if (offset == MTAG_OFFSET_MASK) {
-                ret = 0;
-                goto update_cache;
-        }
         db_info.type = type;
 
         run_sql(get_vals, &db_info,
                 "select value from mtag_data where tag = %lld and offset = %d and type = %d;",
                 tag, offset, DATA_VALUE);

@@ -214,11 +215,11 @@
 
         *rl = db_info.rl;
         ret = 1;
 
 update_cache:
-        cached_results[idx].sval = sval;
+        cached_results[idx].tag = merged;
         cached_results[idx].rl = db_info.rl;
         idx = (idx + 1) % ARRAY_SIZE(cached_results);
 
         return ret;
 }

@@ -229,20 +230,23 @@
 }
 
 int get_mtag_rl(struct expression *expr, struct range_list **rl)
 {
         struct symbol *type;
-        sval_t sval;
+        mtag_t tag;
+        int offset;
 
-        if (!get_mtag_addr_sval(expr, &sval))
+        if (!expr_to_mtag_offset(expr, &tag, &offset))
                 return 0;
+        if (offset >= MTAG_OFFSET_MASK)
+                return 0;
 
         type = get_type(expr);
         if (!type)
                 return 0;
 
-        return get_rl_from_mtag_sval(sval, type, rl);
+        return get_rl_from_mtag_offset(tag, offset, type, rl);
 }
 
 void register_mtag_data(int id)
 {
         my_id = id;