Overload resolution fixes to inline typedef #2226.

This commit is contained in:
Christoffer Lerno
2025-06-21 13:03:16 +02:00
parent b4a6e3704f
commit fa730e7ec2
6 changed files with 118 additions and 7 deletions

View File

@@ -0,0 +1,39 @@
// #target: macos-x64
module test;
struct Word {int x;}
typedef Byte = inline ushort;
macro Word Word.add0(self, int other) @operator(+) => { self.x + (int)other };
macro Word Word.add1(self, Byte other) @operator(+) => { self.x + (int)other };
fn int main()
{
Word a = {1};
Byte b = 2;
Word c = a + b;
return 0;
}
/* #expect: test.ll
define i32 @main() #0 {
entry:
%a = alloca %Word, align 4
%b = alloca i16, align 2
%c = alloca %Word, align 4
%self = alloca %Word, align 4
%other = alloca i16, align 2
%literal = alloca %Word, align 4
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %a, ptr align 4 @.__const, i32 4, i1 false)
store i16 2, ptr %b, align 2
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %self, ptr align 4 %a, i32 4, i1 false)
%0 = load i16, ptr %b, align 2
store i16 %0, ptr %other, align 2
%1 = load i32, ptr %self, align 4
%2 = load i16, ptr %other, align 2
%zext = zext i16 %2 to i32
%add = add i32 %1, %zext
store i32 %add, ptr %literal, align 4
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %c, ptr align 4 %literal, i32 4, i1 false)
ret i32 0
}