This is an archive of the discontinued LLVM Phabricator instance.

[CodeGen] Don't scavenge non-saved regs in exception throwing functions
ClosedPublic

Authored by olista01 on Jan 29 2019, 6:17 AM.

Details

Summary

Previously, LiveRegUnits was assuming that if a block has no successors
and does not return, then no registers are live at the end of it
(because the end of the block is unreachable). This was causing the
register scavenger to use callee-saved registers to materialise stack
frame addresses without saving them in the prologue. This would normally
be fine, because the end of the block is unreachable, but this is not
legal if the block ends by throwing a C++ exception. If this happens,
the scratch register will be modified, but its previous value won't be
preserved, so it doesn't get restored by the exception unwinder.

Diff Detail

Repository
rL LLVM

Event Timeline

olista01 created this revision.Jan 29 2019, 6:17 AM
olista01 updated this revision to Diff 184078.Jan 29 2019, 6:45 AM
olista01 edited reviewers, added: efriedma; removed: eli.friedman.

LivePhysRegs had some related issues; see https://reviews.llvm.org/D42655 (and related discussion on https://reviews.llvm.org/D42509, which was reverted). Can we structure this code the same way?

lib/CodeGen/LiveRegUnits.cpp
128

Please restructure this so we aren't checking succ_empty(); that check will cause wrong results in general.

olista01 updated this revision to Diff 184257.Jan 30 2019, 2:23 AM
efriedma added inline comments.Jan 30 2019, 11:33 AM
lib/CodeGen/LiveRegUnits.cpp
136

Looks like this comment fell out of date?

olista01 updated this revision to Diff 184469.Jan 31 2019, 1:26 AM
This revision is now accepted and ready to land.Jan 31 2019, 12:10 PM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptFeb 1 2019, 1:23 AM