Add macro method test update LLVM version for MSVC.

This commit is contained in:
Christoffer Lerno
2022-09-08 15:06:37 +02:00
parent 8eefce235f
commit e4e1541cd7
4 changed files with 131 additions and 2 deletions

View File

@@ -0,0 +1,65 @@
// #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 %Foo*, align 8
%this1 = alloca %Foo, align 4
%0 = bitcast %Foo* %a to i32*
store i32 0, i32* %0, align 4
%1 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
store i32 3, i32* %1, align 4
%2 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
%3 = load i32, i32* %2, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i32 %3)
%4 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
%5 = load i32, i32* %4, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i32 %5)
store %Foo* %a, %Foo** %this, align 8
%6 = load %Foo*, %Foo** %this, align 8
%7 = getelementptr inbounds %Foo, %Foo* %6, i32 0, i32 0
store i32 4, i32* %7, align 8
%8 = load %Foo*, %Foo** %this, align 8
%9 = getelementptr inbounds %Foo, %Foo* %8, i32 0, i32 0
%10 = load i32, i32* %9, align 8
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i32 0, i32 0), i32 %10)
%11 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
%12 = load i32, i32* %11, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i32 %12)
%13 = bitcast %Foo* %this1 to i8*
%14 = bitcast %Foo* %a to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %13, i8* align 4 %14, i32 4, i1 false)
%15 = getelementptr inbounds %Foo, %Foo* %this1, i32 0, i32 0
store i32 5, i32* %15, align 4
%16 = getelementptr inbounds %Foo, %Foo* %this1, i32 0, i32 0
%17 = load i32, i32* %16, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i32 0, i32 0), i32 %17)
%18 = getelementptr inbounds %Foo, %Foo* %a, i32 0, i32 0
%19 = load i32, i32* %18, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i32 0, i32 0), i32 %19)
ret void
}

View File

@@ -0,0 +1,62 @@
// #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 8
%7 = load ptr, ptr %this, align 8
%8 = getelementptr inbounds %Foo, ptr %7, i32 0, i32 0
%9 = load i32, ptr %8, align 8
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
}