From: Eric Botcazou Date: Fri, 24 Feb 2017 10:35:14 +0000 (+0000) Subject: * gcc-interface/trans.c (return_value_ok_for_nrv_p): Add sanity check. X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=0b9cdb9a4011886f0166a648f874f880ac9e026a;p=gcc.git * gcc-interface/trans.c (return_value_ok_for_nrv_p): Add sanity check. From-SVN: r245701 --- diff --git a/gcc/ada/ChangeLog b/gcc/ada/ChangeLog index c7b1ef0ab6d..44e525abc47 100644 --- a/gcc/ada/ChangeLog +++ b/gcc/ada/ChangeLog @@ -1,3 +1,7 @@ +2017-02-24 Eric Botcazou + + * gcc-interface/trans.c (return_value_ok_for_nrv_p): Add sanity check. + 2017-02-24 Eric Botcazou * gcc-interface/decl.c: Include demangle.h. diff --git a/gcc/ada/gcc-interface/trans.c b/gcc/ada/gcc-interface/trans.c index 7cde2306480..d38a0a96011 100644 --- a/gcc/ada/gcc-interface/trans.c +++ b/gcc/ada/gcc-interface/trans.c @@ -3614,9 +3614,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; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dc2cf4ee2af..9425a0d9c71 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,7 @@ +2017-02-24 Eric Botcazou + + * gnat.dg/opt63.adb: New test. + 2017-02-24 Eric Botcazou * gnat.dg/discr47.adb: New test. diff --git a/gcc/testsuite/gnat.dg/opt63.adb b/gcc/testsuite/gnat.dg/opt63.adb new file mode 100644 index 00000000000..6471be40bbd --- /dev/null +++ b/gcc/testsuite/gnat.dg/opt63.adb @@ -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;