From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 48040 invoked by alias); 11 Jan 2019 22:35:44 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Received: (qmail 48025 invoked by uid 89); 11 Jan 2019 22:35:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-26.9 required=5.0 tests=BAYES_00,GIT_PATCH_0,GIT_PATCH_1,GIT_PATCH_2,GIT_PATCH_3,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 spammy=integer_cst, start_decl, DECL_P, cp_fold X-HELO: mail-qk1-f193.google.com Received: from mail-qk1-f193.google.com (HELO mail-qk1-f193.google.com) (209.85.222.193) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 11 Jan 2019 22:35:42 +0000 Received: by mail-qk1-f193.google.com with SMTP id w204so7502370qka.2 for ; Fri, 11 Jan 2019 14:35:42 -0800 (PST) Return-Path: Received: from orpheus.redhat.com (209-6-216-142.s141.c3-0.smr-cbr1.sbo-smr.ma.cable.rcncustomer.com. [209.6.216.142]) by smtp.gmail.com with ESMTPSA id v50sm42743514qtc.7.2019.01.11.14.35.40 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 11 Jan 2019 14:35:40 -0800 (PST) From: Jason Merrill To: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] PR c++/88613 - ICE with use of const var in lambda. Date: Fri, 11 Jan 2019 22:35:00 -0000 Message-Id: <20190111223538.22509-1-jason@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-IsSubscribed: yes X-SW-Source: 2019-01/txt/msg00674.txt.bz2 The issue here was that we were cp_folding a location wrapper around a lambda capture proxy before it had been mark_rvalue_used. I considered adding mark_rvalue_use calls to build_new_op_1, but it seems appropriate to have them in cp_fold_maybe_rvalue when we know we're trying to produce an rvalue. The change to mark_use is for a related issue: when we change the operand of the location wrapper from VAR_DECL to INTEGER_CST, we need the TREE_CODE of the location wrapper to change as well, from VIEW_CONVERT_EXPR to NON_LVALUE_EXPR. Tested x86_64-cp-linux-gnu, applying to trunk. * expr.c (mark_use): Fix location wrapper handling. * cp-gimplify.c (cp_fold_maybe_rvalue): Call mark_rvalue_use. --- gcc/cp/cp-gimplify.c | 2 ++ gcc/cp/expr.c | 17 +++++++++++++++-- .../g++.dg/cpp0x/lambda/lambda-const10.C | 11 +++++++++++ gcc/cp/ChangeLog | 6 ++++++ 4 files changed, 34 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const10.C diff --git a/gcc/cp/cp-gimplify.c b/gcc/cp/cp-gimplify.c index 726adac4f4e..121dfa41d8d 100644 --- a/gcc/cp/cp-gimplify.c +++ b/gcc/cp/cp-gimplify.c @@ -2124,6 +2124,8 @@ cp_fold_maybe_rvalue (tree x, bool rval) while (true) { x = cp_fold (x); + if (rval) + x = mark_rvalue_use (x); if (rval && DECL_P (x) && !TYPE_REF_P (TREE_TYPE (x))) { diff --git a/gcc/cp/expr.c b/gcc/cp/expr.c index 071c6fb9205..9160043ed11 100644 --- a/gcc/cp/expr.c +++ b/gcc/cp/expr.c @@ -187,10 +187,23 @@ mark_use (tree expr, bool rvalue_p, bool read_p, } break; - CASE_CONVERT: case VIEW_CONVERT_EXPR: if (location_wrapper_p (expr)) - loc = EXPR_LOCATION (expr); + { + loc = EXPR_LOCATION (expr); + tree op = TREE_OPERAND (expr, 0); + tree nop = RECUR (op); + if (nop == error_mark_node) + return error_mark_node; + TREE_OPERAND (expr, 0) = nop; + /* If we're replacing a DECL with a constant, we also need to change + the TREE_CODE of the location wrapper. */ + if (op != nop && rvalue_p) + TREE_SET_CODE (expr, NON_LVALUE_EXPR); + return expr; + } + gcc_fallthrough(); + CASE_CONVERT: recurse_op[0] = true; break; diff --git a/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const10.C b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const10.C new file mode 100644 index 00000000000..3112f08f5c2 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/lambda/lambda-const10.C @@ -0,0 +1,11 @@ +// PR c++/88613 +// { dg-do compile { target c++11 } } +// { dg-additional-options -Wtautological-compare } + +void a() { + const int b = 5; + [=] { + if (b != 5) + ; + }(); +} diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4b9fa821d74..74e4dff494e 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,9 @@ +2019-01-11 Jason Merrill + + PR c++/88613 - ICE with use of const var in lambda. + * expr.c (mark_use): Fix location wrapper handling. + * cp-gimplify.c (cp_fold_maybe_rvalue): Call mark_rvalue_use. + 2019-01-11 Paolo Carlini * decl.c (start_decl): Improve error location. base-commit: ead1f4b6412011a79e84db928f6a98dd7cf09a3d -- 2.20.1