From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-qk1-x742.google.com (mail-qk1-x742.google.com [IPv6:2607:f8b0:4864:20::742]) by sourceware.org (Postfix) with ESMTPS id E23833851C0F for ; Wed, 13 May 2020 15:10:48 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org E23833851C0F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qk1-x742.google.com with SMTP id z80so12140752qka.0 for ; Wed, 13 May 2020 08:10:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=Xx+HnJrVXl1Jq9MqyuBMWJqnJYtrQCq0V1On16w/E64=; b=iUKHZGSmpj3xPiGv9wYA/qmBydvyguyXDt/bWaT32ZsqX+/oXKXOLptqELJXwThrBg DLRdsuh2djVB6ABL3WLxKKcyoh+YuaefWR/sdEJA+5vbEI8KrXunKi2pVJnFsa9qEOqW j1UB3U5z5MWCD3Qh6xIXlcna5quFBzJpTTrWsSG1Apvx4cl7/wNLmxscq3kVXR3DOmFW UqY0+/grmmcLYorb2wVcY7NuMyMz7qU77mVMiAfo2TaxKBeZFa9XjJU9MyhTwe813NVU jm6eLYRP0q/o+/AGoJ3yImiuGmfOfi6ZVt5py5pOkCsnIywvcM75s42c+HpaptuJEA6d +dTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:cc:references:from:message-id :date:user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Xx+HnJrVXl1Jq9MqyuBMWJqnJYtrQCq0V1On16w/E64=; b=fYs6Z2CdIU2q3RXLu2lr4YoDKq1dHkVOlF0401ATp0AAwQuzHg+mutwv1FyjIuKLLv lT2YN+yeVnuZ8Pz9r513gbgCEOE9tk53hqdg4NdQGLrsge//QVT2xaBYS+cvU/Bec9cP neDiXtVpTIYRSf261SZ8WvcHEeYTCrZIxWCt9R3gLf7FSCfmctX4ZTT0c06oaFZNrEdK 3mnBPhf2U3EPczghBvl70Ot/BMErbbHPg8a/mVoPvJSsY0Ya7jy8oOeVo5ScR33HL1Cg lUYqowGRNRS9j/IgR+PJJemJcxLGdPk2SWDoQNy4tI1BMQ0WZ0YTwJ+wUbfsENS8w2Q/ mRfw== X-Gm-Message-State: AOAM532FW/XtQekgD2MZJvZuxVAFK3HSl0L5MXleQO6v5AdS0GZSbvhF xdEjjJB06LBAmCBhTROPQ4M= X-Google-Smtp-Source: ABdhPJz+4uk2Ontu4eqSgAIHIhzShSk8mjgpqnFbwBcbw9yzmZP9xHYPjUbq909JOzKM3ZFE5UAgRQ== X-Received: by 2002:a37:955:: with SMTP id 82mr88479qkj.291.1589382648041; Wed, 13 May 2020 08:10:48 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:b09d:d9a:a398:471a? ([2620:10d:c091:480::1:2e4f]) by smtp.googlemail.com with ESMTPSA id t126sm49079qkc.79.2020.05.13.08.10.46 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 13 May 2020 08:10:47 -0700 (PDT) Sender: Nathan Sidwell Subject: Re: [PATCH] coroutines: Implicitly movable objects should use move CTORs for co_return. To: Iain Sandoe Cc: gcc-patches@gcc.gnu.org References: <7f0d0b86-bde4-1719-4285-84e69b53b19a@acm.org> From: Nathan Sidwell Message-ID: <14b501e5-2376-baec-e416-16ceeba7d74d@acm.org> Date: Wed, 13 May 2020 11:10:46 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00, BODY_8BITS, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=no autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 13 May 2020 15:10:50 -0000 On 5/13/20 9:26 AM, Iain Sandoe wrote: > Nathan Sidwell wrote: > >> On 5/13/20 6:59 AM, Iain Sandoe wrote: > >>> @@ -1045,25 +1044,50 @@ finish_co_return_stmt (location_t kw, tree expr) >>>        if (!crv_meth || crv_meth == error_mark_node) >>>      return error_mark_node; >>>  -      vec *args = make_tree_vector_single (expr); >>> -      co_ret_call = build_new_method_call ( >>> -    get_coroutine_promise_proxy (current_function_decl), crv_meth, >>> &args, >>> -    NULL_TREE, LOOKUP_NORMAL, NULL, tf_warning_or_error); >>> +      /* [class.copy.elision] / 3. >>> +     An implicitly movable entity is a variable of automatic storage >>> +     duration that is either a non-volatile object or an rvalue >>> reference >>> +     to a non-volatile object type.  For such objects in the context of >>> +     the co_return, the overload resolution should be carried out first >>> +     treating the object as an rvalue, if that fails, then we fall back >>> +     to regular overload resolution.  */ >>> +      tree obj = STRIP_NOPS (expr); >>> +      if (TREE_TYPE (obj) >>> +      && TYPE_REF_P (TREE_TYPE (obj)) >>> +      && TYPE_REF_IS_RVALUE (TREE_TYPE (obj))) >>> +    obj = TREE_OPERAND (obj, 0); >>> + >>> +      if (TREE_CODE (obj) == PARM_DECL >>> +      || (VAR_P (obj) >>> +          && decl_storage_duration (obj) == dk_auto >>> +          && !TYPE_VOLATILE (TREE_TYPE (obj)))) >> >> this is wrong and insufficient. As I explained on IRC -- 'expressions >> of reference type are not a thing'.  We always bash them into an >> indirect-ref of the referency thing. >> >> Look at check_return_value and how it handles NRVO.  There's a >> treat_lvalue_as_rvalue_p call that I'll bet you can use[*], along with >> a move wrapper, which maybe what you want rather than the below rvalue >> (expr). >> >> a return_expr's operand is an INIT_EXPR or MODIFY_EXPR whose LHS is >> DECL_RESULT(fn).  So that's almost what you want here.  I think the >> general form is >> if (treat_lval_as_rval ()) >>   { silently try callexpr with moved operand } >> >> if no joy either way >>   { noisily try callexpr with unmoved operand } >> >> [*] That is insufficient, because elision also applies to objects >> you've placed into the coro frame.  by the std those are still >> automatic storage objects, but inside the compiler they are of course >> COMPONENT_REFs (or do you cons up VAR_DECLS of reference type that >> refer to them?).   Further, the PARM_DECL case can;t occur here -- the >> actor fn's only parm is the coro frame pointer. > > This is the equivalent of finish_return_stmt () in the parser, it knows > nothing of the eventual morphing of local vars (or parms) into frame > references. > > So I only need to handle what can be returned by "expr = > cp_parser_expression (parser);” > dependent expressions are dealt with above, with an early return with > “type_unknown_node”. > > So, it might be I can just reuse the code you point to? Yeah I think so. I realized it was pre-xform so the component-ref stuff was irrelevant when out shopping. In other news, flour's back in stock :) nathan -- Nathan Sidwell