diff options
| author | Justus Klausecker <justus@klausecker.de> | 2025-08-03 13:43:03 +0200 |
|---|---|---|
| committer | Justus Klausecker <justus@klausecker.de> | 2025-08-12 16:33:57 +0200 |
| commit | d0586da18e08d0b8bdc2347fabdc0ba531901641 (patch) | |
| tree | 97ce80427e777a766cb3e3521141325f1b588e3c /src/arch/wasm/CodeGen.zig | |
| parent | 749f10af49022597d873d41df5c600e97e5c4a37 (diff) | |
| download | zig-d0586da18e08d0b8bdc2347fabdc0ba531901641.tar.gz zig-d0586da18e08d0b8bdc2347fabdc0ba531901641.zip | |
Sema: Improve comptime arithmetic undef handling
This commit expands on the foundations laid by https://github.com/ziglang/zig/pull/23177
and moves even more `Sema`-only functionality from `Value`
to `Sema.arith`. Specifically all shift and bitwise operations,
`@truncate`, `@bitReverse` and `@byteSwap` have been moved and
adapted to the new rules around `undefined`.
Especially the comptime shift operations have been basically
rewritten, fixing many open issues in the process.
New rules applied to operators:
* `<<`, `@shlExact`, `@shlWithOverflow`, `>>`, `@shrExact`: compile error if any operand is undef
* `<<|`, `~`, `^`, `@truncate`, `@bitReverse`, `@byteSwap`: return undef if any operand is undef
* `&`, `|`: Return undef if both operands are undef, turn undef into actual `0xAA` bytes otherwise
Additionally this commit canonicalizes the representation of
aggregates with all-undefined members in the `InternPool` by
disallowing them and enforcing the usage of a single typed
`undef` value instead. This reduces the amount of edge cases
and fixes a bunch of bugs related to partially undefined vecs.
List of operations directly affected by this patch:
* `<<`, `<<|`, `@shlExact`, `@shlWithOverflow`
* `>>`, `@shrExact`
* `&`, `|`, `~`, `^` and their atomic rmw + reduce pendants
* `@truncate`, `@bitReverse`, `@byteSwap`
Diffstat (limited to 'src/arch/wasm/CodeGen.zig')
| -rw-r--r-- | src/arch/wasm/CodeGen.zig | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/src/arch/wasm/CodeGen.zig b/src/arch/wasm/CodeGen.zig index b8e48a3842..d8d8933cc3 100644 --- a/src/arch/wasm/CodeGen.zig +++ b/src/arch/wasm/CodeGen.zig @@ -3131,7 +3131,7 @@ fn lowerConstant(cg: *CodeGen, val: Value, ty: Type) InnerError!WValue { const zcu = pt.zcu; assert(!isByRef(ty, zcu, cg.target)); const ip = &zcu.intern_pool; - if (val.isUndefDeep(zcu)) return cg.emitUndefined(ty); + if (val.isUndef(zcu)) return cg.emitUndefined(ty); switch (ip.indexToKey(val.ip_index)) { .int_type, |
