[clang] 2f23dc9 - [AST/Interp] Fix left shift overflow bug in D64146

Fangrui Song via cfe-commits cfe-commits at lists.llvm.org
Thu Sep 8 13:49:15 PDT 2022


Author: Fangrui Song
Date: 2022-09-08T13:49:07-07:00
New Revision: 2f23dc9127e6c0ef392f163cbaa58afcb7b61a09

URL: https://github.com/llvm/llvm-project/commit/2f23dc9127e6c0ef392f163cbaa58afcb7b61a09
DIFF: https://github.com/llvm/llvm-project/commit/2f23dc9127e6c0ef392f163cbaa58afcb7b61a09.diff

LOG: [AST/Interp] Fix left shift overflow bug in D64146

Noticed by Dmitri Gribenko

Added: 
    

Modified: 
    clang/lib/AST/Interp/Descriptor.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/Interp/Descriptor.cpp b/clang/lib/AST/Interp/Descriptor.cpp
index 2098ae778a87..34240ed4352d 100644
--- a/clang/lib/AST/Interp/Descriptor.cpp
+++ b/clang/lib/AST/Interp/Descriptor.cpp
@@ -269,7 +269,7 @@ InitMap::T *InitMap::data() {
 
 bool InitMap::initialize(unsigned I) {
   unsigned Bucket = I / PER_FIELD;
-  unsigned Mask = 1ull << static_cast<uint64_t>(I % PER_FIELD);
+  T Mask = T(1) << (I % PER_FIELD);
   if (!(data()[Bucket] & Mask)) {
     data()[Bucket] |= Mask;
     UninitFields -= 1;
@@ -279,8 +279,7 @@ bool InitMap::initialize(unsigned I) {
 
 bool InitMap::isInitialized(unsigned I) {
   unsigned Bucket = I / PER_FIELD;
-  unsigned Mask = 1ull << static_cast<uint64_t>(I % PER_FIELD);
-  return data()[Bucket] & Mask;
+  return data()[Bucket] & (T(1) << (I % PER_FIELD));
 }
 
 InitMap *InitMap::allocate(unsigned N) {


        


More information about the cfe-commits mailing list