[cfe-commits] r68511 - in /cfe/trunk: test/Preprocessor/macro-multiline.c tools/clang-cc/clang-cc.cpp

Chris Lattner sabre at nondot.org
Mon Apr 6 23:02:44 PDT 2009


Author: lattner
Date: Tue Apr  7 01:02:44 2009
New Revision: 68511

URL: http://llvm.org/viewvc/llvm-project?rev=68511&view=rev
Log:
implement rdar://6762183.  I'm not sure if it is more insane that
GCC ignores macro definitions after \n's or that real code depends
on this.

Added:
    cfe/trunk/test/Preprocessor/macro-multiline.c
Modified:
    cfe/trunk/tools/clang-cc/clang-cc.cpp

Added: cfe/trunk/test/Preprocessor/macro-multiline.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Preprocessor/macro-multiline.c?rev=68511&view=auto

==============================================================================
--- cfe/trunk/test/Preprocessor/macro-multiline.c (added)
+++ cfe/trunk/test/Preprocessor/macro-multiline.c Tue Apr  7 01:02:44 2009
@@ -0,0 +1,8 @@
+// RUN: clang -E %s "-DX=A
+// RUN: THIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT" > %t &&
+// RUN: grep "GOOD: A" %t &&
+// RUN: not grep THIS_SHOULD_NOT_EXIST_IN_THE_OUTPUT %t
+// rdar://6762183
+
+GOOD: X
+

Modified: cfe/trunk/tools/clang-cc/clang-cc.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/tools/clang-cc/clang-cc.cpp?rev=68511&r1=68510&r2=68511&view=diff

==============================================================================
--- cfe/trunk/tools/clang-cc/clang-cc.cpp (original)
+++ cfe/trunk/tools/clang-cc/clang-cc.cpp Tue Apr  7 01:02:44 2009
@@ -969,7 +969,12 @@
     // Turn the = into ' '.
     Buf.insert(Buf.end(), Macro, Equal);
     Buf.push_back(' ');
-    Buf.insert(Buf.end(), Equal+1, Equal+strlen(Equal));
+    
+    // Per GCC -D semantics, the macro ends at \n if it exists.
+    const char *End = strpbrk(Equal, "\n\r");
+    if (End == 0) End = Equal+strlen(Equal);
+    
+    Buf.insert(Buf.end(), Equal+1, End);
   } else {
     // Push "macroname 1".
     Buf.insert(Buf.end(), Macro, Macro+strlen(Macro));





More information about the cfe-commits mailing list