================
@@ -3282,6 +3292,36 @@ bool ARMExpandPseudo::ExpandMI(MachineBasicBlock &MBB,
       MI.eraseFromParent();
       return true;
     }
+    case ARM::WIN_RECOVER_FP: {
+      MachineBasicBlock &MBB = *MI.getParent();
+      MachineBasicBlock::iterator MBBI = MI.getIterator();
+      MachineFunction &MF = *MI.getMF();
+      DebugLoc dl = MI.getDebugLoc();
+      Register DstReg = MI.getOperand(0).getReg();
+      const ARMBaseRegisterInfo &RI = TII->getRegisterInfo();
+      Register BaseReg = RI.getBaseRegister();
+      Register LocalAddrReg = RI.getLocalAddressRegister(MF);
+      if (AFI->isBasePtrSpilled()) {
+        // If the handler itself uses R6, we must restore the parent's R6.
----------------
trungnt2910 wrote:

I was worried that `r6` might get clobbered when the funclet has its own base 
pointer. However:
1. `__except` blocks are just a special label in the parent function.
2. `__finally` blocks are separate functions. They don't access variables via 
`r6` but through a live-in `r1`. They also don't set up the pointer - it's 
either the parent function or the trampoline that calls the `__finally` block.
3. The trampoline before `__finally` block does nothing but pass `r6` into `r1` 
for `__finally` blocks to consume. They can't define aligned variables or VLAs.
4. `__except` filter functions. These are tricky because they allow arbitrary 
expressions, which may include aligned variables and VLAs via a 
`[[msvc::forceinline]]` lambda. However:
   - Realigned variables can still be accessed via `sp`, if no VLAs are 
involved.
   - VLAs are already not supported by `clang` when in an SEH context: 
https://godbolt.org/z/hTjbaP8bx. They are also forbidden by MSVC.

There is also code that prevents clobbering `r6` due to it affecting other 
funclets like the case in `3.`:
https://github.com/llvm/llvm-project/blob/9889b965d18c37601fbe225adc0041c75ac3be9c/llvm/lib/Target/ARM/ARMFrameLowering.cpp#L1384

I added `CHECK` lines for `4.` and asserted that the aligned variable is 
accessed through the stack pointer `sp` and that `r6` remains unclobbered.

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

Reply via email to