[clang] adeb8c5 - Replace getAs with castAs to fix null dereference static analyzer warning.

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 12 11:53:32 PDT 2020


Author: Simon Pilgrim
Date: 2020-03-12T18:52:58Z
New Revision: adeb8c54285e754f7c34690b583a0bd9af19de78

URL: https://github.com/llvm/llvm-project/commit/adeb8c54285e754f7c34690b583a0bd9af19de78
DIFF: https://github.com/llvm/llvm-project/commit/adeb8c54285e754f7c34690b583a0bd9af19de78.diff

LOG: Replace getAs with castAs to fix null dereference static analyzer warning.

Use castAs as we know the cast should succeed (and castAs will assert if it doesn't) and we're dereferencing it directly in the BuildRCBlockVarRecordLayout call.

Added: 
    

Modified: 
    clang/lib/CodeGen/CGObjCMac.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index 44c14a745a98..87fd51b5d8b1 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2558,9 +2558,8 @@ void CGObjCCommonMac::BuildRCRecordLayout(const llvm::StructLayout *RecLayout,
       }
       if (FQT->isRecordType() && ElCount) {
         int OldIndex = RunSkipBlockVars.size() - 1;
-        const RecordType *RT = FQT->getAs<RecordType>();
-        BuildRCBlockVarRecordLayout(RT, BytePos + FieldOffset,
-                                    HasUnion);
+        auto *RT = FQT->castAs<RecordType>();
+        BuildRCBlockVarRecordLayout(RT, BytePos + FieldOffset, HasUnion);
 
         // Replicate layout information for each array element. Note that
         // one element is already done.


        


More information about the cfe-commits mailing list