diff mbox

Fix ICE in initialize_inlined_parameters with LTO

Message ID 1708227.BH4S3ROK0u@polaris
State New
Headers show

Commit Message

Eric Botcazou Nov. 13, 2016, 5:29 p.m. UTC
This is a regression present on the mainline and 6 branch: for the attached 
Ada testcase compiled in LTO mode, the following assertion triggers in 
initialize_inlined_parameters during inlining:

  if (p)
    {
      /* No static chain?  Seems like a bug in tree-nested.c.  */
      gcc_assert (static_chain);

      setup_one_parameter (id, p, static_chain, fn, bb, &vars);
    }

So we have a callee expecting a static chain but the caller doesn't pass one.
It turns out that the caller is a thunk created by the ICF pass (as a wrapper 
in ICF's terminology) so it definitely cannot pass a static chain.  Now ICF 
already makes sure that it doesn't create a wrapper in the opposite situation 
(alias expecting a static chain instead of original function) so the fixlet 
simply makes the test symmetric.

Tested on x86_64-suse-linux, applied on the mainline and 6 branch as obvious.


2016-11-13  Eric Botcazou  <ebotcazou@adacore.com>

	* ipa-icf.c (sem_function::merge): Do not create a wrapper also if the
	original function needs a static chain.


2016-11-13  Eric Botcazou  <ebotcazou@adacore.com>

	* gnat.dg/lto21.adb: New test.
	* gnat.dg/lto21_pkg1.ads: New helper.
	* gnat.dg/lto21_pkg2.ad[sb]: Likewise.

-- 
Eric Botcazou
diff mbox

Patch

Index: ipa-icf.c
===================================================================
--- ipa-icf.c	(revision 242334)
+++ ipa-icf.c	(working copy)
@@ -1186,11 +1186,12 @@  sem_function::merge (sem_item *alias_ite
 	    fprintf (dump_file,
 		     "Wrapper cannot be created because of COMDAT\n");
 	}
-      else if (DECL_STATIC_CHAIN (alias->decl))
+      else if (DECL_STATIC_CHAIN (alias->decl)
+	       || DECL_STATIC_CHAIN (original->decl))
         {
 	  if (dump_file)
 	    fprintf (dump_file,
-		     "Can not create wrapper of nested functions.\n");
+		     "Cannot create wrapper of nested function.\n");
         }
       /* TODO: We can also deal with variadic functions never calling
 	 VA_START.  */