From patchwork Tue Sep 5 10:19:33 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 810070 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-461475-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="am1mIzT+"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3xmjQ14VmJz9s3w for ; Tue, 5 Sep 2017 20:19:53 +1000 (AEST) 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=Bdthfw2rX+gBWt2mjLjoeq80F/PsD52meovfA+wTon2YAxrAHL kvCsG/6D+CyxysHxqxDSo/Gk4NZkMyZTC8exrb6CMA4Cv9VktGVn9l/80QCb1Dz/ UjfThJ9uVAJ3pyQp6r2AnYDRomiGs+8wn2gDIWL+OirRZyv8LLOQxe1gs= 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=q3SvJk3u5MRoYy5EYnOArGZAPQk=; b=am1mIzT+hRa2Hp0aDXvR tk/Vubb6oBmmLMJ0kQ2xirPxUNQgbHtDGjsU1OHpR+ZIb3msoZhu2lFfcZLSD8nh xI3vdPz9/67fMeTS/Zs+CeBoA0y3n7K6c6w011YGoLDAel2VwzTJUg/G4ZjBMl24 ujWzp8Mi0Ph88J7DrUSFnfM= Received: (qmail 26617 invoked by alias); 5 Sep 2017 10:19:45 -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 26600 invoked by uid 89); 5 Sep 2017 10:19:43 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KAM_LAZY_DOMAIN_SECURITY, RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: userp1040.oracle.com Received: from userp1040.oracle.com (HELO userp1040.oracle.com) (156.151.31.81) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 05 Sep 2017 10:19:38 +0000 Received: from aserv0021.oracle.com (aserv0021.oracle.com [141.146.126.233]) by userp1040.oracle.com (Sentrion-MTA-4.3.2/Sentrion-MTA-4.3.2) with ESMTP id v85AJaUh009833 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Sep 2017 10:19:36 GMT Received: from aserv0121.oracle.com (aserv0121.oracle.com [141.146.126.235]) by aserv0021.oracle.com (8.14.4/8.14.4) with ESMTP id v85AJZFO027769 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Tue, 5 Sep 2017 10:19:35 GMT Received: from abhmp0001.oracle.com (abhmp0001.oracle.com [141.146.116.7]) by aserv0121.oracle.com (8.14.4/8.13.8) with ESMTP id v85AJZRw003487; Tue, 5 Sep 2017 10:19:35 GMT Received: from [192.168.1.4] (/87.18.226.243) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Tue, 05 Sep 2017 03:19:35 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++/ARM Patch] PR 81942 ("ICE on empty constexpr constructor with C++14") Message-ID: <25f223e6-8b85-d81a-51f0-2dec92838338@oracle.com> Date: Tue, 5 Sep 2017 12:19:33 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.1.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, Hi, in this ICE on valid, a gcc_assert fires when a GOTO_EXPR is handled by cxx_eval_constant_expression which is the translation of a "return;" on a targetm.cxx.cdtor_returns_this target (like ARM): ;; Function constexpr A::A() (null) ;; enabled by -tree-original { // predicted unlikely by goto predictor.; goto ; } :; return this; I think the right way to handle this is marking such special labels with a LABEL_DECL_CDTOR flag and using it in the returns helper function (we already use a similar strategy with LABEL_DECL_BREAK and LABEL_DECL_CONTINUE and the breaks and continues helpers). Then adjusting the ICEing gcc_assert is trivial. Tested x86_64-linux and aarch64-linux. Thanks, Paolo. ////////////////////////////////// /cp 2017-09-05 Paolo Carlini PR c++/81942 * cp-tree.h (LABEL_DECL_CDTOR): Add and document. * decl.c (start_preparsed_function): Set LABEL_DECL_CDTOR when creating cdtor_label. * constexpr.c (returns): Add the case of a constructor/destructor returning via a LABEL_DECL_CDTOR label. (cxx_eval_constant_expression, case [GOTO_EXPR]): Likewise. /testsuite 2017-09-05 Paolo Carlini PR c++/81942 * g++.dg/cpp1y/constexpr-return3.C: New. Index: cp/constexpr.c =================================================================== --- cp/constexpr.c (revision 251700) +++ cp/constexpr.c (working copy) @@ -3671,7 +3671,9 @@ static bool returns (tree *jump_target) { return *jump_target - && TREE_CODE (*jump_target) == RETURN_EXPR; + && (TREE_CODE (*jump_target) == RETURN_EXPR + || (TREE_CODE (*jump_target) == LABEL_DECL + && LABEL_DECL_CDTOR (*jump_target))); } static bool @@ -4554,7 +4556,9 @@ cxx_eval_constant_expression (const constexpr_ctx case GOTO_EXPR: *jump_target = TREE_OPERAND (t, 0); - gcc_assert (breaks (jump_target) || continues (jump_target)); + gcc_assert (breaks (jump_target) || continues (jump_target) + /* Allow for jumping to a cdtor_label. */ + || returns (jump_target)); break; case LOOP_EXPR: Index: cp/cp-tree.h =================================================================== --- cp/cp-tree.h (revision 251700) +++ cp/cp-tree.h (working copy) @@ -456,6 +456,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; DECL_CONSTRAINT_VAR_P (in a PARM_DECL) TEMPLATE_DECL_COMPLEX_ALIAS_P (in TEMPLATE_DECL) DECL_INSTANTIATING_NSDMI_P (in a FIELD_DECL) + LABEL_DECL_CDTOR (in LABEL_DECL) 3: DECL_IN_AGGR_P. 4: DECL_C_BIT_FIELD (in a FIELD_DECL) DECL_ANON_UNION_VAR_P (in a VAR_DECL) @@ -3833,6 +3834,11 @@ more_aggr_init_expr_args_p (const aggr_init_expr_a #define LABEL_DECL_CONTINUE(NODE) \ DECL_LANG_FLAG_1 (LABEL_DECL_CHECK (NODE)) +/* Nonzero if NODE is the target for genericization of 'return' stmts + in constructors/destructors of targetm.cxx.cdtor_returns_this targets. */ +#define LABEL_DECL_CDTOR(NODE) \ + DECL_LANG_FLAG_2 (LABEL_DECL_CHECK (NODE)) + /* True if NODE was declared with auto in its return type, but it has started compilation and so the return type might have been changed by return type deduction; its declared return type should be found in Index: cp/decl.c =================================================================== --- cp/decl.c (revision 251700) +++ cp/decl.c (working copy) @@ -15072,7 +15073,10 @@ start_preparsed_function (tree decl1, tree attrs, if (DECL_DESTRUCTOR_P (decl1) || (DECL_CONSTRUCTOR_P (decl1) && targetm.cxx.cdtor_returns_this ())) - cdtor_label = create_artificial_label (input_location); + { + cdtor_label = create_artificial_label (input_location); + LABEL_DECL_CDTOR (cdtor_label) = true; + } start_fname_decls (); Index: testsuite/g++.dg/cpp1y/constexpr-return3.C =================================================================== --- testsuite/g++.dg/cpp1y/constexpr-return3.C (revision 0) +++ testsuite/g++.dg/cpp1y/constexpr-return3.C (working copy) @@ -0,0 +1,11 @@ +// PR c++/81942 +// { dg-do compile { target c++14 } } + +class A { +public: + constexpr A() { + return; + } +}; + +A mwi;