Hi,
PR51347 shows up a problem due to the TM IPA rework.
tree_function_versioning segfault because the cfg of old_decl (alias) is
NULL.
Indeed, an alias can get called but tm cg data are in the parent of the
alias.
Bootstrapped and regtested.
Thanks,
Patrick.
ChangeLog
2011-12-02 Patrick Marlier <patrick.marl...@gmail.com>
PR c++/51347
* trans-mem.c (ipa_tm_scan_calls_block): Use parent node of
aliases.
(ipa_tm_decrement_clone_counts): Likewise.
testsuite/ChangeLog
2011-12-02 Patrick Marlier <patrick.marl...@gmail.com>
PR c++/51347
* g++.dg/tm/pr51347.C: New test.
* 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: testsuite/g++.dg/tm/pr51347.C
===================================================================
--- testsuite/g++.dg/tm/pr51347.C (revision 0)
+++ testsuite/g++.dg/tm/pr51347.C (revision 0)
@@ -0,0 +1,37 @@
+// { dg-do compile }
+// { dg-options "-fgnu-tm -O1" }
+
+template<class ValueType>
+class BugContainer {
+public:
+ BugContainer() {
+ elem = new ValueType();
+ }
+
+ virtual ~BugContainer() {
+ delete elem;
+ }
+
+ void bug() {
+ delete elem;
+ elem = new ValueType();
+ }
+
+protected:
+ ValueType *elem;
+};
+
+struct Info {
+ BugContainer<int> vec;
+};
+
+int main(int argc, char *argv[])
+{
+ BugContainer<Info> bugs;
+
+ __transaction_atomic {
+ bugs.bug();
+ }
+
+ return 0;
+}
Index: trans-mem.c
===================================================================
--- trans-mem.c (revision 181888)
+++ 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
@@ -3849,13 +3853,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);
@@ -4179,7 +4190,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