From a1ee817906deec24c5d3a5033c97d63bc9d372f9 Mon Sep 17 00:00:00 2001 From: Hojun-Cho Date: Wed, 20 May 2026 19:28:59 +0900 Subject: [PATCH] =?UTF-8?q?selfhost/cmd/ww/main.ww:=203=C3=97=20".\0"=20am?= =?UTF-8?q?alloc=20=E2=86=92=20stack=20[2]u8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit dobuild/dorun/dotest each allocated a 2-byte heap "." prefix buffer via amalloc, set dot[0]='.'; dot[1]=0; passed dot as *u8 to a callee, then let the arena chunk live forever. The dot pointer never escapes the function — every callee chain (resolvemodule, cstrendswithlit, rundirtests/runsingletest) byte-copies its input into a fresh arena allocation before returning, never storing the original pointer. Replace with `let dot: [2]u8 = ['.': u8, 0u8]; ... &dot[0]`. Both stages allocate a fresh frame slot per let at function-frame entry (localoff cstage / localadd wwstage), so the slot lives across the synchronous callee. Verified 132/132 + 995_self_rebuild byte-identity. --- selfhost/cmd/ww/main.combined.ww | 15 ++++++--------- selfhost/cmd/ww/main.ww | 15 ++++++--------- 2 files changed, 12 insertions(+), 18 deletions(-) diff --git a/selfhost/cmd/ww/main.combined.ww b/selfhost/cmd/ww/main.combined.ww index db84b3d4..03d6fe1d 100644 --- a/selfhost/cmd/ww/main.combined.ww +++ b/selfhost/cmd/ww/main.combined.ww @@ -2038,9 +2038,8 @@ fn dobuild(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = { if (src == nil) { // default to cwd module - let dot: *u8 = amalloc(a, 2u64): *u8; - dot[0] = 46u8; dot[1] = 0u8; - src = dot; + let dot: [2]u8 = ['.': u8, 0u8]; + src = &dot[0]; }; let isdir: i32 = 0; let resolved: *u8 = resolvemodule(a, selfdir, src, incs, &isdir); @@ -2193,9 +2192,8 @@ fn dorun(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = { }; if (src == nil) { - let dot: *u8 = amalloc(a, 2u64): *u8; - dot[0] = 46u8; dot[1] = 0u8; - src = dot; + let dot: [2]u8 = ['.': u8, 0u8]; + src = &dot[0]; }; let isdir: i32 = 0; let resolved: *u8 = resolvemodule(a, selfdir, src, incs, &isdir); @@ -2331,9 +2329,8 @@ fn dotest(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = { let a: *arena = newarena(); let target: *u8; if (start >= argc) { - let dot: *u8 = amalloc(a, 2u64): *u8; - dot[0] = 46u8; dot[1] = 0u8; - target = dot; + let dot: [2]u8 = ['.': u8, 0u8]; + target = &dot[0]; } else { target = argv[start]; }; diff --git a/selfhost/cmd/ww/main.ww b/selfhost/cmd/ww/main.ww index d17955c4..af5ff430 100644 --- a/selfhost/cmd/ww/main.ww +++ b/selfhost/cmd/ww/main.ww @@ -1178,9 +1178,8 @@ fn dobuild(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = { if (src == nil) { // default to cwd module - let dot: *u8 = amalloc(a, 2u64): *u8; - dot[0] = 46u8; dot[1] = 0u8; - src = dot; + let dot: [2]u8 = ['.': u8, 0u8]; + src = &dot[0]; }; let isdir: i32 = 0; let resolved: *u8 = resolvemodule(a, selfdir, src, incs, &isdir); @@ -1333,9 +1332,8 @@ fn dorun(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = { }; if (src == nil) { - let dot: *u8 = amalloc(a, 2u64): *u8; - dot[0] = 46u8; dot[1] = 0u8; - src = dot; + let dot: [2]u8 = ['.': u8, 0u8]; + src = &dot[0]; }; let isdir: i32 = 0; let resolved: *u8 = resolvemodule(a, selfdir, src, incs, &isdir); @@ -1471,9 +1469,8 @@ fn dotest(selfdir: *u8, argv: **u8, argc: i32, start: i32) i32 = { let a: *arena = newarena(); let target: *u8; if (start >= argc) { - let dot: *u8 = amalloc(a, 2u64): *u8; - dot[0] = 46u8; dot[1] = 0u8; - target = dot; + let dot: [2]u8 = ['.': u8, 0u8]; + target = &dot[0]; } else { target = argv[start]; };