https://github.com/GkvJwa created 
https://github.com/llvm/llvm-project/pull/180959

None

>From f77c9f28c55209bd589a7122de4dcc5bab113528 Mon Sep 17 00:00:00 2001
From: GkvJwa <[email protected]>
Date: Wed, 11 Feb 2026 23:38:58 +0800
Subject: [PATCH] [WinEH] Also check object unwinding for enabling
 CXXExceptions(/ehs*)

---
 clang/lib/CodeGen/CGDecl.cpp             | 6 ++++--
 clang/test/CodeGenCXX/exceptions-seh.cpp | 9 +++++++++
 2 files changed, 13 insertions(+), 2 deletions(-)

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* differs 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..0afabd788146a 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 -DERR5
 
 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(ERR5)
 void seh_unwinding() {
   __try {
     HasCleanup x; // expected-no-diagnostics

_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to