PATCH: In -traditional mode, ignore token pasting and stringification (PR16371)
Eli Friedman
eli.friedman at gmail.com
Fri Jul 5 16:50:00 PDT 2013
On Fri, Jul 5, 2013 at 3:44 PM, Austin Seipp <aseipp at pobox.com> wrote:
> Hello,
>
> Attached is a patch that makes the preprocessor ignore token pasting
> (##) and stringification (#) when in -traditional mode. This makes it
> behave more like GCC[1].
>
> This change fixes PR16371, and is needed for Clang to function
> properly as a preprocessor for Haskell (in the Glasgow Haskell
> Compiler.) If you're curious and look at the bug, I made some
> incorrect assumptions about the behavior of -traditional for GCC (and
> attached a bad patch,) but this fixes the problem in the principled
> way. And the patch is simpler, which is good too.
>
> There is something this patch does not handle compared to GCC. For
> traditional macros, GCC will expand parameter identifiers *inside*
> string bodies. This allows you to imitate these operators. So this
> code:
>
> ---
> #define foo(a) test(#a)
> foo(123)
> ---
>
> would become the following under -traditional:
>
> ---
> #define foo(a) test("a")
> foo(123)
> ---
>
> and 'a' would be expanded to '123' inside the string. This would even
> occur in a case like:
>
> ---
> #define foo(a) test("this is a test")
> ---
>
> under -traditional mode.
>
> This patch does not attempt to implement this behavior; we don't need
> it in GHC, and Clang's -traditional is already a subset of what GCC
> supports anyway, and as a result it's pretty simple.
Completely emulating -traditional would be crazy with our current lexer and
parser implementation; I think the only implementation we would accept
would be implementing it from scratch, independent from the current Lexer.
(There wouldn't be much code duplication given how different the semantics
of traditional preprocessing are, and we could simplify the implementation
by assuming it's only used for preprocessed output.)
Richard, do you have an opinion on this patch? You've expressed some
concerns about -traditional-cpp before.
-Eli
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20130705/d33cfa51/attachment.html>
More information about the cfe-commits
mailing list