Skip to content

Commit 9d30535

Browse files
JeffBezansonKristofferC
authored andcommitted
fix #40050, handling fields that are pointers due to subtype circularity (#40095)
(cherry picked from commit e3dffb9)
1 parent ca12dcc commit 9d30535

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

src/cgutils.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,10 @@ static Type *_julia_struct_to_llvm(jl_codegen_params_t *ctx, jl_value_t *jt, jl_
608608
size_t fsz = 0, al = 0;
609609
bool isptr = !jl_islayout_inline(ty, &fsz, &al);
610610
if (jst->layout) {
611-
assert(isptr == jl_field_isptr(jst, i));
611+
// NOTE: jl_field_isptr can disagree with jl_islayout_inline here if the
612+
// struct decided this field must be a pointer due to a type circularity.
613+
// Example from issue #40050: `struct B <: Ref{Tuple{B}}; end`
614+
isptr = jl_field_isptr(jst, i);
612615
assert((isptr ? sizeof(void*) : fsz + jl_is_uniontype(ty)) == jl_field_size(jst, i));
613616
}
614617
Type *lty;

test/core.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7224,6 +7224,11 @@ end
72247224
@test_broken isbitstype(Tuple{B33954})
72257225
@test_broken isbitstype(B33954)
72267226

7227+
struct B40050 <: Ref{Tuple{B40050}}
7228+
end
7229+
@test string((B40050(),)) == "($B40050(),)"
7230+
@test_broken isbitstype(Tuple{B40050})
7231+
72277232
# Issue #34206/34207
72287233
function mre34206(a, n)
72297234
va = view(a, :)

0 commit comments

Comments
 (0)