Print this page
12724 update smatch to 0.6.1-rc1-il-5


 534 
 535         type = get_type(expr);
 536         if (!type || type->type != SYM_PTR)
 537                 return 0;
 538         type = get_real_base_type(type);
 539         if (type == &char_ctype)
 540                 return 1;
 541         return 0;
 542 }
 543 
 544 int is_string(struct expression *expr)
 545 {
 546         expr = strip_expr(expr);
 547         if (!expr || expr->type != EXPR_STRING)
 548                 return 0;
 549         if (expr->string)
 550                 return 1;
 551         return 0;
 552 }
 553 










 554 int is_static(struct expression *expr)
 555 {
 556         char *name;
 557         struct symbol *sym;
 558         int ret = 0;
 559 
 560         name = expr_to_str_sym(expr, &sym);
 561         if (!name || !sym)
 562                 goto free;
 563 
 564         if (sym->ctype.modifiers & MOD_STATIC)
 565                 ret = 1;
 566 free:
 567         free_string(name);
 568         return ret;
 569 }
 570 
 571 bool is_local_variable(struct expression *expr)
 572 {
 573         struct symbol *sym;


 578         if (!(sym->ctype.modifiers & MOD_TOPLEVEL))
 579                 return true;
 580         return false;
 581 }
 582 
 583 int types_equiv(struct symbol *one, struct symbol *two)
 584 {
 585         if (!one && !two)
 586                 return 1;
 587         if (!one || !two)
 588                 return 0;
 589         if (one->type != two->type)
 590                 return 0;
 591         if (one->type == SYM_PTR)
 592                 return types_equiv(get_real_base_type(one), get_real_base_type(two));
 593         if (type_positive_bits(one) != type_positive_bits(two))
 594                 return 0;
 595         return 1;
 596 }
 597 

















 598 int fn_static(void)
 599 {
 600         return !!(cur_func_sym->ctype.modifiers & MOD_STATIC);
 601 }
 602 
 603 const char *global_static(void)
 604 {
 605         if (cur_func_sym->ctype.modifiers & MOD_STATIC)
 606                 return "static";
 607         else
 608                 return "global";
 609 }
 610 
 611 struct symbol *cur_func_return_type(void)
 612 {
 613         struct symbol *sym;
 614 
 615         sym = get_real_base_type(cur_func_sym);
 616         if (!sym || sym->type != SYM_FN)
 617                 return NULL;


 668                 if (strcmp(tmp->ident->name, name) == 0)
 669                         return tmp;
 670 
 671                 chunk_len = tmp->ident->len;
 672                 if (strncmp(tmp->ident->name, name, chunk_len) == 0 &&
 673                     (name[chunk_len] == '.' || name[chunk_len] == '-')) {
 674                         sub = get_real_base_type(tmp);
 675                         if (sub->type == SYM_PTR)
 676                                 sub = get_real_base_type(sub);
 677                         return get_member_from_string(sub->symbol_list, name + chunk_len);
 678                 }
 679 
 680         } END_FOR_EACH_PTR(tmp);
 681 
 682         return NULL;
 683 }
 684 
 685 struct symbol *get_member_type_from_key(struct expression *expr, const char *key)
 686 {
 687         struct symbol *sym;


 688 
 689         if (strcmp(key, "$") == 0)
 690                 return get_type(expr);
 691 
 692         if (strcmp(key, "*$") == 0) {
 693                 sym = get_type(expr);
 694                 if (!sym || sym->type != SYM_PTR)
 695                         return NULL;
 696                 return get_real_base_type(sym);
 697         }
 698 
 699         sym = get_type(expr);
 700         if (!sym)
 701                 return NULL;
 702         if (sym->type == SYM_PTR)
 703                 sym = get_real_base_type(sym);
 704 
 705         key = key + 1;








 706         sym = get_member_from_string(sym->symbol_list, key);
 707         if (!sym)
 708                 return NULL;
 709         return get_real_base_type(sym);







 710 }
 711 
 712 struct symbol *get_arg_type_from_key(struct expression *fn, int param, struct expression *arg, const char *key)
 713 {
 714         struct symbol *type;
 715 
 716         if (!key)
 717                 return NULL;
 718         if (strcmp(key, "$") == 0)
 719                 return get_arg_type(fn, param);
 720         if (strcmp(key, "*$") == 0) {
 721                 type = get_arg_type(fn, param);
 722                 if (!type || type->type != SYM_PTR)
 723                         return NULL;
 724                 return get_real_base_type(type);
 725         }
 726         return get_member_type_from_key(arg, key);
 727 }
 728 
 729 int is_struct(struct expression *expr)




 534 
 535         type = get_type(expr);
 536         if (!type || type->type != SYM_PTR)
 537                 return 0;
 538         type = get_real_base_type(type);
 539         if (type == &char_ctype)
 540                 return 1;
 541         return 0;
 542 }
 543 
 544 int is_string(struct expression *expr)
 545 {
 546         expr = strip_expr(expr);
 547         if (!expr || expr->type != EXPR_STRING)
 548                 return 0;
 549         if (expr->string)
 550                 return 1;
 551         return 0;
 552 }
 553 
 554 bool is_struct_ptr(struct symbol *type)
 555 {
 556         if (!type || type->type != SYM_PTR)
 557                 return false;
 558         type = get_real_base_type(type);
 559         if (!type || type->type != SYM_STRUCT)
 560                 return false;
 561         return true;
 562 }
 563 
 564 int is_static(struct expression *expr)
 565 {
 566         char *name;
 567         struct symbol *sym;
 568         int ret = 0;
 569 
 570         name = expr_to_str_sym(expr, &sym);
 571         if (!name || !sym)
 572                 goto free;
 573 
 574         if (sym->ctype.modifiers & MOD_STATIC)
 575                 ret = 1;
 576 free:
 577         free_string(name);
 578         return ret;
 579 }
 580 
 581 bool is_local_variable(struct expression *expr)
 582 {
 583         struct symbol *sym;


 588         if (!(sym->ctype.modifiers & MOD_TOPLEVEL))
 589                 return true;
 590         return false;
 591 }
 592 
 593 int types_equiv(struct symbol *one, struct symbol *two)
 594 {
 595         if (!one && !two)
 596                 return 1;
 597         if (!one || !two)
 598                 return 0;
 599         if (one->type != two->type)
 600                 return 0;
 601         if (one->type == SYM_PTR)
 602                 return types_equiv(get_real_base_type(one), get_real_base_type(two));
 603         if (type_positive_bits(one) != type_positive_bits(two))
 604                 return 0;
 605         return 1;
 606 }
 607 
 608 bool type_fits(struct symbol *type, struct symbol *test)
 609 {
 610         if (!type || !test)
 611                 return false;
 612 
 613         if (type == test)
 614                 return true;
 615 
 616         if (type_bits(test) > type_bits(type))
 617                 return false;
 618         if (type_signed(test) && !type_signed(type))
 619                 return false;
 620         if (type_positive_bits(test) > type_positive_bits(type))
 621                 return false;
 622         return true;
 623 }
 624 
 625 int fn_static(void)
 626 {
 627         return !!(cur_func_sym->ctype.modifiers & MOD_STATIC);
 628 }
 629 
 630 const char *global_static(void)
 631 {
 632         if (cur_func_sym->ctype.modifiers & MOD_STATIC)
 633                 return "static";
 634         else
 635                 return "global";
 636 }
 637 
 638 struct symbol *cur_func_return_type(void)
 639 {
 640         struct symbol *sym;
 641 
 642         sym = get_real_base_type(cur_func_sym);
 643         if (!sym || sym->type != SYM_FN)
 644                 return NULL;


 695                 if (strcmp(tmp->ident->name, name) == 0)
 696                         return tmp;
 697 
 698                 chunk_len = tmp->ident->len;
 699                 if (strncmp(tmp->ident->name, name, chunk_len) == 0 &&
 700                     (name[chunk_len] == '.' || name[chunk_len] == '-')) {
 701                         sub = get_real_base_type(tmp);
 702                         if (sub->type == SYM_PTR)
 703                                 sub = get_real_base_type(sub);
 704                         return get_member_from_string(sub->symbol_list, name + chunk_len);
 705                 }
 706 
 707         } END_FOR_EACH_PTR(tmp);
 708 
 709         return NULL;
 710 }
 711 
 712 struct symbol *get_member_type_from_key(struct expression *expr, const char *key)
 713 {
 714         struct symbol *sym;
 715         int star = 0;
 716         int i;
 717 
 718         if (strcmp(key, "$") == 0)
 719                 return get_type(expr);
 720 
 721         if (strcmp(key, "*$") == 0) {
 722                 sym = get_type(expr);
 723                 if (!sym || sym->type != SYM_PTR)
 724                         return NULL;
 725                 return get_real_base_type(sym);
 726         }
 727 
 728         sym = get_type(expr);
 729         if (!sym)
 730                 return NULL;
 731         if (sym->type == SYM_PTR)
 732                 sym = get_real_base_type(sym);
 733 
 734         while (*key == '*') {
 735                 key++;
 736                 star++;
 737         }
 738 
 739         if (*key != '$')
 740                 return NULL;
 741         key++;
 742 
 743         sym = get_member_from_string(sym->symbol_list, key);
 744         if (!sym)
 745                 return NULL;
 746         if (sym->type == SYM_RESTRICT || sym->type == SYM_NODE)
 747                 sym = get_real_base_type(sym);
 748         for (i = 0; i < star; i++) {
 749                 if (!sym || sym->type != SYM_PTR)
 750                         return NULL;
 751                 sym = get_real_base_type(sym);
 752         }
 753         return sym;
 754 }
 755 
 756 struct symbol *get_arg_type_from_key(struct expression *fn, int param, struct expression *arg, const char *key)
 757 {
 758         struct symbol *type;
 759 
 760         if (!key)
 761                 return NULL;
 762         if (strcmp(key, "$") == 0)
 763                 return get_arg_type(fn, param);
 764         if (strcmp(key, "*$") == 0) {
 765                 type = get_arg_type(fn, param);
 766                 if (!type || type->type != SYM_PTR)
 767                         return NULL;
 768                 return get_real_base_type(type);
 769         }
 770         return get_member_type_from_key(arg, key);
 771 }
 772 
 773 int is_struct(struct expression *expr)