From 9c3e6de627eb1c0c74a21b61485f35e546bea86e Mon Sep 17 00:00:00 2001 From: Andrew Adams Date: Mon, 23 Dec 2024 12:48:06 -0800 Subject: [PATCH] Fix #8534 (#8535) * Fix #8534 This needs to take src by value, because the helper function mutates ones of its members in-place. * Add comment --- src/runtime/HalideBuffer.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/runtime/HalideBuffer.h b/src/runtime/HalideBuffer.h index f854cf43c24f..9741c0278e3d 100644 --- a/src/runtime/HalideBuffer.h +++ b/src/runtime/HalideBuffer.h @@ -1991,9 +1991,11 @@ class Buffer { /** Make a buffer with the same shape and memory nesting order as * another buffer. It may have a different type. */ template - static Buffer make_with_shape_of(const Buffer &src, + static Buffer make_with_shape_of(Buffer src, void *(*allocate_fn)(size_t) = nullptr, void (*deallocate_fn)(void *) = nullptr) { + // Note that src is taken by value because its dims are mutated + // in-place by the helper. Do not change to taking it by reference. static_assert(Dims == D2 || Dims == AnyDims); const halide_type_t dst_type = T_is_void ? src.type() : halide_type_of::type>(); return Buffer<>::make_with_shape_of_helper(dst_type, src.dimensions(), src.buf.dim,