Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1361030

Re: [PATCH] x86: Avoid undefined behavior in macro expansion

From Al Viro <viro@ZenIV.linux.org.uk>
Newsgroups linux.kernel
Subject Re: [PATCH] x86: Avoid undefined behavior in macro expansion
Date 2016-03-19 03:20 +0100
Message-ID <reeEF-7K5-3@gated-at.bofh.it> (permalink)
References <rdwaB-15J-3@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


On Wed, Mar 16, 2016 at 11:48:49PM -0300, Vinicius Tinti wrote:
> C11 standard (at 6.10.3.3) says that ## operator (paste) has undefined
> behavior when one of the result operands is not a valid preprocessing
> token.
> 
> Therefore the macro expansion may depend on compiler implementation
> which may or no preserve the leading white space.
> 
> Moreover other places in kernel use CONCAT(a,b) instead of CONCAT(a, b).
> Changing favors concise usage.

Huh?

> -#define	XMM(i)		CONCAT(%xmm, i)
> +#define	XMM(i)		CONCAT(%xmm,i)

What are you talking about?  Undefined behaviour is when the result of
concatenation of adjacent tokens is not a valid preprocessor token.
It says nothing about the either argument being a single token.

In this case after the substitution of e.g. XMM(42) we get 3 tokens:
Punctuator[%] Identifier[xmm] Pp-number[42]
with ## instructing us to replace the last two with preprocessor token that
would be represented as concatenation of their representations.  Which is
to say, concatenation of xmm and 42, i.e. xmm42.  Which *is* a
representation of a valid preprocessor token - namely, Identifier[xmm42].
No undefined behaviour at all.  And yes, you get two preprocessor tokens
in the expansion - % and xmm42.  Preprocessor works in terms of tokens,
not strings...

If you know of any compiler where these two variants would produce different
expansions of XMM(<sequence of digits>), please report it to maintainers of
the compiler in question; it's a bug, plain and simple.  And no, there's
no undefined behaviour in that.

Back to linux.kernel | Previous | NextNext in thread | Find similar | Unroll thread


Thread

Re: [PATCH] x86: Avoid undefined behavior in macro expansion Al Viro <viro@ZenIV.linux.org.uk> - 2016-03-19 03:20 +0100
  Re: [PATCH] x86: Avoid undefined behavior in macro expansion Vinicius Tinti <viniciustinti@gmail.com> - 2016-03-22 03:20 +0100

csiph-web