Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: tools/gcmole/gcmole.cc

Issue 2691103008: [gcmole] Fixes for unreachable code (Closed)
Patch Set: Add comment Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/gcmole/gcmole.cc
diff --git a/tools/gcmole/gcmole.cc b/tools/gcmole/gcmole.cc
index 67f676d667165fe1f3c5baa8f4f5d3ede21d2218..f7a6c94c2920742d959cd5ab00f1396d2bc49d59 100644
--- a/tools/gcmole/gcmole.cc
+++ b/tools/gcmole/gcmole.cc
@@ -348,7 +348,7 @@ class Environment {
}
bool Equal(const Environment& env) {
- if (unreachable_) return env.unreachable_;
+ if (unreachable_ && env.unreachable_) return true;
size_t size = std::max(live_.size(), env.live_.size());
for (size_t i = 0; i < size; ++i) {
if (is_live(i) != env.is_live(i)) return false;
@@ -405,7 +405,8 @@ class Environment {
}
void set_live(size_t pos) {
- if (live_.size() <= pos) live_.resize(std::max(pos + 1, 2 * live_.size()));
+ if (unreachable_) return;
+ if (pos >= live_.size()) live_.resize(pos + 1);
live_[pos] = true;
}
@@ -414,19 +415,27 @@ class Environment {
}
Environment& operator|=(const Environment& o) {
- unreachable_ |= o.unreachable_;
- for (size_t i = 0, e = o.live_.size(); i < e; ++i) {
- if (o.live_[i]) set_live(i);
+ if (o.unreachable_) {
+ unreachable_ = true;
+ live_.clear();
+ } else if (!unreachable_) {
+ for (size_t i = 0, e = o.live_.size(); i < e; ++i) {
+ if (o.live_[i]) set_live(i);
+ }
}
return *this;
}
Environment& operator&=(const Environment& o) {
- unreachable_ &= o.unreachable_;
- size_t size = std::min(live_.size(), o.live_.size());
- if (live_.size() > size) live_.resize(size);
+ if (o.unreachable_) return *this;
+ if (unreachable_) return *this = o;
+
+ // Carry over false bits from the tail of o.live_, and reset all bits that
+ // are not set in o.live_.
+ size_t size = std::max(live_.size(), o.live_.size());
+ if (size > live_.size()) live_.resize(size);
for (size_t i = 0; i < size; ++i) {
- if (live_[i] && (i > o.live_.size() || !o.live_[i])) live_[i] = false;
+ if (live_[i] && (i >= o.live_.size() || !o.live_[i])) live_[i] = false;
}
return *this;
}
@@ -435,6 +444,8 @@ class Environment {
static std::vector<Environment*> envs_;
std::vector<bool> live_;
+ // unreachable_ == true implies live_.empty(), but still is_live(i) returns
+ // true for all i.
bool unreachable_ = false;
friend class ExprEffect;
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698