aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorRobin Voetter <robin@voetter.nl>2021-10-22 01:24:38 +0200
committerAndrew Kelley <andrew@ziglang.org>2021-10-21 20:10:27 -0400
commita3c9bfef301e0a4675fcea57356653334e07df45 (patch)
tree6b5ca8affd586340ebb0f43d9aef8b558671e0f6 /src/Sema.zig
parentd49c601d623d0b5a90f47c95cb931fe21a13d89e (diff)
downloadzig-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/Sema.zig')
-rw-r--r--src/Sema.zig8
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,