| 1 | extern void __VERIFIER_error() __attribute__ ((__noreturn__));
|
|---|
| 2 |
|
|---|
| 3 | #include <stdlib.h>
|
|---|
| 4 |
|
|---|
| 5 | extern void *malloc(__SIZE_TYPE__);
|
|---|
| 6 | extern void *memset(void *, int, __SIZE_TYPE__);
|
|---|
| 7 | typedef struct
|
|---|
| 8 | {
|
|---|
| 9 | short a;
|
|---|
| 10 | unsigned short b;
|
|---|
| 11 | unsigned short c;
|
|---|
| 12 | unsigned long long Count;
|
|---|
| 13 | long long Count2;
|
|---|
| 14 | } __attribute__((packed)) Struct1;
|
|---|
| 15 |
|
|---|
| 16 | typedef struct
|
|---|
| 17 | {
|
|---|
| 18 | short a;
|
|---|
| 19 | unsigned short b;
|
|---|
| 20 | unsigned short c;
|
|---|
| 21 | unsigned long long d;
|
|---|
| 22 | long long e;
|
|---|
| 23 | long long f;
|
|---|
| 24 | } __attribute__((packed)) Struct2;
|
|---|
| 25 |
|
|---|
| 26 | typedef union
|
|---|
| 27 | {
|
|---|
| 28 | Struct1 a;
|
|---|
| 29 | Struct2 b;
|
|---|
| 30 | } Union;
|
|---|
| 31 |
|
|---|
| 32 | typedef struct
|
|---|
| 33 | {
|
|---|
| 34 | int Count;
|
|---|
| 35 | Union List[1];
|
|---|
| 36 | } __attribute__((packed)) Struct3;
|
|---|
| 37 |
|
|---|
| 38 | unsigned long long Sum (Struct3 *instrs) __attribute__((noinline));
|
|---|
| 39 | unsigned long long Sum (Struct3 *instrs)
|
|---|
| 40 | {
|
|---|
| 41 | unsigned long long count = 0;
|
|---|
| 42 | int i;
|
|---|
| 43 |
|
|---|
| 44 | for (i = 0; i < instrs->Count; i++) {
|
|---|
| 45 | count += instrs->List[i].a.Count;
|
|---|
| 46 | }
|
|---|
| 47 | return count;
|
|---|
| 48 | }
|
|---|
| 49 | long long Sum2 (Struct3 *instrs) __attribute__((noinline));
|
|---|
| 50 | long long Sum2 (Struct3 *instrs)
|
|---|
| 51 | {
|
|---|
| 52 | long long count = 0;
|
|---|
| 53 | int i;
|
|---|
| 54 |
|
|---|
| 55 | for (i = 0; i < instrs->Count; i++) {
|
|---|
| 56 | count += instrs->List[i].a.Count2;
|
|---|
| 57 | }
|
|---|
| 58 | return count;
|
|---|
| 59 | }
|
|---|
| 60 | static void dummy_abort(void)
|
|---|
| 61 | {
|
|---|
| 62 | }
|
|---|
| 63 | int main() {
|
|---|
| 64 | Struct3 *p = malloc (sizeof (int) + 3 * sizeof(Union));
|
|---|
| 65 | memset(p, 0, sizeof(int) + 3*sizeof(Union));
|
|---|
| 66 | p->Count = 3;
|
|---|
| 67 | p->List[0].a.Count = 555;
|
|---|
| 68 | p->List[1].a.Count = 999;
|
|---|
| 69 | p->List[2].a.Count = 0x101010101ULL;
|
|---|
| 70 | p->List[0].a.Count2 = 555;
|
|---|
| 71 | p->List[1].a.Count2 = 999;
|
|---|
| 72 | p->List[2].a.Count2 = 0x101010101LL;
|
|---|
| 73 | if (Sum(p) != 555 + 999 + 0x101010101ULL)
|
|---|
| 74 | dummy_abort();
|
|---|
| 75 | if (Sum2(p) != 555 + 999 + 0x101010101LL)
|
|---|
| 76 | dummy_abort();
|
|---|
| 77 | p = NULL;
|
|---|
| 78 | return 0;
|
|---|
| 79 | }
|
|---|