Hi,

(Initially from http://gcc.gnu.org/ml/gcc-patches/2011-12/msg00225.html)
PR51516 shows up a problem due to the TM IPA rework.
Indeed, an alias can get called but tm cg data is in the parent of the alias. The fix consists to set and use information from the parent and not the alias itself.

Bootstrapped and regtested on x86_64-unknown-linux-gnu.

Richard, ok?
(Don't have an account yet, thanks in advance for the committer)

Thanks.
--
Patrick Marlier.
ChangeLog
2012-01-05  Patrick Marlier  <patrick.marl...@gmail.com>

        PR middle-end/51516
        * trans-mem.c (ipa_tm_scan_calls_block): Use parent node of aliases.
        (ipa_tm_decrement_clone_counts): Likewise.

testsuite/ChangeLog
2012-01-05  Patrick Marlier  <patrick.marl...@gmail.com>

        PR middle-end/51516
        * g++.dg/tm/ctor-used.C: New test.
Index: testsuite/g++.dg/tm/ctor-used.C
===================================================================
--- testsuite/g++.dg/tm/ctor-used.C	(revision 0)
+++ testsuite/g++.dg/tm/ctor-used.C	(revision 0)
@@ -0,0 +1,21 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -fdump-tree-optimized" } */
+
+struct C {
+  long l;
+  C():l(0) {}
+};
+
+int main()
+{
+  C* alloc;
+  __transaction_atomic {
+    alloc = new C;
+  }
+  alloc->l = 2;
+
+  return 0;
+}
+/* { dg-final { scan-assembler-not "_ITM_getTMCloneOrIrrevocable" } } */
+/* { dg-final { scan-tree-dump-times ";; Function C::C" 1 "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
Index: trans-mem.c
===================================================================
--- trans-mem.c	(revision 182899)
+++ trans-mem.c	(working copy)
@@ -3566,6 +3566,10 @@ ipa_tm_scan_calls_block (cgraph_node_queue *callee
 
 	      node = cgraph_get_node (fndecl);
 	      gcc_assert (node != NULL);
+
+	      if (node->alias)
+		node = cgraph_get_node (node->thunk.alias);
+
 	      d = get_cg_data (node);
 
 	      pcallers = (for_clone ? &d->tm_callers_clone
@@ -3853,13 +3857,20 @@ ipa_tm_decrement_clone_counts (basic_block bb, boo
 	    {
 	      struct tm_ipa_cg_data *d;
 	      unsigned *pcallers;
+	      struct cgraph_node *node;
 
 	      if (is_tm_ending_fndecl (fndecl))
 		continue;
 	      if (find_tm_replacement_function (fndecl))
 		continue;
 
-	      d = get_cg_data (cgraph_get_node (fndecl));
+	      node = cgraph_get_node (fndecl);
+	      gcc_assert (node != NULL);
+
+	      if (node->alias)
+		node = cgraph_get_node (node->thunk.alias);
+
+	      d = get_cg_data (node);
 	      pcallers = (for_clone ? &d->tm_callers_clone
 			  : &d->tm_callers_normal);
 
@@ -4188,7 +4199,7 @@ struct create_version_alias_info
   tree new_decl;
 };
 
-/* A subrontine of ipa_tm_create_version, called via
+/* A subroutine of ipa_tm_create_version, called via
    cgraph_for_node_and_aliases.  Create new tm clones for each of
    the existing aliases.  */
 static bool

Reply via email to