[clang][Lex] Fix a crash on malformed string literals

Differential Revision: https://reviews.llvm.org/D135161
This commit is contained in:
Kadir Cetinkaya 2022-10-04 17:06:24 +02:00
parent 05fa8e88f4
commit 36a200208f
No known key found for this signature in database
GPG Key ID: E39E36B8D2057ED6
3 changed files with 9 additions and 2 deletions

View File

@ -545,7 +545,6 @@ static bool ProcessNamedUCNEscape(const char *ThisTokBegin,
diag::err_delimited_escape_missing_brace)
<< StringRef(&ThisTokBuf[-1], 1);
}
ThisTokBuf++;
return false;
}
ThisTokBuf++;

View File

@ -94,7 +94,7 @@ void named(void) {
unsigned h = U'\N{LOTUS}'; // ext-warning {{extension}} cxx2b-warning {{C++2b}}
unsigned i = u'\N{GREEK CAPITAL LETTER DELTA}'; // ext-warning {{extension}} cxx2b-warning {{C++2b}}
char j = '\NN'; // expected-error {{expected '{' after '\N' escape sequence}}
char j = '\NN'; // expected-error {{expected '{' after '\N' escape sequence}} expected-warning {{multi-character character constant}}
unsigned k = u'\N{LOTUS'; // expected-error {{incomplete universal character name}}
}

View File

@ -18,6 +18,7 @@
#include "clang/Basic/TokenKinds.h"
#include "clang/Lex/HeaderSearch.h"
#include "clang/Lex/HeaderSearchOptions.h"
#include "clang/Lex/LiteralSupport.h"
#include "clang/Lex/MacroArgs.h"
#include "clang/Lex/MacroInfo.h"
#include "clang/Lex/ModuleLoader.h"
@ -659,4 +660,11 @@ TEST_F(LexerTest, RawAndNormalLexSameForLineComments) {
}
EXPECT_TRUE(ToksView.empty());
}
TEST_F(LexerTest, BrokenStringLiteral) {
const llvm::StringLiteral Source = R"cpp("\N")cpp";
// Make sure this isn't crashing.
StringLiteralParser P(Lex(Source), *PP);
EXPECT_TRUE(P.hadError);
}
} // anonymous namespace