OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [gnu-dev/] [or1k-gcc/] [gcc/] [testsuite/] [gcc.c-torture/] [execute/] [20051113-1.c] - Blame information for rev 801

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.