Files
c3c/test/test_suite/initializer_lists/general_tests.c3t
Christoffer Lerno 002ee006c1 More efficient int[] a = {}; Disallow zero length arrays. Bump to 0.2.19 (#489)
More efficient int[] a = {}; Disallow zero length arrays. Bump to 0.2.19. Improve error on mistyped types.
2022-07-20 22:25:03 +02:00

90 lines
2.9 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 = {};
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 { i32*, i64 }
%"Bar[]" = type { %Bar*, i64 }
@"ct$general_tests_Baz" = linkonce constant %.introspect { i8 11, i64 8, i64 0, i64 2, [0 x i64] zeroinitializer }, align 8
@"ct$general_tests_Bar" = linkonce constant %.introspect { i8 10, i64 8, i64 0, i64 2, [0 x i64] zeroinitializer }, 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
%foo2 = alloca i32, align 4
%str = alloca i8*, 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
%foo = alloca %"Bar[]", align 8
%baz = alloca [3 x %Baz], align 16
%0 = bitcast %Baz* %ffe to i8*
call void @llvm.memcpy.p0i8.p0i8.i32(i8* align 8 %0, i8* align 8 bitcast ({ i32, [4 x i8] }* @.__const to i8*), i32 8, i1 false)
%1 = getelementptr inbounds [1 x i32], [1 x i32]* %azz, i64 0, i64 0
store i32 0, i32* %1, align 4
store i32 33, i32* %foo2, align 4
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i8** %str, align 8
%2 = getelementptr inbounds [3 x i32], [3 x i32]* %literal, i64 0, i64 0
store i32 1, i32* %2, align 4
%3 = getelementptr inbounds [3 x i32], [3 x i32]* %literal, i64 0, i64 1
store i32 2, i32* %3, align 4
%4 = getelementptr inbounds [3 x i32], [3 x i32]* %literal, i64 0, i64 2
store i32 3, i32* %4, align 4
%5 = bitcast [3 x i32]* %literal to i32*
%6 = insertvalue %"int[]" undef, i32* %5, 0
%7 = insertvalue %"int[]" %6, i64 3, 1
%8 = extractvalue %"int[]" %7, 1
%not = icmp eq i64 %8, 0
%9 = zext i1 %not to i8
store i8 %9, i8* %x, align 1
%10 = getelementptr inbounds %Bar, %Bar* %b, i32 0, i32 0
store i32 0, i32* %10, align 4
%11 = getelementptr inbounds %Bar, %Bar* %b, i32 0, i32 1
store i32 0, i32* %11, align 4
%12 = bitcast %Baz* %z to i8*
call void @llvm.memset.p0i8.i64(i8* align 8 %12, i8 0, i64 8, i1 false)
store %"int[]" zeroinitializer, %"int[]"* %sub, align 8
store %"Bar[]" zeroinitializer, %"Bar[]"* %foo, align 8
%13 = bitcast [3 x %Baz]* %baz to i8*
call void @llvm.memset.p0i8.i64(i8* align 16 %13, i8 0, i64 24, i1 false)
ret i32 1
}