From 6f2a85cece5c31fe01881446a9bdda7fd0971ec1 Mon Sep 17 00:00:00 2001 From: Andrew Adams Date: Fri, 20 Dec 2024 12:08:03 -0800 Subject: [PATCH 1/2] Fix #8534 This needs to take src by value, because the helper function mutates ones of its members in-place. --- src/runtime/HalideBuffer.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/runtime/HalideBuffer.h b/src/runtime/HalideBuffer.h index f854cf43c24f..7dca3022cd3e 100644 --- a/src/runtime/HalideBuffer.h +++ b/src/runtime/HalideBuffer.h @@ -1991,7 +1991,7 @@ 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) { static_assert(Dims == D2 || Dims == AnyDims); From 7a9be6f06c0894f768c04d1e33d9600e39e1b6fc Mon Sep 17 00:00:00 2001 From: Andrew Adams Date: Fri, 20 Dec 2024 12:09:26 -0800 Subject: [PATCH 2/2] Add comment --- src/runtime/HalideBuffer.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/runtime/HalideBuffer.h b/src/runtime/HalideBuffer.h index 7dca3022cd3e..9741c0278e3d 100644 --- a/src/runtime/HalideBuffer.h +++ b/src/runtime/HalideBuffer.h @@ -1994,6 +1994,8 @@ class Buffer { 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,