]> granicus.if.org Git - gc/commitdiff
Fix GC_call_with_stack_base to prevent its tail-call optimization
authorIvan Maidanski <ivmai@mail.ru>
Wed, 1 Aug 2012 19:12:22 +0000 (23:12 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Wed, 1 Aug 2012 19:12:22 +0000 (23:12 +0400)
* misc.c (GC_call_with_stack_base): Call GC_noop1 after fn()
invocation to prevent a tail-call optimization.

misc.c

diff --git a/misc.c b/misc.c
index b98e419680ad6273fda7ff0f828a81379fa09d74..2fb67b7214e1499164d770a909cd8d3813dd8ccb 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -1640,6 +1640,7 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func fn, void *arg)
 {
     volatile int dummy;
     struct GC_stack_base base;
+    void *result;
 
     base.mem_base = (void *)&dummy;
 #   ifdef IA64
@@ -1647,7 +1648,11 @@ GC_API void * GC_CALL GC_call_with_stack_base(GC_stack_base_func fn, void *arg)
       /* Unnecessarily flushes register stack,          */
       /* but that probably doesn't hurt.                */
 #   endif
-    return fn(&base, arg);
+    result = fn(&base, arg);
+    /* Strongly discourage the compiler from treating the above */
+    /* as a tail call.                                          */
+    GC_noop1((word)(&base));
+    return result;
 }
 
 #ifndef THREADS