[WebAssembly] Fix a sanitizer error in WasmEHPrepare

Summary:
D77423 started using a dominator tree in WasmEHPrepare, but we deleted
BBs in `prepareThrows` before we used the domtree in `prepareEHPads`,
and those CFG changes were not reflected in the domtree. This uses
`DomTreeUpdater` to make sure we update the domtree every time we delete
BBs from the CFG. This fixes ubsan/msan/expensive_check errors caught in
LLVM buildbots.

Reviewers: dschuff

Subscribers: sbc100, jgravelle-google, hiraditya, sunfish, llvm-commits

Tags: #llvm

Differential Revision: https://reviews.llvm.org/D77465
This commit is contained in:
Heejin Ahn 2020-04-04 09:45:47 -07:00
parent eb81d440fc
commit fc5d8b672b
1 changed files with 7 additions and 3 deletions

View File

@ -81,6 +81,7 @@
#include "llvm/ADT/SetVector.h" #include "llvm/ADT/SetVector.h"
#include "llvm/ADT/Statistic.h" #include "llvm/ADT/Statistic.h"
#include "llvm/ADT/Triple.h" #include "llvm/ADT/Triple.h"
#include "llvm/Analysis/DomTreeUpdater.h"
#include "llvm/CodeGen/Passes.h" #include "llvm/CodeGen/Passes.h"
#include "llvm/CodeGen/TargetLowering.h" #include "llvm/CodeGen/TargetLowering.h"
#include "llvm/CodeGen/TargetSubtargetInfo.h" #include "llvm/CodeGen/TargetSubtargetInfo.h"
@ -164,14 +165,14 @@ bool WasmEHPrepare::doInitialization(Module &M) {
// Erase the specified BBs if the BB does not have any remaining predecessors, // Erase the specified BBs if the BB does not have any remaining predecessors,
// and also all its dead children. // and also all its dead children.
template <typename Container> template <typename Container>
static void eraseDeadBBsAndChildren(const Container &BBs) { static void eraseDeadBBsAndChildren(const Container &BBs, DomTreeUpdater *DTU) {
SmallVector<BasicBlock *, 8> WL(BBs.begin(), BBs.end()); SmallVector<BasicBlock *, 8> WL(BBs.begin(), BBs.end());
while (!WL.empty()) { while (!WL.empty()) {
auto *BB = WL.pop_back_val(); auto *BB = WL.pop_back_val();
if (pred_begin(BB) != pred_end(BB)) if (pred_begin(BB) != pred_end(BB))
continue; continue;
WL.append(succ_begin(BB), succ_end(BB)); WL.append(succ_begin(BB), succ_end(BB));
DeleteDeadBlock(BB); DeleteDeadBlock(BB, DTU);
} }
} }
@ -184,6 +185,9 @@ bool WasmEHPrepare::runOnFunction(Function &F) {
} }
bool WasmEHPrepare::prepareThrows(Function &F) { bool WasmEHPrepare::prepareThrows(Function &F) {
auto &DT = getAnalysis<DominatorTreeWrapperPass>().getDomTree();
DomTreeUpdater DTU(&DT, /*PostDominatorTree*/ nullptr,
DomTreeUpdater::UpdateStrategy::Eager);
Module &M = *F.getParent(); Module &M = *F.getParent();
IRBuilder<> IRB(F.getContext()); IRBuilder<> IRB(F.getContext());
bool Changed = false; bool Changed = false;
@ -206,7 +210,7 @@ bool WasmEHPrepare::prepareThrows(Function &F) {
InstList.erase(std::next(BasicBlock::iterator(ThrowI)), InstList.end()); InstList.erase(std::next(BasicBlock::iterator(ThrowI)), InstList.end());
IRB.SetInsertPoint(BB); IRB.SetInsertPoint(BB);
IRB.CreateUnreachable(); IRB.CreateUnreachable();
eraseDeadBBsAndChildren(Succs); eraseDeadBBsAndChildren(Succs, &DTU);
} }
return Changed; return Changed;