Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ntuple of arrays segfaults on 1.0.3 (works on 0.7) #30739

Closed
kalmarek opened this issue Jan 17, 2019 · 13 comments · Fixed by #36395
Closed

ntuple of arrays segfaults on 1.0.3 (works on 0.7) #30739

kalmarek opened this issue Jan 17, 2019 · 13 comments · Fixed by #36395
Labels
bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code good first issue Indicates a good issue for first-time contributors to Julia

Comments

@kalmarek
Copy link
Contributor

julia> versioninfo()
Julia Version 0.7.0
Commit a4cb80f3ed (2018-08-08 06:46 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 2

julia> function ifelsetuple(n::Integer, k::Integer, f, g)
           return ntuple(i -> (i <= k ? f : g), n)
       end
ifelsetuple (generic function with 1 method)

julia> f(x) = x^2; g(x) = x^3; ifelsetuple(5, 3, f, g)
(f, f, f, g, g)

julia> a = [1]; b=[2]; ifelsetuple(5, 3, a, b)
([1], [1], [1], [2], [2])

but

julia> versioninfo()
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i5-6200U CPU @ 2.30GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, skylake)
Environment:
  JULIA_NUM_THREADS = 2

julia> function ifelsetuple(n::Integer, k::Integer, f, g)
           return ntuple(i -> (i <= k ? f : g), n)
       end
ifelsetuple (generic function with 1 method)

julia> f(x) = x^2; g(x) = x^3; ifelsetuple(5, 3, f, g)
(f, f, f, g, g)

julia> a = [1]; b=[2]; ifelsetuple(5, 3, a, b)

signal (11): Segmentation fault
in expression starting at no file:0
_ZN4llvm9LiveRange4joinERS0_PKiS3_RNS_15SmallVectorImplIPNS_6VNInfoEEE at /opt/julia-1.0.3/bin/../lib/julia/libLLVM-6.0.so (unknown line)
_ZN12_GLOBAL__N_117RegisterCoalescer12joinVirtRegsERN4llvm13CoalescerPairE at /opt/julia-1.0.3/bin/../lib/julia/libLLVM-6.0.so (unknown line)
_ZN12_GLOBAL__N_117RegisterCoalescer20copyCoalesceWorkListEN4llvm15MutableArrayRefIPNS1_12MachineInstrEEE at /opt/julia-1.0.3/bin/../lib/julia/libLLVM-6.0.so (unknown line)
_ZN12_GLOBAL__N_117RegisterCoalescer20runOnMachineFunctionERN4llvm15MachineFunctionE at /opt/julia-1.0.3/bin/../lib/julia/libLLVM-6.0.so (unknown line)
_ZN4llvm19MachineFunctionPass13runOnFunctionERNS_8FunctionE at /opt/julia-1.0.3/bin/../lib/julia/libLLVM-6.0.so (unknown line)
_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE at /opt/julia-1.0.3/bin/../lib/julia/libLLVM-6.0.so (unknown line)
_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE at /opt/julia-1.0.3/bin/../lib/julia/libLLVM-6.0.so (unknown line)
_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE at /opt/julia-1.0.3/bin/../lib/julia/libLLVM-6.0.so (unknown line)
operator() at /buildworker/worker/package_linux64/build/src/jitlayers.cpp:481
addModule at /buildworker/worker/package_linux64/build/usr/include/llvm/ExecutionEngine/Orc/IRCompileLayer.h:57 [inlined]
addModule at /buildworker/worker/package_linux64/build/src/jitlayers.cpp:608
jl_add_to_ee at /buildworker/worker/package_linux64/build/src/jitlayers.cpp:855 [inlined]
jl_finalize_function at /buildworker/worker/package_linux64/build/src/jitlayers.cpp:863
getAddressForFunction at /buildworker/worker/package_linux64/build/src/codegen.cpp:1299
jl_generate_fptr at /buildworker/worker/package_linux64/build/src/codegen.cpp:1408
jl_compile_method_internal at /buildworker/worker/package_linux64/build/src/gf.c:1823 [inlined]
jl_fptr_trampoline at /buildworker/worker/package_linux64/build/src/gf.c:1830
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
do_call at /buildworker/worker/package_linux64/build/src/interpreter.c:324
eval_value at /buildworker/worker/package_linux64/build/src/interpreter.c:430
eval_stmt_value at /buildworker/worker/package_linux64/build/src/interpreter.c:363 [inlined]
eval_body at /buildworker/worker/package_linux64/build/src/interpreter.c:682
jl_interpret_toplevel_thunk_callback at /buildworker/worker/package_linux64/build/src/interpreter.c:806
unknown function (ip: 0xfffffffffffffffe)
unknown function (ip: 0x7f5ce2e2cfaf)
unknown function (ip: 0xffffffffffffffff)
jl_interpret_toplevel_thunk at /buildworker/worker/package_linux64/build/src/interpreter.c:815
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:805
jl_toplevel_eval_flex at /buildworker/worker/package_linux64/build/src/toplevel.c:754
jl_toplevel_eval_in at /buildworker/worker/package_linux64/build/src/builtins.c:622
eval at ./boot.jl:319
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
eval_user_input at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:85
macro expansion at /buildworker/worker/package_linux64/build/usr/share/julia/stdlib/v1.0/REPL/src/REPL.jl:117 [inlined]
#28 at ./task.jl:259
jl_apply_generic at /buildworker/worker/package_linux64/build/src/gf.c:2184
jl_apply at /buildworker/worker/package_linux64/build/src/julia.h:1537 [inlined]
start_task at /buildworker/worker/package_linux64/build/src/task.c:268
unknown function (ip: 0xffffffffffffffff)
Allocations: 4935311 (Pool: 4934051; Big: 1260); GC: 10
[1]    1657 segmentation fault (core dumped)  julia-1.0.3
@fredrikekre fredrikekre added the bug Indicates an unexpected problem or unintended behavior label Jan 17, 2019
@JeffBezanson
Copy link
Sponsor Member

