[PATCH] D63044: [LangRef] Clarify poison semantics

Nikita Popov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Jun 9 12:27:46 PDT 2019


nikic marked an inline comment as done.
nikic added inline comments.


================
Comment at: llvm/docs/LangRef.rst:3270
+   any other pointer dereferencing instruction, if dereferencing ``null``
+   is undefined behavior based on address space and function attributes.
+-  The divisor operand of a ``udiv``, ``sdiv``, ``urem`` or ``srem``
----------------
nlopes wrote:
> jdoerfert wrote:
> > Why do you make `null` special here? Generally, there are a lot of non-dereferenceable addresses and `null` is just a special one. I'd argue, loading poison, etc., is bad even if `null` is a valid address.
> I agree. Dereferencing poison should always be UB, since that pointer is not based on a valid object.
I mentioned null here because I thought it is the only way in which UB for dereferencing follows directly from existing semantics (poison -> undef -> null -> UB).

Apparently that's not right. Looking around the code, https://github.com/llvm-mirror/llvm/blob/master/lib/Transforms/Utils/Local.cpp#L2102-L2109 does indeed assume that storing to undef is always UB, independent of whether null is dereferencable.

I assume that this is a consequence of https://llvm.org/docs/LangRef.html#pointer-aliasing-rules. I've added an explicit bullet for it there, as it wasn't obvious to me that this is the case.


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D63044/new/

https://reviews.llvm.org/D63044





More information about the llvm-commits mailing list