aboutsummaryrefslogtreecommitdiffhomepage
path: root/parse.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-04 15:10:48 +0200
committerlemon <lsof@mailbox.org>2023-06-04 19:21:55 +0200
commit5f4daefd7554f04fd7cd3e416609ed021415a2f7 (patch)
treefb9939b5f6415756492105cd486ec2308ae4a09d /parse.c
parentae8f6c54bc8dc2a439bff83b590481427c9ed58d (diff)
correctly handle function call returning narrow int
Diffstat (limited to 'parse.c')
-rw-r--r--parse.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/parse.c b/parse.c
index 1081fca..d3167ce 100644
--- a/parse.c
+++ b/parse.c
@@ -1139,12 +1139,10 @@ narrow(struct function *fn, enum irclass to, enum typetag tt, union ref ref)
assert(to == KF4 && tt == TYDOUBLE);
ins.op = Ocvtf8f4;
} else {
- switch (targ_primsizes[tt]) {
- case 1: ins.op = issignedt(tt) ? Oexts1 : Oextu1; break;
- case 2: ins.op = issignedt(tt) ? Oexts2 : Oextu2; break;
- case 4: ins.op = issignedt(tt) ? Oexts4 : Oextu4; break;
- default: assert(0);
- }
+ static const enum op ext[5][2] = {
+ [1] = {Oextu1, Oexts1}, [2] = {Oextu2, Oexts2}, [4] = {Oextu4, Oexts4}
+ };
+ ins.op = ext[targ_primsizes[tt]][issignedt(tt)];
}
ins.l = ref;
return addinstr(fn, ins);
@@ -1564,7 +1562,10 @@ compileexpr(struct function *fn, const struct expr *ex, bool discard)
if (discard) return NOREF;
return narrow(fn, cls, ex->ty.t, q);
case ECALL:
- return compilecall(fn, ex);
+ r = compilecall(fn, ex);
+ if (isint(ex->ty))
+ return narrow(fn, cls, ex->ty.t, r);
+ return r;
case ECOND:
if (ex->ty.t == TYVOID) {
struct block *tr, *fl, *end;