[libcxx-dev] deque, block_size, __add_back_capacity

Jason MacDonald via libcxx-dev libcxx-dev at lists.llvm.org
Tue Apr 2 08:55:04 PDT 2019


Hello all,

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

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){}
}


Digging in to the problem more, I found that if I call resize(1) first, push_back will work just fine thereafter. I found there are differences between __add_back_capacity() vs __add_back_capacity(1). Should there be?
Example, look at comments for output result:
#define protected public
#define private public
#include <deque>

struct s {
      char d[65];
};

int main()
{
      {
            std::deque<s> test;
            test.resize(1, s());
            int back_spare = test.__back_spare(); // 0
            int cap = test.__capacity(); // 1
      }

      {
            std::deque<s> test;
            test.push_back(s());
            int back_spare = test.__back_spare(); // -1
            int cap = test.__capacity(); // 0
      }

      {
            std::deque<s> test;
            test.__add_back_capacity(1);
            int back_spare = test.__back_spare(); // 1
            int cap = test.__capacity(); // 1
      }

      {
            std::deque<s> test;
            test.__add_back_capacity();
            int back_spare = test.__back_spare(); // 0
            int cap = test.__capacity(); // 0
      }
      while (1){}
}

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?

Jason
This email and any files transmitted with it from Charles Machine Works are confidential and intended solely for the use of the individual or entity to which they are addressed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/libcxx-dev/attachments/20190402/9f768e07/attachment-0001.html>


More information about the libcxx-dev mailing list