Files
c3c/test/test_suite/statements/ranged_switch.c3t
2022-07-20 12:22:03 +02:00

203 lines
6.9 KiB
C

// #target: macos-x64
module foo;
extern fn void printf(char*, ...);
fn void main()
{
for (int i = 0; i < 12; i++)
{
switch (i)
{
case 1 .. 3:
printf("1-3\n");
case 7 .. 277:
printf("7-277 %d\n", i);
case 4 .. 5:
printf("4-5 %d\n", i);
case 6:
printf("6 %d\n", i);
default:
printf("Something else: %d\n", i);
nextcase 5;
}
}
for (int i = 0; i < 12; i++)
{
switch (i)
{
case 1 .. 3:
printf("1-3\n");
case 4 .. 6:
printf("4-6 %d\n", i);
default:
printf("Something else: %d\n", i);
nextcase 5;
}
}
bool x = false;
switch (x)
{
case true:
printf("Was true!\n");
case false:
printf("Was false!\n");
}
}
/* #expect: foo.ll
define void @foo_main() #0 {
entry:
%i = alloca i32, align 4
%switch = alloca i32, align 4
%i11 = alloca i32, align 4
%switch15 = alloca i32, align 4
%x = alloca i8, align 1
%switch23 = alloca i8, align 1
store i32 0, i32* %i, align 4
br label %loop.cond
loop.cond: ; preds = %switch.exit, %entry
%0 = load i32, i32* %i, align 4
%lt = icmp slt i32 %0, 12
br i1 %lt, label %loop.body, label %loop.exit
loop.body: ; preds = %loop.cond
%1 = load i32, i32* %i, align 4
store i32 %1, i32* %switch, align 4
br label %switch.entry
switch.entry: ; preds = %loop.body
%2 = load i32, i32* %switch, align 4
%le = icmp sle i32 1, %2
%ge = icmp sge i32 3, %2
%3 = and i1 %le, %ge
br i1 %3, label %switch.case, label %next_if
switch.case: ; preds = %switch.entry
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0))
br label %switch.exit
next_if: ; preds = %switch.entry
%le1 = icmp sle i32 7, %2
%ge2 = icmp sge i32 277, %2
%4 = and i1 %le1, %ge2
br i1 %4, label %switch.case3, label %next_if4
switch.case3: ; preds = %next_if
%5 = load i32, i32* %i, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i32 0, i32 0), i32 %5)
br label %switch.exit
next_if4: ; preds = %next_if
%le5 = icmp sle i32 4, %2
%ge6 = icmp sge i32 5, %2
%6 = and i1 %le5, %ge6
br i1 %6, label %switch.case7, label %next_if8
switch.case7: ; preds = %switch.default, %next_if4
%7 = load i32, i32* %i, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.2, i32 0, i32 0), i32 %7)
br label %switch.exit
next_if8: ; preds = %next_if4
%eq = icmp eq i32 6, %2
br i1 %eq, label %switch.case9, label %next_if10
switch.case9: ; preds = %next_if8
%8 = load i32, i32* %i, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.3, i32 0, i32 0), i32 %8)
br label %switch.exit
next_if10: ; preds = %next_if8
br label %switch.default
switch.default: ; preds = %next_if10
%9 = load i32, i32* %i, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.4, i32 0, i32 0), i32 %9)
br label %switch.case7
switch.exit: ; preds = %switch.case9, %switch.case7, %switch.case3, %switch.case
%10 = load i32, i32* %i, align 4
%add = add i32 %10, 1
store i32 %add, i32* %i, align 4
br label %loop.cond
loop.exit: ; preds = %loop.cond
store i32 0, i32* %i11, align 4
br label %loop.cond12
loop.cond12: ; preds = %switch.exit20, %loop.exit
%11 = load i32, i32* %i11, align 4
%lt13 = icmp slt i32 %11, 12
br i1 %lt13, label %loop.body14, label %loop.exit22
loop.body14: ; preds = %loop.cond12
%12 = load i32, i32* %i11, align 4
store i32 %12, i32* %switch15, align 4
br label %switch.entry16
switch.entry16: ; preds = %loop.body14
%13 = load i32, i32* %switch15, align 4
switch i32 %13, label %switch.default19 [
i32 1, label %switch.case17
i32 2, label %switch.case17
i32 3, label %switch.case17
i32 4, label %switch.case18
i32 5, label %switch.case18
i32 6, label %switch.case18
]
switch.case17: ; preds = %switch.entry16, %switch.entry16, %switch.entry16
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i32 0, i32 0))
br label %switch.exit20
switch.case18: ; preds = %switch.default19, %switch.entry16, %switch.entry16, %switch.entry16
%14 = load i32, i32* %i11, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i32 0, i32 0), i32 %14)
br label %switch.exit20
switch.default19: ; preds = %switch.entry16
%15 = load i32, i32* %i11, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.7, i32 0, i32 0), i32 %15)
br label %switch.case18
switch.exit20: ; preds = %switch.case18, %switch.case17
%16 = load i32, i32* %i11, align 4
%add21 = add i32 %16, 1
store i32 %add21, i32* %i11, align 4
br label %loop.cond12
loop.exit22: ; preds = %loop.cond12
store i8 0, i8* %x, align 1
%17 = load i8, i8* %x, align 1
store i8 %17, i8* %switch23, align 1
br label %switch.entry24
switch.entry24: ; preds = %loop.exit22
%18 = load i8, i8* %switch23, align 1
%19 = trunc i8 %18 to i1
%eq25 = icmp eq i1 true, %19
br i1 %eq25, label %switch.case26, label %next_if27
switch.case26: ; preds = %switch.entry24
call void (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.8, i32 0, i32 0))
br label %switch.exit31
next_if27: ; preds = %switch.entry24
%eq28 = icmp eq i1 false, %19
br i1 %eq28, label %switch.case29, label %next_if30
switch.case29: ; preds = %next_if27
call void (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.9, i32 0, i32 0))
br label %switch.exit31
next_if30: ; preds = %next_if27
br label %switch.exit31
switch.exit31: ; preds = %next_if30, %switch.case29, %switch.case26
ret void
}