aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Forney <mforney@mforney.org>2022-05-19 10:34:32 -0700
committerMichael Forney <mforney@mforney.org>2022-05-19 12:01:25 -0700
commitc88c649fc658a6acf4e03999268d6546b9dad87e (patch)
treedc54fb375f1530a38a76f357a439e9939c595530
parent13eb0640cc58bee1a29c82c1b230137e7ff411c3 (diff)
Add unreachable returns to silence compiler warnings
-rwxr-xr-xconfigure2
-rw-r--r--driver.c1
-rw-r--r--expr.c11
-rw-r--r--init.c1
-rw-r--r--qbe.c22
5 files changed, 26 insertions, 11 deletions
diff --git a/configure b/configure
index 6185c13..fe5688a 100755
--- a/configure
+++ b/configure
@@ -169,7 +169,7 @@ cat >config.mk <<EOF
PREFIX=$prefix
BINDIR=$bindir
CC=${CC:-cc}
-CFLAGS=${CFLAGS:--std=c99 -Wall -Wpedantic -Wno-parentheses -Wno-switch -Wno-maybe-uninitialized -g -pipe}
+CFLAGS=${CFLAGS:--std=c99 -Wall -Wpedantic -Wno-parentheses -Wno-switch -g -pipe}
LDFLAGS=$LDFLAGS
EOF
echo done
diff --git a/driver.c b/driver.c
index 1015153..23de769 100644
--- a/driver.c
+++ b/driver.c
@@ -394,6 +394,7 @@ main(int argc, char *argv[])
qbearch = "rv64";
} else {
fatal("unsupported target '%s'", target);
+ return 1; /* unreachable */
}
arrayaddptr(&stages[COMPILE].cmd, "-t");
arrayaddptr(&stages[COMPILE].cmd, arch);
diff --git a/expr.c b/expr.c
index 98b23a9..67976b8 100644
--- a/expr.c
+++ b/expr.c
@@ -698,6 +698,7 @@ primaryexpr(struct scope *s)
break;
default:
error(&tok.loc, "expected primary expression");
+ return NULL; /* unreachable */
}
return e;
@@ -848,6 +849,7 @@ builtinfunc(struct scope *s, enum builtinkind kind)
break;
default:
fatal("internal error; unknown builtin");
+ return NULL; /* unreachable */
}
return e;
}
@@ -1055,6 +1057,7 @@ unaryexpr(struct scope *s)
e = unaryexpr(s);
} else {
error(&tok.loc, "expected ')' after '_Alignof'");
+ return NULL; /* unreachable */
}
if (!t) {
if (e->decayed)
@@ -1200,12 +1203,14 @@ condexpr(struct scope *s)
tq = lt->qual | rt->qual;
lt = lt->base;
rt = rt->base;
- if (lt == &typevoid || rt == &typevoid)
+ if (lt == &typevoid || rt == &typevoid) {
t = &typevoid;
- else if (typecompatible(lt, rt))
+ } else if (typecompatible(lt, rt)) {
t = typecomposite(lt, rt);
- else
+ } else {
error(&tok.loc, "operands of conditional operator must have compatible types");
+ return NULL; /* unreachable */
+ }
t = mkpointertype(t, tq);
} else {
error(&tok.loc, "invalid operands to conditional operator");
diff --git a/init.c b/init.c
index 9d39130..6056f5b 100644
--- a/init.c
+++ b/init.c
@@ -165,6 +165,7 @@ focus(struct initparser *p)
break;
default:
fatal("internal error: init cursor has unexpected type");
+ return; /* unreachable */
}
subobj(p, t, 0);
}
diff --git a/qbe.c b/qbe.c
index 061e6ac..b95af9e 100644
--- a/qbe.c
+++ b/qbe.c
@@ -422,14 +422,18 @@ convert(struct func *f, struct type *dst, struct type *src, struct value *l)
case 2: op = ICNEW, l = funcinst(f, IEXTUH, 'w', l, NULL); break;
case 4: op = ICNEW; break;
case 8: op = ICNEL; break;
- default: fatal("internal error; unknown integer conversion");
+ default:
+ fatal("internal error; unknown integer conversion");
+ return NULL; /* unreachable */
}
} else {
assert(src->prop & PROPFLOAT);
switch (src->size) {
case 4: op = ICNES, r = mkfltconst(VALUE_FLTCONST, 0); break;
case 8: op = ICNED, r = mkfltconst(VALUE_DBLCONST, 0); break;
- default: fatal("internal error; unknown floating point conversion");
+ default:
+ fatal("internal error; unknown floating point conversion");
+ return NULL; /* unreachable */
}
}
} else if (dst->prop & PROPINT) {
@@ -441,7 +445,9 @@ convert(struct func *f, struct type *dst, struct type *src, struct value *l)
case 4: op = src->u.basic.issigned ? IEXTSW : IEXTUW; break;
case 2: op = src->u.basic.issigned ? IEXTSH : IEXTUH; break;
case 1: op = src->u.basic.issigned ? IEXTSB : IEXTUB; break;
- default: fatal("internal error; unknown integer conversion");
+ default:
+ fatal("internal error; unknown integer conversion");
+ return NULL; /* unreachable */
}
} else {
if (dst->u.basic.issigned)
@@ -692,14 +698,16 @@ funcexpr(struct func *f, struct expr *e)
lval = funclval(f, e->base);
l = funcload(f, e->base->type, lval);
t = e->type;
- if (t->kind == TYPEPOINTER)
+ if (t->kind == TYPEPOINTER) {
r = mkintconst(t->base->size);
- else if (t->prop & PROPINT)
+ } else if (t->prop & PROPINT) {
r = mkintconst(1);
- else if (t->prop & PROPFLOAT)
+ } else if (t->prop & PROPFLOAT) {
r = mkfltconst(t->size == 4 ? VALUE_FLTCONST : VALUE_DBLCONST, 1);
- else
+ } else {
fatal("not a scalar");
+ return NULL; /* unreachable */
+ }
v = funcinst(f, e->op == TINC ? IADD : ISUB, qbetype(t).base, l, r);
v = funcstore(f, e->type, e->qual, lval, v);
return e->u.incdec.post ? l : v;