diff options
| author | Robin Voetter <robin@voetter.nl> | 2021-10-22 01:24:38 +0200 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-10-21 20:10:27 -0400 |
| commit | a3c9bfef301e0a4675fcea57356653334e07df45 (patch) | |
| tree | 6b5ca8affd586340ebb0f43d9aef8b558671e0f6 /src | |
| parent | d49c601d623d0b5a90f47c95cb931fe21a13d89e (diff) | |
| download | zig-a3c9bfef301e0a4675fcea57356653334e07df45.tar.gz zig-a3c9bfef301e0a4675fcea57356653334e07df45.zip | |
stage2: truncation
* Also fixes a related case where big int truncate would assume that the
input fits in the output limbs buffer
Diffstat (limited to 'src')
| -rw-r--r-- | src/Sema.zig | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index b01e4539b0..b76274c446 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -9477,14 +9477,18 @@ fn zirTruncate(sema: *Sema, block: *Block, inst: Zir.Inst.Index) CompileError!Ai } const target = sema.mod.getTarget(); - const src_info = operand_ty.intInfo(target); const dest_info = dest_ty.intInfo(target); - if (src_info.bits == 0 or dest_info.bits == 0) { + if (dest_info.bits == 0) { return sema.addConstant(dest_ty, Value.zero); } if (!src_is_comptime_int) { + const src_info = operand_ty.intInfo(target); + if (src_info.bits == 0) { + return sema.addConstant(dest_ty, Value.zero); + } + if (src_info.signedness != dest_info.signedness) { return sema.fail(block, operand_src, "expected {s} integer type, found '{}'", .{ @tagName(dest_info.signedness), operand_ty, |
