Fix of shadowing bug. Allow pointer and subarrays to be constant initialized. Compile time values may now pass around anything considered compile time constant. It's possible to index into an initializer list at compile time. (Some work still remains on this)

This commit is contained in:
Christoffer Lerno
2021-09-14 11:14:51 +02:00
committed by Christoffer Lerno
parent 1b103a3e22
commit e4c7dde30b
30 changed files with 1209 additions and 343 deletions

View File

@@ -0,0 +1,22 @@
// #target: x64-darwin
module test;
int*[] blurp = { &ptr, &ptr, (&ptr + 1), &ptr - 1, (int*)((iptr)(&ptr) - 4) };
int* c = (int*)((iptr)(&ptr) - 4);
int* c2 = (int*)((iptr)(&ptr) + 4);
int* c3 = (int*)(4 + (iptr)(&ptr));
iptr ff = (iptr)(&ptr);
int ptr = 0;
// #expect: test.ll
%"int*[]" = type { i32**, i64 }
@.taddr = private hidden global [5 x i32*] [i32* @test.ptr, i32* @test.ptr, i32* getelementptr inbounds (i32, i32* @test.ptr, i64 1), i32* getelementptr (i32, i32* @test.ptr, i64 -1), i32* bitcast (i8* getelementptr (i8, i8* bitcast (i32* @test.ptr to i8*), i64 -4) to i32*)], align 8
@test.blurp = global %"int*[]" { i32** getelementptr inbounds ([5 x i32*], [5 x i32*]* @.taddr, i32 0, i32 0), i64 5 }, align 8
@test.c = global i32* bitcast (i8* getelementptr (i8, i8* bitcast (i32* @test.ptr to i8*), i64 -4) to i32*), align 8
@test.c2 = global i32* bitcast (i8* getelementptr (i8, i8* bitcast (i32* @test.ptr to i8*), i64 4) to i32*), align 8
@test.c3 = global i32* bitcast (i8* getelementptr (i8, i8* bitcast (i32* @test.ptr to i8*), i64 4) to i32*), align 8
@test.ff = global i64 ptrtoint (i32* @test.ptr to i64), align 8
@test.ptr = global i32 0, align 4

View File

@@ -0,0 +1,25 @@
// #target: x64-darwin
int foo = 2.2 ? 1 : 2;
double bar = false ? 1.0 : 2;
bool baz = 1 ? false : true;
func void test()
{
int x = 1 ? 0 : test2();
}
func int test2() { return 3; }
// #expect: ternary_folding.ll
@ternary_folding.foo = global i32 1, align 4
@ternary_folding.bar = global double 2.000000e+00, align 8
@ternary_folding.baz = global i8 0, align 1
define void @ternary_folding.test() #0 {
entry:
%x = alloca i32, align 4
store i32 0, i32* %x, align 4
ret void
}

View File

@@ -355,7 +355,7 @@ entry:
%x = alloca %"int[]", align 8
%sum = alloca i32, align 4
%vararg = alloca %"int[]", align 8
%tempaddr = alloca %"int[]", align 8
%taddr = alloca %"int[]", align 8
%pair = bitcast %"int[]"* %x to { i8*, i64 }*
%lo = getelementptr inbounds { i8*, i64 }, { i8*, i64 }* %pair, i32 0, i32 0
store i8* %0, i8** %lo, align 8
@@ -387,8 +387,8 @@ if.exit: ; preds = %entry
%10 = insertvalue %"int[]" %9, i64 %size, 1
%11 = getelementptr inbounds %"int[]", %"int[]"* %vararg, i32 0, i32 1
%12 = getelementptr inbounds %"int[]", %"int[]"* %vararg, i32 0, i32 0
store %"int[]" %10, %"int[]"* %tempaddr, align 8
%casttemp = bitcast %"int[]"* %tempaddr to { i8*, i64 }*
store %"int[]" %10, %"int[]"* %taddr, align 8
%casttemp = bitcast %"int[]"* %taddr to { i8*, i64 }*
%lo1 = getelementptr inbounds { i8*, i64 }, { i8*, i64 }* %casttemp, i32 0, i32 0
%lo2 = load i8*, i8** %lo1, align 8
%hi3 = getelementptr inbounds { i8*, i64 }, { i8*, i64 }* %casttemp, i32 0, i32 1

