Files
c3c/test/test_suite/pointers/array_pointer_decay.c3t
2022-12-15 23:46:26 +01:00

84 lines
3.2 KiB
C

// #target: macos-x64
module foo;
extern fn void printf(char*, ...);
fn void main()
{
int[3] x;
int[3]* y = &x;
int* z = y;
int[] sub = y;
int[3] y1 = y[1];
int z1 = z[1];
int* xx = &x + 1;
int[3]* yy = (int[3]*)(xx);
int* zz = yy - 1;
printf("%p = %p = %p, %p = %p\n", y, z, zz, &(*y)[1], xx);
x[1] = 123;
printf("%d = %d\n", x[1], z[1]);
}
/* #expect: foo.ll
define void @foo_main() #0 {
entry:
%x = alloca [3 x i32], align 4
%y = alloca [3 x i32]*, align 8
%z = alloca i32*, align 8
%sub = alloca %"int[]", align 8
%y1 = alloca [3 x i32], align 4
%z1 = alloca i32, align 4
%xx = alloca i32*, align 8
%yy = alloca [3 x i32]*, align 8
%zz = alloca i32*, align 8
%0 = getelementptr inbounds [3 x i32], [3 x i32]* %x, i64 0, i64 0
store i32 0, i32* %0, align 4
%1 = getelementptr inbounds [3 x i32], [3 x i32]* %x, i64 0, i64 1
store i32 0, i32* %1, align 4
%2 = getelementptr inbounds [3 x i32], [3 x i32]* %x, i64 0, i64 2
store i32 0, i32* %2, align 4
store [3 x i32]* %x, [3 x i32]** %y, align 8
%3 = load [3 x i32]*, [3 x i32]** %y, align 8
%ptrptr = bitcast [3 x i32]* %3 to i32*
store i32* %ptrptr, i32** %z, align 8
%4 = load [3 x i32]*, [3 x i32]** %y, align 8
%5 = bitcast [3 x i32]* %4 to i32*
%6 = insertvalue %"int[]" undef, i32* %5, 0
%7 = insertvalue %"int[]" %6, i64 3, 1
store %"int[]" %7, %"int[]"* %sub, align 8
%8 = load [3 x i32]*, [3 x i32]** %y, align 8
%ptroffset = getelementptr inbounds [3 x i32], [3 x i32]* %8, i64 1
%9 = bitcast [3 x i32]* %y1 to i8*
%10 = bitcast [3 x i32]* %ptroffset to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 4 %9, i8* align 4 %10, i32 12, i1 false)
%11 = load i32*, i32** %z, align 8
%ptroffset1 = getelementptr inbounds i32, i32* %11, i64 1
%12 = load i32, i32* %ptroffset1, align 4
store i32 %12, i32* %z1, align 4
%ptrptr2 = bitcast [3 x i32]* %x to i32*
%ptroffset3 = getelementptr i32, i32* %ptrptr2, i64 1
store i32* %ptroffset3, i32** %xx, align 8
%13 = load i32*, i32** %xx, align 8
%ptrptr4 = bitcast i32* %13 to [3 x i32]*
store [3 x i32]* %ptrptr4, [3 x i32]** %yy, align 8
%14 = load [3 x i32]*, [3 x i32]** %yy, align 8
%ptrptr5 = bitcast [3 x i32]* %14 to i32*
%ptroffset6 = getelementptr i32, i32* %ptrptr5, i64 -1
store i32* %ptroffset6, i32** %zz, align 8
%15 = load [3 x i32]*, [3 x i32]** %y, align 8
%16 = load i32*, i32** %z, align 8
%17 = load i32*, i32** %zz, align 8
%18 = load [3 x i32]*, [3 x i32]** %y, align 8
%19 = getelementptr inbounds [3 x i32], [3 x i32]* %18, i64 0, i64 1
%20 = load i32*, i32** %xx, align 8
call void (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str, i32 0, i32 0), [3 x i32]* %15, i32* %16, i32* %17, i32* %19, i32* %20)
%21 = getelementptr inbounds [3 x i32], [3 x i32]* %x, i64 0, i64 1
store i32 123, i32* %21, align 4
%22 = getelementptr inbounds [3 x i32], [3 x i32]* %x, i64 0, i64 1
%23 = load i32, i32* %22, align 4
%24 = load i32*, i32** %z, align 8
%ptroffset7 = getelementptr inbounds i32, i32* %24, i64 1
%25 = load i32, i32* %ptroffset7, align 4
call void (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i32 0, i32 0), i32 %23, i32 %25)
ret void
}