[trans-mem] random segfault
Aldy Hernandez
aldyh@redhat.com
Tue Jun 15 15:17:00 GMT 2010
> Hi Aldy,
>
> I was trying to compile almost the same code and gcc is going into a
> stack overflow (infinite call).
>
> Here the testcase (gcc -fgnu-tm -Wall -O1 -o common.o -c common.c):
> __attribute__((transaction_safe))
> void Info_RemoveKey (char *s)
> {
> char *o = 0;
> while (1)
> {
> s++;
> while (*s)
> {
> if (!*s)
> return;
> *o++ = *s++;
> }
> *o = 0;
> }
> }
thread_private_new_memory() is recursing on itself when the web of PHI
nodes has a mutual dependency (albeit with SSA variables originating
from different basic blocks).
Fixed by making sure we're not recursing on the same variable.
OK for branch?
* trans-mem.c (thread_private_new_memory): Avoid infinite recursion.
Index: testsuite/gcc.dg/tm/20100615-2.c
===================================================================
--- testsuite/gcc.dg/tm/20100615-2.c (revision 0)
+++ testsuite/gcc.dg/tm/20100615-2.c (revision 0)
@@ -0,0 +1,19 @@
+/* { dg-do compile } */
+/* { dg-options "-fgnu-tm -O" } */
+
+__attribute__((transaction_safe))
+void Info_RemoveKey (char *s)
+{
+ char *o = 0;
+ while (1)
+ {
+ s++;
+ while (*s)
+ {
+ if (!*s)
+ return;
+ *o++ = *s++;
+ }
+ *o = 0;
+ }
+}
Index: trans-mem.c
===================================================================
--- trans-mem.c (revision 160765)
+++ trans-mem.c (working copy)
@@ -1331,6 +1331,10 @@ thread_private_new_memory (basic_block e
if (phi_result == op)
continue;
+ /* Ignore self-recursion in calculation. */
+ if (val == op)
+ continue;
+
mem = thread_private_new_memory (entry_block, op);
if (mem == mem_non_local)
{
More information about the Gcc-patches
mailing list