@@ -54,11 +54,30 @@ createInterpreter(const Args &ExtraArgs = {},
54
54
return cantFail (clang::Interpreter::create (std::move (CI)));
55
55
}
56
56
57
+ static bool HostSupportsJit () {
58
+ auto J = llvm::orc::LLJITBuilder ().create ();
59
+ if (J)
60
+ return true ;
61
+ LLVMConsumeError (llvm::wrap (J.takeError ()));
62
+ return false ;
63
+ }
64
+
65
+ struct LLVMInitRAII {
66
+ LLVMInitRAII () {
67
+ llvm::InitializeNativeTarget ();
68
+ llvm::InitializeNativeTargetAsmPrinter ();
69
+ }
70
+ ~LLVMInitRAII () { llvm::llvm_shutdown (); }
71
+ } LLVMInit;
72
+
57
73
static size_t DeclsSize (TranslationUnitDecl *PTUDecl) {
58
74
return std::distance (PTUDecl->decls ().begin (), PTUDecl->decls ().end ());
59
75
}
60
76
61
77
TEST (InterpreterTest, Sanity) {
78
+ if (!HostSupportsJit ())
79
+ GTEST_SKIP ();
80
+
62
81
std::unique_ptr<Interpreter> Interp = createInterpreter ();
63
82
64
83
using PTU = PartialTranslationUnit;
@@ -74,7 +93,14 @@ static std::string DeclToString(Decl *D) {
74
93
return llvm::cast<NamedDecl>(D)->getQualifiedNameAsString ();
75
94
}
76
95
96
+ #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
97
+ TEST (InterpreterTest, DISABLED_IncrementalInputTopLevelDecls) {
98
+ #else
77
99
TEST (InterpreterTest, IncrementalInputTopLevelDecls) {
100
+ #endif
101
+ if (!HostSupportsJit ())
102
+ GTEST_SKIP ();
103
+
78
104
std::unique_ptr<Interpreter> Interp = createInterpreter ();
79
105
auto R1 = Interp->Parse (" int var1 = 42; int f() { return var1; }" );
80
106
// gtest doesn't expand into explicit bool conversions.
@@ -91,7 +117,14 @@ TEST(InterpreterTest, IncrementalInputTopLevelDecls) {
91
117
EXPECT_EQ (" var2" , DeclToString (*R2DeclRange.begin ()));
92
118
}
93
119
120
+ #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
121
+ TEST (InterpreterTest, DISABLED_Errors) {
122
+ #else
94
123
TEST (InterpreterTest, Errors) {
124
+ #endif
125
+ if (!HostSupportsJit ())
126
+ GTEST_SKIP ();
127
+
95
128
Args ExtraArgs = {" -Xclang" , " -diagnostic-log-file" , " -Xclang" , " -" };
96
129
97
130
// Create the diagnostic engine with unowned consumer.
@@ -114,7 +147,14 @@ TEST(InterpreterTest, Errors) {
114
147
// Here we test whether the user can mix declarations and statements. The
115
148
// interpreter should be smart enough to recognize the declarations from the
116
149
// statements and wrap the latter into a declaration, producing valid code.
150
+ #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
151
+ TEST (InterpreterTest, DISABLED_DeclsAndStatements) {
152
+ #else
117
153
TEST (InterpreterTest, DeclsAndStatements) {
154
+ #endif
155
+ if (!HostSupportsJit ())
156
+ GTEST_SKIP ();
157
+
118
158
Args ExtraArgs = {" -Xclang" , " -diagnostic-log-file" , " -Xclang" , " -" };
119
159
120
160
// Create the diagnostic engine with unowned consumer.
@@ -136,7 +176,14 @@ TEST(InterpreterTest, DeclsAndStatements) {
136
176
EXPECT_TRUE (!!R2);
137
177
}
138
178
179
+ #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
180
+ TEST (InterpreterTest, DISABLED_UndoCommand) {
181
+ #else
139
182
TEST (InterpreterTest, UndoCommand) {
183
+ #endif
184
+ if (!HostSupportsJit ())
185
+ GTEST_SKIP ();
186
+
140
187
Args ExtraArgs = {" -Xclang" , " -diagnostic-log-file" , " -Xclang" , " -" };
141
188
142
189
// Create the diagnostic engine with unowned consumer.
@@ -190,39 +237,20 @@ static std::string MangleName(NamedDecl *ND) {
190
237
return RawStr.str ();
191
238
}
192
239
193
- static bool HostSupportsJit () {
194
- auto J = llvm::orc::LLJITBuilder ().create ();
195
- if (J)
196
- return true ;
197
- LLVMConsumeError (llvm::wrap (J.takeError ()));
198
- return false ;
199
- }
200
-
201
- struct LLVMInitRAII {
202
- LLVMInitRAII () {
203
- llvm::InitializeNativeTarget ();
204
- llvm::InitializeNativeTargetAsmPrinter ();
205
- }
206
- ~LLVMInitRAII () { llvm::llvm_shutdown (); }
207
- } LLVMInit;
208
-
209
240
#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
210
- TEST (IncrementalProcessing , DISABLED_FindMangledNameSymbol) {
241
+ TEST (InterpreterTest , DISABLED_FindMangledNameSymbol) {
211
242
#else
212
- TEST (IncrementalProcessing , FindMangledNameSymbol) {
243
+ TEST (InterpreterTest , FindMangledNameSymbol) {
213
244
#endif
245
+ if (!HostSupportsJit ())
246
+ GTEST_SKIP ();
214
247
215
248
std::unique_ptr<Interpreter> Interp = createInterpreter ();
216
249
217
250
auto &PTU (cantFail (Interp->Parse (" int f(const char*) {return 0;}" )));
218
251
EXPECT_EQ (1U , DeclsSize (PTU.TUPart ));
219
252
auto R1DeclRange = PTU.TUPart ->decls ();
220
253
221
- // We cannot execute on the platform.
222
- if (!HostSupportsJit ()) {
223
- return ;
224
- }
225
-
226
254
NamedDecl *FD = cast<FunctionDecl>(*R1DeclRange.begin ());
227
255
// Lower the PTU
228
256
if (llvm::Error Err = Interp->Execute (PTU)) {
@@ -271,10 +299,13 @@ static NamedDecl *LookupSingleName(Interpreter &Interp, const char *Name) {
271
299
}
272
300
273
301
#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
274
- TEST (IncrementalProcessing , DISABLED_InstantiateTemplate) {
302
+ TEST (InterpreterTest , DISABLED_InstantiateTemplate) {
275
303
#else
276
- TEST (IncrementalProcessing , InstantiateTemplate) {
304
+ TEST (InterpreterTest , InstantiateTemplate) {
277
305
#endif
306
+ if (!HostSupportsJit ())
307
+ GTEST_SKIP ();
308
+
278
309
// FIXME: We cannot yet handle delayed template parsing. If we run with
279
310
// -fdelayed-template-parsing we try adding the newly created decl to the
280
311
// active PTU which causes an assert.
@@ -291,11 +322,6 @@ TEST(IncrementalProcessing, InstantiateTemplate) {
291
322
auto PTUDeclRange = PTU.TUPart ->decls ();
292
323
EXPECT_EQ (1 , std::distance (PTUDeclRange.begin (), PTUDeclRange.end ()));
293
324
294
- // We cannot execute on the platform.
295
- if (!HostSupportsJit ()) {
296
- return ;
297
- }
298
-
299
325
// Lower the PTU
300
326
if (llvm::Error Err = Interp->Execute (PTU)) {
301
327
// We cannot execute on the platform.
@@ -325,7 +351,7 @@ TEST(InterpreterTest, Value) {
325
351
#endif
326
352
// We cannot execute on the platform.
327
353
if (!HostSupportsJit ())
328
- return ;
354
+ GTEST_SKIP () ;
329
355
330
356
std::unique_ptr<Interpreter> Interp = createInterpreter ();
331
357
0 commit comments