Skip to content

Add error propagation to interpreter creation logic #553

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 7 commits into from
Apr 17, 2025

Conversation

anutosh491
Copy link
Collaborator

Description

@Vipul-Cariappa and I were discussing a use case yesterday (especially while building with repl) and this is what we realized

  1. The function responsible for creating clang::Interpreter is createClangInterpreter which can return a nullptr, for eg

  2. This is assigned to inner while the constructor for compat::Interpreter is called

    inner = compat::createClangInterpreter(vargs);

which means inner can be nullptr

  1. And then if we look at CreateInterpreter from the top, we're creating the compat::Interpreter here

auto I = new compat::Interpreter(ClingArgv.size(), &ClingArgv[0]);

Which means compat::Interpreter can exist even when the underlying clang::Interpreter is not existing. So we can say that the Interpreter from the top is half broken

  1. So if we try something like
Cpp::CreateInterpreter(...)
Cpp::Parse(..)

We would hit the following finally

llvm::Expected<clang::PartialTranslationUnit&> Parse(llvm::StringRef Code) {
return inner->Parse(Code);
}

And although the call is made to compat::Interpreter, we end up using the underlying clang::Interpreter without checking if it is valid.

Type of change

Please tick all options which are relevant.

  • Bug fix
  • New feature
  • Requires documentation updates

Testing

Please describe the test(s) that you added and ran to verify your changes.

Checklist

  • I have read the contribution guide recently

@anutosh491 anutosh491 changed the title Fixing creation of Interpreter Add error propagation to interpreter creation logic Apr 4, 2025
@mcbarton mcbarton requested a review from vgvassilev April 4, 2025 07:37
@anutosh491
Copy link
Collaborator Author

anutosh491 commented Apr 4, 2025

Hence, we had a couple approaches to go ahead here

i) Introduce a isValid for clang::Interpreter and anytime we have a inner->func_call we use that (sounds a bit cumbersome checking for validity everytime)

ii) What Vipul and I liked was propagating the error all the way to that top, so that a half broken interpreter can't be put to use and a utility function like parse/declare would only work if CreateInterpreter doesn't return null along with an error message saying Interpreter creation failed.

@mcbarton mcbarton requested a review from aaronj0 April 4, 2025 07:40
Copy link

codecov bot commented Apr 4, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.16%. Comparing base (208c36a) to head (0268905).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #553      +/-   ##
==========================================
+ Coverage   75.93%   76.16%   +0.23%     
==========================================
  Files           9        9              
  Lines        3644     3655      +11     
