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

Side by Side Diff: tools/clang/plugins/CheckIPCVisitor.h

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
(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 check ensures that 32/64-bit unstable types are not used in IPC.
6 //
7 // A type (or typedef) is unstable if it changes size between 32/ 64-bit
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 // Additionally, templates referencing blacklisted types (e.g. vector<long>)
20 // are also blacklisted.
21 //
22 // Blacklisted types are checked in:
23 // 1. IPC::WriteParam() calls
24 // 2. IPC::CheckedTuple<> specializations
25 //
26
27 #ifndef TOOLS_CLANG_PLUGINS_CHECKIPC_VISITOR_H_
28 #define TOOLS_CLANG_PLUGINS_CHECKIPC_VISITOR_H_
29
30 #include <vector>
31
32 #include "clang/AST/AST.h"
33 #include "clang/AST/ASTConsumer.h"
34 #include "clang/AST/RecursiveASTVisitor.h"
35 #include "clang/Frontend/CompilerInstance.h"
36 #include "llvm/ADT/StringSet.h"
37
38 namespace chrome_checker {
39
40 class CheckIPCVisitor {
41 public:
42 explicit CheckIPCVisitor(clang::CompilerInstance& compiler);
43
44 void set_context(clang::ASTContext* context) { context_ = context; }
45
46 bool should_visit_template_instantiations() const { return true; }
47
48 void BeginDecl(clang::Decl*);
dcheng 2016/03/07 23:44:39 We should probably either consistently include or
Dmitry Skiba 2016/03/08 01:16:11 Done.
49 void EndDecl();
50 void VisitTemplateSpecializationType(clang::TemplateSpecializationType*);
51 void VisitCallExpr(clang::CallExpr*);
52
53 private:
54 // ValidateXXX functions return false if validation failed and diagnostic
55 // was reported. They return true otherwise (not applicable / validation
56 // succeeded).
57
58 bool ValidateWriteParam(const clang::CallExpr* call_expr);
59
60 bool ValidateWriteParamSignature(const clang::CallExpr* call_expr);
61
62 bool ValidateWriteParamArgument(const clang::Expr* arg_expr);
63
64 bool ValidateCheckedTuple(
dcheng 2016/03/07 23:44:39 Nit: No newlines on 59, 61, 63, 71, 81, 83 to help
Dmitry Skiba 2016/03/08 01:16:11 Done.
65 const clang::TemplateSpecializationType* spec);
66
67 template <typename T>
68 const T* GetParentDecl() const;
69
70 bool IsBlacklistedType(clang::QualType type) const;
71
72 bool IsBlacklistedTypedef(const clang::TypedefNameDecl* tdef) const;
73
74 struct CheckDetails {
75 clang::QualType entry_type;
76 clang::QualType exit_type;
77 llvm::SmallVector<const clang::TypedefType*, 5> typedefs;
78 };
79
80 bool CheckType(clang::QualType type, CheckDetails* details) const;
81
82 bool CheckIntegerType(clang::QualType type, CheckDetails* details) const;
83
84 bool CheckTemplateArgument(const clang::TemplateArgument& arg,
85 CheckDetails* details) const;
86
87 void ReportCheckError(const CheckDetails& details,
88 clang::SourceLocation loc,
89 unsigned error);
90
91 clang::CompilerInstance& compiler_;
92 clang::ASTContext* context_;
93
94 unsigned error_write_param_bad_type_;
95 unsigned error_tuple_bad_type_;
96 unsigned error_write_param_bad_signature_;
97 unsigned note_see_here_;
98
99 std::vector<const clang::Decl*> decl_stack_;
100
101 llvm::StringSet<> blacklisted_typedefs_;
102 };
103
104 } // namespace chrome_checker
105
106 #endif // TOOLS_CLANG_PLUGINS_CHECKIPC_VISITOR_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698