Skip to content

Commit 4bddbdb

Browse files
committed
Merge from 'master' to 'sycl-web' (#62)
CONFLICT (content): Merge conflict in clang/lib/Sema/SemaStmtAttr.cpp
2 parents dafcc9e + 49e5f60 commit 4bddbdb

File tree

202 files changed

+3717
-1964
lines changed

Some content is hidden

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

202 files changed

+3717
-1964
lines changed

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

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,11 +161,13 @@ void ClangTidyCheck::OptionsView::store(ClangTidyOptions::OptionMap &Options,
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+
llvm::Expected<int64_t>
165+
ClangTidyCheck::OptionsView::getEnumInt(StringRef LocalName,
166+
ArrayRef<NameAndValue> Mapping,
167+
bool CheckGlobal, bool IgnoreCase) {
168+
auto Iter = CheckGlobal
169+
? findPriorityOption(CheckOptions, NamePrefix, LocalName)
170+
: CheckOptions.find((NamePrefix + LocalName).str());
169171
if (Iter == CheckOptions.end())
170172
return llvm::make_error<MissingOptionError>((NamePrefix + LocalName).str());
171173

@@ -174,19 +176,19 @@ llvm::Expected<int64_t> ClangTidyCheck::OptionsView::getEnumInt(
174176
unsigned EditDistance = -1;
175177
for (const auto &NameAndEnum : Mapping) {
176178
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;
179+
if (Value.equals_lower(NameAndEnum.second))
180+
return NameAndEnum.first;
181+
} else if (Value.equals(NameAndEnum.second)) {
182+
return NameAndEnum.first;
183+
} else if (Value.equals_lower(NameAndEnum.second)) {
184+
Closest = NameAndEnum.second;
183185
EditDistance = 0;
184186
continue;
185187
}
186-
unsigned Distance = Value.edit_distance(NameAndEnum.first);
188+
unsigned Distance = Value.edit_distance(NameAndEnum.second);
187189
if (Distance < EditDistance) {
188190
EditDistance = Distance;
189-
Closest = NameAndEnum.first;
191+
Closest = NameAndEnum.second;
190192
}
191193
}
192194
if (EditDistance < 3)

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

Lines changed: 48 additions & 32 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());
@@ -400,34 +410,40 @@ class ClangTidyCheck : public ast_matchers::MatchFinder::MatchCallback {
400410
int64_t Value) const;
401411

402412
/// 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.
413+
/// representation of the Enum \p Value to \p Options.
414+
///
415+
/// \ref clang::tidy::OptionEnumMapping must be specialized for ``T`` to
416+
/// supply the mapping required to convert between ``T`` and a string.
404417
template <typename T>
405418
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) {
419+
store(ClangTidyOptions::OptionMap &Options, StringRef LocalName, T Value) {
420+
ArrayRef<std::pair<T, StringRef>> Mapping =
421+
OptionEnumMapping<T>::getEnumMapping();
408422
auto Iter = llvm::find_if(
409-
Mapping, [&](const std::pair<StringRef, T> &NameAndEnum) {
410-
return NameAndEnum.second == Value;
423+
Mapping, [&](const std::pair<T, StringRef> &NameAndEnum) {
424+
return NameAndEnum.first == Value;
411425
});
412426
assert(Iter != Mapping.end() && "Unknown Case Value");
413-
store(Options, LocalName, Iter->first);
427+
store(Options, LocalName, Iter->second);
414428
}
415429

416430
private:
417-
using NameAndValue = std::pair<StringRef, int64_t>;
431+
using NameAndValue = std::pair<int64_t, StringRef>;
418432

419433
llvm::Expected<int64_t> getEnumInt(StringRef LocalName,
420434
ArrayRef<NameAndValue> Mapping,
421435
bool CheckGlobal, bool IgnoreCase);
422436

423437
template <typename T>
424438
std::enable_if_t<std::is_enum<T>::value, std::vector<NameAndValue>>
425-
typeEraseMapping(ArrayRef<std::pair<StringRef, T>> Mapping) {
439+
typeEraseMapping() {
440+
ArrayRef<std::pair<T, StringRef>> Mapping =
441+
OptionEnumMapping<T>::getEnumMapping();
426442
std::vector<NameAndValue> Result;
427443
Result.reserve(Mapping.size());
428444
for (auto &MappedItem : Mapping) {
429-
Result.emplace_back(MappedItem.first,
430-
static_cast<int64_t>(MappedItem.second));
445+
Result.emplace_back(static_cast<int64_t>(MappedItem.first),
446+
MappedItem.second);
431447
}
432448
return Result;
433449
}

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) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
4545
StringRef MakeSmartPtrFunctionName)
4646
: ClangTidyCheck(Name, Context),
4747
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
48-
utils::IncludeSorter::getMapping(),
4948
utils::IncludeSorter::IS_LLVM)),
5049
MakeSmartPtrFunctionHeader(
5150
Options.get("MakeSmartPtrFunctionHeader", StdMemoryHeader)),
@@ -54,8 +53,7 @@ MakeSmartPtrCheck::MakeSmartPtrCheck(StringRef Name, ClangTidyContext *Context,
5453
IgnoreMacros(Options.getLocalOrGlobal("IgnoreMacros", true)) {}
5554

5655
void MakeSmartPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
57-
Options.store(Opts, "IncludeStyle", IncludeStyle,
58-
utils::IncludeSorter::getMapping());
56+
Options.store(Opts, "IncludeStyle", IncludeStyle);
5957
Options.store(Opts, "MakeSmartPtrFunctionHeader", MakeSmartPtrFunctionHeader);
6058
Options.store(Opts, "MakeSmartPtrFunction", MakeSmartPtrFunctionName);
6159
Options.store(Opts, "IgnoreMacros", IgnoreMacros);

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -121,13 +121,11 @@ collectParamDecls(const CXXConstructorDecl *Ctor,
121121
PassByValueCheck::PassByValueCheck(StringRef Name, ClangTidyContext *Context)
122122
: ClangTidyCheck(Name, Context),
123123
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
124-
utils::IncludeSorter::getMapping(),
125124
utils::IncludeSorter::IS_LLVM)),
126125
ValuesOnly(Options.get("ValuesOnly", false)) {}
127126

