Skip to content

Commit 5aace18

Browse files
committed
Bump to llvm 7.0
This is needed in order to work with llvm 7.0 and provides C++17 support for the checker. (tmp disabling a test)
1 parent 22d5ac0 commit 5aace18

File tree

9 files changed

+332
-192
lines changed

9 files changed

+332
-192
lines changed

ClangTidy.h

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,23 @@ class OptionsView {
7373
return Result;
7474
}
7575

76+
/// \brief Read a named option from the ``Context`` and parse it as an
77+
/// integral type ``T``.
78+
///
79+
/// Reads the option with the check-local name \p LocalName from local or
80+
/// global ``CheckOptions``. Gets local option first. If local is not present,
81+
/// falls back to get global option. If global option is not present either,
82+
/// returns Default.
83+
template <typename T>
84+
typename std::enable_if<std::is_integral<T>::value, T>::type
85+
getLocalOrGlobal(StringRef LocalName, T Default) const {
86+
std::string Value = getLocalOrGlobal(LocalName, "");
87+
T Result = Default;
88+
if (!Value.empty())
89+
StringRef(Value).getAsInteger(10, Result);
90+
return Result;
91+
}
92+
7693
/// \brief Stores an option with the check-local name \p LocalName with string
7794
/// value \p Value to \p Options.
7895
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
@@ -187,47 +204,53 @@ class ClangTidyASTConsumerFactory {
187204
ClangTidyOptions::OptionMap getCheckOptions();
188205

189206
private:
190-
typedef std::vector<std::pair<std::string, bool>> CheckersList;
191-
CheckersList getCheckersControlList(GlobList &Filter);
192-
193207
ClangTidyContext &Context;
194208
std::unique_ptr<ClangTidyCheckFactories> CheckFactories;
195209
};
196210

197211
/// \brief Fills the list of check names that are enabled when the provided
198212
/// filters are applied.
199-
std::vector<std::string> getCheckNames(const ClangTidyOptions &Options);
213+
std::vector<std::string> getCheckNames(const ClangTidyOptions &Options,
214+
bool AllowEnablingAnalyzerAlphaCheckers);
200215

201216
/// \brief Returns the effective check-specific options.
202217
///
203218
/// The method configures ClangTidy with the specified \p Options and collects
204219
/// effective options from all created checks. The returned set of options
205220
/// includes default check-specific options for all keys not overridden by \p
206221
/// Options.
207-
ClangTidyOptions::OptionMap getCheckOptions(const ClangTidyOptions &Options);
222+
ClangTidyOptions::OptionMap
223+
getCheckOptions(const ClangTidyOptions &Options,
224+
bool AllowEnablingAnalyzerAlphaCheckers);
208225

209226
/// \brief Run a set of clang-tidy checks on a set of files.
210227
///
211-
/// \param Profile if provided, it enables check profile collection in
212-
/// MatchFinder, and will contain the result of the profile.
213-
ClangTidyStats
214-
runClangTidy(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
215-
const tooling::CompilationDatabase &Compilations,
216-
ArrayRef<std::string> InputFiles,
217-
std::vector<ClangTidyError> *Errors,
218-
ProfileData *Profile = nullptr);
228+
/// \param EnableCheckProfile If provided, it enables check profile collection
229+
/// in MatchFinder, and will contain the result of the profile.
230+
/// \param StoreCheckProfile If provided, and EnableCheckProfile is true,
231+
/// the profile will not be output to stderr, but will instead be stored
232+
/// as a JSON file in the specified directory.
233+
void runClangTidy(clang::tidy::ClangTidyContext &Context,
234+
const tooling::CompilationDatabase &Compilations,
235+
ArrayRef<std::string> InputFiles,
236+
llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS,
237+
bool EnableCheckProfile = false,
238+
llvm::StringRef StoreCheckProfile = StringRef());
219239

220240
// FIXME: This interface will need to be significantly extended to be useful.
221241
// FIXME: Implement confidence levels for displaying/fixing errors.
222242
//
223243
/// \brief Displays the found \p Errors to the users. If \p Fix is true, \p
224-
/// Errors containing fixes are automatically applied.
225-
void handleErrors(const std::vector<ClangTidyError> &Errors, bool Fix,
226-
unsigned &WarningsAsErrorsCount);
244+
/// Errors containing fixes are automatically applied and reformatted. If no
245+
/// clang-format configuration file is found, the given \P FormatStyle is used.
246+
void handleErrors(ClangTidyContext &Context, bool Fix,
247+
unsigned &WarningsAsErrorsCount,
248+
llvm::IntrusiveRefCntPtr<vfs::FileSystem> BaseFS);
227249

