[llvm-bugs] [Bug 47824] Clang generates wrong alignment on packed structs (looks like #5598 again)
via llvm-bugs
llvm-bugs at lists.llvm.org
Tue Oct 13 13:06:41 PDT 2020
https://bugs.llvm.org/show_bug.cgi?id=47824
Richard Smith <richard-llvm at metafoo.co.uk> changed:
What |Removed |Added
----------------------------------------------------------------------------
Resolution|--- |INVALID
Status|NEW |RESOLVED
--- Comment #1 from Richard Smith <richard-llvm at metafoo.co.uk> ---
The frontend behavior is correct. __attribute__((packed)) reduces the alignment
of the 'x' field of 'a' to 1. Extending your example a little:
struct __attribute__((packed)) a { int x; };
struct b { int x; };
void test(struct a *a, struct b *b)
{
a->x = b->x;
}
struct c { int n; char x; struct a a; };
int main() {
struct c c;
struct b b;
test(&c.a, &b);
}
... results in a->x not being 4-byte aligned in practice: struct c has 4 byte
alignment, and the offset of a.x in c is 5. So the "align 1" is necessary for
correctness.
Also, bug#5598 was that we did not properly mark accesses as "align 1" in this
case, not that we did incorrectly mark them.
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201013/6df7ea19/attachment.html>
More information about the llvm-bugs
mailing list