r185896 - Don't give # and ## special treatment when in -traditional-cpp mode. Patch by

Richard Smith richard-llvm at metafoo.co.uk
Mon Jul 8 18:00:30 PDT 2013


Author: rsmith
Date: Mon Jul  8 20:00:29 2013
New Revision: 185896

URL: http://llvm.org/viewvc/llvm-project?rev=185896&view=rev
Log:
Don't give # and ## special treatment when in -traditional-cpp mode. Patch by
Austin Seipp!

Modified:
    cfe/trunk/lib/Lex/PPDirectives.cpp
    cfe/trunk/test/Preprocessor/traditional-cpp.c

Modified: cfe/trunk/lib/Lex/PPDirectives.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/PPDirectives.cpp?rev=185896&r1=185895&r2=185896&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/PPDirectives.cpp (original)
+++ cfe/trunk/lib/Lex/PPDirectives.cpp Mon Jul  8 20:00:29 2013
@@ -1905,6 +1905,18 @@ void Preprocessor::HandleDefineDirective
         continue;
       }
 
+      // If we're in -traditional mode, then we should ignore stringification
+      // and token pasting. Mark the tokens as unknown so as not to confuse
+      // things.
+      if (getLangOpts().TraditionalCPP) {
+        Tok.setKind(tok::unknown);
+        MI->AddTokenToBody(Tok);
+
+        // Get the next token of the macro.
+        LexUnexpandedToken(Tok);
+        continue;
+      }
+
       if (Tok.is(tok::hashhash)) {
         
         // If we see token pasting, check if it looks like the gcc comma

Modified: cfe/trunk/test/Preprocessor/traditional-cpp.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/traditional-cpp.c?rev=185896&r1=185895&r2=185896&view=diff
==============================================================================
--- cfe/trunk/test/Preprocessor/traditional-cpp.c (original)
+++ cfe/trunk/test/Preprocessor/traditional-cpp.c Mon Jul  8 20:00:29 2013
@@ -88,3 +88,20 @@ a b c in skipped block
 Preserve URLs: http://clang.llvm.org
 /* CHECK: {{^}}Preserve URLs: http://clang.llvm.org{{$}}
  */
+
+/* The following tests ensure we ignore # and ## in macro bodies */
+
+#define FOO_NO_STRINGIFY(a) test(# a)
+FOO_NO_STRINGIFY(foobar)
+/* CHECK: {{^}}test(# foobar){{$}}
+ */
+
+#define FOO_NO_PASTE(a, b) test(b##a)
+FOO_NO_PASTE(foo,bar)
+/* CHECK {{^}}test(bar##foo){{$}}
+ */
+
+#define BAR_NO_STRINGIFY(a) test(#a)
+BAR_NO_STRINGIFY(foobar)
+/* CHECK: {{^}}test(#foobar){{$}}
+ */





More information about the cfe-commits mailing list