Print this page
new smatch

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/smatch/src/inline.c
          +++ new/usr/src/tools/smatch/src/inline.c
↓ open down ↓ 24 lines elided ↑ open up ↑
  25   25  
  26   26  #include <stdlib.h>
  27   27  #include <stdio.h>
  28   28  
  29   29  #include "lib.h"
  30   30  #include "allocate.h"
  31   31  #include "token.h"
  32   32  #include "parse.h"
  33   33  #include "symbol.h"
  34   34  #include "expression.h"
       35 +#include "evaluate.h"
  35   36  
       37 +static void copy_statement(struct statement *src, struct statement *dst);
       38 +
  36   39  static struct expression * dup_expression(struct expression *expr)
  37   40  {
  38   41          struct expression *dup = alloc_expression(expr->pos, expr->type);
  39   42          *dup = *expr;
  40   43          return dup;
  41   44  }
  42   45  
  43   46  static struct statement * dup_statement(struct statement *stmt)
  44   47  {
  45   48          struct statement *dup = alloc_statement(stmt->pos, stmt->type);
↓ open down ↓ 125 lines elided ↑ open up ↑
 171  174                          break;
 172  175                  expr = dup_expression(expr);
 173  176                  expr->cast_expression = cast;
 174  177                  break;
 175  178          }
 176  179  
 177  180          /* Conditional expression */
 178  181          case EXPR_SELECT:
 179  182          case EXPR_CONDITIONAL: {
 180  183                  struct expression *cond = copy_expression(expr->conditional);
 181      -                struct expression *true = copy_expression(expr->cond_true);
 182      -                struct expression *false = copy_expression(expr->cond_false);
 183      -                if (cond == expr->conditional && true == expr->cond_true && false == expr->cond_false)
      184 +                struct expression *valt = copy_expression(expr->cond_true);
      185 +                struct expression *valf = copy_expression(expr->cond_false);
      186 +                if (cond == expr->conditional && valt == expr->cond_true && valf == expr->cond_false)
 184  187                          break;
 185  188                  expr = dup_expression(expr);
 186  189                  expr->conditional = cond;
 187      -                expr->cond_true = true;
 188      -                expr->cond_false = false;
      190 +                expr->cond_true = valt;
      191 +                expr->cond_false = valf;
 189  192                  break;
 190  193          }
 191  194  
 192  195          /* Statement expression */
 193  196          case EXPR_STATEMENT: {
 194  197                  struct statement *stmt = alloc_statement(expr->pos, STMT_COMPOUND);
 195  198                  copy_statement(expr->statement, stmt);
 196  199                  expr = dup_expression(expr);
 197  200                  expr->statement = stmt;
 198  201                  break;
↓ open down ↓ 65 lines elided ↑ open up ↑
 264  267                  } else {
 265  268                          struct expression *idx = copy_expression(expr->index);
 266  269                          if (expr->down != val || expr->index != idx) {
 267  270                                  expr = dup_expression(expr);
 268  271                                  expr->down = val;
 269  272                                  expr->index = idx;
 270  273                          }
 271  274                  }
 272  275                  break;
 273  276          }
      277 +        case EXPR_ASM_OPERAND: {
      278 +                expr = dup_expression(expr);
      279 +                expr->constraint = copy_expression(expr->constraint);
      280 +                expr->expr = copy_expression(expr->expr);
      281 +                break;
      282 +        }
 274  283          default:
 275  284                  warning(expr->pos, "trying to copy expression type %d", expr->type);
 276  285          }
 277  286          return expr;
 278  287  }
 279  288  
 280  289  static struct expression_list *copy_asm_constraints(struct expression_list *in)
 281  290  {
 282  291          struct expression_list *out = NULL;
 283  292          struct expression *expr;
 284      -        int state = 0;
 285  293  
 286  294          FOR_EACH_PTR(in, expr) {
 287      -                switch (state) {
 288      -                case 0: /* identifier */
 289      -                case 1: /* constraint */
 290      -                        state++;
 291      -                        add_expression(&out, expr);
 292      -                        continue;
 293      -                case 2: /* expression */
 294      -                        state = 0;
 295      -                        add_expression(&out, copy_expression(expr));
 296      -                        continue;
 297      -                }
      295 +                add_expression(&out, copy_expression(expr));
 298  296          } END_FOR_EACH_PTR(expr);
 299  297          return out;
 300  298  }
 301  299  
 302  300  static void set_replace(struct symbol *old, struct symbol *new)
 303  301  {
 304  302          new->replace = old;
 305  303          old->replace = new;
 306  304  }
 307  305  
↓ open down ↓ 54 lines elided ↑ open up ↑
 362  360                  break;
 363  361          }
 364  362          case STMT_COMPOUND: {
 365  363                  struct statement *new = alloc_statement(stmt->pos, STMT_COMPOUND);
 366  364                  copy_statement(stmt, new);
 367  365                  stmt = new;
 368  366                  break;
 369  367          }
 370  368          case STMT_IF: {
 371  369                  struct expression *cond = stmt->if_conditional;
 372      -                struct statement *true = stmt->if_true;
 373      -                struct statement *false = stmt->if_false;
      370 +                struct statement *valt = stmt->if_true;
      371 +                struct statement *valf = stmt->if_false;
 374  372  
 375  373                  cond = copy_expression(cond);
 376      -                true = copy_one_statement(true);
 377      -                false = copy_one_statement(false);
      374 +                valt = copy_one_statement(valt);
      375 +                valf = copy_one_statement(valf);
 378  376                  if (stmt->if_conditional == cond &&
 379      -                    stmt->if_true == true &&
 380      -                    stmt->if_false == false)
      377 +                    stmt->if_true == valt &&
      378 +                    stmt->if_false == valf)
 381  379                          break;
 382  380                  stmt = dup_statement(stmt);
 383  381                  stmt->if_conditional = cond;
 384      -                stmt->if_true = true;
 385      -                stmt->if_false = false;
      382 +                stmt->if_true = valt;
      383 +                stmt->if_false = valf;
 386  384                  break;
 387  385          }
 388  386          case STMT_RETURN: {
 389  387                  struct expression *retval = copy_expression(stmt->ret_value);
 390  388                  struct symbol *sym = copy_symbol(stmt->pos, stmt->ret_target);
 391  389  
 392  390                  stmt = dup_statement(stmt);
 393  391                  stmt->ret_value = retval;
 394  392                  stmt->ret_target = sym;
 395  393                  break;
↓ open down ↓ 65 lines elided ↑ open up ↑
 461  459  
 462  460  /*
 463  461   * Copy a statement tree from 'src' to 'dst', where both
 464  462   * source and destination are of type STMT_COMPOUND.
 465  463   *
 466  464   * We do this for the tree-level inliner.
 467  465   *
 468  466   * This doesn't do the symbol replacement right: it's not
 469  467   * re-entrant.
 470  468   */
 471      -void copy_statement(struct statement *src, struct statement *dst)
      469 +static void copy_statement(struct statement *src, struct statement *dst)
 472  470  {
 473  471          struct statement *stmt;
 474  472  
 475  473          FOR_EACH_PTR(src->stmts, stmt) {
 476  474                  add_statement(&dst->stmts, copy_one_statement(stmt));
 477  475          } END_FOR_EACH_PTR(stmt);
 478  476          dst->args = copy_one_statement(src->args);
 479  477          dst->ret = copy_symbol(src->pos, src->ret);
 480  478          dst->inline_fn = src->inline_fn;
 481  479  }
↓ open down ↓ 104 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX