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
7 changes: 7 additions & 0 deletions tslang/lib/TypeScript/MLIRGenImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -6192,6 +6192,13 @@ class MLIRGenImpl
else
{
LLVM_DEBUG(dbgs() << "\n!! left expr.: " << leftExpressionValueBeforeCast << " ...\n";);
// `p[i]` of a `Ref<T>` is the reference to the element (as a read gives it), not the element
if (leftExpressionValueBeforeCast.getDefiningOp<mlir_ts::PointerOffsetRefOp>())
{
emitError(location, "indexing a 'Ref<T>' gives a reference to the element; store through it with 'Deref(p[i]) = value'");
return mlir::failure();
}

emitError(location, "saving to constant object");
return mlir::failure();
}
Expand Down
10 changes: 10 additions & 0 deletions tslang/test/tester/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2699,6 +2699,16 @@ add_test(NAME test-compile-integer-literal-truncation-quiet
set_tests_properties(test-compile-integer-literal-truncation-quiet
PROPERTIES FAIL_REGULAR_EXPRESSION "warning:|error:|Stack dump|Assertion failed")

# A store to an indexed Ref<T> (`bytes[i] = x`) names the form that stores, `Deref(bytes[i]) = x`,
# instead of "saving to constant object".
add_test(NAME test-compile-ref-index-store
COMMAND $<TARGET_FILE:tslang> --emit=obj --no-default-lib -mm=none
"${PROJECT_SOURCE_DIR}/test/tester/ref-index-store/store.ts"
-o "${CMAKE_CURRENT_BINARY_DIR}/ref-index-store.obj")
set_tests_properties(test-compile-ref-index-store
PROPERTIES PASS_REGULAR_EXPRESSION "store\\.ts:8:5: error: indexing a 'Ref<T>' gives a reference to the element; store through it with 'Deref\\(p\\[i\\]\\) = value'"
FAIL_REGULAR_EXPRESSION "Stack dump|Assertion failed")

# A number, string, boolean or array passed where an interface with members is expected is an
# error; it compiled to a cast lowering could not make, and the callee read garbage. An interface
# without members still takes any value.
Expand Down
9 changes: 9 additions & 0 deletions tslang/test/tester/ref-index-store/store.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Indexing a Ref<T> gives the element's reference, as a read does (`Deref(bytes[i])`), so a store
// to it is an error that names the form that stores: `Deref(bytes[i]) = value`.
type Str = [buf: [_0: u64, _1: u64], size: index];

function main() {
let value: Str = [[0, 0], 0];
let bytes = <Ref<u8>><Opaque>Ref(value);
bytes[0] = 65;
}
Loading