<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Thu, Jan 14, 2016 at 10:59 PM, John McCall via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div style="word-wrap:break-word"><div><div><div class="h5"><div><br></div></div></div>Part of my point is indeed an acknowledgement that valid objects can exist at misaligned addresses, and it should not be UB to perform a member access into them as long as the memory isn't accessed.  Consider, say, a pointer serialized data structure held in an unaligned buffer.  I am trying to say that code which drills into that data structure via that pointer and then works around the lack of alignment on the resulting address is not buggy; you seem to be suggesting that it is, and that the user has a responsibility to ensure that all of their pointer arithmetic is done on properly-aligned pointers.  I don’t think that's a defensible model.</div><div><span class=""><br><blockquote type="cite"><div><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div>(Note that sometimes the only way we detect the UB stemming from member access on a non-object -- for instance, with UBSan -- is because the pointer is misaligned. Your list can be read as suggesting that the UBSan alignment check for member access would violate our guarantees.)</div></div></div></div></div></blockquote><div><br></div></span>That’s true; I do not think the UBSan alignment check should be kicking in when we’re not accessing memory.</div><span class=""><font color="#888888"><div></div></font></span></div></blockquote></div></div><div class="gmail_extra"><br></div><div class="gmail_extra">Arithmetic (e.g. +), and casts is one thing. But, you're actually *dereferencing* a pointer which isn't valid (granted the dereference is syntactic, and doesn't result in an actual load.) I don't understand why you think it is not a defensible model to (continue to) forbid this?<div><div><br></div><div>Furthermore, if that is to be valid, why should it only be the case for misalignment, and not null?</div><div><br></div><div>That is, I'd argue that either "&X->foo" should be considered always valid, regardless of what the value of the X pointer is, OR it must (as it does now) require an X pointing to an actually valid object. Going halfway and saying it's only valid for some kinds of invalid X pointers does not seem like a good way to go.</div></div><div><br></div></div></div>