re PR ada/56474 (bogus Storage_Error raised for record containing empty zero-based...
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 7 May 2013 07:59:37 +0000 (07:59 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 7 May 2013 07:59:37 +0000 (07:59 +0000)
PR ada/56474
* gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Subtype>: Use
int_const_binop to shift bounds by 1 when they are integer constants.

From-SVN: r198663

gcc/ada/ChangeLog
gcc/ada/gcc-interface/decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gnat.dg/specs/array3.ads [new file with mode: 0644]

index 5088853790df9dbe040298cc97cc05d5a858d7b6..a3e776c0d1893748a87a6bc71ecd600578a9bc9f 100644 (file)
@@ -1,3 +1,9 @@
+2013-05-07  Eric Botcazou  <ebotcazou@adacore.com>
+
+       PR ada/56474
+       * gcc-interface/decl.c (gnat_to_gnu_entity) <E_Array_Subtype>: Use
+       int_const_binop to shift bounds by 1 when they are integer constants.
+
 2013-04-25  Arnaud Charlet  <charlet@adacore.com>
 
        * gcc-interface/Makefile.in (ADA_EXCLUDE_SRCS): Exclude s-init.ad{s,b}
index e65701b9a0575d884237e7a293a9c50c3077db14..98653243b8080326a59529c5844bb7e30722c026 100644 (file)
@@ -2447,15 +2447,17 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
                                                        gnu_orig_max,
                                                        gnu_orig_min),
                                       gnu_min,
-                                      size_binop (PLUS_EXPR, gnu_max,
-                                                  size_one_node));
+                                      int_const_binop (PLUS_EXPR, gnu_max,
+                                                       size_one_node));
                }
 
              /* Finally we use (hb >= lb) ? hb : lb - 1 for the upper bound
                 in all the other cases.  Note that, here as well as above,
                 the condition used in the comparison must be equivalent to
                 the condition (length != 0).  This is relied upon in order
-                to optimize array comparisons in compare_arrays.  */
+                to optimize array comparisons in compare_arrays.  Moreover
+                we use int_const_binop for the shift by 1 if the bound is
+                constant to avoid any unwanted overflow.  */
              else
                gnu_high
                  = build_cond_expr (sizetype,
@@ -2464,8 +2466,11 @@ gnat_to_gnu_entity (Entity_Id gnat_entity, tree gnu_expr, int definition)
                                                      gnu_orig_max,
                                                      gnu_orig_min),
                                     gnu_max,
-                                    size_binop (MINUS_EXPR, gnu_min,
-                                                size_one_node));
+                                    TREE_CODE (gnu_min) == INTEGER_CST
+                                    ? int_const_binop (MINUS_EXPR, gnu_min,
+                                                       size_one_node)
+                                    : size_binop (MINUS_EXPR, gnu_min,
+                                                  size_one_node));
 
              /* Reuse the index type for the range type.  Then make an index
                 type with the size range in sizetype.  */
index dc8c10e19db32999646544984980861cec15319f..0908c8678e9eeb84c1dc049a87c68c43e9132f11 100644 (file)
@@ -1,3 +1,7 @@
+2013-05-07  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/specs/array3.ads: New test.
+
 2013-05-06  Marc Glisse  <marc.glisse@inria.fr>
 
        * c-c++-common/vector-scalar-2.c: New testcase.
diff --git a/gcc/testsuite/gnat.dg/specs/array3.ads b/gcc/testsuite/gnat.dg/specs/array3.ads
new file mode 100644 (file)
index 0000000..3ef39f3
--- /dev/null
@@ -0,0 +1,18 @@
+-- PR middle-end/56474
+-- Reported by Pavel Zhukov <pavel@zhukoff.net>
+
+-- { dg-do compile }
+
+with Ada.Streams;
+
+package Array3 is
+
+   use type Ada.Streams.Stream_Element_Offset;
+
+   type Vector (Size : Ada.Streams.Stream_Element_Offset) is record
+      Value : Ada.Streams.Stream_Element_Array (0 .. Size);
+   end record;
+
+   Empty_Vector : Vector (-1);
+
+end Array3;