From patchwork Tue Jan 24 15:15:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Martin_Li=C5=A1ka?= X-Patchwork-Id: 47740 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2207195wrn; Tue, 24 Jan 2023 07:15:38 -0800 (PST) X-Google-Smtp-Source: AMrXdXvRaHtuc+EvhzQLssGBwmpS6qqfwcjXRxhNZ2uWLByJGXVOCBNYHH9D2JhjGp5jwczRc4LU X-Received: by 2002:a17:907:6c16:b0:86f:3dfa:4016 with SMTP id rl22-20020a1709076c1600b0086f3dfa4016mr33544639ejc.7.1674573337855; Tue, 24 Jan 2023 07:15:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674573337; cv=none; d=google.com; s=arc-20160816; b=Usg3OBbSCe41p4fNM1LlESPUo929qFq7fY48nDn6aMj6EXzSUDt06/NK0W5lkoslgr fwHCh/2dIJKRam8FIRKEsnQnFvL3mpBTA6vYf0n+2To2zA4G6D9F9etJukkhfks2Li3m /ErxBBL2sElZN7LpcY/m22X+Hk6CW4NeQ+o6w13JbYez9fP/Oa20nIs8llO3zY9TLN+o AgJt1od5JY75NAKq1d2ug5+EE6HPh6NBSwK80SuwQTuiMxLsmcz2dDKFcoKUJWfOzK/8 h3AY/RH4ViOBTFeDiZYxQP1Yap9ZZMhZX0Ywz4PlTZ9YR6MvkV6BQIQwEitsy1WksOKF BJ9g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding:cc :content-language:to:subject:from:user-agent:mime-version:date :message-id:dkim-signature:dkim-signature:dmarc-filter:delivered-to; bh=pY58KIQxfAF8Aw+2QSNviTSQLyUOG+4AxmSzMB6jNC0=; b=056LLrpOSK1S8v3MCIJnnTh2SUGLX631a+VbhZTg0doMFDicemrNwBAYJnp9nhiy/f 3Ddy0h1Cd/0wgtg+uyfCPODT/xD7tmpE6a+bsCoQg52IYY2BSWmHrjZz5brQTOnqZ9WR Hn6Avgfz5ChUGgzS99FZTCoDS8NAaNjNgbCfg7lHlSsKrsjk/mBj277wNBdJt4BIJkDe StmFbnPzz7kSszYzKt5T9i+pvzFNHQR3MSY109yFAStGo828ok5ROLetzS8UkdshLkMm D/BHYfP53MlOTdgZ1QJgVn1ZiAH9Egr+LM8VRzArk8+eH2nvMkYD2Q5a7EqzE13RGiq4 t+Yg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Bp5OJR+b; dkim=neutral (no key) header.i=@gcc.gnu.org header.s=susede2_ed25519; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from sourceware.org (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id ev8-20020a17090729c800b00871119f459asi2295636ejc.762.2023.01.24.07.15.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 24 Jan 2023 07:15:37 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@suse.cz header.s=susede2_rsa header.b=Bp5OJR+b; dkim=neutral (no key) header.i=@gcc.gnu.org header.s=susede2_ed25519; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org" Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 5D2ED3858431 for ; Tue, 24 Jan 2023 15:15:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) by sourceware.org (Postfix) with ESMTPS id E286F3858D1E for ; Tue, 24 Jan 2023 15:15:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E286F3858D1E Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=suse.cz Authentication-Results: sourceware.org; spf=fail smtp.mailfrom=suse.cz Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id B432D21904; Tue, 24 Jan 2023 15:15:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_rsa; t=1674573305; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pY58KIQxfAF8Aw+2QSNviTSQLyUOG+4AxmSzMB6jNC0=; b=Bp5OJR+bfG1L96ic73XBVyZwMGAKmb18qMTvg4QghffXwJw0F5YYBc2jji5whttTVd5icX kIxq//kIn58hMlSLNJaQlLnow9setnv46qsiYPmU4dnKwSeL8mI7JR7hNwLRpLIy7rdKpE G691veGEZfdooEi+ydfQfCKB1mly51o= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.cz; s=susede2_ed25519; t=1674573305; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=pY58KIQxfAF8Aw+2QSNviTSQLyUOG+4AxmSzMB6jNC0=; b=XN3kHI5MRBLfpL2DOzy6BvKLvp9jpcNZG/RoIwbfc3LvLt24Ne/cEwVtFrc0HaMTWUCsKm HS63BYqVcCS/oLCQ== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 9C6BC13487; Tue, 24 Jan 2023 15:15:05 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id 6cocJfn1z2PHHwAAMHmgww (envelope-from ); Tue, 24 Jan 2023 15:15:05 +0000 Message-ID: <196e54c5-4ee3-2d0b-3803-8b574eb71b99@suse.cz> Date: Tue, 24 Jan 2023 16:15:05 +0100 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.6.1 From: =?utf-8?q?Martin_Li=C5=A1ka?= Subject: [PATCH] ipa: check if cache_token != NULL before hash_set::add call To: gcc-patches@gcc.gnu.org Content-Language: en-US Cc: Martin Jambor , Jan Hubicka X-Spam-Status: No, score=-11.5 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, SPF_HELO_NONE, SPF_SOFTFAIL, TXREP, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755917412057324127?= X-GMAIL-MSGID: =?utf-8?q?1755917412057324127?= We should not insert an empty value to the container. Patch can bootstrap on x86_64-linux-gnu and survives regression tests. Ready to be installed? Thanks, Martin PR ipa/108509 gcc/ChangeLog: * cgraphunit.cc (walk_polymorphic_call_targets): Insert ony non-null values. * ipa.cc (walk_polymorphic_call_targets): Likewise. gcc/testsuite/ChangeLog: * g++.dg/ipa/pr108509.C: New test. --- gcc/cgraphunit.cc | 2 +- gcc/ipa.cc | 2 +- gcc/testsuite/g++.dg/ipa/pr108509.C | 22 ++++++++++++++++++++++ 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/ipa/pr108509.C diff --git a/gcc/cgraphunit.cc b/gcc/cgraphunit.cc index 832818d651f..a972900900b 100644 --- a/gcc/cgraphunit.cc +++ b/gcc/cgraphunit.cc @@ -1000,7 +1000,7 @@ walk_polymorphic_call_targets (hash_set *reachable_call_targets, = possible_polymorphic_call_targets (edge, &final, &cache_token); - if (!reachable_call_targets->add (cache_token)) + if (cache_token != NULL && !reachable_call_targets->add (cache_token)) { if (symtab->dump_file) dump_possible_polymorphic_call_targets diff --git a/gcc/ipa.cc b/gcc/ipa.cc index 4de605000b6..5c15b60a603 100644 --- a/gcc/ipa.cc +++ b/gcc/ipa.cc @@ -182,7 +182,7 @@ walk_polymorphic_call_targets (hash_set *reachable_call_targets, = possible_polymorphic_call_targets (edge, &final, &cache_token); - if (!reachable_call_targets->add (cache_token)) + if (cache_token != NULL && !reachable_call_targets->add (cache_token)) { for (i = 0; i < targets.length (); i++) { diff --git a/gcc/testsuite/g++.dg/ipa/pr108509.C b/gcc/testsuite/g++.dg/ipa/pr108509.C new file mode 100644 index 00000000000..2844189bbb4 --- /dev/null +++ b/gcc/testsuite/g++.dg/ipa/pr108509.C @@ -0,0 +1,22 @@ +// PR ipa/108509 +// { dg-do compile } +// { dg-options "-O1 -fdevirtualize -fno-tree-fre" } + +struct B { + virtual void deref (); +}; + +struct RefPtr { + B *p; + + RefPtr () + { + p->deref (); + } +}; + +void +f () +{ + RefPtr b; +}