[PATCH] D76531: [Win64] Insert int3 into trailing empty BBs

Reid Kleckner via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Mar 20 15:12:49 PDT 2020


rnk created this revision.
rnk added reviewers: mstorsjo, hans, majnemer.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D76531

Files:
  llvm/lib/CodeGen/MIRParser/MILexer.cpp
  llvm/lib/CodeGen/MIRParser/MILexer.h
  llvm/lib/CodeGen/MIRParser/MIParser.cpp
  llvm/lib/CodeGen/MIRPrinter.cpp
  llvm/lib/Target/X86/X86.h
  llvm/lib/Target/X86/X86AvoidTrailingCall.cpp
  llvm/lib/Target/X86/X86TargetMachine.cpp
  llvm/test/CodeGen/X86/win64-eh-empty-block-2.mir
  llvm/test/CodeGen/X86/win64-eh-empty-block.ll

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D76531.251785.patch
Type: text/x-patch
Size: 17606 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20200320/47be1ff6/attachment.bin>


More information about the llvm-commits mailing list