From patchwork Tue Feb 27 13:41:14 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Malcolm X-Patchwork-Id: 86444 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 B5EF43858438 for ; Tue, 27 Feb 2024 13:41:48 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 7527D3858433 for ; Tue, 27 Feb 2024 13:41:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 7527D3858433 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 7527D3858433 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709041278; cv=none; b=I/8nQr1NgUkAQ0tPtd407uoAWE4qQ6/9cuwKfnNkPmeS+HsOUkcekIwQoceGpKyzCc7+GBsDG2oTeN9nKRbG6gOQSYz36B3cw0ZvbwF4qpAmEL7eufg0vgI6sgFh9hOq0n354Ibuh/HBiZrGkUJmzupaTue3qISyIVnOuN1QCJc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709041278; c=relaxed/simple; bh=N0h5fRk3I33HXMwWkBqqdLh7r7m6NJc2IGCtfQ9fdqY=; h=DKIM-Signature:From:To:Subject:Date:Message-Id:MIME-Version; b=lNmf7hENa4sAIKYv9+BT4j1HNPvBarmeeCp0k/Pg9vvKadMJh3Std3u2MXl41ZAb8UuSRZJR8CgnlF6k/Q4aaB3r/VTKUG6DTqwhgZbsRj6AJTR8wg6A/N4AZvLDJXD8LP15tnF11FIpW5LmrLm0daptsHW0ZL++PTPwZS7rsfk= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1709041277; 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=SothdChf8C4qtrMXDEBI49sB/D18duW8M25mWp/inTI=; b=L4bH8Mt0nMRtdPiL4Cceqkv6nkNgAtPt8ABgw7MXpCKTLNwv9sIQkgxMWSvkATSFqLM63Z 56gncJU96u2e++0iGMxfMwu1jK28oQ1JdEK378v32bJWM8WqagmWF6D+qoQBcWaePjyNqN OXsVogvllSdYtXWv4OxWW5n9iYIKSMM= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-210-k057MUMWMG-R_IXiw2hk-Q-1; Tue, 27 Feb 2024 08:41:15 -0500 X-MC-Unique: k057MUMWMG-R_IXiw2hk-Q-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 683C58828C1 for ; Tue, 27 Feb 2024 13:41:15 +0000 (UTC) Received: from t14s.localdomain.com (unknown [10.22.9.138]) by smtp.corp.redhat.com (Postfix) with ESMTP id 405CF1BDB1; Tue, 27 Feb 2024 13:41:15 +0000 (UTC) From: David Malcolm To: gcc-patches@gcc.gnu.org Cc: David Malcolm Subject: [pushed] analyzer: fix ICE on floating-point bounds [PR111881] Date: Tue, 27 Feb 2024 08:41:14 -0500 Message-Id: <20240227134114.3490126-1-dmalcolm@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.5 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-11.5 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_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, 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 X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.30 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 Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu. Successful run of analyzer integration tests on x86_64-pc-linux-gnu. Pushed to trunk as r14-9195-g43ad6ce60108ac. gcc/analyzer/ChangeLog: PR analyzer/111881 * constraint-manager.cc (bound::ensure_closed): Assert that m_constant has integral type. (range::add_bound): Bail out on floating point constants. gcc/testsuite/ChangeLog: PR analyzer/111881 * c-c++-common/analyzer/conditionals-pr111881.c: New test. Signed-off-by: David Malcolm --- gcc/analyzer/constraint-manager.cc | 6 ++++++ .../c-c++-common/analyzer/conditionals-pr111881.c | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 gcc/testsuite/c-c++-common/analyzer/conditionals-pr111881.c diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc index e8bcabeb0cd5..a380b95315ee 100644 --- a/gcc/analyzer/constraint-manager.cc +++ b/gcc/analyzer/constraint-manager.cc @@ -124,10 +124,12 @@ bound::ensure_closed (enum bound_kind bound_kind) For example, convert 3 < x into 4 <= x, and convert x < 5 into x <= 4. */ gcc_assert (CONSTANT_CLASS_P (m_constant)); + gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (m_constant))); m_constant = fold_build2 (bound_kind == BK_UPPER ? MINUS_EXPR : PLUS_EXPR, TREE_TYPE (m_constant), m_constant, integer_one_node); gcc_assert (CONSTANT_CLASS_P (m_constant)); + gcc_assert (INTEGRAL_TYPE_P (TREE_TYPE (m_constant))); m_closed = true; } } @@ -306,6 +308,10 @@ range::above_upper_bound (tree rhs_const) const bool range::add_bound (bound b, enum bound_kind bound_kind) { + /* Bail out on floating point constants. */ + if (!INTEGRAL_TYPE_P (TREE_TYPE (b.m_constant))) + return true; + b.ensure_closed (bound_kind); switch (bound_kind) diff --git a/gcc/testsuite/c-c++-common/analyzer/conditionals-pr111881.c b/gcc/testsuite/c-c++-common/analyzer/conditionals-pr111881.c new file mode 100644 index 000000000000..ecf165feeec2 --- /dev/null +++ b/gcc/testsuite/c-c++-common/analyzer/conditionals-pr111881.c @@ -0,0 +1,8 @@ +/* Verify we don't ICE on certain float conditionals. */ + +/* { dg-additional-options "-Ofast" } */ + +int test_pr111881 (float sf1) +{ + return sf1 <= 0 || sf1 >= 7 ? 0 : sf1; +}