This is an archive of the discontinued LLVM Phabricator instance.

[Win64] Insert int3 into trailing empty BBs
ClosedPublic

Authored by rnk on Mar 20 2020, 3:06 PM.

Details

Summary

Otherwise, the Win64 unwinder considers direct branches to such empty
trailing BBs to be a branch out of the function. It treats such a branch
as a tail call, which can only be part of an epilogue. If the unwinder
misclassifies such a branch as part of the epilogue, it will fail to
unwind the stack further. This can lead to bad stack traces, or failure
to handle exceptions properly. This is described in
https://llvm.org/PR45064#c4, and by the comment at the top of the
X86AvoidTrailingCallPass.cpp file.

It should be safe to insert int3 for such blocks. An empty trailing BB
that reaches this pass is pretty much guaranteed to be unreachable. If
a program executed such a block, it would fall off the end of the
function.

Most of the complexity in this patch comes from threading through the
"EHFuncletEntry" boolean on the MIRParser and registering the pass so we
can stop and start codegen around it. I used an MIR test because we
should teach LLVM to optimize away these branches as a follow-up.

Diff Detail

Event Timeline

rnk created this revision.Mar 20 2020, 3:06 PM
Herald added a project: Restricted Project. · View Herald TranscriptMar 20 2020, 3:06 PM
Herald added a subscriber: hiraditya. · View Herald Transcript
rnk updated this revision to Diff 251795.Mar 20 2020, 4:13 PM
  • fix test expectations, avoid empty fns
hans accepted this revision.Mar 23 2020, 6:16 AM

lgtm

This revision is now accepted and ready to land.Mar 23 2020, 6:16 AM
This revision was automatically updated to reflect the committed changes.