[PATCH] D139889: [Clang] Fix a crash when encountering an ill-formed delimited UCN.

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Dec 12 15:29:01 PST 2022


cor3ntin created this revision.
Herald added a project: All.
cor3ntin requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.

\u<DIGIT>{...} was incorrectly parsed as a valid UCN instead
of emitting a diagnostic, causing an assertion failure.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D139889

Files:
  clang/lib/Lex/Lexer.cpp
  clang/test/Preprocessor/ucn-pp-identifier.c


Index: clang/test/Preprocessor/ucn-pp-identifier.c
===================================================================
--- clang/test/Preprocessor/ucn-pp-identifier.c
+++ clang/test/Preprocessor/ucn-pp-identifier.c
@@ -118,6 +118,7 @@
 // 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}}
Index: clang/lib/Lex/Lexer.cpp
===================================================================
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -3224,7 +3224,7 @@
   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;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D139889.482294.patch
Type: text/x-patch
Size: 1573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221212/665f8655/attachment.bin>


More information about the cfe-commits mailing list