Skip to content

Commit

Permalink
[NFC] Use fold expressions to replace discarded initializer_lists (#8…
Browse files Browse the repository at this point in the history
  • Loading branch information
MagentaTreehouse committed Mar 2, 2024
1 parent 60fbd60 commit f505a92
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 25 deletions.
5 changes: 1 addition & 4 deletions clang/lib/AST/Interp/ByteCodeEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,7 @@ bool ByteCodeEmitter::emitOp(Opcode Op, const Tys &... Args, const SourceInfo &S
if (SI)
SrcMap.emplace_back(Code.size(), SI);

// The initializer list forces the expression to be evaluated
// for each argument in the variadic template, in order.
(void)std::initializer_list<int>{(emit(P, Code, Args, Success), 0)...};

(..., emit(P, Code, Args, Success));
return Success;
}

Expand Down
9 changes: 2 additions & 7 deletions llvm/lib/Target/AArch64/AArch64SLSHardening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,20 +412,15 @@ class AArch64IndirectThunks : public MachineFunctionPass {
private:
std::tuple<SLSBLRThunkInserter> TIs;

// FIXME: When LLVM moves to C++17, these can become folds
template <typename... ThunkInserterT>
static void initTIs(Module &M,
std::tuple<ThunkInserterT...> &ThunkInserters) {
(void)std::initializer_list<int>{
(std::get<ThunkInserterT>(ThunkInserters).init(M), 0)...};
(..., std::get<ThunkInserterT>(ThunkInserters).init(M));
}
template <typename... ThunkInserterT>
static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
std::tuple<ThunkInserterT...> &ThunkInserters) {
bool Modified = false;
(void)std::initializer_list<int>{
Modified |= std::get<ThunkInserterT>(ThunkInserters).run(MMI, MF)...};
return Modified;
return (0 | ... | std::get<ThunkInserterT>(ThunkInserters).run(MMI, MF));
}
};

Expand Down
9 changes: 2 additions & 7 deletions llvm/lib/Target/ARM/ARMSLSHardening.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -404,20 +404,15 @@ class ARMIndirectThunks : public MachineFunctionPass {
private:
std::tuple<SLSBLRThunkInserter> TIs;

// FIXME: When LLVM moves to C++17, these can become folds
template <typename... ThunkInserterT>
static void initTIs(Module &M,
std::tuple<ThunkInserterT...> &ThunkInserters) {
(void)std::initializer_list<int>{
(std::get<ThunkInserterT>(ThunkInserters).init(M), 0)...};
(..., std::get<ThunkInserterT>(ThunkInserters).init(M));
}
template <typename... ThunkInserterT>
static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
std::tuple<ThunkInserterT...> &ThunkInserters) {
bool Modified = false;
(void)std::initializer_list<int>{
Modified |= std::get<ThunkInserterT>(ThunkInserters).run(MMI, MF)...};
return Modified;
return (0 | ... | std::get<ThunkInserterT>(ThunkInserters).run(MMI, MF));
}
};

Expand Down
9 changes: 2 additions & 7 deletions llvm/lib/Target/X86/X86IndirectThunks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,20 +118,15 @@ class X86IndirectThunks : public MachineFunctionPass {
private:
std::tuple<RetpolineThunkInserter, LVIThunkInserter> TIs;

// FIXME: When LLVM moves to C++17, these can become folds
template <typename... ThunkInserterT>
static void initTIs(Module &M,
std::tuple<ThunkInserterT...> &ThunkInserters) {
(void)std::initializer_list<int>{
(std::get<ThunkInserterT>(ThunkInserters).init(M), 0)...};
(..., std::get<ThunkInserterT>(ThunkInserters).init(M));
}
template <typename... ThunkInserterT>
static bool runTIs(MachineModuleInfo &MMI, MachineFunction &MF,
std::tuple<ThunkInserterT...> &ThunkInserters) {
bool Modified = false;
(void)std::initializer_list<int>{
Modified |= std::get<ThunkInserterT>(ThunkInserters).run(MMI, MF)...};
return Modified;
return (0 | ... | std::get<ThunkInserterT>(ThunkInserters).run(MMI, MF));
}
};

Expand Down

0 comments on commit f505a92

Please sign in to comment.