https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105769
--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Using last night's trunk, it is:
#include <iostream>
#include <iomanip>
#include <functional>
template<size_t n, class T>
struct vec {
T dat[n];
vec() {}
explicit vec(const T& x) { for(size_t i = 0; i < n; i++) dat[i] = x; }
T& operator [](size_t i) { return dat[i]; }
const T& operator [](size_t i) const { return dat[i]; }
};
template<size_t m, size_t n, class T>
using mat = vec<m, vec<n, T>>;
template<size_t n, class T>
using sq_mat = mat<n, n, T>;
using map_t = std::function<size_t(size_t)>;
template<class T_v>
using est_t = std::function<T_v(map_t map)>; template<class T_v> using est2_t =
std::function<T_v(map_t map)>;
map_t id_map() { return [](size_t j) -> size_t { return j; }; }
template<size_t n, class T>
est2_t<void> jacknife(const est_t<vec<n, T>> est, sq_mat<n, T>& cov, vec<n, T>&
bias) {
return [est, &cov, &bias](map_t map) -> void { bias = est(map); for(size_t i
= 0; i < n; i++) std::cout << bias[i] << std::endl; };
}
template<class T>
void print_cov_ratio() {
sq_mat<2, T> cov_jn;
vec<2, T> bias;
jacknife<2, T>([](map_t map) -> vec<2, T> { vec<2, T> retv; retv[0] = 1;
retv[1] = 1; return retv; }, cov_jn, bias)(id_map());
}
struct ab {
long long unsigned a;
short unsigned b;
double operator()() { return a; }
ab& operator=(double rhs) { a = rhs; return *this; }
friend std::ostream& operator<<(std::ostream&, const ab&);
};
std::ostream& operator<<(std::ostream& os, const ab& x) { os << x.a; return os;
}
int main() {
std::cout << "will do (ab)" << std::endl;
print_cov_ratio<ab>();
return 0;
}
Partition 4: size 64 align 16
cov_jn
Partition 0: size 48 align 16
D.5698 bias D.5681
Partition 1: size 32 align 16
D.5683
Partition 2: size 32 align 16
D.5682
where
struct struct void D.5698;
struct est2_t D.5683;
struct est_t D.5682;
struct map_t D.5681;
struct sq_mat cov_jn;
struct vec bias;
aka D.5682 is the est argument slot - const est_t<vec<n, T>> est, D.5683 is the
return slot from jacknife est2_t<void>, D.5698 is the lambda object which
contains __est, __cov, __bias and cov_jn and bias the automatic variables in
print_cov_ratio and
D.5681 return value slot of id_map.
main in ltrans optimized dump is mostly serial code with some EH edges, except
for one
_M_manager == nullptr check (if nullptr it throws bad function call, otherwise
continues).
Now, those vars are referenced in:
_12 = (long unsigned int) &bias;
_15 = (long unsigned int) &cov_jn;
_21 = {_15, _12};
...
MEM[(struct vec *)&cov_jn] ={v} {CLOBBER};
bias ={v} {CLOBBER};
MEM[(struct function *)&D.5682] ={v} {CLOBBER};
MEM <char[16]> [(struct _Function_base *)&D.5682] = {};
MEM <vector(2) long unsigned int> [(bool (*<T72d>) (union _Any_data &
{ref-all}, const union _Any_data & {ref-all}, _Manager_operation) *)&D.5682 +
16B] = _8;
__ct_comp (&D.5698.__est, &D.5682);
...
MEM <vector(2) long unsigned int> [(void *)&D.5698 + 32B] = _21;
MEM[(struct function *)&D.5683] ={v} {CLOBBER};
MEM[(struct function *)&D.5683].D.5217 = {};
MEM[(struct function *)&D.5683]._M_invoker = 0B;
...
_14 = &MEM[(struct struct void *)_13].__est;
__ct_comp (_14, &D.5698.__est);
...
MEM[(struct struct void * &)&D.5683] = _13;
MEM <vector(2) long unsigned int> [(bool (*<T72d>) (union _Any_data &
{ref-all}, const union _Any_data & {ref-all}, _Manager_operation) *)&D.5683 +
16B] = _7;
__dt_base (&MEM[(struct function *)&D.5698].D.5235);
D.5698 ={v} {CLOBBER};
D.5698 ={v} {CLOBBER(eol)};
MEM <char[16]> [(struct _Function_base *)&D.5681] = {};
MEM <vector(2) long unsigned int> [(bool (*<T72d>) (union _Any_data &
{ref-all}, const union _Any_data & {ref-all}, _Manager_operation) *)&D.5681 +
16B] = _84;
_18 = MEM[(const struct _Function_base *)&D.5683]._M_manager;
...
_19 = D.5683._M_invoker;
_19 (&D.5683.D.5217._M_functor, &D.5681);
...
__dt_base (&D.5681.D.5223);
D.5681 ={v} {CLOBBER};
D.5681 ={v} {CLOBBER(eol)};
__dt_base (&D.5683.D.5217);
D.5683 ={v} {CLOBBER};
__dt_base (&D.5682.D.5235);
D.5682 ={v} {CLOBBER};
D.5682 ={v} {CLOBBER(eol)};
D.5683 ={v} {CLOBBER(eol)};
cov_jn ={v} {CLOBBER(eol)};
bias ={v} {CLOBBER(eol)};
return 0;
and some EH stuff.