Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 29 May 2021 14:08:50 GMT
From:      Dimitry Andric <dim@FreeBSD.org>
To:        ports-committers@FreeBSD.org, dev-commits-ports-all@FreeBSD.org, dev-commits-ports-main@FreeBSD.org
Subject:   git: 6f95cc52457d - main - lang/ruby{26, 27}: work around clang 12 -Wcompound-token-split-by-macro warning
Message-ID:  <202105291408.14TE8on6091212@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by dim (src committer):

URL: https://cgit.FreeBSD.org/ports/commit/?id=6f95cc52457d9c074ce91cdbd652a782424e41ee

commit 6f95cc52457d9c074ce91cdbd652a782424e41ee
Author:     Dimitry Andric <dim@FreeBSD.org>
AuthorDate: 2021-05-15 17:12:06 +0000
Commit:     Dimitry Andric <dim@FreeBSD.org>
CommitDate: 2021-05-29 14:08:19 +0000

    lang/ruby{26,27}: work around clang 12 -Wcompound-token-split-by-macro warning
    
    During an exp-run for llvm 12 (see bug 255570), it turned out that
    several ruby gem extensions do not build with clang 12.0.0, for example
    devel/rubygem-thrift:
    
    compiling binary_protocol_accelerated.c
    binary_protocol_accelerated.c:404:68: error: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Werror,-Wcompound-token-split-by-macro]
      VALUE thrift_binary_protocol_class = rb_const_get(thrift_module, rb_intern("BinaryProtocol"));
                                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/local/include/ruby-2.7/ruby/ruby.h:1847:23: note: expanded from macro 'rb_intern'
            __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                          ^
    binary_protocol_accelerated.c:404:68: note: '{' token is here
      VALUE thrift_binary_protocol_class = rb_const_get(thrift_module, rb_intern("BinaryProtocol"));
                                                                       ^~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/local/include/ruby-2.7/ruby/ruby.h:1847:24: note: expanded from macro 'rb_intern'
            __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/local/include/ruby-2.7/ruby/ruby.h:1832:5: note: expanded from macro 'RUBY_CONST_ID_CACHE'
        {                                                   \
        ^
    
    and similarly www/unit-ruby:
    
    src/ruby/nxt_ruby.c:242:21: error: '(' and '{' tokens introducing statement expression appear in different macro expansion contexts [-Werror,-Wcompound-token-split-by-macro]
        nxt_ruby_call = rb_intern("call");
                        ^~~~~~~~~~~~~~~~~
    /usr/local/include/ruby-2.7/ruby/ruby.h:1847:23: note: expanded from macro 'rb_intern'
            __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                          ^
    src/ruby/nxt_ruby.c:242:21: note: '{' token is here
        nxt_ruby_call = rb_intern("call");
                        ^~~~~~~~~~~~~~~~~
    /usr/local/include/ruby-2.7/ruby/ruby.h:1847:24: note: expanded from macro 'rb_intern'
            __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
                           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    /usr/local/include/ruby-2.7/ruby/ruby.h:1832:5: note: expanded from macro 'RUBY_CONST_ID_CACHE'
        {                                                   \
        ^
    
    The gem extensions appear to purposefully compile using -Werror, and
    this new -Wcompound-token-split-by-macro is enabled by default in clang
    12 and later. Of course we could go over all these extensions, and
    either remove -Werror or add -Wno-compound-token-split-by-macro, but
    that seems quite a lot of effort.
    
    Instead, I have submitted a pull request to ruby's GitHub, which fixes
    this by modifying the main ruby.h header:
    * Add RUBY_CONST_ID_CACHE_NB() (i.e. no-brace) which contains the code
      itself, without any braces
    * RUBY_CONST_ID_CACHE() which uses RUBY_CONST_ID_CACHE_NB(), but puts
      braces around it (so no existing code using this macro breaks)
    * Finally, change rb_intern() so the __extension__ directly creates a
      gcc statement expression, using the RUBY_CONST_ID_CACHE_NB() macro
    
    Patch this locally in our lang/ruby26 and lang/ruby27 ports for now,
    until upstream manages to get this in.
    
    Approved by:    maintainer timeout (2 weeks)
    PR:             255910
    MFH:            2021Q2
---
 lang/ruby26/files/patch-include_ruby_ruby.h | 29 +++++++++++++++++++++++++++++
 lang/ruby27/files/patch-include_ruby_ruby.h | 29 +++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/lang/ruby26/files/patch-include_ruby_ruby.h b/lang/ruby26/files/patch-include_ruby_ruby.h
new file mode 100644
index 000000000000..b165854810ea
--- /dev/null
+++ b/lang/ruby26/files/patch-include_ruby_ruby.h
@@ -0,0 +1,29 @@
+--- include/ruby/ruby.h.orig	2021-04-05 11:48:34 UTC
++++ include/ruby/ruby.h
+@@ -1807,12 +1807,14 @@ VALUE rb_sym2str(VALUE);
+ VALUE rb_to_symbol(VALUE name);
+ VALUE rb_check_symbol(volatile VALUE *namep);
+ 
+-#define RUBY_CONST_ID_CACHE(result, str)		\
+-    {							\
++#define RUBY_CONST_ID_CACHE_NB(result, str)		\
+ 	static ID rb_intern_id_cache;			\
+ 	if (!rb_intern_id_cache)			\
+ 	    rb_intern_id_cache = rb_intern2((str), (long)strlen(str)); \
+-	result rb_intern_id_cache;			\
++	result rb_intern_id_cache;
++#define RUBY_CONST_ID_CACHE(result, str)		\
++    {							\
++	RUBY_CONST_ID_CACHE_NB(result, str)		\
+     }
+ #define RUBY_CONST_ID(var, str) \
+     do RUBY_CONST_ID_CACHE((var) =, (str)) while (0)
+@@ -1823,7 +1825,7 @@ VALUE rb_check_symbol(volatile VALUE *namep);
+  * since gcc-2.7.2.3 at least. */
+ #define rb_intern(str) \
+     (__builtin_constant_p(str) ? \
+-        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
++        __extension__ ({RUBY_CONST_ID_CACHE_NB((ID), (str))}) : \
+         rb_intern(str))
+ #define rb_intern_const(str) \
+     (__builtin_constant_p(str) ? \
diff --git a/lang/ruby27/files/patch-include_ruby_ruby.h b/lang/ruby27/files/patch-include_ruby_ruby.h
new file mode 100644
index 000000000000..1cbe0ed4a699
--- /dev/null
+++ b/lang/ruby27/files/patch-include_ruby_ruby.h
@@ -0,0 +1,29 @@
+--- include/ruby/ruby.h.orig	2021-04-05 12:39:38 UTC
++++ include/ruby/ruby.h
+@@ -1828,12 +1828,14 @@ VALUE rb_sym2str(VALUE);
+ VALUE rb_to_symbol(VALUE name);
+ VALUE rb_check_symbol(volatile VALUE *namep);
+ 
+-#define RUBY_CONST_ID_CACHE(result, str)		\
+-    {							\
++#define RUBY_CONST_ID_CACHE_NB(result, str)		\
+ 	static ID rb_intern_id_cache;			\
+ 	if (!rb_intern_id_cache)			\
+ 	    rb_intern_id_cache = rb_intern2((str), (long)strlen(str)); \
+-	result rb_intern_id_cache;			\
++	result rb_intern_id_cache;
++#define RUBY_CONST_ID_CACHE(result, str)		\
++    {							\
++	RUBY_CONST_ID_CACHE_NB(result, str)		\
+     }
+ #define RUBY_CONST_ID(var, str) \
+     do RUBY_CONST_ID_CACHE((var) =, (str)) while (0)
+@@ -1844,7 +1846,7 @@ VALUE rb_check_symbol(volatile VALUE *namep);
+  * since gcc-2.7.2.3 at least. */
+ #define rb_intern(str) \
+     (__builtin_constant_p(str) ? \
+-        __extension__ (RUBY_CONST_ID_CACHE((ID), (str))) : \
++        __extension__ ({RUBY_CONST_ID_CACHE_NB((ID), (str))}) : \
+         rb_intern(str))
+ #define rb_intern_const(str) \
+     (__builtin_constant_p(str) ? \



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202105291408.14TE8on6091212>