Add parsing for escaping and remove "fault" token name. Allow excluding stdlib. Fixes to the x64 abi: no narrowing done for i32 results, assuming too many registers, more tests.

This commit is contained in:
Christoffer Lerno
2022-01-11 22:24:47 +01:00
committed by Christoffer Lerno
parent 684ad9e663
commit 5683fe3f8c
33 changed files with 397 additions and 49 deletions

View File

@@ -0,0 +1,48 @@
// #target: x64-darwin
module test;
fn char f0() {
return 0;
}
fn short f1() {
return 0;
}
fn int f2() {
return 0;
}
fn float f3() {
return 0;
}
fn double f4() {
return 0;
}
fn void f6(char a0, short a1, int a2, long a3, void *a4) {}
enum Enum7 : int { A, B, C }
fn void f7(Enum7 a0) {}
struct Struct8
{
int a;
int b;
}
fn Struct8 f8_1() { while (1) {} return Struct8 {}; }
fn void f8_2(Struct8 a0) {}
/* #expect: test.ll
define zeroext i8 @test.f0()
define signext i16 @test.f1()
define i32 @test.f2()
define float @test.f3()
define double @test.f4()
define void @test.f6(i8 zeroext %0, i16 signext %1, i32 %2, i64 %3, i8* %4)
define void @test.f7(i32 %0)
define i64 @test.f8_1()
define void @test.f8_2(i64 %0) #0 {

View File

@@ -0,0 +1,93 @@
// #target: x64-darwin
module test;
struct St12
{
int a @align(16);
}
fn St12 f12_0(void) { while (1) {}; $unreachable; }
fn void f12_1(St12 a0) {}
struct St13_0 { long[3] f0; }
struct St13_1 { long[2] f0; }
fn St13_0 f13(int a, int b, int c, int d,
St13_1 e, int f) { while (1) {}; $unreachable; }
fn void f14(int a, int b, int c, int d, int e, int f, ichar x) {}
fn void f15(int a, int b, int c, int d, int e, int f, void *x) {}
fn void f16(float a, float b, float c, float d, float e, float f, float g, float h,
float x) {}
struct Fl18_s0 { int f0; }
fn void fl18(int a, Fl18_s0 f18_arg1) { while (1) {} }
struct St20 @align(32) {
int x;
int y;
}
fn void f20(St20 x) {}
struct StringRef
{
int x;
char* ptr;
}
fn char *f21(StringRef s) { return s.x+s.ptr; }
struct St22s @align(16)
{ ulong[2] x; }
fn void f22(St22s x, St22s y) { }
struct St23S {
short f0;
uint f1;
int f2;
}
fn void f23(int a, St23S b) {
}
struct St24s { int a; int b; }
fn St23S f24(St23S *x, St24s *p2)
{
return *x;
}
fn float[<4>] f25(float[<4>] x) {
return x+x;
}
/* #expect: test.ll
define i32 @test.f12_0()
define void @test.f12_1(i32 %0)
define void @test.f13(%St13_0* noalias sret(%St13_0) align 8 %0, i32 %1, i32 %2, i32 %3, i32 %4, %St13_1* byval(%St13_1) align 8 %5, i32 %6) #0 {
define void @test.f14(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8 signext %6) #0 {
define void @test.f15(i32 %0, i32 %1, i32 %2, i32 %3, i32 %4, i32 %5, i8* %6)
define void @test.f16(float %0, float %1, float %2, float %3, float %4, float %5, float %6, float %7, float %8)
define void @test.fl18(i32 %0, i32 %1)
define void @test.f20(%St20* byval(%St20) align 32 %0)
define i8* @test.f21(i64 %0, i8* %1)
define void @test.f22(i64 %0, i64 %1, i64 %2, i64 %3)
entry:
%x = alloca %St22s, align 16
%y = alloca %St22s, align 16
define void @test.f23(i32 %0, i64 %1, i32 %2)
define { i64, i32 } @test.f24(%St23S* %0, %St24s* %1)
define <4 x float> @test.f25(<4 x float> %0) #0 {
entry:
%fadd = fadd <4 x float> %0, %0
ret <4 x float> %fadd
}

View File

@@ -0,0 +1,73 @@
// #target: x64-darwin
module test;
struct Foo
{
char a;
char b;
char c;
}
fn int testing()
{
Foo y = getFoo(Foo { 4, 5, 6 });
return y.a + y.c;
}
fn Foo getFoo(Foo f)
{
return Foo { 1, 2, 3 };
}
/* #expect: test.ll
define i32 @test.testing() #0 {
entry:
%y = alloca %Foo, align 1
%literal = alloca %Foo, align 1
%tempcoerce = alloca i24, align 4
%result = alloca %Foo, align 1
%0 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 0
store i8 4, i8* %0, align 1
%1 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 1
store i8 5, i8* %1, align 1
%2 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 2
store i8 6, i8* %2, align 1
%3 = bitcast i24* %tempcoerce to i8*
%4 = bitcast %Foo* %literal to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %3, i8* align 1 %4, i32 3, i1 false)
%5 = load i24, i24* %tempcoerce, align 4
%6 = call i24 @test.getFoo(i24 %5)
%7 = bitcast %Foo* %result to i24*
store i24 %6, i24* %7, align 1
%8 = bitcast %Foo* %y to i8*
%9 = bitcast %Foo* %result to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 1 %8, i8* align 1 %9, i32 3, i1 false)
%10 = getelementptr inbounds %Foo, %Foo* %y, i32 0, i32 0
%11 = load i8, i8* %10, align 1
%uisiext = zext i8 %11 to i32
%12 = getelementptr inbounds %Foo, %Foo* %y, i32 0, i32 2
%13 = load i8, i8* %12, align 1
%uisiext1 = zext i8 %13 to i32
%add = add i32 %uisiext, %uisiext1
ret i32 %add
}
; Function Attrs: nounwind
define i24 @test.getFoo(i24 %0) #0 {
entry:
%f = alloca %Foo, align 1
%literal = alloca %Foo, align 1
%tempcoerce = alloca i24, align 4
%1 = bitcast %Foo* %f to i24*
store i24 %0, i24* %1, align 1
%2 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 0
store i8 1, i8* %2, align 1
%3 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 1
store i8 2, i8* %3, align 1
%4 = getelementptr inbounds %Foo, %Foo* %literal, i32 0, i32 2
store i8 3, i8* %4, align 1
%5 = bitcast i24* %tempcoerce to i8*
%6 = bitcast %Foo* %literal to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %5, i8* align 1 %6, i32 3, i1 false)
%7 = load i24, i24* %tempcoerce, align 4
ret i24 %7
}

View File

@@ -0,0 +1,28 @@
// #target: x64-darwin
module test;
extern fn void test1_f(void *);
fn void test1_g()
{
float[4] x;
test1_f(&x);
}
/* #expect: test.ll
define void @test.test1_g() #0 {
entry:
%x = alloca [4 x float], align 16
%0 = getelementptr inbounds [4 x float], [4 x float]* %x, i64 0, i64 0
store float 0.000000e+00, float* %0, align 4
%1 = getelementptr inbounds [4 x float], [4 x float]* %x, i64 0, i64 1
store float 0.000000e+00, float* %1, align 4
%2 = getelementptr inbounds [4 x float], [4 x float]* %x, i64 0, i64 2
store float 0.000000e+00, float* %2, align 4
%3 = getelementptr inbounds [4 x float], [4 x float]* %x, i64 0, i64 3
store float 0.000000e+00, float* %3, align 4
%ptrptr = bitcast [4 x float]* %x to i8*
call void @test1_f(i8* %ptrptr)
ret void
}

View File

@@ -65,3 +65,5 @@ cond.phi: ; preds = %cond.rhs, %entry
%4 = zext i1 %val to i8
ret i8 %4
}
attributes #0 = { nounwind }

View File

@@ -0,0 +1,34 @@
// #target: x64-darwin
module test;
struct Test
{
int x;
}
extern Test *cfun;
fn int f()
{
if (!(cfun + 0)) return 0;
return cfun.x;
}
/* #expect: test.ll
define i32 @test.f() #0 {
entry:
%0 = load %Test*, %Test** @cfun, align 8
%ptroffset = getelementptr %Test, %Test* %0, i64 0
%not = icmp eq %Test* %ptroffset, null
br i1 %not, label %if.then, label %if.exit
if.then: ; preds = %entry
ret i32 0
if.exit: ; preds = %entry
%1 = load %Test*, %Test** @cfun, align 8
%2 = getelementptr inbounds %Test, %Test* %1, i32 0, i32 0
%3 = load i32, i32* %2, align 8
ret i32 %3
}