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: 63623 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8DA44385842C for ; Tue, 24 Jan 2023 15:15:25 +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+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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; +}