[cfe-commits] r171635 - in /cfe/trunk: lib/Format/UnwrappedLineParser.cpp unittests/Format/FormatTest.cpp

Manuel Klimek klimek at google.com
Sat Jan 5 13:34:55 PST 2013


Author: klimek
Date: Sat Jan  5 15:34:55 2013
New Revision: 171635

URL: http://llvm.org/viewvc/llvm-project?rev=171635&view=rev
Log:
Fixes PR14811: Crash when formatting some macros

A preprocessor directive cannot be started while we're parsing one.

Modified:
    cfe/trunk/lib/Format/UnwrappedLineParser.cpp
    cfe/trunk/unittests/Format/FormatTest.cpp

Modified: cfe/trunk/lib/Format/UnwrappedLineParser.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/UnwrappedLineParser.cpp?rev=171635&r1=171634&r2=171635&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Sat Jan  5 15:34:55 2013
@@ -469,7 +469,7 @@
 
 void UnwrappedLineParser::readToken() {
   FormatTok = Tokens->getNextToken();
-  while (FormatTok.Tok.is(tok::hash)) {
+  while (!Line.InPPDirective && FormatTok.Tok.is(tok::hash)) {
     // FIXME: This is incorrect - the correct way is to create a
     // data structure that will construct the parts around the preprocessor
     // directive as a structured \c UnwrappedLine.

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=171635&r1=171634&r2=171635&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Sat Jan  5 15:34:55 2013
@@ -458,6 +458,14 @@
   EXPECT_EQ("int x,\n#define A\ny;", format("int x,\n#define A\ny;"));
 }
 
+TEST_F(FormatTest, HashInMacroDefinition) {
+  verifyFormat("#define A \\\n  b #c;", getLLVMStyleWithColumns(11));
+  verifyFormat("#define A \\\n"
+               "  {       \\\n"
+               "    f(#c);\\\n"
+               "  }", getLLVMStyleWithColumns(11));
+}
+
 // FIXME: write test for unbalanced braces in macros...
 // FIXME: test { { #include "a.h" } }
 // FIXME: test # in the middle of a statement without \n before it





More information about the cfe-commits mailing list