OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // This clang plugin checks various invariants of the Blink garbage | 5 // This clang plugin checks various invariants of the Blink garbage |
6 // collection infrastructure. | 6 // collection infrastructure. |
7 // | 7 // |
8 // Errors are described at: | 8 // Errors are described at: |
9 // http://www.chromium.org/developers/blink-gc-plugin-errors | 9 // http://www.chromium.org/developers/blink-gc-plugin-errors |
10 | 10 |
(...skipping 468 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
479 for (RecordInfo::Fields::iterator it = info->GetFields().begin(); | 479 for (RecordInfo::Fields::iterator it = info->GetFields().begin(); |
480 it != info->GetFields().end(); | 480 it != info->GetFields().end(); |
481 ++it) { | 481 ++it) { |
482 context().clear(); | 482 context().clear(); |
483 current_ = &it->second; | 483 current_ = &it->second; |
484 current_->edge()->Accept(this); | 484 current_->edge()->Accept(this); |
485 } | 485 } |
486 return !invalid_fields_.empty(); | 486 return !invalid_fields_.empty(); |
487 } | 487 } |
488 | 488 |
489 void VisitMember(Member* edge) override { | 489 void AtMember(Member* edge) override { |
490 if (managed_host_) | 490 if (managed_host_) |
491 return; | 491 return; |
492 // A member is allowed to appear in the context of a root. | 492 // A member is allowed to appear in the context of a root. |
493 for (Context::iterator it = context().begin(); | 493 for (Context::iterator it = context().begin(); |
494 it != context().end(); | 494 it != context().end(); |
495 ++it) { | 495 ++it) { |
496 if ((*it)->Kind() == Edge::kRoot) | 496 if ((*it)->Kind() == Edge::kRoot) |
497 return; | 497 return; |
498 } | 498 } |
499 invalid_fields_.push_back(std::make_pair(current_, kMemberInUnmanaged)); | 499 invalid_fields_.push_back(std::make_pair(current_, kMemberInUnmanaged)); |
500 } | 500 } |
501 | 501 |
502 void VisitValue(Value* edge) override { | 502 void AtValue(Value* edge) override { |
503 // TODO: what should we do to check unions? | 503 // TODO: what should we do to check unions? |
504 if (edge->value()->record()->isUnion()) | 504 if (edge->value()->record()->isUnion()) |
505 return; | 505 return; |
506 | 506 |
507 if (!stack_allocated_host_ && edge->value()->IsStackAllocated()) { | 507 if (!stack_allocated_host_ && edge->value()->IsStackAllocated()) { |
508 invalid_fields_.push_back(std::make_pair(current_, kPtrFromHeapToStack)); | 508 invalid_fields_.push_back(std::make_pair(current_, kPtrFromHeapToStack)); |
509 return; | 509 return; |
510 } | 510 } |
511 | 511 |
512 if (!Parent() && | 512 if (!Parent() && |
(...skipping 20 matching lines...) Expand all Loading... |
533 return; | 533 return; |
534 } | 534 } |
535 | 535 |
536 if (Parent()->IsRawPtr() || Parent()->IsRefPtr() || Parent()->IsOwnPtr()) { | 536 if (Parent()->IsRawPtr() || Parent()->IsRefPtr() || Parent()->IsOwnPtr()) { |
537 invalid_fields_.push_back(std::make_pair( | 537 invalid_fields_.push_back(std::make_pair( |
538 current_, InvalidSmartPtr(Parent()))); | 538 current_, InvalidSmartPtr(Parent()))); |
539 return; | 539 return; |
540 } | 540 } |
541 } | 541 } |
542 | 542 |
| 543 void AtCollection(Collection* edge) override { |
| 544 if (edge->on_heap() && Parent() && Parent()->IsOwnPtr()) |
| 545 invalid_fields_.push_back(std::make_pair(current_, kOwnPtrToGCManaged)); |
| 546 } |
| 547 |
543 private: | 548 private: |
544 Error InvalidSmartPtr(Edge* ptr) { | 549 Error InvalidSmartPtr(Edge* ptr) { |
545 if (ptr->IsRawPtr()) | 550 if (ptr->IsRawPtr()) |
546 return kRawPtrToGCManaged; | 551 return kRawPtrToGCManaged; |
547 if (ptr->IsRefPtr()) | 552 if (ptr->IsRefPtr()) |
548 return kRefPtrToGCManaged; | 553 return kRefPtrToGCManaged; |
549 if (ptr->IsOwnPtr()) | 554 if (ptr->IsOwnPtr()) |
550 return kOwnPtrToGCManaged; | 555 return kOwnPtrToGCManaged; |
551 assert(false && "Unknown smart pointer kind"); | 556 assert(false && "Unknown smart pointer kind"); |
552 } | 557 } |
(...skipping 919 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1472 | 1477 |
1473 private: | 1478 private: |
1474 BlinkGCPluginOptions options_; | 1479 BlinkGCPluginOptions options_; |
1475 }; | 1480 }; |
1476 | 1481 |
1477 } // namespace | 1482 } // namespace |
1478 | 1483 |
1479 static FrontendPluginRegistry::Add<BlinkGCPluginAction> X( | 1484 static FrontendPluginRegistry::Add<BlinkGCPluginAction> X( |
1480 "blink-gc-plugin", | 1485 "blink-gc-plugin", |
1481 "Check Blink GC invariants"); | 1486 "Check Blink GC invariants"); |
OLD | NEW |