NAME struct assignment into variable
PROG struct Foo { int m; } u:./testprogs/simple_struct:func { $s = *((struct Foo *)arg0); printf("Result: %d\n", $s.m); exit(); }
EXPECT Result: 2
TIMEOUT 4
AFTER ./testprogs/simple_struct

NAME struct assignment into map
PROG struct Foo { int m; int n; } u:./testprogs/simple_struct:func { @s = *((struct Foo *)arg0); exit(); }
EXPECT @s: { .m = 2, .n = 3 }
TIMEOUT 4
AFTER ./testprogs/simple_struct

NAME struct field order
PROG struct Foo { int n; int m; } u:./testprogs/simple_struct:func { @s = *((struct Foo *)arg0); exit(); }
EXPECT @s: { .n = 2, .m = 3 }
TIMEOUT 4
AFTER ./testprogs/simple_struct

NAME nested struct assignment into map
PROG struct Foo { struct { int m[1] } y; struct { int n } a; } u:./testprogs/simple_struct:func { @s = *((struct Foo *)arg0); exit(); }
EXPECT @s: { .y = { .m = [2] }, .a = { .n = 3 } }
TIMEOUT 4
AFTER ./testprogs/simple_struct

NAME struct as a map key
PROG struct Foo { int m; int n; } u:./testprogs/simple_struct:func { @s[*((struct Foo *)arg0)] = 0; exit(); }
EXPECT @s[{ .m = 2, .n = 3 }]: 0
TIMEOUT 4
AFTER ./testprogs/simple_struct

NAME struct as a part of multikey
PROG struct Foo { int m; int n; } u:./testprogs/simple_struct:func { @s[*((struct Foo *)arg0), 42] = 0; exit(); }
EXPECT @s[{ .m = 2, .n = 3 }, 42]: 0
TIMEOUT 4
AFTER ./testprogs/simple_struct

NAME struct as a map key assigned from another map
PROG struct Foo { int m; int n; } u:./testprogs/simple_struct:func { @x = *((struct Foo *)arg0); @s[@x] = 0; exit(); }
EXPECT @s[{ .m = 2, .n = 3 }]: 0
TIMEOUT 4
AFTER ./testprogs/simple_struct

NAME struct in a tuple
PROG struct Foo { int m; int n; } u:./testprogs/simple_struct:func { @s = (1, *((struct Foo *)arg0)); exit(); }
EXPECT @s: (1, { .m = 2, .n = 3 })
TIMEOUT 4
AFTER ./testprogs/simple_struct

NAME struct with bitfield
PROG struct foo { unsigned long long x_0:1; unsigned long long x_1:1; unsigned long long x_2:2; } begin { $val = (uint64)0x1e; $f = *(struct foo *)(&$val); print($f); }
EXPECT { .x_0 = 0, .x_1 = 1, .x_2 = 3 }

NAME struct with attribute
PROG struct foo { int x; char y; int z; } struct bar { int x; char y; int z; } __attribute__((packed)) struct bar2 { int x; char y; int z; } __attribute__((packed)) __attribute__((aligned(1))) begin { print(sizeof(struct foo)); print(sizeof(struct bar)); print(sizeof(struct bar2)); }
EXPECT 12
EXPECT 9
EXPECT 9

NAME struct with attribute and comment
PROG struct foo { int x; char y; int z; } /**/ __attribute__ /**/ ((packed)) /**/ begin { print(sizeof(struct foo)); }
EXPECT 9
