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