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: 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: 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 +