From patchwork Fri Jan 26 13:46:19 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 866323 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-472101-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="aGoq3GlF"; 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 3zSgDW3BqVz9s75 for ; Sat, 27 Jan 2018 00:46:34 +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=ORaHQh5Ac6oiQ5smIa0yDEoTK/18uJsFqUoZ4WXQsq7l9AhcrU M3Fz5Mp5psaYRpxftpJLpt1wHKjNtDMmqAr6CwooiFfHjon88u1NayAoilnjsVmr bolNirG2KozL8gSMxbXgaMcb0ZkXix2/MXrw+4n+QKlVXqQLFFH0melak= 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=lAN0xOKFRK/OMlBfdg2TXUoZDvE=; b=aGoq3GlF65qNZjiwdG7P UYkFbwmb8OU9qMixF5oFnRsjkBkzgr9rkLEavluOxIj0bRA0uhv2LC8TEezT7l+4 owrGpB6ULH7bhv6+btkByOZ5+jZhRE0mmyjR3xWhpgFQa/zvfxqtBeaj4qAx+N32 NtP7V3E6xkX3afHuyDltOgI= Received: (qmail 67943 invoked by alias); 26 Jan 2018 13:46:25 -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 67620 invoked by uid 89); 26 Jan 2018 13:46:24 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.1 required=5.0 tests=BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 spammy=invisible X-HELO: mail-yw0-f171.google.com Received: from mail-yw0-f171.google.com (HELO mail-yw0-f171.google.com) (209.85.161.171) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 26 Jan 2018 13:46:23 +0000 Received: by mail-yw0-f171.google.com with SMTP id t201so186912ywf.1 for ; Fri, 26 Jan 2018 05:46:22 -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=0ZYqzmEYbeF/YdGl8Ij0o8CRBOuU41HBiR3Pz3R5Aok=; b=fxlPpyHEFWqoCng5MjegzPd3zOWG15t4wnKmULgAfWK+IZlgHu+4LrDk1iLTLD3afw 3E1fmTBH+/uDLi9Udaw2vrXbZtFrt78qL8bgBZlu64vpe27PYROH26mUsW57wfjkpAyI IFaK/w/dlCOCL6M2Nzzv5zD6gvSgXb+0DLy0auvPGnoCRiSij7hAPMyQqBYJLp8rwY8L pSecQuBNwiD6HXvT6/iyJwBlByUAb+jzgZXfEd0EJayGksSCtFeF2YP6y3tpv2sRYX2s KisyFKcIaEWKPP+vWJtcvdKrK19WWiibY/59sBwlVOOJiyVg+4y4TklAXxijOl0TayjR 3QoQ== X-Gm-Message-State: AKwxytdscf2mMYNMoIdwiqXbdZqTZ+WD0tTJ8oZOeQ6Eii7OVgxsJV6d 2XSIAmijzotusiehEMIy5dE= X-Google-Smtp-Source: AH8x227WzJll9yCnIxfDsvVU7CutSVO1rr/v6lexDTkMS+LUQ43TNC2Ux3ouRVrB88WvQOUABuVXSA== X-Received: by 10.129.92.66 with SMTP id q63mr10918963ywb.138.1516974381466; Fri, 26 Jan 2018 05:46:21 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:7500:e7fb:4a6f:2254? ([2620:10d:c091:200::1:896]) by smtp.googlemail.com with ESMTPSA id z77sm2062964ywd.21.2018.01.26.05.46.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 26 Jan 2018 05:46:20 -0800 (PST) To: GCC Patches Cc: Jonathan Wakely From: Nathan Sidwell Subject: [C++/82878] backport fix Message-ID: Date: Fri, 26 Jan 2018 08:46:19 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.5.2 MIME-Version: 1.0 I'm applying this backport to the gcc-7 branch. Jonathan was kind enough to point out it's needed tehre. nathan 2018-01-26 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 257087) +++ cp/call.c (working copy) @@ -375,18 +375,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 257087) +++ cp/cp-gimplify.c (working copy) @@ -1107,6 +1107,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: cp/lambda.c =================================================================== --- cp/lambda.c (revision 257087) +++ cp/lambda.c (working copy) @@ -1072,7 +1072,6 @@ maybe_add_lambda_conv_op (tree type) } } - if (generic_lambda_p) { if (decltype_call) 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 257087) +++ 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_)) {}