-
Notifications
You must be signed in to change notification settings - Fork 12.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[NFC] Avoid potential nullptr deref by using castAs<> #123395
Conversation
Use castAs<> instead of getAs<>
@llvm/pr-subscribers-clang Author: None (schittir) ChangesUse castAs<> instead of getAs<> Full diff: /~https://github.com/llvm/llvm-project/pull/123395.diff 1 Files Affected:
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()));
}
|
@llvm/pr-subscribers-clang-codegen Author: None (schittir) ChangesUse castAs<> instead of getAs<> Full diff: /~https://github.com/llvm/llvm-project/pull/123395.diff 1 Files Affected:
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()));
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Thank you for the review, @efriedma-quic |
Use castAs<> instead of getAs<>