Sparse preprocessing bug with zero-arg variadic macros

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

 



Hi,

I think I'm seeing a bug in the sparse preprocessor.  I've reduced it to
the following test case.

----------------------
/* If the macro has arguments, prepend them with a comma. */
#define ARGS_APPEND(...) , ## __VA_ARGS__

#define __ARG17(_0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12,	\
		_13, _14, _15, _16, _17, ...) _17

/* Return 1 if the macro has arguments, 0 otherwise. */
#define HAS_ARGS(...) __ARG17(0, ## __VA_ARGS__, 1, 1, 1, 1, 1, 1, 1,	\
			      1, 1, 1, 1, 1, 1, 1, 1, 1, 0)

/* Macros for passing inline asm constraints as macro arguments */
#define ARGS(args...) args
#define OUTPUTS ARGS
#define INPUTS ARGS
#define CLOBBERS ARGS

#define __CLOBBERS_APPEND_0(...)
#define __CLOBBERS_APPEND_1(...)  , __VA_ARGS__

#define __CLOBBERS_APPEND(has_args, ...) \
	__CLOBBERS_APPEND_ ## has_args (__VA_ARGS__)

#define _CLOBBERS_APPEND(has_args, ...) \
	__CLOBBERS_APPEND(has_args, __VA_ARGS__)

/* If the macro has arguments, prepend them with a colon. */
#define CLOBBERS_APPEND(...) \
	_CLOBBERS_APPEND(HAS_ARGS(__VA_ARGS__), __VA_ARGS__)


void foo()
{
	ARGS_APPEND()
	CLOBBERS_APPEND()
}
----------------------

  $ gcc -c -o test.o test.c -E; cat test.o
  # 1 "test.c"
  # 1 "<built-in>"
  # 1 "<command-line>"
  # 31 "<command-line>"
  # 1 "/usr/include/stdc-predef.h" 1 3 4
  # 32 "<command-line>" 2
  # 1 "test.c"
  # 31 "test.c"
  void foo()
  {
  
  
  }

  $ sparse -c -o test.o test.c -E
  
  void foo()
  {
  			,
  			,
  }


Notice that sparse incorrectly inserts a comma for both macros when they
have zero arguments.

-- 
Josh
--
To unsubscribe from this list: send the line "unsubscribe linux-sparse" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[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