[WebAssembly] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Sat, 29 Jan 2022 16:08:06 +0000 (16:08 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Sat, 29 Jan 2022 16:08:06 +0000 (16:08 +0000)
The pointers are dereferenced immediately, so assert the cast is correct instead of returning nullptr

llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp

index 8a63c7c..b6c43be 100644 (file)
@@ -875,7 +875,7 @@ static void nullifySetjmp(Function *F) {
   SmallVector<Instruction *, 1> ToErase;
 
   for (User *U : make_early_inc_range(SetjmpF->users())) {
-    auto *CB = dyn_cast<CallBase>(U);
+    auto *CB = cast<CallBase>(U);
     BasicBlock *BB = CB->getParent();
     if (BB->getParent() != F) // in other function
       continue;
@@ -1320,7 +1320,7 @@ bool WebAssemblyLowerEmscriptenEHSjLj::runSjLjOnFunction(Function &F) {
   SmallVector<PHINode *, 4> SetjmpRetPHIs;
   Function *SetjmpF = M.getFunction("setjmp");
   for (auto *U : make_early_inc_range(SetjmpF->users())) {
-    auto *CB = dyn_cast<CallBase>(U);
+    auto *CB = cast<CallBase>(U);
     BasicBlock *BB = CB->getParent();
     if (BB->getParent() != &F) // in other function
       continue;