Joel Stanley | 72b0246 | 2018-06-27 14:40:11 +0930 | [diff] [blame] | 1 | From 8c014bceeca6a558519e86b16a8142accc41e94f Mon Sep 17 00:00:00 2001 |
| 2 | From: jason <jason@138bc75d-0d04-0410-961f-82ee72b054a4> |
| 3 | Date: Thu, 28 Jun 2018 00:25:21 +0000 |
| 4 | Subject: [PATCH] PR c++/80290 - memory-hog with std::pair. |
| 5 | |
| 6 | * pt.c (type_unification_real): Skip non-dependent conversion |
| 7 | check for a nested list argument. |
| 8 | (braced_init_depth): New. |
| 9 | |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 10 | Upstream-Status: Backport |
Joel Stanley | 72b0246 | 2018-06-27 14:40:11 +0930 | [diff] [blame] | 11 | Signed-off-by: Joel Stanley <joel@jms.id.au> |
| 12 | --- |
| 13 | gcc/cp/pt.c | 22 ++++++++++++++++++++++ |
| 14 | 1 file changed, 22 insertions(+) |
| 15 | |
| 16 | diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c |
| 17 | index 79cfd0129226..71077a3b0498 100644 |
| 18 | --- a/gcc/cp/pt.c |
| 19 | +++ b/gcc/cp/pt.c |
| 20 | @@ -19242,6 +19242,24 @@ try_array_deduction (tree tparms, tree targs, tree parm) |
| 21 | /*nondeduced*/false, array_deduction_r); |
| 22 | } |
| 23 | |
| 24 | +/* Returns how many levels of { } INIT contains. */ |
| 25 | + |
| 26 | +static int |
| 27 | +braced_init_depth (tree init) |
| 28 | +{ |
| 29 | + if (!init || !BRACE_ENCLOSED_INITIALIZER_P (init)) |
| 30 | + return 0; |
| 31 | + unsigned i; tree val; |
| 32 | + unsigned max = 0; |
| 33 | + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (init), i, val) |
| 34 | + { |
| 35 | + unsigned elt_d = braced_init_depth (val); |
| 36 | + if (elt_d > max) |
| 37 | + max = elt_d; |
| 38 | + } |
| 39 | + return max + 1; |
| 40 | +} |
| 41 | + |
| 42 | /* Most parms like fn_type_unification. |
| 43 | |
| 44 | If SUBR is 1, we're being called recursively (to unify the |
| 45 | @@ -19478,6 +19496,10 @@ type_unification_real (tree tparms, |
| 46 | |
| 47 | if (uses_template_parms (parm)) |
| 48 | continue; |
| 49 | + /* Workaround for c++/80290: avoid combinatorial explosion on |
| 50 | + deeply nested braced init-lists. */ |
| 51 | + if (braced_init_depth (arg) > 2) |
| 52 | + continue; |
| 53 | if (check_non_deducible_conversion (parm, arg, strict, flags, |
| 54 | explain_p)) |
| 55 | return 1; |
| 56 | -- |
| 57 | 2.17.1 |
| 58 | |