diff options
author | Richard Biener <rguenther@suse.de> | 2021-09-16 11:19:14 +0200 |
---|---|---|
committer | Richard Biener <rguenther@suse.de> | 2021-09-16 13:22:50 +0200 |
commit | 8d6b12b2233dabf3573383a15ccc67fdb925e5b3 (patch) | |
tree | b0c07d6519e9b9d8a76d1ed8bd50ac99cb605a4f | |
parent | 275a076f762daaf0e1d6148a1da1d7222f1aea9f (diff) | |
download | gcc-8d6b12b2233dabf3573383a15ccc67fdb925e5b3.zip gcc-8d6b12b2233dabf3573383a15ccc67fdb925e5b3.tar.gz gcc-8d6b12b2233dabf3573383a15ccc67fdb925e5b3.tar.bz2 |
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 <rguenther@suse.de>
PR middle-end/102360
* internal-fn.c (expand_DEFERRED_INIT): Make pattern-init
of non-memory more robust.
* g++.dg/pr102360.C: New testcase.
-rw-r--r-- | gcc/internal-fn.c | 25 | ||||
-rw-r--r-- | gcc/testsuite/g++.dg/pr102360.C | 54 |
2 files changed, 64 insertions, 15 deletions
diff --git a/gcc/internal-fn.c b/gcc/internal-fn.c index b1283690..8312d08 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 0000000..fdf9e08 --- /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 <typename _Tp, int m, int n> 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 <typename _Tp, int m, int n> 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 <typename _Tp, int m, int n> +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 <typename _Tp, int m, int n, int nm> + 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 <typename _Tp, int m, int n, int nm> +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<double, 4, 4> b, c, e; + B<double, 4, 1> d; + F::compute(b, d, c, e); +} |