authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-07 23:49:28+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2021-06-08 10:15:34+03:00
logd41a5105cd6222564dfe6bad9cff2c445847c6b3
treec62fb79d125919a206a6087d060802d70a1b504a
parent7efd7bc3b8cc403814c0aa62be0a17ff25b33902

stage2: fix repeat_inline skipping first instruction in block

Co-authored-by: Andrew Kelley <andrew@ziglang.org>

2 files changed, 42 insertions(+), 1 deletions(-)

src/Sema.zig+21-1
...@@ -147,7 +147,7 @@ pub fn analyzeBody(...@@ -147,7 +147,7 @@ pub fn analyzeBody(
147 // directly jump to the next one, rather than detouring through the loop147 // directly jump to the next one, rather than detouring through the loop
148 // continue expression. Related: https://github.com/ziglang/zig/issues/8220148 // continue expression. Related: https://github.com/ziglang/zig/issues/8220
149 var i: usize = 0;149 var i: usize = 0;
150 while (true) : (i += 1) {150 while (true) {
151 const inst = body[i];151 const inst = body[i];
152 const air_inst = switch (tags[inst]) {152 const air_inst = switch (tags[inst]) {
153 // zig fmt: off153 // zig fmt: off
...@@ -394,78 +394,97 @@ pub fn analyzeBody(...@@ -394,78 +394,97 @@ pub fn analyzeBody(
394 // putting them into the map.394 // putting them into the map.
395 .breakpoint => {395 .breakpoint => {
396 try sema.zirBreakpoint(block, inst);396 try sema.zirBreakpoint(block, inst);
397 i += 1;
397 continue;398 continue;
398 },399 },
399 .fence => {400 .fence => {
400 try sema.zirFence(block, inst);401 try sema.zirFence(block, inst);
402 i += 1;
401 continue;403 continue;
402 },404 },
403 .dbg_stmt => {405 .dbg_stmt => {
404 try sema.zirDbgStmt(block, inst);406 try sema.zirDbgStmt(block, inst);
407 i += 1;
405 continue;408 continue;
406 },409 },
407 .ensure_err_payload_void => {410 .ensure_err_payload_void => {
408 try sema.zirEnsureErrPayloadVoid(block, inst);411 try sema.zirEnsureErrPayloadVoid(block, inst);
412 i += 1;
409 continue;413 continue;
410 },414 },
411 .ensure_result_non_error => {415 .ensure_result_non_error => {
412 try sema.zirEnsureResultNonError(block, inst);416 try sema.zirEnsureResultNonError(block, inst);
417 i += 1;
413 continue;418 continue;
414 },419 },
415 .ensure_result_used => {420 .ensure_result_used => {
416 try sema.zirEnsureResultUsed(block, inst);421 try sema.zirEnsureResultUsed(block, inst);
422 i += 1;
417 continue;423 continue;
418 },424 },
419 .set_eval_branch_quota => {425 .set_eval_branch_quota => {
420 try sema.zirSetEvalBranchQuota(block, inst);426 try sema.zirSetEvalBranchQuota(block, inst);
427 i += 1;
421 continue;428 continue;
422 },429 },
423 .store => {430 .store => {
424 try sema.zirStore(block, inst);431 try sema.zirStore(block, inst);
432 i += 1;
425 continue;433 continue;
426 },434 },
427 .store_node => {435 .store_node => {
428 try sema.zirStoreNode(block, inst);436 try sema.zirStoreNode(block, inst);
437 i += 1;
429 continue;438 continue;
430 },439 },
431 .store_to_block_ptr => {440 .store_to_block_ptr => {
432 try sema.zirStoreToBlockPtr(block, inst);441 try sema.zirStoreToBlockPtr(block, inst);
442 i += 1;
433 continue;443 continue;
434 },444 },
435 .store_to_inferred_ptr => {445 .store_to_inferred_ptr => {
436 try sema.zirStoreToInferredPtr(block, inst);446 try sema.zirStoreToInferredPtr(block, inst);
447 i += 1;
437 continue;448 continue;
438 },449 },
439 .resolve_inferred_alloc => {450 .resolve_inferred_alloc => {
440 try sema.zirResolveInferredAlloc(block, inst);451 try sema.zirResolveInferredAlloc(block, inst);
452 i += 1;
441 continue;453 continue;
442 },454 },
443 .validate_struct_init_ptr => {455 .validate_struct_init_ptr => {
444 try sema.zirValidateStructInitPtr(block, inst);456 try sema.zirValidateStructInitPtr(block, inst);
457 i += 1;
445 continue;458 continue;
446 },459 },
447 .validate_array_init_ptr => {460 .validate_array_init_ptr => {
448 try sema.zirValidateArrayInitPtr(block, inst);461 try sema.zirValidateArrayInitPtr(block, inst);
462 i += 1;
449 continue;463 continue;
450 },464 },
451 .@"export" => {465 .@"export" => {
452 try sema.zirExport(block, inst);466 try sema.zirExport(block, inst);
467 i += 1;
453 continue;468 continue;
454 },469 },
455 .set_align_stack => {470 .set_align_stack => {
456 try sema.zirSetAlignStack(block, inst);471 try sema.zirSetAlignStack(block, inst);
472 i += 1;
457 continue;473 continue;
458 },474 },
459 .set_cold => {475 .set_cold => {
460 try sema.zirSetAlignStack(block, inst);476 try sema.zirSetAlignStack(block, inst);
477 i += 1;
461 continue;478 continue;
462 },479 },
463 .set_float_mode => {480 .set_float_mode => {
464 try sema.zirSetFloatMode(block, inst);481 try sema.zirSetFloatMode(block, inst);
482 i += 1;
465 continue;483 continue;
466 },484 },
467 .set_runtime_safety => {485 .set_runtime_safety => {
468 try sema.zirSetRuntimeSafety(block, inst);486 try sema.zirSetRuntimeSafety(block, inst);
487 i += 1;
469 continue;488 continue;
470 },489 },
471490
...@@ -510,6 +529,7 @@ pub fn analyzeBody(...@@ -510,6 +529,7 @@ pub fn analyzeBody(
510 if (air_inst.ty.isNoReturn())529 if (air_inst.ty.isNoReturn())
511 return always_noreturn;530 return always_noreturn;
512 try map.put(sema.gpa, inst, air_inst);531 try map.put(sema.gpa, inst, air_inst);
532 i += 1;
513 }533 }
514}534}
515535
test/stage2/test.zig+21
...@@ -1475,6 +1475,7 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1475,6 +1475,7 @@ pub fn addCases(ctx: *TestContext) !void {
1475 \\ x += 1;1475 \\ x += 1;
1476 \\ if (x != 1) unreachable;1476 \\ if (x != 1) unreachable;
1477 \\}1477 \\}
1478 \\pub fn main() void {}
1478 , &.{":4:17: error: unable to resolve comptime value"});1479 , &.{":4:17: error: unable to resolve comptime value"});
14791480
1480 case.addError(1481 case.addError(
...@@ -1501,5 +1502,25 @@ pub fn addCases(ctx: *TestContext) !void {...@@ -1501,5 +1502,25 @@ pub fn addCases(ctx: *TestContext) !void {
1501 \\ if (x != 2) unreachable;1502 \\ if (x != 2) unreachable;
1502 \\}1503 \\}
1503 , "");1504 , "");
1505
1506 case.addCompareOutput(
1507 \\pub fn main() void {
1508 \\ comptime var i: u64 = 2;
1509 \\ inline while (i < 6) : (i+=1) {
1510 \\ print(i);
1511 \\ }
1512 \\}
1513 \\fn print(len: usize) void {
1514 \\ asm volatile ("syscall"
1515 \\ :
1516 \\ : [number] "{rax}" (1),
1517 \\ [arg1] "{rdi}" (1),
1518 \\ [arg2] "{rsi}" (@ptrToInt("Hello")),
1519 \\ [arg3] "{rdx}" (len)
1520 \\ : "rcx", "r11", "memory"
1521 \\ );
1522 \\ return;
1523 \\}
1524 , "HeHelHellHello");
1504 }1525 }
1505}1526}