Manna created this revision. Manna added reviewers: erichkeane, aaron.ballman, tahonermann. Herald added a project: All. Manna requested review of this revision. Herald added a project: clang.
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 does cast MinElts to type uint64_t. Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D153146 Files: clang/lib/AST/ASTContext.cpp Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -9566,7 +9566,7 @@ unsigned EltSize = Context.getTypeSize(Info.ElementType); unsigned MinElts = Info.EC.getKnownMinValue(); - return VScale->first * MinElts * EltSize; + return VScale->first * static_cast<uint64_t>(MinElts) * EltSize; } bool ASTContext::areCompatibleRVVTypes(QualType FirstType,
Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -9566,7 +9566,7 @@ unsigned EltSize = Context.getTypeSize(Info.ElementType); unsigned MinElts = Info.EC.getKnownMinValue(); - return VScale->first * MinElts * EltSize; + return VScale->first * static_cast<uint64_t>(MinElts) * EltSize; } bool ASTContext::areCompatibleRVVTypes(QualType FirstType,
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits