Skip to content

Commit cdd9ca6

Browse files
committed
Fix reaching definitions merge
1 parent f09dedc commit cdd9ca6

File tree

3 files changed

+78
-23
lines changed

3 files changed

+78
-23
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
int g_x;
2+
int g_y;
3+
4+
int x;
5+
int y;
6+
7+
void main(void)
8+
{
9+
g_x = g_y;
10+
x = y;
11+
12+
g_y = 1;
13+
y = 1;
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
CORE
2+
main.c
3+
--show --dependence-graph --periodic-task --json -
4+
activate-multi-line-match
5+
EXIT=0
6+
SIGNAL=0
7+
"line": "2",\n.*\n.*\n\s*"task": "first"
8+
"line": "12",\n.*\n.*\n\s*"task": "later"
9+
"line": "5",\n.*\n.*\n\s*"task": "first"
10+
"line": "13",\n.*\n.*\n\s*"task": "later"
11+
--
12+
^warning: ignoring
13+
--

src/analyses/reaching_definitions.cpp

Lines changed: 51 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Author: Michael Tautschnig
1616

1717
#include "reaching_definitions.h"
1818

19+
#include <algorithm>
1920
#include <memory>
2021

2122
#include <util/pointer_offset_size.h>
@@ -575,51 +576,78 @@ bool rd_range_domaint::merge(
575576
locationt from,
576577
locationt to)
577578
{
578-
bool changed=false;
579+
bool changed = false;
579580

580-
if(other.has_values.is_false())
581+
if(other.is_bottom())
581582
{
582-
assert(other.values.empty());
583583
return false;
584584
}
585585

586-
if(has_values.is_false())
586+
if(is_bottom())
587587
{
588-
assert(values.empty());
589-
values=other.values;
590-
assert(!other.has_values.is_true());
591-
has_values=other.has_values;
588+
values = other.values;
589+
590+
INVARIANT(!other.is_top(), "top unused");
591+
has_values = other.has_values;
592+
592593
return true;
593594
}
594-
rd_range_domaint &o=const_cast<rd_range_domaint &>(other);
595+
596+
rd_range_domaint &o =
597+
const_cast<rd_range_domaint &>(other);
595598
values.swap(o.values);
596-
valuest::delta_viewt delta_view;
597-
o.values.get_delta_view(values, delta_view);
599+
600+
{
601+
// Needed to set changed
602+
typename valuest::delta_viewt delta_view_test;
603+
values.get_delta_view(o.values, delta_view_test, false);
604+
605+
for(const auto &element : delta_view_test)
606+
{
607+
if(!element.in_both)
608+
{
609+
changed = true;
610+
break;
611+
}
612+
}
613+
}
614+
615+
typename valuest::delta_viewt delta_view;
616+
o.values.get_delta_view(values, delta_view, false);
617+
598618
for(const auto &element : delta_view)
599619
{
600-
bool in_both=element.in_both;
601-
const irep_idt &k=element.k;
602-
const values_innert &inner_other=element.m; // in other
603-
const values_innert &inner=element.other_m; // in this
620+
bool in_both = element.in_both;
621+
const irep_idt &k = element.k;
622+
const values_innert &inner_other = element.m; // in other
623+
const values_innert &inner = element.other_m; // in this
604624

605625
if(!in_both)
606626
{
607627
values.insert(k, inner_other);
608-
changed=true;
609628
}
610629
else
611630
{
612-
if(inner!=inner_other)
631+
bool inner_is_superset = std::includes(
632+
inner.begin(), inner.end(), inner_other.begin(), inner_other.end());
633+
634+
if(!inner_is_superset)
613635
{
614-
auto &v=values.find(k);
615-
assert(v.second);
636+
auto &v = values.find(k);
637+
INVARIANT(v.second, "key exists as in_both is true");
616638

617-
values_innert &inner=v.first;
639+
values_innert &inner = v.first;
640+
const values_innert copy(inner_other);
618641

619-
size_t n=inner.size();
620642
inner.insert(inner_other.begin(), inner_other.end());
621-
if(inner.size()!=n)
622-
changed=true;
643+
644+
if(inner != copy)
645+
changed = true;
646+
}
647+
else
648+
{
649+
if(inner != inner_other)
650+
changed = true;
623651
}
624652
}
625653
}

0 commit comments

Comments
 (0)