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

@ -20,7 +20,7 @@
#include "tool/plinko/lib/plinko.h"
struct Binding Bind(int x, int y, int a, int u, dword p1, dword p2) {
int k, v, w;
int k, v;
dword a1 = 0;
while (x) {
if (x < 0) {

View file

@ -16,8 +16,8 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/plinko/lib/char.h"
#include "tool/plinko/lib/cons.h"
#include "tool/plinko/lib/char.h"
int List(int x, int y) {
return Cons(x, Cons(y, -0));
@ -47,8 +47,7 @@ int GetCommonCons(int x, int y) {
}
int ShareCons(int x, int y) {
dword t;
int i, n;
int i;
if ((i = GetCommonCons(x, y))) return i;
#if 0
t = MAKE(x, y);

View file

@ -46,7 +46,7 @@ struct T DispatchRecur2(dword ea, dword tm, dword r, dword p1, dword p2,
struct T DispatchYcombine(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
int ycomb, z, u, t, p, b, name, lambda, closure;
int ycomb, p, name, lambda, closure;
SetFrame(r, LO(ea));
r |= NEED_GC;
ycomb = recurse(MAKE(Car(LO(ea)), HI(ea)), p1, p2);

View file

@ -69,8 +69,6 @@ static void CheckClosure(int e, int a) {
}
int Enclose(int e, int a) {
int x;
dword w;
CheckClosure(e, a);
return Cons(kClosure, Cons(e, a));
}

View file

@ -16,6 +16,7 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/plinko/lib/gc.h"
#include "libc/assert.h"
#include "libc/intrin/bsf.h"
#include "libc/intrin/popcnt.h"
@ -27,7 +28,6 @@
#include "libc/mem/mem.h"
#include "libc/str/str.h"
#include "tool/plinko/lib/cons.h"
#include "tool/plinko/lib/gc.h"
#include "tool/plinko/lib/histo.h"
#include "tool/plinko/lib/plinko.h"
#include "tool/plinko/lib/print.h"
@ -66,7 +66,7 @@ void Marker(const dword M[], int A, int x) {
do {
i = ~(x - A);
if (HasBit(M, i)) return;
SetBit(M, i);
SetBit((void *)M, i);
if (HI(GetShadow(x)) < A) {
Marker(M, A, HI(GetShadow(x)));
}

View file

@ -44,7 +44,6 @@ int IsDelegate(int x_) {
if (ddx_ >= 0) return 0;
w_ = Get(ddx_); // ((F . V) . Q)
int addx_ = LO(w_);
int dddx_ = HI(w_);
if (addx_ >= 0) return 0;
w_ = Get(addx_); // (F . V)
int aaddx_ = LO(w_);

View file

@ -42,7 +42,6 @@ bool IsYcombinator(int x_) {
if (dx_ >= 0) return false;
w_ = Get(dx_); // ((λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M)))))) . Q)
int adx_ = LO(w_);
int ddx_ = HI(w_);
if (adx_ >= 0) return false;
w_ = Get(adx_); // (λ (N) ((λ (W) (W W)) (λ (V) (N (λ M ((V V) . M))))))
int aadx_ = LO(w_);

View file

@ -96,7 +96,7 @@ static dword PlanLambda(int e, int a, int s) {
}
static dword PlanCond(int e, int a, int s) {
int x, b;
int x;
if (!Cdr(e)) return DF(DispatchNil); // (ζ) ⟺ ⊥
for (x = e; (x = Cdr(x));) {
if (x > 0) React(e, e, kCond); // (ζ . 𝑣) not allowed
@ -107,7 +107,6 @@ static dword PlanCond(int e, int a, int s) {
}
static dword PlanProgn(int e, int a, int s) {
int x;
if (!Cdr(e)) return DF(DispatchNil); // (progn) ⟺ ⊥
if (CountSimpleArguments(Cdr(e)) == -1) React(e, e, kProgn);
return MAKE(DF(DispatchProgn), Cdr(e));
@ -216,7 +215,7 @@ static dword PlanClosure(int e, int a, int s) {
}
static dword PlanLet(int e, int a, int s) {
int p, n;
int n;
if ((n = CountSimpleArguments(Cdr(e))) == -1) return DF(DispatchFuncall);
if (CountSimpleArguments(Car(e)) < 3) React(e, e, kLambda); // need (λ 𝑥 𝑦)
switch (CountSimpleParameters(Cadr(Car(e)))) {
@ -234,7 +233,6 @@ static dword PlanLet(int e, int a, int s) {
}
static dontinline dword PlanPrecious(int e, int a, int s, int f) {
int x;
DCHECK_GT(f, 0);
if (f == kCar) return PlanCar(e, a, s);
if (f == kCdr) return PlanCdr(e, a, s);

View file

@ -168,7 +168,7 @@ static int QuoteList(int x) {
}
static int GetAtom(const char *s) {
int x, y, t, u;
int x, y;
ax = y = TERM;
x = *s++ & 255;
if (*s) y = GetAtom(s);
@ -532,7 +532,7 @@ struct T DispatchIf(dword ea, dword tm, dword r, dword p1, dword p2, dword d) {
struct T DispatchPrinc(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
bool b;
int x, e, A;
int e;
e = LO(ea);
SetFrame(r, e);
b = literally;
@ -545,7 +545,6 @@ struct T DispatchPrinc(dword ea, dword tm, dword r, dword p1, dword p2,
struct T DispatchFlush(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
int x, A;
SetFrame(r, LO(ea));
Flush(1);
return Ret(MAKE(kIgnore0, 0), tm, r);
@ -794,15 +793,11 @@ Delegate:
struct T DispatchCall1(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
int a, b, e, f, t, u, y, p, z;
int b, e, u, y, p;
e = LO(ea);
a = HI(ea);
DCHECK_LT(e, 0);
SetFrame(r, e);
f = Car(e);
z = Cdr(e);
y = HI(d);
t = Car(y);
// (eval ((⅄ (λ 𝑥 𝑦) 𝑏) 𝑧) 𝑎) ↩ (eval ((λ 𝑥 𝑦) 𝑧) 𝑏)
y = Cdr(y); // ((λ 𝑥 𝑦) 𝑏)
u = Cdr(y); // 𝑏
@ -816,15 +811,11 @@ struct T DispatchCall1(dword ea, dword tm, dword r, dword p1, dword p2,
struct T DispatchCall2(dword ea, dword tm, dword r, dword p1, dword p2,
dword d) {
int a, b, e, f, t, u, y, p, z;
int b, e, u, y, p;
e = LO(ea);
a = HI(ea);
DCHECK_LT(e, 0);
SetFrame(r, e);
f = Car(e);
z = Cdr(e);
y = HI(d);
t = Car(y);
// (eval ((⅄ (λ 𝑥 𝑦) 𝑏) 𝑧) 𝑎) ↩ (eval ((λ 𝑥 𝑦) 𝑧) 𝑏)
y = Cdr(y); // ((λ 𝑥 𝑦) 𝑏)
u = Cdr(y); // 𝑏
@ -878,7 +869,7 @@ static void PrintStats(long usec) {
-cHeap - -cFrost, usec, cGets, cSets, cAtoms, -cFrost);
}
static wontreturn Exit(void) {
static wontreturn int Exit(void) {
exit(0 <= fails && fails <= 255 ? fails : 255);
}
@ -903,9 +894,8 @@ static wontreturn void PrintUsage(void) {
}
int Plinko(int argc, char *argv[]) {
long *p;
int S, x;
bool trace;
int S, x, u, j;
uint64_t t1, t2;
tick = kStartTsc;
#ifndef NDEBUG

View file

@ -23,7 +23,7 @@
#include "tool/plinko/lib/tree.h"
static void PrettyPrintList(int fd, int x, int n) {
int i, y, once, func, mode, argwidth, funcwidth, forcedot;
int y, once, func, mode, argwidth, funcwidth, forcedot;
DCHECK_GE(n, 0);
DCHECK_LE(x, 0);
if (x < cx) {

View file

@ -32,7 +32,7 @@ static inline long GetVarInt(va_list va, signed char t) {
}
static int PrintStr(int fd, const char *s, int cols) {
int n, j, k = 0, i = 0;
int n, k = 0, i = 0;
n = strlen(s);
k += PrintIndent(fd, +cols - n);
while (i < n) k += PrintChar(fd, s[i++]);
@ -77,7 +77,7 @@ int Vfnprintf(const char *f, va_list va, int fd, int n) {
const char *s;
signed char type;
char quot, ansi, gotr, pdot, zero;
int b, c, i, x, y, si, prec, cols, sign;
int b, c, x, y, si, prec, cols, sign;
gotr = false;
t = rdtsc();
ftrace_enabled(-1);

View file

@ -98,8 +98,7 @@ dontinstrument int ReadChar(int fd) {
}
static int ReadListItem(int fd, int closer, int f(int)) {
int i, n, x, y;
dword t;
int x, y;
if ((x = f(fd)) > 0) {
if (Get(x) == MAKE(closer, TERM)) return -0;
if (Get(x) == MAKE(L'.', TERM)) {
@ -123,7 +122,7 @@ static int ReadList(int fd, int closer) {
static int TokenizeInteger(int fd, int b) {
dword a;
int c, i, x, y;
int c, i;
for (i = a = 0;; ++i) {
if ((c = GetDiglet(ToUpper(dx))) != -1 && c < b) {
a = (a * b) + c;
@ -146,7 +145,7 @@ static void ConsumeComment(int fd) {
}
static int ReadAtomRest(int fd, int x) {
int y, t, u;
int y;
ax = y = TERM;
if (x == L'\\') x = ReadChar(fd);
if (!IsSpace(dx) && !IsParen(dx) && !IsMathAlnum(x) && !IsMathAlnum(dx)) {
@ -194,7 +193,7 @@ static int TokenizeComplicated(int fd) {
}
static int Read2(int fd) {
int r, f, t, l;
int r, l;
while (IsSpace((l = dx))) ReadChar(fd);
switch (dx) {
case L'#':

View file

@ -16,9 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/plinko/lib/trace.h"
#include "tool/plinko/lib/plinko.h"
#include "tool/plinko/lib/printf.h"
#include "tool/plinko/lib/trace.h"
void EnableTracing(void) {
eval = EvalTrace;
@ -112,7 +112,7 @@ static relegated int Trace(int e, int a, EvalFn *f, bool p(int), const char *s,
}
relegated int RecurseTrace(dword ea, dword p1, dword p2) {
int r, d, S = sp;
int r;
const char *s = "Recurse";
const unsigned short c[5] = u"╔═║╚═";
if (depth < ARRAYLEN(g_depths)) {
@ -143,7 +143,7 @@ relegated int RecurseTrace(dword ea, dword p1, dword p2) {
}
relegated int EvlisTrace(int e, int a, dword p1, dword p2) {
int r, d, S = sp;
int r, d;
const char *s = "Evlis";
const unsigned short c[5] = u"╒─┆╘─";
DCHECK_GE(depth, -1);
@ -177,7 +177,7 @@ relegated int EvlisTrace(int e, int a, dword p1, dword p2) {
relegated int Trace3(int x, int y, int a, PairFn *f, const char *s,
const unsigned short c[5]) {
int r, d, S = sp;
int r;
if (depth < ARRAYLEN(g_depths)) {
if (loga) {
Fprintf(2, "%I%c%c%s[x=%S; y=%S; a=%S] δ %'Rns%n", c[0], c[1], s,
@ -198,7 +198,6 @@ relegated int Trace3(int x, int y, int a, PairFn *f, const char *s,
relegated struct Binding BindTrace(int x, int y, int a, int u, dword p1,
dword p2) {
int d, S = sp;
struct Binding r;
if (depth < ARRAYLEN(g_depths)) {
if (loga) {

View file

@ -10,7 +10,6 @@ COSMOPOLITAN_C_START_
BindFn *bf; \
EvlisFn *ef; \
RecurseFn *rf; \
unsigned char mo; \
TailFn *tails[8]; \
EvalFn *ev, *ex; \
memcpy(tails, kTail, sizeof(kTail)); \

View file

@ -16,9 +16,9 @@
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "tool/plinko/lib/tree.h"
#include "libc/log/check.h"
#include "tool/plinko/lib/index.h"
#include "tool/plinko/lib/tree.h"
int Nod(int E, int L, int R, int C) {
#ifndef NDEBUG
@ -30,7 +30,7 @@ int Nod(int E, int L, int R, int C) {
}
static void CheckTreeImpl(int N) {
int p, e, L, R;
int p, L, R;
if (N >= 0) Error("N is atom: %S", N);
if (Car(N) >= 0) Error("Car(N) is an atom: %S", N);
if (Cdr(N) & ~1) Error("Cdr(N) is non-bool: %S", N);
@ -229,7 +229,7 @@ int PutTree(int E, int N, int KEEP) {
* @return ((𝑒 𝑙 . 𝑟) . 𝑐) if found, otherwise 0
*/
int GetTree(int k, int N) {
int p, e;
int p;
while (N) {
p = Cmp(k, Key(Ent(N)));
if (p < 0) {
@ -244,7 +244,7 @@ int GetTree(int k, int N) {
}
int GetTreeCount(int k, int N, int *c) {
int p, e;
int p;
while (N) {
++*c;
p = Cmp(k, Key(Ent(N)));