From e4687bb97616a19432e1b46565b6b6065276b657 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?S=C3=A9bastien=20Villemot?= <sebastien@dynare.org>
Date: Wed, 23 Sep 2020 17:28:18 +0200
Subject: [PATCH] Ensure that negative constants are never marked as temporary
 terms

---
 src/ExprNode.cc | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/src/ExprNode.cc b/src/ExprNode.cc
index a48de883..7d2814be 100644
--- a/src/ExprNode.cc
+++ b/src/ExprNode.cc
@@ -2191,6 +2191,9 @@ UnaryOpNode::cost(const vector<vector<temporary_terms_t>> &blocks_temporary_term
 int
 UnaryOpNode::cost(int cost, bool is_matlab) const
 {
+  if (op_code == UnaryOpcode::uminus && dynamic_cast<NumConstNode *>(arg))
+    return 0; // Cost is zero for a negative constant, as for a positive one
+
   if (is_matlab)
     // Cost for Matlab files
     switch (op_code)
-- 
GitLab