mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
66 lines
2.0 KiB
C
66 lines
2.0 KiB
C
// #target: macos-x64
|
|
module defer1;
|
|
import std::io;
|
|
|
|
fn void test(int x)
|
|
{
|
|
defer io::printn();
|
|
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 ptr @std.io.stdout()
|
|
%2 = call i64 @std.io.File.print(ptr %retparam, ptr %1, ptr @.str, i64 1)
|
|
%3 = call ptr @std.io.stdout()
|
|
%4 = call i64 @std.io.File.printn(ptr %retparam1, ptr %3, ptr null, i64 0)
|
|
ret void
|
|
if.exit: ; preds = %entry
|
|
%eq2 = icmp eq i32 %0, 0
|
|
br i1 %eq2, label %if.then3, label %if.exit7
|
|
if.then3: ; preds = %if.exit
|
|
%5 = call ptr @std.io.stdout()
|
|
%6 = call i64 @std.io.File.print(ptr %retparam4, ptr %5, ptr @.str.1, i64 1)
|
|
%7 = call ptr @std.io.stdout()
|
|
%8 = call i64 @std.io.File.print(ptr %retparam5, ptr %7, ptr @.str.2, i64 1)
|
|
%9 = call ptr @std.io.stdout()
|
|
%10 = call i64 @std.io.File.printn(ptr %retparam6, ptr %9, ptr null, i64 0)
|
|
ret void
|
|
if.exit7: ; preds = %if.exit
|
|
%11 = call ptr @std.io.stdout()
|
|
%12 = call i64 @std.io.File.print(ptr %retparam8, ptr %11, ptr @.str.3, i64 1)
|
|
%13 = call ptr @std.io.stdout()
|
|
%14 = call i64 @std.io.File.print(ptr %retparam9, ptr %13, ptr @.str.4, i64 1)
|
|
%15 = call ptr @std.io.stdout()
|
|
%16 = call i64 @std.io.File.print(ptr %retparam10, ptr %15, ptr @.str.5, i64 1)
|
|
%17 = call ptr @std.io.stdout()
|
|
%18 = call i64 @std.io.File.printn(ptr %retparam11, ptr %17, ptr null, i64 0)
|
|
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
|
|
}
|