<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=http://email.email.llvm.org/c/eJytV1Fv2zgM_jXOi2DDlp00echD27SHA2576Q7DPQWyTcdaFSmQ5Dbprz9SttNkTXfbrYCS2BJFfvxIkUpp6sPyVgm9YUIp8-yYsFYcHDMNM09ghZIbDTUDBVvQ3rHnFiww3wILSzTJhK7DjJMvwGoDjmnjmWvFINm5TihmQQkvjXat3LGIz4O0RIOaSe1hA5ZtO-XlTgFZPzMR8QV7lr5FxayWYqON87JiW3BObABBCe8MIF5SHM3S-Ct6w-KvsPdW0C8uHXwr0c14B7XQuDsGa411KE3aUUKjTdNtWua6qh15KC2IRwb7HVS-h8-MRoviwIxF7AZx2sDAH7e3rBWud01XiN4zBcJ5ViRZwslILV1gGQk9LlbCwSmtIy0KfaMJfc5EEqWrKL3uv__ERbDbEK2dcU6WKkDDjQb5xk2oq_dG9w5F_JaBDJhJ7TGsFCoKmoaKOLVSHSgh2Bh_1EfyrdwEd4-hN_YV9Bg0soOhRN9KYErYTTAm9BvJo_Uh7hINlYewpLttidtQcBRKWJ-mcrsbt5FgY-z2JABIvgh0ZFmyJ8rFk5E1hhHjdEbdrdnupMKdd_udMhYflNSPUX7NWu93Dh8ifo9jY-rSKJ8Yu8G3F_y0_7zo-bd9UZ6qiziNB9PZCsLeMPolTLAwqv7dHzADoWHO267y7Dpj0dUNq_C0MBFNb7JouoryG5xc0dp6Lby3suw8rNeU3HyOU31UwgTOLIaR31y2wM8tzE8t8A-xkJ9bWJxayP-XhZHWHM1IPHCf__60vvvr7tPd5y8PjJ_K4BkHq4krzDxk7-ZUdADC-mCGFBmOPc72CTUWrHNtnLTx_9ZmHjHZQ2nC8uLOdeSkI_9dRP33-oHKT7UWzoH1Q_k0DeU7eY2ZHvEsylfsOI8J-Lp0fUYgVYGI8zAWp2iGI-YuuvVDCKG-of0LEPjPQPgJE_n7XuYf5-XxuL493seaIfWTqUI3eHvWq6A8rqqMxY07aC_2sdFYTn-hJ7F4zyoWXwRxF1oRVUpoxZPEivMdhtWb_uioSg51-bWRk9tEI9VR7EZjB3i_HcuTwv8W13Xlqcu_h2rgzlE7ohbTdEodLvR09wPakTCHnCO-xgyNfmD7qe_i71Xe_rWXHZVkRZImKan5ruAjpK5MKrPFF6Wexp94Z803ZD5BAdZAnuZXaZmmV3AFjcjKOmvyhciz-aLkVwIKmDZVCYQp2P5CbdBTe9nPZ-tZEXf6UZtnHWPX6fbxRneDXIttu2ZbU4Miaezqcj82e-cxg6BeSSKXktns8IzcP2PzKw12u_vgYdyiBnwppe433psOu2OFUrIWHkLJkb2yMYdJWecsuSpLIqGq8HuA-gqR3w_uPGAahST8AF23R2Ah32gTKkmoJhTpdlZ8Z_FHQseAT-plXi8wIBPR4aXOLjGkWFBiC5TbdmfB473LTzqrlr8WfnyVznXg8GGaF1kxaZc8TYu6KtJFnRYlL_g0z5piBqKaZemiLJuJEiUot8ROgMUoBAntNdYgFl1TfZquJr8PRCIQztOMz9JZMS94ssggyxfVXGTNfFqlC6QKtkKqhPTQjWZil0Fl2W0cLirp8J51XMQiTC0aAm5E6KVXcPHPQjjGF_4uMLonnJSavsCc1ZXXq2R_BaaEov6nI37lJ8HDZXDvXyRxAec>53414</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Clang allows arrays with overaligned element types with size not a multiple of alignment where GCC doesn't
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang:frontend
      </td>
    </tr>

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

    <tr>
      <th>Reporter</th>
      <td>
          hubert-reinterpretcast
      </td>
    </tr>
</table>

<pre>
    Clang allows arrays of overaligned elements where the alignment and the size does not share the usual relationship (size is an integer multiple of the alignment) with no diagnostic message whatsoever (`-Wall -Wextra -Weverything -pedantic-errors`) even though such arrays break expectations one way or another and GCC has (since at least 4.1.2) disallowed at least cases where the size is less then the alignment.

In terms of possible ways to realize such an array, either the elements are not necessarily all aligned to the higher alignment or the size of the array must be larger than the size of the elements multiplied by the number of elements. Clang implements the former and GCC (as of 11.x) avoids both.

Compiler Explorer link: https://godbolt.org/z/hYzn8jx4b

**Source:**
```c
typedef struct A1 { char a[1]; } A1 __attribute__((__aligned__(8)));
typedef struct A2 { char a[8]; } A2 __attribute__((__aligned__(8)));
typedef struct A3 { char a[9]; } A3 __attribute__((__aligned__(8)));

#define NUM_ELEMENTS 2

extern A1 arr1[NUM_ELEMENTS];  // GCC errors; Clang does not
extern A2 arr2[NUM_ELEMENTS];  // GCC okay with this
extern A3 arr3[NUM_ELEMENTS];  // GCC errors; Clang does not

_Static_assert(sizeof(arr1) != sizeof(*arr1) * NUM_ELEMENTS, "");  // Clang is okay with this
_Static_assert(sizeof(arr2) == sizeof(*arr2) * NUM_ELEMENTS, "");
_Static_assert(sizeof(arr3) != sizeof(*arr3) * NUM_ELEMENTS, "");  // Clang is okay with this
```

**Compiler invocation:**
`clang -cc1 -fsyntax-only -Wall -Wextra -Weverything -pedantic-errors -x c -`

**Expected behaviour:**
Diagnostic messages for array elements with sizes that are not an integer multiple of their alignment

**Actual behaviour:**
Compiles successfully with no diagnostics

**Compiler version info (`clang -v`):**
```
clang version 14.0.0 (https://github.com/llvm/llvm-project.git fe30370b007e7efa1bd1f39a3189b27ae4e5fcbe)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /opt/wandbox/clang-head/bin
Found candidate GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Selected GCC installation: /usr/lib/gcc/x86_64-linux-gnu/9
Candidate multilib: .;@m64
Selected multilib: .;@m64
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJytVktv2zgQ_jXyhZAgUfLr4EMSJ4sFtr2ki6Ing5JGFhuaNEgqsfvrd4aSHLtxuu1uAfkhcjjzzTcvlqY-ru6U0FsmlDIvjglrxdEx0zDzDFYoudVQM1CwA-0de2nBAvMtsLBFi0zoOqw4-Q1YbcAxbTxzrRgkO9cJxSwo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