From patchwork Mon Sep 17 17:53:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 970759 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-485787-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="jbQFnQx0"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="MKoo71jb"; 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 42DYdr5fJNz9sj8 for ; Tue, 18 Sep 2018 03:53:51 +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 :subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=aj0DFZB/hw31mFhCu 1SSa2qCUjzxABnlzTWpeYoznD/t2IGX+p6Kef8Wj6XPEpQdMM3ve3mZlDIOkwpDa +JgbV0qgdleYg3ZbILHWnRMLVOpNo4fyPtyHILkHg2G2P+S29Hdk6tYod2vkGW3x XdSn/kYliYnaY0ZflYOGA3e+Eg= 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 :subject:from:to:cc:references:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=s/4lw41Y7ZvMlVkMn9GNm8B +eaU=; b=jbQFnQx0EQfDpSJ19VlPgyAVULFa8yOC3fLW/xLCkV3OXeCvYD3THZF ah4cy5dgztPkGey8cMwlKo5oRFQLujMgK1fNnmftNOdQxe2tcQA6iRJOLf3XzrqZ y96YexqG/lRie8fZOgJXiUF8vtbIU/ZAq995VfW0935DneT1xn0I= Received: (qmail 37786 invoked by alias); 17 Sep 2018 17:53:44 -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 37777 invoked by uid 89); 17 Sep 2018 17:53:44 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=satisfied, concepts, lately, neat X-HELO: aserp2120.oracle.com Received: from aserp2120.oracle.com (HELO aserp2120.oracle.com) (141.146.126.78) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Mon, 17 Sep 2018 17:53:42 +0000 Received: from pps.filterd (aserp2120.oracle.com [127.0.0.1]) by aserp2120.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w8HHi7QZ119942; Mon, 17 Sep 2018 17:53:39 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=subject : from : to : cc : references : message-id : date : mime-version : in-reply-to : content-type; s=corp-2018-07-02; bh=Zudyv/XjynK2J7694hOVfgTim375fikL1tWAebWbHvw=; b=MKoo71jbJ4TcEZmzXgVfgnV9oZcYyneVuwwgCvdO1OtaCDKwxuD1tVZL5hjxNfHeU+Wd czN6OZy7gRV4iySm8SEVQZTUPS1Nm3kznb1gThj6LiILbXqqNu6JlnwmESfQ5uXjM+L6 yF0pDU8ub8QfX06abhHnGcTy73KtDvn8W6eVy0LX/jSs/2a/d8EM5w8TADBGPf+yeAgb qFtMifhhbPrx2dQ7jqGxDzz4fXZURuObOkKPGuSl52uFdgjQToCNQ+gAXWolTeN9gsju I4Se3s7qYWfokGSbiFw1o3Z8XeV5OM1+bs5vmc/darOHBklJeHP69XQgzLqACF/ikhp4 EQ== Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by aserp2120.oracle.com with ESMTP id 2mgt1pfv9h-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Sep 2018 17:53:38 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w8HHrctj032721 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 17 Sep 2018 17:53:38 GMT Received: from abhmp0004.oracle.com (abhmp0004.oracle.com [141.146.116.10]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w8HHrbqe032159; Mon, 17 Sep 2018 17:53:37 GMT Received: from [192.168.1.4] (/79.19.198.236) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Mon, 17 Sep 2018 10:53:37 -0700 Subject: [C++ Patch PING] [C++ Patch] PR 85065 ("[concepts] ICE with invalid use of a concept") From: Paolo Carlini To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill , Nathan Sidwell References: <1323550c-2bd5-8351-231e-c4093ab960a4@oracle.com> Message-ID: <93851680-6ba2-cdec-4dc0-e2dd9f5767cd@oracle.com> Date: Mon, 17 Sep 2018 19:53:34 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0 MIME-Version: 1.0 In-Reply-To: <1323550c-2bd5-8351-231e-c4093ab960a4@oracle.com> X-IsSubscribed: yes Hi again, On 9/3/18 10:59 PM, Paolo Carlini wrote: > in this error-recovery ICE, upon the error make_constrained_auto > assigns error_mark_node to PLACEHOLDER_TYPE_CONSTRAINTS (type) which > then causes a crash later when hash_placeholder_constraint is called > on it. I think we should cope with this somehow, I believe that > consistency with the way we use error_mark_node in this part of the > front-end prevents us from avoiding to assign the error_mark_node in > the first place and, for the reasons explained in my previous patch, > we want to unconditionally call make_constrained_auto. This said, > catching in practice the error_mark_node would normally mean > renouncing to the pattern 'if (tree c = ...)' which we lately appear > to like a lot and seems indeed neat. Thus I'm wondering if we want > instead to add a macro like ERROR_AS_NULL, which of course would be > also useful in many other places - essentially in all the > circumstances where we want to check for a kosher node, thus neither > null nor error_mark_node. What do you think? What about the name, in > case? Tested x86_64-linux. Today I reviewed again this issue, for which I sent a tentative patch a couple of weeks ago. All in all, I still believe that is the right place to catch the error_mark_node and avoid ICE-ing later, the quick rationale being that PLACEHOLDER_TYPE_CONSTRAINTS can be error_mark_node for other reasons too. As regards the ERROR_AS_NULL idea, I'm still not sure, on one hand it would allow for more compact and neat code in some cases, on the other hand could be seen as some sort of obfuscation - well, some people out there consider an obfuscation the very 'if (c =...)' pattern ;) Anyway, I'm attaching the normal versions of the fix, which, per a recent message from Jason, probably is almost obvious... Thanks, Paolo. ///////////////////// Index: cp/pt.c =================================================================== --- cp/pt.c (revision 264362) +++ cp/pt.c (working copy) @@ -26121,7 +26121,8 @@ struct auto_hash : default_hash_traits inline hashval_t auto_hash::hash (tree t) { - if (tree c = PLACEHOLDER_TYPE_CONSTRAINTS (t)) + tree c = PLACEHOLDER_TYPE_CONSTRAINTS (t); + if (c && c != error_mark_node) /* Matching constrained-type-specifiers denote the same template parameter, so hash the constraint. */ return hash_placeholder_constraint (c); @@ -26880,50 +26881,53 @@ do_auto_deduction (tree type, tree init, tree auto /* Check any placeholder constraints against the deduced type. */ if (flag_concepts && !processing_template_decl) - if (tree constr = PLACEHOLDER_TYPE_CONSTRAINTS (auto_node)) - { - /* Use the deduced type to check the associated constraints. If we - have a partial-concept-id, rebuild the argument list so that - we check using the extra arguments. */ - gcc_assert (TREE_CODE (constr) == CHECK_CONSTR); - tree cargs = CHECK_CONSTR_ARGS (constr); - if (TREE_VEC_LENGTH (cargs) > 1) - { - cargs = copy_node (cargs); - TREE_VEC_ELT (cargs, 0) = TREE_VEC_ELT (targs, 0); - } - else - cargs = targs; - if (!constraints_satisfied_p (constr, cargs)) - { - if (complain & tf_warning_or_error) - { - auto_diagnostic_group d; - switch (context) - { - case adc_unspecified: - case adc_unify: - error("placeholder constraints not satisfied"); - break; - case adc_variable_type: - case adc_decomp_type: - error ("deduced initializer does not satisfy " - "placeholder constraints"); - break; - case adc_return_type: - error ("deduced return type does not satisfy " - "placeholder constraints"); - break; - case adc_requirement: - error ("deduced expression type does not satisfy " - "placeholder constraints"); - break; - } - diagnose_constraints (input_location, constr, targs); - } - return error_mark_node; - } - } + { + tree constr = PLACEHOLDER_TYPE_CONSTRAINTS (auto_node); + if (constr && constr != error_mark_node) + { + /* Use the deduced type to check the associated constraints. If we + have a partial-concept-id, rebuild the argument list so that + we check using the extra arguments. */ + gcc_assert (TREE_CODE (constr) == CHECK_CONSTR); + tree cargs = CHECK_CONSTR_ARGS (constr); + if (TREE_VEC_LENGTH (cargs) > 1) + { + cargs = copy_node (cargs); + TREE_VEC_ELT (cargs, 0) = TREE_VEC_ELT (targs, 0); + } + else + cargs = targs; + if (!constraints_satisfied_p (constr, cargs)) + { + if (complain & tf_warning_or_error) + { + auto_diagnostic_group d; + switch (context) + { + case adc_unspecified: + case adc_unify: + error("placeholder constraints not satisfied"); + break; + case adc_variable_type: + case adc_decomp_type: + error ("deduced initializer does not satisfy " + "placeholder constraints"); + break; + case adc_return_type: + error ("deduced return type does not satisfy " + "placeholder constraints"); + break; + case adc_requirement: + error ("deduced expression type does not satisfy " + "placeholder constraints"); + break; + } + diagnose_constraints (input_location, constr, targs); + } + return error_mark_node; + } + } + } if (processing_template_decl && context != adc_unify) outer_targs = current_template_args (); Index: testsuite/g++.dg/concepts/pr85065.C =================================================================== --- testsuite/g++.dg/concepts/pr85065.C (nonexistent) +++ testsuite/g++.dg/concepts/pr85065.C (working copy) @@ -0,0 +1,6 @@ +// { dg-do compile { target c++14 } } +// { dg-additional-options "-fconcepts" } + +template concept bool C = true; + +C c = 0; // { dg-error "invalid reference to concept" }