diff options
| author | mlugg <mlugg@mlugg.co.uk> | 2024-03-01 06:01:53 +0000 |
|---|---|---|
| committer | mlugg <mlugg@mlugg.co.uk> | 2024-03-01 06:01:53 +0000 |
| commit | eefa60e376ba44e163a501143ff44dde445b4bfe (patch) | |
| tree | cf4e1820c2c0cde161ac47fa7be6af5bc8838332 /lib/std | |
| parent | 408a08708fbb0abe03bfeaa835666a72d79c843d (diff) | |
| download | zig-eefa60e376ba44e163a501143ff44dde445b4bfe.tar.gz zig-eefa60e376ba44e163a501143ff44dde445b4bfe.zip | |
AstGen: optimize ZIR for `-1` literal
Diffstat (limited to 'lib/std')
| -rw-r--r-- | lib/std/zig/AstGen.zig | 9 |
1 files changed, 8 insertions, 1 deletions
diff --git a/lib/std/zig/AstGen.zig b/lib/std/zig/AstGen.zig index 0968d85a6a..61ff3413a1 100644 --- a/lib/std/zig/AstGen.zig +++ b/lib/std/zig/AstGen.zig @@ -8458,7 +8458,14 @@ fn numberLiteral(gz: *GenZir, ri: ResultInfo, node: Ast.Node.Index, source_node: try astgen.errNoteTok(num_token, "use '-0.0' for a floating-point signed zero", .{}), }, ), - 1 => .one, + 1 => { + // Handle the negation here! + const result: Zir.Inst.Ref = switch (sign) { + .positive => .one, + .negative => .negative_one, + }; + return rvalue(gz, ri, result, source_node); + }, else => try gz.addInt(num), }, .big_int => |base| big: { |
