#5780·tinygo

go test caching does not track .ll fixtures loaded through go-llvm

Author: davecheneyCreated Sep 28, 2026Updated Sep 28, 2026

go test decides whether a cached PASS is still valid from a log of files the test binary read. That log only records files opened through Go's os package. llvm.NewMemoryBufferFromFile opens the file in C, so the .ll fixture never becomes a cache input: you can edit or corrupt a fixture and go test will keep reporting ok (cached) forever.

The discarded os.Stat(path) next to each fixture load exists solely to register the path with that log.

transform/optimizer_internal_test.go has no such call. Its fixture is not tracked today.

Possible solutions

  1. Give the pattern a name. A helper, ensureCacheFreshness(t *testing.T, path string), that stats the path and fails the test if it is missing. The call site then states its purpose instead of reading as dead code, and the explanation lives in one comment rather than being reconstructed by whoever next meets it. Four call sites across three packages — transform_test, transform (the internal optimizer_internal_test.go) and interp — so it has to be reachable from all three.

  2. Fix go-llvm. Add a NewMemoryBufferFromMemoryRangeCopy binding, then switch the tests to os.ReadFile plus parse-from-bytes and drop the helper entirely. The read goes through os, so caching works with no special pleading, and the discarded os.Stat error becomes a real one on the read. Removes the idiom rather than documenting it, and fixes the class of bug rather than its instances. Requires a go-llvm release and a go.mod bump; v0.0.0-20260721072906 exposes only NewMemoryBufferFromFile and NewMemoryBufferFromStdin.