This is an archive of the discontinued LLVM Phabricator instance.

[X86] Fix emitEpilogue() to make less assumptions about pops
ClosedPublic

Authored by aaboud on Sep 8 2015, 2:16 AM.

Details

Summary

When X86FrameLowering::emitEpilogue() looks for where to insert the %esp restore to deallocate stack space for local allocations, it assumes that any sequence of pop instructions that starts from function exit consists purely of restoring callee-save registers.
This may be false, since from some point backward, the pops may be popping arguments, recently pushed to a preceded function call.

This caused a miscompile that was exposed by D12609, and is not easily testable since D12609 was not committed yet.. A test will be committed as part of D12609.

The solution is to introduce "FrameUnsetup" flag (similar to "FrameSetup"), which will be attached to all instructions in the epilogue code. This solution is inspired from r242395.

Diff Detail

Repository
rL LLVM

Event Timeline

aaboud updated this revision to Diff 34200.Sep 8 2015, 2:16 AM
aaboud retitled this revision from to [X86] Fix emitEpilogue() to make less assumptions about pops.
aaboud updated this object.
aaboud added reviewers: mkuper, rnk.
aaboud set the repository for this revision to rL LLVM.
rnk accepted this revision.Sep 8 2015, 1:36 PM
rnk edited edge metadata.

I think FrameDestroy would be a better name for the flag. It's consistent with our existing functions getCallFrameSetupOpcode() / getCallFrameDestroyOpcode().

At a high level, it seems like it would be better for us to insert some kind of marker for the beginning of the CSR restoration, but all the targets currently follow this exact pattern. This seems acceptable for now.

I guess the change is also untestable for now, but this is clearly an improvement. Looks good to me with the name change.

This revision is now accepted and ready to land.Sep 8 2015, 1:36 PM
This revision was automatically updated to reflect the committed changes.