diff options
author | Benjamin Kramer <benny.kra@googlemail.com> | 2014-07-08 14:32:17 +0000 |
---|---|---|
committer | Benjamin Kramer <benny.kra@googlemail.com> | 2014-07-08 14:32:17 +0000 |
commit | 190e2cfd7459b5acc30f12702137ce33913b85b4 (patch) | |
tree | cd97d25268318ea65f973576a3fa124afe2da34c /clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h | |
parent | eb893a1fd688362a7809525c3b8761b77090f048 (diff) | |
download | bcm5719-llvm-190e2cfd7459b5acc30f12702137ce33913b85b4.tar.gz bcm5719-llvm-190e2cfd7459b5acc30f12702137ce33913b85b4.zip |
[clang-tidy] Add a little checker for Twine locals in LLVM.
Those often cause use after free bugs and should be generally avoided.
Technically it is safe to have a Twine with >=2 components in a variable
but I don't think it is a good pattern to follow. The almost trivial checker
comes with elaborated fix-it hints that turn the Twine into a std::string
if necessary and otherwise fall back to the original type if the Twine
is created from a single value.
llvm-svn: 212535
Diffstat (limited to 'clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h')
-rw-r--r-- | clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h new file mode 100644 index 00000000000..f538f81430c --- /dev/null +++ b/clang-tools-extra/clang-tidy/llvm/TwineLocalCheck.h @@ -0,0 +1,31 @@ +//===--- TwineLocalCheck.h - clang-tidy -------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_TWINE_LOCAL_CHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_TWINE_LOCAL_CHECK_H + +#include "../ClangTidy.h" +#include "llvm/Support/Regex.h" + +namespace clang { +namespace tidy { + +/// \brief Looks for local Twine variables which are prone to use after frees +/// and should be generally avoided. +class TwineLocalCheck : public ClangTidyCheck { +public: + TwineLocalCheck(); + void registerMatchers(ast_matchers::MatchFinder *Finder) override; + void check(const ast_matchers::MatchFinder::MatchResult &Result) override; +}; + +} // namespace tidy +} // namespace clang + +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_LLVM_TWINE_LOCAL_CHECK_H |