Files
c3c/test/test_suite/initializer_lists/statics.c3t

95 lines
2.8 KiB
C

// #target: x64-darwin
import std::io;
import std::mem;
union Baz
{
int x;
double y;
}
struct Bar
{
int x;
int y;
}
func void test()
{
Bar[] b = { { 1, 2 } };
static Bar[] c = { { 1, 2 } };
io::printf("%d %d\n", b[0].y, c[0].y);
b[0].y += 1;
c[0].y += 1;
}
func int main()
{
test();
test();
test();
return 1;
}
// #expect: statics.ll
%Bar = type { i32, i32 }
%"Bar[]" = type { %Bar*, i64 }
@Baz = linkonce_odr constant i8 1
@Bar = linkonce_odr constant i8 1
@.taddr = private hidden global [1 x %Bar] [%Bar { i32 1, i32 2 }], align 4
@test.c = hidden global %"Bar[]" { %Bar* getelementptr inbounds ([1 x %Bar], [1 x %Bar]* @.taddr, i32 0, i32 0), i64 1 }, align 8
@.str = private constant [7 x i8] c"%d %d\0A\00", align 1
declare i32 @printf(i8*, ...)
; Function Attrs: nounwind
define void @statics.test() #0 {
entry:
%b = alloca %"Bar[]", align 8
%literal = alloca [1 x %Bar], align 4
%0 = getelementptr inbounds [1 x %Bar], [1 x %Bar]* %literal, i64 0, i64 0
%1 = getelementptr inbounds %Bar, %Bar* %0, i32 0, i32 0
store i32 1, i32* %1, align 4
%2 = getelementptr inbounds %Bar, %Bar* %0, i32 0, i32 1
store i32 2, i32* %2, align 4
%3 = bitcast [1 x %Bar]* %literal to %Bar*
%4 = insertvalue %"Bar[]" undef, %Bar* %3, 0
%5 = insertvalue %"Bar[]" %4, i64 1, 1
store %"Bar[]" %5, %"Bar[]"* %b, align 8
%6 = getelementptr inbounds %"Bar[]", %"Bar[]"* %b, i32 0, i32 0
%7 = load %Bar*, %Bar** %6, align 8
%ptroffset = getelementptr inbounds %Bar, %Bar* %7, i64 0
%8 = getelementptr inbounds %Bar, %Bar* %ptroffset, i32 0, i32 1
%9 = load i32, i32* %8, align 4
%10 = load %Bar*, %Bar** getelementptr inbounds (%"Bar[]", %"Bar[]"* @test.c, i32 0, i32 0), align 8
%ptroffset1 = getelementptr inbounds %Bar, %Bar* %10, i64 0
%11 = getelementptr inbounds %Bar, %Bar* %ptroffset1, i32 0, i32 1
%12 = load i32, i32* %11, align 4
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i32 0, i32 0), i32 %9, i32 %12)
%14 = getelementptr inbounds %"Bar[]", %"Bar[]"* %b, i32 0, i32 0
%15 = load %Bar*, %Bar** %14, align 8
%ptroffset2 = getelementptr inbounds %Bar, %Bar* %15, i64 0
%16 = getelementptr inbounds %Bar, %Bar* %ptroffset2, i32 0, i32 1
%17 = load i32, i32* %16, align 4
%add = add i32 %17, 1
store i32 %add, i32* %16, align 4
%18 = load %Bar*, %Bar** getelementptr inbounds (%"Bar[]", %"Bar[]"* @test.c, i32 0, i32 0), align 8
%ptroffset3 = getelementptr inbounds %Bar, %Bar* %18, i64 0
%19 = getelementptr inbounds %Bar, %Bar* %ptroffset3, i32 0, i32 1
%20 = load i32, i32* %19, align 4
%add4 = add i32 %20, 1
store i32 %add4, i32* %19, align 4
ret void
}
; Function Attrs: nounwind
define i32 @main() #0 {
entry:
call void @statics.test()
call void @statics.test()
call void @statics.test()
ret i32 1
}