Skip to content

Commit 99345cb

Browse files
authored
Merge pull request #8779 from tautschnig/fix-8144-empty-interval
Fix handling of empty intervals in interval_template.h
2 parents 0985044 + 2a8543e commit 99345cb

File tree

3 files changed

+988
-0
lines changed

3 files changed

+988
-0
lines changed

src/util/interval_template.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,9 @@ template<class T> class interval_templatet
170170

171171
bool is_less_than_eq(const interval_templatet &i)
172172
{
173+
// Empty intervals are less than or equal to any interval
174+
if(empty() || i.empty())
175+
return true;
173176
if(i.lower_set && upper_set && upper <= i.lower)
174177
return true;
175178
else
@@ -178,6 +181,9 @@ template<class T> class interval_templatet
178181

179182
bool is_less_than(const interval_templatet &i)
180183
{
184+
// Empty intervals are less than any interval
185+
if(empty() || i.empty())
186+
return true;
181187
if(i.lower_set && upper_set && upper < i.lower)
182188
return true;
183189
else
@@ -186,6 +192,17 @@ template<class T> class interval_templatet
186192

187193
void approx_union_with(const interval_templatet &i)
188194
{
195+
// If i is empty, union is just this interval
196+
if(i.empty())
197+
return;
198+
199+
// If this interval is empty, union is just i
200+
if(empty())
201+
{
202+
*this = i;
203+
return;
204+
}
205+
189206
if(i.lower_set && lower_set)
190207
lower=std::min(lower, i.lower);
191208
else if(!i.lower_set && lower_set)
@@ -201,6 +218,9 @@ template<class T> class interval_templatet
201218
template<class T>
202219
tvt operator<=(const interval_templatet<T> &a, const interval_templatet<T> &b)
203220
{
221+
// Empty sets compare as less than or equal
222+
if(a.empty() || b.empty())
223+
return tvt(true);
204224
if(a.upper_set && b.lower_set && a.upper<=b.lower)
205225
return tvt(true);
206226
if(a.lower_set && b.upper_set && a.lower>b.upper)
@@ -230,6 +250,10 @@ tvt operator>(const interval_templatet<T> &a, const interval_templatet<T> &b)
230250
template<class T>
231251
bool operator==(const interval_templatet<T> &a, const interval_templatet<T> &b)
232252
{
253+
// Empty sets are always equal
254+
if(a.empty() && b.empty())
255+
return true;
256+
233257
if(a.lower_set!=b.lower_set)
234258
return false;
235259
if(a.upper_set!=b.upper_set)

unit/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ SRC += analyses/ai/ai.cpp \
170170
util/interval/subtract.cpp \
171171
util/interval/to_string.cpp \
172172
util/interval_constraint.cpp \
173+
util/interval_template.cpp \
173174
util/interval_union.cpp \
174175
util/irep.cpp \
175176
util/irep_sharing.cpp \

0 commit comments

Comments
 (0)