]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
utils.c (unchecked_convert): When the result type is a non-biased integral type with...
authorEric Botcazou <ebotcazou@adacore.com>
Tue, 5 Sep 2017 09:16:52 +0000 (09:16 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Tue, 5 Sep 2017 09:16:52 +0000 (09:16 +0000)
* gcc-interface/utils.c (unchecked_convert): When the result type is a
non-biased integral type with size 0, set the result to 0 directly.

From-SVN: r251703

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

index 18e428bd5555d0e908d4958883fd9a06be081ca5..7b79356b1f8561e3d9f0228970b4c0e7b39e6689 100644 (file)
@@ -1,3 +1,8 @@
+2017-09-05  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/utils.c (unchecked_convert): When the result type is a
+       non-biased integral type with size 0, set the result to 0 directly.
+
 2017-09-05  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/trans.c (Call_to_gnu): If this is a function call and
index 86848ac4bc25cf54d42cc2d8697bf0b997f4b74c..d1c6da4e30cd81cb02467199faa670be50d64869 100644 (file)
@@ -5207,20 +5207,26 @@ unchecked_convert (tree type, tree expr, bool notrunc_p)
       && !(code == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (type))
       && !(TYPE_UNSIGNED (type) && TYPE_UNSIGNED (etype)))
     {
-      tree base_type
-       = gnat_type_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
-                             TYPE_UNSIGNED (type));
-      tree shift_expr
-       = convert (base_type,
-                  size_binop (MINUS_EXPR,
-                              TYPE_SIZE (type), TYPE_RM_SIZE (type)));
-      expr
-       = convert (type,
-                  build_binary_op (RSHIFT_EXPR, base_type,
-                                   build_binary_op (LSHIFT_EXPR, base_type,
-                                                    convert (base_type, expr),
-                                                    shift_expr),
-                                   shift_expr));
+      if (integer_zerop (TYPE_RM_SIZE (type)))
+       expr = build_int_cst (type, 0);
+      else
+       {
+         tree base_type
+           = gnat_type_for_size (TREE_INT_CST_LOW (TYPE_SIZE (type)),
+                                 TYPE_UNSIGNED (type));
+         tree shift_expr
+           = convert (base_type,
+                      size_binop (MINUS_EXPR,
+                                  TYPE_SIZE (type), TYPE_RM_SIZE (type)));
+         expr
+           = convert (type,
+                      build_binary_op (RSHIFT_EXPR, base_type,
+                                       build_binary_op (LSHIFT_EXPR, base_type,
+                                                        convert (base_type,
+                                                                 expr),
+                                                        shift_expr),
+                                       shift_expr));
+       }
     }
 
   /* An unchecked conversion should never raise Constraint_Error.  The code
index 389833b42557afc3f07675d2b22614abf34ffcc4..b83bf8d8765d55327f460aed83ac409eb2ce36f0 100644 (file)
@@ -1,3 +1,7 @@
+2017-09-05  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/specs/uc2.ads: New test.
+
 2017-09-05  Eric Botcazou  <ebotcazou@adacore.com>
 
        * testsuite/gnat.dg/array29.ad[sb]: New test.
diff --git a/gcc/testsuite/gnat.dg/specs/uc2.ads b/gcc/testsuite/gnat.dg/specs/uc2.ads
new file mode 100644 (file)
index 0000000..84d4e04
--- /dev/null
@@ -0,0 +1,18 @@
+-- { dg-do compile }
+-- { dg-options "-O" }
+
+with Ada.Unchecked_Conversion;
+
+package UC2 is
+
+  subtype Word_Type is Integer range 0 .. 0;
+  type Arr is array (1 .. Word_Type'Size) of Boolean;
+  pragma Pack(Arr);
+
+  function Conv is
+     new Ada.Unchecked_Conversion (Source => Arr, Target => Word_Type);
+
+  A : Arr;
+  W : Word_Type := Conv(A);
+
+end UC2;