* gcc-interface/utils2.c (gnat_invariant_expr): Add type conversions.
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 30 Nov 2015 11:34:31 +0000 (11:34 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 30 Nov 2015 11:34:31 +0000 (11:34 +0000)
From-SVN: r231063

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

index a90fa647b5f7c94019eb7480d1a248b05e5ed739..cc0add237d1e23cd8b563d604d0842ce89ee6f7c 100644 (file)
@@ -1,3 +1,7 @@
+2015-11-30  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/utils2.c (gnat_invariant_expr): Add type conversions.
+
 2015-11-30  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gcc-interface/ada-tree.h (TYPE_MAX_ALIGN): New macro.
index 79e9b2f26dae9cfd5c866b9e90fc11221b13a161..a74b8a81018d3755e27cfd808591c87ba5632d1d 100644 (file)
@@ -2860,7 +2860,9 @@ gnat_invariant_expr (tree expr)
       tree op0 = gnat_invariant_expr (TREE_OPERAND (expr, 0));
       tree op1 = TREE_OPERAND (expr, 1);
       if (op0 && TREE_CONSTANT (op1))
-       return fold_build2 (TREE_CODE (expr), type, op0, op1);
+       return
+         fold_build2 (TREE_CODE (expr), type,
+                      fold_convert (type, op0), fold_convert (type, op1));
       else
        return NULL_TREE;
     }
index e7a3058c4b4e4252cf4ed392736aa307fd8243e1..e31b7f0c6c6c13c15e42d86362e94b80a4eb9af8 100644 (file)
@@ -1,3 +1,7 @@
+2015-11-30  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/loop_optimization22.ad[sb]: New test.
+
 2015-11-30  Eric Botcazou  <ebotcazou@adacore.com>
 
        * gnat.dg/specs/rep_clause5.ads: New test.
diff --git a/gcc/testsuite/gnat.dg/loop_optimization22.adb b/gcc/testsuite/gnat.dg/loop_optimization22.adb
new file mode 100644 (file)
index 0000000..7fb307b
--- /dev/null
@@ -0,0 +1,16 @@
+-- { dg-do compile }
+-- { dg-options "-O" }
+
+pragma Overflow_Mode (Minimized);
+
+package body Loop_Optimization22 is
+
+  procedure Foo (X : Discrim_Type) is
+      H : array (1 .. Integer (X.Count) + 1) of Float;
+   begin
+      for I in 1 .. X.Count loop
+         H (Integer(I) + 1):= 0.0;
+      end loop;
+   end;
+
+end Loop_Optimization22;
diff --git a/gcc/testsuite/gnat.dg/loop_optimization22.ads b/gcc/testsuite/gnat.dg/loop_optimization22.ads
new file mode 100644 (file)
index 0000000..ec3ac0d
--- /dev/null
@@ -0,0 +1,7 @@
+package Loop_Optimization22 is
+
+  type Discrim_Type (Count : Positive) is null record;
+
+  procedure Foo (X : Discrim_Type);
+
+end Loop_Optimization22;