Print this page
new smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/show-parse.c
          +++ new/usr/src/tools/smatch/src/show-parse.c
↓ open down ↓ 64 lines elided ↑ open up ↑
  65   65                  [SYM_LABEL] = "labl",
  66   66                  [SYM_RESTRICT] = "rstr",
  67   67                  [SYM_FOULED] = "foul",
  68   68                  [SYM_BAD] = "bad.",
  69   69          };
  70   70          struct context *context;
  71   71          int i;
  72   72  
  73   73          if (!sym)
  74   74                  return;
  75      -        fprintf(stderr, "%.*s%s%3d:%lu %s %s (as: %d) %p (%s:%d:%d) %s\n",
       75 +        fprintf(stderr, "%.*s%s%3d:%lu %s %s (as: %s) %p (%s:%d:%d) %s\n",
  76   76                  indent, indent_string, typestr[sym->type],
  77   77                  sym->bit_size, sym->ctype.alignment,
  78      -                modifier_string(sym->ctype.modifiers), show_ident(sym->ident), sym->ctype.as,
       78 +                modifier_string(sym->ctype.modifiers), show_ident(sym->ident),
       79 +                show_as(sym->ctype.as),
  79   80                  sym, stream_name(sym->pos.stream), sym->pos.line, sym->pos.pos,
  80   81                  builtin_typename(sym) ?: "");
  81   82          i = 0;
  82   83          FOR_EACH_PTR(sym->ctype.contexts, context) {
  83   84                  /* FIXME: should print context expression */
  84   85                  fprintf(stderr, "< context%d: in=%d, out=%d\n",
  85   86                          i, context->in, context->out);
  86   87                  fprintf(stderr, "  end context%d >\n", i);
  87   88                  i++;
  88   89          } END_FOR_EACH_PTR(context);
↓ open down ↓ 29 lines elided ↑ open up ↑
 118  119                  const char *name;
 119  120          } *m;
 120  121  
 121  122          static struct mod_name mod_names[] = {
 122  123                  {MOD_AUTO,              "auto"},
 123  124                  {MOD_REGISTER,          "register"},
 124  125                  {MOD_STATIC,            "static"},
 125  126                  {MOD_EXTERN,            "extern"},
 126  127                  {MOD_CONST,             "const"},
 127  128                  {MOD_VOLATILE,          "volatile"},
      129 +                {MOD_RESTRICT,          "restrict"},
      130 +                {MOD_ATOMIC,            "[atomic]"},
 128  131                  {MOD_SIGNED,            "[signed]"},
 129  132                  {MOD_UNSIGNED,          "[unsigned]"},
 130  133                  {MOD_CHAR,              "[char]"},
 131  134                  {MOD_SHORT,             "[short]"},
 132  135                  {MOD_LONG,              "[long]"},
 133  136                  {MOD_LONGLONG,          "[long long]"},
 134  137                  {MOD_LONGLONGLONG,      "[long long long]"},
 135      -                {MOD_TYPEDEF,           "[typedef]"},
 136  138                  {MOD_TLS,               "[tls]"},
 137  139                  {MOD_INLINE,            "inline"},
 138  140                  {MOD_ADDRESSABLE,       "[addressable]"},
 139  141                  {MOD_NOCAST,            "[nocast]"},
 140  142                  {MOD_NODEREF,           "[noderef]"},
 141      -                {MOD_ACCESSED,          "[accessed]"},
 142  143                  {MOD_TOPLEVEL,          "[toplevel]"},
 143  144                  {MOD_ASSIGNED,          "[assigned]"},
 144  145                  {MOD_TYPE,              "[type]"},
 145  146                  {MOD_SAFE,              "[safe]"},
 146  147                  {MOD_USERTYPE,          "[usertype]"},
 147  148                  {MOD_NORETURN,          "[noreturn]"},
 148  149                  {MOD_EXPLICITLY_SIGNED, "[explicitly-signed]"},
 149  150                  {MOD_BITWISE,           "[bitwise]"},
 150  151                  {MOD_PURE,              "[pure]"},
 151  152          };
