[PATCH] IR: Do not canonicalize constant GEPs into an out-of-bounds array access

Bill Wendling isanbard at gmail.com
Wed Nov 6 17:14:21 PST 2013


  Could you test your change on PR17158? This may work, but it would be good if Chandler lent his eyes to it. :-)


================
Comment at: lib/IR/ConstantFold.cpp:1972
@@ +1971,3 @@
+            IsSequentialAccessInRange = true;
+
+        if (NumElements <= INT64_MAX && NumElements != 0)
----------------
After this 'if' statement, the next if statement is superfluous. You should make the if statement below in the 'else' part of this if.

================
Comment at: lib/IR/ConstantFold.cpp:1963
@@ +1962,3 @@
+      if (LastTy && isa<SequentialType>(LastTy)) {
+        int64_t NumElements = 0;
+        if (ArrayType *ATy = dyn_cast<ArrayType>(LastTy))
----------------
Please use unsigned types here.

================
Comment at: lib/IR/ConstantFold.cpp:1965
@@ +1964,3 @@
+        if (ArrayType *ATy = dyn_cast<ArrayType>(LastTy))
+          NumElements = (int64_t)ATy->getNumElements();
+        else if (VectorType *VTy = dyn_cast<VectorType>(LastTy))
----------------
Ditto.

================
Comment at: lib/IR/ConstantFold.cpp:1975
@@ +1974,3 @@
+          if (ConstantInt *CIIdx0 = dyn_cast<ConstantInt>(Idx0))
+            if (CIIdx0->getSExtValue() < NumElements)
+              IsSequentialAccessInRange = true;
----------------
Please do a zext instead of sext.


http://llvm-reviews.chandlerc.com/D2093



More information about the llvm-commits mailing list