Skip to content

Commit 78f60bf

Browse files
authored
LLVM and SPIRV-LLVM-Translator pulldown (WW30)
LLVM: llvm/llvm-project@f7a5715 SPIRV-LLVM-Translator: KhronosGroup/SPIRV-LLVM-Translator@5202e9c
2 parents 13a1e49 + 5b18de1 commit 78f60bf

File tree

2,854 files changed

+123413
-33982
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

2,854 files changed

+123413
-33982
lines changed

clang-tools-extra/clang-tidy/ClangTidyCheck.cpp

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -155,17 +155,26 @@ void ClangTidyCheck::OptionsView::store(ClangTidyOptions::OptionMap &Options,
155155
Options[NamePrefix + LocalName.str()] = Value;
156156
}
157157

158-
void ClangTidyCheck::OptionsView::store(ClangTidyOptions::OptionMap &Options,
159-
StringRef LocalName,
160-
int64_t Value) const {
158+
void ClangTidyCheck::OptionsView::storeInt(ClangTidyOptions::OptionMap &Options,
159+
StringRef LocalName,
160+
int64_t Value) const {
161161
store(Options, LocalName, llvm::itostr(Value));
162162
}
163163

164-
llvm::Expected<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
165-
StringRef LocalName, ArrayRef<std::pair<StringRef, int64_t>> Mapping,
166-
bool CheckGlobal, bool IgnoreCase) {
167-
auto Iter = CheckGlobal ? findPriorityOption(CheckOptions, NamePrefix, LocalName)
168-
: CheckOptions.find((NamePrefix + LocalName).str());
164+
template <>
165+
void ClangTidyCheck::OptionsView::store<bool>(
166+
ClangTidyOptions::OptionMap &Options, StringRef LocalName,
167+
bool Value) const {
168+
store(Options, LocalName, Value ? StringRef("true") : StringRef("false"));
169+
}
170+
171+
llvm::Expected<int64_t>
172+
ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
173+
ArrayRef<NameAndValue> Mapping,
174+
bool CheckGlobal, bool IgnoreCase) {
175+
auto Iter = CheckGlobal
176+
? findPriorityOption(CheckOptions, NamePrefix, LocalName)
177+
: CheckOptions.find((NamePrefix + LocalName).str());
169178
if (Iter == CheckOptions.end())
170179
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
171180

@@ -174,19 +183,19 @@ llvm::Expected<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
174183
unsigned EditDistance = -1;
175184
for (const auto &NameAndEnum : Mapping) {
176185
if (IgnoreCase) {
177-
if (Value.equals_lower(NameAndEnum.first))
178-
return NameAndEnum.second;
179-
} else if (Value.equals(NameAndEnum.first)) {
180-
return NameAndEnum.second;
181-
} else if (Value.equals_lower(NameAndEnum.first)) {
182-
Closest = NameAndEnum.first;
186+
if (Value.equals_lower(NameAndEnum.second))
187+
return NameAndEnum.first;
188+
} else if (Value.equals(NameAndEnum.second)) {
189+
return NameAndEnum.first;
190+
} else if (Value.equals_lower(NameAndEnum.second)) {
191+
Closest = NameAndEnum.second;
183192
EditDistance = 0;
184193
continue;
185194
}
186-
unsigned Distance = Value.edit_distance(NameAndEnum.first);
195+
unsigned Distance = Value.edit_distance(NameAndEnum.second);
187196
if (Distance < EditDistance) {
188197
EditDistance = Distance;
189-
Closest = NameAndEnum.first;
198+
Closest = NameAndEnum.second;
190199
}
191200
}
192201
if (EditDistance < 3)

clang-tools-extra/clang-tidy/ClangTidyCheck.h

Lines changed: 65 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ class SourceManager;
2626

2727
namespace tidy {
2828

29+
/// This class should be specialized by any enum type that needs to be converted
30+
/// to and from an \ref llvm::StringRef.
31+
template <class T> struct OptionEnumMapping {
32+
// Specializations of this struct must implement this function.
33+
static ArrayRef<std::pair<T, StringRef>> getEnumMapping() = delete;
34+
};
35+
2936
template <typename T> class OptionError : public llvm::ErrorInfo<T> {
3037
std::error_code convertToErrorCode() const override {
3138
return llvm::inconvertibleErrorCode();
@@ -312,77 +319,80 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
312319
}
313320

314321
/// Read a named option from the ``Context`` and parse it as an
315-
/// enum type ``T`` using the \p Mapping provided. If \p IgnoreCase is set,
316-
/// it will search the mapping ignoring the case.
322+
/// enum type ``T``.
317323
///
318324
/// Reads the option with the check-local name \p LocalName from the
319325
/// ``CheckOptions``. If the corresponding key is not present, returns a
320326
/// ``MissingOptionError``. If the key can't be parsed as a ``T`` returns a
321327
/// ``UnparseableEnumOptionError``.
328+
///
329+
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
330+
/// supply the mapping required to convert between ``T`` and a string.
322331
template <typename T>
323332
std::enable_if_t<std::is_enum<T>::value, llvm::Expected<T>>
324-
get(StringRef LocalName, ArrayRef<std::pair<StringRef, T>> Mapping,
325-
bool IgnoreCase = false) {
326-
if (llvm::Expected<int64_t> ValueOr = getEnumInt(
327-
LocalName, typeEraseMapping(Mapping), false, IgnoreCase))
333+
get(StringRef LocalName, bool IgnoreCase = false) {
334+
if (llvm::Expected<int64_t> ValueOr =
335+
getEnumInt(LocalName, typeEraseMapping<T>(), false, IgnoreCase))
328336
return static_cast<T>(*ValueOr);
329337
else
330338
return std::move(ValueOr.takeError());
331339
}
332340

333341
/// Read a named option from the ``Context`` and parse it as an
334-
/// enum type ``T`` using the \p Mapping provided. If \p IgnoreCase is set,
335-
/// it will search the mapping ignoring the case.
342+
/// enum type ``T``.
336343
///
337344
/// Reads the option with the check-local name \p LocalName from the
338345
/// ``CheckOptions``. If the corresponding key is not present or it can't be
339346
/// parsed as a ``T``, returns \p Default.
347+
///
348+
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
349+
/// supply the mapping required to convert between ``T`` and a string.
340350
template <typename T>
341351
std::enable_if_t<std::is_enum<T>::value, T>
342-
get(StringRef LocalName, ArrayRef<std::pair<StringRef, T>> Mapping,
343-
T Default, bool IgnoreCase = false) {
344-
if (auto ValueOr = get(LocalName, Mapping, IgnoreCase))
352+
get(StringRef LocalName, T Default, bool IgnoreCase = false) {
353+
if (auto ValueOr = get<T>(LocalName, IgnoreCase))
345354
return *ValueOr;
346355
else
347356
logErrToStdErr(ValueOr.takeError());
348357
return Default;
349358
}
350359

351360
/// Read a named option from the ``Context`` and parse it as an
352-
/// enum type ``T`` using the \p Mapping provided. If \p IgnoreCase is set,
353-
/// it will search the mapping ignoring the case.
361+
/// enum type ``T``.
354362
///
355363
/// Reads the option with the check-local name \p LocalName from local or
356364
/// global ``CheckOptions``. Gets local option first. If local is not
357365
/// present, falls back to get global option. If global option is not
358366
/// present either, returns a ``MissingOptionError``. If the key can't be
359367
/// parsed as a ``T`` returns a ``UnparseableEnumOptionError``.
368+
///
369+
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
370+
/// supply the mapping required to convert between ``T`` and a string.
360371
template <typename T>
361372
std::enable_if_t<std::is_enum<T>::value, llvm::Expected<T>>
362373
getLocalOrGlobal(StringRef LocalName,
363-
ArrayRef<std::pair<StringRef, T>> Mapping,
364374
bool IgnoreCase = false) {
365-
if (llvm::Expected<int64_t> ValueOr = getEnumInt(
366-
LocalName, typeEraseMapping(Mapping), true, IgnoreCase))
375+
if (llvm::Expected<int64_t> ValueOr =
376+
getEnumInt(LocalName, typeEraseMapping<T>(), true, IgnoreCase))
367377
return static_cast<T>(*ValueOr);
368378
else
369379
return std::move(ValueOr.takeError());
370380
}
371381

372382
/// Read a named option from the ``Context`` and parse it as an
373-
/// enum type ``T`` using the \p Mapping provided. If \p IgnoreCase is set,
374-
/// it will search the mapping ignoring the case.
383+
/// enum type ``T``.
375384
///
376385
/// Reads the option with the check-local name \p LocalName from local or
377386
/// global ``CheckOptions``. Gets local option first. If local is not
378387
/// present, falls back to get global option. If global option is not
379388
/// present either or it can't be parsed as a ``T``, returns \p Default.
389+
///
390+
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
391+
/// supply the mapping required to convert between ``T`` and a string.
380392
template <typename T>
381393
std::enable_if_t<std::is_enum<T>::value, T>
382-
getLocalOrGlobal(StringRef LocalName,
383-
ArrayRef<std::pair<StringRef, T>> Mapping, T Default,
384-
bool IgnoreCase = false) {
385-
if (auto ValueOr = getLocalOrGlobal(LocalName, Mapping, IgnoreCase))
394+
getLocalOrGlobal(StringRef LocalName, T Default, bool IgnoreCase = false) {
395+
if (auto ValueOr = getLocalOrGlobal<T>(LocalName, IgnoreCase))
386396
return *ValueOr;
387397
else
388398
logErrToStdErr(ValueOr.takeError());
@@ -395,43 +405,56 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
395405
StringRef Value) const;
396406

397407
/// Stores an option with the check-local name \p LocalName with
398-
/// ``int64_t`` value \p Value to \p Options.
399-
void store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
400-
int64_t Value) const;
408+
/// integer value \p Value to \p Options.
409+
template <typename T>
410+
std::enable_if_t<std::is_integral<T>::value>
411+
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
412+
T Value) const {
413+
storeInt(Options, LocalName, Value);
414+
}
401415

402416
/// Stores an option with the check-local name \p LocalName as the string
403-
/// representation of the Enum \p Value using the \p Mapping to \p Options.
417+
/// representation of the Enum \p Value to \p Options.
418+
///
419+
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
420+
/// supply the mapping required to convert between ``T`` and a string.
404421
template <typename T>
405422
std::enable_if_t<std::is_enum<T>::value>
406-
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, T Value,
407-
ArrayRef<std::pair<StringRef, T>> Mapping) {
423+
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, T Value) {
424+
ArrayRef<std::pair<T, StringRef>> Mapping =
425+
OptionEnumMapping<T>::getEnumMapping();
408426
auto Iter = llvm::find_if(
409-
Mapping, [&](const std::pair<StringRef, T> &NameAndEnum) {
410-
return NameAndEnum.second == Value;
427+
Mapping, [&](const std::pair<T, StringRef> &NameAndEnum) {
428+
return NameAndEnum.first == Value;
411429
});
412430
assert(Iter != Mapping.end() && "Unknown Case Value");
413-
store(Options, LocalName, Iter->first);
431+
store(Options, LocalName, Iter->second);
414432
}
415433

416434
private:
417-
using NameAndValue = std::pair<StringRef, int64_t>;
435+
using NameAndValue = std::pair<int64_t, StringRef>;
418436

419437
llvm::Expected<int64_t> getEnumInt(StringRef LocalName,
420438
ArrayRef<NameAndValue> Mapping,
421439
bool CheckGlobal, bool IgnoreCase);
422440

423441
template <typename T>
424442
std::enable_if_t<std::is_enum<T>::value, std::vector<NameAndValue>>
425-
typeEraseMapping(ArrayRef<std::pair<StringRef, T>> Mapping) {
443+
typeEraseMapping() {
444+
ArrayRef<std::pair<T, StringRef>> Mapping =
445+
OptionEnumMapping<T>::getEnumMapping();
426446
std::vector<NameAndValue> Result;
427447
Result.reserve(Mapping.size());
428448
for (auto &MappedItem : Mapping) {
429-
Result.emplace_back(MappedItem.first,
430-
static_cast<int64_t>(MappedItem.second));
449+
Result.emplace_back(static_cast<int64_t>(MappedItem.first),
450+
MappedItem.second);
431451
}
432452
return Result;
433453
}
434454

455+
void storeInt(ClangTidyOptions::OptionMap &Options, StringRef LocalName,
456+
int64_t Value) const;
457+
435458
static void logErrToStdErr(llvm::Error &&Err);
436459

437460
std::string NamePrefix;
@@ -493,6 +516,13 @@ template <>
493516
bool ClangTidyCheck::OptionsView::getLocalOrGlobal<bool>(StringRef LocalName,
494517
bool Default) const;
495518

519+
/// Stores an option with the check-local name \p LocalName with
520+
/// bool value \p Value to \p Options.
521+
template <>
522+
void ClangTidyCheck::OptionsView::store<bool>(
523+
ClangTidyOptions::OptionMap &Options, StringRef LocalName,
524+
bool Value) const;
525+
496526
} // namespace tidy
497527
} // namespace clang
498528

clang-tools-extra/clang-tidy/abseil/StringFindStartswithCheck.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ StringFindStartswithCheck::StringFindStartswithCheck(StringRef Name,
2727
StringLikeClasses(utils::options::parseStringList(
2828
Options.get("StringLikeClasses", "::std::basic_string"))),
2929
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
30-
utils::IncludeSorter::getMapping(),
3130
utils::IncludeSorter::IS_LLVM)),
3231
AbseilStringsMatchHeader(
3332
Options.get("AbseilStringsMatchHeader", "absl/strings/match.h")) {}
@@ -122,8 +121,7 @@ void StringFindStartswithCheck::storeOptions(
122121
ClangTidyOptions::OptionMap &Opts) {
123122
Options.store(Opts, "StringLikeClasses",
124123
utils::options::serializeStringList(StringLikeClasses));
125-
Options.store(Opts, "IncludeStyle", IncludeStyle,
126-
utils::IncludeSorter::getMapping());
124+
Options.store(Opts, "IncludeStyle", IncludeStyle);
127125
Options.store(Opts, "AbseilStringsMatchHeader", AbseilStringsMatchHeader);
128126
}
129127

clang-tools-extra/clang-tidy/cppcoreguidelines/InitVariablesCheck.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,11 @@ InitVariablesCheck::InitVariablesCheck(StringRef Name,
2727
ClangTidyContext *Context)
2828
: ClangTidyCheck(Name, Context),
2929
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
30-
utils::IncludeSorter::getMapping(),
3130
utils::IncludeSorter::IS_LLVM)),
3231
MathHeader(Options.get("MathHeader", "math.h")) {}
3332

