Files
c3c/test/test_suite/dynamic/dynamic_with_default.c3t
2023-10-20 14:12:08 +02:00

106 lines
3.8 KiB
C

// #target: macos-x64
module test;
interface Abc
{
fn int[<2>] test() @optional;
fn int bye();
}
fn int[<2>] Abc.test(&self) @default
{
return { 5, 7 };
}
struct Hello (Abc)
{
int y;
}
fn int[<2>] Hello.test(&self) @dynamic { return { 5, 10 }; }
fn int Hello.bye(&self) @dynamic { return 7; }
fn void main()
{
Hello z = { 32 };
Abc* x = &z;
int[<2>] z2 = x.test();
int w = x.bye();
}
/* #expect: test.ll
define double @test.Abc.test(i64 %0, ptr %1) #0 {
define double @test.Hello.test(ptr %0) #0 {
define i32 @test.Hello.bye(ptr %0) #0 {
define void @test.main() #0 {
entry:
%2 = getelementptr inbounds %"any*", ptr %x, i32 0, i32 1
%3 = load i64, ptr %2, align 8
%4 = getelementptr inbounds %"any*", ptr %x, i32 0, i32 0
%5 = inttoptr i64 %3 to ptr
%type = load ptr, ptr %.cachedtype, align 8
%6 = icmp eq ptr %5, %type
br i1 %6, label %cache_hit, label %cache_miss
cache_miss: ; preds = %entry
%7 = getelementptr inbounds %.introspect, ptr %5, i32 0, i32 2
%8 = load ptr, ptr %7, align 8
%9 = call ptr @.dyn_search(ptr %8, ptr @"$sel.test")
store ptr %9, ptr %.inlinecache, align 8
store ptr %5, ptr %.cachedtype, align 8
br label %10
cache_hit: ; preds = %entry
%cache_hit_fn = load ptr, ptr %.inlinecache, align 8
br label %10
10: ; preds = %cache_hit, %cache_miss
%fn_phi = phi ptr [ %cache_hit_fn, %cache_hit ], [ %9, %cache_miss ]
%11 = icmp eq ptr %fn_phi, null
br i1 %11, label %missing_function, label %match
missing_function: ; preds = %10
%12 = getelementptr inbounds { i64, ptr }, ptr %x, i32 0, i32 0
%lo = load i64, ptr %12, align 8
%13 = getelementptr inbounds { i64, ptr }, ptr %x, i32 0, i32 1
%hi = load ptr, ptr %13, align 8
%14 = call double @test.Abc.test(i64 %lo, ptr %hi)
store double %14, ptr %result, align 8
%15 = load <2 x i32>, ptr %result, align 8
br label %after_call
match: ; preds = %10
%16 = load ptr, ptr %4, align 8
%17 = call double %fn_phi(ptr %16)
store double %17, ptr %result1, align 8
%18 = load <2 x i32>, ptr %result1, align 8
br label %after_call
after_call: ; preds = %match, %missing_function
%result2 = phi <2 x i32> [ %15, %missing_function ], [ %18, %match ]
store <2 x i32> %result2, ptr %z2, align 8
%19 = getelementptr inbounds %"any*", ptr %x, i32 0, i32 1
%20 = load i64, ptr %19, align 8
%21 = getelementptr inbounds %"any*", ptr %x, i32 0, i32 0
%22 = inttoptr i64 %20 to ptr
%type5 = load ptr, ptr %.cachedtype4, align 8
%23 = icmp eq ptr %22, %type5
br i1 %23, label %cache_hit7, label %cache_miss6
cache_miss6: ; preds = %after_call
%24 = getelementptr inbounds %.introspect, ptr %22, i32 0, i32 2
%25 = load ptr, ptr %24, align 8
%26 = call ptr @.dyn_search(ptr %25, ptr @"$sel.bye")
store ptr %26, ptr %.inlinecache3, align 8
store ptr %22, ptr %.cachedtype4, align 8
br label %27
cache_hit7: ; preds = %after_call
%cache_hit_fn8 = load ptr, ptr %.inlinecache3, align 8
br label %27
27: ; preds = %cache_hit7, %cache_miss6
%fn_phi9 = phi ptr [ %cache_hit_fn8, %cache_hit7 ], [ %26, %cache_miss6 ]
%28 = icmp eq ptr %fn_phi9, null
br i1 %28, label %missing_function10, label %match11
missing_function10: ; preds = %27
%29 = load ptr, ptr @std.core.builtin.panic, align 8
call void %29(ptr @.panic_msg, i64 40, ptr @.file, i64 23, ptr @.func, i64 4, i32 26)
unreachable
match11: ; preds = %27
%30 = load ptr, ptr %21, align 8
%31 = call i32 %fn_phi9(ptr %30)
store i32 %31, ptr %w, align 4
ret void
}