Patrick, I see what you mean. Your patch looks sensible, but Richard will have to review.

Richard, here is a resubmission of Patrick's patch, as the original patch had the wrong description, and one of the testcases no longer applied. Could you please review?

The problem here is that a __comp_ctor is a weak alias. When we look at the tm_ipa_cg_data for the alias, it is the original/parent that actually has such information. Eventually we call _ITM_getTMCloneOrIrrevocable for the alias, when we should be calling the constructor directly.

This patch looks at the parent's tm_ipa_cg_data.

I don't understand why we don't apply similar logic to every other get_cg_data call, but I will let you two sort this out, and I will apply if/when approved.

Thanks guys.

p.s. The original submission is here (though I have restated everything above: http://gcc.gnu.org/ml/gcc-patches/2011-12/msg00225.html).
        * trans-mem.c (ipa_tm_scan_calls_block): Use parent node of
        aliases.
        (ipa_tm_decrement_clone_counts): Likewise.

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,22 @@
+/* { 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 182290)
+++ trans-mem.c (working copy)
@@ -3552,6 +3552,9 @@ ipa_tm_scan_calls_block (cgraph_node_que
 
              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
@@ -3839,13 +3842,20 @@ ipa_tm_decrement_clone_counts (basic_blo
            {
              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);
+
+             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);

Reply via email to