Skip to content

Commit

Permalink
reduce copy & paste
Browse files Browse the repository at this point in the history
We see several occurrence of "diagnostic push/pop" so why not
make them macros.  Tested on GCC8 / Clang 6.

Note that ruby.h is intentionally left untouched because we don't
want to introduce new public macros.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
shyouhei committed Jul 30, 2018
1 parent 7018acc commit d83536c
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 38 deletions.
8 changes: 3 additions & 5 deletions cont.c
Expand Up @@ -628,9 +628,9 @@ show_vm_pcs(const rb_control_frame_t *cfp,
}
}
#endif
COMPILER_WARNING_PUSH
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wduplicate-decl-specifier"
COMPILER_WARNING_IGNORED(-Wduplicate-decl-specifier)
#endif
static VALUE
cont_capture(volatile int *volatile stat)
Expand Down Expand Up @@ -694,9 +694,7 @@ cont_capture(volatile int *volatile stat)
return contval;
}
}
#ifdef __clang__
#pragma clang diagnostic pop
#endif
COMPILER_WARNING_POP

static inline void
fiber_restore_thread(rb_thread_t *th, rb_fiber_t *fib)
Expand Down
15 changes: 4 additions & 11 deletions dln.c
Expand Up @@ -1244,24 +1244,17 @@ rb_w32_check_imported(HMODULE ext, HMODULE mine)
#endif

#ifdef USE_DLN_DLOPEN
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wpedantic"
#elif defined(__GNUC__) && (__GNUC__ >= 5)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wpedantic"
COMPILER_WARNING_PUSH
#if defined(__clang__) || GCC_VERSION_SINCE(4, 2, 0)
COMPILER_WARNING_IGNORED(-Wpedantic)
#endif
static bool
dln_incompatible_library_p(void *handle)
{
void *ex = dlsym(handle, EXTERNAL_PREFIX"ruby_xmalloc");
return ex && ex != ruby_xmalloc;
}
#ifdef __clang__
#pragma clang diagnostic pop
#elif defined(__GNUC__) && (__GNUC__ >= 5)
#pragma GCC diagnostic pop
#endif
COMPILER_WARNING_POP
#endif

void*
Expand Down
6 changes: 3 additions & 3 deletions eval_intern.h
Expand Up @@ -160,10 +160,10 @@ LONG WINAPI rb_w32_stack_overflow_handler(struct _EXCEPTION_POINTERS *);
#if defined(USE_UNALIGNED_MEMBER_ACCESS) && USE_UNALIGNED_MEMBER_ACCESS && \
defined(__clang__)
# define UNALIGNED_MEMBER_ACCESS(expr) __extension__({ \
_Pragma("GCC diagnostic push"); \
_Pragma("GCC diagnostic ignored \"-Waddress-of-packed-member\""); \
COMPILER_WARNING_PUSH; \
COMPILER_WARNING_IGNORED(-Waddress-of-packed-member); \
typeof(expr) unaligned_member_access_result = (expr); \
_Pragma("GCC diagnostic pop"); \
COMPILER_WARNING_POP; \
unaligned_member_access_result; \
})
#else
Expand Down
37 changes: 37 additions & 0 deletions internal.h
Expand Up @@ -2147,6 +2147,43 @@ rb_obj_builtin_type(VALUE obj)
# define BITFIELD(type) unsigned int
#endif

#if defined(_MSC_VER)
# define COMPILER_WARNING_PUSH __pragma(warning(push))
# define COMPILER_WARNING_POP __pragma(warning(pop))
# define COMPILER_WARNING_ERROR(flag) __pragma(warning(error: flag)))
# define COMPILER_WARNING_IGNORED(flag) __pragma(warning(suppress: flag)))

#elif defined(__clang__) /* clang 2.6 already had this feature */
# define COMPILER_WARNING_PUSH _Pragma("clang diagnostic push")
# define COMPILER_WARNING_POP _Pragma("clang diagnostic pop")
# define COMPILER_WARNING_SPECIFIER(kind, msg) \
clang diagnostic kind # msg
# define COMPILER_WARNING_ERROR(flag) \
COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(error, flag))
# define COMPILER_WARNING_IGNORED(flag) \
COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(ignored, flag))

