]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
utils.c (convert): For a biased input type, convert the bias itself to the base type...
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 10 Oct 2016 08:53:06 +0000 (08:53 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 10 Oct 2016 08:53:06 +0000 (08:53 +0000)
* gcc-interface/utils.c (convert): For a biased input type, convert
the bias itself to the base type before adding it.

From-SVN: r240912

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

index 9b0a98b57623c19e4222b3328cb4ccb6d9ec3596..d6dc7e6c0c8288c2558105e5301df5391b8bebcc 100644 (file)
@@ -1,3 +1,8 @@
+2016-10-10  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/utils.c (convert): For a biased input type, convert
+       the bias itself to the base type before adding it.
+
 2016-06-03  Release Manager
 
        * GCC 5.4.0 released.
index 68340122b5c6a7156837a26e3e7eb830b58cc567..ce53e93d9b3d2505ef44734dd6f2aa7e41d9c39a 100644 (file)
@@ -4086,12 +4086,15 @@ convert (tree type, tree expr)
       return convert (type, unpadded);
     }
 
-  /* If the input is a biased type, adjust first.  */
+  /* If the input is a biased type, convert first to the base type and add
+     the bias.  Note that the bias must go through a full conversion to the
+     base type, lest it is itself a biased value; this happens for subtypes
+     of biased types.  */
   if (ecode == INTEGER_TYPE && TYPE_BIASED_REPRESENTATION_P (etype))
     return convert (type, fold_build2 (PLUS_EXPR, TREE_TYPE (etype),
                                       fold_convert (TREE_TYPE (etype), expr),
-                                      fold_convert (TREE_TYPE (etype),
-                                                    TYPE_MIN_VALUE (etype))));
+                                      convert (TREE_TYPE (etype),
+                                               TYPE_MIN_VALUE (etype))));
 
   /* If the input is a justified modular type, we need to extract the actual
      object before converting it to any other type with the exceptions of an
@@ -4393,7 +4396,12 @@ convert (tree type, tree expr)
          && (ecode == ARRAY_TYPE || ecode == UNCONSTRAINED_ARRAY_TYPE
              || (ecode == RECORD_TYPE && TYPE_CONTAINS_TEMPLATE_P (etype))))
        return unchecked_convert (type, expr, false);
-      else if (TYPE_BIASED_REPRESENTATION_P (type))
+
+      /* If the output is a biased type, convert first to the base type and
+        subtract the bias.  Note that the bias itself must go through a full
+        conversion to the base type, lest it is a biased value; this happens
+        for subtypes of biased types.  */
+      if (TYPE_BIASED_REPRESENTATION_P (type))
        return fold_convert (type,
                             fold_build2 (MINUS_EXPR, TREE_TYPE (type),
                                          convert (TREE_TYPE (type), expr),
index 7d71d00c1e8eb194b1635a919fc6687c2392ed31..7f4de62785376edebae170639bc00e6450fcf673 100644 (file)
@@ -1,3 +1,7 @@
+2016-10-10  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/biased_subtype.adb: New test.
+
 2016-10-05  Steven G. Kargl  <kargls@gcc.gnu.org>
 
        PR fortran/58991
diff --git a/gcc/testsuite/gnat.dg/biased_subtype.adb b/gcc/testsuite/gnat.dg/biased_subtype.adb
new file mode 100644 (file)
index 0000000..3833022
--- /dev/null
@@ -0,0 +1,20 @@
+-- { dg-do run }
+-- { dg-options "-gnatws" }
+
+procedure Biased_Subtype is
+
+   CIM_Max_AA : constant := 9_999_999;
+   CIM_Min_AA : constant := -999_999;
+
+   type TIM_AA is range CIM_Min_AA..CIM_Max_AA + 1;
+   for TIM_AA'Size use 24;
+
+   subtype STIM_AA is TIM_AA range TIM_AA(CIM_Min_AA)..TIM_AA(CIM_Max_AA);
+
+   SAA : STIM_AA := 1;
+
+begin
+   if Integer(SAA) /= 1 then
+     raise Program_Error;
+   end if;
+end;