[Transforms] classifyArgUse - don't deference pointer before null test
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 25 Oct 2022 16:23:25 +0000 (17:23 +0100)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Tue, 25 Oct 2022 16:24:00 +0000 (17:24 +0100)
Reported here: https://pvs-studio.com/en/blog/posts/cpp/1003/ (N11)

llvm/lib/Transforms/Utils/SimplifyLibCalls.cpp

index dd25fb3..7922f78 100644 (file)
@@ -2621,9 +2621,7 @@ void LibCallSimplifier::classifyArgUse(
     SmallVectorImpl<CallInst *> &SinCalls,
     SmallVectorImpl<CallInst *> &CosCalls,
     SmallVectorImpl<CallInst *> &SinCosCalls) {
-  CallInst *CI = dyn_cast<CallInst>(Val);
-  Module *M = CI->getModule();
-
+  auto *CI = dyn_cast<CallInst>(Val);
   if (!CI || CI->use_empty())
     return;
 
@@ -2631,6 +2629,7 @@ void LibCallSimplifier::classifyArgUse(
   if (CI->getFunction() != F)
     return;
 
+  Module *M = CI->getModule();
   Function *Callee = CI->getCalledFunction();
   LibFunc Func;
   if (!Callee || !TLI->getLibFunc(*Callee, Func) ||