Commit 613f39eb62

gracefu <81774659+gracefuu@users.noreply.github.com>
2021-04-10 08:01:09
stage2 x86_64: fix comptime integer multiplication when rhs=0
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
1 parent c4b83ea
Changed files (1)
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) {