aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2009-09-07 22:44:55 +0000
committerDan Gohman <gohman@apple.com>2009-09-07 22:44:55 +0000
commit80bdc967e946b5d68646ffdee857400f9a120cca (patch)
tree78a005c4d5415ea6d7c4c0df94cddb8392e3570f
parentce5de5b52768d0c3b9c0f6c4bc915a17e962202c (diff)
downloadexternal_llvm-80bdc967e946b5d68646ffdee857400f9a120cca.zip
external_llvm-80bdc967e946b5d68646ffdee857400f9a120cca.tar.gz
external_llvm-80bdc967e946b5d68646ffdee857400f9a120cca.tar.bz2
Don't commit stores with addresses that have indices that are not
compile-time constant integers or that are out of bounds for their corresponding static array types. These can cause aliasing that GlobalOpt assumes won't happen. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@81165 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Transforms/IPO/GlobalOpt.cpp21
1 files changed, 21 insertions, 0 deletions
diff --git a/lib/Transforms/IPO/GlobalOpt.cpp b/lib/Transforms/IPO/GlobalOpt.cpp
index 86c5e29..b995a3d 100644
--- a/lib/Transforms/IPO/GlobalOpt.cpp
+++ b/lib/Transforms/IPO/GlobalOpt.cpp
@@ -2044,6 +2044,27 @@ static bool isSimpleEnoughPointerToCommit(Constant *C, LLVMContext &Context) {
// external globals.
if (!GV->hasDefinitiveInitializer())
return false;
+
+ gep_type_iterator GEPI = gep_type_begin(CE), E = gep_type_end(CE);
+ User::op_iterator OI = next(CE->op_begin());
+
+ // The first index must be zero.
+ ConstantInt *CI = dyn_cast<ConstantInt>(*OI);
+ if (!CI || !CI->isZero()) return false;
+ ++GEPI;
+ ++OI;
+
+ // The remaining indices must be compile-time known integers within the
+ // bounds of the corresponding static array types.
+ for (; GEPI != E; ++GEPI, ++OI) {
+ CI = dyn_cast<ConstantInt>(*OI);
+ if (!CI) return false;
+ if (const ArrayType *ATy = dyn_cast<ArrayType>(*GEPI))
+ if (CI->getValue().getActiveBits() > 64 ||
+ CI->getZExtValue() >= ATy->getNumElements())
+ return false;
+ }
+
return ConstantFoldLoadThroughGEPConstantExpr(GV->getInitializer(), CE,
Context);
}