mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Allow "if (try foo())"."
This commit is contained in:
49
test/test_suite/errors/try_expr.c3t
Normal file
49
test/test_suite/errors/try_expr.c3t
Normal 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
|
||||
}
|
||||
Reference in New Issue
Block a user