↓ open down ↓ 23 lines elided ↑ open up ↑
 175  176          struct symbol *sym;
 176  177          const char *prepend = "";
 177  178  
 178  179          FOR_EACH_PTR(list, sym) {
 179  180                  puts(prepend);
 180  181                  prepend = ", ";
 181  182                  show_symbol(sym);
 182  183          } END_FOR_EACH_PTR(sym);
 183  184  }
 184  185  
      186 +const char *show_as(struct ident *as)
      187 +{
      188 +        if (!as)
      189 +                return "";
      190 +        return show_ident(as);
      191 +}
      192 +
 185  193  struct type_name {
 186  194          char *start;
 187  195          char *end;
 188  196  };
 189  197  
 190  198  static void FORMAT_ATTR(2) prepend(struct type_name *name, const char *fmt, ...)
 191  199  {
 192  200          static char buffer[512];
 193  201          int n;
 194  202  
↓ open down ↓ 16 lines elided ↑ open up ↑
 211  219          n = vsprintf(buffer, fmt, args);
 212  220          va_end(args);
 213  221  
 214  222          memcpy(name->end, buffer, n);
 215  223          name->end += n;
 216  224  }
 217  225  
 218  226  static struct ctype_name {
 219  227          struct symbol *sym;
 220  228          const char *name;
      229 +        const char *suffix;
 221  230  } typenames[] = {
 222      -        { & char_ctype,  "char" },
 223      -        { &schar_ctype,  "signed char" },
 224      -        { &uchar_ctype,  "unsigned char" },
 225      -        { & short_ctype, "short" },
 226      -        { &sshort_ctype, "signed short" },
 227      -        { &ushort_ctype, "unsigned short" },
 228      -        { & int_ctype,   "int" },
 229      -        { &sint_ctype,   "signed int" },
 230      -        { &uint_ctype,   "unsigned int" },
 231      -        { &slong_ctype,  "signed long" },
 232      -        { & long_ctype,  "long" },
 233      -        { &ulong_ctype,  "unsigned long" },
 234      -        { & llong_ctype, "long long" },
 235      -        { &sllong_ctype, "signed long long" },
 236      -        { &ullong_ctype, "unsigned long long" },
 237      -        { & lllong_ctype, "long long long" },
 238      -        { &slllong_ctype, "signed long long long" },
 239      -        { &ulllong_ctype, "unsigned long long long" },
      231 +        { & char_ctype,  "char", "" },
      232 +        { &schar_ctype,  "signed char", "" },
      233 +        { &uchar_ctype,  "unsigned char", "" },
      234 +        { & short_ctype, "short", "" },
      235 +        { &sshort_ctype, "signed short", "" },
      236 +        { &ushort_ctype, "unsigned short", "" },
      237 +        { & int_ctype,   "int", "" },
      238 +        { &sint_ctype,   "signed int", "" },
      239 +        { &uint_ctype,   "unsigned int", "U" },
      240 +        { & long_ctype,  "long", "L" },
      241 +        { &slong_ctype,  "signed long", "L" },
      242 +        { &ulong_ctype,  "unsigned long", "UL" },
      243 +        { & llong_ctype, "long long", "LL" },
      244 +        { &sllong_ctype, "signed long long", "LL" },
      245 +        { &ullong_ctype, "unsigned long long", "ULL" },
      246 +        { & lllong_ctype, "long long long", "LLL" },
      247 +        { &slllong_ctype, "signed long long long", "LLL" },
      248 +        { &ulllong_ctype, "unsigned long long long", "ULLL" },
 240  249  
 241      -        { &void_ctype,   "void" },
 242      -        { &bool_ctype,   "bool" },
 243      -        { &string_ctype, "string" },
      250 +        { &void_ctype,   "void", "" },
      251 +        { &bool_ctype,   "bool", "" },
 244  252  
 245      -        { &float_ctype,  "float" },
 246      -        { &double_ctype, "double" },
 247      -        { &ldouble_ctype,"long double" },
 248      -        { &incomplete_ctype, "incomplete type" },
 249      -        { &int_type, "abstract int" },
 250      -        { &fp_type, "abstract fp" },
 251      -        { &label_ctype, "label type" },
 252      -        { &bad_ctype, "bad type" },
      253 +        { &float_ctype,  "float", "F" },
      254 +        { &double_ctype, "double", "" },
      255 +        { &ldouble_ctype,"long double", "L" },
      256 +        { &incomplete_ctype, "incomplete type", "" },
      257 +        { &int_type, "abstract int", "" },
      258 +        { &fp_type, "abstract fp", "" },
      259 +        { &label_ctype, "label type", "" },
      260 +        { &bad_ctype, "bad type", "" },
 253  261  };
 254  262  
 255  263  const char *builtin_typename(struct symbol *sym)
 256  264  {
 257  265          int i;
 258  266  
 259  267          for (i = 0; i < ARRAY_SIZE(typenames); i++)
 260  268                  if (typenames[i].sym == sym)
 261  269                          return typenames[i].name;
 262  270          return NULL;
 263  271  }
 264  272  
      273 +const char *builtin_type_suffix(struct symbol *sym)
      274 +{
      275 +        int i;
      276 +
      277 +        for (i = 0; i < ARRAY_SIZE(typenames); i++)
      278 +                if (typenames[i].sym == sym)
      279 +                        return typenames[i].suffix;
      280 +        return NULL;
      281 +}
      282 +
 265  283  const char *builtin_ctypename(struct ctype *ctype)
 266  284  {
 267  285          int i;
 268  286  
 269  287          for (i = 0; i < ARRAY_SIZE(typenames); i++)
 270  288                  if (&typenames[i].sym->ctype == ctype)
 271  289                          return typenames[i].name;
 272  290          return NULL;
 273  291  }
 274  292  
 275  293  static void do_show_type(struct symbol *sym, struct type_name *name)
 276  294  {
 277  295          const char *typename;
 278  296          unsigned long mod = 0;
 279      -        int as = 0;
      297 +        struct ident *as = NULL;
 280  298          int was_ptr = 0;
 281  299          int restr = 0;
 282  300          int fouled = 0;
 283  301  
 284  302  deeper:
 285  303          if (!sym || (sym->type != SYM_NODE && sym->type != SYM_ARRAY &&
 286  304                       sym->type != SYM_BITFIELD)) {
 287  305                  const char *s;
 288  306                  size_t len;
 289  307  
 290  308                  if (as)
 291      -                        prepend(name, "<asn:%d>", as);
      309 +                        prepend(name, "%s ", show_as(as));
 292  310  
      311 +                if (sym->type == SYM_BASETYPE || sym->type == SYM_ENUM)
      312 +                        mod &= ~MOD_SPECIFIER;
 293  313                  s = modifier_string(mod);
 294  314                  len = strlen(s);
 295  315                  name->start -= len;    
 296  316                  memcpy(name->start, s, len);  
 297  317                  mod = 0;
 298      -                as = 0;
      318 +                as = NULL;
 299  319          }
 300  320  
 301  321          if (!sym)
 302  322                  goto out;
 303  323  
 304  324          if ((typename = builtin_typename(sym))) {
 305  325                  int len = strlen(typename);
 306  326                  if (name->start != name->end)
 307  327                          *--name->start = ' ';
 308  328                  name->start -= len;
↓ open down ↓ 29 lines elided ↑ open up ↑
 338  358                  if (name->start != name->end)
 339  359                          *--name->start = ' ';
 340  360                  prepend(name, "union %s", show_ident(sym->ident));
 341  361                  goto out;
 342  362  
 343  363          case SYM_ENUM:
 344  364                  prepend(name, "enum %s ", show_ident(sym->ident));
 345  365                  break;
 346  366  
 347  367          case SYM_NODE:
 348      -                append(name, "%s", show_ident(sym->ident));
      368 +                if (sym->ident)
      369 +                        append(name, "%s", show_ident(sym->ident));
 349  370                  mod |= sym->ctype.modifiers;
 350      -                as |= sym->ctype.as;
      371 +                combine_address_space(sym->pos, &as, sym->ctype.as);
 351  372                  break;
 352  373  
 353  374          case SYM_BITFIELD:
 354  375                  mod |= sym->ctype.modifiers;
 355      -                as |= sym->ctype.as;
      376 +                combine_address_space(sym->pos, &as, sym->ctype.as);
 356  377                  append(name, ":%d", sym->bit_size);
 357  378                  break;
 358  379  
 359  380          case SYM_LABEL:
 360  381                  append(name, "label(%s:%p)", show_ident(sym->ident), sym);
 361  382                  return;
 362  383  
 363  384          case SYM_ARRAY:
 364  385                  mod |= sym->ctype.modifiers;
 365      -                as |= sym->ctype.as;
      386 +                combine_address_space(sym->pos, &as, sym->ctype.as);
 366  387                  if (was_ptr) {
 367  388                          prepend(name, "( ");
 368  389                          append(name, " )");
 369  390                          was_ptr = 0;
 370  391                  }
 371  392                  append(name, "[%lld]", get_expression_value(sym->array_size));
 372  393                  break;
 373  394  
 374  395          case SYM_RESTRICT:
 375  396                  if (!sym->ident) {
↓ open down ↓ 17 lines elided ↑ open up ↑
 393  414          }
 394  415  
 395  416          sym = sym->ctype.base_type;
 396  417          goto deeper;
 397  418  
 398  419  out:
 399  420          if (restr)
 400  421                  prepend(name, "restricted ");
 401  422          if (fouled)
 402  423                  prepend(name, "fouled ");
      424 +
      425 +        // strip trailing space
      426 +        if (name->end > name->start && name->end[-1] == ' ')
      427 +                name->end--;
 403  428  }
 404  429  
 405  430  void show_type(struct symbol *sym)
 406  431  {
 407  432          char array[200];
 408  433          struct type_name name;
 409  434  
 410  435          name.start = name.end = array+100;
 411  436          do_show_type(sym, &name);
 412  437          *name.end = 0;
↓ open down ↓ 507 lines elided ↑ open up ↑
 920  945          int new = new_pseudo();
 921  946  
 922  947          if (sym->initializer && sym->initializer->type == EXPR_STRING)
 923  948                  return show_string_expr(sym->initializer);
 924  949  
 925  950          if (sym->ctype.modifiers & (MOD_TOPLEVEL | MOD_EXTERN | MOD_STATIC)) {
 926  951                  printf("\tmovi.%d\t\tv%d,$%s\n", bits_in_pointer, new, show_ident(sym->ident));
 927  952                  return new;
 928  953          }
 929  954          if (sym->ctype.modifiers & MOD_ADDRESSABLE) {
 930      -                printf("\taddi.%d\t\tv%d,vFP,$%lld\n", bits_in_pointer, new, sym->value);
      955 +                printf("\taddi.%d\t\tv%d,vFP,$%lld\n", bits_in_pointer, new, 0LL);
 931  956                  return new;
 932  957          }
 933  958          printf("\taddi.%d\t\tv%d,vFP,$offsetof(%s:%p)\n", bits_in_pointer, new, show_ident(sym->ident), sym);
 934  959          return new;
 935  960  }
 936  961  
 937  962  static int show_symbol_init(struct symbol *sym)
 938  963  {
 939  964          struct expression *expr = sym->initializer;
 940  965  
↓ open down ↓ 1 lines elided ↑ open up ↑
 942  967                  int val, addr, bits;
 943  968  
 944  969                  bits = expr->ctype->bit_size;
 945  970                  val = show_expression(expr);
 946  971                  addr = show_symbol_expr(sym);
 947  972                  show_store_gen(bits, val, NULL, addr);
 948  973          }
 949  974          return 0;
 950  975  }
 951  976  
 952      -static int type_is_signed(struct symbol *sym)
 953      -{
 954      -        if (sym->type == SYM_NODE)
 955      -                sym = sym->ctype.base_type;
 956      -        if (sym->type == SYM_PTR)
 957      -                return 0;
 958      -        return !(sym->ctype.modifiers & MOD_UNSIGNED);
 959      -}
 960      -
 961  977  static int show_cast_expr(struct expression *expr)
 962  978  {
 963  979          struct symbol *old_type, *new_type;
 964  980          int op = show_expression(expr->cast_expression);
 965  981          int oldbits, newbits;
 966  982          int new, is_signed;
 967  983  
 968  984          old_type = expr->cast_expression->ctype;
 969  985          new_type = expr->cast_type;
 970  986          
 971  987          oldbits = old_type->bit_size;
 972  988          newbits = new_type->bit_size;
 973  989          if (oldbits >= newbits)
 974  990                  return op;
 975  991          new = new_pseudo();
 976      -        is_signed = type_is_signed(old_type);
      992 +        is_signed = is_signed_type(old_type);
 977  993          if (is_signed) {
 978  994                  printf("\tsext%d.%d\tv%d,v%d\n", oldbits, newbits, new, op);
 979  995          } else {
 980  996                  printf("\tandl.%d\t\tv%d,v%d,$%lu\n", newbits, new, op, (1UL << oldbits)-1);
 981  997          }
 982  998          return new;
 983  999  }
 984 1000  
 985 1001  static int show_value(struct expression *expr)
 986 1002  {
↓ open down ↓ 2 lines elided ↑ open up ↑
 989 1005  
 990 1006          printf("\tmovi.%d\t\tv%d,$%llu\n", expr->ctype->bit_size, new, value);
 991 1007          return new;
 992 1008  }
 993 1009  
 994 1010  static int show_fvalue(struct expression *expr)
 995 1011  {
 996 1012          int new = new_pseudo();
 997 1013          long double value = expr->fvalue;
 998 1014  
 999      -        printf("\tmovf.%d\t\tv%d,$%Lf\n", expr->ctype->bit_size, new, value);
     1015 +        printf("\tmovf.%d\t\tv%d,$%Le\n", expr->ctype->bit_size, new, value);
1000 1016          return new;
1001 1017  }
1002 1018  
1003 1019  static int show_string_expr(struct expression *expr)
1004 1020  {
1005 1021          int new = new_pseudo();
1006 1022  
1007 1023          printf("\tmovi.%d\t\tv%d,&%s\n", bits_in_pointer, new, show_string(expr->string));
1008 1024          return new;
1009 1025  }
↓ open down ↓ 1 lines elided ↑ open up ↑
1011 1027  static int show_label_expr(struct expression *expr)
1012 1028  {
1013 1029          int new = new_pseudo();
1014 1030          printf("\tmovi.%d\t\tv%d,.L%p\n",bits_in_pointer, new, expr->label_symbol);
1015 1031          return new;
1016 1032  }
1017 1033  
1018 1034  static int show_conditional_expr(struct expression *expr)
1019 1035  {
1020 1036          int cond = show_expression(expr->conditional);
1021      -        int true = show_expression(expr->cond_true);
1022      -        int false = show_expression(expr->cond_false);
     1037 +        int valt = show_expression(expr->cond_true);
     1038 +        int valf = show_expression(expr->cond_false);
1023 1039          int new = new_pseudo();
1024 1040  
1025      -        printf("[v%d]\tcmov.%d\t\tv%d,v%d,v%d\n", cond, expr->ctype->bit_size, new, true, false);
     1041 +        printf("[v%d]\tcmov.%d\t\tv%d,v%d,v%d\n", cond, expr->ctype->bit_size, new, valt, valf);
1026 1042          return new;
1027 1043  }
1028 1044  
1029 1045  static int show_statement_expr(struct expression *expr)
1030 1046  {
1031 1047          return show_statement(expr->statement);
1032 1048  }
1033 1049  
1034 1050  static int show_position_expr(struct expression *expr, struct symbol *base)
1035 1051  {
↓ open down ↓ 126 lines elided ↑ open up ↑
1162 1178                  return 0;
1163 1179          case EXPR_IDENTIFIER:
1164 1180                  warning(expr->pos, "unable to show identifier expression");
1165 1181                  return 0;
1166 1182          case EXPR_INDEX:
1167 1183                  warning(expr->pos, "unable to show index expression");
1168 1184                  return 0;
1169 1185          case EXPR_TYPE:
1170 1186                  warning(expr->pos, "unable to show type expression");
1171 1187                  return 0;
     1188 +        case EXPR_ASM_OPERAND:
     1189 +                warning(expr->pos, "unable to show asm operand expression");
     1190 +                return 0;
1172 1191          }
1173 1192          return 0;
1174 1193  }
    
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX