[PATCH] D12247: [libc++] remove possible trailing padding from aligned_storage

Yiran Wang via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 24 13:52:48 PDT 2015


yiranwang added a comment.

A test case is as following. It has to be build by GCC 4.9 -O3 (maybe or later), with latest libc++, and for AARCH64+ANDROID target. 
AARCH64 requires 128 bit alignment for aligned_storage and 64 bit pointers, while gcc 4.9 alias analysis will do field-sensitive points-to analysis. But this could happen for other ISA+ABI.
The fundamental issue is that for this combination, std::function has member __buf_ declared as 
aligned_storage<3*sizoef(void*)>::type __buf_;
Basically, it is
aligned_storage<24>::type;
This will generate aligned_storage of, _Len==24 and _Align==16;
While std::function will use the __buf_ to sizeof(__buf_) bytes (at line 1593 and 1628 of <functional>), which is 32. Basically, the pointer to "tbool' will be stored at "&__buf_+24". 
This is not a well defined memory area, and GCC alias analysis is going to ignore the "ESCAPE" of address of "tbool". Basically, the function "test_simple" would always return "false".

#include <functional>
extern void external_test(std::function<bool()>fn);
extern bool test_simple(){

  bool tbool = false;
  int a, b;
  external_test([&a, &b, &tbool](){
    tbool = true;
    return true;
  });
  return tbool;

}


http://reviews.llvm.org/D12247





More information about the cfe-commits mailing list