[llvm-commits] [125161] Return the correct type for ARRAY_RANGE_REF.

dpatel at apple.com dpatel at apple.com
Mon Mar 19 16:38:02 PDT 2007


Revision: 125161
Author:   dpatel
Date:     2007-03-19 16:38:02 -0700 (Mon, 19 Mar 2007)

Log Message:
-----------
Return the correct type for ARRAY_RANGE_REF.
Patch by Duncan Sands.

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-19 20:55:02 UTC (rev 125160)
+++ apple-local/branches/llvm/gcc/llvm-convert.cpp	2007-03-19 23:38:02 UTC (rev 125161)
@@ -4558,6 +4558,8 @@
 
   // If this is an index into an array, codegen as a GEP.
   if (TREE_CODE(TREE_TYPE(Array)) == ARRAY_TYPE) {
+    Value *Ptr;
+
     // Check for variable sized array reference.
     tree length = arrayLength(TREE_TYPE(Array));
     if (length && !host_integerp(length, 1)) {
@@ -4568,13 +4570,16 @@
         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))));
+      Ptr = new GetElementPtrInst(ArrayAddr, IndexVal, "tmp", CurBB);
+    } else {
+      // Otherwise, this is not a variable-sized array, use a GEP to index.
+      Ptr = new GetElementPtrInst(ArrayAddr, ConstantInt::get(Type::Int32Ty, 0),
+                                  IndexVal, "tmp", CurBB);
     }
 
-    // Otherwise, this is not a variable-sized array, use a GEP to index.
-    return new GetElementPtrInst(ArrayAddr, ConstantInt::get(Type::Int32Ty, 0),
-                                 IndexVal, "tmp", CurBB);
+    // The result type is an ElementTy* in the case of an ARRAY_REF, an array
+    // of ElementTy in the case of ARRAY_RANGE_REF.  Return the correct type.
+    return BitCastToType(Ptr, PointerType::get(ConvertType(TREE_TYPE(exp))));
   }
 
   // Otherwise, this is an index off a pointer, codegen as a 2-idx GEP.





More information about the llvm-commits mailing list