[IFUNC}: Properly handle indirect function return

H.J. Lu hongjiu.lu@intel.com
Mon Jul 6 19:41:00 GMT 2009


Hi,


Indirect function isn't const/pure.  I am checking this patch into
ifunc branch with a testcase.


H.J.
---
Index: testsuite/ChangeLog.ifunc
===================================================================
--- testsuite/ChangeLog.ifunc	(revision 149285)
+++ testsuite/ChangeLog.ifunc	(working copy)
@@ -1,3 +1,7 @@
+2009-07-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* g++.dg/torture/ifunc-26.C: New.
+
 2009-07-05  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* g++.dg/torture/ifunc-16.C: Add function name to scan-assembler.
Index: testsuite/g++.dg/torture/ifunc-26.C
===================================================================
--- testsuite/g++.dg/torture/ifunc-26.C	(revision 0)
+++ testsuite/g++.dg/torture/ifunc-26.C	(revision 0)
@@ -0,0 +1,51 @@
+/* { dg-do compile { target i?86-*-linux* x86_64-*-linux* } } */
+/* { dg-options "-Wall -Wextra" } */
+
+template <class T1, class T2>
+class ifunc
+{
+private:
+  void foo1 (T1);
+  void foo1 (T2);
+
+public:
+  void foo (T1);
+  void foo (T2);
+};
+
+template <class T1, class T2>
+void
+__attribute__ ((ifunc))
+ifunc<T1, T2>::foo (T1)
+{ 
+  return &ifunc<T1, T2>::foo1;
+}
+
+template <class T1, class T2>
+void
+__attribute__ ((ifunc))
+ifunc<T1, T2>::foo (T2)
+{ 
+  return &ifunc<T1, T2>::foo1;
+}
+
+void
+bar (int x)
+{
+  ifunc<int, float> i;
+  i.foo (x);
+}
+
+void
+bar (float x)
+{
+  ifunc<int, float> i;
+  i.foo (x);
+}
+
+/* { dg-final { scan-assembler-not ".type\[ 	\]\+_ZN5ifuncIifE3fooEf, .function" } } */
+/* { dg-final { scan-assembler-not ".type\[ 	\]\+_ZN5ifuncIifE3fooEi, .function" } } */
+/* { dg-final { scan-assembler "(call|jmp)\[ 	\]\+_ZN5ifuncIifE3fooEi" } } */
+/* { dg-final { scan-assembler "(call|jmp)\[ 	\]\+_ZN5ifuncIifE3fooEf" } } */
+/* { dg-final { scan-assembler ".type\[ 	\]\+_ZN5ifuncIifE3fooEi, .gnu_indirect_function" } } */
+/* { dg-final { scan-assembler ".type\[ 	\]\+_ZN5ifuncIifE3fooEf, .gnu_indirect_function" } } */
Index: ipa-pure-const.c
===================================================================
--- ipa-pure-const.c	(revision 149285)
+++ ipa-pure-const.c	(working copy)
@@ -471,6 +471,14 @@ check_stmt (gimple_stmt_iterator *gsip, 
           local->looping = true;
 	}
       return;
+    case GIMPLE_RETURN:
+      if (DECL_IS_IFUNC (current_function_decl))
+	{
+	  if (dump_file)
+	    fprintf (dump_file, "    Indirect function is not const/pure");
+	  local->pure_const_state = IPA_NEITHER;
+	}
+      break;
     default:
       break;
     }
Index: ChangeLog.ifunc
===================================================================
--- ChangeLog.ifunc	(revision 149285)
+++ ChangeLog.ifunc	(working copy)
@@ -1,3 +1,8 @@
+2009-07-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+	* ipa-pure-const.c (check_stmt): Properly handle indirect function
+	return.
+
 2009-06-28  H.J. Lu  <hongjiu.lu@intel.com>
 
 	* doc/extend.texi: Update ifunc attribute document.



More information about the Gcc-patches mailing list