Skip to content

Commit

Permalink
[Clang] Fix a crash when encountering an ill-formed delimited UCN.
Browse files Browse the repository at this point in the history
\u<DIGIT>{...} was incorrectly parsed as a valid UCN instead
of emitting a diagnostic, causing an assertion failure.

Reviewed By: tahonermann

Differential Revision: https://reviews.llvm.org/D139889
  • Loading branch information
cor3ntin committed Jan 3, 2023
1 parent a315534 commit 0d6b26b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion clang/lib/Lex/Lexer.cpp
Expand Up @@ -3286,7 +3286,7 @@ llvm::Optional<uint32_t> Lexer::tryReadNumericUCN(const char *&StartPtr,
uint32_t CodePoint = 0;
while (Count != NumHexDigits || Delimited) {
char C = getCharAndSize(CurPtr, CharSize);
if (!Delimited && C == '{') {
if (!Delimited && Count == 0 && C == '{') {
Delimited = true;
CurPtr += CharSize;
continue;
Expand Down
1 change: 1 addition & 0 deletions clang/test/Preprocessor/ucn-pp-identifier.c
Expand Up @@ -117,6 +117,7 @@ C 1
// CHECK-NEXT: {{^ u}}

#define \u{} // expected-warning {{empty delimited universal character name; treating as '\' 'u' '{' '}'}} expected-error {{macro name must be an identifier}}
#define \u1{123} // expected-warning {{incomplete universal character name; treating as '\' followed by identifier}} expected-error {{macro name must be an identifier}}
#define \u{123456789} // expected-error {{hex escape sequence out of range}} expected-error {{macro name must be an identifier}}
#define \u{ // expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
#define \u{fgh} // expected-warning {{incomplete delimited universal character name; treating as '\' 'u' '{' identifier}} expected-error {{macro name must be an identifier}}
Expand Down

0 comments on commit 0d6b26b

Please sign in to comment.