From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([208.118.235.92]:59166) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THvTF-0006Yt-K7 for qemu-devel@nongnu.org; Sat, 29 Sep 2012 07:44:34 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1THvTE-0003G4-Dj for qemu-devel@nongnu.org; Sat, 29 Sep 2012 07:44:33 -0400 Received: from mail-ie0-f173.google.com ([209.85.223.173]:47160) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1THvTE-0003G0-9B for qemu-devel@nongnu.org; Sat, 29 Sep 2012 07:44:32 -0400 Received: by iea17 with SMTP id 17so8518006iea.4 for ; Sat, 29 Sep 2012 04:44:31 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <23216f8d6e3e00bdf667e1c7f942500d3c892a18.1348417996.git.blauwirbel@gmail.com> Date: Sat, 29 Sep 2012 12:44:31 +0100 Message-ID: From: Peter Maydell Content-Type: text/plain; charset=UTF-8 Subject: Re: [Qemu-devel] [PATCH] gic: avoid a warning from clang List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Blue Swirl Cc: qemu-devel@nongnu.org On 29 September 2012 12:25, Blue Swirl wrote: > On Mon, Sep 24, 2012 at 2:56 PM, Peter Maydell wrote: >> On 24 September 2012 14:22, Peter Maydell wrote: >>> On 23 September 2012 17:33, Blue Swirl wrote: >>>> Avoid this warning: >>>> CC arm-softmmu/hw/arm/../arm_gic.o >>>> /src/qemu/hw/arm/../arm_gic.c:432:17: error: implicit truncation from 'unsigned int' to bitfield changes value from 4294967040 to 0 [-Werror,-Wconstant-conversion] >>>> GIC_CLEAR_PENDING(irq + i, ALL_CPU_MASK); >>>> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >>>> /src/qemu/hw/arm/../arm_gic_internal.h:43:62: note: expanded from: >>>> #define GIC_CLEAR_PENDING(irq, cm) s->irq_state[irq].pending &= ~(cm) >>>> ^ ~~~~~ >>>> >>>> 4294967040 is 0xffffff00 and field 'pending' is effectively 8 bits >>>> wide, so the masking has no effect except for avoiding the warning. >>> >>> foo &= ~SOME_FLAGS; is an entirely legitimate and common C idiom, >>> and I think clang is being overexuberant in warning here: we should >>> disable this warning instead of working around it in the code. > > This is the only warning generated from QEMU sources, related to > -Wconstant-conversion (enabled by -Wall). It would be nice to work > around it. How about changing the macros to functions? The use of 's' > in the macros look bad and there's no do {} while(0) either to protect > the assignment. Using inline functions would be cleaner code, I think, so if that happens to fix the warning that's OK I guess. I still think clang is actively wrong here, though: foo.bar &= ~(cm); where foo.bar is an 8 bit unsigned bitfield means that we do the standard integer promotions, so we do the & on 'unsigned int' types. So we're not truncating 4294967040 at all, and provably the value that goes back into bar has the top 24 bits clear anyway. Clang appears to think it's doing the & operation on an 8-bit-wide type? -- PMM