Skip to content

Add support for array of objects in Construct/Destruct #587

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

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

aaronj0
Copy link
Collaborator

@aaronj0 aaronj0 commented May 21, 2025

No description provided.

@aaronj0 aaronj0 requested a review from vgvassilev May 21, 2025 15:37
Copy link

codecov bot commented May 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 76.47%. Comparing base (6951212) to head (624bfb1).

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #587      +/-   ##
==========================================
+ Coverage   76.36%   76.47%   +0.11%     
==========================================
  Files           9        9              
  Lines        3655     3673      +18     
==========================================
+ Hits         2791     2809      +18     
  Misses        864      864              
Files with missing lines Coverage Δ
include/clang/Interpreter/CppInterOp.h 96.29% <100.00%> (ø)
lib/Interpreter/CXCppInterOp.cpp 48.86% <100.00%> (ø)
lib/Interpreter/CppInterOp.cpp 84.39% <100.00%> (+0.14%) ⬆️
Files with missing lines Coverage Δ
include/clang/Interpreter/CppInterOp.h 96.29% <100.00%> (ø)
lib/Interpreter/CXCppInterOp.cpp 48.86% <100.00%> (ø)
lib/Interpreter/CppInterOp.cpp 84.39% <100.00%> (+0.14%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@aaronj0 aaronj0 marked this pull request as draft May 21, 2025 16:47
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 22. Check the log or trigger a new build to see more.

// Forward if we intended to call a dtor with only 1 parameter.
if (m_Kind == kDestructorCall && result && !args.m_Args)
return InvokeDestructor(result, /*nary=*/0UL, /*withFree=*/true);
return InvokeDestructor(result, nary, /*withFree=*/true);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: return statement within a void function should not have a specified return value [readability-avoid-return-with-void-value]

Suggested change
return InvokeDestructor(result, nary, /*withFree=*/true);
{ InvokeDestructor(result, nary, /*withFree=*/true); return;
}


#ifndef NDEBUG
assert(AreArgumentsValid(result, args, self) && "Invalid args!");
ReportInvokeStart(result, args, self);
#endif // NDEBUG
m_GenericCall(self, args.m_ArgSize, args.m_Args, result);
m_GenericCall(self, args.m_ArgSize, args.m_Args, result, nary);
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 access members of unions; use (boost::)variant instead [cppcoreguidelines-pro-type-union-access]

      m_GenericCall(self, args.m_ArgSize, args.m_Args, result, nary);
      ^


#ifndef NDEBUG
assert(AreArgumentsValid(result, args, self) && "Invalid args!");
ReportInvokeStart(result, args, self);
#endif // NDEBUG
m_GenericCall(self, args.m_ArgSize, args.m_Args, result);
m_GenericCall(self, args.m_ArgSize, args.m_Args, result, nary);
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: narrowing conversion from 'size_t' (aka 'unsigned long') to signed type 'int' is implementation-defined [cppcoreguidelines-narrowing-conversions]

      m_GenericCall(self, args.m_ArgSize, args.m_Args, result, nary);
                          ^

TCppObject_t Allocate(TCppScope_t scope) {
return (TCppObject_t)::operator new(Cpp::SizeOf(scope));
TCppObject_t Allocate(TCppScope_t scope, TCppIndex_t count) {
return (TCppObject_t)::operator new(Cpp::SizeOf(scope) * count);
Copy link
Contributor

Choose a reason for hiding this comment

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

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

lib/Interpreter/CppInterOp.cpp:39:

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

::operator delete(address);
void Deallocate(TCppScope_t scope, TCppObject_t address, TCppIndex_t count) {
size_t bytes = Cpp::SizeOf(scope) * count;
::operator delete(address, bytes);
Copy link
Contributor

Choose a reason for hiding this comment

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

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

    ::operator delete(address, bytes);
      ^

@@ -3596,7 +3633,8 @@
auto* const Ctor = GetDefaultConstructor(interp, Class);
if (JitCall JC = MakeFunctionCallable(&interp, Ctor)) {
if (arena) {
JC.Invoke(&arena, {}, (void*)~0); // Tell Invoke to use placement new.
JC.Invoke(&arena, {}, (void*)~0,
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]

        JC.Invoke(&arena, {}, (void*)~0,
                              ^

@@ -3596,7 +3633,8 @@
auto* const Ctor = GetDefaultConstructor(interp, Class);
if (JitCall JC = MakeFunctionCallable(&interp, Ctor)) {
if (arena) {
JC.Invoke(&arena, {}, (void*)~0); // Tell Invoke to use placement new.
JC.Invoke(&arena, {}, (void*)~0,
Copy link
Contributor

Choose a reason for hiding this comment

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

warning: integer to pointer cast pessimizes optimization opportunities [performance-no-int-to-ptr]

        JC.Invoke(&arena, {}, (void*)~0,
                              ^

@@ -3596,7 +3633,8 @@
auto* const Ctor = GetDefaultConstructor(interp, Class);
if (JitCall JC = MakeFunctionCallable(&interp, Ctor)) {
if (arena) {
JC.Invoke(&arena, {}, (void*)~0); // Tell Invoke to use placement new.
JC.Invoke(&arena, {}, (void*)~0,
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.Invoke(&arena, {}, (void*)~0,
                  ^

@@ -1950,6 +1950,58 @@ TEST(FunctionReflectionTest, ConstructNested) {
output.clear();
}

TEST(FunctionReflectionTest, ConstructArray) {
Copy link
Contributor

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(FunctionReflectionTest, ConstructArray) {
TESTstatic (FunctionReflectionTest, ConstructArray) {

testing::internal::CaptureStdout();
EXPECT_TRUE(where == Cpp::Construct(scope, where, a)); // placement new
// Check for the value of x which should be at the start of the object.
EXPECT_TRUE(*(int*)where == 42);
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 == 42);
               ^

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.

1 participant