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

Never discard ivar initializer inside .allocate and .pre_initialize #14337

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions spec/primitives/reference_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,28 @@ private class Bar < Base
end
end

private struct Inner
end

private class Outer
@x = Inner.new
end

describe "Primitives: reference" do
describe ".allocate" do
it "doesn't fail on complex ivar initializer if value is discarded (#14325)" do
Outer.allocate
1
end
end

describe ".pre_initialize" do
it "doesn't fail on complex ivar initializer if value is discarded (#14325)" do
bar_buffer = GC.malloc(instance_sizeof(Outer))
Outer.pre_initialize(bar_buffer)
1
end

it "zeroes the instance data" do
bar_buffer = GC.malloc(instance_sizeof(Bar))
Slice.new(bar_buffer.as(UInt8*), instance_sizeof(Bar)).fill(0xFF)
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/crystal/codegen/codegen.cr
Original file line number Diff line number Diff line change
Expand Up @@ -2126,7 +2126,7 @@ module Crystal
context.vars = LLVMVars.new
alloca_vars init.meta_vars

accept init.value
request_value(init.value)

ivar_ptr = instance_var_ptr real_type, init.name, type_ptr
assign ivar_ptr, ivar.type, init.value.type, @last
Expand Down
Loading