aboutsummaryrefslogtreecommitdiff
path: root/test/cases/safety
AgeCommit message (Collapse)Author
2025-09-16test: rename backend=stage2 to backend=selfhosted, and add backend=autoAlex Rønne Petersen
backend=auto (now the default if backend is omitted) means to let the compiler pick whatever backend it wants as the default. This is important for platforms where we don't yet have a self-hosted backend, such as loongarch64. Also purge a bunch of redundant target=native.
2025-07-26aarch64: implement some safety checksJacob Young
Closes #24553
2025-07-19tests: remove more old async testsmlugg
The rejection of #6025 indicates that if stackless coroutines return to Zig, they will look quite different; see #23446 for the working draft proposal for their return (though it will definitely be tweaked before being accepted). Some of this test coverage was deleted in 40d11cc, but because stackless coroutines will take on a new form if re-introduced, I anticipate that essentially *none* of this coverage will be relevant. Of course, if it for some reason is, we can always grab it from the Git history.
2025-07-07fix test case expected float valueAndrew Kelley
it's better now
2025-07-07remove `async` and `await` keywordsAndrew Kelley
Also remove `@frameSize`, closing #3654. While the other machinery might remain depending on #23446, it is settled that there will not be `async`/ `await` keywords in the language.
2025-06-29Sema: correct OPV for optional empty error setAndrew Kelley
prevents crashes in backends; improves codegen; provides more comptime-ness.
2025-06-15compiler: fix `@intFromFloat` safety checkmlugg
This safety check was completely broken; it triggered unchecked illegal behavior *in order to implement the safety check*. You definitely can't do that! Instead, we must explicitly check the boundaries. This is a tiny bit fiddly, because we need to make sure we do floating-point rounding in the correct direction, and also handle the fact that the operation truncates so the boundary works differently for min vs max. Instead of implementing this safety check in Sema, there are now dedicated AIR instructions for safety-checked intfromfloat (two instructions; which one is used depends on the float mode). Currently, no backend directly implements them; instead, a `Legalize.Feature` is added which expands the safety check, and this feature is enabled for all backends we currently test, including the LLVM backend. The `u0` case is still handled in Sema, because Sema needs to check for that anyway due to the comptime-known result. The old safety check here was also completely broken and has therefore been rewritten. In that case, we just check for 'abs(input) < 1.0'. I've added a bunch of test coverage for the boundary cases of `@intFromFloat`, both for successes (in `test/behavior/cast.zig`) and failures (in `test/cases/safety/`). Resolves: #24161
2025-06-01compiler: combine `@intCast` safety checksmlugg
`castTruncatedData` was a poorly worded error (all shrinking casts "truncate bits", it's just that we assume those bits to be zext/sext of the other bits!), and `negativeToUnsigned` was a pointless distinction which forced the compiler to emit worse code (since two separate safety checks were required for casting e.g. 'i32' to 'u16') and wasn't even implemented correctly. This commit combines those safety panics into one function, `integerOutOfBounds`. The name maybe isn't perfect, but that's not hugely important; what matters is the new default message, which is clearer than the old ones: "integer does not fit in destination type".
2025-06-01Legalize: implement scalarization of overflow intrinsicsJacob Young
2025-04-27make `@memcpy` and `@memmove` share panic handlersAndrew Kelley
2025-04-26test: add tests for @memmovedweiller
2025-04-26test: add error return to memcpy_len_mismatch and memcpy_aliasdweiller
2025-03-05Remove uses of deprecated callconv aliasesLinus Groh
2025-02-23Sema: allow `@ptrCast` of slices changing the lengthmlugg
Also, refactor `Sema.ptrCastFull` to not be a horrifying hellscape.
2025-02-15x86_64: rewrite scalar and vector int `@rem`Jacob Young
2025-02-15x86_64: rewrite scalar and vector int `@divTrunc`Jacob Young
2025-02-15x86_64: implement error set and enum safetyJacob Young
This is all of the expected 0.14.0 progress on #21530, which can now be postponed once this commit is merged. This required rewriting the (un)wrap operations since the original implementations were extremely buggy. Also adds an easy way to retrigger Sema OPV bugs so that I don't have to keep updating #22419 all the time.
2025-01-30compiler: add `intcast_safe` AIR instructionmlugg
This instruction is like `intcast`, but includes two safety checks: * Checks that the int is in range of the destination type * If the destination type is an exhaustive enum, checks that the int is a named enum value This instruction is locked behind the `safety_checked_instructions` backend feature; if unsupported, Sema will emit a fallback, as with other safety-checked instructions. This instruction is used to add a missing safety check for `@enumFromInt` truncating bits. This check also has a fallback for backends which do not yet support `safety_checked_instructions`. Resolves: #21946
2024-12-29fix slice of slice with sentinel on the lhs sliceTechatrix
example: ```zig test { var foo: [2:0]u8 = .{ 1, 2 }; _ = foo[0.. :1][0..2]; } ``` A `.slice_open` ast node will not have a end index nor sentinel.
2024-09-25disallow non-scalar sentinel typesAndrew Kelley
see #17969
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-03-20Revert the last two commits in this branchAndrew Kelley
When the slice-by-length start position is runtime-known, it is likely protected by a runtime-known condition and therefore a compile error is less appropriate than a runtime panic check. This is demonstrated in the json code that was updated and then reverted in this commit. When #3806 is implemented, this decision can be reassessed. Revert "std: work around compiler unable to evaluate condition at compile time" Revert "frontend: comptime array slice-by-length OOB detection" This reverts commit 7741aca96c8cc6df7e8c4bd10ada741d6a3ffb9d. This reverts commit 2583b389eaf5f7aaa0eb79b51126506c1e172d15.
2024-03-20frontend: comptime array slice-by-length OOB detectionAndrew Kelley
2024-03-20frontend: add missing bounds check for slice-by-length arraysAndrew Kelley
closes #18382
2024-03-19fix compilation failures found by CIAndrew Kelley
2024-03-09std.fmt: fix std-cases and perform round-trip check in ryu unit testsMarc Tiehuis
2024-02-20Liveness: do not elide safety-checked instructionsmlugg
Resolves: #19012
2024-01-13Revert "Merge pull request #18410 from dweiller/by-length-slice-bug"Andrew Kelley
This reverts commit d9d840a33ac8abb0e616de862f592821a7f4a35e, reversing changes made to a04d4330945565b8d6f298ace993f6954c42d0f3. This is not an adequate implementation of the missing safety check, as evidenced by the changes to std.json that are reverted in this commit. Reopens #18382 Closes #18510
2023-12-31sema: add compile error for OOB by-length slice of arraydweiller
2023-11-19test: update cases to silence 'var is never mutated' errorsmlugg
2023-10-03Sema: fix issues in `@errorCast` with error unionsVeikka Tuominen
2023-10-01Sema: add `@errorCast` which works for both error sets and error unionsVeikka Tuominen
Closes #17343
2023-07-12Update tests to new splat syntaxantlilja
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-05-16add runtime safety for noreturn function returningVeikka Tuominen
Closes #15221
2023-04-25update test cases for new memcpy/memset semanticsAndrew Kelley
2023-04-25Sema: implement comptime `@memset`Andrew Kelley
2023-04-23Sema: emit cast to null panics for function pointersVeikka Tuominen
Closes #14676
2023-02-18add safety test cases for multi-object for loopsAndrew Kelley
2022-11-29Sema: improve safety panic for access of inactive union fieldVeikka Tuominen
2022-11-29Sema: improve panic for slice start index being greater than end indexVeikka Tuominen
Closes #13689
2022-10-07safety: add safety check for hitting else branch on a corrupt enum valueVeikka Tuominen
Closes #7053
2022-09-20std: add return address parameter to panic fnVeikka Tuominen
2022-09-20safety: show error return trace when unwrapping error in switchVeikka Tuominen
2022-08-19make self-hosted the default compilerAndrew Kelley
stage1 is available behind the -fstage1 flag. closes #89
2022-08-12stage2: check for zero in `@intToError` safetyVeikka Tuominen
2022-08-06Merge pull request #12337 from Vexu/stage2-safetyAndrew Kelley
Stage2: implement remaining runtime safety checks
2022-08-05Sema: elide safety of modulus and remainder division sometimesAndrew Kelley
Piggybacking on 40f8f0134f5da9baaefd0fdab529d5585fa46199, remainder division, modulus, and `%` syntax no longer emit safety checks for a comptime-known denominator.
2022-08-05stage2: add runtime safety for invalid enum valuesVeikka Tuominen