[trans-mem] fix gettmclone buglet

Aldy Hernandez aldyh@redhat.com
Tue Oct 13 21:39:00 GMT 2009


Hi folks.

As discussed on off-list.

tm_gettmclone*() returns a void *, but we use the result as a function
pointer.  This causes PRE to ice.  Fixed by inserting the appropriate
cast before dereferencing as a function pointer.

OK for branch?

p.s. Thanks guys.

	* trans-mem.c (ipa_tm_insert_gettmclone_call): Cast return value
	from gettmclone.

Index: testsuite/gcc.dg/tm/20091013.c
===================================================================
--- testsuite/gcc.dg/tm/20091013.c	(revision 0)
+++ testsuite/gcc.dg/tm/20091013.c	(revision 0)
@@ -0,0 +1,13 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -O2" } */
+
+extern long ringo(long int);
+int g,i;
+
+f()
+{
+  __tm_atomic {
+    for (i=0; i < 10; ++i)
+      ringo(g);  
+  }
+}
Index: trans-mem.c
===================================================================
--- trans-mem.c	(revision 152675)
+++ trans-mem.c	(working copy)
@@ -2803,8 +2803,8 @@ ipa_tm_insert_gettmclone_call (struct cg
 			       struct tm_region *region,
 			       gimple_stmt_iterator *gsi, gimple stmt)
 {
-  tree gettm_fn, ret, old_fn;
-  gimple g;
+  tree gettm_fn, ret, old_fn, callfn;
+  gimple g, g2;
   bool safe;
 
   old_fn = gimple_call_fn (stmt);
@@ -2812,7 +2812,7 @@ ipa_tm_insert_gettmclone_call (struct cg
   safe = is_tm_safe (TREE_TYPE (old_fn));
   gettm_fn = built_in_decls[safe ? BUILT_IN_TM_GETTMCLONE_SAFE
 			    : BUILT_IN_TM_GETTMCLONE_IRR];
-  ret = create_tmp_var (TREE_TYPE (old_fn), NULL);
+  ret = create_tmp_var (ptr_type_node, NULL);
   add_referenced_var (ret);
 
   if (!safe)
@@ -2842,6 +2842,16 @@ ipa_tm_insert_gettmclone_call (struct cg
 
   cgraph_create_edge (node, cgraph_node (gettm_fn), g, 0, 0, 0);
 
+  /* Cast return value from tm_gettmclone* into appropriate function
+     pointer.  */
+  callfn = create_tmp_var (TREE_TYPE (old_fn), NULL);
+  add_referenced_var (callfn);
+  g2 = gimple_build_assign (callfn,
+			    fold_build1 (NOP_EXPR, TREE_TYPE (callfn), ret));
+  callfn = make_ssa_name (callfn, g2);
+  gimple_assign_set_lhs (g2, callfn);
+  gsi_insert_before (gsi, g2, GSI_SAME_STMT);
+
   /* ??? This is a hack to preserve the NOTHROW bit on the call,
      which we would have derived from the decl.  Failure to save
      this bit means we might have to split the basic block.  */
@@ -2854,7 +2864,7 @@ ipa_tm_insert_gettmclone_call (struct cg
      and thus requiring extra EH edges.  */
   gimple_call_set_noinline_p (stmt);
 
-  gimple_call_set_fn (stmt, ret);
+  gimple_call_set_fn (stmt, callfn);
   update_stmt (stmt);
 
   return safe;



More information about the Gcc-patches mailing list