From patchwork Thu Jun 20 04:24:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 1119113 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-503321-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=oracle.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="MPTeryFP"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=oracle.com header.i=@oracle.com header.b="x7PXnRqf"; 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 45Tpcw29yKz9s00 for ; Thu, 20 Jun 2019 14:24:46 +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:to:cc :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=qZCwL7p1fsAXuARj7fW+7cE47PNoSifBHyiQucQSz7lpWsfuY3 OcJDU8yEJg5LrTydlFQo+QEXvgUpH1F6YF0OrmqAo0Fyq5eeAMnZHrxYHiPqZsIy 6xXfW3Iu8hnLJ0zp22NuAqJHG96AkSLXtdFwTrS2eQaS5nr9sGk68cfVY= 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=31BmYcsiLC65EDorfHJwdokdsps=; b=MPTeryFPRXM+pEAt2KMj LkAKxifk1zXwLOI/LovGcSdsFmXIFy6iStAfkn/mE8B7rgrfrMoiyK7kA4d/Bl56 2D+f01DN4bExjxhbU3RTOyb21OWNUHHgvxXW6MrFWoCarkzwZbvbaJypoPwbRIkX qMZL6MDu1srdKC8gH10ZU5E= Received: (qmail 13568 invoked by alias); 20 Jun 2019 04:24:38 -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 12933 invoked by uid 89); 20 Jun 2019 04:24:37 -0000 Authentication-Results: sourceware.org; auth=none X-Spam-SWARE-Status: No, score=-8.7 required=5.0 tests=AWL, BAYES_05, GIT_PATCH_2, GIT_PATCH_3, KAM_ASCII_DIVIDERS, SPF_HELO_PASS autolearn=ham version=3.3.1 spammy=cure, HX-Spam-Relays-External:192.168.1.4, H*r:ip*192.168.1.4, H*RU:192.168.1.4 X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Thu, 20 Jun 2019 04:24:36 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5K4JFHC046274; Thu, 20 Jun 2019 04:24:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=to : cc : from : subject : message-id : date : mime-version : content-type; s=corp-2018-07-02; bh=D6JJ/RJ+Wz1i8PZiYJwYKreY3wYUMuuz1ruwcRNSgtc=; b=x7PXnRqfUGs2Q+LfyT+dXEQK6GlzkSISu/UFgroE989LqvknTflo00n6XAY0hYIit1TZ dhVQXojnS/FEWHlzxQWaJ7g0mUMChVNKu7ENyQziojxdm53wMdW39EVvgX/0oKZvqxqg hQ6tHHD6H8/hLR/M7RM8VPcQTzlar5MUiV1Rl6irOT7bR2avJocB/DtGw7pWmm84Jv4e cf9NoNjAndXGqzzsJM8q2J0Dnv1V+bZq/G99OOsY1odGCMojqR9dbwmctYlEf1eeV7MM Qvc6GsvWO1eWImxT3G6+LjjkdE7HrYh2Xqr6boF2Et0DasXE1+vXTGwDmYe/ETR4/9bc aA== Received: from userp3030.oracle.com (userp3030.oracle.com [156.151.31.80]) by userp2130.oracle.com with ESMTP id 2t7809esmf-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2019 04:24:34 +0000 Received: from pps.filterd (userp3030.oracle.com [127.0.0.1]) by userp3030.oracle.com (8.16.0.27/8.16.0.27) with SMTP id x5K4NdS1164277; Thu, 20 Jun 2019 04:24:34 GMT Received: from userv0121.oracle.com (userv0121.oracle.com [156.151.31.72]) by userp3030.oracle.com with ESMTP id 2t77yne646-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Jun 2019 04:24:33 +0000 Received: from abhmp0018.oracle.com (abhmp0018.oracle.com [141.146.116.24]) by userv0121.oracle.com (8.14.4/8.13.8) with ESMTP id x5K4OW1E017726; Thu, 20 Jun 2019 04:24:32 GMT Received: from [192.168.1.4] (/87.13.236.52) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 19 Jun 2019 21:24:31 -0700 To: "gcc-patches@gcc.gnu.org" Cc: Jason Merrill From: Paolo Carlini Subject: [C++ Patch] PR 90909 ("[10 Regression] call devirtualized to pure virtual") Message-ID: <44e13170-109c-e540-9fc5-0c8e24737a96@oracle.com> Date: Thu, 20 Jun 2019 06:24:29 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 X-IsSubscribed: yes Hi, this bug notices that the more aggressive de-virtualization check that we have now in place (fixed c++/67184) doesn't work correctly for the below reproducer, which involves a pure virtual: we de-virtualize and the build fails at link-time. To cure this I believe we simply want an additional DECL_PURE_VIRTUAL_P in the condition. I also checked that the other compilers I have at hand appear to do the same, that is, they compile the reproducer both as-is and without the final specifier to the same assembly. Note, in principle we have the option of not doing the additional DECL_PURE_VIRTUAL_P check when the final overrider comes from the class itself, not from a base, that is in the cases that we were already de-virtualizing pre-67184. That is, for something like: struct A final {   virtual void foo () = 0; }; void fun(A* a, B* b) {   a->foo(); } devirtualize anyway (which then doesn't link). We could add back an '|| CLASSTYPE_FINAL (TYPE_METHOD_BASETYPE (TREE_TYPE (fn)))' for that. ICC appears to behave this way. Tested x86_64-linux. Thanks, Paolo. //////////////////////// /cp 2019-06-20 Paolo Carlini PR c++/90909 * call.c (build_over_call): Do not try to devirtualize when then function is pure virtual. /testsuite 2019-06-20 Paolo Carlini PR c++/90909 * g++.dg/other/final6.C: New. Index: testsuite/g++.dg/other/final6.C =================================================================== --- testsuite/g++.dg/other/final6.C (nonexistent) +++ testsuite/g++.dg/other/final6.C (working copy) @@ -0,0 +1,9 @@ +// PR c++/90909 +// { dg-do link { target c++11 } } + +struct S1 { virtual void f() = 0; }; +struct S2: S1 { virtual void f() {} }; +struct S3: S2 { using S1::f; }; +struct S4 final: S3 { void g(); }; +void S4::g() { f(); } +int main() { S4().g(); } Index: cp/call.c =================================================================== --- cp/call.c (revision 272410) +++ cp/call.c (working copy) @@ -8244,7 +8244,8 @@ build_over_call (struct z_candidate *cand, int fla /* See if the function member or the whole class type is declared final and the call can be devirtualized. */ if (DECL_FINAL_P (fn) - || CLASSTYPE_FINAL (TREE_TYPE (argtype))) + || (CLASSTYPE_FINAL (TREE_TYPE (argtype)) + && !DECL_PURE_VIRTUAL_P (fn))) flags |= LOOKUP_NONVIRTUAL; /* [class.mfct.nonstatic]: If a nonstatic member function of a class