stage2: fix typo in liveness; add comptime switch test

master
Vexu 2020-10-30 15:57:18 +02:00
parent 4ed2c52fb7
commit 22ec5e0859
No known key found for this signature in database
GPG Key ID: 59AEB8936E16A6AC
2 changed files with 39 additions and 1 deletions

View File

@ -189,7 +189,8 @@ fn analyzeInst(
for (case_tables) |*ct_inner, j| {
if (i == j) continue;
if (!ct_inner.contains(case_death)) {
try case_deaths[i].append(case_death);
// instruction is not referenced in this case
try case_deaths[j].append(case_death);
}
}
// undo resetting the table

View File

@ -974,6 +974,43 @@ pub fn addCases(ctx: *TestContext) !void {
,
"hello\nhello\nhello\nhello\nhello\n",
);
// comptime switch
// Basic for loop
case.addCompareOutput(
\\pub export fn _start() noreturn {
\\ assert(foo() == 1);
\\ exit();
\\}
\\
\\fn foo() u32 {
\\ const a: comptime_int = 1;
\\ var b: u32 = 0;
\\ switch (a) {
\\ 1 => b = 1,
\\ 2 => b = 2,
\\ else => unreachable,
\\ }
\\ return b;
\\}
\\
\\pub fn assert(ok: bool) void {
\\ if (!ok) unreachable; // assertion failure
\\}
\\
\\fn exit() noreturn {
\\ asm volatile ("syscall"
\\ :
\\ : [number] "{rax}" (231),
\\ [arg1] "{rdi}" (0)
\\ : "rcx", "r11", "memory"
\\ );
\\ unreachable;
\\}
,
"",
);
}
{