==========================================
+ Hits         2767     2784      +17     
+ Misses        877      871       -6     
Files with missing lines Coverage Δ
lib/Interpreter/CXCppInterOp.cpp 48.86% <100.00%> (+1.58%) ⬆️
lib/Interpreter/Compatibility.h 91.96% <100.00%> (+1.87%) ⬆️
lib/Interpreter/CppInterOp.cpp 83.91% <100.00%> (+0.02%) ⬆️
lib/Interpreter/CppInterOpInterpreter.h 80.54% <100.00%> (+0.43%) ⬆️
Files with missing lines Coverage Δ
lib/Interpreter/CXCppInterOp.cpp 48.86% <100.00%> (+1.58%) ⬆️
lib/Interpreter/Compatibility.h 91.96% <100.00%> (+1.87%) ⬆️
lib/Interpreter/CppInterOp.cpp 83.91% <100.00%> (+0.02%) ⬆️
lib/Interpreter/CppInterOpInterpreter.h 80.54% <100.00%> (+0.43%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

There were too many comments to post at once. Showing the first 10 out of 11. Check the log or trigger a new build to see more.

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

Can we figure out how to write tests?

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

@anutosh491 anutosh491 force-pushed the fix_inner branch 2 times, most recently from 1bb5c43 to 764d551 Compare April 9, 2025 13:13
@anutosh491
Copy link
Collaborator Author

anutosh491 commented Apr 9, 2025

Can we figure out how to write tests?

Okay I think the codecov says that 3 patches are not being tested. All of them are directly based out of the changes in CXCppInterOp.cpp

I tried adding tests but was quick to realize that I am not really doing just justice as I might not be the best one to goto for adding tests for the C API (hence I reverted them and squashed the commits 😅)

cc @Gnimuc

Would be great if you could help me out with the tests here. The PR description (#553 (comment)) should be good to get you started on the changed made in the C-API (the changes are not too concerning, simple ones !)

So we need to test clang_createInterpreter itself which is not being tested anywhere as per codecov

  1. Maybe for the creation of the Intepreter we could start with something simple like
#ifndef CPPINTEROP_USE_CLING
TEST(InterpreterTest, CreateInterpreterCAPI) {
 const char* argv[] = {"-std=c++17"};
 CXInterpreter CXI = clang_createInterpreter(argv, 1);
 EXPECT_TRUE(CXI);


 clang_Interpreter_dispose(CXI);
}
#endif
  1. For testing the failure while creating the interpreter (the case where we return nullptr from clang_createInterpreter), not sure what we can try. Maybe creating an non existent target or so I guess
#ifndef CPPINTEROP_USE_CLING
TEST(InterpreterTest, CreateInterpreterCAPIFailure) {
  // This should return nullptr due to bad target triple
  const char* argv[] = {"-target", "nonexistent-unknown-target"};
  CXInterpreter CXI = clang_createInterpreter(argv, 2);
  EXPECT_EQ(CXI, nullptr);
}
#endif

Thanks in advance ;)

@Gnimuc
Copy link
Contributor

Gnimuc commented Apr 10, 2025

I'll give it a look this weekend.

@anutosh491
Copy link
Collaborator Author

I'll give it a look this weekend.

Thanks a lot for the help. This change ends up being critical now that we'll soon be moving to llvm 20 !

@Gnimuc
Copy link
Contributor

Gnimuc commented Apr 13, 2025

The C API clang_createInterpreter aims to provide a way to customize compiler arguments that are used to create the interpreter, so it doesn't adopt the following setups provided in the C++ API.

ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str());
#ifdef _WIN32
// FIXME : Workaround Sema::PushDeclContext assert on windows
ClingArgv.push_back("-fno-delayed-template-parsing");
#endif
ClingArgv.insert(ClingArgv.end(), Args.begin(), Args.end());
// To keep the Interpreter creation interface between cling and clang-repl
// to some extent compatible we should put Args and GpuArgs together. On the
// receiving end we should check for -xcuda to know.
if (!GpuArgs.empty()) {
llvm::StringRef Arg0 = GpuArgs[0];
Arg0 = Arg0.trim().ltrim('-');
if (Arg0 != "cuda") {
llvm::errs() << "[CreateInterpreter]: Make sure --cuda is passed as the"
<< " first argument of the GpuArgs\n";
return nullptr;
}
}
ClingArgv.insert(ClingArgv.end(), GpuArgs.begin(), GpuArgs.end());
// Process externally passed arguments if present.
std::vector<std::string> ExtraArgs;
auto EnvOpt =
llvm::sys::Process::GetEnv("CPPINTEROP_EXTRA_INTERPRETER_ARGS");
if (EnvOpt) {
StringRef Env(*EnvOpt);
while (!Env.empty()) {
StringRef Arg;
std::tie(Arg, Env) = Env.split(' ');
ExtraArgs.push_back(Arg.str());
}
}
std::transform(ExtraArgs.begin(), ExtraArgs.end(),
std::back_inserter(ClingArgv),
[&](const std::string& str) { return str.c_str(); });

It's a bit tricky to set up a successful test environment because we need to know the path of system headers for each test platform. (Although most of the arguments are excluded in the C API, -include new is mandatory, which needs the correct path of system headers)

@Gnimuc
Copy link
Contributor

Gnimuc commented Apr 13, 2025

Given auto* I = Cpp::CreateInterpreter();, if we can find a way to retrieve the arguments used to create the interpreter, then those arguments can be used to test the C API.

BTW, I think the changes in the PR look good.

@anutosh491
Copy link
Collaborator Author

Thanks for the reply @Gnimuc

BTW, I think the changes in the PR look good.

Also thanks for going through the changes ! Much appreciated :)

Hey @vgvassilev , do you think it's okay if we move ahead with this ?

As said above there's some discussion that needs to be done on testing the C API. And although some simple dummy tests can possibly be added as I wrote above, those won't probably be meaningful enough. So yeah the changes introduce 4 lines of untested code in the C API but we can probably get to it in the future.

The main reason for this Pr is to help @mcbarton 's PR moving to llvm 20 (as his Pr should benefit with these changes after a rebase)

@vgvassilev
Copy link
Contributor

