2
votes

I am new to Julia and I am really surprised by the behavior of the following code.

using Random, Distributions

function get_a(a, b)
        if b == 1
        a = rand(Dirichlet([1,1]),1)'
        end
        return a
end

function test()
        a = get_a([0 0] ,1)
        println("a[2]  = ", a[2])
        t = a[2]
end

c = test()

I get the following errors when running this code.

Illegal inttoptr
      %26 = ptrtoint %jl_value_t addrspace(10)* %20 to i64, !dbg !89
Illegal inttoptr
      %27 = inttoptr i64 %26 to i64 addrspace(13)*, !dbg !89

signal (6): Aborted
in expression starting at /some_path//test.jl:16
gsignal at /usr/bin/../lib/x86_64-linux-gnu/libc.so.6 (unknown line)
abort at /usr/bin/../lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x7f7614d76d04)
_ZN4llvm13FPPassManager13runOnFunctionERNS_8FunctionE at /usr/bin/../lib/x86_64-linux-gnu/libLLVM-8.so.1 (unknown line)
_ZN4llvm13FPPassManager11runOnModuleERNS_6ModuleE at /usr/bin/../lib/x86_64-linux-gnu/libLLVM-8.so.1 (unknown line)
_ZN4llvm6legacy15PassManagerImpl3runERNS_6ModuleE at /usr/bin/../lib/x86_64-linux-gnu/libLLVM-8.so.1 (unknown line)
unknown function (ip: 0x7f7614e60ac1)
unknown function (ip: 0x7f7614e632d8)
unknown function (ip: 0x7f7614e638cd)
unknown function (ip: 0x7f7614d9eb4a)
unknown function (ip: 0x7f7614dd0082)
unknown function (ip: 0x7f7614df584b)
jl_apply_generic at /usr/bin/../lib/x86_64-linux-gnu/libjulia.so.1 (unknown line)
unknown function (ip: 0x7f7614e0875b)
unknown function (ip: 0x7f7614e08389)
unknown function (ip: 0x7f7614e088f0)
unknown function (ip: 0x7f7614e099c8)
unknown function (ip: 0x7f7614e0a616)
unknown function (ip: 0x7f7614e22e08)
unknown function (ip: 0x7f7614dfe105)
jl_load at /usr/bin/../lib/x86_64-linux-gnu/libjulia.so.1 (unknown line)
include at ./Base.jl:377
exec_options at ./client.jl:288
_start at ./client.jl:484
jfptr__start_2075.clone_1 at /usr/lib/x86_64-linux-gnu/julia/sys.so (unknown line)
unknown function (ip: 0x55dde18589d9)
unknown function (ip: 0x55dde18585a6)
__libc_start_main at /usr/bin/../lib/x86_64-linux-gnu/libc.so.6 (unknown line)
unknown function (ip: 0x55dde185864d)
Allocations: 6718336 (Pool: 6716442; Big: 1894); GC: 6
Aborted (core dumped)

These errors go away if I comment out the "if", "return", "t =", or "println" statements. I am aware of the method mismatch issue where "[0 0]" that goes into the "get_a" function are of integer type and "a" returned by "rand()" function is of float type. However, I would expect the code to return a method mismatch error instead of the cryptic error messages above. I really do not understand why commenting out some of the statements removes these errors. Thank you for your help.

P.S. The result of executing versioninfo() in Julia REPL produces the following output:

Julia Version 1.4.1
Platform Info:
  OS: Linux (x86_64-linux-gnu)
  CPU: Intel(R) Core(TM) i5-8350U CPU @ 1.70GHz
  WORD_SIZE: 64
  LIBM: libopenlibm
  LLVM: libLLVM-8.0.1 (ORCJIT, skylake)
1
In newer Julia version this just works OK (tried on 1.6.0 beta).Przemyslaw Szufel
This gives me as well no errors for Julia 1.5.2. You can try shrinking down the Problem with Debugger.jl? Maybe also @code_llvm test() can help you understand the problem better.Oskar
I still had a copy of v1.4.2 installed and just tried this and didn't get any errors either. Have you double-checked that you get the error message when you paste the code snippet into an completely fresh REPL session?Colin T Bowers
@ColinTBowers, I did try pasting this code into julia REPL and the error persists. Julia basically crashes after throwing this error. Also, I am using a completely fresh install of Ubuntu, so I am not sure if this is because I am missing a library or something. If the error messages were not this cryptic, I would have tried to figure out myself. I am not a computer science expert, so it is a little difficult for me. Thank you.singularity
@singularity The reason the message is cryptic is because it doesn't look (to me) as if it is being generated by Julia but rather Julia is passing on error information from something else. FYI, the core devs usually regard any segfault as a bug, but if it can't be reproduced on systems other than your own and if it is also working fine on 1.5.3 then it probably won't be investigated. Could be as simple as a corrupted library that got a fresh install with the latest version. Unless you have a specific reason to need v1.4.1 I'd just forget about things and move forward :-)Colin T Bowers

1 Answers

0
votes

Moving to Julia 1.5 fixed the issue.