View File

@@ -0,0 +1,8 @@
func void test()
{
char* hello = "123";
char[] a = { '1', '2', '3' };
char[*] b = { '1', '2', '3' };
char[3] c = { '1', '2', '3' };
char* d = { '1', '2', '3' }; // #error: Pointers cannot be initialized using an initializer list, instead you need to take the address of an array
}

View File

@@ -105,6 +105,8 @@ func void main(int argc, char **argv)
}
// #expect: fasta.ll
%"char[]" = type { i8*, i64 }
%"double[]" = type { double*, i64 }
@fasta.IM = constant i32 139968, align 1
@fasta.IA = constant i32 3877, align 1
@@ -115,12 +117,12 @@ func void main(int argc, char **argv)
@fasta.alu = protected global %"char[]" { i8* getelementptr inbounds ([288 x i8], [288 x i8]* @.str, i32 0, i32 0), i64 287 }, align 8
@.str.11 = private constant [16 x i8] c"acgtBDHKMNRSVWY\00", align 1
@fasta.iub = global %"char[]" { i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.11, i32 0, i32 0), i64 15 }, align 8
@.__const = private constant [15 x double] [double 2.700000e-01, double 1.200000e-01, double 1.200000e-01, double 2.700000e-01, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02], align 8
@fasta.iub_p = global %"double[]" { %"double[]"* bitcast ([15 x double]* @.__const to %"double[]"*), i64 15 }, align 8
@.taddr = private hidden global [15 x double] [double 2.700000e-01, double 1.200000e-01, double 1.200000e-01, double 2.700000e-01, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02, double 2.000000e-02], align 8
@fasta.iub_p = global %"double[]" { double* getelementptr inbounds ([15 x double], [15 x double]* @.taddr, i32 0, i32 0), i64 15 }, align 8
@.str.12 = private constant [5 x i8] c"acgt\00", align 1
@fasta.homosapiens = global %"char[]" { i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.12, i32 0, i32 0), i64 4 }, align 8
@.__const.13 = private constant [4 x double] [double 0x3FD3639D20BAEB5B, double 0x3FC957AE3DCD561B, double 0x3FC9493AEAB6C2BF, double 0x3FD34BEE4B030838], align 8
@fasta.homosapiens_p = global %"double[]" { %"double[]"* bitcast ([4 x double]* @.__const.13 to %"double[]"*), i64 4 }, align 8
@.taddr.13 = private hidden global [4 x double] [double 0x3FD3639D20BAEB5B, double 0x3FC957AE3DCD561B, double 0x3FC9493AEAB6C2BF, double 0x3FD34BEE4B030838], align 8
@fasta.homosapiens_p = global %"double[]" { double* getelementptr inbounds ([4 x double], [4 x double]* @.taddr.13, i32 0, i32 0), i64 4 }, align 8
@fasta.LINELEN = constant i32 60, align 1
@.str.14 = private constant [23 x i8] c">ONE Homo sapiens alu\0A\00", align 1
@.str.15 = private constant [26 x i8] c">TWO IUB ambiguity codes\0A\00", align 1
@@ -381,4 +383,4 @@ if.exit: ; preds = %if.then, %entry
%mul10 = mul i32 %11, 5
call void @fasta.random_fasta(i8* %lo6, i64 %hi7, i8* %lo8, i64 %hi9, i32 %mul10)
ret void
}
}

View File

