aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorgracefu <81774659+gracefuu@users.noreply.github.com>2021-04-10 14:01:09 +0800
committergracefu <81774659+gracefuu@users.noreply.github.com>2021-04-16 15:21:17 +0800
commit613f39eb622d341d036ef418b19778d1f04d5a47 (patch)
tree6218de38f6206c0f3d278fdcc975001fdc0e9a39 /src/Sema.zig
parentc4b83ea02102611a85f75b189f0803d9b6a335c2 (diff)
downloadzig-613f39eb622d341d036ef418b19778d1f04d5a47.tar.gz
zig-613f39eb622d341d036ef418b19778d1f04d5a47.zip
stage2 x86_64: fix comptime integer multiplication when rhs=0
Co-authored-by: joachimschmidt557 <joachim.schmidt557@outlook.com>
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig13
1 files 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) {