diff mbox

[Ada] Fix segfault in NRV on pathological case

Message ID 1799087.z6Hqgvfm9Q@polaris
State New
Headers show

Commit Message

Eric Botcazou Feb. 24, 2017, 10:41 a.m. UTC
This is a regression present on all active branches where the NRV pass 
implemented in gigi segfaults on a pathological case.

Tested on x86_64-suse-linux, applied on all active branches.


2017-02-24  Eric Botcazou  <ebotcazou@adacore.com>

	* gcc-interface/trans.c (return_value_ok_for_nrv_p): Add sanity check


2017-02-24  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/opt63.adb: New test.
diff mbox

Patch

Index: gcc-interface/trans.c
===================================================================
--- gcc-interface/trans.c	(revision 245699)
+++ gcc-interface/trans.c	(working copy)
@@ -3614,9 +3614,16 @@  return_value_ok_for_nrv_p (tree ret_obj,
   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;
 }