]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
* gcc-interface/trans.c (return_value_ok_for_nrv_p): Add sanity check.
authorEric Botcazou <ebotcazou@adacore.com>
Fri, 24 Feb 2017 10:40:56 +0000 (10:40 +0000)
committerEric Botcazou <ebotcazou@gcc.gnu.org>
Fri, 24 Feb 2017 10:40:56 +0000 (10:40 +0000)
From-SVN: r245703

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

index 8f904d3b2619ecc4b0388d7f6705d0c35bbab569..950fed95d1bff033406abff9f8e80a05ceb335f7 100644 (file)
@@ -1,3 +1,7 @@
+2017-02-24  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gcc-interface/trans.c (return_value_ok_for_nrv_p): Add sanity check.
+
 2016-11-22  Uros Bizjak  <ubizjak@gmail.com>
 
        * gcc-interface/Make-lang.in (check-acats): Fix detection
index d142989448421ef6f5155229d14fb36a252c9e5b..fa4940a90fb5a9e1753d3272a94cd853d79a1599 100644 (file)
@@ -3499,9 +3499,16 @@ return_value_ok_for_nrv_p (tree ret_obj, tree ret_val)
   if (TREE_ADDRESSABLE (ret_val))
     return false;
 
+  /* For the constrained case, test for overalignment.  */
   if (ret_obj && DECL_ALIGN (ret_val) > DECL_ALIGN (ret_obj))
     return false;
 
+  /* For the unconstrained case, test for bogus initialization.  */
+  if (!ret_obj
+      && DECL_INITIAL (ret_val)
+      && TREE_CODE (DECL_INITIAL (ret_val)) == NULL_EXPR)
+    return false;
+
   return true;
 }
 
index 3fb7dba7672d41070ba20e82141fb936f2e9e063..fe526b4df404d2ddfa4f292f5f02a69d29e67e73 100644 (file)
@@ -1,3 +1,7 @@
+2017-02-24  Eric Botcazou  <ebotcazou@adacore.com>
+
+       * gnat.dg/opt63.adb: New test.
+
 2017-02-22  Bill Schmidt  <wschmidt@linux.vnet.ibm.com>
 
        Backport from mainline
diff --git a/gcc/testsuite/gnat.dg/opt63.adb b/gcc/testsuite/gnat.dg/opt63.adb
new file mode 100644 (file)
index 0000000..6471be4
--- /dev/null
@@ -0,0 +1,19 @@
+-- { dg-do compile }
+-- { dg-options "-O -gnatws" }
+
+procedure Opt63 is
+
+   type T_MOD is mod 2**32;
+   subtype T_INDEX is T_MOD range 3_000_000_000 .. 4_000_000_000;
+   type T_ARRAY is array(T_INDEX range <>) of INTEGER;
+
+   function Build_Crash(First : T_INDEX; Length : NATURAL) return T_ARRAY is
+      R : T_ARRAY(First .. T_Index'Val (T_Index'Pos (First) + Length))
+             := (others => -1); -- Crash here
+   begin
+      return R;
+   end;
+
+begin
+   null;
+end;