From 86e95f35c522136ee6ec8b648b2fd415360774bc Mon Sep 17 00:00:00 2001 From: =?utf8?q?P=C3=A1draig=20Brady?= Date: Wed, 5 Sep 2018 09:59:08 +0000 Subject: [PATCH] [PR c++/87185] ICE in prune-lambdas https://gcc.gnu.org/ml/gcc-patches/2018-09/msg00249.html cp/ PR c++/87185 * lambda.c (prune_lambda_captures): Protect against const_vars.get returning NULL. testsuite/ PR c++/87185 * g++.dg/pr87185.C: New. From-SVN: r264118 --- gcc/cp/ChangeLog | 6 ++++++ gcc/cp/lambda.c | 6 +++--- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/pr87185.C | 4 ++++ 4 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr87185.C diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 3fbfe18..498b1fa 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2018-09-05 Pádraig Brady p@draigbrady.com + + PR c++/87185 + * lambda.c (prune_lambda_captures): Protect against const_vars.get + returning NULL. + 2018-09-04 Marek Polacek * cp-tree.h (treat_lvalue_as_rvalue_p): Declare. diff --git a/gcc/cp/lambda.c b/gcc/cp/lambda.c index 25a4d6f..297327f 100644 --- a/gcc/cp/lambda.c +++ b/gcc/cp/lambda.c @@ -1519,8 +1519,8 @@ prune_lambda_captures (tree body) tree cap = *capp; if (tree var = var_to_maybe_prune (cap)) { - tree *use = *const_vars.get (var); - if (TREE_CODE (*use) == DECL_EXPR) + tree **use = const_vars.get (var); + if (use && TREE_CODE (**use) == DECL_EXPR) { /* All uses of this capture were folded away, leaving only the proxy declaration. */ @@ -1535,7 +1535,7 @@ prune_lambda_captures (tree body) *fieldp = DECL_CHAIN (*fieldp); /* And remove the capture proxy declaration. */ - *use = void_node; + **use = void_node; continue; } } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index a4db4f8..2b22784 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-09-05 Pádraig Brady p@draigbrady.com + + PR c++/87185 + * g++.dg/pr87185.C: New. + 2018-09-05 Martin Liska PR testsuite/87216 diff --git a/gcc/testsuite/g++.dg/pr87185.C b/gcc/testsuite/g++.dg/pr87185.C new file mode 100644 index 0000000..46dae0e --- /dev/null +++ b/gcc/testsuite/g++.dg/pr87185.C @@ -0,0 +1,4 @@ +// PR c++/87185 +// { dg-do compile { target c++11 } } + +void f() { const int i=0; [&]() noexcept {i;}; } -- 2.7.4