Re: Issue with inline functions and switch statements

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

 



On Mon, Aug 03, 2020 at 11:29:03PM +0900, Stafford Horne wrote:
> Hello,

Hi,
 
> I am the maintainer of the OpenRISC architecture linux port, and recently have
> started to look at the kbuild sparse errors.
> 
> The Linux kernel kbuild process is reporting sparse error:
> 
>    net/dccp/proto.c: note: in included file (through include/asm-generic/atomic.h, arch/openrisc/include/asm/atomic.h, include/linux/atomic.h, ...):
>    arch/openrisc/include/asm/cmpxchg.h:101:29: sparse: sparse: shift too big (32) for type int
> 
> Example: https://www.mail-archive.com/linux-kernel@xxxxxxxxxxxxxxx/msg2256733.html
> 
> I have traced this down to the case like the below.
> 
> It reports an unexpected warning:
> 
>    simple_test.c:7:18: warning: shift too big (32) for type int
> 
> This is not pssible because size = 4 should never call shift_small.
> 
> I have debugged sparse when this is running and it seems that when checking the switch
> cases it evaluates all cases, and thinks size = 4 is possible.  I am not sure if this
> is a problem with the sparse front end of the check logic.
> 
> Can you help?

Sure. The problem is sparse sees the expression '1 << (4 * 8)' 
and warns about it before it can know it will never be evaluated.
The exact same problem happens with an even simpler example:
	int foo(void)
	{
		return 0;
		return 1 << 32;
	}

I have an old series for this problem, I would just need to dust off.
It shouldn't take much time, probably just a few days, maximum 10
(but I vaguely remember there was a nasty complication, which is
why it's still pending).

Best regards,
-- Luc



[Index of Archives]     [Newbies FAQ]     [LKML]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Trinity Fuzzer Tool]

  Powered by Linux