Skip to content

_LIBCPP_ABI_BOUNDED_ITERATORS_IN_VECTOR is not optimized out in range-for loops #101370

Open
@davidben

Description

@davidben

Filing this since we lost track of #78929 (comment) (oops)

#78929 had to round the bounds on std::vector up from size() to capacity() because the standard promises more permissive iterator invalidation. This had the side effect of making the checks harder to optimize.

See this compiler output for a demonstration:
https://godbolt.org/z/9c688Moab

I think this will require both STL and compiler improvements to fix. There are a couple type-level invariants that the compiler needs to be informed of. Those we can add with _LIBCPP_ASSUME after #91801 lands.

However, that is not sufficient. It also requires Clang to perform some loop reasoning:
https://godbolt.org/z/h78T188r9

I'll file a separate bug for that one. One that is fixed and #91801 lands, I can add the missing assumptions to libc++. (Happy to add them now, but since we're missing a compiler check, it'd be speculative without the compiler half.)

(CC @ldionne @var-const @danakj)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions