[clang] 497a4b2 - CGBuiltin - Use castAs<> instead of getAs<> to avoid dereference of nullptr

Simon Pilgrim via cfe-commits cfe-commits at lists.llvm.org
Wed Jan 12 07:36:10 PST 2022


Author: Simon Pilgrim
Date: 2022-01-12T15:35:37Z
New Revision: 497a4b26c487a9640847c485f9b0c36c110a8545

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

LOG: CGBuiltin - Use castAs<> instead of getAs<> to avoid dereference of nullptr

The pointer is always dereferenced immediately below, so assert the cast is correct instead of returning nullptr

Added: 
    

Modified: 
    clang/lib/CodeGen/CGBuiltin.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index e9dd41a7daa1..91284baf123a 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -3223,7 +3223,7 @@ RValue CodeGenFunction::EmitBuiltinExpr(const GlobalDecl GD, unsigned BuiltinID,
         *this, E, llvm::Intrinsic::vector_reduce_xor, "rdx.xor"));
 
   case Builtin::BI__builtin_matrix_transpose: {
-    const auto *MatrixTy = E->getArg(0)->getType()->getAs<ConstantMatrixType>();
+    auto *MatrixTy = E->getArg(0)->getType()->castAs<ConstantMatrixType>();
     Value *MatValue = EmitScalarExpr(E->getArg(0));
     MatrixBuilder<CGBuilderTy> MB(Builder);
     Value *Result = MB.CreateMatrixTranspose(MatValue, MatrixTy->getNumRows(),


        


More information about the cfe-commits mailing list