From 9d22bcc53e70a597ccdfc2c4c1a2276a5bbeee00 Mon Sep 17 00:00:00 2001 From: Daniel Jasper Date: Mon, 19 Jan 2015 10:51:05 +0000 Subject: [PATCH] clang-format: Fix assertion when trying to build a nullptr StringRef. llvm-svn: 226448 --- clang/lib/Format/UnwrappedLineParser.cpp | 1 + clang/unittests/Format/FormatTest.cpp | 1 + 2 files changed, 2 insertions(+) diff --git a/clang/lib/Format/UnwrappedLineParser.cpp b/clang/lib/Format/UnwrappedLineParser.cpp index 00dc1bd..23b9d55 100644 --- a/clang/lib/Format/UnwrappedLineParser.cpp +++ b/clang/lib/Format/UnwrappedLineParser.cpp @@ -549,6 +549,7 @@ void UnwrappedLineParser::conditionalCompilationEnd() { 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); diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index 5f8fba26e..7987e58 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -2600,6 +2600,7 @@ TEST_F(FormatTest, MacroDefinitionsWithIncompleteCode) { " y)), // expected-warning", getLLVMStyleWithColumns(28)); verifyFormat("#d, = };"); + verifyFormat("#if \"a"); } TEST_F(FormatTest, MacrosWithoutTrailingSemicolon) { -- 2.7.4