@@ -1,4 +1,4 @@
// #skip
// #target: x64-darwin
union Baz
{
@@ -16,7 +16,11 @@ func int test()
Baz ffe = { .x = 1 };
int[1] azz = {};
int[*] a = {};
var $foo = { 1, 2, 3 };
var $foo = { 11, 22, 33 };
static int foo1 = $foo[1];
int foo2 = $foo[2];
var $foos = { "Hello!" };
char* str = $foos[0];
bool x = ! int[] { 1, 2, 3 };
Bar b = {};
Baz z = {};
@@ -24,4 +28,81 @@ func int test()
Bar[] foo = {};
Baz[3] baz = {};
return 1;
}
}
// #expect: general_tests.ll
%Baz = type { double }
%Bar = type { i32, i32 }
%"int[]" = type { i32*, i64 }
%"Bar[]" = type { %Bar*, i64 }
@Baz = linkonce_odr constant i8 1
@Bar = linkonce_odr constant i8 1
@.__const = private constant { i32, [4 x i8] } { i32 1, [4 x i8] undef }, align 8
@test.foo1 = hidden global i32 22, align 4
@.str = private constant [7 x i8] c"Hello!\00", align 1
; Function Attrs: nounwind
define i32 @general_tests.test() #0 {
entry:
%ffe = alloca %Baz, align 8
%azz = alloca [1 x i32], align 4
%a = alloca [0 x i32], align 4
%foo2 = alloca i32, align 4
%str = alloca i8*, align 8
%literal = alloca [1 x i8*], align 8
%x = alloca i8, align 1
%literal1 = alloca [3 x i32], align 4
%b = alloca %Bar, align 4
%z = alloca %Baz, align 8
%sub = alloca %"int[]", align 8
%literal2 = alloca [0 x i32], align 4
%foo = alloca %"Bar[]", align 8
%literal3 = alloca [0 x %Bar], align 4
%baz = alloca [3 x %Baz], align 16
%0 = bitcast %Baz* %ffe to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %0, i8* align 8 bitcast ({ i32, [4 x i8] }* @.__const to i8*), i32 8, i1 false)
%1 = bitcast [1 x i32]* %azz to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %1, i8 0, i64 4, i1 false)
%2 = bitcast [0 x i32]* %a to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %2, i8 0, i64 0, i1 false)
store i32 33, i32* %foo2, align 4
%3 = getelementptr inbounds i8*, [1 x i8*]* %literal, i32 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8** %3, align 8
%arridx = getelementptr inbounds [1 x i8*], [1 x i8*]* %literal, i64 0, i64 0
%4 = load i8*, i8** %arridx, align 8
store i8* %4, i8** %str, align 8
%5 = getelementptr inbounds i32, [3 x i32]* %literal1, i32 0
store i32 1, i32* %5, align 4
%6 = getelementptr inbounds i32, [3 x i32]* %literal1, i32 1
store i32 2, i32* %6, align 4
%7 = getelementptr inbounds i32, [3 x i32]* %literal1, i32 2
store i32 3, i32* %7, align 4
%8 = bitcast [3 x i32]* %literal1 to i32*
%9 = insertvalue %"int[]" undef, i32* %8, 0
%10 = insertvalue %"int[]" %9, i64 3, 1
%11 = extractvalue %"int[]" %10, 1
%neq = icmp ne i64 %11, 0
%not = xor i1 %neq, true
%12 = zext i1 %not to i8
store i8 %12, i8* %x, align 1
%13 = bitcast %Bar* %b to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %13, i8 0, i64 8, i1 false)
%14 = bitcast %Baz* %z to i8*
call void @llvm.memset.p0i8.i64(i8* align 8 %14, i8 0, i64 8, i1 false)
store [0 x i32] zeroinitializer, [0 x i32]* %literal2, align 4
%15 = bitcast [0 x i32]* %literal2 to i32*
%16 = insertvalue %"int[]" undef, i32* %15, 0
%17 = insertvalue %"int[]" %16, i64 0, 1
store %"int[]" %17, %"int[]"* %sub, align 8
store [0 x %Bar] zeroinitializer, [0 x %Bar]* %literal3, align 4
%18 = bitcast [0 x %Bar]* %literal3 to %Bar*
%19 = insertvalue %"Bar[]" undef, %Bar* %18, 0
%20 = insertvalue %"Bar[]" %19, i64 0, 1
store %"Bar[]" %20, %"Bar[]"* %foo, align 8
%21 = bitcast [3 x %Baz]* %baz to i8*
call void @llvm.memset.p0i8.i64(i8* align 16 %21, i8 0, i64 24, i1 false)
ret i32 1
}

View File

