Allow "if (try foo())"."

This commit is contained in:
Christoffer Lerno
2023-08-13 18:15:20 +02:00
parent c060569599
commit e22afe5424
4 changed files with 66 additions and 4 deletions

View File

@@ -0,0 +1,49 @@
// #target: macos-x64
module foo;
import std::io;
fn void main()
{
int a;
if (try foo())
{
a--;
}
else
{
a++;
}
}
fn void! foo() {}
/* #expect: foo.ll
define void @foo.main() #0 {
entry:
%a = alloca i32, align 4
store i32 0, ptr %a, align 4
%0 = call i64 @foo.foo()
%not_err = icmp eq i64 %0, 0
%1 = call i1 @llvm.expect.i1(i1 %not_err, i1 true)
br i1 %1, label %after_check, label %catch_landing
after_check: ; preds = %entry
br label %phi_try_catch
catch_landing: ; preds = %entry
br label %phi_try_catch
phi_try_catch: ; preds = %catch_landing, %after_check
%val = phi i1 [ true, %after_check ], [ false, %catch_landing ]
br i1 %val, label %if.then, label %if.else
if.then: ; preds = %phi_try_catch
%2 = load i32, ptr %a, align 4
%sub = sub i32 %2, 1
store i32 %sub, ptr %a, align 4
br label %if.exit
if.else: ; preds = %phi_try_catch
%3 = load i32, ptr %a, align 4
%add = add i32 %3, 1
store i32 %add, ptr %a, align 4
br label %if.exit
if.exit: ; preds = %if.else, %if.then
ret void
}