Index: cfe/trunk/include/clang/Basic/LangOptions.h =================================================================== --- cfe/trunk/include/clang/Basic/LangOptions.h +++ cfe/trunk/include/clang/Basic/LangOptions.h @@ -98,11 +98,14 @@ enum AddrSpaceMapMangling { ASMM_Target, ASMM_On, ASMM_Off }; + // Corresponds to _MSC_VER enum MSVCMajorVersion { - MSVC2010 = 16, - MSVC2012 = 17, - MSVC2013 = 18, - MSVC2015 = 19 + MSVC2010 = 1600, + MSVC2012 = 1700, + MSVC2013 = 1800, + MSVC2015 = 1900, + MSVC2017 = 1910, + MSVC2017_5 = 1912 }; /// Clang versions with different platform ABI conformance. @@ -271,7 +274,7 @@ } bool isCompatibleWithMSVC(MSVCMajorVersion MajorVersion) const { - return MSCompatibilityVersion >= MajorVersion * 10000000U; + return MSCompatibilityVersion >= MajorVersion * 100000U; } /// Reset all of the options that are not considered when building a Index: cfe/trunk/lib/AST/MicrosoftMangle.cpp =================================================================== --- cfe/trunk/lib/AST/MicrosoftMangle.cpp +++ cfe/trunk/lib/AST/MicrosoftMangle.cpp @@ -316,7 +316,8 @@ QualifierMangleMode QMM = QMM_Mangle); void mangleFunctionType(const FunctionType *T, const FunctionDecl *D = nullptr, - bool ForceThisQuals = false); + bool ForceThisQuals = false, + bool MangleExceptionSpec = true); void mangleNestedName(const NamedDecl *ND); private: @@ -513,7 +514,7 @@ mangleFunctionClass(FD); - mangleFunctionType(FT, FD); + mangleFunctionType(FT, FD, false, false); } else { Out << '9'; } @@ -2127,7 +2128,8 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, const FunctionDecl *D, - bool ForceThisQuals) { + bool ForceThisQuals, + bool MangleExceptionSpec) { // ::= // const FunctionProtoType *Proto = dyn_cast(T); @@ -2260,7 +2262,12 @@ Out << '@'; } - mangleThrowSpecification(Proto); + if (MangleExceptionSpec && getASTContext().getLangOpts().CPlusPlus17 && + getASTContext().getLangOpts().isCompatibleWithMSVC( + LangOptions::MSVC2017_5)) + mangleThrowSpecification(Proto); + else + Out << 'Z'; } void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) { @@ -2365,15 +2372,15 @@ void MicrosoftCXXNameMangler::mangleCallingConvention(const FunctionType *T) { mangleCallingConvention(T->getCallConv()); } + void MicrosoftCXXNameMangler::mangleThrowSpecification( const FunctionProtoType *FT) { - // ::= Z # throw(...) (default) - // ::= @ # throw() or __declspec/__attribute__((nothrow)) - // ::= + - // NOTE: Since the Microsoft compiler ignores throw specifications, they are - // all actually mangled as 'Z'. (They're ignored because their associated - // functionality isn't implemented, and probably never will be.) - Out << 'Z'; + // ::= Z # (default) + // ::= _E # noexcept + if (FT->canThrow()) + Out << 'Z'; + else + Out << "_E"; } void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T, Index: cfe/trunk/lib/Driver/ToolChains/MSVC.cpp =================================================================== --- cfe/trunk/lib/Driver/ToolChains/MSVC.cpp +++ cfe/trunk/lib/Driver/ToolChains/MSVC.cpp @@ -1286,7 +1286,7 @@ if (MSVT.empty() && Args.hasFlag(options::OPT_fms_extensions, options::OPT_fno_ms_extensions, IsWindowsMSVC)) { - // -fms-compatibility-version=19.11 is default, aka 2017 + // -fms-compatibility-version=19.11 is default, aka 2017, 15.3 MSVT = VersionTuple(19, 11); } return MSVT; Index: cfe/trunk/lib/Sema/SemaDeclAttr.cpp =================================================================== --- cfe/trunk/lib/Sema/SemaDeclAttr.cpp +++ cfe/trunk/lib/Sema/SemaDeclAttr.cpp @@ -5694,6 +5694,11 @@ if (!checkUInt32Argument(S, AL, AL.getArgAsExpr(0), Version)) return; + // The attribute expects a "major" version number like 19, but new versions of + // MSVC have moved to updating the "minor", or less significant numbers, so we + // have to multiply by 100 now. + Version *= 100; + // TODO: Investigate what happens with the next major version of MSVC. if (Version != LangOptions::MSVC2015) { S.Diag(AL.getLoc(), diag::err_attribute_argument_out_of_bounds)