[clang] [WinEH] Fix crash when aligning parameters larger than ABI (PR #180905)

via cfe-commits cfe-commits at lists.llvm.org
Thu Feb 12 09:05:46 PST 2026


https://github.com/GkvJwa updated https://github.com/llvm/llvm-project/pull/180905

>From beeee4ee91ed70de12a6eb8e48f3a9846b944f16 Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Wed, 11 Feb 2026 17:38:09 +0800
Subject: [PATCH 1/2] [WinEH] Support ptr types(to Argument)

---
 clang/lib/CodeGen/CGException.cpp | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp
index 2f1df6e9a8a5c..de5c9e92dd655 100644
--- a/clang/lib/CodeGen/CGException.cpp
+++ b/clang/lib/CodeGen/CGException.cpp
@@ -1836,8 +1836,20 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF,
                                                    llvm::Value *ParentFP) {
   llvm::CallInst *RecoverCall = nullptr;
   CGBuilderTy Builder(*this, AllocaInsertPt);
-  if (auto *ParentAlloca =
-          dyn_cast_or_null<llvm::AllocaInst>(ParentVar.getBasePointer())) {
+  auto *ParentAlloca =
+      dyn_cast_or_null<llvm::AllocaInst>(ParentVar.getBasePointer());
+  if (!ParentAlloca) {
+    if (auto *ParentArg =
+            dyn_cast_or_null<llvm::Argument>(ParentVar.getBasePointer())) {
+      llvm::BasicBlock &EntryBB = ParentCGF.CurFn->getEntryBlock();
+      llvm::IRBuilder<> ParentEntryBuilder(&EntryBB, EntryBB.begin());
+      ParentAlloca = ParentEntryBuilder.CreateAlloca(
+          ParentArg->getType(), nullptr, ParentArg->getName() + ".addr");
+      ParentEntryBuilder.CreateStore(ParentArg, ParentAlloca);
+    }
+  }
+
+  if (ParentAlloca) {
     // Mark the variable escaped if nobody else referenced it and compute the
     // localescape index.
     auto InsertPair = ParentCGF.EscapedLocals.insert(

>From f8da8cbe737f53e8178551ca2a985bfd7e1d56d8 Mon Sep 17 00:00:00 2001
From: GkvJwa <gkvjwa at gmail.com>
Date: Fri, 13 Feb 2026 01:05:36 +0800
Subject: [PATCH 2/2] Use DNOERR

---
 clang/test/CodeGenCXX/exceptions-seh.cpp | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/clang/test/CodeGenCXX/exceptions-seh.cpp b/clang/test/CodeGenCXX/exceptions-seh.cpp
index 0716ed7ee81d6..92e24d1518408 100644
--- a/clang/test/CodeGenCXX/exceptions-seh.cpp
+++ b/clang/test/CodeGenCXX/exceptions-seh.cpp
@@ -11,7 +11,7 @@
 // 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
+// RUN:         -fms-extensions -x c++ -emit-llvm-only -verify %s -DNOERR
 
 extern "C" unsigned long _exception_code();
 extern "C" void might_throw();
@@ -205,7 +205,7 @@ void seh_unwinding() {
   } __except (1) {
   }
 }
-#elif defined(ERR4)
+#elif defined(NOERR)
 void seh_unwinding() {
   __try {
     HasCleanup x; // expected-no-diagnostics



More information about the cfe-commits mailing list