qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Qemu-devel] [PATCH 0/4] target-arm: fix various clang UB sanitizer


From: Richard Henderson
Subject: Re: [Qemu-devel] [PATCH 0/4] target-arm: fix various clang UB sanitizer warnings
Date: Fri, 06 Feb 2015 08:20:29 -0800
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0

On 02/06/2015 06:34 AM, Peter Maydell wrote:
> I can't see any nice way of avoiding this. Possible nasty ways:
> 
> (1) Drop the enum and just use old-fashioned
> #define EC_AA64_BKPT 0x3cU
> since then we can force them to be unsigned
> (2) Cast the constant to unsigned at point of use
> (3) Keep the enum and add defines wrapping actual use
> #define EC_AA64_BKPT ((unsigned)EC_AA64_BKPT)
> I guess there's also
> (4) Ignore the problem and trust that the compiler developers will
> never decide to use this bit of undefined behaviour.

It should be enough to simply add the unsigned suffix to the integers as they
are, forcing the underlying type to be unsigned.

At least that's suggested by the simple test case

   extern void link_error(void);
   enum X { bot = 1u } x = bot;
   int main() { if (-x < 0) link_error(); return 0; }

$ clang -O z.c
z.c:3:21: warning: comparison of unsigned expression < 0 is always false
      [-Wtautological-compare]
int main() { if (-x < 0) link_error(); return 0; }
                 ~~ ^ ~
$ gcc -O -Wall z.c
$


r~




reply via email to

[Prev in Thread] Current Thread [Next in Thread]