[llvm-commits] CVS: llvm/lib/Support/APInt.cpp

Reid Spencer reid at x10sys.com
Wed May 16 23:26:47 PDT 2007



Changes in directory llvm/lib/Support:

APInt.cpp updated: 1.83 -> 1.84
---
Log message:

For lshr by 0 bits, just return *this as a short cut. This also prevents
undefined behavior when the width > 64 bits.


---
Diffs of the changes:  (+6 -0)

 APInt.cpp |    6 ++++++
 1 files changed, 6 insertions(+)


Index: llvm/lib/Support/APInt.cpp
diff -u llvm/lib/Support/APInt.cpp:1.83 llvm/lib/Support/APInt.cpp:1.84
--- llvm/lib/Support/APInt.cpp:1.83	Wed May 16 14:18:22 2007
+++ llvm/lib/Support/APInt.cpp	Thu May 17 01:26:29 2007
@@ -1149,6 +1149,12 @@
   if (shiftAmt == BitWidth)
     return APInt(BitWidth, 0);
 
+  // If none of the bits are shifted out, the result is *this. This avoids
+  // issues with shifting byt he size of the integer type, which produces 
+  // undefined results in the code below. This is also an optimization.
+  if (shiftAmt == 0)
+    return *this;
+
   // Create some space for the result.
   uint64_t * val = new uint64_t[getNumWords()];
 






More information about the llvm-commits mailing list