aboutsummaryrefslogtreecommitdiffhomepage
path: root/c/c.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2025-11-02 19:25:40 +0100
committerlemon <lsof@mailbox.org>2025-11-02 19:25:40 +0100
commitca3dd9e031edf9c5c756e7bcee12a45eca368c62 (patch)
tree4f68347cda57f94d48113128c39f2ae890239e50 /c/c.c
parentbefaa58970f0f6de4aefe4741d9a0a9cb281d82e (diff)
c: various codegen bugs
Diffstat (limited to 'c/c.c')
-rw-r--r--c/c.c24
1 files changed, 18 insertions, 6 deletions
diff --git a/c/c.c b/c/c.c
index a8ad132..d37bd6b 100644
--- a/c/c.c
+++ b/c/c.c
@@ -2971,7 +2971,7 @@ condexprrec(struct function *fn, const struct expr *ex, struct condphis *phis,
if (next && next != end) {
putcondbranch(fn, r, next, end);
} else {
- //assert(boolcon < 0);
+ if (phis) assert(boolcon < 0);
putbranch(fn, end);
}
}
@@ -3647,8 +3647,11 @@ stmt(struct comp *cm, struct function *fn)
* @end:
* <-
*/
+ doemit = 1;
EMITS {
- putbranch(fn, begin = newblk(fn));
+ begin = newblk(fn);
+ if (fn->curblk)
+ putbranch(fn, begin);
useblk(fn, begin);
condjump(fn, &ex, tr = newblk(fn), end = newblk(fn));
useblk(fn, tr);
@@ -3671,8 +3674,11 @@ stmt(struct comp *cm, struct function *fn)
* @end:
* <-
*/
+ doemit = 1;
EMITS {
- putbranch(fn, begin = newblk(fn));
+ begin = newblk(fn);
+ if (fn->curblk)
+ putbranch(fn, begin);
useblk(fn, begin);
tr = newblk(fn);
end = newblk(fn);
@@ -3724,8 +3730,11 @@ stmt(struct comp *cm, struct function *fn)
expect(cm, ';', NULL);
}
}
+ doemit = 1;
EMITS {
- putbranch(fn, end = tr = begin = newblk(fn));
+ end = tr = begin = newblk(fn);
+ if (fn->curblk)
+ putbranch(fn, begin);
useblk(fn, begin);
fl = newblk(fn);
}
@@ -3881,6 +3890,7 @@ localdecl(struct comp *cm, struct function *fn, bool forini)
bool put = 0;
bool dynarr = 0;
+ decl.id = -1;
switch (decl.scls) {
case SCSTATIC:
if (forini)
@@ -3903,8 +3913,10 @@ localdecl(struct comp *cm, struct function *fn, bool forini)
error(&decl.span, "declaring variable '%s' with incomplete type '%ty'", decl.name, decl.ty);
goto Err;
}
- EMITS {
- decl.id = addinstr(fn, mkalloca(typesize(decl.ty), typealign(decl.ty))).i;
+ if (!nerror) {
+ struct instr alloc = mkalloca(typesize(decl.ty), typealign(decl.ty));
+ if (fn->curblk) decl.id = addinstr(fn, alloc).i;
+ else decl.id = insertinstr(fn->entry, fn->entry->ins.n, alloc).i;
}
Initz:
if (st.varini) {