Skip to content

Commit

Permalink
Merge pull request #40 from davidrohr/PR
Browse files Browse the repository at this point in the history
Bump to LLVM 17.0.6
  • Loading branch information
davidrohr authored Aug 9, 2024
2 parents a22935e + 1f7dc38 commit ba095ee
Show file tree
Hide file tree
Showing 11 changed files with 117 additions and 91 deletions.
68 changes: 34 additions & 34 deletions ClangTidyCheck.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include "ClangTidyOptions.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Basic/Diagnostic.h"
#include "llvm/ADT/Optional.h"
#include <optional>
#include <type_traits>
#include <utility>
#include <vector>
Expand Down Expand Up @@ -154,8 +154,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
///
/// Reads the option with the check-local name \p LocalName from the
/// ``CheckOptions``. If the corresponding key is not present, return
/// ``None``.
llvm::Optional<StringRef> get(StringRef LocalName) const;
/// ``std::nullopt``.
std::optional<StringRef> get(StringRef LocalName) const;

/// Read a named option from the ``Context``.
///
Expand All @@ -169,8 +169,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// 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 ``None``.
llvm::Optional<StringRef> getLocalOrGlobal(StringRef LocalName) const;
/// present either, return ``std::nullopt``.
std::optional<StringRef> getLocalOrGlobal(StringRef LocalName) const;

