summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--8/isel.c6
-rw-r--r--8/reduce.c22
-rw-r--r--mk/c.mk2
-rw-r--r--opt/cfg.c12
-rw-r--r--opt/opt.h2
-rw-r--r--parse/bitset.c14
-rw-r--r--parse/dump.c6
-rw-r--r--parse/htab.c3
-rw-r--r--parse/infer.c20
-rw-r--r--parse/node.c6
-rw-r--r--parse/parse.h10
-rw-r--r--parse/pickle.c93
-rw-r--r--parse/type.c12
13 files changed, 118 insertions, 90 deletions
diff --git a/8/isel.c b/8/isel.c
index 1d79185..0d0e4eb 100644
--- a/8/isel.c
+++ b/8/isel.c
@@ -322,7 +322,7 @@ static Loc memloc(Isel *s, Node *e, Mode m)
Loc gencall(Isel *s, Node *n)
{
int argsz, argoff;
- int i;
+ size_t i;
Loc eax, esp; /* hard-coded registers */
Loc stkbump; /* calculated stack offset */
Loc dst, arg, fn; /* values we reduced */
@@ -707,7 +707,7 @@ void epilogue(Isel *s)
static void writeasm(Func *fn, Isel *is, FILE *fd)
{
- int i;
+ size_t i;
if (fn->isglobl)
fprintf(fd, ".globl %s\n", fn->name);
@@ -722,7 +722,7 @@ static void writeasm(Func *fn, Isel *is, FILE *fd)
void genasm(FILE *fd, Func *fn, Htab *globls)
{
struct Isel is = {0,};
- int i;
+ size_t i;
is.locs = fn->locs;
is.globls = globls;
diff --git a/8/reduce.c b/8/reduce.c
index f0acd38..3b47597 100644
--- a/8/reduce.c
+++ b/8/reduce.c
@@ -72,7 +72,7 @@ int isconstfn(Sym *s)
static char *asmname(Node *n)
{
- int i;
+ size_t i;
char *s;
char *sep;
int len;
@@ -94,7 +94,7 @@ static char *asmname(Node *n)
size_t tysize(Type *t)
{
size_t sz;
- int i;
+ size_t i;
sz = 0;
switch (t->type) {
@@ -245,7 +245,7 @@ void simploop(Simp *s, Node *n)
void simpblk(Simp *s, Node *n)
{
- int i;
+ size_t i;
for (i = 0; i < n->block.nstmts; i++) {
simp(s, n->block.stmts[i]);
@@ -256,7 +256,7 @@ static size_t offsetof(Node *aggr, Node *memb)
{
Type *ty;
Node **nl;
- int nn, i;
+ size_t nn, i;
size_t off;
if (aggr->expr.type->type == Typtr)
@@ -395,7 +395,7 @@ Node *rval(Simp *s, Node *n)
{
Node *r; /* expression result */
Node *t, *u, *v; /* temporary nodes */
- int i;
+ size_t i;
Node **args;
const Op fusedmap[] = {
[Oaddeq] = Oadd,
@@ -541,7 +541,7 @@ void declarearg(Simp *s, Node *n)
Node *simp(Simp *s, Node *n)
{
Node *r;
- int i;
+ size_t i;
if (!n)
return NULL;
@@ -583,7 +583,7 @@ Node *simp(Simp *s, Node *n)
void reduce(Simp *s, Node *f)
{
- int i;
+ size_t i;
assert(f->type == Nfunc);
s->nstmts = 0;
@@ -605,7 +605,7 @@ void reduce(Simp *s, Node *f)
static void lowerfn(char *name, Node *n, Htab *globls, FILE *fd)
{
- int i;
+ size_t i;
Simp s = {0,};
Func fn;
Cfg *cfg;
@@ -622,8 +622,8 @@ static void lowerfn(char *name, Node *n, Htab *globls, FILE *fd)
reduce(&s, n);
if (debug)
- for (i = 0; i < s.nstmts; i++)
- dump(s.stmts[i], stdout);
+ for (i = 0; i < s.nstmts; i++)
+ dump(s.stmts[i], stdout);
cfg = mkcfg(s.stmts, s.nstmts);
if (debug)
dumpcfg(cfg, stdout);
@@ -640,7 +640,7 @@ static void lowerfn(char *name, Node *n, Htab *globls, FILE *fd)
void blobdump(Blob *b, FILE *fd)
{
- int i;
+ size_t i;
char *p;
p = b->data;
diff --git a/mk/c.mk b/mk/c.mk
index 4e6e3be..d2524e3 100644
--- a/mk/c.mk
+++ b/mk/c.mk
@@ -1,7 +1,7 @@
DEPSDIR = .deps
DEPS=$(addprefix $(DEPSDIR)/, $(OBJ:.o=.d))
-CFLAGS += -Wall -Werror
+CFLAGS += -Wall -Werror -Wextra -Wno-unused-parameter -Wno-missing-field-initializers
CFLAGS += -g
CFLAGS += -MMD -MP -MF ${DEPSDIR}/$(subst /,-,$*).d
diff --git a/opt/cfg.c b/opt/cfg.c
index 04ab335..92e3d50 100644
--- a/opt/cfg.c
+++ b/opt/cfg.c
@@ -50,12 +50,12 @@ int addnode(Cfg *cfg, Bb *bb, Node *n)
return 0;
}
-Cfg *mkcfg(Node **nl, int nn)
+Cfg *mkcfg(Node **nl, size_t nn)
{
Cfg *cfg;
Bb *bb, *targ;
Node *a, *b;
- int i;
+ size_t i;
cfg = zalloc(sizeof(Cfg));
cfg->lblmap = mkht(strhash, streq);
@@ -116,7 +116,7 @@ Cfg *mkcfg(Node **nl, int nn)
}
void dumpcfg(Cfg *cfg, FILE *fd)
{
- int i, j;
+ size_t i, j;
Bb *bb;
char *sep;
@@ -125,7 +125,7 @@ void dumpcfg(Cfg *cfg, FILE *fd)
fprintf(fd, "\n");
fprintf(fd, "Bb: %d labels=(", bb->id);
sep = "";
- for (i = 0; i < bb->nlbls; i++) {
+ for (i = 0; i < bb->nlbls; i++) {;
fprintf(fd, "%s%s", bb->lbls[i], sep);
sep = ",";
}
@@ -136,7 +136,7 @@ void dumpcfg(Cfg *cfg, FILE *fd)
sep = "";
for (i = 0; i < bsmax(bb->in); i++) {
if (bshas(bb->in, i)) {
- fprintf(fd, "%s%d", sep, i);
+ fprintf(fd, "%s%zd", sep, i);
sep = ",";
}
}
@@ -147,7 +147,7 @@ void dumpcfg(Cfg *cfg, FILE *fd)
sep = "";
for (i = 0; i < bsmax(bb->out); i++) {
if (bshas(bb->out, i)) {
- fprintf(fd, "%s%d", sep, i);
+ fprintf(fd, "%s%zd", sep, i);
sep = ",";
}
}
diff --git a/opt/opt.h b/opt/opt.h
index dbf7dce..d875dbd 100644
--- a/opt/opt.h
+++ b/opt/opt.h
@@ -24,6 +24,6 @@ struct Bb {
};
/* Takes a reduced block, and returns a flow graph. */
-Cfg *mkcfg(Node **nl, int nn);
+Cfg *mkcfg(Node **nl, size_t nn);
void dumpcfg(Cfg *c, FILE *fd);
void flow(Cfg *cfg);
diff --git a/parse/bitset.c b/parse/bitset.c
index 153b602..b0ec557 100644
--- a/parse/bitset.c
+++ b/parse/bitset.c
@@ -44,9 +44,9 @@ Bitset *dupbs(Bitset *a)
return bs;
}
-int bscount(Bitset *bs)
+size_t bscount(Bitset *bs)
{
- int i, j, n;
+ size_t i, j, n;
n = 0;
for (i = 0; i < bs->nchunks; i++)
@@ -59,7 +59,7 @@ int bscount(Bitset *bs)
/* Returns the largest value that the bitset can possibly
* hold. It's conservative, but scanning the entire bitset
* is a bit slow. This is mostly an aid to iterate over it. */
-int bsmax(Bitset *bs)
+size_t bsmax(Bitset *bs)
{
return bs->nchunks*sizeof(uint)*CHAR_BIT;
}
@@ -97,7 +97,7 @@ int bshas(Bitset *bs, uint elt)
void bsunion(Bitset *a, Bitset *b)
{
- int i;
+ size_t i;
eqsz(a, b);
for (i = 0; i < a->nchunks; i++)
@@ -106,7 +106,7 @@ void bsunion(Bitset *a, Bitset *b)
void bsintersect(Bitset *a, Bitset *b)
{
- int i;
+ size_t i;
eqsz(a, b);
for (i = 0; i < a->nchunks; i++)
@@ -115,7 +115,7 @@ void bsintersect(Bitset *a, Bitset *b)
void bsdiff(Bitset *a, Bitset *b)
{
- int i;
+ size_t i;
eqsz(a, b);
for (i = 0; i < a->nchunks; i++)
@@ -124,7 +124,7 @@ void bsdiff(Bitset *a, Bitset *b)
int bsissubset(Bitset *set, Bitset *sub)
{
- int i;
+ size_t i;
eqsz(set, sub);
for (i = 0; i < set->nchunks; i++)
diff --git a/parse/dump.c b/parse/dump.c
index 0999052..ebb1378 100644
--- a/parse/dump.c
+++ b/parse/dump.c
@@ -20,9 +20,9 @@ static void indent(FILE *fd, int depth)
static void outname(Node *n, FILE *fd)
{
- int i;
+ size_t i;
char *sep;
-
+
sep = "";
for (i = 0; i < n->name.nparts; i++) {
fprintf(fd, "%s%s", sep, n->name.parts[i]);
@@ -91,7 +91,7 @@ void dumpstab(Stab *st, FILE *fd)
static void outnode(Node *n, FILE *fd, int depth)
{
- int i;
+ size_t i;
char *ty;
indent(fd, depth);
diff --git a/parse/htab.c b/parse/htab.c
index 0b02c11..46b8d78 100644
--- a/parse/htab.c
+++ b/parse/htab.c
@@ -127,7 +127,7 @@ int hthas(Htab *ht, void *k)
void **htkeys(Htab *ht, int *nkeys)
{
void **k;
- int i, j;
+ size_t i, j;
j = 0;
k = xalloc(sizeof(void*)*ht->nelt);
@@ -171,4 +171,3 @@ int ptreq(void *a, void *b)
{
return a == b;
}
-
diff --git a/parse/infer.c b/parse/infer.c
index 6b63aa3..8a61fe8 100644
--- a/parse/infer.c
+++ b/parse/infer.c
@@ -32,7 +32,7 @@ static void setsuper(Stab *st, Stab *super)
static void tyresolve(Type *t)
{
- int i, nn;
+ size_t i, nn;
Node **n;
if (t->resolved)
@@ -83,7 +83,8 @@ static int cstrcheck(Type *a, Type *b)
static void loaduses(Node *n)
{
- int i;
+ size_t i;
+
/* uses only allowed at top level. Do we want to keep it this way? */
for (i = 0; i < n->file.nuses; i++)
fprintf(stderr, "INTERNAL: implement use loading\n");
@@ -182,7 +183,7 @@ static Type *unify(Node *ctx, Type *a, Type *b)
{
Type *t;
Type *r;
- int i;
+ size_t i;
/* a ==> b */
a = tf(a);
@@ -218,7 +219,7 @@ static Type *unify(Node *ctx, Type *a, Type *b)
static void unifycall(Node *n)
{
- int i;
+ size_t i;
Type *ft;
inferexpr(n->expr.args[0], NULL, NULL);
@@ -377,7 +378,7 @@ static void inferexpr(Node *n, Type *ret, int *sawret)
static void inferfunc(Node *n)
{
- int i;
+ size_t i;
int sawret;
sawret = 0;
@@ -416,7 +417,7 @@ static void inferstab(Stab *s)
static void infernode(Node *n, Type *ret, int *sawret)
{
- int i;
+ size_t i;
if (!n)
return;
@@ -482,7 +483,7 @@ static void checkcast(Node *n)
static Type *tyfin(Node *ctx, Type *t)
{
static Type *tyint;
- int i;
+ size_t i;
char buf[1024];
if (!tyint)
@@ -507,7 +508,7 @@ static Type *tyfin(Node *ctx, Type *t)
static void infercompn(Node *file)
{
- int i, j, nn;
+ size_t i, j, nn;
Node *aggr;
Node *memb;
Node *n;
@@ -532,7 +533,7 @@ static void infercompn(Node *file)
static void typesub(Node *n)
{
- int i;
+ size_t i;
if (!n)
return;
@@ -600,4 +601,3 @@ void infer(Node *file)
checkcast(file);
typesub(file);
}
-
diff --git a/parse/node.c b/parse/node.c
index 36890c5..f36560d 100644
--- a/parse/node.c
+++ b/parse/node.c
@@ -61,7 +61,7 @@ Node *mkexpr(int line, Op op, ...)
Node *mkcall(int line, Node *fn, Node **args, size_t nargs)
{
Node *n;
- int i;
+ size_t i;
n = mkexpr(line, Ocall, fn, NULL);
for (i = 0; i < nargs; i++)
@@ -98,7 +98,7 @@ Node *mkfunc(int line, Node **args, size_t nargs, Type *ret, Node *body)
{
Node *n;
Node *f;
- int i;
+ size_t i;
f = mknode(line, Nfunc);
f->func.args = args;
@@ -258,7 +258,7 @@ Op exprop(Node *e)
return e->expr.op;
}
-Node **aggrmemb(Type *t, int *n)
+Node **aggrmemb(Type *t, size_t *n)
{
*n = t->nmemb;
switch (t->type) {
diff --git a/parse/parse.h b/parse/parse.h
index b44c197..a4e7821 100644
--- a/parse/parse.h
+++ b/parse/parse.h
@@ -53,7 +53,7 @@ typedef enum {
} Dclflags;
struct Bitset {
- int nchunks;
+ size_t nchunks;
uint *chunks;
};
@@ -228,13 +228,13 @@ Bitset *dupbs(Bitset *bs);
void delbs(Bitset *bs);
void bsput(Bitset *bs, uint elt);
void bsdel(Bitset *bs, uint elt);
-int bshas(Bitset *bs, uint elt);
void bsunion(Bitset *a, Bitset *b);
void bsintersect(Bitset *a, Bitset *b);
void bsdiff(Bitset *a, Bitset *b);
-int bscount(Bitset *bs);
-int bsmax(Bitset *bs);
+int bshas(Bitset *bs, uint elt);
int bsissubset(Bitset *set, Bitset *sub);
+size_t bscount(Bitset *bs);
+size_t bsmax(Bitset *bs);
Htab *mkht(ulong (*hash)(void *key), int (*cmp)(void *k1, void *k2));
int htput(Htab *ht, void *k, void *v);
@@ -335,7 +335,7 @@ Type *nodetype(Node *n);
void addstmt(Node *file, Node *stmt);
void setns(Node *n, char *name);
Op exprop(Node *n);
-Node **aggrmemb(Type *t, int *n);
+Node **aggrmemb(Type *t, size_t *n);
char *namestr(Node *name);
/* usefiles */
diff --git a/parse/pickle.c b/parse/pickle.c
index e3cf2ed..89e9a4a 100644
--- a/parse/pickle.c
+++ b/parse/pickle.c
@@ -20,30 +20,49 @@ static Stab *rdstab(FILE *fd);
static void wrsym(FILE *fd, Sym *val);
static Sym *rdsym(FILE *fd);
-static vlong be64(vlong v)
+static void be64(vlong v, char buf[8])
{
- if (htonl(42) != 42)
- return ((vlong)htonl(v >> 32) << 32) | htonl((uint32_t)v);
- else
- return v;
+ buf[0] = (v >> 56) & 0xff;
+ buf[1] = (v >> 48) & 0xff;
+ buf[2] = (v >> 40) & 0xff;
+ buf[3] = (v >> 32) & 0xff;
+ buf[4] = (v >> 24) & 0xff;
+ buf[5] = (v >> 16) & 0xff;
+ buf[6] = (v >> 8) & 0xff;
+ buf[7] = (v >> 0) & 0xff;
}
-static vlong host64(vlong v)
+static vlong host64(char buf[8])
{
- if (htonl(42) != 42) /* we need to swap */
- return (vlong)ntohl(v >> 32) << 32 | htonl((uint32_t)v);
- else
- return v;
+ vlong v = 0;
+
+ v |= ((vlong)buf[0] << 56LL) & 0xff;
+ v |= ((vlong)buf[1] << 48LL) & 0xff;
+ v |= ((vlong)buf[2] << 40LL) & 0xff;
+ v |= ((vlong)buf[3] << 32LL) & 0xff;
+ v |= ((vlong)buf[4] << 24LL) & 0xff;
+ v |= ((vlong)buf[5] << 16LL) & 0xff;
+ v |= ((vlong)buf[6] << 8LL) & 0xff;
+ v |= ((vlong)buf[7] << 0LL) & 0xff;
+ return v;
}
-static long be32(long v)
+static void be32(long v, char buf[4])
{
- return htonl(v);
+ buf[0] = (v >> 24) & 0xff;
+ buf[1] = (v >> 16) & 0xff;
+ buf[2] = (v >> 8) & 0xff;
+ buf[3] = (v >> 0) & 0xff;
}
-static long host32(long v)
+static long host32(char buf[4])
{
- return ntohl(v);
+ long v = 0;
+ v |= (buf[4] << 24) & 0xff;
+ v |= (buf[5] << 16) & 0xff;
+ v |= (buf[6] << 8) & 0xff;
+ v |= (buf[7] << 0) & 0xff;
+ return v;
}
static void wrbyte(FILE *fd, char val)
@@ -63,34 +82,42 @@ static char rdbyte(FILE *fd)
static void wrint(FILE *fd, int32_t val)
{
- val = be32(val);
- if (fwrite(&val, sizeof(int32_t), 1, fd) == EOF)
+ char buf[4];
+ be32(val, buf);
+ if (fwrite(buf, 4, 1, fd) < 4)
die("Unexpected EOF");
}
static int32_t rdint(FILE *fd)
{
- uint32_t val;
-
- if (fread(&val, sizeof(uint32_t), 1, fd) == EOF)
+ char buf[4];
+ if (fread(buf, sizeof(uint32_t), 1, fd) < 4)
die("Unexpected EOF");
- return host32(val);
+ return host32(buf);
}
static void wrstr(FILE *fd, char *val)
{
+ size_t len;
+ size_t n;
+
if (!val) {
wrint(fd, -1);
} else {
wrint(fd, strlen(val));
- if (fwrite(val, strlen(val), 1, fd) == EOF)
- die("Unexpected EOF");
+ len = strlen(val);
+ n = 0;
+ while (n < len) {
+ n += fwrite(val, len - n, 1, fd);
+ if (feof(fd) || ferror(fd))
+ die("Unexpected EOF");
+ }
}
}
/*static */char *rdstr(FILE *fd)
{
- int len;
+ ssize_t len;
char *s;
len = rdint(fd);
@@ -98,7 +125,7 @@ static void wrstr(FILE *fd, char *val)
return NULL;
} else {
s = xalloc(len + 1);
- if (fread(s, len, 1, fd) == EOF)
+ if (fread(s, len, 1, fd) != (size_t)len)
die("Unexpected EOF");
s[len] = '\0';
return s;
@@ -107,6 +134,7 @@ static void wrstr(FILE *fd, char *val)
static void wrflt(FILE *fd, double val)
{
+ char buf[8];
/* Assumption: We have 'val' in 64 bit IEEE format */
union {
uvlong ival;
@@ -114,21 +142,22 @@ static void wrflt(FILE *fd, double val)
} u;
u.fval = val;
- u.ival = be64(u.ival);
- if (fwrite(&u.ival, sizeof(uvlong), 1, fd) == EOF)
+ be64(u.ival, buf);
+ if (fwrite(buf, 8, 1, fd) < 8)
die("Unexpected EOF");
}
/*static */double rdflt(FILE *fd)
{
+ char buf[8];
union {
uvlong ival;
double fval;
} u;
- if (fread(&u.ival, sizeof(uvlong), 1, fd) == EOF)
+ if (fread(buf, 8, 1, fd) < 8)
die("Unexpected EOF");
- u.ival = host64(u.ival);
+ u.ival = host64(buf);
return u.fval;
}
@@ -226,7 +255,7 @@ static Sym *rdsym(FILE *fd)
static void wrtype(FILE *fd, Type *ty)
{
- int i;
+ size_t i;
if (!ty) {
die("trying to pickle null type\n");
@@ -280,7 +309,7 @@ static Type *rdtype(FILE *fd)
{
Type *ty;
Ty t;
- int i;
+ size_t i;
t = rdbyte(fd);
ty = mkty(-1, t);
@@ -338,7 +367,7 @@ static Type *rdtype(FILE *fd)
*/
void pickle(Node *n, FILE *fd)
{
- int i;
+ size_t i;
if (!n) {
wrbyte(fd, Nnone);
@@ -429,7 +458,7 @@ void pickle(Node *n, FILE *fd)
Node *unpickle(FILE *fd)
{
- int i;
+ size_t i;
Ntype type;
Node *n;
diff --git a/parse/type.c b/parse/type.c
index 5219bc7..80fd3c6 100644
--- a/parse/type.c
+++ b/parse/type.c
@@ -146,7 +146,7 @@ Type *mktyptr(int line, Type *base)
Type *mktyfunc(int line, Node **args, size_t nargs, Type *ret)
{
Type *t;
- int i;
+ size_t i;
t = mkty(line, Tyfunc);
t->nsub = nargs + 1;
@@ -207,7 +207,7 @@ void tlappend(Type ***tl, int *len, Type *t)
static int namefmt(char *buf, size_t len, Node *name)
{
- int i;
+ size_t i;
char *p;
char *end;
char *sep;
@@ -261,7 +261,7 @@ static int cstrfmt(char *buf, size_t len, Type *t)
static int fmtstruct(char *buf, size_t len, Type *t)
{
- int i;
+ size_t i;
char *end, *p;
char *name, *ty;
@@ -280,7 +280,7 @@ static int fmtstruct(char *buf, size_t len, Type *t)
static int fmtunion(char *buf, size_t len, Type *t)
{
- int i;
+ size_t i;
*buf = 0;
for (i = 0; i < t->nmemb; i++)
dump(t->sdecls[i], stdout);
@@ -289,7 +289,7 @@ static int fmtunion(char *buf, size_t len, Type *t)
static int fmtenum(char *buf, size_t len, Type *t)
{
- int i;
+ size_t i;
*buf = 0;
for (i = 0; i < t->nmemb; i++)
dump(t->sdecls[i], stdout);
@@ -298,9 +298,9 @@ static int fmtenum(char *buf, size_t len, Type *t)
static int tybfmt(char *buf, size_t len, Type *t)
{
+ size_t i;
char *p;
char *end;
- int i;
char *sep;
p = buf;