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

    <tr>
        <th>Summary</th>
        <td>
            [Clang][CodeGen] __bdos off by 4
        </td>
    </tr>

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

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

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

<pre>
    Under certain circumstances __bdos can be off by 4 bytes compared to gcc.

Seen in the linux kernel:
https://lore.kernel.org/linux-kernel/3D0816D1-0807-4D37-8D5F-3C55CA910FAA@linux.dev/


Reproducer from Thorsten Blum (also here: https://godbolt.org/z/vvK9PE1Yq):
```C
#include <stdio.h>
#include <stdlib.h>

typedef struct {
    int counter;
} atomic_t;

typedef struct refcount_struct {
    atomic_t refs;
} refcount_t;

struct callback_head {
    struct callback_head *next;
    void (*func)(struct callback_head *head);
} __attribute__((aligned(sizeof(void *))));
#define rcu_head callback_head

typedef struct {
    uid_t val;
} kuid_t;

typedef struct {
    gid_t val;
} kgid_t;

struct posix_acl_entry {
    short e_tag;
    unsigned short e_perm;
 union {
        kuid_t e_uid;
        kgid_t e_gid;
 };
};

struct posix_acl {
    refcount_t a_refcount;
 struct rcu_head a_rcu;
    unsigned int a_count;
    struct posix_acl_entry a_entries[] __attribute__((counted_by(a_count)));
};

int main() {
 unsigned int count = 1;
    struct posix_acl *acl;

    acl = malloc(sizeof(struct posix_acl) +
                 sizeof(struct posix_acl_entry) * count);
    acl->a_count = count;

 printf("%zu", __builtin_dynamic_object_size(acl, 0));
    return 0;
}

```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyMVcuS6yYQ_Rq8oeySwBpLCy081jiLbFJ5LLJSIWjJZBA4CFzj-foUSH7I1zO5LhUYuvtw-gHNhkF2GqBE2SvKqgXz7mBsuTsL87FojDiXf2kBFnOwjkmNubTc94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