From df4c981b0531ba5a98b2a4a19ad8a86a0d122ac4 Mon Sep 17 00:00:00 2001 From: Xuanda Yang Date: Thu, 27 Jul 2023 08:13:02 -0700 Subject: [PATCH] Throw an erorr if split is called with the same older and inner var name (#7715) * throw an erorr if split is called with the same older and inner name * update * fix naming * rewording * add test --------- Co-authored-by: Steven Johnson --- src/Func.cpp | 6 ++++++ test/error/CMakeLists.txt | 1 + test/error/split_same_var_names.cpp | 13 +++++++++++++ 3 files changed, 20 insertions(+) create mode 100644 test/error/split_same_var_names.cpp diff --git a/src/Func.cpp b/src/Func.cpp index cc5b8bb5979c..ffb53632f658 100644 --- a/src/Func.cpp +++ b/src/Func.cpp @@ -1010,6 +1010,12 @@ void Stage::split(const string &old, const string &outer, const string &inner, c definition.schedule().touched() = true; + user_assert(inner != outer) << "In schedule for " << name() + << ", can't split " << old << " into " + << outer << " and " << inner + << " because the new Vars have the same name.\n" + << dump_argument_list(); + // Check that the new names aren't already in the dims list. for (auto &dim : dims) { string new_names[2] = {inner, outer}; diff --git a/test/error/CMakeLists.txt b/test/error/CMakeLists.txt index 95243a757cfd..f217d19534f0 100644 --- a/test/error/CMakeLists.txt +++ b/test/error/CMakeLists.txt @@ -91,6 +91,7 @@ tests(GROUPS error specialize_fail.cpp split_inner_wrong_tail_strategy.cpp split_non_innermost_predicated.cpp + split_same_var_names.cpp thread_id_outside_block_id.cpp too_many_args.cpp tuple_arg_select_undef.cpp diff --git a/test/error/split_same_var_names.cpp b/test/error/split_same_var_names.cpp new file mode 100644 index 000000000000..966427c471e4 --- /dev/null +++ b/test/error/split_same_var_names.cpp @@ -0,0 +1,13 @@ +#include "Halide.h" + +using namespace Halide; + +int main(int argc, char **argv) { + Var x; + Func f; + f(x) = x; + f.split(x, x, x, 16, TailStrategy::RoundUp); + + printf("Success!\n"); + return 0; +}