Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions TSLANG_ISSUES.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 `<any>undefined` or `<any>null` (`{ t: <any>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 `<any>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
Expand All @@ -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 `<any>undefined` or `<any>null` (`{ t: <any>undefined, n: 1 }`) is
released twice: OwnershipInferencePass does not count the store of its box into the object as a move (a box of
`<any>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 `<any>0` for that reason (its first version was `<any>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<T, void, Box>`) is refused ("'this value'
is a parameter, kept here, but -mm=own cannot make the callers of this function expression give it up"): next()
Expand Down
10 changes: 9 additions & 1 deletion tslang/lib/TypeScript/OwnershipFacts.h
Original file line number Diff line number Diff line change
Expand Up @@ -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: <any>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<mlir_ts::CastOp>())
{
if (mlir::isa<mlir_ts::AnyType, mlir_ts::UnknownType>(castOp.getType()))
{
return false;
}

root = castOp.getIn();
}

Expand Down
4 changes: 4 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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")
Expand Down
24 changes: 24 additions & 0 deletions tslang/test/tester/tests/00any_undefined_field.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// An object literal's field of `<any>undefined` or `<any>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: <any>undefined, n: 1 };
}

function mkNull() {
return { t: <any>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.");
}
Loading