summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.c-torture/execute/stdarg-1.c
blob: 0ff9759e959cc17b6af158d4f830f1376e975e6f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdarg.h>

extern void abort (void);

int foo_arg, bar_arg;
long x;
double d;
va_list gap;
va_list *pap;

void
foo (int v, va_list ap)
{
  switch (v)
    {
    case 5: foo_arg = va_arg (ap, int); break;
    default: abort ();
    }
}

void
bar (int v)
{
  if (v == 0x4006)
    {
      if (va_arg (gap, double) != 17.0
	  || va_arg (gap, long) != 129L)
	abort ();
    }
  else if (v == 0x4008)
    {
      if (va_arg (*pap, long long) != 14LL
	  || va_arg (*pap, long double) != 131.0L
	  || va_arg (*pap, int) != 17)
	abort ();
    }
  bar_arg = v;
}

void
f0 (int i, ...)
{
}

void
f1 (int i, ...)
{
  va_list ap;
  va_start (ap, i);
  va_end (ap);
}

void
f2 (int i, ...)
{
  va_list ap;
  va_start (ap, i);
  bar (d);
  x = va_arg (ap, long);
  bar (x);
  va_end (ap);
}

void
f3 (int i, ...)
{
  va_list ap;
  va_start (ap, i);
  d = va_arg (ap, double);
  va_end (ap);
}

void
f4 (int i, ...)
{
  va_list ap;
  va_start (ap, i);
  x = va_arg (ap, double);
  foo (i, ap);
  va_end (ap);
}

void
f5 (int i, ...)
{
  va_list ap;
  va_start (ap, i);
  va_copy (gap, ap);
  bar (i);
  va_end (ap);
  va_end (gap);
}

void
f6 (int i, ...)
{
  va_list ap;
  va_start (ap, i);
  bar (d);
  va_arg (ap, long);
  va_arg (ap, long);
  x = va_arg (ap, long);
  bar (x);
  va_end (ap);
}

void
f7 (int i, ...)
{
  va_list ap;
  va_start (ap, i);
  pap = &ap;
  bar (i);
  va_end (ap);
}

void
f8 (int i, ...)
{
  va_list ap;
  va_start (ap, i);
  pap = &ap;
  bar (i);
  d = va_arg (ap, double);
  va_end (ap);
}

int
main (void)
{
  f0 (1);
  f1 (2);
  d = 31.0;
  f2 (3, 28L);
  if (bar_arg != 28 || x != 28)
    abort ();
  f3 (4, 131.0);
  if (d != 131.0)
    abort ();
  f4 (5, 16.0, 128);
  if (x != 16 || foo_arg != 128)
    abort ();
  f5 (0x4006, 17.0, 129L);
  if (bar_arg != 0x4006)
    abort ();
  f6 (7, 12L, 14L, -31L);
  if (bar_arg != -31)
    abort ();
  f7 (0x4008, 14LL, 131.0L, 17, 26.0);
  if (bar_arg != 0x4008)
    abort ();
  f8 (0x4008, 14LL, 131.0L, 17, 27.0);
  if (bar_arg != 0x4008 || d != 27.0)
    abort ();
  return 0;
}