From 2fc5210f31ad23463d7b0a0e36bcfbeee7b41b3e Mon Sep 17 00:00:00 2001 From: shyouhei Date: Fri, 16 Sep 2016 06:15:55 +0000 Subject: [PATCH] * internal.h (WARN_UNUSED_RESULT): moved to configure.in, to actually check its availability rather to check GCC's version. * configure.in (WARN_UNUSED_RESULT): moved to here. * configure.in (RUBY_FUNC_ATTRIBUTE): change function declaration to return int rather than void, because it makes no sense for a warn_unused_result attributed function to return void. Funny thing however is that it also makes no sense for noreturn attributed function to return int. So there is a fundamental conflict between them. While I tested this, I confirmed both GCC 6 and Clang 3.8 prefers int over void to correctly detect necessary attributes under this setup. Maybe subject to change in future. * internal.h (UNINITIALIZED_VAR): renamed to MAYBE_UNUSED, then moved to configure.in for the same reason we move WARN_UNUSED_RESULT. * configure.in (MAYBE_UNUSED): moved to here. * internal.h (__has_attribute): deleted, because it has no use now. * string.c (rb_str_enumerate_lines): refactor macro rename. * string.c (rb_str_enumerate_bytes): ditto. * string.c (rb_str_enumerate_chars): ditto. * string.c (rb_str_enumerate_codepoints): ditto. * thread.c (do_select): ditto. * vm_backtrace.c (rb_debug_inspector_open): ditto. * vsnprintf.c (BSD_vfprintf): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56169 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 40 ++++++++++++++++++++++++++++++++++++++++ configure.in | 4 +++- internal.h | 20 -------------------- string.c | 8 ++++---- thread.c | 8 ++++---- vm_backtrace.c | 2 +- vsnprintf.c | 4 ++-- 7 files changed, 54 insertions(+), 32 deletions(-) diff --git a/ChangeLog b/ChangeLog index 2e8780b546..8eeefbd34e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,43 @@ +Fri Sep 16 14:54:34 2016 URABE Shyouhei + + * internal.h (WARN_UNUSED_RESULT): moved to configure.in, to + actually check its availability rather to check GCC's version. + + * configure.in (WARN_UNUSED_RESULT): moved to here. + + * configure.in (RUBY_FUNC_ATTRIBUTE): change function declaration + to return int rather than void, because it makes no sense for a + warn_unused_result attributed function to return void. + + Funny thing however is that it also makes no sense for noreturn + attributed function to return int. So there is a fundamental + conflict between them. While I tested this, I confirmed both + GCC 6 and Clang 3.8 prefers int over void to correctly detect + necessary attributes under this setup. Maybe subject to change + in future. + + * internal.h (UNINITIALIZED_VAR): renamed to MAYBE_UNUSED, then + moved to configure.in for the same reason we move + WARN_UNUSED_RESULT. + + * configure.in (MAYBE_UNUSED): moved to here. + + * internal.h (__has_attribute): deleted, because it has no use now. + + * string.c (rb_str_enumerate_lines): refactor macro rename. + + * string.c (rb_str_enumerate_bytes): ditto. + + * string.c (rb_str_enumerate_chars): ditto. + + * string.c (rb_str_enumerate_codepoints): ditto. + + * thread.c (do_select): ditto. + + * vm_backtrace.c (rb_debug_inspector_open): ditto. + + * vsnprintf.c (BSD_vfprintf): ditto. + Fri Sep 16 14:35:55 2016 URABE Shyouhei * ChangeLog (add-log-time-format): Not exactly sure when but diff --git a/configure.in b/configure.in index da0fc54997..fe8ee14f79 100644 --- a/configure.in +++ b/configure.in @@ -1809,7 +1809,7 @@ AS_VAR_POPDEF([rbcv])dnl dnl RUBY_FUNC_ATTRIBUTE(attrib, macroname, cachevar, condition) AC_DEFUN([RUBY_FUNC_ATTRIBUTE], [dnl RUBY_DECL_ATTRIBUTE([$1], [$2], [$3], [$4], - [function], [@%:@define x void conftest_attribute_check(void)] + [function], [@%:@define x int conftest_attribute_check(void)] ) ]) @@ -1829,6 +1829,8 @@ RUBY_FUNC_ATTRIBUTE(__deprecated__("by "@%:@n), DEPRECATED_BY(n,x), rb_cv_func_d RUBY_TYPE_ATTRIBUTE(__deprecated__ mesg, DEPRECATED_TYPE(mesg,x), rb_cv_type_deprecated) RUBY_FUNC_ATTRIBUTE(__noinline__, NOINLINE) RUBY_FUNC_ATTRIBUTE(__always_inline__, ALWAYS_INLINE) +RUBY_FUNC_ATTRIBUTE(__warn_unused_result__, WARN_UNUSED_RESULT) +RUBY_FUNC_ATTRIBUTE(__unused__, MAYBE_UNUSED) RUBY_FUNC_ATTRIBUTE(__error__ mesg, ERRORFUNC(mesg,x), rb_cv_func___error__) RUBY_FUNC_ATTRIBUTE(__warning__ mesg, WARNINGFUNC(mesg,x), rb_cv_func___warning__) RUBY_FUNC_ATTRIBUTE(__weak__, WEAK, rb_cv_func_weak) diff --git a/internal.h b/internal.h index bf3880e695..57d023600a 100644 --- a/internal.h +++ b/internal.h @@ -26,26 +26,6 @@ extern "C" { #define LIKELY(x) RB_LIKELY(x) #define UNLIKELY(x) RB_UNLIKELY(x) -#ifndef __has_attribute -# define __has_attribute(x) 0 -#endif - -#if __has_attribute(__unused__) -#define UNINITIALIZED_VAR(x) x __attribute__((__unused__)) -#elif defined(__GNUC__) && __GNUC__ >= 3 -#define UNINITIALIZED_VAR(x) x = x -#else -#define UNINITIALIZED_VAR(x) x -#endif - -#if __has_attribute(__warn_unused_result__) -#define WARN_UNUSED_RESULT(x) x __attribute__((__warn_unused_result__)) -#elif GCC_VERSION_SINCE(3,4,0) -#define WARN_UNUSED_RESULT(x) x __attribute__((__warn_unused_result__)) -#else -#define WARN_UNUSED_RESULT(x) x -#endif - #ifdef HAVE_VALGRIND_MEMCHECK_H # include # ifndef VALGRIND_MAKE_MEM_DEFINED diff --git a/string.c b/string.c index 9725e32805..6988e08ec1 100644 --- a/string.c +++ b/string.c @@ -7348,7 +7348,7 @@ rb_str_enumerate_lines(int argc, VALUE *argv, VALUE str, int wantarray) long pos, len, rslen; int paragraph_mode = 0; - VALUE UNINITIALIZED_VAR(ary); + VALUE MAYBE_UNUSED(ary); if (argc == 0) rs = rb_rs; @@ -7522,7 +7522,7 @@ static VALUE rb_str_enumerate_bytes(VALUE str, int wantarray) { long i; - VALUE UNINITIALIZED_VAR(ary); + VALUE MAYBE_UNUSED(ary); if (rb_block_given_p()) { if (wantarray) { @@ -7606,7 +7606,7 @@ rb_str_enumerate_chars(VALUE str, int wantarray) long i, len, n; const char *ptr; rb_encoding *enc; - VALUE UNINITIALIZED_VAR(ary); + VALUE MAYBE_UNUSED(ary); str = rb_str_new_frozen(str); ptr = RSTRING_PTR(str); @@ -7705,7 +7705,7 @@ rb_str_enumerate_codepoints(VALUE str, int wantarray) unsigned int c; const char *ptr, *end; rb_encoding *enc; - VALUE UNINITIALIZED_VAR(ary); + VALUE MAYBE_UNUSED(ary); if (single_byte_optimizable(str)) return rb_str_enumerate_bytes(str, wantarray); diff --git a/thread.c b/thread.c index 46077f6ea4..c0bdaf546e 100644 --- a/thread.c +++ b/thread.c @@ -3660,11 +3660,11 @@ static int do_select(int n, rb_fdset_t *readfds, rb_fdset_t *writefds, rb_fdset_t *exceptfds, struct timeval *timeout) { - int UNINITIALIZED_VAR(result); + int MAYBE_UNUSED(result); int lerrno; - rb_fdset_t UNINITIALIZED_VAR(orig_read); - rb_fdset_t UNINITIALIZED_VAR(orig_write); - rb_fdset_t UNINITIALIZED_VAR(orig_except); + rb_fdset_t MAYBE_UNUSED(orig_read); + rb_fdset_t MAYBE_UNUSED(orig_write); + rb_fdset_t MAYBE_UNUSED(orig_except); double limit = 0; struct timeval wait_rest; rb_thread_t *th = GET_THREAD(); diff --git a/vm_backtrace.c b/vm_backtrace.c index cbde6409a5..d4d4d41ed8 100644 --- a/vm_backtrace.c +++ b/vm_backtrace.c @@ -1173,7 +1173,7 @@ rb_debug_inspector_open(rb_debug_inspector_func_t func, void *data) rb_debug_inspector_t dbg_context; rb_thread_t *th = GET_THREAD(); int state; - volatile VALUE UNINITIALIZED_VAR(result); + volatile VALUE MAYBE_UNUSED(result); dbg_context.th = th; dbg_context.cfp = dbg_context.th->cfp; diff --git a/vsnprintf.c b/vsnprintf.c index 65012ea746..9a4f37abe0 100644 --- a/vsnprintf.c +++ b/vsnprintf.c @@ -558,9 +558,9 @@ BSD_vfprintf(FILE *fp, const char *fmt0, va_list ap) int fprec = 0; /* floating point precision */ char expstr[7]; /* buffer for exponent string */ #endif - u_long UNINITIALIZED_VAR(ulval); /* integer arguments %[diouxX] */ + u_long MAYBE_UNUSED(ulval); /* integer arguments %[diouxX] */ #ifdef _HAVE_SANE_QUAD_ - u_quad_t UNINITIALIZED_VAR(uqval); /* %q integers */ + u_quad_t MAYBE_UNUSED(uqval); /* %q integers */ #endif /* _HAVE_SANE_QUAD_ */ int base; /* base for [diouxX] conversion */ int dprec; /* a copy of prec if [diouxX], 0 otherwise */