Re: <infiniband/verbs.h> & ICC

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

 



+Zuoyu,

Hi Zuoyo,

What compiler flags were you using while compiling the <verbs.h>
file throwing the error about 'enumeration value is out of "int" range'?


On 23/05/2019 18.30, Jason Gunthorpe wrote:
> On Thu, May 23, 2019 at 03:57:29PM -0700, Gerd Rausch wrote:
>>
>> error: enumeration value is out of "int" range
>>          IBV_RX_HASH_INNER = (1UL << 31),
> 
> I assume you are running with some higher warning flags and -Werror?
> gcc will not emit this warning without -Wpedantic
> 

Perhaps. I've added Zuoyu, who reported this issue
to this e-mail thread.

> 
>> Since "int" is signed, it can't hold the unsigned value of 1UL<<31
>> on target platforms with sizeof(int) <= 4.
> 
> Pedentically yes, but gcc and any compiler that can compile on linux
> supports an extension where the underlying type of an enum constant is
> automatically increased until it can hold the value of the
> constant. In this case the constant is type promoted to long,
> IIRC.
> 

Evidently ICC supports that as well:
% icc --version
icc (ICC) 17.0.5 20170817
Copyright (C) 1985-2017 Intel Corporation.  All rights reserved.

% cat foo.c
enum { FOO = 1UL << 31 } foo = FOO;

% icc -c -g foo.c && gdb -ex 'ptype foo' -ex 'print sizeof foo' foo.o
type = enum {FOO = -2147483648}
$1 = 4

% cat bar.c
enum { FOO = 1UL << 31, BAR = -1 } bar = BAR;
% icc -c -g bar.c && gdb -ex 'ptype bar' -ex 'print sizeof bar' bar.o
type = enum {FOO = -2147483648, BAR = -1}
$1 = 8

I can't say that I'm thrilled with this behavior though,
as it appears error-prone:
As soon as an enum value goes out of range for an "int", the
type silently changes, potentially rendering structures and functions silently incompatible.
It's quite the pitfall (e.g. the foo.c vs bar.c case above).

> 
> Can you clarify if icc is being run in some wonky mode that is causing
> this warning? AFAIK icc will compile the linux kernel, and the kernel
> makes extensive use of this extension. So I think the compiler is not
> configured properly.
> 

I've added Zuoyu to the distribution to shed some light on that.

> IIRC I looked at this once for -Wpedantic support and decided it was a
> lot of work as there are more cases than just this.
> 

Not exactly shocking news ;-)

Thanks for providing the information,

  Gerd



[Index of Archives]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Photo]     [Yosemite News]     [Yosemite Photos]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux