Skip to content

Commit 3f31c06

Browse files
rascaniRJ Ascani
andauthored
Explicitly construct Span<EValue*> from EValue*[] in tests (#16520)
### Summary GCC exhibits inconsistent behavior where it applies array-to-pointer decay when calling through function pointers, but not for direct function calls, even though both should invoke the same conversion to the parameter type. Minimal reproduction: template <int N> struct S { S(int (&)[N]) {} }; void f(S<3>) {} int main() { int a[3]; f(a); // OK on both GCC and Clang (&f)(a); // OK on Clang, ERROR on GCC } A similar issue is tracked at: [GCC Bugzilla 114812](https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114812) In ExecuTorch, OpFunction is defined as: using OpFunction = void (*)(KernelRuntimeContext&, Span<EValue*>); When tests call `(*func)(context, stack)` where `stack` is an `EValue*[]` array, GCC decays it to `EValue**` before considering Span's array constructor `template<size_t N> Span(T (&)[N])`, causing compilation to fail. This PR updates call sites to work around this issue by explicitly constructing the Span. An alternative option would be to convert the C arrays to std::arrays, which would not be subject to array to pointer decay. ### Test plan ``` # Using GCC 11.5 ./test/run_oss_cpp_tests.sh ``` Co-authored-by: RJ Ascani <[email protected]>
1 parent 13e7377 commit 3f31c06

File tree

4 files changed

+117
-73
lines changed

4 files changed

+117
-73
lines changed

extension/kernel_util/test/make_boxed_from_unboxed_functor_test.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ using executorch::runtime::EValue;
2525
using executorch::runtime::get_op_function_from_registry;
2626
using executorch::runtime::KernelRuntimeContext;
2727
using executorch::runtime::registry_has_op_function;
28+
using executorch::runtime::Span;
2829
using std::optional;
2930

3031
Tensor& my_op_out(KernelRuntimeContext& ctx, const Tensor& a, Tensor& out) {
@@ -117,7 +118,7 @@ TEST_F(MakeBoxedFromUnboxedFunctorTest, UnboxLogicWorks) {
117118
EValue* stack[1];
118119
stack[0] = &values[0];
119120

120-
(*fn)(context, stack);
121+
(*fn)(context, Span<EValue*>(stack));
121122

122123
// check result
123124
EXPECT_EQ(a.const_data_ptr<int32_t>()[0], 1);
@@ -144,7 +145,7 @@ TEST_F(MakeBoxedFromUnboxedFunctorTest, UnboxArrayRef) {
144145
KernelRuntimeContext context;
145146
EValue values[2] = {boxed_array_ref, out};
146147
EValue* stack[2] = {&values[0], &values[1]};
147-
(*fn)(context, stack);
148+
(*fn)(context, Span<EValue*>(stack));
148149

149150
// check result.
150151
for (int i = 0; i < 5; i++) {
@@ -170,7 +171,7 @@ TEST_F(MakeBoxedFromUnboxedFunctorTest, UnboxOptional) {
170171
KernelRuntimeContext context;
171172
EValue values[3] = {scalar, scalar_none, out};
172173
EValue* stack[3] = {&values[0], &values[1], &values[2]};
173-
(*fn)(context, stack);
174+
(*fn)(context, Span<EValue*>(stack));
174175

175176
// check result.
176177
EXPECT_EQ(stack[2]->toTensor().const_data_ptr<int32_t>()[0], 4);
@@ -197,7 +198,7 @@ TEST_F(MakeBoxedFromUnboxedFunctorTest, UnboxOptionalArrayRef) {
197198
KernelRuntimeContext context;
198199
EValue values[2] = {boxed_array_ref, out};
199200
EValue* stack[2] = {&values[0], &values[1]};
200-
(*fn)(context, stack);
201+
(*fn)(context, Span<EValue*>(stack));
201202

202203
// check result.
203204
for (int i = 0; i < 5; i++) {

0 commit comments

Comments
 (0)