From e18259424ea6f1baafacab442d57c05d51c2548b Mon Sep 17 00:00:00 2001 From: nobu Date: Fri, 4 Apr 2014 08:34:12 +0000 Subject: eval_intern.h: VAR_INITIALIZED * eval_intern.h (VAR_INITIALIZED): macro to suppress maybe-uninitialized warnings by gcc 4.7 and 4.8. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45516 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- cont.c | 4 ++-- eval_intern.h | 10 +++++++++- eval_jump.c | 1 + proc.c | 1 + vm_eval.c | 2 ++ 5 files changed, 15 insertions(+), 3 deletions(-) diff --git a/cont.c b/cont.c index 3b05f995d4..670aef0ec2 100644 --- a/cont.c +++ b/cont.c @@ -510,6 +510,7 @@ cont_capture(volatile int *stat) if (ruby_setjmp(cont->jmpbuf)) { volatile VALUE value; + VAR_INITIALIZED(cont); value = cont->value; if (cont->argc == -1) rb_exc_raise(value); cont->value = Qnil; @@ -1271,15 +1272,14 @@ rb_fiber_start(void) { rb_thread_t *th = GET_THREAD(); rb_fiber_t *fib; - rb_context_t *cont; rb_proc_t *proc; int state; GetFiberPtr(th->fiber, fib); - cont = &fib->cont; TH_PUSH_TAG(th); if ((state = EXEC_TAG()) == 0) { + rb_context_t *cont = &VAR_FROM_MEMORY(fib)->cont; int argc; const VALUE *argv, args = cont->value; GetProcPtr(cont->saved_thread.first_proc, proc); diff --git a/eval_intern.h b/eval_intern.h index f81f922269..f19c252918 100644 --- a/eval_intern.h +++ b/eval_intern.h @@ -128,6 +128,14 @@ extern int select_large_fdset(int, fd_set *, fd_set *, fd_set *, struct timeval #define PUSH_TAG() TH_PUSH_TAG(GET_THREAD()) #define POP_TAG() TH_POP_TAG() +#if defined __GNUC__ && __GNUC__ == 4 && (__GNUC_MINOR__ == 7 || __GNUC_MINOR__ == 8) +# define VAR_FROM_MEMORY(var) __extension__(*(__typeof__(var) volatile *)&(var)) +# define VAR_INITIALIZED(var) ((var) = VAR_FROM_MEMORY(var)) +#else +# define VAR_FROM_MEMORY(var) (var) +# define VAR_INITIALIZED(var) ((void)&(var)) +#endif + /* clear th->state, and return the value */ static inline int rb_threadptr_tag_state(rb_thread_t *th) @@ -150,7 +158,7 @@ rb_threadptr_tag_jump(rb_thread_t *th, int st) [ISO/IEC 9899:1999] 7.13.1.1 */ #define TH_EXEC_TAG() \ - (ruby_setjmp(_tag.buf) ? rb_threadptr_tag_state(_th) : (TH_REPUSH_TAG(), 0)) + (ruby_setjmp(_tag.buf) ? rb_threadptr_tag_state(VAR_FROM_MEMORY(_th)) : (TH_REPUSH_TAG(), 0)) #define EXEC_TAG() \ TH_EXEC_TAG() diff --git a/eval_jump.c b/eval_jump.c index 30094e9176..5443ed224e 100644 --- a/eval_jump.c +++ b/eval_jump.c @@ -123,6 +123,7 @@ rb_exec_end_proc(void) exec_end_procs_chain(&end_procs); } else { + VAR_INITIALIZED(th); TH_TMPPOP_TAG(); error_handle(status); if (!NIL_P(th->errinfo)) errinfo = th->errinfo; diff --git a/proc.c b/proc.c index db4c327b7a..5355ab57ea 100644 --- a/proc.c +++ b/proc.c @@ -1899,6 +1899,7 @@ rb_method_call_with_block(int argc, VALUE *argv, VALUE method, VALUE pass_procva } th->passed_block = block; + VAR_INITIALIZED(data); result = rb_vm_call(th, data->recv, data->id, argc, argv, data->me, data->defined_class); } POP_TAG(); diff --git a/vm_eval.c b/vm_eval.c index 7b11e38d84..23e0b772b2 100644 --- a/vm_eval.c +++ b/vm_eval.c @@ -1060,6 +1060,8 @@ rb_iterate(VALUE (* it_proc) (VALUE), VALUE data1, TH_PUSH_TAG(th); state = TH_EXEC_TAG(); if (state == 0) { + VAR_INITIALIZED(th); + VAR_INITIALIZED(node); iter_retry: { rb_block_t *blockptr; -- cgit v1.2.3