https://github.com/GkvJwa updated https://github.com/llvm/llvm-project/pull/172287
>From 1adba34a4702c5372c835dac9972829fad2662e4 Mon Sep 17 00:00:00 2001 From: GkvJwa <[email protected]> Date: Mon, 29 Dec 2025 00:20:05 +0800 Subject: [PATCH] Test --- clang/lib/CodeGen/CGDecl.cpp | 15 ++++++++++++++- clang/test/CodeGenCXX/exceptions-seh.cpp | 20 ++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp index 8b1cd83af2396..21b6dc9444943 100644 --- a/clang/lib/CodeGen/CGDecl.cpp +++ b/clang/lib/CodeGen/CGDecl.cpp @@ -2212,8 +2212,21 @@ void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) { const VarDecl &D = *emission.Variable; // Check the type for a cleanup. - if (QualType::DestructionKind dtorKind = D.needsDestruction(getContext())) + if (QualType::DestructionKind dtorKind = D.needsDestruction(getContext())) { + // Check if we're in a SEH block and this is a C++ destructor + if (dtorKind == QualType::DK_cxx_destructor) { + if (isSEHTryScope()) { + // We're in a __try block + getContext().getDiagnostics().Report(D.getLocation(), + diag::err_seh_expected_handler); + } else if (!SEHCodeSlotStack.empty()) { + // We're in an __except block + getContext().getDiagnostics().Report(D.getLocation(), + diag::err_seh_expected_handler); + } + } emitAutoVarTypeCleanup(emission, dtorKind); + } // In GC mode, honor objc_precise_lifetime. if (getLangOpts().getGC() != LangOptions::NonGC && diff --git a/clang/test/CodeGenCXX/exceptions-seh.cpp b/clang/test/CodeGenCXX/exceptions-seh.cpp index bb374dd1f5bd5..87adde5ff1baa 100644 --- a/clang/test/CodeGenCXX/exceptions-seh.cpp +++ b/clang/test/CodeGenCXX/exceptions-seh.cpp @@ -4,6 +4,10 @@ // RUN: %clang_cc1 -std=c++11 -fblocks -fms-extensions %s -triple=x86_64-windows-msvc -emit-llvm \ // RUN: -o - -mconstructor-aliases -O1 -disable-llvm-passes | \ // RUN: FileCheck %s --check-prefix=CHECK --check-prefix=NOCXX +// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions \ +// RUN: -fms-extensions -x c++ -emit-llvm -verify %s -DERR1 +// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions \ +// RUN: -fms-extensions -x c++ -emit-llvm -verify %s -DERR2 extern "C" unsigned long _exception_code(); extern "C" void might_throw(); @@ -175,3 +179,19 @@ void use_inline() { // CHECK: attributes #[[NOINLINE]] = { {{.*noinline.*}} } void seh_in_noexcept() noexcept { __try {} __finally {} } + +#if defined(ERR1) +void seh_unwinding() { + __try { + HasCleanup x; // expected-error{{expected '__except' or '__finally' block}} + } __except (1) { + } +} +#elif defined(ERR2) +void seh_unwinding() { + __try { + } __except (1) { + HasCleanup x; // expected-error{{expected '__except' or '__finally' block}} + } +} +#endif _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
