public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r14-9195] analyzer: fix ICE on floating-point bounds [PR111881]
@ 2024-02-27 13:38 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2024-02-27 13:38 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:43ad6ce60108acc822efcd394b75e270c1996cb5

commit r14-9195-g43ad6ce60108acc822efcd394b75e270c1996cb5
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Tue Feb 27 08:36:58 2024 -0500

    analyzer: fix ICE on floating-point bounds [PR111881]
    
    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 <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/constraint-manager.cc                          | 6 ++++++
 gcc/testsuite/c-c++-common/analyzer/conditionals-pr111881.c | 8 ++++++++
 2 files changed, 14 insertions(+)

diff --git a/gcc/analyzer/constraint-manager.cc b/gcc/analyzer/constraint-manager.cc
index e8bcabeb0cd..a380b95315e 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 00000000000..ecf165feeec
--- /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;
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2024-02-27 13:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-27 13:38 [gcc r14-9195] analyzer: fix ICE on floating-point bounds [PR111881] David Malcolm

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).