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,10 @@ Out << '@'; } - mangleThrowSpecification(Proto); + if (getASTContext().getLangOpts().CPlusPlus17 && MangleExceptionSpec) + mangleThrowSpecification(Proto); + else + Out << 'Z'; } void MicrosoftCXXNameMangler::mangleFunctionClass(const FunctionDecl *FD) { @@ -2301,13 +2306,12 @@ } 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: test/CodeGenCXX/mangle-ms-exception-spec.cpp =================================================================== --- test/CodeGenCXX/mangle-ms-exception-spec.cpp +++ test/CodeGenCXX/mangle-ms-exception-spec.cpp @@ -0,0 +1,34 @@ +// RUN: %clang_cc1 -std=c++11 -fms-extensions -emit-llvm %s -o - -triple=x86_64-pc-win32 -Wno-noexcept-type | 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=CXX17 + +// CXX11-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" +// 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" + // 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;