From 763c8d3a428994f7474a8234497936aed0438e6b Mon Sep 17 00:00:00 2001 From: bymehul Date: Wed, 11 Mar 2026 03:04:26 +0530 Subject: [PATCH] Fix generic cycle deadlock in struct layout --- src/types.cpp | 5 +++-- tests/issues/run.bat | 1 + tests/issues/run.sh | 6 ++++++ tests/issues/test_issue_6401.odin | 16 ++++++++++++++++ 4 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 tests/issues/test_issue_6401.odin diff --git a/src/types.cpp b/src/types.cpp index 0ecce1adc..b11e95452 100644 --- a/src/types.cpp +++ b/src/types.cpp @@ -4201,8 +4201,9 @@ gb_internal i64 type_align_of_internal(Type *t, TypePath *path) { if (t->Struct.is_packed) { return 1; } - - type_set_offsets(t); + // Avoid forcing offset computation here. The caller's type-path state must + // be able to detect recursive field cycles before any nested struct tries to + // re-enter this struct's offset mutex. i64 max = 1; for_array(i, t->Struct.fields) { diff --git a/tests/issues/run.bat b/tests/issues/run.bat index 9e722886d..3db9d48c2 100644 --- a/tests/issues/run.bat +++ b/tests/issues/run.bat @@ -31,6 +31,7 @@ set COMMON=-define:ODIN_TEST_FANCY=false -file -vet -strict-style -ignore-unused ..\..\..\odin test ..\test_issue_6101.odin %COMMON% || exit /b ..\..\..\odin test ..\test_issue_6165.odin %COMMON% || exit /b ..\..\..\odin build ..\test_issue_6240.odin %COMMON% 2>&1 | find /c "Error:" | findstr /x "3" || exit /b +..\..\..\odin build ..\test_issue_6401.odin %COMMON% 2>&1 | find /c "Error:" | findstr /x "3" || exit /b @echo off diff --git a/tests/issues/run.sh b/tests/issues/run.sh index e2e45dbfa..01e6a6a28 100755 --- a/tests/issues/run.sh +++ b/tests/issues/run.sh @@ -43,6 +43,12 @@ else echo "SUCCESSFUL 0/1" exit 1 fi +if [[ $($ODIN build ../test_issue_6401.odin $COMMON 2>&1 >/dev/null | grep -c "Error:") -eq 3 ]] ; then + echo "SUCCESSFUL 1/1" +else + echo "SUCCESSFUL 0/1" + exit 1 +fi set +x popd diff --git a/tests/issues/test_issue_6401.odin b/tests/issues/test_issue_6401.odin new file mode 100644 index 000000000..0f7cd58b6 --- /dev/null +++ b/tests/issues/test_issue_6401.odin @@ -0,0 +1,16 @@ +// Tests issue #6401 https://github.com/odin-lang/Odin/issues/6401 +package test_issues + +Wrapper :: struct(T: typeid) { + value: T, +} + +A :: struct { + value: Wrapper(B), +} + +B :: struct { + value: A, +} + +main :: proc() {}