|
|
|||
File indexing completed on 2026-05-10 08:36:19
0001 //===--- NoMallocCheck.h - clang-tidy----------------------------*- C++ -*-===// 0002 // 0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 0004 // See https://llvm.org/LICENSE.txt for license information. 0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 0006 // 0007 //===----------------------------------------------------------------------===// 0008 0009 #ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H 0010 #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H 0011 0012 #include "../ClangTidyCheck.h" 0013 0014 namespace clang::tidy::cppcoreguidelines { 0015 0016 /// This checker is concerned with C-style memory management and suggest modern 0017 /// alternatives to it. 0018 /// The check is only enabled in C++. For analyzing malloc calls see Clang 0019 /// Static Analyzer - unix.Malloc. 0020 /// 0021 /// For the user-facing documentation see: 0022 /// http://clang.llvm.org/extra/clang-tidy/checks/cppcoreguidelines/no-malloc.html 0023 class NoMallocCheck : public ClangTidyCheck { 0024 public: 0025 /// Construct Checker and read in configuration for function names. 0026 NoMallocCheck(StringRef Name, ClangTidyContext *Context) 0027 : ClangTidyCheck(Name, Context), 0028 AllocList(Options.get("Allocations", "::malloc;::calloc")), 0029 ReallocList(Options.get("Reallocations", "::realloc")), 0030 DeallocList(Options.get("Deallocations", "::free")) {} 0031 0032 bool isLanguageVersionSupported(const LangOptions &LangOpts) const override { 0033 return LangOpts.CPlusPlus; 0034 } 0035 0036 /// Make configuration of checker discoverable. 0037 void storeOptions(ClangTidyOptions::OptionMap &Opts) override; 0038 0039 /// Registering for malloc, calloc, realloc and free calls. 0040 void registerMatchers(ast_matchers::MatchFinder *Finder) override; 0041 0042 /// Checks matched function calls and gives suggestion to modernize the code. 0043 void check(const ast_matchers::MatchFinder::MatchResult &Result) override; 0044 0045 private: 0046 /// Semicolon-separated list of fully qualified names of memory allocation 0047 /// functions the check warns about. Defaults to `::malloc;::calloc`. 0048 const StringRef AllocList; 0049 /// Semicolon-separated list of fully qualified names of memory reallocation 0050 /// functions the check warns about. Defaults to `::realloc`. 0051 const StringRef ReallocList; 0052 /// Semicolon-separated list of fully qualified names of memory deallocation 0053 /// functions the check warns about. Defaults to `::free`. 0054 const StringRef DeallocList; 0055 }; 0056 0057 } // namespace clang::tidy::cppcoreguidelines 0058 0059 #endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CPPCOREGUIDELINES_NO_MALLOC_H
| [ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
|
This page was automatically generated by the 2.3.7 LXR engine. The LXR team |
|