@@ -0,0 +1,93 @@
// #target: x64-darwin
import std::io;
import std::mem;
union Baz
{
int x;
double y;
}
struct Bar
{
int x;
int y;
}
func void test()
{
Bar[] b = { { 1, 2 } };
static Bar[] c = { { 1, 2 } };
io::printf("%d %d\n", b[0].y, c[0].y);
b[0].y += 1;
c[0].y += 1;
}
func int main()
{
test();
test();
test();
return 1;
}
// #expect: statics.ll
%Bar = type { i32, i32 }
%"Bar[]" = type { %Bar*, i64 }
@Baz = linkonce_odr constant i8 1
@Bar = linkonce_odr constant i8 1
@.taddr = private hidden global [1 x %Bar] [%Bar { i32 1, i32 2 }], align 4
@test.c = hidden global %"Bar[]" { %Bar* getelementptr inbounds ([1 x %Bar], [1 x %Bar]* @.taddr, i32 0, i32 0), i64 1 }, align 8
@.str = private constant [7 x i8] c"%d %d\0A\00", align 1
declare i32 @printf(i8*, ...)
; Function Attrs: nounwind
define void @statics.test() #0 {
entry:
%b = alloca %"Bar[]", align 8
%literal = alloca [1 x %Bar], align 4
%0 = getelementptr inbounds %Bar, [1 x %Bar]* %literal, i32 0
%1 = getelementptr inbounds %Bar, %Bar* %0, i32 0, i32 0
store i32 1, i32* %1, align 4
%2 = getelementptr inbounds %Bar, %Bar* %0, i32 0, i32 1
store i32 2, i32* %2, align 4
%3 = bitcast [1 x %Bar]* %literal to %Bar*
%4 = insertvalue %"Bar[]" undef, %Bar* %3, 0
%5 = insertvalue %"Bar[]" %4, i64 1, 1
store %"Bar[]" %5, %"Bar[]"* %b, align 8
%subarrayptr = getelementptr inbounds %"Bar[]", %"Bar[]"* %b, i32 0, i32 0
%saptr = load %Bar*, %Bar** %subarrayptr, align 8
%sarridx = getelementptr inbounds %Bar, %Bar* %saptr, i64 0
%6 = getelementptr inbounds %Bar, %Bar* %sarridx, i32 0, i32 1
%7 = load i32, i32* %6, align 4
%saptr1 = load %Bar*, %Bar** getelementptr inbounds (%"Bar[]", %"Bar[]"* @test.c, i32 0, i32 0), align 8
%sarridx2 = getelementptr inbounds %Bar, %Bar* %saptr1, i64 0
%8 = getelementptr inbounds %Bar, %Bar* %sarridx2, i32 0, i32 1
%9 = load i32, i32* %8, align 4
%10 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i32 %7, i32 %9)
%subarrayptr3 = getelementptr inbounds %"Bar[]", %"Bar[]"* %b, i32 0, i32 0
%saptr4 = load %Bar*, %Bar** %subarrayptr3, align 8
%sarridx5 = getelementptr inbounds %Bar, %Bar* %saptr4, i64 0
%11 = getelementptr inbounds %Bar, %Bar* %sarridx5, i32 0, i32 1
%12 = load i32, i32* %11, align 4
%add = add i32 %12, 1
store i32 %add, i32* %11, align 4
%saptr6 = load %Bar*, %Bar** getelementptr inbounds (%"Bar[]", %"Bar[]"* @test.c, i32 0, i32 0), align 8
%sarridx7 = getelementptr inbounds %Bar, %Bar* %saptr6, i64 0
%13 = getelementptr inbounds %Bar, %Bar* %sarridx7, i32 0, i32 1
%14 = load i32, i32* %13, align 4
%add8 = add i32 %14, 1
store i32 %add8, i32* %13, align 4
ret void
}
; Function Attrs: nounwind
define i32 @main() #0 {
entry:
call void @statics.test()
call void @statics.test()
call void @statics.test()
ret i32 1
}

View File

