From 7b376492c2106064b83dca330b272ad9f197b47c Mon Sep 17 00:00:00 2001 From: Nathan Lanza Date: Thu, 21 Sep 2023 20:38:28 -0400 Subject: [PATCH] [CIR] Remove cir-tidy We've integrated this functionality into the main clang-tidy and clangd tools and no longer have a purpose for it. We only kept around to maintain support for internal tooling built upon it. So remove it here. --- clang-tools-extra/clang-tidy/CMakeLists.txt | 4 - .../clang-tidy/cir-tidy/CIRASTConsumer.cpp | 189 ------- .../clang-tidy/cir-tidy/CIRASTConsumer.h | 26 - .../clang-tidy/cir-tidy/CIRChecks.h | 21 - .../clang-tidy/cir-tidy/CIRTidy.cpp | 157 ------ .../clang-tidy/cir-tidy/CIRTidy.h | 62 --- .../clang-tidy/cir-tidy/CMakeLists.txt | 55 -- .../clang-tidy/cir-tidy/tool/CIRTidyMain.cpp | 493 ------------------ .../clang-tidy/cir-tidy/tool/CIRTidyMain.h | 23 - .../cir-tidy/tool/CIRTidyToolMain.cpp | 21 - clang-tools-extra/test/CMakeLists.txt | 6 - .../test/cir-tidy/check_cir_tidy.py | 191 ------- .../test/cir-tidy/lifetime-basic.cpp | 40 -- clang-tools-extra/test/cir-tidy/lit.local.cfg | 2 - clang-tools-extra/test/lit.cfg.py | 5 - 15 files changed, 1295 deletions(-) delete mode 100644 clang-tools-extra/clang-tidy/cir-tidy/CIRASTConsumer.cpp delete mode 100644 clang-tools-extra/clang-tidy/cir-tidy/CIRASTConsumer.h delete mode 100644 clang-tools-extra/clang-tidy/cir-tidy/CIRChecks.h delete mode 100644 clang-tools-extra/clang-tidy/cir-tidy/CIRTidy.cpp delete mode 100644 clang-tools-extra/clang-tidy/cir-tidy/CIRTidy.h delete mode 100644 clang-tools-extra/clang-tidy/cir-tidy/CMakeLists.txt delete mode 100644 clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyMain.cpp delete mode 100644 clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyMain.h delete mode 100644 clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyToolMain.cpp delete mode 100644 clang-tools-extra/test/cir-tidy/check_cir_tidy.py delete mode 100644 clang-tools-extra/test/cir-tidy/lifetime-basic.cpp delete mode 100644 clang-tools-extra/test/cir-tidy/lit.local.cfg diff --git a/clang-tools-extra/clang-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/CMakeLists.txt index 69e883f67967b0..8dfa6d81b20407 100644 --- a/clang-tools-extra/clang-tidy/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/CMakeLists.txt @@ -119,10 +119,6 @@ add_subdirectory(plugin) add_subdirectory(tool) add_subdirectory(utils) -if(CLANG_ENABLE_CIR) - add_subdirectory(cir-tidy) -endif() - if (NOT LLVM_INSTALL_TOOLCHAIN_ONLY) install(DIRECTORY . DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/clang-tidy" diff --git a/clang-tools-extra/clang-tidy/cir-tidy/CIRASTConsumer.cpp b/clang-tools-extra/clang-tidy/cir-tidy/CIRASTConsumer.cpp deleted file mode 100644 index 4ef0b0d88d735e..00000000000000 --- a/clang-tools-extra/clang-tidy/cir-tidy/CIRASTConsumer.cpp +++ /dev/null @@ -1,189 +0,0 @@ -//===--- clang-tidy/cir-tidy/CIRASTConsumer.cpp ---------------------------===// -// -// 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 "CIRASTConsumer.h" -#include "CIRChecks.h" - -#include "../utils/OptionsUtils.h" -#include "mlir/IR/BuiltinOps.h" -#include "mlir/IR/MLIRContext.h" -#include "mlir/Pass/Pass.h" -#include "mlir/Pass/PassManager.h" -#include "clang/CIR/Dialect/Passes.h" -#include - -using namespace clang; -using namespace clang::tidy; - -namespace cir { -namespace tidy { - -CIRASTConsumer::CIRASTConsumer(CompilerInstance &CI, StringRef inputFile, - clang::tidy::ClangTidyContext &Context) - : Context(Context), - OptsView(ClangTidyCheck::OptionsView(cir::checks::LifetimeCheckName, - Context.getOptions().CheckOptions, - &Context)) { - // Setup CIR codegen options via config specified information. - CI.getCodeGenOpts().ClangIRBuildDeferredThreshold = - OptsView.get("CodeGenBuildDeferredThreshold", 500U); - CI.getCodeGenOpts().ClangIRSkipFunctionsFromSystemHeaders = - OptsView.get("CodeGenSkipFunctionsFromSystemHeaders", false); - - Gen = std::make_unique(CI.getDiagnostics(), nullptr, - CI.getCodeGenOpts()); -} - -bool CIRASTConsumer::HandleTopLevelDecl(DeclGroupRef D) { - PrettyStackTraceDecl CrashInfo(*D.begin(), SourceLocation(), - AstContext->getSourceManager(), - "CIR generation of declaration"); - Gen->HandleTopLevelDecl(D); - return true; -} - -void CIRASTConsumer::Initialize(ASTContext &Context) { - AstContext = &Context; - Gen->Initialize(Context); -} - -void CIRASTConsumer::HandleTranslationUnit(ASTContext &C) { - Gen->HandleTranslationUnit(C); - Gen->verifyModule(); - - mlir::ModuleOp mlirMod = Gen->getModule(); - std::unique_ptr mlirCtx = Gen->takeContext(); - - mlir::OpPrintingFlags flags; - flags.enableDebugInfo(/*prettyForm=*/false); - - clang::SourceManager &clangSrcMgr = C.getSourceManager(); - FileID MainFileID = clangSrcMgr.getMainFileID(); - - llvm::MemoryBufferRef MainFileBuf = clangSrcMgr.getBufferOrFake(MainFileID); - std::unique_ptr FileBuf = - llvm::MemoryBuffer::getMemBuffer(MainFileBuf); - - llvm::SourceMgr llvmSrcMgr; - llvmSrcMgr.AddNewSourceBuffer(std::move(FileBuf), llvm::SMLoc()); - - class CIRTidyDiagnosticHandler : public mlir::SourceMgrDiagnosticHandler { - clang::tidy::ClangTidyContext &tidyCtx; - clang::SourceManager &clangSrcMgr; - - clang::SourceLocation getClangFromFileLineCol(mlir::FileLineColLoc loc) { - clang::SourceLocation clangLoc; - FileManager &fileMgr = clangSrcMgr.getFileManager(); - assert(loc && "not a valid mlir::FileLineColLoc"); - // The column and line may be zero to represent unknown column and/or - // unknown line/column information. - if (loc.getLine() == 0 || loc.getColumn() == 0) { - llvm_unreachable("How should we workaround this?"); - return clangLoc; - } - if (auto FE = fileMgr.getFile(loc.getFilename())) { - return clangSrcMgr.translateFileLineCol(*FE, loc.getLine(), - loc.getColumn()); - } - llvm_unreachable("location doesn't map to a file?"); - } - - clang::SourceLocation getClangSrcLoc(mlir::Location loc) { - // Direct maps into a clang::SourceLocation. - if (auto fileLoc = loc.dyn_cast()) { - return getClangFromFileLineCol(fileLoc); - } - - // FusedLoc needs to be decomposed but the canonical one - // is the first location, we handle source ranges somewhere - // else. - if (auto fileLoc = loc.dyn_cast()) { - auto locArray = fileLoc.getLocations(); - assert(locArray.size() > 0 && "expected multiple locs"); - return getClangFromFileLineCol( - locArray[0].dyn_cast()); - } - - // Many loc styles are yet to be handled. - if (auto fileLoc = loc.dyn_cast()) { - llvm_unreachable("mlir::UnknownLoc not implemented!"); - } - if (auto fileLoc = loc.dyn_cast()) { - llvm_unreachable("mlir::CallSiteLoc not implemented!"); - } - llvm_unreachable("Unknown location style"); - } - - clang::DiagnosticIDs::Level - translateToClangDiagLevel(const mlir::DiagnosticSeverity &sev) { - switch (sev) { - case mlir::DiagnosticSeverity::Note: - return clang::DiagnosticIDs::Level::Note; - case mlir::DiagnosticSeverity::Warning: - return clang::DiagnosticIDs::Level::Warning; - case mlir::DiagnosticSeverity::Error: - return clang::DiagnosticIDs::Level::Error; - case mlir::DiagnosticSeverity::Remark: - return clang::DiagnosticIDs::Level::Remark; - } - llvm_unreachable("should not get here!"); - } - - public: - void emitClangTidyDiagnostic(mlir::Diagnostic &diag) { - auto clangBeginLoc = getClangSrcLoc(diag.getLocation()); - tidyCtx.diag(cir::checks::LifetimeCheckName, clangBeginLoc, diag.str(), - translateToClangDiagLevel(diag.getSeverity())); - for (const auto ¬e : diag.getNotes()) { - auto clangNoteBeginLoc = getClangSrcLoc(note.getLocation()); - tidyCtx.diag(cir::checks::LifetimeCheckName, clangNoteBeginLoc, - note.str(), translateToClangDiagLevel(note.getSeverity())); - } - } - - CIRTidyDiagnosticHandler(llvm::SourceMgr &mgr, mlir::MLIRContext *ctx, - clang::tidy::ClangTidyContext &tidyContext, - clang::SourceManager &clangMgr, - ShouldShowLocFn &&shouldShowLocFn = {}) - : SourceMgrDiagnosticHandler(mgr, ctx, llvm::errs(), - std::move(shouldShowLocFn)), - tidyCtx(tidyContext), clangSrcMgr(clangMgr) { - setHandler([this](mlir::Diagnostic &diag) { - // Emit diagnostic to llvm::errs() but also populate Clang - emitClangTidyDiagnostic(diag); - emitDiagnostic(diag); - }); - } - ~CIRTidyDiagnosticHandler() = default; - }; - - // Use a custom diagnostic handler that can allow both regular printing to - // stderr but also populates clang-tidy context with diagnostics (and allow - // for instance, diagnostics to be later converted to YAML). - CIRTidyDiagnosticHandler sourceMgrHandler(llvmSrcMgr, mlirCtx.get(), Context, - clangSrcMgr); - - mlir::PassManager pm(mlirCtx.get()); - pm.addPass(mlir::createMergeCleanupsPass()); - - auto remarks = - utils::options::parseStringList(OptsView.get("RemarksList", "")); - auto hist = - utils::options::parseStringList(OptsView.get("HistoryList", "all")); - auto hLimit = OptsView.get("HistLimit", 1U); - - if (Context.isCheckEnabled(cir::checks::LifetimeCheckName)) - pm.addPass(mlir::createLifetimeCheckPass(remarks, hist, hLimit, &C)); - - bool Result = !mlir::failed(pm.run(mlirMod)); - if (!Result) - llvm::report_fatal_error( - "The pass manager failed to run pass on the module!"); -} -} // namespace tidy -} // namespace cir diff --git a/clang-tools-extra/clang-tidy/cir-tidy/CIRASTConsumer.h b/clang-tools-extra/clang-tidy/cir-tidy/CIRASTConsumer.h deleted file mode 100644 index d9511451998605..00000000000000 --- a/clang-tools-extra/clang-tidy/cir-tidy/CIRASTConsumer.h +++ /dev/null @@ -1,26 +0,0 @@ -#include "../ClangTidyDiagnosticConsumer.h" -#include "ClangTidyCheck.h" -#include "clang/AST/ASTContext.h" -#include "clang/CIR/CIRGenerator.h" -#include "clang/Frontend/CompilerInstance.h" - -using namespace clang; - -namespace cir { -namespace tidy { -class CIRASTConsumer : public ASTConsumer { -public: - CIRASTConsumer(CompilerInstance &CI, StringRef inputFile, - clang::tidy::ClangTidyContext &Context); - -private: - void Initialize(ASTContext &Context) override; - void HandleTranslationUnit(ASTContext &C) override; - bool HandleTopLevelDecl(DeclGroupRef D) override; - std::unique_ptr Gen; - ASTContext *AstContext{nullptr}; - clang::tidy::ClangTidyContext &Context; - clang::tidy::ClangTidyCheck::OptionsView OptsView; -}; -} // namespace tidy -} // namespace cir diff --git a/clang-tools-extra/clang-tidy/cir-tidy/CIRChecks.h b/clang-tools-extra/clang-tidy/cir-tidy/CIRChecks.h deleted file mode 100644 index 7dccbf879b4b49..00000000000000 --- a/clang-tools-extra/clang-tidy/cir-tidy/CIRChecks.h +++ /dev/null @@ -1,21 +0,0 @@ -//===--- CIRChecks.h - cir-tidy -----------------------------*- 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 -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CIRTIDY_CHECKS_H -#define LLVM_CLANG_TOOLS_EXTRA_CIRTIDY_CHECKS_H - -// FIXME: split LifetimeCheck.cpp into headers and expose the class in a way -// we can directly query the pass name and unique the source of truth. - -namespace cir { -namespace checks { -constexpr const char *LifetimeCheckName = "cir-lifetime-check"; -} -} // namespace cir - -#endif \ No newline at end of file diff --git a/clang-tools-extra/clang-tidy/cir-tidy/CIRTidy.cpp b/clang-tools-extra/clang-tidy/cir-tidy/CIRTidy.cpp deleted file mode 100644 index 2a751fab274459..00000000000000 --- a/clang-tools-extra/clang-tidy/cir-tidy/CIRTidy.cpp +++ /dev/null @@ -1,157 +0,0 @@ -//===--- clang-tidy/cir-tidy/CIRTidy.cpp - CIR tidy tool ------------------===// -// -// 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 -// -//===----------------------------------------------------------------------===// -/// -/// \file This file implements a cir-tidy tool. -/// -/// This tool uses the Clang Tooling infrastructure, see -/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html -/// for details on setting it up with LLVM source tree. -/// -//===----------------------------------------------------------------------===// - -#include "CIRTidy.h" -#include "CIRASTConsumer.h" -#include "ClangTidyModuleRegistry.h" -#include "ClangTidyProfiling.h" -#ifndef CLANG_TIDY_CONFIG_H -#include "clang-tidy-config.h" -#endif -#include "clang/Frontend/CompilerInstance.h" -#include "clang/Lex/PreprocessorOptions.h" -#include "clang/Tooling/DiagnosticsYaml.h" -#include "clang/Tooling/Refactoring.h" -#include "clang/Tooling/ReplacementsYaml.h" -#include "clang/Tooling/Tooling.h" - -using namespace clang::tooling; -using namespace llvm; - -namespace cir { -namespace tidy { - -CIRTidyASTConsumerFactory::CIRTidyASTConsumerFactory( - ClangTidyContext &Context, - IntrusiveRefCntPtr OverlayFS) - : Context(Context), OverlayFS(std::move(OverlayFS)) {} - -std::unique_ptr -CIRTidyASTConsumerFactory::createASTConsumer(clang::CompilerInstance &Compiler, - StringRef File) { - // FIXME(clang-tidy): Move this to a separate method, so that - // CreateASTConsumer doesn't modify Compiler. - SourceManager *SM = &Compiler.getSourceManager(); - Context.setSourceManager(SM); - Context.setCurrentFile(File); - Context.setASTContext(&Compiler.getASTContext()); - - auto WorkingDir = Compiler.getSourceManager() - .getFileManager() - .getVirtualFileSystem() - .getCurrentWorkingDirectory(); - if (WorkingDir) - Context.setCurrentBuildDirectory(WorkingDir.get()); - return std::make_unique(Compiler, File, Context); -} - -std::vector CIRTidyASTConsumerFactory::getCheckNames() { - std::vector CheckNames; - for (const auto &CIRCheckName : this->CIRChecks) { - if (Context.isCheckEnabled(CIRCheckName)) - CheckNames.emplace_back(CIRCheckName); - } - - llvm::sort(CheckNames); - return CheckNames; -} - -void exportReplacements(const llvm::StringRef MainFilePath, - const std::vector &Errors, - raw_ostream &OS) { - TranslationUnitDiagnostics TUD; - TUD.MainSourceFile = std::string(MainFilePath); - for (const auto &Error : Errors) { - tooling::Diagnostic Diag = Error; - TUD.Diagnostics.insert(TUD.Diagnostics.end(), Diag); - } - - yaml::Output YAML(OS); - YAML << TUD; -} - -std::vector -runCIRTidy(ClangTidyContext &Context, const CompilationDatabase &Compilations, - ArrayRef InputFiles, - llvm::IntrusiveRefCntPtr BaseFS, - bool ApplyAnyFix, bool EnableCheckProfile, - llvm::StringRef StoreCheckProfile) { - ClangTool Tool(Compilations, InputFiles, - std::make_shared(), BaseFS); - - Context.setEnableProfiling(EnableCheckProfile); - Context.setProfileStoragePrefix(StoreCheckProfile); - - ClangTidyDiagnosticConsumer DiagConsumer(Context, nullptr, true, ApplyAnyFix); - DiagnosticsEngine DE(new DiagnosticIDs(), new DiagnosticOptions(), - &DiagConsumer, /*ShouldOwnClient=*/false); - Context.setDiagnosticsEngine(&DE); - Tool.setDiagnosticConsumer(&DiagConsumer); - - class ActionFactory : public FrontendActionFactory { - public: - ActionFactory(ClangTidyContext &Context, - IntrusiveRefCntPtr BaseFS) - : ConsumerFactory(Context, std::move(BaseFS)) {} - std::unique_ptr create() override { - return std::make_unique(&ConsumerFactory); - } - - bool runInvocation(std::shared_ptr Invocation, - FileManager *Files, - std::shared_ptr PCHContainerOps, - DiagnosticConsumer *DiagConsumer) override { - // Explicitly ask to define __clang_analyzer__ macro. - Invocation->getPreprocessorOpts().SetUpStaticAnalyzer = true; - return FrontendActionFactory::runInvocation( - Invocation, Files, PCHContainerOps, DiagConsumer); - } - - private: - class Action : public ASTFrontendAction { - public: - Action(CIRTidyASTConsumerFactory *Factory) : Factory(Factory) {} - std::unique_ptr CreateASTConsumer(CompilerInstance &Compiler, - StringRef File) override { - return Factory->createASTConsumer(Compiler, File); - } - - private: - CIRTidyASTConsumerFactory *Factory; - }; - - CIRTidyASTConsumerFactory ConsumerFactory; - }; - - ActionFactory Factory(Context, std::move(BaseFS)); - Tool.run(&Factory); - return DiagConsumer.take(); -} - -} // namespace tidy -} // namespace cir - -// Now that clang-tidy is integrated with the lifetime checker, CIR changes to -// ClangTidyForceLinker.h are forcing CIRModuleAnchorSource to also be available -// as part of cir-tidy. Since cir-tidy is going to be removed soon, add this so -// that it can still builds in the meantime. -namespace clang::tidy { - -// This anchor is used to force the linker to link in the generated object file -// and thus register the CIRModule. -volatile int CIRModuleAnchorSource = 0; - -} // namespace clang::tidy diff --git a/clang-tools-extra/clang-tidy/cir-tidy/CIRTidy.h b/clang-tools-extra/clang-tidy/cir-tidy/CIRTidy.h deleted file mode 100644 index 91073d10632818..00000000000000 --- a/clang-tools-extra/clang-tidy/cir-tidy/CIRTidy.h +++ /dev/null @@ -1,62 +0,0 @@ -//===--- CIRTidy.h - cir-tidy -------------------------------*- 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 -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CIRTIDY_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CIRTIDY_H - -#include "CIRChecks.h" -#include "ClangTidyDiagnosticConsumer.h" -#include "ClangTidyModule.h" -#include "clang/AST/ASTConsumer.h" -#include "clang/CIR/Dialect/Passes.h" -#include - -namespace clang { -class CompilerInstance; -namespace tooling { -class CompilationDatabase; -} -} // namespace clang - -using namespace clang; -using namespace clang::tidy; - -namespace cir { -namespace tidy { - -class CIRTidyASTConsumerFactory { -public: - CIRTidyASTConsumerFactory( - ClangTidyContext &Context, - IntrusiveRefCntPtr OverlayFS = nullptr); - - std::unique_ptr - createASTConsumer(clang::CompilerInstance &Compiler, StringRef File); - - /// Get the list of enabled checks. - std::vector getCheckNames(); - -private: - ClangTidyContext &Context; - IntrusiveRefCntPtr OverlayFS; - const std::vector CIRChecks = { - cir::checks::LifetimeCheckName}; -}; - -std::vector -runCIRTidy(clang::tidy::ClangTidyContext &Context, - const tooling::CompilationDatabase &Compilations, - ArrayRef InputFiles, - llvm::IntrusiveRefCntPtr BaseFS, - bool ApplyAnyFix, bool EnableCheckProfile = false, - llvm::StringRef StoreCheckProfile = StringRef()); - -} // end namespace tidy -} // end namespace cir - -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CIRTIDY_H diff --git a/clang-tools-extra/clang-tidy/cir-tidy/CMakeLists.txt b/clang-tools-extra/clang-tidy/cir-tidy/CMakeLists.txt deleted file mode 100644 index fb58718bf769f2..00000000000000 --- a/clang-tools-extra/clang-tidy/cir-tidy/CMakeLists.txt +++ /dev/null @@ -1,55 +0,0 @@ -set(LLVM_LINK_COMPONENTS - FrontendOpenMP - Support - ) - -include_directories( ${CMAKE_CURRENT_SOURCE_DIR}/.. ) -include_directories( ${LLVM_MAIN_SRC_DIR}/../mlir/include ) -include_directories( ${CMAKE_BINARY_DIR}/tools/mlir/include ) - -get_property(dialect_libs GLOBAL PROPERTY MLIR_DIALECT_LIBS) - -add_subdirectory(tool) - -add_clang_library(CIRTidy - CIRTidy.cpp - CIRASTConsumer.cpp - - DEPENDS - omp_gen - - LINK_LIBS - clangASTMatchers - clangCIR - clangFrontend - clangSerialization - clangTidy - clangTidyUtils - ${dialect_libs} - MLIRCIR - MLIRCIRTransforms - MLIRAffineToStandard - MLIRAnalysis - MLIRIR - MLIRLLVMCommonConversion - MLIRLLVMDialect - MLIRLLVMToLLVMIRTranslation - MLIRMemRefDialect - MLIRMemRefToLLVM - MLIRParser - MLIRPass - MLIRSideEffectInterfaces - MLIRSCFToControlFlow - MLIRFuncToLLVM - MLIRSupport - MLIRMemRefDialect - MLIRTargetLLVMIRExport - MLIRTransforms -) - -clang_target_link_libraries(CIRTidy - PRIVATE - clangBasic - clangTooling - clangToolingCore - ) diff --git a/clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyMain.cpp b/clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyMain.cpp deleted file mode 100644 index 14d9298e09cc41..00000000000000 --- a/clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyMain.cpp +++ /dev/null @@ -1,493 +0,0 @@ -//===--- tools/extra/clang-tidy/cir/CIRTidyMain.cpp - cir tidy tool -------===// -// -// 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 -// -//===----------------------------------------------------------------------===// -/// -/// \file This file implements a cir-tidy tool. -/// -/// This tool uses the Clang Tooling infrastructure, see -/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html -/// for details on setting it up with LLVM source tree. -/// -//===----------------------------------------------------------------------===// - -#include "CIRTidyMain.h" -#include "../ClangTidy.h" -#include "../ClangTidyForceLinker.h" -#include "../GlobList.h" -#include "CIRTidy.h" -#include "clang/Tooling/CommonOptionsParser.h" -#include "llvm/Support/InitLLVM.h" -#include "llvm/Support/Process.h" -#include "llvm/Support/TargetSelect.h" -#include "llvm/Support/WithColor.h" - -using namespace clang::tooling; -using namespace clang::tidy; -using namespace llvm; - -static cl::OptionCategory CIRTidyCategory("cir-tidy options"); - -static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage); -static cl::extrahelp CIRTidyHelp(R"( -Configuration files: - cir-tidy attempts to read configuration for each source file from a - .clang-tidy file located in the closest parent directory of the source - file. If InheritParentConfig is true in a config file, the configuration file - in the parent directory (if any exists) will be taken and current config file - will be applied on top of the parent one. If any configuration options have - a corresponding command-line option, command-line option takes precedence. - The effective configuration can be inspected using -dump-config: - - $ cir-tidy -dump-config - --- - Checks: '-*,some-check' - WarningsAsErrors: '' - HeaderFilterRegex: '' - FormatStyle: none - InheritParentConfig: true - User: user - CheckOptions: - - key: some-check.SomeOption - value: 'some value' - ... - -)"); - -const char DefaultChecks[] = // Enable these checks by default: - "clang-diagnostic-*," // * compiler diagnostics - "clang-analyzer-*"; // * Static Analyzer checks - -static cl::opt - Checks("checks", cl::desc(R"(Comma-separated list of globs with optional '-' -prefix. Globs are processed in order of -appearance in the list. Globs without '-' -prefix add checks with matching names to the -set, globs with the '-' prefix remove checks -with matching names from the set of enabled -checks. This option's value is appended to the -value of the 'Checks' option in .clang-tidy -file, if any. -)"), - cl::init(""), cl::cat(CIRTidyCategory)); - -static cl::opt - WarningsAsErrors("warnings-as-errors", - cl::desc(R"(Upgrades warnings to errors. Same format as -'-checks'. -This option's value is appended to the value of -the 'WarningsAsErrors' option in .clang-tidy -file, if any. -)"), - cl::init(""), cl::cat(CIRTidyCategory)); - -static cl::opt - HeaderFilter("header-filter", - cl::desc(R"(Regular expression matching the names of the -headers to output diagnostics from. Diagnostics -from the main file of each translation unit are -always displayed. -Can be used together with -line-filter. -This option overrides the 'HeaderFilterRegex' -option in .clang-tidy file, if any. -)"), - cl::init(""), cl::cat(CIRTidyCategory)); - -static cl::opt - SystemHeaders("system-headers", - cl::desc("Display the errors from system headers."), - cl::init(false), cl::cat(CIRTidyCategory)); -static cl::opt - LineFilter("line-filter", - cl::desc(R"(List of files with line ranges to filter the -warnings. Can be used together with --header-filter. The format of the list is a -JSON array of objects: - [ - {"name":"file1.cpp","lines":[[1,3],[5,7]]}, - {"name":"file2.h"} - ] -)"), - cl::init(""), cl::cat(CIRTidyCategory)); - -static cl::opt Fix("fix", - cl::desc(R"(Apply suggested fixes. Without -fix-errors -cir-tidy will bail out if any compilation -errors were found. -)"), - cl::init(false), cl::cat(CIRTidyCategory)); - -static cl::opt - FixErrors("fix-errors", - cl::desc(R"(Apply suggested fixes even if compilation -errors were found. If compiler errors have -attached fix-its, cir-tidy will apply them as -well. -)"), - cl::init(false), cl::cat(CIRTidyCategory)); - -static cl::opt - FixNotes("fix-notes", - cl::desc(R"(If a warning has no fix, but a single fix can -be found through an associated diagnostic note, -apply the fix. -Specifying this flag will implicitly enable the -'--fix' flag. -)"), - cl::init(false), cl::cat(CIRTidyCategory)); - -static cl::opt - FormatStyle("format-style", - cl::desc(R"(Style for formatting code around applied fixes: - - 'none' (default) turns off formatting - - 'file' (literally 'file', not a placeholder) - uses .clang-format file in the closest parent - directory - - '{ }' specifies options inline, e.g. - -format-style='{BasedOnStyle: llvm, IndentWidth: 8}' - - 'llvm', 'google', 'webkit', 'mozilla' -See clang-format documentation for the up-to-date -information about formatting styles and options. -This option overrides the 'FormatStyle` option in -.clang-tidy file, if any. -)"), - cl::init("none"), cl::cat(CIRTidyCategory)); - -static cl::opt - ListChecks("list-checks", - cl::desc(R"(List all enabled checks and exit. Use with --checks=* to list all available checks. -)"), - cl::init(false), cl::cat(CIRTidyCategory)); - -static cl::opt - ExplainConfig("explain-config", - cl::desc(R"(For each enabled check explains, where it is -enabled, i.e. in cir-tidy binary, command -line or a specific configuration file. -)"), - cl::init(false), cl::cat(CIRTidyCategory)); - -static cl::opt - Config("config", cl::desc(R"(Specifies a configuration in YAML/JSON format: - -config="{Checks: '*', - CheckOptions: [{key: x, - value: y}]}" -When the value is empty, cir-tidy will -attempt to find a file named .clang-tidy for -each source file in its parent directories. -)"), - cl::init(""), cl::cat(CIRTidyCategory)); - -static cl::opt ConfigFile( - "config-file", - cl::desc(R"(Specify the path of .clang-tidy or custom config file: - e.g. --config-file=/some/path/myTidyConfigFile -This option internally works exactly the same way as - --config option after reading specified config file. -Use either --config-file or --config, not both. -)"), - cl::init(""), cl::cat(CIRTidyCategory)); - -static cl::opt - DumpConfig("dump-config", - cl::desc(R"(Dumps configuration in the YAML format to -stdout. This option can be used along with a -file name (and '--' if the file is outside of a -project with configured compilation database). -The configuration used for this file will be -printed. -Use along with -checks=* to include -configuration of all checks. -)"), - cl::init(false), cl::cat(CIRTidyCategory)); - -static cl::opt - EnableCheckProfile("enable-check-profile", - cl::desc(R"(Enable per-check timing profiles, and print a -report to stderr. -)"), - cl::init(false), cl::cat(CIRTidyCategory)); - -static cl::opt - StoreCheckProfile("store-check-profile", - cl::desc(R"(By default reports are printed in tabulated -format to stderr. When this option is passed, -these per-TU profiles are instead stored as JSON. -)"), - cl::value_desc("prefix"), cl::cat(CIRTidyCategory)); - -/// This option allows enabling the experimental alpha checkers from the static -/// analyzer. This option is set to false and not visible in help, because it is -/// highly not recommended for users. -static cl::opt - AllowEnablingAnalyzerAlphaCheckers("allow-enabling-analyzer-alpha-checkers", - cl::init(false), cl::Hidden, - cl::cat(CIRTidyCategory)); - -static cl::opt - ExportFixes("export-fixes", - cl::desc(R"(YAML file to store suggested fixes in. The -stored fixes can be applied to the input source -code with cir-apply-replacements. -)"), - cl::value_desc("filename"), cl::cat(CIRTidyCategory)); - -static cl::opt - Quiet("quiet", cl::desc(R"(Run cir-tidy in quiet mode. This suppresses -printing statistics about ignored warnings and -warnings treated as errors if the respective -options are specified. -)"), - cl::init(false), cl::cat(CIRTidyCategory)); - -static cl::opt - VfsOverlay("vfsoverlay", - cl::desc(R"(Overlay the virtual filesystem described by file -over the real file system. -)"), - cl::value_desc("filename"), cl::cat(CIRTidyCategory)); - -static cl::opt - UseColor("use-color", - cl::desc(R"(Use colors in diagnostics. If not set, colors -will be used if the terminal connected to -standard output supports colors. -This option overrides the 'UseColor' option in -.clang-tidy file, if any. -)"), - cl::init(false), cl::cat(CIRTidyCategory)); -namespace cir { -namespace tidy { - -std::vector getCIRCheckNames(const ClangTidyOptions &Options) { - clang::tidy::ClangTidyContext Context( - std::make_unique(ClangTidyGlobalOptions(), - Options)); - CIRTidyASTConsumerFactory Factory(Context); - return Factory.getCheckNames(); -} - -static std::unique_ptr -createOptionsProvider(llvm::IntrusiveRefCntPtr FS) { - ClangTidyGlobalOptions GlobalOptions; - if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) { - llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n"; - llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); - return nullptr; - } - - ClangTidyOptions DefaultOptions; - DefaultOptions.Checks = DefaultChecks; - DefaultOptions.WarningsAsErrors = ""; - DefaultOptions.HeaderFilterRegex = HeaderFilter; - DefaultOptions.SystemHeaders = SystemHeaders; - DefaultOptions.FormatStyle = FormatStyle; - DefaultOptions.User = llvm::sys::Process::GetEnv("USER"); - // USERNAME is used on Windows. - if (!DefaultOptions.User) - DefaultOptions.User = llvm::sys::Process::GetEnv("USERNAME"); - - ClangTidyOptions OverrideOptions; - if (Checks.getNumOccurrences() > 0) - OverrideOptions.Checks = Checks; - if (WarningsAsErrors.getNumOccurrences() > 0) - OverrideOptions.WarningsAsErrors = WarningsAsErrors; - if (HeaderFilter.getNumOccurrences() > 0) - OverrideOptions.HeaderFilterRegex = HeaderFilter; - if (SystemHeaders.getNumOccurrences() > 0) - OverrideOptions.SystemHeaders = SystemHeaders; - if (FormatStyle.getNumOccurrences() > 0) - OverrideOptions.FormatStyle = FormatStyle; - if (UseColor.getNumOccurrences() > 0) - OverrideOptions.UseColor = UseColor; - - auto LoadConfig = - [&](StringRef Configuration, - StringRef Source) -> std::unique_ptr { - llvm::ErrorOr ParsedConfig = - parseConfiguration(MemoryBufferRef(Configuration, Source)); - if (ParsedConfig) - return std::make_unique( - std::move(GlobalOptions), - ClangTidyOptions::getDefaults().merge(DefaultOptions, 0), - std::move(*ParsedConfig), std::move(OverrideOptions), std::move(FS)); - llvm::errs() << "Error: invalid configuration specified.\n" - << ParsedConfig.getError().message() << "\n"; - return nullptr; - }; - - if (ConfigFile.getNumOccurrences() > 0) { - if (Config.getNumOccurrences() > 0) { - llvm::errs() << "Error: --config-file and --config are " - "mutually exclusive. Specify only one.\n"; - return nullptr; - } - - llvm::ErrorOr> Text = - llvm::MemoryBuffer::getFile(ConfigFile); - if (std::error_code EC = Text.getError()) { - llvm::errs() << "Error: can't read config-file '" << ConfigFile - << "': " << EC.message() << "\n"; - return nullptr; - } - - return LoadConfig((*Text)->getBuffer(), ConfigFile); - } - - if (Config.getNumOccurrences() > 0) - return LoadConfig(Config, ""); - - return std::make_unique( - std::move(GlobalOptions), std::move(DefaultOptions), - std::move(OverrideOptions), std::move(FS)); -} - -llvm::IntrusiveRefCntPtr -getVfsFromFile(const std::string &OverlayFile, - llvm::IntrusiveRefCntPtr BaseFS) { - llvm::ErrorOr> Buffer = - BaseFS->getBufferForFile(OverlayFile); - if (!Buffer) { - llvm::errs() << "Can't load virtual filesystem overlay file '" - << OverlayFile << "': " << Buffer.getError().message() - << ".\n"; - return nullptr; - } - - IntrusiveRefCntPtr FS = vfs::getVFSFromYAML( - std::move(Buffer.get()), /*DiagHandler*/ nullptr, OverlayFile); - if (!FS) { - llvm::errs() << "Error: invalid virtual filesystem overlay file '" - << OverlayFile << "'.\n"; - return nullptr; - } - return FS; -} - -int CIRTidyMain(int argc, const char **argv) { - llvm::InitLLVM X(argc, argv); - llvm::Expected OptionsParser = - CommonOptionsParser::create(argc, argv, CIRTidyCategory, cl::ZeroOrMore); - if (!OptionsParser) { - llvm::WithColor::error() << llvm::toString(OptionsParser.takeError()); - return 1; - } - - llvm::IntrusiveRefCntPtr BaseFS( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); - - if (!VfsOverlay.empty()) { - IntrusiveRefCntPtr VfsFromFile = - getVfsFromFile(VfsOverlay, BaseFS); - if (!VfsFromFile) - return 1; - BaseFS->pushOverlay(std::move(VfsFromFile)); - } - - auto OwningOptionsProvider = createOptionsProvider(BaseFS); - auto *OptionsProvider = OwningOptionsProvider.get(); - if (!OptionsProvider) - return 1; - - auto MakeAbsolute = [](const std::string &Input) -> SmallString<256> { - if (Input.empty()) - return {}; - SmallString<256> AbsolutePath(Input); - if (std::error_code EC = llvm::sys::fs::make_absolute(AbsolutePath)) { - llvm::errs() << "Can't make absolute path from " << Input << ": " - << EC.message() << "\n"; - } - return AbsolutePath; - }; - - SmallString<256> ProfilePrefix = MakeAbsolute(StoreCheckProfile); - - StringRef FileName("dummy"); - auto PathList = OptionsParser->getSourcePathList(); - if (!PathList.empty()) { - FileName = PathList.front(); - } - - SmallString<256> FilePath = MakeAbsolute(std::string(FileName)); - - ClangTidyOptions EffectiveOptions = OptionsProvider->getOptions(FilePath); - std::vector EnabledChecks = getCIRCheckNames(EffectiveOptions); - - if (ExplainConfig) { - // FIXME: Show other ClangTidyOptions' fields, like ExtraArg. - std::vector - RawOptions = OptionsProvider->getRawOptions(FilePath); - for (const std::string &Check : EnabledChecks) { - for (auto It = RawOptions.rbegin(); It != RawOptions.rend(); ++It) { - if (It->first.Checks && GlobList(*It->first.Checks).contains(Check)) { - llvm::outs() << "'" << Check << "' is enabled in the " << It->second - << ".\n"; - break; - } - } - } - return 0; - } - - if (ListChecks) { - if (EnabledChecks.empty()) { - llvm::errs() << "No checks enabled.\n"; - return 1; - } - llvm::outs() << "Enabled checks:"; - for (const auto &CheckName : EnabledChecks) - llvm::outs() << "\n " << CheckName; - llvm::outs() << "\n\n"; - return 0; - } - - if (DumpConfig) { - EffectiveOptions.CheckOptions = - getCheckOptions(EffectiveOptions, AllowEnablingAnalyzerAlphaCheckers); - llvm::outs() << configurationAsText(ClangTidyOptions::getDefaults().merge( - EffectiveOptions, 0)) - << "\n"; - return 0; - } - - if (EnabledChecks.empty()) { - llvm::errs() << "Error: no checks enabled.\n"; - llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); - return 1; - } - - if (PathList.empty()) { - llvm::errs() << "Error: no input files specified.\n"; - llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true); - return 1; - } - - llvm::InitializeAllTargetInfos(); - llvm::InitializeAllTargetMCs(); - llvm::InitializeAllAsmParsers(); - - ClangTidyContext Context(std::move(OwningOptionsProvider), - AllowEnablingAnalyzerAlphaCheckers); - std::vector Errors = - runCIRTidy(Context, OptionsParser->getCompilations(), PathList, BaseFS, - FixNotes, EnableCheckProfile, ProfilePrefix); - - if (!ExportFixes.empty() && !Errors.empty()) { - std::error_code EC; - llvm::raw_fd_ostream OS(ExportFixes, EC, llvm::sys::fs::OF_None); - if (EC) { - llvm::errs() << "Error opening output file: " << EC.message() << '\n'; - return 1; - } - exportReplacements(FilePath.str(), Errors, OS); - } - - return 0; -} - -} // namespace tidy -} // namespace cir diff --git a/clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyMain.h b/clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyMain.h deleted file mode 100644 index 08d25544dbf359..00000000000000 --- a/clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyMain.h +++ /dev/null @@ -1,23 +0,0 @@ -//===--- tools/extra/clang-tidy/cir/CIRTidyMain.h - cir tidy tool ---------===// -// -// 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 -// -//===----------------------------------------------------------------------===// -/// -/// \file This file declares the main function for the cir-tidy tool. -/// -/// This tool uses the Clang Tooling infrastructure, see -/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html -/// for details on setting it up with LLVM source tree. -/// -//===----------------------------------------------------------------------===// - -namespace cir { -namespace tidy { - -int CIRTidyMain(int argc, const char **argv); - -} // namespace tidy -} // namespace cir diff --git a/clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyToolMain.cpp b/clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyToolMain.cpp deleted file mode 100644 index b5213510e8229e..00000000000000 --- a/clang-tools-extra/clang-tidy/cir-tidy/tool/CIRTidyToolMain.cpp +++ /dev/null @@ -1,21 +0,0 @@ -//===--- tools/extra/clang-tidy/cir/CIRTidyToolMain.cpp - cir tidy tool ---===// -// -// 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 -// -//===----------------------------------------------------------------------===// -/// -/// \file This file contains cir-tidy tool entry point main function. -/// -/// This tool uses the Clang Tooling infrastructure, see -/// http://clang.llvm.org/docs/HowToSetupToolingForLLVM.html -/// for details on setting it up with LLVM source tree. -/// -//===----------------------------------------------------------------------===// - -#include "CIRTidyMain.h" - -int main(int argc, const char **argv) { - return cir::tidy::CIRTidyMain(argc, argv); -} diff --git a/clang-tools-extra/test/CMakeLists.txt b/clang-tools-extra/test/CMakeLists.txt index 9ea69ca33e43ff..d42306898fe06b 100644 --- a/clang-tools-extra/test/CMakeLists.txt +++ b/clang-tools-extra/test/CMakeLists.txt @@ -58,12 +58,6 @@ set(CLANG_TOOLS_TEST_DEPS clang ) -if(CLANG_ENABLE_CIR) - list(APPEND CLANG_TOOLS_TEST_DEPS - cir-tidy - ) -endif() - # Add lit test dependencies. set(LLVM_UTILS_DEPS FileCheck count not diff --git a/clang-tools-extra/test/cir-tidy/check_cir_tidy.py b/clang-tools-extra/test/cir-tidy/check_cir_tidy.py deleted file mode 100644 index 5f042718efda6d..00000000000000 --- a/clang-tools-extra/test/cir-tidy/check_cir_tidy.py +++ /dev/null @@ -1,191 +0,0 @@ -#!/usr/bin/env python -# -#===- check_cir_tidy.py - CIRTidy Test Helper ------------*- python -*--=======# -# -# 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 -# -#===------------------------------------------------------------------------===# - -r""" -CIRTIDY Test Helper -===================== - -This script runs cir-tidy and check outputed messages. - -Usage: - check_cir_tidy.py -- \ - [optional cir-tidy arguments] - -Example: - // RUN: %check_cir_tidy %s cir-lifetime-check %t -- -""" - -import argparse -import re -import subprocess -import sys -import shutil - -def write_file(file_name, text): - with open(file_name, 'w', encoding='utf-8') as f: - f.write(text) - f.truncate() - - -def run_test_once(args, extra_args): - input_file_name = args.input_file_name - check_name = args.check_name - temp_file_name = args.temp_file_name - temp_file_name = temp_file_name + ".cpp" - - cir_tidy_extra_args = extra_args - cir_extra_args = [] - if '--' in extra_args: - i = cir_tidy_extra_args.index('--') - cir_extra_args = cir_tidy_extra_args[i + 1:] - cir_tidy_extra_args = cir_tidy_extra_args[:i] - - # If the test does not specify a config style, force an empty one; otherwise - # autodetection logic can discover a ".clang-tidy" file that is not related to - # the test. - if not any( - [arg.startswith('-config=') for arg in cir_tidy_extra_args]): - cir_tidy_extra_args.append('-config={}') - - with open(input_file_name, 'r', encoding='utf-8') as input_file: - input_text = input_file.read() - - check_fixes_prefixes = [] - check_messages_prefixes = [] - check_notes_prefixes = [] - - has_check_fixes = False - has_check_messages = False - has_check_notes = False - - check_fixes_prefix = 'CHECK-FIXES' - check_messages_prefix = 'CHECK-MESSAGES' - check_notes_prefix = 'CHECK-NOTES' - - has_check_fix = check_fixes_prefix in input_text - has_check_message = check_messages_prefix in input_text - has_check_note = check_notes_prefix in input_text - - if not has_check_fix and not has_check_message and not has_check_note: - sys.exit('%s, %s or %s not found in the input' % - (check_fixes_prefix, check_messages_prefix, check_notes_prefix)) - - has_check_fixes = has_check_fixes or has_check_fix - has_check_messages = has_check_messages or has_check_message - has_check_notes = has_check_notes or has_check_note - - if has_check_fix: - check_fixes_prefixes.append(check_fixes_prefix) - if has_check_message: - check_messages_prefixes.append(check_messages_prefix) - if has_check_note: - check_notes_prefixes.append(check_notes_prefix) - - assert has_check_fixes or has_check_messages or has_check_notes - # Remove the contents of the CHECK lines to avoid CHECKs matching on - # themselves. We need to keep the comments to preserve line numbers while - # avoiding empty lines which could potentially trigger formatting-related - # checks. - cleaned_test = re.sub('// *CHECK-[A-Z0-9\-]*:[^\r\n]*', '//', input_text) - - write_file(temp_file_name, cleaned_test) - - original_file_name = temp_file_name + ".orig" - write_file(original_file_name, cleaned_test) - - args = ['cir-tidy', temp_file_name, '--checks=-*,' + check_name] + \ - cir_tidy_extra_args + ['--'] + cir_extra_args - - arg_print_list = [] - for arg_print in cir_tidy_extra_args: - if (arg_print.startswith("-config=")): - conf = arg_print.replace("-config=", "-config='") - conf += "'" - arg_print_list.append(conf) - continue - arg_print_list.append(arg_print) - - cir_tidy_bin = shutil.which('cir-tidy') - args_for_print = [cir_tidy_bin, temp_file_name, "--checks='-*," + check_name + "'"] + \ - arg_print_list + ['--'] + cir_extra_args - print('Running: ' + " ".join(args_for_print)) - - try: - cir_tidy_output = \ - subprocess.check_output(args, stderr=subprocess.STDOUT).decode() - except subprocess.CalledProcessError as e: - print('cir-tidy failed:\n' + e.output.decode()) - raise - - print('------------------------ cir-tidy output -------------------------') - print(cir_tidy_output.encode()) - print('\n------------------------------------------------------------------') - - try: - diff_output = subprocess.check_output( - ['diff', '-u', original_file_name, temp_file_name], - stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as e: - diff_output = e.output - - print('------------------------------ Fixes -----------------------------\n' + - diff_output.decode(errors='ignore') + - '\n------------------------------------------------------------------') - - if has_check_fixes: - try: - subprocess.check_output( - ['FileCheck', '-input-file=' + temp_file_name, input_file_name, - '-check-prefixes=' + ','.join(check_fixes_prefixes), - '-strict-whitespace'], - stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as e: - print('FileCheck failed:\n' + e.output.decode()) - raise - - if has_check_messages: - messages_file = temp_file_name + '.msg' - write_file(messages_file, cir_tidy_output) - try: - subprocess.check_output( - ['FileCheck', '-input-file=' + messages_file, input_file_name, - '-check-prefixes=' + ','.join(check_messages_prefixes), - '-implicit-check-not={{warning|error}}:'], - stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as e: - print('FileCheck failed:\n' + e.output.decode()) - raise - - if has_check_notes: - notes_file = temp_file_name + '.notes' - write_file(notes_file, cir_tidy_output) - try: - subprocess.check_output( - ['FileCheck', '-input-file=' + notes_file, input_file_name, - '-check-prefixes=' + ','.join(check_notes_prefixes), - '-implicit-check-not={{error}}:'], - stderr=subprocess.STDOUT) - except subprocess.CalledProcessError as e: - print('FileCheck failed:\n' + e.output.decode()) - raise - - -def main(): - parser = argparse.ArgumentParser() - parser.add_argument('input_file_name') - parser.add_argument('check_name') - parser.add_argument('temp_file_name') - - args, extra_args = parser.parse_known_args() - run_test_once(args, extra_args) - - -if __name__ == '__main__': - main() diff --git a/clang-tools-extra/test/cir-tidy/lifetime-basic.cpp b/clang-tools-extra/test/cir-tidy/lifetime-basic.cpp deleted file mode 100644 index 7bf684fbad6621..00000000000000 --- a/clang-tools-extra/test/cir-tidy/lifetime-basic.cpp +++ /dev/null @@ -1,40 +0,0 @@ -// RUN: %check_cir_tidy %s cir-lifetime-check %t \ -// RUN: --export-fixes=%t.yaml \ -// RUN: -config='{CheckOptions: \ -// RUN: [{key: cir-lifetime-check.RemarksList, value: "all"}, \ -// RUN: {key: cir-lifetime-check.HistLimit, value: "1"}, \ -// RUN: {key: cir-lifetime-check.CodeGenBuildDeferredThreshold, value: "500"}, \ -// RUN: {key: cir-lifetime-check.CodeGenSkipFunctionsFromSystemHeaders, value: "false"}, \ -// RUN: {key: cir-lifetime-check.HistoryList, value: "invalid;null"}]}' \ -// RUN: -- -// RUN: FileCheck -input-file=%t.yaml -check-prefix=CHECK-YAML %s - -int *p0() { - int *p = nullptr; - { - int x = 0; - p = &x; - *p = 42; // CHECK-MESSAGES: remark: pset => { x } - } // CHECK-NOTES: note: pointee 'x' invalidated at end of scope - *p = 42; // CHECK-MESSAGES: remark: pset => { invalid } - // CHECK-MESSAGES: :[[@LINE-1]]:4: warning: use of invalid pointer 'p' - return p; -} - -// CHECK-YAML: DiagnosticMessage: -// CHECK-YAML: Message: 'pset => { x }' -// CHECK-YAML: Replacements: [] -// CHECK-YAML: Level: Remark - -// CHECK-YAML: DiagnosticMessage: -// CHECK-YAML: Message: 'pset => { invalid }' -// CHECK-YAML: Replacements: [] -// CHECK-YAML: Level: Remark - -// CHECK-YAML: DiagnosticMessage: -// CHECK-YAML: Message: 'use of invalid pointer ''p''' -// CHECK-YAML: Replacements: [] -// CHECK-YAML: Notes: -// CHECK-YAML: - Message: 'pointee ''x'' invalidated at end of scope' -// CHECK-YAML: Replacements: [] -// CHECK-YAML: Level: Warning \ No newline at end of file diff --git a/clang-tools-extra/test/cir-tidy/lit.local.cfg b/clang-tools-extra/test/cir-tidy/lit.local.cfg deleted file mode 100644 index e479c3e74cb6c2..00000000000000 --- a/clang-tools-extra/test/cir-tidy/lit.local.cfg +++ /dev/null @@ -1,2 +0,0 @@ -if not config.clang_enable_cir: - config.unsupported = True \ No newline at end of file diff --git a/clang-tools-extra/test/lit.cfg.py b/clang-tools-extra/test/lit.cfg.py index 2e3937337ed3d8..9f64fd3d2ffa20 100644 --- a/clang-tools-extra/test/lit.cfg.py +++ b/clang-tools-extra/test/lit.cfg.py @@ -54,11 +54,6 @@ config.substitutions.append( ("%check_clang_tidy", "%s %s" % (python_exec, check_clang_tidy)) ) -check_cir_tidy = os.path.join( - config.test_source_root, "cir-tidy", "check_cir_tidy.py") -config.substitutions.append( - ('%check_cir_tidy', - '%s %s' % (python_exec, check_cir_tidy)) ) clang_tidy_diff = os.path.join( config.test_source_root, "..", "clang-tidy", "tool", "clang-tidy-diff.py" )