r226448 - clang-format: Fix assertion when trying to build a nullptr StringRef.

Daniel Jasper djasper at google.com
Mon Jan 19 02:51:05 PST 2015


Author: djasper
Date: Mon Jan 19 04:51:05 2015
New Revision: 226448

URL: http://llvm.org/viewvc/llvm-project?rev=226448&view=rev
Log:
clang-format: Fix assertion when trying to build a nullptr StringRef.

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=226448&r1=226447&r2=226448&view=diff
==============================================================================
--- cfe/trunk/lib/Format/UnwrappedLineParser.cpp (original)
+++ cfe/trunk/lib/Format/UnwrappedLineParser.cpp Mon Jan 19 04:51:05 2015
@@ -549,6 +549,7 @@ void UnwrappedLineParser::conditionalCom
 void UnwrappedLineParser::parsePPIf(bool IfDef) {
   nextToken();
   bool IsLiteralFalse = (FormatTok->Tok.isLiteral() &&
+                         FormatTok->Tok.getLiteralData() != nullptr &&
                          StringRef(FormatTok->Tok.getLiteralData(),
                                    FormatTok->Tok.getLength()) == "0") ||
                         FormatTok->Tok.is(tok::kw_false);

Modified: cfe/trunk/unittests/Format/FormatTest.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTest.cpp?rev=226448&r1=226447&r2=226448&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTest.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTest.cpp Mon Jan 19 04:51:05 2015
@@ -2600,6 +2600,7 @@ TEST_F(FormatTest, MacroDefinitionsWithI
                "    y)), // expected-warning",
                getLLVMStyleWithColumns(28));
   verifyFormat("#d, = };");
+  verifyFormat("#if \"a");
 }
 
 TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) {





More information about the cfe-commits mailing list