Skip to content

Commit 1c611cd

Browse files
kuhargithub-actions[bot]
authored andcommitted
Automerge: [ADT] Migrate StringSwitch Cases with 6+ arguments to new overload. NFC. (#163549)
Switch to the `.Cases({S0, S1, ...}, Value)` overload instead, and the manually-enumerated overloads with 6+ arguments are getting deprecated in llvm/llvm-project#163405. This pre-commits API updates ahead of the deprecation to make potential reverts cleaner. This was already reviewed in #163405.
2 parents 17a2465 + 2ed7baa commit 1c611cd

File tree

22 files changed

+279
-249
lines changed

22 files changed

+279
-249
lines changed

clang/include/clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,8 @@ class AnalysisManager : public BugReporterData {
140140
// It might be great to reuse FrontendOptions::getInputKindForExtension()
141141
// but for now it doesn't discriminate between code and header files.
142142
return llvm::StringSwitch<bool>(SM.getFilename(SL).rsplit('.').second)
143-
.Cases("c", "m", "mm", "C", "cc", "cp", true)
144-
.Cases("cpp", "CPP", "c++", "cxx", "cppm", true)
143+
.Cases({"c", "m", "mm", "C", "cc", "cp"}, true)
144+
.Cases({"cpp", "CPP", "c++", "cxx", "cppm"}, true)
145145
.Default(false);
146146
}
147147

clang/lib/Basic/Targets/AVR.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -420,23 +420,23 @@ static MCUInfo AVRMcus[] = {
420420

421421
static bool ArchHasELPM(StringRef Arch) {
422422
return llvm::StringSwitch<bool>(Arch)
423-
.Cases("31", "51", "6", true)
424-
.Cases("102", "104", "105", "106", "107", true)
425-
.Default(false);
423+
.Cases({"31", "51", "6"}, true)
424+
.Cases({"102", "104", "105", "106", "107"}, true)
425+
.Default(false);
426426
}
427427

428428
static bool ArchHasELPMX(StringRef Arch) {
429429
return llvm::StringSwitch<bool>(Arch)
430-
.Cases("51", "6", true)
431-
.Cases("102", "104", "105", "106", "107", true)
432-
.Default(false);
430+
.Cases({"51", "6"}, true)
431+
.Cases({"102", "104", "105", "106", "107"}, true)
432+
.Default(false);
433433
}
434434

435435
static bool ArchHasMOVW(StringRef Arch) {
436436
return llvm::StringSwitch<bool>(Arch)
437-
.Cases("25", "35", "4", "5", "51", "6", true)
438-
.Cases("102", "103", "104", "105", "106", "107", true)
439-
.Default(false);
437+
.Cases({"25", "35", "4", "5", "51", "6"}, true)
438+
.Cases({"102", "103", "104", "105", "106", "107"}, true)
439+
.Default(false);
440440
}
441441

442442
static bool ArchHasLPMX(StringRef Arch) {
@@ -445,16 +445,16 @@ static bool ArchHasLPMX(StringRef Arch) {
445445

446446
static bool ArchHasMUL(StringRef Arch) {
447447
return llvm::StringSwitch<bool>(Arch)
448-
.Cases("4", "5", "51", "6", true)
449-
.Cases("102", "103", "104", "105", "106", "107", true)
450-
.Default(false);
448+
.Cases({"4", "5", "51", "6"}, true)
449+
.Cases({"102", "103", "104", "105", "106", "107"}, true)
450+
.Default(false);
451451
}
452452

453453
static bool ArchHasJMPCALL(StringRef Arch) {
454454
return llvm::StringSwitch<bool>(Arch)
455-
.Cases("3", "31", "35", "5", "51", "6", true)
456-
.Cases("102", "103", "104", "105", "106", "107", true)
457-
.Default(false);
455+
.Cases({"3", "31", "35", "5", "51", "6"}, true)
456+
.Cases({"102", "103", "104", "105", "106", "107"}, true)
457+
.Default(false);
458458
}
459459

460460
static bool ArchHas3BytePC(StringRef Arch) {

clang/lib/Driver/Job.cpp

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,24 +57,25 @@ static bool skipArgs(const char *Flag, bool HaveCrashVFS, int &SkipNum,
5757
SkipNum = 2;
5858
// These flags are all of the form -Flag <Arg> and are treated as two
5959
// arguments. Therefore, we need to skip the flag and the next argument.
60-
bool ShouldSkip = llvm::StringSwitch<bool>(Flag)
61-
.Cases("-MF", "-MT", "-MQ", "-serialize-diagnostic-file", true)
62-
.Cases("-o", "-dependency-file", true)
63-
.Cases("-fdebug-compilation-dir", "-diagnostic-log-file", true)
64-
.Cases("-dwarf-debug-flags", "-ivfsoverlay", true)
65-
.Default(false);
60+
bool ShouldSkip =
61+
llvm::StringSwitch<bool>(Flag)
62+
.Cases({"-MF", "-MT", "-MQ", "-serialize-diagnostic-file"}, true)
63+
.Cases({"-o", "-dependency-file"}, true)
64+
.Cases({"-fdebug-compilation-dir", "-diagnostic-log-file"}, true)
65+
.Cases({"-dwarf-debug-flags", "-ivfsoverlay"}, true)
66+
.Default(false);
6667
if (ShouldSkip)
6768
return true;
6869

6970
// Some include flags shouldn't be skipped if we have a crash VFS
7071
IsInclude =
7172
llvm::StringSwitch<bool>(Flag)
72-
.Cases("-include", "-header-include-file", true)
73-
.Cases("-idirafter", "-internal-isystem", "-iwithprefix", true)
74-
.Cases("-internal-externc-isystem", "-iprefix", true)
75-
.Cases("-iwithprefixbefore", "-isystem", "-iquote", true)
76-
.Cases("-isysroot", "-I", "-F", "-resource-dir", true)
77-
.Cases("-internal-iframework", "-iframework", "-include-pch", true)
73+
.Cases({"-include", "-header-include-file"}, true)
74+
.Cases({"-idirafter", "-internal-isystem", "-iwithprefix"}, true)
75+
.Cases({"-internal-externc-isystem", "-iprefix"}, true)
76+
.Cases({"-iwithprefixbefore", "-isystem", "-iquote"}, true)
77+
.Cases({"-isysroot", "-I", "-F", "-resource-dir"}, true)
78+
.Cases({"-internal-iframework", "-iframework", "-include-pch"}, true)
7879
.Default(false);
7980
if (IsInclude)
8081
return !HaveCrashVFS;
@@ -83,9 +84,9 @@ static bool skipArgs(const char *Flag, bool HaveCrashVFS, int &SkipNum,
8384

8485
// These flags are all of the form -Flag and have no second argument.
8586
ShouldSkip = llvm::StringSwitch<bool>(Flag)
86-
.Cases("-M", "-MM", "-MG", "-MP", "-MD", true)
87-
.Case("-MMD", true)
88-
.Default(false);
87+
.Cases({"-M", "-MM", "-MG", "-MP", "-MD"}, true)
88+
.Case("-MMD", true)
89+
.Default(false);
8990

9091
// Match found.
9192
SkipNum = 1;

clang/lib/Driver/XRayArgs.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,8 +105,9 @@ XRayArgs::XRayArgs(const ToolChain &TC, const ArgList &Args) {
105105
for (const auto &P : BundleParts) {
106106
// TODO: Automate the generation of the string case table.
107107
auto Valid = llvm::StringSwitch<bool>(P)
108-
.Cases("none", "all", "function", "function-entry",
109-
"function-exit", "custom", true)
108+
.Cases({"none", "all", "function", "function-entry",
109+
"function-exit", "custom"},
110+
true)
110111
.Default(false);
111112

112113
if (!Valid) {

clang/lib/Frontend/FrontendOptions.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,26 @@ using namespace clang;
1414

1515
InputKind FrontendOptions::getInputKindForExtension(StringRef Extension) {
1616
return llvm::StringSwitch<InputKind>(Extension)
17-
.Cases("ast", "pcm", InputKind(Language::Unknown, InputKind::Precompiled))
17+
.Cases({"ast", "pcm"},
18+
InputKind(Language::Unknown, InputKind::Precompiled))
1819
.Case("c", Language::C)
19-
.Cases("S", "s", Language::Asm)
20+
.Cases({"S", "s"}, Language::Asm)
2021
.Case("i", InputKind(Language::C).getPreprocessed())
2122
.Case("ii", InputKind(Language::CXX).getPreprocessed())
2223
.Case("cui", InputKind(Language::CUDA).getPreprocessed())
2324
.Case("m", Language::ObjC)
2425
.Case("mi", InputKind(Language::ObjC).getPreprocessed())
25-
.Cases("mm", "M", Language::ObjCXX)
26+
.Cases({"mm", "M"}, Language::ObjCXX)
2627
.Case("mii", InputKind(Language::ObjCXX).getPreprocessed())
27-
.Cases("C", "cc", "cp", Language::CXX)
28-
.Cases("cpp", "CPP", "c++", "cxx", "hpp", "hxx", Language::CXX)
28+
.Cases({"C", "cc", "cp"}, Language::CXX)
29+
.Cases({"cpp", "CPP", "c++", "cxx", "hpp", "hxx"}, Language::CXX)
2930
.Case("cppm", Language::CXX)
30-
.Cases("iim", "iih", InputKind(Language::CXX).getPreprocessed())
31+
.Cases({"iim", "iih"}, InputKind(Language::CXX).getPreprocessed())
3132
.Case("cl", Language::OpenCL)
3233
.Case("clcpp", Language::OpenCLCXX)
33-
.Cases("cu", "cuh", Language::CUDA)
34+
.Cases({"cu", "cuh"}, Language::CUDA)
3435
.Case("hip", Language::HIP)
35-
.Cases("ll", "bc", Language::LLVM_IR)
36+
.Cases({"ll", "bc"}, Language::LLVM_IR)
3637
.Case("hlsl", Language::HLSL)
3738
.Case("cir", Language::CIR)
3839
.Default(Language::Unknown);

clang/lib/InstallAPI/HeaderFile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ std::optional<std::string> createIncludeHeaderName(const StringRef FullPath) {
3838

3939
bool isHeaderFile(StringRef Path) {
4040
return StringSwitch<bool>(sys::path::extension(Path))
41-
.Cases(".h", ".H", ".hh", ".hpp", ".hxx", true)
41+
.Cases({".h", ".H", ".hh", ".hpp", ".hxx"}, true)
4242
.Default(false);
4343
}
4444

clang/lib/Lex/PPDirectives.cpp

Lines changed: 61 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -248,50 +248,67 @@ static bool warnByDefaultOnWrongCase(StringRef Include) {
248248

249249
// The standard C/C++ and Posix headers
250250
return llvm::StringSwitch<bool>(LowerInclude)
251-
// C library headers
252-
.Cases("assert.h", "complex.h", "ctype.h", "errno.h", "fenv.h", true)
253-
.Cases("float.h", "inttypes.h", "iso646.h", "limits.h", "locale.h", true)
254-
.Cases("math.h", "setjmp.h", "signal.h", "stdalign.h", "stdarg.h", true)
255-
.Cases("stdatomic.h", "stdbool.h", "stdckdint.h", "stdcountof.h", true)
256-
.Cases("stddef.h", "stdint.h", "stdio.h", "stdlib.h", "stdnoreturn.h", true)
257-
.Cases("string.h", "tgmath.h", "threads.h", "time.h", "uchar.h", true)
258-
.Cases("wchar.h", "wctype.h", true)
259-
260-
// C++ headers for C library facilities
261-
.Cases("cassert", "ccomplex", "cctype", "cerrno", "cfenv", true)
262-
.Cases("cfloat", "cinttypes", "ciso646", "climits", "clocale", true)
263-
.Cases("cmath", "csetjmp", "csignal", "cstdalign", "cstdarg", true)
264-
.Cases("cstdbool", "cstddef", "cstdint", "cstdio", "cstdlib", true)
265-
.Cases("cstring", "ctgmath", "ctime", "cuchar", "cwchar", true)
266-
.Case("cwctype", true)
267-
268-
// C++ library headers
269-
.Cases("algorithm", "fstream", "list", "regex", "thread", true)
270-
.Cases("array", "functional", "locale", "scoped_allocator", "tuple", true)
271-
.Cases("atomic", "future", "map", "set", "type_traits", true)
272-
.Cases("bitset", "initializer_list", "memory", "shared_mutex", "typeindex", true)
273-
.Cases("chrono", "iomanip", "mutex", "sstream", "typeinfo", true)
274-
.Cases("codecvt", "ios", "new", "stack", "unordered_map", true)
275-
.Cases("complex", "iosfwd", "numeric", "stdexcept", "unordered_set", true)
276-
.Cases("condition_variable", "iostream", "ostream", "streambuf", "utility", true)
277-
.Cases("deque", "istream", "queue", "string", "valarray", true)
278-
.Cases("exception", "iterator", "random", "strstream", "vector", true)
279-
.Cases("forward_list", "limits", "ratio", "system_error", true)
280-
281-
// POSIX headers (which aren't also C headers)
282-
.Cases("aio.h", "arpa/inet.h", "cpio.h", "dirent.h", "dlfcn.h", true)
283-
.Cases("fcntl.h", "fmtmsg.h", "fnmatch.h", "ftw.h", "glob.h", true)
284-
.Cases("grp.h", "iconv.h", "langinfo.h", "libgen.h", "monetary.h", true)
285-
.Cases("mqueue.h", "ndbm.h", "net/if.h", "netdb.h", "netinet/in.h", true)
286-
.Cases("netinet/tcp.h", "nl_types.h", "poll.h", "pthread.h", "pwd.h", true)
287-
.Cases("regex.h", "sched.h", "search.h", "semaphore.h", "spawn.h", true)
288-
.Cases("strings.h", "stropts.h", "sys/ipc.h", "sys/mman.h", "sys/msg.h", true)
289-
.Cases("sys/resource.h", "sys/select.h", "sys/sem.h", "sys/shm.h", "sys/socket.h", true)
290-
.Cases("sys/stat.h", "sys/statvfs.h", "sys/time.h", "sys/times.h", "sys/types.h", true)
291-
.Cases("sys/uio.h", "sys/un.h", "sys/utsname.h", "sys/wait.h", "syslog.h", true)
292-
.Cases("tar.h", "termios.h", "trace.h", "ulimit.h", true)
293-
.Cases("unistd.h", "utime.h", "utmpx.h", "wordexp.h", true)
294-
.Default(false);
251+
// C library headers
252+
.Cases({"assert.h", "complex.h", "ctype.h", "errno.h", "fenv.h"}, true)
253+
.Cases({"float.h", "inttypes.h", "iso646.h", "limits.h", "locale.h"},
254+
true)
255+
.Cases({"math.h", "setjmp.h", "signal.h", "stdalign.h", "stdarg.h"}, true)
256+
.Cases({"stdatomic.h", "stdbool.h", "stdckdint.h", "stdcountof.h"}, true)
257+
.Cases({"stddef.h", "stdint.h", "stdio.h", "stdlib.h", "stdnoreturn.h"},
258+
true)
259+
.Cases({"string.h", "tgmath.h", "threads.h", "time.h", "uchar.h"}, true)
260+
.Cases({"wchar.h", "wctype.h"}, true)
261+
262+
// C++ headers for C library facilities
263+
.Cases({"cassert", "ccomplex", "cctype", "cerrno", "cfenv"}, true)
264+
.Cases({"cfloat", "cinttypes", "ciso646", "climits", "clocale"}, true)
265+
.Cases({"cmath", "csetjmp", "csignal", "cstdalign", "cstdarg"}, true)
266+
.Cases({"cstdbool", "cstddef", "cstdint", "cstdio", "cstdlib"}, true)
267+
.Cases({"cstring", "ctgmath", "ctime", "cuchar", "cwchar"}, true)
268+
.Case("cwctype", true)
269+
270+
// C++ library headers
271+
.Cases({"algorithm", "fstream", "list", "regex", "thread"}, true)
272+
.Cases({"array", "functional", "locale", "scoped_allocator", "tuple"},
273+
true)
274+
.Cases({"atomic", "future", "map", "set", "type_traits"}, true)
275+
.Cases(
276+
{"bitset", "initializer_list", "memory", "shared_mutex", "typeindex"},
277+
true)
278+
.Cases({"chrono", "iomanip", "mutex", "sstream", "typeinfo"}, true)
279+
.Cases({"codecvt", "ios", "new", "stack", "unordered_map"}, true)
280+
.Cases({"complex", "iosfwd", "numeric", "stdexcept", "unordered_set"},
281+
true)
282+
.Cases(
283+
{"condition_variable", "iostream", "ostream", "streambuf", "utility"},
284+
true)
285+
.Cases({"deque", "istream", "queue", "string", "valarray"}, true)
286+
.Cases({"exception", "iterator", "random", "strstream", "vector"}, true)
287+
.Cases({"forward_list", "limits", "ratio", "system_error"}, true)
288+
289+
// POSIX headers (which aren't also C headers)
290+
.Cases({"aio.h", "arpa/inet.h", "cpio.h", "dirent.h", "dlfcn.h"}, true)
291+
.Cases({"fcntl.h", "fmtmsg.h", "fnmatch.h", "ftw.h", "glob.h"}, true)
292+
.Cases({"grp.h", "iconv.h", "langinfo.h", "libgen.h", "monetary.h"}, true)
293+
.Cases({"mqueue.h", "ndbm.h", "net/if.h", "netdb.h", "netinet/in.h"},
294+
true)
295+
.Cases({"netinet/tcp.h", "nl_types.h", "poll.h", "pthread.h", "pwd.h"},
296+
true)
297+
.Cases({"regex.h", "sched.h", "search.h", "semaphore.h", "spawn.h"}, true)
298+
.Cases({"strings.h", "stropts.h", "sys/ipc.h", "sys/mman.h", "sys/msg.h"},
299+
true)
300+
.Cases({"sys/resource.h", "sys/select.h", "sys/sem.h", "sys/shm.h",
301+
"sys/socket.h"},
302+
true)
303+
.Cases({"sys/stat.h", "sys/statvfs.h", "sys/time.h", "sys/times.h",
304+
"sys/types.h"},
305+
true)
306+
.Cases(
307+
{"sys/uio.h", "sys/un.h", "sys/utsname.h", "sys/wait.h", "syslog.h"},
308+
true)
309+
.Cases({"tar.h", "termios.h", "trace.h", "ulimit.h"}, true)
310+
.Cases({"unistd.h", "utime.h", "utmpx.h", "wordexp.h"}, true)
311+
.Default(false);
295312
}
296313

297314
/// Find a similar string in `Candidates`.

clang/lib/Sema/CheckExprLifetime.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -361,11 +361,11 @@ static bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee) {
361361
if (!Callee->getIdentifier())
362362
return false;
363363
return llvm::StringSwitch<bool>(Callee->getName())
364-
.Cases("begin", "rbegin", "cbegin", "crbegin", true)
365-
.Cases("end", "rend", "cend", "crend", true)
366-
.Cases("c_str", "data", "get", true)
364+
.Cases({"begin", "rbegin", "cbegin", "crbegin"}, true)
365+
.Cases({"end", "rend", "cend", "crend"}, true)
366+
.Cases({"c_str", "data", "get"}, true)
367367
// Map and set types.
368-
.Cases("find", "equal_range", "lower_bound", "upper_bound", true)
368+
.Cases({"find", "equal_range", "lower_bound", "upper_bound"}, true)
369369
.Default(false);
370370
}
371371
if (Callee->getReturnType()->isReferenceType()) {
@@ -377,7 +377,7 @@ static bool shouldTrackImplicitObjectArg(const CXXMethodDecl *Callee) {
377377
OO == OverloadedOperatorKind::OO_Star;
378378
}
379379
return llvm::StringSwitch<bool>(Callee->getName())
380-
.Cases("front", "back", "at", "top", "value", true)
380+
.Cases({"front", "back", "at", "top", "value"}, true)
381381
.Default(false);
382382
}
383383
return false;
@@ -394,14 +394,14 @@ static bool shouldTrackFirstArgument(const FunctionDecl *FD) {
394394
if (FD->getReturnType()->isPointerType() ||
395395
isRecordWithAttr<PointerAttr>(FD->getReturnType())) {
396396
return llvm::StringSwitch<bool>(FD->getName())
397-
.Cases("begin", "rbegin", "cbegin", "crbegin", true)
398-
.Cases("end", "rend", "cend", "crend", true)
397+
.Cases({"begin", "rbegin", "cbegin", "crbegin"}, true)
398+
.Cases({"end", "rend", "cend", "crend"}, true)
399399
.Case("data", true)
400400
.Default(false);
401401
}
402402
if (FD->getReturnType()->isReferenceType()) {
403403
return llvm::StringSwitch<bool>(FD->getName())
404-
.Cases("get", "any_cast", true)
404+
.Cases({"get", "any_cast"}, true)
405405
.Default(false);
406406
}
407407
return false;

clang/lib/Sema/SemaDeclAttr.cpp

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3629,18 +3629,20 @@ static FormatAttrKind getFormatAttrKind(StringRef Format) {
36293629
// Check for formats that get handled specially.
36303630
.Case("NSString", NSStringFormat)
36313631
.Case("CFString", CFStringFormat)
3632-
.Cases("gnu_strftime", "strftime", StrftimeFormat)
3632+
.Cases({"gnu_strftime", "strftime"}, StrftimeFormat)
36333633

36343634
// Otherwise, check for supported formats.
3635-
.Cases("gnu_scanf", "scanf", "gnu_printf", "printf", "printf0",
3636-
"gnu_strfmon", "strfmon", SupportedFormat)
3637-
.Cases("cmn_err", "vcmn_err", "zcmn_err", SupportedFormat)
3638-
.Cases("kprintf", "syslog", SupportedFormat) // OpenBSD.
3639-
.Case("freebsd_kprintf", SupportedFormat) // FreeBSD.
3635+
.Cases({"gnu_scanf", "scanf", "gnu_printf", "printf", "printf0",
3636+
"gnu_strfmon", "strfmon"},
3637+
SupportedFormat)
3638+
.Cases({"cmn_err", "vcmn_err", "zcmn_err"}, SupportedFormat)
3639+
.Cases({"kprintf", "syslog"}, SupportedFormat) // OpenBSD.
3640+
.Case("freebsd_kprintf", SupportedFormat) // FreeBSD.
36403641
.Case("os_trace", SupportedFormat)
36413642
.Case("os_log", SupportedFormat)
36423643

3643-
.Cases("gcc_diag", "gcc_cdiag", "gcc_cxxdiag", "gcc_tdiag", IgnoredFormat)
3644+
.Cases({"gcc_diag", "gcc_cdiag", "gcc_cxxdiag", "gcc_tdiag"},
3645+
IgnoredFormat)
36443646
.Default(InvalidFormat);
36453647
}
36463648

0 commit comments

Comments
 (0)