diff mbox series

[committed] analyzer: fold -(-(VAL)) to VAL

Message ID 20221005002423.710736-1-dmalcolm@redhat.com
State New
Headers show
Series [committed] analyzer: fold -(-(VAL)) to VAL | expand

Commit Message

David Malcolm Oct. 5, 2022, 12:24 a.m. UTC
Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
Pushed to trunk as r13-3075-g7f42f7adfa69fe.

gcc/analyzer/ChangeLog:
	* region-model-manager.cc
	(region_model_manager::maybe_fold_unaryop): Fold -(-(VAL)) to VAL.

Signed-off-by: David Malcolm <dmalcolm@redhat.com>
---
 gcc/analyzer/region-model-manager.cc | 11 +++++++++++
 1 file changed, 11 insertions(+)
diff mbox series

Patch

diff --git a/gcc/analyzer/region-model-manager.cc b/gcc/analyzer/region-model-manager.cc
index ed5b9c75910..1956cfc3e8d 100644
--- a/gcc/analyzer/region-model-manager.cc
+++ b/gcc/analyzer/region-model-manager.cc
@@ -432,6 +432,17 @@  region_model_manager::maybe_fold_unaryop (tree type, enum tree_code op,
 	    }
       }
       break;
+    case NEGATE_EXPR:
+      {
+	/* -(-(VAL)) is VAL, for integer types.  */
+	if (const unaryop_svalue *unaryop = arg->dyn_cast_unaryop_svalue ())
+	  if (unaryop->get_op () == NEGATE_EXPR
+	      && type == unaryop->get_type ()
+	      && type
+	      && INTEGRAL_TYPE_P (type))
+	    return unaryop->get_arg ();
+      }
+      break;
     }
 
   /* Constants.  */