Skip to content

Commit 36a2002

Browse files
committed
[clang][Lex] Fix a crash on malformed string literals
Differential Revision: https://reviews.llvm.org/D135161
1 parent 05fa8e8 commit 36a2002

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

clang/lib/Lex/LiteralSupport.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -545,7 +545,6 @@ static bool ProcessNamedUCNEscape(const char *ThisTokBegin,
545545
diag::err_delimited_escape_missing_brace)
546546
<< StringRef(&ThisTokBuf[-1], 1);
547547
}
548-
ThisTokBuf++;
549548
return false;
550549
}
551550
ThisTokBuf++;

clang/test/Lexer/char-escapes-delimited.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ void named(void) {
9494

9595
unsigned h = U'\N{LOTUS}'; // ext-warning {{extension}} cxx2b-warning {{C++2b}}
9696
unsigned i = u'\N{GREEK CAPITAL LETTER DELTA}'; // ext-warning {{extension}} cxx2b-warning {{C++2b}}
97-
char j = '\NN'; // expected-error {{expected '{' after '\N' escape sequence}}
97+
char j = '\NN'; // expected-error {{expected '{' after '\N' escape sequence}} expected-warning {{multi-character character constant}}
9898
unsigned k = u'\N{LOTUS'; // expected-error {{incomplete universal character name}}
9999
}
100100

clang/unittests/Lex/LexerTest.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "clang/Basic/TokenKinds.h"
1919
#include "clang/Lex/HeaderSearch.h"
2020
#include "clang/Lex/HeaderSearchOptions.h"
21+
#include "clang/Lex/LiteralSupport.h"
2122
#include "clang/Lex/MacroArgs.h"
2223
#include "clang/Lex/MacroInfo.h"
2324
#include "clang/Lex/ModuleLoader.h"
@@ -659,4 +660,11 @@ TEST_F(LexerTest, RawAndNormalLexSameForLineComments) {
659660
}
660661
EXPECT_TRUE(ToksView.empty());
661662
}
663+
664+
TEST_F(LexerTest, BrokenStringLiteral) {
665+
const llvm::StringLiteral Source = R"cpp("\N")cpp";
666+
// Make sure this isn't crashing.
667+
StringLiteralParser P(Lex(Source), *PP);
668+
EXPECT_TRUE(P.hadError);
669+
}
662670
} // anonymous namespace

0 commit comments

Comments
 (0)