From 6dee4df79d5f251d12e387d8425e2b05cdd60523 Mon Sep 17 00:00:00 2001 From: Michael Forney Date: Sat, 16 Feb 2019 02:25:30 -0800 Subject: Fix casts from integer types less than 32 bits wide --- qbe.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/qbe.c b/qbe.c index f43aee8..3d68495 100644 --- 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); -- cgit v1.2.3