From patchwork Tue Nov 14 20:13:42 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 838014 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-466774-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="A8Ddzjs8"; 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 3ybzHG5M8hz9s5L for ; Wed, 15 Nov 2017 07:13:58 +1100 (AEDT) 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=ZmRzgqEKQxqqvSiA9fNM+wAin+SKR7XcvIvgy7V/5ZfkOd9khO oJxMF7iujZoFv6k7+zjcMnbqPA94XBaR8ABiMQAWYsCJ4Flyq6cAYn6Yjx/FF3YA gJif2TH5wI9kiMWCh0euSuLF3TQT2da+tfsMWbigQwGouKyaXLeptxegk= 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=WhU72c5lNx/weI29ErSIJSbJ054=; b=A8Ddzjs8fPTQo7tsL11E BJp7CiWTLbiKD9PkN6T9DzmsGimHVeyyiCmbvDPRnLcBpuMKdpQu8lw3erPTppx5 aHoVmy+F6SzO/3cfo41H1fMHEdZcdvoVURYtJHfi5afHRcOs82C1NEvOQyCD/Jjz U8bJONRaYpE53u2yCfWR93o= Received: (qmail 115769 invoked by alias); 14 Nov 2017 20:13:49 -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 115752 invoked by uid 89); 14 Nov 2017 20:13:48 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-10.9 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, KB_WAM_FROM_NAME_SINGLEWORD, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=254686, elided X-HELO: mail-qt0-f177.google.com Received: from mail-qt0-f177.google.com (HELO mail-qt0-f177.google.com) (209.85.216.177) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 14 Nov 2017 20:13:46 +0000 Received: by mail-qt0-f177.google.com with SMTP id f8so28769400qta.5 for ; Tue, 14 Nov 2017 12:13:46 -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:content-language; bh=zMGVkDx7ThDliIH75FAoYyyI0vkRlvr/WzX5e5XXPyU=; b=GQId8Tinq/3M7EQgBsJFll6PcNfrh/7rxpsnvDX6CsXW+g9VHyYU3k9WyC0++Yp7qV BE+M2BH6kQhT1+aCMj6SxYUY+y0inM+5IjKmAMTbND+RRfT15Qn5OGyQyqxXKJ75gLie 5ULDY+NaKkwtStL6HnOzhQsR4+S1LcHLReOugknxmRsuxLiyJaEbzAXjarrvHitxNNyK ZDFqh7cpvEhhRvWGdDneVqrXSuVmcadT0M3RStWdJ0+4EwFLc7Hdjo/yer99WEumlJQ/ OtzJwE9x4dY+M5nxySnNCleLirBzzXq0OqNFjhpqeHz+bcQCJXVoTR1VUPPcY6buLs84 lJsA== X-Gm-Message-State: AJaThX66cKQ9sM2+oVZljg+PzQEEwIBBVf7j3MokY0HZ6/8QkH8sZAs8 7Ej1NWRydF23lVE1Vo+svrs= X-Google-Smtp-Source: AGs4zMYHeCF74coWnuYBTkcZRyFsOM7rd9i4bMHHbRhpXboy+sVWFmeVZFKPrxU4HFmoqkY6fOnrUg== X-Received: by 10.129.197.72 with SMTP id o8mr9318419ywj.164.1510690424645; Tue, 14 Nov 2017 12:13:44 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::2:8a77]) by smtp.googlemail.com with ESMTPSA id g189sm4832845ywf.77.2017.11.14.12.13.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 14 Nov 2017 12:13:44 -0800 (PST) To: Jason Merrill Cc: GCC Patches From: Nathan Sidwell Subject: [PR c++/82878] pass-by-invisiref in lambda Message-ID: Date: Tue, 14 Nov 2017 15:13:42 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.4.0 MIME-Version: 1.0 This patch fixes 82878, which turned out to be a problem in genericizing the call inside a __closure::_FUN () that we synthesize when we're providing a non-member fn pointer for a non-capturing lambda. That call is marked as CALL_FROM_THUNK_P, but I elided the check for that when fixing 78495. I think the 78495 fix is incorrect. That's when genericizing the call from an inheriting ctor to the target ctor. That too was setting CALL_FROM_THUNK_P. I think the right fix for that was to not set CALL_FROM_THUNK_P. We're generating that call inside a function whose parms have yet to be bashed into invisrefs. So not thunky enough. This patch restores the deleted cp_genericize_r code and elides the setting of CALL_FROM_THUNK_P during call generation. Jason, does this look right? nathan 2017-11-14 Nathan Sidwell PR c++/82878 PR c++/78495 * call.c (build_call_a): Don't set CALL_FROM_THUNK_P for inherited ctor. * cp-gimplify.c (cp_genericize_r): Restore THUNK dereference inhibibition check removed in previous c++/78495 change. PR c++/82878 * g++.dg/cpp0x/pr82878.C: New. * g++.dg/cpp1z/inh-ctor38.C: Check moves too. Index: cp/call.c =================================================================== --- cp/call.c (revision 254686) +++ cp/call.c (working copy) @@ -376,18 +376,10 @@ build_call_a (tree function, int n, tree TREE_HAS_CONSTRUCTOR (function) = (decl && DECL_CONSTRUCTOR_P (decl)); - if (current_function_decl && decl - && flag_new_inheriting_ctors - && DECL_INHERITED_CTOR (current_function_decl) - && (DECL_INHERITED_CTOR (current_function_decl) - == DECL_CLONED_FUNCTION (decl))) - /* Pass arguments directly to the inherited constructor. */ - CALL_FROM_THUNK_P (function) = true; - /* Don't pass empty class objects by value. This is useful for tags in STL, which are used to control overload resolution. We don't need to handle other cases of copying empty classes. */ - else if (! decl || ! DECL_BUILT_IN (decl)) + if (! decl || ! DECL_BUILT_IN (decl)) for (i = 0; i < n; i++) { tree arg = CALL_EXPR_ARG (function, i); Index: cp/cp-gimplify.c =================================================================== --- cp/cp-gimplify.c (revision 254686) +++ cp/cp-gimplify.c (working copy) @@ -1078,6 +1078,14 @@ cp_genericize_r (tree *stmt_p, int *walk && omp_var_to_track (stmt)) omp_cxx_notice_variable (wtd->omp_ctx, stmt); + /* Don't dereference parms in a thunk, pass the references through. */ + if ((TREE_CODE (stmt) == CALL_EXPR && CALL_FROM_THUNK_P (stmt)) + || (TREE_CODE (stmt) == AGGR_INIT_EXPR && AGGR_INIT_FROM_THUNK_P (stmt))) + { + *walk_subtrees = 0; + return NULL; + } + /* Dereference invisible reference parms. */ if (wtd->handle_invisiref_parm_p && is_invisiref_parm (stmt)) { Index: testsuite/g++.dg/cpp0x/pr82878.C =================================================================== --- testsuite/g++.dg/cpp0x/pr82878.C (revision 0) +++ testsuite/g++.dg/cpp0x/pr82878.C (working copy) @@ -0,0 +1,20 @@ +// { dg-do compile { target c++11 } } +// { dg-additional-options "-O" } +// pr 82878 erroneously unwrapped a reference parm in the lambda::_FUN +// thunk. + +struct A { + ~A(); + operator int (); +}; + +void baz (); + +void +bar (A b) +{ + void (*lam) (A) = [](A) { baz (); }; + + if (auto c = b) + lam (c); +} Index: testsuite/g++.dg/cpp1z/inh-ctor38.C =================================================================== --- testsuite/g++.dg/cpp1z/inh-ctor38.C (revision 254686) +++ testsuite/g++.dg/cpp1z/inh-ctor38.C (working copy) @@ -1,17 +1,19 @@ // { dg-do run { target c++11 } } // PR78495 failed to propagate pass-by-value struct to base ctor. +static int moves = 0; + struct Ptr { void *ptr = 0; Ptr() {} Ptr(Ptr const&) = delete; - Ptr(Ptr&& other) : ptr (other.ptr) {} + Ptr(Ptr&& other) : ptr (other.ptr) {moves++;} }; struct Base { Ptr val; - Base(Ptr val_) : val(static_cast(val_)) {} + Base(Ptr val_); }; struct Derived: Base { @@ -27,5 +29,13 @@ void *Foo () { } int main () { - return Foo () != 0; + if (Foo ()) + return 1; + + if (moves != 2) + return 2; + + return 0; } + +Base::Base(Ptr val_) : val(static_cast(val_)) {}