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(
147147 // directly jump to the next one, rather than detouring through the loop
148148 // continue expression. Related: https://github.com/ziglang/zig/issues/8220
149149 var i: usize = 0;
150 while (true) : (i += 1) {
150 while (true) {
151151 const inst = body[i];
152152 const air_inst = switch (tags[inst]) {
153153 // zig fmt: off
......@@ -394,78 +394,97 @@ pub fn analyzeBody(
394394 // putting them into the map.
395395 .breakpoint => {
396396 try sema.zirBreakpoint(block, inst);
397 i += 1;
397398 continue;
398399 },
399400 .fence => {
400401 try sema.zirFence(block, inst);
402 i += 1;
401403 continue;
402404 },
403405 .dbg_stmt => {
404406 try sema.zirDbgStmt(block, inst);
407 i += 1;
405408 continue;
406409 },
407410 .ensure_err_payload_void => {
408411 try sema.zirEnsureErrPayloadVoid(block, inst);
412 i += 1;
409413 continue;
410414 },
411415 .ensure_result_non_error => {
412416 try sema.zirEnsureResultNonError(block, inst);
417 i += 1;
413418 continue;
414419 },
415420 .ensure_result_used => {
416421 try sema.zirEnsureResultUsed(block, inst);
422 i += 1;
417423 continue;
418424 },
419425 .set_eval_branch_quota => {
420426 try sema.zirSetEvalBranchQuota(block, inst);
427 i += 1;
421428 continue;
422429 },
423430 .store => {
424431 try sema.zirStore(block, inst);
432 i += 1;
425433 continue;
426434 },
427435 .store_node => {
428436 try sema.zirStoreNode(block, inst);
437 i += 1;
429438 continue;
430439 },
431440 .store_to_block_ptr => {
432441 try sema.zirStoreToBlockPtr(block, inst);
442 i += 1;
433443 continue;
434444 },
435445 .store_to_inferred_ptr => {
436446 try sema.zirStoreToInferredPtr(block, inst);
447 i += 1;
437448 continue;
438449 },
439450 .resolve_inferred_alloc => {
440451 try sema.zirResolveInferredAlloc(block, inst);
452 i += 1;
441453 continue;
442454 },
443455 .validate_struct_init_ptr => {
444456 try sema.zirValidateStructInitPtr(block, inst);
457 i += 1;
445458 continue;
446459 },
447460 .validate_array_init_ptr => {
448461 try sema.zirValidateArrayInitPtr(block, inst);
462 i += 1;
449463 continue;
450464 },
451465 .@"export" => {
452466 try sema.zirExport(block, inst);
467 i += 1;
453468 continue;
454469 },
455470 .set_align_stack => {
456471 try sema.zirSetAlignStack(block, inst);
472 i += 1;
457473 continue;
458474 },
459475 .set_cold => {
460476 try sema.zirSetAlignStack(block, inst);
477 i += 1;
461478 continue;
462479 },
463480 .set_float_mode => {
464481 try sema.zirSetFloatMode(block, inst);
482 i += 1;
465483 continue;
466484 },
467485 .set_runtime_safety => {
468486 try sema.zirSetRuntimeSafety(block, inst);
487 i += 1;
469488 continue;
470489 },
471490
......@@ -510,6 +529,7 @@ pub fn analyzeBody(
510529 if (air_inst.ty.isNoReturn())
511530 return always_noreturn;
512531 try map.put(sema.gpa, inst, air_inst);
532 i += 1;
513533 }
514534}
515535
test/stage2/test.zig+21
......@@ -1475,6 +1475,7 @@ pub fn addCases(ctx: *TestContext) !void {
14751475 \\ x += 1;
14761476 \\ if (x != 1) unreachable;
14771477 \\}
1478 \\pub fn main() void {}
14781479 , &.{":4:17: error: unable to resolve comptime value"});
14791480
14801481 case.addError(
......@@ -1501,5 +1502,25 @@ pub fn addCases(ctx: *TestContext) !void {
15011502 \\ if (x != 2) unreachable;
15021503 \\}
15031504 , "");
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");
15041525 }
15051526}