Skip to content

Commit 5d84b1f

Browse files
committed
Make the custom bitvector analysis actually work
1. has_values was not initialised or used correctly. Fix-up for bda847f 2. merge would never include new values from the other element and was a no-op for the "must" case.
1 parent 34e6b04 commit 5d84b1f

File tree

2 files changed

+38
-29
lines changed

2 files changed

+38
-29
lines changed

src/analyses/custom_bitvector_analysis.cpp

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,6 @@ void custom_bitvector_domaint::transform(
210210
ai_baset &ai,
211211
const namespacet &ns)
212212
{
213-
if(has_values.is_false())
214-
return;
215-
216213
// upcast of ai
217214
custom_bitvector_analysist &cba=
218215
static_cast<custom_bitvector_analysist &>(ai);
@@ -484,44 +481,55 @@ bool custom_bitvector_domaint::merge(
484481
locationt from,
485482
locationt to)
486483
{
487-
if(b.has_values.is_false())
488-
return false; // no change
489-
490-
if(has_values.is_false())
491-
{
492-
*this=b;
493-
return true; // change
494-
}
495-
496-
bool changed=false;
484+
bool changed=has_values.is_false();
485+
has_values=tvt::unknown();
497486

498487
// first do MAY
499-
for(const auto &bit : may_bits)
488+
bitst::iterator it=may_bits.begin();
489+
for(const auto &bit : b.may_bits)
500490
{
501-
bit_vectort &a_bits=may_bits[bit.first];
502-
bit_vectort old=a_bits;
503-
a_bits|=bit.second;
504-
if(old!=a_bits)
491+
while(it!=may_bits.end() && it->first<bit.first)
492+
++it;
493+
if(it==may_bits.end() || bit.first<it->first)
494+
{
495+
may_bits.insert(it, bit);
505496
changed=true;
497+
}
498+
else if(it!=may_bits.end())
499+
{
500+
bit_vectort &a_bits=it->second;
501+
bit_vectort old=a_bits;
502+
a_bits|=bit.second;
503+
if(old!=a_bits)
504+
changed=true;
505+
506+
++it;
507+
}
506508
}
507509

508510
// now do MUST
509-
for(auto &bit : must_bits)
511+
it=must_bits.begin();
512+
for(auto &bit : b.must_bits)
510513
{
511-
bitst::const_iterator b_it=
512-
b.must_bits.find(bit.first);
513-
514-
if(b_it==b.must_bits.end())
514+
while(it!=must_bits.end() && it->first<bit.first)
515515
{
516-
bit.second=0;
516+
it=must_bits.erase(it);
517517
changed=true;
518518
}
519-
else
519+
if(it==must_bits.end() || bit.first<it->first)
520520
{
521-
bit_vectort old=bit.second;
522-
bit.second&=bit.second;
523-
if(old!=bit.second)
521+
must_bits.insert(it, bit);
522+
changed=true;
523+
}
524+
else if(it!=must_bits.end())
525+
{
526+
bit_vectort &a_bits=it->second;
527+
bit_vectort old=a_bits;
528+
a_bits&=bit.second;
529+
if(old!=a_bits)
524530
changed=true;
531+
532+
++it;
525533
}
526534
}
527535

src/analyses/custom_bitvector_analysis.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ class custom_bitvector_domaint:public ai_domain_baset
8787

8888
tvt has_values;
8989

90-
custom_bitvector_domaint():has_values(true)
90+
custom_bitvector_domaint():has_values(false)
9191
{
9292
}
9393

@@ -145,6 +145,7 @@ class custom_bitvector_analysist:public ait<custom_bitvector_domaint>
145145
protected:
146146
virtual void initialize(const goto_functionst &_goto_functions)
147147
{
148+
ait<custom_bitvector_domaint>::initialize(_goto_functions);
148149
local_may_alias_factory(_goto_functions);
149150
}
150151

0 commit comments

Comments
 (0)