Index: include/clang/Basic/LangOptions.h =================================================================== --- include/clang/Basic/LangOptions.h +++ 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: lib/AST/MicrosoftMangle.cpp =================================================================== --- lib/AST/MicrosoftMangle.cpp +++ lib/AST/MicrosoftMangle.cpp @@ -315,7 +315,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: @@ -512,7 +513,7 @@ mangleFunctionClass(FD); - mangleFunctionType(FT, FD); + mangleFunctionType(FT, FD, false, false); } else { Out << '9'; } @@ -2061,7 +2062,8 @@ void MicrosoftCXXNameMangler::mangleFunctionType(const FunctionType *T, const FunctionDecl *D, - bool ForceThisQuals) { + bool ForceThisQuals, + bool MangleExceptionSpec) { // ::= // const FunctionProtoType *Proto = dyn_cast(T); @@ -2194,7 +2196,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) { @@ -2299,15 +2306,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: lib/Driver/ToolChains/MSVC.cpp =================================================================== --- lib/Driver/ToolChains/MSVC.cpp +++ 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: test/CodeGenCXX/mangle-ms-exception-spec.cpp =================================================================== --- test/CodeGenCXX/mangle-ms-exception-spec.cpp +++ test/CodeGenCXX/mangle-ms-exception-spec.cpp @@ -0,0 +1,42 @@ +// RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - -triple=x86_64-pc-win32 -Wno-noexcept-type -fms-compatibility-version=19.12 | FileCheck %s --check-prefix=CHECK --check-prefix=CXX11 +// RUN: %clang_cc1 -std=c++17 -fms-extensions -emit-llvm %s -o - -triple=x86_64-pc-win32 | FileCheck %s --check-prefix=CHECK --check-prefix=NOCOMPAT +// RUN: %clang_cc1 -std=c++17 -fms-extensions -emit-llvm %s -o - -triple=x86_64-pc-win32 -fms-compatibility-version=19.12 | FileCheck %s --check-prefix=CHECK --check-prefix=CXX17 + +// Prove that mangling only changed for noexcept types under /std:C++17, not all noexcept functions +// CHECK-DAG: @"?nochange@@YAXXZ" +void nochange() noexcept {} + +// CXX11-DAG: @"?a@@YAXP6AHXZ@Z" +// NOCOMPAT-DAG: @"?a@@YAXP6AHXZ@Z" +// CXX17-DAG: @"?a@@YAXP6AHX_E@Z" +void a(int() noexcept) {} +// CHECK-DAG: @"?b@@YAXP6AHXZ@Z" +void b(int() noexcept(false)) {} +// CXX11-DAG: @"?c@@YAXP6AHXZ@Z" +// NOCOMPAT-DAG: @"?c@@YAXP6AHXZ@Z" +// CXX17-DAG: @"?c@@YAXP6AHX_E@Z" +void c(int() noexcept(true)) {} +// CHECK-DAG: @"?d@@YAXP6AHXZ@Z" +void d(int()) {} + +template +class e; +template +class e { + // CXX11-DAG: @"?ee@?$e@$$A6AXXZ@@EEAAXXZ" + // NOCOMPAT-DAG: @"?ee@?$e@$$A6AXXZ@@EEAAXXZ" + // CXX17-DAG: @"?ee@?$e@$$A6AXX_E@@EEAAXXZ" + virtual T ee(U &&...) noexcept {}; +}; + +e e1; + +template +class f; +template +class f { + // CHECK-DAG: @"?ff@?$f@$$A6AXXZ@@EEAAXXZ" + virtual T ff(U &&...) noexcept {}; +}; + +f f1;