From a2c1e8e5a0af577a9376b12fe4cc2b3ae9ffdde0 Mon Sep 17 00:00:00 2001 From: Malik Shahzad Muzaffar Date: Wed, 8 Jan 2020 16:03:37 +0100 Subject: [PATCH 1/8] LLVM to 9.0.1 --- llvm.spec | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/llvm.spec b/llvm.spec index 519f79d1721..37f0cb64d3c 100644 --- a/llvm.spec +++ b/llvm.spec @@ -1,4 +1,4 @@ -### RPM external llvm 8.0.1 +### RPM external llvm 9.0.1 ## INITENV +PATH LD_LIBRARY_PATH %{i}/lib64 ## INITENV +PATH PYTHON27PATH %{i}/lib64/python`echo $PYTHON_VERSION | cut -d. -f 1,2`/site-packages ## INITENV +PATH PYTHON3PATH %{i}/lib64/python`echo $PYTHON3_VERSION | cut -d. -f 1,2`/site-packages @@ -11,9 +11,9 @@ Requires: cuda %endif AutoReq: no -%define llvmCommit dd3df36604b9a3418a28efce78ac470b22992f70 -%define llvmBranch cms/release/8.x/635f8ff -%define iwyuCommit 4d2bbcc0d98faccfc51d15c6f6a573ec78d7751d +%define llvmCommit 379a43bc841451feccf78db64f2ed5c9e62c7de8 +%define llvmBranch cms/release/9.x/c1a0a21 +%define iwyuCommit a40a28740c963636d8d41e75f297e8e078302d70 %define iwyuBranch master Source0: git+https://github.com/cms-externals/llvm-project.git?obj=%{llvmBranch}/%{llvmCommit}&export=llvm-%{realversion}-%{llvmCommit}&module=llvm-%{realversion}-%{llvmCommit}&output=/llvm-%{realversion}-%{llvmCommit}.tgz From 7a0e7e7a32ccb328c2804bf73118a0743ce791d8 Mon Sep 17 00:00:00 2001 From: Malik Shahzad Muzaffar Date: Wed, 8 Jan 2020 23:33:45 +0100 Subject: [PATCH 2/8] use clang_9.0 branch for iwyu --- llvm.spec | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/llvm.spec b/llvm.spec index 37f0cb64d3c..b94b1473bb2 100644 --- a/llvm.spec +++ b/llvm.spec @@ -13,8 +13,8 @@ AutoReq: no %define llvmCommit 379a43bc841451feccf78db64f2ed5c9e62c7de8 %define llvmBranch cms/release/9.x/c1a0a21 -%define iwyuCommit a40a28740c963636d8d41e75f297e8e078302d70 -%define iwyuBranch master +%define iwyuCommit 06e88efada2ff6dbccee3bbb1279c10439daa4d2 +%define iwyuBranch clang_9.0 Source0: git+https://github.com/cms-externals/llvm-project.git?obj=%{llvmBranch}/%{llvmCommit}&export=llvm-%{realversion}-%{llvmCommit}&module=llvm-%{realversion}-%{llvmCommit}&output=/llvm-%{realversion}-%{llvmCommit}.tgz Source1: git+https://github.com/include-what-you-use/include-what-you-use.git?obj=%{iwyuBranch}/%{iwyuCommit}&export=iwyu-%{realversion}-%{iwyuCommit}&module=iwyu-%{realversion}-%{iwyuCommit}&output=/iwyu-%{realversion}-%{iwyuCommit}.tgz From 457d3f7ce017a7596ef0ce4ff9a0ff12d8f9e0c8 Mon Sep 17 00:00:00 2001 From: Mircho Rodozov Date: Thu, 9 Jan 2020 16:51:05 +0100 Subject: [PATCH 3/8] Add patch for llvm9 compat --- codechecker-llvm9.patch | 794 ++++++++++++++++++++++++++++++++++++++++ codechecker.spec | 2 +- 2 files changed, 795 insertions(+), 1 deletion(-) create mode 100644 codechecker-llvm9.patch diff --git a/codechecker-llvm9.patch b/codechecker-llvm9.patch new file mode 100644 index 00000000000..43ba1a5aa25 --- /dev/null +++ b/codechecker-llvm9.patch @@ -0,0 +1,794 @@ +diff --git a/ClangTidy.h b/ClangTidy.h +index 0ea9a70..a9433f6 100644 +--- a/ClangTidy.h ++++ b/ClangTidy.h +@@ -1,25 +1,19 @@ + //===--- ClangTidy.h - clang-tidy -------------------------------*- C++ -*-===// + // +-// The LLVM Compiler Infrastructure +-// +-// This file is distributed under the University of Illinois Open Source +-// License. See LICENSE.TXT for details. ++// 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_CLANGTIDY_H + #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H + ++#include "ClangTidyCheck.h" + #include "ClangTidyDiagnosticConsumer.h" + #include "ClangTidyOptions.h" +-#include "clang/ASTMatchers/ASTMatchFinder.h" +-#include "clang/Basic/Diagnostic.h" +-#include "clang/Basic/SourceManager.h" +-#include "clang/Tooling/Refactoring.h" +-#include "llvm/ADT/StringExtras.h" + #include "llvm/Support/raw_ostream.h" + #include +-#include + #include + + namespace clang { +@@ -31,167 +25,13 @@ class CompilationDatabase; + + namespace tidy { + +-/// \brief Provides access to the ``ClangTidyCheck`` options via check-local +-/// names. +-/// +-/// Methods of this class prepend ``CheckName + "."`` to translate check-local +-/// option names to global option names. +-class OptionsView { +-public: +- /// \brief Initializes the instance using \p CheckName + "." as a prefix. +- OptionsView(StringRef CheckName, +- const ClangTidyOptions::OptionMap &CheckOptions); +- +- /// \brief Read a named option from the ``Context``. +- /// +- /// Reads the option with the check-local name \p LocalName from the +- /// ``CheckOptions``. If the corresponding key is not present, returns +- /// \p Default. +- std::string get(StringRef LocalName, StringRef Default) const; +- +- /// \brief Read a named option from the ``Context``. +- /// +- /// 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 Default. +- std::string getLocalOrGlobal(StringRef LocalName, StringRef Default) const; +- +- /// \brief 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 not present, returns +- /// \p Default. +- template +- typename std::enable_if::value, T>::type +- get(StringRef LocalName, T Default) const { +- std::string Value = get(LocalName, ""); +- T Result = Default; +- if (!Value.empty()) +- StringRef(Value).getAsInteger(10, Result); +- return Result; +- } +- +- /// \brief 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, +- /// returns Default. +- template +- typename std::enable_if::value, T>::type +- getLocalOrGlobal(StringRef LocalName, T Default) const { +- std::string Value = getLocalOrGlobal(LocalName, ""); +- T Result = Default; +- if (!Value.empty()) +- StringRef(Value).getAsInteger(10, Result); +- return Result; +- } +- +- /// \brief Stores an option with the check-local name \p LocalName with string +- /// value \p Value to \p Options. +- void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, +- StringRef Value) const; +- +- /// \brief Stores an option with the check-local name \p LocalName with +- /// ``int64_t`` value \p Value to \p Options. +- void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, +- int64_t Value) const; +- +-private: +- std::string NamePrefix; +- const ClangTidyOptions::OptionMap &CheckOptions; +-}; +- +-/// \brief Base class for all clang-tidy checks. +-/// +-/// To implement a ``ClangTidyCheck``, write a subclass and override some of the +-/// base class's methods. E.g. to implement a check that validates namespace +-/// declarations, override ``registerMatchers``: +-/// +-/// ~~~{.cpp} +-/// void registerMatchers(ast_matchers::MatchFinder *Finder) override { +-/// Finder->addMatcher(namespaceDecl().bind("namespace"), this); +-/// } +-/// ~~~ +-/// +-/// and then override ``check(const MatchResult &Result)`` to do the actual +-/// check for each match. +-/// +-/// A new ``ClangTidyCheck`` instance is created per translation unit. +-/// +-/// FIXME: Figure out whether carrying information from one TU to another is +-/// useful/necessary. +-class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { +-public: +- /// \brief Initializes the check with \p CheckName and \p Context. +- /// +- /// Derived classes must implement the constructor with this signature or +- /// delegate it. If a check needs to read options, it can do this in the +- /// constructor using the Options.get() methods below. +- ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context) +- : CheckName(CheckName), Context(Context), +- Options(CheckName, Context->getOptions().CheckOptions) { +- assert(Context != nullptr); +- assert(!CheckName.empty()); +- } +- +- /// \brief Override this to register ``PPCallbacks`` with ``Compiler``. +- /// +- /// This should be used for clang-tidy checks that analyze preprocessor- +- /// dependent properties, e.g. the order of include directives. +- virtual void registerPPCallbacks(CompilerInstance &Compiler) {} +- +- /// \brief Override this to register AST matchers with \p Finder. +- /// +- /// This should be used by clang-tidy checks that analyze code properties that +- /// dependent on AST knowledge. +- /// +- /// You can register as many matchers as necessary with \p Finder. Usually, +- /// "this" will be used as callback, but you can also specify other callback +- /// classes. Thereby, different matchers can trigger different callbacks. +- /// +- /// If you need to merge information between the different matchers, you can +- /// store these as members of the derived class. However, note that all +- /// matches occur in the order of the AST traversal. +- virtual void registerMatchers(ast_matchers::MatchFinder *Finder) {} +- +- /// \brief ``ClangTidyChecks`` that register ASTMatchers should do the actual +- /// work in here. +- virtual void check(const ast_matchers::MatchFinder::MatchResult &Result) {} +- +- /// \brief Add a diagnostic with the check's name. +- DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, +- DiagnosticIDs::Level Level = DiagnosticIDs::Warning); +- +- /// \brief Should store all options supported by this check with their +- /// current values or default values for options that haven't been overridden. +- /// +- /// The check should use ``Options.store()`` to store each option it supports +- /// whether it has the default value or it has been overridden. +- virtual void storeOptions(ClangTidyOptions::OptionMap &Options) {} +- +-private: +- void run(const ast_matchers::MatchFinder::MatchResult &Result) override; +- StringRef getID() const override { return CheckName; } +- std::string CheckName; +- ClangTidyContext *Context; +- +-protected: +- OptionsView Options; +- /// \brief Returns the main file name of the current translation unit. +- StringRef getCurrentMainFile() const { return Context->getCurrentFile(); } +- /// \brief Returns the language options from the context. +- LangOptions getLangOpts() const { return Context->getLangOpts(); } +-}; +- + class ClangTidyCheckFactories; + + class ClangTidyASTConsumerFactory { + public: +- ClangTidyASTConsumerFactory(ClangTidyContext &Context); ++ ClangTidyASTConsumerFactory( ++ ClangTidyContext &Context, ++ IntrusiveRefCntPtr OverlayFS = nullptr); + + /// \brief Returns an ASTConsumer that runs the specified clang-tidy checks. + std::unique_ptr +@@ -205,6 +45,7 @@ public: + + private: + ClangTidyContext &Context; ++ IntrusiveRefCntPtr OverlayFS; + std::unique_ptr CheckFactories; + }; + +@@ -230,12 +71,13 @@ getCheckOptions(const ClangTidyOptions &Options, + /// \param StoreCheckProfile If provided, and EnableCheckProfile is true, + /// the profile will not be output to stderr, but will instead be stored + /// as a JSON file in the specified directory. +-void runClangTidy(clang::tidy::ClangTidyContext &Context, +- const tooling::CompilationDatabase &Compilations, +- ArrayRef InputFiles, +- llvm::IntrusiveRefCntPtr BaseFS, +- bool EnableCheckProfile = false, +- llvm::StringRef StoreCheckProfile = StringRef()); ++std::vector ++runClangTidy(clang::tidy::ClangTidyContext &Context, ++ const tooling::CompilationDatabase &Compilations, ++ ArrayRef InputFiles, ++ llvm::IntrusiveRefCntPtr BaseFS, ++ bool EnableCheckProfile = false, ++ llvm::StringRef StoreCheckProfile = StringRef()); + + // FIXME: This interface will need to be significantly extended to be useful. + // FIXME: Implement confidence levels for displaying/fixing errors. +@@ -243,9 +85,10 @@ void runClangTidy(clang::tidy::ClangTidyContext &Context, + /// \brief Displays the found \p Errors to the users. If \p Fix is true, \p + /// Errors containing fixes are automatically applied and reformatted. If no + /// clang-format configuration file is found, the given \P FormatStyle is used. +-void handleErrors(ClangTidyContext &Context, bool Fix, ++void handleErrors(llvm::ArrayRef Errors, ++ ClangTidyContext &Context, bool Fix, + unsigned &WarningsAsErrorsCount, +- llvm::IntrusiveRefCntPtr BaseFS); ++ llvm::IntrusiveRefCntPtr BaseFS); + + /// \brief Serializes replacements into YAML and writes them to the specified + /// output stream. +diff --git a/ClangTidyCheck.h b/ClangTidyCheck.h +new file mode 100644 +index 0000000..3064a41 +--- /dev/null ++++ b/ClangTidyCheck.h +@@ -0,0 +1,194 @@ ++//===--- ClangTidyCheck.h - clang-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_CLANGTIDYCHECK_H ++#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYCHECK_H ++ ++#include "ClangTidyDiagnosticConsumer.h" ++#include "ClangTidyOptions.h" ++#include "clang/ASTMatchers/ASTMatchFinder.h" ++#include "clang/Basic/Diagnostic.h" ++#include "clang/Basic/SourceManager.h" ++#include "llvm/ADT/StringExtras.h" ++#include ++#include ++#include ++ ++namespace clang { ++ ++class CompilerInstance; ++ ++namespace tidy { ++ ++/// \brief Base class for all clang-tidy checks. ++/// ++/// To implement a ``ClangTidyCheck``, write a subclass and override some of the ++/// base class's methods. E.g. to implement a check that validates namespace ++/// declarations, override ``registerMatchers``: ++/// ++/// ~~~{.cpp} ++/// void registerMatchers(ast_matchers::MatchFinder *Finder) override { ++/// Finder->addMatcher(namespaceDecl().bind("namespace"), this); ++/// } ++/// ~~~ ++/// ++/// and then override ``check(const MatchResult &Result)`` to do the actual ++/// check for each match. ++/// ++/// A new ``ClangTidyCheck`` instance is created per translation unit. ++/// ++/// FIXME: Figure out whether carrying information from one TU to another is ++/// useful/necessary. ++class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { ++public: ++ /// \brief Initializes the check with \p CheckName and \p Context. ++ /// ++ /// Derived classes must implement the constructor with this signature or ++ /// delegate it. If a check needs to read options, it can do this in the ++ /// constructor using the Options.get() methods below. ++ ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context); ++ ++ /// \brief Override this to register ``PPCallbacks`` in the preprocessor. ++ /// ++ /// This should be used for clang-tidy checks that analyze preprocessor- ++ /// dependent properties, e.g. include directives and macro definitions. ++ /// ++ /// There are two Preprocessors to choose from that differ in how they handle ++ /// modular #includes: ++ /// - PP is the real Preprocessor. It doesn't walk into modular #includes and ++ /// thus doesn't generate PPCallbacks for their contents. ++ /// - ModuleExpanderPP preprocesses the whole translation unit in the ++ /// non-modular mode, which allows it to generate PPCallbacks not only for ++ /// the main file and textual headers, but also for all transitively ++ /// included modular headers when the analysis runs with modules enabled. ++ /// When modules are not enabled ModuleExpanderPP just points to the real ++ /// preprocessor. ++ virtual void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, ++ Preprocessor *ModuleExpanderPP) {} ++ ++ /// \brief Override this to register AST matchers with \p Finder. ++ /// ++ /// This should be used by clang-tidy checks that analyze code properties that ++ /// dependent on AST knowledge. ++ /// ++ /// You can register as many matchers as necessary with \p Finder. Usually, ++ /// "this" will be used as callback, but you can also specify other callback ++ /// classes. Thereby, different matchers can trigger different callbacks. ++ /// ++ /// If you need to merge information between the different matchers, you can ++ /// store these as members of the derived class. However, note that all ++ /// matches occur in the order of the AST traversal. ++ virtual void registerMatchers(ast_matchers::MatchFinder *Finder) {} ++ ++ /// \brief ``ClangTidyChecks`` that register ASTMatchers should do the actual ++ /// work in here. ++ virtual void check(const ast_matchers::MatchFinder::MatchResult &Result) {} ++ ++ /// \brief Add a diagnostic with the check's name. ++ DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, ++ DiagnosticIDs::Level Level = DiagnosticIDs::Warning); ++ ++ /// \brief Should store all options supported by this check with their ++ /// current values or default values for options that haven't been overridden. ++ /// ++ /// The check should use ``Options.store()`` to store each option it supports ++ /// whether it has the default value or it has been overridden. ++ virtual void storeOptions(ClangTidyOptions::OptionMap &Options) {} ++ ++ /// \brief Provides access to the ``ClangTidyCheck`` options via check-local ++ /// names. ++ /// ++ /// Methods of this class prepend ``CheckName + "."`` to translate check-local ++ /// option names to global option names. ++ class OptionsView { ++ public: ++ /// \brief Initializes the instance using \p CheckName + "." as a prefix. ++ OptionsView(StringRef CheckName, ++ const ClangTidyOptions::OptionMap &CheckOptions); ++ ++ /// \brief Read a named option from the ``Context``. ++ /// ++ /// Reads the option with the check-local name \p LocalName from the ++ /// ``CheckOptions``. If the corresponding key is not present, returns ++ /// \p Default. ++ std::string get(StringRef LocalName, StringRef Default) const; ++ ++ /// \brief Read a named option from the ``Context``. ++ /// ++ /// 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 Default. ++ std::string getLocalOrGlobal(StringRef LocalName, StringRef Default) const; ++ ++ /// \brief 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 not present, returns ++ /// \p Default. ++ template ++ typename std::enable_if::value, T>::type ++ get(StringRef LocalName, T Default) const { ++ std::string Value = get(LocalName, ""); ++ T Result = Default; ++ if (!Value.empty()) ++ StringRef(Value).getAsInteger(10, Result); ++ return Result; ++ } ++ ++ /// \brief 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, returns Default. ++ template ++ typename std::enable_if::value, T>::type ++ getLocalOrGlobal(StringRef LocalName, T Default) const { ++ std::string Value = getLocalOrGlobal(LocalName, ""); ++ T Result = Default; ++ if (!Value.empty()) ++ StringRef(Value).getAsInteger(10, Result); ++ return Result; ++ } ++ ++ /// \brief Stores an option with the check-local name \p LocalName with ++ /// string value \p Value to \p Options. ++ void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, ++ StringRef Value) const; ++ ++ /// \brief Stores an option with the check-local name \p LocalName with ++ /// ``int64_t`` value \p Value to \p Options. ++ void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, ++ int64_t Value) const; ++ ++ private: ++ std::string NamePrefix; ++ const ClangTidyOptions::OptionMap &CheckOptions; ++ }; ++ ++private: ++ void run(const ast_matchers::MatchFinder::MatchResult &Result) override; ++ StringRef getID() const override { return CheckName; } ++ std::string CheckName; ++ ClangTidyContext *Context; ++ ++protected: ++ OptionsView Options; ++ /// \brief Returns the main file name of the current translation unit. ++ StringRef getCurrentMainFile() const { return Context->getCurrentFile(); } ++ /// \brief Returns the language options from the context. ++ const LangOptions &getLangOpts() const { return Context->getLangOpts(); } ++}; ++ ++} // namespace tidy ++} // namespace clang ++ ++#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYCHECK_H +diff --git a/ClangTidyDiagnosticConsumer.h b/ClangTidyDiagnosticConsumer.h +index ae25013..01a3526 100644 +--- a/ClangTidyDiagnosticConsumer.h ++++ b/ClangTidyDiagnosticConsumer.h +@@ -1,9 +1,8 @@ + //===--- ClangTidyDiagnosticConsumer.h - clang-tidy -------------*- C++ -*-===// + // +-// The LLVM Compiler Infrastructure +-// +-// This file is distributed under the University of Illinois Open Source +-// License. See LICENSE.TXT for details. ++// 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 + // + //===----------------------------------------------------------------------===// + +@@ -102,6 +101,12 @@ public: + /// \brief Initializes \c ClangTidyContext instance. + ClangTidyContext(std::unique_ptr OptionsProvider, + bool AllowEnablingAnalyzerAlphaCheckers = 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. ++ void setDiagnosticsEngine(DiagnosticsEngine *DiagEngine) { ++ this->DiagEngine = DiagEngine; ++ } + + ~ClangTidyContext(); + +@@ -133,7 +138,7 @@ public: + + /// \brief Returns the name of the clang-tidy check which produced this + /// diagnostic ID. +- StringRef getCheckName(unsigned DiagnosticID) const; ++ std::string getCheckName(unsigned DiagnosticID) const; + + /// \brief Returns \c true if the check is enabled for the \c CurrentFile. + /// +@@ -160,12 +165,6 @@ public: + /// counters. + const ClangTidyStats &getStats() const { return Stats; } + +- /// \brief Returns all collected errors. +- ArrayRef getErrors() const { return Errors; } +- +- /// \brief Clears collected errors. +- void clearErrors() { Errors.clear(); } +- + /// \brief Control profile collection in clang-tidy. + void setEnableProfiling(bool Profile); + bool getEnableProfiling() const { return Profile; } +@@ -191,19 +190,19 @@ public: + return AllowEnablingAnalyzerAlphaCheckers; + } + ++ using DiagLevelAndFormatString = std::pair; ++ DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID, ++ SourceLocation Loc) { ++ return DiagLevelAndFormatString( ++ static_cast( ++ DiagEngine->getDiagnosticLevel(DiagnosticID, Loc)), ++ DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID)); ++ } ++ + private: +- // Calls setDiagnosticsEngine() and storeError(). ++ // Writes to Stats. + friend class ClangTidyDiagnosticConsumer; +- friend class ClangTidyPluginAction; +- +- /// \brief Sets the \c DiagnosticsEngine so that Diagnostics can be generated +- /// correctly. +- void setDiagnosticsEngine(DiagnosticsEngine *Engine); + +- /// \brief Store an \p Error. +- void storeError(const ClangTidyError &Error); +- +- std::vector Errors; + DiagnosticsEngine *DiagEngine; + std::unique_ptr OptionsProvider; + +@@ -227,6 +226,23 @@ private: + bool AllowEnablingAnalyzerAlphaCheckers; + }; + ++/// Check whether a given diagnostic should be suppressed due to the presence ++/// of a "NOLINT" suppression comment. ++/// This is exposed so that other tools that present clang-tidy diagnostics ++/// (such as clangd) can respect the same suppression rules as clang-tidy. ++/// This does not handle suppression of notes following a suppressed diagnostic; ++/// that is left to the caller is it requires maintaining state in between calls ++/// to this function. ++/// The `CheckMacroExpansion` parameter determines whether the function should ++/// handle the case where the diagnostic is inside a macro expansion. A degree ++/// of control over this is needed because handling this case can require ++/// examining source files other than the one in which the diagnostic is ++/// located, and in some use cases we cannot rely on such other files being ++/// mapped in the SourceMapper. ++bool ShouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel, ++ const Diagnostic &Info, ClangTidyContext &Context, ++ bool CheckMacroExpansion = true); ++ + /// \brief A diagnostic consumer that turns each \c Diagnostic into a + /// \c SourceManager-independent \c ClangTidyError. + // +@@ -235,6 +251,7 @@ private: + class ClangTidyDiagnosticConsumer : public DiagnosticConsumer { + public: + ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx, ++ DiagnosticsEngine *ExternalDiagEngine = nullptr, + bool RemoveIncompatibleErrors = true); + + // FIXME: The concept of converting between FixItHints and Replacements is +@@ -243,13 +260,12 @@ public: + void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, + const Diagnostic &Info) override; + +- /// \brief Flushes the internal diagnostics buffer to the ClangTidyContext. +- void finish() override; ++ // Retrieve the diagnostics that were captured. ++ std::vector take(); + + private: + void finalizeLastError(); +- +- void removeIncompatibleErrors(SmallVectorImpl &Errors) const; ++ void removeIncompatibleErrors(); + + /// \brief Returns the \c HeaderFilter constructed for the options set in the + /// context. +@@ -257,13 +273,15 @@ private: + + /// \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter + /// according to the diagnostic \p Location. +- void checkFilters(SourceLocation Location); ++ void checkFilters(SourceLocation Location, const SourceManager &Sources); + bool passesLineFilter(StringRef FileName, unsigned LineNumber) const; + ++ void forwardDiagnostic(const Diagnostic &Info); ++ + ClangTidyContext &Context; ++ DiagnosticsEngine *ExternalDiagEngine; + bool RemoveIncompatibleErrors; +- std::unique_ptr Diags; +- SmallVector Errors; ++ std::vector Errors; + std::unique_ptr HeaderFilter; + bool LastErrorRelatesToUserCode; + bool LastErrorPassesLineFilter; +diff --git a/ClangTidyModule.h b/ClangTidyModule.h +index 4721636..378f109 100644 +--- a/ClangTidyModule.h ++++ b/ClangTidyModule.h +@@ -1,9 +1,8 @@ + //===--- ClangTidyModule.h - clang-tidy -------------------------*- C++ -*-===// + // +-// The LLVM Compiler Infrastructure +-// +-// This file is distributed under the University of Illinois Open Source +-// License. See LICENSE.TXT for details. ++// 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 + // + //===----------------------------------------------------------------------===// + +diff --git a/ClangTidyModuleRegistry.h b/ClangTidyModuleRegistry.h +index dc44d14..891671a 100644 +--- a/ClangTidyModuleRegistry.h ++++ b/ClangTidyModuleRegistry.h +@@ -1,9 +1,8 @@ + //===--- ClangTidyModuleRegistry.h - clang-tidy -----------------*- C++ -*-===// + // +-// The LLVM Compiler Infrastructure +-// +-// This file is distributed under the University of Illinois Open Source +-// License. See LICENSE.TXT for details. ++// 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 + // + //===----------------------------------------------------------------------===// + +diff --git a/ClangTidyOptions.h b/ClangTidyOptions.h +index b2a4ce4..87c7cf5 100644 +--- a/ClangTidyOptions.h ++++ b/ClangTidyOptions.h +@@ -1,21 +1,20 @@ + //===--- ClangTidyOptions.h - clang-tidy ------------------------*- C++ -*-===// + // +-// The LLVM Compiler Infrastructure +-// +-// This file is distributed under the University of Illinois Open Source +-// License. See LICENSE.TXT for details. ++// 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_CLANGTIDYOPTIONS_H + #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H + ++#include "llvm/ADT/IntrusiveRefCntPtr.h" + #include "llvm/ADT/Optional.h" + #include "llvm/ADT/StringMap.h" + #include "llvm/ADT/StringRef.h" +-#include "llvm/ADT/IntrusiveRefCntPtr.h" + #include "llvm/Support/ErrorOr.h" +-#include "clang/Basic/VirtualFileSystem.h" ++#include "llvm/Support/VirtualFileSystem.h" + #include + #include + #include +@@ -218,10 +217,11 @@ public: + /// + /// If any of the \param OverrideOptions fields are set, they will override + /// whatever options are read from the configuration file. +- FileOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions, +- const ClangTidyOptions &DefaultOptions, +- const ClangTidyOptions &OverrideOptions, +- llvm::IntrusiveRefCntPtr FS = nullptr); ++ FileOptionsProvider( ++ const ClangTidyGlobalOptions &GlobalOptions, ++ const ClangTidyOptions &DefaultOptions, ++ const ClangTidyOptions &OverrideOptions, ++ llvm::IntrusiveRefCntPtr FS = nullptr); + + /// \brief Initializes the \c FileOptionsProvider instance with a custom set + /// of configuration file handlers. +@@ -255,7 +255,7 @@ protected: + llvm::StringMap CachedOptions; + ClangTidyOptions OverrideOptions; + ConfigFileHandlers ConfigHandlers; +- llvm::IntrusiveRefCntPtr FS; ++ llvm::IntrusiveRefCntPtr FS; + }; + + /// \brief Parses LineFilter from JSON and stores it to the \p Options. +diff --git a/ClangTidyProfiling.h b/ClangTidyProfiling.h +index 9d86b8e..a266e38 100644 +--- a/ClangTidyProfiling.h ++++ b/ClangTidyProfiling.h +@@ -1,9 +1,8 @@ + //===--- ClangTidyProfiling.h - clang-tidy ----------------------*- C++ -*-===// + // +-// The LLVM Compiler Infrastructure +-// +-// This file is distributed under the University of Illinois Open Source +-// License. See LICENSE.TXT for details. ++// 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 + // + //===----------------------------------------------------------------------===// + +diff --git a/tool/ClangTidyMain.cpp b/tool/ClangTidyMain.cpp +index f36c4ec..329a1e9 100644 +--- a/tool/ClangTidyMain.cpp ++++ b/tool/ClangTidyMain.cpp +@@ -326,12 +326,41 @@ getVfsOverlayFromFile(const std::string &OverlayFile) { + return OverlayFS; + } + ++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; ++} ++ + static int clangTidyMain(int argc, const char **argv) { + CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory, + cl::ZeroOrMore); +- llvm::IntrusiveRefCntPtr BaseFS( +- VfsOverlay.empty() ? vfs::getRealFileSystem() +- : getVfsOverlayFromFile(VfsOverlay)); ++ llvm::IntrusiveRefCntPtr BaseFS( ++ new vfs::OverlayFileSystem(vfs::getRealFileSystem())); ++ ++ if (!VfsOverlay.empty()) { ++ IntrusiveRefCntPtr VfsFromFile = ++ getVfsFromFile(VfsOverlay, BaseFS); ++ if (!VfsFromFile) ++ return 1; ++ BaseFS->pushOverlay(VfsFromFile); ++ } + if (!BaseFS) + return 1; + +@@ -421,9 +450,9 @@ static int clangTidyMain(int argc, const char **argv) { + + ClangTidyContext Context(std::move(OwningOptionsProvider), + AllowEnablingAnalyzerAlphaCheckers); +- runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS, +- EnableCheckProfile, ProfilePrefix); +- ArrayRef Errors = Context.getErrors(); ++ std::vector Errors = ++ runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS, ++ EnableCheckProfile, ProfilePrefix); + bool FoundErrors = llvm::find_if(Errors, [](const ClangTidyError &E) { + return E.DiagLevel == ClangTidyError::Error; + }) != Errors.end(); +@@ -433,7 +462,7 @@ static int clangTidyMain(int argc, const char **argv) { + unsigned WErrorCount = 0; + + // -fix-errors implies -fix. +- handleErrors(Context, (FixErrors || Fix) && !DisableFixes, WErrorCount, ++ handleErrors(Errors, Context, (FixErrors || Fix) && !DisableFixes, WErrorCount, + BaseFS); + + if (!ExportFixes.empty() && !Errors.empty()) { +@@ -569,10 +598,15 @@ extern volatile int ZirconModuleAnchorSource; + static int LLVM_ATTRIBUTE_UNUSED ZirconModuleAnchorDestination = + ZirconModuleAnchorSource; + +-// This anchor is used to force the linker to link the CMS. +-extern volatile int CMSModuleAnchorSource; +-static int LLVM_ATTRIBUTE_UNUSED CMSAnchorDestination = +- CMSModuleAnchorSource; ++// This anchor is used to force the linker to link the AliceO2Module. ++extern volatile int AliceO2ModuleAnchorSource; ++static int LLVM_ATTRIBUTE_UNUSED AliceO2ModuleAnchorDestination = ++ AliceO2ModuleAnchorSource; ++ ++// This anchor is used to force the linker to link the ReportingModule. ++extern volatile int ReportingModuleAnchorSource; ++static int LLVM_ATTRIBUTE_UNUSED ReportingModuleAnchorDestination = ++ ReportingModuleAnchorSource; + + } // namespace tidy + } // namespace clang diff --git a/codechecker.spec b/codechecker.spec index 3563d8ab097..369fb6c3bc3 100644 --- a/codechecker.spec +++ b/codechecker.spec @@ -8,7 +8,7 @@ Source: git+https://github.com/%github_user/CMSCodeChecker.git?obj=%{branch}/%{t BuildRequires: cmake Requires: llvm -Patch0: codechecker-llvm8 +Patch0: codechecker-llvm9 %prep %setup -n %n-%{realversion} From 187fd4cf415bb06134f4265979678cf3a7361962 Mon Sep 17 00:00:00 2001 From: Mircho Rodozov Date: Thu, 9 Jan 2020 17:39:12 +0100 Subject: [PATCH 4/8] More changes to point to cms-externals --- codechecker.spec | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/codechecker.spec b/codechecker.spec index 369fb6c3bc3..bf4913a3997 100644 --- a/codechecker.spec +++ b/codechecker.spec @@ -1,18 +1,16 @@ ### RPM external codechecker 0.1 ## INITENV +PATH LD_LIBRARY_PATH %i/lib64 -%define tag 5248cbf0bc6e0f5a81e5f2fe75d81f55601b23b9 -%define branch master -%define github_user gartung +%define tag f10d1156e2295d688d6b0a80fae50df029caa1fd +%define branch llvm9 +%define github_user cms-externals Source: git+https://github.com/%github_user/CMSCodeChecker.git?obj=%{branch}/%{tag}&export=%{n}-%{realversion}&output=/%{n}-%{realversion}.tgz BuildRequires: cmake Requires: llvm -Patch0: codechecker-llvm9 %prep %setup -n %n-%{realversion} -%patch0 -p1 %build mkdir build From b61a8820c968e401a832b33047f6b4c1bff6d928 Mon Sep 17 00:00:00 2001 From: Mircho Rodozov Date: Thu, 9 Jan 2020 17:40:59 +0100 Subject: [PATCH 5/8] Remove patches --- codechecker-llvm8.patch | 213 ----------- codechecker-llvm9.patch | 794 ---------------------------------------- 2 files changed, 1007 deletions(-) delete mode 100644 codechecker-llvm8.patch delete mode 100644 codechecker-llvm9.patch diff --git a/codechecker-llvm8.patch b/codechecker-llvm8.patch deleted file mode 100644 index 5f2618b861e..00000000000 --- a/codechecker-llvm8.patch +++ /dev/null @@ -1,213 +0,0 @@ -diff --git a/ClangTidy.h b/ClangTidy.h -index 0ea9a70..dc11200 100644 ---- a/ClangTidy.h -+++ b/ClangTidy.h -@@ -230,12 +230,13 @@ getCheckOptions(const ClangTidyOptions &Options, - /// \param StoreCheckProfile If provided, and EnableCheckProfile is true, - /// the profile will not be output to stderr, but will instead be stored - /// as a JSON file in the specified directory. --void runClangTidy(clang::tidy::ClangTidyContext &Context, -- const tooling::CompilationDatabase &Compilations, -- ArrayRef InputFiles, -- llvm::IntrusiveRefCntPtr BaseFS, -- bool EnableCheckProfile = false, -- llvm::StringRef StoreCheckProfile = StringRef()); -+std::vector -+runClangTidy(clang::tidy::ClangTidyContext &Context, -+ const tooling::CompilationDatabase &Compilations, -+ ArrayRef InputFiles, -+ llvm::IntrusiveRefCntPtr BaseFS, -+ bool EnableCheckProfile = false, -+ llvm::StringRef StoreCheckProfile = StringRef()); - - // FIXME: This interface will need to be significantly extended to be useful. - // FIXME: Implement confidence levels for displaying/fixing errors. -@@ -243,9 +244,10 @@ void runClangTidy(clang::tidy::ClangTidyContext &Context, - /// \brief Displays the found \p Errors to the users. If \p Fix is true, \p - /// Errors containing fixes are automatically applied and reformatted. If no - /// clang-format configuration file is found, the given \P FormatStyle is used. --void handleErrors(ClangTidyContext &Context, bool Fix, -+void handleErrors(llvm::ArrayRef Errors, -+ ClangTidyContext &Context, bool Fix, - unsigned &WarningsAsErrorsCount, -- llvm::IntrusiveRefCntPtr BaseFS); -+ llvm::IntrusiveRefCntPtr BaseFS); - - /// \brief Serializes replacements into YAML and writes them to the specified - /// output stream. -diff --git a/ClangTidyDiagnosticConsumer.h b/ClangTidyDiagnosticConsumer.h -index ae25013..a868203 100644 ---- a/ClangTidyDiagnosticConsumer.h -+++ b/ClangTidyDiagnosticConsumer.h -@@ -102,6 +102,12 @@ public: - /// \brief Initializes \c ClangTidyContext instance. - ClangTidyContext(std::unique_ptr OptionsProvider, - bool AllowEnablingAnalyzerAlphaCheckers = 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. -+ void setDiagnosticsEngine(DiagnosticsEngine *DiagEngine) { -+ this->DiagEngine = DiagEngine; -+ } - - ~ClangTidyContext(); - -@@ -160,12 +166,6 @@ public: - /// counters. - const ClangTidyStats &getStats() const { return Stats; } - -- /// \brief Returns all collected errors. -- ArrayRef getErrors() const { return Errors; } -- -- /// \brief Clears collected errors. -- void clearErrors() { Errors.clear(); } -- - /// \brief Control profile collection in clang-tidy. - void setEnableProfiling(bool Profile); - bool getEnableProfiling() const { return Profile; } -@@ -192,18 +192,9 @@ public: - } - - private: -- // Calls setDiagnosticsEngine() and storeError(). -+ // Writes to Stats. - friend class ClangTidyDiagnosticConsumer; -- friend class ClangTidyPluginAction; -- -- /// \brief Sets the \c DiagnosticsEngine so that Diagnostics can be generated -- /// correctly. -- void setDiagnosticsEngine(DiagnosticsEngine *Engine); - -- /// \brief Store an \p Error. -- void storeError(const ClangTidyError &Error); -- -- std::vector Errors; - DiagnosticsEngine *DiagEngine; - std::unique_ptr OptionsProvider; - -@@ -243,13 +234,12 @@ public: - void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, - const Diagnostic &Info) override; - -- /// \brief Flushes the internal diagnostics buffer to the ClangTidyContext. -- void finish() override; -+ // Retrieve the diagnostics that were captured. -+ std::vector take(); - - private: - void finalizeLastError(); -- -- void removeIncompatibleErrors(SmallVectorImpl &Errors) const; -+ void removeIncompatibleErrors(); - - /// \brief Returns the \c HeaderFilter constructed for the options set in the - /// context. -@@ -257,13 +247,12 @@ private: - - /// \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter - /// according to the diagnostic \p Location. -- void checkFilters(SourceLocation Location); -+ void checkFilters(SourceLocation Location, const SourceManager& Sources); - bool passesLineFilter(StringRef FileName, unsigned LineNumber) const; - - ClangTidyContext &Context; - bool RemoveIncompatibleErrors; -- std::unique_ptr Diags; -- SmallVector Errors; -+ std::vector Errors; - std::unique_ptr HeaderFilter; - bool LastErrorRelatesToUserCode; - bool LastErrorPassesLineFilter; -diff --git a/ClangTidyOptions.h b/ClangTidyOptions.h -index b2a4ce4..3ea3538 100644 ---- a/ClangTidyOptions.h -+++ b/ClangTidyOptions.h -@@ -15,7 +15,7 @@ - #include "llvm/ADT/StringRef.h" - #include "llvm/ADT/IntrusiveRefCntPtr.h" - #include "llvm/Support/ErrorOr.h" --#include "clang/Basic/VirtualFileSystem.h" -+#include "llvm/Support/VirtualFileSystem.h" - #include - #include - #include -@@ -221,7 +221,7 @@ public: - FileOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions, - const ClangTidyOptions &DefaultOptions, - const ClangTidyOptions &OverrideOptions, -- llvm::IntrusiveRefCntPtr FS = nullptr); -+ llvm::IntrusiveRefCntPtr FS = nullptr); - - /// \brief Initializes the \c FileOptionsProvider instance with a custom set - /// of configuration file handlers. -@@ -255,7 +255,7 @@ protected: - llvm::StringMap CachedOptions; - ClangTidyOptions OverrideOptions; - ConfigFileHandlers ConfigHandlers; -- llvm::IntrusiveRefCntPtr FS; -+ llvm::IntrusiveRefCntPtr FS; - }; - - /// \brief Parses LineFilter from JSON and stores it to the \p Options. -diff --git a/tool/ClangTidyMain.cpp b/tool/ClangTidyMain.cpp -index f36c4ec..d72cf98 100644 ---- a/tool/ClangTidyMain.cpp -+++ b/tool/ClangTidyMain.cpp -@@ -254,7 +254,7 @@ static void printStats(const ClangTidyStats &Stats) { - } - - static std::unique_ptr createOptionsProvider( -- llvm::IntrusiveRefCntPtr FS) { -+ llvm::IntrusiveRefCntPtr FS) { - ClangTidyGlobalOptions GlobalOptions; - if (std::error_code Err = parseLineFilter(LineFilter, GlobalOptions)) { - llvm::errs() << "Invalid LineFilter: " << Err.message() << "\n\nUsage:\n"; -@@ -302,7 +302,7 @@ static std::unique_ptr createOptionsProvider( - OverrideOptions, std::move(FS)); - } - --llvm::IntrusiveRefCntPtr -+llvm::IntrusiveRefCntPtr - getVfsOverlayFromFile(const std::string &OverlayFile) { - llvm::IntrusiveRefCntPtr OverlayFS( - new vfs::OverlayFileSystem(vfs::getRealFileSystem())); -@@ -315,7 +315,7 @@ getVfsOverlayFromFile(const std::string &OverlayFile) { - return nullptr; - } - -- IntrusiveRefCntPtr FS = vfs::getVFSFromYAML( -+ IntrusiveRefCntPtr FS = vfs::getVFSFromYAML( - std::move(Buffer.get()), /*DiagHandler*/ nullptr, OverlayFile); - if (!FS) { - llvm::errs() << "Error: invalid virtual filesystem overlay file '" -@@ -329,7 +329,7 @@ getVfsOverlayFromFile(const std::string &OverlayFile) { - static int clangTidyMain(int argc, const char **argv) { - CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory, - cl::ZeroOrMore); -- llvm::IntrusiveRefCntPtr BaseFS( -+ llvm::IntrusiveRefCntPtr BaseFS( - VfsOverlay.empty() ? vfs::getRealFileSystem() - : getVfsOverlayFromFile(VfsOverlay)); - if (!BaseFS) -@@ -421,9 +421,9 @@ static int clangTidyMain(int argc, const char **argv) { - - ClangTidyContext Context(std::move(OwningOptionsProvider), - AllowEnablingAnalyzerAlphaCheckers); -- runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS, -- EnableCheckProfile, ProfilePrefix); -- ArrayRef Errors = Context.getErrors(); -+ std::vector Errors = -+ runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS, -+ EnableCheckProfile, ProfilePrefix); - bool FoundErrors = llvm::find_if(Errors, [](const ClangTidyError &E) { - return E.DiagLevel == ClangTidyError::Error; - }) != Errors.end(); -@@ -433,7 +433,7 @@ static int clangTidyMain(int argc, const char **argv) { - unsigned WErrorCount = 0; - - // -fix-errors implies -fix. -- handleErrors(Context, (FixErrors || Fix) && !DisableFixes, WErrorCount, -+ handleErrors(Errors, Context, (FixErrors || Fix) && !DisableFixes, WErrorCount, - BaseFS); - - if (!ExportFixes.empty() && !Errors.empty()) { diff --git a/codechecker-llvm9.patch b/codechecker-llvm9.patch deleted file mode 100644 index 43ba1a5aa25..00000000000 --- a/codechecker-llvm9.patch +++ /dev/null @@ -1,794 +0,0 @@ -diff --git a/ClangTidy.h b/ClangTidy.h -index 0ea9a70..a9433f6 100644 ---- a/ClangTidy.h -+++ b/ClangTidy.h -@@ -1,25 +1,19 @@ - //===--- ClangTidy.h - clang-tidy -------------------------------*- C++ -*-===// - // --// The LLVM Compiler Infrastructure --// --// This file is distributed under the University of Illinois Open Source --// License. See LICENSE.TXT for details. -+// 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_CLANGTIDY_H - #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDY_H - -+#include "ClangTidyCheck.h" - #include "ClangTidyDiagnosticConsumer.h" - #include "ClangTidyOptions.h" --#include "clang/ASTMatchers/ASTMatchFinder.h" --#include "clang/Basic/Diagnostic.h" --#include "clang/Basic/SourceManager.h" --#include "clang/Tooling/Refactoring.h" --#include "llvm/ADT/StringExtras.h" - #include "llvm/Support/raw_ostream.h" - #include --#include - #include - - namespace clang { -@@ -31,167 +25,13 @@ class CompilationDatabase; - - namespace tidy { - --/// \brief Provides access to the ``ClangTidyCheck`` options via check-local --/// names. --/// --/// Methods of this class prepend ``CheckName + "."`` to translate check-local --/// option names to global option names. --class OptionsView { --public: -- /// \brief Initializes the instance using \p CheckName + "." as a prefix. -- OptionsView(StringRef CheckName, -- const ClangTidyOptions::OptionMap &CheckOptions); -- -- /// \brief Read a named option from the ``Context``. -- /// -- /// Reads the option with the check-local name \p LocalName from the -- /// ``CheckOptions``. If the corresponding key is not present, returns -- /// \p Default. -- std::string get(StringRef LocalName, StringRef Default) const; -- -- /// \brief Read a named option from the ``Context``. -- /// -- /// 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 Default. -- std::string getLocalOrGlobal(StringRef LocalName, StringRef Default) const; -- -- /// \brief 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 not present, returns -- /// \p Default. -- template -- typename std::enable_if::value, T>::type -- get(StringRef LocalName, T Default) const { -- std::string Value = get(LocalName, ""); -- T Result = Default; -- if (!Value.empty()) -- StringRef(Value).getAsInteger(10, Result); -- return Result; -- } -- -- /// \brief 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, -- /// returns Default. -- template -- typename std::enable_if::value, T>::type -- getLocalOrGlobal(StringRef LocalName, T Default) const { -- std::string Value = getLocalOrGlobal(LocalName, ""); -- T Result = Default; -- if (!Value.empty()) -- StringRef(Value).getAsInteger(10, Result); -- return Result; -- } -- -- /// \brief Stores an option with the check-local name \p LocalName with string -- /// value \p Value to \p Options. -- void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, -- StringRef Value) const; -- -- /// \brief Stores an option with the check-local name \p LocalName with -- /// ``int64_t`` value \p Value to \p Options. -- void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, -- int64_t Value) const; -- --private: -- std::string NamePrefix; -- const ClangTidyOptions::OptionMap &CheckOptions; --}; -- --/// \brief Base class for all clang-tidy checks. --/// --/// To implement a ``ClangTidyCheck``, write a subclass and override some of the --/// base class's methods. E.g. to implement a check that validates namespace --/// declarations, override ``registerMatchers``: --/// --/// ~~~{.cpp} --/// void registerMatchers(ast_matchers::MatchFinder *Finder) override { --/// Finder->addMatcher(namespaceDecl().bind("namespace"), this); --/// } --/// ~~~ --/// --/// and then override ``check(const MatchResult &Result)`` to do the actual --/// check for each match. --/// --/// A new ``ClangTidyCheck`` instance is created per translation unit. --/// --/// FIXME: Figure out whether carrying information from one TU to another is --/// useful/necessary. --class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { --public: -- /// \brief Initializes the check with \p CheckName and \p Context. -- /// -- /// Derived classes must implement the constructor with this signature or -- /// delegate it. If a check needs to read options, it can do this in the -- /// constructor using the Options.get() methods below. -- ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context) -- : CheckName(CheckName), Context(Context), -- Options(CheckName, Context->getOptions().CheckOptions) { -- assert(Context != nullptr); -- assert(!CheckName.empty()); -- } -- -- /// \brief Override this to register ``PPCallbacks`` with ``Compiler``. -- /// -- /// This should be used for clang-tidy checks that analyze preprocessor- -- /// dependent properties, e.g. the order of include directives. -- virtual void registerPPCallbacks(CompilerInstance &Compiler) {} -- -- /// \brief Override this to register AST matchers with \p Finder. -- /// -- /// This should be used by clang-tidy checks that analyze code properties that -- /// dependent on AST knowledge. -- /// -- /// You can register as many matchers as necessary with \p Finder. Usually, -- /// "this" will be used as callback, but you can also specify other callback -- /// classes. Thereby, different matchers can trigger different callbacks. -- /// -- /// If you need to merge information between the different matchers, you can -- /// store these as members of the derived class. However, note that all -- /// matches occur in the order of the AST traversal. -- virtual void registerMatchers(ast_matchers::MatchFinder *Finder) {} -- -- /// \brief ``ClangTidyChecks`` that register ASTMatchers should do the actual -- /// work in here. -- virtual void check(const ast_matchers::MatchFinder::MatchResult &Result) {} -- -- /// \brief Add a diagnostic with the check's name. -- DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, -- DiagnosticIDs::Level Level = DiagnosticIDs::Warning); -- -- /// \brief Should store all options supported by this check with their -- /// current values or default values for options that haven't been overridden. -- /// -- /// The check should use ``Options.store()`` to store each option it supports -- /// whether it has the default value or it has been overridden. -- virtual void storeOptions(ClangTidyOptions::OptionMap &Options) {} -- --private: -- void run(const ast_matchers::MatchFinder::MatchResult &Result) override; -- StringRef getID() const override { return CheckName; } -- std::string CheckName; -- ClangTidyContext *Context; -- --protected: -- OptionsView Options; -- /// \brief Returns the main file name of the current translation unit. -- StringRef getCurrentMainFile() const { return Context->getCurrentFile(); } -- /// \brief Returns the language options from the context. -- LangOptions getLangOpts() const { return Context->getLangOpts(); } --}; -- - class ClangTidyCheckFactories; - - class ClangTidyASTConsumerFactory { - public: -- ClangTidyASTConsumerFactory(ClangTidyContext &Context); -+ ClangTidyASTConsumerFactory( -+ ClangTidyContext &Context, -+ IntrusiveRefCntPtr OverlayFS = nullptr); - - /// \brief Returns an ASTConsumer that runs the specified clang-tidy checks. - std::unique_ptr -@@ -205,6 +45,7 @@ public: - - private: - ClangTidyContext &Context; -+ IntrusiveRefCntPtr OverlayFS; - std::unique_ptr CheckFactories; - }; - -@@ -230,12 +71,13 @@ getCheckOptions(const ClangTidyOptions &Options, - /// \param StoreCheckProfile If provided, and EnableCheckProfile is true, - /// the profile will not be output to stderr, but will instead be stored - /// as a JSON file in the specified directory. --void runClangTidy(clang::tidy::ClangTidyContext &Context, -- const tooling::CompilationDatabase &Compilations, -- ArrayRef InputFiles, -- llvm::IntrusiveRefCntPtr BaseFS, -- bool EnableCheckProfile = false, -- llvm::StringRef StoreCheckProfile = StringRef()); -+std::vector -+runClangTidy(clang::tidy::ClangTidyContext &Context, -+ const tooling::CompilationDatabase &Compilations, -+ ArrayRef InputFiles, -+ llvm::IntrusiveRefCntPtr BaseFS, -+ bool EnableCheckProfile = false, -+ llvm::StringRef StoreCheckProfile = StringRef()); - - // FIXME: This interface will need to be significantly extended to be useful. - // FIXME: Implement confidence levels for displaying/fixing errors. -@@ -243,9 +85,10 @@ void runClangTidy(clang::tidy::ClangTidyContext &Context, - /// \brief Displays the found \p Errors to the users. If \p Fix is true, \p - /// Errors containing fixes are automatically applied and reformatted. If no - /// clang-format configuration file is found, the given \P FormatStyle is used. --void handleErrors(ClangTidyContext &Context, bool Fix, -+void handleErrors(llvm::ArrayRef Errors, -+ ClangTidyContext &Context, bool Fix, - unsigned &WarningsAsErrorsCount, -- llvm::IntrusiveRefCntPtr BaseFS); -+ llvm::IntrusiveRefCntPtr BaseFS); - - /// \brief Serializes replacements into YAML and writes them to the specified - /// output stream. -diff --git a/ClangTidyCheck.h b/ClangTidyCheck.h -new file mode 100644 -index 0000000..3064a41 ---- /dev/null -+++ b/ClangTidyCheck.h -@@ -0,0 +1,194 @@ -+//===--- ClangTidyCheck.h - clang-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_CLANGTIDYCHECK_H -+#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYCHECK_H -+ -+#include "ClangTidyDiagnosticConsumer.h" -+#include "ClangTidyOptions.h" -+#include "clang/ASTMatchers/ASTMatchFinder.h" -+#include "clang/Basic/Diagnostic.h" -+#include "clang/Basic/SourceManager.h" -+#include "llvm/ADT/StringExtras.h" -+#include -+#include -+#include -+ -+namespace clang { -+ -+class CompilerInstance; -+ -+namespace tidy { -+ -+/// \brief Base class for all clang-tidy checks. -+/// -+/// To implement a ``ClangTidyCheck``, write a subclass and override some of the -+/// base class's methods. E.g. to implement a check that validates namespace -+/// declarations, override ``registerMatchers``: -+/// -+/// ~~~{.cpp} -+/// void registerMatchers(ast_matchers::MatchFinder *Finder) override { -+/// Finder->addMatcher(namespaceDecl().bind("namespace"), this); -+/// } -+/// ~~~ -+/// -+/// and then override ``check(const MatchResult &Result)`` to do the actual -+/// check for each match. -+/// -+/// A new ``ClangTidyCheck`` instance is created per translation unit. -+/// -+/// FIXME: Figure out whether carrying information from one TU to another is -+/// useful/necessary. -+class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback { -+public: -+ /// \brief Initializes the check with \p CheckName and \p Context. -+ /// -+ /// Derived classes must implement the constructor with this signature or -+ /// delegate it. If a check needs to read options, it can do this in the -+ /// constructor using the Options.get() methods below. -+ ClangTidyCheck(StringRef CheckName, ClangTidyContext *Context); -+ -+ /// \brief Override this to register ``PPCallbacks`` in the preprocessor. -+ /// -+ /// This should be used for clang-tidy checks that analyze preprocessor- -+ /// dependent properties, e.g. include directives and macro definitions. -+ /// -+ /// There are two Preprocessors to choose from that differ in how they handle -+ /// modular #includes: -+ /// - PP is the real Preprocessor. It doesn't walk into modular #includes and -+ /// thus doesn't generate PPCallbacks for their contents. -+ /// - ModuleExpanderPP preprocesses the whole translation unit in the -+ /// non-modular mode, which allows it to generate PPCallbacks not only for -+ /// the main file and textual headers, but also for all transitively -+ /// included modular headers when the analysis runs with modules enabled. -+ /// When modules are not enabled ModuleExpanderPP just points to the real -+ /// preprocessor. -+ virtual void registerPPCallbacks(const SourceManager &SM, Preprocessor *PP, -+ Preprocessor *ModuleExpanderPP) {} -+ -+ /// \brief Override this to register AST matchers with \p Finder. -+ /// -+ /// This should be used by clang-tidy checks that analyze code properties that -+ /// dependent on AST knowledge. -+ /// -+ /// You can register as many matchers as necessary with \p Finder. Usually, -+ /// "this" will be used as callback, but you can also specify other callback -+ /// classes. Thereby, different matchers can trigger different callbacks. -+ /// -+ /// If you need to merge information between the different matchers, you can -+ /// store these as members of the derived class. However, note that all -+ /// matches occur in the order of the AST traversal. -+ virtual void registerMatchers(ast_matchers::MatchFinder *Finder) {} -+ -+ /// \brief ``ClangTidyChecks`` that register ASTMatchers should do the actual -+ /// work in here. -+ virtual void check(const ast_matchers::MatchFinder::MatchResult &Result) {} -+ -+ /// \brief Add a diagnostic with the check's name. -+ DiagnosticBuilder diag(SourceLocation Loc, StringRef Description, -+ DiagnosticIDs::Level Level = DiagnosticIDs::Warning); -+ -+ /// \brief Should store all options supported by this check with their -+ /// current values or default values for options that haven't been overridden. -+ /// -+ /// The check should use ``Options.store()`` to store each option it supports -+ /// whether it has the default value or it has been overridden. -+ virtual void storeOptions(ClangTidyOptions::OptionMap &Options) {} -+ -+ /// \brief Provides access to the ``ClangTidyCheck`` options via check-local -+ /// names. -+ /// -+ /// Methods of this class prepend ``CheckName + "."`` to translate check-local -+ /// option names to global option names. -+ class OptionsView { -+ public: -+ /// \brief Initializes the instance using \p CheckName + "." as a prefix. -+ OptionsView(StringRef CheckName, -+ const ClangTidyOptions::OptionMap &CheckOptions); -+ -+ /// \brief Read a named option from the ``Context``. -+ /// -+ /// Reads the option with the check-local name \p LocalName from the -+ /// ``CheckOptions``. If the corresponding key is not present, returns -+ /// \p Default. -+ std::string get(StringRef LocalName, StringRef Default) const; -+ -+ /// \brief Read a named option from the ``Context``. -+ /// -+ /// 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 Default. -+ std::string getLocalOrGlobal(StringRef LocalName, StringRef Default) const; -+ -+ /// \brief 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 not present, returns -+ /// \p Default. -+ template -+ typename std::enable_if::value, T>::type -+ get(StringRef LocalName, T Default) const { -+ std::string Value = get(LocalName, ""); -+ T Result = Default; -+ if (!Value.empty()) -+ StringRef(Value).getAsInteger(10, Result); -+ return Result; -+ } -+ -+ /// \brief 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, returns Default. -+ template -+ typename std::enable_if::value, T>::type -+ getLocalOrGlobal(StringRef LocalName, T Default) const { -+ std::string Value = getLocalOrGlobal(LocalName, ""); -+ T Result = Default; -+ if (!Value.empty()) -+ StringRef(Value).getAsInteger(10, Result); -+ return Result; -+ } -+ -+ /// \brief Stores an option with the check-local name \p LocalName with -+ /// string value \p Value to \p Options. -+ void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, -+ StringRef Value) const; -+ -+ /// \brief Stores an option with the check-local name \p LocalName with -+ /// ``int64_t`` value \p Value to \p Options. -+ void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, -+ int64_t Value) const; -+ -+ private: -+ std::string NamePrefix; -+ const ClangTidyOptions::OptionMap &CheckOptions; -+ }; -+ -+private: -+ void run(const ast_matchers::MatchFinder::MatchResult &Result) override; -+ StringRef getID() const override { return CheckName; } -+ std::string CheckName; -+ ClangTidyContext *Context; -+ -+protected: -+ OptionsView Options; -+ /// \brief Returns the main file name of the current translation unit. -+ StringRef getCurrentMainFile() const { return Context->getCurrentFile(); } -+ /// \brief Returns the language options from the context. -+ const LangOptions &getLangOpts() const { return Context->getLangOpts(); } -+}; -+ -+} // namespace tidy -+} // namespace clang -+ -+#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYCHECK_H -diff --git a/ClangTidyDiagnosticConsumer.h b/ClangTidyDiagnosticConsumer.h -index ae25013..01a3526 100644 ---- a/ClangTidyDiagnosticConsumer.h -+++ b/ClangTidyDiagnosticConsumer.h -@@ -1,9 +1,8 @@ - //===--- ClangTidyDiagnosticConsumer.h - clang-tidy -------------*- C++ -*-===// - // --// The LLVM Compiler Infrastructure --// --// This file is distributed under the University of Illinois Open Source --// License. See LICENSE.TXT for details. -+// 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 - // - //===----------------------------------------------------------------------===// - -@@ -102,6 +101,12 @@ public: - /// \brief Initializes \c ClangTidyContext instance. - ClangTidyContext(std::unique_ptr OptionsProvider, - bool AllowEnablingAnalyzerAlphaCheckers = 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. -+ void setDiagnosticsEngine(DiagnosticsEngine *DiagEngine) { -+ this->DiagEngine = DiagEngine; -+ } - - ~ClangTidyContext(); - -@@ -133,7 +138,7 @@ public: - - /// \brief Returns the name of the clang-tidy check which produced this - /// diagnostic ID. -- StringRef getCheckName(unsigned DiagnosticID) const; -+ std::string getCheckName(unsigned DiagnosticID) const; - - /// \brief Returns \c true if the check is enabled for the \c CurrentFile. - /// -@@ -160,12 +165,6 @@ public: - /// counters. - const ClangTidyStats &getStats() const { return Stats; } - -- /// \brief Returns all collected errors. -- ArrayRef getErrors() const { return Errors; } -- -- /// \brief Clears collected errors. -- void clearErrors() { Errors.clear(); } -- - /// \brief Control profile collection in clang-tidy. - void setEnableProfiling(bool Profile); - bool getEnableProfiling() const { return Profile; } -@@ -191,19 +190,19 @@ public: - return AllowEnablingAnalyzerAlphaCheckers; - } - -+ using DiagLevelAndFormatString = std::pair; -+ DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID, -+ SourceLocation Loc) { -+ return DiagLevelAndFormatString( -+ static_cast( -+ DiagEngine->getDiagnosticLevel(DiagnosticID, Loc)), -+ DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID)); -+ } -+ - private: -- // Calls setDiagnosticsEngine() and storeError(). -+ // Writes to Stats. - friend class ClangTidyDiagnosticConsumer; -- friend class ClangTidyPluginAction; -- -- /// \brief Sets the \c DiagnosticsEngine so that Diagnostics can be generated -- /// correctly. -- void setDiagnosticsEngine(DiagnosticsEngine *Engine); - -- /// \brief Store an \p Error. -- void storeError(const ClangTidyError &Error); -- -- std::vector Errors; - DiagnosticsEngine *DiagEngine; - std::unique_ptr OptionsProvider; - -@@ -227,6 +226,23 @@ private: - bool AllowEnablingAnalyzerAlphaCheckers; - }; - -+/// Check whether a given diagnostic should be suppressed due to the presence -+/// of a "NOLINT" suppression comment. -+/// This is exposed so that other tools that present clang-tidy diagnostics -+/// (such as clangd) can respect the same suppression rules as clang-tidy. -+/// This does not handle suppression of notes following a suppressed diagnostic; -+/// that is left to the caller is it requires maintaining state in between calls -+/// to this function. -+/// The `CheckMacroExpansion` parameter determines whether the function should -+/// handle the case where the diagnostic is inside a macro expansion. A degree -+/// of control over this is needed because handling this case can require -+/// examining source files other than the one in which the diagnostic is -+/// located, and in some use cases we cannot rely on such other files being -+/// mapped in the SourceMapper. -+bool ShouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel, -+ const Diagnostic &Info, ClangTidyContext &Context, -+ bool CheckMacroExpansion = true); -+ - /// \brief A diagnostic consumer that turns each \c Diagnostic into a - /// \c SourceManager-independent \c ClangTidyError. - // -@@ -235,6 +251,7 @@ private: - class ClangTidyDiagnosticConsumer : public DiagnosticConsumer { - public: - ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx, -+ DiagnosticsEngine *ExternalDiagEngine = nullptr, - bool RemoveIncompatibleErrors = true); - - // FIXME: The concept of converting between FixItHints and Replacements is -@@ -243,13 +260,12 @@ public: - void HandleDiagnostic(DiagnosticsEngine::Level DiagLevel, - const Diagnostic &Info) override; - -- /// \brief Flushes the internal diagnostics buffer to the ClangTidyContext. -- void finish() override; -+ // Retrieve the diagnostics that were captured. -+ std::vector take(); - - private: - void finalizeLastError(); -- -- void removeIncompatibleErrors(SmallVectorImpl &Errors) const; -+ void removeIncompatibleErrors(); - - /// \brief Returns the \c HeaderFilter constructed for the options set in the - /// context. -@@ -257,13 +273,15 @@ private: - - /// \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter - /// according to the diagnostic \p Location. -- void checkFilters(SourceLocation Location); -+ void checkFilters(SourceLocation Location, const SourceManager &Sources); - bool passesLineFilter(StringRef FileName, unsigned LineNumber) const; - -+ void forwardDiagnostic(const Diagnostic &Info); -+ - ClangTidyContext &Context; -+ DiagnosticsEngine *ExternalDiagEngine; - bool RemoveIncompatibleErrors; -- std::unique_ptr Diags; -- SmallVector Errors; -+ std::vector Errors; - std::unique_ptr HeaderFilter; - bool LastErrorRelatesToUserCode; - bool LastErrorPassesLineFilter; -diff --git a/ClangTidyModule.h b/ClangTidyModule.h -index 4721636..378f109 100644 ---- a/ClangTidyModule.h -+++ b/ClangTidyModule.h -@@ -1,9 +1,8 @@ - //===--- ClangTidyModule.h - clang-tidy -------------------------*- C++ -*-===// - // --// The LLVM Compiler Infrastructure --// --// This file is distributed under the University of Illinois Open Source --// License. See LICENSE.TXT for details. -+// 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 - // - //===----------------------------------------------------------------------===// - -diff --git a/ClangTidyModuleRegistry.h b/ClangTidyModuleRegistry.h -index dc44d14..891671a 100644 ---- a/ClangTidyModuleRegistry.h -+++ b/ClangTidyModuleRegistry.h -@@ -1,9 +1,8 @@ - //===--- ClangTidyModuleRegistry.h - clang-tidy -----------------*- C++ -*-===// - // --// The LLVM Compiler Infrastructure --// --// This file is distributed under the University of Illinois Open Source --// License. See LICENSE.TXT for details. -+// 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 - // - //===----------------------------------------------------------------------===// - -diff --git a/ClangTidyOptions.h b/ClangTidyOptions.h -index b2a4ce4..87c7cf5 100644 ---- a/ClangTidyOptions.h -+++ b/ClangTidyOptions.h -@@ -1,21 +1,20 @@ - //===--- ClangTidyOptions.h - clang-tidy ------------------------*- C++ -*-===// - // --// The LLVM Compiler Infrastructure --// --// This file is distributed under the University of Illinois Open Source --// License. See LICENSE.TXT for details. -+// 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_CLANGTIDYOPTIONS_H - #define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYOPTIONS_H - -+#include "llvm/ADT/IntrusiveRefCntPtr.h" - #include "llvm/ADT/Optional.h" - #include "llvm/ADT/StringMap.h" - #include "llvm/ADT/StringRef.h" --#include "llvm/ADT/IntrusiveRefCntPtr.h" - #include "llvm/Support/ErrorOr.h" --#include "clang/Basic/VirtualFileSystem.h" -+#include "llvm/Support/VirtualFileSystem.h" - #include - #include - #include -@@ -218,10 +217,11 @@ public: - /// - /// If any of the \param OverrideOptions fields are set, they will override - /// whatever options are read from the configuration file. -- FileOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions, -- const ClangTidyOptions &DefaultOptions, -- const ClangTidyOptions &OverrideOptions, -- llvm::IntrusiveRefCntPtr FS = nullptr); -+ FileOptionsProvider( -+ const ClangTidyGlobalOptions &GlobalOptions, -+ const ClangTidyOptions &DefaultOptions, -+ const ClangTidyOptions &OverrideOptions, -+ llvm::IntrusiveRefCntPtr FS = nullptr); - - /// \brief Initializes the \c FileOptionsProvider instance with a custom set - /// of configuration file handlers. -@@ -255,7 +255,7 @@ protected: - llvm::StringMap CachedOptions; - ClangTidyOptions OverrideOptions; - ConfigFileHandlers ConfigHandlers; -- llvm::IntrusiveRefCntPtr FS; -+ llvm::IntrusiveRefCntPtr FS; - }; - - /// \brief Parses LineFilter from JSON and stores it to the \p Options. -diff --git a/ClangTidyProfiling.h b/ClangTidyProfiling.h -index 9d86b8e..a266e38 100644 ---- a/ClangTidyProfiling.h -+++ b/ClangTidyProfiling.h -@@ -1,9 +1,8 @@ - //===--- ClangTidyProfiling.h - clang-tidy ----------------------*- C++ -*-===// - // --// The LLVM Compiler Infrastructure --// --// This file is distributed under the University of Illinois Open Source --// License. See LICENSE.TXT for details. -+// 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 - // - //===----------------------------------------------------------------------===// - -diff --git a/tool/ClangTidyMain.cpp b/tool/ClangTidyMain.cpp -index f36c4ec..329a1e9 100644 ---- a/tool/ClangTidyMain.cpp -+++ b/tool/ClangTidyMain.cpp -@@ -326,12 +326,41 @@ getVfsOverlayFromFile(const std::string &OverlayFile) { - return OverlayFS; - } - -+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; -+} -+ - static int clangTidyMain(int argc, const char **argv) { - CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory, - cl::ZeroOrMore); -- llvm::IntrusiveRefCntPtr BaseFS( -- VfsOverlay.empty() ? vfs::getRealFileSystem() -- : getVfsOverlayFromFile(VfsOverlay)); -+ llvm::IntrusiveRefCntPtr BaseFS( -+ new vfs::OverlayFileSystem(vfs::getRealFileSystem())); -+ -+ if (!VfsOverlay.empty()) { -+ IntrusiveRefCntPtr VfsFromFile = -+ getVfsFromFile(VfsOverlay, BaseFS); -+ if (!VfsFromFile) -+ return 1; -+ BaseFS->pushOverlay(VfsFromFile); -+ } - if (!BaseFS) - return 1; - -@@ -421,9 +450,9 @@ static int clangTidyMain(int argc, const char **argv) { - - ClangTidyContext Context(std::move(OwningOptionsProvider), - AllowEnablingAnalyzerAlphaCheckers); -- runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS, -- EnableCheckProfile, ProfilePrefix); -- ArrayRef Errors = Context.getErrors(); -+ std::vector Errors = -+ runClangTidy(Context, OptionsParser.getCompilations(), PathList, BaseFS, -+ EnableCheckProfile, ProfilePrefix); - bool FoundErrors = llvm::find_if(Errors, [](const ClangTidyError &E) { - return E.DiagLevel == ClangTidyError::Error; - }) != Errors.end(); -@@ -433,7 +462,7 @@ static int clangTidyMain(int argc, const char **argv) { - unsigned WErrorCount = 0; - - // -fix-errors implies -fix. -- handleErrors(Context, (FixErrors || Fix) && !DisableFixes, WErrorCount, -+ handleErrors(Errors, Context, (FixErrors || Fix) && !DisableFixes, WErrorCount, - BaseFS); - - if (!ExportFixes.empty() && !Errors.empty()) { -@@ -569,10 +598,15 @@ extern volatile int ZirconModuleAnchorSource; - static int LLVM_ATTRIBUTE_UNUSED ZirconModuleAnchorDestination = - ZirconModuleAnchorSource; - --// This anchor is used to force the linker to link the CMS. --extern volatile int CMSModuleAnchorSource; --static int LLVM_ATTRIBUTE_UNUSED CMSAnchorDestination = -- CMSModuleAnchorSource; -+// This anchor is used to force the linker to link the AliceO2Module. -+extern volatile int AliceO2ModuleAnchorSource; -+static int LLVM_ATTRIBUTE_UNUSED AliceO2ModuleAnchorDestination = -+ AliceO2ModuleAnchorSource; -+ -+// This anchor is used to force the linker to link the ReportingModule. -+extern volatile int ReportingModuleAnchorSource; -+static int LLVM_ATTRIBUTE_UNUSED ReportingModuleAnchorDestination = -+ ReportingModuleAnchorSource; - - } // namespace tidy - } // namespace clang From 651f393229955bbf2820ae644132ae5886e24974 Mon Sep 17 00:00:00 2001 From: Shahzad Malik Muzaffar Date: Fri, 10 Jan 2020 14:58:12 +0100 Subject: [PATCH 6/8] patch llvmlite to build against llvm9 --- pip/llvmlite.file | 2 ++ pip/requirements.txt | 3 ++- py2-llvmlite-llvm9.patch | 12 ++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) create mode 100644 py2-llvmlite-llvm9.patch diff --git a/pip/llvmlite.file b/pip/llvmlite.file index bca656fce1e..673eb26e96f 100644 --- a/pip/llvmlite.file +++ b/pip/llvmlite.file @@ -1,4 +1,6 @@ Requires: llvm py2-wheel py2-enum34 Patch0: py2-llvmlite-fpic-flag +Patch1: py2-llvmlite-llvm9 +%define source0 git+https://github.com/numba/llvmlite?obj=master/6435ea21f73dbf909a0418ed16375361e40d9892&export=llvmlite-%{realversion}&output=/source.tar.gz %define PipPreBuild export LLVM_CONFIG=${LLVM_ROOT}/bin/llvm-config diff --git a/pip/requirements.txt b/pip/requirements.txt index d6a4f3ae048..e73f6173506 100644 --- a/pip/requirements.txt +++ b/pip/requirements.txt @@ -112,7 +112,8 @@ keras-preprocessing==1.1.0 kiwisolver==1.1.0 lazy-object-proxy==1.4.3 lizard==1.16.6 -llvmlite==0.30.0 +#NO_AUTO_UPDATE: Source is defined in llvmlite.file, changing version here is not going to get new sources +llvmlite==0.32.0x lxml==4.4.1 lz4==2.2.1 Mako==1.1.0 diff --git a/py2-llvmlite-llvm9.patch b/py2-llvmlite-llvm9.patch new file mode 100644 index 00000000000..641b567a162 --- /dev/null +++ b/py2-llvmlite-llvm9.patch @@ -0,0 +1,12 @@ +diff -Naur a/ffi/build.py b/ffi/build.py +--- a/ffi/build.py 2020-01-10 14:51:38.000000000 +0100 ++++ b/ffi/build.py 2020-01-10 14:45:27.059843040 +0100 +@@ -110,7 +110,7 @@ + out = out.decode('latin1') + print(out) + if not (out.startswith('8.0.') or out.startswith('7.0.') +- or out.startswith('7.1.')): ++ or out.startswith('7.1.') or out.startswith('9.0.')): + msg = ( + "Building llvmlite requires LLVM 7.0.x, 7.1.x or 8.0.x Be sure to " + "set LLVM_CONFIG to the right executable path.\n" From bac62315916f9cab81e11e072cf99e220da53de1 Mon Sep 17 00:00:00 2001 From: Shahzad Malik Muzaffar Date: Tue, 28 Jan 2020 15:12:00 +0100 Subject: [PATCH 7/8] update llvm-cxxcompiler toolfile --- llvm-gcc-toolfile.spec | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/llvm-gcc-toolfile.spec b/llvm-gcc-toolfile.spec index 71ead2cfb9e..2003917f717 100644 --- a/llvm-gcc-toolfile.spec +++ b/llvm-gcc-toolfile.spec @@ -1,4 +1,4 @@ -### RPM cms llvm-gcc-toolfile 13.0 +### RPM cms llvm-gcc-toolfile 14.0 Requires: llvm BuildRequires: python @@ -55,6 +55,9 @@ cat << \EOF_TOOLFILE >%i/etc/scram.d/llvm-cxxcompiler.xml + + + @@ -64,6 +67,7 @@ cat << \EOF_TOOLFILE >%i/etc/scram.d/llvm-cxxcompiler.xml + From 8295f2a6c2d4d357615f2b64540e70d8dc7fc9be Mon Sep 17 00:00:00 2001 From: Malik Shahzad Muzaffar Date: Fri, 31 Jan 2020 09:45:27 +0100 Subject: [PATCH 8/8] Update llvm-gcc-toolfile.spec --- llvm-gcc-toolfile.spec | 2 -- 1 file changed, 2 deletions(-) diff --git a/llvm-gcc-toolfile.spec b/llvm-gcc-toolfile.spec index 2003917f717..12f05b8f290 100644 --- a/llvm-gcc-toolfile.spec +++ b/llvm-gcc-toolfile.spec @@ -55,8 +55,6 @@ cat << \EOF_TOOLFILE >%i/etc/scram.d/llvm-cxxcompiler.xml - -