This is an archive of the discontinued LLVM Phabricator instance.

[BOLT] Towards FunctionLayout const-correctness
ClosedPublic

Authored by FPar on Aug 17 2022, 11:26 AM.

Details

Summary

A const-qualified reference to function layout allows accessing
non-const qualified basic blocks on a const-qualified function. This
patch adds or removes const-qualifiers where necessary to indicate where
basic blocks are used in a non-const manner.

Diff Detail

Event Timeline

FPar created this revision.Aug 17 2022, 11:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2022, 11:26 AM
Herald added a subscriber: ayermolo. · View Herald Transcript
FPar requested review of this revision.Aug 17 2022, 11:26 AM
Herald added a project: Restricted Project. · View Herald TranscriptAug 17 2022, 11:26 AM
This revision is now accepted and ready to land.Aug 22 2022, 12:59 PM
This revision was automatically updated to reflect the committed changes.
haowei added a subscriber: haowei.Aug 24 2022, 10:44 AM

We are seeing clang build warnings and errors after this patch was landed. Error message:

In file included from /b/s/w/ir/x/w/llvm-llvm-project/bolt/include/bolt/Core/BinaryBasicBlock.h:18:
/b/s/w/ir/x/w/llvm-llvm-project/bolt/include/bolt/Core/FunctionLayout.h:307:62: error: no viable conversion from returned value of type 'reverse_iterator<const_iterator>' to function return type 'reverse_iterator<block_const_iterator>'
  block_const_reverse_iterator block_rbegin() const { return Blocks.rbegin(); }
                                                             ^~~~~~~~~~~~~~~
/b/s/w/ir/x/w/cipd/bin/../include/c++/v1/__iterator/reverse_iterator.h:43:28: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const_reverse_iterator' (aka 'reverse_iterator<llvm::bolt::BinaryBasicBlock *const *>') to 'const std::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
                           ^
/b/s/w/ir/x/w/cipd/bin/../include/c++/v1/__iterator/reverse_iterator.h:43:28: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const_reverse_iterator' (aka 'reverse_iterator<llvm::bolt::BinaryBasicBlock *const *>') to 'std::reverse_iterator<llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>> &&' for 1st argument
/b/s/w/ir/x/w/cipd/bin/../include/c++/v1/__iterator/reverse_iterator.h:119: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)
    ^
/b/s/w/ir/x/w/cipd/bin/../include/c++/v1/__iterator/reverse_iterator.h:113:14: note: explicit constructor is not a candidate
    explicit reverse_iterator(_Iter __x) : current(__x) {}

Could you take a look? If it takes a while to fix. Could you revert your change please?

Full build task: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8804929257456173105/overview
Full build step output: https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8804929257456173105/+/u/clang/build/stdout

FPar added a comment.Aug 24 2022, 10:46 AM

We are seeing clang build warnings and errors after this patch was landed. Error message:

In file included from /b/s/w/ir/x/w/llvm-llvm-project/bolt/include/bolt/Core/BinaryBasicBlock.h:18:
/b/s/w/ir/x/w/llvm-llvm-project/bolt/include/bolt/Core/FunctionLayout.h:307:62: error: no viable conversion from returned value of type 'reverse_iterator<const_iterator>' to function return type 'reverse_iterator<block_const_iterator>'
  block_const_reverse_iterator block_rbegin() const { return Blocks.rbegin(); }
                                                             ^~~~~~~~~~~~~~~
/b/s/w/ir/x/w/cipd/bin/../include/c++/v1/__iterator/reverse_iterator.h:43:28: note: candidate constructor (the implicit copy constructor) not viable: no known conversion from 'const_reverse_iterator' (aka 'reverse_iterator<llvm::bolt::BinaryBasicBlock *const *>') to 'const std::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
                           ^
/b/s/w/ir/x/w/cipd/bin/../include/c++/v1/__iterator/reverse_iterator.h:43:28: note: candidate constructor (the implicit move constructor) not viable: no known conversion from 'const_reverse_iterator' (aka 'reverse_iterator<llvm::bolt::BinaryBasicBlock *const *>') to 'std::reverse_iterator<llvm::pointer_iterator<llvm::pointee_iterator<llvm::bolt::BinaryBasicBlock *const *, const llvm::bolt::BinaryBasicBlock>, const llvm::bolt::BinaryBasicBlock *>> &&' for 1st argument
/b/s/w/ir/x/w/cipd/bin/../include/c++/v1/__iterator/reverse_iterator.h:119: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)
    ^
/b/s/w/ir/x/w/cipd/bin/../include/c++/v1/__iterator/reverse_iterator.h:113:14: note: explicit constructor is not a candidate
    explicit reverse_iterator(_Iter __x) : current(__x) {}

Could you take a look? If it takes a while to fix. Could you revert your change please?

Full build task: https://ci.chromium.org/ui/p/fuchsia/builders/toolchain.ci/clang-linux-x64/b8804929257456173105/overview
Full build step output: https://logs.chromium.org/logs/fuchsia/buildbucket/cr-buildbucket/8804929257456173105/+/u/clang/build/stdout

Sorry, I'll revert it.

FPar reopened this revision.Aug 24 2022, 1:42 PM
This revision is now accepted and ready to land.Aug 24 2022, 1:42 PM
FPar updated this revision to Diff 455356.Aug 24 2022, 1:42 PM

Fix iterator conversion build failure

rafauler accepted this revision.Aug 24 2022, 3:43 PM
This revision was automatically updated to reflect the committed changes.