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

Unified Diff: tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp

Issue 2696713003: blink_gc_plugin: detect singletons with embedded ScriptWrappables.
Patch Set: non-copying iteration 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 | « tools/clang/blink_gc_plugin/DiagnosticsReporter.h ('k') | tools/clang/blink_gc_plugin/RecordInfo.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp
diff --git a/tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp b/tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp
index 95d5595beb5f38ffe8f690c98a710a3dee062971..fc28fc453566d30eeca66a20c15f59e9af5da338 100644
--- a/tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp
+++ b/tools/clang/blink_gc_plugin/DiagnosticsReporter.cpp
@@ -147,13 +147,21 @@ const char kBaseClassMustDeclareVirtualTrace[] =
"[blink-gc] Left-most base class %0 of derived class %1"
" must define a virtual trace method.";
-const char kIteratorToGCManagedCollectionNote[] =
+const char kIteratorToGCManagedCollection[] =
"[blink-gc] Iterator field %0 to a GC managed collection declared here:";
-const char kTraceMethodOfStackAllocatedParentNote[] =
+const char kTraceMethodOfStackAllocatedParent[] =
"[blink-gc] The stack allocated class %0 provides an unnecessary "
"trace method:";
+const char kStaticSingletonContainsScriptWrappable[] =
+ "[blink-gc] The static singleton %0 contains one or more unsafe "
+ "ScriptWrappable references";
+
+const char kUnsafeScriptWrappableFieldNote[] =
+ "[blink-gc] Embedded unsafe ScriptWrappable-derived field with type '%1' "
+ "located at '%0'";
+
} // namespace
DiagnosticBuilder DiagnosticsReporter::ReportDiagnostic(
@@ -164,6 +172,10 @@ DiagnosticBuilder DiagnosticsReporter::ReportDiagnostic(
return diagnostic_.Report(full_loc, diag_id);
}
+DiagnosticBuilder DiagnosticsReporter::ReportDiagnostic(unsigned diag_id) {
+ return diagnostic_.Report(diag_id);
+}
+
DiagnosticsReporter::DiagnosticsReporter(
clang::CompilerInstance& instance)
: instance_(instance),
@@ -214,10 +226,12 @@ DiagnosticsReporter::DiagnosticsReporter(
getErrorLevel(), kLeftMostBaseMustBePolymorphic);
diag_base_class_must_declare_virtual_trace_ = diagnostic_.getCustomDiagID(
getErrorLevel(), kBaseClassMustDeclareVirtualTrace);
- diag_iterator_to_gc_managed_collection_note_ = diagnostic_.getCustomDiagID(
- getErrorLevel(), kIteratorToGCManagedCollectionNote);
+ diag_iterator_to_gc_managed_collection_ = diagnostic_.getCustomDiagID(
+ getErrorLevel(), kIteratorToGCManagedCollection);
diag_trace_method_of_stack_allocated_parent_ = diagnostic_.getCustomDiagID(
- getErrorLevel(), kTraceMethodOfStackAllocatedParentNote);
+ getErrorLevel(), kTraceMethodOfStackAllocatedParent);
+ diag_static_singleton_with_scriptwrappable_ = diagnostic_.getCustomDiagID(
+ getErrorLevel(), kStaticSingletonContainsScriptWrappable);
// Register note messages.
diag_base_requires_tracing_note_ = diagnostic_.getCustomDiagID(
@@ -264,6 +278,8 @@ DiagnosticsReporter::DiagnosticsReporter(
DiagnosticsEngine::Note, kOverriddenNonVirtualTraceNote);
diag_manual_dispatch_method_note_ = diagnostic_.getCustomDiagID(
DiagnosticsEngine::Note, kManualDispatchMethodNote);
+ diag_unsafe_scriptwrappable_field_note_ = diagnostic_.getCustomDiagID(
+ DiagnosticsEngine::Note, kUnsafeScriptWrappableFieldNote);
}
bool DiagnosticsReporter::hasErrorOccurred() const
@@ -355,7 +371,7 @@ void DiagnosticsReporter::ClassContainsInvalidFields(
} else if (error.second == CheckFieldsVisitor::kGCDerivedPartObject) {
note = diag_part_object_to_gc_derived_class_note_;
} else if (error.second == CheckFieldsVisitor::kIteratorToGCManaged) {
- note = diag_iterator_to_gc_managed_collection_note_;
+ note = diag_iterator_to_gc_managed_collection_;
} else {
assert(false && "Unknown field error");
}
@@ -513,6 +529,13 @@ void DiagnosticsReporter::TraceMethodForStackAllocatedClass(
<< info->record();
}
+void DiagnosticsReporter::StaticSingletonContainsScriptWrappable(
+ VarDecl* decl) {
+ ReportDiagnostic(decl->getLocStart(),
+ diag_static_singleton_with_scriptwrappable_)
+ << decl;
+}
+
void DiagnosticsReporter::NoteManualDispatchMethod(CXXMethodDecl* dispatch) {
ReportDiagnostic(dispatch->getLocStart(),
diag_manual_dispatch_method_note_)
@@ -580,3 +603,11 @@ void DiagnosticsReporter::NoteOverriddenNonVirtualTrace(
diag_overridden_non_virtual_trace_note_)
<< overridden;
}
+
+void DiagnosticsReporter::NoteUnsafeScriptWrappableField(
+ VarDecl* decl,
+ const std::string& context,
+ const std::string& type_name) {
+ ReportDiagnostic(diag_unsafe_scriptwrappable_field_note_) << context
+ << type_name;
+}
« no previous file with comments | « tools/clang/blink_gc_plugin/DiagnosticsReporter.h ('k') | tools/clang/blink_gc_plugin/RecordInfo.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698