aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--qbe.c4
-rw-r--r--test/if-char.c5
-rw-r--r--test/if-char.qbe11
3 files changed, 19 insertions, 1 deletions
diff --git a/qbe.c b/qbe.c
index 50eb5eb..d40029a 100644
--- a/qbe.c
+++ b/qbe.c
@@ -627,7 +627,9 @@ funcjnz(struct func *f, struct value *v, struct type *t, struct block *l1, struc
but QBE is not currently able to optimize the conversion
away for int.
*/
- if (t->prop & PROPFLOAT || t->size > 4)
+ if (t->prop & PROPINT && t->size < 4)
+ v = convert(f, &typeint, t, v);
+ else if (t->prop & PROPFLOAT || t->size > 4)
v = convert(f, &typebool, t, v);
}
b->jump.kind = JUMP_JNZ;
diff --git a/test/if-char.c b/test/if-char.c
new file mode 100644
index 0000000..c22d767
--- /dev/null
+++ b/test/if-char.c
@@ -0,0 +1,5 @@
+int main(void) {
+ if ((unsigned char)0x100)
+ return 1;
+ return 0;
+}
diff --git a/test/if-char.qbe b/test/if-char.qbe
new file mode 100644
index 0000000..d964db4
--- /dev/null
+++ b/test/if-char.qbe
@@ -0,0 +1,11 @@
+export
+function w $main() {
+@start.1
+@body.2
+ %.1 =w extub 256
+ jnz %.1, @if_true.3, @if_false.4
+@if_true.3
+ ret 1
+@if_false.4
+ ret 0
+}