[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
Tue Jan 3 11:58:14 PST 2023


This revision was automatically updated to reflect the committed changes.
Closed by commit rG0d6b26b4d3e3: [Clang] Fix a crash when encountering an ill-formed delimited UCN. (authored by cor3ntin).

Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D139889/new/

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
@@ -117,6 +117,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
@@ -3286,7 +3286,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.486045.patch
Type: text/x-patch
Size: 1573 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230103/ecc57832/attachment.bin>


More information about the cfe-commits mailing list