Files
c3c/test/test_suite/errors/or_and_rethrow.c3t
2023-02-04 19:48:42 +01:00

284 lines
9.0 KiB
C

// #target: macos-x64
module foo;
import std::io;
fault Foo { ABC }
fn void blurb() { io::printn("Blurb");}
macro int! tester()
{
defer blurb();
return Foo.ABC!;
}
fn void! test(int x)
{
io::printfn("test(%d)", x);
if (x || (tester()?)) io::printn("Ok1");
io::printn("Test next");
if (tester()? || x) io::printn("Ok?");
io::printn("Test ok");
}
fn void! test2(int x)
{
io::printfn("test2(%d)", x);
if (x && (tester()?)) io::printn("Ok1");
io::printn("Test next");
if ((tester()?) && x) io::printn("Ok?");
io::printn("Test ok");
}
fn void main()
{
anyerr a = test(0);
anyerr b = test(1);
anyerr c = test2(0);
anyerr d = test2(1);
}
/* #expect: foo.ll
define i64 @foo_test(i32 %0) #0 {
entry:
%retparam = alloca i64, align 8
%varargslots = alloca [1 x %variant], align 16
%taddr = alloca i32, align 4
%error_var = alloca i64, align 8
%blockret = alloca i32, align 4
%x = alloca ptr, align 8
%retparam1 = alloca i64, align 8
%result = alloca %File, align 8
%x2 = alloca ptr, align 8
%retparam3 = alloca i64, align 8
%result4 = alloca %File, align 8
%error_var5 = alloca i64, align 8
%blockret6 = alloca i32, align 4
%x10 = alloca ptr, align 8
%retparam11 = alloca i64, align 8
%result12 = alloca %File, align 8
%x14 = alloca ptr, align 8
%retparam15 = alloca i64, align 8
%result16 = alloca %File, align 8
%reterr = alloca i64, align 8
store i32 %0, ptr %taddr, align 4
%1 = insertvalue %variant undef, ptr %taddr, 0
%2 = insertvalue %variant %1, i64 ptrtoint (ptr @"ct$int" to i64), 1
%3 = getelementptr inbounds [1 x %variant], ptr %varargslots, i64 0, i64 0
store %variant %2, ptr %3, align 16
%4 = call i64 @std_io_printfn(ptr %retparam, ptr @.str.1, i64 8, ptr %varargslots, i64 1)
%intbool = icmp ne i32 %0, 0
br i1 %intbool, label %or.phi, label %or.rhs
or.rhs: ; preds = %entry
store i64 ptrtoint (ptr @"foo_Foo$ABC" to i64), ptr %error_var, align 8
br label %opt_block_cleanup
opt_block_cleanup: ; preds = %or.rhs
call void @foo_blurb()
br label %guard_block
guard_block: ; preds = %opt_block_cleanup
%5 = load i64, ptr %error_var, align 8
ret i64 %5
or.phi: ; preds = %entry
br label %if.then
if.then: ; preds = %or.phi
store ptr @.str.2, ptr %x, align 8
%6 = call ptr @std_io_stdout()
store ptr %6, ptr %result, align 8
%7 = load ptr, ptr %x, align 8
%8 = call i64 @std_io_File_printn(ptr %retparam1, ptr %result, ptr %7, i64 3)
br label %if.exit
if.exit: ; preds = %if.then
store ptr @.str.3, ptr %x2, align 8
%9 = call ptr @std_io_stdout()
store ptr %9, ptr %result4, align 8
%10 = load ptr, ptr %x2, align 8
%11 = call i64 @std_io_File_printn(ptr %retparam3, ptr %result4, ptr %10, i64 9)
store i64 ptrtoint (ptr @"foo_Foo$ABC" to i64), ptr %error_var5, align 8
br label %opt_block_cleanup7
opt_block_cleanup7: ; preds = %if.exit
call void @foo_blurb()
br label %guard_block8
guard_block8: ; preds = %opt_block_cleanup7
%12 = load i64, ptr %error_var5, align 8
ret i64 %12
if.exit13: ; No predecessors!
store ptr @.str.5, ptr %x14, align 8
%13 = call ptr @std_io_stdout()
store ptr %13, ptr %result16, align 8
%14 = load ptr, ptr %x14, align 8
%15 = call i64 @std_io_File_printn(ptr %retparam15, ptr %result16, ptr %14, i64 7)
ret i64 0
}
; Function Attrs: nounwind
define i64 @foo_test2(i32 %0) #0 {
entry:
%retparam = alloca i64, align 8
%varargslots = alloca [1 x %variant], align 16
%taddr = alloca i32, align 4
%error_var = alloca i64, align 8
%blockret = alloca i32, align 4
%x = alloca ptr, align 8
%retparam1 = alloca i64, align 8
%result = alloca %File, align 8
%error_var2 = alloca i64, align 8
%blockret3 = alloca i32, align 4
%x7 = alloca ptr, align 8
%retparam8 = alloca i64, align 8
%result9 = alloca %File, align 8
%reterr = alloca i64, align 8
store i32 %0, ptr %taddr, align 4
%1 = insertvalue %variant undef, ptr %taddr, 0
%2 = insertvalue %variant %1, i64 ptrtoint (ptr @"ct$int" to i64), 1
%3 = getelementptr inbounds [1 x %variant], ptr %varargslots, i64 0, i64 0
store %variant %2, ptr %3, align 16
%4 = call i64 @std_io_printfn(ptr %retparam, ptr @.str.6, i64 9, ptr %varargslots, i64 1)
%intbool = icmp ne i32 %0, 0
br i1 %intbool, label %and.rhs, label %and.phi
and.rhs: ; preds = %entry
store i64 ptrtoint (ptr @"foo_Foo$ABC" to i64), ptr %error_var, align 8
br label %opt_block_cleanup
opt_block_cleanup: ; preds = %and.rhs
call void @foo_blurb()
br label %guard_block
guard_block: ; preds = %opt_block_cleanup
%5 = load i64, ptr %error_var, align 8
ret i64 %5
and.phi: ; preds = %entry
br label %if.exit
if.exit: ; preds = %and.phi
store ptr @.str.7, ptr %x, align 8
%6 = call ptr @std_io_stdout()
store ptr %6, ptr %result, align 8
%7 = load ptr, ptr %x, align 8
%8 = call i64 @std_io_File_printn(ptr %retparam1, ptr %result, ptr %7, i64 9)
store i64 ptrtoint (ptr @"foo_Foo$ABC" to i64), ptr %error_var2, align 8
br label %opt_block_cleanup4
opt_block_cleanup4: ; preds = %if.exit
call void @foo_blurb()
br label %guard_block5
guard_block5: ; preds = %opt_block_cleanup4
%9 = load i64, ptr %error_var2, align 8
ret i64 %9
if.exit6: ; No predecessors!
store ptr @.str.8, ptr %x7, align 8
%10 = call ptr @std_io_stdout()
store ptr %10, ptr %result9, align 8
%11 = load ptr, ptr %x7, align 8
%12 = call i64 @std_io_File_printn(ptr %retparam8, ptr %result9, ptr %11, i64 7)
ret i64 0
}
; Function Attrs: nounwind
define void @foo_main() #0 {
entry:
%a = alloca i64, align 8
%error_var = alloca i64, align 8
%b = alloca i64, align 8
%error_var1 = alloca i64, align 8
%c = alloca i64, align 8
%error_var6 = alloca i64, align 8
%d = alloca i64, align 8
%error_var11 = alloca i64, align 8
store i64 0, ptr %error_var, align 8
%0 = call i64 @foo_test(i32 0)
%not_err = icmp eq i64 %0, 0
br i1 %not_err, label %after_check, label %assign_optional
assign_optional: ; preds = %entry
store i64 %0, ptr %error_var, align 8
br label %noerr_block
after_check: ; preds = %entry
br label %noerr_block
noerr_block: ; preds = %after_check, %assign_optional
%1 = load i64, ptr %error_var, align 8
store i64 %1, ptr %a, align 8
store i64 0, ptr %error_var1, align 8
%2 = call i64 @foo_test(i32 1)
%not_err2 = icmp eq i64 %2, 0
br i1 %not_err2, label %after_check4, label %assign_optional3
assign_optional3: ; preds = %noerr_block
store i64 %2, ptr %error_var1, align 8
br label %noerr_block5
after_check4: ; preds = %noerr_block
br label %noerr_block5
noerr_block5: ; preds = %after_check4, %assign_optional3
%3 = load i64, ptr %error_var1, align 8
store i64 %3, ptr %b, align 8
store i64 0, ptr %error_var6, align 8
%4 = call i64 @foo_test2(i32 0)
%not_err7 = icmp eq i64 %4, 0
br i1 %not_err7, label %after_check9, label %assign_optional8
assign_optional8: ; preds = %noerr_block5
store i64 %4, ptr %error_var6, align 8
br label %noerr_block10
after_check9: ; preds = %noerr_block5
br label %noerr_block10
noerr_block10: ; preds = %after_check9, %assign_optional8
%5 = load i64, ptr %error_var6, align 8
store i64 %5, ptr %c, align 8
store i64 0, ptr %error_var11, align 8
%6 = call i64 @foo_test2(i32 1)
%not_err12 = icmp eq i64 %6, 0
br i1 %not_err12, label %after_check14, label %assign_optional13
assign_optional13: ; preds = %noerr_block10
store i64 %6, ptr %error_var11, align 8
br label %noerr_block15
after_check14: ; preds = %noerr_block10
br label %noerr_block15
noerr_block15: ; preds = %after_check14, %assign_optional13
%7 = load i64, ptr %error_var11, align 8
store i64 %7, ptr %d, align 8
ret void
}
; Function Attrs: nounwind
define i32 @main(i32 %0, ptr %1) #0 {
entry:
%.anon = alloca i32, align 4
%.anon1 = alloca ptr, align 8
store i32 %0, ptr %.anon, align 4
store ptr %1, ptr %.anon1, align 8
call void @foo_main()
ret i32 0
}
; Function Attrs: nounwind
declare i64 @std_io_File_printn(ptr, ptr, ptr, i64) #0
; Function Attrs: nounwind
declare ptr @std_io_stdout() #0
; Function Attrs: nounwind
declare i64 @std_io_printfn(ptr, ptr, i64, ptr, i64) #0
attributes #0 = { nounwind }