From: Ivan Maidanski Date: Mon, 23 Jan 2012 04:03:10 +0000 (+0400) Subject: Turn some unreachable return statements into reachable (to suppress X-Git-Tag: gc7_3alpha2~200 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f23154f0a8f02b9519632e4341635f7c5e866da0;p=gc Turn some unreachable return statements into reachable (to suppress compiler warning) * dbg_mlc.c (GC_generate_random_heap_address): Change function algorithm structure to have reachable return statement at function end. * mark.c (GC_mark_some): Likewise. * os_dep.c (GC_mprotect_thread): Place a dummy return statement (which uses function "arg"); remove unreachable return statement. * win32_threads.c (GC_DllMain): Place GC_ASSERT before GC_get_stack_base. --- diff --git a/dbg_mlc.c b/dbg_mlc.c index 1eb25eb5..c6b76fe5 100644 --- a/dbg_mlc.c +++ b/dbg_mlc.c @@ -142,7 +142,9 @@ GC_API void * GC_CALL GC_generate_random_heap_address(void) { size_t i; + size_t size; word heap_offset = RANDOM(); + if (GC_heapsize > RAND_MAX) { heap_offset *= RAND_MAX; heap_offset += RANDOM(); @@ -151,17 +153,18 @@ /* This doesn't yield a uniform distribution, especially if */ /* e.g. RAND_MAX = 1.5* GC_heapsize. But for typical cases, */ /* it's not too bad. */ - for (i = 0; i < GC_n_heap_sects; ++ i) { - size_t size = GC_heap_sects[i].hs_bytes; + for (i = 0;; ++i) { + if (i >= GC_n_heap_sects) + ABORT("GC_generate_random_heap_address: size inconsistency"); + + size = GC_heap_sects[i].hs_bytes; if (heap_offset < size) { - return GC_heap_sects[i].hs_start + heap_offset; + break; } else { heap_offset -= size; } } - ABORT("GC_generate_random_heap_address: size inconsistency"); - /*NOTREACHED*/ - return 0; + return GC_heap_sects[i].hs_start + heap_offset; } /* Generate a random address inside a valid marked heap object. */ diff --git a/mark.c b/mark.c index 858cf1fe..4d70b596 100644 --- a/mark.c +++ b/mark.c @@ -325,7 +325,7 @@ static void alloc_mark_stack(size_t); { switch(GC_mark_state) { case MS_NONE: - return(FALSE); + break; case MS_PUSH_RESCUERS: if (GC_mark_stack_top @@ -335,7 +335,7 @@ static void alloc_mark_stack(size_t); /* in the future. */ GC_mark_stack_too_small = TRUE; MARK_FROM_MARK_STACK(); - return(FALSE); + break; } else { scan_ptr = GC_push_next_marked_dirty(scan_ptr); if (scan_ptr == 0) { @@ -350,7 +350,7 @@ static void alloc_mark_stack(size_t); } } } - return(FALSE); + break; case MS_PUSH_UNCOLLECTABLE: if (GC_mark_stack_top @@ -361,7 +361,7 @@ static void alloc_mark_stack(size_t); if (GC_parallel) GC_mark_stack_too_small = TRUE; # endif MARK_FROM_MARK_STACK(); - return(FALSE); + break; } else { scan_ptr = GC_push_next_marked_uncollectable(scan_ptr); if (scan_ptr == 0) { @@ -372,7 +372,7 @@ static void alloc_mark_stack(size_t); } } } - return(FALSE); + break; case MS_ROOTS_PUSHED: # ifdef PARALLEL_MARK @@ -394,14 +394,13 @@ static void alloc_mark_stack(size_t); if (GC_mark_state == MS_ROOTS_PUSHED) { GC_mark_state = MS_NONE; return(TRUE); - } else { - return(FALSE); } + break; } # endif if (GC_mark_stack_top >= GC_mark_stack) { MARK_FROM_MARK_STACK(); - return(FALSE); + break; } else { GC_mark_state = MS_NONE; if (GC_mark_stack_too_small) { @@ -414,11 +413,11 @@ static void alloc_mark_stack(size_t); case MS_PARTIALLY_INVALID: if (!GC_objects_are_marked) { GC_mark_state = MS_PUSH_UNCOLLECTABLE; - return(FALSE); + break; } if (GC_mark_stack_top >= GC_mark_stack) { MARK_FROM_MARK_STACK(); - return(FALSE); + break; } if (scan_ptr == 0 && GC_mark_state == MS_INVALID) { /* About to start a heap scan for marked objects. */ @@ -436,11 +435,12 @@ static void alloc_mark_stack(size_t); GC_mark_state = MS_ROOTS_PUSHED; } } - return(FALSE); + break; + default: ABORT("GC_mark_some: bad state"); - return(FALSE); } + return(FALSE); } #ifdef WRAP_MARK_SOME diff --git a/os_dep.c b/os_dep.c index 8bc10991..fbd9b81f 100644 --- a/os_dep.c +++ b/os_dep.c @@ -3997,6 +3997,8 @@ STATIC void *GC_mprotect_thread(void *arg) } msg; mach_msg_id_t id; + if ((word)arg == (word)-1) return 0; /* to make compiler happy */ + # if defined(THREADS) && !defined(GC_NO_THREADS_DISCOVERY) GC_darwin_register_mach_handler_thread(mach_thread_self()); # endif @@ -4062,8 +4064,6 @@ STATIC void *GC_mprotect_thread(void *arg) } } /* switch */ } /* for(;;) */ - /* NOT REACHED */ - return NULL; } /* All this SIGBUS code shouldn't be necessary. All protection faults should diff --git a/win32_threads.c b/win32_threads.c index 7cc0dcfa..66ae019e 100644 --- a/win32_threads.c +++ b/win32_threads.c @@ -2616,16 +2616,17 @@ GC_INNER void GC_thr_init(void) /* This may run with the collector uninitialized. */ thread_id = GetCurrentThreadId(); if (parallel_initialized && GC_main_thread != thread_id) { - /* Don't lock here. */ -# ifdef GC_ASSERTIONS - sb_result = -# endif - GC_get_stack_base(&sb); - GC_ASSERT(sb_result == GC_SUCCESS); # if defined(THREAD_LOCAL_ALLOC) || defined(PARALLEL_MARK) ABORT("Cannot initialize thread local cache from DllMain"); +# else + /* Don't lock here. */ +# ifdef GC_ASSERTIONS + sb_result = +# endif + GC_get_stack_base(&sb); + GC_ASSERT(sb_result == GC_SUCCESS); + GC_register_my_thread_inner(&sb, thread_id); # endif - GC_register_my_thread_inner(&sb, thread_id); } /* o.w. we already did it during GC_thr_init, called by GC_init */ break;