提交 d2ba88a9 编写于 作者: S Shreedhar Hardikar

Fix codegen unittests using DatumCastGenerator

The lifetime of double pointer passed to BaseCodegen must be strictly
longer than that of the CodegenManager in which it is enrolled. Using
a local variable can thus cause a SIGSEGV.
Signed-off-by: NKarthikeyan Jambu Rajaraman <karthi.jrk@gmail.com>
上级 c419f07f
......@@ -242,16 +242,17 @@ class DatumToCppCastGenerator :
public:
explicit DatumToCppCastGenerator(
gpcodegen::CodegenManager* manager,
DatumCastTemplateFn regular_func_ptr,
DatumCastTemplateFn* ptr_to_regular_func_ptr):
BaseCodegen<DatumCastTemplateFn>(manager,
DatumCastTemplateFn regular_func_ptr)
: BaseCodegen<DatumCastTemplateFn>(manager,
kDatumToCppCastFuncNamePrefix,
regular_func_ptr,
ptr_to_regular_func_ptr) {
&swappable_function_holder) {
}
virtual ~DatumToCppCastGenerator() = default;
DatumCastTemplateFn swappable_function_holder;
protected:
bool GenerateCodeInternal(gpcodegen::GpCodegenUtils* codegen_utils) final {
llvm::Function* cast_func
......@@ -279,16 +280,17 @@ class CppToDatumCastGenerator :
public:
explicit CppToDatumCastGenerator(
gpcodegen::CodegenManager* manager,
DatumCastTemplateFn regular_func_ptr,
DatumCastTemplateFn* ptr_to_regular_func_ptr):
BaseCodegen<DatumCastTemplateFn>(manager,
DatumCastTemplateFn regular_func_ptr)
: BaseCodegen<DatumCastTemplateFn>(manager,
kCppToDatumCastFuncNamePrefix,
regular_func_ptr,
ptr_to_regular_func_ptr) {
&swappable_function_holder) {
}
virtual ~CppToDatumCastGenerator() = default;
DatumCastTemplateFn swappable_function_holder;
protected:
bool GenerateCodeInternal(gpcodegen::GpCodegenUtils* codegen_utils) final {
llvm::Function* cast_func
......@@ -354,16 +356,18 @@ class CodegenManagerTest : public ::testing::Test {
void CheckDatumCast(DatumCastFn<Datum, CppType> CppToDatumReg,
DatumCastFn<CppType, Datum> DatumToCppReg,
const std::vector<CppType>& values) {
DatumCastFn<Datum, CppType> CppToDatumCgFn = CppToDatumReg;
CppToDatumCastGenerator<CppType>* cpp_datum_gen =
new CppToDatumCastGenerator<CppType>(
manager_.get(), CppToDatumReg, &CppToDatumCgFn);
manager_.get(), CppToDatumReg);
DatumCastFn<Datum, CppType>& CppToDatumCgFn =
cpp_datum_gen->swappable_function_holder;
DatumCastFn<CppType, Datum> DatumToCppCgFn = DatumToCppReg;
DatumToCppCastGenerator<CppType>* datum_cpp_gen =
new DatumToCppCastGenerator<CppType>(
manager_.get(), DatumToCppReg, &DatumToCppCgFn);
manager_.get(), DatumToCppReg);
DatumCastFn<CppType, Datum>& DatumToCppCgFn =
datum_cpp_gen->swappable_function_holder;
ASSERT_TRUE(manager_->EnrollCodeGenerator(
CodegenFuncLifespan_Parameter_Invariant, cpp_datum_gen));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册