[clang] [llvm] [win][x64] Unwind v2 3/n: Add support for requiring unwind v2 to be used (equivalent to MSVC's /d2epilogunwindrequirev2) (PR #143577)
via llvm-commits
llvm-commits at lists.llvm.org
Tue Jun 10 11:08:46 PDT 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff HEAD~1 HEAD --extensions c,cpp,h -- clang/lib/CodeGen/CodeGenModule.cpp clang/lib/Driver/ToolChains/Clang.cpp clang/test/CodeGen/epilog-unwind.c clang/test/Driver/cl-options.c llvm/include/llvm/IR/Module.h llvm/include/llvm/Support/CodeGen.h llvm/lib/IR/Module.cpp llvm/lib/Target/X86/X86WinEHUnwindV2.cpp
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/llvm/lib/Target/X86/X86WinEHUnwindV2.cpp b/llvm/lib/Target/X86/X86WinEHUnwindV2.cpp
index 01256ec89..ae53a5060 100644
--- a/llvm/lib/Target/X86/X86WinEHUnwindV2.cpp
+++ b/llvm/lib/Target/X86/X86WinEHUnwindV2.cpp
@@ -37,9 +37,9 @@ static cl::opt<unsigned> MaximumUnwindCodes(
cl::desc("Maximum number of unwind codes permitted in each unwind info."),
cl::init(UINT8_MAX));
-static cl::opt<unsigned> ForceMode(
- "x86-wineh-unwindv2-force-mode", cl::Hidden,
- cl::desc("Overwrites the Unwind v2 mode for testing purposes."));
+static cl::opt<unsigned>
+ ForceMode("x86-wineh-unwindv2-force-mode", cl::Hidden,
+ cl::desc("Overwrites the Unwind v2 mode for testing purposes."));
namespace {
@@ -57,8 +57,7 @@ public:
private:
bool rejectCurrentFunction(const MachineFunction &MF, const DebugLoc &Loc,
- WinX64EHUnwindV2Mode Mode,
- StringRef Reason) const;
+ WinX64EHUnwindV2Mode Mode, StringRef Reason) const;
bool rejectCurrentFunction(const MachineFunction &MF,
const MachineBasicBlock &EpilogBlock,
@@ -67,8 +66,7 @@ private:
// If we're in the Epilog, then the generated instructions might not have a
// location, so use the terminator's location.
return rejectCurrentFunction(
- MF, EpilogBlock.getFirstTerminator()->getDebugLoc(), Mode,
- Reason);
+ MF, EpilogBlock.getFirstTerminator()->getDebugLoc(), Mode, Reason);
}
};
@@ -204,14 +202,14 @@ bool X86WinEHUnwindV2::runOnMachineFunction(MachineFunction &MF) {
// If the prolog contains a stack allocation, then the first
// instruction in the epilog must be to adjust the stack pointer.
if (!HasStackAlloc)
- return rejectCurrentFunction(
- MF, MBB, Mode,
- "The epilog is deallocating a stack allocation, but the prolog did "
- "not allocate one");
+ return rejectCurrentFunction(MF, MBB, Mode,
+ "The epilog is deallocating a stack "
+ "allocation, but the prolog did "
+ "not allocate one");
if (HasStackDealloc)
- return rejectCurrentFunction(
- MF, MBB, Mode,
- "The epilog is deallocating the stack allocation more than once");
+ return rejectCurrentFunction(MF, MBB, Mode,
+ "The epilog is deallocating the stack "
+ "allocation more than once");
if (PoppedRegCount > 0)
llvm_unreachable(
"Should have raised an error: either popping before "
@@ -230,19 +228,20 @@ bool X86WinEHUnwindV2::runOnMachineFunction(MachineFunction &MF) {
// POP each register in reverse order of the PUSHes in the prolog.
PoppedRegCount++;
if (HasStackAlloc != HasStackDealloc)
- return rejectCurrentFunction(MF, MBB, Mode,
- "Cannot pop registers before the stack "
- "allocation has been deallocated");
+ return rejectCurrentFunction(
+ MF, MBB, Mode,
+ "Cannot pop registers before the stack "
+ "allocation has been deallocated");
if (PoppedRegCount > PushedRegs.size())
return rejectCurrentFunction(
MF, MBB, Mode,
"The epilog is popping more registers than the prolog pushed");
if (PushedRegs[PushedRegs.size() - PoppedRegCount] !=
MI.getOperand(0).getReg())
- return rejectCurrentFunction(
- MF, MBB, Mode,
- "The epilog is popping a registers in a different order than the "
- "prolog pushed them");
+ return rejectCurrentFunction(MF, MBB, Mode,
+ "The epilog is popping a registers in "
+ "a different order than the "
+ "prolog pushed them");
// Unwind v2 records the size of the epilog not from where we place
// SEH_BeginEpilogue (as that contains the instruction to adjust the
@@ -255,8 +254,7 @@ bool X86WinEHUnwindV2::runOnMachineFunction(MachineFunction &MF) {
} else if (State == FunctionState::FinishedEpilog)
// Unexpected instruction after the epilog.
return rejectCurrentFunction(
- MF, MBB, Mode,
- "Registers are being popped after the epilog");
+ MF, MBB, Mode, "Registers are being popped after the epilog");
break;
default:
@@ -291,9 +289,8 @@ bool X86WinEHUnwindV2::runOnMachineFunction(MachineFunction &MF) {
// optimization.
if (ApproximatePrologCodeCount + UnwindV2StartLocations.size() + 1 >
static_cast<unsigned>(MaximumUnwindCodes))
- return rejectCurrentFunction(
- MF, findDebugLoc(FirstMBB), Mode,
- "The function has too many epilogs");
+ return rejectCurrentFunction(MF, findDebugLoc(FirstMBB), Mode,
+ "The function has too many epilogs");
MeetsUnwindV2Criteria++;
``````````
</details>
https://github.com/llvm/llvm-project/pull/143577
More information about the llvm-commits
mailing list