https://github.com/GkvJwa updated https://github.com/llvm/llvm-project/pull/180905
>From beeee4ee91ed70de12a6eb8e48f3a9846b944f16 Mon Sep 17 00:00:00 2001 From: GkvJwa <[email protected]> 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 cd12c337fb3cf5a5c69c2b0eb36226441972d6a2 Mon Sep 17 00:00:00 2001 From: GkvJwa <[email protected]> Date: Mon, 2 Mar 2026 16:36:40 +0800 Subject: [PATCH 2/2] [WinEH] Fix crash when aligning parameters larger than ABI --- clang/lib/CodeGen/CGException.cpp | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/clang/lib/CodeGen/CGException.cpp b/clang/lib/CodeGen/CGException.cpp index de5c9e92dd655..fb96ede7a6812 100644 --- a/clang/lib/CodeGen/CGException.cpp +++ b/clang/lib/CodeGen/CGException.cpp @@ -1834,13 +1834,14 @@ struct CaptureFinder : ConstStmtVisitor<CaptureFinder> { Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, Address ParentVar, llvm::Value *ParentFP) { - llvm::CallInst *RecoverCall = nullptr; + llvm::Value *RecoverCall = nullptr; CGBuilderTy Builder(*this, AllocaInsertPt); auto *ParentAlloca = dyn_cast_or_null<llvm::AllocaInst>(ParentVar.getBasePointer()); + auto *ParentArg = + dyn_cast_or_null<llvm::Argument>(ParentVar.getBasePointer()); if (!ParentAlloca) { - if (auto *ParentArg = - dyn_cast_or_null<llvm::Argument>(ParentVar.getBasePointer())) { + if (ParentArg) { llvm::BasicBlock &EntryBB = ParentCGF.CurFn->getEntryBlock(); llvm::IRBuilder<> ParentEntryBuilder(&EntryBB, EntryBB.begin()); ParentAlloca = ParentEntryBuilder.CreateAlloca( @@ -1861,7 +1862,9 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, RecoverCall = Builder.CreateCall( FrameRecoverFn, {ParentCGF.CurFn, ParentFP, llvm::ConstantInt::get(Int32Ty, FrameEscapeIdx)}); - + if (ParentArg) + RecoverCall = Builder.CreateLoad( + Address(RecoverCall, ParentArg->getType(), getPointerAlign())); } else { // If the parent didn't have an alloca, we're doing some nested outlining. // Just clone the existing localrecover call, but tweak the FP argument to @@ -1870,9 +1873,10 @@ Address CodeGenFunction::recoverAddrOfEscapedLocal(CodeGenFunction &ParentCGF, ParentVar.emitRawPointer(*this)->stripPointerCasts()); assert(ParentRecover->getIntrinsicID() == llvm::Intrinsic::localrecover && "expected alloca or localrecover in parent LocalDeclMap"); - RecoverCall = cast<llvm::CallInst>(ParentRecover->clone()); - RecoverCall->setArgOperand(1, ParentFP); - RecoverCall->insertBefore(AllocaInsertPt->getIterator()); + RecoverCall = ParentRecover->clone(); + cast<llvm::CallInst>(RecoverCall)->setArgOperand(1, ParentFP); + cast<llvm::CallInst>(RecoverCall) + ->insertBefore(AllocaInsertPt->getIterator()); } // Bitcast the variable, rename it, and insert it in the local decl map. _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
