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
76 lines
2.7 KiB
C++
76 lines
2.7 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 "DeprecatedIosBaseAliasesCheck.h"
|
|
#include "clang/ASTMatchers/ASTMatchFinder.h"
|
|
#include <optional>
|
|
|
|
using namespace clang::ast_matchers;
|
|
|
|
namespace clang::tidy::modernize {
|
|
|
|
static constexpr std::array<StringRef, 5> DeprecatedTypes = {
|
|
"::std::ios_base::io_state", "::std::ios_base::open_mode",
|
|
"::std::ios_base::seek_dir", "::std::ios_base::streamoff",
|
|
"::std::ios_base::streampos"};
|
|
|
|
static std::optional<const char *> getReplacementType(StringRef Type) {
|
|
return llvm::StringSwitch<std::optional<const char *>>(Type)
|
|
.Case("io_state", "iostate")
|
|
.Case("open_mode", "openmode")
|
|
.Case("seek_dir", "seekdir")
|
|
.Default(std::nullopt);
|
|
}
|
|
|
|
void DeprecatedIosBaseAliasesCheck::registerMatchers(MatchFinder *Finder) {
|
|
auto IoStateDecl = typedefDecl(hasAnyName(DeprecatedTypes)).bind("TypeDecl");
|
|
auto IoStateType = typedefType(hasDeclaration(IoStateDecl));
|
|
|
|
Finder->addMatcher(typeLoc(loc(IoStateType)).bind("TypeLoc"), this);
|
|
}
|
|
|
|
void DeprecatedIosBaseAliasesCheck::check(
|
|
const MatchFinder::MatchResult &Result) {
|
|
const SourceManager &SM = *Result.SourceManager;
|
|
|
|
const auto *Typedef = Result.Nodes.getNodeAs<TypedefDecl>("TypeDecl");
|
|
const StringRef TypeName = Typedef->getName();
|
|
auto Replacement = getReplacementType(TypeName);
|
|
|
|
TypeLoc TL = *Result.Nodes.getNodeAs<TypeLoc>("TypeLoc");
|
|
if (auto QTL = TL.getAs<QualifiedTypeLoc>())
|
|
TL = QTL.getUnqualifiedLoc();
|
|
|
|
SourceLocation IoStateLoc = TL.castAs<TypedefTypeLoc>().getNameLoc();
|
|
// Do not generate fixits for matches depending on template arguments and
|
|
// macro expansions.
|
|
bool Fix = Replacement && !TL.getType()->isDependentType();
|
|
if (IoStateLoc.isMacroID()) {
|
|
IoStateLoc = SM.getSpellingLoc(IoStateLoc);
|
|
Fix = false;
|
|
}
|
|
|
|
const SourceLocation EndLoc =
|
|
IoStateLoc.getLocWithOffset(TypeName.size() - 1);
|
|
|
|
if (Replacement) {
|
|
const char *FixName = *Replacement;
|
|
auto Builder = diag(IoStateLoc, "'std::ios_base::%0' is deprecated; use "
|
|
"'std::ios_base::%1' instead")
|
|
<< TypeName << FixName;
|
|
|
|
if (Fix)
|
|
Builder << FixItHint::CreateReplacement(SourceRange(IoStateLoc, EndLoc),
|
|
FixName);
|
|
} else {
|
|
diag(IoStateLoc, "'std::ios_base::%0' is deprecated") << TypeName;
|
|
}
|
|
}
|
|
|
|
} // namespace clang::tidy::modernize
|