Print this page
12166 resync smatch to 0.6.1-rc1-il-3

@@ -21,10 +21,11 @@
 # define        SMATCH_H_
 
 #include <stdio.h>
 #include <string.h>
 #include <limits.h>
+#include <float.h>
 #include <sys/time.h>
 #include <sqlite3.h>
 #include "lib.h"
 #include "allocate.h"
 #include "scope.h"

@@ -35,10 +36,13 @@
 typedef struct {
         struct symbol *type;
         union {
                 long long value;
                 unsigned long long uvalue;
+                float fvalue;
+                double dvalue;
+                long double ldvalue;
         };
 } sval_t;
 
 typedef long long mtag_t;
 

@@ -204,10 +208,11 @@
 int get_lineno(void);
 extern int final_pass;
 extern struct symbol *cur_func_sym;
 extern int option_debug;
 extern int local_debug;
+extern int debug_db;
 bool debug_implied(void);
 extern int option_info;
 extern int option_spammy;
 extern int option_timeout;
 extern char *trace_variable;

@@ -238,11 +243,14 @@
  * sm_info(): info message (from option_info)
  * sm_debug(): debug message
  * sm_msg(): other message (please avoid using this)
  */
 
-#define sm_printf(msg...) do { if (final_pass || option_debug || local_debug) fprintf(sm_outfd, msg); } while (0)
+#define sm_printf(msg...) do {                                          \
+        if (final_pass || option_debug || local_debug || debug_db)      \
+                fprintf(sm_outfd, msg);                                 \
+} while (0)
 
 static inline void sm_prefix(void)
 {
         sm_printf("%s: %s:%d %s() ", progname, get_filename(), get_lineno(), get_function());
 }

@@ -252,11 +260,11 @@
 extern bool __silence_warnings_for_stmt;
 
 #define sm_print_msg(type, msg...) \
 do {                                                           \
         print_implied_debug_msg();                             \
-        if (!final_pass && !option_debug && !local_debug)      \
+        if (!final_pass && !option_debug && !local_debug && !debug_db)    \
                 break;                                         \
         if (__silence_warnings_for_stmt && !option_debug && !local_debug) \
                 break;                                         \
         if (!option_info && is_silenced_function())            \
                 break;                                         \

@@ -275,16 +283,10 @@
         sm_printf("\n");                                       \
 } while (0)
 
 #define sm_msg(msg...) do { sm_print_msg(0, msg); } while (0)
 
-#define local_debug(msg...)                                     \
-do {                                                            \
-        if (local_debug)                                        \
-                sm_msg(msg);                                    \
-} while (0)
-
 extern char *implied_debug_msg;
 static inline void print_implied_debug_msg(void)
 {
         static struct symbol *last_printed = NULL;
 

@@ -295,10 +297,11 @@
         last_printed = cur_func_sym;
         sm_msg("%s", implied_debug_msg);
 }
 
 #define sm_debug(msg...) do { if (option_debug) sm_printf(msg); } while (0)
