mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
More variant code. Fixes to typekind. Fixes to macro with failable returns. Remove use of LLVMConstInsert etc. Version 0.2.8
97 lines
3.0 KiB
C
97 lines
3.0 KiB
C
// #target: macos-x64
|
|
|
|
union Baz
|
|
{
|
|
int x;
|
|
double y;
|
|
}
|
|
struct Bar
|
|
{
|
|
int x;
|
|
int y;
|
|
}
|
|
|
|
fn int test()
|
|
{
|
|
Baz ffe = { .x = 1 };
|
|
int[1] azz = {};
|
|
int[*] a = {};
|
|
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 = {};
|
|
int[] sub = {};
|
|
Bar[] foo = {};
|
|
Baz[3] baz = {};
|
|
return 1;
|
|
}
|
|
|
|
|
|
/* #expect: general_tests.ll
|
|
|
|
%Baz = type { double }
|
|
%Bar = type { i32, i32 }
|
|
%"int[]" = type { ptr, i64 }
|
|
%"Bar[]" = type { ptr, i64 }
|
|
|
|
@.typeid.general_tests.Baz = linkonce constant { i8, i64 } { i8 11, i64 2 }, align 8
|
|
@.typeid.general_tests.Bar = linkonce constant { i8, i64 } { i8 10, i64 2 }, align 8
|
|
@.__const = private unnamed_addr constant { i32, [4 x i8] } { i32 1, [4 x i8] undef }, align 8
|
|
@test.foo1 = internal unnamed_addr global i32 22, align 4
|
|
@.str = private unnamed_addr 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 ptr, align 8
|
|
%x = alloca i8, align 1
|
|
%literal = alloca [3 x i32], align 4
|
|
%b = alloca %Bar, align 4
|
|
%z = alloca %Baz, align 8
|
|
%sub = alloca %"int[]", align 8
|
|
%literal1 = alloca [0 x i32], align 4
|
|
%foo = alloca %"Bar[]", align 8
|
|
%literal2 = alloca [0 x %Bar], align 4
|
|
%baz = alloca [3 x %Baz], align 16
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 8 %ffe, ptr align 8 @.__const, i32 8, i1 false)
|
|
%0 = getelementptr inbounds [1 x i32], ptr %azz, i64 0, i64 0
|
|
store i32 0, ptr %0, align 4
|
|
store i32 33, ptr %foo2, align 4
|
|
store ptr @.str, ptr %str, align 8
|
|
%1 = getelementptr inbounds [3 x i32], ptr %literal, i64 0, i64 0
|
|
store i32 1, ptr %1, align 4
|
|
%2 = getelementptr inbounds [3 x i32], ptr %literal, i64 0, i64 1
|
|
store i32 2, ptr %2, align 4
|
|
%3 = getelementptr inbounds [3 x i32], ptr %literal, i64 0, i64 2
|
|
store i32 3, ptr %3, align 4
|
|
%4 = insertvalue %"int[]" undef, ptr %literal, 0
|
|
%5 = insertvalue %"int[]" %4, i64 3, 1
|
|
%6 = extractvalue %"int[]" %5, 1
|
|
%not = icmp eq i64 %6, 0
|
|
%7 = zext i1 %not to i8
|
|
store i8 %7, ptr %x, align 1
|
|
%8 = getelementptr inbounds %Bar, ptr %b, i32 0, i32 0
|
|
store i32 0, ptr %8, align 4
|
|
%9 = getelementptr inbounds %Bar, ptr %b, i32 0, i32 1
|
|
store i32 0, ptr %9, align 4
|
|
call void @llvm.memset.p0.i64(ptr align 8 %z, i8 0, i64 8, i1 false)
|
|
store [0 x i32] zeroinitializer, ptr %literal1, align 4
|
|
%10 = insertvalue %"int[]" undef, ptr %literal1, 0
|
|
%11 = insertvalue %"int[]" %10, i64 0, 1
|
|
store %"int[]" %11, ptr %sub, align 8
|
|
store [0 x %Bar] zeroinitializer, ptr %literal2, align 4
|
|
%12 = insertvalue %"Bar[]" undef, ptr %literal2, 0
|
|
%13 = insertvalue %"Bar[]" %12, i64 0, 1
|
|
store %"Bar[]" %13, ptr %foo, align 8
|
|
call void @llvm.memset.p0.i64(ptr align 16 %baz, i8 0, i64 24, i1 false)
|
|
ret i32 1
|
|
}
|