[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:55:34 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47824

Doctor Strange <femtium at protonmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|INVALID                     |FIXED

--- Comment #2 from Doctor Strange <femtium at protonmail.com> ---
Thank you very much for the detailed explanation.

Just now, I was having a discussion on discord about this, and learned more of
how aligned and packed work together.

I'm trying to build a mental model of this behaviour - if you have time,
perhaps you can tell me if the following is correct?


 1) Each struct has a required alignment, which is either derived or explicitly
set

 2) An n-aligned element must start at an address such that addr % n == 0. 

 3) Structs with unspecified alignment will use the maximum for any fields it
contains

 4) The aligned(x) attribute specifies the minimum alignment required.

 5) The "packed" attribute (e.g. on a struct) forbids padding, both between
fields in the struct, and before/after the struct itself, if the struct is used
as a field elsewhere.

 6) A combination of packed,aligned(n) will pack the struct fields, but still
keep aligned(n) externally.

Is that a fair representation of reality?

-- 
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/f6907944/attachment.html>


More information about the llvm-bugs mailing list