diff --git a/clang/include/clang/AST/Mangle.h b/clang/include/clang/AST/Mangle.h --- a/clang/include/clang/AST/Mangle.h +++ b/clang/include/clang/AST/Mangle.h @@ -166,10 +166,10 @@ virtual void mangleDynamicAtExitDestructor(const VarDecl *D, raw_ostream &) = 0; - virtual void mangleSEHFilterExpression(const NamedDecl *EnclosingDecl, + virtual void mangleSEHFilterExpression(GlobalDecl EnclosingDecl, raw_ostream &Out) = 0; - virtual void mangleSEHFinallyBlock(const NamedDecl *EnclosingDecl, + virtual void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl, raw_ostream &Out) = 0; /// Generates a unique string for an externally visible type for use with TBAA diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -118,9 +118,9 @@ void mangleDynamicAtExitDestructor(const VarDecl *D, raw_ostream &Out) override; void mangleDynamicStermFinalizer(const VarDecl *D, raw_ostream &Out) override; - void mangleSEHFilterExpression(const NamedDecl *EnclosingDecl, + void mangleSEHFilterExpression(GlobalDecl EnclosingDecl, raw_ostream &Out) override; - void mangleSEHFinallyBlock(const NamedDecl *EnclosingDecl, + void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl, raw_ostream &Out) override; void mangleItaniumThreadLocalInit(const VarDecl *D, raw_ostream &) override; void mangleItaniumThreadLocalWrapper(const VarDecl *D, @@ -6430,23 +6430,25 @@ } void ItaniumMangleContextImpl::mangleSEHFilterExpression( - const NamedDecl *EnclosingDecl, raw_ostream &Out) { + GlobalDecl EnclosingDecl, raw_ostream &Out) { CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "__filt_"; - if (shouldMangleDeclName(EnclosingDecl)) + auto *EnclosingFD = cast(EnclosingDecl.getDecl()); + if (shouldMangleDeclName(EnclosingFD)) Mangler.mangle(EnclosingDecl); else - Mangler.getStream() << EnclosingDecl->getName(); + Mangler.getStream() << EnclosingFD->getName(); } void ItaniumMangleContextImpl::mangleSEHFinallyBlock( - const NamedDecl *EnclosingDecl, raw_ostream &Out) { + GlobalDecl EnclosingDecl, raw_ostream &Out) { CXXNameMangler Mangler(*this, Out); Mangler.getStream() << "__fin_"; - if (shouldMangleDeclName(EnclosingDecl)) + auto *EnclosingFD = cast(EnclosingDecl.getDecl()); + if (shouldMangleDeclName(EnclosingFD)) Mangler.mangle(EnclosingDecl); else - Mangler.getStream() << EnclosingDecl->getName(); + Mangler.getStream() << EnclosingFD->getName(); } void ItaniumMangleContextImpl::mangleItaniumThreadLocalInit(const VarDecl *D, diff --git a/clang/lib/AST/MicrosoftMangle.cpp b/clang/lib/AST/MicrosoftMangle.cpp --- a/clang/lib/AST/MicrosoftMangle.cpp +++ b/clang/lib/AST/MicrosoftMangle.cpp @@ -142,8 +142,8 @@ llvm::DenseMap Discriminator; llvm::DenseMap Uniquifier; llvm::DenseMap LambdaIds; - llvm::DenseMap SEHFilterIds; - llvm::DenseMap SEHFinallyIds; + llvm::DenseMap SEHFilterIds; + llvm::DenseMap SEHFinallyIds; SmallString<16> AnonymousNamespaceHash; public: @@ -201,9 +201,9 @@ void mangleDynamicInitializer(const VarDecl *D, raw_ostream &Out) override; void mangleDynamicAtExitDestructor(const VarDecl *D, raw_ostream &Out) override; - void mangleSEHFilterExpression(const NamedDecl *EnclosingDecl, + void mangleSEHFilterExpression(GlobalDecl EnclosingDecl, raw_ostream &Out) override; - void mangleSEHFinallyBlock(const NamedDecl *EnclosingDecl, + void mangleSEHFinallyBlock(GlobalDecl EnclosingDecl, raw_ostream &Out) override; void mangleStringLiteral(const StringLiteral *SL, raw_ostream &Out) override; bool getNextDiscriminator(const NamedDecl *ND, unsigned &disc) { @@ -3730,7 +3730,7 @@ } void MicrosoftMangleContextImpl::mangleSEHFilterExpression( - const NamedDecl *EnclosingDecl, raw_ostream &Out) { + GlobalDecl EnclosingDecl, raw_ostream &Out) { msvc_hashing_ostream MHO(Out); MicrosoftCXXNameMangler Mangler(*this, MHO); // The function body is in the same comdat as the function with the handler, @@ -3742,7 +3742,7 @@ } void MicrosoftMangleContextImpl::mangleSEHFinallyBlock( - const NamedDecl *EnclosingDecl, raw_ostream &Out) { + GlobalDecl EnclosingDecl, raw_ostream &Out) { msvc_hashing_ostream MHO(Out); MicrosoftCXXNameMangler Mangler(*this, MHO); // The function body is in the same comdat as the function with the handler, diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp --- a/clang/lib/CodeGen/CGException.cpp +++ b/clang/lib/CodeGen/CGException.cpp @@ -249,7 +249,7 @@ // For outlined finallys and filters, use the SEH personality in case they // contain more SEH. This mostly only affects finallys. Filters could // hypothetically use gnu statement expressions to sneak in nested SEH. - FD = FD ? FD : CGF.CurSEHParent; + FD = FD ? FD : CGF.CurSEHParent.getDecl(); return get(CGF.CGM, dyn_cast_or_null(FD)); } @@ -2005,7 +2005,7 @@ SmallString<128> Name; { llvm::raw_svector_ostream OS(Name); - const NamedDecl *ParentSEHFn = ParentCGF.CurSEHParent; + GlobalDecl ParentSEHFn = ParentCGF.CurSEHParent; assert(ParentSEHFn && "No CurSEHParent!"); MangleContext &Mangler = CGM.getCXXABI().getMangleContext(); if (IsFilter) diff --git a/clang/lib/CodeGen/CodeGenFunction.h b/clang/lib/CodeGen/CodeGenFunction.h --- a/clang/lib/CodeGen/CodeGenFunction.h +++ b/clang/lib/CodeGen/CodeGenFunction.h @@ -539,7 +539,7 @@ /// potentially set the return value. bool SawAsmBlock = false; - const NamedDecl *CurSEHParent = nullptr; + GlobalDecl CurSEHParent; /// True if the current function is an outlined SEH helper. This can be a /// finally block or filter expression. @@ -2021,7 +2021,7 @@ return getInvokeDestImpl(); } - bool currentFunctionUsesSEHTry() const { return CurSEHParent != nullptr; } + bool currentFunctionUsesSEHTry() const { return !!CurSEHParent; } const TargetInfo &getTarget() const { return Target; } llvm::LLVMContext &getLLVMContext() { return CGM.getLLVMContext(); } diff --git a/clang/lib/CodeGen/CodeGenFunction.cpp b/clang/lib/CodeGen/CodeGenFunction.cpp --- a/clang/lib/CodeGen/CodeGenFunction.cpp +++ b/clang/lib/CodeGen/CodeGenFunction.cpp @@ -701,7 +701,7 @@ CurCodeDecl = D; const FunctionDecl *FD = dyn_cast_or_null(D); if (FD && FD->usesSEHTry()) - CurSEHParent = FD; + CurSEHParent = GD; CurFuncDecl = (D ? D->getNonClosureContext() : nullptr); FnRetTy = RetTy; CurFn = Fn; diff --git a/clang/test/CodeGenCXX/exceptions-seh.cpp b/clang/test/CodeGenCXX/exceptions-seh.cpp --- a/clang/test/CodeGenCXX/exceptions-seh.cpp +++ b/clang/test/CodeGenCXX/exceptions-seh.cpp @@ -121,6 +121,15 @@ // CHECK: invoke void @might_throw() #[[NOINLINE]] // CHECK: catchpad +class use_seh_in_constructor { use_seh_in_constructor(); }; +use_seh_in_constructor::use_seh_in_constructor(){ + __try { + } __finally { + } +} + +// CHECK: define internal void @"?fin$0@0@?0use_seh_in_constructor@@" + static int my_unique_global; extern "C" inline void use_seh_in_inline_func() {