Skip to content

Commit 96045bd

Browse files
authored
Removed "include new" from Interpreter constructor (#561)
* removed include new from Interpreter constructor * filter_implicitGenerated in default arg * added interpreter_args to VariableOffsetsWithInheritance
1 parent ddd67a2 commit 96045bd

File tree

8 files changed

+55
-24
lines changed

8 files changed

+55
-24
lines changed

lib/Interpreter/CppInterOpInterpreter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,6 @@ class Interpreter {
148148
llvm::InitializeAllAsmPrinters();
149149

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

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 21 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -637,7 +637,8 @@ TEST(FunctionReflectionTest, ExistsFunctionTemplate) {
637637
TEST(FunctionReflectionTest, InstantiateTemplateFunctionFromString) {
638638
if (llvm::sys::RunningOnValgrind())
639639
GTEST_SKIP() << "XFAIL due to Valgrind report";
640-
Cpp::CreateInterpreter();
640+
std::vector<const char*> interpreter_args = { "-include", "new" };
641+
Cpp::CreateInterpreter(interpreter_args);
641642
std::string code = R"(#include <memory>)";
642643
Interp->process(code);
643644
const char* str = "std::make_unique<int,int>";
@@ -1322,8 +1323,10 @@ TEST(FunctionReflectionTest, GetFunctionAddress) {
13221323
#endif
13231324
std::vector<Decl*> Decls, SubDecls;
13241325
std::string code = "int f1(int i) { return i * i; }";
1326+
std::vector<const char*> interpreter_args = {"-include", "new"};
13251327

1326-
GetAllTopLevelDecls(code, Decls);
1328+
GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false,
1329+
interpreter_args);
13271330

13281331
testing::internal::CaptureStdout();
13291332
Interp->declare("#include <iostream>");
@@ -1372,7 +1375,10 @@ TEST(FunctionReflectionTest, JitCallAdvanced) {
13721375
} name;
13731376
)";
13741377

1375-
GetAllTopLevelDecls(code, Decls);
1378+
std::vector<const char*> interpreter_args = {"-include", "new"};
1379+
1380+
GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false,
1381+
interpreter_args);
13761382
auto *CtorD
13771383
= (clang::CXXConstructorDecl*)Cpp::GetDefaultConstructor(Decls[0]);
13781384
auto Ctor = Cpp::MakeFunctionCallable(CtorD);
@@ -1410,7 +1416,10 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
14101416
int f1(int i) { return i * i; }
14111417
)";
14121418

1413-
GetAllTopLevelDecls(code, Decls);
1419+
std::vector<const char*> interpreter_args = {"-include", "new"};
1420+
1421+
GetAllTopLevelDecls(code, Decls, /*filter_implicitGenerated=*/false,
1422+
interpreter_args);
14141423

14151424
Interp->process(R"(
14161425
#include <string>
@@ -1510,7 +1519,8 @@ TEST(FunctionReflectionTest, GetFunctionCallWrapper) {
15101519
};
15111520
)";
15121521

1513-
GetAllTopLevelDecls(code1, Decls1);
1522+
GetAllTopLevelDecls(code1, Decls1, /*filter_implicitGenerated=*/false,
1523+
interpreter_args);
15141524
ASTContext& C = Interp->getCI()->getASTContext();
15151525

15161526
std::vector<Cpp::TemplateArgInfo> argument = {C.IntTy.getAsOpaquePtr()};
@@ -1715,8 +1725,8 @@ TEST(FunctionReflectionTest, Construct) {
17151725
#ifdef _WIN32
17161726
GTEST_SKIP() << "Disabled on Windows. Needs fixing.";
17171727
#endif
1718-
1719-
Cpp::CreateInterpreter();
1728+
std::vector<const char*> interpreter_args = {"-include", "new"};
1729+
Cpp::CreateInterpreter(interpreter_args);
17201730

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

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

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

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

18421854
Interp->declare(R"(
18431855
#include <new>

unittests/CppInterOp/InterpreterTest.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ TEST(InterpreterTest, Process) {
8686
#endif
8787
if (llvm::sys::RunningOnValgrind())
8888
GTEST_SKIP() << "XFAIL due to Valgrind report";
89-
auto* I = Cpp::CreateInterpreter();
89+
std::vector<const char*> interpreter_args = { "-include", "new" };
90+
auto* I = Cpp::CreateInterpreter(interpreter_args);
9091
EXPECT_TRUE(Cpp::Process("") == 0);
9192
EXPECT_TRUE(Cpp::Process("int a = 12;") == 0);
9293
EXPECT_FALSE(Cpp::Process("error_here;") == 0);

unittests/CppInterOp/ScopeReflectionTest.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,9 @@ TEST(ScopeReflectionTest, IsBuiltin) {
168168
// "int", "unsigned int", "long", "unsigned long", "long long", "unsigned long long",
169169
// "float", "double", "long double", "void"}
170170

171-
Cpp::CreateInterpreter();
171+
std::vector<const char*> interpreter_args = { "-include", "new" };
172+
173+
Cpp::CreateInterpreter(interpreter_args);
172174
ASTContext &C = Interp->getCI()->getASTContext();
173175
EXPECT_TRUE(Cpp::IsBuiltin(C.BoolTy.getAsOpaquePtr()));
174176
EXPECT_TRUE(Cpp::IsBuiltin(C.CharTy.getAsOpaquePtr()));
@@ -503,7 +505,10 @@ TEST(ScopeReflectionTest, GetNamed) {
503505
}
504506
}
505507
)";
506-
Cpp::CreateInterpreter();
508+
509+
std::vector<const char*> interpreter_args = {"-include", "new"};
510+
511+
Cpp::CreateInterpreter(interpreter_args);
507512

508513
Interp->declare(code);
509514
Cpp::TCppScope_t ns_N1 = Cpp::GetNamed("N1", nullptr);
@@ -880,7 +885,8 @@ template<typename T> T TrivialFnTemplate() { return T(); }
880885
TEST(ScopeReflectionTest, InstantiateTemplateFunctionFromString) {
881886
if (llvm::sys::RunningOnValgrind())
882887
GTEST_SKIP() << "XFAIL due to Valgrind report";
883-
Cpp::CreateInterpreter();
888+
std::vector<const char*> interpreter_args = {"-include", "new"};
889+
Cpp::CreateInterpreter(interpreter_args);
884890
std::string code = R"(#include <memory>)";
885891
Interp->process(code);
886892
const char* str = "std::make_unique<int,int>";
@@ -1024,6 +1030,8 @@ TEST(ScopeReflectionTest, IncludeVector) {
10241030
#include <vector>
10251031
#include <iostream>
10261032
)";
1033+
std::vector<const char*> interpreter_args = {"-include", "new"};
1034+
Cpp::CreateInterpreter(interpreter_args);
10271035
Interp->declare(code);
10281036
}
10291037

unittests/CppInterOp/TypeReflectionTest.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -550,7 +550,9 @@ TEST(TypeReflectionTest, IsPODType) {
550550
TEST(TypeReflectionTest, IsSmartPtrType) {
551551
if (llvm::sys::RunningOnValgrind())
552552
GTEST_SKIP() << "XFAIL due to Valgrind report";
553-
Cpp::CreateInterpreter();
553+
554+
std::vector<const char*> interpreter_args = {"-include", "new"};
555+
Cpp::CreateInterpreter(interpreter_args);
554556

555557
Interp->declare(R"(
556558
#include <memory>
@@ -588,7 +590,8 @@ TEST(TypeReflectionTest, IsSmartPtrType) {
588590
}
589591

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

593596
Interp->declare(R"(
594597
typedef int (*int_func)(int, int);

unittests/CppInterOp/Utils.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@
1414

1515
#include <algorithm>
1616
#include <string>
17+
#include <vector>
1718

1819
using namespace clang;
1920
using namespace llvm;
2021

21-
void TestUtils::GetAllTopLevelDecls(const std::string& code, std::vector<Decl*>& Decls,
22-
bool filter_implicitGenerated /* = false */) {
23-
Cpp::CreateInterpreter();
22+
void TestUtils::GetAllTopLevelDecls(
23+
const std::string& code, std::vector<Decl*>& Decls,
24+
bool filter_implicitGenerated /* = false */,
25+
const std::vector<const char*>& interpreter_args /* = {} */) {
26+
Cpp::CreateInterpreter(interpreter_args);
2427
#ifdef CPPINTEROP_USE_CLING
2528
cling::Transaction *T = nullptr;
2629
Interp->declare(code, &T);

unittests/CppInterOp/Utils.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include "llvm/Support/Valgrind.h"
77
#include <memory>
8+
#include <string>
89
#include <vector>
910
#include "clang-c/CXCppInterOp.h"
1011
#include "clang-c/CXString.h"
@@ -17,10 +18,12 @@ namespace clang {
1718
}
1819
#define Interp (static_cast<compat::Interpreter*>(Cpp::GetInterpreter()))
1920
namespace TestUtils {
20-
void GetAllTopLevelDecls(const std::string& code, std::vector<clang::Decl*>& Decls,
21-
bool filter_implicitGenerated = false);
22-
void GetAllSubDecls(clang::Decl *D, std::vector<clang::Decl*>& SubDecls,
23-
bool filter_implicitGenerated = false);
21+
void GetAllTopLevelDecls(const std::string& code,
22+
std::vector<clang::Decl*>& Decls,
23+
bool filter_implicitGenerated = false,
24+
const std::vector<const char*>& interpreter_args = {});
25+
void GetAllSubDecls(clang::Decl* D, std::vector<clang::Decl*>& SubDecls,
26+
bool filter_implicitGenerated = false);
2427
} // end namespace TestUtils
2528

2629
const char* get_c_string(CXString string);

unittests/CppInterOp/VariableReflectionTest.cpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,9 @@ TEST(VariableReflectionTest, VariableOffsetsWithInheritance) {
334334
if (llvm::sys::RunningOnValgrind())
335335
GTEST_SKIP() << "XFAIL due to Valgrind report";
336336

337+
std::vector<const char*> interpreter_args = {"-include", "new"};
338+
Cpp::CreateInterpreter(interpreter_args);
339+
337340
Cpp::Declare("#include<string>");
338341

339342
#define Stringify(s) Stringifyx(s)

0 commit comments

Comments
 (0)