Skip to content

Commit

Permalink
Check whether all fields of a mutable struct are defined before SROA
Browse files Browse the repository at this point in the history
For now, just bail out in this situation. There's a number of better
things we could do here. However, I want to avoid making JuliaLang#26764 worse
for now.

Fixes JuliaLang#27365
  • Loading branch information
Keno committed Jun 8, 2018
1 parent 917ae8b commit c8230b8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -696,6 +696,18 @@ function getfield_elim_pass!(ir::IRCode, domtree)
push!(fielddefuse[field].defs, use)
end
ok || continue
# Check that the defexpr has defined values for all the fields
# we're accessing. In the future, we may want to relax this,
# but we should come up with semantics for well defined semantics
# for uninitialized fields first.
for (fidx, du) in pairs(fielddefuse)
isempty(du.uses) && continue
if fidx + 1 > length(defexpr.args)
ok = false
break
end
end
ok || continue
preserve_uses = IdDict{Int, Vector{Any}}((idx=>Any[] for idx in IdSet{Int}(defuse.ccall_preserve_uses)))
# Everything accounted for. Go field by field and perform idf
for (fidx, du) in pairs(fielddefuse)
Expand Down
13 changes: 13 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6170,3 +6170,16 @@ translate27368(name::Symbol) =
translate27368(::Type{Val{name}}) where {name} =
field27368(name)
@test isa(translate27368(:name), Combinator27368)

# issue #27365
mutable struct foo27365
x::Float64
foo27365() = new()
end

function baz27365()
data = foo27365()
return data.x
end

@test isa(baz27365(), Float64)

0 comments on commit c8230b8

Please sign in to comment.