Re: [PATCH] IB/mlx4: Avoid implicit enumerated type conversion

From: Bart Van Assche
Date: Thu Sep 27 2018 - 19:09:05 EST

On Thu, 2018-09-27 at 16:58 -0600, Jason Gunthorpe wrote:
+AD4 Anyhow, the standard is hard to read in this area, but reality is
+AD4 this:
+AD4 +ACM-include +ADw-stdio.h+AD4
+AD4 enum a
+AD4 +AHs
+AD4 A1 +AD0 1,
+AD4 A2 +AD0 1ULL+ADwAPA-40,
+AD4 +AH0AOw
+AD4 int main(int argc, const char +ACo-argv+AFsAXQ)
+AD4 +AHs
+AD4 printf(+ACIAJQ-zu+AFw-n+ACI, sizeof(enum a))+ADs
+AD4 return 0+ADs
+AD4 +AH0
+AD4 +ACQ gcc -Wall -std+AD0-c11 test.c +ACYAJg ./a.out
+AD4 8
+AD4 I forget if this a common compiler extension, unclear standard, or was
+AD4 formally revised in C11 or what, but it is the real world the Linux
+AD4 kernel lives in.
+AD4 It is even more confusing if you wonder what types A1 and A2 are+ACE

What's unfortunate is that gcc and sparse have different opinions about how
to compile the above code. Even if gcc supports enumeration constants that
exceed what fits in an int, sparse does not AFAIK.