-
Notifications
You must be signed in to change notification settings - Fork 103
/
Copy pathgcc_bugs.cpp
130 lines (108 loc) · 2.72 KB
/
gcc_bugs.cpp
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
/*
g++ --version:
g++ (Ubuntu 10 - 20200416 - 0ubuntu1~18.04) 10.0.1 20200416 (experimental)[master revision 3c3f12e2a76:dcee354ce56:44b326839d864fc10c459916abcc97f35a9ac3de]
Copyright(C) 2020 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
*/
#include <iostream>
#include "librf.h"
using namespace librf;
#define GCC_FIX_BUGS 1
static future_t<> gcc_bugs_if_await(event_t e)
{
#if GCC_FIX_BUGS
auto result = co_await e.wait();
if (result == false)
#else
if (co_await e.wait() == false) //internal compiler error: in fold_convert_loc, at fold-const.c:2435
#endif
std::cout << "time out!" << std::endl;
else
std::cout << "event signal!" << std::endl;
}
static future_t<> gcc_bugs_while_await(mutex_t lock)
{
#if GCC_FIX_BUGS
for (;;)
{
auto result = co_await lock.try_lock();
if (result) break;
}
#else
while (!co_await lock.try_lock()); //internal compiler error: in fold_convert_loc, at fold-const.c:2435
#endif
std::cout << "OK." << std::endl;
}
#if GCC_FIX_BUGS
static future_t<> gcc_bugs_lambda_coroutines_fixed(std::thread& other, channel_t<bool> c_done)
{
co_await c_done;
std::cout << "other thread = " << other.get_id();
co_await c_done;
}
#endif
static void gcc_bugs_lambda_coroutines()
{
channel_t<bool> c_done{ 1 };
std::thread other;
#if GCC_FIX_BUGS
go gcc_bugs_lambda_coroutines_fixed(other, c_done);
#else
go[&other, c_done]()->future_t<>
{
co_await c_done;
std::cout << "other thread = " << other.get_id();
co_await c_done;
}; //internal compiler error: in captures_temporary, at cp/coroutines.cc:2716
#endif
}
#if GCC_FIX_BUGS
static future_t<> gcc_bugs_lambda_coroutines2_fixed(channel_t<intptr_t> head, channel_t<intptr_t> tail)
{
for (int i = 0; i < 100; ++i)
{
co_await(head << 0);
co_await tail;
}
}
#endif
static void gcc_bugs_lambda_coroutines2()
{
channel_t<intptr_t> head{ 1 };
channel_t<intptr_t> tail{ 0 };
#if GCC_FIX_BUGS
go gcc_bugs_lambda_coroutines2_fixed(head, tail);
#else
GO
{
for (int i = 0; i < 100; ++i)
{
co_await(head << 0);
intptr_t value = co_await tail;
(void)value;
}
}; //internal compiler error: in captures_temporary, at cp/coroutines.cc:2716
#endif
}
template<class... _Mtxs>
static future_t<> gcc_bugs_nameless_args(adopt_manual_unlock_t
#if GCC_FIX_BUGS
nameless
#endif
, _Mtxs&... mtxs)
{
#if GCC_FIX_BUGS
(void)nameless;
#endif
co_await mutex_t::lock(adopt_manual_unlock, mtxs...);
} //internal compiler error: Segmentation fault
void gcc_bugs()
{
event_t e;
go gcc_bugs_if_await(e);
mutex_t mtx;
go gcc_bugs_while_await(mtx);
mutex_t a, b, c;
go gcc_bugs_nameless_args(adopt_manual_unlock, a, b, c);
}