mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
104 lines
2.2 KiB
C
104 lines
2.2 KiB
C
// #target: macos-x64
|
|
|
|
module foo;
|
|
|
|
extern fn void printf(char*, ...);
|
|
|
|
bitstruct Foo : uint
|
|
{
|
|
int x : 1..3;
|
|
uint y : 11..13;
|
|
int z : 15..15;
|
|
}
|
|
|
|
bitstruct Foo2 : char[4]
|
|
{
|
|
int x : 1..3;
|
|
uint y : 11..13;
|
|
int z : 15..15;
|
|
}
|
|
|
|
fn void test()
|
|
{
|
|
Foo b = {};
|
|
int x = (int)b;
|
|
char[4] y = (char[4])b;
|
|
Foo *c = &b;
|
|
c.x;
|
|
int* x2 = (int*)c;
|
|
char[4]* y2 = (char[4]*)c;
|
|
}
|
|
|
|
fn void test2()
|
|
{
|
|
Foo2 b = { 3, 2, -1 };
|
|
int x = (int)b;
|
|
char[4] y = (char[4])b;
|
|
Foo2 *c = &b;
|
|
printf("%d\n", c.x);
|
|
int* x2 = (int*)c;
|
|
char[4]* y2 = (char[4]*)c;
|
|
}
|
|
|
|
fn void main()
|
|
{
|
|
test();
|
|
test2();
|
|
}
|
|
|
|
/* #expect: foo.ll
|
|
|
|
define void @foo.test() #0 {
|
|
entry:
|
|
%b = alloca i32, align 4
|
|
%x = alloca i32, align 4
|
|
%y = alloca [4 x i8], align 1
|
|
%c = alloca ptr, align 8
|
|
%x2 = alloca ptr, align 8
|
|
%y2 = alloca ptr, align 8
|
|
store i32 0, ptr %b, align 4
|
|
%0 = load i32, ptr %b, align 4
|
|
store i32 %0, ptr %x, align 4
|
|
%1 = load [4 x i8], ptr %b, align 4
|
|
store [4 x i8] %1, ptr %y, align 1
|
|
store ptr %b, ptr %c, align 8
|
|
%2 = load ptr, ptr %c, align 8
|
|
%3 = load i32, ptr %2, align 4
|
|
%shl = shl i32 %3, 28
|
|
%ashr = ashr i32 %shl, 29
|
|
%4 = load ptr, ptr %c, align 8
|
|
store ptr %4, ptr %x2, align 8
|
|
%5 = load ptr, ptr %c, align 8
|
|
store ptr %5, ptr %y2, align 8
|
|
ret void
|
|
}
|
|
|
|
; Function Attrs: nounwind
|
|
define void @foo.test2() #0 {
|
|
entry:
|
|
%b = alloca [4 x i8], align 1
|
|
%x = alloca i32, align 4
|
|
%y = alloca [4 x i8], align 1
|
|
%c = alloca ptr, align 8
|
|
%x2 = alloca ptr, align 8
|
|
%y2 = alloca ptr, align 8
|
|
store [4 x i8] c"\06\90\00\00", ptr %b, align 1
|
|
%0 = load i32, ptr %b, align 1
|
|
store i32 %0, ptr %x, align 4
|
|
call void @llvm.memcpy.p0.p0.i32(ptr align 1 %y, ptr align 1 %b, i32 4, i1 false)
|
|
store ptr %b, ptr %c, align 8
|
|
%1 = load ptr, ptr %c, align 8
|
|
%2 = getelementptr inbounds [4 x i8], ptr %1, i64 0, i64 0
|
|
%3 = load i8, ptr %2, align 1
|
|
%zext = zext i8 %3 to i32
|
|
%lshrl = lshr i32 %zext, 1
|
|
%shl = shl i32 %lshrl, 29
|
|
%ashr = ashr i32 %shl, 29
|
|
call void (ptr, ...) @printf(ptr @.str, i32 %ashr)
|
|
%4 = load ptr, ptr %c, align 8
|
|
store ptr %4, ptr %x2, align 8
|
|
%5 = load ptr, ptr %c, align 8
|
|
store ptr %5, ptr %y2, align 8
|
|
ret void
|
|
}
|