<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/69872>69872</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
Is a undefined behavior that apply __attribute__((aligned)) to C++ bit field?
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
hstk30-hw
</td>
</tr>
</table>
<pre>
In `C++17` standard say,
> An alignment-specifier may be applied to a variable or to a class data member, but it shall not be applied to a
bit-field, a function parameter, or an exception-declaration (18.3).
The `alignment-specifier` is language realm, and `__attribute__((aligned))` is gcc extension.
https://discourse.llvm.org/t/whats-the-difference-between-attribute-aligned-x-and-c-11-alignas/62391
This post mention it, but not enough.
So, I want to know can we apply `__attribute__((aligned))` to c++'s bit field? Is a undefined behavior? Or like that post, what is diff between `alignas` and `__attribute__((aligned))` .
---
What lead to this problem is follow code:
```
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
extern void *memset (void *__s, int __c, size_t __n);
struct S94 {
long long int __attribute__((aligned)): 0;
};
struct S94 s94;
void check94va(int z, ...) {
va_list ap;
va_start(ap, z);
struct S94 arg1 = va_arg(ap, struct S94);
long long int tmp = va_arg(ap, long long);
//printf("result = %lld\n", tmp);
if (tmp != 2LL) {
printf("Fails!!!!\n");
}
va_end(ap);
}
int main(void) {
memset(&s94, '\0', sizeof(s94));
//printf("sizeof(s94) = %ld\n", sizeof(s94));
check94va(1, s94, 2LL);
return 0;
}
```
failed in aarch64 as C++ code compiled use clang++. If not apply ` __attribute__((aligned))` for `long long int`, it work.
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVkuPozoT_TXOpkQEJiFhkUU_JlJLI32L-aS7jApcBN82NrJNZ3p-_VUBnQmZ170SIo3rdXxO2dUYgj5booPYPort8wqH2Dp_aEN8zdOkvawqp94PLxZEkT4J-SjkY7YTRQo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