[PATCH] D130750: [Clang] Do not check for underscores in isAllowedInitiallyIDChar

Corentin Jabot via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 29 02:08:41 PDT 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.

isAllowedInitiallyIDChar is only used with non-ASCII codepoints,
which are handled by isAsciiIdentifierStart.
To make that clearer, remove the check for _ from
isAllowedInitiallyIDChar, and assert on ASCII - to ensure neither
_ or $ are passed to this function.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D130750

Files:
  clang/lib/Lex/Lexer.cpp


Index: clang/lib/Lex/Lexer.cpp
===================================================================
--- clang/lib/Lex/Lexer.cpp
+++ clang/lib/Lex/Lexer.cpp
@@ -1483,13 +1483,13 @@
 }
 
 static bool isAllowedInitiallyIDChar(uint32_t C, const LangOptions &LangOpts) {
+  assert(C > 0x7F && "isAllowedInitiallyIDChar called with a non-ASCII codepoint");
   if (LangOpts.AsmPreprocessor) {
     return false;
   }
   if (LangOpts.CPlusPlus || LangOpts.C2x) {
     static const llvm::sys::UnicodeCharSet XIDStartChars(XIDStartRanges);
-    // '_' doesn't have the XID_Start property but is allowed in C++.
-    return C == '_' || XIDStartChars.contains(C);
+    return XIDStartChars.contains(C);
   }
   if (!isAllowedIDChar(C, LangOpts))
     return false;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D130750.448553.patch
Type: text/x-patch
Size: 752 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220729/25026943/attachment-0001.bin>


More information about the cfe-commits mailing list