The address of a VIEW_CONVERT_EXPR is the address of its
operand, but the type is the type of the expression.  The
current code gets the address right but the type wrong.
Fix and Ada testcase attached.

Duncan.
Index: gcc.llvm.master/gcc/llvm-convert.cpp
===================================================================
--- gcc.llvm.master.orig/gcc/llvm-convert.cpp	2007-03-14 19:03:58.000000000 +0100
+++ gcc.llvm.master/gcc/llvm-convert.cpp	2007-03-14 23:55:58.000000000 +0100
@@ -850,14 +850,17 @@
   case BIT_FIELD_REF: return EmitLV_BIT_FIELD_REF(exp);
   case REALPART_EXPR: return EmitLV_XXXXPART_EXPR(exp, 0);
   case IMAGPART_EXPR: return EmitLV_XXXXPART_EXPR(exp, 1);
+
   // Constants.
   case LABEL_DECL:    return TreeConstantToLLVM::EmitLV_LABEL_DECL(exp);
   case STRING_CST:    return LValue(TreeConstantToLLVM::EmitLV_STRING_CST(exp));
 
+  // Type Conversion.
+  case VIEW_CONVERT_EXPR: return EmitLV_VIEW_CONVERT_EXPR(exp);
+
   // Trivial Cases.
-  case VIEW_CONVERT_EXPR:
   case WITH_SIZE_EXPR:
-    // The address of a these is the address of their operand.
+    // The address is the address of the operand.
     return EmitLV(TREE_OPERAND(exp, 0));
   case INDIRECT_REF:
     // The lvalue is just the address.
@@ -4882,6 +4885,15 @@
                                       "tmp", CurBB));
 }
 
+LValue TreeToLLVM::EmitLV_VIEW_CONVERT_EXPR(tree exp) {
+  // The address is the address of the operand.
+  LValue LV = EmitLV(TREE_OPERAND(exp, 0));
+  // The type is the type of the expression.
+  const Type *Ty = ConvertType(TREE_TYPE(exp));
+  LV.Ptr = BitCastToType(LV.Ptr, PointerType::get(Ty));
+  return LV;
+}
+
 //===----------------------------------------------------------------------===//
 //                       ... Constant Expressions ...
 //===----------------------------------------------------------------------===//
Index: gcc.llvm.master/gcc/llvm-internal.h
===================================================================
--- gcc.llvm.master.orig/gcc/llvm-internal.h	2007-03-14 18:49:36.000000000 +0100
+++ gcc.llvm.master/gcc/llvm-internal.h	2007-03-14 22:15:29.000000000 +0100
@@ -523,6 +523,7 @@
   LValue EmitLV_COMPONENT_REF(tree_node *exp);
   LValue EmitLV_BIT_FIELD_REF(tree_node *exp);
   LValue EmitLV_XXXXPART_EXPR(tree_node *exp, unsigned Idx);
+  LValue EmitLV_VIEW_CONVERT_EXPR(tree_node *exp);
 
   // Constant Expressions.
   Value *EmitINTEGER_CST(tree_node *exp);
Index: llvm.master/test/AdaFrontend/vce_lv.adb
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ llvm.master/test/AdaFrontend/vce_lv.adb	2007-03-14 23:32:09.000000000 +0100
@@ -0,0 +1,9 @@
+-- RUN: %llvmgcc -c %s -o /dev/null
+procedure VCE_LV is
+   type P is access String ;
+   type T is new P (5 .. 7);
+   subtype U is String (5 .. 7);
+   X : T := new U'(others => 'A');
+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