Fix "pointer is null" static analyzer warning. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 15 Jan 2020 11:49:21 +0000 (11:49 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Wed, 15 Jan 2020 12:18:11 +0000 (12:18 +0000)
Use cast<> instead of dyn_cast<> since the pointer is always dereferenced and cast<> will perform the null assertion for us.

llvm/lib/Target/NVPTX/NVPTXLowerAlloca.cpp

index 945b728..cf488b0 100644 (file)
@@ -70,8 +70,7 @@ bool NVPTXLowerAlloca::runOnFunction(Function &F) {
     for (auto &I : BB) {
       if (auto allocaInst = dyn_cast<AllocaInst>(&I)) {
         Changed = true;
-        auto PTy = dyn_cast<PointerType>(allocaInst->getType());
-        auto ETy = PTy->getElementType();
+        auto ETy = cast<PointerType>(allocaInst->getType())->getElementType();
         auto LocalAddrTy = PointerType::get(ETy, ADDRESS_SPACE_LOCAL);
         auto NewASCToLocal = new AddrSpaceCastInst(allocaInst, LocalAddrTy, "");
         auto GenericAddrTy = PointerType::get(ETy, ADDRESS_SPACE_GENERIC);