[llvm] 3a1fd17 - [WebAssembly] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Sat Jan 29 08:08:19 PST 2022


Author: Simon Pilgrim
Date: 2022-01-29T16:08:06Z
New Revision: 3a1fd170271da25e7ce9b0a329adf47483378229

URL: https://github.com/llvm/llvm-project/commit/3a1fd170271da25e7ce9b0a329adf47483378229
DIFF: https://github.com/llvm/llvm-project/commit/3a1fd170271da25e7ce9b0a329adf47483378229.diff

LOG: [WebAssembly] Use cast<> instead of dyn_cast<> to avoid dereference of nullptr

The pointers are dereferenced immediately, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
index 8a63c7c893dc7..b6c43be03aba0 100644
--- a/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
+++ b/llvm/lib/Target/WebAssembly/WebAssemblyLowerEmscriptenEHSjLj.cpp
@@ -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;


        


More information about the llvm-commits mailing list