Files
c3c/test/test_suite/errors/anyerr_void.c3t
Christoffer Lerno b31629c5e8 Removal of "or_else jump". Fixes to defer & macros/blocks, optimized failable return. @noscope macros removed. Disallow meaningless defer.
Correctly show error on return or rethrow inside of a defer. Fix copying an access expression. Removing scoped expr.
2022-03-26 20:16:36 +01:00

88 lines
2.8 KiB
C

optenum MyError
{
FOO,
BAR
}
fn void! errorThing()
{
return MyError.BAR!;
}
fn void! errorThing2()
{
return;
}
extern fn void printf(char*, ...);
fn void main()
{
anyerr z = errorThing();
printf("Z; %llx\n", (iptr)(z));
printf("BAR: %llx\n", (iptr)(MyError.BAR));
printf("FOO: %llx\n", (iptr)(MyError.FOO));
z = errorThing2();
printf("Z2: %llx\n", (iptr)(z));
}
/* #expect: anyerr_void.ll
; Function Attrs: nounwind
define i64 @anyerr_void.errorThing() #0 {
entry:
ret i64 ptrtoint (i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @"anyerr_void.MyError$elements", i64 0, i64 1) to i64)
}
; Function Attrs: nounwind
define i64 @anyerr_void.errorThing2() #0 {
entry:
%reterr = alloca i64, align 8
ret i64 0
}
; Function Attrs: nounwind
declare void @printf(i8*, ...) #0
; Function Attrs: nounwind
define void @anyerr_void.main() #0 {
entry:
%z = alloca i64, align 8
%error_var = alloca i64, align 8
%error_var1 = alloca i64, align 8
store i64 0, i64* %error_var, align 8
%0 = call i64 @anyerr_void.errorThing()
%not_err = icmp eq i64 %0, 0
br i1 %not_err, label %after.errcheck, label %error
error: ; preds = %entry
store i64 %0, i64* %error_var, align 8
br label %noerr_block
after.errcheck: ; preds = %entry
br label %noerr_block
noerr_block: ; preds = %after.errcheck, %error
%1 = load i64, i64* %error_var, align 8
store i64 %1, i64* %z, align 8
%2 = load i64, i64* %z, align 8
call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i64 %2)
call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i32 0, i32 0), i64 ptrtoint (i8** getelementptr inbounds ([2 x i8*], [2 x i8*]* @"anyerr_void.MyError$elements", i64 0, i64 1) to i64))
call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i32 0, i32 0), i64 ptrtoint ([2 x i8*]* @"anyerr_void.MyError$elements" to i64))
store i64 0, i64* %error_var1, align 8
%3 = call i64 @anyerr_void.errorThing2()
%not_err2 = icmp eq i64 %3, 0
br i1 %not_err2, label %after.errcheck4, label %error3
error3: ; preds = %noerr_block
store i64 %3, i64* %error_var1, align 8
br label %noerr_block5
after.errcheck4: ; preds = %noerr_block
br label %noerr_block5
noerr_block5: ; preds = %after.errcheck4, %error3
%4 = load i64, i64* %error_var1, align 8
store i64 %4, i64* %z, align 8
%5 = load i64, i64* %z, align 8
call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.3, i32 0, i32 0), i64 %5)
ret void
}