From 98f9bb384af1beb62eb62a353f0585281bee8c26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Gr=C3=A4nitz?= Date: Tue, 28 May 2024 13:18:02 +0200 Subject: [clang-repl] Check host JIT support in all tests that create an Interpreter (#84758) --- clang/unittests/Interpreter/InterpreterTest.cpp | 88 ++++++++++++++++--------- 1 file changed, 57 insertions(+), 31 deletions(-) (limited to 'clang/unittests/Interpreter/InterpreterTest.cpp') diff --git a/clang/unittests/Interpreter/InterpreterTest.cpp b/clang/unittests/Interpreter/InterpreterTest.cpp index 69bc2da..86eeb4b 100644 --- a/clang/unittests/Interpreter/InterpreterTest.cpp +++ b/clang/unittests/Interpreter/InterpreterTest.cpp @@ -54,11 +54,30 @@ createInterpreter(const Args &ExtraArgs = {}, return cantFail(clang::Interpreter::create(std::move(CI))); } +static bool HostSupportsJit() { + auto J = llvm::orc::LLJITBuilder().create(); + if (J) + return true; + LLVMConsumeError(llvm::wrap(J.takeError())); + return false; +} + +struct LLVMInitRAII { + LLVMInitRAII() { + llvm::InitializeNativeTarget(); + llvm::InitializeNativeTargetAsmPrinter(); + } + ~LLVMInitRAII() { llvm::llvm_shutdown(); } +} LLVMInit; + static size_t DeclsSize(TranslationUnitDecl *PTUDecl) { return std::distance(PTUDecl->decls().begin(), PTUDecl->decls().end()); } TEST(InterpreterTest, Sanity) { + if (!HostSupportsJit()) + GTEST_SKIP(); + std::unique_ptr Interp = createInterpreter(); using PTU = PartialTranslationUnit; @@ -74,7 +93,14 @@ static std::string DeclToString(Decl *D) { return llvm::cast(D)->getQualifiedNameAsString(); } +#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC +TEST(InterpreterTest, DISABLED_IncrementalInputTopLevelDecls) { +#else TEST(InterpreterTest, IncrementalInputTopLevelDecls) { +#endif + if (!HostSupportsJit()) + GTEST_SKIP(); + std::unique_ptr Interp = createInterpreter(); auto R1 = Interp->Parse("int var1 = 42; int f() { return var1; }"); // gtest doesn't expand into explicit bool conversions. @@ -91,7 +117,14 @@ TEST(InterpreterTest, IncrementalInputTopLevelDecls) { EXPECT_EQ("var2", DeclToString(*R2DeclRange.begin())); } +#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC +TEST(InterpreterTest, DISABLED_Errors) { +#else TEST(InterpreterTest, Errors) { +#endif + if (!HostSupportsJit()) + GTEST_SKIP(); + Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"}; // Create the diagnostic engine with unowned consumer. @@ -114,7 +147,14 @@ TEST(InterpreterTest, Errors) { // Here we test whether the user can mix declarations and statements. The // interpreter should be smart enough to recognize the declarations from the // statements and wrap the latter into a declaration, producing valid code. +#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC +TEST(InterpreterTest, DISABLED_DeclsAndStatements) { +#else TEST(InterpreterTest, DeclsAndStatements) { +#endif + if (!HostSupportsJit()) + GTEST_SKIP(); + Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"}; // Create the diagnostic engine with unowned consumer. @@ -136,7 +176,14 @@ TEST(InterpreterTest, DeclsAndStatements) { EXPECT_TRUE(!!R2); } +#ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC +TEST(InterpreterTest, DISABLED_UndoCommand) { +#else TEST(InterpreterTest, UndoCommand) { +#endif + if (!HostSupportsJit()) + GTEST_SKIP(); + Args ExtraArgs = {"-Xclang", "-diagnostic-log-file", "-Xclang", "-"}; // Create the diagnostic engine with unowned consumer. @@ -190,27 +237,13 @@ static std::string MangleName(NamedDecl *ND) { return RawStr.str(); } -static bool HostSupportsJit() { - auto J = llvm::orc::LLJITBuilder().create(); - if (J) - return true; - LLVMConsumeError(llvm::wrap(J.takeError())); - return false; -} - -struct LLVMInitRAII { - LLVMInitRAII() { - llvm::InitializeNativeTarget(); - llvm::InitializeNativeTargetAsmPrinter(); - } - ~LLVMInitRAII() { llvm::llvm_shutdown(); } -} LLVMInit; - #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC -TEST(IncrementalProcessing, DISABLED_FindMangledNameSymbol) { +TEST(InterpreterTest, DISABLED_FindMangledNameSymbol) { #else -TEST(IncrementalProcessing, FindMangledNameSymbol) { +TEST(InterpreterTest, FindMangledNameSymbol) { #endif + if (!HostSupportsJit()) + GTEST_SKIP(); std::unique_ptr Interp = createInterpreter(); @@ -218,11 +251,6 @@ TEST(IncrementalProcessing, FindMangledNameSymbol) { EXPECT_EQ(1U, DeclsSize(PTU.TUPart)); auto R1DeclRange = PTU.TUPart->decls(); - // We cannot execute on the platform. - if (!HostSupportsJit()) { - return; - } - NamedDecl *FD = cast(*R1DeclRange.begin()); // Lower the PTU if (llvm::Error Err = Interp->Execute(PTU)) { @@ -271,10 +299,13 @@ static NamedDecl *LookupSingleName(Interpreter &Interp, const char *Name) { } #ifdef CLANG_INTERPRETER_NO_SUPPORT_EXEC -TEST(IncrementalProcessing, DISABLED_InstantiateTemplate) { +TEST(InterpreterTest, DISABLED_InstantiateTemplate) { #else -TEST(IncrementalProcessing, InstantiateTemplate) { +TEST(InterpreterTest, InstantiateTemplate) { #endif + if (!HostSupportsJit()) + GTEST_SKIP(); + // FIXME: We cannot yet handle delayed template parsing. If we run with // -fdelayed-template-parsing we try adding the newly created decl to the // active PTU which causes an assert. @@ -291,11 +322,6 @@ TEST(IncrementalProcessing, InstantiateTemplate) { auto PTUDeclRange = PTU.TUPart->decls(); EXPECT_EQ(1, std::distance(PTUDeclRange.begin(), PTUDeclRange.end())); - // We cannot execute on the platform. - if (!HostSupportsJit()) { - return; - } - // Lower the PTU if (llvm::Error Err = Interp->Execute(PTU)) { // We cannot execute on the platform. @@ -325,7 +351,7 @@ TEST(InterpreterTest, Value) { #endif // We cannot execute on the platform. if (!HostSupportsJit()) - return; + GTEST_SKIP(); std::unique_ptr Interp = createInterpreter(); -- cgit v1.1