Created attachment 160356 [details]
Fix signed left-shifting in lang/ruby21's public ruby.h
During the exp-run in bug 201377, it was found that devel/rubygem-thrift gives errors with a recent clang 3.7.0 snapshot:
This is because it includes ruby.h from the lang/ruby21 port, which uses this macro:
#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG))
Unfortunately, left-shifting negative 'i' values is undefined behavior, so clang warns about this. I changed the macro to:
#define INT2FIX(i) ((VALUE)(((VALUE)(i))<<1 | FIXNUM_FLAG))
which avoids the undefined behavior by casting to VALUE (which is unsigned) first. I ran all ruby21 tests before and after this fix, and I got "1 failures, 4 errors" in both cases, so no regressions.
However, since this is a public ruby header, I can imagine that this is a change that makes some people nervous. So if ruby maintainers prefer to fix this in the devel/rubygem-thrift port instead, for example by squelching the warning, please let me know.
https://github.com/ruby/ruby/commit/1efb3c31b731e99627bbc0da13dfd3463bb67c67 did change this i upstream to
#define INT2FIX(i) (((VALUE)(i))<<1 | FIXNUM_FLAG)
could you check if that solves the problem with clang 3.7.0?
(In reply to Michael Moll from comment #1)
> did change this i upstream to
> #define INT2FIX(i) (((VALUE)(i))<<1 | FIXNUM_FLAG)
> could you check if that solves the problem with clang 3.7.0?
Yes, that is fine too. Even better that it comes from upstream. :)
I applied the complete diff you mentioned, but it may be a bit overkill. It should be enough to just patch the public ruby.h header.
Btw, I think this also applies to the other ruby ports?
Let's stick with the one line patch to ruby.h then, if that's sufficient. :)
It would also be applicable to lang/ruby20, as lang/ruby22 already includes the whole upstream change.
A commit references this bug:
Date: Sun Sep 20 21:30:41 UTC 2015
New revision: 397464
fix Ruby 2.0 and 2.1 header for clang 3.7
2.2 already had this change in upstream
Submitted by: dim (different version)
Obtained from: Ruby SVN repository (r47996)