#elif GCC_VERSION_SINCE(4, 2, 0)
/* https://gcc.gnu.org/onlinedocs/gcc-4.2.0/gcc/Diagnostic-Pragmas.html */
# define COMPILER_WARNING_PUSH _Pragma("GCC diagnostic push")
# define COMPILER_WARNING_POP _Pragma("GCC diagnostic pop")
# define COMPILER_WARNING_SPECIFIER(kind, msg) \
GCC diagnostic kind # msg
# define COMPILER_WARNING_ERROR(flag) \
COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(error, flag))
# define COMPILER_WARNING_IGNORED(flag) \
COMPILER_WARNING_PRAGMA(COMPILER_WARNING_SPECIFIER(ignored, flag))

#else /* other compilers to follow? */
# define COMPILER_WARNING_PUSH /* nop */
# define COMPILER_WARNING_POP /* nop */
# define COMPILER_WARNING_ERROR(cond, flag) /* nop */
# define COMPILER_WARNING_ignored(cond, flag) /* nop */
#endif

#define COMPILER_WARNING_PRAGMA(str) COMPILER_WARNING_PRAGMA_(str)
#define COMPILER_WARNING_PRAGMA_(str) _Pragma(#str)

#if defined(__cplusplus)
#if 0
{ /* satisfy cc-mode */
Expand Down
9 changes: 4 additions & 5 deletions mjit.c
Expand Up @@ -387,14 +387,13 @@ start_process(const char *path, char *const *argv)
}
dev_null = rb_cloexec_open(ruby_null_device, O_WRONLY, 0);

COMPILER_WARNING_PUSH;
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
COMPILER_WARNING_IGNORED(-Wdeprecated-declarations);
#endif
if ((pid = vfork()) == 0) {
#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif
COMPILER_WARNING_POP;

umask(0077);
if (mjit_opts.verbose == 0) {
/* CC can be started in a thread using a file which has been
Expand Down
14 changes: 6 additions & 8 deletions process.c
Expand Up @@ -3972,9 +3972,9 @@ retry_fork_async_signal_safe(int *status, int *ep,
while (1) {
prefork();
disable_child_handler_before_fork(&old);
COMPILER_WARNING_PUSH;
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
COMPILER_WARNING_IGNORED(-Wdeprecated-declarations);
#endif
#ifdef HAVE_WORKING_VFORK
if (!has_privilege())
Expand All @@ -3984,9 +3984,7 @@ retry_fork_async_signal_safe(int *status, int *ep,
#else
pid = fork();
#endif
#ifdef __GNUC__
# pragma GCC diagnostic pop
#endif
COMPILER_WARNING_POP;
if (pid == 0) {/* fork succeed, child process */
int ret;
close(ep[0]);
Expand Down Expand Up @@ -4055,13 +4053,13 @@ rb_fork_ruby(int *status)
prefork();
disable_child_handler_before_fork(&old);
before_fork_ruby();
COMPILER_WARNING_PUSH;
#ifdef __GNUC__
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wdeprecated-declarations"
COMPILER_WARNING_IGNORED(-Wdeprecated-declarations);
#endif
pid = fork();
#ifdef __GNUC__
# pragma GCC diagnostic pop
COMPILER_WARNING_POP;
#endif
err = errno;
after_fork_ruby();
Expand Down
10 changes: 4 additions & 6 deletions template/prelude.c.tmpl
Expand Up @@ -138,9 +138,9 @@ prelude_prefix_path(VALUE self)
% unless preludes.empty?
#define PRELUDE_NAME(n) rb_usascii_str_new_static(prelude_name##n, sizeof(prelude_name##n)-1)
#define PRELUDE_CODE(n) rb_usascii_str_new_static(prelude_code##n.L0, sizeof(prelude_code##n))
#if defined __GNUC__ && __GNUC__ >= 5
# pragma GCC diagnostic push
# pragma GCC diagnostic error "-Wmissing-field-initializers"
COMPILER_WARNING_PUSH
#if GCC_VERSION_SINCE(4, 2, 0)
COMPILER_WARNING_ERROR(-Wmissing-field-initializers)
#endif
static void
prelude_eval(VALUE code, VALUE name, int line)
Expand Down Expand Up @@ -168,9 +168,7 @@ prelude_eval(VALUE code, VALUE name, int line)
NULL, ISEQ_TYPE_TOP, &optimization));
rb_ast_dispose(ast);
}
#if defined __GNUC__ && __GNUC__ >= 5
# pragma GCC diagnostic pop
#endif
COMPILER_WARNING_POP
% end

% if @have_sublib
Expand Down

0 comments on commit d83536c

Please sign in to comment.