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

    <tr>
        <th>Summary</th>
        <td>
            Increased sizeof of std::atomic with enum as type and -ffreestanding
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

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

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

<pre>
    We have faced with a problem of increased sizeof of std::atomic with enum as type with -ffreestanding that leads to broken class layout.
This problem reproduce only with -ffreestanding and C++11/14 with C++17 and higher problem also doesn't reproduce. It is also required to use libc++ standard library because with libstdc++ this issue doesn't reproduce.

We faced with this problem with: Apple clang version 13.1.6 (clang-1316.0.21.2.5)
But this also reproduced on godbolt with clang 14.0.0
There are compilation command and reduced reproducer:
`clang++ -ffreestanding -std=c++11 -stdlib=libstdc++`
```cpp
#include <atomic>
#include <cstdint>

struct test_struct {
    enum class state : std::uint8_t {
        created
    };
    std::atomic<state> my_state;
};

template <std::size_t S>
struct print;

print<sizeof(test_struct::state)> print_enum_size;
print<sizeof(test_struct)> print_size;
static_assert(sizeof(test_struct) == 1, "Incorrect sizeof");
```
The problem that `sizeof(std::atomic<state>) == 2` but the `sizeof(state) == 1`
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJydVUuPozgQ_jVwsRoZQ3gcOHQn01Kfd6U5RgYqwTsGM7bpUfbXb9km5KGeOSwy4NTjq6qPKqdV_aX5DmTgn0BOvIOe_BJ2IJzMWrUSRqJOREydBm5QZ8S_gAJcxvZR9oqLWzWKLnjBtIyEG2IvMwTJy-mkAYzlUy-mM7EDt0QC79FGkVarHzCRTnJjiOQXtdgkooeIvv49CLNloAF3_dIBUZO8fImLL7KP2BuuNI3Ye5oHs6us9BaDOA-gN1wujSK9AjNFrLS3MAn5sATje72Gn4vQWDrmuxggUrRdAC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