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

2021-05-20 Thread Melvin Fox via Phabricator via cfe-commits
super_concat marked 3 inline comments as done.
super_concat added a comment.

@hans, could you land this for me? I do not have commit access.


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

https://reviews.llvm.org/D100252

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-05-19 Thread Melvin Fox via Phabricator via cfe-commits
super_concat updated this revision to Diff 346595.
super_concat added a comment.

Correctly handle string literals and add more test cases. Also MSVC 
 by default gives an error when trying to use 
`__identifier` with a string literal but disabling/surprising that error allows 
string literals to be used with `__identifier`. However given how esoteric it 
is, it wouldn't really be necessary for clang to give a warning or error like 
MSVC


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

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
@@ -263,6 +263,12 @@
 
 extern int __identifier(and);
 
+int __identifier("baz") = 0;
+int bar = baz;
+
+void mangled_function();
+extern "C" void __identifier("?mangled_function@@YAXXZ")() {}
+
 void f() {
   __identifier(() // expected-error {{cannot convert '(' token to an 
identifier}}
   __identifier(void) // expected-error {{use of undeclared identifier 'void'}}
@@ -270,8 +276,10 @@
   // FIXME: We should pick a friendlier display name for this token kind.
   __identifier(1) // expected-error {{cannot convert  token 
to an identifier}}
   __identifier(+) // expected-error {{cannot convert '+' token to an 
identifier}}
-  __identifier("foo") // expected-error {{cannot convert  
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
@@ -25,6 +25,7 @@
 #include "clang/Lex/ExternalPreprocessorSource.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/LexDiagnostic.h"
+#include "clang/Lex/LiteralSupport.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
@@ -1813,7 +1814,14 @@
 
 if (!Tok.isAnnotation() && Tok.getIdentifierInfo())
   Tok.setKind(tok::identifier);
-else {
+else if (Tok.is(tok::string_literal) && !Tok.hasUDSuffix()) {
+  StringLiteralParser Literal(Tok, *this);
+  if (Literal.hadError)
+return;
+
+  Tok.setIdentifierInfo(getIdentifierInfo(Literal.GetString()));
+  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.


Index: clang/test/Parser/MicrosoftExtensions.cpp
===
--- clang/test/Parser/MicrosoftExtensions.cpp
+++ clang/test/Parser/MicrosoftExtensions.cpp
@@ -263,6 +263,12 @@
 
 extern int __identifier(and);
 
+int __identifier("baz") = 0;
+int bar = baz;
+
+void mangled_function();
+extern "C" void __identifier("?mangled_function@@YAXXZ")() {}
+
 void f() {
   __identifier(() // expected-error {{cannot convert '(' token to an identifier}}
   __identifier(void) // expected-error {{use of undeclared identifier 'void'}}
@@ -270,8 +276,10 @@
   // FIXME: We should pick a friendlier display name for this token kind.
   __identifier(1) // expected-error {{cannot convert  token to an identifier}}
   __identifier(+) // expected-error {{cannot convert '+' token to an identifier}}
-  __identifier("foo") // expected-error {{cannot convert  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
@@ -25,6 +25,7 @@
 #include "clang/Lex/ExternalPreprocessorSource.h"
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/LexDiagnostic.h"
+#include "clang/Lex/LiteralSupport.h"
 #include "clang/Lex/MacroArgs.h"
 #include "clang/Lex/MacroInfo.h"
 #include "clang/Lex/Preprocessor.h"
@@ -1813,7 +1814,14 @@
 
 if (!Tok.isAnnotation() && Tok.getIdentifierInfo())
   Tok.setKind(tok::identifier);
-else {
+else if (Tok.is(tok::string_literal) && !Tok.hasUDSuffix()) {
+  StringLiteralParser Literal(Tok, 

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

2021-05-18 Thread Melvin Fox via Phabricator via cfe-commits
super_concat added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100252

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-05-07 Thread Melvin Fox via Phabricator via cfe-commits
super_concat added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100252

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-04-29 Thread Melvin Fox via Phabricator via cfe-commits
super_concat added a comment.

Ping


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D100252

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2021-04-10 Thread Melvin Fox via Phabricator via cfe-commits
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  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  token 
to an identifier}}
   __identifier(+) // expected-error {{cannot convert '+' token to an 
identifier}}
-  __identifier("foo") // expected-error {{cannot convert  
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.


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  token to an identifier}}
   __identifier(+) // expected-error {{cannot convert '+' token to an identifier}}
-  __identifier("foo") // expected-error {{cannot convert  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.
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits