]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
utils2.c (gnat_invariant_expr): Return null if the type of the expression ends up...
authorEric Botcazou <ebotcazou@adacore.com>
Mon, 16 Mar 2015 10:09:27 +0000 (10:09 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Mon, 16 Mar 2015 10:09:27 +0000 (10:09 +0000)
* gcc-interface/utils2.c (gnat_invariant_expr): Return null if the type
of the expression ends up being composite.

From-SVN: r221451

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

index 0050ae5f6367676de7ccf58dc5d1754f9d84fe90..03a5c83f6c76d03407fae869059c85851230f10a 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-16  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/utils2.c (gnat_invariant_expr): Return null if the type
+       of the expression ends up being composite.
+
 2014-12-19  Release Manager
 
        * GCC 4.8.4 released.
index 71dd8e5651395b0d56da8069243f7e96e90c54ac..c427247342952e0aac97ad0e7dd0327cccc872e0 100644 (file)
@@ -2740,6 +2740,12 @@ gnat_invariant_expr (tree expr)
         && DECL_INITIAL (expr))
     expr = remove_conversions (DECL_INITIAL (expr), false);
 
+  /* We are only interested in scalar types at the moment and, even if we may
+     have gone through padding types in the above loop, we must be back to a
+     scalar value at this point.  */
+  if (AGGREGATE_TYPE_P (TREE_TYPE (expr)))
+    return NULL_TREE;
+
   if (TREE_CONSTANT (expr))
     return fold_convert (type, expr);
 
index 73c6b9e6a0726a822f65257157f20aa989065867..6465a02f381e485d8641687a10438c7b0483bbd1 100644 (file)
@@ -1,3 +1,8 @@
+2015-03-16  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/loop_optimization18.ad[sb]: New test.
+       * gnat.dg/loop_optimization18_pkg.ads: New helper.
+
 2015-03-15  Paul Thomas  <pault@gcc.gnu.org>
 
        Backport from mainline
diff --git a/gcc/testsuite/gnat.dg/loop_optimization18.adb b/gcc/testsuite/gnat.dg/loop_optimization18.adb
new file mode 100644 (file)
index 0000000..eb4eeca
--- /dev/null
@@ -0,0 +1,16 @@
+-- { dg-do compile }
+-- { dg-options "-O3" }
+
+package body Loop_Optimization18 is
+
+   procedure Proc (Message : Byte_Array_Type) is
+
+      R : Rec (Conv (Message));
+
+   begin
+      for Division in 1 .. R.UB loop
+         R.L (Division) := 0;
+      end loop;
+  end;
+
+end Loop_Optimization18;
diff --git a/gcc/testsuite/gnat.dg/loop_optimization18.ads b/gcc/testsuite/gnat.dg/loop_optimization18.ads
new file mode 100644 (file)
index 0000000..c9f3e2a
--- /dev/null
@@ -0,0 +1,7 @@
+with Loop_Optimization18_Pkg; use Loop_Optimization18_Pkg;
+
+package Loop_Optimization18 is
+
+   procedure Proc (Message : Byte_Array_Type);
+
+end Loop_Optimization18;
diff --git a/gcc/testsuite/gnat.dg/loop_optimization18_pkg.ads b/gcc/testsuite/gnat.dg/loop_optimization18_pkg.ads
new file mode 100644 (file)
index 0000000..9fb3311
--- /dev/null
@@ -0,0 +1,15 @@
+with Unchecked_Conversion;
+
+package Loop_Optimization18_Pkg is
+
+   type Arr is array (Integer range <>) of Natural;
+
+   type Rec (UB : Integer) is record
+      L : Arr (1 .. UB);
+   end record;
+
+   type Byte_Array_Type is new String (1..4);
+
+   function Conv is new Unchecked_Conversion (Byte_Array_Type, Integer);
+
+end Loop_Optimization18_Pkg;