diff --git a/lib/Interpreter/CppInterOpInterpreter.h b/lib/Interpreter/CppInterOpInterpreter.h index cdac4f768..01b6d9795 100644 --- a/lib/Interpreter/CppInterOpInterpreter.h +++ b/lib/Interpreter/CppInterOpInterpreter.h @@ -148,8 +148,6 @@ class Interpreter { llvm::InitializeAllAsmPrinters(); std::vector vargs(argv + 1, argv + argc); - vargs.push_back("-include"); - vargs.push_back("new"); inner = compat::createClangInterpreter(vargs); } diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index 606c30cda..5153bf19c 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -637,7 +637,8 @@ TEST(FunctionReflectionTest, ExistsFunctionTemplate) { TEST(FunctionReflectionTest, InstantiateTemplateFunctionFromString) { if (llvm::sys::RunningOnValgrind()) GTEST_SKIP() << "XFAIL due to Valgrind report"; - Cpp::CreateInterpreter(); + std::vector interpreter_args = { "-include", "new" }; + Cpp::CreateInterpreter(interpreter_args); std::string code = R"(#include )"; Interp->process(code); const char* str = "std::make_unique"; @@ -1322,8 +1323,10 @@ TEST(FunctionReflectionTest, GetFunctionAddress) { #endif std::vector Decls, SubDecls; std::string code = "int f1(int i) { return i * i; }"; + std::vector interpreter_args = {"-include", "new"}; - GetAllTopLevelDecls(code, Decls); + GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false, + interpreter_args); testing::internal::CaptureStdout(); Interp->declare("#include "); @@ -1372,7 +1375,10 @@ TEST(FunctionReflectionTest, JitCallAdvanced) { } name; )"; - GetAllTopLevelDecls(code, Decls); + std::vector interpreter_args = {"-include", "new"}; + + GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false, + interpreter_args); auto *CtorD = (clang::CXXConstructorDecl*)Cpp::GetDefaultConstructor(Decls[0]); auto Ctor = Cpp::MakeFunctionCallable(CtorD); @@ -1410,7 +1416,10 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) { int f1(int i) { return i * i; } )"; - GetAllTopLevelDecls(code, Decls); + std::vector interpreter_args = {"-include", "new"}; + + GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false, + interpreter_args); Interp->process(R"( #include @@ -1510,7 +1519,8 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) { }; )"; - GetAllTopLevelDecls(code1, Decls1); + GetAllTopLevelDecls(code1, Decls1, /*filter_implicitGenerated=*/false, + interpreter_args); ASTContext& C = Interp->getCI()->getASTContext(); std::vector argument = {C.IntTy.getAsOpaquePtr()}; @@ -1715,8 +1725,8 @@ TEST(FunctionReflectionTest, Construct) { #ifdef _WIN32 GTEST_SKIP() << "Disabled on Windows. Needs fixing."; #endif - - Cpp::CreateInterpreter(); + std::vector interpreter_args = {"-include", "new"}; + Cpp::CreateInterpreter(interpreter_args); Interp->declare(R"( #include @@ -1777,7 +1787,8 @@ TEST(FunctionReflectionTest, ConstructNested) { GTEST_SKIP() << "Disabled on Windows. Needs fixing."; #endif - Cpp::CreateInterpreter(); + std::vector interpreter_args = {"-include", "new"}; + Cpp::CreateInterpreter(interpreter_args); Interp->declare(R"( #include @@ -1837,7 +1848,8 @@ TEST(FunctionReflectionTest, Destruct) { GTEST_SKIP() << "Disabled on Windows. Needs fixing."; #endif - Cpp::CreateInterpreter(); + std::vector interpreter_args = {"-include", "new"}; + Cpp::CreateInterpreter(interpreter_args); Interp->declare(R"( #include diff --git a/unittests/CppInterOp/InterpreterTest.cpp b/unittests/CppInterOp/InterpreterTest.cpp index 55cd3f742..71e1ca991 100644 --- a/unittests/CppInterOp/InterpreterTest.cpp +++ b/unittests/CppInterOp/InterpreterTest.cpp @@ -86,7 +86,8 @@ TEST(InterpreterTest, Process) { #endif if (llvm::sys::RunningOnValgrind()) GTEST_SKIP() << "XFAIL due to Valgrind report"; - auto* I = Cpp::CreateInterpreter(); + std::vector interpreter_args = { "-include", "new" }; + auto* I = Cpp::CreateInterpreter(interpreter_args); EXPECT_TRUE(Cpp::Process("") == 0); EXPECT_TRUE(Cpp::Process("int a = 12;") == 0); EXPECT_FALSE(Cpp::Process("error_here;") == 0); diff --git a/unittests/CppInterOp/ScopeReflectionTest.cpp b/unittests/CppInterOp/ScopeReflectionTest.cpp index db441e124..1d18575f0 100644 --- a/unittests/CppInterOp/ScopeReflectionTest.cpp +++ b/unittests/CppInterOp/ScopeReflectionTest.cpp @@ -168,7 +168,9 @@ TEST(ScopeReflectionTest, IsBuiltin) { // "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long", // "float", "double", "long double", "void"} - Cpp::CreateInterpreter(); + std::vector interpreter_args = { "-include", "new" }; + + Cpp::CreateInterpreter(interpreter_args); ASTContext &C = Interp->getCI()->getASTContext(); EXPECT_TRUE(Cpp::IsBuiltin(C.BoolTy.getAsOpaquePtr())); EXPECT_TRUE(Cpp::IsBuiltin(C.CharTy.getAsOpaquePtr())); @@ -503,7 +505,10 @@ TEST(ScopeReflectionTest, GetNamed) { } } )"; - Cpp::CreateInterpreter(); + + std::vector interpreter_args = {"-include", "new"}; + + Cpp::CreateInterpreter(interpreter_args); Interp->declare(code); Cpp::TCppScope_t ns_N1 = Cpp::GetNamed("N1", nullptr); @@ -880,7 +885,8 @@ template T TrivialFnTemplate() { return T(); } TEST(ScopeReflectionTest, InstantiateTemplateFunctionFromString) { if (llvm::sys::RunningOnValgrind()) GTEST_SKIP() << "XFAIL due to Valgrind report"; - Cpp::CreateInterpreter(); + std::vector interpreter_args = {"-include", "new"}; + Cpp::CreateInterpreter(interpreter_args); std::string code = R"(#include )"; Interp->process(code); const char* str = "std::make_unique"; @@ -1024,6 +1030,8 @@ TEST(ScopeReflectionTest, IncludeVector) { #include #include )"; + std::vector interpreter_args = {"-include", "new"}; + Cpp::CreateInterpreter(interpreter_args); Interp->declare(code); } diff --git a/unittests/CppInterOp/TypeReflectionTest.cpp b/unittests/CppInterOp/TypeReflectionTest.cpp index 7d5dafcc2..37d884839 100644 --- a/unittests/CppInterOp/TypeReflectionTest.cpp +++ b/unittests/CppInterOp/TypeReflectionTest.cpp @@ -550,7 +550,9 @@ TEST(TypeReflectionTest, IsPODType) { TEST(TypeReflectionTest, IsSmartPtrType) { if (llvm::sys::RunningOnValgrind()) GTEST_SKIP() << "XFAIL due to Valgrind report"; - Cpp::CreateInterpreter(); + + std::vector interpreter_args = {"-include", "new"}; + Cpp::CreateInterpreter(interpreter_args); Interp->declare(R"( #include @@ -588,7 +590,8 @@ TEST(TypeReflectionTest, IsSmartPtrType) { } TEST(TypeReflectionTest, IsFunctionPointerType) { - Cpp::CreateInterpreter(); + std::vector interpreter_args = {"-include", "new"}; + Cpp::CreateInterpreter(interpreter_args); Interp->declare(R"( typedef int (*int_func)(int, int); diff --git a/unittests/CppInterOp/Utils.cpp b/unittests/CppInterOp/Utils.cpp index ca7227b99..4daf18c35 100644 --- a/unittests/CppInterOp/Utils.cpp +++ b/unittests/CppInterOp/Utils.cpp @@ -14,13 +14,16 @@ #include #include +#include using namespace clang; using namespace llvm; -void TestUtils::GetAllTopLevelDecls(const std::string& code, std::vector& Decls, - bool filter_implicitGenerated /* = false */) { - Cpp::CreateInterpreter(); +void TestUtils::GetAllTopLevelDecls( + const std::string& code, std::vector& Decls, + bool filter_implicitGenerated /* = false */, + const std::vector& interpreter_args /* = {} */) { + Cpp::CreateInterpreter(interpreter_args); #ifdef CPPINTEROP_USE_CLING cling::Transaction *T = nullptr; Interp->declare(code, &T); diff --git a/unittests/CppInterOp/Utils.h b/unittests/CppInterOp/Utils.h index 180e209fe..fb79ee804 100644 --- a/unittests/CppInterOp/Utils.h +++ b/unittests/CppInterOp/Utils.h @@ -5,6 +5,7 @@ #include "llvm/Support/Valgrind.h" #include +#include #include #include "clang-c/CXCppInterOp.h" #include "clang-c/CXString.h" @@ -17,10 +18,12 @@ namespace clang { } #define Interp (static_cast(Cpp::GetInterpreter())) namespace TestUtils { - void GetAllTopLevelDecls(const std::string& code, std::vector& Decls, - bool filter_implicitGenerated = false); - void GetAllSubDecls(clang::Decl *D, std::vector& SubDecls, - bool filter_implicitGenerated = false); +void GetAllTopLevelDecls(const std::string& code, + std::vector& Decls, + bool filter_implicitGenerated = false, + const std::vector& interpreter_args = {}); +void GetAllSubDecls(clang::Decl* D, std::vector& SubDecls, + bool filter_implicitGenerated = false); } // end namespace TestUtils const char* get_c_string(CXString string); diff --git a/unittests/CppInterOp/VariableReflectionTest.cpp b/unittests/CppInterOp/VariableReflectionTest.cpp index 0d8376f4d..cf906ead9 100644 --- a/unittests/CppInterOp/VariableReflectionTest.cpp +++ b/unittests/CppInterOp/VariableReflectionTest.cpp @@ -334,6 +334,9 @@ TEST(VariableReflectionTest, VariableOffsetsWithInheritance) { if (llvm::sys::RunningOnValgrind()) GTEST_SKIP() << "XFAIL due to Valgrind report"; + std::vector interpreter_args = {"-include", "new"}; + Cpp::CreateInterpreter(interpreter_args); + Cpp::Declare("#include"); #define Stringify(s) Stringifyx(s)