[clang-tools-extra] 2b240cc - [tidy] Expose getID to tidy checks
Kadir Cetinkaya via cfe-commits
cfe-commits at lists.llvm.org
Wed May 10 03:53:02 PDT 2023
Author: Kadir Cetinkaya
Date: 2023-05-10T12:50:25+02:00
New Revision: 2b240cc377b5e4f41c05d68c9a513f7d08ab69c8
URL: https://github.com/llvm/llvm-project/commit/2b240cc377b5e4f41c05d68c9a513f7d08ab69c8
DIFF: https://github.com/llvm/llvm-project/commit/2b240cc377b5e4f41c05d68c9a513f7d08ab69c8.diff
LOG: [tidy] Expose getID to tidy checks
This also fixes a possible use-after-free in the IdentifierNamingCheck.
Differential Revision: https://reviews.llvm.org/D150254
Added:
Modified:
clang-tools-extra/clang-tidy/ClangTidyCheck.h
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/ClangTidyCheck.h b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
index 9381b6e8becb2..17e9df96c39be 100644
--- a/clang-tools-extra/clang-tidy/ClangTidyCheck.h
+++ b/clang-tools-extra/clang-tidy/ClangTidyCheck.h
@@ -407,7 +407,6 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
private:
void run(const ast_matchers::MatchFinder::MatchResult &Result) override;
- StringRef getID() const override { return CheckName; }
std::string CheckName;
ClangTidyContext *Context;
@@ -422,6 +421,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
bool areDiagsSelfContained() const {
return Context->areDiagsSelfContained();
}
+ StringRef getID() const override { return CheckName; }
};
/// Read a named option from the ``Context`` and parse it as a bool.
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
index 9561b2b00904f..0e16edc10a953 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.cpp
@@ -14,6 +14,7 @@
#include "clang/Lex/Preprocessor.h"
#include "llvm/ADT/ArrayRef.h"
#include "llvm/ADT/DenseMapInfo.h"
+#include "llvm/ADT/StringRef.h"
#include "llvm/Support/Debug.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/FormatVariadic.h"
@@ -396,7 +397,7 @@ std::string IdentifierNamingCheck::HungarianNotation::getDeclTypeName(
IdentifierNamingCheck::IdentifierNamingCheck(StringRef Name,
ClangTidyContext *Context)
- : RenamerClangTidyCheck(Name, Context), Context(Context), CheckName(Name),
+ : RenamerClangTidyCheck(Name, Context), Context(Context),
GetConfigPerFile(Options.get("GetConfigPerFile", true)),
IgnoreFailedSplit(Options.get("IgnoreFailedSplit", false)) {
@@ -1461,6 +1462,7 @@ IdentifierNamingCheck::getStyleForFile(StringRef FileName) const {
if (Iter != NamingStylesCache.end())
return Iter->getValue();
+ llvm::StringRef CheckName = getID();
ClangTidyOptions Options = Context->getOptionsForFile(FileName);
if (Options.Checks && GlobList(*Options.Checks).contains(CheckName)) {
auto It = NamingStylesCache.try_emplace(
diff --git a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
index 3df15ad780180..2e3d4ea8c39c8 100644
--- a/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
+++ b/clang-tools-extra/clang-tidy/readability/IdentifierNamingCheck.h
@@ -11,6 +11,7 @@
#include "../utils/RenamerClangTidyCheck.h"
#include <optional>
+#include <string>
namespace clang::tidy {
namespace readability {
@@ -202,7 +203,6 @@ class IdentifierNamingCheck final : public RenamerClangTidyCheck {
mutable llvm::StringMap<FileStyle> NamingStylesCache;
FileStyle *MainFileStyle;
ClangTidyContext *Context;
- const StringRef CheckName;
const bool GetConfigPerFile;
const bool IgnoreFailedSplit;
HungarianNotation HungarianNotation;
More information about the cfe-commits
mailing list