Skip to content

Commit

Permalink
Bump to LLVM 18.1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
singiamtel committed Aug 22, 2024
1 parent ba095ee commit d2738dd
Show file tree
Hide file tree
Showing 6 changed files with 117 additions and 41 deletions.
105 changes: 88 additions & 17 deletions ClangTidyCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -184,13 +184,13 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// integral type ``T``.
///
/// Reads the option with the check-local name \p LocalName from the
/// ``CheckOptions``. If the corresponding key is not present, return
/// ``std::nullopt``.
/// ``CheckOptions``. If the corresponding key is not present,
/// return ``std::nullopt``.
///
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return ``std::nullopt``.
template <typename T>
std::enable_if_t<std::is_integral<T>::value, std::optional<T>>
std::enable_if_t<std::is_integral_v<T>, std::optional<T>>
get(StringRef LocalName) const {
if (std::optional<StringRef> Value = get(LocalName)) {
T Result{};
Expand All @@ -201,6 +201,31 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
return std::nullopt;
}

/// Read a named option from the ``Context`` and parse it as an
/// integral type ``T``.
///
/// Reads the option with the check-local name \p LocalName from the
/// ``CheckOptions``. If the corresponding key is `none`, `null`,
/// `-1` or empty, return ``std::nullopt``. If the corresponding
/// key is not present, return \p Default.
///
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return \p Default.
template <typename T>
std::enable_if_t<std::is_integral_v<T>, std::optional<T>>
get(StringRef LocalName, std::optional<T> Default) const {
if (std::optional<StringRef> Value = get(LocalName)) {
if (Value == "" || Value == "none" || Value == "null" ||
(std::is_unsigned_v<T> && Value == "-1"))
return std::nullopt;
T Result{};
if (!StringRef(*Value).getAsInteger(10, Result))
return Result;
diagnoseBadIntegerOption(NamePrefix + LocalName, *Value);
}
return Default;
}

/// Read a named option from the ``Context`` and parse it as an
/// integral type ``T``.
///
Expand All @@ -211,8 +236,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return \p Default.
template <typename T>
std::enable_if_t<std::is_integral<T>::value, T> get(StringRef LocalName,
T Default) const {
std::enable_if_t<std::is_integral_v<T>, T> get(StringRef LocalName,
T Default) const {
return get<T>(LocalName).value_or(Default);
}

Expand All @@ -227,7 +252,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return ``std::nullopt``.
template <typename T>
std::enable_if_t<std::is_integral<T>::value, std::optional<T>>
std::enable_if_t<std::is_integral_v<T>, std::optional<T>>
getLocalOrGlobal(StringRef LocalName) const {
std::optional<StringRef> ValueOr = get(LocalName);
bool IsGlobal = false;
Expand All @@ -245,6 +270,39 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
return std::nullopt;
}

/// Read a named option from the ``Context`` and parse it as an
/// integral type ``T``.
///
/// Reads the option with the check-local name \p LocalName from local or
/// global ``CheckOptions``. Gets local option first. If local is not
/// present, falls back to get global option. If global option is not
/// present either, return \p Default. If the value value was found
/// and equals ``none``, ``null``, ``-1`` or empty, return ``std::nullopt``.
///
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return \p Default.
template <typename T>
std::enable_if_t<std::is_integral_v<T>, std::optional<T>>
getLocalOrGlobal(StringRef LocalName, std::optional<T> Default) const {
std::optional<StringRef> ValueOr = get(LocalName);
bool IsGlobal = false;
if (!ValueOr) {
IsGlobal = true;
ValueOr = getLocalOrGlobal(LocalName);
if (!ValueOr)
return Default;
}
T Result{};
if (ValueOr == "" || ValueOr == "none" || ValueOr == "null" ||
(std::is_unsigned_v<T> && ValueOr == "-1"))
return std::nullopt;
if (!StringRef(*ValueOr).getAsInteger(10, Result))
return Result;
diagnoseBadIntegerOption(
IsGlobal ? Twine(LocalName) : NamePrefix + LocalName, *ValueOr);
return Default;
}

/// Read a named option from the ``Context`` and parse it as an
/// integral type ``T``.
///
Expand All @@ -256,7 +314,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return \p Default.
template <typename T>
std::enable_if_t<std::is_integral<T>::value, T>
std::enable_if_t<std::is_integral_v<T>, T>
getLocalOrGlobal(StringRef LocalName, T Default) const {
return getLocalOrGlobal<T>(LocalName).value_or(Default);
}
Expand All @@ -274,7 +332,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
/// supply the mapping required to convert between ``T`` and a string.
template <typename T>
std::enable_if_t<std::is_enum<T>::value, std::optional<T>>
std::enable_if_t<std::is_enum_v<T>, std::optional<T>>
get(StringRef LocalName, bool IgnoreCase = false) const {
if (std::optional<int64_t> ValueOr =
getEnumInt(LocalName, typeEraseMapping<T>(), false, IgnoreCase))
Expand All @@ -286,17 +344,17 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// enum type ``T``.
///
/// Reads the option with the check-local name \p LocalName from the
/// ``CheckOptions``. If the corresponding key is not present, return
/// \p Default.
/// ``CheckOptions``. If the corresponding key is not present,
/// return \p Default.
///
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return \p Default.
///
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
/// supply the mapping required to convert between ``T`` and a string.
template <typename T>
std::enable_if_t<std::is_enum<T>::value, T>
get(StringRef LocalName, T Default, bool IgnoreCase = false) const {
std::enable_if_t<std::is_enum_v<T>, T> get(StringRef LocalName, T Default,
bool IgnoreCase = false) const {
return get<T>(LocalName, IgnoreCase).value_or(Default);
}

Expand All @@ -314,7 +372,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
/// supply the mapping required to convert between ``T`` and a string.
template <typename T>
std::enable_if_t<std::is_enum<T>::value, std::optional<T>>
std::enable_if_t<std::is_enum_v<T>, std::optional<T>>
getLocalOrGlobal(StringRef LocalName, bool IgnoreCase = false) const {
if (std::optional<int64_t> ValueOr =
getEnumInt(LocalName, typeEraseMapping<T>(), true, IgnoreCase))
Expand All @@ -336,7 +394,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
/// supply the mapping required to convert between ``T`` and a string.
template <typename T>
std::enable_if_t<std::is_enum<T>::value, T>
std::enable_if_t<std::is_enum_v<T>, T>
getLocalOrGlobal(StringRef LocalName, T Default,
bool IgnoreCase = false) const {
return getLocalOrGlobal<T>(LocalName, IgnoreCase).value_or(Default);
Expand All @@ -350,19 +408,32 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// Stores an option with the check-local name \p LocalName with
/// integer value \p Value to \p Options.
template <typename T>
std::enable_if_t<std::is_integral<T>::value>
std::enable_if_t<std::is_integral_v<T>>
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
T Value) const {
storeInt(Options, LocalName, Value);
}

/// Stores an option with the check-local name \p LocalName with
/// integer value \p Value to \p Options. If the value is empty
/// stores ``
template <typename T>
std::enable_if_t<std::is_integral_v<T>>
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
std::optional<T> Value) const {
if (Value)
storeInt(Options, LocalName, *Value);
else
store(Options, LocalName, "none");
}

/// Stores an option with the check-local name \p LocalName as the string
/// representation of the Enum \p Value to \p Options.
///
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
/// supply the mapping required to convert between ``T`` and a string.
template <typename T>
std::enable_if_t<std::is_enum<T>::value>
std::enable_if_t<std::is_enum_v<T>>
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
T Value) const {
ArrayRef<std::pair<T, StringRef>> Mapping =
Expand All @@ -383,7 +454,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
bool CheckGlobal, bool IgnoreCase) const;

template <typename T>
std::enable_if_t<std::is_enum<T>::value, std::vector<NameAndValue>>
std::enable_if_t<std::is_enum_v<T>, std::vector<NameAndValue>>
typeEraseMapping() const {
ArrayRef<std::pair<T, StringRef>> Mapping =
OptionEnumMapping<T>::getEnumMapping();
Expand Down
30 changes: 19 additions & 11 deletions ClangTidyDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,8 @@ class ClangTidyContext {
public:
/// Initializes \c ClangTidyContext instance.
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
bool AllowEnablingAnalyzerAlphaCheckers = false);
bool AllowEnablingAnalyzerAlphaCheckers = false,
bool EnableModuleHeadersParsing = false);
/// Sets the DiagnosticsEngine that diag() will emit diagnostics to.
// FIXME: this is required initialization, and should be a constructor param.
// Fix the context -> diag engine -> consumer -> context initialization cycle.
Expand All @@ -86,10 +87,10 @@ class ClangTidyContext {
/// tablegen'd diagnostic IDs.
/// FIXME: Figure out a way to manage ID spaces.
DiagnosticBuilder diag(StringRef CheckName, SourceLocation Loc,
StringRef Message,
StringRef Description,
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);

DiagnosticBuilder diag(StringRef CheckName, StringRef Message,
DiagnosticBuilder diag(StringRef CheckName, StringRef Description,
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);

DiagnosticBuilder diag(const tooling::Diagnostic &Error);
Expand Down Expand Up @@ -198,18 +199,24 @@ class ClangTidyContext {
return AllowEnablingAnalyzerAlphaCheckers;
}

// This method determines whether preprocessor-level module header parsing is
// enabled using the `--experimental-enable-module-headers-parsing` option.
bool canEnableModuleHeadersParsing() const {
return EnableModuleHeadersParsing;
}

void setSelfContainedDiags(bool Value) { SelfContainedDiags = Value; }

bool areDiagsSelfContained() const { return SelfContainedDiags; }

using DiagLevelAndFormatString = std::pair<DiagnosticIDs::Level, std::string>;
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID,
SourceLocation Loc) {
return DiagLevelAndFormatString(
return {
static_cast<DiagnosticIDs::Level>(
DiagEngine->getDiagnosticLevel(DiagnosticID, Loc)),
std::string(
DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID)));
DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID))};
}

void setOptionsCollector(llvm::StringSet<> *Collector) {
Expand All @@ -221,7 +228,7 @@ class ClangTidyContext {
// Writes to Stats.
friend class ClangTidyDiagnosticConsumer;

DiagnosticsEngine *DiagEngine;
DiagnosticsEngine *DiagEngine = nullptr;
std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;

std::string CurrentFile;
Expand All @@ -241,12 +248,13 @@ class ClangTidyContext {

llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;

bool Profile;
bool Profile = false;
std::string ProfilePrefix;

bool AllowEnablingAnalyzerAlphaCheckers;
bool EnableModuleHeadersParsing;

bool SelfContainedDiags;
bool SelfContainedDiags = false;

NoLintDirectiveHandler NoLintHandler;
llvm::StringSet<> *OptionsCollector = nullptr;
Expand Down Expand Up @@ -305,9 +313,9 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
bool EnableNolintBlocks;
std::vector<ClangTidyError> Errors;
std::unique_ptr<llvm::Regex> HeaderFilter;
bool LastErrorRelatesToUserCode;
bool LastErrorPassesLineFilter;
bool LastErrorWasIgnored;
bool LastErrorRelatesToUserCode = false;
bool LastErrorPassesLineFilter = false;
bool LastErrorWasIgnored = false;
};

} // end namespace tidy
Expand Down
2 changes: 1 addition & 1 deletion ClangTidyModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class ClangTidyCheckFactories {
std::vector<std::unique_ptr<ClangTidyCheck>>
createChecksForLanguage(ClangTidyContext *Context) const;

typedef llvm::StringMap<CheckFactory> FactoryMap;
using FactoryMap = llvm::StringMap<CheckFactory>;
FactoryMap::const_iterator begin() const { return Factories.begin(); }
FactoryMap::const_iterator end() const { return Factories.end(); }
bool empty() const { return Factories.empty(); }
Expand Down
2 changes: 1 addition & 1 deletion ClangTidyModuleRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

namespace clang::tidy {

typedef llvm::Registry<ClangTidyModule> ClangTidyModuleRegistry;
using ClangTidyModuleRegistry = llvm::Registry<ClangTidyModule>;

} // namespace clang::tidy

Expand Down
17 changes: 7 additions & 10 deletions ClangTidyOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct FileFilter {
std::string Name;

/// LineRange is a pair<start, end> (inclusive).
typedef std::pair<unsigned, unsigned> LineRange;
using LineRange = std::pair<unsigned int, unsigned int>;

/// A list of line ranges in this file, for which we show warnings.
std::vector<LineRange> LineRanges;
Expand Down Expand Up @@ -118,13 +118,13 @@ struct ClangTidyOptions {
/// files to disambiguate local vs global value from different levels.
unsigned Priority = 0;
};
typedef std::pair<std::string, std::string> StringPair;
typedef llvm::StringMap<ClangTidyValue> OptionMap;
using StringPair = std::pair<std::string, std::string>;
using OptionMap = llvm::StringMap<ClangTidyValue>;

/// Key-value mapping used to store check-specific options.
OptionMap CheckOptions;

typedef std::vector<std::string> ArgList;
using ArgList = std::vector<std::string>;

/// Add extra compilation arguments to the end of the list.
std::optional<ArgList> ExtraArgs;
Expand Down Expand Up @@ -165,7 +165,7 @@ class ClangTidyOptionsProvider {
/// commandline option is specified, clang-tidy will ignore the
/// configuration file.
/// * '-checks' commandline option.
typedef std::pair<ClangTidyOptions, std::string> OptionsSource;
using OptionsSource = std::pair<ClangTidyOptions, std::string>;

/// Returns an ordered vector of OptionsSources, in order of increasing
/// priority.
Expand Down Expand Up @@ -199,9 +199,7 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
protected:
// A pair of configuration file base name and a function parsing
// configuration from text in the corresponding format.
typedef std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions>(
llvm::MemoryBufferRef)>>
ConfigFileHandler;
using ConfigFileHandler = std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions> (llvm::MemoryBufferRef)>>;

/// Configuration file handlers listed in the order of priority.
///
Expand All @@ -220,7 +218,7 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
///
/// With the order of handlers shown above, the ".my-tidy-config" file would
/// take precedence over ".clang-tidy" if both reside in the same directory.
typedef std::vector<ConfigFileHandler> ConfigFileHandlers;
using ConfigFileHandlers = std::vector<ConfigFileHandler>;

FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions,
ClangTidyOptions DefaultOptions,
Expand All @@ -232,7 +230,6 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
ClangTidyOptions OverrideOptions,
ConfigFileHandlers ConfigHandlers);

protected:
void addRawFileOptions(llvm::StringRef AbsolutePath,
std::vector<OptionsSource> &CurOptions);

Expand Down
2 changes: 1 addition & 1 deletion FileExtensionsSet.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "llvm/ADT/StringRef.h"

namespace clang::tidy {
typedef llvm::SmallSet<llvm::StringRef, 5> FileExtensionsSet;
using FileExtensionsSet = llvm::SmallSet<llvm::StringRef, 5>;
} // namespace clang::tidy

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H

0 comments on commit d2738dd

Please sign in to comment.