Use container's reverse iterators
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
Can you please add a unit test? It's a bit strange that there was this issue and we didn't see it – or were these reverse iterators unused?
@Amir Currently these iterators are almost unused - I see them used only under opts::ReportBadLayout right now. After I've tried to use them by my self I've found out that there are some problems with them, e.g. BBs hasInstructions() assert appeared. Anyway it does not look like it is right to use end() block iterator as an reverse begin...
This doesn't build: http://45.33.8.238/macm1/50229/step_4.txt
FAILED: obj/bolt/lib/Passes/Passes.MCF.o /Users/thakis/src/depot_tools/.cipd_bin/gomacc ../../chromeclang/bin/clang++ -MMD -MF obj/bolt/lib/Passes/Passes.MCF.o.d -o obj/bolt/lib/Passes/Passes.MCF.o -c ../../bolt/lib/Passes/MCF.cpp -I../../llvm/include -Igen/llvm/include -I../../bolt/include -Igen/bolt/include -mmacos-version-min=10.10 -O3 -fdiagnostics-color -Wall -Wextra -Wno-unused-parameter -Wdelete-non-virtual-dtor -Wstring-conversion -Wno-nonportable-include-path -no-canonical-prefixes -Werror=date-time -isysroot ../../sysroot/MacOSX.sdk -Wpoison-system-directories -fPIC -Wcovered-switch-default -std=c++17 -fvisibility-inlines-hidden -fno-exceptions -fno-rtti warning: include location '/usr/local/include' is unsafe for cross-compilation [-Wpoison-system-directories] In file included from ../../bolt/lib/Passes/MCF.cpp:14: In file included from ../../bolt/include/bolt/Core/BinaryFunction.h:28: In file included from ../../bolt/include/bolt/Core/BinaryBasicBlock.h:18: ../../bolt/include/bolt/Core/FunctionLayout.h:309:12: error: no matching conversion for functional-style cast from 'llvm::SmallVectorTemplateCommon<llvm::bolt::BinaryBasicBlock *>::const_reverse_iterator' (aka 'reverse_iterator<llvm::bolt::BinaryBasicBlock *const *>') to 'llvm::bolt::FunctionLayout::block_const_reverse_iterator' (aka 'reverse_iterator<pointer_iterator<pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>>') return block_const_reverse_iterator(Blocks.rbegin()); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:34:28: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'reverse_iterator<llvm::SmallVectorTemplateCommon<llvm::bolt::BinaryBasicBlock *>::const_iterator>' to 'const reverse_iterator<llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>>' for 1st argument class _LIBCPP_TEMPLATE_VIS reverse_iterator ^ ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:34:28: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'reverse_iterator<llvm::SmallVectorTemplateCommon<llvm::bolt::BinaryBasicBlock *>::const_iterator>' to 'reverse_iterator<llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>>' for 1st argument ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:76:14: note: candidate constructor not viable: no known conversion from 'llvm::SmallVectorTemplateCommon<llvm::bolt::BinaryBasicBlock *>::const_reverse_iterator' (aka 'reverse_iterator<llvm::bolt::BinaryBasicBlock *const *>') to 'llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>' for 1st argument explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} ^ ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:82:5: note: candidate template ignored: requirement 'is_convertible<llvm::bolt::BinaryBasicBlock *const *const &, llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>>::value' was not satisfied [with _Up = llvm::bolt::BinaryBasicBlock *const *] reverse_iterator(const reverse_iterator<_Up>& __u) ^ ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:73:5: note: candidate constructor not viable: requires 0 arguments, but 1 was provided reverse_iterator() : __t(), current() {} ^ In file included from ../../bolt/lib/Passes/MCF.cpp:14: In file included from ../../bolt/include/bolt/Core/BinaryFunction.h:28: In file included from ../../bolt/include/bolt/Core/BinaryBasicBlock.h:18: ../../bolt/include/bolt/Core/FunctionLayout.h:315:12: error: no matching conversion for functional-style cast from 'llvm::SmallVectorTemplateCommon<llvm::bolt::BinaryBasicBlock *>::const_reverse_iterator' (aka 'reverse_iterator<llvm::bolt::BinaryBasicBlock *const *>') to 'llvm::bolt::FunctionLayout::block_const_reverse_iterator' (aka 'reverse_iterator<pointer_iterator<pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>>') return block_const_reverse_iterator(Blocks.rend()); ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:34:28: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'reverse_iterator<llvm::SmallVectorTemplateCommon<llvm::bolt::BinaryBasicBlock *>::const_iterator>' to 'const reverse_iterator<llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>>' for 1st argument class _LIBCPP_TEMPLATE_VIS reverse_iterator ^ ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:34:28: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'reverse_iterator<llvm::SmallVectorTemplateCommon<llvm::bolt::BinaryBasicBlock *>::const_iterator>' to 'reverse_iterator<llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>>' for 1st argument ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:76:14: note: candidate constructor not viable: no known conversion from 'llvm::SmallVectorTemplateCommon<llvm::bolt::BinaryBasicBlock *>::const_reverse_iterator' (aka 'reverse_iterator<llvm::bolt::BinaryBasicBlock *const *>') to 'llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>' for 1st argument explicit reverse_iterator(_Iter __x) : __t(__x), current(__x) {} ^ ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:82:5: note: candidate template ignored: requirement 'is_convertible<llvm::bolt::BinaryBasicBlock *const *const &, llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>>::value' was not satisfied [with _Up = llvm::bolt::BinaryBasicBlock *const *] reverse_iterator(const reverse_iterator<_Up>& __u) ^ ../../chromeclang/bin/../include/c++/v1/__iterator/reverse_iterator.h:73:5: note: candidate constructor not viable: requires 0 arguments, but 1 was provided reverse_iterator() : __t(), current() {} ^ 1 warning and 2 errors generated.
Reverting for now.
Actually I'm not quite sure why this problem appeared on osx. @Amir Have you got any ideas?
Thanks @Amir I'm not that deep in the C++ to be honest, but it looks OK. But I still have some problems using these iterators with this patch, resulting in SIGSEGV :( I've found out that if I replace (addition to this patch):
- In class FunctionFragment iterator types to
using iterator = BasicBlockListType::iterator;
using const_iterator = BasicBlockListType::const_iterator; - In class FunctionLayout
using block_const_iterator = BasicBlockListType::const_iterator;
Everything works fine. What do you think about it?
I'm not an expert either. Your proposed changes make sense to me, submit them as a diff and I'll test it.
clang-format not found in user’s local PATH; not linting file.