aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-ssa-loop-ivopts.c
diff options
context:
space:
mode:
authorBin Cheng <bin.cheng@linux.alibaba.com>2019-04-23 04:07:46 +0000
committerBin Cheng <amker@gcc.gnu.org>2019-04-23 04:07:46 +0000
commit4b5689aa6c285429368b8bc9eef2b186162ff78d (patch)
tree8e9b3df727ba818a867f1f45c4bf618bf87b870a /gcc/tree-ssa-loop-ivopts.c
parent9e14603dfeba1fc1d54f2373de20eea7469ee0c3 (diff)
downloadgcc-4b5689aa6c285429368b8bc9eef2b186162ff78d.zip
gcc-4b5689aa6c285429368b8bc9eef2b186162ff78d.tar.gz
gcc-4b5689aa6c285429368b8bc9eef2b186162ff78d.tar.bz2
re PR tree-optimization/90078 (ICE with deep templates caused by overflow)
PR tree-optimization/90078 * tree-ssa-loop-ivopts.c (comp_cost::operator +,-,+=,-+,/=,*=): Add checks for infinite_cost overflow. gcc/testsuite * gcc/testsuite/g++.dg/tree-ssa/pr90078.C: New test. Also fix typo in ChangeLog entry for revision 270499. From-SVN: r270500
Diffstat (limited to 'gcc/tree-ssa-loop-ivopts.c')
-rw-r--r--gcc/tree-ssa-loop-ivopts.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/tree-ssa-loop-ivopts.c b/gcc/tree-ssa-loop-ivopts.c
index a2b6b2b..4ca1f0e 100644
--- a/gcc/tree-ssa-loop-ivopts.c
+++ b/gcc/tree-ssa-loop-ivopts.c
@@ -243,6 +243,9 @@ operator+ (comp_cost cost1, comp_cost cost2)
if (cost1.infinite_cost_p () || cost2.infinite_cost_p ())
return infinite_cost;
+ if (cost1.cost + cost2.cost >= infinite_cost.cost)
+ return infinite_cost;
+
cost1.cost += cost2.cost;
cost1.complexity += cost2.complexity;
@@ -256,6 +259,8 @@ operator- (comp_cost cost1, comp_cost cost2)
return infinite_cost;
gcc_assert (!cost2.infinite_cost_p ());
+ if (cost1.cost - cost2.cost >= infinite_cost.cost)
+ return infinite_cost;
cost1.cost -= cost2.cost;
cost1.complexity -= cost2.complexity;
@@ -276,6 +281,8 @@ comp_cost::operator+= (HOST_WIDE_INT c)
if (infinite_cost_p ())
return *this;
+ if (this->cost + c >= infinite_cost.cost)
+ return infinite_cost;
this->cost += c;
return *this;
@@ -287,6 +294,8 @@ comp_cost::operator-= (HOST_WIDE_INT c)
if (infinite_cost_p ())
return *this;
+ if (this->cost - c >= infinite_cost.cost)
+ return infinite_cost;
this->cost -= c;
return *this;
@@ -295,6 +304,7 @@ comp_cost::operator-= (HOST_WIDE_INT c)
comp_cost
comp_cost::operator/= (HOST_WIDE_INT c)
{
+ gcc_assert (c != 0);
if (infinite_cost_p ())
return *this;
@@ -309,6 +319,9 @@ comp_cost::operator*= (HOST_WIDE_INT c)
if (infinite_cost_p ())
return *this;
+ if (this->cost * c >= infinite_cost.cost)
+ return infinite_cost;
+
this->cost *= c;
return *this;