Files
c3c/test/test_suite/statements/various_switching.c3t

246 lines
7.5 KiB
C

// #target: macos-x64
module mymodule;
extern fn void printf(char *, ...);
fault HelloErr
{
FOO,
}
fault ByeErr
{
BAR,
BAZ
}
fn void test()
{
int! x = ByeErr.BAR?;
typeid z = int.typeid;
if (catch err = x)
{
case HelloErr.FOO:
printf("Hello\n");
case ByeErr.BAR:
printf("Bye\n");
default:
printf("Noerrmatch\n");
}
switch (z)
{
case int:
printf("Was int!\n");
case bool:
nextcase double;
case double:
nextcase;
default:
printf("Wasn't int :(\n");
}
int a = 1;
int b = 2;
int zy = b + a;
switch (zy)
{
case a:
printf("Got a\n");
case b:
printf("Got b\n");
default:
printf("None of the above\n");
}
switch
{
case a < 0:
printf("A negative\n");
case a == 1:
printf("A is 1\n");
default:
printf("Unexpected a\n");
}
}
fn void main()
{
test();
printf("Hello!\n");
}
/* #expect: mymodule.ll
define void @mymodule.test() #0 {
entry:
%x = alloca i32, align 4
%x.f = alloca i64, align 8
%z = alloca i64, align 8
%err = alloca i64, align 8
%switch = alloca i64, align 8
%switch4 = alloca i64, align 8
%a = alloca i32, align 4
%b = alloca i32, align 4
%zy = alloca i32, align 4
%switch17 = alloca i32, align 4
%switch27 = alloca i8, align 1
store i64 ptrtoint (ptr @"mymodule.ByeErr$BAR" to i64), ptr %x.f, align 8
store i64 ptrtoint (ptr @"$ct.int" to i64), ptr %z, align 8
br label %testblock
testblock: ; preds = %entry
%optval = load i64, ptr %x.f, align 8
%not_err = icmp eq i64 %optval, 0
%0 = call i1 @llvm.expect.i1(i1 %not_err, i1 true)
br i1 %0, label %after_check, label %assign_optional
assign_optional: ; preds = %testblock
store i64 %optval, ptr %err, align 8
br label %end_block
after_check: ; preds = %testblock
store i64 0, ptr %err, align 8
br label %end_block
end_block: ; preds = %after_check, %assign_optional
%1 = load i64, ptr %err, align 8
%neq = icmp ne i64 %1, 0
br i1 %neq, label %if.then, label %if.exit
if.then: ; preds = %end_block
store i64 %1, ptr %switch, align 8
br label %switch.entry
switch.entry: ; preds = %if.then
%2 = load i64, ptr %switch, align 8
%eq = icmp eq i64 ptrtoint (ptr @"mymodule.HelloErr$FOO" to i64), %2
br i1 %eq, label %switch.case, label %next_if
switch.case: ; preds = %switch.entry
call void (ptr, ...) @printf(ptr @.str)
br label %switch.exit
next_if: ; preds = %switch.entry
%eq1 = icmp eq i64 ptrtoint (ptr @"mymodule.ByeErr$BAR" to i64), %2
br i1 %eq1, label %switch.case2, label %next_if3
switch.case2: ; preds = %next_if
call void (ptr, ...) @printf(ptr @.str.3)
br label %switch.exit
next_if3: ; preds = %next_if
br label %switch.default
switch.default: ; preds = %next_if3
call void (ptr, ...) @printf(ptr @.str.4)
br label %switch.exit
switch.exit: ; preds = %switch.default, %switch.case2, %switch.case
br label %if.exit
if.exit: ; preds = %switch.exit, %end_block
%3 = load i64, ptr %z, align 8
store i64 %3, ptr %switch4, align 8
br label %switch.entry5
switch.entry5: ; preds = %if.exit
%4 = load i64, ptr %switch4, align 8
%eq6 = icmp eq i64 ptrtoint (ptr @"$ct.int" to i64), %4
br i1 %eq6, label %switch.case7, label %next_if8
switch.case7: ; preds = %switch.entry5
call void (ptr, ...) @printf(ptr @.str.5)
br label %switch.exit16
next_if8: ; preds = %switch.entry5
%eq9 = icmp eq i64 ptrtoint (ptr @"$ct.bool" to i64), %4
br i1 %eq9, label %switch.case10, label %next_if11
switch.case10: ; preds = %next_if8
br label %switch.case13
next_if11: ; preds = %next_if8
%eq12 = icmp eq i64 ptrtoint (ptr @"$ct.double" to i64), %4
br i1 %eq12, label %switch.case13, label %next_if14
switch.case13: ; preds = %next_if11, %switch.case10
br label %switch.default15
next_if14: ; preds = %next_if11
br label %switch.default15
switch.default15: ; preds = %next_if14, %switch.case13
call void (ptr, ...) @printf(ptr @.str.6)
br label %switch.exit16
switch.exit16: ; preds = %switch.default15, %switch.case7
store i32 1, ptr %a, align 4
store i32 2, ptr %b, align 4
%5 = load i32, ptr %b, align 4
%6 = load i32, ptr %a, align 4
%add = add i32 %5, %6
store i32 %add, ptr %zy, align 4
%7 = load i32, ptr %zy, align 4
store i32 %7, ptr %switch17, align 4
br label %switch.entry18
switch.entry18: ; preds = %switch.exit16
%8 = load i32, ptr %switch17, align 4
%9 = load i32, ptr %a, align 4
%eq19 = icmp eq i32 %9, %8
br i1 %eq19, label %switch.case20, label %next_if21
switch.case20: ; preds = %switch.entry18
call void (ptr, ...) @printf(ptr @.str.7)
br label %switch.exit26
next_if21: ; preds = %switch.entry18
%10 = load i32, ptr %b, align 4
%eq22 = icmp eq i32 %10, %8
br i1 %eq22, label %switch.case23, label %next_if24
switch.case23: ; preds = %next_if21
call void (ptr, ...) @printf(ptr @.str.8)
br label %switch.exit26
next_if24: ; preds = %next_if21
br label %switch.default25
switch.default25: ; preds = %next_if24
call void (ptr, ...) @printf(ptr @.str.9)
br label %switch.exit26
switch.exit26: ; preds = %switch.default25, %switch.case23, %switch.case20
store i8 1, ptr %switch27, align 1
br label %switch.entry28
switch.entry28: ; preds = %switch.exit26
%11 = load i8, ptr %switch27, align 1
%12 = trunc i8 %11 to i1
%13 = load i32, ptr %a, align 4
%lt = icmp slt i32 %13, 0
%eq29 = icmp eq i1 %lt, %12
br i1 %eq29, label %switch.case30, label %next_if31
switch.case30: ; preds = %switch.entry28
call void (ptr, ...) @printf(ptr @.str.10)
br label %switch.exit37
next_if31: ; preds = %switch.entry28
%14 = load i32, ptr %a, align 4
%eq32 = icmp eq i32 %14, 1
%eq33 = icmp eq i1 %eq32, %12
br i1 %eq33, label %switch.case34, label %next_if35
switch.case34: ; preds = %next_if31
call void (ptr, ...) @printf(ptr @.str.11)
br label %switch.exit37
next_if35: ; preds = %next_if31
br label %switch.default36
switch.default36: ; preds = %next_if35
call void (ptr, ...) @printf(ptr @.str.12)
br label %switch.exit37
switch.exit37: ; preds = %switch.default36, %switch.case34, %switch.case30
ret void
}