[libcxx-dev] deque, block_size, __add_back_capacity

Marshall Clow via libcxx-dev libcxx-dev at lists.llvm.org
Tue Apr 2 14:04:23 PDT 2019


On Tue, Apr 2, 2019 at 8:55 AM Jason MacDonald via libcxx-dev <
libcxx-dev at lists.llvm.org> wrote:

> Hello all,
>
>
>
> First, apologizes if this is the wrong mailing list for this discussion.
>

This is not a terrible place.


>  I am using the TI 18.1.5 compiler to compile for the TM4C1294NCPDT chip.
> A longer/better explanation of my problems might be obtained from the TI
> forums of my issue, which didn’t gain traction:
> https://e2e.ti.com/support/tools/ccs/f/81/t/787948
>
> So I am trying to go upstream for more discussion.
>
>
>
> Summary of my problem: Using deque::push_back on structures over 64 bytes
> will cause a crash.
>
> Example code:
>
> #include <deque>
>
> struct s {
>
>     char d[65];
>
> };
>
> int main()
>
> {
>
>     int size = sizeof(s);
>
>
>
>     std::deque<s> test;
>
>     test.push_back(s());
>
>     test.push_back(s()); // will crash here
>
>     while (1){}
>
> }
>

I tried this on my desktop, and it did not crash.
I also turned on address sanitizer to see if there might be an
out-of-bounds read or write, but it didn't report any.

I tried your second program (again, on my desktop), and added some printf
statements, and I got:

back_spare  cap
61  62
61  62
62  62
62  62

TI’s implementation of the struct __deque_block_size allows a minimum size
> of 1. Not sure if this should cause a problem or not.
>
> TI:
>
> template <class _ValueType, class _DiffType>
>
> struct __deque_block_size {
>
>   enum __attribute__((__packed__)) { _MAX_BYTES = 32 * sizeof(void*) };
>
>   static const _DiffType value = sizeof(_ValueType) < _MAX_BYTES ?
> (_MAX_BYTES / sizeof(_ValueType)) : 1;
>
> };
>
>
>
> So, is this a problem in LLVM’s __add_back_capacity() or TI’s block_size?
>

I'm suspecting TI's block_size.

here's the one from trunk:

template <class _ValueType, class _DiffType>
struct __deque_block_size {
  static const _DiffType value = sizeof(_ValueType) < 256 ? 4096 /
sizeof(_ValueType) : 16;
};

Note that it never is smaller than 16.

-- Marshall
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20190402/42f9df9b/attachment.html>


More information about the libcxx-dev mailing list