[clang] 32c79e0 - [WinEH] Only emit err_seh_object_unwinding when CXXExceptions are enabled (#180959)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 13 06:33:34 PST 2026
Author: GkvJwa
Date: 2026-02-13T22:33:27+08:00
New Revision: 32c79e0e9cc67b2f531fbcd1991d1c5a912e1313
URL: https://github.com/llvm/llvm-project/commit/32c79e0e9cc67b2f531fbcd1991d1c5a912e1313
DIFF: https://github.com/llvm/llvm-project/commit/32c79e0e9cc67b2f531fbcd1991d1c5a912e1313.diff
LOG: [WinEH] Only emit err_seh_object_unwinding when CXXExceptions are enabled (#180959)
Based on the PR(https://github.com/llvm/llvm-project/pull/180108)
discussion, it has been modified to check when `/EH*` is enabled.
Although `/EHsc` `/EHs` are slightly different from `/EHa`, and the
changes here have different effects than `/EHa` when these two switches
are enabled, we are still considering supporting this situation, and we
will improve support for `/EHs*` in the future.
Added:
Modified:
clang/lib/CodeGen/CGDecl.cpp
clang/test/CodeGenCXX/exceptions-seh.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGDecl.cpp b/clang/lib/CodeGen/CGDecl.cpp
index b470f48ccd911..81697e02e8f3f 100644
--- a/clang/lib/CodeGen/CGDecl.cpp
+++ b/clang/lib/CodeGen/CGDecl.cpp
@@ -2228,8 +2228,10 @@ 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 with EHa, prevent it
- if (getLangOpts().EHAsynch && currentFunctionUsesSEHTry())
+ // Check if we're in a SEH block with /EH, prevent it
+ // TODO: /EHs*
diff ers from /EHa, the former may not be executed to this
+ // point.
+ if (getLangOpts().CXXExceptions && currentFunctionUsesSEHTry())
getContext().getDiagnostics().Report(D.getLocation(),
diag::err_seh_object_unwinding);
emitAutoVarTypeCleanup(emission, dtorKind);
diff --git a/clang/test/CodeGenCXX/exceptions-seh.cpp b/clang/test/CodeGenCXX/exceptions-seh.cpp
index 0716ed7ee81d6..270b249f700fa 100644
--- a/clang/test/CodeGenCXX/exceptions-seh.cpp
+++ b/clang/test/CodeGenCXX/exceptions-seh.cpp
@@ -12,6 +12,8 @@
// 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
+// RUN: %clang_cc1 -triple x86_64-windows \
+// RUN: -fms-extensions -x c++ -emit-llvm-only -verify %s -DNOERR
extern "C" unsigned long _exception_code();
extern "C" void might_throw();
@@ -206,6 +208,13 @@ void seh_unwinding() {
}
}
#elif defined(ERR4)
+void seh_unwinding() {
+ __try {
+ HasCleanup x; // expected-error{{'__try' is not permitted in functions that require object unwinding}}
+ } __except (1) {
+ }
+}
+#elif defined(NOERR)
void seh_unwinding() {
__try {
HasCleanup x; // expected-no-diagnostics
More information about the cfe-commits
mailing list