An ARRAY_RANGE_REF is for extracting a range of elements from
an array, for example elements 1 to 2 of an [3 x i32], while
ARRAY_REF is for extracting a single element, say element 2.
EmitLV_ARRAY_REF, which handles both expression types, should
return a [2 x i32]* in the first case and an i32* in the second
case (currently it always returns a pointer to the element type).
The testcase is, as ever, in Ada (Ada is the only front-end that
generates ARRAY_RANGE_REF).

Duncan.
Index: gcc.llvm.master/gcc/llvm-convert.cpp
===================================================================
--- gcc.llvm.master.orig/gcc/llvm-convert.cpp	2007-03-14 22:15:45.000000000 +0100
+++ gcc.llvm.master/gcc/llvm-convert.cpp	2007-03-14 22:58:08.000000000 +0100
@@ -4617,6 +4617,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)) {
@@ -4627,13 +4629,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.
Index: llvm.master/test/AdaFrontend/array_range_ref.adb
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ llvm.master/test/AdaFrontend/array_range_ref.adb	2007-03-14 23:01:35.000000000 +0100
@@ -0,0 +1,7 @@
+-- RUN: %llvmgcc -c %s -o /dev/null
+procedure Array_Range_Ref is
+   A : String (1 .. 3);
+   B : String := A (A'RANGE)(1 .. 3);
+begin
+   null;
+end;
_______________________________________________
llvm-commits mailing list
llvm-commits@cs.uiuc.edu
http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits

Reply via email to