[PATCH] D17330: PR26648: "inline" shouldn't be recognized as a C keyword in MSVC 2013 compatibility mode

Andrey Bokhanko via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 17 02:44:27 PST 2016


andreybokhanko created this revision.
andreybokhanko added reviewers: rnk, majnemer, thakis.
andreybokhanko added a subscriber: cfe-commits.

See PR26648 for full description of the problem.

Here I added a new keyword flag (KEYNOMS18_C) for keywords that shouldn't be enabled in MSVC 2013 mode for C programs and set it for "inline".

Andrey


http://reviews.llvm.org/D17330

Files:
  include/clang/Basic/TokenKinds.def
  lib/Basic/IdentifierTable.cpp
  test/Sema/inline-ms.c

Index: lib/Basic/IdentifierTable.cpp
===================================================================
--- lib/Basic/IdentifierTable.cpp
+++ lib/Basic/IdentifierTable.cpp
@@ -106,14 +106,15 @@
     KEYC11 = 0x400,
     KEYARC = 0x800,
     KEYNOMS18 = 0x01000,
-    KEYNOOPENCL = 0x02000,
-    WCHARSUPPORT = 0x04000,
-    HALFSUPPORT = 0x08000,
-    KEYCONCEPTS = 0x10000,
-    KEYOBJC2    = 0x20000,
-    KEYZVECTOR  = 0x40000,
-    KEYCOROUTINES = 0x80000,
-    KEYALL = (0xfffff & ~KEYNOMS18 &
+    KEYNOMS18_C = 0x02000,
+    KEYNOOPENCL = 0x04000,
+    WCHARSUPPORT = 0x08000,
+    HALFSUPPORT = 0x10000,
+    KEYCONCEPTS = 0x20000,
+    KEYOBJC2    = 0x40000,
+    KEYZVECTOR  = 0x80000,
+    KEYCOROUTINES = 0x100000,
+    KEYALL = (0xfffff & ~KEYNOMS18 & ~KEYNOMS18_C &
               ~KEYNOOPENCL) // KEYNOMS18 and KEYNOOPENCL are used to exclude.
   };
 
@@ -167,6 +168,12 @@
       !LangOpts.isCompatibleWithMSVC(LangOptions::MSVC2015))
     return;
 
+  // Don't add this keyword under MSVCCompat in C language.
+  if (LangOpts.MSVCCompat && (Flags & KEYNOMS18_C) &&
+      !LangOpts.isCompatibleWithMSVC(LangOptions::MSVC2015) &&
+      !LangOpts.CPlusPlus)
+    return;
+
   // Don't add this keyword under OpenCL.
   if (LangOpts.OpenCL && (Flags & KEYNOOPENCL))
     return;
Index: include/clang/Basic/TokenKinds.def
===================================================================
--- include/clang/Basic/TokenKinds.def
+++ include/clang/Basic/TokenKinds.def
@@ -239,6 +239,8 @@
 //   KEYMS    - This is a keyword if Microsoft extensions are enabled
 //   KEYNOMS18 - This is a keyword that must never be enabled under
 //               MSVC <= v18.
+//   KEYNOMS18_C - This is a keyword that must never be enabled under
+//                 MSVC <= v18 in C.
 //   KEYOPENCL  - This is a keyword in OpenCL
 //   KEYNOOPENCL  - This is a keyword that is not supported in OpenCL
 //   KEYALTIVEC - This is a keyword in AltiVec
@@ -267,7 +269,7 @@
 KEYWORD(for                         , KEYALL)
 KEYWORD(goto                        , KEYALL)
 KEYWORD(if                          , KEYALL)
-KEYWORD(inline                      , KEYC99|KEYCXX|KEYGNU)
+KEYWORD(inline                      , KEYC99|KEYCXX|KEYGNU|KEYNOMS18_C)
 KEYWORD(int                         , KEYALL)
 KEYWORD(long                        , KEYALL)
 KEYWORD(register                    , KEYALL)
Index: test/Sema/inline-ms.c
===================================================================
--- test/Sema/inline-ms.c
+++ test/Sema/inline-ms.c
@@ -0,0 +1,20 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-compatibility -fms-compatibility-version=18 -triple=x86_64-windows-msvc -DV18 %s
+// RUN: %clang_cc1 -fsyntax-only -verify -fms-compatibility -fms-compatibility-version=19 -triple=x86_64-windows-msvc -DV19 %s
+
+// expected-no-diagnostics
+
+#if V18
+// MSVC 12.0 doesn't recognize "inline" in C programs and allows its usage as an
+// identifier.
+int inline = 0;
+
+#elif V19
+// MSVC 14.0 recognizes "inline" as a keyword.
+inline int foo();
+
+#else
+
+#error Unknown test mode
+
+#endif
+


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D17330.48165.patch
Type: text/x-patch
Size: 3091 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160217/02ea4929/attachment.bin>


More information about the cfe-commits mailing list