From 11ac22a5c907644f4aa6a4fd5c17a340c295f777 Mon Sep 17 00:00:00 2001 From: kr-2003 Date: Mon, 14 Apr 2025 11:03:51 +0530 Subject: [PATCH 1/3] removed include new from Interpreter constructor --- lib/Interpreter/CppInterOpInterpreter.h | 2 -- .../CppInterOp/FunctionReflectionTest.cpp | 26 ++++++++++++------- unittests/CppInterOp/InterpreterTest.cpp | 3 ++- unittests/CppInterOp/ScopeReflectionTest.cpp | 14 +++++++--- unittests/CppInterOp/TypeReflectionTest.cpp | 7 +++-- unittests/CppInterOp/Utils.cpp | 9 ++++--- unittests/CppInterOp/Utils.h | 11 +++++--- .../CppInterOp/VariableReflectionTest.cpp | 3 +++ 8 files changed, 51 insertions(+), 24 deletions(-) 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..b01b30397 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,9 @@ 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, false, interpreter_args); testing::internal::CaptureStdout(); Interp->declare("#include "); @@ -1372,7 +1374,9 @@ TEST(FunctionReflectionTest, JitCallAdvanced) { } name; )"; - GetAllTopLevelDecls(code, Decls); + std::vector interpreter_args = {"-include", "new"}; + + GetAllTopLevelDecls(code, Decls, false, interpreter_args); auto *CtorD = (clang::CXXConstructorDecl*)Cpp::GetDefaultConstructor(Decls[0]); auto Ctor = Cpp::MakeFunctionCallable(CtorD); @@ -1410,7 +1414,9 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) { int f1(int i) { return i * i; } )"; - GetAllTopLevelDecls(code, Decls); + std::vector interpreter_args = {"-include", "new"}; + + GetAllTopLevelDecls(code, Decls, false, interpreter_args); Interp->process(R"( #include @@ -1510,7 +1516,7 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) { }; )"; - GetAllTopLevelDecls(code1, Decls1); + GetAllTopLevelDecls(code1, Decls1, false, interpreter_args); ASTContext& C = Interp->getCI()->getASTContext(); std::vector argument = {C.IntTy.getAsOpaquePtr()}; @@ -1715,8 +1721,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 +1783,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 +1844,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..11ede7a5c 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", "string"}; + Cpp::CreateInterpreter(interpreter_args); + Cpp::Declare("#include"); #define Stringify(s) Stringifyx(s) From 331cfb8f538824fdbb66894dde6fd9e5971b78b6 Mon Sep 17 00:00:00 2001 From: kr-2003 Date: Mon, 14 Apr 2025 14:48:06 +0530 Subject: [PATCH 2/3] filter_implicitGenerated in default arg --- unittests/CppInterOp/FunctionReflectionTest.cpp | 12 ++++++++---- unittests/CppInterOp/VariableReflectionTest.cpp | 3 +-- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/unittests/CppInterOp/FunctionReflectionTest.cpp b/unittests/CppInterOp/FunctionReflectionTest.cpp index b01b30397..5153bf19c 100644 --- a/unittests/CppInterOp/FunctionReflectionTest.cpp +++ b/unittests/CppInterOp/FunctionReflectionTest.cpp @@ -1325,7 +1325,8 @@ TEST(FunctionReflectionTest, GetFunctionAddress) { std::string code = "int f1(int i) { return i * i; }"; std::vector interpreter_args = {"-include", "new"}; - GetAllTopLevelDecls(code, Decls, false, interpreter_args); + GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false, + interpreter_args); testing::internal::CaptureStdout(); Interp->declare("#include "); @@ -1376,7 +1377,8 @@ TEST(FunctionReflectionTest, JitCallAdvanced) { std::vector interpreter_args = {"-include", "new"}; - GetAllTopLevelDecls(code, Decls, false, interpreter_args); + GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false, + interpreter_args); auto *CtorD = (clang::CXXConstructorDecl*)Cpp::GetDefaultConstructor(Decls[0]); auto Ctor = Cpp::MakeFunctionCallable(CtorD); @@ -1416,7 +1418,8 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) { std::vector interpreter_args = {"-include", "new"}; - GetAllTopLevelDecls(code, Decls, false, interpreter_args); + GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false, + interpreter_args); Interp->process(R"( #include @@ -1516,7 +1519,8 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) { }; )"; - GetAllTopLevelDecls(code1, Decls1, false, interpreter_args); + GetAllTopLevelDecls(code1, Decls1, /*filter_implicitGenerated=*/false, + interpreter_args); ASTContext& C = Interp->getCI()->getASTContext(); std::vector argument = {C.IntTy.getAsOpaquePtr()}; diff --git a/unittests/CppInterOp/VariableReflectionTest.cpp b/unittests/CppInterOp/VariableReflectionTest.cpp index 11ede7a5c..7b9ceab8e 100644 --- a/unittests/CppInterOp/VariableReflectionTest.cpp +++ b/unittests/CppInterOp/VariableReflectionTest.cpp @@ -334,8 +334,7 @@ TEST(VariableReflectionTest, VariableOffsetsWithInheritance) { if (llvm::sys::RunningOnValgrind()) GTEST_SKIP() << "XFAIL due to Valgrind report"; - std::vector interpreter_args = {"-include", "string"}; - Cpp::CreateInterpreter(interpreter_args); + Cpp::CreateInterpreter(); Cpp::Declare("#include"); From 4651c6f749fce32235266329c611c2272d7413f2 Mon Sep 17 00:00:00 2001 From: kr-2003 Date: Mon, 14 Apr 2025 14:58:12 +0530 Subject: [PATCH 3/3] added interpreter_args to VariableOffsetsWithInheritance --- unittests/CppInterOp/VariableReflectionTest.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/unittests/CppInterOp/VariableReflectionTest.cpp b/unittests/CppInterOp/VariableReflectionTest.cpp index 7b9ceab8e..cf906ead9 100644 --- a/unittests/CppInterOp/VariableReflectionTest.cpp +++ b/unittests/CppInterOp/VariableReflectionTest.cpp @@ -334,7 +334,8 @@ TEST(VariableReflectionTest, VariableOffsetsWithInheritance) { if (llvm::sys::RunningOnValgrind()) GTEST_SKIP() << "XFAIL due to Valgrind report"; - Cpp::CreateInterpreter(); + std::vector interpreter_args = {"-include", "new"}; + Cpp::CreateInterpreter(interpreter_args); Cpp::Declare("#include");