clang-tools
5.0.0
Main Page
Namespaces
Classes
Files
File List
File Members
llvm.src
tools
clang
tools
extra
clang-tidy
cppcoreguidelines
NoMallocCheck.h
Go to the documentation of this file.
1
//===--- NoMallocCheck.h - clang-tidy----------------------------*- C++ -*-===//
2
//
3
// The LLVM Compiler Infrastructure
4
//
5
// This file is distributed under the University of Illinois Open Source
6
// License. See LICENSE.TXT for details.
7
//
8
//===----------------------------------------------------------------------===//
9
10
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
11
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
12
13
#include "../ClangTidy.h"
14
#include "clang/AST/ASTContext.h"
15
#include "clang/ASTMatchers/ASTMatchFinder.h"
16
17
namespace
clang {
18
namespace
tidy {
19
namespace
cppcoreguidelines {
20
21
/// This checker is concerned with C-style memory management and suggest modern
22
/// alternatives to it.
23
/// The check is only enabled in C++. For analyzing malloc calls see Clang
24
/// Static Analyzer - unix.Malloc.
25
///
26
/// For the user-facing documentation see:
27
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-no-malloc.html
28
class
NoMallocCheck
:
public
ClangTidyCheck
{
29
public
:
30
/// Construct Checker and read in configuration for function names.
31
NoMallocCheck
(StringRef
Name
,
ClangTidyContext
*Context)
32
:
ClangTidyCheck
(Name, Context),
33
AllocList(
Options
.get(
"Allocations"
,
"::malloc;::calloc"
)),
34
ReallocList(
Options
.get(
"Reallocations"
,
"::realloc"
)),
35
DeallocList(
Options
.get(
"Deallocations"
,
"::free"
)) {}
36
37
/// Make configuration of checker discoverable.
38
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
39
40
/// Registering for malloc, calloc, realloc and free calls.
41
void
registerMatchers
(ast_matchers::MatchFinder *
Finder
)
override
;
42
43
/// Checks matched function calls and gives suggestion to modernize the code.
44
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
45
46
private
:
47
/// Semicolon-separated list of fully qualified names of memory allocation
48
/// functions the check warns about. Defaults to `::malloc;::calloc`.
49
const
std::string AllocList;
50
/// Semicolon-separated list of fully qualified names of memory reallocation
51
/// functions the check warns about. Defaults to `::realloc`.
52
const
std::string ReallocList;
53
/// Semicolon-separated list of fully qualified names of memory deallocation
54
/// functions the check warns about. Defaults to `::free`.
55
const
std::string DeallocList;
56
};
57
58
}
// namespace cppcoreguidelines
59
}
// namespace tidy
60
}
// namespace clang
61
62
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
clang::tidy::cppcoreguidelines::NoMallocCheck::NoMallocCheck
NoMallocCheck(StringRef Name, ClangTidyContext *Context)
Construct Checker and read in configuration for function names.
Definition:
NoMallocCheck.h:31
Name
StringHandle Name
Definition:
PreprocessorTracker.cpp:525
Finder
std::unique_ptr< ast_matchers::MatchFinder > Finder
Definition:
ClangTidy.cpp:275
clang::tidy::cppcoreguidelines::NoMallocCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Make configuration of checker discoverable.
Definition:
NoMallocCheck.cpp:34
clang::tidy::cppcoreguidelines::NoMallocCheck
This checker is concerned with C-style memory management and suggest modern alternatives to it...
Definition:
NoMallocCheck.h:28
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidy.h:127
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition:
ClangTidy.h:183
clang::tidy::cppcoreguidelines::NoMallocCheck::check
void check(const ast_matchers::MatchFinder::MatchResult &Result) override
Checks matched function calls and gives suggestion to modernize the code.
Definition:
NoMallocCheck.cpp:63
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition:
ClangTidyOptions.h:99
clang::tidy::cppcoreguidelines::NoMallocCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Registering for malloc, calloc, realloc and free calls.
Definition:
NoMallocCheck.cpp:40
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:104
Generated on Mon Aug 14 2017 13:32:20 for clang-tools by
1.8.6