Skip to content

Improve Cpp::Construct pointer logic for memory arena flags #650

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 1 commit into from
Jun 28, 2025

Conversation

aaronj0
Copy link
Collaborator

@aaronj0 aaronj0 commented Jun 27, 2025

Also handle both ctors and class scopes. Upstreamed from root-project/root#18546

@aaronj0 aaronj0 requested a review from vgvassilev June 27, 2025 08:45
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

return nullptr;
// invoke the constructor (placement/heap) in one shot
// flag is non-null for placement new, null for normal new
void* flag = arena ? reinterpret_cast<void*>(1) : nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast]

    void* flag = arena ? reinterpret_cast<void*>(1) : nullptr;
                         ^

// flag is non-null for placement new, null for normal new
void* flag = arena ? reinterpret_cast<void*>(1) : nullptr;
void* result = arena;
JC.InvokeConstructor(&result, count, {}, flag);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]

    JC.InvokeConstructor(&result, count, {}, flag);
                         ^

Copy link

codecov bot commented Jun 27, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 78.80%. Comparing base (3474903) to head (6d11f91).
Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #650      +/-   ##
==========================================
+ Coverage   78.79%   78.80%   +0.01%     
==========================================
  Files           9        9              
  Lines        3852     3854       +2     
==========================================
+ Hits         3035     3037       +2     
  Misses        817      817              
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.34% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 86.70% <100.00%> (+0.01%) ⬆️
Files with missing lines Coverage Δ
include/CppInterOp/CppInterOp.h 95.34% <ø> (ø)
lib/CppInterOp/CppInterOp.cpp 86.70% <100.00%> (+0.01%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@mcbarton
Copy link
Collaborator

mcbarton commented Jun 27, 2025

@aaronj0 Ignore the failing Emscripten job. It wasn't anything you did. It happened on one of my PRs. The Emscripten static library for llvm 19 is a little demanding for the Ubuntu Github runners. If you rerun the job it should pass.

@aaronj0 aaronj0 force-pushed the improve-cpp-construct branch from 92a2afa to 6d22d46 Compare June 27, 2025 11:42
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

testing::internal::CaptureStdout();
where = Cpp::Allocate(scope);
EXPECT_TRUE(where == Cpp::Construct(SubDecls[2], where));
EXPECT_TRUE(*(int *)where == 12345);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]

  EXPECT_TRUE(*(int *)where == 12345);
               ^

@aaronj0 aaronj0 requested a review from vgvassilev June 27, 2025 11:58
@aaronj0 aaronj0 force-pushed the improve-cpp-construct branch 2 times, most recently from 7f632d3 to f4c269a Compare June 27, 2025 15:02
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

testing::internal::CaptureStdout();
where = Cpp::Allocate(scope);
EXPECT_TRUE(where == Cpp::Construct(SubDecls[3], where));
EXPECT_TRUE(*(int*)where == 12345);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use C-style cast to convert between unrelated types [cppcoreguidelines-pro-type-cstyle-cast]

  EXPECT_TRUE(*(int*)where == 12345);
               ^

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

return nullptr;
// invoke the constructor (placement/heap) in one shot
// flag is non-null for placement new, null for normal new
void* is_arena = arena ? reinterpret_cast<void*>(1) : nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: do not use reinterpret_cast [cppcoreguidelines-pro-type-reinterpret-cast]

    void* is_arena = arena ? reinterpret_cast<void*>(1) : nullptr;
                             ^

// flag is non-null for placement new, null for normal new
void* is_arena = arena ? reinterpret_cast<void*>(1) : nullptr;
void* result = arena;
JC.InvokeConstructor(&result, count, /*args=*/{}, is_arena);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: multilevel pointer conversion from 'void **' to 'void *', please use explicit cast [bugprone-multi-level-implicit-pointer-conversion]

    JC.InvokeConstructor(&result, count, /*args=*/{}, is_arena);
                         ^

Also handle both ctors and class scopes
@aaronj0 aaronj0 force-pushed the improve-cpp-construct branch from dba9728 to 6d11f91 Compare June 28, 2025 06:11
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.

Nice! LGTM!

@aaronj0
Copy link
Collaborator Author

aaronj0 commented Jun 28, 2025

@mcbarton There is something wrong with the Emscripten build jobs, they have been running for over an hour and (seems to have) stopped progressing past [ 55%] Built target googletest

@aaronj0
Copy link
Collaborator Author

aaronj0 commented Jun 28, 2025

I am going ahead and merging this PR since the test that was extended is not run on windows, nor emscripten builds with llvm < 20 (which cover the 3 jobs that are stalled), but the issue on the CI must be investigated

@aaronj0 aaronj0 merged commit 9c94230 into compiler-research:main Jun 28, 2025
90 of 95 checks passed
aaronj0 added a commit to aaronj0/root that referenced this pull request Jun 28, 2025
Adds various upstreamed developments:

compiler-research/CppInterOp#650 streamlines the logic in Cpp::Construct to be more generic.
compiler-research/CppInterOp#643 by @hageboeck making CppInterOp work with new gtest target names
Fixed wrapper name conflicts with ROOT that also uses `__cf`, allowing us to integrate JitCall incrementally and co-exist with CallFunc
Fixes related to the cppyy forks
Unrelated work on Emscripten and WebAssembly
aaronj0 added a commit to root-project/root that referenced this pull request Jun 28, 2025
Adds various upstreamed developments:

compiler-research/CppInterOp#650 streamlines the logic in Cpp::Construct to be more generic.
compiler-research/CppInterOp#643 by @hageboeck making CppInterOp work with new gtest target names
Fixed wrapper name conflicts with ROOT that also uses `__cf`, allowing us to integrate JitCall incrementally and co-exist with CallFunc
Fixes related to the cppyy forks
Unrelated work on Emscripten and WebAssembly
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.

3 participants