From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from [140.186.70.92] (port=39884 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1P4Kin-0000KJ-94 for qemu-devel@nongnu.org; Fri, 08 Oct 2010 17:43:22 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P4Kil-0003LV-PF for qemu-devel@nongnu.org; Fri, 08 Oct 2010 17:43:21 -0400 Received: from moutng.kundenserver.de ([212.227.126.171]:57173) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P4Kil-0003LO-9h for qemu-devel@nongnu.org; Fri, 08 Oct 2010 17:43:19 -0400 Message-ID: <4CAF9072.8080600@mail.berlios.de> Date: Fri, 08 Oct 2010 23:43:14 +0200 From: Stefan Weil MIME-Version: 1.0 References: <1286526743-10253-1-git-send-email-weil@mail.berlios.de> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Subject: [Qemu-devel] Re: [PATCH] tcg: Fix compiler error (comparison of unsigned expression) List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Hollis Blanchard Cc: Blue Swirl , QEMU Developers Am 08.10.2010 18:57, schrieb Hollis Blanchard: > On Fri, Oct 8, 2010 at 1:32 AM, Stefan Weil wrote: >> When qemu is configured with --enable-debug-tcg, >> gcc throws this warning (or error with -Werror): >> >> tcg/tcg.c:1030: error: comparison of unsigned expression >= 0 is >> always true >> >> Fix it by removing the >= 0 part. >> The type cast to 'unsigned' catches negative values of op >> (which should never happen). >> >> This is a modification of Hollis Blanchard's patch. >> >> Cc: Hollis Blanchard >> Cc: Blue Swirl >> Signed-off-by: Stefan Weil >> --- >> tcg/tcg.c | 2 +- >> 1 files changed, 1 insertions(+), 1 deletions(-) >> >> diff --git a/tcg/tcg.c b/tcg/tcg.c >> index e0a9030..0cdef0d 100644 >> --- a/tcg/tcg.c >> +++ b/tcg/tcg.c >> @@ -1027,7 +1027,7 @@ void tcg_add_target_add_op_defs(const >> TCGTargetOpDef *tdefs) >> if (tdefs->op == (TCGOpcode)-1) >> break; >> op = tdefs->op; >> - assert(op >= 0 && op < NB_OPS); >> + assert((unsigned)op < NB_OPS); >> def = &tcg_op_defs[op]; >> #if defined(CONFIG_DEBUG_TCG) >> /* Duplicate entry in op definitions? */ > > According to the warning, op is already unsigned, so this simply > removes the >=0 test, which was my original patch. > > In contrast, Blue wanted a cast to int, as seen in > 95ee3914bfd551aeec49932a400530141865acad. > > -Hollis I read the original thread. Michael already proposed the unsigned cast in that thread. Your patch is correct as long as we use gcc and as long as gcc uses unsigned enums when possible (it is possible here). Other compilers or new versions of gcc might use signed enums. For those (and also for current gcc versions), my patch works. Blue's solution also works but is a bit more code without having advantages. There are even more solutions which are accepted by the compiler: ((op > first && op <= last) || (op == first)) with first, last being the first or last enum member. - Stefan