From 613f39eb622d341d036ef418b19778d1f04d5a47 Mon Sep 17 00:00:00 2001 From: gracefu <81774659+gracefuu@users.noreply.github.com> Date: Sat, 10 Apr 2021 14:01:09 +0800 Subject: [PATCH] stage2 x86_64: fix comptime integer multiplication when rhs=0 Co-authored-by: joachimschmidt557 --- src/Sema.zig | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/Sema.zig b/src/Sema.zig index 74af84b078..65a196911e 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -3864,10 +3864,15 @@ fn analyzeArithmetic( // incase rhs is 0, simply return lhs without doing any calculations // TODO Once division is implemented we should throw an error when dividing by 0. if (rhs_val.compareWithZero(.eq)) { - return sema.mod.constInst(sema.arena, src, .{ - .ty = scalar_type, - .val = lhs_val, - }); + switch (zir_tag) { + .add, .addwrap, .sub, .subwrap => { + return sema.mod.constInst(sema.arena, src, .{ + .ty = scalar_type, + .val = lhs_val, + }); + }, + else => {}, + } } const value = switch (zir_tag) {