[cfe-commits] r162626 - in /cfe/trunk: include/clang/AST/VTableBuilder.h lib/CodeGen/CGRTTI.cpp

Richard Smith richard-llvm at metafoo.co.uk
Fri Aug 24 16:43:39 PDT 2012


Author: rsmith
Date: Fri Aug 24 18:43:39 2012
New Revision: 162626

URL: http://llvm.org/viewvc/llvm-project?rev=162626&view=rev
Log:
Fix integer unsigned behavior in clang due to signed left shift overflow.

Modified:
    cfe/trunk/include/clang/AST/VTableBuilder.h
    cfe/trunk/lib/CodeGen/CGRTTI.cpp

Modified: cfe/trunk/include/clang/AST/VTableBuilder.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/AST/VTableBuilder.h?rev=162626&r1=162625&r2=162626&view=diff
==============================================================================
--- cfe/trunk/include/clang/AST/VTableBuilder.h (original)
+++ cfe/trunk/include/clang/AST/VTableBuilder.h Fri Aug 24 18:43:39 2012
@@ -147,9 +147,10 @@
     assert((ComponentKind == CK_VCallOffset ||
             ComponentKind == CK_VBaseOffset ||
             ComponentKind == CK_OffsetToTop) && "Invalid component kind!");
-    assert(Offset.getQuantity() <= ((1LL << 56) - 1) && "Offset is too big!");
+    assert(Offset.getQuantity() < (1LL << 56) && "Offset is too big!");
+    assert(Offset.getQuantity() >= -(1LL << 56) && "Offset is too small!");
 
-    Value = ((Offset.getQuantity() << 3) | ComponentKind);
+    Value = (uint64_t(Offset.getQuantity()) << 3) | ComponentKind;
   }
 
   VTableComponent(Kind ComponentKind, uintptr_t Ptr) {

Modified: cfe/trunk/lib/CodeGen/CGRTTI.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/CodeGen/CGRTTI.cpp?rev=162626&r1=162625&r2=162626&view=diff
==============================================================================
--- cfe/trunk/lib/CodeGen/CGRTTI.cpp (original)
+++ cfe/trunk/lib/CodeGen/CGRTTI.cpp Fri Aug 24 18:43:39 2012
@@ -886,7 +886,7 @@
       Offset = Layout.getBaseClassOffset(BaseDecl);
     };
     
-    OffsetFlags = Offset.getQuantity() << 8;
+    OffsetFlags = uint64_t(Offset.getQuantity()) << 8;
     
     // The low-order byte of __offset_flags contains flags, as given by the 
     // masks from the enumeration __offset_flags_masks.





More information about the cfe-commits mailing list