228250
/// \brief Serializes replacements into YAML and writes them to the specified
229251
/// output stream.
230-
void exportReplacements(const std::vector<ClangTidyError> &Errors,
252+
void exportReplacements(StringRef MainFilePath,
253+
const std::vector<ClangTidyError> &Errors,
231254
raw_ostream &OS);
232255

233256
} // end namespace tidy

ClangTidyDiagnosticConsumer.h

Lines changed: 41 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_CLANGTIDYDIAGNOSTICCONSUMER_H
1212

1313
#include "ClangTidyOptions.h"
14+
#include "ClangTidyProfiling.h"
1415
#include "clang/Basic/Diagnostic.h"
1516
#include "clang/Basic/SourceManager.h"
17+
#include "clang/Tooling/Core/Diagnostic.h"
1618
#include "clang/Tooling/Refactoring.h"
1719
#include "llvm/ADT/DenseMap.h"
1820
#include "llvm/ADT/StringMap.h"
@@ -32,49 +34,17 @@ class CompilationDatabase;
3234

3335
namespace tidy {
3436

35-
/// \brief A message from a clang-tidy check.
36-
///
37-
/// Note that this is independent of a \c SourceManager.
38-
struct ClangTidyMessage {
39-
ClangTidyMessage(StringRef Message = "");
40-
ClangTidyMessage(StringRef Message, const SourceManager &Sources,
41-
SourceLocation Loc);
42-
std::string Message;
43-
std::string FilePath;
44-
unsigned FileOffset;
45-
};
46-
4737
/// \brief A detected error complete with information to display diagnostic and
4838
/// automatic fix.
4939
///
5040
/// This is used as an intermediate format to transport Diagnostics without a
5141
/// dependency on a SourceManager.
5242
///
5343
/// FIXME: Make Diagnostics flexible enough to support this directly.
54-
struct ClangTidyError {
55-
enum Level {
56-
Warning = DiagnosticsEngine::Warning,
57-
Error = DiagnosticsEngine::Error
58-
};
59-
60-
ClangTidyError(StringRef CheckName, Level DiagLevel, bool IsWarningAsError,
61-
StringRef BuildDirectory);
62-
63-
std::string CheckName;
64-
ClangTidyMessage Message;
65-
tooling::Replacements Fix;
66-
SmallVector<ClangTidyMessage, 1> Notes;
67-
68-
// A build directory of the diagnostic source file.
69-
//
70-
// It's an absolute path which is `directory` field of the source file in
71-
// compilation database. If users don't specify the compilation database
72-
// directory, it is the current directory where clang-tidy runs.
73-
//
74-
// Note: it is empty in unittest.
75-
std::string BuildDirectory;
76-
77-
Level DiagLevel;
44+
struct ClangTidyError : tooling::Diagnostic {
45+
ClangTidyError(StringRef CheckName, Level DiagLevel, StringRef BuildDirectory,
46+
bool IsWarningAsError);
47+
7848
bool IsWarningAsError;
7949
};
8050

@@ -118,11 +88,6 @@ struct ClangTidyStats {
11888
}
11989
};
12090

121-
/// \brief Container for clang-tidy profiling data.
122-
struct ProfileData {
123-
llvm::StringMap<llvm::TimeRecord> Records;
124-
};
125-
12691
/// \brief Every \c ClangTidyCheck reports errors through a \c DiagnosticsEngine
12792
/// provided by this context.
12893
///
@@ -135,7 +100,10 @@ struct ProfileData {
135100
class ClangTidyContext {
136101
public:
137102
/// \brief Initializes \c ClangTidyContext instance.
138-
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider);
103+
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
104+
bool AllowEnablingAnalyzerAlphaCheckers = false);
105+
106+
~ClangTidyContext();
139107

140108
/// \brief Report any errors detected using this method.
141109
///
@@ -167,14 +135,14 @@ class ClangTidyContext {
167135
/// diagnostic ID.
168136
StringRef getCheckName(unsigned DiagnosticID) const;
169137

170-
/// \brief Returns check filter for the \c CurrentFile.
138+
/// \brief Returns \c true if the check is enabled for the \c CurrentFile.
171139
///
172140
/// The \c CurrentFile can be changed using \c setCurrentFile.
173-
GlobList &getChecksFilter();
141+
bool isCheckEnabled(StringRef CheckName) const;
174142

175-
/// \brief Returns check filter for the \c CurrentFile which
176-
/// selects checks for upgrade to error.
177-
GlobList &getWarningAsErrorFilter();
143+
/// \brief Returns \c true if the check should be upgraded to error for the
144+
/// \c CurrentFile.
145+
bool treatAsError(StringRef CheckName) const;
178146

179147
/// \brief Returns global options.
180148
const ClangTidyGlobalOptions &getGlobalOptions() const;
@@ -193,17 +161,19 @@ class ClangTidyContext {
193161
const ClangTidyStats &getStats() const { return Stats; }
194162

195163
/// \brief Returns all collected errors.
196-
const std::vector<ClangTidyError> &getErrors() const { return Errors; }
164+
ArrayRef<ClangTidyError> getErrors() const { return Errors; }
197165

198166
/// \brief Clears collected errors.
199167
void clearErrors() { Errors.clear(); }
200168

201-
/// \brief Set the output struct for profile data.
202-
///
203-
/// Setting a non-null pointer here will enable profile collection in
204-
/// clang-tidy.
205-
void setCheckProfileData(ProfileData *Profile);
206-
ProfileData *getCheckProfileData() const { return Profile; }
169+
/// \brief Control profile collection in clang-tidy.
170+
void setEnableProfiling(bool Profile);
171+
bool getEnableProfiling() const { return Profile; }
172+
173+
/// \brief Control storage of profile date.
174+
void setProfileStoragePrefix(StringRef ProfilePrefix);
175+
llvm::Optional<ClangTidyProfiling::StorageParams>
176+
getProfileStorageParams() const;
207177

208178
/// \brief Should be called when starting to process new translation unit.
209179
void setCurrentBuildDirectory(StringRef BuildDirectory) {
@@ -215,6 +185,12 @@ class ClangTidyContext {
215185
return CurrentBuildDirectory;
216186
}
217187

188+
/// \brief If the experimental alpha checkers from the static analyzer can be
189+
/// enabled.
190+
bool canEnableAnalyzerAlphaCheckers() const {
191+
return AllowEnablingAnalyzerAlphaCheckers;
192+
}
193+
218194
private:
219195
// Calls setDiagnosticsEngine() and storeError().
220196
friend class ClangTidyDiagnosticConsumer;
@@ -233,8 +209,9 @@ class ClangTidyContext {
233209

234210
std::string CurrentFile;
235211
ClangTidyOptions CurrentOptions;
236-
std::unique_ptr<GlobList> CheckFilter;
237-
std::unique_ptr<GlobList> WarningAsErrorFilter;
212+
class CachedGlobList;
213+
std::unique_ptr<CachedGlobList> CheckFilter;
214+
std::unique_ptr<CachedGlobList> WarningAsErrorFilter;
238215

239216
LangOptions LangOpts;
240217

@@ -244,7 +221,10 @@ class ClangTidyContext {
244221

245222
llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
246223

247-
ProfileData *Profile;
224+
bool Profile;
225+
std::string ProfilePrefix;
226+
227+
bool AllowEnablingAnalyzerAlphaCheckers;
248228
};
249229

250230
/// \brief A diagnostic consumer that turns each \c Diagnostic into a
@@ -254,7 +234,8 @@ class ClangTidyContext {
254234
// implementation file.
255235
class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
256236
public:
257-
ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx);
237+
ClangTidyDiagnosticConsumer(ClangTidyContext &Ctx,
238+
bool RemoveIncompatibleErrors = true);
258239

259240
// FIXME: The concept of converting between FixItHints and Replacements is
260241
// more generic and should be pulled out into a more useful Diagnostics
@@ -280,11 +261,13 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
280261
bool passesLineFilter(StringRef FileName, unsigned LineNumber) const;
281262

282263
ClangTidyContext &Context;
264+
bool RemoveIncompatibleErrors;
283265
std::unique_ptr<DiagnosticsEngine> Diags;
284266
SmallVector<ClangTidyError, 8> Errors;
285267
std::unique_ptr<llvm::Regex> HeaderFilter;
286268
bool LastErrorRelatesToUserCode;
287269
bool LastErrorPassesLineFilter;
270+
bool LastErrorWasIgnored;
288271
};
289272

290273
} // end namespace tidy

ClangTidyModule.h

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,9 @@ namespace tidy {
2626
/// this object.
2727
class ClangTidyCheckFactories {
2828
public:
29-
typedef std::function<ClangTidyCheck *(
30-
StringRef Name, ClangTidyContext *Context)> CheckFactory;
29+
typedef std::function<ClangTidyCheck *(StringRef Name,
30+
ClangTidyContext *Context)>
31+
CheckFactory;
3132

3233
/// \brief Registers check \p Factory with name \p Name.
3334
///
@@ -58,8 +59,8 @@ class ClangTidyCheckFactories {
5859
template <typename CheckType> void registerCheck(StringRef CheckName) {
5960
registerCheckFactory(CheckName,
6061
[](StringRef Name, ClangTidyContext *Context) {
61-
return new CheckType(Name, Context);
62-
});
62+
return new CheckType(Name, Context);
63+
});
6364
}
6465

6566
/// \brief Create instances of all checks matching \p CheckRegexString and

ClangTidyModuleRegistry.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
#include "ClangTidyModule.h"
1414
#include "llvm/Support/Registry.h"
1515

16-
extern template class llvm::Registry<clang::tidy::ClangTidyModule>;
17-
1816
namespace clang {
1917
namespace tidy {
2018

ClangTidyOptions.h

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
#include "llvm/ADT/Optional.h"
1414
#include "llvm/ADT/StringMap.h"
1515
#include "llvm/ADT/StringRef.h"
16+
#include "llvm/ADT/IntrusiveRefCntPtr.h"
1617
#include "llvm/Support/ErrorOr.h"
18+
#include "clang/Basic/VirtualFileSystem.h"
1719
#include <functional>
1820
#include <map>
1921
#include <string>
@@ -72,8 +74,19 @@ struct ClangTidyOptions {
7274
/// \brief Output warnings from system headers matching \c HeaderFilterRegex.
7375
llvm::Optional<bool> SystemHeaders;
7476

75-
/// \brief Turns on temporary destructor-based analysis.
76-
llvm::Optional<bool> AnalyzeTemporaryDtors;
77+
/// \brief Format code around applied fixes with clang-format using this
78+
/// style.
79+
///
80+
/// Can be one of:
81+
/// * 'none' - don't format code around applied fixes;
82+
/// * 'llvm', 'google', 'mozilla' or other predefined clang-format style
83+
/// names;
84+
/// * 'file' - use the .clang-format file in the closest parent directory of
85+
/// each source file;
86+
/// * '{inline-formatting-style-in-yaml-format}'.
87+
///
88+
/// See clang-format documentation for more about configuring format style.
89+
llvm::Optional<std::string> FormatStyle;
7790

7891
/// \brief Specifies the name or e-mail of the user running clang-tidy.
7992
///
@@ -173,7 +186,8 @@ class FileOptionsProvider : public DefaultOptionsProvider {
173186
// \brief A pair of configuration file base name and a function parsing
174187
// configuration from text in the corresponding format.
175188
typedef std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions>(
176-
llvm::StringRef)>> ConfigFileHandler;
189+
llvm::StringRef)>>
190+
ConfigFileHandler;
177191

178192
/// \brief Configuration file handlers listed in the order of priority.
179193
///
@@ -206,7 +220,8 @@ class FileOptionsProvider : public DefaultOptionsProvider {
206220
/// whatever options are read from the configuration file.
207221
FileOptionsProvider(const ClangTidyGlobalOptions &GlobalOptions,
208222
const ClangTidyOptions &DefaultOptions,
209-
const ClangTidyOptions &OverrideOptions);
223+
const ClangTidyOptions &OverrideOptions,
224+
llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS = nullptr);
210225

211226
/// \brief Initializes the \c FileOptionsProvider instance with a custom set
212227
/// of configuration file handlers.
@@ -240,6 +255,7 @@ class FileOptionsProvider : public DefaultOptionsProvider {
240255
llvm::StringMap<OptionsSource> CachedOptions;
241256
ClangTidyOptions OverrideOptions;
242257
ConfigFileHandlers ConfigHandlers;
258+
llvm::IntrusiveRefCntPtr<vfs::FileSystem> FS;
243259
};
244260

245261
/// \brief Parses LineFilter from JSON and stores it to the \p Options.

aliceO2/AliceO2TidyModule.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,13 @@ class AliceO2Module : public ClangTidyModule {
3030
}
3131
};
3232

33+
3334
} // namespace aliceO2
3435

3536
// Register the AliceO2TidyModule using this statically initialized variable.
36-
static ClangTidyModuleRegistry::Add<aliceO2::AliceO2Module>
37-
X("aliceO2-module", "Adds AliceO2 specific checks");
37+
static ClangTidyModuleRegistry::Add<aliceO2::AliceO2Module> X("aliceO2-module",
38+
"Adds AliceO2 specific checks");
39+
3840

3941
// This anchor is used to force the linker to link in the generated object file
4042
// and thus register the AliceO2Module.

0 commit comments

Comments
 (0)