Skip to content

TypeSanitizer errors with global or static STL container #122470

@firewave

Description

@firewave
#include <unordered_set>

static const std::unordered_set<int> s_s;

int main()
{
}
==1==ERROR: TypeSanitizer: type-aliasing-violation on address 0x6166d60cfca8 (pc 0x6166d5769c55 bp 0x7fffc9c45f90 sp 0x7fffc9c45f20 tid 1)
WRITE of size 8 at 0x6166d60cfca8 with type long (in std::__1::__bucket_list_deallocator<std::__1::allocator<std::__1::__hash_node_base<std::__1::__hash_node<int, void*>*>*>> at offset 0) accesses part of an existing object of type std::__1::unordered_set<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>> that starts at offset -8
    #0 0x6166d5769c54  (/app/output.s+0x2dc54)

==1==ERROR: TypeSanitizer: type-aliasing-violation on address 0x6166d60cfcb0 (pc 0x6166d5769385 bp 0x7fffc9c46000 sp 0x7fffc9c45f90 tid 1)
WRITE of size 8 at 0x6166d60cfcb0 with type p1 _ZTSNSt3__116__hash_node_baseIPNS_11__hash_nodeIiPvEEEE (in std::__1::__hash_node_base<std::__1::__hash_node<int, void*>*> at offset 0) accesses part of an existing object of type std::__1::unordered_set<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>> that starts at offset -16
    #0 0x6166d5769384  (/app/output.s+0x2d384)

==1==ERROR: TypeSanitizer: type-aliasing-violation on address 0x6166d60cfcb8 (pc 0x6166d57687bf bp 0x7fffc9c46070 sp 0x7fffc9c46000 tid 1)
WRITE of size 8 at 0x6166d60cfcb8 with type long (in std::__1::__hash_table<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>> at offset 24) accesses part of an existing object of type std::__1::unordered_set<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>> that starts at offset -24
    #0 0x6166d57687be  (/app/output.s+0x2c7be)

==1==ERROR: TypeSanitizer: type-aliasing-violation on address 0x6166d60cfcc0 (pc 0x6166d5768920 bp 0x7fffc9c46070 sp 0x7fffc9c46000 tid 1)
WRITE of size 4 at 0x6166d60cfcc0 with type float (in std::__1::__hash_table<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>> at offset 32) accesses part of an existing object of type std::__1::unordered_set<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>> that starts at offset -32
    #0 0x6166d576891f  (/app/output.s+0x2c91f)

==1==ERROR: TypeSanitizer: type-aliasing-violation on address 0x6166d60cfcb0 (pc 0x6166d576ac5d bp 0x7fffc9c45fa0 sp 0x7fffc9c45f30 tid 1)
READ of size 8 at 0x6166d60cfcb0 with type p1 _ZTSNSt3__116__hash_node_baseIPNS_11__hash_nodeIiPvEEEE (in std::__1::__hash_table<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>> at offset 16) accesses part of an existing object of type std::__1::unordered_set<int, std::__1::hash<int>, std::__1::equal_to<int>, std::__1::allocator<int>> that starts at offset -16
    #0 0x6166d576ac5c  (/app/output.s+0x2ec5c)

https://godbolt.org/z/sjnE1974P

Errors will also be reported if you remove the static or if you move the static declaration into the function.

A local declaration is not causing any errors.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions