]> git.ipfire.org Git - thirdparty/gcc.git/blob - gcc/testsuite/c-c++-common/cilk-plus/AN/exec-once2.c
[Patch AArch64] Fixup floating point division with -march=armv8-a+nosimd
[thirdparty/gcc.git] / gcc / testsuite / c-c++-common / cilk-plus / AN / exec-once2.c
1 /* { dg-do run } */
2 /* { dg-options "-fcilkplus" } */
3
4 #ifdef HAVE_IO
5 #include <stdio.h>
6 #endif
7
8
9 int func1(int x)
10 {
11 /* If x == 2 then it should return 0. */
12 return (x - 2);
13 }
14
15 int func2(int x)
16 {
17 /* If x == 2 then it should return 1000. */
18 return (x * 500);
19 }
20
21 int func3 (int x)
22 {
23 /* If x == 2 then it should return 1. */
24 /* If x == 1 then it should return 0. */
25 return (x-1);
26 }
27
28 int func4(int x)
29 {
30 if (x > 0)
31 return x;
32 else
33 return x--;
34 }
35
36
37 /* This program makes an assumption that argc == 1. */
38 int main (void)
39 {
40 int argc = 1;
41 int array[2500];
42
43 /* This is done to make sure the compiler does not optimize out argc. */
44 __asm volatile ("" : "+r" (argc));
45 /* This should set array[0->999] to 5. */
46 array[argc-1:func2(++argc):1] = 5;
47 array[1000:500:1] = 10; /* set all variables in array[1000-->1499] to 10. */
48 array[1500:500:1] = 15; /* set all variables in array[1500-->1999] to 15. */
49 array[2000:500:1] = 20; /* set all variables in array[2000-->2499] to 20. */
50 array[2000:500:1] = 25; /* set all variables in array[2500-->2999] to 25. */
51 array[2000:500:1] = 30; /* set all variables in array[3000-->3499] to 30. */
52
53 argc = func3 (argc); /* This will set argc back to 1. */
54 #if HAVE_IO
55 printf("argc = %d\n", argc);
56 #endif
57 /* If the parameters inside the function get evaluated only once, then this
58 if statement must work fine, i.e. the triplet values will be 0, 1000, 1.
59
60 Otherwise, the program should crash or give some uneasy value. */
61
62 /* If done correctly, it should boil down to: array[0:1000:1]. */
63 if (array[func3(argc):func2(++argc)] != 5) {
64 #ifdef HAVE_IO
65 printf ("Should not be there(1).\n");
66 #endif
67 return 1;
68 }
69
70 /* If done correctly, it should boil down to: array[999:500:-1]. */
71 if (func4(array[func2(argc)-1:func2(argc--):func1(argc)]) != 5) {
72 #ifdef HAVE_IO
73 printf ("Should not be there(2).\n");
74 #endif
75 return 2;
76 }
77
78 /* If done correctly, it should boil down to: array[1000:500:1]. */
79 if (func4 (func4(array[func2(argc++):500: func1(argc--)])) != 5) {
80 #ifdef HAVE_IO
81 printf ("Should not be there(3).\n");
82 #endif
83 return 3;
84 }
85
86 return 0;
87 }