[PATCH] D147772: [NFC][GlobalISel] Add check for potentially dereferencing null return value

Bing Yu via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 7 01:58:02 PDT 2023


yubing created this revision.
Herald added a subscriber: hiraditya.
Herald added a project: All.
yubing requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D147772

Files:
  llvm/lib/CodeGen/GlobalISel/Utils.cpp


Index: llvm/lib/CodeGen/GlobalISel/Utils.cpp
===================================================================
--- llvm/lib/CodeGen/GlobalISel/Utils.cpp
+++ llvm/lib/CodeGen/GlobalISel/Utils.cpp
@@ -426,8 +426,9 @@
       VReg, MRI, isFConstant, getCImmOrFPImmAsAPInt, LookThroughInstrs);
   if (!Reg)
     return std::nullopt;
-  return FPValueAndVReg{getConstantFPVRegVal(Reg->VReg, MRI)->getValueAPF(),
-                        Reg->VReg};
+  const ConstantFP *CFP = getConstantFPVRegVal(Reg->VReg, MRI);
+  assert(CFP && "invalid ConstantFP!");
+  return FPValueAndVReg{CFP->getValueAPF(), Reg->VReg};
 }
 
 const ConstantFP *


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D147772.511642.patch
Type: text/x-patch
Size: 633 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230407/2dcbfe15/attachment.bin>


More information about the llvm-commits mailing list