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

Matthieu Monrocq matthieu.monrocq at gmail.com
Fri Jan 18 10:23:59 PST 2013


On Fri, Jan 18, 2013 at 5:17 PM, Tim Northover <t.p.northover at gmail.com>wrote:

> >> sanitize=undefined is giving me an error message about unaligned access
> to
> >> a size_t.  It's in a packed structure, and indeed is not 8 byte aligned
> >> (although it is 4 byte aligned.)
> >
> > In short: because the C++ standard says so. -fsanitize=undefined is
> designed
> > to catch programs that have undefined behavior according to the C++
> > standard.
>
> Surely the standard doesn't say anything about packed structures? If
> Clang supports them I'd expect accesses to be lowered to ones which
> the target supports (based on the DataLayout, perhaps amongst other
> things).
>
> Tim.
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>

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.

If possible you might be able to either:
- deactivate the check that is not applicable to your situation
- blacklist the functions/files that perform that check (doing so will
remove *all* checks in the concerned functions/files though as far as I
know)

-- Matthieu
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130118/29b91f0d/attachment.html>


More information about the cfe-dev mailing list