1
1
#include " gtest/gtest.h"
2
2
3
3
#include " Plugins/LanguageRuntime/Swift/SwiftLanguageRuntime.h"
4
+ #include " llvm/ADT/Sequence.h"
4
5
5
6
using namespace lldb ;
6
7
using namespace lldb_private ;
7
8
using namespace llvm ;
8
9
static constexpr auto IsSwiftMangledName =
9
10
SwiftLanguageRuntime::IsSwiftMangledName;
11
+ static constexpr auto GetFuncletNumber = [](StringRef name) {
12
+ return SwiftLanguageRuntime::GetFuncletNumber (name);
13
+ };
10
14
static constexpr auto IsAnySwiftAsyncFunctionSymbol = [](StringRef name) {
11
15
return SwiftLanguageRuntime::IsAnySwiftAsyncFunctionSymbol (name);
12
16
};
@@ -47,6 +51,13 @@ CheckGroupOfFuncletsFromDifferentFunctions(ArrayRef<StringRef> funclets1,
47
51
}
48
52
}
49
53
54
+ // / Check that funclets contain a sequence of funclet names whose "async
55
+ // / numbers" go from 0 to size(funclets).
56
+ static void CheckFuncletNumbersAreARange (ArrayRef<StringRef> funclets) {
57
+ for (auto idx : llvm::seq<int >(0 , funclets.size ()))
58
+ EXPECT_EQ (idx, GetFuncletNumber (funclets[idx]));
59
+ }
60
+
50
61
TEST (TestSwiftDemangleAsyncNames, BasicAsync) {
51
62
// "sayBasic" == a basic async function
52
63
// "sayGeneric" == a generic async function
@@ -71,6 +82,8 @@ TEST(TestSwiftDemangleAsyncNames, BasicAsync) {
71
82
CheckGroupOfFuncletsFromSameFunction (basic_funclets);
72
83
CheckGroupOfFuncletsFromSameFunction (generic_funclets);
73
84
CheckGroupOfFuncletsFromDifferentFunctions (basic_funclets, generic_funclets);
85
+ CheckFuncletNumbersAreARange (basic_funclets);
86
+ CheckFuncletNumbersAreARange (generic_funclets);
74
87
}
75
88
76
89
TEST (TestSwiftDemangleAsyncNames, ClosureAsync) {
@@ -127,6 +140,10 @@ TEST(TestSwiftDemangleAsyncNames, ClosureAsync) {
127
140
nested2_funclets_top_not_async);
128
141
CheckGroupOfFuncletsFromDifferentFunctions (nested2_funclets2,
129
142
nested2_funclets_top_not_async);
143
+ CheckFuncletNumbersAreARange (nested1_funclets);
144
+ CheckFuncletNumbersAreARange (nested2_funclets1);
145
+ CheckFuncletNumbersAreARange (nested2_funclets2);
146
+ CheckFuncletNumbersAreARange (nested2_funclets_top_not_async);
130
147
}
131
148
132
149
TEST (TestSwiftDemangleAsyncNames, StaticAsync) {
@@ -153,4 +170,20 @@ TEST(TestSwiftDemangleAsyncNames, StaticAsync) {
153
170
" $s1a8sayBasicyySSYaF" , " $s1a8sayBasicyySSYaFTY0_" };
154
171
CheckGroupOfFuncletsFromDifferentFunctions (static_async_funclets,
155
172
other_funclets);
173
+ CheckFuncletNumbersAreARange (static_async_funclets);
174
+ }
175
+
176
+ TEST (TestSwiftDemangleAsyncNames, NonAsync) {
177
+ // func factorial(_ n:Int) -> Int {
178
+ {
179
+ StringRef func = " $s4test9factorialyS2iF" ;
180
+ EXPECT_EQ (GetFuncletNumber (func), std::nullopt);
181
+ }
182
+
183
+ // func factorial(_ n:Int) async -> Int {
184
+ // func inner_factorial(_ n:Int) -> Int {
185
+ {
186
+ StringRef func = " $s4test9factorialyS2iYaF06inner_B0L_yS2iF" ;
187
+ EXPECT_EQ (GetFuncletNumber (func), std::nullopt);
188
+ }
156
189
}
0 commit comments