Skip to content

Commit f1c4d31

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 22e4c0c commit f1c4d31

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) 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
@@ -134,7 +134,8 @@ static clang::Sema& getSema() { return getInterp().getCI()->getSema(); }
134134
static clang::ASTContext& getASTContext() { return getSema().getASTContext(); }
135135

136136
#define DEBUG_TYPE "jitcall"
137-
bool JitCall::AreArgumentsValid(void* result, ArgList args, void* self) const {
137+
bool JitCall::AreArgumentsValid(void* result, ArgList args, void* self,
138+
size_t nary) const {
138139
bool Valid = true;
139140
if (Cpp::IsConstructor(m_FD)) {
140141
assert(result && "Must pass the location of the created object!");
@@ -158,6 +159,18 @@ bool JitCall::AreArgumentsValid(void* result, ArgList args, void* self) const {
158159
assert(0 && "We are discarding the return type of the function!");
159160
Valid = false;
160161
}
162+
if (Cpp::IsConstructor(m_FD) && nary == 0UL) {
163+
assert(0 && "Number of objects to construct should be atleast 1");
164+
Valid = false;
165+
}
166+
if (Cpp::IsConstructor(m_FD)) {
167+
const auto* CD = cast<CXXConstructorDecl>((const Decl*)m_FD);
168+
if (CD->getMinRequiredArguments() != 0 && nary > 1) {
169+
assert(0 &&
170+
"Cannot pass initialization parameters to array new construction");
171+
Valid = false;
172+
}
173+
}
161174
assert(m_Kind != kDestructorCall && "Wrong overload!");
162175
Valid &= m_Kind != kDestructorCall;
163176
return Valid;

0 commit comments

Comments
 (0)