Project

General

Profile

Bug #17854

Updated by meta@vmeta.jp (Koichiro Iwao) 3 months ago

## Affected version 
 * Ruby 2.6, 2.7, 3.0 compiled with **clang on FressBD** 

 No tested with other versions. Ruby compiled with GCC doesn't have this issue. 

 ## Snippet to reproduce 
 ``` 
 ruby -e 'case 1; when 2r; 3; end' 
 ``` 

 ## Step to reproduce 

 Prepare a fresh installation of FreeBSD 13. Either Ruby installed from system package or ruby-build can reproduce the issue. 


 ``` 
 # clang -v  
 FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe) 
 Target: x86_64-unknown-freebsd13.0 
 Thread model: posix 
 InstalledDir: /usr/bin 
 [root@ruby-bug /tmp]# clang -v  
 FreeBSD clang version 11.0.1 (git@github.com:llvm/llvm-project.git llvmorg-11.0.1-0-g43ff75f2c3fe) 
 Target: x86_64-unknown-freebsd13.0 
 Thread model: posix 
 InstalledDir: /usr/bin 
 ``` 

 ### System Ruby 


 ``` 
 # pkg install ruby  
 # /usr/local/bin/ruby -v 
 # /usr/local/bin/ruby -e 'case 1; when 2r; 3; end' 
 ``` 

 ### Ruby installed by ruby-build 

 Same as Ruby installed by ruby-build. 
 ``` 
 # pkg install rbenv ruby-build 
 # bash 
 bash# eval "$(rbenv init -)" 
 bash# cd /tmp 
 bash# rbenv install 2.7.3 
 bash# rbenv local 2.7.3 
 bash# rbenv which ruby 
 /root/.rbenv/versions/2.7.3/bin/ruby 
 bash# ruby -e 'case 1; when 2r; 3; end' 
 ``` 

 ## Patch 

 The following patch is provided by the original reporter but it looks too ad-hoc. If this bug is fixed in Ruby upstream, I'll apply it to FreeBSD package. 

 ```diff 
 diff --git a/compile.c b/compile.c 
 index 1cabb8c..a954176 100644 
 --- a/compile.c 
 +++ b/compile.c 
 @@ -1987,7 +1987,7 @@ cdhash_cmp(VALUE val, VALUE lit) 
          return rb_float_cmp(lit, val); 
      } 
      else { 
 -          UNREACHABLE_RETURN(-1); 
 +          return -1; 
      } 
  } 
 
 @@ -2005,7 +2005,7 @@ cdhash_hash(VALUE a) 
        case T_FLOAT: 
          return rb_dbl_long_hash(RFLOAT_VALUE(a)); 
        default: 
 -          UNREACHABLE_RETURN(0); 
 +          return 0; 
      } 
  } 
 ``` 

 ## See also 
 Downstream bug: 
 * https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=255583

Back