From patchwork Fri Jan 20 13:15:26 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 717646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org 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 3v4h6M29Blz9sxN for ; Sat, 21 Jan 2017 00:15:54 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="TMo847H/"; dkim-atps=neutral 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=Z9gXeER7XZcwLE8+fLVohfi08+WrR5FxtQ8SryCr0ynsaWZTR5 KcChqMXOAw0w+7Y+kBT4xp7EcQI9uvLeSanochLTX+HrX2SzI8Ts1ZwcXmJ38Ond kLxU2PXlkVclPcNtmZCk0GYEw6CH4UK1aApqreyypTEpm69nX6/5lyvRk= 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=2Itzh/k0ZRvtzEhn4EOYWLAnnfA=; b=TMo847H/xBmae/JmxTg7 GkpX7rttOvD4TXnnK204rwpfPF+S+bppHg/n8Bo1+pfuFcqvBpLZ+JA/w7XAzHxL bp3FDpkvXVlNuJ+x4oi1A+HKmdGNRfh2twY8jlDdkT9jxXX1ZQmotl11L8bhxikw vjpFCnlsEUQzOf8zZHstilg= Received: (qmail 10550 invoked by alias); 20 Jan 2017 13:15:46 -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 128538 invoked by uid 89); 20 Jan 2017 13:15:30 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-HELO: mail-yw0-f194.google.com Received: from mail-yw0-f194.google.com (HELO mail-yw0-f194.google.com) (209.85.161.194) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 20 Jan 2017 13:15:30 +0000 Received: by mail-yw0-f194.google.com with SMTP id q71so5479560ywg.3 for ; Fri, 20 Jan 2017 05:15:29 -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; bh=xbPYhMWwNWZwlB2Tp5TEbdbKvTX2U+yQ0hBT4Naf/fU=; b=ilwT9OWCvdzd0vGjJJlg4XZA6HQxEZNRDq77IHM7vg085DtFz0HN4bYASLLmYdoehc 4b0qzKyDFcdNFHcmVR+42eSnrpuNd7e45fdYaoPnVdEDRD4+B6wP1CffBFVHDSPnLFcs MCZB2ILiIVZTyjOZzX3ZE+xFJiPEo3za3jzX1RuiLD+PT2snX8ePQfd083wC0Qejhnn3 2XijiBJxwqXBmutk4qaPrNz9pfr38uSwZvmMQeey63w6HfBkK1TygjRw+WEEdoEG/PbO ol2rkqvJJ08Ni5Mu2qtYLL91BOh5zSlmQBMCh4/ZF7Pg2AkWKAI5QWDwcRxIZeSvFXR2 /fbw== X-Gm-Message-State: AIkVDXJI0OOrF+ruDuqeImLG+FaBynH3UwidA5Lr9XSloKiknh74CSb+Lpp8l9FqZaWGPA== X-Received: by 10.129.166.16 with SMTP id d16mr12960888ywh.204.1484918128246; Fri, 20 Jan 2017 05:15:28 -0800 (PST) Received: from ?IPv6:2620:10d:c0a3:20fb:f6d0:5ac5:64cd:f102? ([2620:10d:c091:200::9:7c73]) by smtp.googlemail.com with ESMTPSA id p4sm3272940ywe.30.2017.01.20.05.15.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 20 Jan 2017 05:15:27 -0800 (PST) To: Jason Merrill Cc: GCC Patches From: Nathan Sidwell Subject: [C++ PATCH] c++/78495 inherited ctor and inivis-ref parm Message-ID: Date: Fri, 20 Jan 2017 08:15:26 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.6.0 MIME-Version: 1.0 Bug 78495 is a wrong code bug caused by an invisiref parm. When building the inherited ctor, we use forward_parm to create a forwarding reference. That code generation considers the type of the parm to be 'T'. We thus end up with a tree that looks like *&PARM The subsequent call gets 'CALL_FROM_THUNK' set. We need that set so code generation doesn't copy pass-by-invisiref objects that are specified by the C abi (but not specified so by the C++ abi) (POD structs, commonly). cp_genericize is used to mutate invisiref parm_decls from T to &T and bash their uses from PARM to *PARM (with suitable checking of &PARM turning into plain PARM). However it explicitly skips genericizing the args of a CALL_FROM_THUNK tree. Thus we end up taking the address of the reference parm itself. That appears to be incorrect now we have forward_parm. This patch deletes that skipping. ok? nathan 2017-01-20 Nathan Sidwell PR c++/78495 - wrong code inherited ctor and invisi-ref parm * cp-gimplify.c (cp_generize_r): Don't skip thunks. PR c++/79495 * g++.dg/cpp1z/inh-ctor38.C: New. Index: cp/cp-gimplify.c =================================================================== --- cp/cp-gimplify.c (revision 244596) +++ cp/cp-gimplify.c (working copy) @@ -1103,15 +1103,7 @@ 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; - } - - /* Otherwise, do dereference invisible reference parms. */ + /* Dereference invisible reference parms. */ if (wtd->handle_invisiref_parm_p && is_invisiref_parm (stmt)) { *stmt_p = convert_from_reference (stmt); Index: testsuite/g++.dg/cpp1z/inh-ctor38.C =================================================================== --- testsuite/g++.dg/cpp1z/inh-ctor38.C (revision 0) +++ testsuite/g++.dg/cpp1z/inh-ctor38.C (working copy) @@ -0,0 +1,31 @@ +// { dg-do run { target c++11 } } +// PR78495 failed to propagate pass-by-value struct to base ctor. + +struct Ptr { + void *ptr = 0; + + Ptr() {} + Ptr(Ptr const&) = delete; + Ptr(Ptr&& other) : ptr (other.ptr) {} +}; + +struct Base { + Ptr val; + Base(Ptr val_) : val(static_cast(val_)) {} +}; + +struct Derived: Base { + using Base::Base; +}; + +void *Foo () { + Ptr ptr; + + Derived d(static_cast(ptr)); + + return d.val.ptr; +} + +int main () { + return Foo () != 0; +}