This is an archive of the discontinued LLVM Phabricator instance.

[PowerPC] Fix the frame addresss computing return address for `__builtin_return_address`
ClosedPublic

Authored by NeHuang on Aug 6 2021, 7:36 AM.

Details

Summary

When depth > 0, callee frame address is used to compute the return address of callee producing improper return address. This patch adds the fix to use caller frame address to compute the return address of callee.

Diff Detail

Event Timeline

NeHuang created this revision.Aug 6 2021, 7:36 AM
NeHuang requested review of this revision.Aug 6 2021, 7:36 AM
NeHuang updated this revision to Diff 364856.Aug 6 2021, 11:32 AM
  • Rebased with ToT
  • Clang-format
amyk added a subscriber: amyk.Aug 9 2021, 2:23 PM
amyk added inline comments.
llvm/test/CodeGen/PowerPC/retaddr_multi_levels.ll
3

nit: The RUN lines look a bit too long in this test.

22

At a glance, it looks like CHECK-64B-BE and CHECK-64B-AIX looks like they're the same CHECKs.
Do you think it's a good idea to combine them into a single check/use check-prefixes?

NeHuang updated this revision to Diff 365470.Aug 10 2021, 1:03 PM

Address review comments on the test case.

NeHuang marked 2 inline comments as done.Aug 10 2021, 1:04 PM
nemanjai added inline comments.Aug 10 2021, 5:42 PM
llvm/lib/Target/PowerPC/PPCISelLowering.cpp
15962

Please add a comment:

// The link register (return address) is saved in the caller's frame
// not the callee's stack frame. So we must get the caller's frame
// address and load the return address at the LR offset from there.
llvm/test/CodeGen/PowerPC/2010-05-03-retaddr1.ll
2

It is very hard to see what the actual differences are when you have changed the codegen as well as how the checks are produced in the same review. Could you please use the script to produce the checks and pre-commit that? Then this will show just the differences due to this patch.

NeHuang updated this revision to Diff 365761.Aug 11 2021, 7:59 AM

Address review comment from Nemanja.

NeHuang marked 2 inline comments as done.Aug 11 2021, 7:59 AM
nemanjai accepted this revision.Aug 11 2021, 8:43 AM

LGTM. Thanks for fixing this.

This revision is now accepted and ready to land.Aug 11 2021, 8:43 AM