+#define db_debug(msg...) do { if (option_debug || debug_db) sm_printf(msg); } while (0)
 
 #define sm_info(msg...) do {                                    \
         if (option_debug || (option_info && final_pass)) {      \
                 sm_prefix();                                    \
                 sm_printf("info: ");                            \

@@ -436,10 +439,11 @@
 struct statement *get_current_statement(void);
 struct statement *get_prev_statement(void);
 struct expression *get_last_expr_from_expression_stmt(struct expression *expr);
 int get_param_num_from_sym(struct symbol *sym);
 int get_param_num(struct expression *expr);
+struct symbol *get_param_sym_from_num(int num);
 int ms_since(struct timeval *start);
 int parent_is_gone_var_sym(const char *name, struct symbol *sym);
 int parent_is_gone(struct expression *expr);
 int invert_op(int op);
 int op_remove_assign(int op);

@@ -804,12 +808,10 @@
         BUF_SIZE        = 1002,
         CAPPED_DATA     = 1004,
         RETURN_VALUE    = 1005,
         DEREFERENCE     = 1006,
         RANGE_CAP       = 1007,
-        LOCK_HELD       = 1008,
-        LOCK_RELEASED   = 1009,
         ABSOLUTE_LIMITS = 1010,
         PARAM_ADD       = 1012,
         PARAM_FREED     = 1013,
         DATA_SOURCE     = 1014,
         FUZZY_MAX       = 1015,

@@ -843,10 +845,14 @@
         USER_DATA_SET   = 9017,
         NO_OVERFLOW     = 8018,
         NO_OVERFLOW_SIMPLE = 8019,
         LOCKED          = 8020,
         UNLOCKED        = 8021,
+        HALF_LOCKED     = 9022,
+        LOCK_RESTORED   = 9023,
+        KNOWN_LOCKED    = 9024,
+        KNOWN_UNLOCKED  = 9025,
         SET_FS          = 8022,
         ATOMIC_INC      = 8023,
         ATOMIC_DEC      = 8024,
         NO_SIDE_EFFECT  = 8025,
         FN_ARG_LINK     = 8028,

@@ -885,10 +891,11 @@
 const char *get_param_name_var_sym(const char *name, struct symbol *sym);
 const char *get_param_name(struct sm_state *sm);
 const char *get_mtag_name_var_sym(const char *state_name, struct symbol *sym);
 const char *get_mtag_name_expr(struct expression *expr);
 char *get_data_info_name(struct expression *expr);
+char *sm_to_arg_name(struct expression *expr, struct sm_state *sm);
 int is_recursive_member(const char *param_name);
 
 char *escape_newlines(const char *str);
 void sql_exec(struct sqlite3 *db, int (*callback)(void*, int, char**, char**), void *data, const char *sql);
 

@@ -895,11 +902,11 @@
 #define sql_helper(db, call_back, data, sql...)                                 \
 do {                                                                            \
         char sql_txt[1024];                                                     \
                                                                                 \
         sqlite3_snprintf(sizeof(sql_txt), sql_txt, sql);                        \
-        sm_debug("debug: %s\n", sql_txt);                                       \
+        db_debug("debug: %s\n", sql_txt);                                       \
         sql_exec(db, call_back, data, sql_txt);                                 \
 } while (0)
 
 
 #define run_sql(call_back, data, sql...)                                        \

@@ -929,11 +936,11 @@
                 p += snprintf(p, buf + sizeof(buf) - p,                         \
                               "insert %sinto %s values (",                      \
                               ignore ? "or ignore " : "", #table);              \
                 p += snprintf(p, buf + sizeof(buf) - p, values);                \
                 p += snprintf(p, buf + sizeof(buf) - p, ");");                  \
-                sm_debug("mem-db: %s\n", buf);                                  \
+                db_debug("mem-db: %s\n", buf);                                  \
                 rc = sqlite3_exec(_db, buf, NULL, NULL, &err);                  \
                 if (rc != SQLITE_OK) {                                          \
                         sm_ierror("SQL error #2: %s", err);                     \
                         sm_ierror("SQL: '%s'", buf);                            \
                         parse_error = 1;                                        \

@@ -1005,11 +1012,10 @@
 extern char *option_project_str;
 extern char *bin_dir;
 extern char *data_dir;
 extern int option_no_data;
 extern int option_full_path;
-extern int option_param_mapper;
 extern int option_call_tree;
 extern int num_checks;
 
 enum project_type {
         PROJ_NONE,

@@ -1060,10 +1066,11 @@
 /* smatch_return_to_param.c */
 void __add_return_to_param_mapping(struct expression *assign, const char *return_string);
 char *map_call_to_param_name_sym(struct expression *expr, struct symbol **sym);
 
 /* smatch_comparison.c */
+extern int comparison_id;
 #define UNKNOWN_COMPARISON 0
 #define IMPOSSIBLE_COMPARISON -1
 struct compare_data {
         /* The ->left and ->right expression pointers might be NULL (I'm lazy) */
         struct expression *left;

@@ -1115,12 +1122,15 @@
 /* smatch_sval.c */
 sval_t *sval_alloc(sval_t sval);
 sval_t *sval_alloc_permanent(sval_t sval);
 sval_t sval_blank(struct expression *expr);
 sval_t sval_type_val(struct symbol *type, long long val);
+sval_t sval_type_fval(struct symbol *type, long double fval);
 sval_t sval_from_val(struct expression *expr, long long val);
+sval_t sval_from_fval(struct expression *expr, long double fval);
 int sval_is_ptr(sval_t sval);
+bool sval_is_fp(sval_t sval);
 int sval_unsigned(sval_t sval);
 int sval_signed(sval_t sval);
 int sval_bits(sval_t sval);
 int sval_bits_used(sval_t sval);
 int sval_is_negative(sval_t sval);

@@ -1169,10 +1179,14 @@
 struct smatch_state *get_stored_condition(struct expression *expr);
 struct expression_list *get_conditions(struct expression *expr);
 struct sm_state *stored_condition_implication_hook(struct expression *expr,
                         struct state_list **true_stack,
                         struct state_list **false_stack);
+/* smatch_parsed_conditions.c */
+struct sm_state *parsed_condition_implication_hook(struct expression *expr,
+                        struct state_list **true_stack,
+                        struct state_list **false_stack);
 
 /* check_string_len.c */
 int get_formatted_string_size(struct expression *call, int arg);
 int get_formatted_string_min_size(struct expression *call, int arg);
 

@@ -1270,10 +1284,18 @@
                (type->type == SYM_PTR ||
                 type->type == SYM_ARRAY ||
                 type->type == SYM_FN);
 }
 
+static inline bool type_is_fp(struct symbol *type)
+{
+        return type &&
+               (type == &float_ctype ||
+                type == &double_ctype ||
+                type == &ldouble_ctype);
+}
+
 static inline int type_bits(struct symbol *type)
 {
         if (!type)
                 return 0;
         if (type_is_ptr(type))

@@ -1311,14 +1333,57 @@
 }
 
 /*
  * Returns -1 if one is smaller, 0 if they are the same and 1 if two is larger.
  */
+
+static inline int fp_cmp(sval_t one, sval_t two)
+{
+        struct symbol *type;
+
+        if (sval_is_fp(one) && sval_is_fp(two))
+                type = type_bits(one.type) > type_bits(two.type) ? one.type : two.type;
+        else if (sval_is_fp(one))
+                type = one.type;
+        else
+                type = two.type;
+
+        one = sval_cast(type, one);
+        two = sval_cast(type, two);
+
+        if (one.type == &float_ctype) {
+                if (one.fvalue < two.fvalue)
+                        return -1;
+                if (one.fvalue == two.fvalue)
+                        return 0;
+                return 1;
+        }
+        if (one.type == &double_ctype) {
+                if (one.dvalue < two.dvalue)
+                        return -1;
+                if (one.dvalue == two.dvalue)
+                        return 0;
+                return 1;
+        }
+        if (one.type == &ldouble_ctype) {
+                if (one.ldvalue < two.ldvalue)
+                        return -1;
+                if (one.ldvalue == two.ldvalue)
+                        return 0;
+                return 1;
+        }
+        sm_perror("bad type in fp_cmp(): %s", type_to_str(type));
+        return 1;
+}
+
 static inline int sval_cmp(sval_t one, sval_t two)
 {
         struct symbol *type;
 
+        if (sval_is_fp(one) || sval_is_fp(two))
+                return fp_cmp(one, two);
+
         type = one.type;
         if (sval_positive_bits(two) > sval_positive_bits(one))
                 type = two.type;
         if (type_bits(type) < 31)
                 type = &int_ctype;