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

    <tr>
        <th>Summary</th>
        <td>
            False positive for `-Walign-mismatch` with C `aligned` attribute in Clang
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
      </td>
    </tr>

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

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

<pre>
    Example code:

```c
typedef char char_aligned2 __attribute__((aligned(2)));
int foo(char_aligned2 *p) {
   return *p + 1;
}
int bar(void) {
   char x[] __attribute__((aligned(2))) = "foo";
   return foo(x);
}
```

Result:

```
$ clang asdf.c -Weverything -Wno-missing-prototypes -S -emit-llvm
asdf.c:7:15: warning: passing 1-byte aligned argument to 2-byte aligned parameter 1 of 'foo' may result in an unaligned pointer access [-Walign-mismatch]
   return foo(x);
              ^
1 warning generated.
```

The emitted code seems to do what I expect, in that `foo` does a `load` with `align 2` and `bar` does an `alloca` with `align 2`, so it all seems to work out correctly in the end but the diagnostic doesn't match the codegen: it's not a "1-byte aligned argument".

A `(void*)` cast is a workaround but of course effectively disables the diagnostic.

Tested with 14.0.6:

```
$ clang --version
clang version 14.0.6
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyNVMFu4zgM_RrnQtiw5dhpDj60zQSY6-wAPQayTDvakSVDkpvk75eSk7SZ3Vm0UBWLlMj3Him1prs03858nBSCMB0m5XOS75L8Ntf5MsSy9pcJO-xBHLmN04ErOWjsGBwO3Hsr29nj4ZCwJxpXH32xhG2vo3xZQkntoTeGnI9xEvY80T5INteNAGDRz1ZHF00vUNyjJJvdR7iWWwr3bmT3e4CI95xUL0m1-ypSSModZWMRJLtn_ICzoD9_JnWHcxfus5o_0M3K_0ni65KtQSiuB-Cu6zMB6Ru-o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