summaryrefslogtreecommitdiff
path: root/gcc/testsuite/gcc.dg/vla-stexp-4.c
blob: 929768cd802734dcf0417c8368507103fe950395 (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
/* PR29970, PR91038 */
/* { dg-do run } */
/* { dg-options "-O0 -Wunused-variable" } */
/* { dg-require-effective-target alloca } */

int foo3b(void)   // should not return 0
{
        int n = 0;
        return sizeof *({ n = 10; int x[n]; &x; });
}

int foo4(void)   // should not ICE
{
        return (*({
                        int n = 20;
                        char (*x)[n][n] = __builtin_malloc(n * n);
                        (*x)[12][1] = 1;
                        x;
                }))[12][1];
}

int foo5(void)   // should return 1, returns 0
{
        int n = 0;
        return (*({
                        n = 20;
                        char (*x)[n][n] = __builtin_malloc(n * n);
                        (*x)[12][1] = 1;
                        (*x)[0][1] = 0;
                        x;
                }))[12][1];
}

int foo5c(void)   // should return 400 
{
        int n = 0;
        return sizeof(*({
                        n = 20;
                        char (*x)[n][n] = __builtin_malloc(n * n);
                        (*x)[12][1] = 1;
                        (*x)[0][1] = 0;
                        x;
                }));
}

int foo5b(void)   // should return 1, returns 0
{
	int n = 0;			/* { dg-warning "unused variable" } */
        return (*({
                        int n = 20;
                        char (*x)[n][n] = __builtin_malloc(n * n);
                        (*x)[12][1] = 1;
                        (*x)[0][1] = 0;
                        x;
                }))[12][1];
}

int foo5a(void)   // should return 1, returns 0
{
        return (*({
                        int n = 20;
                        char (*x)[n][n] = __builtin_malloc(n * n);
                        (*x)[12][1] = 1;
                        (*x)[0][1] = 0;
                        x;
                }))[12][1];
}




int main()
{
	if (sizeof(int[10]) != foo3b())
		__builtin_abort();

	if (1 != foo4())
		__builtin_abort();

	if (400 != foo5c())
		__builtin_abort();

	if (1 != foo5a())
		__builtin_abort();

	if (1 != foo5b()) // -O0
		__builtin_abort();

	if (1 != foo5())
		__builtin_abort();

	return 0;
}