Skip to content
Open
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
13 changes: 11 additions & 2 deletions lib/Interpreter/CXCppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,17 @@ static inline compat::Interpreter* getInterpreter(const CXInterpreterImpl* I) {
}

CXInterpreter clang_createInterpreter(const char* const* argv, int argc) {
auto* I = new CXInterpreterImpl(); // NOLINT(*-owning-memory)
auto I = std::make_unique<CXInterpreterImpl>(); // NOLINT(*-owning-memory)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::make_unique" is directly included [misc-include-cleaner]

  auto I = std::make_unique<CXInterpreterImpl>(); // NOLINT(*-owning-memory)
                ^

#ifdef CPPINTEROP_USE_CLING
I->Interp = std::make_unique<compat::Interpreter>(argc, argv);
#else
I->Interp = compat::Interpreter::create(argc, argv);
if (!I->Interp) {
return nullptr;
}
#endif
return I.release();
// I->Interp = std::make_unique<compat::Interpreter>(argc, argv);
// create a bridge between CXTranslationUnit and clang::Interpreter
// auto AU = std::make_unique<ASTUnit>(false);
// AU->FileMgr = I->Interp->getCompilerInstance().getFileManager();
Expand All @@ -281,7 +290,7 @@ CXInterpreter clang_createInterpreter(const char* const* argv, int argc) {
// AU->Ctx = &I->Interp->getSema().getASTContext();
// I->TU.reset(MakeCXTranslationUnit(static_cast<CIndexer*>(clang_createIndex(0,
// 0)), AU));
return I;
// return I;
}

CXInterpreter clang_createInterpreterFromRawPtr(TInterp_t I) {
Expand Down
8 changes: 8 additions & 0 deletions lib/Interpreter/CppInterOp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2957,7 +2957,15 @@ namespace Cpp {
std::back_inserter(ClingArgv),
[&](const std::string& str) { return str.c_str(); });

#ifdef CPPINTEROP_USE_CLING
auto I = new compat::Interpreter(ClingArgv.size(), &ClingArgv[0]);
#else
auto Interp = compat::Interpreter::create(
static_cast<int>(ClingArgv.size()), ClingArgv.data());
if (!Interp)
return nullptr;
auto* I = Interp.release();
#endif

// Honor -mllvm.
//
Expand Down
20 changes: 15 additions & 5 deletions lib/Interpreter/CppInterOpInterpreter.h
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,15 @@ class Interpreter {
private:
std::unique_ptr<clang::Interpreter> inner;

Interpreter(std::unique_ptr<clang::Interpreter> CI) : inner(std::move(CI)) {}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::move" is directly included [misc-include-cleaner]

lib/Interpreter/CppInterOpInterpreter.h:24:

- #if CLANG_VERSION_MAJOR >= 19
+ #include <utility>
+ #if CLANG_VERSION_MAJOR >= 19


public:
Interpreter(int argc, const char* const* argv, const char* llvmdir = 0,
const std::vector<std::shared_ptr<clang::ModuleFileExtension>>&
moduleExtensions = {},
void* extraLibHandle = 0, bool noRuntime = true) {

static std::unique_ptr<Interpreter>
create(int argc, const char* const* argv, const char* llvmdir = nullptr,
const std::vector<std::shared_ptr<clang::ModuleFileExtension>>&

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "clang::ModuleFileExtension" is directly included [misc-include-cleaner]

lib/Interpreter/CppInterOpInterpreter.h:24:

- #if CLANG_VERSION_MAJOR >= 19
+ #include <clang/Serialization/ModuleFileExtension.h>
+ #if CLANG_VERSION_MAJOR >= 19

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::shared_ptr" is directly included [misc-include-cleaner]

         const std::vector<std::shared_ptr<clang::ModuleFileExtension>>&
                                ^

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "std::vector" is directly included [misc-include-cleaner]

lib/Interpreter/CppInterOpInterpreter.h:24:

- #if CLANG_VERSION_MAJOR >= 19
+ #include <vector>
+ #if CLANG_VERSION_MAJOR >= 19

moduleExtensions = {},
void* extraLibHandle = nullptr, bool noRuntime = true) {
// Initialize all targets (required for device offloading)
llvm::InitializeAllTargetInfos();
llvm::InitializeAllTargets();
Expand All @@ -150,7 +154,13 @@ class Interpreter {
std::vector<const char*> vargs(argv + 1, argv + argc);
vargs.push_back("-include");
vargs.push_back("new");
inner = compat::createClangInterpreter(vargs);
auto CI = compat::createClangInterpreter(vargs);
if (!CI) {
llvm::errs() << "Interpreter creation failed\n";

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: no header providing "llvm::errs" is directly included [misc-include-cleaner]

lib/Interpreter/CppInterOpInterpreter.h:24:

- #if CLANG_VERSION_MAJOR >= 19
+ #include <llvm/Support/raw_ostream.h>
+ #if CLANG_VERSION_MAJOR >= 19

return nullptr;
}

return std::unique_ptr<Interpreter>(new Interpreter(std::move(CI)));
}

~Interpreter() {}
Expand Down
23 changes: 23 additions & 0 deletions unittests/CppInterOp/InterpreterTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,29 @@ TEST(InterpreterTest, CreateInterpreter) {
#endif
}

TEST(InterpreterTest, CreateInterpreterCAPI) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'TEST' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]

Suggested change
TEST(InterpreterTest, CreateInterpreterCAPI) {
TESTstatic (InterpreterTest, CreateInterpreterCAPI) {

#ifdef CPPINTEROP_USE_CLING
GTEST_SKIP() << "C API is not available in this build";
#endif
// C API
const char* argv[] = {"-std=c++17"};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

  const char* argv[] = {"-std=c++17"};
        ^

auto *CXI = clang_createInterpreter(argv, 1);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

  auto *CXI = clang_createInterpreter(argv, 1);
                                      ^

auto CLI = clang_Interpreter_getClangInterpreter(CXI);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: 'auto CLI' can be declared as 'auto *CLI' [llvm-qualified-auto]

Suggested change
auto CLI = clang_Interpreter_getClangInterpreter(CXI);
auto *CLI = clang_Interpreter_getClangInterpreter(CXI);

EXPECT_TRUE(CLI);
clang_Interpreter_dispose(CXI);
}

TEST(InterpreterTest, CreateInterpreterCAPIFailure) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: function 'TEST' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]

Suggested change
TEST(InterpreterTest, CreateInterpreterCAPIFailure) {
TESTstatic (InterpreterTest, CreateInterpreterCAPIFailure) {

#ifdef CPPINTEROP_USE_CLING
GTEST_SKIP() << "C API is not available in this build";
#endif
const char* argv[] = {"-fsyntax-only", "-Xclang", "-invalid-plugin"};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not declare C-style arrays, use std::array<> instead [cppcoreguidelines-avoid-c-arrays]

  const char* argv[] = {"-fsyntax-only", "-Xclang", "-invalid-plugin"};
        ^

testing::internal::CaptureStderr(); // Suppress error messages
auto *CXI = clang_createInterpreter(argv, 3);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: do not implicitly decay an array into a pointer; consider using gsl::array_view or an explicit cast instead [cppcoreguidelines-pro-bounds-array-to-pointer-decay]

  auto *CXI = clang_createInterpreter(argv, 3);
                                      ^

std::string capturedStderr = testing::internal::GetCapturedStderr();
EXPECT_EQ(CXI, nullptr);
}

#ifdef LLVM_BINARY_DIR
TEST(InterpreterTest, DetectResourceDir) {
#ifdef EMSCRIPTEN
Expand Down
Loading