JeffBezanson commented Jan 17, 2019

So far I cannot reproduce this. Might be skylake-related? Edit: indeed, happens on skylake and not ivybridge.

@JeffBezanson
Copy link
Sponsor Member

Crash goes away with -O1. Likely involves the vectorizer.

@JeffBezanson JeffBezanson added the compiler:codegen Generation of LLVM IR and native code label Jan 17, 2019
@aaowens
Copy link

aaowens commented Jan 17, 2019

Haswell too

julia> versioninfo()
Julia Version 1.0.3
Commit 099e826241 (2018-12-18 01:34 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-4810MQ CPU @ 2.80GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.0 (ORCJIT, haswell)

julia> function ifelsetuple(n::Integer, k::Integer, f, g)
           return ntuple(i -> (i <= k ? f : g), n)
       end
ifelsetuple (generic function with 1 method)

julia> f(x) = x^2; g(x) = x^3; ifelsetuple(5, 3, f, g)
(f, f, f, g, g)

julia> a = [1]; b=[2]; ifelsetuple(5, 3, a, b)

signal (11): Segmentation fault
in expression starting at no file:0
_ZN4llvm9LiveRange4joinERS0_PKiS3_RNS_15SmallVectorImplIPNS_6VNInfoEEE at /home/andrew/Programs/julia-1.0.3-linux-x86_64/julia-1.0.3/bin/../lib/julia/libLLVM-6.0.so (unknown line)
...

@ararslan
Copy link
Member

In case it's useful, here's LLDB output of the crash with a debug build of current master with a Skylake processor:

$ lldb -- ./usr/bin/julia-debug -e 'f(n, m, a, b) = ntuple(i->(i <= m ? a : b), n); f(5, 3, [1], [2])'
(lldb) target create "./usr/bin/julia-debug"
Current executable set to './usr/bin/julia-debug' (x86_64).
(lldb) settings set -- target.run-args  "-e" "f(n, m, a, b) = ntuple(i->(i <= m ? a : b), n); f(5, 3, [1], [2])"
(lldb) run
Process 23208 launched: './usr/bin/julia-debug' (x86_64)
Process 23208 stopped
* thread #1, name = 'julia-debug', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
    frame #0: 0x00007ffff4564797 libLLVM-6.0.so`llvm::LiveRange::join(llvm::LiveRange&, int const*, int const*, llvm::SmallVectorImpl<llvm::VNInfo*>&) + 183
libLLVM-6.0.so`llvm::LiveRange::join:
->  0x7ffff4564797 <+183>: movl   (%rdx), %edx
    0x7ffff4564799 <+185>: movslq (%rcx,%rdx,4), %rdx
    0x7ffff456479d <+189>: movq   (%rdi,%rdx,8), %rdx
    0x7ffff45647a1 <+193>: movq   %rdx, -0x18(%rax)
(lldb) thread backtrace
* thread #1, name = 'julia-debug', stop reason = signal SIGSEGV: invalid address (fault address: 0x0)
  * frame #0: 0x00007ffff4564797 libLLVM-6.0.so`llvm::LiveRange::join(llvm::LiveRange&, int const*, int const*, llvm::SmallVectorImpl<llvm::VNInfo*>&) + 183
    frame #1: 0x00007ffff46f10f8 libLLVM-6.0.so`(anonymous namespace)::RegisterCoalescer::joinVirtRegs(llvm::CoalescerPair&) + 2744
    frame #2: 0x00007ffff46f4438 libLLVM-6.0.so`(anonymous namespace)::RegisterCoalescer::copyCoalesceWorkList(llvm::MutableArrayRef<llvm::MachineInstr*>) + 840
    frame #3: 0x00007ffff46f7ae0 libLLVM-6.0.so`(anonymous namespace)::RegisterCoalescer::runOnMachineFunction(llvm::MachineFunction&) + 2896
    frame #4: 0x00007ffff45f4c31 libLLVM-6.0.so`llvm::MachineFunctionPass::runOnFunction(llvm::Function&) + 145
    frame #5: 0x00007ffff43fd771 libLLVM-6.0.so`llvm::FPPassManager::runOnFunction(llvm::Function&) + 769
    frame #6: 0x00007ffff43fd7b1 libLLVM-6.0.so`llvm::FPPassManager::runOnModule(llvm::Module&) + 49
    frame #7: 0x00007ffff43fcf64 libLLVM-6.0.so`llvm::legacy::PassManagerImpl::run(llvm::Module&) + 772
    frame #8: 0x00007ffff763bb5d libjulia-debug.so.1`JuliaOJIT::CompilerT::operator(this=0x0000555555876920, M=0x00005555557d8c60)(llvm::Module&) at jitlayers.cpp:335
    frame #9: 0x00007ffff76433d4 libjulia-debug.so.1`llvm::orc::IRCompileLayer<llvm::orc::RTDyldObjectLinkingLayer, JuliaOJIT::CompilerT>::addModule(this=0x0000555555876918, M=std::__shared_ptr<llvm::Module, 4>::element_type @ 0x00005555557d8c60, Resolver=std::__shared_ptr<llvm::JITSymbolResolver, 4>::element_type @ 0x0000555555b84ca0) at IRCompileLayer.h:57
    frame #10: 0x00007ffff763cc92 libjulia-debug.so.1`JuliaOJIT::addModule(this=0x0000555555875620, M=unique_ptr<llvm::Module, std::default_delete<llvm::Module> > @ 0x00007fffffffb6c0) at jitlayers.cpp:454
    frame #11: 0x00007ffff763da10 libjulia-debug.so.1`::jl_add_to_ee(m=unique_ptr<llvm::Module, std::default_delete<llvm::Module> > @ 0x00007fffffffb710) at jitlayers.cpp:679
    frame #12: 0x00007ffff763daed libjulia-debug.so.1`jl_finalize_function(F=(Data = "jfptr_f_12108", Length = 13)) at jitlayers.cpp:687
    frame #13: 0x00007ffff759b955 libjulia-debug.so.1`::getAddressForFunction(fname=(Data = "jfptr_f_12108", Length = 13)) at codegen.cpp:1281
    frame #14: 0x00007ffff759c130 libjulia-debug.so.1`::jl_generate_fptr(pli=0x00007fffffffba18, decls=(functionObject = "jfptr_f_12108", specFunctionObject = "julia_f_12107"), world=25684) at codegen.cpp:1386
    frame #15: 0x00007ffff74d5bfa libjulia-debug.so.1`jl_compile_method_internal(pli=0x00007fffffffba18, world=25684) at gf.c:1906
    frame #16: 0x00007ffff74d5c5a libjulia-debug.so.1`jl_fptr_trampoline(m=0x00007fffe4dcc890, args=0x00007fffffffbab0, nargs=5) at gf.c:1913
    frame #17: 0x00007ffff74d6df4 libjulia-debug.so.1`jl_apply_generic(args=0x00007fffffffbab0, nargs=5) at gf.c:2269
    frame #18: 0x00007ffff7778294 libjulia-debug.so.1`do_call(args=0x00007fffe4dcc850, nargs=5, s=0x00007fffffffbf90) at interpreter.c:323
    frame #19: 0x00007ffff7778ad7 libjulia-debug.so.1`eval_value(e=0x00007fffe4ceb6b0, s=0x00007fffffffbf90) at interpreter.c:411
    frame #20: 0x00007ffff77785d1 libjulia-debug.so.1`eval_stmt_value(stmt=0x00007fffe4ceb6b0, s=0x00007fffffffbf90) at interpreter.c:362
    frame #21: 0x00007ffff777a654 libjulia-debug.so.1`eval_body(stmts=0x00007fffe4cd75e0, s=0x00007fffffffbf90, ip=2, toplevel=1) at interpreter.c:755
    frame #22: 0x00007ffff777ae33 libjulia-debug.so.1`jl_interpret_toplevel_thunk_callback(s=0x00007fffffffbf90, vargs=0x00007fffffffbff0) at interpreter.c:885
    frame #23: 0x00007ffff74ee29c libjulia-debug.so.1`Lenter_interpreter_frame_start_val at julia_internal.h:350

kalmarek added a commit to kalmarek/PropertyT.jl that referenced this issue Feb 18, 2019
@rlecover007
Copy link

I'm running into this myself. I can get around it by running the code within the Debugger, but that's a less than ideal solution.

Julia Version 1.1.0
Commit 80516ca202 (2019-01-21 21:24 UTC)
Platform Info:
  OS: Linux (x86_64-pc-linux-gnu)
  CPU: Intel(R) Core(TM) i7-6700 CPU @ 3.40GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-6.0.1 (ORCJIT, skylake)

@KristofferC
Copy link
Sponsor Member

Works on master for me. Perhaps you can try a nightly build.

@kalmarek
Copy link
Contributor Author

kalmarek commented Apr 3, 2019

@rlecover007 the simple workaround is to create an array first, then convert to tuple;

@KristofferC great to know!

@rlecover007
Copy link

Thanks! The nightly build works.

@KristofferC
Copy link
Sponsor Member

Should add a test that can close this then.

@KristofferC KristofferC added the good first issue Indicates a good issue for first-time contributors to Julia label Apr 3, 2019
@martinholters
Copy link
Member

Do we know what fixed it and can we backport that to 1.0?

@kalmarek
Copy link
Contributor Author

@KristofferC I can add tests, just tell me in where

is https://github.com/JuliaLang/julia/blob/master/test/compiler/codegen.jl ok?

@kczimm
Copy link
Contributor

kczimm commented Feb 12, 2020

Is this work done? I’m just looking for issues to contribute to but don’t want to reproduce work done.

@KristofferC
Copy link
Sponsor Member

I don't think a test got added so that would still be good to do.

KristofferC added a commit that referenced this issue Jun 23, 2020
JeffBezanson pushed a commit that referenced this issue Jun 25, 2020
mbauman added a commit to dlfivefifty/julia that referenced this issue Jun 26, 2020
* origin/master: (232 commits)
  Add passthrough for non-Markdown docs (JuliaLang#36091)
  Fix pointer to no longer assume contiguity (JuliaLang#36405)
  Ensure string-hashing is defined before it gets used (JuliaLang#36411)
  Make compilecache atomic (JuliaLang#36416)
  add a test for JuliaLang#30739 (JuliaLang#36395)
  Fix broken links in docstring of `repeat` (JuliaLang#36376)
  fix and de-dup cached calls to `methods_by_ftype` in compiler (JuliaLang#36404)
  ml-matches: skip unnecessary work, when possible (JuliaLang#36413)
  gf: fix some issues with the move from using a tree to a hash lookup of leaf types (JuliaLang#36413)
  Add news and manual entry for sincospi (JuliaLang#36403)
  Check axes in Array(::AbstractArray) (fixes JuliaLang#36220) (JuliaLang#36397)
  add versions of `code_typed` and `which` that accept tuple types (JuliaLang#36389)
  Fix spelling of readdir. (JuliaLang#36409)
  add sincospi (JuliaLang#35816)
  fix showing methods with unicode gensymed variable names (JuliaLang#36396)
  Add doctest: eachslice (JuliaLang#36386)
  fix documentation typo ("Ingeger")
  Refactor `abstract_eval` to separate out statements and values (JuliaLang#36350)
  fix return type of `get!` on `IdDict` (JuliaLang#36383)
  Allow single option with REPL.TerminalMenus (JuliaLang#36369)
  ...
simeonschaub pushed a commit to simeonschaub/julia that referenced this issue Aug 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Indicates an unexpected problem or unintended behavior compiler:codegen Generation of LLVM IR and native code good first issue Indicates a good issue for first-time contributors to Julia
Projects
None yet
Development

Successfully merging a pull request may close this issue.

9 participants