@@ -54,11 +54,30 @@ createInterpreter(const Args &ExtraArgs = {},
5454 return cantFail (clang::Interpreter::create (std::move (CI)));
5555}
5656
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+
5773static size_t DeclsSize (TranslationUnitDecl *PTUDecl) {
5874 return std::distance (PTUDecl->decls ().begin (), PTUDecl->decls ().end ());
5975}
6076
6177TEST (InterpreterTest, Sanity) {
78+ if (!HostSupportsJit ())
79+ GTEST_SKIP ();
80+
6281 std::unique_ptr<Interpreter> Interp = createInterpreter ();
6382
6483 using PTU = PartialTranslationUnit;
@@ -74,7 +93,14 @@ static std::string DeclToString(Decl *D) {
7493 return llvm::cast<NamedDecl>(D)->getQualifiedNameAsString ();
7594}
7695
96+ #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
97+ TEST (InterpreterTest, DISABLED_IncrementalInputTopLevelDecls) {
98+ #else
7799TEST (InterpreterTest, IncrementalInputTopLevelDecls) {
100+ #endif
101+ if (!HostSupportsJit ())
102+ GTEST_SKIP ();
103+
78104 std::unique_ptr<Interpreter> Interp = createInterpreter ();
79105 auto R1 = Interp->Parse (" int var1 = 42; int f() { return var1; }" );
80106 // gtest doesn't expand into explicit bool conversions.
@@ -91,7 +117,14 @@ TEST(InterpreterTest, IncrementalInputTopLevelDecls) {
91117 EXPECT_EQ (" var2" , DeclToString (*R2DeclRange.begin ()));
92118}
93119
120+ #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
121+ TEST (InterpreterTest, DISABLED_Errors) {
122+ #else
94123TEST (InterpreterTest, Errors) {
124+ #endif
125+ if (!HostSupportsJit ())
126+ GTEST_SKIP ();
127+
95128 Args ExtraArgs = {" -Xclang" , " -diagnostic-log-file" , " -Xclang" , " -" };
96129
97130 // Create the diagnostic engine with unowned consumer.
@@ -114,7 +147,14 @@ TEST(InterpreterTest, Errors) {
114147// Here we test whether the user can mix declarations and statements. The
115148// interpreter should be smart enough to recognize the declarations from the
116149// 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
117153TEST (InterpreterTest, DeclsAndStatements) {
154+ #endif
155+ if (!HostSupportsJit ())
156+ GTEST_SKIP ();
157+
118158 Args ExtraArgs = {" -Xclang" , " -diagnostic-log-file" , " -Xclang" , " -" };
119159
120160 // Create the diagnostic engine with unowned consumer.
@@ -136,7 +176,14 @@ TEST(InterpreterTest, DeclsAndStatements) {
136176 EXPECT_TRUE (!!R2);
137177}
138178
179+ #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
180+ TEST (InterpreterTest, DISABLED_UndoCommand) {
181+ #else
139182TEST (InterpreterTest, UndoCommand) {
183+ #endif
184+ if (!HostSupportsJit ())
185+ GTEST_SKIP ();
186+
140187 Args ExtraArgs = {" -Xclang" , " -diagnostic-log-file" , " -Xclang" , " -" };
141188
142189 // Create the diagnostic engine with unowned consumer.
@@ -190,39 +237,20 @@ static std::string MangleName(NamedDecl *ND) {
190237 return RawStr.str ();
191238}
192239
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-
209240#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
210- TEST (IncrementalProcessing , DISABLED_FindMangledNameSymbol) {
241+ TEST (InterpreterTest , DISABLED_FindMangledNameSymbol) {
211242#else
212- TEST (IncrementalProcessing , FindMangledNameSymbol) {
243+ TEST (InterpreterTest , FindMangledNameSymbol) {
213244#endif
245+ if (!HostSupportsJit ())
246+ GTEST_SKIP ();
214247
215248 std::unique_ptr<Interpreter> Interp = createInterpreter ();
216249
217250 auto &PTU (cantFail (Interp->Parse (" int f(const char*) {return 0;}" )));
218251 EXPECT_EQ (1U , DeclsSize (PTU.TUPart ));
219252 auto R1DeclRange = PTU.TUPart ->decls ();
220253
221- // We cannot execute on the platform.
222- if (!HostSupportsJit ()) {
223- return ;
224- }
225-
226254 NamedDecl *FD = cast<FunctionDecl>(*R1DeclRange.begin ());
227255 // Lower the PTU
228256 if (llvm::Error Err = Interp->Execute (PTU)) {
@@ -271,10 +299,13 @@ static NamedDecl *LookupSingleName(Interpreter &Interp, const char *Name) {
271299}
272300
273301#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC
274- TEST (IncrementalProcessing , DISABLED_InstantiateTemplate) {
302+ TEST (InterpreterTest , DISABLED_InstantiateTemplate) {
275303#else
276- TEST (IncrementalProcessing , InstantiateTemplate) {
304+ TEST (InterpreterTest , InstantiateTemplate) {
277305#endif
306+ if (!HostSupportsJit ())
307+ GTEST_SKIP ();
308+
278309 // FIXME: We cannot yet handle delayed template parsing. If we run with
279310 // -fdelayed-template-parsing we try adding the newly created decl to the
280311 // active PTU which causes an assert.
@@ -291,11 +322,6 @@ TEST(IncrementalProcessing, InstantiateTemplate) {
291322 auto PTUDeclRange = PTU.TUPart ->decls ();
292323 EXPECT_EQ (1 , std::distance (PTUDeclRange.begin (), PTUDeclRange.end ()));
293324
294- // We cannot execute on the platform.
295- if (!HostSupportsJit ()) {
296- return ;
297- }
298-
299325 // Lower the PTU
300326 if (llvm::Error Err = Interp->Execute (PTU)) {
301327 // We cannot execute on the platform.
@@ -325,7 +351,7 @@ TEST(InterpreterTest, Value) {
325351#endif
326352 // We cannot execute on the platform.
327353 if (!HostSupportsJit ())
328- return ;
354+ GTEST_SKIP () ;
329355
330356 std::unique_ptr<Interpreter> Interp = createInterpreter ();
331357
0 commit comments