AstGen: fix incorrect handling of source cursor with shift builtins

Closes #13714
This commit is contained in:
Veikka Tuominen 2022-11-30 15:22:34 +02:00
parent 7be6f352e3
commit f4afeb3ffd
3 changed files with 15 additions and 3 deletions

View File

@ -8551,11 +8551,18 @@ fn shiftOp(
rhs_node: Ast.Node.Index,
tag: Zir.Inst.Tag,
) InnerError!Zir.Inst.Ref {
var line = gz.astgen.source_line - gz.decl_line;
var column = gz.astgen.source_column;
const lhs = try expr(gz, scope, .{ .rl = .none }, lhs_node);
maybeAdvanceSourceCursorToMainToken(gz, node);
const line = gz.astgen.source_line - gz.decl_line;
const column = gz.astgen.source_column;
switch (gz.astgen.tree.nodes.items(.tag)[node]) {
.shl, .shr => {
maybeAdvanceSourceCursorToMainToken(gz, node);
line = gz.astgen.source_line - gz.decl_line;
column = gz.astgen.source_column;
},
else => {},
}
const log2_int_type = try gz.addUnNode(.typeof_log2_int_type, lhs, lhs_node);
const rhs = try expr(gz, scope, .{ .rl = .{ .ty = log2_int_type }, .ctx = .shift_op }, rhs_node);

View File

@ -117,6 +117,7 @@ test {
_ = @import("behavior/bugs/13285.zig");
_ = @import("behavior/bugs/13435.zig");
_ = @import("behavior/bugs/13664.zig");
_ = @import("behavior/bugs/13714.zig");
_ = @import("behavior/byteswap.zig");
_ = @import("behavior/byval_arg_var.zig");
_ = @import("behavior/call.zig");

View File

@ -0,0 +1,4 @@
comptime {
var image: [1]u8 = undefined;
_ = @shlExact(@as(u16, image[0]), 8);
}