[PATCH] D58363: Bugfix for nullptr check by klocwork

Xiang Zhang via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 18 17:38:23 PST 2019


xiangzhangllvm created this revision.
xiangzhangllvm added reviewers: LuoYuanke, wxiao3, craig.topper, vzakhari.
xiangzhangllvm added a project: LLVM.
Herald added a subscriber: llvm-commits.

klocwork critical issues in CG files:

#10087: Pointer 'ReferenceDI' returned from call to function 'get' at line 87 may be NULL and will be dereferenced at line 90.  	                llvm/lib/Target/X86/X86DiscriminateMemOps.cpp:87

#13373: Pointer 'DI' returned from call to function 'cloneWithDiscriminator' at line 145 may be NULL and will be dereferenced at line 150.	llvm/lib/Target/X86/X86DiscriminateMemOps.cpp:145

#17178: Pointer 'RegRB' returned from call to function 'getRegBank' at line 1603 may be NULL and will be dereferenced at line 1604.	        llvm/lib/Target/X86/X86InstructionSelector.cpp:1603


Repository:
  rL LLVM

https://reviews.llvm.org/D58363

Files:
  lib/Target/X86/X86DiscriminateMemOps.cpp
  lib/Target/X86/X86InstructionSelector.cpp


Index: lib/Target/X86/X86InstructionSelector.cpp
===================================================================
--- lib/Target/X86/X86InstructionSelector.cpp
+++ lib/Target/X86/X86InstructionSelector.cpp
@@ -1600,7 +1600,10 @@
   assert(RegTy == MRI.getType(Op1Reg) && RegTy == MRI.getType(Op2Reg) &&
          "Arguments and return value types must match");
 
-  const RegisterBank &RegRB = *RBI.getRegBank(DstReg, MRI, TRI);
+  const RegisterBank *PtrRegRB = RBI.getRegBank(DstReg, MRI, TRI);
+  if (!PtrRegRB)
+    return false;
+  const RegisterBank &RegRB = *PtrRegRB;
   if (RegRB.getID() != X86::GPRRegBankID)
     return false;
 
Index: lib/Target/X86/X86DiscriminateMemOps.cpp
===================================================================
--- lib/Target/X86/X86DiscriminateMemOps.cpp
+++ lib/Target/X86/X86DiscriminateMemOps.cpp
@@ -85,7 +85,7 @@
   // have any debug info.
   const DILocation *ReferenceDI =
       DILocation::get(FDI->getContext(), FDI->getLine(), 0, FDI);
-
+  assert(ReferenceDI && "ReferenceDI should not be nullptr");
   DenseMap<Location, unsigned> MemOpDiscriminators;
   MemOpDiscriminators[diToLocation(ReferenceDI)] = 0;
 
@@ -143,6 +143,7 @@
         // Since we were able to encode, bump the MemOpDiscriminators.
         ++MemOpDiscriminators[L];
         DI = DI->cloneWithDiscriminator(EncodedDiscriminator.getValue());
+        assert(DI && "DI should not be nullptr");
         updateDebugInfo(&MI, DI);
         Changed = true;
         std::pair<DenseSet<unsigned>::iterator, bool> MustInsert =


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D58363.187286.patch
Type: text/x-patch
Size: 1552 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190219/cc8c0fa9/attachment.bin>


More information about the llvm-commits mailing list