Skip to content

Commit

Permalink
fix compiler error on gcc 4.x
Browse files Browse the repository at this point in the history
It seems gcc prior to 5 suffered from preprocessor bug.  We have to
provide workarounds.

See https://github.com/ruby/ruby/runs/591138012

----

Here is something interesting.  According to C99, strictly speaking,
the gcc behaviour was in fact legal(!) and everything else were
wrong.  This was not a bug of gcc, rather a bug of the ISO C Standard.
This defect was reported to the committee as DR#412, and fixed
accordingly.  All tested compilers now conform C17's updated
preprocessor description.

See http://www.open-std.org/JTC1/SC22/WG14/www/docs/dr_412.htm
  • Loading branch information
shyouhei committed Apr 16, 2020
1 parent 4ab14ae commit 3eb05a8
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
15 changes: 7 additions & 8 deletions include/ruby/3/has/attribute.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,13 @@
#include "ruby/3/compiler_since.h"
#include "ruby/3/token_paste.h"

#ifndef __has_attribute
# /* Don't bother. */
#elif RUBY3_COMPILER_IS(GCC) && ! __has_attribute(pure)
# /* FreeBSD's <sys/cdefs.h> defines its own *broken* version of
# * __has_attribute. Cygwin copied that content to be a victim of the broken-
# * ness. We don't take them into account. */
#else
# define RUBY3_HAVE___HAS_ATTRIBUTE 1
#if defined(__has_attribute)
# if __has_attribute(pure) || RUBY3_COMPILER_IS(GCC)
# /* FreeBSD's <sys/cdefs.h> defines its own *broken* version of
# * __has_attribute. Cygwin copied that content to be a victim of the
# * broken-ness. We don't take them into account. */
# define RUBY3_HAVE___HAS_ATTRIBUTE 1
# endif
#endif

/** Wraps (or simulates) `__has_attribute`. */
Expand Down
24 changes: 12 additions & 12 deletions include/ruby/3/has/builtin.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,18 @@
#include "ruby/3/compiler_since.h"
#include "ruby/3/token_paste.h"

#ifndef __has_builtin
# /* Don't bother. */
#elif RUBY3_COMPILER_IS(Intel)
# /* :TODO: Intel C Compiler has __has_builtin (since 19.1 maybe?), and is
# * reportedly broken. We have to skip them. However the situation can
# * change. They might improve someday. We need to revisit here later. */
#elif RUBY3_COMPILER_IS(GCC) && ! __has_builtin(__builtin_alloca)
# /* FreeBSD's <sys/cdefs.h> defines its own *broken* version of __has_builtin.
# * Cygwin copied that content to be a victim of the broken-ness. We don't
# * take them into account. */
#else
# define RUBY3_HAVE___HAS_BUILTIN 1
#if defined(__has_builtin)
# if RUBY3_COMPILER_IS(Intel)
# /* :TODO: Intel C Compiler has __has_builtin (since 19.1 maybe?), and is
# * reportedly broken. We have to skip them. However the situation can
# * change. They might improve someday. We need to revisit here later. */
# elif RUBY3_COMPILER_IS(GCC) && ! __has_builtin(__builtin_alloca)
# /* FreeBSD's <sys/cdefs.h> defines its own *broken* version of
# * __has_builtin. Cygwin copied that content to be a victim of the
# * broken-ness. We don't take them into account. */
# else
# define RUBY3_HAVE___HAS_BUILTIN 1
# endif
#endif

/** Wraps (or simulates) `__has_builtin`. */
Expand Down

0 comments on commit 3eb05a8

Please sign in to comment.