poplevel already tries to keep undeduced autos out of BLOCK_VARS, but
in this testcase cp_genericize_r was adding one in later on.

Tested x86_64-pc-linux-gnu, applying to trunk.
commit 61f3456c563fd7b3354a688f40c1afbfa8423442
Author: Jason Merrill <ja...@redhat.com>
Date:   Fri Apr 6 07:45:01 2018 -0400

            PR c++/85240 - LTO ICE with using of undeduced auto fn.
    
            * cp-gimplify.c (cp_genericize_r): Discard using of undeduced auto.

diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c
index fd0c37f9be2..fb0aea3e0c7 100644
--- a/gcc/cp/cp-gimplify.c
+++ b/gcc/cp/cp-gimplify.c
@@ -1294,16 +1294,20 @@ cp_genericize_r (tree *stmt_p, int *walk_subtrees, void *data)
 	  }
 	if (block)
 	  {
-	    tree using_directive;
-	    gcc_assert (TREE_OPERAND (stmt, 0));
+	    tree decl = TREE_OPERAND (stmt, 0);
+	    gcc_assert (decl);
 
-	    using_directive = make_node (IMPORTED_DECL);
-	    TREE_TYPE (using_directive) = void_type_node;
+	    if (undeduced_auto_decl (decl))
+	      /* Omit from the GENERIC, the back-end can't handle it.  */;
+	    else
+	      {
+		tree using_directive = make_node (IMPORTED_DECL);
+		TREE_TYPE (using_directive) = void_type_node;
 
-	    IMPORTED_DECL_ASSOCIATED_DECL (using_directive)
-	      = TREE_OPERAND (stmt, 0);
-	    DECL_CHAIN (using_directive) = BLOCK_VARS (block);
-	    BLOCK_VARS (block) = using_directive;
+		IMPORTED_DECL_ASSOCIATED_DECL (using_directive) = decl;
+		DECL_CHAIN (using_directive) = BLOCK_VARS (block);
+		BLOCK_VARS (block) = using_directive;
+	      }
 	  }
 	/* The USING_STMT won't appear in GENERIC.  */
 	*stmt_p = build1 (NOP_EXPR, void_type_node, integer_zero_node);
diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn51.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn51.C
new file mode 100644
index 00000000000..7e4f488458b
--- /dev/null
+++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn51.C
@@ -0,0 +1,9 @@
+// PR c++/85240
+// { dg-do compile { target c++14 } }
+
+auto foo();
+
+void bar()
+{
+  using ::foo;
+}

Reply via email to