From: Dan Carpenter Date: Mon, 19 Nov 2012 16:32:33 +0000 (+0300) Subject: sval: type: use type_bits() through out. X-Git-Tag: 1.57~186 X-Git-Url: https://repo.or.cz/w/smatch.git/commitdiff_plain/af6b9dc9b1dad6ceea9cd80c3aa1092003c56434 sval: type: use type_bits() through out. This changes things a little because sval_bits() used to assume an int if the type wasn't specified but type_bits() returns zero. Signed-off-by: Dan Carpenter --- diff --git a/smatch_sval.c b/smatch_sval.c index d91d426a..631503a2 100644 --- a/smatch_sval.c +++ b/smatch_sval.c @@ -84,18 +84,12 @@ int sval_signed(sval_t sval) int sval_bits(sval_t sval) { - if (!sval.type) - return 32; - return sval.type->bit_size; + return type_bits(sval.type); } int sval_positive_bits(sval_t sval) { - if (!sval.type) - return 31; - if (sval_signed(sval)) - return sval.type->bit_size - 1; - return sval.type->bit_size; + return type_positive_bits(sval.type); } int sval_bits_used(sval_t sval) diff --git a/smatch_type.c b/smatch_type.c index 3cc6d67a..614235c9 100644 --- a/smatch_type.c +++ b/smatch_type.c @@ -36,8 +36,8 @@ int type_positive_bits(struct symbol *type) if (!type) return 0; if (type_unsigned(type)) - return type->bit_size; - return type->bit_size - 1; + return type_bits(type); + return type_bits(type) - 1; } static struct symbol *get_binop_type(struct expression *expr) @@ -302,11 +302,7 @@ sval_t sval_type_max(struct symbol *base_type) if (!base_type || !base_type->bit_size) return ret; - if (type_unsigned(base_type)) - ret.value = (~0ULL) >> (64 - base_type->bit_size); - else - ret.value = (~0ULL) >> (64 - (base_type->bit_size - 1)); - + ret.value = (~0ULL) >> (64 - type_positive_bits(base_type)); return ret; } @@ -323,7 +319,7 @@ sval_t sval_type_min(struct symbol *base_type) return ret; } - ret.value = (~0ULL) << (base_type->bit_size - 1); + ret.value = (~0ULL) << type_positive_bits(base_type); return ret; } @@ -335,7 +331,7 @@ int nr_bits(struct expression *expr) type = get_type(expr); if (!type) return 0; - return type->bit_size; + return type_bits(type); } int is_static(struct expression *expr)