From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id E31E638582B0 for ; Fri, 17 Mar 2023 14:52:49 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org E31E638582B0 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1679064769; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:in-reply-to:in-reply-to: references:references; bh=/8y2tzVB5AUlT4HWuU0RZuG/mY6DZnT1oGlYlyou3kM=; b=QAnooAKDgCVri7zoNKrQQ145UznlBB0kz4J+y7eY6GQQBMFlRL/ZK8SOX3B3ZLT5OH/y7G bR8338rrwXS4NLj8DPFyz3X27MMHtpVQDJA2uSpcNcWEhMEG7vrCNQbaBCD3S7utTRvgDO q5opu4+HEA6P8WLX2os9+6IHLaeQ1/o= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-503-qrcIgROSM2-STGeZaJ20zA-1; Fri, 17 Mar 2023 10:52:46 -0400 X-MC-Unique: qrcIgROSM2-STGeZaJ20zA-1 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.rdu2.redhat.com [10.11.54.6]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 24336185A791; Fri, 17 Mar 2023 14:52:46 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.192.16]) by smtp.corp.redhat.com (Postfix) with ESMTPS id D71142166B26; Fri, 17 Mar 2023 14:52:45 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 32HEqhPA943446 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Fri, 17 Mar 2023 15:52:43 +0100 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 32HEqgpB943445; Fri, 17 Mar 2023 15:52:42 +0100 Date: Fri, 17 Mar 2023 15:52:42 +0100 From: Jakub Jelinek To: Richard Biener Cc: gcc-patches@gcc.gnu.org, aldyh@redhat.com, amacleod@redhat.com Subject: Re: [PATCH] tree-optimization/109170 - bogus use-after-free with __builtin_expect Message-ID: Reply-To: Jakub Jelinek References: <20230317121833.16A961346F@imap2.suse-dmz.suse.de> MIME-Version: 1.0 In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.6 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On Fri, Mar 17, 2023 at 02:18:52PM +0000, Richard Biener wrote: > > And as you show on the testcases, it probably isn't a good idea for > > BUILT_IN_EXPECT* either. > > > > So, perhaps use op_cfn_pass_through_arg1 for the ERF_RETURNS_ARG functions > > and BUILT_IN_EXPECT* ? > > But that already causes the problems (I didn't yet finish testing > adding RET1 to BUILT_IN_EXPECT*). Note FRE currently does not use > returns_arg but I have old patches that do - but those replace > uses after a RET1 function with the return value to also reduce > spilling around a call (they of course CSE equal calls). I meant in your patch drop the builtins.cc hunk and add from your other patch > > + case CFN_BUILT_IN_EXPECT: > > + case CFN_BUILT_IN_EXPECT_WITH_PROBABILITY: > > + m_valid = true; > > + m_op1 = gimple_call_arg (call, 0); > > + m_int = &op_cfn_pass_through_arg1; > > + break; hunk to gimple_range_op_handler::maybe_builtin_call. Does that already cause the problems? I mean, if we e.g. see that a range of the argument is singleton, then it is fine to optimize the __builtin_expect away. Jakub