Skip to content

Commit 4f31615

Browse files
authored
Make ReferenceStorage(T) non-atomic if T is non-atomic (#14730)
1 parent a63e874 commit 4f31615

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

spec/primitives/pointer_spec.cr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
require "spec"
2+
require "../support/finalize"
3+
require "../support/interpreted"
4+
5+
private class Inner
6+
include FinalizeCounter
7+
8+
def initialize(@key : String)
9+
end
10+
end
11+
12+
private class Outer
13+
@inner = Inner.new("reference-storage")
14+
end
15+
16+
describe "Primitives: pointer" do
17+
describe ".malloc" do
18+
pending_interpreted "is non-atomic for ReferenceStorage(T) if T is non-atomic (#14692)" do
19+
FinalizeState.reset
20+
outer = Outer.unsafe_construct(Pointer(ReferenceStorage(Outer)).malloc(1))
21+
GC.collect
22+
FinalizeState.count("reference-storage").should eq(0)
23+
end
24+
end
25+
end

src/compiler/crystal/codegen/types.cr

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ module Crystal
6969
self.tuple_types.any? &.has_inner_pointers?
7070
when NamedTupleInstanceType
7171
self.entries.any? &.type.has_inner_pointers?
72+
when ReferenceStorageType
73+
self.reference_type.has_inner_pointers?
7274
when PrimitiveType
7375
false
7476
when EnumType

0 commit comments

Comments
 (0)