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

Side by Side 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 unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2011 the V8 project authors. All rights reserved. 1 // Copyright 2011 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 341
342 typedef std::map<std::string, int> SymbolTable; 342 typedef std::map<std::string, int> SymbolTable;
343 343
344 bool IsAlive(const std::string& name) const { 344 bool IsAlive(const std::string& name) const {
345 SymbolTable::iterator code = symbol_table_.find(name); 345 SymbolTable::iterator code = symbol_table_.find(name);
346 if (code == symbol_table_.end()) return false; 346 if (code == symbol_table_.end()) return false;
347 return is_live(code->second); 347 return is_live(code->second);
348 } 348 }
349 349
350 bool Equal(const Environment& env) { 350 bool Equal(const Environment& env) {
351 if (unreachable_) return env.unreachable_; 351 if (unreachable_ && env.unreachable_) return true;
352 size_t size = std::max(live_.size(), env.live_.size()); 352 size_t size = std::max(live_.size(), env.live_.size());
353 for (size_t i = 0; i < size; ++i) { 353 for (size_t i = 0; i < size; ++i) {
354 if (is_live(i) != env.is_live(i)) return false; 354 if (is_live(i) != env.is_live(i)) return false;
355 } 355 }
356 return true; 356 return true;
357 } 357 }
358 358
359 Environment Define(const std::string& name) const { 359 Environment Define(const std::string& name) const {
360 return Environment(*this, SymbolToCode(name)); 360 return Environment(*this, SymbolToCode(name));
361 } 361 }
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 return allocated_env; 398 return allocated_env;
399 } 399 }
400 400
401 private: 401 private:
402 Environment(const Environment& l, int code) 402 Environment(const Environment& l, int code)
403 : live_(l.live_) { 403 : live_(l.live_) {
404 set_live(code); 404 set_live(code);
405 } 405 }
406 406
407 void set_live(size_t pos) { 407 void set_live(size_t pos) {
408 if (live_.size() <= pos) live_.resize(std::max(pos + 1, 2 * live_.size())); 408 if (unreachable_) return;
409 if (pos >= live_.size()) live_.resize(pos + 1);
409 live_[pos] = true; 410 live_[pos] = true;
410 } 411 }
411 412
412 bool is_live(size_t pos) const { 413 bool is_live(size_t pos) const {
413 return unreachable_ || (live_.size() > pos && live_[pos]); 414 return unreachable_ || (live_.size() > pos && live_[pos]);
414 } 415 }
415 416
416 Environment& operator|=(const Environment& o) { 417 Environment& operator|=(const Environment& o) {
417 unreachable_ |= o.unreachable_; 418 if (o.unreachable_) {
418 for (size_t i = 0, e = o.live_.size(); i < e; ++i) { 419 unreachable_ = true;
419 if (o.live_[i]) set_live(i); 420 live_.clear();
421 } else if (!unreachable_) {
422 for (size_t i = 0, e = o.live_.size(); i < e; ++i) {
423 if (o.live_[i]) set_live(i);
424 }
420 } 425 }
421 return *this; 426 return *this;
422 } 427 }
423 428
424 Environment& operator&=(const Environment& o) { 429 Environment& operator&=(const Environment& o) {
425 unreachable_ &= o.unreachable_; 430 if (o.unreachable_) return *this;
426 size_t size = std::min(live_.size(), o.live_.size()); 431 if (unreachable_) return *this = o;
427 if (live_.size() > size) live_.resize(size); 432
433 // Carry over false bits from the tail of o.live_, and reset all bits that
434 // are not set in o.live_.
435 size_t size = std::max(live_.size(), o.live_.size());
436 if (size > live_.size()) live_.resize(size);
428 for (size_t i = 0; i < size; ++i) { 437 for (size_t i = 0; i < size; ++i) {
429 if (live_[i] && (i > o.live_.size() || !o.live_[i])) live_[i] = false; 438 if (live_[i] && (i >= o.live_.size() || !o.live_[i])) live_[i] = false;
430 } 439 }
431 return *this; 440 return *this;
432 } 441 }
433 442
434 static SymbolTable symbol_table_; 443 static SymbolTable symbol_table_;
435 static std::vector<Environment*> envs_; 444 static std::vector<Environment*> envs_;
436 445
437 std::vector<bool> live_; 446 std::vector<bool> live_;
447 // unreachable_ == true implies live_.empty(), but still is_live(i) returns
448 // true for all i.
438 bool unreachable_ = false; 449 bool unreachable_ = false;
439 450
440 friend class ExprEffect; 451 friend class ExprEffect;
441 friend class CallProps; 452 friend class CallProps;
442 }; 453 };
443 454
444 455
445 class CallProps { 456 class CallProps {
446 public: 457 public:
447 CallProps() : env_(NULL) { } 458 CallProps() : env_(NULL) { }
(...skipping 831 matching lines...) Expand 10 before | Expand all | Expand 10 after
1279 1290
1280 1291
1281 } 1292 }
1282 1293
1283 static clang::FrontendPluginRegistry::Add<Action<ProblemsFinder> > 1294 static clang::FrontendPluginRegistry::Add<Action<ProblemsFinder> >
1284 FindProblems("find-problems", "Find GC-unsafe places."); 1295 FindProblems("find-problems", "Find GC-unsafe places.");
1285 1296
1286 static clang::FrontendPluginRegistry::Add< 1297 static clang::FrontendPluginRegistry::Add<
1287 Action<FunctionDeclarationFinder> > 1298 Action<FunctionDeclarationFinder> >
1288 DumpCallees("dump-callees", "Dump callees for each function."); 1299 DumpCallees("dump-callees", "Dump callees for each function.");
OLDNEW
« 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