@@ -0,0 +1,180 @@
// #target: x64-darwin
import std::io;
import std::mem;
union Baz
{
int x;
double y;
}
struct Bar
{
int x;
int y;
}
Bar[] arrbar = { { 3, 4 }, { 8, 9 }};
int[] xd = { 1, 2 };
int* fofeo = &&(int[2]{ 3, 4 });
func int main()
{
Bar w = arrbar[1];
io::printf("%d\n", arrbar[1].x);
int[] x = { 1, 2, 3 };
int* y = &&(int[3]{ 123, 234, 567 });
io::println("Start:");
io::printf("X len: %d mid element %d\n", (int)(x.len), x[1]);
io::printf("Y mid element %d\n", y[1]);
io::printf("Fofeo second element %d\n", fofeo[1]);
Baz ffe = { .x = 1 };
int[1] azz = {};
int[*] a = {};
//var $foo = { 1, 2, 3 };
bool xy = ! int[] { 1, 2, 3 };
if (!xy) io::println("Ok");
Bar b = {};
Baz z = {};
int[] sub = {};
Bar[] foo = {};
Baz[3] baz = {};
return 1;
}
// #expect: subarrays.ll
%Bar = type { i32, i32 }
%"Bar[]" = type { %Bar*, i64 }
%"int[]" = type { i32*, i64 }
%Baz = type { double }
@Baz = linkonce_odr constant i8 1
@Bar = linkonce_odr constant i8 1
@.taddr = private hidden global [2 x %Bar] [%Bar { i32 3, i32 4 }, %Bar { i32 8, i32 9 }], align 4
@subarrays.arrbar = global %"Bar[]" { %Bar* getelementptr inbounds ([2 x %Bar], [2 x %Bar]* @.taddr, i32 0, i32 0), i64 2 }, align 8
@.taddr.3 = private hidden global [2 x i32] [i32 1, i32 2], align 4
@subarrays.xd = global %"int[]" { i32* getelementptr inbounds ([2 x i32], [2 x i32]* @.taddr.3, i32 0, i32 0), i64 2 }, align 8
@.taddr.4 = private hidden global [2 x i32] [i32 3, i32 4], align 4
@subarrays.fofeo = global i32* getelementptr inbounds ([2 x i32], [2 x i32]* @.taddr.4, i32 0, i32 0), align 8
@.str = private constant [4 x i8] c"%d\0A\00", align 1
@.str.5 = private constant [7 x i8] c"Start:\00", align 1
@.str.6 = private constant [26 x i8] c"X len: %d mid element %d\0A\00", align 1
@.str.7 = private constant [18 x i8] c"Y mid element %d\0A\00", align 1
@.str.8 = private constant [25 x i8] c"Fofeo second element %d\0A\00", align 1
@.__const = private constant { i32, [4 x i8] } { i32 1, [4 x i8] undef }, align 8
@.str.9 = private constant [3 x i8] c"Ok\00", align 1
define i32 @main() #0 {
entry:
%w = alloca %Bar, align 4
%x = alloca %"int[]", align 8
%literal = alloca [3 x i32], align 4
%y = alloca i32*, align 8
%literal3 = alloca [3 x i32], align 4
%ffe = alloca %Baz, align 8
%azz = alloca [1 x i32], align 4
%a = alloca [0 x i32], align 4
%xy = alloca i8, align 1
%literal7 = alloca [3 x i32], align 4
%b = alloca %Bar, align 4
%z = alloca %Baz, align 8
%sub = alloca %"int[]", align 8
%literal9 = alloca [0 x i32], align 4
%foo = alloca %"Bar[]", align 8
%literal10 = alloca [0 x %Bar], align 4
%baz = alloca [3 x %Baz], align 16
%saptr = load %Bar*, %Bar** getelementptr inbounds (%"Bar[]", %"Bar[]"* @subarrays.arrbar, i32 0, i32 0), align 8
%sarridx = getelementptr inbounds %Bar, %Bar* %saptr, i64 1
%0 = bitcast %Bar* %w to i8*
%1 = bitcast %Bar* %sarridx to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %0, i8* align 4 %1, i32 8, i1 false)
%saptr1 = load %Bar*, %Bar** getelementptr inbounds (%"Bar[]", %"Bar[]"* @subarrays.arrbar, i32 0, i32 0), align 8
%sarridx2 = getelementptr inbounds %Bar, %Bar* %saptr1, i64 1
%2 = getelementptr inbounds %Bar, %Bar* %sarridx2, i32 0, i32 0
%3 = load i32, i32* %2, align 4
%4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i32 %3)
%5 = getelementptr inbounds i32, [3 x i32]* %literal, i32 0
store i32 1, i32* %5, align 4
%6 = getelementptr inbounds i32, [3 x i32]* %literal, i32 1
store i32 2, i32* %6, align 4
%7 = getelementptr inbounds i32, [3 x i32]* %literal, i32 2
store i32 3, i32* %7, align 4
%8 = bitcast [3 x i32]* %literal to i32*
%9 = insertvalue %"int[]" undef, i32* %8, 0
%10 = insertvalue %"int[]" %9, i64 3, 1
store %"int[]" %10, %"int[]"* %x, align 8
%11 = getelementptr inbounds i32, [3 x i32]* %literal3, i32 0
store i32 123, i32* %11, align 4
%12 = getelementptr inbounds i32, [3 x i32]* %literal3, i32 1
store i32 234, i32* %12, align 4
%13 = getelementptr inbounds i32, [3 x i32]* %literal3, i32 2
store i32 567, i32* %13, align 4
%ptrptr = bitcast [3 x i32]* %literal3 to i32*
store i32* %ptrptr, i32** %y, align 8
%14 = call i32 @"std::io.println"(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i32 0, i32 0)) #3
%len = getelementptr inbounds %"int[]", %"int[]"* %x, i32 0, i32 1
%15 = load i64, i64* %len, align 8
%uisitrunc = trunc i64 %15 to i32
%subarrayptr = getelementptr inbounds %"int[]", %"int[]"* %x, i32 0, i32 0
%saptr4 = load i32*, i32** %subarrayptr, align 8
%sarridx5 = getelementptr inbounds i32, i32* %saptr4, i64 1
%16 = load i32, i32* %sarridx5, align 4
%17 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.6, i32 0, i32 0), i32 %uisitrunc, i32 %16)
%18 = load i32*, i32** %y, align 8
%ptridx = getelementptr inbounds i32, i32* %18, i64 1
%19 = load i32, i32* %ptridx, align 4
%20 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.7, i32 0, i32 0), i32 %19)
%21 = load i32*, i32** @subarrays.fofeo, align 8
%ptridx6 = getelementptr inbounds i32, i32* %21, i64 1
%22 = load i32, i32* %ptridx6, align 4
%23 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i32 0, i32 0), i32 %22)
%24 = bitcast %Baz* %ffe to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %24, i8* align 8 bitcast ({ i32, [4 x i8] }* @.__const to i8*), i32 8, i1 false)
%25 = bitcast [1 x i32]* %azz to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %25, i8 0, i64 4, i1 false)
%26 = bitcast [0 x i32]* %a to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %26, i8 0, i64 0, i1 false)
%27 = getelementptr inbounds i32, [3 x i32]* %literal7, i32 0
store i32 1, i32* %27, align 4
%28 = getelementptr inbounds i32, [3 x i32]* %literal7, i32 1
store i32 2, i32* %28, align 4
%29 = getelementptr inbounds i32, [3 x i32]* %literal7, i32 2
store i32 3, i32* %29, align 4
%30 = bitcast [3 x i32]* %literal7 to i32*
%31 = insertvalue %"int[]" undef, i32* %30, 0
%32 = insertvalue %"int[]" %31, i64 3, 1
%33 = extractvalue %"int[]" %32, 1
%neq = icmp ne i64 %33, 0
%not = xor i1 %neq, true
%34 = zext i1 %not to i8
store i8 %34, i8* %xy, align 1
%35 = load i8, i8* %xy, align 1
%36 = trunc i8 %35 to i1
%not8 = xor i1 %36, true
br i1 %not8, label %if.then, label %if.exit
if.then: ; preds = %entry
%37 = call i32 @"std::io.println"(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i32 0, i32 0)) #3
br label %if.exit
if.exit: ; preds = %if.then, %entry
%38 = bitcast %Bar* %b to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %38, i8 0, i64 8, i1 false)
%39 = bitcast %Baz* %z to i8*
call void @llvm.memset.p0i8.i64(i8* align 8 %39, i8 0, i64 8, i1 false)
store [0 x i32] zeroinitializer, [0 x i32]* %literal9, align 4
%40 = bitcast [0 x i32]* %literal9 to i32*
%41 = insertvalue %"int[]" undef, i32* %40, 0
%42 = insertvalue %"int[]" %41, i64 0, 1
store %"int[]" %42, %"int[]"* %sub, align 8
store [0 x %Bar] zeroinitializer, [0 x %Bar]* %literal10, align 4
%43 = bitcast [0 x %Bar]* %literal10 to %Bar*
%44 = insertvalue %"Bar[]" undef, %Bar* %43, 0
%45 = insertvalue %"Bar[]" %44, i64 0, 1
store %"Bar[]" %45, %"Bar[]"* %foo, align 8
%46 = bitcast [3 x %Baz]* %baz to i8*
call void @llvm.memset.p0i8.i64(i8* align 16 %46, i8 0, i64 24, i1 false)
ret i32 1
}

