[all-commits] [llvm/llvm-project] 5ff5dd: [Win64] Insert int3 into trailing empty BBs

Reid Kleckner via All-commits all-commits at lists.llvm.org
Mon Mar 23 08:57:47 PDT 2020


  Branch: refs/heads/master
  Home:   https://github.com/llvm/llvm-project
  Commit: 5ff5ddd0adc89f8827b345577bbb3e7eb74fc644
      https://github.com/llvm/llvm-project/commit/5ff5ddd0adc89f8827b345577bbb3e7eb74fc644
  Author: Reid Kleckner <rnk at google.com>
  Date:   2020-03-23 (Mon, 23 Mar 2020)

  Changed paths:
    M llvm/lib/CodeGen/MIRParser/MILexer.cpp
    M llvm/lib/CodeGen/MIRParser/MILexer.h
    M llvm/lib/CodeGen/MIRParser/MIParser.cpp
    M llvm/lib/CodeGen/MIRPrinter.cpp
    M llvm/lib/Target/X86/X86.h
    M llvm/lib/Target/X86/X86AvoidTrailingCall.cpp
    M llvm/lib/Target/X86/X86TargetMachine.cpp
    A llvm/test/CodeGen/X86/win64-eh-empty-block-2.mir
    M llvm/test/CodeGen/X86/win64-eh-empty-block.ll
    M llvm/test/CodeGen/X86/wineh-coreclr.ll

  Log Message:
  -----------
  [Win64] Insert int3 into trailing empty BBs

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.

Reviewed By: hans

Differential Revision: https://reviews.llvm.org/D76531




More information about the All-commits mailing list