r305087 - support operator keywords used in Windows SDK
Erich Keane via cfe-commits
cfe-commits at lists.llvm.org
Fri Jun 9 09:29:35 PDT 2017
Author: erichkeane
Date: Fri Jun 9 11:29:35 2017
New Revision: 305087
URL: http://llvm.org/viewvc/llvm-project?rev=305087&view=rev
Log:
support operator keywords used in Windows SDK
to support operator keywords used in Windows SDK, alter token type when
seen in system headers
Hello, I submitted D33505 to address this problem, but the
proposal was rejected as too big a hammer.
This change will allow clang to parse the WindowsSDK header <query.h>
which uses the operator name "or" as a field name. Treat cpp operator
keywords as ordinary identifiers inside the Microsoft headers, but
treat them as usual in the user's program.
Original Submitter: Melanie Blower (mibintc)
Differential Revision: https://reviews.llvm.org/D33782
Added:
cfe/trunk/test/Headers/ms-cppoperkey.cpp
cfe/trunk/test/Headers/ms-cppoperkey1.cpp
cfe/trunk/test/Headers/ms-cppoperkey2.cpp
Modified:
cfe/trunk/lib/Lex/Preprocessor.cpp
Modified: cfe/trunk/lib/Lex/Preprocessor.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Lex/Preprocessor.cpp?rev=305087&r1=305086&r2=305087&view=diff
==============================================================================
--- cfe/trunk/lib/Lex/Preprocessor.cpp (original)
+++ cfe/trunk/lib/Lex/Preprocessor.cpp Fri Jun 9 11:29:35 2017
@@ -580,7 +580,11 @@ IdentifierInfo *Preprocessor::LookUpIden
// Update the token info (identifier info and appropriate token kind).
Identifier.setIdentifierInfo(II);
- Identifier.setKind(II->getTokenID());
+ if (getLangOpts().MSVCCompat && II->isCPlusPlusOperatorKeyword() &&
+ getSourceManager().isInSystemHeader(Identifier.getLocation()))
+ Identifier.setKind(clang::tok::identifier);
+ else
+ Identifier.setKind(II->getTokenID());
return II;
}
Added: cfe/trunk/test/Headers/ms-cppoperkey.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-cppoperkey.cpp?rev=305087&view=auto
==============================================================================
--- cfe/trunk/test/Headers/ms-cppoperkey.cpp (added)
+++ cfe/trunk/test/Headers/ms-cppoperkey.cpp Fri Jun 9 11:29:35 2017
@@ -0,0 +1,16 @@
+// RUN: %clang_cc1 \
+// RUN: -fms-compatibility -x c++-cpp-output \
+// RUN: -ffreestanding -fsyntax-only -Werror \
+// RUN: %s -verify
+// expected-no-diagnostics
+# 1 "t.cpp"
+# 1 "query.h" 1 3
+// MS header <query.h> uses operator keyword as field name.
+// Compile without syntax errors.
+struct tagRESTRICTION
+ {
+ union _URes
+ {
+ int or; // Note use of cpp operator token
+ } res;
+ };
Added: cfe/trunk/test/Headers/ms-cppoperkey1.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-cppoperkey1.cpp?rev=305087&view=auto
==============================================================================
--- cfe/trunk/test/Headers/ms-cppoperkey1.cpp (added)
+++ cfe/trunk/test/Headers/ms-cppoperkey1.cpp Fri Jun 9 11:29:35 2017
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 \
+// RUN: -fms-compatibility -x c++-cpp-output \
+// RUN: -ffreestanding -fsyntax-only -Werror \
+// RUN: %s -verify
+
+
+# 1 "t.cpp"
+# 1 "query.h" 1 3 4
+// MS header <query.h> uses operator keyword as field name.
+// Compile without syntax errors.
+struct tagRESTRICTION
+ {
+ union _URes
+ {
+ int or; // Note use of cpp operator token
+ } res;
+ };
+ ;
+
+int aa ( int x)
+{
+ // In system header code, treat operator keyword as identifier.
+ if ( // expected-note{{to match this '('}}
+ x>1 or x<0) return 1; // expected-error{{expected ')'}}
+ else return 0;
+}
+
Added: cfe/trunk/test/Headers/ms-cppoperkey2.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Headers/ms-cppoperkey2.cpp?rev=305087&view=auto
==============================================================================
--- cfe/trunk/test/Headers/ms-cppoperkey2.cpp (added)
+++ cfe/trunk/test/Headers/ms-cppoperkey2.cpp Fri Jun 9 11:29:35 2017
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -triple x86_64-pc-win32 -fms-compatibility \
+// RUN: -ffreestanding -fsyntax-only -Werror %s -verify
+// RUN: %clang_cc1 \
+// RUN: -ffreestanding -fsyntax-only -Werror %s -verify
+// expected-no-diagnostics
+int bb ( int x)
+{
+ // In user code, treat operator keyword as operator keyword.
+ if ( x>1 or x<0) return 1;
+ else return 0;
+}
More information about the cfe-commits
mailing list