public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-3578] middle-end/102360 - adjust .DEFERRED_INIT expansion
@ 2021-09-16 11:23 Richard Biener
0 siblings, 0 replies; only message in thread
From: Richard Biener @ 2021-09-16 11:23 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:8d6b12b2233dabf3573383a15ccc67fdb925e5b3
commit r12-3578-g8d6b12b2233dabf3573383a15ccc67fdb925e5b3
Author: Richard Biener <rguenther@suse.de>
Date: Thu Sep 16 11:19:14 2021 +0200
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.
Diff:
---
gcc/internal-fn.c | 25 ++++++++-----------
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 b1283690080..8312d08aab2 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 00000000000..fdf9e08b283
--- /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);
+}
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-09-16 11:23 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-16 11:23 [gcc r12-3578] middle-end/102360 - adjust .DEFERRED_INIT expansion Richard Biener
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).