Skip to content

Removed "include new" from Interpreter constructor #561

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Apr 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions lib/Interpreter/CppInterOpInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ class Interpreter {
llvm::InitializeAllAsmPrinters();

std::vector<const char*> vargs(argv + 1, argv + argc);
vargs.push_back("-include");
vargs.push_back("new");
inner = compat::createClangInterpreter(vargs);
}

Expand Down
30 changes: 21 additions & 9 deletions unittests/CppInterOp/FunctionReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*> interpreter_args = { "-include", "new" };
Cpp::CreateInterpreter(interpreter_args);
std::string code = R"(#include <memory>)";
Interp->process(code);
const char* str = "std::make_unique<int,int>";
Expand Down Expand Up @@ -1322,8 +1323,10 @@ TEST(FunctionReflectionTest, GetFunctionAddress) {
#endif
std::vector<Decl*> Decls, SubDecls;
std::string code = "int f1(int i) { return i * i; }";
std::vector<const char*> interpreter_args = {"-include", "new"};

GetAllTopLevelDecls(code, Decls);
GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false,
interpreter_args);

testing::internal::CaptureStdout();
Interp->declare("#include <iostream>");
Expand Down Expand Up @@ -1372,7 +1375,10 @@ TEST(FunctionReflectionTest, JitCallAdvanced) {
} name;
)";

GetAllTopLevelDecls(code, Decls);
std::vector<const char*> 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);
Expand Down Expand Up @@ -1410,7 +1416,10 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
int f1(int i) { return i * i; }
)";

GetAllTopLevelDecls(code, Decls);
std::vector<const char*> interpreter_args = {"-include", "new"};

GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false,
interpreter_args);

Interp->process(R"(
#include <string>
Expand Down Expand Up @@ -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<Cpp::TemplateArgInfo> argument = {C.IntTy.getAsOpaquePtr()};
Expand Down Expand Up @@ -1715,8 +1725,8 @@ TEST(FunctionReflectionTest, Construct) {
#ifdef _WIN32
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
#endif

Cpp::CreateInterpreter();
std::vector<const char*> interpreter_args = {"-include", "new"};
Cpp::CreateInterpreter(interpreter_args);

Interp->declare(R"(
#include <new>
Expand Down Expand Up @@ -1777,7 +1787,8 @@ TEST(FunctionReflectionTest, ConstructNested) {
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
#endif

Cpp::CreateInterpreter();
std::vector<const char*> interpreter_args = {"-include", "new"};
Cpp::CreateInterpreter(interpreter_args);

Interp->declare(R"(
#include <new>
Expand Down Expand Up @@ -1837,7 +1848,8 @@ TEST(FunctionReflectionTest, Destruct) {
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
#endif

Cpp::CreateInterpreter();
std::vector<const char*> interpreter_args = {"-include", "new"};
Cpp::CreateInterpreter(interpreter_args);

Interp->declare(R"(
#include <new>
Expand Down
3 changes: 2 additions & 1 deletion unittests/CppInterOp/InterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*> 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);
Expand Down
14 changes: 11 additions & 3 deletions unittests/CppInterOp/ScopeReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*> 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()));
Expand Down Expand Up @@ -503,7 +505,10 @@ TEST(ScopeReflectionTest, GetNamed) {
}
}
)";
Cpp::CreateInterpreter();

std::vector<const char*> interpreter_args = {"-include", "new"};

Cpp::CreateInterpreter(interpreter_args);

Interp->declare(code);
Cpp::TCppScope_t ns_N1 = Cpp::GetNamed("N1", nullptr);
Expand Down Expand Up @@ -880,7 +885,8 @@ template<typename T> T TrivialFnTemplate() { return T(); }
TEST(ScopeReflectionTest, InstantiateTemplateFunctionFromString) {
if (llvm::sys::RunningOnValgrind())
GTEST_SKIP() << "XFAIL due to Valgrind report";
Cpp::CreateInterpreter();
std::vector<const char*> interpreter_args = {"-include", "new"};
Cpp::CreateInterpreter(interpreter_args);
std::string code = R"(#include <memory>)";
Interp->process(code);
const char* str = "std::make_unique<int,int>";
Expand Down Expand Up @@ -1024,6 +1030,8 @@ TEST(ScopeReflectionTest, IncludeVector) {
#include <vector>
#include <iostream>
)";
std::vector<const char*> interpreter_args = {"-include", "new"};
Cpp::CreateInterpreter(interpreter_args);
Interp->declare(code);
}

Expand Down
7 changes: 5 additions & 2 deletions unittests/CppInterOp/TypeReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const char*> interpreter_args = {"-include", "new"};
Cpp::CreateInterpreter(interpreter_args);

Interp->declare(R"(
#include <memory>
Expand Down Expand Up @@ -588,7 +590,8 @@ TEST(TypeReflectionTest, IsSmartPtrType) {
}

TEST(TypeReflectionTest, IsFunctionPointerType) {
Cpp::CreateInterpreter();
std::vector<const char*> interpreter_args = {"-include", "new"};
Cpp::CreateInterpreter(interpreter_args);

Interp->declare(R"(
typedef int (*int_func)(int, int);
Expand Down
9 changes: 6 additions & 3 deletions unittests/CppInterOp/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,16 @@

#include <algorithm>
#include <string>
#include <vector>

using namespace clang;
using namespace llvm;

void TestUtils::GetAllTopLevelDecls(const std::string& code, std::vector<Decl*>& Decls,
bool filter_implicitGenerated /* = false */) {
Cpp::CreateInterpreter();
void TestUtils::GetAllTopLevelDecls(
const std::string& code, std::vector<Decl*>& Decls,
bool filter_implicitGenerated /* = false */,
const std::vector<const char*>& interpreter_args /* = {} */) {
Cpp::CreateInterpreter(interpreter_args);
#ifdef CPPINTEROP_USE_CLING
cling::Transaction *T = nullptr;
Interp->declare(code, &T);
Expand Down
11 changes: 7 additions & 4 deletions unittests/CppInterOp/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

#include "llvm/Support/Valgrind.h"
#include <memory>
#include <string>
#include <vector>
#include "clang-c/CXCppInterOp.h"
#include "clang-c/CXString.h"
Expand All @@ -17,10 +18,12 @@ namespace clang {
}
#define Interp (static_cast<compat::Interpreter*>(Cpp::GetInterpreter()))
namespace TestUtils {
void GetAllTopLevelDecls(const std::string& code, std::vector<clang::Decl*>& Decls,
bool filter_implicitGenerated = false);
void GetAllSubDecls(clang::Decl *D, std::vector<clang::Decl*>& SubDecls,
bool filter_implicitGenerated = false);
void GetAllTopLevelDecls(const std::string& code,
std::vector<clang::Decl*>& Decls,
bool filter_implicitGenerated = false,
const std::vector<const char*>& interpreter_args = {});
void GetAllSubDecls(clang::Decl* D, std::vector<clang::Decl*>& SubDecls,
bool filter_implicitGenerated = false);
} // end namespace TestUtils

const char* get_c_string(CXString string);
Expand Down
3 changes: 3 additions & 0 deletions unittests/CppInterOp/VariableReflectionTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,9 @@ TEST(VariableReflectionTest, VariableOffsetsWithInheritance) {
if (llvm::sys::RunningOnValgrind())
GTEST_SKIP() << "XFAIL due to Valgrind report";

std::vector<const char*> interpreter_args = {"-include", "new"};
Cpp::CreateInterpreter(interpreter_args);

Cpp::Declare("#include<string>");

#define Stringify(s) Stringifyx(s)
Expand Down
Loading