3433
void InitVariablesCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
35-
Options.store(Opts, "IncludeStyle", IncludeStyle,
36-
utils::IncludeSorter::getMapping());
34+
Options.store(Opts, "IncludeStyle", IncludeStyle);
3735
Options.store(Opts, "MathHeader", MathHeader);
3836
}
3937

clang-tools-extra/clang-tidy/cppcoreguidelines/ProBoundsConstantArrayIndexCheck.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ ProBoundsConstantArrayIndexCheck::ProBoundsConstantArrayIndexCheck(
2222
StringRef Name, ClangTidyContext *Context)
2323
: ClangTidyCheck(Name, Context), GslHeader(Options.get("GslHeader", "")),
2424
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
25-
utils::IncludeSorter::getMapping(),
2625
utils::IncludeSorter::IS_LLVM)) {}
2726

2827
void ProBoundsConstantArrayIndexCheck::storeOptions(

clang-tools-extra/clang-tidy/modernize/LoopConvertCheck.cpp

Lines changed: 29 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,31 @@ using namespace llvm;
2828

2929
namespace clang {
3030
namespace tidy {
31+
32+
template <> struct OptionEnumMapping<modernize::Confidence::Level> {
33+
static llvm::ArrayRef<std::pair<modernize::Confidence::Level, StringRef>>
34+
getEnumMapping() {
35+
static constexpr std::pair<modernize::Confidence::Level, StringRef>
36+
Mapping[] = {{modernize::Confidence::CL_Reasonable, "reasonable"},
37+
{modernize::Confidence::CL_Safe, "safe"},
38+
{modernize::Confidence::CL_Risky, "risky"}};
39+
return makeArrayRef(Mapping);
40+
}
41+
};
42+
43+
template <> struct OptionEnumMapping<modernize::VariableNamer::NamingStyle> {
44+
static llvm::ArrayRef<
45+
std::pair<modernize::VariableNamer::NamingStyle, StringRef>>
46+
getEnumMapping() {
47+
static constexpr std::pair<modernize::VariableNamer::NamingStyle, StringRef>
48+
Mapping[] = {{modernize::VariableNamer::NS_CamelCase, "CamelCase"},
49+
{modernize::VariableNamer::NS_CamelBack, "camelBack"},
50+
{modernize::VariableNamer::NS_LowerCase, "lower_case"},
51+
{modernize::VariableNamer::NS_UpperCase, "UPPER_CASE"}};
52+
return makeArrayRef(Mapping);
53+
}
54+
};
55+
3156
namespace modernize {
3257

3358
static const char LoopNameArray[] = "forLoopArray";
@@ -44,25 +69,6 @@ static const char EndVarName[] = "endVar";
4469
static const char DerefByValueResultName[] = "derefByValueResult";
4570
static const char DerefByRefResultName[] = "derefByRefResult";
4671

47-
static ArrayRef<std::pair<StringRef, Confidence::Level>>
48-
getConfidenceMapping() {
49-
static constexpr std::pair<StringRef, Confidence::Level> Mapping[] = {
50-
{"reasonable", Confidence::CL_Reasonable},
51-
{"safe", Confidence::CL_Safe},
52-
{"risky", Confidence::CL_Risky}};
53-
return makeArrayRef(Mapping);
54-
}
55-
56-
static ArrayRef<std::pair<StringRef, VariableNamer::NamingStyle>>
57-
getStyleMapping() {
58-
static constexpr std::pair<StringRef, VariableNamer::NamingStyle> Mapping[] =
59-
{{"CamelCase", VariableNamer::NS_CamelCase},
60-
{"camelBack", VariableNamer::NS_CamelBack},
61-
{"lower_case", VariableNamer::NS_LowerCase},
62-
{"UPPER_CASE", VariableNamer::NS_UpperCase}};
63-
return makeArrayRef(Mapping);
64-
}
65-
6672
// shared matchers
6773
static const TypeMatcher AnyType() { return anything(); }
6874

@@ -474,15 +480,13 @@ LoopConvertCheck::RangeDescriptor::RangeDescriptor()
474480
LoopConvertCheck::LoopConvertCheck(StringRef Name, ClangTidyContext *Context)
475481
: ClangTidyCheck(Name, Context), TUInfo(new TUTrackingInfo),
476482
MaxCopySize(Options.get("MaxCopySize", 16ULL)),
477-
MinConfidence(Options.get("MinConfidence", getConfidenceMapping(),
478-
Confidence::CL_Reasonable)),
479-
NamingStyle(Options.get("NamingStyle", getStyleMapping(),
480-
VariableNamer::NS_CamelCase)) {}
483+
MinConfidence(Options.get("MinConfidence", Confidence::CL_Reasonable)),
484+
NamingStyle(Options.get("NamingStyle", VariableNamer::NS_CamelCase)) {}
481485

482486
void LoopConvertCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
483487
Options.store(Opts, "MaxCopySize", std::to_string(MaxCopySize));
484-
Options.store(Opts, "MinConfidence", MinConfidence, getConfidenceMapping());
485-
Options.store(Opts, "NamingStyle", NamingStyle, getStyleMapping());
488+
Options.store(Opts, "MinConfidence", MinConfidence);
489+
Options.store(Opts, "NamingStyle", NamingStyle);
486490
}
487491

488492
void LoopConvertCheck::registerMatchers(MatchFinder *Finder) {

0 commit comments

Comments
 (0)