[cfe-dev] Clang macro expansion differs from GCC
clattner at apple.com
Thu Apr 8 09:48:47 PDT 2010
On Apr 8, 2010, at 8:34 AM, David Peixotto wrote:
> I have found a discrepancy in behavior between the clang preprocessor and gcc.
> $ cat t.c
> #define X 0 .. 1
> 0 .. 1 // Ok
> X // Bad: space between ..
> $ gcc -E t.c
> 0 .. 1
> 0 .. 1
> $ clang -E t.c
> 0 .. 1
> 0 . . 1
> The problem is that when ".." is in the macro and the macro gets expanded, it adds a space between the dots. As you can see, the space is not added when the ".." is entered directly in the text. GCC does not insert a space in either case.
> I'm not sure this qualifies as a bug, but the reason I need this to work is that I am trying to compile GHC (a Haskell compiler) with clang. It uses GCC to preprocess c-- files (http://www.cminusminus.org) before parsing them and ".." is a valid operator in c--. Adding the extra space messes up the subsequent parsing phase.
I'm not particularly interested in fixing this: people abusing the C preprocessor to preprocess things that aren't C don't get much sympathy from me. However, if you are able to produce a patch that works, doesn't break anything else, and doesn't affect performance, I'd be happy to apply it.
> I'd be happy to take a look at fixing this myself if someone could point me in the right direction.
lib/Frontend/PrintPreprocessedOutput.cpp is the code that outputs a .i file, the "AvoidConcat" stuff is what you want. It is what decides to add spaces to prevent three . tokens from looking like a ... for example.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the cfe-dev