diff mbox

C++ PATCH for c++/79050 (ICE with undeduced auto and LTO)

Message ID CADzB+2nk02CEHONWG2sze0D3iz9788KCmsYHAOiLfc8WX7muXw@mail.gmail.com
State New
Headers show

Commit Message

Jason Merrill Feb. 16, 2017, 4:38 p.m. UTC
LTO doesn't know how to stream undeduced auto, which shows up as a
TEMPLATE_TYPE_PARM.  Such a declaration isn't useful, since any
reference to it would give an error, so let's just remove it from
BLOCK_VARS.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 3ea102f324537e5706400bfdc8d9f57137877be6
Author: Jason Merrill <jason@redhat.com>
Date:   Wed Feb 15 16:33:00 2017 -0500

            PR c++/79050 - ICE with undeduced auto and LTO
    
            * decl.c (poplevel): Remove undeduced auto decls.
diff mbox

Patch

diff --git a/gcc/cp/decl.c b/gcc/cp/decl.c
index 353e7b5..70c44fb 100644
--- a/gcc/cp/decl.c
+++ b/gcc/cp/decl.c
@@ -792,14 +792,17 @@  poplevel (int keep, int reverse, int functionbody)
      back ends won't understand OVERLOAD, so we remove them here.
      Because the BLOCK_VARS are (temporarily) shared with
      CURRENT_BINDING_LEVEL->NAMES we must do this fixup after we have
-     popped all the bindings.  */
+     popped all the bindings.  Also remove undeduced 'auto' decls,
+     which LTO doesn't understand, and can't have been used by anything.  */
   if (block)
     {
       tree* d;
 
       for (d = &BLOCK_VARS (block); *d; )
 	{
-	  if (TREE_CODE (*d) == TREE_LIST)
+	  if (TREE_CODE (*d) == TREE_LIST
+	      || (!processing_template_decl
+		  && undeduced_auto_decl (*d)))
 	    *d = TREE_CHAIN (*d);
 	  else
 	    d = &DECL_CHAIN (*d);
diff --git a/gcc/testsuite/g++.dg/lto/pr79050_0.C b/gcc/testsuite/g++.dg/lto/pr79050_0.C
new file mode 100644
index 0000000..1f31b5d
--- /dev/null
+++ b/gcc/testsuite/g++.dg/lto/pr79050_0.C
@@ -0,0 +1,7 @@ 
+// PR c++/79050
+// { dg-lto-do assemble }
+
+int main ()
+{
+  auto foo ();
+}