diff options
author | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-24 16:23:59 +0900 |
---|---|---|
committer | 卜部昌平 <shyouhei@ruby-lang.org> | 2020-06-29 11:05:41 +0900 |
commit | de3e931df7abdc3ee22dbb7543e86af6d00ee899 (patch) | |
tree | 63f8471b59282d2ca5e7af0282f34d9cfef14ee1 | |
parent | c8dc2bf1401fc01d35a4a7587ed224f1f2fe29e6 (diff) |
add UNREACHABLE_RETURN
Not every compilers understand that rb_raise does not return. When a
function does not end with a return statement, such compilers can issue
warnings. We would better tell them about reachabilities.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/3247
-rw-r--r-- | error.c | 1 | ||||
-rw-r--r-- | file.c | 1 | ||||
-rw-r--r-- | io.c | 2 | ||||
-rw-r--r-- | numeric.c | 1 | ||||
-rw-r--r-- | object.c | 7 | ||||
-rw-r--r-- | proc.c | 2 | ||||
-rw-r--r-- | process.c | 1 | ||||
-rw-r--r-- | range.c | 2 | ||||
-rw-r--r-- | signal.c | 1 | ||||
-rw-r--r-- | string.c | 2 | ||||
-rw-r--r-- | thread.c | 1 | ||||
-rw-r--r-- | time.c | 1 | ||||
-rw-r--r-- | variable.c | 2 | ||||
-rw-r--r-- | vm_eval.c | 1 |
14 files changed, 24 insertions, 1 deletions
@@ -930,6 +930,7 @@ rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type) const char *expected = data_type->wrap_struct_name; rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected %s)", actual, expected); + UNREACHABLE_RETURN(NULL); } /* exception classes */ @@ -5433,6 +5433,7 @@ rb_f_test(int argc, VALUE *argv, VALUE _) else { rb_raise(rb_eArgError, "unknown command \"\\x%02X\"", cmd); } + UNREACHABLE_RETURN(Qundef); } @@ -4199,6 +4199,7 @@ rb_io_each_codepoint(VALUE io) invalid: rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc)); + UNREACHABLE_RETURN(Qundef); } /* @@ -5578,6 +5579,7 @@ rb_io_modestr_fmode(const char *modestr) error: rb_raise(rb_eArgError, "invalid access mode %s", modestr); + UNREACHABLE_RETURN(Qundef); } int @@ -4013,6 +4013,7 @@ fix_pow_inverted(VALUE x, VALUE minusb) { if (x == INT2FIX(0)) { rb_num_zerodiv(); + UNREACHABLE_RETURN(Qundef); } else { VALUE y = rb_int_pow(x, minusb); @@ -2574,6 +2574,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) wrong_name: rb_name_err_raise(wrong_constant_name, mod, name); + UNREACHABLE_RETURN(Qundef); } /* @@ -2752,6 +2753,7 @@ rb_mod_const_defined(int argc, VALUE *argv, VALUE mod) wrong_name: rb_name_err_raise(wrong_constant_name, mod, name); + UNREACHABLE_RETURN(Qundef); } /* @@ -2904,6 +2906,7 @@ rb_mod_const_source_location(int argc, VALUE *argv, VALUE mod) wrong_name: rb_name_err_raise(wrong_constant_name, mod, name); + UNREACHABLE_RETURN(Qundef); } /* @@ -3607,8 +3610,10 @@ rb_cstr_to_dbl_raise(const char *p, int badcheck, int raise, int *error) return d; bad: - if (raise) + if (raise) { rb_invalid_str(q, "Float()"); + UNREACHABLE_RETURN(nan("")); + } else { if (error) *error = 1; return 0.0; @@ -549,6 +549,7 @@ bind_local_variable_get(VALUE bindval, VALUE sym) undefined: rb_name_err_raise("local variable `%1$s' is not defined for %2$s", bindval, sym); + UNREACHABLE_RETURN(Qundef); } /* @@ -2021,6 +2022,7 @@ rb_obj_singleton_method(VALUE obj, VALUE vid) /* undef: */ rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'", obj, vid); + UNREACHABLE_RETURN(Qundef); } /* @@ -1900,6 +1900,7 @@ check_exec_redirect_fd(VALUE v, int iskey) wrong: rb_raise(rb_eArgError, "wrong exec redirect"); + UNREACHABLE_RETURN(Qundef); } static VALUE @@ -836,6 +836,7 @@ range_each_bignum_endless(VALUE beg) for (;; beg = rb_big_plus(beg, INT2FIX(1))) { rb_yield(beg); } + UNREACHABLE; } RBIMPL_ATTR_NORETURN() @@ -847,6 +848,7 @@ range_each_fixnum_endless(VALUE beg) } range_each_bignum_endless(LONG2NUM(RUBY_FIXNUM_MAX + 1)); + UNREACHABLE; } static VALUE @@ -274,6 +274,7 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr) } rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'", prefix, signame_prefix, vsig); + UNREACHABLE_RETURN(0); } static const char* @@ -3015,6 +3015,7 @@ rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len, incompatible: rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s", rb_enc_name(str_enc), rb_enc_name(ptr_enc)); + UNREACHABLE_RETURN(Qundef); } VALUE @@ -9679,6 +9680,7 @@ rb_str_crypt(VALUE str, VALUE salt) short_salt: rb_raise(rb_eArgError, "salt too short (need >=2 bytes)"); + UNREACHABLE_RETURN(Qundef); } @@ -5175,6 +5175,7 @@ exec_recursive(VALUE (*func) (VALUE, VALUE, int), VALUE obj, VALUE pairid, VALUE rb_raise(rb_eTypeError, "invalid inspect_tbl pair_list " "for %+"PRIsVALUE" in %+"PRIsVALUE, sym, rb_thread_current()); + UNREACHABLE_RETURN(Qundef); } /* @@ -5434,6 +5434,7 @@ end_submicro: ; invalid_format: rb_raise(rb_eTypeError, "marshaled time format differ"); + UNREACHABLE_RETURN(Qundef); } /* :nodoc: */ diff --git a/variable.c b/variable.c index 362ccddc13..4d62361fd0 100644 --- a/variable.c +++ b/variable.c @@ -277,6 +277,7 @@ rb_path_to_class(VALUE pathname) undefined_class: rb_raise(rb_eArgError, "undefined class/module % "PRIsVALUE, rb_str_subseq(pathname, 0, p-path)); + UNREACHABLE_RETURN(Qundef); } VALUE @@ -3347,6 +3348,7 @@ rb_mod_remove_cvar(VALUE mod, VALUE name) not_defined: rb_name_err_raise("class variable %1$s not defined for %2$s", mod, name); + UNREACHABLE_RETURN(Qundef); } VALUE @@ -846,6 +846,7 @@ method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missin return result; missing: raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING); + UNREACHABLE_RETURN(Qundef); } #ifndef MJIT_HEADER |