[clang] [NFC] Avoid potential nullptr deref by using castAs<> (PR #123395)
via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 17 12:56:51 PST 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: None (schittir)
<details>
<summary>Changes</summary>
Use castAs<> instead of getAs<>
---
Full diff: https://github.com/llvm/llvm-project/pull/123395.diff
1 Files Affected:
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+4-4)
``````````diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 2385f2a320b625..d87528c432a360 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -19297,9 +19297,9 @@ Value *CodeGenFunction::EmitHLSLBuiltinExpr(unsigned BuiltinID,
assert(T0->isVectorTy() && T1->isVectorTy() &&
"Dot product of vector and scalar is not supported.");
- auto *VecTy0 = E->getArg(0)->getType()->getAs<VectorType>();
+ auto *VecTy0 = E->getArg(0)->getType()->castAs<VectorType>();
[[maybe_unused]] auto *VecTy1 =
- E->getArg(1)->getType()->getAs<VectorType>();
+ E->getArg(1)->getType()->castAs<VectorType>();
assert(VecTy0->getElementType() == VecTy1->getElementType() &&
"Dot product of vectors need the same element types.");
@@ -19392,7 +19392,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
llvm::Type *Xty = Op0->getType();
llvm::Type *retType = llvm::Type::getInt1Ty(this->getLLVMContext());
if (Xty->isVectorTy()) {
- auto *XVecTy = E->getArg(0)->getType()->getAs<VectorType>();
+ auto *XVecTy = E->getArg(0)->getType()->castAs<VectorType>();
retType = llvm::VectorType::get(
retType, ElementCount::getFixed(XVecTy->getNumElements()));
}
@@ -19578,7 +19578,7 @@ case Builtin::BI__builtin_hlsl_elementwise_isinf: {
llvm::Type *Xty = Op0->getType();
llvm::Type *retType = llvm::Type::getInt32Ty(this->getLLVMContext());
if (Xty->isVectorTy()) {
- auto *XVecTy = Arg0->getType()->getAs<VectorType>();
+ auto *XVecTy = Arg0->getType()->castAs<VectorType>();
retType = llvm::VectorType::get(
retType, ElementCount::getFixed(XVecTy->getNumElements()));
}
``````````
</details>
https://github.com/llvm/llvm-project/pull/123395
More information about the cfe-commits
mailing list