[clang] b5b3843 - [clang] Fix for "Bug 27113 - MSVC-compat __identifier implementation incomplete"
Hans Wennborg via cfe-commits
cfe-commits at lists.llvm.org
Fri May 21 02:14:15 PDT 2021
Author: Melvin Fox
Date: 2021-05-21T11:14:01+02:00
New Revision: b5b3843f8d9327039bbcc08b61ff768081a2220d
URL: https://github.com/llvm/llvm-project/commit/b5b3843f8d9327039bbcc08b61ff768081a2220d
DIFF: https://github.com/llvm/llvm-project/commit/b5b3843f8d9327039bbcc08b61ff768081a2220d.diff
LOG: [clang] Fix for "Bug 27113 - MSVC-compat __identifier implementation incomplete"
this patch fixes Bug 27113 by adding support for string literals to the
implementation of the MS extension __identifier.
Differential revision: https://reviews.llvm.org/D100252
Added:
Modified:
clang/lib/Lex/PPMacroExpansion.cpp
clang/test/Parser/MicrosoftExtensions.cpp
Removed:
################################################################################
diff --git a/clang/lib/Lex/PPMacroExpansion.cpp b/clang/lib/Lex/PPMacroExpansion.cpp
index 9528a8f575f0c..74ef9df592dbe 100644
--- a/clang/lib/Lex/PPMacroExpansion.cpp
+++ b/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 @@ void Preprocessor::ExpandBuiltinMacro(Token &Tok) {
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.
diff --git a/clang/test/Parser/MicrosoftExtensions.cpp b/clang/test/Parser/MicrosoftExtensions.cpp
index 9706eecce2db2..c625bf3d6befc 100644
--- a/clang/test/Parser/MicrosoftExtensions.cpp
+++ b/clang/test/Parser/MicrosoftExtensions.cpp
@@ -263,6 +263,12 @@ int k = identifier_weird(if)); // expected-error {{use of undeclared identifier
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 @@ void f() {
// 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 {
More information about the cfe-commits
mailing list