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

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

Issue 1901643003: Always enable warn-raw-ptr's check of raw heap pointers. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@sof-gc-plugin-upd
Patch Set: remove unused warning diagnostic Created 4 years, 8 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "CheckFieldsVisitor.h" 5 #include "CheckFieldsVisitor.h"
6 6
7 #include <cassert> 7 #include <cassert>
8 8
9 #include "BlinkGCPluginOptions.h" 9 #include "BlinkGCPluginOptions.h"
10 #include "RecordInfo.h" 10 #include "RecordInfo.h"
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
86 return; 86 return;
87 87
88 // Disallow OwnPtr<T>, RefPtr<T> and T* to stack-allocated types. 88 // Disallow OwnPtr<T>, RefPtr<T> and T* to stack-allocated types.
89 if (Parent()->IsOwnPtr() || 89 if (Parent()->IsOwnPtr() ||
90 (Parent()->IsRefPtr() && !edge->value()->IsGCRefCounted()) || 90 (Parent()->IsRefPtr() && !edge->value()->IsGCRefCounted()) ||
91 (stack_allocated_host_ && Parent()->IsRawPtr())) { 91 (stack_allocated_host_ && Parent()->IsRawPtr())) {
92 invalid_fields_.push_back(std::make_pair( 92 invalid_fields_.push_back(std::make_pair(
93 current_, InvalidSmartPtr(Parent()))); 93 current_, InvalidSmartPtr(Parent())));
94 return; 94 return;
95 } 95 }
96 if (options_.warn_raw_ptr && Parent()->IsRawPtr()) { 96 if (Parent()->IsRawPtr()) {
97 if (static_cast<RawPtr*>(Parent())->HasReferenceType()) { 97 RawPtr* rawPtr = static_cast<RawPtr*>(Parent());
98 invalid_fields_.push_back(std::make_pair( 98 Error error = rawPtr->HasReferenceType() ?
99 current_, kReferencePtrToGCManagedWarning)); 99 kReferencePtrToGCManaged : kRawPtrToGCManaged;
100 } else { 100 invalid_fields_.push_back(std::make_pair(current_, error));
101 invalid_fields_.push_back(std::make_pair(
102 current_, kRawPtrToGCManagedWarning));
103 }
104 } 101 }
105 } 102 }
106 103
107 void CheckFieldsVisitor::AtCollection(Collection* edge) { 104 void CheckFieldsVisitor::AtCollection(Collection* edge) {
108 if (edge->on_heap() && Parent() && Parent()->IsOwnPtr()) 105 if (edge->on_heap() && Parent() && Parent()->IsOwnPtr())
109 invalid_fields_.push_back(std::make_pair(current_, kOwnPtrToGCManaged)); 106 invalid_fields_.push_back(std::make_pair(current_, kOwnPtrToGCManaged));
110 } 107 }
111 108
112 bool CheckFieldsVisitor::IsWarning(Error error) {
113 if (error == kRawPtrToGCManagedWarning)
114 return true;
115 if (error == kReferencePtrToGCManagedWarning)
116 return true;
117 return false;
118 }
119
120 bool CheckFieldsVisitor::IsRawPtrError(Error error) {
121 return (error == kRawPtrToGCManaged ||
122 error == kRawPtrToGCManagedWarning);
123 }
124
125 bool CheckFieldsVisitor::IsReferencePtrError(Error error) {
126 return (error == kReferencePtrToGCManaged ||
127 error == kReferencePtrToGCManagedWarning);
128 }
129
130 CheckFieldsVisitor::Error CheckFieldsVisitor::InvalidSmartPtr(Edge* ptr) { 109 CheckFieldsVisitor::Error CheckFieldsVisitor::InvalidSmartPtr(Edge* ptr) {
131 if (ptr->IsRawPtr()) { 110 if (ptr->IsRawPtr()) {
132 if (static_cast<RawPtr*>(ptr)->HasReferenceType()) 111 if (static_cast<RawPtr*>(ptr)->HasReferenceType())
133 return kReferencePtrToGCManaged; 112 return kReferencePtrToGCManaged;
134 else 113 else
135 return kRawPtrToGCManaged; 114 return kRawPtrToGCManaged;
136 } 115 }
137 if (ptr->IsRefPtr()) 116 if (ptr->IsRefPtr())
138 return kRefPtrToGCManaged; 117 return kRefPtrToGCManaged;
139 if (ptr->IsOwnPtr()) 118 if (ptr->IsOwnPtr())
140 return kOwnPtrToGCManaged; 119 return kOwnPtrToGCManaged;
141 assert(false && "Unknown smart pointer kind"); 120 assert(false && "Unknown smart pointer kind");
142 } 121 }
OLDNEW
« no previous file with comments | « tools/clang/blink_gc_plugin/CheckFieldsVisitor.h ('k') | tools/clang/blink_gc_plugin/tests/raw_ptr_to_gc_managed_class.flags » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698