Skip to content

Commit

Permalink
[NFC] [Coroutines] Use llvm::make_scope_exit to replace self-defined …
Browse files Browse the repository at this point in the history
…RTTIHelper
  • Loading branch information
ChuanqiXu9 committed Oct 29, 2021
1 parent 6fcc19a commit bb16e83
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions llvm/lib/Transforms/Coroutines/CoroFrame.cpp
Expand Up @@ -16,6 +16,7 @@

#include "CoroInternal.h"
#include "llvm/ADT/BitVector.h"
#include "llvm/ADT/ScopeExit.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/Analysis/PtrUseVisitor.h"
#include "llvm/Analysis/StackLifetime.h"
Expand Down Expand Up @@ -576,13 +577,8 @@ void FrameTypeBuilder::addFieldForAllocas(const Function &F,
using AllocaSetType = SmallVector<AllocaInst *, 4>;
SmallVector<AllocaSetType, 4> NonOverlapedAllocas;

// We need to add field for allocas at the end of this function. However, this
// function has multiple exits, so we use this helper to avoid redundant code.
struct RTTIHelper {
std::function<void()> func;
RTTIHelper(std::function<void()> &&func) : func(func) {}
~RTTIHelper() { func(); }
} Helper([&]() {
// We need to add field for allocas at the end of this function.
auto AddFieldForAllocasAtExit = make_scope_exit([&]() {
for (auto AllocaList : NonOverlapedAllocas) {
auto *LargestAI = *AllocaList.begin();
FieldIDType Id = addFieldForAlloca(LargestAI);
Expand Down

0 comments on commit bb16e83

Please sign in to comment.