public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc r12-6700] analyzer: fix ICE on unary ops folding to casts of constants [PR104089]
@ 2022-01-18 20:57 David Malcolm
  0 siblings, 0 replies; only message in thread
From: David Malcolm @ 2022-01-18 20:57 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:2aefe248aa4160205c44808166393a42031d2dea

commit r12-6700-g2aefe248aa4160205c44808166393a42031d2dea
Author: David Malcolm <dmalcolm@redhat.com>
Date:   Tue Jan 18 11:41:19 2022 -0500

    analyzer: fix ICE on unary ops folding to casts of constants [PR104089]
    
    gcc/analyzer/ChangeLog:
            PR analyzer/104089
            * region-model-manager.cc
            (region_model_manager::get_or_create_constant_svalue): Assert that
            we have a CONSTANT_CLASS_P.
            (region_model_manager::maybe_fold_unaryop): Only fold a constant
            when fold_unary's result is a constant or a cast of a constant.
    
    gcc/testsuite/ChangeLog:
            * gcc.dg/analyzer/pr104089.c: New test.
            PR analyzer/104089
    
    Signed-off-by: David Malcolm <dmalcolm@redhat.com>

Diff:
---
 gcc/analyzer/region-model-manager.cc     | 19 ++++++++++++++++++-
 gcc/testsuite/gcc.dg/analyzer/pr104089.c |  9 +++++++++
 2 files changed, 27 insertions(+), 1 deletion(-)

diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc
index 9d4f5952ef3..bb93526807f 100644
--- a/gcc/analyzer/region-model-manager.cc
+++ b/gcc/analyzer/region-model-manager.cc
@@ -209,6 +209,7 @@ const svalue *
 region_model_manager::get_or_create_constant_svalue (tree cst_expr)
 {
   gcc_assert (cst_expr);
+  gcc_assert (CONSTANT_CLASS_P (cst_expr));
 
   constant_svalue **slot = m_constants_map.get (cst_expr);
   if (slot)
@@ -426,7 +427,23 @@ region_model_manager::maybe_fold_unaryop (tree type, enum tree_code op,
   /* Constants.  */
   if (tree cst = arg->maybe_get_constant ())
     if (tree result = fold_unary (op, type, cst))
-      return get_or_create_constant_svalue (result);
+      {
+	if (CONSTANT_CLASS_P (result))
+	  return get_or_create_constant_svalue (result);
+
+	/* fold_unary can return casts of constants; try to handle them.  */
+	if (op != NOP_EXPR
+		 && type
+		 && TREE_CODE (result) == NOP_EXPR
+		 && CONSTANT_CLASS_P (TREE_OPERAND (result, 0)))
+	  {
+	    const svalue *inner_cst
+	      = get_or_create_constant_svalue (TREE_OPERAND (result, 0));
+	    return get_or_create_cast (type,
+				       get_or_create_cast (TREE_TYPE (result),
+							   inner_cst));
+	  }
+      }
 
   return NULL;
 }
diff --git a/gcc/testsuite/gcc.dg/analyzer/pr104089.c b/gcc/testsuite/gcc.dg/analyzer/pr104089.c
new file mode 100644
index 00000000000..c51770411f1
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/analyzer/pr104089.c
@@ -0,0 +1,9 @@
+/* { dg-additional-options "-frounding-math" } */
+
+volatile _Float16 true_min = 5.96046447753906250000000000000000000e-8F16;
+
+int
+main (void)
+{
+  return __builtin_fpclassify (0, 1, 4, 3, 2, true_min);
+}


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

only message in thread, other threads:[~2022-01-18 20:57 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-18 20:57 [gcc r12-6700] analyzer: fix ICE on unary ops folding to casts of constants [PR104089] 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).