From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:40314) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJle1-0005t5-GI for qemu-devel@nongnu.org; Fri, 06 Feb 2015 11:20:38 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1YJldx-0001Z3-Rk for qemu-devel@nongnu.org; Fri, 06 Feb 2015 11:20:37 -0500 Received: from mail-qg0-x22d.google.com ([2607:f8b0:400d:c04::22d]:50558) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1YJldx-0001YQ-NY for qemu-devel@nongnu.org; Fri, 06 Feb 2015 11:20:33 -0500 Received: by mail-qg0-f45.google.com with SMTP id h3so6073977qgf.4 for ; Fri, 06 Feb 2015 08:20:33 -0800 (PST) Sender: Richard Henderson Message-ID: <54D4E9CD.3020707@twiddle.net> Date: Fri, 06 Feb 2015 08:20:29 -0800 From: Richard Henderson MIME-Version: 1.0 References: <1423233250-15853-1-git-send-email-peter.maydell@linaro.org> In-Reply-To: <1423233250-15853-1-git-send-email-peter.maydell@linaro.org> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH 0/4] target-arm: fix various clang UB sanitizer warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell , qemu-devel@nongnu.org Cc: patches@linaro.org 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~