Fix warnings

This change fixes Cosmopolitan so it has fewer opinions about compiler
warnings. The whole repository had to be cleaned up to be buildable in
-Werror -Wall mode. This lets us benefit from things like strict const
checking. Some actual bugs might have been caught too.
This commit is contained in:
Justine Tunney 2023-09-01 20:49:13 -07:00
parent e2b3c3618e
commit 0d748ad58e
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
571 changed files with 1306 additions and 1888 deletions

View file

@ -775,7 +775,7 @@ static void Tokenize(struct As *a, int path) {
static int GetSymbol(struct As *a, int name) {
struct HashEntry *p;
unsigned i, j, k, n, m, h, n2;
unsigned i, j, k, n, m, h;
if (!(h = crc32c(0, a->slices.p[name].p, a->slices.p[name].n))) h = 1;
n = a->symbolindex.n;
i = 0;
@ -932,7 +932,6 @@ static int NewBinary(struct As *a, enum ExprKind k, int lhs, int rhs) {
// | symbol
// | reference
static int ParsePrimary(struct As *a, int *rest, int i) {
int e;
if (IsInt(a, i)) {
*rest = i + 1;
return NewPrimary(a, EX_INT, a->ints.p[a->things.p[i].i]);
@ -1765,7 +1764,7 @@ static void OnSize(struct As *a, struct Slice s) {
}
static void OnEqu(struct As *a, struct Slice s) {
int i, j;
int i;
i = GetSymbol(a, a->things.p[a->i++].i);
ConsumeComma(a);
a->symbols.p[i].offset = GetInt(a);
@ -1967,15 +1966,17 @@ static int RemoveRexw(int x) {
static int GetRegisterReg(struct As *a) {
int reg;
struct Slice wut;
if ((reg = FindRegReg(GetSlice(a))) == -1) InvalidRegister(a);
if ((reg = FindRegReg(GetSlice(a))) == -1) {
InvalidRegister(a);
}
return reg;
}
static int GetRegisterRm(struct As *a) {
int reg;
struct Slice wut;
if ((reg = FindRegRm(GetSlice(a))) == -1) InvalidRegister(a);
if ((reg = FindRegRm(GetSlice(a))) == -1) {
InvalidRegister(a);
}
return reg;
}
@ -1992,7 +1993,7 @@ static int ParseModrm(struct As *a, int *disp) {
0b00000000000000000000000000000000*/
struct Slice str;
int reg, scale, modrm = 0;
int reg, modrm = 0;
if (!ConsumeSegment(a) && IsRegister(a, a->i)) {
*disp = 0;
modrm = GetRegisterRm(a) | ISREG;
@ -2057,12 +2058,12 @@ static void EmitImm(struct As *a, int reg, int imm) {
}
static void EmitModrm(struct As *a, int reg, int modrm, int disp) {
int relo, mod, rm;
int relo, mod;
void (*emitter)(struct As *, uint128_t);
reg &= 7;
reg <<= 3;
if (modrm & ISREG) {
EmitByte(a, 0300 | reg | modrm & 7);
EmitByte(a, 0300 | reg | (modrm & 7));
} else {
if (modrm & ISRIP) {
EmitByte(a, 005 | reg);
@ -2348,7 +2349,7 @@ static dontinline void OpXadd(struct As *a) {
}
static dontinline int OpF6Impl(struct As *a, struct Slice s, int reg) {
int modrm, imm, disp;
int modrm, disp;
modrm = ParseModrm(a, &disp);
reg |= GetOpSize(a, s, modrm, 1) << 3;
EmitRexOpModrm(a, 0xF6, reg, modrm, disp, 1);
@ -2642,7 +2643,6 @@ static void OnPush(struct As *a, struct Slice s) {
}
static void OnRdpid(struct As *a, struct Slice s) {
int modrm, disp;
EmitVarword(a, 0xf30fc7);
EmitByte(a, 0370 | GetRegisterReg(a));
}
@ -2700,6 +2700,8 @@ static void OnFile(struct As *a, struct Slice s) {
struct Slice path;
fileno = GetInt(a);
path = GetSlice(a);
(void)fileno;
(void)path;
// TODO: DWARF
}
@ -2707,6 +2709,8 @@ static void OnLoc(struct As *a, struct Slice s) {
int fileno, lineno;
fileno = GetInt(a);
lineno = GetInt(a);
(void)fileno;
(void)lineno;
// TODO: DWARF
}
@ -2762,7 +2766,7 @@ static void OnFxch(struct As *a, struct Slice s) {
int rm;
rm = !IsSemicolon(a) ? GetRegisterRm(a) : 1;
EmitByte(a, 0xD9);
EmitByte(a, 0310 | rm & 7);
EmitByte(a, 0310 | (rm & 7));
}
static void OnBswap(struct As *a, struct Slice s) {
@ -2770,7 +2774,7 @@ static void OnBswap(struct As *a, struct Slice s) {
srm = GetRegisterRm(a);
EmitRex(a, srm);
EmitByte(a, 0x0F);
EmitByte(a, 0310 | srm & 7);
EmitByte(a, 0310 | (srm & 7));
}
static dontinline void OpFcomImpl(struct As *a, int op) {
@ -2786,7 +2790,7 @@ static dontinline void OpFcomImpl(struct As *a, int op) {
}
}
}
EmitVarword(a, op | rm & 7);
EmitVarword(a, op | (rm & 7));
}
static dontinline void OpFcom(struct As *a, int op) {

View file

@ -670,7 +670,7 @@ static void PopAsmInputs(Asm *a) {
}
static void StoreAsmOutputs(Asm *a) {
int i, z, x0, x1;
int i, z;
for (i = 0; i < a->n; ++i) {
if (a->ops[i].flow == '=' || a->ops[i].flow == '+') {
switch (a->ops[i].type) {

View file

@ -424,7 +424,7 @@ static bool NeedsShellQuotes(const char *s) {
static bool run_subprocess(char **argv) {
int rc, ws;
size_t i, j, n;
size_t i, j;
if (opt_verbose) {
for (i = 0; argv[i]; i++) {
fputc(' ', stderr);

View file

@ -180,7 +180,7 @@ struct AsmOperand {
uint8_t reg;
uint8_t type;
char flow;
char x87mask;
unsigned char x87mask;
bool isused;
int regmask;
int predicate;
@ -216,10 +216,10 @@ void gen_addr(Node *);
void gen_asm(Asm *);
void gen_expr(Node *);
void pop(char *);
void popreg(char *);
void popreg(const char *);
void print_loc(int64_t, int64_t);
void push(void);
void pushreg(char *);
void pushreg(const char *);
//
// fpclassify.c

View file

@ -67,7 +67,6 @@ static void emitlin(char *nextline) {
void println(char *fmt, ...) {
va_list ap;
char *nextline;
va_start(ap, fmt);
emitlin(xvasprintf(fmt, ap));
va_end(ap);
@ -105,12 +104,12 @@ void pop2(char *a, char *b) {
DCHECK_GE(depth, 0);
}
void pushreg(char *arg) {
void pushreg(const char *arg) {
println("\tpush\t%%%s", arg);
depth++;
}
void popreg(char *arg) {
void popreg(const char *arg) {
println("\tpop\t%%%s", arg);
depth--;
DCHECK_GE(depth, 0);
@ -1777,15 +1776,13 @@ void gen_expr(Node *node) {
gen_expr(node->lhs);
pop("%rdi");
}
char *ax, *di, *dx;
char *ax, *di;
if (node->lhs->ty->kind == TY_LONG || node->lhs->ty->base) {
ax = "%rax";
di = "%rdi";
dx = "%rdx";
} else {
ax = "%eax";
di = "%edi";
dx = "%edx";
}
switch (node->kind) {
case ND_PMOVMSKB:

View file

@ -42,7 +42,6 @@ struct DoxWriter {
};
static void SerializeData(struct Buffer *buf, const void *p, unsigned long n) {
struct Slice *s;
buf->p = realloc(buf->p, buf->n + n);
memcpy(buf->p + buf->n, p, n);
buf->n += n;

View file

@ -153,7 +153,6 @@ static char *DeserializeStr(struct Dox *dox) {
static struct Javadown *DeserializeJavadown(struct Dox *dox) {
int i;
bool present;
struct Javadown *jd;
if (DeserializeInt(dox)) {
jd = FreeLater(dox, calloc(1, sizeof(struct Javadown)));
@ -273,7 +272,7 @@ static bool AddSet(struct Set *set, char *s) {
static int CompareDoxIndexEntry(const void *p1, const void *p2, void *arg) {
struct Dox *dox;
const char *s1, *s2;
struct DoxIndexEntry *a, *b;
const struct DoxIndexEntry *a, *b;
dox = arg, a = p1, b = p2;
s1 = a->t == kObject ? dox->objects.p[a->i].name : dox->macros.p[a->i].name;
s2 = b->t == kObject ? dox->objects.p[b->i].name : dox->macros.p[b->i].name;

View file

@ -2436,7 +2436,6 @@ static Node *logor(Token **rest, Token *tok) {
// logand = binor ("&&" binor)*
static Node *logand(Token **rest, Token *tok) {
Token *start = tok;
Node *node = binor(&tok, tok);
while (EQUAL(tok, "&&")) {
Token *start = tok;