Files
c3c/test/test_suite/any/variant_switch.c3t
Christoffer Lerno e293c435af 0.6.0: init_new/init_temp removed. LinkedList API rewritten. List "pop" and "remove" function now return Optionals. RingBuffer API rewritten. Allocator interface changed. Deprecated Allocator, DString and mem functions removed. "identity" functions are now constants for Matrix and Complex numbers. @default implementations for interfaces removed. any* => any, same for interfaces. Emit local/private globals as "private" in LLVM, following C "static". Updated enum syntax. Add support [rgba] properties in vectors. Improved checks of aliased "void". Subarray -> slice. Fix of llvm codegen enum check. Improved alignment handling. Add --output-dir #1155. Removed List/Object append. GenericList renamed AnyList. Remove unused "unwrap". Fixes to cond. Optimize output in dead branches. Better checking of operator methods. Disallow any from implementing dynamic methods. Check for operator mismatch. Remove unnecessary bitfield. Remove numbering in --list* commands Old style enum declaration for params/type, but now the type is optional. Add note on #1086. Allow making distinct types out of "void", "typeid", "anyfault" and faults. Remove system linker build options. "Try" expressions must be simple expressions. Add optimized build to Mac tests. Register int. assert(false) only allowed in unused branches or in tests. Compile time failed asserts is a compile time error. Remove current_block_is_target. Bug when assigning an optional from an optional. Remove unused emit_zstring. Simplify phi code. Remove unnecessary unreachable blocks and remove unnecessary current_block NULL assignments. Proper handling of '.' and Win32 '//server' paths. Add "no discard" to expression blocks with a return value. Detect "unsigned >= 0" as errors. Fix issue with distinct void as a member #1147. Improve callstack debug information #1184. Fix issue with absolute output-dir paths. Lambdas were not type checked thoroughly #1185. Fix compilation warning #1187. Request jump table using @jump for switches. Path normalization - fix possible null terminator out of bounds. Improved error messages on inlined macros.
Upgrade of mingw in CI. Fix problems using reflection on interface types #1203. Improved debug information on defer. $foreach doesn't create an implicit syntactic scope.
Error if `@if` depends on `@if`. Updated Linux stacktrace. Fix of default argument stacktrace. Allow linking libraries directly by file path. Improve inlining warning messages. Added `index_of_char_from`. Compiler crash using enum nameof from different module #1205. Removed unused fields in find_msvc. Use vswhere to find msvc. Update tests for LLVM 19
2024-06-12 10:14:26 +02:00

166 lines
5.9 KiB
Plaintext