128127
void PassByValueCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
129-
Options.store(Opts, "IncludeStyle", IncludeStyle,
130-
utils::IncludeSorter::getMapping());
128+
Options.store(Opts, "IncludeStyle", IncludeStyle);
131129
Options.store(Opts, "ValuesOnly", ValuesOnly);
132130
}
133131

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,12 +75,10 @@ ReplaceAutoPtrCheck::ReplaceAutoPtrCheck(StringRef Name,
7575
ClangTidyContext *Context)
7676
: ClangTidyCheck(Name, Context),
7777
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
78-
utils::IncludeSorter::getMapping(),
7978
utils::IncludeSorter::IS_LLVM)) {}
8079

8180
void ReplaceAutoPtrCheck::storeOptions(ClangTidyOptions::OptionMap &Opts) {
82-
Options.store(Opts, "IncludeStyle", IncludeStyle,
83-
utils::IncludeSorter::getMapping());
81+
Options.store(Opts, "IncludeStyle", IncludeStyle);
8482
}
8583

8684
void ReplaceAutoPtrCheck::registerMatchers(MatchFinder *Finder) {

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

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ ReplaceRandomShuffleCheck::ReplaceRandomShuffleCheck(StringRef Name,
2424
ClangTidyContext *Context)
2525
: ClangTidyCheck(Name, Context),
2626
IncludeStyle(Options.getLocalOrGlobal("IncludeStyle",
27-
utils::IncludeSorter::getMapping(),
2827
utils::IncludeSorter::IS_LLVM)) {}
2928

3029
void ReplaceRandomShuffleCheck::registerMatchers(MatchFinder *Finder) {
@@ -52,8 +51,7 @@ void ReplaceRandomShuffleCheck::registerPPCallbacks(
5251

5352
void ReplaceRandomShuffleCheck::storeOptions(
5453
ClangTidyOptions::OptionMap &Opts) {
55-
Options.store(Opts, "IncludeStyle", IncludeStyle,
56-
utils::IncludeSorter::getMapping());
54+
Options.store(Opts, "IncludeStyle", IncludeStyle);
5755
}
5856

5957
void ReplaceRandomShuffleCheck::check(const MatchFinder::MatchResult &Result) {

0 commit comments

Comments
 (0)