-
Notifications
You must be signed in to change notification settings - Fork 31
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
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #587 +/- ##
==========================================
+ Coverage 77.70% 77.86% +0.16%
==========================================
Files 9 9
Lines 3749 3809 +60
==========================================
+ Hits 2913 2966 +53
- Misses 836 843 +7
🚀 New features to boost your workflow:
|
There was a problem hiding this 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); |
There was a problem hiding this comment.
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]
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); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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);
^
lib/Interpreter/CppInterOp.cpp
Outdated
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); |
There was a problem hiding this comment.
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
lib/Interpreter/CppInterOp.cpp
Outdated
::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); |
There was a problem hiding this comment.
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);
^
lib/Interpreter/CppInterOp.cpp
Outdated
@@ -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, |
There was a problem hiding this comment.
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,
^
lib/Interpreter/CppInterOp.cpp
Outdated
@@ -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, |
There was a problem hiding this comment.
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,
^
lib/Interpreter/CppInterOp.cpp
Outdated
@@ -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, |
There was a problem hiding this comment.
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,
^
0b3d49d
to
b6d01ac
Compare
There was a problem hiding this 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.
@@ -768,19 +798,24 @@ enum : long int { | |||
CPPINTEROP_API std::vector<long int> GetDimensions(TCppType_t type); | |||
|
|||
/// Allocates memory for a given class. | |||
CPPINTEROP_API TCppObject_t Allocate(TCppScope_t scope); | |||
/// \c count is used to indicate the number of objects to allocate for. | |||
CPPINTEROP_API TCppObject_t Allocate(TCppScope_t scope, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: enum '(unnamed enum at /github/workspace/include/CppInterOp/CppInterOp.h:802:1)' uses a larger base type ('long', size: 8 bytes) than necessary for its value set, consider using 'std::int8_t' (1 byte) as the base type to reduce its size [performance-enum-size]
enum : long int {
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should adjust the types to match the signature types to match the generated code types and disable the clang-tidy complaints if we have to.
} | ||
|
||
// Standard branch: | ||
// (*(ClassName**)ret) = (obj) ? new (*(ClassName**)ret) ClassName(args...) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'auto *CD' can be declared as 'const auto *CD' [readability-qualified-auto]
// (*(ClassName**)ret) = (obj) ? new (*(ClassName**)ret) ClassName(args...) | |
const auto* CD = dyn_cast<CXXConstructorDecl>(FD); |
@@ -2831,6 +2904,13 @@ CPPINTEROP_API JitCall MakeFunctionCallable(TInterp_t I, | |||
return {}; | |||
} | |||
|
|||
if (const auto* Ctor = dyn_cast<CXXConstructorDecl>(D)) { | |||
if (auto Wrapper = make_wrapper(*interp, cast<FunctionDecl>(D))) |
There was a problem hiding this comment.
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_pair" is directly included [misc-include-cleaner]
gDtorWrapperStore.insert(make_pair(D, F));
^
@@ -1883,7 +1883,7 @@ TEST(FunctionReflectionTest, Construct) { | |||
testing::internal::CaptureStdout(); | |||
auto* I = clang_createInterpreterFromRawPtr(Cpp::GetInterpreter()); | |||
auto scope_c = make_scope(static_cast<clang::Decl*>(scope), I); | |||
auto object_c = clang_construct(scope_c, nullptr); | |||
auto object_c = clang_construct(scope_c, nullptr, 1UL); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'auto object_c' can be declared as 'auto *object_c' [llvm-qualified-auto]
auto object_c = clang_construct(scope_c, nullptr, 1UL); | |
auto *object_c = clang_construct(scope_c, nullptr, 1UL); |
There was a problem hiding this 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 20. Check the log or trigger a new build to see more.
"Number of objects to construct/destruct should be atleast 1"); | ||
|
||
if (Cpp::IsConstructor(m_FD)) { | ||
const auto* CD = cast<CXXConstructorDecl>((const Decl*)m_FD); |
There was a problem hiding this comment.
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]
const auto* CD = cast<CXXConstructorDecl>((const Decl*)m_FD);
^
@@ -3613,33 +3694,36 @@ TCppObject_t Construct(compat::Interpreter& interp, TCppScope_t scope, | |||
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.InvokeConstructor(&arena, count, {}, |
There was a problem hiding this comment.
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(&arena, count, {},
^
lib/CppInterOp/CppInterOp.cpp
Outdated
return arena; | ||
} | ||
|
||
void* obj = nullptr; | ||
JC.Invoke(&obj); | ||
JC.InvokeConstructor(&obj, count, {}, false); |
There was a problem hiding this comment.
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(&obj, count, {}, false);
^
There was a problem hiding this 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.
@@ -3613,33 +3694,36 @@ TCppObject_t Construct(compat::Interpreter& interp, TCppScope_t scope, | |||
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.InvokeConstructor(&arena, count, {}, | |||
(void*)~0); // Tell Invoke to use placement new. |
There was a problem hiding this comment.
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]
(void*)~0); // Tell Invoke to use placement new.
^
@@ -3613,33 +3694,36 @@ | |||
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.InvokeConstructor(&arena, count, {}, | |||
(void*)~0); // Tell Invoke to use placement new. |
There was a problem hiding this comment.
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]
(void*)~0); // Tell Invoke to use placement new.
^
return arena; | ||
} | ||
|
||
void* obj = nullptr; | ||
JC.Invoke(&obj); | ||
JC.InvokeConstructor(&obj, count, {}, nullptr); |
There was a problem hiding this comment.
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(&obj, count, {}, nullptr);
^
There was a problem hiding this 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(); | ||
|
||
// destruct the rest | ||
auto new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) + |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: 'auto new_head' can be declared as 'auto *new_head' [llvm-qualified-auto]
auto new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) + | |
auto *new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) + |
testing::internal::CaptureStdout(); | ||
|
||
// destruct the rest | ||
auto new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) + |
There was a problem hiding this comment.
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]
auto new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) +
^
testing::internal::CaptureStdout(); | ||
|
||
// destruct the rest | ||
auto new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) + |
There was a problem hiding this comment.
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]
auto new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) +
^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like we are heading in a good direction. Let's make clang-tidy and codecov happy first.
if (Cpp::IsConstructor(m_FD)) { | ||
const auto* CD = cast<CXXConstructorDecl>((const Decl*)m_FD); | ||
if (CD->getMinRequiredArguments() != 0 && nary > 1) { | ||
assert(0 && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add a death test here.
There was a problem hiding this 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(); | ||
|
||
// destruct the rest | ||
auto *new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) + |
There was a problem hiding this comment.
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]
auto *new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) +
^
testing::internal::CaptureStdout(); | ||
|
||
// destruct the rest | ||
auto *new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) + |
There was a problem hiding this comment.
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]
auto *new_head = reinterpret_cast<void*>(reinterpret_cast<char*>(where) +
^
lib/CppInterOp/CppInterOp.cpp
Outdated
if (N) { | ||
callbuf << "("; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd move that in the loop, maybe it improves readability...
There was a problem hiding this 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 obj; | ||
} | ||
return nullptr; | ||
} | ||
|
||
TCppObject_t Construct(TCppScope_t scope, void* arena /*=nullptr*/) { | ||
return Construct(getInterp(), scope, arena); | ||
TCppObject_t Construct(TCppScope_t scope, void* arena /*=nullptr*/, |
There was a problem hiding this comment.
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(&arena, count, {},
^
TCppObject_t Construct(TCppScope_t scope, void* arena /*=nullptr*/) { | ||
return Construct(getInterp(), scope, arena); | ||
TCppObject_t Construct(TCppScope_t scope, void* arena /*=nullptr*/, | ||
TCppIndex_t count /*=1UL*/) { |
There was a problem hiding this comment.
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]
(void*)~0); // Tell Invoke to use placement new.
^
TCppObject_t Construct(TCppScope_t scope, void* arena /*=nullptr*/) { | ||
return Construct(getInterp(), scope, arena); | ||
TCppObject_t Construct(TCppScope_t scope, void* arena /*=nullptr*/, | ||
TCppIndex_t count /*=1UL*/) { |
There was a problem hiding this comment.
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]
(void*)~0); // Tell Invoke to use placement new.
^
} | ||
|
||
void Destruct(compat::Interpreter& interp, TCppObject_t This, Decl* Class, | ||
bool withFree) { | ||
bool withFree, TCppIndex_t nary) { |
There was a problem hiding this comment.
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(&obj, count, {}, nullptr);
^
auto* Class = static_cast<Decl*>(scope); | ||
Destruct(getInterp(), This, Class, withFree); | ||
Destruct(getInterp(), This, Class, withFree, count); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: function 'Destruct' can be made static or moved into an anonymous namespace to enforce internal linkage [misc-use-internal-linkage]
Destruct(getInterp(), This, Class, withFree, count); | |
static void Destruct(compat::Interpreter& interp, TCppObject_t This, Decl* Class, |
This catches 0 objects to construct/destruct and attempting array new with requried initialization parameters
There was a problem hiding this 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 obj; | ||
} | ||
return nullptr; | ||
} | ||
|
||
TCppObject_t Construct(TCppScope_t scope, void* arena /*=nullptr*/) { | ||
return Construct(getInterp(), scope, arena); | ||
TCppObject_t Construct(TCppScope_t scope, void* arena /*=nullptr*/, |
There was a problem hiding this comment.
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);
^
} | ||
|
||
void Destruct(compat::Interpreter& interp, TCppObject_t This, Decl* Class, | ||
bool withFree) { | ||
bool withFree, TCppIndex_t nary) { |
There was a problem hiding this comment.
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]
auto* Class = (Decl*)scope;
^
return; | ||
} | ||
// FIXME: Diagnose. | ||
} | ||
|
||
void Destruct(TCppObject_t This, TCppScope_t scope, bool withFree /*=true*/) { | ||
void Destruct(TCppObject_t This, TCppScope_t scope, bool withFree /*=true*/, |
There was a problem hiding this comment.
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(&arena, count, {},
^
return; | ||
} | ||
// FIXME: Diagnose. | ||
} | ||
|
||
void Destruct(TCppObject_t This, TCppScope_t scope, bool withFree /*=true*/) { | ||
void Destruct(TCppObject_t This, TCppScope_t scope, bool withFree /*=true*/, | ||
TCppIndex_t count /*=0UL*/) { |
There was a problem hiding this comment.
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]
(void*)~0); // Tell Invoke to use placement new.
^
return; | ||
} | ||
// FIXME: Diagnose. | ||
} | ||
|
||
void Destruct(TCppObject_t This, TCppScope_t scope, bool withFree /*=true*/) { | ||
void Destruct(TCppObject_t This, TCppScope_t scope, bool withFree /*=true*/, | ||
TCppIndex_t count /*=0UL*/) { |
There was a problem hiding this comment.
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]
(void*)~0); // Tell Invoke to use placement new.
^
No description provided.