utils2.c (build_binary_op): Make sure the element type is consistent.
authorEric Botcazou <ebotcazou@adacore.com>
Sat, 17 Oct 2009 11:05:35 +0000 (11:05 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Sat, 17 Oct 2009 11:05:35 +0000 (11:05 +0000)
* gcc-interface/utils2.c (build_binary_op) <ARRAY_RANGE_REF>: Make
sure the element type is consistent.

From-SVN: r152934

gcc/ada/ChangeLog
gcc/ada/gcc-interface/utils2.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/slice8.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/slice8_pkg1.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/slice8_pkg2.ads [new file with mode: 0644]
gcc/testsuite/gnat.dg/slice8_pkg3.adb [new file with mode: 0644]
gcc/testsuite/gnat.dg/slice8_pkg3.ads [new file with mode: 0644]

index d74fccebda6650a6cdac4db5d4d47c85fa564ece..80103fb053a0757cf09cf31539fc902c0b0a8bdf 100644 (file)
@@ -1,3 +1,8 @@
+2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/utils2.c (build_binary_op) <ARRAY_RANGE_REF>: Mak
+       sure the element type is consistent.
+
 2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/trans.c (addressable_p): Handle bitwise operations.
index fcd9ecd1253fd5d85f60ba9ecabccfe99a5d6264..7176740f453d625f3d55cca89d9e88eba144eb59 100644 (file)
@@ -755,6 +755,12 @@ build_binary_op (enum tree_code op_code, tree result_type,
          left_type = TREE_TYPE (left_operand);
        }
 
+      /* For a range, make sure the element type is consistent.  */
+      if (op_code == ARRAY_RANGE_REF
+         && TREE_TYPE (operation_type) != TREE_TYPE (left_type))
+       operation_type = build_array_type (TREE_TYPE (left_type),
+                                          TYPE_DOMAIN (operation_type));
+
       /* Then convert the right operand to its base type.  This will prevent
         unneeded sign conversions when sizetype is wider than integer.  */
       right_operand = convert (right_base_type, right_operand);
index 217c0d718617f5c9a175f9a51de54fe6aa66ff61..acbbe3619151ddd208cdc2f81befc37545d9f230 100644 (file)
@@ -1,3 +1,10 @@
+2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/slice8.adb: New test.
+       * gnat.dg/slice8_pkg1.ads: New helper.
+       * gnat.dg/slice8_pkg2.ads: Likewise.
+       * gnat.dg/slice8_pkg3.ad[sb]: Likewise.
+
 2009-10-17  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/unchecked_convert4.adb: New test.
diff --git a/gcc/testsuite/gnat.dg/slice8.adb b/gcc/testsuite/gnat.dg/slice8.adb
new file mode 100644 (file)
index 0000000..b05829d
--- /dev/null
@@ -0,0 +1,13 @@
+-- { dg-do compile }
+-- { dg-options "-gnatws" }
+
+with Slice8_Pkg1;
+with Slice8_Pkg3;
+
+procedure Slice8 is
+
+   package Bp is new Slice8_Pkg3 (Slice8_Pkg1);
+
+begin
+   null;
+end;
diff --git a/gcc/testsuite/gnat.dg/slice8_pkg1.ads b/gcc/testsuite/gnat.dg/slice8_pkg1.ads
new file mode 100644 (file)
index 0000000..3f433fd
--- /dev/null
@@ -0,0 +1,3 @@
+with Slice8_Pkg2;
+
+package Slice8_Pkg1 is new Slice8_Pkg2 (Line_Length => 132, Max_Lines => 1000);
diff --git a/gcc/testsuite/gnat.dg/slice8_pkg2.ads b/gcc/testsuite/gnat.dg/slice8_pkg2.ads
new file mode 100644 (file)
index 0000000..a6eafc6
--- /dev/null
@@ -0,0 +1,23 @@
+generic
+
+   Line_Length : Natural;
+   Max_Lines   : Natural;
+
+package Slice8_Pkg2 is
+
+   Subtype Index      is Natural Range 0..Line_length;
+   Subtype Line_Count is Natural Range 0..Max_Lines;
+
+   Type Line (Size : Index := 0) is
+   Record
+      Data : String (1..Size);
+   End Record;
+
+   Type Lines is Array (Line_Count Range <>) of Line;
+
+   Type Paragraph (Size : Line_Count) is
+   Record
+      Data : Lines (1..Size);
+   End Record;
+
+end Slice8_Pkg2;
diff --git a/gcc/testsuite/gnat.dg/slice8_pkg3.adb b/gcc/testsuite/gnat.dg/slice8_pkg3.adb
new file mode 100644 (file)
index 0000000..3524de1
--- /dev/null
@@ -0,0 +1,17 @@
+-- { dg-do compile }
+-- { dg-options "-gnatws" }
+
+package body Slice8_Pkg3 is
+
+   Current : Str.Lines (Str.Line_Count);
+   Last    : Natural := 0;
+
+   function Get return Str.Paragraph is
+      Result : constant Str.Paragraph := (Size => Last,
+                                          Data => Current (1..Last));
+   begin
+      Last := 0;
+      return Result;
+   end Get;
+
+end Slice8_Pkg3;
diff --git a/gcc/testsuite/gnat.dg/slice8_pkg3.ads b/gcc/testsuite/gnat.dg/slice8_pkg3.ads
new file mode 100644 (file)
index 0000000..a802cb7
--- /dev/null
@@ -0,0 +1,11 @@
+with Slice8_Pkg2;
+
+generic
+
+   with package Str is new Slice8_Pkg2 (<>);
+
+package Slice8_Pkg3 is
+
+   function Get return Str.Paragraph;
+
+end Slice8_Pkg3;