Files
TheRock/compiler/amd-llvm/clang-tools-extra/clang-tidy/llvm/UseRangesCheck.cpp
T
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

118 lines
3.5 KiB
C++

//===----------------------------------------------------------------------===//
//
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
// See https://llvm.org/LICENSE.txt for license information.
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
//
//===----------------------------------------------------------------------===//
#include "UseRangesCheck.h"
// FixItHint - Let the docs script know that this class does provide fixits
namespace clang::tidy::llvm_check {
namespace {
class StdToLLVMReplacer : public utils::UseRangesCheck::Replacer {
public:
explicit StdToLLVMReplacer(
ArrayRef<utils::UseRangesCheck::Signature> Signatures)
: Signatures(Signatures) {}
ArrayRef<utils::UseRangesCheck::Signature>
getReplacementSignatures() const override {
return Signatures;
}
std::optional<std::string>
getReplaceName(const NamedDecl &OriginalName) const override {
return ("llvm::" + OriginalName.getName()).str();
}
std::optional<std::string>
getHeaderInclusion(const NamedDecl &) const override {
return "llvm/ADT/STLExtras.h";
}
private:
ArrayRef<utils::UseRangesCheck::Signature> Signatures;
};
} // namespace
utils::UseRangesCheck::ReplacerMap UseRangesCheck::getReplacerMap() const {
ReplacerMap Results;
static const Signature SingleSig = {{0}};
static const Signature TwoSig = {{0}, {2}};
const auto AddStdToLLVM =
[&Results](llvm::IntrusiveRefCntPtr<Replacer> Replacer,
std::initializer_list<StringRef> Names) {
for (const StringRef Name : Names)
Results.try_emplace(("::std::" + Name).str(), Replacer);
};
// Single range algorithms. One per line, keep sorted.
// clang-format off
AddStdToLLVM(llvm::makeIntrusiveRefCnt<StdToLLVMReplacer>(SingleSig),
{"accumulate",
"adjacent_find",
"all_of",
"any_of",
"binary_search",
"copy",
"copy_if",
"count",
"count_if",
"fill",
"find",
"find_if",
"find_if_not",
"for_each",
"is_sorted",
"lower_bound",
"max_element",
"min_element",
"none_of",
"partition",
"partition_point",
"remove_if",
"replace",
"replace_copy",
"replace_copy_if",
"stable_sort",
"transform",
"uninitialized_copy",
"unique",
"upper_bound"});
// clang-format on
// Two range algorithms.
AddStdToLLVM(llvm::makeIntrusiveRefCnt<StdToLLVMReplacer>(TwoSig),
{"equal", "mismatch", "includes", "search"});
return Results;
}
UseRangesCheck::UseRangesCheck(StringRef Name, ClangTidyContext *Context)
: utils::UseRangesCheck(Name, Context) {}
DiagnosticBuilder UseRangesCheck::createDiag(const CallExpr &Call) {
return diag(Call.getBeginLoc(), "use an LLVM range-based algorithm");
}
ArrayRef<std::pair<StringRef, StringRef>>
UseRangesCheck::getFreeBeginEndMethods() const {
static constexpr std::pair<StringRef, StringRef> Refs[] = {
{"::std::begin", "::std::end"},
{"::std::cbegin", "::std::cend"},
{"::std::rbegin", "::std::rend"},
{"::std::crbegin", "::std::crend"},
};
return Refs;
}
} // namespace clang::tidy::llvm_check