[clang] 6ee589e - [CGObjCMac] Use castAs<> instead of getAs<> to avoid dereference of nullptr inside BuildRCBlockVarRecordLayout

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 8 08:19:09 PST 2022


Author: Simon Pilgrim
Date: 2022-01-08T16:18:55Z
New Revision: 6ee589e2f563a2a5c91f9aeb2762f092dd197e32

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

LOG: [CGObjCMac] Use castAs<> instead of getAs<> to avoid dereference of nullptr inside BuildRCBlockVarRecordLayout

This will assert the cast is correct instead of returning nullptr (UnionType is a subtype of RecordType so this should be clean).

Added: 
    

Modified: 
    clang/lib/CodeGen/CGObjCMac.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp
index d769574c1f5ef..d07524be127bb 100644
--- a/clang/lib/CodeGen/CGObjCMac.cpp
+++ b/clang/lib/CodeGen/CGObjCMac.cpp
@@ -2487,7 +2487,7 @@ void CGObjCCommonMac::BuildRCRecordLayout(const llvm::StructLayout *RecLayout,
       if (FQT->isUnionType())
         HasUnion = true;
 
-      BuildRCBlockVarRecordLayout(FQT->getAs<RecordType>(),
+      BuildRCBlockVarRecordLayout(FQT->castAs<RecordType>(),
                                   BytePos + FieldOffset, HasUnion);
       continue;
     }


        


More information about the cfe-commits mailing list