Files
c3c/test/test_suite/initializer_lists/zero_init.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

62 lines
1.4 KiB
C

// #target: macos-x64
union Baz
{
int x;
double y;
}
struct Bar
{
int x;
int y;
}
struct Mega
{
int[10] z;
}
fn int test()
{
Mega m = {};
int[1] azz = {};
Bar b = {};
Baz z = {};
int[] sub = {};
Bar[] foo = {};
Baz[3] baz = {};
return 1;
}
// #expect: zero_init.ll
%Mega = type { [10 x i32] }
%Bar = type { i32, i32 }
%Baz = type { double }
define i32 @zero_init_test() #0 {
entry:
%m = alloca %Mega, align 4
%azz = alloca [1 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 %Mega* %m to i8*
call void @llvm.memset.p0i8.i64(i8* align 4 %0, i8 0, i64 40, i1 false)
%1 = getelementptr inbounds [1 x i32], [1 x i32]* %azz, i64 0, i64 0
store i32 0, i32* %1, align 4
%2 = getelementptr inbounds %Bar, %Bar* %b, i32 0, i32 0
store i32 0, i32* %2, align 4
%3 = getelementptr inbounds %Bar, %Bar* %b, i32 0, i32 1
store i32 0, i32* %3, align 4
%4 = bitcast %Baz* %z to i8*
call void @llvm.memset.p0i8.i64(i8* align 8 %4, i8 0, i64 8, i1 false)
store %"int[]" zeroinitializer, %"int[]"* %sub, align 8
store %"Bar[]" zeroinitializer, %"Bar[]"* %foo, align 8
%5 = bitcast [3 x %Baz]* %baz to i8*
call void @llvm.memset.p0i8.i64(i8* align 16 %5, i8 0, i64 24, i1 false)
ret i32 1
}