[llvm] [NFC][Coroutines] Remove integer indexing in several CoroSplit loops (PR #115954)

Tyler Nowicki via llvm-commits llvm-commits at lists.llvm.org
Thu Nov 14 14:51:31 PST 2024


TylerNowicki wrote:

> For `llvm::enumerate` I think you can also have structured binding instead of `CS.value()` or `CS.index()` calls.
> 
> ```
> for (const auto &[Index, Value] : llvm::enumerate(Vec)) { ... }
> ```

Thanks! I will try this again and post another PR. I briefly tried it in one place, but it caused some build errors:

**> for (auto [Arg, Index] : llvm::enumerate(Args))**
llvm-project/llvm/lib/Transforms/Coroutines/CoroSplit.cpp:633:42: error: cannot initialize a parameter of type 'llvm::Value *' with an lvalue of type 'std::tuple_element<0, std::tuple<unsigned long, llvm::Value *&>>::type' (aka 'unsigned long')
    Agg = Builder.CreateInsertValue(Agg, Arg, Index);
                                         ^~~
/home/tyler/llvm-project/llvm/include/llvm/IR/IRBuilder.h:2549:47: note: passing argument to parameter 'Val' here
  Value *CreateInsertValue(Value *Agg, Value *Val, ArrayRef<unsigned> Idxs,

**> for (auto &[Arg, Index] : llvm::enumerate(Args))**
/home/tyler/llvm-project/llvm/lib/Transforms/Coroutines/CoroSplit.cpp:632:14: error: non-const lvalue reference to type 'enumerator_result<...>' cannot bind to a temporary of type 'enumerator_result<...>'
  for (auto &[Arg, Index] : llvm::enumerate(Args))
             ^            ~
/home/tyler/llvm-project/llvm/include/llvm/ADT/STLExtras.h:827:12: note: selected 'begin' function with iterator type 'llvm::detail::zippy<llvm::detail::zip_enumerator, llvm::detail::index_stream, llvm::SmallVector<llvm::Value *, 8> &>::iterator' (aka 'zip_enumerator<llvm::detail::index_iterator, llvm::Value **>')
  iterator begin() { return begin_impl(IndexSequence{}); }


https://github.com/llvm/llvm-project/pull/115954


More information about the llvm-commits mailing list