Distinct inline can now be called if it is aliasing a function pointer.

This commit is contained in:
Christoffer Lerno
2024-08-03 03:08:38 +02:00
parent 74b9971494
commit d91c289bf6
5 changed files with 42 additions and 4 deletions

View File

@@ -1,7 +1,8 @@
module output;
module test;
def FnA = fn void(int*);
distinct FnB = FnA;
distinct FnC = inline FnA;
fn void func(int*) {}
@@ -11,4 +12,22 @@ fn void main()
FnB b = (FnB)&func;
FnB b2 = &func;
FnB b3 = fn (int* x) {};
}
FnC c = &func;
c(null);
}
/* #expect: test.ll
%a = alloca ptr, align 8
%b = alloca ptr, align 8
%b2 = alloca ptr, align 8
%b3 = alloca ptr, align 8
%c = alloca ptr, align 8
store ptr @test.func, ptr %a, align 8
store ptr @test.func, ptr %b, align 8
store ptr @test.func, ptr %b2, align 8
store ptr @"test.main$lambda1", ptr %b3, align 8
store ptr @test.func, ptr %c, align 8
%0 = load ptr, ptr %c, align 8
call void %0(ptr null)
ret void

View File

@@ -0,0 +1,16 @@
def Abc = fn void();
distinct Foo = inline Abc;
struct Bar
{
inline Abc a;
}
fn void test()
{
}
fn void main()
{
Foo f = &test;
Bar b = { &test };
f();
b(); // #error: may be invoked
}