/// Read a named option from the ``Context``.
///
Expand All @@ -185,20 +185,20 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
///
/// Reads the option with the check-local name \p LocalName from the
/// ``CheckOptions``. If the corresponding key is not present, return
/// ``None``.
/// ``std::nullopt``.
///
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return ``None``.
/// diagnostic and return ``std::nullopt``.
template <typename T>
std::enable_if_t<std::is_integral<T>::value, llvm::Optional<T>>
std::enable_if_t<std::is_integral<T>::value, std::optional<T>>
get(StringRef LocalName) const {
if (llvm::Optional<StringRef> Value = get(LocalName)) {
if (std::optional<StringRef> Value = get(LocalName)) {
T Result{};
if (!StringRef(*Value).getAsInteger(10, Result))
return Result;
diagnoseBadIntegerOption(NamePrefix + LocalName, *Value);
}
return None;
return std::nullopt;
}

/// Read a named option from the ``Context`` and parse it as an
Expand All @@ -222,27 +222,27 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// 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 ``None``.
/// present either, return ``std::nullopt``.
///
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return ``None``.
/// diagnostic and return ``std::nullopt``.
template <typename T>
std::enable_if_t<std::is_integral<T>::value, llvm::Optional<T>>
std::enable_if_t<std::is_integral<T>::value, std::optional<T>>
getLocalOrGlobal(StringRef LocalName) const {
llvm::Optional<StringRef> ValueOr = get(LocalName);
std::optional<StringRef> ValueOr = get(LocalName);
bool IsGlobal = false;
if (!ValueOr) {
IsGlobal = true;
ValueOr = getLocalOrGlobal(LocalName);
if (!ValueOr)
return None;
return std::nullopt;
}
T Result{};
if (!StringRef(*ValueOr).getAsInteger(10, Result))
return Result;
diagnoseBadIntegerOption(
IsGlobal ? Twine(LocalName) : NamePrefix + LocalName, *ValueOr);
return None;
return std::nullopt;
}

/// Read a named option from the ``Context`` and parse it as an
Expand All @@ -266,20 +266,20 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
///
/// Reads the option with the check-local name \p LocalName from the
/// ``CheckOptions``. If the corresponding key is not present, return
/// ``None``.
/// ``std::nullopt``.
///
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return ``None``.
/// diagnostic and return ``std::nullopt``.
///
/// \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, llvm::Optional<T>>
std::enable_if_t<std::is_enum<T>::value, std::optional<T>>
get(StringRef LocalName, bool IgnoreCase = false) const {
if (llvm::Optional<int64_t> ValueOr =
if (std::optional<int64_t> ValueOr =
getEnumInt(LocalName, typeEraseMapping<T>(), false, IgnoreCase))
return static_cast<T>(*ValueOr);
return None;
return std::nullopt;
}

/// Read a named option from the ``Context`` and parse it as an
Expand All @@ -306,20 +306,20 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
/// 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, returns ``None``.
/// present either, returns ``std::nullopt``.
///
/// If the corresponding key can't be parsed as a ``T``, emit a
/// diagnostic and return ``None``.
/// diagnostic and return ``std::nullopt``.
///
/// \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, llvm::Optional<T>>
std::enable_if_t<std::is_enum<T>::value, std::optional<T>>
getLocalOrGlobal(StringRef LocalName, bool IgnoreCase = false) const {
if (llvm::Optional<int64_t> ValueOr =
if (std::optional<int64_t> ValueOr =
getEnumInt(LocalName, typeEraseMapping<T>(), true, IgnoreCase))
return static_cast<T>(*ValueOr);
return None;
return std::nullopt;
}

/// Read a named option from the ``Context`` and parse it as an
Expand Down Expand Up @@ -378,9 +378,9 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
private:
using NameAndValue = std::pair<int64_t, StringRef>;

llvm::Optional<int64_t> getEnumInt(StringRef LocalName,
ArrayRef<NameAndValue> Mapping,
bool CheckGlobal, bool IgnoreCase) const;
std::optional<int64_t> getEnumInt(StringRef LocalName,
ArrayRef<NameAndValue> Mapping,
bool CheckGlobal, bool IgnoreCase) const;

template <typename T>
std::enable_if_t<std::is_enum<T>::value, std::vector<NameAndValue>>
Expand All @@ -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;

Expand All @@ -422,18 +421,19 @@ 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.
///
/// Reads the option with the check-local name \p LocalName from the
/// ``CheckOptions``. If the corresponding key is not present, return
/// ``None``.
/// ``std::nullopt``.
///
/// If the corresponding key can't be parsed as a bool, emit a
/// diagnostic and return ``None``.
/// diagnostic and return ``std::nullopt``.
template <>
llvm::Optional<bool>
std::optional<bool>
ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName) const;

/// Read a named option from the ``Context`` and parse it as a bool.
Expand All @@ -445,7 +445,7 @@ ClangTidyCheck::OptionsView::get<bool>(StringRef LocalName) const;
/// If the corresponding key can't be parsed as a bool, emit a
/// diagnostic and return \p Default.
template <>
llvm::Optional<bool>
std::optional<bool>
ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName) const;

/// Stores an option with the check-local name \p LocalName with
Expand Down
15 changes: 14 additions & 1 deletion ClangTidyDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,14 @@

#include "ClangTidyOptions.h"
#include "ClangTidyProfiling.h"
#include "FileExtensionsSet.h"
#include "NoLintDirectiveHandler.h"
#include "clang/Basic/Diagnostic.h"
#include "clang/Tooling/Core/Diagnostic.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringSet.h"
#include "llvm/Support/Regex.h"
#include <optional>

namespace clang {

Expand Down Expand Up @@ -159,6 +161,14 @@ class ClangTidyContext {
/// \c CurrentFile.
ClangTidyOptions getOptionsForFile(StringRef File) const;

const FileExtensionsSet &getHeaderFileExtensions() const {
return HeaderFileExtensions;
}

const FileExtensionsSet &getImplementationFileExtensions() const {
return ImplementationFileExtensions;
}

/// Returns \c ClangTidyStats containing issued and ignored diagnostic
/// counters.
const ClangTidyStats &getStats() const { return Stats; }
Expand All @@ -169,7 +179,7 @@ class ClangTidyContext {

/// Control storage of profile date.
void setProfileStoragePrefix(StringRef ProfilePrefix);
llvm::Optional<ClangTidyProfiling::StorageParams>
std::optional<ClangTidyProfiling::StorageParams>
getProfileStorageParams() const;

/// Should be called when starting to process new translation unit.
Expand Down Expand Up @@ -220,6 +230,9 @@ class ClangTidyContext {
std::unique_ptr<CachedGlobList> CheckFilter;
std::unique_ptr<CachedGlobList> WarningAsErrorFilter;

FileExtensionsSet HeaderFileExtensions;
FileExtensionsSet ImplementationFileExtensions;

LangOptions LangOpts;

ClangTidyStats Stats;
Expand Down
6 changes: 2 additions & 4 deletions ClangTidyForceLinker.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
#include "clang-tidy-config.h"
#include "llvm/Support/Compiler.h"

namespace clang {
namespace tidy {
namespace clang::tidy {

// This anchor is used to force the linker to link the AbseilModule.
extern volatile int AbseilModuleAnchorSource;
Expand Down Expand Up @@ -138,7 +137,6 @@ extern volatile int ZirconModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ZirconModuleAnchorDestination =
ZirconModuleAnchorSource;

} // namespace tidy
} // namespace clang
} // namespace clang::tidy

#endif
10 changes: 4 additions & 6 deletions ClangTidyModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@
#include <functional>
#include <memory>

namespace clang {
namespace tidy {
namespace clang::tidy {

class ClangTidyCheck;
class ClangTidyContext;
Expand Down Expand Up @@ -65,11 +64,11 @@ class ClangTidyCheckFactories {

/// Create instances of checks that are enabled.
std::vector<std::unique_ptr<ClangTidyCheck>>
createChecks(ClangTidyContext *Context);
createChecks(ClangTidyContext *Context) const;

/// Create instances of checks that are enabled for the current Language.
std::vector<std::unique_ptr<ClangTidyCheck>>
createChecksForLanguage(ClangTidyContext *Context);
createChecksForLanguage(ClangTidyContext *Context) const;

typedef llvm::StringMap<CheckFactory> FactoryMap;
FactoryMap::const_iterator begin() const { return Factories.begin(); }
Expand All @@ -94,7 +93,6 @@ class ClangTidyModule {
virtual ClangTidyOptions getModuleOptions();
};

} // end namespace tidy
} // end namespace clang
} // namespace clang::tidy

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULE_H
6 changes: 2 additions & 4 deletions ClangTidyModuleRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,10 @@
#include "ClangTidyModule.h"
#include "llvm/Support/Registry.h"

namespace clang {
namespace tidy {
namespace clang::tidy {

typedef llvm::Registry<ClangTidyModule> ClangTidyModuleRegistry;

} // end namespace tidy
} // end namespace clang
} // namespace clang::tidy

#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYMODULEREGISTRY_H
Loading

0 comments on commit ba095ee

Please sign in to comment.