1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.
This commit is contained in:
卜部昌平 2020-06-24 16:23:59 +09:00
parent c8dc2bf140
commit de3e931df7
Notes: git 2020-06-29 11:06:32 +09:00
14 changed files with 24 additions and 1 deletions

View file

@ -930,6 +930,7 @@ rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type)
const char *expected = data_type->wrap_struct_name; const char *expected = data_type->wrap_struct_name;
rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected %s)", rb_raise(rb_eTypeError, "wrong argument type %"PRIsVALUE" (expected %s)",
actual, expected); actual, expected);
UNREACHABLE_RETURN(NULL);
} }
/* exception classes */ /* exception classes */

1
file.c
View file

@ -5433,6 +5433,7 @@ rb_f_test(int argc, VALUE *argv, VALUE _)
else { else {
rb_raise(rb_eArgError, "unknown command \"\\x%02X\"", cmd); rb_raise(rb_eArgError, "unknown command \"\\x%02X\"", cmd);
} }
UNREACHABLE_RETURN(Qundef);
} }

2
io.c
View file

@ -4199,6 +4199,7 @@ rb_io_each_codepoint(VALUE io)
invalid: invalid:
rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(enc)); 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: error:
rb_raise(rb_eArgError, "invalid access mode %s", modestr); rb_raise(rb_eArgError, "invalid access mode %s", modestr);
UNREACHABLE_RETURN(Qundef);
} }
int int

View file

@ -4013,6 +4013,7 @@ fix_pow_inverted(VALUE x, VALUE minusb)
{ {
if (x == INT2FIX(0)) { if (x == INT2FIX(0)) {
rb_num_zerodiv(); rb_num_zerodiv();
UNREACHABLE_RETURN(Qundef);
} }
else { else {
VALUE y = rb_int_pow(x, minusb); VALUE y = rb_int_pow(x, minusb);

View file

@ -2574,6 +2574,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod)
wrong_name: wrong_name:
rb_name_err_raise(wrong_constant_name, mod, 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: wrong_name:
rb_name_err_raise(wrong_constant_name, mod, 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: wrong_name:
rb_name_err_raise(wrong_constant_name, mod, 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; return d;
bad: bad:
if (raise) if (raise) {
rb_invalid_str(q, "Float()"); rb_invalid_str(q, "Float()");
UNREACHABLE_RETURN(nan(""));
}
else { else {
if (error) *error = 1; if (error) *error = 1;
return 0.0; return 0.0;

2
proc.c
View file

@ -549,6 +549,7 @@ bind_local_variable_get(VALUE bindval, VALUE sym)
undefined: undefined:
rb_name_err_raise("local variable `%1$s' is not defined for %2$s", rb_name_err_raise("local variable `%1$s' is not defined for %2$s",
bindval, sym); bindval, sym);
UNREACHABLE_RETURN(Qundef);
} }
/* /*
@ -2021,6 +2022,7 @@ rb_obj_singleton_method(VALUE obj, VALUE vid)
/* undef: */ /* undef: */
rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'", rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
obj, vid); obj, vid);
UNREACHABLE_RETURN(Qundef);
} }
/* /*

View file

@ -1900,6 +1900,7 @@ check_exec_redirect_fd(VALUE v, int iskey)
wrong: wrong:
rb_raise(rb_eArgError, "wrong exec redirect"); rb_raise(rb_eArgError, "wrong exec redirect");
UNREACHABLE_RETURN(Qundef);
} }
static VALUE static VALUE

View file

@ -836,6 +836,7 @@ range_each_bignum_endless(VALUE beg)
for (;; beg = rb_big_plus(beg, INT2FIX(1))) { for (;; beg = rb_big_plus(beg, INT2FIX(1))) {
rb_yield(beg); rb_yield(beg);
} }
UNREACHABLE;
} }
RBIMPL_ATTR_NORETURN() RBIMPL_ATTR_NORETURN()
@ -847,6 +848,7 @@ range_each_fixnum_endless(VALUE beg)
} }
range_each_bignum_endless(LONG2NUM(RUBY_FIXNUM_MAX + 1)); range_each_bignum_endless(LONG2NUM(RUBY_FIXNUM_MAX + 1));
UNREACHABLE;
} }
static VALUE static VALUE

View file

@ -274,6 +274,7 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr)
} }
rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'", rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'",
prefix, signame_prefix, vsig); prefix, signame_prefix, vsig);
UNREACHABLE_RETURN(0);
} }
static const char* static const char*

View file

@ -3015,6 +3015,7 @@ rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len,
incompatible: incompatible:
rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s", rb_raise(rb_eEncCompatError, "incompatible character encodings: %s and %s",
rb_enc_name(str_enc), rb_enc_name(ptr_enc)); rb_enc_name(str_enc), rb_enc_name(ptr_enc));
UNREACHABLE_RETURN(Qundef);
} }
VALUE VALUE
@ -9679,6 +9680,7 @@ rb_str_crypt(VALUE str, VALUE salt)
short_salt: short_salt:
rb_raise(rb_eArgError, "salt too short (need >=2 bytes)"); rb_raise(rb_eArgError, "salt too short (need >=2 bytes)");
UNREACHABLE_RETURN(Qundef);
} }

View file

@ -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 " rb_raise(rb_eTypeError, "invalid inspect_tbl pair_list "
"for %+"PRIsVALUE" in %+"PRIsVALUE, "for %+"PRIsVALUE" in %+"PRIsVALUE,
sym, rb_thread_current()); sym, rb_thread_current());
UNREACHABLE_RETURN(Qundef);
} }
/* /*

1
time.c
View file

@ -5434,6 +5434,7 @@ end_submicro: ;
invalid_format: invalid_format:
rb_raise(rb_eTypeError, "marshaled time format differ"); rb_raise(rb_eTypeError, "marshaled time format differ");
UNREACHABLE_RETURN(Qundef);
} }
/* :nodoc: */ /* :nodoc: */

View file

@ -277,6 +277,7 @@ rb_path_to_class(VALUE pathname)
undefined_class: undefined_class:
rb_raise(rb_eArgError, "undefined class/module % "PRIsVALUE, rb_raise(rb_eArgError, "undefined class/module % "PRIsVALUE,
rb_str_subseq(pathname, 0, p-path)); rb_str_subseq(pathname, 0, p-path));
UNREACHABLE_RETURN(Qundef);
} }
VALUE VALUE
@ -3347,6 +3348,7 @@ rb_mod_remove_cvar(VALUE mod, VALUE name)
not_defined: not_defined:
rb_name_err_raise("class variable %1$s not defined for %2$s", rb_name_err_raise("class variable %1$s not defined for %2$s",
mod, name); mod, name);
UNREACHABLE_RETURN(Qundef);
} }
VALUE VALUE

View file

@ -846,6 +846,7 @@ method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missin
return result; return result;
missing: missing:
raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING); raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
UNREACHABLE_RETURN(Qundef);
} }
#ifndef MJIT_HEADER #ifndef MJIT_HEADER