From patchwork Tue Jul 3 07:35:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 938469 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-480887-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="v4YB7AgU"; 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 41KbXD6hCPz9s29 for ; Tue, 3 Jul 2018 17:36:11 +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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; q=dns; s=default; b=RjTu1p+aZoFx9lmUp7REyWVtT8Z0o 2a/ZngPM5yQBTtkqFJIIf82QOYqO9zxhWBKWx+Gnds+yzHKhDiXORmmB5JDO3Gzt db4QJGLfq+2hH2nFh9DiZCcLEIWgfCcJAnWYSBE5TaJ2UNh8O4xxHtGZyK4dmujt MoOK3ncxl04EIw= 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:date :from:to:cc:subject:message-id:reply-to:mime-version :content-type; s=default; bh=lyrPpq3x6CJqKzP2hy9mNQulQbU=; b=v4Y B7AgUVOJNbkXCHOavh5yYZuIhu0UxzV0V5rz+2V8OPhSPUW6XWqZmzrWJ3tLbkTo vAhBCCjBQyxzulGUuXFuZJKXbItQujMRs08GlhGpowqPtH9+4J1bNfB0lr8Z4k7l IzcCuFIplJUx4i75G+Qzb5cclAeuOjQNF7ySx32k= Received: (qmail 99745 invoked by alias); 3 Jul 2018 07:36:04 -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 99714 invoked by uid 89); 3 Jul 2018 07:36:01 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-9.4 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, KAM_LAZY_DOMAIN_SECURITY, KAM_STOCKGEN, SPF_HELO_PASS autolearn=ham version=3.3.2 spammy=xi, i686linux, i686-linux X-HELO: mx1.redhat.com Received: from mx1.redhat.com (HELO mx1.redhat.com) (209.132.183.28) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Tue, 03 Jul 2018 07:35:59 +0000 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 88B0430E6848; Tue, 3 Jul 2018 07:35:58 +0000 (UTC) Received: from tucnak.zalov.cz (ovpn-204-22.brq.redhat.com [10.40.204.22]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 17E7560177; Tue, 3 Jul 2018 07:35:57 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.15.2/8.15.2) with ESMTP id w637Zt1W020786; Tue, 3 Jul 2018 09:35:56 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.15.2/8.15.2/Submit) id w637ZtZw020785; Tue, 3 Jul 2018 09:35:55 +0200 Date: Tue, 3 Jul 2018 09:35:55 +0200 From: Jakub Jelinek To: Jason Merrill , Nathan Sidwell Cc: gcc-patches@gcc.gnu.org Subject: [C++ PATCH] Fix extern_decl_map handling (PR c++/3698, PR c++/86208) Message-ID: <20180703073555.GX7166@tucnak> Reply-To: Jakub Jelinek MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.9.2 (2017-12-15) X-IsSubscribed: yes Hi! This testcase got fixed in G++ 3.2, where we used for decision if inline function body should be kept TREE_SYMBOL_REFERENCED (DECL_ASSEMBLER_NAME (...)), but we now use cgraph and the testcase fails again; the particular problem is that we set TREE_USED only on the local extern decl and don't propagate it to the decl that extern_decl_map maps it into. Fixed by the following patch, which propagates it at genericization time. Bootstrapped/regtested on x86_64-linux and i686-linux. Another option is: + /* If decl is local extern, recurse into corresponding decl. */ + if (cfun + && cp_function_chain + && cp_function_chain->extern_decl_map + && VAR_OR_FUNCTION_DECL_P (decl) + && DECL_EXTERNAL (decl)) + { + struct cxx_int_tree_map *h, in; + in.uid = DECL_UID (decl); + h = cp_function_chain->extern_decl_map->find_with_hash (&in, in.uid); + if (h) + TREE_USED (h->to) = 1; + } + in mark_used, another one: + /* If decl is local extern, recurse into corresponding decl. */ + if (cfun + && cp_function_chain + && cp_function_chain->extern_decl_map + && VAR_OR_FUNCTION_DECL_P (decl) + && DECL_EXTERNAL (decl)) + { + struct cxx_int_tree_map *h, in; + in.uid = DECL_UID (decl); + h = cp_function_chain->extern_decl_map->find_with_hash (&in, in.uid); + if (h && !mark_used (h->to)) + return false; + } + in the same spot. None of these fix the PR82204 though. 2018-07-02 Jakub Jelinek PR c++/3698 PR c++/86208 * cp-gimplify.c (cp_genericize_r): When using extern_decl_map, or in TREE_USED flag from stmt to h->to. * g++.dg/opt/pr3698.C: New test. Jakub --- gcc/cp/cp-gimplify.c.jj 2018-06-20 08:15:28.980857357 +0200 +++ gcc/cp/cp-gimplify.c 2018-07-02 18:03:00.714313555 +0200 @@ -1085,6 +1085,7 @@ cp_genericize_r (tree *stmt_p, int *walk if (h) { *stmt_p = h->to; + TREE_USED (h->to) |= TREE_USED (stmt); *walk_subtrees = 0; return NULL; } --- gcc/testsuite/g++.dg/opt/pr3698.C.jj 2018-07-02 18:05:52.535479087 +0200 +++ gcc/testsuite/g++.dg/opt/pr3698.C 2018-07-02 18:05:44.507471531 +0200 @@ -0,0 +1,21 @@ +// PR c++/3698 +// { dg-do link } +// { dg-options "-O0" } + +struct X { + int i; +}; + +inline const int& +OHashKey (const X& x) +{ + return x.i; +} + +int +main () +{ + extern const int& OHashKey (const X& x); + X x; + return OHashKey (x); +}