linux-sparse.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Sparse preprocessing bug with zero-arg variadic macros
@ 2017-08-31 13:34 Josh Poimboeuf
  2017-08-31 17:19 ` Linus Torvalds
  0 siblings, 1 reply; 7+ messages in thread
From: Josh Poimboeuf @ 2017-08-31 13:34 UTC (permalink / raw)
  To: linux-sparse

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

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2017-09-01  0:06 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-08-31 13:34 Sparse preprocessing bug with zero-arg variadic macros Josh Poimboeuf
2017-08-31 17:19 ` Linus Torvalds
2017-08-31 20:54   ` Al Viro
2017-08-31 21:09     ` Al Viro
2017-08-31 21:34       ` Josh Triplett
2017-08-31 21:48         ` Al Viro
2017-09-01  0:06           ` Christopher Li

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).