clang-tools
10.0.0
clang-tools-extra
clang-tidy
cppcoreguidelines
NoMallocCheck.h
Go to the documentation of this file.
1
//===--- NoMallocCheck.h - clang-tidy----------------------------*- C++ -*-===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
10
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
11
12
#include "../ClangTidy.h"
13
#include "clang/AST/ASTContext.h"
14
#include "clang/ASTMatchers/ASTMatchFinder.h"
15
16
namespace
clang
{
17
namespace
tidy {
18
namespace
cppcoreguidelines {
19
20
/// This checker is concerned with C-style memory management and suggest modern
21
/// alternatives to it.
22
/// The check is only enabled in C++. For analyzing malloc calls see Clang
23
/// Static Analyzer - unix.Malloc.
24
///
25
/// For the user-facing documentation see:
26
/// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines-no-malloc.html
27
class
NoMallocCheck
:
public
ClangTidyCheck
{
28
public
:
29
/// Construct Checker and read in configuration for function names.
30
NoMallocCheck
(StringRef
Name
,
ClangTidyContext
*Context)
31
:
ClangTidyCheck
(Name, Context),
32
AllocList(
Options
.get(
"Allocations"
,
"::malloc;::calloc"
)),
33
ReallocList(
Options
.get(
"Reallocations"
,
"::realloc"
)),
34
DeallocList(
Options
.get(
"Deallocations"
,
"::free"
)) {}
35
36
/// Make configuration of checker discoverable.
37
void
storeOptions
(
ClangTidyOptions::OptionMap
&Opts)
override
;
38
39
/// Registering for malloc, calloc, realloc and free calls.
40
void
registerMatchers
(ast_matchers::MatchFinder *Finder)
override
;
41
42
/// Checks matched function calls and gives suggestion to modernize the code.
43
void
check
(
const
ast_matchers::MatchFinder::MatchResult &Result)
override
;
44
45
private
:
46
/// Semicolon-separated list of fully qualified names of memory allocation
47
/// functions the check warns about. Defaults to `::malloc;::calloc`.
48
const
std::string AllocList;
49
/// Semicolon-separated list of fully qualified names of memory reallocation
50
/// functions the check warns about. Defaults to `::realloc`.
51
const
std::string ReallocList;
52
/// Semicolon-separated list of fully qualified names of memory deallocation
53
/// functions the check warns about. Defaults to `::free`.
54
const
std::string DeallocList;
55
};
56
57
}
// namespace cppcoreguidelines
58
}
// namespace tidy
59
}
// namespace clang
60
61
#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:30
clang::tidy::cppcoreguidelines::NoMallocCheck::storeOptions
void storeOptions(ClangTidyOptions::OptionMap &Opts) override
Make configuration of checker discoverable.
Definition:
NoMallocCheck.cpp:33
clang::tidy::cppcoreguidelines::NoMallocCheck
This checker is concerned with C-style memory management and suggest modern alternatives to it...
Definition:
NoMallocCheck.h:27
clang::tidy::ClangTidyCheck
Base class for all clang-tidy checks.
Definition:
ClangTidyCheck.h:47
clang::tidy::ClangTidyCheck::Options
OptionsView Options
Definition:
ClangTidyCheck.h:184
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:62
Name
static constexpr llvm::StringLiteral Name
Definition:
UppercaseLiteralSuffixCheck.cpp:27
clang::tidy::ClangTidyOptions::OptionMap
std::map< std::string, std::string > OptionMap
Definition:
ClangTidyOptions.h:97
clang::tidy::cppcoreguidelines::NoMallocCheck::registerMatchers
void registerMatchers(ast_matchers::MatchFinder *Finder) override
Registering for malloc, calloc, realloc and free calls.
Definition:
NoMallocCheck.cpp:39
clang
===– Representation.cpp - ClangDoc Representation --------—*- C++ -*-===//
Definition:
ApplyReplacements.h:27
clang::tidy::ClangTidyContext
Every ClangTidyCheck reports errors through a DiagnosticsEngine provided by this context.
Definition:
ClangTidyDiagnosticConsumer.h:77
Generated on Thu Mar 19 2020 12:57:25 for clang-tools by
1.8.13