Files
c3c/test/test_suite/macro_methods/macro_method_different_args.c3t

62 lines
1.9 KiB
C

// #target: macos-x64
module foo;
extern fn void printf(char* fmt, ...);
struct Foo
{
int x;
}
macro void Foo.@hello(Foo &this) { this.x = 3; printf("-%d\n", this.x); }
macro void Foo.hello(Foo* this) { this.x = 4; printf("-%d\n", this.x); }
macro void Foo.hello2(Foo this) { this.x = 5; printf("-%d\n", this.x); }
fn void main()
{
Foo a;
a.@hello();
printf("%d\n", a.x);
a.hello();
printf("%d\n", a.x);
a.hello2();
printf("%d\n", a.x);
}
/* #expect: foo.ll
define void @foo.main() #0 {
entry:
%a = alloca %Foo, align 4
%this = alloca ptr, align 8
%this1 = alloca %Foo, align 4
store i32 0, ptr %a, align 4
%0 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
store i32 3, ptr %0, align 4
%1 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
%2 = load i32, ptr %1, align 4
call void (ptr, ...) @printf(ptr @.str, i32 %2)
%3 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
%4 = load i32, ptr %3, align 4
call void (ptr, ...) @printf(ptr @.str.1, i32 %4)
store ptr %a, ptr %this, align 8
%5 = load ptr, ptr %this, align 8
%6 = getelementptr inbounds %Foo, ptr %5, i32 0, i32 0
store i32 4, ptr %6, align 4
%7 = load ptr, ptr %this, align 8
%8 = getelementptr inbounds %Foo, ptr %7, i32 0, i32 0
%9 = load i32, ptr %8, align 4
call void (ptr, ...) @printf(ptr @.str.2, i32 %9)
%10 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
%11 = load i32, ptr %10, align 4
call void (ptr, ...) @printf(ptr @.str.3, i32 %11)
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %this1, ptr align 4 %a, i32 4, i1 false)
%12 = getelementptr inbounds %Foo, ptr %this1, i32 0, i32 0
store i32 5, ptr %12, align 4
%13 = getelementptr inbounds %Foo, ptr %this1, i32 0, i32 0
%14 = load i32, ptr %13, align 4
call void (ptr, ...) @printf(ptr @.str.4, i32 %14)
%15 = getelementptr inbounds %Foo, ptr %a, i32 0, i32 0
%16 = load i32, ptr %15, align 4
call void (ptr, ...) @printf(ptr @.str.5, i32 %16)
ret void
}