diff options
| author | 2023-06-04 15:10:48 +0200 | |
|---|---|---|
| committer | 2023-06-04 19:21:55 +0200 | |
| commit | 5f4daefd7554f04fd7cd3e416609ed021415a2f7 (patch) | |
| tree | fb9939b5f6415756492105cd486ec2308ae4a09d | |
| parent | ae8f6c54bc8dc2a439bff83b590481427c9ed58d (diff) | |
correctly handle function call returning narrow int
| -rw-r--r-- | parse.c | 15 | ||||
| -rw-r--r-- | test2.c | 8 |
2 files changed, 16 insertions, 7 deletions
@@ -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; @@ -13,3 +13,11 @@ v2d add(v2d a, v2d b) addp(&a, &b); return a; } + +short s(int a, int b) { + return a + b; +} + +int i() { + return s(1,2); +} |