Skip to content

Commit d2738dd

Browse files
committed
Bump to LLVM 18.1.8
1 parent ba095ee commit d2738dd

File tree

6 files changed

+117
-41
lines changed

6 files changed

+117
-41
lines changed

ClangTidyCheck.h

Lines changed: 88 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,13 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
184184
/// integral type ``T``.
185185
///
186186
/// Reads the option with the check-local name \p LocalName from the
187-
/// ``CheckOptions``. If the corresponding key is not present, return
188-
/// ``std::nullopt``.
187+
/// ``CheckOptions``. If the corresponding key is not present,
188+
/// return ``std::nullopt``.
189189
///
190190
/// If the corresponding key can't be parsed as a ``T``, emit a
191191
/// diagnostic and return ``std::nullopt``.
192192
template <typename T>
193-
std::enable_if_t<std::is_integral<T>::value, std::optional<T>>
193+
std::enable_if_t<std::is_integral_v<T>, std::optional<T>>
194194
get(StringRef LocalName) const {
195195
if (std::optional<StringRef> Value = get(LocalName)) {
196196
T Result{};
@@ -201,6 +201,31 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
201201
return std::nullopt;
202202
}
203203

204+
/// Read a named option from the ``Context`` and parse it as an
205+
/// integral type ``T``.
206+
///
207+
/// Reads the option with the check-local name \p LocalName from the
208+
/// ``CheckOptions``. If the corresponding key is `none`, `null`,
209+
/// `-1` or empty, return ``std::nullopt``. If the corresponding
210+
/// key is not present, return \p Default.
211+
///
212+
/// If the corresponding key can't be parsed as a ``T``, emit a
213+
/// diagnostic and return \p Default.
214+
template <typename T>
215+
std::enable_if_t<std::is_integral_v<T>, std::optional<T>>
216+
get(StringRef LocalName, std::optional<T> Default) const {
217+
if (std::optional<StringRef> Value = get(LocalName)) {
218+
if (Value == "" || Value == "none" || Value == "null" ||
219+
(std::is_unsigned_v<T> && Value == "-1"))
220+
return std::nullopt;
221+
T Result{};
222+
if (!StringRef(*Value).getAsInteger(10, Result))
223+
return Result;
224+
diagnoseBadIntegerOption(NamePrefix + LocalName, *Value);
225+
}
226+
return Default;
227+
}
228+
204229
/// Read a named option from the ``Context`` and parse it as an
205230
/// integral type ``T``.
206231
///
@@ -211,8 +236,8 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
211236
/// If the corresponding key can't be parsed as a ``T``, emit a
212237
/// diagnostic and return \p Default.
213238
template <typename T>
214-
std::enable_if_t<std::is_integral<T>::value, T> get(StringRef LocalName,
215-
T Default) const {
239+
std::enable_if_t<std::is_integral_v<T>, T> get(StringRef LocalName,
240+
T Default) const {
216241
return get<T>(LocalName).value_or(Default);
217242
}
218243

@@ -227,7 +252,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
227252
/// If the corresponding key can't be parsed as a ``T``, emit a
228253
/// diagnostic and return ``std::nullopt``.
229254
template <typename T>
230-
std::enable_if_t<std::is_integral<T>::value, std::optional<T>>
255+
std::enable_if_t<std::is_integral_v<T>, std::optional<T>>
231256
getLocalOrGlobal(StringRef LocalName) const {
232257
std::optional<StringRef> ValueOr = get(LocalName);
233258
bool IsGlobal = false;
@@ -245,6 +270,39 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
245270
return std::nullopt;
246271
}
247272

273+
/// Read a named option from the ``Context`` and parse it as an
274+
/// integral type ``T``.
275+
///
276+
/// Reads the option with the check-local name \p LocalName from local or
277+
/// global ``CheckOptions``. Gets local option first. If local is not
278+
/// present, falls back to get global option. If global option is not
279+
/// present either, return \p Default. If the value value was found
280+
/// and equals ``none``, ``null``, ``-1`` or empty, return ``std::nullopt``.
281+
///
282+
/// If the corresponding key can't be parsed as a ``T``, emit a
283+
/// diagnostic and return \p Default.
284+
template <typename T>
285+
std::enable_if_t<std::is_integral_v<T>, std::optional<T>>
286+
getLocalOrGlobal(StringRef LocalName, std::optional<T> Default) const {
287+
std::optional<StringRef> ValueOr = get(LocalName);
288+
bool IsGlobal = false;
289+
if (!ValueOr) {
290+
IsGlobal = true;
291+
ValueOr = getLocalOrGlobal(LocalName);
292+
if (!ValueOr)
293+
return Default;
294+
}
295+
T Result{};
296+
if (ValueOr == "" || ValueOr == "none" || ValueOr == "null" ||
297+
(std::is_unsigned_v<T> && ValueOr == "-1"))
298+
return std::nullopt;
299+
if (!StringRef(*ValueOr).getAsInteger(10, Result))
300+
return Result;
301+
diagnoseBadIntegerOption(
302+
IsGlobal ? Twine(LocalName) : NamePrefix + LocalName, *ValueOr);
303+
return Default;
304+
}
305+
248306
/// Read a named option from the ``Context`` and parse it as an
249307
/// integral type ``T``.
250308
///
@@ -256,7 +314,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
256314
/// If the corresponding key can't be parsed as a ``T``, emit a
257315
/// diagnostic and return \p Default.
258316
template <typename T>
259-
std::enable_if_t<std::is_integral<T>::value, T>
317+
std::enable_if_t<std::is_integral_v<T>, T>
260318
getLocalOrGlobal(StringRef LocalName, T Default) const {
261319
return getLocalOrGlobal<T>(LocalName).value_or(Default);
262320
}
@@ -274,7 +332,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
274332
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
275333
/// supply the mapping required to convert between ``T`` and a string.
276334
template <typename T>
277-
std::enable_if_t<std::is_enum<T>::value, std::optional<T>>
335+
std::enable_if_t<std::is_enum_v<T>, std::optional<T>>
278336
get(StringRef LocalName, bool IgnoreCase = false) const {
279337
if (std::optional<int64_t> ValueOr =
280338
getEnumInt(LocalName, typeEraseMapping<T>(), false, IgnoreCase))
@@ -286,17 +344,17 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
286344
/// enum type ``T``.
287345
///
288346
/// Reads the option with the check-local name \p LocalName from the
289-
/// ``CheckOptions``. If the corresponding key is not present, return
290-
/// \p Default.
347+
/// ``CheckOptions``. If the corresponding key is not present,
348+
/// return \p Default.
291349
///
292350
/// If the corresponding key can't be parsed as a ``T``, emit a
293351
/// diagnostic and return \p Default.
294352
///
295353
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
296354
/// supply the mapping required to convert between ``T`` and a string.
297355
template <typename T>
298-
std::enable_if_t<std::is_enum<T>::value, T>
299-
get(StringRef LocalName, T Default, bool IgnoreCase = false) const {
356+
std::enable_if_t<std::is_enum_v<T>, T> get(StringRef LocalName, T Default,
357+
bool IgnoreCase = false) const {
300358
return get<T>(LocalName, IgnoreCase).value_or(Default);
301359
}
302360

@@ -314,7 +372,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
314372
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
315373
/// supply the mapping required to convert between ``T`` and a string.
316374
template <typename T>
317-
std::enable_if_t<std::is_enum<T>::value, std::optional<T>>
375+
std::enable_if_t<std::is_enum_v<T>, std::optional<T>>
318376
getLocalOrGlobal(StringRef LocalName, bool IgnoreCase = false) const {
319377
if (std::optional<int64_t> ValueOr =
320378
getEnumInt(LocalName, typeEraseMapping<T>(), true, IgnoreCase))
@@ -336,7 +394,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
336394
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
337395
/// supply the mapping required to convert between ``T`` and a string.
338396
template <typename T>
339-
std::enable_if_t<std::is_enum<T>::value, T>
397+
std::enable_if_t<std::is_enum_v<T>, T>
340398
getLocalOrGlobal(StringRef LocalName, T Default,
341399
bool IgnoreCase = false) const {
342400
return getLocalOrGlobal<T>(LocalName, IgnoreCase).value_or(Default);
@@ -350,19 +408,32 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
350408
/// Stores an option with the check-local name \p LocalName with
351409
/// integer value \p Value to \p Options.
352410
template <typename T>
353-
std::enable_if_t<std::is_integral<T>::value>
411+
std::enable_if_t<std::is_integral_v<T>>
354412
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
355413
T Value) const {
356414
storeInt(Options, LocalName, Value);
357415
}
358416

417+
/// Stores an option with the check-local name \p LocalName with
418+
/// integer value \p Value to \p Options. If the value is empty
419+
/// stores ``
420+
template <typename T>
421+
std::enable_if_t<std::is_integral_v<T>>
422+
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
423+
std::optional<T> Value) const {
424+
if (Value)
425+
storeInt(Options, LocalName, *Value);
426+
else
427+
store(Options, LocalName, "none");
428+
}
429+
359430
/// Stores an option with the check-local name \p LocalName as the string
360431
/// representation of the Enum \p Value to \p Options.
361432
///
362433
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
363434
/// supply the mapping required to convert between ``T`` and a string.
364435
template <typename T>
365-
std::enable_if_t<std::is_enum<T>::value>
436+
std::enable_if_t<std::is_enum_v<T>>
366437
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
367438
T Value) const {
368439
ArrayRef<std::pair<T, StringRef>> Mapping =
@@ -383,7 +454,7 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
383454
bool CheckGlobal, bool IgnoreCase) const;
384455

385456
template <typename T>
386-
std::enable_if_t<std::is_enum<T>::value, std::vector<NameAndValue>>
457+
std::enable_if_t<std::is_enum_v<T>, std::vector<NameAndValue>>
387458
typeEraseMapping() const {
388459
ArrayRef<std::pair<T, StringRef>> Mapping =
389460
OptionEnumMapping<T>::getEnumMapping();

ClangTidyDiagnosticConsumer.h

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,8 @@ class ClangTidyContext {
7070
public:
7171
/// Initializes \c ClangTidyContext instance.
7272
ClangTidyContext(std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider,
73-
bool AllowEnablingAnalyzerAlphaCheckers = false);
73+
bool AllowEnablingAnalyzerAlphaCheckers = false,
74+
bool EnableModuleHeadersParsing = false);
7475
/// Sets the DiagnosticsEngine that diag() will emit diagnostics to.
7576
// FIXME: this is required initialization, and should be a constructor param.
7677
// Fix the context -> diag engine -> consumer -> context initialization cycle.
@@ -86,10 +87,10 @@ class ClangTidyContext {
8687
/// tablegen'd diagnostic IDs.
8788
/// FIXME: Figure out a way to manage ID spaces.
8889
DiagnosticBuilder diag(StringRef CheckName, SourceLocation Loc,
89-
StringRef Message,
90+
StringRef Description,
9091
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
9192

92-
DiagnosticBuilder diag(StringRef CheckName, StringRef Message,
93+
DiagnosticBuilder diag(StringRef CheckName, StringRef Description,
9394
DiagnosticIDs::Level Level = DiagnosticIDs::Warning);
9495

9596
DiagnosticBuilder diag(const tooling::Diagnostic &Error);
@@ -198,18 +199,24 @@ class ClangTidyContext {
198199
return AllowEnablingAnalyzerAlphaCheckers;
199200
}
200201

202+
// This method determines whether preprocessor-level module header parsing is
203+
// enabled using the `--experimental-enable-module-headers-parsing` option.
204+
bool canEnableModuleHeadersParsing() const {
205+
return EnableModuleHeadersParsing;
206+
}
207+
201208
void setSelfContainedDiags(bool Value) { SelfContainedDiags = Value; }
202209

203210
bool areDiagsSelfContained() const { return SelfContainedDiags; }
204211

205212
using DiagLevelAndFormatString = std::pair<DiagnosticIDs::Level, std::string>;
206213
DiagLevelAndFormatString getDiagLevelAndFormatString(unsigned DiagnosticID,
207214
SourceLocation Loc) {
208-
return DiagLevelAndFormatString(
215+
return {
209216
static_cast<DiagnosticIDs::Level>(
210217
DiagEngine->getDiagnosticLevel(DiagnosticID, Loc)),
211218
std::string(
212-
DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID)));
219+
DiagEngine->getDiagnosticIDs()->getDescription(DiagnosticID))};
213220
}
214221

215222
void setOptionsCollector(llvm::StringSet<> *Collector) {
@@ -221,7 +228,7 @@ class ClangTidyContext {
221228
// Writes to Stats.
222229
friend class ClangTidyDiagnosticConsumer;
223230

224-
DiagnosticsEngine *DiagEngine;
231+
DiagnosticsEngine *DiagEngine = nullptr;
225232
std::unique_ptr<ClangTidyOptionsProvider> OptionsProvider;
226233

227234
std::string CurrentFile;
@@ -241,12 +248,13 @@ class ClangTidyContext {
241248

242249
llvm::DenseMap<unsigned, std::string> CheckNamesByDiagnosticID;
243250

244-
bool Profile;
251+
bool Profile = false;
245252
std::string ProfilePrefix;
246253

247254
bool AllowEnablingAnalyzerAlphaCheckers;
255+
bool EnableModuleHeadersParsing;
248256

249-
bool SelfContainedDiags;
257+
bool SelfContainedDiags = false;
250258

251259
NoLintDirectiveHandler NoLintHandler;
252260
llvm::StringSet<> *OptionsCollector = nullptr;
@@ -305,9 +313,9 @@ class ClangTidyDiagnosticConsumer : public DiagnosticConsumer {
305313
bool EnableNolintBlocks;
306314
std::vector<ClangTidyError> Errors;
307315
std::unique_ptr<llvm::Regex> HeaderFilter;
308-
bool LastErrorRelatesToUserCode;
309-
bool LastErrorPassesLineFilter;
310-
bool LastErrorWasIgnored;
316+
bool LastErrorRelatesToUserCode = false;
317+
bool LastErrorPassesLineFilter = false;
318+
bool LastErrorWasIgnored = false;
311319
};
312320

313321
} // end namespace tidy

ClangTidyModule.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class ClangTidyCheckFactories {
7070
std::vector<std::unique_ptr<ClangTidyCheck>>
7171
createChecksForLanguage(ClangTidyContext *Context) const;
7272

73-
typedef llvm::StringMap<CheckFactory> FactoryMap;
73+
using FactoryMap = llvm::StringMap<CheckFactory>;
7474
FactoryMap::const_iterator begin() const { return Factories.begin(); }
7575
FactoryMap::const_iterator end() const { return Factories.end(); }
7676
bool empty() const { return Factories.empty(); }

ClangTidyModuleRegistry.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
namespace clang::tidy {
1616

17-
typedef llvm::Registry<ClangTidyModule> ClangTidyModuleRegistry;
17+
using ClangTidyModuleRegistry = llvm::Registry<ClangTidyModule>;
1818

1919
} // namespace clang::tidy
2020

ClangTidyOptions.h

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ struct FileFilter {
3030
std::string Name;
3131

3232
/// LineRange is a pair<start, end> (inclusive).
33-
typedef std::pair<unsigned, unsigned> LineRange;
33+
using LineRange = std::pair<unsigned int, unsigned int>;
3434

3535
/// A list of line ranges in this file, for which we show warnings.
3636
std::vector<LineRange> LineRanges;
@@ -118,13 +118,13 @@ struct ClangTidyOptions {
118118
/// files to disambiguate local vs global value from different levels.
119119
unsigned Priority = 0;
120120
};
121-
typedef std::pair<std::string, std::string> StringPair;
122-
typedef llvm::StringMap<ClangTidyValue> OptionMap;
121+
using StringPair = std::pair<std::string, std::string>;
122+
using OptionMap = llvm::StringMap<ClangTidyValue>;
123123

124124
/// Key-value mapping used to store check-specific options.
125125
OptionMap CheckOptions;
126126

127-
typedef std::vector<std::string> ArgList;
127+
using ArgList = std::vector<std::string>;
128128

129129
/// Add extra compilation arguments to the end of the list.
130130
std::optional<ArgList> ExtraArgs;
@@ -165,7 +165,7 @@ class ClangTidyOptionsProvider {
165165
/// commandline option is specified, clang-tidy will ignore the
166166
/// configuration file.
167167
/// * '-checks' commandline option.
168-
typedef std::pair<ClangTidyOptions, std::string> OptionsSource;
168+
using OptionsSource = std::pair<ClangTidyOptions, std::string>;
169169

170170
/// Returns an ordered vector of OptionsSources, in order of increasing
171171
/// priority.
@@ -199,9 +199,7 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
199199
protected:
200200
// A pair of configuration file base name and a function parsing
201201
// configuration from text in the corresponding format.
202-
typedef std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions>(
203-
llvm::MemoryBufferRef)>>
204-
ConfigFileHandler;
202+
using ConfigFileHandler = std::pair<std::string, std::function<llvm::ErrorOr<ClangTidyOptions> (llvm::MemoryBufferRef)>>;
205203

206204
/// Configuration file handlers listed in the order of priority.
207205
///
@@ -220,7 +218,7 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
220218
///
221219
/// With the order of handlers shown above, the ".my-tidy-config" file would
222220
/// take precedence over ".clang-tidy" if both reside in the same directory.
223-
typedef std::vector<ConfigFileHandler> ConfigFileHandlers;
221+
using ConfigFileHandlers = std::vector<ConfigFileHandler>;
224222

225223
FileOptionsBaseProvider(ClangTidyGlobalOptions GlobalOptions,
226224
ClangTidyOptions DefaultOptions,
@@ -232,7 +230,6 @@ class FileOptionsBaseProvider : public DefaultOptionsProvider {
232230
ClangTidyOptions OverrideOptions,
233231
ConfigFileHandlers ConfigHandlers);
234232

235-
protected:
236233
void addRawFileOptions(llvm::StringRef AbsolutePath,
237234
std::vector<OptionsSource> &CurOptions);
238235

FileExtensionsSet.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
#include "llvm/ADT/StringRef.h"
1414

1515
namespace clang::tidy {
16-
typedef llvm::SmallSet<llvm::StringRef, 5> FileExtensionsSet;
16+
using FileExtensionsSet = llvm::SmallSet<llvm::StringRef, 5>;
1717
} // namespace clang::tidy
1818

1919
#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FILE_EXTENSIONS_SET_H

0 commit comments

Comments
 (0)