This is an archive of the discontinued LLVM Phabricator instance.

[AArch64] Fix save register pairing for Windows AAPCS
ClosedPublic

Authored by sanwou01 on Dec 20 2019, 5:34 AM.

Details

Summary

On Windows, when a function does not have an unwind table (for example, EH
filtering funclets), we don't correctly pair FP and LR to form the frame record
in all circumstances.

Fix this by invalidating a pair when the second register is FP when compiling
for Windows, even when CFI is not needed.

Fixes PR44271 introduced by D65653.

Diff Detail

Event Timeline

sanwou01 created this revision.Dec 20 2019, 5:34 AM
rengolin added inline comments.Dec 20 2019, 6:02 AM
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
1877

This seems awfully permissive. Shouldn't you check that the pairs are explicitly:

FP + LR
LR + FP
1986

Is Windows' only ABI WindowsAAPCS?

sanwou01 marked 2 inline comments as done.Dec 23 2019, 9:19 AM
sanwou01 added inline comments.
llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
1877

Hm, this invalidates any pair with FP as the second register, so it follows that FP will be the first register of a pair (on Windows/WinAAPCS). The assert below (line 2028) checks that when FP is the first register of a pair, LR is the second.

Maybe I misunderstood your comment, but that seems quite precise to me!

1986

Good point. It might be so in the AArch64 backend, but who knows when a new ABI comes around.

rengolin accepted this revision.Dec 24 2019, 9:57 AM

LGTM, thanks!

llvm/lib/Target/AArch64/AArch64FrameLowering.cpp
1877

Right, my comment was about the assert below, but I guess you're right. The code that uses this function is not that trivial to read. :)

1986

Right, we change that when it does. :)

This revision is now accepted and ready to land.Dec 24 2019, 9:57 AM
This revision was automatically updated to reflect the committed changes.