summaryrefslogtreecommitdiff
path: root/support/regression/tests/bug-2776.c
blob: 0623e1a38b5101d437c2d4c3ce2d0c39b0cc0b09 (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
/*
   bug-2776.c. Originally a segfault on trying to pass an array element as variable argument struct parameter.
   Later a iCode generation issue for pdk that triggered an assertion in codegen (when trying
   to pass an array element of size 1 as a variable argument struct parameter).
 */

#include <testfwk.h>

#pragma disable_warning 283
#pragma disable_warning 278

#include <stdarg.h>

struct tiny
{
  char c;
};

void f (int n, ...);

void m ()
{
  struct tiny x[3];
  x[0].c = 10;
  x[1].c = 11;
  x[2].c = 12;

  f (3, x[0], x[1], x[2], (long) 123);
}

void f (int n, ...)
{
	ASSERT (n == 3);
	struct tiny x;
	
	va_list args;
	va_start(args, n);
	x = va_arg (args, struct tiny);
	ASSERT (x.c == 10);
	x = va_arg (args, struct tiny);
	ASSERT (x.c == 11);
	x = va_arg (args, struct tiny);
	ASSERT (x.c == 12);

	ASSERT (va_arg (args, long) == 123);

	va_end (args);
}

void
testBug (void)
{
#ifndef __OpenBSD__ // Known to fail on OpenBSD 7.3 powerpc64 (don't know for other OpenBSD versions or archs) reported to OpenBSD.
  m ();
#endif
}