Files
c3c/test/test_suite/pointers/pointer_index.c3t
2022-01-04 23:16:32 +01:00

79 lines
1.9 KiB
C

module pointer_index;
fn void test1(int* x)
{
int a = x[0];
int b = *x;
int c = x[1];
int d = x[-1];
}
fn void test2(char* x)
{
char a = x[0];
char b = *x;
char c = x[1];
}
fn void test3(long* x)
{
long a = x[0];
long b = *x;
long c = x[1];
}
// #expect: pointer_index.ll
define void @pointer_index.test1(i32* %0) #0 {
entry:
%a = alloca i32, align 4
%b = alloca i32, align 4
%c = alloca i32, align 4
%d = alloca i32, align 4
%ptroffset = getelementptr inbounds i32, i32* %0, i64 0
%1 = load i32, i32* %ptroffset, align 4
store i32 %1, i32* %a, align 4
%2 = load i32, i32* %0, align 8
store i32 %2, i32* %b, align 4
%ptroffset1 = getelementptr inbounds i32, i32* %0, i64 1
%3 = load i32, i32* %ptroffset1, align 4
store i32 %3, i32* %c, align 4
%ptroffset2 = getelementptr inbounds i32, i32* %0, i64 -1
%4 = load i32, i32* %ptroffset2, align 4
store i32 %4, i32* %d, align 4
ret void
}
; Function Attrs: nounwind
define void @pointer_index.test2(i8* %0) #0 {
entry:
%a = alloca i8, align 1
%b = alloca i8, align 1
%c = alloca i8, align 1
%ptroffset = getelementptr inbounds i8, i8* %0, i64 0
%1 = load i8, i8* %ptroffset, align 1
store i8 %1, i8* %a, align 1
%2 = load i8, i8* %0, align 8
store i8 %2, i8* %b, align 1
%ptroffset1 = getelementptr inbounds i8, i8* %0, i64 1
%3 = load i8, i8* %ptroffset1, align 1
store i8 %3, i8* %c, align 1
ret void
}
define void @pointer_index.test3(i64* %0) #0 {
entry:
%a = alloca i64, align 8
%b = alloca i64, align 8
%c = alloca i64, align 8
%ptroffset = getelementptr inbounds i64, i64* %0, i64 0
%1 = load i64, i64* %ptroffset, align 8
store i64 %1, i64* %a, align 8
%2 = load i64, i64* %0, align 8
store i64 %2, i64* %b, align 8
%ptroffset1 = getelementptr inbounds i64, i64* %0, i64 1
%3 = load i64, i64* %ptroffset1, align 8
store i64 %3, i64* %c, align 8
ret void
}