Print this page
10063 basic support for smatch
10153 checkpaths shouldn't check packaging exceptions
@@ -24,10 +24,12 @@
* Copyright 2018, Richard Lowe.
*/
/*
* Copyright 2010 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
+ *
+ * Copyright 2018 Joyent, Inc.
*/
/*
* Wrapper for the GNU C compiler to make it accept the Sun C compiler
* arguments where possible.
@@ -289,11 +291,12 @@
int ael_argc;
};
typedef enum {
GNU,
- SUN
+ SUN,
+ SMATCH
} compiler_style_t;
typedef struct {
char *c_name;
char *c_path;
@@ -1269,10 +1272,36 @@
newae(ctx->i_ae, ctx->i_discard);
}
}
static void
+do_smatch(cw_ictx_t *ctx)
+{
+ if (ctx->i_flags & CW_F_PROG) {
+ newae(ctx->i_ae, "--version");
+ return;
+ }
+
+ /*
+ * Some sources shouldn't run smatch at all.
+ */
+ for (int i = 0; i < ctx->i_oldargc; i++) {
+ char *arg = ctx->i_oldargv[i];
+
+ if (strcmp(arg, "-_smatch=off") == 0) {
+ ctx->i_flags &= ~ (CW_F_EXEC | CW_F_ECHO);
+ return;
+ }
+ }
+
+ /*
+ * smatch can handle gcc's options.
+ */
+ do_gcc(ctx);
+}
+
+static void
do_cc(cw_ictx_t *ctx)
{
int in_output = 0, seen_o = 0;
cw_op_t op = CW_O_LINK;
char *nameflag;
@@ -1374,10 +1403,13 @@
do_cc(ctx);
break;
case GNU:
do_gcc(ctx);
break;
+ case SMATCH:
+ do_smatch(ctx);
+ break;
}
}
static int
invoke(cw_ictx_t *ctx)
@@ -1558,17 +1590,20 @@
if ((token = strsep(&tspec, ",")) == NULL)
errx(1, "Compiler is missing a style: %s", spec);
if ((strcasecmp(token, "gnu") == 0) ||
- (strcasecmp(token, "gcc") == 0))
+ (strcasecmp(token, "gcc") == 0)) {
compiler->c_style = GNU;
- else if ((strcasecmp(token, "sun") == 0) ||
- (strcasecmp(token, "cc") == 0))
+ } else if ((strcasecmp(token, "sun") == 0) ||
+ (strcasecmp(token, "cc") == 0)) {
compiler->c_style = SUN;
- else
+ } else if ((strcasecmp(token, "smatch") == 0)) {
+ compiler->c_style = SMATCH;
+ } else {
errx(1, "unknown compiler style: %s", token);
+ }
if (tspec != NULL)
errx(1, "Excess tokens in compiler: %s", spec);
}