Skip to content

Commit

Permalink
Prevent update_julia_type from creating a broken cgval_t. (#48426)
Browse files Browse the repository at this point in the history
When then incoming value is a union without any non-ghost component,
we cannot update it with a non-ghost type.
  • Loading branch information
maleadt authored Jan 30, 2023
1 parent 4f92e79 commit 69a966c
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1967,6 +1967,11 @@ static inline jl_cgval_t update_julia_type(jl_codectx_t &ctx, const jl_cgval_t &
Type *T = julia_type_to_llvm(ctx, typ);
if (type_is_ghost(T))
return ghostValue(ctx, typ);
else if (v.TIndex && v.V == NULL) {
// type mismatch (there weren't any non-ghost values in the union)
CreateTrap(ctx.builder);
return jl_cgval_t();
}
return jl_cgval_t(v, typ, NULL);
}

Expand Down
17 changes: 17 additions & 0 deletions test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -804,3 +804,20 @@ function f34459(args...)
return
end
@test !occursin("jl_f_tuple", get_llvm(f34459, Tuple{Ptr{Int}, Type{Int}}, true, false, false))

# issue #48394: incorrectly-inferred getproperty shouldn't introduce invalid cgval_t
# when dealing with unions of ghost values
struct X48394
x::Nothing
y::Bool
end
struct Y48394
x::Nothing
z::Missing
end
function F48394(a, b, i)
c = i ? a : b
c.y
end
@test F48394(X48394(nothing,true), Y48394(nothing, missing), true)
@test occursin("llvm.trap", get_llvm(F48394, Tuple{X48394, Y48394, Bool}))

0 comments on commit 69a966c

Please sign in to comment.