From 67290faeef877887818dd0c670644c61069cb47b Mon Sep 17 00:00:00 2001 From: ASDAlexander77 Date: Sat, 21 Nov 2026 17:23:46 +0000 Subject: [PATCH] own: undefined / null in an object literal's field is moved in, not released twice own_facts::isConstantData took null or undefined seen through its casts for data nothing owns - a box into `any` included - so checkValueMoves returned before checking the store of `{ t: undefined }`'s box into the object as a move: the store took the box and the temporary's release gave it back too, a double free that wasm's checked heap and Linux caught (Windows did not). A cast into `any` or `unknown` makes a block of its own. Test 00any_undefined_field.ts (compile, JIT, rc, own); TSLANG 153. Co-Authored-By: Claude Opus 5.5 --- TSLANG_ISSUES.md | 11 +++++---- tslang/lib/TypeScript/OwnershipFacts.h | 10 +++++++- tslang/test/tester/CMakeLists.txt | 4 ++++ .../tester/tests/00any_undefined_field.ts | 24 +++++++++++++++++++ 4 files changed, 43 insertions(+), 6 deletions(-) create mode 100644 tslang/test/tester/tests/00any_undefined_field.ts diff --git a/TSLANG_ISSUES.md b/TSLANG_ISSUES.md index 71382e04a..11bdc3475 100644 --- a/TSLANG_ISSUES.md +++ b/TSLANG_ISSUES.md @@ -2186,6 +2186,12 @@ Tests: `00object_dictionary.ts`, `00own_param_exclusive_moves.ts` (compile, JIT, declares them optional (`return?`, `throw?`: a generator declared otherwise has neither) once a compiler with them is released. Under -mm=own a call through an optional one is read as moving the generator, so there a program declaring them required calls them. +- -mm=own: an object literal's field of `undefined` or `null` (`{ t: undefined, n: 1 }`) was + released twice: own_facts::isConstantData took null or undefined seen through its casts for data nothing owns, + a box into `any` included - so the store of the box into the object was not checked as a move, and the + temporary's release gave the box back as well as the object's. wasm's heap caught it ("free of ...: not a block + the heap gave out"), and Linux under -mm=own; Windows did not. A cast into `any` or `unknown` is a block of its + own. (The generator object's `.thrown` holds `0`, from before this was found.) Test `00any_undefined_field.ts`. - Found on the way, generators and `try` (all memory models): - A throw or a call after a resumed yield inside a `try` went past it - its catch did not catch, its finally did not run (`try { yield 1; throw "x"; } catch (e) {...}`: "uncaught exception"). A yield splits the body at its @@ -2202,11 +2208,6 @@ Tests: `00object_dictionary.ts`, `00own_param_exclusive_moves.ts` (compile, JIT, (it crashed in LLVM's instruction selection; before the fixes above the catch did not catch). Still open, looked at: -- -mm=own: an object literal's field of `undefined` or `null` (`{ t: undefined, n: 1 }`) is - released twice: OwnershipInferencePass does not count the store of its box into the object as a move (a box of - `5` it does), so the release at the end of the function stays and the object's release frees the box again. - wasm's heap caught it ("free of ...: not a block the heap gave out"), and Linux under -mm=own; Windows did not. - The generator object's `.thrown` holds `0` for that reason (its first version was `undefined`). - A yield in a finally block is skipped (`try { yield 1; } finally { yield 2; }` gives 1 and not 2), as before. - -mm=own: next(value) of a generator sending it an object (`Generator`) is refused ("'this value' is a parameter, kept here, but -mm=own cannot make the callers of this function expression give it up"): next() diff --git a/tslang/lib/TypeScript/OwnershipFacts.h b/tslang/lib/TypeScript/OwnershipFacts.h index 1aa0fc729..afacf7a14 100644 --- a/tslang/lib/TypeScript/OwnershipFacts.h +++ b/tslang/lib/TypeScript/OwnershipFacts.h @@ -1934,10 +1934,18 @@ inline bool isConstantData(mlir::Value value) } // null or undefined seen as what may hold a block (`on() ? mk(3) : null` as a `Node | null`): - // it holds none + // it holds none - but not one boxed into `any` (or `unknown`) on the way, a block of its own which + // its release frees: taken for constant data, `{ t: undefined }` was not checked for a move, + // so the store into the object took the box and the temporary's release gave it back as well (a + // double free, which wasm's checked heap and Linux caught; TSLANG 153) auto root = value; while (auto castOp = root.getDefiningOp()) { + if (mlir::isa(castOp.getType())) + { + return false; + } + root = castOp.getIn(); } diff --git a/tslang/test/tester/CMakeLists.txt b/tslang/test/tester/CMakeLists.txt index 6288fbd97..471a7a6dd 100644 --- a/tslang/test/tester/CMakeLists.txt +++ b/tslang/test/tester/CMakeLists.txt @@ -471,6 +471,7 @@ tslang_add_test(NAME test-compile-00-generator-typed-yield COMMAND test-runner " tslang_add_test(NAME test-compile-00-object-method-arity COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00object_method_arity.ts") tslang_add_test(NAME test-compile-00-generator-next-value COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_next_value.ts") tslang_add_test(NAME test-compile-00-generator-return-throw COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_return_throw.ts") +tslang_add_test(NAME test-compile-00-any-undefined-field COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00any_undefined_field.ts") tslang_add_test(NAME test-compile-00-constructor-type-value COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00constructor_type_value.ts") tslang_add_test(NAME test-compile-00-string-concat-chain COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00string_concat_chain.ts") tslang_add_test(NAME test-compile-00-arrays COMMAND test-runner "${PROJECT_SOURCE_DIR}/test/tester/tests/00array.ts") @@ -1312,6 +1313,9 @@ tslang_add_test(NAME test-jit-own-00-generator-next-value COMMAND test-runner -j tslang_add_test(NAME test-jit-00-generator-return-throw COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_return_throw.ts") tslang_add_test(NAME test-jit-rc-00-generator-return-throw COMMAND test-runner -jit -mm=rc "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_return_throw.ts") tslang_add_test(NAME test-jit-own-00-generator-return-throw COMMAND test-runner -jit -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00generator_return_throw.ts") +tslang_add_test(NAME test-jit-00-any-undefined-field COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00any_undefined_field.ts") +tslang_add_test(NAME test-jit-rc-00-any-undefined-field COMMAND test-runner -jit -mm=rc "${PROJECT_SOURCE_DIR}/test/tester/tests/00any_undefined_field.ts") +tslang_add_test(NAME test-jit-own-00-any-undefined-field COMMAND test-runner -jit -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00any_undefined_field.ts") tslang_add_test(NAME test-jit-00-constructor-type-value COMMAND test-runner -jit "${PROJECT_SOURCE_DIR}/test/tester/tests/00constructor_type_value.ts") tslang_add_test(NAME test-jit-rc-00-constructor-type-value COMMAND test-runner -jit -mm=rc "${PROJECT_SOURCE_DIR}/test/tester/tests/00constructor_type_value.ts") tslang_add_test(NAME test-jit-own-00-constructor-type-value COMMAND test-runner -jit -mm=own "${PROJECT_SOURCE_DIR}/test/tester/tests/00constructor_type_value.ts") diff --git a/tslang/test/tester/tests/00any_undefined_field.ts b/tslang/test/tester/tests/00any_undefined_field.ts new file mode 100644 index 000000000..89d59503a --- /dev/null +++ b/tslang/test/tester/tests/00any_undefined_field.ts @@ -0,0 +1,24 @@ +// An object literal's field of `undefined` or `null`: the box is a block of its own, which the +// store into the object moves in. Under -mm=own it was taken for constant data (null or undefined seen +// through its casts), so the move was not checked and the temporary's release gave the box back as well +// as the object's: a double free, which wasm's checked heap and Linux caught (TSLANG 153). +function mk() { + return { t: undefined, n: 1 }; +} + +function mkNull() { + return { t: null, n: 2 }; +} + +function main() { + let total = 0; + for (let i = 0; i < 1000; i++) { + const o = mk(); + const p = mkNull(); + total += o.n + p.n; + if (o.t !== undefined || p.t !== null) total = -1000000; + } + + assert(total == 3000, "fields"); + print("done."); +}