Skip to content

Commit c5f18f9

Browse files
weliveindetailvg0204
authored andcommitted
[clang-repl] Check host JIT support in all tests that create an Interpreter (llvm#84758)
1 parent 03c248b commit c5f18f9

File tree

3 files changed

+82
-31
lines changed

3 files changed

+82
-31
lines changed

clang/unittests/Interpreter/IncrementalProcessingTest.cpp

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
#include "clang/Lex/Preprocessor.h"
1717
#include "clang/Parse/Parser.h"
1818
#include "clang/Sema/Sema.h"
19+
20+
#include "llvm/ExecutionEngine/Orc/LLJIT.h"
1921
#include "llvm/IR/LLVMContext.h"
2022
#include "llvm/IR/Module.h"
2123
#include "llvm/Support/MemoryBuffer.h"
@@ -25,11 +27,23 @@
2527

2628
#include <memory>
2729

30+
#if defined(_AIX) || defined(__MVS__)
31+
#define CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT
32+
#endif
33+
2834
using namespace llvm;
2935
using namespace clang;
3036

3137
namespace {
3238

39+
static bool HostSupportsJit() {
40+
auto J = llvm::orc::LLJITBuilder().create();
41+
if (J)
42+
return true;
43+
LLVMConsumeError(llvm::wrap(J.takeError()));
44+
return false;
45+
}
46+
3347
// Incremental processing produces several modules, all using the same "main
3448
// file". Make sure CodeGen can cope with that, e.g. for static initializers.
3549
const char TestProgram1[] = "extern \"C\" int funcForProg1() { return 17; }\n"
@@ -50,7 +64,11 @@ const Function *getGlobalInit(llvm::Module *M) {
5064
return nullptr;
5165
}
5266

67+
#ifdef CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT
68+
TEST(IncrementalProcessing, DISABLED_EmitCXXGlobalInitFunc) {
69+
#else
5370
TEST(IncrementalProcessing, EmitCXXGlobalInitFunc) {
71+
#endif
5472
std::vector<const char *> ClangArgv = {"-Xclang", "-emit-llvm-only"};
5573
auto CB = clang::IncrementalCompilerBuilder();
5674
CB.SetCompilerArgs(ClangArgv);

clang/unittests/Interpreter/InterpreterExtensionsTest.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,14 @@ class RecordRuntimeIBMetrics : public Interpreter {
103103
NoopRuntimeInterfaceBuilder *RuntimeIBPtr = nullptr;
104104
};
105105

106+
#ifdef CLANG_INTERPRETER_PLATFORM_CANNOT_CREATE_LLJIT
107+
TEST(InterpreterExtensionsTest, DISABLED_FindRuntimeInterface) {
108+
#else
106109
TEST(InterpreterExtensionsTest, FindRuntimeInterface) {
110+
#endif
111+
if (!HostSupportsJit())
112+
GTEST_SKIP();
113+
107114
clang::IncrementalCompilerBuilder CB;
108115
llvm::Error ErrOut = llvm::Error::success();
109116
RecordRuntimeIBMetrics Interp(cantFail(CB.CreateCpp()), ErrOut);

clang/unittests/Interpreter/InterpreterTest.cpp

Lines changed: 57 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
5773
static size_t DeclsSize(TranslationUnitDecl *PTUDecl) {
5874
return std::distance(PTUDecl->decls().begin(), PTUDecl->decls().end());
5975
}
6076

6177
TEST(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
7799
TEST(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
94123
TEST(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
117153
TEST(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
139182
TEST(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

Comments
 (0)