[clang] 9ece72c - [clang] VisitCastExpr - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
Simon Pilgrim via cfe-commits
cfe-commits at lists.llvm.org
Fri Feb 11 02:51:49 PST 2022
Author: Simon Pilgrim
Date: 2022-02-11T10:51:34Z
New Revision: 9ece72c159720d1c771249f5a565f6ca39a31ae3
URL: https://github.com/llvm/llvm-project/commit/9ece72c159720d1c771249f5a565f6ca39a31ae3
DIFF: https://github.com/llvm/llvm-project/commit/9ece72c159720d1c771249f5a565f6ca39a31ae3.diff
LOG: [clang] VisitCastExpr - use cast<> instead of dyn_cast<> to avoid dereference of nullptr
The pointer is always dereferenced, so assert the cast is correct (which it should be as we just created that ScalableVectorType) instead of returning nullptr
Added:
Modified:
clang/lib/CodeGen/CGExprScalar.cpp
Removed:
################################################################################
diff --git a/clang/lib/CodeGen/CGExprScalar.cpp b/clang/lib/CodeGen/CGExprScalar.cpp
index 705e50b58324..59d0bd08d33d 100644
--- a/clang/lib/CodeGen/CGExprScalar.cpp
+++ b/clang/lib/CodeGen/CGExprScalar.cpp
@@ -2093,7 +2093,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
if (ScalableDst == PredType &&
FixedSrc->getElementType() == Builder.getInt8Ty()) {
DstTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
- ScalableDst = dyn_cast<llvm::ScalableVectorType>(DstTy);
+ ScalableDst = cast<llvm::ScalableVectorType>(DstTy);
NeedsBitCast = true;
}
if (FixedSrc->getElementType() == ScalableDst->getElementType()) {
@@ -2119,7 +2119,7 @@ Value *ScalarExprEmitter::VisitCastExpr(CastExpr *CE) {
if (ScalableSrc == PredType &&
FixedDst->getElementType() == Builder.getInt8Ty()) {
SrcTy = llvm::ScalableVectorType::get(Builder.getInt8Ty(), 2);
- ScalableSrc = dyn_cast<llvm::ScalableVectorType>(SrcTy);
+ ScalableSrc = cast<llvm::ScalableVectorType>(SrcTy);
Src = Builder.CreateBitCast(Src, SrcTy);
}
if (ScalableSrc->getElementType() == FixedDst->getElementType()) {
More information about the cfe-commits
mailing list