Issue #12893 has been updated by Shugo Maeda.


Reproduced on my FreeBSD box:

```
./ruby -r continuation -e 'cont = nil; ary = [1,2,3]; ary.combination(2) { callcc {|k| cont = k} unless cont }; cont.call'
ruby 2.4.0dev (2016-11-04 trunk 56558) [x86_64-freebsd11.0]

-- Control frame information -----------------------------------------------
c:0005 p:---- s:0020 e:000019 CFUNC  :callcc
c:0004 p:0016 s:0016 E:002420 BLOCK  -e:1 [FINISH]
c:0003 p:---- s:0013 e:000012 CFUNC  :combination
c:0002 p:0017 s:0008 E:001850 EVAL   -e:1 [FINISH]
c:0001 p:0000 s:0003 E:002700 (none) [FINISH]
...
```

In cont_capture(), cont is set to 0x1 after the context is restored. 

```c
    if (ruby_setjmp(cont->jmpbuf)) {
        /* cont is set to 0x1 here */
```

The following patch fixes the problem:

```diff
diff --git a/cont.c b/cont.c
index 8119b5c..79b685f 100644
--- a/cont.c
+++ b/cont.c
@@ -471,6 +471,9 @@ cont_new(VALUE klass)
 
 static VALUE
 cont_capture(volatile int *stat)
+#ifdef __clang__
+__attribute__ ((optnone))
+#endif
 {
     rb_context_t *cont;
     rb_thread_t *th = GET_THREAD();
```


----------------------------------------
Bug #12893: trunk fails on linux with clang on test with callcc
https://bugs.ruby-lang.org/issues/12893#change-61262

* Author: Yura Sokolov
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.4.0dev (2016-11-03 trunk 56550) [x86_64-linux]
* Backport: 2.1: UNKNOWN, 2.2: UNKNOWN, 2.3: UNKNOWN
----------------------------------------
Test fails on linux with clang.
It doesn't fails with gcc.

OS: Ubuntu 16.04 x64_64
clang version 3.8.0-2ubuntu4 (tags/RELEASE_380/final)
configure: `../configure  CC=clang CXX=clang++`
test:

$ make test-all TESTS='-n /callcc/'
....
Run options: "--ruby=./miniruby -I../lib -I. -I.ext/common  ../tool/runruby.rb --extout=.ext  -- --disable-gems" --excludes-dir=../test/excludes --name=!/memory_leak/ -n /callcc/

# Running tests:

[ 1/18] TestArray#test_combination_with_callcc/home/yura/Project/ruby-falcon/test/ruby/test_array.rb:948: [BUG] Segmentation fault at 0x00000000000012
ruby 2.4.0dev (2016-11-03 trunk 56550) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0027 p:---- s:0155 e:000154 CFUNC  :callcc
c:0026 p:0016 s:0151 E:001310 BLOCK  /home/yura/Project/ruby-falcon/test/ruby/test_array.rb:948 [FINISH]
c:0025 p:---- s:0148 e:000147 CFUNC  :combination
c:0024 p:0038 s:0143 E:0021a0 METHOD /home/yura/Project/ruby-falcon/test/ruby/test_array.rb:947
c:0023 p:0036 s:0135 E:000110 METHOD /home/yura/Project/ruby-falcon/test/lib/test/unit.rb:1029
....
-- Ruby level backtrace information ----------------------------------------
....
/home/yura/Project/ruby-falcon/test/lib/test/unit.rb:1029:in `run_test'
/home/yura/Project/ruby-falcon/test/ruby/test_array.rb:947:in `test_combination_with_callcc'
/home/yura/Project/ruby-falcon/test/ruby/test_array.rb:947:in `combination'
/home/yura/Project/ruby-falcon/test/ruby/test_array.rb:948:in `block in test_combination_with_callcc'
/home/yura/Project/ruby-falcon/test/ruby/test_array.rb:948:in `callcc'

-- Machine register context ------------------------------------------------
 RIP: 0x0000559aac7459b3 RBP: 0x00007ffd612aeb40 RSP: 0x00007ffd612aeaf0
 RAX: 0x0000000000000001 RBX: 0x0000559ab4745a50 RCX: 0x00007ffd612aeb3f
 RDX: 0x0000000000000002 RDI: 0x00007ffd612b1000 RSI: 0x0000559ab47765c0
  R8: 0x00007fee67cc4b00  R9: 0x0000559aac744b00 R10: 0x00007fee67cc4b00
 R11: 0x0000000000000020 R12: 0x0000000000000000 R13: 0x0000559ab4745a50
 R14: 0x0000000000000000 R15: 0x0000559aad43b5c0 EFL: 0x0000000000010202

-- C level backtrace information -------------------------------------------
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(rb_vm_bugreport+0x1cd) [0x559aac76652d] ../vm_dump.c:679
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(rb_bug_context+0x1e6) [0x559aac759466] ../error.c:426
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(sigsegv+0x4f) [0x559aac67717f] ../signal.c:897
/lib/x86_64-linux-gnu/libpthread.so.0 [0x7fee678b93e0]
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(cont_capture+0x303) [0x559aac7459b3] ../cont.c:514
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(rb_callcc+0xe) [0x559aac744dbe] ../cont.c:949
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(vm_call_cfunc+0xf1) [0x559aac6e70c1] ../vm_insnhelper.c:1752
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(vm_exec_core+0x27fe) [0x559aac6d0fee] ../insns.def:967
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(vm_exec+0x9d) [0x559aac6e186d] ../vm.c:1711
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(invoke_block_from_c_splattable+0x158) [0x559aac6ef6d8] ../vm.c:1032
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(rb_yield+0x8a) [0x559aac6dc62a] ../vm.c:1069
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(yield_indexed_values+0x197) [0x559aac708857] ../array.c:4970
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(rb_ary_combination+0x3d7) [0x559aac704e47] ../array.c:5137
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(vm_call_cfunc+0xf1) [0x559aac6e70c1] ../vm_insnhelper.c:1752
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(vm_exec_core+0x27fe) [0x559aac6d0fee] ../insns.def:967
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(vm_exec+0x9d) [0x559aac6e186d] ../vm.c:1711
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(invoke_block_from_c_splattable+0x158) [0x559aac6ef6d8] ../vm.c:1032
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(rb_yield+0x8a) [0x559aac6dc62a] ../vm.c:1069
/home/yura/Project/ruby-falcon/.bld-clang~/ruby(rb_ary_collect+0x229) [0x559aac6ff5c9] ../array.c:2732




-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>