The C API clang_createInterpreter aims to provide a way to customize compiler arguments that are used to create the interpreter, so it doesn't adopt the following setups provided in the C++ API.

ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str());
#ifdef _WIN32
// FIXME : Workaround Sema::PushDeclContext assert on windows
ClingArgv.push_back("-fno-delayed-template-parsing");
#endif
ClingArgv.insert(ClingArgv.end(), Args.begin(), Args.end());
// To keep the Interpreter creation interface between cling and clang-repl
// to some extent compatible we should put Args and GpuArgs together. On the
// receiving end we should check for -xcuda to know.
if (!GpuArgs.empty()) {
llvm::StringRef Arg0 = GpuArgs[0];
Arg0 = Arg0.trim().ltrim('-');
if (Arg0 != "cuda") {
llvm::errs() << "[CreateInterpreter]: Make sure --cuda is passed as the"
<< " first argument of the GpuArgs\n";
return nullptr;
}
}
ClingArgv.insert(ClingArgv.end(), GpuArgs.begin(), GpuArgs.end());
// Process externally passed arguments if present.
std::vector<std::string> ExtraArgs;
auto EnvOpt =
llvm::sys::Process::GetEnv("CPPINTEROP_EXTRA_INTERPRETER_ARGS");
if (EnvOpt) {
StringRef Env(*EnvOpt);
while (!Env.empty()) {
StringRef Arg;
std::tie(Arg, Env) = Env.split(' ');
ExtraArgs.push_back(Arg.str());
}
}
std::transform(ExtraArgs.begin(), ExtraArgs.end(),
std::back_inserter(ClingArgv),
[&](const std::string& str) { return str.c_str(); });

It's a bit tricky to set up a successful test environment because we need to know the path of system headers for each test platform. (Although most of the arguments are excluded in the C API, -include new is mandatory, which needs the correct path of system headers)

Can we make the new header optional?

@anutosh491
Copy link
Collaborator Author

anutosh491 commented Apr 13, 2025

Can we make the new header optional?

I think this should be possible isn't it !

The include new header would be required for tests like these

TEST(FunctionReflectionTest, JitCallAdvanced) {
#ifdef EMSCRIPTEN
GTEST_SKIP() << "Test fails for Emscipten builds";
#endif
if (llvm::sys::RunningOnValgrind())
GTEST_SKIP() << "XFAIL due to Valgrind report";
std::vector<Decl*> Decls;
std::string code = R"(
typedef struct _name {
_name() { p[0] = (void*)0x1; p[1] = (void*)0x2; p[2] = (void*)0x3; }
void* p[3];
} name;
)";
GetAllTopLevelDecls(code, Decls);

Now on line 1375 we have the GetAllTopLevelDecls which ends up calling our CreateInterpreter

