// #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 (%.fault* @"mymodule_ByeErr$BAR" to i64), i64* %x.f, align 8 store i64 ptrtoint (%.introspect* @"ct$int" to i64), i64* %z, align 8 br label %testblock testblock: ; preds = %entry %optval = load i64, i64* %x.f, align 8 %not_err = icmp eq i64 %optval, 0 br i1 %not_err, label %after_check, label %assign_optional assign_optional: ; preds = %testblock store i64 %optval, i64* %err, align 8 br label %end_block after_check: ; preds = %testblock store i64 0, i64* %err, align 8 br label %end_block end_block: ; preds = %after_check, %assign_optional %0 = load i64, i64* %err, align 8 %neq = icmp ne i64 %0, 0 br i1 %neq, label %if.then, label %if.exit if.then: ; preds = %end_block store i64 %0, i64* %switch, align 8 br label %switch.entry switch.entry: ; preds = %if.then %1 = load i64, i64* %switch, align 8 %eq = icmp eq i64 ptrtoint (%.fault* @"mymodule_HelloErr$FOO" to i64), %1 br i1 %eq, label %switch.case, label %next_if switch.case: ; preds = %switch.entry call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0)) br label %switch.exit next_if: ; preds = %switch.entry %eq1 = icmp eq i64 ptrtoint (%.fault* @"mymodule_ByeErr$BAR" to i64), %1 br i1 %eq1, label %switch.case2, label %next_if3 switch.case2: ; preds = %next_if call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i32 0, i32 0)) br label %switch.exit next_if3: ; preds = %next_if br label %switch.default switch.default: ; preds = %next_if3 call void (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i32 0, i32 0)) br label %switch.exit switch.exit: ; preds = %switch.default, %switch.case2, %switch.case br label %if.exit if.exit: ; preds = %switch.exit, %end_block %2 = load i64, i64* %z, align 8 store i64 %2, i64* %switch4, align 8 br label %switch.entry5 switch.entry5: ; preds = %if.exit %3 = load i64, i64* %switch4, align 8 %eq6 = icmp eq i64 ptrtoint (%.introspect* @"ct$int" to i64), %3 br i1 %eq6, label %switch.case7, label %next_if8 switch.case7: ; preds = %switch.entry5 call void (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i32 0, i32 0)) br label %switch.exit16 next_if8: ; preds = %switch.entry5 %eq9 = icmp eq i64 ptrtoint (%.introspect* @"ct$bool" to i64), %3 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 (%.introspect* @"ct$double" to i64), %3 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 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.6, i32 0, i32 0)) br label %switch.exit16 switch.exit16: ; preds = %switch.default15, %switch.case7 store i32 1, i32* %a, align 4 store i32 2, i32* %b, align 4 %4 = load i32, i32* %b, align 4 %5 = load i32, i32* %a, align 4 %add = add i32 %4, %5 store i32 %add, i32* %zy, align 4 %6 = load i32, i32* %zy, align 4 store i32 %6, i32* %switch17, align 4 br label %switch.entry18 switch.entry18: ; preds = %switch.exit16 %7 = load i32, i32* %switch17, align 4 %8 = load i32, i32* %a, align 4 %eq19 = icmp eq i32 %8, %7 br i1 %eq19, label %switch.case20, label %next_if21 switch.case20: ; preds = %switch.entry18 call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i32 0, i32 0)) br label %switch.exit26 next_if21: ; preds = %switch.entry18 %9 = load i32, i32* %b, align 4 %eq22 = icmp eq i32 %9, %7 br i1 %eq22, label %switch.case23, label %next_if24 switch.case23: ; preds = %next_if21 call void (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.8, i32 0, i32 0)) br label %switch.exit26 next_if24: ; preds = %next_if21 br label %switch.default25 switch.default25: ; preds = %next_if24 call void (i8*, ...) @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.9, i32 0, i32 0)) br label %switch.exit26 switch.exit26: ; preds = %switch.default25, %switch.case23, %switch.case20 store i8 1, i8* %switch27, align 1 br label %switch.entry28 switch.entry28: ; preds = %switch.exit26 %10 = load i8, i8* %switch27, align 1 %11 = trunc i8 %10 to i1 %12 = load i32, i32* %a, align 4 %lt = icmp slt i32 %12, 0 %eq29 = icmp eq i1 %lt, %11 br i1 %eq29, label %switch.case30, label %next_if31 switch.case30: ; preds = %switch.entry28 call void (i8*, ...) @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.10, i32 0, i32 0)) br label %switch.exit37 next_if31: ; preds = %switch.entry28 %13 = load i32, i32* %a, align 4 %eq32 = icmp eq i32 %13, 1 %eq33 = icmp eq i1 %eq32, %11 br i1 %eq33, label %switch.case34, label %next_if35 switch.case34: ; preds = %next_if31 call void (i8*, ...) @printf(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.11, i32 0, i32 0)) br label %switch.exit37 next_if35: ; preds = %next_if31 br label %switch.default36 switch.default36: ; preds = %next_if35 call void (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.12, i32 0, i32 0)) br label %switch.exit37 switch.exit37: ; preds = %switch.default36, %switch.case34, %switch.case30 ret void }