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

Segfault when accessing uninitialized Nullable field #11675

Closed
johnmyleswhite opened this issue Jun 12, 2015 · 4 comments
Closed

Segfault when accessing uninitialized Nullable field #11675

johnmyleswhite opened this issue Jun 12, 2015 · 4 comments
Assignees
Labels
compiler:codegen Generation of LLVM IR and native code regression Regression in behavior compared to a previous version

Comments

@johnmyleswhite
Copy link
Member

johnmylesw-mbp1:julia-0.4 johnmyleswhite$ julia-0.4
               _
   _       _ _(_)_     |  A fresh approach to technical computing
  (_)     | (_) (_)    |  Documentation: http://docs.julialang.org
   _ _   _| |_  __ _   |  Type "help()" for help.
  | | | | | | |/ _` |  |
  | | |_| | | | (_| |  |  Version 0.4.0-dev+5317 (2015-06-11 15:18 UTC)
 _/ |\__'_|_|_|\__'_|  |  Commit b3a7342* (0 days old master)
|__/                   |  x86_64-apple-darwin14.3.0

julia> function Base.(:+){S1, S2}(x::Nullable{S1}, y::Nullable{S2})
           resval = Base.(:+)(x.value, y.value)
           T = typeof(resval)
           if x.isnull || y.isnull
               return Nullable{T}()
           else
               return Nullable{T}(resval)
           end
       end
+ (generic function with 140 methods)

julia> Nullable(1) + Nullable()

signal (11): Segmentation fault: 11
jl_method_table_assoc_exact at /Users/johnmyleswhite/julia-0.4/src/gf.c:261
jl_apply_generic at /Users/johnmyleswhite/julia-0.4/src/gf.c:1604
+ at none:2
jlcall_+_21298 at  (unknown line)
jl_apply at /Users/johnmyleswhite/julia-0.4/src/gf.c:1632
jl_apply at /Users/johnmyleswhite/julia-0.4/src/interpreter.c:55
eval at /Users/johnmyleswhite/julia-0.4/src/interpreter.c:212
jl_toplevel_eval_flex at /Users/johnmyleswhite/julia-0.4/src/toplevel.c:523
jl_toplevel_eval_in at /Users/johnmyleswhite/julia-0.4/src/builtins.c:539
eval_user_input at REPL.jl:62
jlcall_eval_user_input_21269 at  (unknown line)
anonymous at task.jl:91
jl_apply at /Users/johnmyleswhite/julia-0.4/src/task.c:234

Segmentation fault: 11
johnmylesw-mbp1:julia-0.4 johnmyleswhite$ 

Shows up on master right now.

@mbauman
Copy link
Member

mbauman commented Jun 12, 2015

Nullable() defaults to having an element of type Union(), which is probably where this trouble is stemming from. In fact, on a recent build with LLVM-svn, I can't even print Nullable(), which is even more concerning:

julia> Nullable()
Assertion failed: (jl_is_datatype(ty)), function ghostValue, file codegen.cpp, line 2796.

signal (6): Abort trap: 6
__pthread_kill at /usr/lib/system/libsystem_kernel.dylib (unknown line)
Abort trap: 6

@johnmyleswhite
Copy link
Member Author

Yup, the problem does seem to stem from the representation of Union(): the same code won't segfault with a Nullable{Int}() or other sane input.

@yuyichao
Copy link
Contributor

Looks like the codegen pushes a single value (the Int) on in the argument array and then told jl_apply_generic that there are two argument.

@JeffBezanson JeffBezanson self-assigned this Jun 12, 2015
@JeffBezanson JeffBezanson added regression Regression in behavior compared to a previous version compiler:codegen Generation of LLVM IR and native code labels Jun 12, 2015
@johnmyleswhite
Copy link
Member Author

Thanks, Jeff!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler:codegen Generation of LLVM IR and native code regression Regression in behavior compared to a previous version
Projects
None yet
Development

No branches or pull requests

4 participants