[llvm-commits] [124488] Fix another VLA array indexing bug.

clattner at apple.com clattner at apple.com
Fri Mar 2 15:36:34 PST 2007


Revision: 124488
Author:   clattner
Date:     2007-03-02 15:36:33 -0800 (Fri, 02 Mar 2007)

Log Message:
-----------
Fix another VLA array indexing bug.  PR1233.

Modified Paths:
--------------
    apple-local/branches/llvm/gcc/llvm-convert.cpp

Modified: apple-local/branches/llvm/gcc/llvm-convert.cpp
===================================================================
--- apple-local/branches/llvm/gcc/llvm-convert.cpp	2007-03-02 23:19:09 UTC (rev 124487)
+++ apple-local/branches/llvm/gcc/llvm-convert.cpp	2007-03-02 23:36:33 UTC (rev 124488)
@@ -4541,10 +4541,14 @@
         TREE_CODE(TYPE_MAX_VALUE(Domain)) != INTEGER_CST) {
       // Make sure that ArrayAddr is of type ElementTy*, then do a 2-index gep.
       tree ElTy = TREE_TYPE(TREE_TYPE(Array));
-      // This cast only deals with pointers so BitCast is appropriate
-      ArrayAddr = CastInst::create(Instruction::BitCast, 
-          ArrayAddr, PointerType::get(ConvertType(ElTy)), "tmp", CurBB);
-      return new GetElementPtrInst(ArrayAddr, IndexVal, "tmp", CurBB);
+      ArrayAddr = BitCastToType(ArrayAddr, PointerType::get(Type::Int8Ty));
+      Value *Scale = Emit(TYPE_SIZE_UNIT(ElTy), 0);
+      if (Scale->getType() != IntPtrTy)
+        Scale = CastToUIntType(Scale, IntPtrTy);
+
+      IndexVal = BinaryOperator::createMul(IndexVal, Scale, "tmp", CurBB);
+      Value *Ptr = new GetElementPtrInst(ArrayAddr, IndexVal, "tmp", CurBB);
+      return BitCastToType(Ptr, PointerType::get(ConvertType(TREE_TYPE(exp))));
     }
 
     // Otherwise, this is not a variable-sized array, use a GEP to index.





More information about the llvm-commits mailing list