From 0381387640fecfc1d8bd9e79d972a2b58c508069 Mon Sep 17 00:00:00 2001 From: Michael Matz Date: Mon, 8 Aug 2016 20:46:16 +0200 Subject: [PATCH] x86-asm: Correctly infer register size for bools Register operands of type _Bool weren't correctly getting the 8-bit sized registers (but rather used the default 32-bit ones). --- i386-asm.c | 3 ++- tests/tcctest.c | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/i386-asm.c b/i386-asm.c index dd8bb989..3d87e92d 100644 --- a/i386-asm.c +++ b/i386-asm.c @@ -1478,7 +1478,8 @@ ST_FUNC void subst_asm_operand(CString *add_str, tcc_error("internal compiler error"); /* choose register operand size */ - if ((sv->type.t & VT_BTYPE) == VT_BYTE) + if ((sv->type.t & VT_BTYPE) == VT_BYTE || + (sv->type.t & VT_BTYPE) == VT_BOOL) size = 1; else if ((sv->type.t & VT_BTYPE) == VT_SHORT) size = 2; diff --git a/tests/tcctest.c b/tests/tcctest.c index f8a9ca62..52dbfafc 100644 --- a/tests/tcctest.c +++ b/tests/tcctest.c @@ -2678,6 +2678,9 @@ void asm_test(void) int base_func = 42; void override_func3 (void); unsigned long asmret; +#ifdef BOOL_ISOC99 + _Bool somebool; +#endif printf("inline asm:\n"); @@ -2726,6 +2729,13 @@ void asm_test(void) asm volatile("" : "=r" (asmret) : "0"(s2)); if (asmret != s2.addr) printf("asmstr: failed\n"); +#ifdef BOOL_ISOC99 + /* Check that the typesize correctly sets the register size to + 8 bit. */ + asm volatile("cmp %1,%2; sete %0" : "=a"(somebool) : "r"(1), "r"(2)); + if (!somebool) + printf("asmbool: failed\n"); +#endif return; label1: goto label2; -- 2.11.4.GIT