From e650a6094aa95a4d2b27eb66d8229452ca59ac5c Mon Sep 17 00:00:00 2001 From: liuneng <1398775315@qq.com> Date: Wed, 21 Jun 2023 20:20:37 +0800 Subject: [PATCH] fix core dump when compile expression --- src/DataTypes/Native.cpp | 6 ++++-- .../02790_fix_coredump_when_compile_expression.reference | 1 + .../02790_fix_coredump_when_compile_expression.sql | 4 ++++ 3 files changed, 9 insertions(+), 2 deletions(-) create mode 100644 tests/queries/0_stateless/02790_fix_coredump_when_compile_expression.reference create mode 100644 tests/queries/0_stateless/02790_fix_coredump_when_compile_expression.sql diff --git a/src/DataTypes/Native.cpp b/src/DataTypes/Native.cpp index 6f1ea851dce..9af50a180ea 100644 --- a/src/DataTypes/Native.cpp +++ b/src/DataTypes/Native.cpp @@ -123,9 +123,11 @@ llvm::Value * nativeCast(llvm::IRBuilderBase & b, const DataTypePtr & from_type, } else if (to_type->isNullable()) { - auto * from_native_type = toNativeType(b, from_type); + auto * to_native_type = toNativeType(b, to_type); auto * inner = nativeCast(b, from_type, value, removeNullable(to_type)); - return b.CreateInsertValue(llvm::Constant::getNullValue(from_native_type), inner, {0}); + auto * res_ptr = b.CreateAlloca(to_native_type); + auto * res_value = b.CreateLoad(to_native_type, res_ptr); + return b.CreateInsertValue(res_value, inner, {0}); } else { diff --git a/tests/queries/0_stateless/02790_fix_coredump_when_compile_expression.reference b/tests/queries/0_stateless/02790_fix_coredump_when_compile_expression.reference new file mode 100644 index 00000000000..b8626c4cff2 --- /dev/null +++ b/tests/queries/0_stateless/02790_fix_coredump_when_compile_expression.reference @@ -0,0 +1 @@ +4 diff --git a/tests/queries/0_stateless/02790_fix_coredump_when_compile_expression.sql b/tests/queries/0_stateless/02790_fix_coredump_when_compile_expression.sql new file mode 100644 index 00000000000..90995da0cca --- /dev/null +++ b/tests/queries/0_stateless/02790_fix_coredump_when_compile_expression.sql @@ -0,0 +1,4 @@ +CREATE TABLE test (col1 Nullable(DOUBLE), col2 Nullable(DOUBLE), col3 DOUBLE) ENGINE=Memory; + +insert into test values(1.0 , 2.0, 3.0); +select multiIf(col1 > 2, col2/col3, 4.0) from test SETTINGS min_count_to_compile_expression=0;