From 8d6b12b2233dabf3573383a15ccc67fdb925e5b3 Mon Sep 17 00:00:00 2001 From: Richard Biener Date: Thu, 16 Sep 2021 11:19:14 +0200 Subject: [PATCH] middle-end/102360 - adjust .DEFERRED_INIT expansion This avoids using native_interpret_type when we cannot do it with the original type of the variable, instead use an integer type for the initialization and side-step the size limitation of native_interpret_int. 2021-09-16 Richard Biener PR middle-end/102360 * internal-fn.c (expand_DEFERRED_INIT): Make pattern-init of non-memory more robust. * g++.dg/pr102360.C: New testcase. --- gcc/internal-fn.c | 25 ++++++--------- gcc/testsuite/g++.dg/pr102360.C | 54 +++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 15 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr102360.C diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index b1283690080a..8312d08aab2a 100644 --- a/gcc/internal-fn.c +++ b/gcc/internal-fn.c @@ -3045,23 +3045,18 @@ expand_DEFERRED_INIT (internal_fn, gcall *stmt) if (init_type == AUTO_INIT_PATTERN) { - tree alt_type = NULL_TREE; - if (!can_native_interpret_type_p (var_type)) - { - alt_type - = lang_hooks.types.type_for_mode (TYPE_MODE (var_type), - TYPE_UNSIGNED (var_type)); - gcc_assert (can_native_interpret_type_p (alt_type)); - } - unsigned char *buf = (unsigned char *) xmalloc (total_bytes); memset (buf, INIT_PATTERN_VALUE, total_bytes); - init = native_interpret_expr (alt_type ? alt_type : var_type, - buf, total_bytes); - gcc_assert (init); - - if (alt_type) - init = build1 (VIEW_CONVERT_EXPR, var_type, init); + if (can_native_interpret_type_p (var_type)) + init = native_interpret_expr (var_type, buf, total_bytes); + else + { + tree itype = build_nonstandard_integer_type + (total_bytes * BITS_PER_UNIT, 1); + wide_int w = wi::from_buffer (buf, total_bytes); + init = build1 (VIEW_CONVERT_EXPR, var_type, + wide_int_to_tree (itype, w)); + } } expand_assignment (lhs, init, false); diff --git a/gcc/testsuite/g++.dg/pr102360.C b/gcc/testsuite/g++.dg/pr102360.C new file mode 100644 index 000000000000..fdf9e08b283b --- /dev/null +++ b/gcc/testsuite/g++.dg/pr102360.C @@ -0,0 +1,54 @@ +// { dg-do compile } +// { dg-options "-fno-tree-dse -O1 -ftrivial-auto-var-init=pattern" } + +class A; +template class B { +public: + _Tp val[m * n]; +}; +class C { +public: + C(A); +}; +struct D { + D(); + unsigned long &operator[](int); + unsigned long *p; +}; +class A { +public: + template A(const B<_Tp, m, n> &, bool); + int rows, cols; + unsigned char *data; + unsigned char *datastart; + unsigned char *dataend; + unsigned char *datalimit; + D step; +}; +template +A::A(const B<_Tp, m, n> &p1, bool) + : rows(m), cols(n) { + step[0] = cols * sizeof(_Tp); + datastart = data = (unsigned char *)p1.val; + datalimit = dataend = datastart + rows * step[0]; +} +class F { +public: + static void compute(C); + template + static void compute(const B<_Tp, m, n> &, B<_Tp, nm, 1> &, B<_Tp, m, nm> &, + B<_Tp, n, nm> &); +}; +D::D() {} +unsigned long &D::operator[](int p1) { return p[p1]; } +template +void F::compute(const B<_Tp, m, n> &, B<_Tp, nm, 1> &, B<_Tp, m, nm> &, + B<_Tp, n, nm> &p4) { + A a(p4, false); + compute(a); +} +void fn1() { + B b, c, e; + B d; + F::compute(b, d, c, e); +} -- 2.47.2