[clang] [Clang] Prevent null pointer dereferencein SVE tuple functions (PR #94267)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Jun 3 11:26:44 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang-codegen
Author: None (smanna12)
<details>
<summary>Changes</summary>
This patch replaces dyn_cast<> with cast<> for obtaining ScalableVectorType pointers in the EmitSVETupleSetOrGet() and EmitSVETupleCreate() functions to ensure that the code expects valid ScalableVectorType instances and will cause an assertion if the cast is invalid, preventing possible null pointer dereferences and improving codes safety.
---
Full diff: https://github.com/llvm/llvm-project/pull/94267.diff
1 Files Affected:
- (modified) clang/lib/CodeGen/CGBuiltin.cpp (+2-2)
``````````diff
diff --git a/clang/lib/CodeGen/CGBuiltin.cpp b/clang/lib/CodeGen/CGBuiltin.cpp
index 37d0c478e0330..3ba9f4693170f 100644
--- a/clang/lib/CodeGen/CGBuiltin.cpp
+++ b/clang/lib/CodeGen/CGBuiltin.cpp
@@ -10211,7 +10211,7 @@ Value *CodeGenFunction::EmitSVETupleSetOrGet(const SVETypeFlags &TypeFlags,
"Expects TypleFlag isTupleSet or TypeFlags.isTupleSet()");
unsigned I = cast<ConstantInt>(Ops[1])->getSExtValue();
- auto *SingleVecTy = dyn_cast<llvm::ScalableVectorType>(
+ auto *SingleVecTy = cast<llvm::ScalableVectorType>(
TypeFlags.isTupleSet() ? Ops[2]->getType() : Ty);
Value *Idx = ConstantInt::get(CGM.Int64Ty,
I * SingleVecTy->getMinNumElements());
@@ -10226,7 +10226,7 @@ Value *CodeGenFunction::EmitSVETupleCreate(const SVETypeFlags &TypeFlags,
ArrayRef<Value *> Ops) {
assert(TypeFlags.isTupleCreate() && "Expects TypleFlag isTupleCreate");
- auto *SrcTy = dyn_cast<llvm::ScalableVectorType>(Ops[0]->getType());
+ auto *SrcTy = cast<llvm::ScalableVectorType>(Ops[0]->getType());
unsigned MinElts = SrcTy->getMinNumElements();
Value *Call = llvm::PoisonValue::get(Ty);
for (unsigned I = 0; I < Ops.size(); I++) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/94267
More information about the cfe-commits
mailing list