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


 117                         unsigned long long neg = ~sval.uvalue;
 118                         if (neg <= sval_type_max(type).uvalue)
 119                                 return 0;
 120                 }
 121                 if (sval.value < sval_type_min(type).value)
 122                         return 1;
 123                 if (sval.value > sval_type_max(type).value)
 124                         return 1;
 125                 return 0;
 126         }
 127         if (sval.uvalue > sval_type_max(type).uvalue)
 128                 return 1;
 129         return 0;
 130 }
 131 
 132 static int truncates_nicely(struct symbol *type, sval_t min, sval_t max)
 133 {
 134         unsigned long long mask;
 135         int bits = type_bits(type);
 136 



 137         if (bits >= type_bits(min.type))
 138                 return 0;
 139 
 140         mask = -1ULL << bits;
 141         return (min.uvalue & mask) == (max.uvalue & mask);
 142 }
 143 
 144 static void add_range_t(struct symbol *type, struct range_list **rl, sval_t min, sval_t max)
 145 {
 146         /* If we're just adding a number, cast it and add it */
 147         if (sval_cmp(min, max) == 0) {
 148                 add_range(rl, sval_cast(type, min), sval_cast(type, max));
 149                 return;
 150         }
 151 
 152         /* If the range is within the type range then add it */
 153         if (sval_fits(type, min) && sval_fits(type, max)) {
 154                 add_range(rl, sval_cast(type, min), sval_cast(type, max));
 155                 return;
 156         }


 415                 return start_rl;
 416 
 417         type = &int_ctype;
 418         if (type_positive_bits(rl_type(start_rl)) > type_positive_bits(type))
 419                 type = rl_type(start_rl);
 420         if (type_positive_bits(rl_type(right_orig)) > type_positive_bits(type))
 421                 type = rl_type(right_orig);
 422 
 423         casted_start = cast_rl(type, start_rl);
 424         right_orig = cast_rl(type, right_orig);
 425 
 426         filter_by_comparison(&casted_start, comparison, right_orig);
 427         return cast_rl(rl_type(start_rl), casted_start);
 428 }
 429 
 430 static sval_t parse_val(int use_max, struct expression *call, struct symbol *type, const char *c, const char **endp)
 431 {
 432         const char *start = c;
 433         sval_t ret;
 434 







 435         if (!strncmp(start, "max", 3)) {
 436                 ret = sval_type_max(type);
 437                 c += 3;
 438         } else if (!strncmp(start, "u64max", 6)) {
 439                 ret = sval_type_val(type, ULLONG_MAX);
 440                 c += 6;
 441         } else if (!strncmp(start, "s64max", 6)) {
 442                 ret = sval_type_val(type, LLONG_MAX);
 443                 c += 6;
 444         } else if (!strncmp(start, "u32max", 6)) {
 445                 ret = sval_type_val(type, UINT_MAX);
 446                 c += 6;
 447         } else if (!strncmp(start, "s32max", 6)) {
 448                 ret = sval_type_val(type, INT_MAX);
 449                 c += 6;
 450         } else if (!strncmp(start, "u16max", 6)) {
 451                 ret = sval_type_val(type, USHRT_MAX);
 452                 c += 6;
 453         } else if (!strncmp(start, "s16max", 6)) {
 454                 ret = sval_type_val(type, SHRT_MAX);


 547                 if (*c == ')')
 548                         c++;
 549                 if (*c == '\0' || *c == '[') {
 550                         add_range_t(type, &rl_tmp, min, min);
 551                         break;
 552                 }
 553                 if (*c == ',') {
 554                         add_range_t(type, &rl_tmp, min, min);
 555                         c++;
 556                         continue;
 557                 }
 558                 if (*c == '+') {
 559                         min = prev_min;
 560                         max = sval_type_max(type);
 561                         add_range_t(type, &rl_tmp, min, max);
 562                         c++;
 563                         if (*c == '[' || *c == '\0')
 564                                 break;
 565                 }
 566                 if (*c != '-') {
 567                         sm_msg("debug XXX: trouble parsing %s c = %s", str, c);
 568                         break;
 569                 }
 570                 c++;
 571                 if (*c == '(')
 572                         c++;
 573                 max = parse_val(1, call, type, c, &c);
 574                 if (!sval_fits(type, max))
 575                         max = sval_type_max(type);
 576                 if (*c == '+') {
 577                         max = sval_type_max(type);
 578                         add_range_t(type, &rl_tmp, min, max);
 579                         c++;
 580                         if (*c == '[' || *c == '\0')
 581                                 break;
 582                 }
 583                 prev_min = max;
 584                 add_range_t(type, &rl_tmp, min, max);
 585                 if (*c == ')')
 586                         c++;
 587                 if (*c == ',')




 117                         unsigned long long neg = ~sval.uvalue;
 118                         if (neg <= sval_type_max(type).uvalue)
 119                                 return 0;
 120                 }
 121                 if (sval.value < sval_type_min(type).value)
 122                         return 1;
 123                 if (sval.value > sval_type_max(type).value)
 124                         return 1;
 125                 return 0;
 126         }
 127         if (sval.uvalue > sval_type_max(type).uvalue)
 128                 return 1;
 129         return 0;
 130 }
 131 
 132 static int truncates_nicely(struct symbol *type, sval_t min, sval_t max)
 133 {
 134         unsigned long long mask;
 135         int bits = type_bits(type);
 136 
 137         if (type_is_fp(min.type) && !type_is_fp(type))
 138                 return 0;
 139 
 140         if (bits >= type_bits(min.type))
 141                 return 0;
 142 
 143         mask = -1ULL << bits;
 144         return (min.uvalue & mask) == (max.uvalue & mask);
 145 }
 146 
 147 static void add_range_t(struct symbol *type, struct range_list **rl, sval_t min, sval_t max)
 148 {
 149         /* If we're just adding a number, cast it and add it */
 150         if (sval_cmp(min, max) == 0) {
 151                 add_range(rl, sval_cast(type, min), sval_cast(type, max));
 152                 return;
 153         }
 154 
 155         /* If the range is within the type range then add it */
 156         if (sval_fits(type, min) && sval_fits(type, max)) {
 157                 add_range(rl, sval_cast(type, min), sval_cast(type, max));
 158                 return;
 159         }


 418                 return start_rl;
 419 
 420         type = &int_ctype;
 421         if (type_positive_bits(rl_type(start_rl)) > type_positive_bits(type))
 422                 type = rl_type(start_rl);
 423         if (type_positive_bits(rl_type(right_orig)) > type_positive_bits(type))
 424                 type = rl_type(right_orig);
 425 
 426         casted_start = cast_rl(type, start_rl);
 427         right_orig = cast_rl(type, right_orig);
 428 
 429         filter_by_comparison(&casted_start, comparison, right_orig);
 430         return cast_rl(rl_type(start_rl), casted_start);
 431 }
 432 
 433 static sval_t parse_val(int use_max, struct expression *call, struct symbol *type, const char *c, const char **endp)
 434 {
 435         const char *start = c;
 436         sval_t ret;
 437 
 438         if (type == &float_ctype)
 439                 return sval_type_fval(type, strtof(start, (char **)endp));
 440         else if (type == &double_ctype)
 441                 return sval_type_fval(type, strtod(start, (char **)endp));
 442         else if (type == &ldouble_ctype)
 443                 return sval_type_fval(type, strtold(start, (char **)endp));
 444 
 445         if (!strncmp(start, "max", 3)) {
 446                 ret = sval_type_max(type);
 447                 c += 3;
 448         } else if (!strncmp(start, "u64max", 6)) {
 449                 ret = sval_type_val(type, ULLONG_MAX);
 450                 c += 6;
 451         } else if (!strncmp(start, "s64max", 6)) {
 452                 ret = sval_type_val(type, LLONG_MAX);
 453                 c += 6;
 454         } else if (!strncmp(start, "u32max", 6)) {
 455                 ret = sval_type_val(type, UINT_MAX);
 456                 c += 6;
 457         } else if (!strncmp(start, "s32max", 6)) {
 458                 ret = sval_type_val(type, INT_MAX);
 459                 c += 6;
 460         } else if (!strncmp(start, "u16max", 6)) {
 461                 ret = sval_type_val(type, USHRT_MAX);
 462                 c += 6;
 463         } else if (!strncmp(start, "s16max", 6)) {
 464                 ret = sval_type_val(type, SHRT_MAX);


 557                 if (*c == ')')
 558                         c++;
 559                 if (*c == '\0' || *c == '[') {
 560                         add_range_t(type, &rl_tmp, min, min);
 561                         break;
 562                 }
 563                 if (*c == ',') {
 564                         add_range_t(type, &rl_tmp, min, min);
 565                         c++;
 566                         continue;
 567                 }
 568                 if (*c == '+') {
 569                         min = prev_min;
 570                         max = sval_type_max(type);
 571                         add_range_t(type, &rl_tmp, min, max);
 572                         c++;
 573                         if (*c == '[' || *c == '\0')
 574                                 break;
 575                 }
 576                 if (*c != '-') {
 577                         sm_debug("XXX: trouble parsing %s c = %s", str, c);
 578                         break;
 579                 }
 580                 c++;
 581                 if (*c == '(')
 582                         c++;
 583                 max = parse_val(1, call, type, c, &c);
 584                 if (!sval_fits(type, max))
 585                         max = sval_type_max(type);
 586                 if (*c == '+') {
 587                         max = sval_type_max(type);
 588                         add_range_t(type, &rl_tmp, min, max);
 589                         c++;
 590                         if (*c == '[' || *c == '\0')
 591                                 break;
 592                 }
 593                 prev_min = max;
 594                 add_range_t(type, &rl_tmp, min, max);
 595                 if (*c == ')')
 596                         c++;
 597                 if (*c == ',')