Fix GC_clear_stack by declaring 'dummy' local array as volatile
authorIvan Maidanski <ivmai@mail.ru>
Tue, 23 Oct 2012 03:45:51 +0000 (07:45 +0400)
committerIvan Maidanski <ivmai@mail.ru>
Tue, 23 Oct 2012 10:47:29 +0000 (14:47 +0400)
* misc.c (GC_clear_stack): Declare "dummy" local array as volatile to
prevent optimizing it out by compiler; add cast of "dummy" to void*
(to un-volatile the pointer) in BZERO call (only if THREADS).

misc.c

diff --git a/misc.c b/misc.c
index c886d71..196ec7e 100644 (file)
--- a/misc.c
+++ b/misc.c
@@ -321,7 +321,7 @@ GC_API void * GC_CALL GC_clear_stack(void *arg)
 {
     ptr_t sp = GC_approx_sp();  /* Hotter than actual sp */
 #   ifdef THREADS
-        word dummy[SMALL_CLEAR_SIZE];
+        word volatile dummy[SMALL_CLEAR_SIZE];
         static unsigned random_no = 0;
                                  /* Should be more random than it is ... */
                                  /* Used to occasionally clear a bigger  */
@@ -353,7 +353,7 @@ GC_API void * GC_CALL GC_clear_stack(void *arg)
                         /* implementations of GC_clear_stack_inner.     */
         return GC_clear_stack_inner(arg, limit);
     } else {
-        BZERO(dummy, SMALL_CLEAR_SIZE*sizeof(word));
+        BZERO((void *)dummy, SMALL_CLEAR_SIZE*sizeof(word));
         return arg;
     }
 # else