From patchwork Fri Dec 16 12:23:08 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 88295 Delivered-To: patch@linaro.org Received: by 10.140.20.101 with SMTP id 92csp1372565qgi; Fri, 16 Dec 2016 04:24:09 -0800 (PST) X-Received: by 10.99.176.14 with SMTP id h14mr5254611pgf.22.1481891049554; Fri, 16 Dec 2016 04:24:09 -0800 (PST) Return-Path: Received: from sourceware.org (server1.sourceware.org. [209.132.180.131]) by mx.google.com with ESMTPS id r82si7557091pfi.192.2016.12.16.04.24.09 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 04:24:09 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-return-444587-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) client-ip=209.132.180.131; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org; spf=pass (google.com: domain of gcc-patches-return-444587-patch=linaro.org@gcc.gnu.org designates 209.132.180.131 as permitted sender) smtp.mailfrom=gcc-patches-return-444587-patch=linaro.org@gcc.gnu.org DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=jUDIWDGiYVfV0KhbOk//evfRUWuLmLsuHw2yDS4jkfJmrnFJwQ HhKh56G6xY+Mo/9GEf7JZnGvZ8/Iavry8ZTEDam7slQzCRHbF05LxdsqIsp7jjHy jNJO1b5GHo7lZY5LFcRDKmgBF3NuS8k5EYKKe1S0ejeD0ysuzDrc+FXzM= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to:cc :from:subject:message-id:date:mime-version:content-type; s= default; bh=ghJqgezYeHStLEtu3qBk6rrG7n8=; b=jEiGJeFnk3QfB6iOmoa2 9uzNRksnuYARlZDIMh8xL/MJ8ZxSz8TKMFUyMav1LLWJDF9KU2gu/z7eKQ4bV9C6 p8mZ7Jww7uwjjMC7/AeHIymPwmMmjAFQ2UXFlw2xgyI5cPtJy1EV7WBRpbbL7nRd mR30/H0IB9Yxtt9Ki1zp3f4= Received: (qmail 126007 invoked by alias); 16 Dec 2016 12:23:23 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 125919 invoked by uid 89); 16 Dec 2016 12:23:22 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-0.6 required=5.0 tests=BAYES_00, FREEMAIL_FROM, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=no version=3.3.2 spammy=CASE, Hx-languages-length:2749, cope, alternatively X-HELO: mail-yw0-f196.google.com Received: from mail-yw0-f196.google.com (HELO mail-yw0-f196.google.com) (209.85.161.196) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 16 Dec 2016 12:23:11 +0000 Received: by mail-yw0-f196.google.com with SMTP id b66so3781877ywh.2 for ; Fri, 16 Dec 2016 04:23:11 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:cc:from:subject:message-id:date :user-agent:mime-version; bh=B6BYJ9TVPW3CR2RzNzLQ4Kvc+t8YLlLDe/5KfcKQdLs=; b=GGc+A1Q1fixV4v+vTbaAKjFKRzOmepXNKMVVY/DlOXoozVt68NOnl83V1B35J3qPwn EPzdEysTOehmlpH/IjEUrnuAMAppLsmvd4to1FgNEX0YtGupeyDGcE3LnH5Vkqx2L1dV dajsWAOv/ZENfotSjZ08a0EIJILI1Etx0RIX2lzu92x7C/4qA37TheZVLAWp4kl0ONSL NSPqnDzJL7GjVINknaoxkDfNReKCVrATVpkvNSXnSr0LVi6U93pWJAeUarRVgcWuxBYs CNX4FndJcrGtPgpjR4I3aKo6dNGDMdkRaHk/UlHnmb52fbPKgyjTUy6Q+0jhy9LVbfuF aqQQ== X-Gm-Message-State: AKaTC00SNa0JFLxtY1qu+8N4OUQ8tw4IuRzHaBQ5EfGZsDcFztcCX6L7O5THzJwpgM2c+A== X-Received: by 10.13.248.193 with SMTP id i184mr1988615ywf.265.1481890990143; Fri, 16 Dec 2016 04:23:10 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::640]) by smtp.googlemail.com with ESMTPSA id t77sm2172949ywg.38.2016.12.16.04.23.09 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 16 Dec 2016 04:23:09 -0800 (PST) To: Jason Merrill Cc: GCC Patches From: Nathan Sidwell Subject: [PATCH] c++/78765 Message-ID: Date: Fri, 16 Dec 2016 07:23:08 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.5.1 MIME-Version: 1.0 Jason, this patch fixes an ICE that happens after error recovery of a constexpr object that has a bad initializer. your patch introduced this regression: * tree.c (obvalue_p): Rename from lvalue_p. (lvalue_p): Define for c-common. * call.c, cp-tree.h, cvt.c, init.c: Adjust. * typeck.c: Adjust. (cp_build_addr_expr_1): Remove obsolete code. that cp_build_addr_expr_1 change turns out not quite obsolete. when cxx_eval_constant_expression finds a nonconstant expression it returns a TREE without TREE_CONSTANT set. else if (non_constant_p && TREE_CONSTANT (r)) { /* This isn't actually constant, so unset TREE_CONSTANT. */ ... else // THIS CASE HAPPENS r = build_nop (TREE_TYPE (r), r); TREE_CONSTANT (r) = false; } In this case r is the VAR_DECL for 'var'. And cp_build_addr_expr_1 is called to build the object expression to apply ValueType::operator int (). This patch simply strips the NOP expr. I placed that code in the lvalue_kind checking block, because of the comment in the switch statement: CASE_CONVERT: case FLOAT_EXPR: case FIX_TRUNC_EXPR: /* We should have handled this above in the lvalue_kind check. */ gcc_unreachable (); Alternatively we could check if we've met this case just there. (which was the original location of the obsolete code) ok? nathan -- Nathan Sidwell 2016-12-15 Nathan Sidwell PR c++/78765 * typeck.c (cp_build_addr_expr_1): Cope with failed constexpr eval of incoming arg. PR c++/78765 * g++.dg/cpp0x/pr78765.C: New. Index: cp/typeck.c =================================================================== --- cp/typeck.c (revision 243692) +++ cp/typeck.c (working copy) @@ -5645,9 +5645,24 @@ cp_build_addr_expr_1 (tree arg, bool str else error ("taking address of xvalue (rvalue reference)"); } + + /* If ARG comes from a failed constexpr evaluation, it might be + wrapped in a NOP_EXPR to remove TREE_CONSTANT. */ + if (kind == clk_class && TREE_CODE (arg) == NOP_EXPR) + { + gcc_assert (!TREE_CONSTANT (arg) + && TREE_CONSTANT (TREE_OPERAND (arg, 0)) + && same_type_p (argtype, + TREE_TYPE (TREE_OPERAND (arg, 0)))); + arg = TREE_OPERAND (arg, 0); + } } if (TREE_CODE (argtype) == REFERENCE_TYPE) Index: testsuite/g++.dg/cpp0x/pr78765.C =================================================================== --- testsuite/g++.dg/cpp0x/pr78765.C (revision 0) +++ testsuite/g++.dg/cpp0x/pr78765.C (working copy) @@ -0,0 +1,15 @@ +// PR c++/78765 +// { dg-do compile { target c++11 } } + +// ICE with failed constexpr object and member fn call + +struct ValueType { + constexpr operator int() const {return field;} + int field; +}; + +static constexpr ValueType var = 0; // { dg-error "conversion" } + +template class ValueTypeInfo; + +ValueTypeInfo x;