From 5dbdd8ea3d71719465b1d3757396246219c112bc Mon Sep 17 00:00:00 2001 From: Alexey Milovidov Date: Wed, 26 Aug 2020 19:49:19 +0300 Subject: [PATCH] More range checks when compile_expressions = 1 --- src/Functions/FunctionBinaryArithmetic.h | 5 +++++ src/Functions/FunctionUnaryArithmetic.h | 5 +++++ src/Functions/FunctionsComparison.h | 5 +++++ src/Functions/FunctionsLogical.h | 2 ++ 4 files changed, 17 insertions(+) diff --git a/src/Functions/FunctionBinaryArithmetic.h b/src/Functions/FunctionBinaryArithmetic.h index 47597594f33..241f7b2fae0 100644 --- a/src/Functions/FunctionBinaryArithmetic.h +++ b/src/Functions/FunctionBinaryArithmetic.h @@ -1209,6 +1209,9 @@ public: #if USE_EMBEDDED_COMPILER bool isCompilableImpl(const DataTypes & arguments) const override { + if (2 != arguments.size()) + return false; + return castBothTypes(arguments[0].get(), arguments[1].get(), [&](const auto & left, const auto & right) { using LeftDataType = std::decay_t; @@ -1226,6 +1229,8 @@ public: llvm::Value * compileImpl(llvm::IRBuilderBase & builder, const DataTypes & types, ValuePlaceholders values) const override { + assert(2 == types.size() && 2 == values.size()); + llvm::Value * result = nullptr; castBothTypes(types[0].get(), types[1].get(), [&](const auto & left, const auto & right) { diff --git a/src/Functions/FunctionUnaryArithmetic.h b/src/Functions/FunctionUnaryArithmetic.h index 963313c7ded..5b072e5848a 100644 --- a/src/Functions/FunctionUnaryArithmetic.h +++ b/src/Functions/FunctionUnaryArithmetic.h @@ -216,6 +216,9 @@ public: #if USE_EMBEDDED_COMPILER bool isCompilableImpl(const DataTypes & arguments) const override { + if (1 != arguments.size()) + return false; + return castType(arguments[0].get(), [&](const auto & type) { using DataType = std::decay_t; @@ -228,6 +231,8 @@ public: llvm::Value * compileImpl(llvm::IRBuilderBase & builder, const DataTypes & types, ValuePlaceholders values) const override { + assert(1 == types.size() && 1 == values.size()); + llvm::Value * result = nullptr; castType(types[0].get(), [&](const auto & type) { diff --git a/src/Functions/FunctionsComparison.h b/src/Functions/FunctionsComparison.h index 9b0d6e76924..07455f94568 100644 --- a/src/Functions/FunctionsComparison.h +++ b/src/Functions/FunctionsComparison.h @@ -1272,6 +1272,9 @@ public: #if USE_EMBEDDED_COMPILER bool isCompilableImpl(const DataTypes & types) const override { + if (2 != types.size()) + return false; + auto isBigInteger = &typeIsEither; auto isFloatingPoint = &typeIsEither; if ((isBigInteger(*types[0]) && isFloatingPoint(*types[1])) @@ -1284,6 +1287,8 @@ public: llvm::Value * compileImpl(llvm::IRBuilderBase & builder, const DataTypes & types, ValuePlaceholders values) const override { + assert(2 == types.size() && 2 == values.size()); + auto & b = static_cast &>(builder); auto * x = values[0](); auto * y = values[1](); diff --git a/src/Functions/FunctionsLogical.h b/src/Functions/FunctionsLogical.h index a8809dc3467..474831b0b6d 100644 --- a/src/Functions/FunctionsLogical.h +++ b/src/Functions/FunctionsLogical.h @@ -161,6 +161,8 @@ public: llvm::Value * compileImpl(llvm::IRBuilderBase & builder, const DataTypes & types, ValuePlaceholders values) const override { + assert(!types.empty() && !values.empty()); + auto & b = static_cast &>(builder); if constexpr (!Impl::isSaturable()) {