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: Peter Maydell
Subject: Re: [Qemu-devel] [PATCH 0/4] target-arm: fix various clang UB sanitizer warnings
Date: Fri, 6 Feb 2015 16:43:44 +0000

On 6 February 2015 at 16:20, Richard Henderson <address@hidden> wrote:
> It should be enough to simply add the unsigned suffix to the integers as they
> are, forcing the underlying type to be unsigned.

I can't see anything in the C99 spec that justifies this
as a fix... In fact, 6.7.2.2 para 3 says
"The identifiers in an enumerator list are declared as
constants that have type int", which sounds to me like it
means "if you have enum { foo = ..., }; then 'foo' must
have (signed) integer type even if the representation
of the enum type is unsigned".

And indeed:
e104462:trusty:qemu$ cat /tmp/zz9.c
enum { foo = 1U };

int main(void)
{
    return foo << 31;
}
e104462:trusty:qemu$ clang -fsanitize=undefined -Wall /tmp/zz9.c -o /tmp/zz9
e104462:trusty:qemu$ /tmp/zz9
/tmp/zz9.c:5:16: runtime error: left shift of 1 by 31 places cannot be
represented in type 'int'

-- PMM



reply via email to

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