1
0
mirror of https://github.com/RPCS3/llvm-mirror.git synced 2024-11-22 18:54:02 +01:00

StringSwitch cannot be copied or moved.

...but most importantly, it cannot be used well with 'auto', because
the inferred type is StringSwitch rather than the result type. This
is a problem because StringSwitch stores addresses of temporary
values rather than copying or moving the value into its own storage.

Changing this uncovered the bug in PassBuilder, also in this patch.
Clang doesn't seem to have any occurrences of the issue.

llvm-svn: 276652
This commit is contained in:
Jordan Rose 2016-07-25 17:08:24 +00:00
parent c1d11ed3e5
commit 199957b97b
2 changed files with 14 additions and 7 deletions

View File

@ -53,6 +53,13 @@ public:
explicit StringSwitch(StringRef S)
: Str(S), Result(nullptr) { }
// StringSwitch is neither copyable nor movable.
StringSwitch(const StringSwitch &) = delete;
StringSwitch(StringSwitch &&) = delete;
void operator=(const StringSwitch &) = delete;
void operator=(StringSwitch &&) = delete;
~StringSwitch() = default;
template<unsigned N>
LLVM_ATTRIBUTE_ALWAYS_INLINE
StringSwitch& Case(const char (&S)[N], const T& Value) {

View File

@ -334,13 +334,13 @@ bool PassBuilder::parseModulePassName(ModulePassManager &MPM, StringRef Name,
return false;
assert(Matches.size() == 3 && "Must capture two matched strings!");
auto L = StringSwitch<OptimizationLevel>(Matches[2])
.Case("O0", O0)
.Case("O1", O1)
.Case("O2", O2)
.Case("O3", O3)
.Case("Os", Os)
.Case("Oz", Oz);
OptimizationLevel L = StringSwitch<OptimizationLevel>(Matches[2])
.Case("O0", O0)
.Case("O1", O1)
.Case("O2", O2)
.Case("O3", O3)
.Case("Os", Os)
.Case("Oz", Oz);
if (Matches[1] == "default") {
addPerModuleDefaultPipeline(MPM, L, DebugLogging);