<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/122470>122470</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            TypeSanitizer errors with global or static STL container
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            compiler-rt:tysan
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          firewave
      </td>
    </tr>
</table>

<pre>
    ```cpp
#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.
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJzkl0tv4zYQxz8NfRnY4EPPgw5OIgMBim2QBCjQi0BRlM0tLaok5cT59AVtZ-NH4kXQpttmAUOyh3-ZnJkfhxrunJp3UhYovkDx1YgPfmFs0SorH_hKjmrTrAuU4O1H9D3CU0SZ6oQeGgmIXQ6dsY20sqmc9IiVQYCnznOvBAjTOQ_ON4hNEZseaS9VF54AVznELrYPqs7DkqsO0QzRPNj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