mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
52 lines
1.1 KiB
Plaintext
52 lines
1.1 KiB
Plaintext
// #target: macos-x64
|
|
module repro;
|
|
|
|
import std::collections::list;
|
|
|
|
def FnA = fn void(Foo*);
|
|
def FnB = fn void(Foo*);
|
|
|
|
struct Foo
|
|
{
|
|
List(<FnA>) aFuncs;
|
|
List(<FnB>) bFuncs;
|
|
}
|
|
|
|
fn void! Foo.deinit(&self)
|
|
{
|
|
self.aFuncs.free();
|
|
self.bFuncs.free();
|
|
}
|
|
|
|
fn void Foo.add_fn_a(&self, FnA f) => self.aFuncs.push(f);
|
|
fn void Foo.add_fn_b(&self, FnB f) => self.bFuncs.push(f);
|
|
|
|
fn void a_func(Foo* foo) {}
|
|
fn void b_func(Foo* foo) {}
|
|
|
|
fn void main()
|
|
{
|
|
Foo foo;
|
|
defer foo.deinit()!!;
|
|
foo.add_fn_a(&a_func);
|
|
foo.add_fn_b(&b_func);
|
|
}
|
|
|
|
/* #expect: repro.ll
|
|
|
|
|
|
define void @repro.main() #0 {
|
|
entry:
|
|
%foo = alloca %Foo, align 8
|
|
%error_var = alloca i64, align 8
|
|
%varargslots = alloca [1 x %any], align 16
|
|
%indirectarg = alloca %"any[]", align 8
|
|
call void @llvm.memset.p0.i64(ptr align 8 %foo, i8 0, i64 80, i1 false)
|
|
call void @repro.Foo.add_fn_a(ptr %foo, ptr @repro.a_func)
|
|
call void @repro.Foo.add_fn_b(ptr %foo, ptr @repro.b_func)
|
|
%0 = call i64 @repro.Foo.deinit(ptr %foo)
|
|
%not_err = icmp eq i64 %0, 0
|
|
%1 = call i1 @llvm.expect.i1(i1 %not_err, i1 true)
|
|
br i1 %1, label %after_check, label %assign_optional
|
|
|