From 353e31c2648cc4248108091b29f97b9aa3204cba Mon Sep 17 00:00:00 2001 From: zinc Date: Wed, 14 Oct 2026 16:40:29 +0330 Subject: zc0: a store into a local embed array is an error (its elements are in the code); test in tests/test.sh --- tests/programs/zc0embed_write.zc | 9 +++++++++ tests/test.sh | 1 + 2 files changed, 10 insertions(+) create mode 100644 tests/programs/zc0embed_write.zc (limited to 'tests') diff --git a/tests/programs/zc0embed_write.zc b/tests/programs/zc0embed_write.zc new file mode 100644 index 0000000..09686b5 --- /dev/null +++ b/tests/programs/zc0embed_write.zc @@ -0,0 +1,9 @@ +include rt; +// zc0 keeps a local embed array in the code, so it refuses a store into one; the +// resident compiler accepts it (prints 9). tests/test.sh checks zc0's message. +fn main() { + embed "tests/data/embed/bytes.bin" as u8[] b; + b[1] = 9; + rt.put_n(b[1]); rt.put_c(10); + return 0; +} diff --git a/tests/test.sh b/tests/test.sh index 7a80c3c..5b62262 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -82,6 +82,7 @@ GI="-Isrc/core -I$MAP --embed-dir=$T/s1" # it, and the run-only and bare-metal sections read it as the reference. $CC -pthread -O2 -w -fwrapv -DJTYPE=int src/core/core.c src/core/io_linux.c $GI -o $T/zy || exit 1 chk "$($T/zc0 < tests/programs/zc0typed.zc | md5sum)" "$($T/zc0 < tests/programs/zc0plain.zc | md5sum)" "zc0 reads types and throws them away: typed and plain sources give one image" +case "$($T/zc0 < tests/programs/zc0embed_write.zc 2>&1 >/dev/null)" in *"line 6: a local embed array is part of the code"*) chk 1 1 "zc0 refuses a store into a local embed array";; *) chk 0 1 "zc0 refuses a store into a local embed array";; esac for n in $SECS; do mkdir -p $ROOT/$n -- cgit v1.2.3