mirror of
https://github.com/capstone-engine/llvm-capstone.git
synced 2024-12-03 11:23:58 +00:00
[tidy] Expose getID to tidy checks
This also fixes a possible use-after-free in the IdentifierNamingCheck. Differential Revision: https://reviews.llvm.org/D150254
This commit is contained in:
parent
655f0fc4b9
commit
2b240cc377
@ -407,7 +407,6 @@ public:
|
||||
|
||||
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 @@ protected:
|
||||
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.
|
||||
|
@ -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(
|
||||
|
@ -11,6 +11,7 @@
|
||||
|
||||
#include "../utils/RenamerClangTidyCheck.h"
|
||||
#include <optional>
|
||||
#include <string>
|
||||
namespace clang::tidy {
|
||||
namespace readability {
|
||||
|
||||
@ -202,7 +203,6 @@ private:
|
||||
mutable llvm::StringMap<FileStyle> NamingStylesCache;
|
||||
FileStyle *MainFileStyle;
|
||||
ClangTidyContext *Context;
|
||||
const StringRef CheckName;
|
||||
const bool GetConfigPerFile;
|
||||
const bool IgnoreFailedSplit;
|
||||
HungarianNotation HungarianNotation;
|
||||
|
Loading…
Reference in New Issue
Block a user