[clang] 06e9733 - [CGExpr] Use castAs<> instead of getAs<> to avoid dereference of nullptr

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Sat Jan 8 06:30:20 PST 2022


Author: Simon Pilgrim
Date: 2022-01-08T14:26:09Z
New Revision: 06e9733fec8ddafb4c830853c198204def8a091a

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

LOG: [CGExpr] Use castAs<> instead of getAs<> to avoid dereference of nullptr

This will assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    clang/lib/CodeGen/CGExpr.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGExpr.cpp b/clang/lib/CodeGen/CGExpr.cpp
index 34b4951a7f721..66079328f8d7d 100644
--- a/clang/lib/CodeGen/CGExpr.cpp
+++ b/clang/lib/CodeGen/CGExpr.cpp
@@ -1931,7 +1931,7 @@ RValue CodeGenFunction::EmitLoadOfLValue(LValue LV, SourceLocation Loc) {
   if (LV.isMatrixElt()) {
     llvm::Value *Idx = LV.getMatrixIdx();
     if (CGM.getCodeGenOpts().OptimizationLevel > 0) {
-      const auto *const MatTy = LV.getType()->getAs<ConstantMatrixType>();
+      const auto *const MatTy = LV.getType()->castAs<ConstantMatrixType>();
       llvm::MatrixBuilder<CGBuilderTy> MB(Builder);
       MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
     }
@@ -2077,7 +2077,7 @@ void CodeGenFunction::EmitStoreThroughLValue(RValue Src, LValue Dst,
     if (Dst.isMatrixElt()) {
       llvm::Value *Idx = Dst.getMatrixIdx();
       if (CGM.getCodeGenOpts().OptimizationLevel > 0) {
-        const auto *const MatTy = Dst.getType()->getAs<ConstantMatrixType>();
+        const auto *const MatTy = Dst.getType()->castAs<ConstantMatrixType>();
         llvm::MatrixBuilder<CGBuilderTy> MB(Builder);
         MB.CreateIndexAssumption(Idx, MatTy->getNumElementsFlattened());
       }


        


More information about the cfe-commits mailing list