View File

@@ -24,6 +24,15 @@ func int test()
// #expect: zero_init.ll
%Bar = type { i32, i32 }
%Baz = type { double }
%"int[]" = type { i32*, i64 }
%"Bar[]" = type { %Bar*, i64 }
@Baz = linkonce_odr constant i8 1
@Bar = linkonce_odr constant i8 1
; Function Attrs: nounwind
define i32 @zero_init.test() #0 {
entry:
%azz = alloca [1 x i32], align 4
@@ -31,7 +40,9 @@ entry:
%b = alloca %Bar, align 4
%z = alloca %Baz, align 8
%sub = alloca %"int[]", align 8
%literal = alloca [0 x i32], align 4
%foo = alloca %"Bar[]", align 8
%literal1 = alloca [0 x %Bar], align 4
%baz = alloca [3 x %Baz], align 16
%0 = bitcast [1 x i32]* %azz to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %0, i8 0, i64 4, i1 false)
@@ -41,11 +52,17 @@ entry:
call void @llvm.memset.p0i8.i64(i8* align 4 %2, i8 0, i64 8, i1 false)
%3 = bitcast %Baz* %z to i8*
call void @llvm.memset.p0i8.i64(i8* align 8 %3, i8 0, i64 8, i1 false)
%4 = bitcast %"int[]"* %sub to i8*
call void @llvm.memset.p0i8.i64(i8* align 8 %4, i8 0, i64 16, i1 false)
%5 = bitcast %"Bar[]"* %foo to i8*
call void @llvm.memset.p0i8.i64(i8* align 8 %5, i8 0, i64 16, i1 false)
%6 = bitcast [3 x %Baz]* %baz to i8*
call void @llvm.memset.p0i8.i64(i8* align 16 %6, i8 0, i64 24, i1 false)
store [0 x i32] zeroinitializer, [0 x i32]* %literal, align 4
%4 = bitcast [0 x i32]* %literal to i32*
%5 = insertvalue %"int[]" undef, i32* %4, 0
%6 = insertvalue %"int[]" %5, i64 0, 1
store %"int[]" %6, %"int[]"* %sub, align 8
store [0 x %Bar] zeroinitializer, [0 x %Bar]* %literal1, align 4
%7 = bitcast [0 x %Bar]* %literal1 to %Bar*
%8 = insertvalue %"Bar[]" undef, %Bar* %7, 0
%9 = insertvalue %"Bar[]" %8, i64 0, 1
store %"Bar[]" %9, %"Bar[]"* %foo, align 8
%10 = bitcast [3 x %Baz]* %baz to i8*
call void @llvm.memset.p0i8.i64(i8* align 16 %10, i8 0, i64 24, i1 false)
ret i32 1
}
}

