Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 15 May 2021 19:20:31 +0000
From:      bugzilla-noreply@freebsd.org
To:        ruby@FreeBSD.org
Subject:   maintainer-feedback requested: [Bug 255910] lang/ruby26 lang/ruby27: Fix clang 12 -Wcompound-token-split-by-macro warning in ruby.h
Message-ID:  <bug-255910-21402-lKssKZ2fiR@https.bugs.freebsd.org/bugzilla/>
In-Reply-To: <bug-255910-21402@https.bugs.freebsd.org/bugzilla/>
References:  <bug-255910-21402@https.bugs.freebsd.org/bugzilla/>

next in thread | previous in thread | raw e-mail | index | archive | help
Bugzilla Automation <bugzilla@FreeBSD.org> has asked freebsd-ruby (Nobody)
<ruby@FreeBSD.org> for maintainer-feedback:
Bug 255910: lang/ruby26 lang/ruby27: Fix clang 12
-Wcompound-token-split-by-macro warning in ruby.h
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=3D255910



--- Description ---
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-th=
rift
[1]:

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 =3D rb_const_get(thrift_module,
rb_intern("BinaryProtocol"));
=09=09=09=09=09=09=09=09=20=20
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/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 =3D rb_const_get(thrift_module,
rb_intern("BinaryProtocol"));
=09=09=09=09=09=09=09=09=20=20
^~~~~~~~~~~~~~~~~~~~~~~~~~~
/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 [2]:

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 =3D 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 =3D 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 n=
ew
-Wcompound-token-split-by-macro is enabled by default in clang 12 and later
(see [3]). Of course we could go over all these extensions, and either remo=
ve
-Werror or add -Wno-compound-token-split-by-macro, but that seems quite a l=
ot
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 itse=
lf,
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

I am attaching a patch that adds these changes to the lang/ruby26 and
lang/ruby27 ports.

Also noted in the pull request is that ruby 3.0 does not need these changes=
, as
they have refactored ruby.h, so that it avoids emitting this warning.

[1]
http://package22.nyi.freebsd.org/data/mainamd64PR255570-default/2021-05-08_=
16h0
2m24s/logs/errors/rubygem-thrift-0.14.0,1.log
[2]
http://package22.nyi.freebsd.org/data/mainamd64PR255570-default/2021-05-08_=
16h0
2m24s/logs/errors/unit-ruby2.7-1.23.0.log
[3]
https://github.com/llvm/llvm-project/commit/0e00a95b4fad5e72851de012d3a0b2c=
2d01
f8685
[4] https://github.com/ruby/ruby/pull/4504



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?bug-255910-21402-lKssKZ2fiR>