mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
189 lines
6.5 KiB
C
189 lines
6.5 KiB
C
// #target: x64-darwin
|
|
|
|
errtype MyErr
|
|
{
|
|
TEST
|
|
}
|
|
|
|
macro foo(int x)
|
|
{
|
|
if (x) return x;
|
|
return MyErr.TEST!;
|
|
}
|
|
|
|
extern func void printf(char*, ...);
|
|
|
|
func void main()
|
|
{
|
|
int! a = @foo(1);
|
|
|
|
int! b = @foo((a + 3) ?? 2);
|
|
int! c = @foo(0);
|
|
printf("a = %d\n", a);
|
|
printf("b = %d\n", b);
|
|
printf("c = %d\n", c);
|
|
if (catch(c)) printf("c had error\n");
|
|
c = 3;
|
|
printf("c = %d\n", c);
|
|
}
|
|
|
|
// #expect: failable_catch.ll
|
|
|
|
define void @main() #0 {
|
|
entry:
|
|
%a = alloca i32, align 4
|
|
%a.f = alloca i64, align 8
|
|
%x = alloca i32, align 4
|
|
%blockret = alloca i32, align 4
|
|
%b = alloca i32, align 4
|
|
%b.f = alloca i64, align 8
|
|
%x1 = alloca i32, align 4
|
|
%blockret2 = alloca i32, align 4
|
|
%c = alloca i32, align 4
|
|
%c.f = alloca i64, align 8
|
|
%x8 = alloca i32, align 4
|
|
%blockret9 = alloca i32, align 4
|
|
%error_var = alloca i64, align 8
|
|
store i32 1, i32* %x, align 4
|
|
%0 = load i32, i32* %x, align 4
|
|
%intbool = icmp ne i32 %0, 0
|
|
br i1 %intbool, label %if.then, label %if.exit
|
|
|
|
if.then: ; preds = %entry
|
|
%1 = load i32, i32* %x, align 4
|
|
store i32 %1, i32* %blockret, align 4
|
|
br label %expr_block.exit
|
|
|
|
if.exit: ; preds = %entry
|
|
store i64 ptrtoint ([1 x i8*]* @"failable_catch.MyErr$elements" to i64), i64* %a.f, align 8
|
|
br label %after_assign
|
|
|
|
expr_block.exit: ; preds = %if.then
|
|
%2 = load i32, i32* %blockret, align 4
|
|
store i32 %2, i32* %a, align 4
|
|
store i64 0, i64* %a.f, align 8
|
|
br label %after_assign
|
|
|
|
after_assign: ; preds = %expr_block.exit, %if.exit
|
|
%3 = load i64, i64* %a.f, align 8
|
|
%not_err = icmp eq i64 %3, 0
|
|
br i1 %not_err, label %after_check, label %else_block
|
|
|
|
after_check: ; preds = %after_assign
|
|
%4 = load i32, i32* %a, align 4
|
|
%add = add i32 %4, 3
|
|
br label %phi_block
|
|
|
|
else_block: ; preds = %after_assign
|
|
br label %phi_block
|
|
|
|
phi_block: ; preds = %else_block, %after_check
|
|
%val = phi i32 [ %add, %after_check ], [ 2, %else_block ]
|
|
store i32 %val, i32* %x1, align 4
|
|
%5 = load i32, i32* %x1, align 4
|
|
%intbool3 = icmp ne i32 %5, 0
|
|
br i1 %intbool3, label %if.then4, label %if.exit5
|
|
|
|
if.then4: ; preds = %phi_block
|
|
%6 = load i32, i32* %x1, align 4
|
|
store i32 %6, i32* %blockret2, align 4
|
|
br label %expr_block.exit6
|
|
|
|
if.exit5: ; preds = %phi_block
|
|
store i64 ptrtoint ([1 x i8*]* @"failable_catch.MyErr$elements" to i64), i64* %b.f, align 8
|
|
br label %after_assign7
|
|
|
|
expr_block.exit6: ; preds = %if.then4
|
|
%7 = load i32, i32* %blockret2, align 4
|
|
store i32 %7, i32* %b, align 4
|
|
store i64 0, i64* %b.f, align 8
|
|
br label %after_assign7
|
|
|
|
after_assign7: ; preds = %expr_block.exit6, %if.exit5
|
|
store i32 0, i32* %x8, align 4
|
|
%8 = load i32, i32* %x8, align 4
|
|
%intbool10 = icmp ne i32 %8, 0
|
|
br i1 %intbool10, label %if.then11, label %if.exit12
|
|
|
|
if.then11: ; preds = %after_assign7
|
|
%9 = load i32, i32* %x8, align 4
|
|
store i32 %9, i32* %blockret9, align 4
|
|
br label %expr_block.exit13
|
|
|
|
if.exit12: ; preds = %after_assign7
|
|
store i64 ptrtoint ([1 x i8*]* @"failable_catch.MyErr$elements" to i64), i64* %c.f, align 8
|
|
br label %after_assign14
|
|
|
|
expr_block.exit13: ; preds = %if.then11
|
|
%10 = load i32, i32* %blockret9, align 4
|
|
store i32 %10, i32* %c, align 4
|
|
store i64 0, i64* %c.f, align 8
|
|
br label %after_assign14
|
|
|
|
after_assign14: ; preds = %expr_block.exit13, %if.exit12
|
|
%11 = load i64, i64* %a.f, align 8
|
|
%not_err15 = icmp eq i64 %11, 0
|
|
br i1 %not_err15, label %after_check16, label %voiderr
|
|
|
|
after_check16: ; preds = %after_assign14
|
|
%12 = load i32, i32* %a, align 4
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i32 0, i32 0), i32 %12)
|
|
br label %voiderr
|
|
|
|
voiderr: ; preds = %after_check16, %after_assign14
|
|
%13 = load i64, i64* %b.f, align 8
|
|
%not_err17 = icmp eq i64 %13, 0
|
|
br i1 %not_err17, label %after_check18, label %voiderr19
|
|
|
|
after_check18: ; preds = %voiderr
|
|
%14 = load i32, i32* %b, align 4
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i32 0, i32 0), i32 %14)
|
|
br label %voiderr19
|
|
|
|
voiderr19: ; preds = %after_check18, %voiderr
|
|
%15 = load i64, i64* %c.f, align 8
|
|
%not_err20 = icmp eq i64 %15, 0
|
|
br i1 %not_err20, label %after_check21, label %voiderr22
|
|
|
|
after_check21: ; preds = %voiderr19
|
|
%16 = load i32, i32* %c, align 4
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i32 %16)
|
|
br label %voiderr22
|
|
|
|
voiderr22: ; preds = %after_check21, %voiderr19
|
|
store i64 0, i64* %error_var, align 8
|
|
%17 = load i64, i64* %c.f, align 8
|
|
%not_err23 = icmp eq i64 %17, 0
|
|
br i1 %not_err23, label %after_check24, label %error
|
|
|
|
error: ; preds = %voiderr22
|
|
store i64 %17, i64* %error_var, align 8
|
|
br label %noerr_block
|
|
|
|
after_check24: ; preds = %voiderr22
|
|
br label %noerr_block
|
|
|
|
noerr_block: ; preds = %after_check24, %error
|
|
%18 = load i64, i64* %error_var, align 8
|
|
%neq = icmp ne i64 %18, 0
|
|
br i1 %neq, label %if.then25, label %if.exit26
|
|
|
|
if.then25: ; preds = %noerr_block
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.3, i32 0, i32 0))
|
|
br label %if.exit26
|
|
|
|
if.exit26: ; preds = %if.then25, %noerr_block
|
|
store i32 3, i32* %c, align 4
|
|
store i64 0, i64* %c.f, align 8
|
|
%19 = load i64, i64* %c.f, align 8
|
|
%not_err27 = icmp eq i64 %19, 0
|
|
br i1 %not_err27, label %after_check28, label %voiderr29
|
|
|
|
after_check28: ; preds = %if.exit26
|
|
%20 = load i32, i32* %c, align 4
|
|
call void (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i32 0, i32 0), i32 %20)
|
|
br label %voiderr29
|
|
|
|
voiderr29: ; preds = %after_check28, %if.exit26
|
|
ret void
|
|
} |