[cfe-dev] -fsanitize=undefined and alignment on x86_64

Tim Northover t.p.northover at gmail.com
Fri Jan 18 11:09:33 PST 2013


> The Standard simply says that access should be aligned at least to the
> natural alignment of the type. You are free to overalign but not to
> underalign.
>
> Various compilers provide extensions to "pack" structures and a number of
> CPUs support unaligned accesses, but the Standard is concerned about ALL
> architectures and thus Standard compliant code should conform to alignment.

Well, if you were writing standard compliant code you wouldn't be
using packed structs in the first place. I suppose the question I'd
have is how Clang intends packed structs to fit in.

Saying that the programmer can use them but their code immediately
becomes undefined behaviour by doing so doesn't seem tenable to me.

Some kind of type qualifier seems to be the obvious candidate: if
"__attribute__((packed)) size_t" has no alignment requirements then
most obvious properties follow (you can access fields directly, but
not take pointers). But there may be issues with overloads and other
things I've only vaguely heard about.

Does anyone know what our official intent is, out of curiosity?

Tim.



More information about the cfe-dev mailing list