OLD | NEW |
---|---|
(Empty) | |
1 // Copyright (c) 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 // This plugin ensures that 32/64-bit unstable types are not used in IPC. | |
dcheng
2016/02/23 19:46:47
s/plugin/check/
Dmitry Skiba
2016/02/24 14:39:04
Done.
| |
6 // | |
7 // Type (or typedef) is unstable if it changes size between 32/ 64-bit | |
dcheng
2016/02/23 19:46:47
Nit: s/Type/A type/
Dmitry Skiba
2016/02/24 14:39:04
Done.
| |
8 // platforms. However, it's impossible to accurately identify unstable | |
9 // typedefs, because their definitions rely on the preprocessor. For | |
10 // example uintptr_t is either unsigned int or unsigned long. | |
11 // | |
12 // So we're not trying to be accurate, and just blacklisting some types | |
13 // that are known to be unstable: | |
14 // 1. Types: long / unsigned long (but not typedefs to) | |
15 // 2. Typedefs: intmax_t, uintmax_t, intptr_t, uintptr_t, wint_t, | |
16 // size_t, rsize_t, ssize_t, ptrdiff_t, dev_t, off_t, clock_t, | |
17 // time_t, suseconds_t (including typedefs to) | |
18 // | |
19 // The plugin checks for blacklisted types in: | |
20 // 1. IPC::WriteParam() calls; additionally: | |
21 // a. WriteParam() can be used inside a template only if that template | |
22 // is IPC::ParamTraits<> specialization | |
dcheng
2016/02/23 19:46:46
s/is IPC/is an IPC/
Dmitry Skiba
2016/02/24 14:39:04
Done.
| |
23 // b. When used in a template on a dependent type WriteParam() must | |
24 // explicitly specify template argument (WriteParam<T>(...)) because | |
25 // template arguments are checked by #2 | |
dcheng
2016/02/23 19:46:47
Hmm... is it possible to fix this shortcoming? It'
Dmitry Skiba
2016/02/24 14:39:04
Yes, but that only for templates. Everywhere else
dcheng
2016/02/24 22:57:42
So assume I have a clang::CallExpr representing th
| |
26 // 2. IPC::CheckedTuple<> specializations, both in CheckedTuple<> and | |
27 // all specializations it references (i.e. std::vector<Set<size_t>> is | |
28 // not allowed because size_t is blacklisted) | |
29 | |
30 #ifndef TOOLS_CLANG_PLUGINS_CHECKIPC_VISITOR_H_ | |
31 #define TOOLS_CLANG_PLUGINS_CHECKIPC_VISITOR_H_ | |
32 | |
33 #include <vector> | |
34 | |
35 #include "clang/AST/AST.h" | |
36 #include "clang/AST/ASTConsumer.h" | |
37 #include "clang/AST/RecursiveASTVisitor.h" | |
38 #include "clang/Frontend/CompilerInstance.h" | |
39 | |
40 namespace chrome_checker { | |
41 | |
42 class CheckIPCVisitor { | |
43 public: | |
44 explicit CheckIPCVisitor(clang::CompilerInstance& compiler); | |
45 | |
46 void set_context(clang::ASTContext* context) { context_ = context; } | |
47 | |
48 bool shouldVisitTemplateInstantiations() const { return true; } | |
dcheng
2016/02/23 19:46:47
NameLikeThis or name_like_this please.
Dmitry Skiba
2016/02/24 14:39:04
Done.
| |
49 | |
50 void BeginDecl(clang::Decl*); | |
51 void EndDecl(); | |
52 void VisitTemplateSpecializationType(clang::TemplateSpecializationType*); | |
53 void VisitCallExpr(clang::CallExpr*); | |
54 | |
55 private: | |
56 /* ValidateXXX functions return false if validation failed and diagnostic | |
dcheng
2016/02/23 19:46:47
Nit: Use C++ style // comments for consistency.
Dmitry Skiba
2016/02/24 14:39:04
Done.
| |
57 was reported. They return true otherwise (not applicable / validation | |
58 succeeded). | |
59 */ | |
60 | |
61 bool ValidateWriteParam(const clang::CallExpr* call_expr) const; | |
62 | |
63 bool ValidateWriteParamSignature(const clang::CallExpr* call_expr) const; | |
64 | |
65 bool ValidateWriteParamInsideTemplate( | |
66 const clang::CallExpr* call_expr, | |
67 const clang::UnresolvedLookupExpr* lookup_expr) const; | |
68 | |
69 bool ValidateWriteParamArgument(const clang::Expr* arg_expr) const; | |
70 | |
71 bool ValidateWriteParamCaller(const clang::CallExpr* call_expr) const; | |
72 | |
73 bool ValidateCheckedTuple( | |
74 const clang::TemplateSpecializationType* spec) const; | |
75 | |
76 bool IsInsideParamTraits() const; | |
77 | |
78 template <typename T> | |
79 const T* GetParentDecl() const; | |
80 | |
81 clang::CompilerInstance& compiler_; | |
82 clang::ASTContext* context_; | |
83 | |
84 unsigned error_write_param_bad_type_; | |
85 unsigned error_tuple_bad_type_; | |
86 | |
87 unsigned error_write_param_template_arg_; | |
88 unsigned error_write_param_wrong_template_; | |
89 unsigned error_write_param_bad_signature_; | |
90 unsigned note_see_here_; | |
91 | |
92 std::vector<const clang::Decl*> decl_stack_; | |
93 }; | |
94 | |
95 } // namespace chrome_checker | |
96 | |
97 #endif // TOOLS_CLANG_PLUGINS_CHECKIPC_VISITOR_H_ | |
OLD | NEW |