diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-05-12 16:41:20 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-05-12 16:41:20 -0700 |
| commit | c9cc09a3bfb45d93b84577238047cd69ef0a7d88 (patch) | |
| tree | 1686cda92ae0c5d9ae55c02e7755c55d4e6f3c18 /src/Sema.zig | |
| parent | 71afc3088009944fcd8339ac71e69a0b77a781ab (diff) | |
| parent | 40a47eae65b918866abc9d745f89d837f6a1e591 (diff) | |
| download | zig-c9cc09a3bfb45d93b84577238047cd69ef0a7d88.tar.gz zig-c9cc09a3bfb45d93b84577238047cd69ef0a7d88.zip | |
Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgen
Conflicts:
* lib/std/os/linux.zig
* lib/std/os/windows/bits.zig
* src/Module.zig
* src/Sema.zig
* test/stage2/test.zig
Mainly I wanted Jakub's new macOS code for respecting stack size, since
we now depend on it for debug builds able to pass one of the test cases
for recursive comptime function calls with `@setEvalBranchQuota`.
The conflicts were all trivial.
Diffstat (limited to 'src/Sema.zig')
| -rw-r--r-- | src/Sema.zig | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/src/Sema.zig b/src/Sema.zig index cc77b00789..626624110e 100644 --- a/src/Sema.zig +++ b/src/Sema.zig @@ -4606,10 +4606,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) { @@ -4634,6 +4639,13 @@ fn analyzeArithmetic( try Module.floatDiv(sema.arena, scalar_type, src, lhs_val, rhs_val); break :blk val; }, + .mul => blk: { + const val = if (is_int) + try Module.intMul(sema.arena, lhs_val, rhs_val) + else + try Module.floatMul(sema.arena, scalar_type, src, lhs_val, rhs_val); + break :blk val; + }, else => return sema.mod.fail(&block.base, src, "TODO Implement arithmetic operand '{s}'", .{@tagName(zir_tag)}), }; |
