Skip to content

Conversation

kr-2003
Copy link
Owner

@kr-2003 kr-2003 commented Jun 25, 2025

Description

Please include a summary of changes, motivation and context for this PR.

Fixes # (issue)

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

Copy link

@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 15. Check the log or trigger a new build to see more.

///\returns 0 on success, non-zero on failure.
CPPINTEROP_API int Undo(unsigned N = 1);

CPPINTEROP_API pid_t GetExecutorPID();

Choose a reason for hiding this comment

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

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

include/CppInterOp/CppInterOp.h:21:

- #include <vector>
+ #include <sys/types.h>
+ #include <vector>


#include "llvm/Support/Error.h"

#include <vector>

Choose a reason for hiding this comment

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

warning: #includes are not sorted properly [llvm-include-order]

#include <vector>
^

this fix will not be applied because it overlaps with another fix


#include <vector>
#include <unistd.h>

Choose a reason for hiding this comment

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

warning: included header unistd.h is not used directly [misc-include-cleaner]

Suggested change


namespace compat {

static int m_child_stdout_fd = -1;

Choose a reason for hiding this comment

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

warning: variable 'm_child_stdout_fd' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

static int m_child_stdout_fd = -1;
           ^

namespace compat {

static int m_child_stdout_fd = -1;
static int m_child_stderr_fd = -1;

Choose a reason for hiding this comment

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

warning: variable 'm_child_stderr_fd' is non-const and globally accessible, consider making it const [cppcoreguidelines-avoid-non-const-global-variables]

static int m_child_stderr_fd = -1;
           ^

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

static void drainChildOutput() {
char buffer[4096];

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]

    char buffer[4096];
    ^


static void drainChildOutput() {
char buffer[4096];
ssize_t bytes_read;

Choose a reason for hiding this comment

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

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

lib/CppInterOp/CppInterOpInterpreter.h:25:

- #if CLANG_VERSION_MAJOR >= 19
+ #include <sys/types.h>
+ #if CLANG_VERSION_MAJOR >= 19


if (compat::m_child_stdout_fd != -1) {
int flags = fcntl(compat::m_child_stdout_fd, F_GETFL, 0);
fcntl(compat::m_child_stdout_fd, F_SETFL, flags | O_NONBLOCK);

Choose a reason for hiding this comment

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

warning: do not call c-style vararg functions [cppcoreguidelines-pro-type-vararg]

      fcntl(compat::m_child_stdout_fd, F_SETFL, flags | O_NONBLOCK);
      ^

int flags = fcntl(compat::m_child_stdout_fd, F_GETFL, 0);
fcntl(compat::m_child_stdout_fd, F_SETFL, flags | O_NONBLOCK);

while ((bytes_read = read(compat::m_child_stdout_fd, buffer,

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]

      while ((bytes_read = read(compat::m_child_stdout_fd, buffer,
                                                           ^


while ((bytes_read = read(compat::m_child_stdout_fd, buffer,
sizeof(buffer))) > 0) {
fwrite(buffer, 1, bytes_read, stdout);

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]

        fwrite(buffer, 1, bytes_read, stdout);
               ^

Copy link

@Vipul-Cariappa Vipul-Cariappa left a comment

Choose a reason for hiding this comment

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

We will first need to test this on the CpInterOp CI, then we can make a PR to LLVM. Just to be safe, that are changes are correct and valid.

```bash
mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt \

Choose a reason for hiding this comment

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

Suggested change
cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt \
cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt" \

mkdir build
cd build
cmake -DLLVM_ENABLE_PROJECTS="clang;compiler-rt \

Choose a reason for hiding this comment

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

.

../llvm
# For Linux
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt --parallel $(nproc --all)

Choose a reason for hiding this comment

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

In my system (Linux - X86-64) the target is:

Suggested change
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt --parallel $(nproc --all)
cmake --build . --target clang clang-repl llvm-jitlink-executor orc_rt-x86_64 --parallel $(nproc --all)


CPPINTEROP_API pid_t GetExecutorPID();

// CPPINTEROP_API void SendInputToChild(const std::string& input);

Choose a reason for hiding this comment

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

If this is not yet implemented, it should not be part of the PR. Even as a comment.


EPC = ExitOnError(
launchExecutor(OOPExecutor, UseSharedMemory, SlabAllocateSizeString,
/*stdin_pipe[0]*/0, stdout_pipe[1], stderr_pipe[1]));

Choose a reason for hiding this comment

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

Why are you not yet using the stdin pipe?

Comment on lines +729 to +755
+void drainChildOutput() {
+ char buffer[4096];
+ ssize_t bytes_read;
+
+ // Drain stdout pipe
+ if (g_child_stdout_fd != -1) {
+ // Make non-blocking to avoid hanging if no data
+ int flags = fcntl(g_child_stdout_fd, F_GETFL, 0);
+ fcntl(g_child_stdout_fd, F_SETFL, flags | O_NONBLOCK);
+
+ while ((bytes_read = read(g_child_stdout_fd, buffer, sizeof(buffer))) > 0) {
+ fwrite(buffer, 1, bytes_read, stdout);
+ }
+ fflush(stdout);
+ }
+
+ // Drain stderr pipe
+ if (g_child_stderr_fd != -1) {
+ int flags = fcntl(g_child_stderr_fd, F_GETFL, 0);
+ fcntl(g_child_stderr_fd, F_SETFL, flags | O_NONBLOCK);
+
+ while ((bytes_read = read(g_child_stderr_fd, buffer, sizeof(buffer))) > 0) {
+ fwrite(buffer, 1, bytes_read, stderr);
+ }
+ fflush(stderr);
+ }
+}

Choose a reason for hiding this comment

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

Why is this defined here? I believe this should be part of CppInterOp and not LLVM. Am I missing something?

Comment on lines +770 to +772
+ std::cout << "OOPExecutor: " << OOPExecutor << std::endl;
+ std::cout << "UseSharedMemory: " << UseSharedMemory << std::endl;
+ std::cout << "SlabAllocateSizeString: " << SlabAllocateSizeString << std::endl;

Choose a reason for hiding this comment

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

No prints.

Comment on lines +773 to +780
+ int stdout_pipe[2], stderr_pipe[2];
+ if (pipe(stdout_pipe) != 0 || pipe(stderr_pipe) != 0) {
+ llvm::errs() << "Failed to create pipes for child process I/O\n";
+ return 0;
+ }
+ EPC = ExitOnErr(
+ launchExecutor(OOPExecutor, UseSharedMemory, SlabAllocateSizeString, 0, stdout_pipe[1], stderr_pipe[1]));
+

Choose a reason for hiding this comment

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

We should not create any pipes for the clang-repl case. It should just follow the defaults.

}

Input = "";
+ drainChildOutput();

Choose a reason for hiding this comment

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

.

Choose a reason for hiding this comment

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

You will need to regenerate this patch file by taking a diff with master, as some of these are merged.

Choose a reason for hiding this comment

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

Resolved

@Vipul-Cariappa
Copy link

You should also consider the clang-tidy (github-actions bot) comments.

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.

2 participants