[PATCH] D100252: Fix for "Bug 27113 - MSVC-compat __identifier implementation incomplete"

Melvin Fox via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sat Apr 10 18:27:20 PDT 2021


super_concat created this revision.
super_concat added a reviewer: rsmith.
super_concat added a project: clang.
super_concat requested review of this revision.

this patch fixes Bug 27113 <https://bugs.llvm.org/show_bug.cgi?id=27113> by adding support for string literals to the implementation of the MS extension `__identifier`.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D100252

Files:
  clang/lib/Lex/PPMacroExpansion.cpp
  clang/test/Parser/MicrosoftExtensions.cpp


Index: clang/test/Parser/MicrosoftExtensions.cpp
===================================================================
--- clang/test/Parser/MicrosoftExtensions.cpp
+++ clang/test/Parser/MicrosoftExtensions.cpp
@@ -270,8 +270,10 @@
   // FIXME: We should pick a friendlier display name for this token kind.
   __identifier(1) // expected-error {{cannot convert <numeric_constant> token to an identifier}}
   __identifier(+) // expected-error {{cannot convert '+' token to an identifier}}
-  __identifier("foo") // expected-error {{cannot convert <string_literal> token to an identifier}}
   __identifier(;) // expected-error {{cannot convert ';' token to an identifier}}
+  __identifier("1"); // expected-error {{use of undeclared identifier '1'}}
+  __identifier("+"); // expected-error {{use of undeclared identifier '+'}}
+  __identifier(";"); // expected-error {{use of undeclared identifier ';'}}
 }
 
 class inline_definition_pure_spec {
Index: clang/lib/Lex/PPMacroExpansion.cpp
===================================================================
--- clang/lib/Lex/PPMacroExpansion.cpp
+++ clang/lib/Lex/PPMacroExpansion.cpp
@@ -1813,7 +1813,11 @@
 
     if (!Tok.isAnnotation() && Tok.getIdentifierInfo())
       Tok.setKind(tok::identifier);
-    else {
+    else if (Tok.is(tok::string_literal)) {
+      const StringRef StrData(Tok.getLiteralData() + 1, Tok.getLength() - 2);
+      Tok.setIdentifierInfo(this->getIdentifierInfo(StrData));
+      Tok.setKind(tok::identifier);
+    } else {
       Diag(Tok.getLocation(), diag::err_pp_identifier_arg_not_identifier)
         << Tok.getKind();
       // Don't walk past anything that's not a real token.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100252.336634.patch
Type: text/x-patch
Size: 1662 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210411/41df2798/attachment-0001.bin>


More information about the cfe-commits mailing list