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 6D69F3858CDA for ; Mon, 5 Sep 2022 15:57:15 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D69F3858CDA 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=1662393435; h=from:from:reply-to:subject:subject: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=OPXUrzxUD2x5BbFf8+U1V/K584LlnCfLcshoTpVMcCc=; b=MHl2sUjZXgkABI6fdSnZdIKT5+2STt39L8ZwUBg/6rv2ZU1XqXHYvAO0q90TNIX3784El9 EtmObV+jSZ/WtYVfa5R1DRw3aN6wi7v7Ju3ngIf87Mdv5rseK3HTMW5rjSAl/JHq4/2LjF UvQCrZ1m4bSxy7nKUBFleN1TEfyqax0= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-317-aEJsJhQjPs-wAFvfgkNmbg-1; Mon, 05 Sep 2022 11:57:14 -0400 X-MC-Unique: aEJsJhQjPs-wAFvfgkNmbg-1 Received: from smtp.corp.redhat.com (int-mx10.intmail.prod.int.rdu2.redhat.com [10.11.54.10]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id BD45829AB3FB for ; Mon, 5 Sep 2022 15:57:13 +0000 (UTC) Received: from abulafia.quesejoda.com (unknown [10.39.195.195]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 65E3C492C3B; Mon, 5 Sep 2022 15:57:13 +0000 (UTC) Received: from abulafia.quesejoda.com (localhost [127.0.0.1]) by abulafia.quesejoda.com (8.17.1/8.17.1) with ESMTPS id 285FvAAD3420418 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Mon, 5 Sep 2022 17:57:11 +0200 Received: (from aldyh@localhost) by abulafia.quesejoda.com (8.17.1/8.17.1/Submit) id 285FvA7Q3420417; Mon, 5 Sep 2022 17:57:10 +0200 From: Aldy Hernandez To: GCC patches Cc: Andrew MacLeod , Aldy Hernandez Subject: [COMMITTED] [PR middle-end/106824] Do not ICE when updating a NAN to a non-NAN. Date: Mon, 5 Sep 2022 17:57:08 +0200 Message-Id: <20220905155708.3420282-1-aldyh@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.85 on 10.11.54.10 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset="US-ASCII"; x-default=true X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,RCVD_IN_DNSWL_LOW,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE 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: Updating a definite NAN to a definitely not NAN was an assertion failure, but it turns out we can have such a scenario while attempting to thread an impossible path. This patch updates the range to undefined. What happens in the testcase is that we are trying to thread path that starts like this: [local count: 81335936906]: SR.30_3 = Nan; goto ; [100.00%] [local count: 108447915740]: # SR.30_25 = PHI plus_33 = SR.30_25; w1$value__13 = f_distance$D2421$value__1; w2$value__14 = plus_33; if (w1$value__13 == w2$value__14) goto ; [50.00%] else goto ; [50.00%] On the path, SR.30_25 is NAN, which ultimately makes w2$value__14 a NAN. This means that the 7->8 is impossible on the path. On the true arm (foperator_equal::op1_range) we are asserting that op1 (w1$value__13) is a !NAN because for the == conditional to succeed, neither operand can be a NAN. But...we know that operand 2 is a NAN. This is an impossible scenario. We are ICEing because frange::set_nan() sees the NAN and the desire to set the NAN flag to NO. The correct thing to do is to set the range to undefined, which is basically unreachable, and will cause all the right things to happen. For that matter, the threader will see that an UNDEFINED range was calculated in the path and abort trying to investigate paths in that direction. Tested on x86-64 Linux with regstrap as well as mpfr tests. PR middle-end/106824 gcc/ChangeLog: * value-range.cc (frange::set_nan): Set undefined when updating a NAN to a non-NAN. gcc/testsuite/ChangeLog: * g++.dg/pr106824.C: New test. --- gcc/testsuite/g++.dg/pr106824.C | 76 +++++++++++++++++++++++++++++++++ gcc/value-range.cc | 12 +++++- 2 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/pr106824.C diff --git a/gcc/testsuite/g++.dg/pr106824.C b/gcc/testsuite/g++.dg/pr106824.C new file mode 100644 index 00000000000..bd80be0dfaa --- /dev/null +++ b/gcc/testsuite/g++.dg/pr106824.C @@ -0,0 +1,76 @@ +// { dg-do compile } +// { dg-options "-O2 -w -std=c++11" } + +using int32 = int; +int ShortestPath_distance; +struct FloatWeightTpl { + FloatWeightTpl(float f) : value_(f) {} + float Value() { return value_; } + float value_; +}; +template bool operator!=(FloatWeightTpl w1, T w2) { + bool __trans_tmp_2; + FloatWeightTpl __trans_tmp_3 = w1; + __trans_tmp_2 = __trans_tmp_3.Value() == w2.Value(); + return __trans_tmp_2; +} +struct TropicalWeightTpl : FloatWeightTpl { + TropicalWeightTpl(float f) : FloatWeightTpl(f) {} + static TropicalWeightTpl Zero(); + static TropicalWeightTpl NoWeight() { + float __trans_tmp_5 = __builtin_nanf(""); + return __trans_tmp_5; + } + bool Member() { return value_; } +}; +TropicalWeightTpl Plus(TropicalWeightTpl w1, TropicalWeightTpl &w2) { + return w1.Member() || w2.Member() ? TropicalWeightTpl::NoWeight() : w2.Value() ? : w2; +} +TropicalWeightTpl Times(); +struct ArcTpl { + using Weight = TropicalWeightTpl; +}; +template struct ShortestPathOptions { + ShortestPathOptions(int, int, int32, bool, bool); +}; +template +void SingleShortestPath(ShortestPathOptions) { + using Weight = typename Arc::Weight; + auto f_distance = Weight::Zero(); + while (!0) { + TropicalWeightTpl __trans_tmp_1 = Times(), + plus = Plus(f_distance, __trans_tmp_1); + if (f_distance != plus) + f_distance = plus; + } +} +template +void ShortestPath(int, int *, int *, + ShortestPathOptions opts) { + SingleShortestPath(opts); +} +struct ShortestDistanceOptions { + float delta; +}; +struct Trans_NS_script_ShortestPathOptions : ShortestDistanceOptions { + int32 nshortest; + bool unique; +}; +namespace internal { +template +void ShortestPath(int ifst, int *ofst, int *distance, + Trans_NS_script_ShortestPathOptions opts) { + using ArcFilter = int; + ShortestPathOptions sopts(opts.nshortest, opts.unique, + false, opts.delta, 0); + ShortestPath(ifst, ofst, distance, sopts); +} +int ShortestPath_ifst; +int ShortestPath_ofst; +Trans_NS_script_ShortestPathOptions ShortestPath_opts; +void ShortestPath() { + using StateId = int; + ShortestPath(ShortestPath_ifst, &ShortestPath_ofst, + &ShortestPath_distance, ShortestPath_opts); +} +} // namespace internal diff --git a/gcc/value-range.cc b/gcc/value-range.cc index 9c561415971..c3f668a811a 100644 --- a/gcc/value-range.cc +++ b/gcc/value-range.cc @@ -274,13 +274,21 @@ frange::set_nan (fp_prop::kind k) { if (k == fp_prop::YES) { + if (get_nan ().no_p ()) + { + set_undefined (); + return; + } gcc_checking_assert (!undefined_p ()); *this = frange_nan (m_type); return; } - // Setting NO on an obviously NAN range is nonsensical. - gcc_checking_assert (k != fp_prop::NO || !real_isnan (&m_min)); + if (k == fp_prop::NO && get_nan ().yes_p ()) + { + set_undefined (); + return; + } // Setting VARYING on an obviously NAN range is a no-op. if (k == fp_prop::VARYING && real_isnan (&m_min)) -- 2.37.1