diff --git a/src/runtime/compact.cpp b/src/runtime/compact.cpp index 1469a69bd4..4b2f210235 100644 --- a/src/runtime/compact.cpp +++ b/src/runtime/compact.cpp @@ -73,7 +73,12 @@ object_compactor::~object_compactor() { free(m_begin); } -object_offset g_null_offset = reinterpret_cast(static_cast(-1)); +/* + Remark: g_null_offset must NOT be a valid Lean scalar value (e.g., static_cast(-1)). + Recall that Lean scalar are odd size_t values. So, we use (static_cast(-1) - 1) which is an even number. + In the past we used `static_cast(-1)`, and it caused nontermination in the object compactor. +*/ +object_offset g_null_offset = reinterpret_cast(static_cast(-1) - 1); void * object_compactor::alloc(size_t sz) { size_t rem = sz % sizeof(void*); diff --git a/stage0/src/runtime/compact.cpp b/stage0/src/runtime/compact.cpp index 1469a69bd4..4b2f210235 100644 --- a/stage0/src/runtime/compact.cpp +++ b/stage0/src/runtime/compact.cpp @@ -73,7 +73,12 @@ object_compactor::~object_compactor() { free(m_begin); } -object_offset g_null_offset = reinterpret_cast(static_cast(-1)); +/* + Remark: g_null_offset must NOT be a valid Lean scalar value (e.g., static_cast(-1)). + Recall that Lean scalar are odd size_t values. So, we use (static_cast(-1) - 1) which is an even number. + In the past we used `static_cast(-1)`, and it caused nontermination in the object compactor. +*/ +object_offset g_null_offset = reinterpret_cast(static_cast(-1) - 1); void * object_compactor::alloc(size_t sz) { size_t rem = sz % sizeof(void*);