[llvm-bugs] [Bug 31849] New: Improper alignment in pointer cast in unordered_map of std::aligned_storage

via llvm-bugs llvm-bugs at lists.llvm.org
Thu Feb 2 09:21:20 PST 2017


https://llvm.org/bugs/show_bug.cgi?id=31849

            Bug ID: 31849
           Summary: Improper alignment in pointer cast in unordered_map of
                    std::aligned_storage
           Product: libc++
           Version: 3.9
          Hardware: PC
                OS: Linux
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david at doublewise.net
                CC: llvm-bugs at lists.llvm.org, mclow.lists at gmail.com
    Classification: Unclassified

This might be related to https://llvm.org/bugs/show_bug.cgi?id=22634

#include <unordered_map>

struct S {
    void emplace() {
        m_map.emplace(
            std::piecewise_construct,
            std::forward_as_tuple(0),
            std::forward_as_tuple()
        );
    }
private:
    std::int64_t x;
    // std::int64_t y;
    using mapped_type = typename std::aligned_storage<3*sizeof(void*)>::type;
    std::unordered_map<int, mapped_type> m_map;
};

int main() {
    S s;
    s.emplace();
}




clang++ -stdlib=libc++ -fsanitize=address -fsanitize=undefined -std=c++1z
main.cpp && ./a.out


include/c++/v1/__hash_table:2152:29: runtime error: downcast of misaligned
address 0x7ff2d6c62f8 for type
'std::__1::__hash_node<std::__1::__hash_value_type<int,
std::__1::aligned_storage<24, 16>::type, void *>', which requires 16 byte
alignment



However, unlike with bug 22634 this can result from no particular use of
alignment specifiers in user code. This exact sanitizer error can also be
triggered by using std::function<anything(anything...)> as the mapped_type, as
it contains std::aligned_storage in it.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20170202/b442bec0/attachment.html>


More information about the llvm-bugs mailing list