[clang] [WinEH] Check object unwinding in seh block only when -eha is used (PR #180108)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 7 04:38:04 PST 2026
https://github.com/GkvJwa updated https://github.com/llvm/llvm-project/pull/180108
>From eb6dae98ee28b20ddcd01fc387b1c432f39fb1fc Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Fri, 6 Feb 2026 11:21:17 +0800
Subject: [PATCH 1/2] Check enable eha
---
clang/lib/CodeGen/CGDecl.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index c66112e0e5bfb..b470f48ccd911 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2228,8 +2228,8 @@ void CodeGenFunction::EmitAutoVarCleanups(const AutoVarEmission &emission) {
// Check the type for a cleanup.
if (QualType::DestructionKind dtorKind = D.needsDestruction(getContext())) {
- // Check if we're in a SEH block, prevent it
- if (currentFunctionUsesSEHTry())
+ // Check if we're in a SEH block with EHa, prevent it
+ if (getLangOpts().EHAsynch && currentFunctionUsesSEHTry())
getContext().getDiagnostics().Report(D.getLocation(),
diag::err_seh_object_unwinding);
emitAutoVarTypeCleanup(emission, dtorKind);
>From ed7f4b81190a5ee3b89966a8dcdf1471f1ad832e Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Sat, 7 Feb 2026 20:37:48 +0800
Subject: [PATCH 2/2] Add no diagnostics
---
clang/test/CodeGenCXX/exceptions-seh.cpp | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/clang/test/CodeGenCXX/exceptions-seh.cpp b/clang/test/CodeGenCXX/exceptions-seh.cpp
index 7ccd17fa73bbd..4bb591e4a5618 100644
--- a/clang/test/CodeGenCXX/exceptions-seh.cpp
+++ b/clang/test/CodeGenCXX/exceptions-seh.cpp
@@ -10,6 +10,8 @@
// RUN: -fms-extensions -x c++ -emit-llvm-only -verify %s -DERR2
// RUN: %clang_cc1 -triple x86_64-windows -fasync-exceptions -fcxx-exceptions -fexceptions \
// RUN: -fms-extensions -x c++ -emit-llvm-only -verify %s -DERR3
+// RUN: %clang_cc1 -triple x86_64-windows -fcxx-exceptions -fexceptions \
+// RUN: -fms-extensions -x c++ -emit-llvm-only -verify %s -DERR4
extern "C" unsigned long _exception_code();
extern "C" void might_throw();
@@ -203,4 +205,11 @@ void seh_unwinding() {
} __except (1) {
}
}
+#elif defined(ERR4)
+void seh_unwinding() {
+ __try {
+ HasCleanup x; // expected-no-diagnostics
+ } __except (1) {
+ }
+}
#endif
More information about the cfe-commits
mailing list