Commit 3f31c06
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- extension/kernel_util/test
- kernels/prim_ops/test
- runtime
- executor/test
- kernel/test
4 files changed
+117
-73
lines changedLines changed: 5 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
25 | 25 | | |
26 | 26 | | |
27 | 27 | | |
| 28 | + | |
28 | 29 | | |
29 | 30 | | |
30 | 31 | | |
| |||
117 | 118 | | |
118 | 119 | | |
119 | 120 | | |
120 | | - | |
| 121 | + | |
121 | 122 | | |
122 | 123 | | |
123 | 124 | | |
| |||
144 | 145 | | |
145 | 146 | | |
146 | 147 | | |
147 | | - | |
| 148 | + | |
148 | 149 | | |
149 | 150 | | |
150 | 151 | | |
| |||
170 | 171 | | |
171 | 172 | | |
172 | 173 | | |
173 | | - | |
| 174 | + | |
174 | 175 | | |
175 | 176 | | |
176 | 177 | | |
| |||
197 | 198 | | |
198 | 199 | | |
199 | 200 | | |
200 | | - | |
| 201 | + | |
201 | 202 | | |
202 | 203 | | |
203 | 204 | | |
| |||
0 commit comments