zahen created this revision. zahen added reviewers: zturner, rnk. Herald added a subscriber: cfe-commits.
The msvc exception specifier for noexcept function types has changed from the prior default of "Z" to "_E" if the function cannot throw when compiling with /std:C++17. Repository: rC Clang https://reviews.llvm.org/D55685 Files: lib/AST/MicrosoftMangle.cpp test/CodeGenCXX/mangle-ms-exception-spec.cpp
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 <typename T> +class e; +template <typename T, typename... U> +class e<T(U...) noexcept> { + // CXX11-DAG: @"?ee@?$e@$$A6AXXZ@@EEAAXXZ" + // CXX17-DAG: @"?ee@?$e@$$A6AXX_E@@EEAAXXZ" + virtual T ee(U &&...) noexcept {}; +}; + +e<void() noexcept> e1; + +template <typename T> +class f; +template <typename T, typename... U> +class f<T(U...)> { + // CHECK-DAG: @"?ff@?$f@$$A6AXXZ@@EEAAXXZ" + virtual T ff(U &&...) noexcept {}; +}; + +f<void()> f1; 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) { // <function-type> ::= <this-cvr-qualifiers> <calling-convention> // <return-type> <argument-list> <throw-spec> const FunctionProtoType *Proto = dyn_cast<FunctionProtoType>(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) { - // <throw-spec> ::= Z # throw(...) (default) - // ::= @ # throw() or __declspec/__attribute__((nothrow)) - // ::= <type>+ - // 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'; + // <throw-spec> ::= Z # (default) + // ::= _E # noexcept + if (FT->canThrow()) + Out << 'Z'; + else + Out << "_E"; } void MicrosoftCXXNameMangler::mangleType(const UnresolvedUsingType *T,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits