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

Side by Side Diff: tools/clang/blink_gc_plugin/BlinkGCPlugin.cpp

Issue 839143002: Roll Chrome into Mojo. (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Rebase Created 5 years, 11 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 | « tools/android/memdump/memdump.cc ('k') | tools/clang/blink_gc_plugin/Config.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 " is not permitted to declare a pure-virtual trace method."; 133 " is not permitted to declare a pure-virtual trace method.";
134 134
135 const char kLeftMostBaseMustBePolymorphic[] = 135 const char kLeftMostBaseMustBePolymorphic[] =
136 "[blink-gc] Left-most base class %0 of derived class %1" 136 "[blink-gc] Left-most base class %0 of derived class %1"
137 " must be polymorphic."; 137 " must be polymorphic.";
138 138
139 const char kBaseClassMustDeclareVirtualTrace[] = 139 const char kBaseClassMustDeclareVirtualTrace[] =
140 "[blink-gc] Left-most base class %0 of derived class %1" 140 "[blink-gc] Left-most base class %0 of derived class %1"
141 " must define a virtual trace method."; 141 " must define a virtual trace method.";
142 142
143 const char kClassMustDeclareGCMixinTraceMethod[] =
144 "[blink-gc] Class %0 which inherits from GarbageCollectedMixin must"
145 " locally declare and override trace(Visitor*)";
146
143 struct BlinkGCPluginOptions { 147 struct BlinkGCPluginOptions {
144 BlinkGCPluginOptions() 148 BlinkGCPluginOptions()
145 : enable_oilpan(false) 149 : enable_oilpan(false)
146 , dump_graph(false) 150 , dump_graph(false)
147 , warn_raw_ptr(false) 151 , warn_raw_ptr(false)
148 , warn_unneeded_finalizer(false) {} 152 , warn_unneeded_finalizer(false) {}
149 bool enable_oilpan; 153 bool enable_oilpan;
150 bool dump_graph; 154 bool dump_graph;
151 bool warn_raw_ptr; 155 bool warn_raw_ptr;
152 bool warn_unneeded_finalizer; 156 bool warn_unneeded_finalizer;
(...skipping 687 matching lines...) Expand 10 before | Expand all | Expand 10 after
840 diag_derives_non_stack_allocated_ = 844 diag_derives_non_stack_allocated_ =
841 diagnostic_.getCustomDiagID(getErrorLevel(), kDerivesNonStackAllocated); 845 diagnostic_.getCustomDiagID(getErrorLevel(), kDerivesNonStackAllocated);
842 diag_class_overrides_new_ = 846 diag_class_overrides_new_ =
843 diagnostic_.getCustomDiagID(getErrorLevel(), kClassOverridesNew); 847 diagnostic_.getCustomDiagID(getErrorLevel(), kClassOverridesNew);
844 diag_class_declares_pure_virtual_trace_ = diagnostic_.getCustomDiagID( 848 diag_class_declares_pure_virtual_trace_ = diagnostic_.getCustomDiagID(
845 getErrorLevel(), kClassDeclaresPureVirtualTrace); 849 getErrorLevel(), kClassDeclaresPureVirtualTrace);
846 diag_left_most_base_must_be_polymorphic_ = diagnostic_.getCustomDiagID( 850 diag_left_most_base_must_be_polymorphic_ = diagnostic_.getCustomDiagID(
847 getErrorLevel(), kLeftMostBaseMustBePolymorphic); 851 getErrorLevel(), kLeftMostBaseMustBePolymorphic);
848 diag_base_class_must_declare_virtual_trace_ = diagnostic_.getCustomDiagID( 852 diag_base_class_must_declare_virtual_trace_ = diagnostic_.getCustomDiagID(
849 getErrorLevel(), kBaseClassMustDeclareVirtualTrace); 853 getErrorLevel(), kBaseClassMustDeclareVirtualTrace);
854 diag_class_must_declare_gc_mixin_trace_method_ =
855 diagnostic_.getCustomDiagID(getErrorLevel(),
856 kClassMustDeclareGCMixinTraceMethod);
850 857
851 // Register note messages. 858 // Register note messages.
852 diag_base_requires_tracing_note_ = diagnostic_.getCustomDiagID( 859 diag_base_requires_tracing_note_ = diagnostic_.getCustomDiagID(
853 DiagnosticsEngine::Note, kBaseRequiresTracingNote); 860 DiagnosticsEngine::Note, kBaseRequiresTracingNote);
854 diag_field_requires_tracing_note_ = diagnostic_.getCustomDiagID( 861 diag_field_requires_tracing_note_ = diagnostic_.getCustomDiagID(
855 DiagnosticsEngine::Note, kFieldRequiresTracingNote); 862 DiagnosticsEngine::Note, kFieldRequiresTracingNote);
856 diag_raw_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( 863 diag_raw_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID(
857 DiagnosticsEngine::Note, kRawPtrToGCManagedClassNote); 864 DiagnosticsEngine::Note, kRawPtrToGCManagedClassNote);
858 diag_ref_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( 865 diag_ref_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID(
859 DiagnosticsEngine::Note, kRefPtrToGCManagedClassNote); 866 DiagnosticsEngine::Note, kRefPtrToGCManagedClassNote);
(...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after
998 ReportClassContainsInvalidFields(info, &visitor.invalid_fields()); 1005 ReportClassContainsInvalidFields(info, &visitor.invalid_fields());
999 } 1006 }
1000 1007
1001 if (info->IsGCDerived()) { 1008 if (info->IsGCDerived()) {
1002 1009
1003 if (!info->IsGCMixin()) { 1010 if (!info->IsGCMixin()) {
1004 CheckLeftMostDerived(info); 1011 CheckLeftMostDerived(info);
1005 CheckDispatch(info); 1012 CheckDispatch(info);
1006 if (CXXMethodDecl* newop = info->DeclaresNewOperator()) 1013 if (CXXMethodDecl* newop = info->DeclaresNewOperator())
1007 ReportClassOverridesNew(info, newop); 1014 ReportClassOverridesNew(info, newop);
1015 if (info->IsGCMixinInstance()) {
1016 // Require that declared GCMixin implementations
1017 // also provide a trace() override.
1018 if (info->DeclaresGCMixinMethods()
1019 && !info->DeclaresLocalTraceMethod())
1020 ReportClassMustDeclareGCMixinTraceMethod(info);
1021 }
1008 } 1022 }
1009 1023
1010 { 1024 {
1011 CheckGCRootsVisitor visitor; 1025 CheckGCRootsVisitor visitor;
1012 if (visitor.ContainsGCRoots(info)) 1026 if (visitor.ContainsGCRoots(info))
1013 ReportClassContainsGCRoots(info, &visitor.gc_roots()); 1027 ReportClassContainsGCRoots(info, &visitor.gc_roots());
1014 } 1028 }
1015 1029
1016 if (info->NeedsFinalization()) 1030 if (info->NeedsFinalization())
1017 CheckFinalization(info); 1031 CheckFinalization(info);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 return; 1107 return;
1094 } 1108 }
1095 ReportBaseClassMustDeclareVirtualTrace(info, left_most); 1109 ReportBaseClassMustDeclareVirtualTrace(info, left_most);
1096 return; 1110 return;
1097 } 1111 }
1098 1112
1099 // Check condition (2): 1113 // Check condition (2):
1100 if (DeclaresVirtualMethods(left_most)) 1114 if (DeclaresVirtualMethods(left_most))
1101 return; 1115 return;
1102 if (left_most_base) { 1116 if (left_most_base) {
1103 ++it; // Get the base next to the "safe polymorphic base" 1117 // Get the base next to the "safe polymorphic base"
1118 if (it != left_most->bases_end())
1119 ++it;
1104 if (it != left_most->bases_end()) { 1120 if (it != left_most->bases_end()) {
1105 if (CXXRecordDecl* next_base = it->getType()->getAsCXXRecordDecl()) { 1121 if (CXXRecordDecl* next_base = it->getType()->getAsCXXRecordDecl()) {
1106 if (CXXRecordDecl* next_left_most = GetLeftMostBase(next_base)) { 1122 if (CXXRecordDecl* next_left_most = GetLeftMostBase(next_base)) {
1107 if (DeclaresVirtualMethods(next_left_most)) 1123 if (DeclaresVirtualMethods(next_left_most))
1108 return; 1124 return;
1109 ReportLeftMostBaseMustBePolymorphic(info, next_left_most); 1125 ReportLeftMostBaseMustBePolymorphic(info, next_left_most);
1110 return; 1126 return;
1111 } 1127 }
1112 } 1128 }
1113 } 1129 }
(...skipping 532 matching lines...) Expand 10 before | Expand all | Expand 10 after
1646 } 1662 }
1647 1663
1648 void ReportClassDoesNotRequireFinalization(RecordInfo* info) { 1664 void ReportClassDoesNotRequireFinalization(RecordInfo* info) {
1649 SourceLocation loc = info->record()->getInnerLocStart(); 1665 SourceLocation loc = info->record()->getInnerLocStart();
1650 SourceManager& manager = instance_.getSourceManager(); 1666 SourceManager& manager = instance_.getSourceManager();
1651 FullSourceLoc full_loc(loc, manager); 1667 FullSourceLoc full_loc(loc, manager);
1652 diagnostic_.Report(full_loc, diag_class_does_not_require_finalization_) 1668 diagnostic_.Report(full_loc, diag_class_does_not_require_finalization_)
1653 << info->record(); 1669 << info->record();
1654 } 1670 }
1655 1671
1672 void ReportClassMustDeclareGCMixinTraceMethod(RecordInfo* info) {
1673 SourceLocation loc = info->record()->getInnerLocStart();
1674 SourceManager& manager = instance_.getSourceManager();
1675 FullSourceLoc full_loc(loc, manager);
1676 diagnostic_.Report(
1677 full_loc, diag_class_must_declare_gc_mixin_trace_method_)
1678 << info->record();
1679 }
1680
1656 void ReportOverriddenNonVirtualTrace(RecordInfo* info, 1681 void ReportOverriddenNonVirtualTrace(RecordInfo* info,
1657 CXXMethodDecl* trace, 1682 CXXMethodDecl* trace,
1658 CXXMethodDecl* overridden) { 1683 CXXMethodDecl* overridden) {
1659 SourceLocation loc = trace->getLocStart(); 1684 SourceLocation loc = trace->getLocStart();
1660 SourceManager& manager = instance_.getSourceManager(); 1685 SourceManager& manager = instance_.getSourceManager();
1661 FullSourceLoc full_loc(loc, manager); 1686 FullSourceLoc full_loc(loc, manager);
1662 diagnostic_.Report(full_loc, diag_overridden_non_virtual_trace_) 1687 diagnostic_.Report(full_loc, diag_overridden_non_virtual_trace_)
1663 << info->record() << overridden->getParent(); 1688 << info->record() << overridden->getParent();
1664 NoteOverriddenNonVirtualTrace(overridden); 1689 NoteOverriddenNonVirtualTrace(overridden);
1665 } 1690 }
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
1837 unsigned diag_missing_trace_dispatch_method_; 1862 unsigned diag_missing_trace_dispatch_method_;
1838 unsigned diag_missing_finalize_dispatch_method_; 1863 unsigned diag_missing_finalize_dispatch_method_;
1839 unsigned diag_virtual_and_manual_dispatch_; 1864 unsigned diag_virtual_and_manual_dispatch_;
1840 unsigned diag_missing_trace_dispatch_; 1865 unsigned diag_missing_trace_dispatch_;
1841 unsigned diag_missing_finalize_dispatch_; 1866 unsigned diag_missing_finalize_dispatch_;
1842 unsigned diag_derives_non_stack_allocated_; 1867 unsigned diag_derives_non_stack_allocated_;
1843 unsigned diag_class_overrides_new_; 1868 unsigned diag_class_overrides_new_;
1844 unsigned diag_class_declares_pure_virtual_trace_; 1869 unsigned diag_class_declares_pure_virtual_trace_;
1845 unsigned diag_left_most_base_must_be_polymorphic_; 1870 unsigned diag_left_most_base_must_be_polymorphic_;
1846 unsigned diag_base_class_must_declare_virtual_trace_; 1871 unsigned diag_base_class_must_declare_virtual_trace_;
1872 unsigned diag_class_must_declare_gc_mixin_trace_method_;
1847 1873
1848 unsigned diag_base_requires_tracing_note_; 1874 unsigned diag_base_requires_tracing_note_;
1849 unsigned diag_field_requires_tracing_note_; 1875 unsigned diag_field_requires_tracing_note_;
1850 unsigned diag_raw_ptr_to_gc_managed_class_note_; 1876 unsigned diag_raw_ptr_to_gc_managed_class_note_;
1851 unsigned diag_ref_ptr_to_gc_managed_class_note_; 1877 unsigned diag_ref_ptr_to_gc_managed_class_note_;
1852 unsigned diag_own_ptr_to_gc_managed_class_note_; 1878 unsigned diag_own_ptr_to_gc_managed_class_note_;
1853 unsigned diag_stack_allocated_field_note_; 1879 unsigned diag_stack_allocated_field_note_;
1854 unsigned diag_member_in_unmanaged_class_note_; 1880 unsigned diag_member_in_unmanaged_class_note_;
1855 unsigned diag_part_object_to_gc_derived_class_note_; 1881 unsigned diag_part_object_to_gc_derived_class_note_;
1856 unsigned diag_part_object_contains_gc_root_note_; 1882 unsigned diag_part_object_contains_gc_root_note_;
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
1906 1932
1907 private: 1933 private:
1908 BlinkGCPluginOptions options_; 1934 BlinkGCPluginOptions options_;
1909 }; 1935 };
1910 1936
1911 } // namespace 1937 } // namespace
1912 1938
1913 static FrontendPluginRegistry::Add<BlinkGCPluginAction> X( 1939 static FrontendPluginRegistry::Add<BlinkGCPluginAction> X(
1914 "blink-gc-plugin", 1940 "blink-gc-plugin",
1915 "Check Blink GC invariants"); 1941 "Check Blink GC invariants");
OLDNEW
« no previous file with comments | « tools/android/memdump/memdump.cc ('k') | tools/clang/blink_gc_plugin/Config.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698