In the PR testcase, a call to __builtin_prefetch is done. When this
function call comes into expand_call_tm, there is no cgraph_node
associated for this builtin and thus node->local fails.
trans-mem.c (expand_call_tm):
...
node = cgraph_get_node (fn_decl);
if (node->local.tm_may_enter_irr)
transaction_subcode_ior (region, GTMA_MAY_ENTER_IRREVOCABLE);
...
The attached patch adds a check for non-NULL node. I have added the
testcase but I don't know if it is relevant.
Currently bootstrapping on i686-pc-linux-gnu. Tested on i686-pc-linux-gnu.
OK?
(I am almost sure I already proposed this modification few time ago but
it have been lost somewhere.)
--
Patrick.
2012-01-31 Patrick Marlier <patrick.marl...@gmail.com>
PR middle-end/52047
* trans-mem.c (expand_call_tm): Dereference node only if
non-NULL.
Index: trans-mem.c
===================================================================
--- trans-mem.c (revision 183736)
+++ trans-mem.c (working copy)
@@ -1,5 +1,5 @@
/* Passes for transactional memory support.
- Copyright (C) 2008, 2009, 2010, 2011 Free Software Foundation, Inc.
+ Copyright (C) 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
This file is part of GCC.
@@ -2267,7 +2267,7 @@ expand_call_tm (struct tm_region *region,
}
node = cgraph_get_node (fn_decl);
- if (node->local.tm_may_enter_irr)
+ if (node && node->local.tm_may_enter_irr)
transaction_subcode_ior (region, GTMA_MAY_ENTER_IRREVOCABLE);
if (is_tm_abort (fn_decl))
Index: testsuite/gcc.dg/tm/pr52047.c
===================================================================
--- testsuite/gcc.dg/tm/pr52047.c (revision 0)
+++ testsuite/gcc.dg/tm/pr52047.c (revision 0)
@@ -0,0 +1,26 @@
+/* { dg-do compile } */
+/* { dg-options "-O -fgnu-tm -fprefetch-loop-arrays -w" } */
+
+int test2 (int x[])
+{
+ return x[12];
+}
+
+int test1 (void)
+{
+ int x[1000], i;
+ for (i = 0; i < 1000; i++)
+ x[i] = i;
+ return test2 (x);
+}
+
+int
+main ()
+{
+ __transaction_atomic
+ {
+ if (test1 ())
+ __transaction_cancel;
+ }
+ return 0;
+}