AstGen doesn't emit a `ref` ZIR inst if it encounters a dereference `.*` with a reference result location (`ref`/`ref_coerced_ty`/`ref_const`), since the operand of the dereference expression already is a reference. This caused some problems as Zig allows `.*` on both single-item *and* C pointers, but most logic in Sema assumes that everything with a reference rl is always a single-item pointer. This largely didn't cause any issues since C pointers can do everything single-item pointers can, but it caused Sema to mistake `&p.*[0]` with `@TypeOf(p) == [*c][n]T` for an index into a many-item pointer `[*][n]T` instead of a single-item pointer `*[n]T`. To avoid such problems in the future, a pointer obtained from `&p.*` is now always turned into a proper single-item pointer. This is achieved by introducing two new ZIR instructions, `deref` and `ref_deref`: For `ptr.*`: ``` %1 = validate_deref(%ptr) %2 = load(%ptr) ``` vvv ``` %1 = deref(%ptr) ``` For `&ptr.*`: ``` %1 = validate_deref(%ptr) // use %ptr directly ``` vvv ``` %1 = ref_deref(%ptr) // use %1 ``` This makes `validate_deref` superfluous, so it's been removed. Also fixes `node_offset_deref_ptr` source location to actually point to the pointer being dereferenced and uses it to provide better source locs for `deref` and `ref_deref`.
Test Case Quick Reference
Use comments at the end of the file to indicate metadata about the test case. Here are examples of different kinds of tests:
Compile Error Test
If you want it to be run with zig test and match expected error messages:
// error
// is_test=true
//
// :4:13: error: 'try' outside function scope
Execution
This will do zig run on the code and expect exit code 0.
// run
Incremental Compilation
Make multiple files that have ".", and then an integer, before the ".zig" extension, like this:
hello.0.zig
hello.1.zig
hello.2.zig
Each file can be a different kind of test, such as expecting compile errors, or expecting to be run and exit(0). The test harness will use these to simulate incremental compilation.
At the time of writing there is no way to specify multiple files being changed as part of an update.
Subdirectories
Subdirectories do not have any semantic meaning but they can be used for organization since the test harness will recurse into them. The full directory path will be prepended as a prefix on the test case name.
Limiting which Backends and Targets are Tested
// run
// backend=selfhosted,llvm
// target=x86_64-linux,x86_64-macos
Possible backends are:
auto: the default; compiler picks the backend based on robustness.selfhosted: equivalent to passing-fno-llvm -fno-lld.llvm: equivalent to-fllvm.