Files
c3c/test/test_suite/expressions/addr_compiles.c3t

144 lines
4.2 KiB
C

// #target: x64-darwin
module test;
extern func void printf(char*, ...);
func void main()
{
test();
test2();
test3();
}
func void test()
{
int f = 3;
int* x = &(((f)));
int* h = &&(f++);
printf("x = %d (4), h = %d (3)\n", *x, *h);
}
const int XX = 314;
func void test2()
{
int* w = &XX;
printf("w = %d (314)\n", *w);
}
struct Foo
{
int x;
int y;
}
func void test3()
{
Foo h = { 345, 555 };
int* zx = &h.x;
int* zy = &h.y;
int[3] arr = { 333, 444, 999 };
printf("zx = %d (345) zy = %d (555)\n", *zx, *zy);
arr[0]--;
arr[1]--;
arr[2]--;
int* d = &arr[2];
int[]* e = &&arr[1..2];
printf("d = %d (998) e = %d (443)\n", *d, (*e)[0]);
}
/* #expect: test.ll
define void @main() #0 {
entry:
call void @test.test()
call void @test.test2()
call void @test.test3()
ret void
}
; Function Attrs: nounwind
define void @test.test() #0 {
entry:
%f = alloca i32, align 4
%x = alloca i32*, align 8
%h = alloca i32*, align 8
%taddr = alloca i32, align 4
store i32 3, i32* %f, align 4
store i32* %f, i32** %x, align 8
%0 = load i32, i32* %f, align 4
%add = add i32 %0, 1
store i32 %add, i32* %f, align 4
store i32 %0, i32* %taddr, align 4
store i32* %taddr, i32** %h, align 8
%1 = load i32*, i32** %x, align 8
%2 = load i32, i32* %1, align 8
%3 = load i32*, i32** %h, align 8
%4 = load i32, i32* %3, align 8
call void (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i32 0, i32 0), i32 %2, i32 %4)
ret void
}
; Function Attrs: nounwind
define void @test.test2() #0 {
entry:
%w = alloca i32*, align 8
store i32* @test.XX, i32** %w, align 8
%0 = load i32*, i32** %w, align 8
%1 = load i32, i32* %0, align 8
call void (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i32 0, i32 0), i32 %1)
ret void
}
; Function Attrs: nounwind
define void @test.test3() #0 {
entry:
%h = alloca %Foo, align 4
%zx = alloca i32*, align 8
%zy = alloca i32*, align 8
%arr = alloca [3 x i32], align 4
%d = alloca i32*, align 8
%e = alloca %"int[]"*, align 8
%taddr = alloca %"int[]", align 8
%0 = bitcast %Foo* %h to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %0, i8* align 4 bitcast (%Foo* @.__const to i8*), i32 8, i1 false)
%1 = getelementptr inbounds %Foo, %Foo* %h, i32 0, i32 0
store i32* %1, i32** %zx, align 8
%2 = getelementptr inbounds %Foo, %Foo* %h, i32 0, i32 1
store i32* %2, i32** %zy, align 8
%3 = bitcast [3 x i32]* %arr to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %3, i8* align 4 bitcast ([3 x i32]* @.__const.2 to i8*), i32 12, i1 false)
%4 = load i32*, i32** %zx, align 8
%5 = load i32, i32* %4, align 8
%6 = load i32*, i32** %zy, align 8
%7 = load i32, i32* %6, align 8
call void (i8*, ...) @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i32 0, i32 0), i32 %5, i32 %7)
%8 = getelementptr inbounds [3 x i32], [3 x i32]* %arr, i64 0, i64 0
%9 = load i32, i32* %8, align 4
%sub = sub i32 %9, 1
store i32 %sub, i32* %8, align 4
%10 = getelementptr inbounds [3 x i32], [3 x i32]* %arr, i64 0, i64 1
%11 = load i32, i32* %10, align 4
%sub1 = sub i32 %11, 1
store i32 %sub1, i32* %10, align 4
%12 = getelementptr inbounds [3 x i32], [3 x i32]* %arr, i64 0, i64 2
%13 = load i32, i32* %12, align 4
%sub2 = sub i32 %13, 1
store i32 %sub2, i32* %12, align 4
%14 = getelementptr inbounds [3 x i32], [3 x i32]* %arr, i64 0, i64 2
store i32* %14, i32** %d, align 8
%15 = getelementptr inbounds [3 x i32], [3 x i32]* %arr, i64 0, i64 1
%16 = insertvalue %"int[]" undef, i32* %15, 0
%17 = insertvalue %"int[]" %16, i64 2, 1
store %"int[]" %17, %"int[]"* %taddr, align 8
store %"int[]"* %taddr, %"int[]"** %e, align 8
%18 = load i32*, i32** %d, align 8
%19 = load i32, i32* %18, align 8
%20 = load %"int[]"*, %"int[]"** %e, align 8
%21 = getelementptr inbounds %"int[]", %"int[]"* %20, i32 0, i32 0
%22 = load i32*, i32** %21, align 8
%ptroffset = getelementptr inbounds i32, i32* %22, i64 0
%23 = load i32, i32* %ptroffset, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.4, i32 0, i32 0), i32 %19, i32 %23)
ret void
}