| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 #include "DiagnosticsReporter.h" | 5 #include "DiagnosticsReporter.h" |
| 6 | 6 |
| 7 using namespace clang; | 7 using namespace clang; |
| 8 | 8 |
| 9 namespace { | 9 namespace { |
| 10 | 10 |
| 11 const char kClassMustLeftMostlyDeriveGC[] = | 11 const char kClassMustLeftMostlyDeriveGC[] = |
| 12 "[blink-gc] Class %0 must derive its GC base in the left-most position."; | 12 "[blink-gc] Class %0 must derive its GC base in the left-most position."; |
| 13 | 13 |
| 14 const char kClassRequiresTraceMethod[] = | 14 const char kClassRequiresTraceMethod[] = |
| 15 "[blink-gc] Class %0 requires a trace method."; | 15 "[blink-gc] Class %0 requires a trace method."; |
| 16 | 16 |
| 17 const char kBaseRequiresTracing[] = | 17 const char kBaseRequiresTracing[] = |
| 18 "[blink-gc] Base class %0 of derived class %1 requires tracing."; | 18 "[blink-gc] Base class %0 of derived class %1 requires tracing."; |
| 19 | 19 |
| 20 const char kBaseRequiresTracingNote[] = | 20 const char kBaseRequiresTracingNote[] = |
| 21 "[blink-gc] Untraced base class %0 declared here:"; | 21 "[blink-gc] Untraced base class %0 declared here:"; |
| 22 | 22 |
| 23 const char kFieldsRequireTracing[] = | 23 const char kFieldsRequireTracing[] = |
| 24 "[blink-gc] Class %0 has untraced fields that require tracing."; | 24 "[blink-gc] Class %0 has untraced fields that require tracing."; |
| 25 | 25 |
| 26 const char kFieldsImproperlyTraced[] = |
| 27 "[blink-gc] Class %0 has untraced or not traceable fields."; |
| 28 |
| 26 const char kFieldRequiresTracingNote[] = | 29 const char kFieldRequiresTracingNote[] = |
| 27 "[blink-gc] Untraced field %0 declared here:"; | 30 "[blink-gc] Untraced field %0 declared here:"; |
| 28 | 31 |
| 32 const char kFieldShouldNotBeTracedNote[] = |
| 33 "[blink-gc] Untraceable field %0 declared here:"; |
| 34 |
| 29 const char kClassContainsInvalidFields[] = | 35 const char kClassContainsInvalidFields[] = |
| 30 "[blink-gc] Class %0 contains invalid fields."; | 36 "[blink-gc] Class %0 contains invalid fields."; |
| 31 | 37 |
| 32 const char kClassContainsGCRoot[] = | 38 const char kClassContainsGCRoot[] = |
| 33 "[blink-gc] Class %0 contains GC root in field %1."; | 39 "[blink-gc] Class %0 contains GC root in field %1."; |
| 34 | 40 |
| 35 const char kClassRequiresFinalization[] = | 41 const char kClassRequiresFinalization[] = |
| 36 "[blink-gc] Class %0 requires finalization."; | 42 "[blink-gc] Class %0 requires finalization."; |
| 37 | 43 |
| 38 const char kClassDoesNotRequireFinalization[] = | 44 const char kClassDoesNotRequireFinalization[] = |
| (...skipping 11 matching lines...) Expand all Loading... |
| 50 const char kRefPtrToGCManagedClassNote[] = | 56 const char kRefPtrToGCManagedClassNote[] = |
| 51 "[blink-gc] RefPtr field %0 to a GC managed class declared here:"; | 57 "[blink-gc] RefPtr field %0 to a GC managed class declared here:"; |
| 52 | 58 |
| 53 const char kReferencePtrToGCManagedClassNote[] = | 59 const char kReferencePtrToGCManagedClassNote[] = |
| 54 "[blink-gc] Reference pointer field %0 to a GC managed class" | 60 "[blink-gc] Reference pointer field %0 to a GC managed class" |
| 55 " declared here:"; | 61 " declared here:"; |
| 56 | 62 |
| 57 const char kOwnPtrToGCManagedClassNote[] = | 63 const char kOwnPtrToGCManagedClassNote[] = |
| 58 "[blink-gc] OwnPtr field %0 to a GC managed class declared here:"; | 64 "[blink-gc] OwnPtr field %0 to a GC managed class declared here:"; |
| 59 | 65 |
| 66 const char kUniquePtrToGCManagedClassNote[] = |
| 67 "[blink-gc] std::unique_ptr field %0 to a GC managed class declared here:"; |
| 68 |
| 60 const char kMemberToGCUnmanagedClassNote[] = | 69 const char kMemberToGCUnmanagedClassNote[] = |
| 61 "[blink-gc] Member field %0 to non-GC managed class declared here:"; | 70 "[blink-gc] Member field %0 to non-GC managed class declared here:"; |
| 62 | 71 |
| 63 const char kStackAllocatedFieldNote[] = | 72 const char kStackAllocatedFieldNote[] = |
| 64 "[blink-gc] Stack-allocated field %0 declared here:"; | 73 "[blink-gc] Stack-allocated field %0 declared here:"; |
| 65 | 74 |
| 66 const char kMemberInUnmanagedClassNote[] = | 75 const char kMemberInUnmanagedClassNote[] = |
| 67 "[blink-gc] Member field %0 in unmanaged class declared here:"; | 76 "[blink-gc] Member field %0 in unmanaged class declared here:"; |
| 68 | 77 |
| 69 const char kPartObjectToGCDerivedClassNote[] = | 78 const char kPartObjectToGCDerivedClassNote[] = |
| (...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 { | 164 { |
| 156 // Register warning/error messages. | 165 // Register warning/error messages. |
| 157 diag_class_must_left_mostly_derive_gc_ = diagnostic_.getCustomDiagID( | 166 diag_class_must_left_mostly_derive_gc_ = diagnostic_.getCustomDiagID( |
| 158 getErrorLevel(), kClassMustLeftMostlyDeriveGC); | 167 getErrorLevel(), kClassMustLeftMostlyDeriveGC); |
| 159 diag_class_requires_trace_method_ = | 168 diag_class_requires_trace_method_ = |
| 160 diagnostic_.getCustomDiagID(getErrorLevel(), kClassRequiresTraceMethod); | 169 diagnostic_.getCustomDiagID(getErrorLevel(), kClassRequiresTraceMethod); |
| 161 diag_base_requires_tracing_ = | 170 diag_base_requires_tracing_ = |
| 162 diagnostic_.getCustomDiagID(getErrorLevel(), kBaseRequiresTracing); | 171 diagnostic_.getCustomDiagID(getErrorLevel(), kBaseRequiresTracing); |
| 163 diag_fields_require_tracing_ = | 172 diag_fields_require_tracing_ = |
| 164 diagnostic_.getCustomDiagID(getErrorLevel(), kFieldsRequireTracing); | 173 diagnostic_.getCustomDiagID(getErrorLevel(), kFieldsRequireTracing); |
| 174 diag_fields_improperly_traced_ = |
| 175 diagnostic_.getCustomDiagID(getErrorLevel(), kFieldsImproperlyTraced); |
| 165 diag_class_contains_invalid_fields_ = diagnostic_.getCustomDiagID( | 176 diag_class_contains_invalid_fields_ = diagnostic_.getCustomDiagID( |
| 166 getErrorLevel(), kClassContainsInvalidFields); | 177 getErrorLevel(), kClassContainsInvalidFields); |
| 167 diag_class_contains_gc_root_ = | 178 diag_class_contains_gc_root_ = |
| 168 diagnostic_.getCustomDiagID(getErrorLevel(), kClassContainsGCRoot); | 179 diagnostic_.getCustomDiagID(getErrorLevel(), kClassContainsGCRoot); |
| 169 diag_class_requires_finalization_ = diagnostic_.getCustomDiagID( | 180 diag_class_requires_finalization_ = diagnostic_.getCustomDiagID( |
| 170 getErrorLevel(), kClassRequiresFinalization); | 181 getErrorLevel(), kClassRequiresFinalization); |
| 171 diag_class_does_not_require_finalization_ = diagnostic_.getCustomDiagID( | 182 diag_class_does_not_require_finalization_ = diagnostic_.getCustomDiagID( |
| 172 DiagnosticsEngine::Warning, kClassDoesNotRequireFinalization); | 183 DiagnosticsEngine::Warning, kClassDoesNotRequireFinalization); |
| 173 diag_finalizer_accesses_finalized_field_ = diagnostic_.getCustomDiagID( | 184 diag_finalizer_accesses_finalized_field_ = diagnostic_.getCustomDiagID( |
| 174 getErrorLevel(), kFinalizerAccessesFinalizedField); | 185 getErrorLevel(), kFinalizerAccessesFinalizedField); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 195 diag_left_most_base_must_be_polymorphic_ = diagnostic_.getCustomDiagID( | 206 diag_left_most_base_must_be_polymorphic_ = diagnostic_.getCustomDiagID( |
| 196 getErrorLevel(), kLeftMostBaseMustBePolymorphic); | 207 getErrorLevel(), kLeftMostBaseMustBePolymorphic); |
| 197 diag_base_class_must_declare_virtual_trace_ = diagnostic_.getCustomDiagID( | 208 diag_base_class_must_declare_virtual_trace_ = diagnostic_.getCustomDiagID( |
| 198 getErrorLevel(), kBaseClassMustDeclareVirtualTrace); | 209 getErrorLevel(), kBaseClassMustDeclareVirtualTrace); |
| 199 | 210 |
| 200 // Register note messages. | 211 // Register note messages. |
| 201 diag_base_requires_tracing_note_ = diagnostic_.getCustomDiagID( | 212 diag_base_requires_tracing_note_ = diagnostic_.getCustomDiagID( |
| 202 DiagnosticsEngine::Note, kBaseRequiresTracingNote); | 213 DiagnosticsEngine::Note, kBaseRequiresTracingNote); |
| 203 diag_field_requires_tracing_note_ = diagnostic_.getCustomDiagID( | 214 diag_field_requires_tracing_note_ = diagnostic_.getCustomDiagID( |
| 204 DiagnosticsEngine::Note, kFieldRequiresTracingNote); | 215 DiagnosticsEngine::Note, kFieldRequiresTracingNote); |
| 216 diag_field_should_not_be_traced_note_ = diagnostic_.getCustomDiagID( |
| 217 DiagnosticsEngine::Note, kFieldShouldNotBeTracedNote); |
| 205 diag_raw_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( | 218 diag_raw_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( |
| 206 DiagnosticsEngine::Note, kRawPtrToGCManagedClassNote); | 219 DiagnosticsEngine::Note, kRawPtrToGCManagedClassNote); |
| 207 diag_ref_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( | 220 diag_ref_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( |
| 208 DiagnosticsEngine::Note, kRefPtrToGCManagedClassNote); | 221 DiagnosticsEngine::Note, kRefPtrToGCManagedClassNote); |
| 209 diag_reference_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( | 222 diag_reference_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( |
| 210 DiagnosticsEngine::Note, kReferencePtrToGCManagedClassNote); | 223 DiagnosticsEngine::Note, kReferencePtrToGCManagedClassNote); |
| 211 diag_own_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( | 224 diag_own_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( |
| 212 DiagnosticsEngine::Note, kOwnPtrToGCManagedClassNote); | 225 DiagnosticsEngine::Note, kOwnPtrToGCManagedClassNote); |
| 226 diag_unique_ptr_to_gc_managed_class_note_ = diagnostic_.getCustomDiagID( |
| 227 DiagnosticsEngine::Note, kUniquePtrToGCManagedClassNote); |
| 213 diag_member_to_gc_unmanaged_class_note_ = diagnostic_.getCustomDiagID( | 228 diag_member_to_gc_unmanaged_class_note_ = diagnostic_.getCustomDiagID( |
| 214 DiagnosticsEngine::Note, kMemberToGCUnmanagedClassNote); | 229 DiagnosticsEngine::Note, kMemberToGCUnmanagedClassNote); |
| 215 diag_stack_allocated_field_note_ = diagnostic_.getCustomDiagID( | 230 diag_stack_allocated_field_note_ = diagnostic_.getCustomDiagID( |
| 216 DiagnosticsEngine::Note, kStackAllocatedFieldNote); | 231 DiagnosticsEngine::Note, kStackAllocatedFieldNote); |
| 217 diag_member_in_unmanaged_class_note_ = diagnostic_.getCustomDiagID( | 232 diag_member_in_unmanaged_class_note_ = diagnostic_.getCustomDiagID( |
| 218 DiagnosticsEngine::Note, kMemberInUnmanagedClassNote); | 233 DiagnosticsEngine::Note, kMemberInUnmanagedClassNote); |
| 219 diag_part_object_to_gc_derived_class_note_ = diagnostic_.getCustomDiagID( | 234 diag_part_object_to_gc_derived_class_note_ = diagnostic_.getCustomDiagID( |
| 220 DiagnosticsEngine::Note, kPartObjectToGCDerivedClassNote); | 235 DiagnosticsEngine::Note, kPartObjectToGCDerivedClassNote); |
| 221 diag_part_object_contains_gc_root_note_ = diagnostic_.getCustomDiagID( | 236 diag_part_object_contains_gc_root_note_ = diagnostic_.getCustomDiagID( |
| 222 DiagnosticsEngine::Note, kPartObjectContainsGCRootNote); | 237 DiagnosticsEngine::Note, kPartObjectContainsGCRootNote); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 272 } | 287 } |
| 273 | 288 |
| 274 void DiagnosticsReporter::BaseRequiresTracing( | 289 void DiagnosticsReporter::BaseRequiresTracing( |
| 275 RecordInfo* derived, | 290 RecordInfo* derived, |
| 276 CXXMethodDecl* trace, | 291 CXXMethodDecl* trace, |
| 277 CXXRecordDecl* base) { | 292 CXXRecordDecl* base) { |
| 278 ReportDiagnostic(trace->getLocStart(), diag_base_requires_tracing_) | 293 ReportDiagnostic(trace->getLocStart(), diag_base_requires_tracing_) |
| 279 << base << derived->record(); | 294 << base << derived->record(); |
| 280 } | 295 } |
| 281 | 296 |
| 282 void DiagnosticsReporter::FieldsRequireTracing( | 297 void DiagnosticsReporter::FieldsImproperlyTraced( |
| 283 RecordInfo* info, | 298 RecordInfo* info, |
| 284 CXXMethodDecl* trace) { | 299 CXXMethodDecl* trace) { |
| 285 ReportDiagnostic(trace->getLocStart(), diag_fields_require_tracing_) | 300 // Only mention untraceable in header diagnostic if they appear. |
| 301 unsigned diag = diag_fields_require_tracing_; |
| 302 for (auto& field : info->GetFields()) { |
| 303 if (field.second.IsInproperlyTraced()) { |
| 304 diag = diag_fields_improperly_traced_; |
| 305 break; |
| 306 } |
| 307 } |
| 308 ReportDiagnostic(trace->getLocStart(), diag) |
| 286 << info->record(); | 309 << info->record(); |
| 287 for (auto& field : info->GetFields()) | 310 for (auto& field : info->GetFields()) { |
| 288 if (!field.second.IsProperlyTraced()) | 311 if (!field.second.IsProperlyTraced()) |
| 289 NoteFieldRequiresTracing(info, field.first); | 312 NoteFieldRequiresTracing(info, field.first); |
| 313 if (field.second.IsInproperlyTraced()) |
| 314 NoteFieldShouldNotBeTraced(info, field.first); |
| 315 } |
| 290 } | 316 } |
| 291 | 317 |
| 292 void DiagnosticsReporter::ClassContainsInvalidFields( | 318 void DiagnosticsReporter::ClassContainsInvalidFields( |
| 293 RecordInfo* info, | 319 RecordInfo* info, |
| 294 const CheckFieldsVisitor::Errors& errors) { | 320 const CheckFieldsVisitor::Errors& errors) { |
| 295 | 321 |
| 296 ReportDiagnostic(info->record()->getLocStart(), | 322 ReportDiagnostic(info->record()->getLocStart(), |
| 297 diag_class_contains_invalid_fields_) | 323 diag_class_contains_invalid_fields_) |
| 298 << info->record(); | 324 << info->record(); |
| 299 | 325 |
| 300 for (auto& error : errors) { | 326 for (auto& error : errors) { |
| 301 unsigned note; | 327 unsigned note; |
| 302 if (error.second == CheckFieldsVisitor::kRawPtrToGCManaged) { | 328 if (error.second == CheckFieldsVisitor::kRawPtrToGCManaged) { |
| 303 note = diag_raw_ptr_to_gc_managed_class_note_; | 329 note = diag_raw_ptr_to_gc_managed_class_note_; |
| 304 } else if (error.second == CheckFieldsVisitor::kRefPtrToGCManaged) { | 330 } else if (error.second == CheckFieldsVisitor::kRefPtrToGCManaged) { |
| 305 note = diag_ref_ptr_to_gc_managed_class_note_; | 331 note = diag_ref_ptr_to_gc_managed_class_note_; |
| 306 } else if (error.second == CheckFieldsVisitor::kReferencePtrToGCManaged) { | 332 } else if (error.second == CheckFieldsVisitor::kReferencePtrToGCManaged) { |
| 307 note = diag_reference_ptr_to_gc_managed_class_note_; | 333 note = diag_reference_ptr_to_gc_managed_class_note_; |
| 308 } else if (error.second == CheckFieldsVisitor::kOwnPtrToGCManaged) { | 334 } else if (error.second == CheckFieldsVisitor::kOwnPtrToGCManaged) { |
| 309 note = diag_own_ptr_to_gc_managed_class_note_; | 335 note = diag_own_ptr_to_gc_managed_class_note_; |
| 336 } else if (error.second == CheckFieldsVisitor::kUniquePtrToGCManaged) { |
| 337 note = diag_unique_ptr_to_gc_managed_class_note_; |
| 310 } else if (error.second == CheckFieldsVisitor::kMemberToGCUnmanaged) { | 338 } else if (error.second == CheckFieldsVisitor::kMemberToGCUnmanaged) { |
| 311 note = diag_member_to_gc_unmanaged_class_note_; | 339 note = diag_member_to_gc_unmanaged_class_note_; |
| 312 } else if (error.second == CheckFieldsVisitor::kMemberInUnmanaged) { | 340 } else if (error.second == CheckFieldsVisitor::kMemberInUnmanaged) { |
| 313 note = diag_member_in_unmanaged_class_note_; | 341 note = diag_member_in_unmanaged_class_note_; |
| 314 } else if (error.second == CheckFieldsVisitor::kPtrFromHeapToStack) { | 342 } else if (error.second == CheckFieldsVisitor::kPtrFromHeapToStack) { |
| 315 note = diag_stack_allocated_field_note_; | 343 note = diag_stack_allocated_field_note_; |
| 316 } else if (error.second == CheckFieldsVisitor::kGCDerivedPartObject) { | 344 } else if (error.second == CheckFieldsVisitor::kGCDerivedPartObject) { |
| 317 note = diag_part_object_to_gc_derived_class_note_; | 345 note = diag_part_object_to_gc_derived_class_note_; |
| 318 } else { | 346 } else { |
| 319 assert(false && "Unknown field error"); | 347 assert(false && "Unknown field error"); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 diag_base_requires_tracing_note_) | 503 diag_base_requires_tracing_note_) |
| 476 << base->info()->record(); | 504 << base->info()->record(); |
| 477 } | 505 } |
| 478 | 506 |
| 479 void DiagnosticsReporter::NoteFieldRequiresTracing( | 507 void DiagnosticsReporter::NoteFieldRequiresTracing( |
| 480 RecordInfo* holder, | 508 RecordInfo* holder, |
| 481 FieldDecl* field) { | 509 FieldDecl* field) { |
| 482 NoteField(field, diag_field_requires_tracing_note_); | 510 NoteField(field, diag_field_requires_tracing_note_); |
| 483 } | 511 } |
| 484 | 512 |
| 513 void DiagnosticsReporter::NoteFieldShouldNotBeTraced( |
| 514 RecordInfo* holder, |
| 515 FieldDecl* field) { |
| 516 NoteField(field, diag_field_should_not_be_traced_note_); |
| 517 } |
| 518 |
| 485 void DiagnosticsReporter::NotePartObjectContainsGCRoot(FieldPoint* point) { | 519 void DiagnosticsReporter::NotePartObjectContainsGCRoot(FieldPoint* point) { |
| 486 FieldDecl* field = point->field(); | 520 FieldDecl* field = point->field(); |
| 487 ReportDiagnostic(field->getLocStart(), | 521 ReportDiagnostic(field->getLocStart(), |
| 488 diag_part_object_contains_gc_root_note_) | 522 diag_part_object_contains_gc_root_note_) |
| 489 << field << field->getParent(); | 523 << field << field->getParent(); |
| 490 } | 524 } |
| 491 | 525 |
| 492 void DiagnosticsReporter::NoteFieldContainsGCRoot(FieldPoint* point) { | 526 void DiagnosticsReporter::NoteFieldContainsGCRoot(FieldPoint* point) { |
| 493 NoteField(point, diag_field_contains_gc_root_note_); | 527 NoteField(point, diag_field_contains_gc_root_note_); |
| 494 } | 528 } |
| (...skipping 23 matching lines...) Expand all Loading... |
| 518 void DiagnosticsReporter::NoteField(FieldDecl* field, unsigned note) { | 552 void DiagnosticsReporter::NoteField(FieldDecl* field, unsigned note) { |
| 519 ReportDiagnostic(field->getLocStart(), note) << field; | 553 ReportDiagnostic(field->getLocStart(), note) << field; |
| 520 } | 554 } |
| 521 | 555 |
| 522 void DiagnosticsReporter::NoteOverriddenNonVirtualTrace( | 556 void DiagnosticsReporter::NoteOverriddenNonVirtualTrace( |
| 523 CXXMethodDecl* overridden) { | 557 CXXMethodDecl* overridden) { |
| 524 ReportDiagnostic(overridden->getLocStart(), | 558 ReportDiagnostic(overridden->getLocStart(), |
| 525 diag_overridden_non_virtual_trace_note_) | 559 diag_overridden_non_virtual_trace_note_) |
| 526 << overridden; | 560 << overridden; |
| 527 } | 561 } |
| OLD | NEW |