<p dir="ltr"><br>
On Jan 18, 2013 4:23 AM, "Martin Martin" <<a href="mailto:martin@silverliningsystems.com">martin@silverliningsystems.com</a>> wrote:<br>
><br>
> Hi all,<br>
><br>
> 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.<br>

><br>
> My question is: why is this undefined behavior? </p>
<p dir="ltr">In short: because the C++ standard says so. -fsanitize=undefined is designed to catch programs that have undefined behavior according to the C++ standard.</p>
<p dir="ltr">> 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?</p>
<p dir="ltr">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.</p>

<p dir="ltr">I'm not sure if LLVM has any particular optimizations in this area at the moment.</p>
<p dir="ltr">>  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?<br>
><br>
> Best,<br>
> Martin<br>
><br>
><br>
> _______________________________________________<br>
> cfe-dev mailing list<br>
> <a href="mailto:cfe-dev@cs.uiuc.edu">cfe-dev@cs.uiuc.edu</a><br>
> <a href="http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev">http://lists.cs.uiuc.edu/mailman/listinfo/cfe-dev</a><br>
><br>
</p>