void TestUtils::GetAllTopLevelDecls(const std::string& code, std::vector<Decl*>& Decls,
bool filter_implicitGenerated /* = false */) {
Cpp::CreateInterpreter();

So technically if we can improve GetAllTopLevelDecls to take care of custom args-> we can pass the same args to CreateInterpreter from there and whichever test needs whatever header include can use it. That way it is not mandatory to get that include for tests who wouldn't want to use it.

But yeah that would mean changing the function definition of the utility function GetAllTopLevelDecls overall :\
So probably should be done in subsequent PR !!! (which I can try tomorrow)

@anutosh491
Copy link
Collaborator Author

anutosh491 commented Apr 13, 2025

Ahh the 3 failing checks are due to this

compiler-research/xeus-cpp#286

Making the same change here too ! I think we should be good after that !

@mcbarton
Copy link
Collaborator

mcbarton commented Apr 13, 2025

Ahh the 3 failing checks are due to this

compiler-research/xeus-cpp#286

Making the same change here too ! I think we should be good after that !

I think this change should be made as a separate PR, and this PR rebased on it, given this pinning change has nothing to do with the goal of this PR. I will approve and merge this pinning PR, as soon as I see its been put in.

Can we make the new header optional?

I think this should be possible isn't it !

The include new header would be required for tests like these

TEST(FunctionReflectionTest, JitCallAdvanced) {
#ifdef EMSCRIPTEN
GTEST_SKIP() << "Test fails for Emscipten builds";
#endif
if (llvm::sys::RunningOnValgrind())
GTEST_SKIP() << "XFAIL due to Valgrind report";
std::vector<Decl*> Decls;
std::string code = R"(
typedef struct _name {
_name() { p[0] = (void*)0x1; p[1] = (void*)0x2; p[2] = (void*)0x3; }
void* p[3];
} name;
)";
GetAllTopLevelDecls(code, Decls);

Now on line 1375 we have the GetAllTopLevelDecls which ends up calling our CreateInterpreter

void TestUtils::GetAllTopLevelDecls(const std::string& code, std::vector<Decl*>& Decls,
bool filter_implicitGenerated /* = false */) {
Cpp::CreateInterpreter();

So technically if we can improve GetAllTopLevelDecls to take care of custom args-> we can pass the same args to CreateInterpreter from there and whichever test needs whatever header include can use it. That way it is not mandatory to get that include for tests who wouldn't want to use it.

But yeah that would mean changing the function definition of the utility function GetAllTopLevelDecls overall :\ So probably should be done in subsequent PR !!! (which I can try tomorrow)

If making this header option would allow this PR to be tested, then should probably be done first, and then this PR should be rebased this on it. Otherwise we risk tests never been made to cover these lines. I know its just a few lines, but its because due to not insisting all lines be covered by tests, we have ended up in a situation where CppInterOps coverage has dropped by approximately 13% in the last 12 months (I made an issue about this here #541).

@anutosh491
Copy link
Collaborator Author

anutosh491 commented Apr 13, 2025

Hi,

I think this change should be made as a separate PR

I've taken care of this here #559

If making this header option would allow this PR to be tested, then should probably be done first, and then this PR should be rebased this on it. Otherwise we risk tests never been made to cover these lines. I know its just a few lines, but its because due to not insisting all lines be covered by tests, we have ended up in a situation where CppInterOps coverage has dropped by approximately 13% in the last 12 months (I made an issue about this here #541).

Hmmm, I get it but shouldn't higher priority be moving to LLVM 20 now (it was out on FEB 2 and its high time we move) . The purpose of this PR was to help with that.

Also I am not a huge fan of nobody officially taking responsibility for covering the C API. It shouldn't have been added in the first place if that was the case !

Most of my focus since the past 2-3 weeks is around getting a good build (native/emscripten) for cppinterop around llvm 20 and technically this PR is also tested well on our C++ API. But for the C-API
i) I am not educated enough on the use case.
ii) I would really fall short on time to handle development/coverage there.

But this shouldn't slow any development on C++ API side is what I'm trying to convey.

I'm just going by Gnimuc 's word who added the C-API (he says "BTW, I think the changes in the PR look good." #553 (comment)) so I am just hoping we would be in a good enough state to test it in the near future. But if something as simple as a "create interpreter" function is not tested in the C API do we really stop other work due to that ? I don't know.

I just think handling error propagation while creating the interpreter is much more important that all of the above (but those might just be my views)

@anutosh491
Copy link
Collaborator Author

If making this header option would allow this PR to be tested

I asked @kr-2003 to help me with this and we came up with this #561

@Gnimuc
Copy link
Contributor

Gnimuc commented Apr 14, 2025

#ifndef CPPINTEROP_USE_CLING
TEST(InterpreterTest, CreateInterpreterCAPIFailure) {
// This should return nullptr due to bad target triple
const char* argv[] = {"-target", "nonexistent-unknown-target"};
CXInterpreter CXI = clang_createInterpreter(argv, 2);
EXPECT_EQ(CXI, nullptr);
}
#endif

@anutosh491 Maybe it's a good idea to add this failure test for now. It will improve the coverage a bit.

@Gnimuc
Copy link
Contributor

Gnimuc commented Apr 14, 2025

The C API clang_createInterpreter aims to provide a way to customize compiler arguments that are used to create the interpreter, so it doesn't adopt the following setups provided in the C++ API.

ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str());
#ifdef _WIN32
// FIXME : Workaround Sema::PushDeclContext assert on windows
ClingArgv.push_back("-fno-delayed-template-parsing");
#endif
ClingArgv.insert(ClingArgv.end(), Args.begin(), Args.end());
// To keep the Interpreter creation interface between cling and clang-repl
// to some extent compatible we should put Args and GpuArgs together. On the
// receiving end we should check for -xcuda to know.
if (!GpuArgs.empty()) {
llvm::StringRef Arg0 = GpuArgs[0];
Arg0 = Arg0.trim().ltrim('-');
if (Arg0 != "cuda") {
llvm::errs() << "[CreateInterpreter]: Make sure --cuda is passed as the"
<< " first argument of the GpuArgs\n";
return nullptr;
}
}
ClingArgv.insert(ClingArgv.end(), GpuArgs.begin(), GpuArgs.end());
// Process externally passed arguments if present.
std::vector<std::string> ExtraArgs;
auto EnvOpt =
llvm::sys::Process::GetEnv("CPPINTEROP_EXTRA_INTERPRETER_ARGS");
if (EnvOpt) {
StringRef Env(*EnvOpt);
while (!Env.empty()) {
StringRef Arg;
std::tie(Arg, Env) = Env.split(' ');
ExtraArgs.push_back(Arg.str());
}
}
std::transform(ExtraArgs.begin(), ExtraArgs.end(),
std::back_inserter(ClingArgv),
[&](const std::string& str) { return str.c_str(); });

It's a bit tricky to set up a successful test environment because we need to know the path of system headers for each test platform. (Although most of the arguments are excluded in the C API, -include new is mandatory, which needs the correct path of system headers)

Can we make the new header optional?

I'm wondering what's the original purpose of adding this header. Is it related to the hard-coded code in clang::Interpreter::create. An operator new trampoline function is declared there.

@vgvassilev
Copy link
Contributor

The C API clang_createInterpreter aims to provide a way to customize compiler arguments that are used to create the interpreter, so it doesn't adopt the following setups provided in the C++ API.

ClingArgv.insert(ClingArgv.begin(), MainExecutableName.c_str());
#ifdef _WIN32
// FIXME : Workaround Sema::PushDeclContext assert on windows
ClingArgv.push_back("-fno-delayed-template-parsing");
#endif
ClingArgv.insert(ClingArgv.end(), Args.begin(), Args.end());
// To keep the Interpreter creation interface between cling and clang-repl
// to some extent compatible we should put Args and GpuArgs together. On the
// receiving end we should check for -xcuda to know.
if (!GpuArgs.empty()) {
llvm::StringRef Arg0 = GpuArgs[0];
Arg0 = Arg0.trim().ltrim('-');
if (Arg0 != "cuda") {
llvm::errs() << "[CreateInterpreter]: Make sure --cuda is passed as the"
<< " first argument of the GpuArgs\n";
return nullptr;
}
}
ClingArgv.insert(ClingArgv.end(), GpuArgs.begin(), GpuArgs.end());
// Process externally passed arguments if present.
std::vector<std::string> ExtraArgs;
auto EnvOpt =
llvm::sys::Process::GetEnv("CPPINTEROP_EXTRA_INTERPRETER_ARGS");
if (EnvOpt) {
StringRef Env(*EnvOpt);
while (!Env.empty()) {
StringRef Arg;
std::tie(Arg, Env) = Env.split(' ');
ExtraArgs.push_back(Arg.str());
}
}
std::transform(ExtraArgs.begin(), ExtraArgs.end(),
std::back_inserter(ClingArgv),
[&](const std::string& str) { return str.c_str(); });

It's a bit tricky to set up a successful test environment because we need to know the path of system headers for each test platform. (Although most of the arguments are excluded in the C API, -include new is mandatory, which needs the correct path of system headers)

Can we make the new header optional?

I'm wondering what's the original purpose of adding this header. Is it related to the hard-coded code in clang::Interpreter::create. An operator new trampoline function is declared there.

We did not have a trampoline in the past. I think maybe now we can drop it for llvm20?

@anutosh491
Copy link
Collaborator Author

anutosh491 commented Apr 14, 2025

Hey @Gnimuc, we just dropped the header through #561

Does this put you in a better position to add some basic tests for clang_createInterpreter or other related functions ?

Would be great if yes, cause then we can have some initial set of tests like very simple ones. Move that in and then rebase this PR on top of those changes if that makes sense !

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

clang-tidy made some suggestions

@@ -167,6 +167,22 @@ TEST(InterpreterTest, CreateInterpreter) {
#endif
}

#ifndef CPPINTEROP_USE_CLING
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is there a reason why we are not doing this test for Cling?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

No clue,

I see no C-API tests done through cling and that's what I am trying to replicate. Maybe @Gnimuc can educate us here.

Copy link
Contributor

Choose a reason for hiding this comment

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

The original purpose of adding the C API is to support multiple instances. REPL and Cling are two backends for creating compiler instances. REPL is based on clang::Interpreter from the upstream llvm-project.

I think there is no plan to upstream Cling to the llvm-project, and I didn't check Cling's compatibility when I added those C-API tests.

Copy link
Contributor

Choose a reason for hiding this comment

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

You can build, CppInterOp by providing cling and it will embed cling in it. If that’s not too much of work maybe we can support that, shouldn’t hurt.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can we have a dedicated PR for that ?

I'll say the purpose of this PR is complete now.

If that’s not too much of work maybe we can support that, shouldn’t hurt.

@Gnimuc would you like to give this an attempt ?

@anutosh491
Copy link
Collaborator Author

Hey @Gnimuc @vgvassilev

I have added some simple tests and ensured codecov doesn't complain about changes atleast with regard to this PR.

All tests pass no clue why the windows CI fail (don't look like a direct outcome of my tests)

image

Shall try looking into it for a bit (or shall skip If I am helpless cause I don't have a windows machine :\ )

@kr-2003
Copy link
Contributor

kr-2003 commented Apr 15, 2025

Hey @Gnimuc @vgvassilev

I have added some simple tests and ensured codecov doesn't complain about changes atleast with regard to this PR.

All tests pass no clue why the windows CI fail (don't look like a direct outcome of my tests)

image

Shall try looking into it for a bit (or shall skip If I am helpless cause I don't have a windows machine :\ )

Tests which write something on screen fails on Windows. Here, in this comment @mcbarton explained this:
#513 (comment)

@mcbarton
Copy link
Collaborator

mcbarton commented Apr 15, 2025

Hey @Gnimuc @vgvassilev
I have added some simple tests and ensured codecov doesn't complain about changes atleast with regard to this PR.
All tests pass no clue why the windows CI fail (don't look like a direct outcome of my tests)
image
Shall try looking into it for a bit (or shall skip If I am helpless cause I don't have a windows machine :\ )

Tests which write something on screen fails on Windows. Here, in this comment @mcbarton explained this: #513 (comment)

To refine this comment from before. I think anything which makes the interpreter write an error message in Windows, will be picked up as an error in the overall running of the tests. Tests which seem to write a warning message are ok. I believe it is ok for you skip this test on Windows for this reason.

@kr-2003
Copy link
Contributor

kr-2003 commented Apr 15, 2025

To refine this comment from before. I think anything which makes the interpreter write an error message in Windows, will be picked up as an error in the overall running of the tests. Tests which seem to write a warning message are ok. I believe it is ok for you skip this test on Windows for this reason.

Alternatively, we can suppress the error message and retain this test on windows too. It should pass now.


TEST(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"};
  testing::internal::CaptureStderr(); // Suppress error messages
  auto *CXI = clang_createInterpreter(argv, 3);
  std::string capturedStderr = testing::internal::GetCapturedStderr();
  EXPECT_EQ(CXI, nullptr);
}

@mcbarton
Copy link
Collaborator

mcbarton commented Apr 15, 2025

To refine this comment from before. I think anything which makes the interpreter write an error message in Windows, will be picked up as an error in the overall running of the tests. Tests which seem to write a warning message are ok. I believe it is ok for you skip this test on Windows for this reason.

Alternatively, we can suppress the error message and retain this test on windows too. It should pass now.


TEST(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"};
  testing::internal::CaptureStderr(); // Suppress error messages
  auto *CXI = clang_createInterpreter(argv, 3);
  std::string capturedStderr = testing::internal::GetCapturedStderr();
  EXPECT_EQ(CXI, nullptr);
}

Not entirely sure testing::internal::CaptureStderr() will work to resolve this issue. Its probably better to skip for now on Windows. We do however want to make use of GTEST_SKIP(), instead of the way its done currently in the PR.

@anutosh491
Copy link
Collaborator Author

Its probably better to skip for now on Windows

Yeah I think we can just skip it for now.

@anutosh491
Copy link
Collaborator Author

I think this is ready from my side now that all the checks pass.

Copy link
Contributor

@vgvassilev vgvassilev left a comment

Choose a reason for hiding this comment

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

Please also address the missing includes suggested by clang-tidy before merging.

@anutosh491
Copy link
Collaborator Author

Addressed all reviews. I think this should be ready now. Thanks everyone for the reviews. Squashing and Merging!

@anutosh491 anutosh491 merged commit 721d33b into compiler-research:main Apr 17, 2025
75 checks passed
@anutosh491 anutosh491 deleted the fix_inner branch April 17, 2025 11:04
Gnimuc added a commit to Gnimuc/Yggdrasil that referenced this pull request Apr 19, 2025
- update source to test compiler-research/CppInterOp#553
- remove wasm link flags in the cmake patch
giordano pushed a commit to JuliaPackaging/Yggdrasil that referenced this pull request Apr 22, 2025
- update source to test compiler-research/CppInterOp#553
- remove wasm link flags in the cmake patch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants