[PATCH] D100252: [clang] Fix for "Bug 27113 - MSVC-compat __identifier implementation incomplete"
Melvin Fox via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed May 19 17:25:28 PDT 2021
super_concat updated this revision to Diff 346595.
super_concat added a comment.
Correctly handle string literals and add more test cases. Also MSVC <https://godbolt.org/z/r1Eadzzzq> 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 <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
@@ -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.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D100252.346595.patch
Type: text/x-patch
Size: 2365 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210520/1ae8abd0/attachment.bin>
More information about the cfe-commits
mailing list