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

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

Issue 206123004: Add checks for stack-allocated types and their uses in fields. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 9 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 | Annotate | Revision Log
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 #include "Config.h" 5 #include "Config.h"
6 #include "RecordInfo.h" 6 #include "RecordInfo.h"
7 7
8 #include "clang/AST/Attr.h" 8 #include "clang/AST/Attr.h"
9 9
10 using namespace clang; 10 using namespace clang;
11 using std::string; 11 using std::string;
12 12
13 RecordInfo::RecordInfo(CXXRecordDecl* record, RecordCache* cache) 13 RecordInfo::RecordInfo(CXXRecordDecl* record, RecordCache* cache)
14 : cache_(cache), 14 : cache_(cache),
15 record_(record), 15 record_(record),
16 name_(record->getName()), 16 name_(record->getName()),
17 fields_need_tracing_(TracingStatus::Unknown()), 17 fields_need_tracing_(TracingStatus::Unknown()),
18 bases_(0), 18 bases_(0),
19 fields_(0), 19 fields_(0),
20 is_stack_allocated_(kMaybe),
Mads Ager (chromium) 2014/03/20 10:32:29 Wasn't it called kNone in the enum? This is really
zerny-chromium 2014/03/20 15:14:20 Done.
20 determined_trace_methods_(false), 21 determined_trace_methods_(false),
21 trace_method_(0), 22 trace_method_(0),
22 trace_dispatch_method_(0), 23 trace_dispatch_method_(0),
23 is_gc_derived_(false), 24 is_gc_derived_(false),
24 base_paths_(0) {} 25 base_paths_(0) {}
25 26
26 RecordInfo::~RecordInfo() { 27 RecordInfo::~RecordInfo() {
27 delete fields_; 28 delete fields_;
28 delete bases_; 29 delete bases_;
29 delete base_paths_; 30 delete base_paths_;
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
144 if (!record || IsAnnotated(record, "blink_gc_plugin_ignore")) 145 if (!record || IsAnnotated(record, "blink_gc_plugin_ignore"))
145 return 0; 146 return 0;
146 Cache::iterator it = cache_.find(record); 147 Cache::iterator it = cache_.find(record);
147 if (it != cache_.end()) 148 if (it != cache_.end())
148 return &it->second; 149 return &it->second;
149 return &cache_.insert(std::make_pair(record, RecordInfo(record, this))) 150 return &cache_.insert(std::make_pair(record, RecordInfo(record, this)))
150 .first->second; 151 .first->second;
151 } 152 }
152 153
153 bool RecordInfo::IsStackAllocated() { 154 bool RecordInfo::IsStackAllocated() {
154 for (CXXRecordDecl::method_iterator it = record_->method_begin(); 155 if (is_stack_allocated_ == kNone) {
155 it != record_->method_end(); 156 is_stack_allocated_ = kFalse;
156 ++it) { 157 for (CXXRecordDecl::method_iterator it = record_->method_begin();
157 if (it->getNameAsString() == kNewOperatorName) 158 it != record_->method_end();
158 return it->isDeleted() && IsAnnotated(*it, "blink_stack_allocated"); 159 ++it) {
160 if (it->getNameAsString() == kNewOperatorName) {
161 if (it->isDeleted() && IsAnnotated(*it, "blink_stack_allocated")) {
162 is_stack_allocated_ = kTrue;
163 break;
164 }
165 }
166 }
159 } 167 }
160 return false; 168 return is_stack_allocated_;
161 } 169 }
162 170
163 // An object requires a tracing method if it has any fields that need tracing. 171 // An object requires a tracing method if it has any fields that need tracing.
164 bool RecordInfo::RequiresTraceMethod() { 172 bool RecordInfo::RequiresTraceMethod() {
173 if (IsStackAllocated())
174 return false;
165 GetFields(); 175 GetFields();
166 return fields_need_tracing_.IsNeeded(); 176 return fields_need_tracing_.IsNeeded();
167 } 177 }
168 178
169 // Get the actual tracing method (ie, can be traceAfterDispatch if there is a 179 // Get the actual tracing method (ie, can be traceAfterDispatch if there is a
170 // dispatch method). 180 // dispatch method).
171 CXXMethodDecl* RecordInfo::GetTraceMethod() { 181 CXXMethodDecl* RecordInfo::GetTraceMethod() {
172 DetermineTracingMethods(); 182 DetermineTracingMethods();
173 return trace_method_; 183 return trace_method_;
174 } 184 }
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
418 // We failed to create an edge so abort the entire edge construction. 428 // We failed to create an edge so abort the entire edge construction.
419 delete edge; // Will delete the already allocated members. 429 delete edge; // Will delete the already allocated members.
420 return 0; 430 return 0;
421 } 431 }
422 } 432 }
423 return edge; 433 return edge;
424 } 434 }
425 435
426 return new Value(info); 436 return new Value(info);
427 } 437 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698