This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

PR 63166 (wrong devirtualization in ipa-prop)


Hi,
this patch fixes wrong type propagation across global variable.

Bootstrapped/regtested x86_64-linux, will commit it shortly.
	PR ipa/63166
	* ipa-prop.c (compute_known_type_jump_func): Fix conditional.

	* g++.dg/lto/pr63166_0.ii: New testcase.
	* g++.dg/lto/pr63166_1.ii: New testcase.
Index: ipa-prop.c
===================================================================
--- ipa-prop.c	(revision 215096)
+++ ipa-prop.c	(working copy)
@@ -1537,8 +1537,8 @@ compute_known_type_jump_func (tree op, s
 				    call, current_function_decl)
       /* Even if the var seems to be in construction by inline call stack,
 	 we may work out the actual type by walking memory writes.  */
-      && (!is_global_var (base)
-	  && detect_type_change (op, base, expected_type, call, jfunc, offset)))
+      && (is_global_var (base)
+	  || detect_type_change (op, base, expected_type, call, jfunc, offset)))
     return;
 
   ipa_set_jf_known_type (jfunc, offset, TREE_TYPE (base),
Index: testsuite/g++.dg/lto/pr63166_1.ii
===================================================================
--- testsuite/g++.dg/lto/pr63166_1.ii	(revision 0)
+++ testsuite/g++.dg/lto/pr63166_1.ii	(revision 0)
@@ -0,0 +1,108 @@
+class EIdent { };
+class Cstring { };
+template < class KEY, class VALUE, class HASHER > class HashMapIterator
+{
+public:
+  virtual ~ HashMapIterator () { }
+};
+
+class ECell;
+class ECell_ptr
+{
+  ECell *mp_element;
+public:
+    ECell * operator -> () const
+  {
+    return (mp_element);
+  }
+}
+sicat_cmd_status;
+class CellListIterator;
+class ECellList
+{
+public:
+  virtual CellListIterator * createIterator () const = 0;
+  virtual ECell_ptr Find (const EIdent & anIdent) = 0;
+};
+class Foobar_Out
+{
+  virtual int get_channel () { }
+public:
+    Foobar_Out & operator << (const char *str);
+  Foobar_Out & operator << (const Cstring & cstring);
+};
+
+class Foobar_Log:public Foobar_Out { };
+extern Foobar_Log Foobar_LOG;
+template < class KEY > class BagIterator
+{
+public:
+  inline const KEY & operator * () const;
+  inline int atEnd () const;
+};
+
+class EMaskView;
+class ECell
+{
+public:
+  virtual const EMaskView & getMaskView () const = 0;
+};
+class FoobarDatabase
+{
+public:
+  const Cstring & getName (const EIdent & id) const;
+  ECellList *getCellList ();
+};
+inline FoobarDatabase &
+DB () { }
+
+class EMaskView
+{
+public:
+  inline BagIterator < EIdent > getCallerIterator () const;
+};
+struct DBHashFunctions
+{
+};
+class CellListIterator:public HashMapIterator < EIdent, ECell *,
+  DBHashFunctions >
+{
+};
+class IdentSet
+{
+public:
+  unsigned int getSize () const { }
+  int isEmpty () const { }
+};
+class IdentSetIterator
+{
+public:
+  IdentSetIterator (const IdentSet * p_source) { }
+  int atEnd () const { }
+  EIdent operator* () const { }
+};
+void
+validate ()
+{
+  IdentSet complete_cell_ids;
+  IdentSet incomplete_cell_ids;
+  CellListIterator *p_cl_it = DB ().getCellList ()->createIterator ();
+  delete p_cl_it;
+  while (!incomplete_cell_ids.isEmpty ())
+    {
+      if (incomplete_cell_ids.getSize () < complete_cell_ids.getSize ())
+	{
+	  IdentSetIterator complete_cell_it (&complete_cell_ids);
+	  while (!complete_cell_it.atEnd ())
+	    {
+	      BagIterator < EIdent > caller_it =
+		DB ().getCellList ()->Find (*complete_cell_it)->
+		getMaskView ().getCallerIterator ();
+	      while (!caller_it.atEnd ())
+		{
+		  Foobar_LOG << DB ().getName (*caller_it) << " ";
+		}
+	    }
+	}
+    }
+}
Index: testsuite/g++.dg/lto/pr63166_0.ii
===================================================================
--- testsuite/g++.dg/lto/pr63166_0.ii	(revision 0)
+++ testsuite/g++.dg/lto/pr63166_0.ii	(revision 0)
@@ -0,0 +1,37 @@
+// { dg-lto-do compile }
+extern "C"
+{
+  extern long unsigned int strlen (__const char *__s);
+}
+class Cstring
+{
+};
+class Foobar_Out
+{
+  virtual void put_to_buf (const char *str, long unsigned int msg_len);
+  void put_to_buf (const char *str)
+  {
+    put_to_buf (str, strlen (str));
+  }
+  Foobar_Out & operator << (const char *str);
+  Foobar_Out & operator << (const Cstring & cstring);
+};
+
+class Foobar_Log:public Foobar_Out
+{
+  Foobar_Log (int channel);
+  virtual void put_to_buf (const char *str, long unsigned int msg_len);
+};
+Foobar_Out & Foobar_Out::operator << (const char *str)
+{
+  put_to_buf (str);
+}
+
+Foobar_Out & Foobar_Out::operator << (const Cstring & cstring)
+{
+  return *this;
+}
+
+Foobar_Log::Foobar_Log (int ch)
+{
+}


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]