Skip to content

Commit

Permalink
Bump to llvm 10.0
Browse files Browse the repository at this point in the history
  • Loading branch information
anerokhi authored and sawenzel committed Aug 24, 2020
1 parent acafa24 commit b9e9684
Show file tree
Hide file tree
Showing 6 changed files with 235 additions and 200 deletions.
74 changes: 26 additions & 48 deletions ClangTidyDiagnosticConsumer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
#include "clang/Tooling/Refactoring.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Regex.h"
#include "llvm/Support/Timer.h"

namespace clang {
Expand All @@ -33,7 +32,7 @@ class CompilationDatabase;

namespace tidy {

/// \brief A detected error complete with information to display diagnostic and
/// A detected error complete with information to display diagnostic and
/// automatic fix.
///
/// This is used as an intermediate format to transport Diagnostics without a
Expand All @@ -47,28 +46,7 @@ struct ClangTidyError : tooling::Diagnostic {
bool IsWarningAsError;
};

/// \brief Read-only set of strings represented as a list of positive and
/// negative globs. Positive globs add all matched strings to the set, negative
/// globs remove them in the order of appearance in the list.
class GlobList {
public:
/// \brief \p GlobList is a comma-separated list of globs (only '*'
/// metacharacter is supported) with optional '-' prefix to denote exclusion.
GlobList(StringRef Globs);

/// \brief Returns \c true if the pattern matches \p S. The result is the last
/// matching glob's Positive flag.
bool contains(StringRef S) { return contains(S, false); }

private:
bool contains(StringRef S, bool Contains);

bool Positive;
llvm::Regex Regex;
std::unique_ptr<GlobList> NextGlob;
};

/// \brief Contains displayed and ignored diagnostic counters for a ClangTidy
/// Contains displayed and ignored diagnostic counters for a ClangTidy
/// run.
struct ClangTidyStats {
ClangTidyStats()
Expand All @@ -87,7 +65,7 @@ struct ClangTidyStats {
}
};

/// \brief Every \c ClangTidyCheck reports errors through a \c DiagnosticsEngine
/// Every \c ClangTidyCheck reports errors through a \c DiagnosticsEngine
/// provided by this context.
///
/// A \c ClangTidyCheck always has access to the active context to report
Expand All @@ -98,7 +76,7 @@ struct ClangTidyStats {
/// \endcode
class ClangTidyContext {
public:
/// \brief Initializes \c ClangTidyContext instance.
/// Initializes \c ClangTidyContext instance.
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
bool AllowEnablingAnalyzerAlphaCheckers = false);
/// Sets the DiagnosticsEngine that diag() will emit diagnostics to.
Expand All @@ -110,7 +88,7 @@ class ClangTidyContext {

~ClangTidyContext();

/// \brief Report any errors detected using this method.
/// Report any errors detected using this method.
///
/// This is still under heavy development and will likely change towards using
/// tablegen'd diagnostic IDs.
Expand All @@ -119,72 +97,72 @@ class ClangTidyContext {
StringRef Message,
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);

/// \brief Sets the \c SourceManager of the used \c DiagnosticsEngine.
/// Sets the \c SourceManager of the used \c DiagnosticsEngine.
///
/// This is called from the \c ClangTidyCheck base class.
void setSourceManager(SourceManager *SourceMgr);

/// \brief Should be called when starting to process new translation unit.
/// Should be called when starting to process new translation unit.
void setCurrentFile(StringRef File);

/// \brief Returns the main file name of the current translation unit.
/// Returns the main file name of the current translation unit.
StringRef getCurrentFile() const { return CurrentFile; }

/// \brief Sets ASTContext for the current translation unit.
/// Sets ASTContext for the current translation unit.
void setASTContext(ASTContext *Context);

/// \brief Gets the language options from the AST context.
/// Gets the language options from the AST context.
const LangOptions &getLangOpts() const { return LangOpts; }

/// \brief Returns the name of the clang-tidy check which produced this
/// Returns the name of the clang-tidy check which produced this
/// diagnostic ID.
std::string getCheckName(unsigned DiagnosticID) const;

/// \brief Returns \c true if the check is enabled for the \c CurrentFile.
/// Returns \c true if the check is enabled for the \c CurrentFile.
///
/// The \c CurrentFile can be changed using \c setCurrentFile.
bool isCheckEnabled(StringRef CheckName) const;

/// \brief Returns \c true if the check should be upgraded to error for the
/// Returns \c true if the check should be upgraded to error for the
/// \c CurrentFile.
bool treatAsError(StringRef CheckName) const;

/// \brief Returns global options.
/// Returns global options.
const ClangTidyGlobalOptions &getGlobalOptions() const;

/// \brief Returns options for \c CurrentFile.
/// Returns options for \c CurrentFile.
///
/// The \c CurrentFile can be changed using \c setCurrentFile.
const ClangTidyOptions &getOptions() const;

/// \brief Returns options for \c File. Does not change or depend on
/// Returns options for \c File. Does not change or depend on
/// \c CurrentFile.
ClangTidyOptions getOptionsForFile(StringRef File) const;

/// \brief Returns \c ClangTidyStats containing issued and ignored diagnostic
/// Returns \c ClangTidyStats containing issued and ignored diagnostic
/// counters.
const ClangTidyStats &getStats() const { return Stats; }

/// \brief Control profile collection in clang-tidy.
/// Control profile collection in clang-tidy.
void setEnableProfiling(bool Profile);
bool getEnableProfiling() const { return Profile; }

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

/// \brief Should be called when starting to process new translation unit.
/// Should be called when starting to process new translation unit.
void setCurrentBuildDirectory(StringRef BuildDirectory) {
CurrentBuildDirectory = BuildDirectory;
}

/// \brief Returns build directory of the current translation unit.
/// Returns build directory of the current translation unit.
const std::string &getCurrentBuildDirectory() {
return CurrentBuildDirectory;
}

/// \brief If the experimental alpha checkers from the static analyzer can be
/// If the experimental alpha checkers from the static analyzer can be
/// enabled.
bool canEnableAnalyzerAlphaCheckers() const {
return AllowEnablingAnalyzerAlphaCheckers;
Expand Down Expand Up @@ -239,11 +217,11 @@ class ClangTidyContext {
/// 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,
bool shouldSuppressDiagnostic(DiagnosticsEngine::Level DiagLevel,
const Diagnostic &Info, ClangTidyContext &Context,
bool CheckMacroExpansion = true);

/// \brief A diagnostic consumer that turns each \c Diagnostic into a
/// A diagnostic consumer that turns each \c Diagnostic into a
/// \c SourceManager-independent \c ClangTidyError.
//
// FIXME: If we move away from unit-tests, this can be moved to a private
Expand All @@ -267,11 +245,11 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
void finalizeLastError();
void removeIncompatibleErrors();

/// \brief Returns the \c HeaderFilter constructed for the options set in the
/// Returns the \c HeaderFilter constructed for the options set in the
/// context.
llvm::Regex *getHeaderFilter();

/// \brief Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
/// Updates \c LastErrorRelatesToUserCode and LastErrorPassesLineFilter
/// according to the diagnostic \p Location.
void checkFilters(SourceLocation Location, const SourceManager &Sources);
bool passesLineFilter(StringRef FileName, unsigned LineNumber) const;
Expand Down
129 changes: 129 additions & 0 deletions ClangTidyForceLinker.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
//===- ClangTidyForceLinker.h - clang-tidy --------------------------------===//
//
// 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_CLANGTIDYFORCELINKER_H
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYFORCELINKER_H

#include "clang/Config/config.h"
#include "llvm/Support/Compiler.h"

namespace clang {
namespace tidy {

// This anchor is used to force the linker to link the CERTModule.
extern volatile int CERTModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED CERTModuleAnchorDestination =
CERTModuleAnchorSource;

// This anchor is used to force the linker to link the AbseilModule.
extern volatile int AbseilModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED AbseilModuleAnchorDestination =
AbseilModuleAnchorSource;

// This anchor is used to force the linker to link the BoostModule.
extern volatile int BoostModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED BoostModuleAnchorDestination =
BoostModuleAnchorSource;

// This anchor is used to force the linker to link the BugproneModule.
extern volatile int BugproneModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED BugproneModuleAnchorDestination =
BugproneModuleAnchorSource;

// This anchor is used to force the linker to link the LinuxKernelModule.
extern volatile int LinuxKernelModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED LinuxKernelModuleAnchorDestination =
LinuxKernelModuleAnchorSource;

// This anchor is used to force the linker to link the LLVMModule.
extern volatile int LLVMModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED LLVMModuleAnchorDestination =
LLVMModuleAnchorSource;

// This anchor is used to force the linker to link the CppCoreGuidelinesModule.
extern volatile int CppCoreGuidelinesModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED CppCoreGuidelinesModuleAnchorDestination =
CppCoreGuidelinesModuleAnchorSource;

// This anchor is used to force the linker to link the DarwinModule.
extern volatile int DarwinModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED DarwinModuleAnchorDestination =
DarwinModuleAnchorSource;

// This anchor is used to force the linker to link the FuchsiaModule.
extern volatile int FuchsiaModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED FuchsiaModuleAnchorDestination =
FuchsiaModuleAnchorSource;

// This anchor is used to force the linker to link the GoogleModule.
extern volatile int GoogleModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED GoogleModuleAnchorDestination =
GoogleModuleAnchorSource;

// This anchor is used to force the linker to link the AndroidModule.
extern volatile int AndroidModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED AndroidModuleAnchorDestination =
AndroidModuleAnchorSource;

// This anchor is used to force the linker to link the MiscModule.
extern volatile int MiscModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MiscModuleAnchorDestination =
MiscModuleAnchorSource;

// This anchor is used to force the linker to link the ModernizeModule.
extern volatile int ModernizeModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ModernizeModuleAnchorDestination =
ModernizeModuleAnchorSource;

#if CLANG_ENABLE_STATIC_ANALYZER && \
!defined(CLANG_TIDY_DISABLE_STATIC_ANALYZER_CHECKS)
// This anchor is used to force the linker to link the MPIModule.
extern volatile int MPIModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED MPIModuleAnchorDestination =
MPIModuleAnchorSource;
#endif

// This anchor is used to force the linker to link the OpenMPModule.
extern volatile int OpenMPModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED OpenMPModuleAnchorDestination =
OpenMPModuleAnchorSource;

// This anchor is used to force the linker to link the PerformanceModule.
extern volatile int PerformanceModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED PerformanceModuleAnchorDestination =
PerformanceModuleAnchorSource;

// This anchor is used to force the linker to link the PortabilityModule.
extern volatile int PortabilityModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED PortabilityModuleAnchorDestination =
PortabilityModuleAnchorSource;

// This anchor is used to force the linker to link the ReadabilityModule.
extern volatile int ReadabilityModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ReadabilityModuleAnchorDestination =
ReadabilityModuleAnchorSource;

// This anchor is used to force the linker to link the ObjCModule.
extern volatile int ObjCModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ObjCModuleAnchorDestination =
ObjCModuleAnchorSource;

// This anchor is used to force the linker to link the HICPPModule.
extern volatile int HICPPModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED HICPPModuleAnchorDestination =
HICPPModuleAnchorSource;

// This anchor is used to force the linker to link the ZirconModule.
extern volatile int ZirconModuleAnchorSource;
static int LLVM_ATTRIBUTE_UNUSED ZirconModuleAnchorDestination =
ZirconModuleAnchorSource;

} // namespace tidy
} // namespace clang

#endif
29 changes: 13 additions & 16 deletions ClangTidyModule.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
#include "llvm/ADT/StringRef.h"
#include <functional>
#include <map>
#include <memory>
#include <string>
#include <utility>

namespace clang {
namespace tidy {

/// \brief A collection of \c ClangTidyCheckFactory instances.
/// A collection of \c ClangTidyCheckFactory instances.
///
/// All clang-tidy modules register their check factories with an instance of
/// this object.
class ClangTidyCheckFactories {
public:
typedef std::function<ClangTidyCheck *(StringRef Name,
ClangTidyContext *Context)>
CheckFactory;
using CheckFactory = std::function<std::unique_ptr<ClangTidyCheck>(
StringRef Name, ClangTidyContext *Context)>;

/// \brief Registers check \p Factory with name \p Name.
/// Registers check \p Factory with name \p Name.
///
/// For all checks that have default constructors, use \c registerCheck.
void registerCheckFactory(StringRef Name, CheckFactory Factory);

/// \brief Registers the \c CheckType with the name \p Name.
/// Registers the \c CheckType with the name \p Name.
///
/// This method should be used for all \c ClangTidyChecks that don't require
/// constructor parameters.
Expand All @@ -58,16 +58,13 @@ class ClangTidyCheckFactories {
template <typename CheckType> void registerCheck(StringRef CheckName) {
registerCheckFactory(CheckName,
[](StringRef Name, ClangTidyContext *Context) {
return new CheckType(Name, Context);
return std::make_unique<CheckType>(Name, Context);
});
}

/// \brief Create instances of all checks matching \p CheckRegexString and
/// store them in \p Checks.
///
/// The caller takes ownership of the return \c ClangTidyChecks.
void createChecks(ClangTidyContext *Context,
std::vector<std::unique_ptr<ClangTidyCheck>> &Checks);
/// Create instances of checks that are enabled.
std::vector<std::unique_ptr<ClangTidyCheck>>
createChecks(ClangTidyContext *Context);

typedef std::map<std::string, CheckFactory> FactoryMap;
FactoryMap::const_iterator begin() const { return Factories.begin(); }
Expand All @@ -78,17 +75,17 @@ class ClangTidyCheckFactories {
FactoryMap Factories;
};

/// \brief A clang-tidy module groups a number of \c ClangTidyChecks and gives
/// A clang-tidy module groups a number of \c ClangTidyChecks and gives
/// them a prefixed name.
class ClangTidyModule {
public:
virtual ~ClangTidyModule() {}

/// \brief Implement this function in order to register all \c CheckFactories
/// Implement this function in order to register all \c CheckFactories
/// belonging to this module.
virtual void addCheckFactories(ClangTidyCheckFactories &CheckFactories) = 0;

/// \brief Gets default options for checks defined in this module.
/// Gets default options for checks defined in this module.
virtual ClangTidyOptions getModuleOptions();
};

Expand Down
Loading

0 comments on commit b9e9684

Please sign in to comment.