diff --git a/examples/c/struct4.c b/examples/c/struct4.c new file mode 100644 index 0000000..f43dd63 --- /dev/null +++ b/examples/c/struct4.c @@ -0,0 +1,19 @@ +int nonce = 1; // For random input + +struct Foo +{ + int x; +}; + +struct Foo f() +{ + struct Foo x; + x.x = nonce; + return x; +} + +int main() +{ + int x = f().x; + return x; +} diff --git a/examples/ir0/struct4.ir b/examples/ir0/struct4.ir new file mode 100644 index 0000000..1ffb143 --- /dev/null +++ b/examples/ir0/struct4.ir @@ -0,0 +1,39 @@ +struct Foo : { x:i32 } +var i32 @nonce = 1 + +fun struct Foo @f () { +init: + bid: b0 + allocations: + %l0:struct Foo:x + +block b0: + %b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64 + %b0:i1:i32 = load @nonce:i32* + %b0:i2:unit = store %b0:i1:i32 %b0:i0:i32* + %b0:i3:struct Foo = load %l0:struct Foo* + ret %b0:i3:struct Foo + +block b1: + ret undef:struct Foo +} + +fun i32 @main () { +init: + bid: b0 + allocations: + %l0:i32:x + %l1:struct Foo:t0 + +block b0: + %b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*() + %b0:i1:unit = store %b0:i0:struct Foo %l1:struct Foo* + %b0:i2:i32* = getelementptr %l1:struct Foo* offset 0:i64 + %b0:i3:i32 = load %b0:i2:i32* + %b0:i4:unit = store %b0:i3:i32 %l0:i32* + %b0:i5:i32 = load %l0:i32* + ret %b0:i5:i32 + +block b1: + ret 0:i32 +} diff --git a/examples/ir1/struct4.ir b/examples/ir1/struct4.ir new file mode 100644 index 0000000..7c8fc32 --- /dev/null +++ b/examples/ir1/struct4.ir @@ -0,0 +1,33 @@ +struct Foo : { x:i32 } +var i32 @nonce = 1 + +fun struct Foo @f () { +init: + bid: b0 + allocations: + %l0:struct Foo:x + +block b0: + %b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64 + %b0:i1:i32 = load @nonce:i32* + %b0:i2:unit = store %b0:i1:i32 %b0:i0:i32* + %b0:i3:struct Foo = load %l0:struct Foo* + ret %b0:i3:struct Foo +} + +fun i32 @main () { +init: + bid: b0 + allocations: + %l0:i32:x + %l1:struct Foo:t0 + +block b0: + %b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*() + %b0:i1:unit = store %b0:i0:struct Foo %l1:struct Foo* + %b0:i2:i32* = getelementptr %l1:struct Foo* offset 0:i64 + %b0:i3:i32 = load %b0:i2:i32* + %b0:i4:unit = store %b0:i3:i32 %l0:i32* + %b0:i5:i32 = load %l0:i32* + ret %b0:i5:i32 +} diff --git a/examples/ir2/struct4.ir b/examples/ir2/struct4.ir new file mode 100644 index 0000000..76681a4 --- /dev/null +++ b/examples/ir2/struct4.ir @@ -0,0 +1,33 @@ +struct Foo : { x:i32 } +var i32 @nonce = 1 + +fun struct Foo @f () { +init: + bid: b0 + allocations: + %l0:struct Foo:x + +block b0: + %b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64 + %b0:i1:i32 = load @nonce:i32* + %b0:i2:unit = store %b0:i1:i32 %b0:i0:i32* + %b0:i3:struct Foo = load %l0:struct Foo* + ret %b0:i3:struct Foo +} + +fun i32 @main () { +init: + bid: b0 + allocations: + %l0:i32:x + %l1:struct Foo:t0 + +block b0: + %b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*() + %b0:i1:unit = store %b0:i0:struct Foo %l1:struct Foo* + %b0:i2:i32* = getelementptr %l1:struct Foo* offset 0:i64 + %b0:i3:i32 = load %b0:i2:i32* + %b0:i4:unit = nop + %b0:i5:unit = nop + ret %b0:i3:i32 +} diff --git a/examples/ir3/struct4.ir b/examples/ir3/struct4.ir new file mode 100644 index 0000000..324b374 --- /dev/null +++ b/examples/ir3/struct4.ir @@ -0,0 +1,30 @@ +struct Foo : { x:i32 } +var i32 @nonce = 1 + +fun struct Foo @f () { +init: + bid: b0 + allocations: + %l0:struct Foo:x + +block b0: + %b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64 + %b0:i1:i32 = load @nonce:i32* + %b0:i2:unit = store %b0:i1:i32 %b0:i0:i32* + %b0:i3:struct Foo = load %l0:struct Foo* + ret %b0:i3:struct Foo +} + +fun i32 @main () { +init: + bid: b0 + allocations: + %l0:struct Foo:t0 + +block b0: + %b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*() + %b0:i1:unit = store %b0:i0:struct Foo %l0:struct Foo* + %b0:i2:i32* = getelementptr %l0:struct Foo* offset 0:i64 + %b0:i3:i32 = load %b0:i2:i32* + ret %b0:i3:i32 +} diff --git a/examples/ir4/struct4.ir b/examples/ir4/struct4.ir new file mode 100644 index 0000000..324b374 --- /dev/null +++ b/examples/ir4/struct4.ir @@ -0,0 +1,30 @@ +struct Foo : { x:i32 } +var i32 @nonce = 1 + +fun struct Foo @f () { +init: + bid: b0 + allocations: + %l0:struct Foo:x + +block b0: + %b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64 + %b0:i1:i32 = load @nonce:i32* + %b0:i2:unit = store %b0:i1:i32 %b0:i0:i32* + %b0:i3:struct Foo = load %l0:struct Foo* + ret %b0:i3:struct Foo +} + +fun i32 @main () { +init: + bid: b0 + allocations: + %l0:struct Foo:t0 + +block b0: + %b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*() + %b0:i1:unit = store %b0:i0:struct Foo %l0:struct Foo* + %b0:i2:i32* = getelementptr %l0:struct Foo* offset 0:i64 + %b0:i3:i32 = load %b0:i2:i32* + ret %b0:i3:i32 +} diff --git a/examples/opt/struct4.ir b/examples/opt/struct4.ir new file mode 100644 index 0000000..324b374 --- /dev/null +++ b/examples/opt/struct4.ir @@ -0,0 +1,30 @@ +struct Foo : { x:i32 } +var i32 @nonce = 1 + +fun struct Foo @f () { +init: + bid: b0 + allocations: + %l0:struct Foo:x + +block b0: + %b0:i0:i32* = getelementptr %l0:struct Foo* offset 0:i64 + %b0:i1:i32 = load @nonce:i32* + %b0:i2:unit = store %b0:i1:i32 %b0:i0:i32* + %b0:i3:struct Foo = load %l0:struct Foo* + ret %b0:i3:struct Foo +} + +fun i32 @main () { +init: + bid: b0 + allocations: + %l0:struct Foo:t0 + +block b0: + %b0:i0:struct Foo = call @f:[ret:struct Foo params:()]*() + %b0:i1:unit = store %b0:i0:struct Foo %l0:struct Foo* + %b0:i2:i32* = getelementptr %l0:struct Foo* offset 0:i64 + %b0:i3:i32 = load %b0:i2:i32* + ret %b0:i3:i32 +} diff --git a/tests/test_examples.rs b/tests/test_examples.rs index a0e399a..b4b39e5 100644 --- a/tests/test_examples.rs +++ b/tests/test_examples.rs @@ -46,7 +46,7 @@ fn test_opt_between_dirs>(from: &Path, to: &Pat } } -const IRGEN_SMALL_TEST_IGNORE_LIST: [&str; 11] = [ +const IRGEN_SMALL_TEST_IGNORE_LIST: [&str; 12] = [ "examples/c/array.c", "examples/c/array2.c", "examples/c/array3.c", @@ -57,6 +57,7 @@ const IRGEN_SMALL_TEST_IGNORE_LIST: [&str; 11] = [ "examples/c/struct.c", "examples/c/struct2.c", "examples/c/struct3.c", + "examples/c/struct4.c", "examples/c/temp2.c", ]; @@ -68,7 +69,7 @@ const ASMGEN_TEST_DIR_LIST: [&str; 5] = [ "examples/ir4", ]; -const ASMGEN_SMALL_TEST_IGNORE_LIST: [&str; 11] = [ +const ASMGEN_SMALL_TEST_IGNORE_LIST: [&str; 12] = [ "array.ir", "array2.ir", "array3.ir", @@ -79,6 +80,7 @@ const ASMGEN_SMALL_TEST_IGNORE_LIST: [&str; 11] = [ "struct.ir", "struct2.ir", "struct3.ir", + "struct4.ir", "temp2.ir", ];