[TargetRegisterInfo] Fix BitMaskClassIterator::moveToNextID implementation.
authorQuentin Colombet <qcolombet@apple.com>
Fri, 8 Apr 2016 00:50:58 +0000 (00:50 +0000)
committerQuentin Colombet <qcolombet@apple.com>
Fri, 8 Apr 2016 00:50:58 +0000 (00:50 +0000)
Make sure we do not read past the size of the mask. Although we were not using
the value read, this is bad and makes ASan complain.

llvm-svn: 265763

llvm/include/llvm/Target/TargetRegisterInfo.h

index 96842b3..48a0e0f 100644 (file)
@@ -987,17 +987,16 @@ class BitMaskClassIterator {
     // If the current chunk of memory is empty, move to the next one,
     // while making sure we do not go pass the number of register
     // classes.
-    while (!CurrentChunk && Base < NumRegClasses) {
+    while (!CurrentChunk) {
       // Move to the next chunk.
-      CurrentChunk = *++Mask;
       Base += 32;
+      if (Base >= NumRegClasses) {
+        ID = NumRegClasses;
+        return;
+      }
+      CurrentChunk = *++Mask;
       Idx = Base;
     }
-    // The mask is empty now.
-    if (!CurrentChunk || Base >= NumRegClasses) {
-      ID = NumRegClasses;
-      return;
-    }
     // Otherwise look for the first bit set from the right
     // (representation of the class ID is big endian).
     // See getSubClassMask for more details on the representation.