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

via cfe-commits cfe-commits at lists.llvm.org
Wed Feb 11 01:41:23 PST 2026


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

Fix #180648

>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] [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(



More information about the cfe-commits mailing list