diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 300ab6cd4d2d0ac4982d606aa41f834182465061..582d65a9c4a96563ca55824b35cf58f9dbcd5d0d 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2018-10-11  Jan Hubicka  <hubicka@ucw.cz>
+
+	* ipa-utils.h (type_with_linkage_p): No longer check for TYPE_STUB_DECL;
+	it is wrong for forward declarations.
+
 2018-10-24  Ilya Leoshkevich  <iii@linux.ibm.com>
 
 	* config/s390/s390.c (s390_check_qrst_address): Add the missing
diff --git a/gcc/ipa-utils.h b/gcc/ipa-utils.h
index 98f2a75cd814ceacf08141bd29dd4fd5636fc62d..7d663ec6b0eebbbf75136f1d58a40866b7f85743 100644
--- a/gcc/ipa-utils.h
+++ b/gcc/ipa-utils.h
@@ -193,10 +193,10 @@ type_with_linkage_p (const_tree t)
   if (DECL_ASSEMBLER_NAME_SET_P (TYPE_NAME (t)))
     return true;
 
-  /* If free lang data was not run check if indeed the type looks like C++
-     type with linkage.  */
-  if (in_lto_p || !TYPE_STUB_DECL (t))
+  if (in_lto_p)
     return false;
+  /* We used to check for TYPE_STUB_DECL but that is set to NULL for forward
+     declarations.  */
 
   if (!RECORD_OR_UNION_TYPE_P (t) && TREE_CODE (t) != ENUMERAL_TYPE)
     return false;