Fix "pointer is null" static analyzer warnings. NFCI.
authorSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 9 Jan 2020 11:48:06 +0000 (11:48 +0000)
committerSimon Pilgrim <llvm-dev@redking.me.uk>
Thu, 9 Jan 2020 12:05:47 +0000 (12:05 +0000)
Assert that the pointers are non-null before dereferencing them.

clang/lib/CodeGen/CGObjCGNU.cpp

index 479cd8e..a27b6d4 100644 (file)
@@ -1236,6 +1236,7 @@ class CGObjCGNUstep2 : public CGObjCGNUstep {
         // The first Interface we find may be a @class,
         // which should only be treated as the source of
         // truth in the absence of a true declaration.
+        assert(OID && "Failed to find ObjCInterfaceDecl");
         const ObjCInterfaceDecl *OIDDef = OID->getDefinition();
         if (OIDDef != nullptr)
           OID = OIDDef;
@@ -3036,6 +3037,7 @@ llvm::Value *CGObjCGNU::GenerateProtocolRef(CodeGenFunction &CGF,
   llvm::Constant *&protocol = ExistingProtocols[PD->getNameAsString()];
   if (!protocol)
     GenerateProtocol(PD);
+  assert(protocol && "Unknown protocol");
   llvm::Type *T =
     CGM.getTypes().ConvertType(CGM.getContext().getObjCProtoType());
   return CGF.Builder.CreateBitCast(protocol, llvm::PointerType::getUnqual(T));