aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsmanna12 <soumi.manna@intel.com>2024-03-27 17:17:27 -0500
committerGitHub <noreply@github.com>2024-03-27 17:17:27 -0500
commit4c2f68840e984b0f111779c46845ac00e3a7547d (patch)
tree73bdd268c2602090c2312ecff658d11e86391eec
parent8a75faf4717b8258b59cf9fbb4cbd2f189114d3f (diff)
downloadllvm-4c2f68840e984b0f111779c46845ac00e3a7547d.zip
llvm-4c2f68840e984b0f111779c46845ac00e3a7547d.tar.gz
llvm-4c2f68840e984b0f111779c46845ac00e3a7547d.tar.bz2
[CLANG] Fix potential integer overflow value in getRVVTypeSize() (#86810)
In getRVVTypeSize(clang::ASTContext &, clang::BuiltinType const *) potential integer overflow occurs on expression VScale->first * MinElts with type unsigned int (32 bits, unsigned) is evaluated using 32-bit arithmetic, and then used in a context that expects an expression of type uint64_t (64 bits, unsigned). To avoid integer overflow, this patch changes the types of variables MinElts and EltSize to uint64_t instead of the cast. The change matches what was originally done in https://github.com/llvm/llvm-project/commit/7372c0d46d2185017c509eb30910b102b4f9cdaa. Looks like the revert happened in https://github.com/llvm/llvm-project/commit/c92ad411f2f94d8521cd18abcb37285f9a390ecb
-rw-r--r--clang/lib/AST/ASTContext.cpp4
1 files changed, 2 insertions, 2 deletions
diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp
index 20a5ecc..c90fafb 100644
--- a/clang/lib/AST/ASTContext.cpp
+++ b/clang/lib/AST/ASTContext.cpp
@@ -9600,11 +9600,11 @@ static uint64_t getRVVTypeSize(ASTContext &Context, const BuiltinType *Ty) {
ASTContext::BuiltinVectorTypeInfo Info = Context.getBuiltinVectorTypeInfo(Ty);
- unsigned EltSize = Context.getTypeSize(Info.ElementType);
+ uint64_t EltSize = Context.getTypeSize(Info.ElementType);
if (Info.ElementType == Context.BoolTy)
EltSize = 1;
- unsigned MinElts = Info.EC.getKnownMinValue();
+ uint64_t MinElts = Info.EC.getKnownMinValue();
return VScale->first * MinElts * EltSize;
}