[前][次][番号順一覧][スレッド一覧]

ruby-changes:62025

From: =E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3 <ko1@a...>
Date: Mon, 29 Jun 2020 11:07:52 +0900 (JST)
Subject: [ruby-changes:62025] de3e931df7 (master): add UNREACHABLE_RETURN

https://git.ruby-lang.org/ruby.git/commit/?id=de3e931df7

From de3e931df7abdc3ee22dbb7543e86af6d00ee899 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E5=8D=9C=E9=83=A8=E6=98=8C=E5=B9=B3?=
 <shyouhei@r...>
Date: Wed, 24 Jun 2020 16:23:59 +0900
Subject: 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.

diff --git a/error.c b/error.c
index 5cb808f..ce936ac 100644
--- a/error.c
+++ b/error.c
@@ -930,6 +930,7 @@ rb_check_typeddata(VALUE obj, const rb_data_type_t *data_type) https://github.com/ruby/ruby/blob/trunk/error.c#L930
     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 */
diff --git a/file.c b/file.c
index ccfb3c1..f9237b0 100644
--- a/file.c
+++ b/file.c
@@ -5433,6 +5433,7 @@ rb_f_test(int argc, VALUE *argv, VALUE _) https://github.com/ruby/ruby/blob/trunk/file.c#L5433
     else {
         rb_raise(rb_eArgError, "unknown command \"\\x%02X\"", cmd);
     }
+    UNREACHABLE_RETURN(Qundef);
 }
 
 
diff --git a/io.c b/io.c
index 36099d8..21bf797 100644
--- a/io.c
+++ b/io.c
@@ -4199,6 +4199,7 @@ rb_io_each_codepoint(VALUE io) https://github.com/ruby/ruby/blob/trunk/io.c#L4199
 
   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) https://github.com/ruby/ruby/blob/trunk/io.c#L5579
 
   error:
     rb_raise(rb_eArgError, "invalid access mode %s", modestr);
+    UNREACHABLE_RETURN(Qundef);
 }
 
 int
diff --git a/numeric.c b/numeric.c
index f0c45fa..b883b30 100644
--- a/numeric.c
+++ b/numeric.c
@@ -4013,6 +4013,7 @@ fix_pow_inverted(VALUE x, VALUE minusb) https://github.com/ruby/ruby/blob/trunk/numeric.c#L4013
 {
     if (x == INT2FIX(0)) {
         rb_num_zerodiv();
+        UNREACHABLE_RETURN(Qundef);
     }
     else {
         VALUE y = rb_int_pow(x, minusb);
diff --git a/object.c b/object.c
index fd7d02b..c4a0d3c 100644
--- a/object.c
+++ b/object.c
@@ -2574,6 +2574,7 @@ rb_mod_const_get(int argc, VALUE *argv, VALUE mod) https://github.com/ruby/ruby/blob/trunk/object.c#L2574
 
   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) https://github.com/ruby/ruby/blob/trunk/object.c#L2753
 
   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) https://github.com/ruby/ruby/blob/trunk/object.c#L2906
 
   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) https://github.com/ruby/ruby/blob/trunk/object.c#L3610
     return d;
 
   bad:
-    if (raise)
+    if (raise) {
         rb_invalid_str(q, "Float()");
+        UNREACHABLE_RETURN(nan(""));
+    }
     else {
         if (error) *error = 1;
         return 0.0;
diff --git a/proc.c b/proc.c
index 2780630..eb3e4bb 100644
--- a/proc.c
+++ b/proc.c
@@ -549,6 +549,7 @@ bind_local_variable_get(VALUE bindval, VALUE sym) https://github.com/ruby/ruby/blob/trunk/proc.c#L549
   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) https://github.com/ruby/ruby/blob/trunk/proc.c#L2022
   /* undef: */
     rb_name_err_raise("undefined singleton method `%1$s' for `%2$s'",
                       obj, vid);
