Skip to content

Commit 822a38a

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 98a75fe commit 822a38a

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

102102
#define DEBUG_TYPE "jitcall"
103-
bool JitCall::AreArgumentsValid(void* result, ArgList args, void* self) const {
103+
bool JitCall::AreArgumentsValid(void* result, ArgList args, void* self,
104+
size_t nary) const {
104105
bool Valid = true;
105106
if (Cpp::IsConstructor(m_FD)) {
106107
assert(result && "Must pass the location of the created object!");
@@ -124,6 +125,18 @@ bool JitCall::AreArgumentsValid(void* result, ArgList args, void* self) const {
124125
assert(0 && "We are discarding the return type of the function!");
125126
Valid = false;
126127
}
128+
if (Cpp::IsConstructor(m_FD) || Cpp::IsDestructor(m_FD))
129+
assert(nary > 0 &&
130+
"Number of objects to construct/destruct should be atleast 1");
131+
132+
if (Cpp::IsConstructor(m_FD)) {
133+
const auto* CD = cast<CXXConstructorDecl>((const Decl*)m_FD);
134+
if (CD->getMinRequiredArguments() != 0 && nary > 1) {
135+
assert(0 &&
136+
"Cannot pass initialization parameters to array new construction");
137+
Valid = false;
138+
}
139+
}
127140
assert(m_Kind != kDestructorCall && "Wrong overload!");
128141
Valid &= m_Kind != kDestructorCall;
129142
return Valid;

0 commit comments

Comments
 (0)