<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/61368>61368</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
blocks extension: support access to variably modified types in nested function
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
uecker
</td>
</tr>
</table>
<pre>
Unfortunately, clang does not support accessing variables with variably modified type of the enclosing function from a nested function. Consider the following code (from the BART toolbox) although there is no fundamental reason why this is not implemented. The workaround (see below) is to use a void* to the variably modified object, and cast it back in the nested function.
void ode_adjoint_sa_eval(int N, const float t[N + 1], int M,
int P, float dj[P],
const float x[N + 1][M], const float z[N + 1][M],
const float Adp[P][M][M])
{
void, (^eval)(float out[P], int i) =
^{
for (int p = 0; p < P; p++)
out[p] = adj_eval(M, x[i], z[i], Adp[p]);
};
quadrature_trapezoidal(N, t, P, dj, eval);
}
The workaround looks like this. The NESTED macro is unrelated but makes the code work with GCC's nested function and blocks. For GCC's nested function no workaround is needed.
void ode_adjoint_sa_eval(int N, const float t[N + 1], int M,
int P, float dj[P],
const float x[N + 1][M], const float z[N + 1][M],
const float Adp[P][M][M])
{
#ifdef __clang__
const void* x2 = x;
const void* z2 = z;
const void* Adp2 = Adp;
#endif
NESTED(void, eval, (float out[P], int i))
{
#ifdef __clang__
const float (*x)[M] = x2;
const float (*z)[M] = z2;
const float (*Adp)[M][M] = Adp2;
#endif
for (int p = 0; p < P; p++)
out[p] = adj_eval(M, x[i], z[i], Adp[p]);
};
quadrature_trapezoidal(N, t, P, dj, eval);
}
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzsVk1zqzYU_TXy5s7zEGGwWbDwR9zVe5Np07VHoItRLOtSScSJf31Hwk6IX9J205kuOuPBgM45ut9IOKf2BrFk2Yplm4nofUu27LE-oJ1UJF_L301D1vdGeNSvjK-h1sLsQRI6MOTB9V1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