Thread (18 messages) 18 messages, 8 authors, 2023-01-21

Re: Calculating array sizes in C - was: Re: Build regressions/improvements in v6.2-rc1

From: Michael.Karcher <hidden>
Date: 2023-01-19 22:26:33
Also in: amd-gfx, linux-arm-kernel, linux-f2fs-devel, linux-media, linux-mips, linux-sh, linux-wireless, lkml

Isn't this supposed to be caught by this check:
quoted
quoted
         a, __same_type(a, NULL)

?
Yeah, but gcc thinks it is smarter than us...
Probably it drops the test, assuming UB cannot happen.
Hmm, sounds like a GGC bug to me then. Not sure how to fix this then.

I don't see a clear bug at this point. We are talking about the C expression

   __same_type((void*)0, (void*)0)? 0 : sizeof((void*)0)/sizeof(*((void*0))

This expression is valid (assuming __same_type works, which is a GCC 
extension), and should return 0. As of now, I have no indication that 
this expression does not return 0. Also, it is true that this expression 
contains the suspicious pattern "sizeof(void*)/sizeof(void)", which is 
does not calculate the size of any array. GCC is free to emit as much 
warnings is it wants for any kind of expressions. From a C standard 
point of view, it's just a "quality of implementation" issue, and an 
implementation that emits useless warnings is of low quality, but not 
non-conforming.

In this case, we requested that gcc refuses to compile if it emits any 
kind of warning, which instructs gcc to reject programs that would be 
valid according to the C standard, but are deemed to be "likely incorrect".

I suggest to file a bug against gcc complaining about a "spurious 
warning", and using "-Werror -Wno-error-sizeof-pointer-div" until gcc is 
adapted to not emit the warning about the pointer division if the result 
is not used.


Regards,
   Michael Karcher
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help