cproc

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/cproc
Log | Files | Refs | Submodules | README | LICENSE

commit 6dee4df79d5f251d12e387d8425e2b05cdd60523
parent f4a3a6504b1cf2bc28a2ad87ac5befcda6b78050
Author: Michael Forney <mforney@mforney.org>
Date:   Sat, 16 Feb 2019 02:25:30 -0800

Fix casts from integer types less than 32 bits wide

Diffstat:
Mqbe.c | 12+++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)

diff --git a/qbe.c b/qbe.c @@ -619,10 +619,16 @@ funcexpr(struct function *f, struct expression *e) op = src->size == 8 ? ICNED : ICNES; } else if (dstprop & PROPINT) { if (srcprop & PROPINT) { - if (dst->size == 8 && src->size <= 4) - op = src->basic.issigned ? IEXTSW : IEXTUW; - else + if (dst->size <= src->size) { op = ICOPY; + } else { + switch (src->size) { + case 4: op = src->basic.issigned ? IEXTSW : IEXTUW; break; + case 2: op = src->basic.issigned ? IEXTSH : IEXTUH; break; + case 1: op = src->basic.issigned ? IEXTSB : IEXTUB; break; + default: fatal("internal error; unknown int conversion"); + } + } } else { if (!dst->basic.issigned) return ftou(f, dst->repr, l);