summaryrefslogtreecommitdiff
path: root/gcc/testsuite/g++.dg/ipa/pr93223.C
blob: 87f98b5e244bf881713b3babf6fc5e82bbcc2a5b (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
/* { dg-do compile } */
/* { dg-options "-O3 -std=gnu++14" } */

template <typename Function>
bool run(const int item_count,
         Function && process_range,
         const int max_parallelism,
         int* progress = nullptr)
{
    if (max_parallelism <= 1)
    {
        if (progress == nullptr)
        {
            return process_range(0);
        }
        else
        {
            auto result = true;
            for (int i = 0; i != item_count && result; ++i)
            {
                (*progress)++;
                result = process_range(i);
            }
            return result;
        }
    }

    if (max_parallelism > 10)
    {
        if (progress == nullptr)
        {
            return process_range(0);
        }
        else
        {
            auto result = true;
            for (int i = 0; i != item_count && result; ++i)
            {
                (*progress)++;
                result = process_range(i);
            }
            return result;
        }
    }
    return false;
}

namespace
{
__attribute__((optimize(0))) bool worker_fun(const int)
{
    return true;
}
}

void demo(int n)
{
    for (int i = 0; i < n; ++i)
    {
        run(n, &worker_fun, n);
    }
}