View File

@@ -15,10 +15,17 @@ func Event test(int x)
// #expect: test.ll
@Event = linkonce_odr constant i8 1
@.__const = private constant %Event { i32 1 }, align 4
@.__const.1 = private constant %Event { i32 2 }, align 4
; Function Attrs: nounwind
define i32 @test.test(i32 %0) #0 {
entry:
%x = alloca i32, align 4
%foo = alloca %Event, align 4
%bar = alloca %Event, align 4
%tempaddr = alloca %Event, align 4
%taddr = alloca %Event, align 4
store i32 %0, i32* %x, align 4
%1 = bitcast %Event* %foo to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 4 bitcast (%Event* @.__const to i8*), i32 4, i1 false)
@@ -28,17 +35,18 @@ func Event test(int x)
%intbool = icmp ne i32 %3, 0
br i1 %intbool, label %cond.lhs, label %cond.rhs
cond.lhs:
cond.lhs: ; preds = %entry
%4 = load %Event, %Event* %foo, align 4
br label %cond.phi
cond.rhs:
cond.rhs: ; preds = %entry
%5 = load %Event, %Event* %bar, align 4
br label %cond.phi
cond.phi:
cond.phi: ; preds = %cond.rhs, %cond.lhs
%val = phi %Event [ %4, %cond.lhs ], [ %5, %cond.rhs ]
store %Event %val, %Event* %tempaddr, align 4
%dive = getelementptr inbounds %Event, %Event* %tempaddr, i32 0, i32 0
store %Event %val, %Event* %taddr, align 4
%dive = getelementptr inbounds %Event, %Event* %taddr, i32 0, i32 0
%6 = load i32, i32* %dive, align 4
ret i32 %6
ret i32 %6
}

