Skip to content

Commit 8c0c440

Browse files
committed
Add extra diagnostics in JitCall::AreArgumentsValid
This catches 0 objects to construct/destruct and attempting array new with requried initialization parameters
1 parent db8bbff commit 8c0c440

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

include/CppInterOp/CppInterOp.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ class JitCall {
140140
: m_DestructorCall(C), m_Kind(K), m_FD(Dtor) {}
141141

142142
/// Checks if the passed arguments are valid for the given function.
143-
CPPINTEROP_API bool AreArgumentsValid(void* result, ArgList args,
144-
void* self) const;
143+
CPPINTEROP_API bool AreArgumentsValid(void* result, ArgList args, void* self,
144+
size_t nary = 1UL) const;
145145

146146
/// This function is used for debugging, it reports when the function was
147147
/// called.

lib/CppInterOp/CppInterOp.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ static clang::Sema& getSema() { return getInterp().getCI()->getSema(); }
132132
static clang::ASTContext& getASTContext() { return getSema().getASTContext(); }
133133

134134
#define DEBUG_TYPE "jitcall"
135-
bool JitCall::AreArgumentsValid(void* result, ArgList args, void* self) const {
135+
bool JitCall::AreArgumentsValid(void* result, ArgList args, void* self,
136+
size_t nary) const {
136137
bool Valid = true;
137138
if (Cpp::IsConstructor(m_FD)) {
138139
assert(result && "Must pass the location of the created object!");
@@ -156,6 +157,18 @@ bool JitCall::AreArgumentsValid(void* result, ArgList args, void* self) const {
156157
assert(0 && "We are discarding the return type of the function!");
157158
Valid = false;
158159
}
160+
if (Cpp::IsConstructor(m_FD) || Cpp::IsDestructor(m_FD))
161+
assert(nary > 0 &&
162+
"Number of objects to construct/destruct should be atleast 1");
163+
164+
if (Cpp::IsConstructor(m_FD)) {
165+
const auto* CD = cast<CXXConstructorDecl>((const Decl*)m_FD);
166+
if (CD->getMinRequiredArguments() != 0 && nary > 1) {
167+
assert(0 &&
168+
"Cannot pass initialization parameters to array new construction");
169+
Valid = false;
170+
}
171+
}
159172
assert(m_Kind != kDestructorCall && "Wrong overload!");
160173
Valid &= m_Kind != kDestructorCall;
161174
return Valid;

0 commit comments

Comments
 (0)