Skip to content

Commit

Permalink
Turn some unreachable return statements into reachable (to suppress
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ivmai committed Jan 23, 2012
1 parent 88e0291 commit f23154f
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 27 deletions.
15 changes: 9 additions & 6 deletions dbg_mlc.c
Expand Up @@ -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();
Expand All @@ -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. */
Expand Down
24 changes: 12 additions & 12 deletions mark.c
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -350,7 +350,7 @@ static void alloc_mark_stack(size_t);
}
}
}
return(FALSE);
break;

case MS_PUSH_UNCOLLECTABLE:
if (GC_mark_stack_top
Expand All @@ -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) {
Expand All @@ -372,7 +372,7 @@ static void alloc_mark_stack(size_t);
}
}
}
return(FALSE);
break;

case MS_ROOTS_PUSHED:
# ifdef PARALLEL_MARK
Expand All @@ -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) {
Expand All @@ -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. */
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions os_dep.c
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
15 changes: 8 additions & 7 deletions win32_threads.c
Expand Up @@ -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;

Expand Down

0 comments on commit f23154f

Please sign in to comment.