// #target: macos-x64
module foo;
extern fn void printf(char*, ...);
fn void test(any z)
{
switch (z)
{
case int:
printf("int: %d\n", *z);
*z = 3;
case double:
printf("double %f\n", *z);
default:
printf("Unknown type.\n");
}
if (z.type == int.typeid)
{
printf("int: %d\n", *(int*)(z));
}
}
fn int main()
{
test(&&123.0);
test(&&1);
test(&&true);
return 0;
}
/* #expect: foo.ll
@"$ct.int" = linkonce global %.introspect { i8 2, i64 0, ptr null, i64 4, i64 0, i64 0, [0 x i64] zeroinitializer }, align 8
@"$ct.double" = linkonce global %.introspect { i8 4, i64 0, ptr null, i64 8, i64 0, i64 0, [0 x i64] zeroinitializer }, align 8
@"$ct.bool" = linkonce global %.introspect { i8 1, i64 0, ptr null, i64 1, i64 0, i64 0, [0 x i64] zeroinitializer }, align 8
define void @foo.test(i64 %0, ptr %1) #0 {
entry:
%z = alloca %any, align 8
%switch = alloca i64, align 8
%z3 = alloca ptr, align 8
%z11 = alloca ptr, align 8
store i64 %0, ptr %z, align 8
%ptradd = getelementptr inbounds i8, ptr %z, i64 8
store ptr %1, ptr %ptradd, align 8
%ptradd1 = getelementptr inbounds i8, ptr %z, i64 8
%2 = load i64, ptr %ptradd1, align 8
store i64 %2, ptr %switch, align 8
br label %switch.entry
switch.entry: ; preds = %entry
%3 = load i64, ptr %switch, align 8
br label %check_subtype
check_subtype: ; preds = %parent_type_block, %switch.entry
%4 = phi i64 [ %3, %switch.entry ], [ %typeid.parent, %parent_type_block ]
%eq = icmp eq i64 ptrtoint (ptr @"$ct.int" to i64), %4
br i1 %eq, label %result_block, label %parent_type_block
parent_type_block: ; preds = %check_subtype
%5 = inttoptr i64 %4 to ptr
%ptradd2 = getelementptr inbounds i8, ptr %5, i64 8
%typeid.parent = load i64, ptr %ptradd2, align 8
%6 = icmp eq i64 %typeid.parent, 0
br i1 %6, label %result_block, label %check_subtype
result_block: ; preds = %parent_type_block, %check_subtype
%7 = phi i1 [ false, %parent_type_block ], [ true, %check_subtype ]
br i1 %7, label %switch.case, label %next_if
switch.case: ; preds = %result_block
%8 = load ptr, ptr %z, align 8
store ptr %8, ptr %z3, align 8
%9 = load ptr, ptr %z3, align 8
%10 = load i32, ptr %9, align 4
call void (ptr, ...) @printf(ptr @.str, i32 %10)
%11 = load ptr, ptr %z3, align 8
store i32 3, ptr %11, align 4
br label %switch.exit
next_if: ; preds = %result_block
br label %check_subtype4
check_subtype4: ; preds = %parent_type_block6, %next_if
%12 = phi i64 [ %3, %next_if ], [ %typeid.parent8, %parent_type_block6 ]
%eq5 = icmp eq i64 ptrtoint (ptr @"$ct.double" to i64), %12
br i1 %eq5, label %result_block9, label %parent_type_block6
parent_type_block6: ; preds = %check_subtype4
%13 = inttoptr i64 %12 to ptr
%ptradd7 = getelementptr inbounds i8, ptr %13, i64 8
%typeid.parent8 = load i64, ptr %ptradd7, align 8
%14 = icmp eq i64 %typeid.parent8, 0
br i1 %14, label %result_block9, label %check_subtype4
result_block9: ; preds = %parent_type_block6, %check_subtype4
%15 = phi i1 [ false, %parent_type_block6 ], [ true, %check_subtype4 ]
br i1 %15, label %switch.case10, label %next_if12
switch.case10: ; preds = %result_block9
%16 = load ptr, ptr %z, align 8
store ptr %16, ptr %z11, align 8
%17 = load ptr, ptr %z11, align 8
%18 = load double, ptr %17, align 8
call void (ptr, ...) @printf(ptr @.str.1, double %18)
br label %switch.exit
next_if12: ; preds = %result_block9
br label %switch.default
switch.default: ; preds = %next_if12
call void (ptr, ...) @printf(ptr @.str.2)
br label %switch.exit
switch.exit: ; preds = %switch.default, %switch.case10, %switch.case
%ptradd13 = getelementptr inbounds i8, ptr %z, i64 8
%19 = load i64, ptr %ptradd13, align 8
%eq14 = icmp eq i64 %19, ptrtoint (ptr @"$ct.int" to i64)
br i1 %eq14, label %if.then, label %if.exit
if.then: ; preds = %switch.exit
%20 = load ptr, ptr %z, align 8
%21 = load i32, ptr %20, align 4
call void (ptr, ...) @printf(ptr @.str.3, i32 %21)
br label %if.exit
if.exit: ; preds = %if.then, %switch.exit
ret void
}
; Function Attrs:
define i32 @main() #0 {
entry:
%taddr = alloca double, align 8
%taddr1 = alloca %any, align 8
%taddr2 = alloca i32, align 4
%taddr3 = alloca %any, align 8
%taddr7 = alloca i8, align 1
%taddr8 = alloca %any, align 8
store double 1.230000e+02, ptr %taddr, align 8
%0 = insertvalue %any undef, ptr %taddr, 0
%1 = insertvalue %any %0, i64 ptrtoint (ptr @"$ct.double" to i64), 1
store %any %1, ptr %taddr1, align 8
%lo = load i64, ptr %taddr1, align 8
%ptradd = getelementptr inbounds i8, ptr %taddr1, i64 8
%hi = load ptr, ptr %ptradd, align 8
call void @foo.test(i64 %lo, ptr %hi)
store i32 1, ptr %taddr2, align 4
%2 = insertvalue %any undef, ptr %taddr2, 0
%3 = insertvalue %any %2, i64 ptrtoint (ptr @"$ct.int" to i64), 1
store %any %3, ptr %taddr3, align 8
%lo4 = load i64, ptr %taddr3, align 8
%ptradd5 = getelementptr inbounds i8, ptr %taddr3, i64 8
%hi6 = load ptr, ptr %ptradd5, align 8
call void @foo.test(i64 %lo4, ptr %hi6)
store i8 1, ptr %taddr7, align 1
%4 = insertvalue %any undef, ptr %taddr7, 0
%5 = insertvalue %any %4, i64 ptrtoint (ptr @"$ct.bool" to i64), 1
store %any %5, ptr %taddr8, align 8
%lo9 = load i64, ptr %taddr8, align 8
%ptradd10 = getelementptr inbounds i8, ptr %taddr8, i64 8
%hi11 = load ptr, ptr %ptradd10, align 8
call void @foo.test(i64 %lo9, ptr %hi11)
ret i32 0
}