[PATCH] D153146: [CLANG] Fix potential integer overflow value in getRVVTypeSize()

Soumi Manna via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jun 16 08:25:10 PDT 2023


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,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D153146.532162.patch
Type: text/x-patch
Size: 483 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230616/de40f2cc/attachment.bin>


More information about the cfe-commits mailing list