Print this page
10063 basic support for smatch
10153 checkpaths shouldn't check packaging exceptions

Split Close
Expand all
Collapse all
          --- old/usr/src/tools/cw/cw.c
          +++ new/usr/src/tools/cw/cw.c
↓ open down ↓ 18 lines elided ↑ open up ↑
  19   19   *
  20   20   * CDDL HEADER END
  21   21   */
  22   22  
  23   23  /*
  24   24   * Copyright 2018, Richard Lowe.
  25   25   */
  26   26  /*
  27   27   * Copyright 2010 Sun Microsystems, Inc.  All rights reserved.
  28   28   * Use is subject to license terms.
       29 + *
       30 + * Copyright 2018 Joyent, Inc.
  29   31   */
  30   32  
  31   33  /*
  32   34   * Wrapper for the GNU C compiler to make it accept the Sun C compiler
  33   35   * arguments where possible.
  34   36   *
  35   37   * Since the translation is inexact, this is something of a work-in-progress.
  36   38   *
  37   39   */
  38   40  
↓ open down ↓ 245 lines elided ↑ open up ↑
 284  286  struct aelist {
 285  287          struct ae {
 286  288                  struct ae *ae_next;
 287  289                  char *ae_arg;
 288  290          } *ael_head, *ael_tail;
 289  291          int ael_argc;
 290  292  };
 291  293  
 292  294  typedef enum {
 293  295          GNU,
 294      -        SUN
      296 +        SUN,
      297 +        SMATCH
 295  298  } compiler_style_t;
 296  299  
 297  300  typedef struct {
 298  301          char *c_name;
 299  302          char *c_path;
 300  303          compiler_style_t c_style;
 301  304  } cw_compiler_t;
 302  305  
 303  306  typedef struct cw_ictx {
 304  307          struct cw_ictx  *i_next;
↓ open down ↓ 959 lines elided ↑ open up ↑
1264 1267                  newae(ctx->i_ae, model);
1265 1268          if (!nolibc)
1266 1269                  newae(ctx->i_ae, "-lc");
1267 1270          if (!seen_o && (ctx->i_flags & CW_F_SHADOW)) {
1268 1271                  newae(ctx->i_ae, "-o");
1269 1272                  newae(ctx->i_ae, ctx->i_discard);
1270 1273          }
1271 1274  }
1272 1275  
1273 1276  static void
     1277 +do_smatch(cw_ictx_t *ctx)
     1278 +{
     1279 +        if (ctx->i_flags & CW_F_PROG) {
     1280 +                newae(ctx->i_ae, "--version");
     1281 +                return;
     1282 +        }
     1283 +
     1284 +        /*
     1285 +         * Some sources shouldn't run smatch at all.
     1286 +         */
     1287 +        for (int i = 0; i < ctx->i_oldargc; i++) {
     1288 +                char *arg = ctx->i_oldargv[i];
     1289 +
     1290 +                if (strcmp(arg, "-_smatch=off") == 0) {
     1291 +                        ctx->i_flags &= ~ (CW_F_EXEC | CW_F_ECHO);
     1292 +                        return;
     1293 +                }
     1294 +        }
     1295 +
     1296 +        /*
     1297 +         * smatch can handle gcc's options.
     1298 +         */
     1299 +        do_gcc(ctx);
     1300 +}
     1301 +
     1302 +static void
1274 1303  do_cc(cw_ictx_t *ctx)
1275 1304  {
1276 1305          int in_output = 0, seen_o = 0;
1277 1306          cw_op_t op = CW_O_LINK;
1278 1307          char *nameflag;
1279 1308  
1280 1309          if (ctx->i_flags & CW_F_PROG) {
1281 1310                  newae(ctx->i_ae, "-V");
1282 1311                  return;
1283 1312          }
↓ open down ↓ 85 lines elided ↑ open up ↑
1369 1398          if (!(ctx->i_flags & CW_F_XLATE))
1370 1399                  return;
1371 1400  
1372 1401          switch (ctx->i_compiler->c_style) {
1373 1402          case SUN:
1374 1403                  do_cc(ctx);
1375 1404                  break;
1376 1405          case GNU:
1377 1406                  do_gcc(ctx);
1378 1407                  break;
     1408 +        case SMATCH:
     1409 +                do_smatch(ctx);
     1410 +                break;
1379 1411          }
1380 1412  }
1381 1413  
1382 1414  static int
1383 1415  invoke(cw_ictx_t *ctx)
1384 1416  {
1385 1417          char **newargv;
1386 1418          int ac;
1387 1419          struct ae *a;
1388 1420  
↓ open down ↓ 164 lines elided ↑ open up ↑
1553 1585          compiler->c_name = token;
1554 1586  
1555 1587          if ((token = strsep(&tspec, ",")) == NULL)
1556 1588                  errx(1, "Compiler is missing a path: %s", spec);
1557 1589          compiler->c_path = token;
1558 1590  
1559 1591          if ((token = strsep(&tspec, ",")) == NULL)
1560 1592                  errx(1, "Compiler is missing a style: %s", spec);
1561 1593  
1562 1594          if ((strcasecmp(token, "gnu") == 0) ||
1563      -            (strcasecmp(token, "gcc") == 0))
     1595 +            (strcasecmp(token, "gcc") == 0)) {
1564 1596                  compiler->c_style = GNU;
1565      -        else if ((strcasecmp(token, "sun") == 0) ||
1566      -            (strcasecmp(token, "cc") == 0))
     1597 +        } else if ((strcasecmp(token, "sun") == 0) ||
     1598 +            (strcasecmp(token, "cc") == 0)) {
1567 1599                  compiler->c_style = SUN;
1568      -        else
     1600 +        } else if ((strcasecmp(token, "smatch") == 0)) {
     1601 +                compiler->c_style = SMATCH;
     1602 +        } else {
1569 1603                  errx(1, "unknown compiler style: %s", token);
     1604 +        }
1570 1605  
1571 1606          if (tspec != NULL)
1572 1607                  errx(1, "Excess tokens in compiler: %s", spec);
1573 1608  }
1574 1609  
1575 1610  int
1576 1611  main(int argc, char **argv)
1577 1612  {
1578 1613          int ch;
1579 1614          cw_compiler_t primary = { NULL, NULL, 0 };
↓ open down ↓ 129 lines elided ↑ open up ↑
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX