Skip to content

Commit 371dff5

Browse files
committed
make_dtor_wrapper indicates if codegen fails, add negative case tests
1 parent ff46291 commit 371dff5

File tree

2 files changed

+22
-8
lines changed

2 files changed

+22
-8
lines changed

lib/CppInterOp/CppInterOp.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2986,17 +2986,17 @@ static JitCall::DestructorCall make_dtor_wrapper(compat::Interpreter& interp,
29862986
//
29872987
void* F = compile_wrapper(interp, wrapper_name, wrapper,
29882988
/*withAccessControl=*/false);
2989+
LLVM_DEBUG(dbgs() << "Compiled '" << (F ? "" : "un") << "successfully:\n"
2990+
<< wrapper << "'\n");
29892991
if (F) {
29902992
gDtorWrapperStore.insert(make_pair(D, F));
2991-
} else {
2992-
llvm::errs() << "make_dtor_wrapper"
2993-
<< "Failed to compile\n"
2994-
<< "==== SOURCE BEGIN ====\n"
2995-
<< wrapper << "\n ==== SOURCE END ====";
2993+
return (JitCall::DestructorCall)F;
29962994
}
2997-
LLVM_DEBUG(dbgs() << "Compiled '" << (F ? "" : "un") << "successfully:\n"
2998-
<< wrapper << "'\n");
2999-
return (JitCall::DestructorCall)F;
2995+
llvm::errs() << "make_dtor_wrapper"
2996+
<< "Failed to compile\n"
2997+
<< "==== SOURCE BEGIN ====\n"
2998+
<< wrapper << "\n ==== SOURCE END ====";
2999+
return (JitCall::DestructorCall) nullptr;
30003000
}
30013001
#undef DEBUG_TYPE
30023002
} // namespace

unittests/CppInterOp/FunctionReflectionTest.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2406,6 +2406,20 @@ TEST(FunctionReflectionTest, Destruct) {
24062406
// Clean up resources
24072407
clang_Interpreter_takeInterpreterAsPtr(I);
24082408
clang_Interpreter_dispose(I);
2409+
2410+
// Failure test, this wrapper should not compile since we explicitly delete
2411+
// the destructor
2412+
Interp->declare(R"(
2413+
class D {
2414+
public:
2415+
D() {}
2416+
~D() = delete;
2417+
};
2418+
)");
2419+
2420+
scope = Cpp::GetNamed("D");
2421+
object = Cpp::Construct(scope);
2422+
EXPECT_FALSE(Cpp::Destruct(object, scope));
24092423
}
24102424

24112425
TEST(FunctionReflectionTest, DestructArray) {

0 commit comments

Comments
 (0)