Skip to content

Commit

Permalink
stage2: fix repeat_inline skipping first instruction in block
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew Kelley <andrew@ziglang.org>
  • Loading branch information
Vexu and andrewrk committed Jun 8, 2021
1 parent 7efd7bc commit d41a510
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
22 changes: 21 additions & 1 deletion src/Sema.zig
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ pub fn analyzeBody(
// directly jump to the next one, rather than detouring through the loop
// continue expression. Related: https://github.com/ziglang/zig/issues/8220
var i: usize = 0;
while (true) : (i += 1) {
while (true) {
const inst = body[i];
const air_inst = switch (tags[inst]) {
// zig fmt: off
Expand Down Expand Up @@ -394,78 +394,97 @@ pub fn analyzeBody(
// putting them into the map.
.breakpoint => {
try sema.zirBreakpoint(block, inst);
i += 1;
continue;
},
.fence => {
try sema.zirFence(block, inst);
i += 1;
continue;
},
.dbg_stmt => {
try sema.zirDbgStmt(block, inst);
i += 1;
continue;
},
.ensure_err_payload_void => {
try sema.zirEnsureErrPayloadVoid(block, inst);
i += 1;
continue;
},
.ensure_result_non_error => {
try sema.zirEnsureResultNonError(block, inst);
i += 1;
continue;
},
.ensure_result_used => {
try sema.zirEnsureResultUsed(block, inst);
i += 1;
continue;
},
.set_eval_branch_quota => {
try sema.zirSetEvalBranchQuota(block, inst);
i += 1;
continue;
},
.store => {
try sema.zirStore(block, inst);
i += 1;
continue;
},
.store_node => {
try sema.zirStoreNode(block, inst);
i += 1;
continue;
},
.store_to_block_ptr => {
try sema.zirStoreToBlockPtr(block, inst);
i += 1;
continue;
},
.store_to_inferred_ptr => {
try sema.zirStoreToInferredPtr(block, inst);
i += 1;
continue;
},
.resolve_inferred_alloc => {
try sema.zirResolveInferredAlloc(block, inst);
i += 1;
continue;
},
.validate_struct_init_ptr => {
try sema.zirValidateStructInitPtr(block, inst);
i += 1;
continue;
},
.validate_array_init_ptr => {
try sema.zirValidateArrayInitPtr(block, inst);
i += 1;
continue;
},
.@"export" => {
try sema.zirExport(block, inst);
i += 1;
continue;
},
.set_align_stack => {
try sema.zirSetAlignStack(block, inst);
i += 1;
continue;
},
.set_cold => {
try sema.zirSetAlignStack(block, inst);
i += 1;
continue;
},
.set_float_mode => {
try sema.zirSetFloatMode(block, inst);
i += 1;
continue;
},
.set_runtime_safety => {
try sema.zirSetRuntimeSafety(block, inst);
i += 1;
continue;
},

Expand Down Expand Up @@ -510,6 +529,7 @@ pub fn analyzeBody(
if (air_inst.ty.isNoReturn())
return always_noreturn;
try map.put(sema.gpa, inst, air_inst);
i += 1;
}
}

Expand Down
21 changes: 21 additions & 0 deletions test/stage2/test.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1475,6 +1475,7 @@ pub fn addCases(ctx: *TestContext) !void {
\\ x += 1;
\\ if (x != 1) unreachable;
\\}
\\pub fn main() void {}
, &.{":4:17: error: unable to resolve comptime value"});

case.addError(
Expand All @@ -1501,5 +1502,25 @@ pub fn addCases(ctx: *TestContext) !void {
\\ if (x != 2) unreachable;
\\}
, "");

case.addCompareOutput(
\\pub fn main() void {
\\ comptime var i: u64 = 2;
\\ inline while (i < 6) : (i+=1) {
\\ print(i);
\\ }
\\}
\\fn print(len: usize) void {
\\ asm volatile ("syscall"
\\ :
\\ : [number] "{rax}" (1),
\\ [arg1] "{rdi}" (1),
\\ [arg2] "{rsi}" (@ptrToInt("Hello")),
\\ [arg3] "{rdx}" (len)
\\ : "rcx", "r11", "memory"
\\ );
\\ return;
\\}
, "HeHelHellHello");
}
}

0 comments on commit d41a510

Please sign in to comment.