Issue with inline functions and switch statements

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

 



Hello,

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?

-Stafford

--

/* From: https://github.com/stffrdhrn/junk/tree/master/sparse-shift
 * Run with : sparse -O2 --arch=openrisc -m32 simple_test.c
 */
#include <stdio.h>

typedef unsigned long int u32;

static inline u32 shift_small(int size)
{
	return 1 << (size * 8);
}

static inline u32 test(int size) {
	printf ("Test size=%d: ", size);
	switch (size) {
	case 1:
	case 2:
		return shift_small(size);
	case 4:
		printf ("not small\n");
		return 99;
	default:
		return 9999;
	}
}

int main(int argc, char ** argv) {
	test(1);

	test(2);

	test(4); // simple_test.c:7:18: warning: shift too big (32) for type int

	return 0;
}



[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