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

David Blaikie dblaikie at gmail.com
Fri Jan 18 08:09:12 PST 2013


On Jan 18, 2013 4:23 AM, "Martin Martin" <martin at silverliningsystems.com>
wrote:
>
> Hi all,
>
> 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.)  This is in Linux on an x86_64
architecture.
>
> My question is: why is this undefined behavior?

In short: because the C++ standard says so. -fsanitize=undefined is
designed to catch programs that have undefined behavior according to the
C++ standard.

> Can't modern Intel and AMD processors accesses unaligned ints, although
with a possible performance penalty?  So this would be a performance
problem, but not correctness?

Not necessarily. The compiler is still allowed to optimize on the basis
that the program doesn't do this. Even beyond ignoring the x86 cost penalty
for unaligned stores - it might optimize out tests on the low bits of a
pointer, knowing they must be zero for example.

I'm not sure if LLVM has any particular optimizations in this area at the
moment.

>  Is the problem that the compiler could use SSE or some other
instructions that require alignment and will seg fault or give wrong
results with unaligned access?
>
> Best,
> Martin
>
>
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20130118/1e16635d/attachment.html>


More information about the cfe-dev mailing list