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

Side by Side Diff: tools/clang/plugins/FindBadConstructsConsumer.cpp

Issue 1665363002: Clang plugin to check that unstable types are not used in IPC. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Use SmallVector; revert build script changes Created 4 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "FindBadConstructsConsumer.h" 5 #include "FindBadConstructsConsumer.h"
6 6
7 #include "clang/Frontend/CompilerInstance.h" 7 #include "clang/Frontend/CompilerInstance.h"
8 #include "clang/AST/Attr.h" 8 #include "clang/AST/Attr.h"
9 #include "clang/Lex/Lexer.h" 9 #include "clang/Lex/Lexer.h"
10 #include "llvm/Support/raw_ostream.h" 10 #include "llvm/Support/raw_ostream.h"
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 record.getDescribedClassTemplate() || 96 record.getDescribedClassTemplate() ||
97 record.getTemplateSpecializationKind() || 97 record.getTemplateSpecializationKind() ||
98 record.isDependentType(); 98 record.isDependentType();
99 } 99 }
100 100
101 } // namespace 101 } // namespace
102 102
103 FindBadConstructsConsumer::FindBadConstructsConsumer(CompilerInstance& instance, 103 FindBadConstructsConsumer::FindBadConstructsConsumer(CompilerInstance& instance,
104 const Options& options) 104 const Options& options)
105 : ChromeClassTester(instance, options) { 105 : ChromeClassTester(instance, options) {
106 if (options.check_ipc) {
107 ipc_visitor_.reset(new CheckIPCVisitor(instance));
108 }
109
106 // Messages for virtual method specifiers. 110 // Messages for virtual method specifiers.
107 diag_method_requires_override_ = 111 diag_method_requires_override_ =
108 diagnostic().getCustomDiagID(getErrorLevel(), kMethodRequiresOverride); 112 diagnostic().getCustomDiagID(getErrorLevel(), kMethodRequiresOverride);
109 diag_redundant_virtual_specifier_ = 113 diag_redundant_virtual_specifier_ =
110 diagnostic().getCustomDiagID(getErrorLevel(), kRedundantVirtualSpecifier); 114 diagnostic().getCustomDiagID(getErrorLevel(), kRedundantVirtualSpecifier);
111 diag_base_method_virtual_and_final_ = 115 diag_base_method_virtual_and_final_ =
112 diagnostic().getCustomDiagID(getErrorLevel(), kBaseMethodVirtualAndFinal); 116 diagnostic().getCustomDiagID(getErrorLevel(), kBaseMethodVirtualAndFinal);
113 117
114 // Messages for destructors. 118 // Messages for destructors.
115 diag_no_explicit_dtor_ = 119 diag_no_explicit_dtor_ =
(...skipping 13 matching lines...) Expand all
129 diag_note_inheritance_ = 133 diag_note_inheritance_ =
130 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNoteInheritance); 134 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNoteInheritance);
131 diag_note_implicit_dtor_ = 135 diag_note_implicit_dtor_ =
132 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNoteImplicitDtor); 136 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNoteImplicitDtor);
133 diag_note_public_dtor_ = 137 diag_note_public_dtor_ =
134 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNotePublicDtor); 138 diagnostic().getCustomDiagID(DiagnosticsEngine::Note, kNotePublicDtor);
135 diag_note_protected_non_virtual_dtor_ = diagnostic().getCustomDiagID( 139 diag_note_protected_non_virtual_dtor_ = diagnostic().getCustomDiagID(
136 DiagnosticsEngine::Note, kNoteProtectedNonVirtualDtor); 140 DiagnosticsEngine::Note, kNoteProtectedNonVirtualDtor);
137 } 141 }
138 142
143 void FindBadConstructsConsumer::Visit(ASTContext& context) {
144 if (ipc_visitor_) ipc_visitor_->set_context(&context);
145 RecursiveASTVisitor::TraverseDecl(context.getTranslationUnitDecl());
146 if (ipc_visitor_) ipc_visitor_->set_context(nullptr);
147 }
148
149 bool FindBadConstructsConsumer::shouldVisitTemplateInstantiations() const {
150 return RecursiveASTVisitor::shouldVisitTemplateInstantiations() ||
dcheng 2016/03/07 23:44:39 I don't think we need to call the 'base' method he
Dmitry Skiba 2016/03/08 01:16:11 Yes, but it provides the value I "blend" with. I d
151 (ipc_visitor_ && ipc_visitor_->should_visit_template_instantiations());
152 }
153
154 bool FindBadConstructsConsumer::TraverseDecl(Decl* decl) {
155 if (ipc_visitor_) ipc_visitor_->BeginDecl(decl);
156 bool result = RecursiveASTVisitor::TraverseDecl(decl);
157 if (ipc_visitor_) ipc_visitor_->EndDecl();
158 return result;
dcheng 2016/03/07 23:44:39 Seems like this should all just be in VisitDecl()
Dmitry Skiba 2016/03/08 01:16:11 VisitDecl() is called on leafs, so I won't be able
159 }
160
139 bool FindBadConstructsConsumer::VisitDecl(clang::Decl* decl) { 161 bool FindBadConstructsConsumer::VisitDecl(clang::Decl* decl) {
140 clang::TagDecl* tag_decl = dyn_cast<clang::TagDecl>(decl); 162 clang::TagDecl* tag_decl = dyn_cast<clang::TagDecl>(decl);
141 if (tag_decl && tag_decl->isCompleteDefinition()) 163 if (tag_decl && tag_decl->isCompleteDefinition())
142 CheckTag(tag_decl); 164 CheckTag(tag_decl);
143 return true; 165 return true;
144 } 166 }
145 167
168 bool FindBadConstructsConsumer::VisitTemplateSpecializationType(
169 TemplateSpecializationType* spec) {
170 if (ipc_visitor_) ipc_visitor_->VisitTemplateSpecializationType(spec);
171 return true;
172 }
173
174 bool FindBadConstructsConsumer::VisitCallExpr(CallExpr* call_expr) {
175 if (ipc_visitor_) ipc_visitor_->VisitCallExpr(call_expr);
176 return true;
177 }
178
146 void FindBadConstructsConsumer::CheckChromeClass(SourceLocation record_location, 179 void FindBadConstructsConsumer::CheckChromeClass(SourceLocation record_location,
147 CXXRecordDecl* record) { 180 CXXRecordDecl* record) {
148 // By default, the clang checker doesn't check some types (templates, etc). 181 // By default, the clang checker doesn't check some types (templates, etc).
149 // That was only a mistake; once Chromium code passes these checks, we should 182 // That was only a mistake; once Chromium code passes these checks, we should
150 // remove the "check-templates" option and remove this code. 183 // remove the "check-templates" option and remove this code.
151 // See crbug.com/441916 184 // See crbug.com/441916
152 if (!options_.check_templates && IsPodOrTemplateType(*record)) 185 if (!options_.check_templates && IsPodOrTemplateType(*record))
153 return; 186 return;
154 187
155 bool implementation_file = InImplementationFile(record_location); 188 bool implementation_file = InImplementationFile(record_location);
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
870 // one of those, it means there is at least one member after a factory. 903 // one of those, it means there is at least one member after a factory.
871 if (weak_ptr_factory_location.isValid() && 904 if (weak_ptr_factory_location.isValid() &&
872 !param_is_weak_ptr_factory_to_self) { 905 !param_is_weak_ptr_factory_to_self) {
873 diagnostic().Report(weak_ptr_factory_location, 906 diagnostic().Report(weak_ptr_factory_location,
874 diag_weak_ptr_factory_order_); 907 diag_weak_ptr_factory_order_);
875 } 908 }
876 } 909 }
877 } 910 }
878 911
879 } // namespace chrome_checker 912 } // namespace chrome_checker
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698