mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
138 lines
3.4 KiB
Plaintext
138 lines
3.4 KiB
Plaintext
// #target: macos-x64
|
|
|
|
module test;
|
|
|
|
extern fn void printf(char*, ...);
|
|
|
|
fn void main()
|
|
{
|
|
test();
|
|
test2();
|
|
test3();
|
|
}
|
|
|
|
fn 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;
|
|
fn void test2()
|
|
{
|
|
int* w = &XX;
|
|
printf("w = %d (314)\n", *w);
|
|
}
|
|
|
|
struct Foo
|
|
{
|
|
int x;
|
|
int y;
|
|
}
|
|
fn 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 @test.main() #0 {
|
|
entry:
|
|
call void @test.test()
|
|
call void @test.test2()
|
|
call void @test.test3()
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs:
|
|
define void @test.test() #0 {
|
|
entry:
|
|
%f = alloca i32, align 4
|
|
%x = alloca ptr, align 8
|
|
%h = alloca ptr, align 8
|
|
%taddr = alloca i32, align 4
|
|
store i32 3, ptr %f, align 4
|
|
store ptr %f, ptr %x, align 8
|
|
%0 = load i32, ptr %f, align 4
|
|
%add = add i32 %0, 1
|
|
store i32 %add, ptr %f, align 4
|
|
store i32 %0, ptr %taddr, align 4
|
|
store ptr %taddr, ptr %h, align 8
|
|
%1 = load ptr, ptr %x, align 8
|
|
%2 = load ptr, ptr %h, align 8
|
|
%3 = load i32, ptr %1, align 4
|
|
%4 = load i32, ptr %2, align 4
|
|
call void (ptr, ...) @printf(ptr @.str, i32 %3, i32 %4)
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs:
|
|
define void @test.test2() #0 {
|
|
entry:
|
|
%w = alloca ptr, align 8
|
|
store ptr @test.XX, ptr %w, align 8
|
|
%0 = load ptr, ptr %w, align 8
|
|
%1 = load i32, ptr %0, align 4
|
|
call void (ptr, ...) @printf(ptr @.str.1, i32 %1)
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs:
|
|
define void @test.test3() #0 {
|
|
entry:
|
|
%h = alloca %Foo, align 4
|
|
%zx = alloca ptr, align 8
|
|
%zy = alloca ptr, align 8
|
|
%arr = alloca [3 x i32], align 4
|
|
%d = alloca ptr, align 8
|
|
%e = alloca ptr, align 8
|
|
%taddr = alloca %"int[]", align 8
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %h, ptr align 4 @.__const, i32 8, i1 false)
|
|
store ptr %h, ptr %zx, align 8
|
|
%ptradd = getelementptr inbounds i8, ptr %h, i64 4
|
|
store ptr %ptradd, ptr %zy, align 8
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 4 %arr, ptr align 4 @.__const.2, i32 12, i1 false)
|
|
%0 = load ptr, ptr %zx, align 8
|
|
%1 = load ptr, ptr %zy, align 8
|
|
%2 = load i32, ptr %0, align 4
|
|
%3 = load i32, ptr %1, align 4
|
|
call void (ptr, ...) @printf(ptr @.str.3, i32 %2, i32 %3)
|
|
%4 = load i32, ptr %arr, align 4
|
|
%sub = sub i32 %4, 1
|
|
store i32 %sub, ptr %arr, align 4
|
|
%ptradd1 = getelementptr inbounds i8, ptr %arr, i64 4
|
|
%5 = load i32, ptr %ptradd1, align 4
|
|
%sub2 = sub i32 %5, 1
|
|
store i32 %sub2, ptr %ptradd1, align 4
|
|
%ptradd3 = getelementptr inbounds i8, ptr %arr, i64 8
|
|
%6 = load i32, ptr %ptradd3, align 4
|
|
%sub4 = sub i32 %6, 1
|
|
store i32 %sub4, ptr %ptradd3, align 4
|
|
%ptradd5 = getelementptr inbounds i8, ptr %arr, i64 8
|
|
store ptr %ptradd5, ptr %d, align 8
|
|
%ptradd6 = getelementptr inbounds i8, ptr %arr, i64 4
|
|
%7 = insertvalue %"int[]" undef, ptr %ptradd6, 0
|
|
%8 = insertvalue %"int[]" %7, i64 2, 1
|
|
store %"int[]" %8, ptr %taddr, align 8
|
|
store ptr %taddr, ptr %e, align 8
|
|
%9 = load ptr, ptr %d, align 8
|
|
%10 = load ptr, ptr %e, align 8
|
|
%11 = load ptr, ptr %10, align 8
|
|
%12 = load i32, ptr %9, align 4
|
|
%13 = load i32, ptr %11, align 4
|
|
call void (ptr, ...) @printf(ptr @.str.4, i32 %12, i32 %13)
|
|
ret void
|
|
} |