+    UNREACHABLE_RETURN(Qundef);
 }
 
 /*
diff --git a/process.c b/process.c
index a0b8467..cd53030 100644
--- a/process.c
+++ b/process.c
@@ -1900,6 +1900,7 @@ check_exec_redirect_fd(VALUE v, int iskey) https://github.com/ruby/ruby/blob/trunk/process.c#L1900
 
   wrong:
     rb_raise(rb_eArgError, "wrong exec redirect");
+    UNREACHABLE_RETURN(Qundef);
 }
 
 static VALUE
diff --git a/range.c b/range.c
index b00800b..1903b0c 100644
--- a/range.c
+++ b/range.c
@@ -836,6 +836,7 @@ range_each_bignum_endless(VALUE beg) https://github.com/ruby/ruby/blob/trunk/range.c#L836
     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) https://github.com/ruby/ruby/blob/trunk/range.c#L848
     }
 
     range_each_bignum_endless(LONG2NUM(RUBY_FIXNUM_MAX + 1));
+    UNREACHABLE;
 }
 
 static VALUE
diff --git a/signal.c b/signal.c
index d479ca9..daf0123 100644
--- a/signal.c
+++ b/signal.c
@@ -274,6 +274,7 @@ signm2signo(VALUE *sig_ptr, int negative, int exit, int *prefix_ptr) https://github.com/ruby/ruby/blob/trunk/signal.c#L274
     }
     rb_raise(rb_eArgError, "unsupported signal `%.*s%"PRIsVALUE"'",
              prefix, signame_prefix, vsig);
+    UNREACHABLE_RETURN(0);
 }
 
 static const char*
diff --git a/string.c b/string.c
index 903222e..8bcc6bb 100644
--- a/string.c
+++ b/string.c
@@ -3015,6 +3015,7 @@ rb_enc_cr_str_buf_cat(VALUE str, const char *ptr, long len, https://github.com/ruby/ruby/blob/trunk/string.c#L3015
   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) https://github.com/ruby/ruby/blob/trunk/string.c#L9680
 
   short_salt:
     rb_raise(rb_eArgError, "salt too short (need >=2 bytes)");
+    UNREACHABLE_RETURN(Qundef);
 }
 
 
diff --git a/thread.c b/thread.c
index 3337735..e463b72 100644
--- a/thread.c
+++ b/thread.c
@@ -5175,6 +5175,7 @@ exec_recursive(VALUE (*func) (VALUE, VALUE, int), VALUE obj, VALUE pairid, VALUE https://github.com/ruby/ruby/blob/trunk/thread.c#L5175
     rb_raise(rb_eTypeError, "invalid inspect_tbl pair_list "
              "for %+"PRIsVALUE" in %+"PRIsVALUE,
              sym, rb_thread_current());
+    UNREACHABLE_RETURN(Qundef);
 }
 
 /*
diff --git a/time.c b/time.c
index 457fac9..ca571c8 100644
--- a/time.c
+++ b/time.c
@@ -5434,6 +5434,7 @@ end_submicro: ; https://github.com/ruby/ruby/blob/trunk/time.c#L5434
 
   invalid_format:
     rb_raise(rb_eTypeError, "marshaled time format differ");
+    UNREACHABLE_RETURN(Qundef);
 }
 
 /* :nodoc: */
diff --git a/variable.c b/variable.c
index 362ccdd..4d62361 100644
--- a/variable.c
+++ b/variable.c
@@ -277,6 +277,7 @@ rb_path_to_class(VALUE pathname) https://github.com/ruby/ruby/blob/trunk/variable.c#L277
   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) https://github.com/ruby/ruby/blob/trunk/variable.c#L3348
   not_defined:
     rb_name_err_raise("class variable %1$s not defined for %2$s",
                       mod, name);
+    UNREACHABLE_RETURN(Qundef);
 }
 
 VALUE
diff --git a/vm_eval.c b/vm_eval.c
index 98352ba..db63dcd 100644
--- a/vm_eval.c
+++ b/vm_eval.c
@@ -846,6 +846,7 @@ method_missing(VALUE obj, ID id, int argc, const VALUE *argv, enum method_missin https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L846
     return result;
   missing:
     raise_method_missing(ec, argc, argv, obj, call_status | MISSING_MISSING);
+    UNREACHABLE_RETURN(Qundef);
 }
 
 #ifndef MJIT_HEADER
-- 
cgit v0.10.2


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]