View File

@@ -18,7 +18,7 @@ func Event test(int x)
%x = alloca i32, align 4
%foo = alloca %Event, align 4
%bar = alloca %Event, align 4
%tempaddr = alloca %Event, align 4
%taddr = alloca %Event, align 4
store i32 %0, i32* %x, align 4
%1 = bitcast %Event* %foo to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %1, i8* align 4 bitcast (%Event* @.__const to i8*), i32 4, i1 false)
@@ -38,8 +38,8 @@ cond.rhs:
cond.phi:
%val = phi %Event [ %4, %cond.lhs ], [ %5, %cond.rhs ]
store %Event %val, %Event* %tempaddr, align 4
%dive = getelementptr inbounds %Event, %Event* %tempaddr, i32 0, i32 0
store %Event %val, %Event* %taddr, align 4
%dive = getelementptr inbounds %Event, %Event* %taddr, i32 0, i32 0
%6 = load i32, i32* %dive, align 4
%7 = zext i32 %6 to i64
ret i64 %7

View File

@@ -1,5 +1,19 @@
// #target: x64-darwin
module test;
struct Foo
{
char c;
union {
int a;
double b;
}
int z;
}
Foo foo1 = { .a = 3, .z = 4 };
Foo foo2 = { .b = 3, .z = 4 };
struct Blend_Map_Entry
{
union vals {
@@ -23,6 +37,8 @@ func void test(Blend_Map_Entry* foo)
%Blend_Map_Entry = type { %vals }
%vals = type { [2 x double], [8 x i8] }
@test.foo1 = global { i8, [4 x i8], { i32, [4 x i8] }, i32 } { i8 0, [4 x i8] undef, { i32, [4 x i8] } { i32 3, [4 x i8] undef }, i32 4 }, align 8
@test.foo2 = global %Foo { i8 0, %anon { double 3.000000e+00 }, i32 4 }, align 8
@test.a = global { { [5 x float], [4 x i8] } } { { [5 x float], [4 x i8] } { [5 x float] [float 1.000000e+00, float 2.000000e+00, float 3.000000e+00, float 4.000000e+00, float 5.000000e+00], [4 x i8] undef } }, align 8
@test.b = global %Blend_Map_Entry { %vals { [2 x double] [double 6.000000e+00, double 7.000000e+00], [8 x i8] undef } }, align 8
@test.c = global { { { [2 x float], float, [2 x float] }, [4 x i8] } } { { { [2 x float], float, [2 x float] }, [4 x i8] } { { [2 x float], float, [2 x float] } { [2 x float] zeroinitializer, float 1.000000e+00, [2 x float] zeroinitializer }, [4 x i8] undef } }, align 8