[clang] 0d6b26b - [Clang] Fix a crash when encountering an ill-formed delimited UCN.
Corentin Jabot via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 3 11:57:59 PST 2023
Author: Corentin Jabot
Date: 2023-01-03T20:57:52+01:00
New Revision: 0d6b26b4d3e3991da16f5b7f53e397b0051e8598
URL: https://github.com/llvm/llvm-project/commit/0d6b26b4d3e3991da16f5b7f53e397b0051e8598
DIFF: https://github.com/llvm/llvm-project/commit/0d6b26b4d3e3991da16f5b7f53e397b0051e8598.diff
LOG: [Clang] Fix a crash when encountering an ill-formed delimited UCN.
\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
Added:
Modified:
clang/lib/Lex/Lexer.cpp
clang/test/Preprocessor/ucn-pp-identifier.c
Removed:
################################################################################
diff --git a/clang/lib/Lex/Lexer.cpp b/clang/lib/Lex/Lexer.cpp
index 2f21f7b069cfe..ce48e7da21bb3 100644
--- a/clang/lib/Lex/Lexer.cpp
+++ b/clang/lib/Lex/Lexer.cpp
@@ -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;
diff --git a/clang/test/Preprocessor/ucn-pp-identifier.c b/clang/test/Preprocessor/ucn-pp-identifier.c
index 8d30a6a2bb239..c47ed21ff3158 100644
--- a/clang/test/Preprocessor/ucn-pp-identifier.c
+++ b/clang/test/Preprocessor/ucn-pp-identifier.c
@@ -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}}
More information about the cfe-commits
mailing list