mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 20:11:17 +00:00
61 lines
1.9 KiB
C
61 lines
1.9 KiB
C
// #target: macos-x64
|
|
module defer1;
|
|
import std::io;
|
|
|
|
fn void test(int x)
|
|
{
|
|
defer io::println();
|
|
defer io::print("A");
|
|
if (x == 1) return;
|
|
{
|
|
defer io::print("B");
|
|
if (x == 0) return;
|
|
}
|
|
io::print("!");
|
|
}
|
|
|
|
fn void main()
|
|
{
|
|
test(1); // Prints "A"
|
|
test(0); // Prints "BA"
|
|
test(10); // Prints "B!A"
|
|
}
|
|
|
|
/* #expect: defer1.ll
|
|
|
|
define void @defer1_test(i32 %0) #0 {
|
|
entry:
|
|
%eq = icmp eq i32 %0, 1
|
|
br i1 %eq, label %if.then, label %if.exit
|
|
|
|
if.then: ; preds = %entry
|
|
%1 = call i32 @std_io_print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i32 0, i32 0))
|
|
%2 = call i32 @std_io_println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i32 0, i32 0)) #1
|
|
ret void
|
|
|
|
if.exit: ; preds = %entry
|
|
%eq1 = icmp eq i32 %0, 0
|
|
br i1 %eq1, label %if.then2, label %if.exit3
|
|
|
|
if.then2: ; preds = %if.exit
|
|
%3 = call i32 @std_io_print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i32 0, i32 0))
|
|
%4 = call i32 @std_io_print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.3, i32 0, i32 0))
|
|
%5 = call i32 @std_io_println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.4, i32 0, i32 0)) #1
|
|
ret void
|
|
|
|
if.exit3: ; preds = %if.exit
|
|
%6 = call i32 @std_io_print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.5, i32 0, i32 0))
|
|
%7 = call i32 @std_io_print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.6, i32 0, i32 0))
|
|
%8 = call i32 @std_io_print(i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.7, i32 0, i32 0))
|
|
%9 = call i32 @std_io_println(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.8, i32 0, i32 0)) #1
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define void @defer1_main() #0 {
|
|
entry:
|
|
call void @defer1_test(i32 1)
|
|
call void @defer1_test(i32 0)
|
|
call void @defer1_test(i32 10)
|
|
ret void
|
|
}
|